# End if if (statements is not None) and (len(statements) == 0): statements = read_statements(pobj) # End if # End while return mheaders ######################################################################## if __name__ == "__main__": import doctest doctest.testmod() from parse_tools import register_fortran_ddt_name fpath = '/Users/goldy/scratch/foo' fnames = [ 'GFS_PBL_generic.F90', 'GFS_rad_time_vary.fv3.F90', 'GFS_typedefs.F90' ] register_fortran_ddt_name('GFS_control_type') register_fortran_ddt_name('GFS_data_type') for fname in fnames: fpathname = os.path.join(fpath, fname) if os.path.exists(fpathname): mh = parse_fortran_file(fpathname, preproc_defs={'CCPP': 1}) for h in mh: print('{}: {}'.format(fname, h)) # End for # End if # End for # End if
def __init_from_file__(self, parse_object, property_table, logger): # Read the table preamble, assume the caller already figured out # the first line of the header using the table_start method. curr_line, curr_line_num = self._pobj.next_line() self._table_title = None self._header_type = None self._module_name = None self._dependencies = [] relative_path_local = '' self._property_table = property_table while (curr_line is not None) and (not self.variable_start(curr_line)) and ( not MetadataHeader.table_start(curr_line)): for property in self.parse_config_line(curr_line): # Manually parse name, type, and module properties key = property[0].strip().lower() value = property[1].strip() if key == 'name': self._table_title = value elif key == 'type': if value not in ['module', 'scheme', 'ddt']: raise ParseSyntaxError("metadata table type", token=value, context=self._pobj) # End if self._header_type = value elif key == 'module': if value == "None": raise ParseSyntaxError("metadata table, no module", context=self._pobj) else: self._module_name = value # End if elif key == 'dependencies': if not (value == "None" or value == ""): # Remove trailing comma, remove white spaces from each list element self._dependencies += [ v.strip() for v in value.rstrip(",").split(",") ] elif key == 'relative_path': relative_path_local = value.strip() else: raise ParseSyntaxError("metadata table start property", token=value, context=self._pobj) # End if # End for curr_line, curr_line_num = self._pobj.next_line() # End while if self.title is None: raise ParseSyntaxError("metadata header start, no table name", token=curr_line, context=self._pobj) elif self.header_type is None: raise ParseSyntaxError("metadata header start, no table type", token=curr_line, context=self._pobj) elif self.header_type == "ddt": register_fortran_ddt_name(self.title) # End if # Add relative path to dependencies if self.dependencies and relative_path_local: self._dependencies = [ os.path.join(relative_path_local, v) for v in self.dependencies ] # Initialize our ParseSource parent super(MetadataHeader, self).__init__(self.title, self.header_type, self._pobj) # Read the variables valid_lines = True self._variables = VarDictionary(self.title, logger=logger) while valid_lines: newvar, curr_line = self.parse_variable(curr_line) valid_lines = newvar is not None if valid_lines: self._variables.add_variable(newvar) # Check to see if we hit the end of the table valid_lines = not MetadataHeader.table_start(curr_line)
def __init_from_file__(self, parse_object, logger): # Read the table preamble, assume the caller already figured out # the first line of the header using the table_start method. curr_line, curr_line_num = self._pobj.next_line() self._table_title = None self._header_type = None self._module_name = None while (curr_line is not None) and (not self.variable_start(curr_line)) and ( not MetadataHeader.table_start(curr_line)): for property in self.parse_config_line(curr_line): # Manually parse name, type, and module properties key = property[0].strip().lower() value = property[1].strip() if key == 'name': self._table_title = value elif key == 'type': if value not in ['module', 'scheme', 'ddt']: raise ParseSyntaxError("metadata table type", token=value, context=self._pobj) # End if self._header_type = value elif key == 'module': if value == "None": raise ParseSyntaxError("metadata table, no module", context=self._pobj) else: self._module_name = value # End if else: raise ParseSyntaxError("metadata table start property", token=value, context=self._pobj) # End if # End for curr_line, curr_line_num = self._pobj.next_line() # End while if self.title is None: raise ParseSyntaxError("metadata header start, no table name", token=curr_line, context=self._pobj) elif self.header_type is None: raise ParseSyntaxError("metadata header start, no table type", token=curr_line, context=self._pobj) elif self.header_type == "ddt": register_fortran_ddt_name(self.title) # End if # Initialize our ParseSource parent super(MetadataHeader, self).__init__(self.title, self.header_type, self._pobj) # Read the variables valid_lines = True self._variables = VarDictionary(self.title, logger=logger) while valid_lines: newvar, curr_line = self.parse_variable(curr_line) valid_lines = newvar is not None if valid_lines: self._variables.add_variable(newvar) # Check to see if we hit the end of the table valid_lines = not MetadataHeader.table_start(curr_line)
pdir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) pdir = os.path.join(pdir, 'tests', 'cap_tests') if not os.path.exists(pdir): pdir = os.getcwd() # End if # End if if len(sys.argv) > 1: sdir = sys.argv[1] else: sdir = os.path.join(os.path.dirname(pdir), 'ccpp-physics') # End if print("Converting physics files from {} with output to {}".format( sdir, pdir)) # XXgoldyXX: v debug only # Temporary DDT registration register_fortran_ddt_name('GFS_control_type') register_fortran_ddt_name('GFS_statein_type') register_fortran_ddt_name('GFS_stateout_type') register_fortran_ddt_name('GFS_sfcprop_type') register_fortran_ddt_name('GFS_coupling_type') register_fortran_ddt_name('GFS_grid_type') register_fortran_ddt_name('GFS_tbd_type') register_fortran_ddt_name('GFS_cldprop_type') register_fortran_ddt_name('GFS_radtend_type') register_fortran_ddt_name('GFS_diag_type') register_fortran_ddt_name('GFS_interstitial_type') register_fortran_ddt_name('GFS_data_type') register_fortran_ddt_name('cmpfsw_type') register_fortran_ddt_name('topflw_type') register_fortran_ddt_name('sfcflw_type') register_fortran_ddt_name('proflw_type')