From 40d180476f2f24effd28ba018c3d6b35c227bb2e Mon Sep 17 00:00:00 2001 From: mwaxmonsky <137746677+mwaxmonsky@users.noreply.github.com> Date: Tue, 23 Jul 2024 13:25:58 -0400 Subject: [PATCH] Integration of CCPP-ized TJ2016 implementation (#271) Updates atmospheric_physics to the latest tag bringing in TJ2016 capability and additional changes needed in support of TJ2016. URL: https://github.com/ESCOMP/CAM-SIMA/pull/271 Describe any changes made to build system: N/A Describe any changes made to the namelist: N/A List any changes to the defaults for the boundary datasets: N/A Describe any substantial timing or memory changes: N/A Code reviewed by: nusbaume, peverwhee List all existing files that have been modified, old files eliminated, new files added and describe the changes: M Externals_CAM.cfg - Updating to latest CCPP Framework needed for build. - Updating to latest atmospheric_physics needed to bring in TJ2016. M src/control/cam_comp.F90 - Removing CAM suite and dynamic_constituents to match new API. M src/data/physconst.meta - Updating two standard names. M src/data/registry.xml A src/dynamics/utils/hycoef.meta - Exposing sum_of_sigma_pressure_hybrid_coordinate_a_coefficient_and_sigma_pressure_hybrid_coordinate_b_coefficient (etamid) to physics schemes. M src/dynamics/utils/hycoef.F90 - Updating lev, ilev, hybi, hyai to be read in by their standard names and updating PIO checks appropriately. A tools/generate_input_to_stdnames_update.py - Adding new script to convert CSV file exported from standard names spreadsheet into the inputnames_dictionary.xml M tools/inputnames_to_stdnames.py - Updating script to be tphysac/tphysbc aware to avoid duplicate standard names in snapshots. M tools/stdnames_to_inputnames_dictionary.xml - Adding missing entry for standard_gravitational_acceleration. M cime_config/testdefs/testlist_cam.xml D cime_config/testdefs/testmods_dirs/cam/outfrq_held_suarez_izumi_nooutput/shell_commands D cime_config/testdefs/testmods_dirs/cam/outfrq_held_suarez_izumi_nooutput/user_nl_cam D cime_config/testdefs/testmods_dirs/cam/outfrq_kessler_izumi_nooutput/shell_commands D cime_config/testdefs/testmods_dirs/cam/outfrq_kessler_izumi_nooutput/user_nl_cam A cime_config/testdefs/testmods_dirs/cam/outfrq_tj2016_derecho_nooutput/shell_commands A cime_config/testdefs/testmods_dirs/cam/outfrq_tj2016_derecho_nooutput/user_nl_cam - Adding derecho build test for tj2016, updating existing tests to build using both compilers (gnu and intel) and removing izumi tests based on discussion from 7/15/24 to simplify test setup process. If there were any failures reported from running test_driver.sh on any test platform, and check in with these failures has been OK'd by the gatekeeper, then copy the lines from the td.*.status files for the failed tests to the appropriate machine below. All failed tests must be justified. derecho/intel/aux_cam derecho/gnu/aux_cam - All tests pass. Summarize any changes to answers, i.e., - what code configurations: N/A - what platforms/compilers: N/A - nature of change (roundoff; larger than roundoff but same climate; new climate): N/A --- .gitmodules | 8 +- ccpp_framework | 2 +- cime_config/testdefs/testlist_cam.xml | 42 +++--- .../shell_commands | 1 - .../user_nl_cam | 4 - .../shell_commands | 1 - .../outfrq_kessler_izumi_nooutput/user_nl_cam | 4 - .../shell_commands | 1 + .../user_nl_cam | 4 + src/control/cam_comp.F90 | 4 +- src/data/physconst.meta | 4 +- src/data/registry.xml | 1 + src/dynamics/utils/hycoef.F90 | 80 ++++++++++- src/dynamics/utils/hycoef.meta | 13 ++ src/physics/ncar_ccpp | 2 +- tools/generate_input_to_stdnames_update.py | 125 ++++++++++++++++++ tools/inputnames_to_stdnames.py | 15 ++- tools/stdnames_to_inputnames_dictionary.xml | 6 +- 18 files changed, 260 insertions(+), 57 deletions(-) delete mode 100644 cime_config/testdefs/testmods_dirs/cam/outfrq_held_suarez_izumi_nooutput/shell_commands delete mode 100644 cime_config/testdefs/testmods_dirs/cam/outfrq_held_suarez_izumi_nooutput/user_nl_cam delete mode 100644 cime_config/testdefs/testmods_dirs/cam/outfrq_kessler_izumi_nooutput/shell_commands delete mode 100644 cime_config/testdefs/testmods_dirs/cam/outfrq_kessler_izumi_nooutput/user_nl_cam create mode 100644 cime_config/testdefs/testmods_dirs/cam/outfrq_tj2016_derecho_nooutput/shell_commands create mode 100644 cime_config/testdefs/testmods_dirs/cam/outfrq_tj2016_derecho_nooutput/user_nl_cam create mode 100644 src/dynamics/utils/hycoef.meta create mode 100644 tools/generate_input_to_stdnames_update.py diff --git a/.gitmodules b/.gitmodules index 11bfbfdd..787b14c9 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,9 +1,9 @@ [submodule "ccpp-framework"] path = ccpp_framework - url = https://github.com/peverwhee/ccpp-framework - fxtag = CPF_0.2.056 + url = https://github.com/NCAR/ccpp-framework + fxtag = 2024-07-11-dev fxrequired = AlwaysRequired - fxDONOTUSEurl = https://github.com/peverwhee/ccpp-framework + fxDONOTUSEurl = https://github.com/NCAR/ccpp-framework [submodule "mpas"] path = src/dynamics/mpas/dycore url = https://github.com/MPAS-Dev/MPAS-Model.git @@ -14,7 +14,7 @@ [submodule "ncar-physics"] path = src/physics/ncar_ccpp url = https://github.com/ESCOMP/atmospheric_physics - fxtag = atmos_phys0_02_006 + fxtag = atmos_phys0_03_000 fxrequired = AlwaysRequired fxDONOTUSEurl = https://github.com/ESCOMP/atmospheric_physics [submodule "ccs_config"] diff --git a/ccpp_framework b/ccpp_framework index b1ffd3f0..0f823272 160000 --- a/ccpp_framework +++ b/ccpp_framework @@ -1 +1 @@ -Subproject commit b1ffd3f0f9c47227fbcd4a57e2175a76bc83f357 +Subproject commit 0f8232724975c13289cad390c9a71fa2c6a9bff4 diff --git a/cime_config/testdefs/testlist_cam.xml b/cime_config/testdefs/testlist_cam.xml index 168a151a..ff02f6d5 100644 --- a/cime_config/testdefs/testlist_cam.xml +++ b/cime_config/testdefs/testlist_cam.xml @@ -10,61 +10,53 @@ - - - - - - - - - + - - - + + - + - + + - + - + - - + + - + + - + - + - + + - + - - diff --git a/cime_config/testdefs/testmods_dirs/cam/outfrq_held_suarez_izumi_nooutput/shell_commands b/cime_config/testdefs/testmods_dirs/cam/outfrq_held_suarez_izumi_nooutput/shell_commands deleted file mode 100644 index 60c0b3c9..00000000 --- a/cime_config/testdefs/testmods_dirs/cam/outfrq_held_suarez_izumi_nooutput/shell_commands +++ /dev/null @@ -1 +0,0 @@ - ./xmlchange CAM_CONFIG_OPTS="--dyn none --physics-suites held_suarez_1994" diff --git a/cime_config/testdefs/testmods_dirs/cam/outfrq_held_suarez_izumi_nooutput/user_nl_cam b/cime_config/testdefs/testmods_dirs/cam/outfrq_held_suarez_izumi_nooutput/user_nl_cam deleted file mode 100644 index 2d470eb6..00000000 --- a/cime_config/testdefs/testmods_dirs/cam/outfrq_held_suarez_izumi_nooutput/user_nl_cam +++ /dev/null @@ -1,4 +0,0 @@ -ncdata=/project/amp02/cam_snapshot_files/held_suarez/cam_ne3pg3_held_suarez_snapshot_derecho_gnu_before.nc -ncdata_check=/project/amp02/cam_snapshot_files/held_suarez/cam_ne3pg3_held_suarez_snapshot_derecho_gnu_after.nc -debug_output=0 -pver=30 diff --git a/cime_config/testdefs/testmods_dirs/cam/outfrq_kessler_izumi_nooutput/shell_commands b/cime_config/testdefs/testmods_dirs/cam/outfrq_kessler_izumi_nooutput/shell_commands deleted file mode 100644 index fbf520ab..00000000 --- a/cime_config/testdefs/testmods_dirs/cam/outfrq_kessler_izumi_nooutput/shell_commands +++ /dev/null @@ -1 +0,0 @@ - ./xmlchange CAM_CONFIG_OPTS="--dyn none --physics-suites kessler" diff --git a/cime_config/testdefs/testmods_dirs/cam/outfrq_kessler_izumi_nooutput/user_nl_cam b/cime_config/testdefs/testmods_dirs/cam/outfrq_kessler_izumi_nooutput/user_nl_cam deleted file mode 100644 index 9582d6fb..00000000 --- a/cime_config/testdefs/testmods_dirs/cam/outfrq_kessler_izumi_nooutput/user_nl_cam +++ /dev/null @@ -1,4 +0,0 @@ -ncdata=/project/amp02/cam_snapshot_files/kessler/cam_ne3pg3_kessler_snapshot_derecho_gnu_before.nc -ncdata_check=/project/amp02/cam_snapshot_files/kessler/cam_ne3pg3_kessler_snapshot_derecho_gnu_after.nc -debug_output=0 -pver=30 diff --git a/cime_config/testdefs/testmods_dirs/cam/outfrq_tj2016_derecho_nooutput/shell_commands b/cime_config/testdefs/testmods_dirs/cam/outfrq_tj2016_derecho_nooutput/shell_commands new file mode 100644 index 00000000..1ff03d8f --- /dev/null +++ b/cime_config/testdefs/testmods_dirs/cam/outfrq_tj2016_derecho_nooutput/shell_commands @@ -0,0 +1 @@ + ./xmlchange CAM_CONFIG_OPTS="--dyn none --physics-suites tj2016" diff --git a/cime_config/testdefs/testmods_dirs/cam/outfrq_tj2016_derecho_nooutput/user_nl_cam b/cime_config/testdefs/testmods_dirs/cam/outfrq_tj2016_derecho_nooutput/user_nl_cam new file mode 100644 index 00000000..28c39fd6 --- /dev/null +++ b/cime_config/testdefs/testmods_dirs/cam/outfrq_tj2016_derecho_nooutput/user_nl_cam @@ -0,0 +1,4 @@ +ncdata=/glade/campaign/cesm/community/amwg/sima_baselines/cam_sima_test_snapshots/cam_tj2016_precip_tend_ne3pg3mg37_derecho_gnu_before.nc +ncdata_check=/glade/campaign/cesm/community/amwg/sima_baselines/cam_sima_test_snapshots/cam_tj2016_precip_tend_ne3pg3mg37_derecho_gnu_after.nc +debug_output=0 +pver=30 diff --git a/src/control/cam_comp.F90 b/src/control/cam_comp.F90 index ff835883..db0e943e 100644 --- a/src/control/cam_comp.F90 +++ b/src/control/cam_comp.F90 @@ -612,8 +612,8 @@ subroutine cam_register_constituents(cam_runtime_opts) !Combine host and physics constituents into a single !constituents object: - call cam_ccpp_register_constituents(cam_runtime_opts%suite_as_list(), & - host_constituents, dynamic_constituents, errcode=errflg, errmsg=errmsg) + call cam_ccpp_register_constituents( & + host_constituents, errcode=errflg, errmsg=errmsg) if (errflg /= 0) then call endrun(subname//trim(errmsg), file=__FILE__, line=__LINE__) diff --git a/src/data/physconst.meta b/src/data/physconst.meta index 127dbe35..313033aa 100644 --- a/src/data/physconst.meta +++ b/src/data/physconst.meta @@ -201,7 +201,7 @@ dimensions = () protected = True [ gravit ] - standard_name = gravitational_acceleration + standard_name = standard_gravitational_acceleration units = m s-2 type = real | kind = kind_phys dimensions = () @@ -268,7 +268,7 @@ dimensions = () protected = True [ epsilo ] - standard_name = ratio_of_h2o_to_dry_air_molecular_weights + standard_name = ratio_of_water_vapor_to_dry_air_molecular_weights units = 1 type = real | kind = kind_phys dimensions = () diff --git a/src/data/registry.xml b/src/data/registry.xml index 3d8b5bc0..57a9ae3b 100644 --- a/src/data/registry.xml +++ b/src/data/registry.xml @@ -14,6 +14,7 @@ $SRCROOT/src/data/cam_thermo.meta $SRCROOT/src/data/ref_pres.meta $SRCROOT/src/dynamics/utils/vert_coord.meta + $SRCROOT/src/dynamics/utils/hycoef.meta diff --git a/src/dynamics/utils/hycoef.F90 b/src/dynamics/utils/hycoef.F90 index 02c983dc..59777ef2 100644 --- a/src/dynamics/utils/hycoef.F90 +++ b/src/dynamics/utils/hycoef.F90 @@ -1,6 +1,7 @@ module hycoef use shr_kind_mod, only: r8 => shr_kind_r8 +use ccpp_kinds, only: kind_phys use spmd_utils, only: masterproc use vert_coord, only: pver, pverp use cam_logfile, only: iulog @@ -28,8 +29,6 @@ module hycoef real(r8), public, allocatable, target :: hybi(:) ! ps component of hybrid coordinate - interfaces real(r8), public, allocatable, target :: hybm(:) ! ps component of hybrid coordinate - midpoints -real(r8), public, allocatable :: etamid(:) ! hybrid coordinate - midpoints - real(r8), public, allocatable :: hybd(:) ! difference in b (hybi) across layers real(r8), public, allocatable :: hypi(:) ! reference pressures at interfaces real(r8), public, allocatable :: hypm(:) ! reference pressures at midpoints @@ -47,6 +46,10 @@ module hycoef type(var_desc_t) :: hyam_desc, hyai_desc, hybm_desc, hybi_desc, p0_desc public init_restart_hycoef, write_restart_hycoef +!> \section arg_table_hycoef Argument Table +!! \htmlinclude hycoef.html +real(kind_phys), allocatable, public :: etamid(:) ! hybrid coordinate - midpoints + !======================================================================= contains !======================================================================= @@ -56,6 +59,7 @@ subroutine hycoef_init(file, psdry) ! use cam_history_support, only: add_hist_coord, add_vert_coord, formula_terms_t use physconst, only: pref use string_utils, only: to_str + use phys_vars_init_check, only: mark_as_initialized !----------------------------------------------------------------------- ! @@ -326,6 +330,11 @@ subroutine hycoef_init(file, psdry) write(iulog,9830) pverp, hypi(pverp) end if + ! Mark etamid (input name) as initialized (by standard name sum_of_sigma_...) + call mark_as_initialized( & + 'sum_of_sigma_pressure_hybrid_coordinate_a_coefficient_and_sigma_pressure_hybrid_coordinate_b_coefficient') + + 9800 format( 1x, i3, 3p, 3(f10.4,10x) ) 9810 format( 1x, 3x, 3p, 3(10x,f10.4) ) 9820 format(1x,'reference pressures (Pa)') @@ -394,42 +403,101 @@ subroutine hycoef_read(File) character(len=*), parameter :: routine = 'hycoef_read' !---------------------------------------------------------------------------- + ! Set PIO to return error codes. + call pio_seterrorhandling(file, PIO_BCAST_ERROR, pio_errtype) + ! PIO traps errors internally, no need to check ierr ierr = PIO_Inq_DimID(File, 'lev', lev_dimid) + if (ierr /= PIO_NOERR) then + ierr = PIO_Inq_DimID(File, 'reference_pressure_in_atmosphere_layer', lev_dimid) + if (ierr /= PIO_NOERR) then + call endrun(routine//': ERROR: unable to find lev dimension in ncdata or restart file.') + end if + end if ierr = PIO_Inq_dimlen(File, lev_dimid, flev) + if (ierr /= PIO_NOERR) then + call endrun(routine//': ERROR: Failed to inquire dimension length of flev in ncdata or restart file.') + end if if (pver /= flev) then write(iulog,*) routine//': ERROR: file lev does not match model. lev (file, model):',flev, pver call endrun(routine//': ERROR: file lev does not match model.') end if ierr = PIO_Inq_DimID(File, 'ilev', lev_dimid) + if (ierr /= PIO_NOERR) then + ierr = PIO_Inq_DimID(File, 'reference_pressure_in_atmosphere_layer_at_interfaces', lev_dimid) + if (ierr /= PIO_NOERR) then + call endrun(routine//': ERROR: unable to find ilev dimension in ncdata or restart file') + end if + end if ierr = PIO_Inq_dimlen(File, lev_dimid, filev) + if (ierr /= PIO_NOERR) then + call endrun(routine//': ERROR: Failed to inquire dimension length of filev in ncdata or restart file.') + end if if (pverp /= filev) then write(iulog,*) routine//':ERROR: file ilev does not match model ilev (file, model):',filev, pverp call endrun(routine//':ERROR: file ilev does not match model.') end if ierr = pio_inq_varid(File, 'hyai', hyai_desc) + if (ierr /= PIO_NOERR) then + ierr = pio_inq_varid(File, 'sigma_pressure_hybrid_coordinate_a_coefficient_at_interfaces', hyai_desc) + if (ierr /= PIO_NOERR) then + call endrun(routine//': ERROR: unable to find hyai variable in ncdata or restart file') + end if + end if + ierr = pio_inq_varid(File, 'hyam', hyam_desc) + if (ierr /= PIO_NOERR) then + ierr = pio_inq_varid(File, 'sigma_pressure_hybrid_coordinate_a_coefficient', hyam_desc) + if (ierr /= PIO_NOERR) then + call endrun(routine//': ERROR: unable to find hyam variable in ncdata or restart file') + end if + end if + ierr = pio_inq_varid(File, 'hybi', hybi_desc) + if (ierr /= PIO_NOERR) then + ierr = pio_inq_varid(File, 'sigma_pressure_hybrid_coordinate_b_coefficient_at_interfaces', hybi_desc) + if (ierr /= PIO_NOERR) then + call endrun(routine//': ERROR: unable to find hybi variable in ncdata or restart file') + end if + end if + ierr = pio_inq_varid(File, 'hybm', hybm_desc) + if (ierr /= PIO_NOERR) then + ierr = pio_inq_varid(File, 'sigma_pressure_hybrid_coordinate_b_coefficient', hybm_desc) + if (ierr /= PIO_NOERR) then + call endrun(routine//': ERROR: unable to find hybm variable in ncdata or restart file') + end if + end if ierr = pio_get_var(File, hyai_desc, hyai) + if (ierr /= PIO_NOERR) then + call endrun(routine//': ERROR: Unable to get hyai variable in ncdata or restart file.') + end if ierr = pio_get_var(File, hybi_desc, hybi) + if (ierr /= PIO_NOERR) then + call endrun(routine//': ERROR: Unable to get hybi variable in ncdata or restart file.') + end if ierr = pio_get_var(File, hyam_desc, hyam) + if (ierr /= PIO_NOERR) then + call endrun(routine//': ERROR: Unable to get hyam variable in ncdata or restart file.') + end if ierr = pio_get_var(File, hybm_desc, hybm) + if (ierr /= PIO_NOERR) then + call endrun(routine//': ERROR: Unable to get hybm variable in ncdata or restart file.') + end if if (masterproc) then write(iulog,*) routine//': read hyai, hybi, hyam, hybm' end if ! Check whether file contains value for P0. If it does then use it - - ! Set PIO to return error codes. - call pio_seterrorhandling(file, PIO_BCAST_ERROR, pio_errtype) - ierr = pio_inq_varid(file, 'P0', p0_desc) + if (ierr /= PIO_NOERR) then + ierr = pio_inq_varid(File, 'surface_reference_pressure', p0_desc) + end if if (ierr == PIO_NOERR) then ierr = pio_get_var(file, p0_desc, ps0) if (ierr /= PIO_NOERR) then diff --git a/src/dynamics/utils/hycoef.meta b/src/dynamics/utils/hycoef.meta new file mode 100644 index 00000000..ef3121fa --- /dev/null +++ b/src/dynamics/utils/hycoef.meta @@ -0,0 +1,13 @@ +[ccpp-table-properties] + name = hycoef + type = module +[ccpp-arg-table] + name = hycoef + type = module + +[ etamid ] + standard_name = sum_of_sigma_pressure_hybrid_coordinate_a_coefficient_and_sigma_pressure_hybrid_coordinate_b_coefficient + type = real | kind = kind_phys + units = 1 + dimensions = (vertical_layer_dimension) + diff --git a/src/physics/ncar_ccpp b/src/physics/ncar_ccpp index 4944547f..f4c09618 160000 --- a/src/physics/ncar_ccpp +++ b/src/physics/ncar_ccpp @@ -1 +1 @@ -Subproject commit 4944547f04b1457d78bf7d3c0becddcfe0deabb9 +Subproject commit f4c09618eaaa19eaf3382f0473a531e20aa9f808 diff --git a/tools/generate_input_to_stdnames_update.py b/tools/generate_input_to_stdnames_update.py new file mode 100644 index 00000000..12967d42 --- /dev/null +++ b/tools/generate_input_to_stdnames_update.py @@ -0,0 +1,125 @@ +""" + +""" + +import argparse +import csv +import re +from collections import defaultdict +from bs4 import BeautifulSoup + + +def parse_csv(csv_filepath): + """Returns a dictionary of standard names (keys) to input names from snapshots (set value) + + The current spreadsheet currently uses column 0 as the input name and column 6 as the standard name. + Currently only using 432 lines in the spread sheet that need standard names. + + Ex: + + .. code-block:: + + A1,...,...,...,...,A6,... + B1,...,...,...,...,A6,... + C1,...,...,...,...,C5,... + + -> + + { A6: (A1, B1), C5: (C1) + + """ + datamap = defaultdict(set) + pattern = re.compile(r"\w+") + print(f"Opening {csv_filepath}") + with open(csv_filepath, encoding='ascii') as csvfile: + csvdata = csv.reader(csvfile) + for row in csvdata: + inputname = row[0].split(" ")[0] + standardname_match = pattern.fullmatch(row[5].split(" ")[0]) + if csvdata.line_num < 432 and standardname_match and inputname and "Skipping" not in row[5] and "CCPP" not in row[5]: + print(f"Adding {inputname} under {standardname_match.string}") + datamap[standardname_match.string].add(inputname) + return datamap + + + +def generate_stdname_xml(current_dict, output_filename): + """ + Generates an xml file to be used by a converter script that converts + input names in a snapshot file to standard names. + + For example, + + .. code-block:: + + { A6: (A1, B1), C5: (C1) + + would be converted to: + + .. code-block:: XML + + + + + A1 + B1 + + + + C1 + + + + """ + xmltree = BeautifulSoup(features="xml") + + entries = xmltree.new_tag("entries") + for k, v in current_dict.items(): + entry = xmltree.new_tag("entry") + entry["stdname"] = k + names = xmltree.new_tag("ic_file_input_names") + for name in v: + namenode = xmltree.new_tag("ic_file_input_name") + namenode.string = name + names.append(namenode) + entry.append(names) + entries.append(entry) + xmltree.append(entries) + with open(output_filename, "w", encoding='ascii') as xmlout: + print(f"Creating new xml file : {output_filename}") + xmlout.write(xmltree.prettify()) + + +def main(): + """ + Parses a CSV file with a column ordering of + + .. code-block:: + + ,...,...,...,...,,... + + and generates a corresponding xml file of the format + + .. code-block:: XML + + + + input_name + ... + + ... + + + """ + parser = argparse.ArgumentParser(description='') + parser.add_argument('--csv-file', type=str, default='CCPP Standard Names - Sheet1.csv', help='') + parser.add_argument('--output-map', type=str, default='stdnames_to_inputnames_dictionary_new.xml', help='') + + args = parser.parse_args() + + current_csv_entries = parse_csv(args.csv_file) + generate_stdname_xml(current_csv_entries, args.output_map) + + +if __name__=="__main__": + main() diff --git a/tools/inputnames_to_stdnames.py b/tools/inputnames_to_stdnames.py index bb7a061d..a78b0f48 100644 --- a/tools/inputnames_to_stdnames.py +++ b/tools/inputnames_to_stdnames.py @@ -18,7 +18,7 @@ def write_new_ncdata_file(input_filename, output_filename, inputname_dict): base_cmd += f' {input_filename}' os.system(base_cmd) -def parse_stdname_file(file_to_parse): +def parse_stdname_file(file_to_parse, tphys_exclude): """Parse XML standard name dictionary""" with open(file_to_parse, encoding='utf-8') as fh1: try: @@ -35,7 +35,9 @@ def parse_stdname_file(file_to_parse): for sub_element in entry: if sub_element.tag == "ic_file_input_names": for input_name in sub_element: - inputname_dict[input_name.text.strip()] = stdname + if not input_name.text.startswith(tphys_exclude): + inputname_dict[input_name.text.strip()] = stdname + # end if startswith # end for input_name # end if sub_element.tag # end if for sub_element in entry @@ -43,7 +45,7 @@ def parse_stdname_file(file_to_parse): return inputname_dict -def main(input_file, output_filename, stdname_file): +def main(input_file, output_filename, stdname_file, tphys_exclude): """Parse standard name dictionary and then replace input name variables with stdnames""" if not os.path.isfile(input_file): print(f"Input file {input_file} does not exist") @@ -74,7 +76,7 @@ def main(input_file, output_filename, stdname_file): #end if os.path.isdir(output_dir) #end if len(output_dir.strip())) == 0 # Parse the standard name dictionary - inputname_dict = parse_stdname_file(stdname_file) + inputname_dict = parse_stdname_file(stdname_file, tphys_exclude) if not inputname_dict: print(f"Standard name dictionary {stdname_file} empty or not parse-able") return 6 @@ -97,9 +99,12 @@ def parse_command_line(arguments, description): parser.add_argument("--stdnames", type=str, required=True, metavar='stdname file', help="Full path to the standard names dictionary (e.g. stdnames_to_inputnames_dictionary.xml)") + parser.add_argument('--tphys-exclude', type=str, required=True, + metavar='tphysac or tphysbc group - REQUIRED', + help='Group to exclude when converting variable names to stdandard names') pargs = parser.parse_args(arguments) return pargs if __name__ == "__main__": ARGS = parse_command_line(sys.argv[1:], __doc__) - sys.exit(main(ARGS.input, ARGS.output, ARGS.stdnames)) + sys.exit(main(ARGS.input, ARGS.output, ARGS.stdnames, ARGS.tphys_exclude)) diff --git a/tools/stdnames_to_inputnames_dictionary.xml b/tools/stdnames_to_inputnames_dictionary.xml index 0487f049..7e2c92ce 100644 --- a/tools/stdnames_to_inputnames_dictionary.xml +++ b/tools/stdnames_to_inputnames_dictionary.xml @@ -288,5 +288,9 @@ n2ovmr - + + + gravit + +