# Buggy code
def _read_curry_parameters(fname):
    """Extract Curry params from a Curry info file."""
    _msg_match = (
        "The sampling frequency and the time steps extracted from "
        "the parameter file do not match."
    )
    _msg_invalid = "sfreq must be greater than 0. Got sfreq = {0}"

    var_names = [
        "NumSamples",
        "SampleFreqHz",
        "DataFormat",
        "SampleTimeUsec",
        "NUM_SAMPLES",
        "SAMPLE_FREQ_HZ",
        "DATA_FORMAT",
        "SAMPLE_TIME_USEC",
    ]

    param_dict = dict()
    unit_dict = dict()
    with open(fname) as fid:
        for line in iter(fid):
            if any(var_name in line for var_name in var_names):
                key, val = line.replace(" ", "").replace("\n", "").split("=")
                param_dict[key.lower().replace("_", "")] = val
            for type in CHANTYPES:
                if "DEVICE_PARAMETERS" + CHANTYPES[type] + " START" in line:
                    data_unit = next(fid)
                    unit_dict[type] = (
                        data_unit.replace(" ", "").replace("\n", "").split("=")[-1]
                    )

    n_samples = int(param_dict["numsamples"])
    sfreq = float(param_dict["samplefreqhz"])
    time_step = float(param_dict["sampletimeusec"]) * 1e-6
    is_ascii = param_dict["dataformat"] == "ASCII"

    if time_step == 0:
        true_sfreq = sfreq
    elif sfreq == 0:
        true_sfreq = 1 / time_step
    elif not np.isclose(sfreq, 1 / time_step):
        raise ValueError(_msg_match)
    else:  # they're equal and != 0
        true_sfreq = sfreq
    if true_sfreq <= 0:
        raise ValueError(_msg_invalid.format(true_sfreq))

    return CurryParameters(n_samples, true_sfreq, is_ascii, unit_dict)


# Traceback (RuntimeError)
Data loaded, with preload=False: C:\read_curry example data\PH005_baseline.dat, 70 channels X 76850 points
Leaving device<->head transform as None (no landmarks found)
Reading 0 ... 76849  =      0.000 ...   307.396 secs...
Traceback (most recent call last):
File "c:\Users\todfl\.vscode\extensions\ms-python.python-2020.2.64397\pythonFiles\ptvsd_launcher.py", line 48, in <module>
main(ptvsdArgs)
File "c:\Users\todfl\.vscode\extensions\ms-python.python-2020.2.64397\pythonFiles\lib\python\old_ptvsd\ptvsd\__main__.py", line 432, in main
run()
File "c:\Users\todfl\.vscode\extensions\ms-python.python-2020.2.64397\pythonFiles\lib\python\old_ptvsd\ptvsd\__main__.py", line 316, in run_file
runpy.run_path(target, run_name='__main__')
File "C:\ProgramData\Anaconda3\lib\runpy.py", line 265, in run_path
return _run_module_code(code, init_globals, run_name,
File "C:\ProgramData\Anaconda3\lib\runpy.py", line 97, in _run_module_code
_run_code(code, mod_globals, init_globals,
File "C:\ProgramData\Anaconda3\lib\runpy.py", line 87, in _run_code
File "c:\Users\todfl\Documents\Decker\EEG Processing\EEG Processing Code\read_raw_curry error MWE.py", line 7, in <module>
raw = mne.io.read_raw_curry(data_path,preload=True,verbose=True)
File "<decorator-gen-218>", line 20, in read_raw_curry
File "C:\ProgramData\Anaconda3\lib\site-packages\mne\io\curry\curry.py", line 406, in read_raw_curry
return RawCurry(fname, preload, verbose)
File "<decorator-gen-219>", line 20, in __init__
File "C:\ProgramData\Anaconda3\lib\site-packages\mne\io\curry\curry.py", line 439, in __init__
super(RawCurry, self).__init__(
File "<decorator-gen-160>", line 20, in __init__
File "C:\ProgramData\Anaconda3\lib\site-packages\mne\io\base.py", line 247, in __init__
self._preload_data(preload)
File "<decorator-gen-164>", line 20, in _preload_data
File "C:\ProgramData\Anaconda3\lib\site-packages\mne\io\base.py", line 528, in _preload_data
self._data = self._read_segment(
File "<decorator-gen-162>", line 20, in _read_segment
File "C:\ProgramData\Anaconda3\lib\site-packages\mne\io\base.py", line 412, in _read_segment
_ReadSegmentFileProtector(self)._read_segment_file(
File "C:\ProgramData\Anaconda3\lib\site-packages\mne\io\base.py", line 1816, in _read_segment_file
return self.__raw.__class__._read_segment_file(
File "C:\ProgramData\Anaconda3\lib\site-packages\mne\io\curry\curry.py", line 469, in _read_segment_file
_read_segments_file(
File "C:\ProgramData\Anaconda3\lib\site-packages\mne\io\utils.py", line 221, in _read_segments_file
raise RuntimeError('Incorrect number of samples (%s != %s), '
RuntimeError: Incorrect number of samples (5302650 != 5379500), please report this error to MNE-Python developers

# Fixed code
def _read_curry_parameters(fname):
    """Extract Curry params from a Curry info file."""
    _msg_match = (
        "The sampling frequency and the time steps extracted from "
        "the parameter file do not match."
    )
    _msg_invalid = "sfreq must be greater than 0. Got sfreq = {0}"

    var_names = [
        "NumSamples",
        "SampleFreqHz",
        "DataFormat",
        "SampleTimeUsec",
        "NumChannels",
        "StartYear",
        "StartMonth",
        "StartDay",
        "StartHour",
        "StartMin",
        "StartSec",
        "StartMillisec",
        "NUM_SAMPLES",
        "SAMPLE_FREQ_HZ",
        "DATA_FORMAT",
        "SAMPLE_TIME_USEC",
        "NUM_CHANNELS",
        "START_YEAR",
        "START_MONTH",
        "START_DAY",
        "START_HOUR",
        "START_MIN",
        "START_SEC",
        "START_MILLISEC",
    ]

    param_dict = dict()
    unit_dict = dict()

    with open(fname) as fid:
        for line in iter(fid):
            if any(var_name in line for var_name in var_names):
                key, val = line.replace(" ", "").replace("\n", "").split("=")
                param_dict[key.lower().replace("_", "")] = val
            for type in CHANTYPES:
                if "DEVICE_PARAMETERS" + CHANTYPES[type] + " START" in line:
                    data_unit = next(fid)
                    unit_dict[type] = (
                        data_unit.replace(" ", "").replace("\n", "").split("=")[-1]
                    )

    # look for CHAN_IN_FILE sections, which may or may not exist; issue #8391
    types = ["meg", "eeg", "misc"]
    chanidx_in_file = _read_curry_lines(
        fname, ["CHAN_IN_FILE" + CHANTYPES[key] for key in types]
    )

    n_samples = int(param_dict["numsamples"])
    sfreq = float(param_dict["samplefreqhz"])
    time_step = float(param_dict["sampletimeusec"]) * 1e-6
    is_ascii = param_dict["dataformat"] == "ASCII"
    n_channels = int(param_dict["numchannels"])
    try:
        dt_start = datetime(
            int(param_dict["startyear"]),
            int(param_dict["startmonth"]),
            int(param_dict["startday"]),
            int(param_dict["starthour"]),
            int(param_dict["startmin"]),
            int(param_dict["startsec"]),
            int(param_dict["startmillisec"]) * 1000,
            timezone.utc,
        )
        # Note that the time zone information is not stored in the Curry info
        # file, and it seems the start time info is in the local timezone
        # of the acquisition system (which is unknown); therefore, just set
        # the timezone to be UTC.  If the user knows otherwise, they can
        # change it later.  (Some Curry files might include StartOffsetUTCMin,
        # but its presence is unpredictable, so we won't rely on it.)
    except (ValueError, KeyError):
        dt_start = None  # if missing keywords or illegal values, don't set

    if time_step == 0:
        true_sfreq = sfreq
    elif sfreq == 0:
        true_sfreq = 1 / time_step
    elif not np.isclose(sfreq, 1 / time_step):
        raise ValueError(_msg_match)
    else:  # they're equal and != 0
        true_sfreq = sfreq
    if true_sfreq <= 0:
        raise ValueError(_msg_invalid.format(true_sfreq))

    return CurryParameters(
        n_samples,
        true_sfreq,
        is_ascii,
        unit_dict,
        n_channels,
        dt_start,
        chanidx_in_file,
    )