#NEWLINE# def read( filename ) : #NEWLINE# #INDENT# '\n    Read a nmrglue table file.\n\n    Parameters\n    ----------\n    filename : str\n        Filename of nmrglue table file to read.\n\n    Returns\n    -------\n    comments : list\n        List of comments (strings terminated with newline)\n    rec : recarray\n        Records array with named fields.\n\n    ' #NEWLINE# f = open ( filename , 'rb' ) #NEWLINE# comments = [ l for l in f if ( l [ 0 ] == '#' ) ] #NEWLINE# f . close ( ) #NEWLINE# nl = [ i for ( i , l ) in enumerate ( comments ) if ( l [ : 7 ] == '# NAMES' ) ] #NEWLINE# if ( len ( nl ) != 1 ) : #NEWLINE# #INDENT# raise IOError ( ( '%s does not have a # NAMES line' % filename ) ) #NEWLINE# #UNINDENT# dtd = { #NEWLINE# #INDENT# 'names' : comments . pop ( nl [ 0 ] ) [ 7 : ] . split ( ) , #NEWLINE# #UNINDENT# } #NEWLINE# dl = [ i for ( i , l ) in enumerate ( comments ) if ( l [ : 9 ] == '# FORMATS' ) ] #NEWLINE# if ( len ( dl ) != 1 ) : #NEWLINE# #INDENT# raise IOError ( ( '%s does not have a # FORMATS line' % filename ) ) #NEWLINE# #UNINDENT# dtd [ 'formats' ] = comments . pop ( dl [ 0 ] ) [ 9 : ] . split ( ) #NEWLINE# return ( comments , np . atleast_1d ( np . recfromtxt ( filename , dtype = dtd ) ) )