Skip to content

Commit

Permalink
Merge pull request #41 from cedadev/issue_37
Browse files Browse the repository at this point in the history
Fix for region_name variable being one dimensional
  • Loading branch information
RosalynHatcher authored Feb 28, 2018
2 parents b66e954 + d0edbce commit 23e2566
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/cfchecker/cfchecks.py
Original file line number Diff line number Diff line change
Expand Up @@ -2521,9 +2521,12 @@ def chkDescription(self, varName):
if name == "region":
# Check values are from the permitted list
region_names = self.getStringValue(varName)
for region in region_names:
if not region in self.region_name_lh.list:
self._add_error("Invalid region name: %s" % region, varName, code="3.3")
if len(region_names):
for region in region_names:
if not region in self.region_name_lh.list:
self._add_error("Invalid region name: %s" % region, varName, code="3.3")
else:
self._add_error("No region names specified", varName, code="3.3")

#---------------------------------
def getStringValue(self, varName):
Expand All @@ -2532,10 +2535,10 @@ def getStringValue(self, varName):
# (fastest varying) dimension of string valued array into
# memory. E.g. [['a','b','c']] becomes ['abc']
array=self.f.variables[varName][:]

ndim = array.ndim
if array.dtype.kind == 'S':
strlen = array.shape[-1]

new_shape = array.shape[0:-1]
new_size = long(reduce(mul, new_shape, 1))

Expand All @@ -2549,7 +2552,11 @@ def getStringValue(self, varName):
array = array.reshape(new_shape)

array = numpy.ma.where(array=='', numpy.ma.masked, array)


# If varName is one dimension convert result of join from a string into an array
if ndim == 1:
array = [array]

return array

#-----------------------------------
Expand Down

0 comments on commit 23e2566

Please sign in to comment.