CIME.nmlgen.NamelistGenerator
- class CIME.nmlgen.NamelistGenerator(case, definition_files, files=None)[source]
Bases:
object
Utility class for generating namelists for a given component.
Methods
__init__
Construct a namelist generator.
Add a value for the specified variable to the namelist.
Call add_default for namelist variables in the given group
Write only contents of nml group
clean_streams
Confirms that no values have been added to the given group
Set defaults for shr_strdata_nml variables other than the variable domainfile
Write the pseudo-XML file corresponding to a given stream.
Get the value of a variable from the namelist definition file.
get_group_variables
Get a list of all streams used for the current data model mode.
Get the current value of a given namelist variable.
Return array of names of all definition nodes
Clean the object just enough to introduce a new instance
Convert a string to a quoted Fortran literal.
Pass through to namelist definition
If file_path is relative, make it absolute using DIN_LOC_ROOT.
Set the current value of a given namelist variable.
Updates values for the shr_strdata_nml namelist group.
Write mct component modelio files
Write the nuopc config file
Write nuopc component modelio files
Write out the namelists and input data files.
Write mct out seq_maps.rc
- add_default(name, value=None, ignore_abs_path=None)[source]
Add a value for the specified variable to the namelist.
If the specified variable is already defined in the object, the existing value is preserved. Otherwise, the value argument, if provided, will be used to set the value. If no such value is found, the defaults file will be consulted. If null values are present in any of the above, the result will be a merged array of values.
If no value for the variable is found via any of the above, this method will raise an exception.
- add_defaults_for_group(group)[source]
Call add_default for namelist variables in the given group
This still skips variables that have attributes of skip_default_entry or per_stream_entry.
This must be called after init_defaults. It is often paired with use of skip_default_for_groups in the init_defaults call.
- add_nmlcontents(filename, group, append=True, format_='nmlcontents', sorted_groups=True)[source]
Write only contents of nml group
- confirm_group_is_empty(group_name, errmsg)[source]
Confirms that no values have been added to the given group
If any values HAVE been added to this group, aborts with the given error message.
This is often paired with use of skip_default_for_groups in the init_defaults call and add_defaults_for_group, as in:
- if nmlgen.get_value(“enable_frac_overrides”) == “.true.”:
nmlgen.add_defaults_for_group(“glc_override_nml”)
- else:
nmlgen.confirm_empty(“glc_override_nml”, “some message”)
Args: group_name: string - name of namelist group errmsg: string - error message to print if group is not empty
- create_shr_strdata_nml()[source]
Set defaults for shr_strdata_nml variables other than the variable domainfile
- create_stream_file_and_update_shr_strdata_nml(config, caseroot, stream, stream_path, data_list_path)[source]
Write the pseudo-XML file corresponding to a given stream.
Arguments: config - Used to look up namelist defaults. This is used in addition
to the config used to construct the namelist generator. The main reason to supply additional configuration options here is to specify stream-specific settings.
stream - Name of the stream. stream_path - Path to write the stream file to. data_list_path - Path of file to append input data information to.
- get_default(name, config=None, allow_none=False)[source]
Get the value of a variable from the namelist definition file.
The config argument is passed through to the underlying NamelistDefaults.get_value call as the attribute argument.
The return value of this function is a list of values that were found in the defaults file. If there is no matching default, this function returns None if allow_none=True is passed, otherwise an error is raised.
Note that we perform some translation of the values, since there are a few differences between Fortran namelist literals and values in the defaults file: 1) In the defaults file, whitespace is ignored except within strings, so
the output of this function strips out most whitespace. (This implies that commas are the only way to separate array elements in the defaults file.)
In the defaults file, quotes around character literals (strings) are optional, as long as the literal does not contain whitespace, commas, or (single or double) quotes. If a setting for a character variable does not seem to have quotes (and is not a null value), this function will add them.
Default values may refer to variables in a case’s env_*.xml files. This function replaces references of the form $VAR or ${VAR} with the value of the variable VAR in an env file, if that variable exists. This behavior is suppressed within single-quoted strings (similar to parameter expansion in shell scripts).
- get_value(name)[source]
Get the current value of a given namelist variable.
Note that the return value of this function is always a string or a list of strings. E.g. the scalar logical value .false. will be returned as “.false.”, while an array of two .false. values will be returned as [“.false.”, “.false.”]. Whether or not a value is scalar is determined by checking the array size in the namelist definition file.
Null values are converted to None, and repeated values are expanded, e.g. [‘2*3’] is converted to [‘3’, ‘3’, ‘3’].
For character variables, the value is converted to a Python string (e.g. quotation marks are removed).
All other literals are returned as the raw string values that will be written to the namelist.
- init_defaults(infiles, config, skip_groups=None, skip_entry_loop=False, skip_default_for_groups=None, set_group_name=None)[source]
Return array of names of all definition nodes
infiles should be a list of file paths, each one giving namelist settings that take precedence over the default values. Often there will be only one file in this list. If there are multiple files, earlier files take precedence over later files.
If skip_default_for_groups is provided, it should be a list of namelist group names; the add_default call will not be done for any variables in these groups. This is often paired with later conditional calls to add_defaults_for_group.
- static quote_string(string)[source]
Convert a string to a quoted Fortran literal.
Does nothing if the string appears to be quoted already.
- set_abs_file_path(file_path)[source]
If file_path is relative, make it absolute using DIN_LOC_ROOT.
If an absolute path is input, it is returned unchanged.
- set_value(name, value)[source]
Set the current value of a given namelist variable.
Usually, you should use add_default instead of this function.
The name argument is the name of the variable to set, and the value is a list of strings to use as settings. If the variable is scalar, the list is optional; i.e. a scalar logical can be set using either value=’.false.’ or value=[‘.false.’]. If the variable is of type character, and the input is missing quotes, quotes will be added automatically. If None is provided in place of a string, this will be translated to a null value.
Note that this function will overwrite the current value, which may hold a user-specified setting. Even if value is (or contains) a null value, the old setting for the variable will be thrown out completely.
- update_shr_strdata_nml(config, stream, stream_path)[source]
Updates values for the shr_strdata_nml namelist group.
This should be done once per stream, and it shouldn’t usually be called directly, since create_stream_file calls this method itself.
- write_nuopc_config_file(filename, data_list_path=None, sorted_groups=False)[source]
Write the nuopc config file
- write_output_file(namelist_file, data_list_path=None, groups=None, sorted_groups=True)[source]
Write out the namelists and input data files.
The namelist_file and modelio_file are the locations to which the component and modelio namelists will be written, respectively. The data_list_path argument is the location of the *.input_data_list file, which will have the input data files added to it.