#NEWLINE# @ staticmethod #NEWLINE# def parse_control_record( line , current_unit = None , dtype = np . float32 , ext_unit_dict = None , array_format = None ) : #NEWLINE# #INDENT# '\n        parses a control record when reading an existing file\n        rectifies fixed to free format\n        current_unit (optional) indicates the unit number of the file being parsed\n        ' #NEWLINE# free_fmt = [ 'open/close' , 'internal' , 'external' , 'constant' ] #NEWLINE# raw = line . lower ( ) . strip ( ) . split ( ) #NEWLINE# ( freefmt , cnstnt , fmtin , iprn , nunit ) = ( None , None , None , ( - 1 ) , None ) #NEWLINE# fname = None #NEWLINE# isfloat = False #NEWLINE# if ( ( dtype == np . float ) or ( dtype == np . float32 ) ) : #NEWLINE# #INDENT# isfloat = True #NEWLINE# #UNINDENT# if ( str ( raw [ 0 ] ) in str ( free_fmt ) ) : #NEWLINE# #INDENT# freefmt = raw [ 0 ] #NEWLINE# if ( raw [ 0 ] == 'constant' ) : #NEWLINE# #INDENT# if isfloat : #NEWLINE# #INDENT# cnstnt = np . float ( raw [ 1 ] . lower ( ) . replace ( 'd' , 'e' ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# cnstnt = np . int ( raw [ 1 ] . lower ( ) ) #NEWLINE# #UNINDENT# #UNINDENT# if ( raw [ 0 ] == 'internal' ) : #NEWLINE# #INDENT# if isfloat : #NEWLINE# #INDENT# cnstnt = np . float ( raw [ 1 ] . lower ( ) . replace ( 'd' , 'e' ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# cnstnt = np . int ( raw [ 1 ] . lower ( ) ) #NEWLINE# #UNINDENT# fmtin = raw [ 2 ] . strip ( ) #NEWLINE# iprn = int ( raw [ 3 ] ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( raw [ 0 ] == 'external' ) : #NEWLINE# #INDENT# if ( ext_unit_dict is not None ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# fname = ext_unit_dict [ int ( raw [ 1 ] ) ] . filename . strip ( ) #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# #UNINDENT# nunit = int ( raw [ 1 ] ) #NEWLINE# if isfloat : #NEWLINE# #INDENT# cnstnt = np . float ( raw [ 2 ] . lower ( ) . replace ( 'd' , 'e' ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# cnstnt = np . int ( raw [ 2 ] . lower ( ) ) #NEWLINE# #UNINDENT# fmtin = raw [ 3 ] . strip ( ) #NEWLINE# iprn = int ( raw [ 4 ] ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( raw [ 0 ] == 'open/close' ) : #NEWLINE# #INDENT# fname = raw [ 1 ] . strip ( ) #NEWLINE# if isfloat : #NEWLINE# #INDENT# cnstnt = np . float ( raw [ 2 ] . lower ( ) . replace ( 'd' , 'e' ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# cnstnt = np . int ( raw [ 2 ] . lower ( ) ) #NEWLINE# #UNINDENT# fmtin = raw [ 3 ] . strip ( ) #NEWLINE# iprn = int ( raw [ 4 ] ) #NEWLINE# ( npl , fmt , width , decimal ) = ( None , None , None , None ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# locat = np . int ( line [ 0 : 10 ] . strip ( ) ) #NEWLINE# if isfloat : #NEWLINE# #INDENT# cnstnt = np . float ( line [ 10 : 20 ] . strip ( ) . lower ( ) . replace ( 'd' , 'e' ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# cnstnt = np . int ( line [ 10 : 20 ] . strip ( ) ) #NEWLINE# if ( cnstnt == 0 ) : #NEWLINE# #INDENT# cnstnt = 1 #NEWLINE# #UNINDENT# #UNINDENT# if ( locat != 0 ) : #NEWLINE# #INDENT# fmtin = line [ 20 : 40 ] . strip ( ) #NEWLINE# try : #NEWLINE# #INDENT# iprn = np . int ( line [ 40 : 50 ] . strip ( ) ) #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# iprn = 0 #NEWLINE# #UNINDENT# #UNINDENT# if ( locat == 0 ) : #NEWLINE# #INDENT# freefmt = 'constant' #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( locat < 0 ) : #NEWLINE# #INDENT# freefmt = 'external' #NEWLINE# nunit = ( np . int ( locat ) * ( - 1 ) ) #NEWLINE# fmtin = '(binary)' #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( locat > 0 ) : #NEWLINE# #INDENT# if ( locat == current_unit ) : #NEWLINE# #INDENT# freefmt = 'internal' #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# freefmt = 'external' #NEWLINE# #UNINDENT# nunit = np . int ( locat ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# if ( array_format == 'mt3d' ) : #NEWLINE# #INDENT# if ( locat == 100 ) : #NEWLINE# #INDENT# freefmt = 'internal' #NEWLINE# nunit = current_unit #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( locat == 101 ) : #NEWLINE# #INDENT# raise NotImplementedError ( 'MT3D block format not supported...' ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( locat == 102 ) : #NEWLINE# #INDENT# raise NotImplementedError ( 'MT3D zonal format not supported...' ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( locat == 103 ) : #NEWLINE# #INDENT# freefmt = 'internal' #NEWLINE# nunit = current_unit #NEWLINE# fmtin = '(free)' #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# cr_dict = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# cr_dict [ 'type' ] = freefmt #NEWLINE# cr_dict [ 'cnstnt' ] = cnstnt #NEWLINE# cr_dict [ 'nunit' ] = nunit #NEWLINE# cr_dict [ 'iprn' ] = iprn #NEWLINE# cr_dict [ 'fmtin' ] = fmtin #NEWLINE# cr_dict [ 'fname' ] = cr_dict #NEWLINE# return cr_dict