'Read in header information from a raw file.'

@verbose
def _read_raw_file(self, fname, allow_maxshield, preload, do_check_fname=True, verbose=None):

    logger.info(('Opening    raw    data    file    %s...' % fname))
    if do_check_fname:
        check_fname(fname, 'raw', ('raw.fif', 'raw_sss.fif', 'raw_tsss.fif', 'raw.fif.gz', 'raw_sss.fif.gz', 'raw_tsss.fif.gz'))
    ext = os.path.splitext(fname)[1].lower()
    whole_file = (preload if ('.gz' in ext) else False)
    (ff, tree, _) = fiff_open(fname, preload=whole_file)
    with ff as fid:
        (info, meas) = read_meas_info(fid, tree, clean_bads=True)
        annotations = None
        annot_data = dir_tree_find(tree, FIFF.FIFFB_MNE_ANNOTATIONS)
        if (len(annot_data) > 0):
            annot_data = annot_data[0]
            for k in range(annot_data['nent']):
                kind = annot_data['directory'][k].kind
                pos = annot_data['directory'][k].pos
                orig_time = None
                tag = read_tag(fid, pos)
                if (kind == FIFF.FIFF_MNE_BASELINE_MIN):
                    onset = tag.data
                    if (onset is None):
                        break
                elif (kind == FIFF.FIFF_MNE_BASELINE_MAX):
                    duration = (tag.data - onset)
                elif (kind == FIFF.FIFF_COMMENT):
                    description = tag.data.split(':')
                    description = [d.replace(';', ':') for d in description]
                elif (kind == FIFF.FIFF_MEAS_DATE):
                    orig_time = float(tag.data)
            if (onset is not None):
                annotations = Annotations(onset, duration, description, orig_time)
        raw_node = dir_tree_find(meas, FIFF.FIFFB_RAW_DATA)
        if (len(raw_node) == 0):
            raw_node = dir_tree_find(meas, FIFF.FIFFB_CONTINUOUS_DATA)
            if (len(raw_node) == 0):
                raw_node = dir_tree_find(meas, FIFF.FIFFB_SMSH_RAW_DATA)
                if (len(raw_node) == 0):
                    raise ValueError(('No    raw    data    in    %s' % fname))
                _check_maxshield(allow_maxshield)
                info['maxshield'] = True
        if (len(raw_node) == 1):
            raw_node = raw_node[0]
        directory = raw_node['directory']
        nent = raw_node['nent']
        nchan = int(info['nchan'])
        first = 0
        first_samp = 0
        first_skip = 0
        if (directory[first].kind == FIFF.FIFF_FIRST_SAMPLE):
            tag = read_tag(fid, directory[first].pos)
            first_samp = int(tag.data)
            first += 1
            _check_entry(first, nent)
        if (directory[first].kind == FIFF.FIFF_DATA_SKIP):
            tag = read_tag(fid, directory[first].pos)
            first_skip = int(tag.data)
            first += 1
            _check_entry(first, nent)
        raw = _RawShell()
        raw.filename = fname
        raw.first_samp = first_samp
        raw.annotations = annotations
        raw_extras = list()
        nskip = 0
        orig_format = None
        for k in range(first, nent):
            ent = directory[k]
            if (ent.kind == FIFF.FIFF_DATA_SKIP):
                tag = read_tag(fid, ent.pos)
                nskip = int(tag.data)
            elif (ent.kind == FIFF.FIFF_DATA_BUFFER):
                if (ent.type == FIFF.FIFFT_DAU_PACK16):
                    nsamp = (ent.size // (2 * nchan))
                elif (ent.type == FIFF.FIFFT_SHORT):
                    nsamp = (ent.size // (2 * nchan))
                elif (ent.type == FIFF.FIFFT_FLOAT):
                    nsamp = (ent.size // (4 * nchan))
                elif (ent.type == FIFF.FIFFT_DOUBLE):
                    nsamp = (ent.size // (8 * nchan))
                elif (ent.type == FIFF.FIFFT_INT):
                    nsamp = (ent.size // (4 * nchan))
                elif (ent.type == FIFF.FIFFT_COMPLEX_FLOAT):
                    nsamp = (ent.size // (8 * nchan))
                elif (ent.type == FIFF.FIFFT_COMPLEX_DOUBLE):
                    nsamp = (ent.size // (16 * nchan))
                else:
                    raise ValueError(('Cannot    handle    data    buffers    of    type    %d' % ent.type))
                if (orig_format is None):
                    if (ent.type == FIFF.FIFFT_DAU_PACK16):
                        orig_format = 'short'
                    elif (ent.type == FIFF.FIFFT_SHORT):
                        orig_format = 'short'
                    elif (ent.type == FIFF.FIFFT_FLOAT):
                        orig_format = 'single'
                    elif (ent.type == FIFF.FIFFT_DOUBLE):
                        orig_format = 'double'
                    elif (ent.type == FIFF.FIFFT_INT):
                        orig_format = 'int'
                    elif (ent.type == FIFF.FIFFT_COMPLEX_FLOAT):
                        orig_format = 'single'
                    elif (ent.type == FIFF.FIFFT_COMPLEX_DOUBLE):
                        orig_format = 'double'
                if (first_skip > 0):
                    first_samp += (nsamp * first_skip)
                    raw.first_samp = first_samp
                    first_skip = 0
                if (nskip > 0):
                    raw_extras.append(dict(ent=None, first=first_samp, nsamp=(nskip * nsamp), last=((first_samp + (nskip * nsamp)) - 1)))
                    first_samp += (nskip * nsamp)
                    nskip = 0
                raw_extras.append(dict(ent=ent, first=first_samp, last=((first_samp + nsamp) - 1), nsamp=nsamp))
                first_samp += nsamp
        next_fname = _get_next_fname(fid, fname, tree)
    raw.last_samp = (first_samp - 1)
    raw.orig_format = orig_format
    cals = np.zeros(info['nchan'])
    for k in range(info['nchan']):
        cals[k] = (info['chs'][k]['range'] * info['chs'][k]['cal'])
    raw._cals = cals
    raw._raw_extras = raw_extras
    logger.info(('                Range    :    %d    ...    %d    =        %9.3f    ...    %9.3f    secs' % (raw.first_samp, raw.last_samp, (float(raw.first_samp) / info['sfreq']), (float(raw.last_samp) / info['sfreq']))))
    info['buffer_size_sec'] = (np.median([r['nsamp'] for r in raw_extras]) / info['sfreq'])
    raw.info = info
    raw.verbose = verbose
    logger.info('Ready.')
    return (raw, next_fname)
