diff --git a/mne/_fiff/tag.py b/mne/_fiff/tag.py index 6a4636ef264..7f53cd21bf5 100644 --- a/mne/_fiff/tag.py +++ b/mne/_fiff/tag.py @@ -361,9 +361,9 @@ def _read_old_pack(fid, tag, shape, rlims): def _read_dir_entry_struct(fid, tag, shape, rlims): """Read dir entry struct tag.""" - pos = tag.pos + 16 + pos = tag.pos entries = list() - for offset in range(1, tag.size // 16): + for offset in range(tag.size // 16): ent = _read_tag_header(fid, pos + offset * 16) # The position of the real tag on disk is stored in the "next" entry within the # directory, so we need to overwrite ent.pos. For safety let's also overwrite diff --git a/mne/io/fiff/raw.py b/mne/io/fiff/raw.py index f9e10a0039d..f6b2027d8f5 100644 --- a/mne/io/fiff/raw.py +++ b/mne/io/fiff/raw.py @@ -231,7 +231,6 @@ def _read_raw_file( nchan = int(info["nchan"]) first = 0 first_samp = 0 - first_skip = 0 # Get first sample tag if it is there if directory[first].kind == FIFF.FIFF_FIRST_SAMPLE: @@ -240,14 +239,6 @@ def _read_raw_file( first += 1 _check_entry(first, nent) - # Omit initial skip - if directory[first].kind == FIFF.FIFF_DATA_SKIP: - # This first skip can be applied only after we know the bufsize - tag = read_tag(fid, directory[first].pos) - first_skip = int(tag.data.item()) - first += 1 - _check_entry(first, nent) - raw = _RawShell() raw.first_samp = first_samp if info["meas_date"] is None and annotations is not None: @@ -281,6 +272,9 @@ def _read_raw_file( FIFF.FIFFT_COMPLEX_DOUBLE: "double", } + nskip = 0 + nskip_in_samples = 0 + first_data_buffer = True for k in range(first, nent): ent = directory[k] # There can be skips in the data (e.g., if the user unclicked) @@ -297,24 +291,28 @@ def _read_raw_file( if orig_format is None: orig_format = _orig_format_dict[ent.type] - # Do we have an initial skip pending? - if first_skip > 0: - first_samp += nsamp * first_skip - raw.first_samp = first_samp - first_skip = 0 - # Do we have a skip pending? if nskip > 0: + nskip_in_samples += nskip * nsamp + nskip = 0 + + if nskip_in_samples > 0: raw_extras.append( dict( ent=None, first=first_samp, - nsamp=nskip * nsamp, - last=first_samp + nskip * nsamp - 1, + nsamp=nskip_in_samples, + last=first_samp + nskip_in_samples - 1, ) ) - first_samp += nskip * nsamp - nskip = 0 + first_samp += nskip_in_samples + nskip_in_samples = 0 + + # Handle an initial skip. + + if first_data_buffer: + raw.first_samp = first_samp + first_data_buffer = False # Add a data buffer raw_extras.append( @@ -328,7 +326,10 @@ def _read_raw_file( first_samp += nsamp elif ent.kind == FIFF.FIFF_DATA_SKIP: tag = read_tag(fid, ent.pos) - nskip = int(tag.data.item()) + nskip += int(tag.data.item()) + elif ent.kind == FIFF.FIFF_DATA_SKIP_SAMP: + tag = read_tag(fid, ent.pos) + nskip_in_samples += int(tag.data.item()) next_fname = _get_next_fname(fid, _path_from_fname(fname), tree)