@@ -276,22 +276,26 @@ def _read_nihon_header(fname):
276
276
return header
277
277
278
278
279
- def _read_event_log_block (fid , t_block , device_type ):
279
+ def _read_event_log_block (fid , t_block , version ):
280
280
fid .seek (0x92 + t_block * 20 )
281
- t_blk_address = np .fromfile (fid , np .uint32 , 1 )[ 0 ]
282
- if t_blk_address == 0 :
281
+ data = np .fromfile (fid , np .uint32 , 1 )
282
+ if data . size == 0 or data [ 0 ] == 0 :
283
283
return
284
+ t_blk_address = data [0 ]
284
285
285
286
fid .seek (t_blk_address + 0x1 )
286
- data_name = np .fromfile (fid , "|S16" , 1 ).astype ("U16" )[ 0 ]
287
- if data_name != device_type :
287
+ data = np .fromfile (fid , "|S16" , 1 ).astype ("U16" )
288
+ if data . size == 0 or data [ 0 ] != version :
288
289
return
289
290
290
291
fid .seek (t_blk_address + 0x12 )
291
- n_logs = np .fromfile (fid , np .uint8 , 1 )[0 ]
292
+ data = np .fromfile (fid , np .uint8 , 1 )
293
+ if data .size == 0 :
294
+ return
295
+ n_logs = data [0 ]
296
+
292
297
fid .seek (t_blk_address + 0x14 )
293
- t_logs = np .fromfile (fid , "|S45" , n_logs )
294
- return t_logs
298
+ return np .fromfile (fid , "|S45" , n_logs )
295
299
296
300
297
301
def _parse_event_log (event_log ):
@@ -333,11 +337,10 @@ def _read_nihon_annotations(fname):
333
337
t_sub_logs = None
334
338
if may_have_sub_blocks :
335
339
t_sub_logs = _read_event_log_block (fid , t_block + 22 , version )
336
- assert t_sub_logs is None or len (t_logs ) == len (t_sub_logs )
337
340
338
341
for i , t_log in enumerate (t_logs ):
339
342
t_desc , t_onset = _parse_event_log (t_log )
340
- if t_sub_logs is not None :
343
+ if t_sub_logs is not None and t_logs . size == t_sub_logs . size :
341
344
t_sub_desc , t_sub_onset = _parse_sub_event_log (t_sub_logs [i ])
342
345
t_desc += t_sub_desc
343
346
t_onset += t_sub_onset
@@ -351,7 +354,7 @@ def _read_nihon_annotations(fname):
351
354
else :
352
355
break
353
356
else :
354
- warn (f"Could not decode log { t_desc } as one of { _encodings } " )
357
+ warn (f"Could not decode log as one of { _encodings } " )
355
358
continue
356
359
357
360
all_onsets .append (t_onset )
0 commit comments