Reads given range of integrations from sdm of given scan.
    Uses BDFData object to read.
    readints=0 will read all of bdf (skipping nskip).
    Option to write pkl to store bdf info for faster parse next time.

def read_bdf(sdmpath, scan, nskip=0, readints=0, writebdfpkl=False, bdfdir=None):
    """ Reads given range of integrations from sdm of given scan.
    Uses BDFData object to read.
    readints=0 will read all of bdf (skipping nskip).
    Option to write pkl to store bdf info for faster parse next time.
    """

    assert os.path.exists(sdmpath), 'sdmpath %s does not exist' % sdmpath
    scans, sources = read_metadata(sdmpath, scan, bdfdir=bdfdir)
    assert scans[scan]['bdfstr'], 'bdfstr not defined for scan %d' % scan
    bdffile = scans[scan]['bdfstr']

    assert os.path.exists(bdffile), 'Could not find bdf for scan %d and bdfstr %s.' % (scan, scans[scan]['bdfstr'])

    with open(bdffile, 'r') as fp:
        # define bdfpkldir
        if writebdfpkl:
            bdfpkldir = os.path.join(sdmpath, 'bdfpkls')   # make place for bdfpkls, if needed
            if not os.path.exists(bdfpkldir):
                os.makedirs(bdfpkldir)
        else:
            bdfpkldir = ''

        bdf = BDFData(fp, bdfpkldir=bdfpkldir).parse()
        if readints == 0:
            readints = bdf.n_integrations - nskip

        logger.info('Reading %d ints starting at int %d' % (readints, nskip))
        data = np.empty( (readints, bdf.n_baselines, bdf.n_channels, len(bdf.crosspols)), dtype='complex64', order='C')
        for i in xrange(readints):
            data[i] = bdf.get_data ('crossData.bin', i+nskip)
#            flag[i] = bdf.get_data ('flags.bin', i+nskip)  # need to get auto+cross parsing right to implement this

    return data