def read(filename):
    """
    Read a Tecmag .tnt data file.

    Parameters
    ----------
    filename : str
        Name of file to read from

    Returns
    -------
    dic : dict
        Dictionary of Tecmag parameters.
    data : ndarray
        Array of NMR data.

    """
    tnt_sections = dict()

    with open(filename, 'rb') as tntfile:

        tntmagic = np.fromstring(tntfile.read(TNTMAGIC.itemsize),
                                 TNTMAGIC, count=1)[0]

        if not TNTMAGIC_RE.match(tntmagic):
            err = ("Invalid magic number (is '%s' really TNMR file?): %s" %
                   (filename, tntmagic))
            raise ValueError(err)

        # Read in the section headers
        tnthdrbytes = tntfile.read(TNTTLV.itemsize)
        while(TNTTLV.itemsize == len(tnthdrbytes)):
            tlv = np.fromstring(tnthdrbytes, TNTTLV)[0]
            data_length = tlv['length']
            hdrdict = {'offset': tntfile.tell(),
                       'length': data_length,
                       'bool': bool(tlv['bool'])}
            if 4096 <= data_length:
                hdrdict['data'] = tntfile.read(data_length)
                assert(len(hdrdict['data']) == data_length)
            else:
                tntfile.seek(data_length, os.SEEK_CUR)
            tnt_sections[tlv['tag'].decode()] = hdrdict
            tnthdrbytes = tntfile.read(TNTTLV.itemsize)

    assert(tnt_sections['TMAG']['length'] == TNTTMAG.itemsize)
    tmag = np.fromstring(tnt_sections['TMAG']['data'], TNTTMAG, count=1)[0]

    assert(tnt_sections['DATA']['length'] ==
           tmag['actual_npts'].prod() * 8)
    #  For some reason we can't set offset and shape together
    # DATA = np.memmap(tntfilename,np.dtype('<c8'), mode='r',
    #                  offset=self.tnt_sections['DATA']['offset'],
    #                  shape=self.TMAG['actual_npts'].tolist(),order='F')
    data = np.memmap(filename, np.dtype('<c8'), mode='c',
                     offset=tnt_sections['DATA']['offset'],
                     shape=tmag['actual_npts'].prod())
    data = np.reshape(data, tmag['actual_npts'], order='F')

    assert(tnt_sections['TMG2']['length'] == TNTTMG2.itemsize)
    tmg2 = np.fromstring(tnt_sections['TMG2']['data'], TNTTMG2, count=1)[0]

    dic = dict()
    for name in TNTTMAG.names:
        if not name.startswith('space'):
            dic[name] = tmag[name]
    for name in TNTTMG2.names:
        if name not in ['Boolean_space', 'unused', 'space', 'axis_set']:
            dic[name] = tmg2[name]
    for name in TNTGRIDANDAXIS.names:
        dic[name] = tmg2['axis_set'][name]

    return dic, data
dataset/ETHPy150Open jjhelmus/nmrglue/nmrglue/fileio/tecmag.py/read/swapped operands of `<=`