Skip to content

Commit

Permalink
Merge pull request #1259 from jedwards4b/index_in_namelist
Browse files Browse the repository at this point in the history
Index in namelist
Adds support for namelist entries of the form foo(3) = 'a'

Test suite: scripts_regression_tests.py, --namelist-only tests for cesm prealpha and aux_clm45
Note there are some expected failures here due to bugs found in the process. One bug was that
for multi-instance cases all namelists were using the 0001 stream file and they each should have
a separate file. Another bug was that only changes in user_nl_d***_0001 were being used in all
instances (user_nl_d***_000n where n>1 was being ignored)
Test baseline: cesm2_0_alpha06g
Test namelist changes:
Test status: bit for bit

Fixes #1248
Fixes #1274

User interface changes?:

Code review: @jgfouca @mvertens @gold2718
  • Loading branch information
jedwards4b authored Mar 24, 2017
2 parents 4e125ee + 75a815a commit 9d8396a
Show file tree
Hide file tree
Showing 11 changed files with 292 additions and 109 deletions.
21 changes: 12 additions & 9 deletions scripts/lib/CIME/XML/namelist_definition.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@
# pylint:disable=wildcard-import,unused-wildcard-import

import re
import collections

from CIME.namelist import fortran_namelist_base_value, \
is_valid_fortran_namelist_literal, character_literal_to_string, \
expand_literal_list, Namelist
expand_literal_list, Namelist, get_fortran_name_only

from CIME.XML.standard_module_setup import *
from CIME.XML.entry_id import EntryID
Expand Down Expand Up @@ -306,7 +307,7 @@ def is_valid_value(self, name, value):

# Check size of input array.
if len(expand_literal_list(value)) > size:
return False
expect(False, "Value index exceeds variable size for variable %s, allowed array length is %s value array size is %s"%(name, size, len(expand_literal_list(value))))
return True

def _expect_variable_in_definition(self, name, variable_template):
Expand Down Expand Up @@ -342,21 +343,22 @@ def validate(self, namelist,filename=None):
for group_name in namelist.get_group_names():
for variable_name in namelist.get_variable_names(group_name):
# Check that the variable is defined...
self._expect_variable_in_definition(variable_name, variable_template)
qualified_variable_name = get_fortran_name_only(variable_name)
self._expect_variable_in_definition(qualified_variable_name, variable_template)

# Check if can actually change this variable via filename change
if filename is not None:
self._user_modifiable_in_variable_definition(variable_name)
self._user_modifiable_in_variable_definition(qualified_variable_name)

# and has the right group name...
var_group = self.get_group(variable_name)
var_group = self.get_group(qualified_variable_name)
expect(var_group == group_name,
(variable_template + " is in a group named %r, but should be in %r.") %
(str(variable_name), str(group_name), str(var_group)))

# and has a valid value.
value = namelist.get_variable_value(group_name, variable_name)
expect(self.is_valid_value(variable_name, value),
expect(self.is_valid_value(qualified_variable_name, value),
(variable_template + " has invalid value %r.") %
(str(variable_name), [str(scalar) for scalar in value]))

Expand All @@ -379,11 +381,12 @@ def dict_to_namelist(self, dict_, filename=None):
groups = {}
for variable_name in dict_:
variable_lc = variable_name.lower()
self._expect_variable_in_definition(variable_lc, variable_template)
group_name = self.get_group(variable_lc)
qualified_varname = get_fortran_name_only(variable_lc)
self._expect_variable_in_definition(qualified_varname, variable_template)
group_name = self.get_group(qualified_varname)
expect (group_name is not None, "No group found for var %s"%variable_lc)
if group_name not in groups:
groups[group_name] = {}
groups[group_name] = collections.OrderedDict()
groups[group_name][variable_lc] = dict_[variable_name]
return Namelist(groups)

Expand Down
1 change: 0 additions & 1 deletion scripts/lib/CIME/buildnml.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,5 @@ def create_namelist_infile(case, user_nl_file, namelist_infile, infile_text=""):
lines_output.append(line)

lines_output.append("/ \n")

with open(namelist_infile, "w") as file_infile:
file_infile.write("\n".join(lines_output))
Loading

0 comments on commit 9d8396a

Please sign in to comment.