def read_fid(filename, shape=None, torder='flat', as_2d=False,
             read_blockhead=False):
    """
    Read a Agilent/Varian binary (fid) file.

    Parameters
    ----------
    filename : str
        Filename of Agilent/Varian binary file (fid) to read.
    shape : tuple of ints, optional
        Shape of the binary data. If not provided data is returned as a 2D
        array. Required if more than one trace per block (non-standard).
    torder : {'f', 'n', 'o'}
        Trace order. See :py:func:`read` for details.
    as_2d : bool, optional
        True to return the data as a 2D array, ignoring the shape and torder
        parameters.
    read_blockhead : bool, optional
        True to read the Agilent/Varian blockheaders(s) into the returned
        dictionary. False ignores them.

    Returns
    -------
    dic : dict
        Dictionary of Agilent/Varian binary file parameters.
    data : ndarray
        Array of NMR data.

    See Also
    --------
    read_fid_lowmem : Read a Agilent/Varian binary file using minimal amounts
        of memory.
    read : Read Agilent/Varian files from a directory.

    """
    # 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 __HOLE__:
        warn(str(data.shape) + "cannot be shaped into" + str(shape))
        return dic, data

    return dic, data
dataset/ETHPy150Open jjhelmus/nmrglue/nmrglue/fileio/varian.py/read_fid