diff --git a/mhkit/dolfyn/io/base.py b/mhkit/dolfyn/io/base.py index 5208ca47..c31f5fc0 100644 --- a/mhkit/dolfyn/io/base.py +++ b/mhkit/dolfyn/io/base.py @@ -83,6 +83,9 @@ def _handle_nan(data): Finds trailing nan's that cause issues in running the rotation algorithms and deletes them. """ + if "time" not in data["coords"]: + raise Exception("No data recorded in file.") + nan = np.zeros(data["coords"]["time"].shape, dtype=bool) l = data["coords"]["time"].size diff --git a/mhkit/dolfyn/io/nortek.py b/mhkit/dolfyn/io/nortek.py index 0e81a874..3510ef40 100644 --- a/mhkit/dolfyn/io/nortek.py +++ b/mhkit/dolfyn/io/nortek.py @@ -262,6 +262,7 @@ def __init__( self.config["coord_sys_axes"] ] da["has_imu"] = 0 # Initiate attribute + self._eof = self.pos if self.debug: logging.info("Init completed") @@ -384,6 +385,7 @@ def findnext(self, do_cs=True): if self.endian == "<": func = np.uint8 func2 = lib._bitshift8 + searching = False while True: val = unpack(self.endian + "H", self.read(2))[0] if np.array(val).astype(func) == 165 and (not do_cs or cs == sum): @@ -391,6 +393,9 @@ def findnext(self, do_cs=True): return hex(func2(val)) sum += cs cs = val + if self.debug and not searching: + logging.debug("Scanning every 2 bytes for next datablock...") + searching = True def read_id(self): """Read the next 'ID' from the file.""" @@ -456,6 +461,7 @@ def findnextid(self, id): id = int(id, 0) nowid = None while nowid != id: + pos = self.pos nowid = self.read_id() if nowid == 16: shift = 22 @@ -463,6 +469,9 @@ def findnextid(self, id): sz = 2 * unpack(self.endian + "H", self.read(2))[0] shift = sz - 4 self.f.seek(shift, 1) + # If we get stuck in a while loop + if self.pos == pos: + self.f.seek(2, 1) return self.pos def code_spacing(self, searchcode, iternum=50):