def read_fid(filename, shape=None, torder='flat', as_2d=False,
             read_blockhead=False):
    # open the file
    f = open(filename, 'rb')

    # read the fileheader
    dic = fileheader2dic(get_fileheader(f))

    # if ntraces is not 1 use _ntraces version
    if dic["ntraces"] != 1:
        return read_fid_ntraces(filename, shape, torder, as_2d, read_blockhead)

    # data parameters
    dt = find_dtype(dic)
    nblocks = dic["nblocks"]
    pts = dic["np"]
    nbheaders = dic["nbheaders"]

    # read the data
    if read_blockhead:
        bdic, data = get_nblocks(f, nblocks, pts, nbheaders, dt,
                                 read_blockhead)
        dic["blockheader"] = bdic
    else:
        data = get_nblocks(f, nblocks, pts, nbheaders, dt, read_blockhead)
    f.close()

    # uninterleave the real and imaginary data
    data = uninterleave_data(data)

    # return as 2D is requested
    if as_2d:
        return dic, data

    # return raw data if no shape provided.
    if shape is None:
        warn("unknown shape, returning unshaped data")
        return dic, data

    # check for 1D
    if data.shape[0] == 1:
        return dic, np.squeeze(data)

    # try to reshape
    # reorder 3D/4D data
    if len(shape) >= 3:
        try:
            return dic, reorder_data(data, shape, torder)
        except:
            warn("data cannot be re-ordered, returning raw 2D data\n" +
                 "Provided shape: " + str(shape) + " torder: " + str(torder))
            return dic, data

    try:
        data = data.reshape(shape)
    except ValueError:
        warn(str(data.shape) + "cannot be shaped into" + str(shape))
        return dic, data

    return dic, data
Read a Agilent/Varian binary (fid) file.
dataset/ETHPy150Open jjhelmus/nmrglue/nmrglue/fileio/varian.py/read_fid