From d0edbcec90d04a952d2e4940befdc2c9866afdb8 Mon Sep 17 00:00:00 2001 From: RosalynHatcher Date: Wed, 28 Feb 2018 16:08:38 +0000 Subject: [PATCH] Fix for region_name variable being one dimensional --- src/cfchecker/cfchecks.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/cfchecker/cfchecks.py b/src/cfchecker/cfchecks.py index b8a06f4..c99258e 100644 --- a/src/cfchecker/cfchecks.py +++ b/src/cfchecker/cfchecks.py @@ -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): @@ -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)) @@ -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 #-----------------------------------