def collect_physics_subroutines(scheme_files): """Scan all Fortran source files in scheme_files for subroutines with argument tables.""" logging.info('Parsing metadata tables in physics scheme files ...') success = True # Parse all scheme files metadata_request = {} arguments_request = {} pset_request = {} pset_schemes = {} for scheme_file in scheme_files.keys(): (scheme_filepath, scheme_filename) = os.path.split(os.path.abspath(scheme_file)) # Change to directory where scheme_file lives os.chdir(scheme_filepath) (metadata, arguments) = parse_scheme_tables(scheme_filename) # The different psets for the variables used by schemes in scheme_file pset = { var_name: scheme_files[scheme_file] for var_name in metadata.keys() } # The different psets for the schemes in scheme_file for scheme_name in arguments.keys(): pset_schemes[scheme_name] = scheme_files[scheme_file] # Merge metadata and pset, append to arguments metadata_request = merge_dictionaries(metadata_request, metadata) pset_request = merge_dictionaries(pset_request, pset) arguments_request.update(arguments) os.chdir(BASEDIR) # Return to BASEDIR os.chdir(BASEDIR) return (success, metadata_request, pset_request, arguments_request, pset_schemes)
def collect_physics_subroutines(scheme_files): """Scan all Fortran source files in scheme_files for subroutines with argument tables.""" logging.info('Parsing metadata tables in physics scheme files ...') success = True # Parse all scheme files: record metadata, argument list, dependencies, and which scheme is in which file metadata_request = collections.OrderedDict() arguments_request = collections.OrderedDict() dependencies_request = collections.OrderedDict() schemes_in_files = collections.OrderedDict() for scheme_file in scheme_files: scheme_file_with_abs_path = os.path.abspath(scheme_file) (scheme_filepath, scheme_filename) = os.path.split(scheme_file_with_abs_path) # Change to directory where scheme_file lives os.chdir(scheme_filepath) (metadata, arguments, dependencies) = parse_scheme_tables(scheme_filepath, scheme_filename) # Record which scheme is in which file for scheme in arguments.keys(): schemes_in_files[scheme] = scheme_file_with_abs_path # Merge metadata, append to arguments and dependencies metadata_request = merge_dictionaries(metadata_request, metadata) arguments_request.update(arguments) dependencies_request.update(dependencies) os.chdir(BASEDIR) # Return to BASEDIR os.chdir(BASEDIR) return (success, metadata_request, arguments_request, dependencies_request, schemes_in_files)
def gather_variable_definitions(variable_definition_files, typedefs_new_metadata): """Scan all Fortran source files with variable definitions on the host model side. If typedefs_new_metadata is not None, search all metadata entries and convert new metadata (local names) into old metadata by prepending the DDT references.""" # logging.info( 'Parsing metadata tables for variables provided by host model ...') success = True metadata_define = collections.OrderedDict() dependencies_define = collections.OrderedDict() for variable_definition_file in variable_definition_files: (filedir, filename) = os.path.split(os.path.abspath(variable_definition_file)) # Change to directory of variable_definition_file and parse it os.chdir(os.path.join(BASEDIR, filedir)) (metadata, dependencies) = parse_variable_tables(filedir, filename) metadata_define = merge_dictionaries(metadata_define, metadata) dependencies_define.update(dependencies) # Return to BASEDIR os.chdir(BASEDIR) # if typedefs_new_metadata: logging.info( 'Convert local names from new metadata format into old metadata format ...' ) # Keep track of which variables have already been converted converted_variables = [] for key in metadata_define.keys(): # Double-check that variable definitions are unique if len(metadata_define[key]) > 1: logging.error( "Multiple definitions of standard_name {0} in type/variable defintions" .format(key)) success = False return (success, local_name, converted_variables) = convert_local_name_from_new_metadata( metadata_define, key, typedefs_new_metadata, converted_variables) if not success: logging.error( "An error occurred during the conversion of variable {0} from new to old metadata format" .format(key)) return (success, metadata_define) # Update the local name of the variable, if necessary if not metadata_define[key][0].local_name == local_name: logging.debug( "Updating local name of variable {0} from {1} to {2}". format(key, metadata_define[key][0].local_name, local_name)) metadata_define[key][0].local_name = local_name # return (success, metadata_define, dependencies_define)
def gather_variable_definitions(variable_definition_files): """Scan all Fortran source files with variable definitions on the host model side.""" logging.info('Parsing metadata tables for variables provided by host model ...') success = True metadata_define = {} for variable_definition_file in variable_definition_files: (filedir, filename) = os.path.split(variable_definition_file) # Change to directory of variable_definition_file and parse it os.chdir(os.path.join(BASEDIR,filedir)) metadata = parse_variable_tables(filename) metadata_define = merge_dictionaries(metadata_define, metadata) # Return to BASEDIR os.chdir(BASEDIR) return (success, metadata_define)