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

Index in namelist #1259

Merged
merged 25 commits into from
Mar 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
97244cb
add _nameindex to NamelistParser
jedwards4b Mar 17, 2017
ae96067
fix doctest issues
jedwards4b Mar 17, 2017
7105184
better assignment
jedwards4b Mar 17, 2017
388f7d2
fixed multiple instance problem
Mar 17, 2017
9be48ca
need to clean streams between instances
jedwards4b Mar 17, 2017
91b899a
add new_instance function to all data models
jedwards4b Mar 17, 2017
906c66a
remove commented code
jedwards4b Mar 17, 2017
c106652
add space before return
jedwards4b Mar 20, 2017
31c5f95
added error for values out of range
jedwards4b Mar 20, 2017
3cfe6cc
finish abandoned branch
jedwards4b Mar 22, 2017
5a12888
seems to be working now
jedwards4b Mar 22, 2017
d085370
fix step > 1
jedwards4b Mar 23, 2017
a46759a
character not char
jedwards4b Mar 23, 2017
757bc28
need a special case for cice
jedwards4b Mar 23, 2017
ed578f0
move new_instance code from buildnml to init_defaults since it is als…
jedwards4b Mar 23, 2017
e255277
remove bad line info, better error for multiple dimensions
jedwards4b Mar 24, 2017
6584df0
fix ordering issues
jedwards4b Mar 24, 2017
4bc8257
fix doctests
jedwards4b Mar 24, 2017
4ba1711
fix pylint issue
jedwards4b Mar 24, 2017
00285b7
fix spelling in comment
jedwards4b Mar 24, 2017
454f484
remove blank lines
jedwards4b Mar 24, 2017
6c9e249
error for values exceed array size
jedwards4b Mar 24, 2017
357d31d
fix issues with array limits
jedwards4b Mar 24, 2017
b284bde
remove unneeded restriction on step
jedwards4b Mar 24, 2017
75a815a
one more fix for negative index
jedwards4b Mar 24, 2017
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
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