@@ -21,6 +21,7 @@ def read_rdi(
2121 debug_level = - 1 ,
2222 vmdas_search = False ,
2323 winriver = False ,
24+ search_num = 20000 ,
2425 ** kwargs ,
2526) -> xr .Dataset :
2627 """
@@ -65,7 +66,11 @@ def read_rdi(
6566 # Reads into a dictionary of dictionaries using netcdf naming conventions
6667 # Should be easier to debug
6768 rdr = _RDIReader (
68- filename , debug_level = debug_level , vmdas_search = vmdas_search , winriver = winriver
69+ filename ,
70+ debug_level = debug_level ,
71+ vmdas_search = vmdas_search ,
72+ winriver = winriver ,
73+ search_num = search_num ,
6974 )
7075 datNB , datBB = rdr .load_data (nens = nens )
7176
@@ -159,9 +164,7 @@ def _set_rdi_declination(dat, fname, inplace):
159164
160165
161166class _RDIReader :
162- def __init__ (
163- self , fname , navg = 1 , debug_level = - 1 , vmdas_search = False , winriver = False
164- ):
167+ def __init__ (self , fname , debug_level , vmdas_search , winriver , search_num ):
165168 self .fname = base ._abspath (fname )
166169 print ("\n Reading file {} ..." .format (fname ))
167170 self ._debug_level = debug_level
@@ -170,6 +173,7 @@ def __init__(
170173 self ._vm_source = 0
171174 self ._pos = 0
172175 self .progress = 0
176+ self .search_num = search_num
173177 self ._cfac32 = np .float32 (180 / 2 ** 31 ) # signed 32 to float
174178 self ._cfac16 = np .float32 (180 / 2 ** 15 ) # unsigned16 to float
175179 self ._fixoffset = 0
@@ -194,7 +198,7 @@ def __init__(
194198 logging .info ("self._BB {}" .format (self ._BB ))
195199 logging .info ("self.cfgBB: {}" .format (self .cfgBB ))
196200 self .f .seek (self ._pos , 0 )
197- self .n_avg = navg
201+ self .n_avg = 1
198202
199203 self .ensemble = lib ._ensemble (self .n_avg , self .cfg ["n_cells" ])
200204 if self ._BB :
@@ -500,7 +504,7 @@ def search_buffer(self):
500504 """
501505 Check to see if the next bytes indicate the beginning of a
502506 data block. If not, search for the next data block, up to
503- _search_num times.
507+ search_num times.
504508 """
505509 fd = self .f
506510 id = fd .read_ui8 (2 )
@@ -515,8 +519,11 @@ def search_buffer(self):
515519 logging .info ("cfgid0: [{:x}, {:x}]" .format (* cfgid ))
516520 # If not [127, 127] or if the file ends in the next ensemble
517521 while (cfgid != [127 , 127 ]) or self .check_eof ():
522+ if search_cnt == self .search_num :
523+ logging .debug (f"Stopped searching at byte position { fd .tell ()} " )
524+ return False
525+ # Search for the next header or the end of the file
518526 if cfgid == [127 , 121 ]:
519- # Search for the next header or the end of the file
520527 skipbytes = fd .read_i16 (1 )
521528 fd .seek (skipbytes - 2 , 1 )
522529 id = fd .read_ui8 (2 )
0 commit comments