Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove legacy src/ccpp_api.F90 - contains #445 (fix metadata2html.py) and #447 (remove NEMSfv3gfs test scripts) #443

Merged
merged 6 commits into from
Apr 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 19 additions & 10 deletions scripts/metadata2html.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@

# CCPP framework imports
from common import CCPP_INTERNAL_VARIABLE_DEFINITON_FILE
from parse_checkers import registered_fortran_ddt_names
from parse_tools import init_log, set_log_level
from metadata_table import MetadataHeader
from metadata_table import MetadataTable, parse_metadata_file
from framework_env import CCPPFrameworkEnv

###############################################################################
# Set up the command line argument parser and other global variables #
Expand All @@ -27,7 +29,7 @@

# List and order of variable attributes to output to HTML
ATTRIBUTES = [ 'local_name', 'standard_name', 'long_name', 'units',
'type', 'dimensions', 'kind', 'intent', 'optional' ]
'type', 'dimensions', 'kind', 'intent' ]

###############################################################################
# Functions and subroutines #
Expand Down Expand Up @@ -56,7 +58,7 @@ def import_config(configfile, logger):

# Get the base directory for running metadata2html.py from
# the default build directory value in the CCPP prebuild config
basedir = os.path.join(os.getcwd(), ccpp_prebuild_config.DEFAULT_BUILD_DIR)
basedir = os.path.join(os.getcwd())
logger.info('Relative path to CCPP directory from CCPP prebuild config: {}'.format(
ccpp_prebuild_config.DEFAULT_BUILD_DIR))

Expand Down Expand Up @@ -92,31 +94,38 @@ def get_output_directory_from_config(config, logger):
raise Exception("Output directory {} for converted metadata tables does not exist".format(outdir))
return outdir

def convert_to_html(filename_in, outdir, logger):
def convert_to_html(filename_in, outdir, logger, run_env):
"""Convert a metadata file into html (one html file for each table)"""
if not os.path.isfile(filename_in):
raise Exception("Metadata file {} not found".format(filename_in))
logger.info("Converting file {} to HTML".format(filename_in))
metadata_headers = MetadataHeader.parse_metadata_file(filename_in)
metadata_headers = parse_metadata_file(filename_in,
known_ddts=registered_fortran_ddt_names(),
run_env=run_env)
for metadata_header in metadata_headers:
filename_out = metadata_header.to_html(outdir, ATTRIBUTES)
if filename_out:
logger.info(" ... wrote {}".format(filename_out))
for metadata_section in metadata_header.sections():
filename_out = metadata_section.to_html(outdir, ATTRIBUTES)
if filename_out:
logger.info(" ... wrote {}".format(filename_out))

def main():
# Initialize logging
logger = init_log('metadata2html')
set_log_level(logger, logging.INFO)
run_env = CCPPFrameworkEnv(logger, ndict={'host_files':'',
'scheme_files':'',
'suites':''})

# Convert metadata file
(configfile, filename, outdir) = parse_arguments()
if configfile:
config = import_config(configfile, logger)
filenames = get_metadata_files_from_config(config, logger)
outdir = get_output_directory_from_config(config, logger)
for filename in filenames:
convert_to_html(filename, outdir, logger)
convert_to_html(filename, outdir, logger, run_env)
else:
convert_to_html(filename, outdir, logger)
convert_to_html(filename, outdir, logger, run_env)

if __name__ == '__main__':
main()
43 changes: 43 additions & 0 deletions scripts/metadata_table.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,19 @@ class MetadataSection(ParseSource):

__vref_start = re.compile(r"^\[\s*"+FORTRAN_SCALAR_REF+r"\s*\]$")

__html_template__ = """
<html>
<head>
<title>{title}</title>
<meta charset="UTF-8">
</head>
<body>
<table border="1">
{header}{contents}</table>
</body>
</html>
"""

def __init__(self, table_name, table_type, run_env, parse_object=None,
title=None, type_in=None, module=None, process_type=None,
var_dict=None, known_ddts=None):
Expand Down Expand Up @@ -1183,6 +1196,36 @@ def write_to_file(self, filename, append=False):
# end for
# end with

def to_html(self, outdir, props):
"""Write html file for metadata section and return filename.
Skip metadata sections without variables"""
if not self.__variables.variable_list():
return None
# Write table header
header = f"<tr>"
for prop in props:
header += f"<th>{prop}</th>".format(prop=prop)
header += f"</tr>\n"
# Write table contents, one row per variable
contents = ""
for var in self.__variables.variable_list():
row = f"<tr>"
for prop in props:
value = var.get_prop_value(prop)
# Pretty-print for dimensions
if prop == 'dimensions':
value = '(' + ', '.join(value) + ')'
elif value is None:
value = f"n/a"
row += f"<td>{value}</td>".format(value=value)
row += f"</tr>\n"
contents += row
filename = os.path.join(outdir, self.title + '.html')
with open(filename,"w") as f:
f.writelines(self.__html_template__.format(title=self.title + ' argument table',
header=header, contents=contents))
return filename

def __repr__(self):
base = super().__repr__()
pind = base.find(' object ')
Expand Down
1 change: 0 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# Set the sources
set(SOURCES_F90
ccpp_types.F90
ccpp_api.F90
)

# Generate list of Fortran modules from defined sources
Expand Down
27 changes: 0 additions & 27 deletions src/ccpp_api.F90

This file was deleted.

230 changes: 0 additions & 230 deletions test/nemsfv3gfs/regression_test_nemsfv3gfs.py

This file was deleted.

Loading