'Read a segment of data from a file.'

def _read_segment_file(self, data, idx, fi, start, stop, cals, mult):

    bti_info = self._raw_extras[fi]
    fname = bti_info['pdf_fname']
    dtype = bti_info['dtype']
    n_channels = self.info['nchan']
    n_bytes = np.dtype(dtype).itemsize
    data_left = ((stop - start) * n_channels)
    read_cals = np.empty((bti_info['total_chans'],))
    for ch in bti_info['chs']:
        read_cals[ch['index']] = ch['cal']
    block_size = (((int(100000000.0) // n_bytes) // n_channels) * n_channels)
    block_size = min(data_left, block_size)
    with _bti_open(fname, 'rb') as fid:
        fid.seek((bti_info['bytes_per_slice'] * start), 0)
        for sample_start in (np.arange(0, data_left, block_size) // n_channels):
            count = min(block_size, (data_left - (sample_start * n_channels)))
            if isinstance(fid, six.BytesIO):
                block = np.fromstring(fid.getvalue(), dtype, count)
            else:
                block = np.fromfile(fid, dtype, count)
            sample_stop = (sample_start + (count // n_channels))
            shape = ((sample_stop - sample_start), bti_info['total_chans'])
            block.shape = shape
            data_view = data[:, sample_start:sample_stop]
            one = np.empty(block.shape[::(-1)])
            for (ii, b_i_o) in enumerate(bti_info['order']):
                one[ii] = (block[:, b_i_o] * read_cals[b_i_o])
            _mult_cal_one(data_view, one, idx, cals, mult)
