Skip to content

Commit

Permalink
one more fix for negative index
Browse files Browse the repository at this point in the history
  • Loading branch information
jedwards4b committed Mar 24, 2017
1 parent b284bde commit 75a815a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion scripts/lib/CIME/XML/namelist_definition.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ def is_valid_value(self, name, value):

# Check size of input array.
if len(expand_literal_list(value)) > size:
expect(False, "Value index exceeds variable size for variable %s"%name)
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
8 changes: 5 additions & 3 deletions scripts/lib/CIME/namelist.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,8 @@ def get_fortran_variable_indices(varname, varlen=1, allow_any_len=False):
if allow_any_len and maxindex == minindex:
maxindex = -1

expect(step != 0,"Step size 0 not allowed")

return (minindex, maxindex, step)

def fortran_namelist_base_value(string):
Expand Down Expand Up @@ -1017,10 +1019,10 @@ def set_variable_value(self, group_name, variable_name, value, var_size=1):
if minindex > tlen:
self._groups[group_name][variable_name].extend(['']*(minindex-tlen-1))

for i in range(minindex-1, maxindex+step, step):
while len(self._groups[group_name][variable_name]) < i+1:
for i in range(minindex, maxindex+2*step, step):
while len(self._groups[group_name][variable_name]) < i:
self._groups[group_name][variable_name].append('')
self._groups[group_name][variable_name][i] = value.pop(0)
self._groups[group_name][variable_name][i-1] = value.pop(0)
if len(value) == 0:
break

Expand Down

0 comments on commit 75a815a

Please sign in to comment.