Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion Lib/avariable.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ def _returnArray(self, ar, squeeze, singles=None):
result = numpy.ma.masked_array(ar)
elif missing==inf or missing!=missing: # (x!=x) ==> x is NaN
result = numpy.ma.masked_object(ar, missing, copy=0)
elif ar.dtype.char=='c':
elif ar.dtype.char=='c' or ar.dtype.char=='S':
# umath.equal is not implemented
resultmask = (ar==missing)
if not resultmask.any():
Expand Down
2 changes: 2 additions & 0 deletions Lib/tvariable.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,8 @@ def __new__(cls, data, typecode=None, copy=0, savespace=0,
data = numpy.ma.masked.data
mask = numpy.ma.masked.mask

if fill_value in ["N/A"]: fill_value = None

if fill_value is not None:
fill_value = numpy.array(fill_value).astype(dtype)
else:
Expand Down
66 changes: 57 additions & 9 deletions Src/Cdunifmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -1104,9 +1104,6 @@ static void collect_attributes(PyCdunifFileObject *file, int varid,
;
Py_END_ALLOW_THREADS
;
if ((py_type == NPY_STRING)) {
length = strlen(s) + 1;
}
s[length] = '\0';
string = PyString_FromString(s);
free(s);
Expand Down Expand Up @@ -2429,7 +2426,13 @@ PyCdunifVariable_ReadAsArray(PyCdunifVariableObject *self,
free(indices);
return NULL;
}
array = (PyArrayObject *) PyArray_SimpleNew(d, dims, self->type);
//
// If we don't have a flexible type define a Simple Array
//
if( self->type != NPY_STRING) {
array = (PyArrayObject *) PyArray_SimpleNew(d, dims, self->type);
}

if (array != NULL && nitems > 0) {
if (self->nd == 0) {
long zero = 0;
Expand All @@ -2452,6 +2455,11 @@ PyCdunifVariable_ReadAsArray(PyCdunifVariableObject *self,
long *start;
long *count;
long *stride;
char **value;
int err;
int i,j;
int maxsize;

start = (long *) malloc(self->nd * sizeof(long));
count = (long *) malloc(self->nd * sizeof(long));
stride = (long *) malloc(self->nd * sizeof(long));
Expand All @@ -2464,13 +2472,53 @@ PyCdunifVariable_ReadAsArray(PyCdunifVariableObject *self,
/ indices[i].stride + 1;
}
Py_BEGIN_ALLOW_THREADS
;

acquire_Cdunif_lock()
;
ret = cdvargets(self->file, self->id, start, count, stride,
array->data);

if (self->type == NPY_STRING) {
if( d > 1) {
// *********************
// Limit to 1 dimension
// **********************
PyErr_SetString(PyExc_IOError, "cdunif: More than 1 dimension String variables not allowed");
return NULL;
}
value = (char**) PyMem_Malloc(nitems * sizeof(char*));
err = nc_get_vara_string(self->file->id, self->id, start,
count, (void *) value);
// Look for maximum string size to create object.
// -----------------------------------------------
maxsize = -1;
for( i=0; i<nitems; i++) {
int len = strlen(value[i]);
if( maxsize < len) {
maxsize = len+1;
}
}
array = (PyArrayObject *) PyArray_New(&PyArray_Type, d,
dims,
NPY_STRING, NULL,
NULL, maxsize, 0, NULL);
//
// Copy each string into new PyArray.
//
if (err == NC_NOERR) {
// Note limited to 1 dimension...
for (j = 0; j < count[0]; j++) {
PyObject *obj = PyUnicode_FromString(value[j]);
if (obj != NULL) {
PyArray_SETITEM((PyArrayObject*)array,
PyArray_GETPTR1((PyArrayObject*)array, j), obj);
}
}
}
PyMem_Free(value);
} else {
ret = cdvargets(self->file, self->id, start, count, stride,
array->data);
}
release_Cdunif_lock()
;

Py_END_ALLOW_THREADS
;
if (ret == -1) {
Expand Down
3 changes: 3 additions & 0 deletions Test/test_allMIPs.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ def testinput4MIPs(self):
f=cdms2.open("161122_RobertPincus_multiple_input4MIPs_radiation_RFMIP_UColorado-RFMIP-20161122_none.nc")
self.assertEqual(f['water_vapor'].getLatitude()[0:4].tolist(), [-28.5, 28.5, 31.5, 87.])
self.assertEqual(f['water_vapor'].getLongitude()[0:4].tolist(), [27., 24., 162., 126.])
labels=f['expt_label'][:]
self.assertEqual(labels.tolist(), ['Present day (PD)', 'Pre-industrial (PI) greenhouse gas concentrations', '4xCO2', '"future"', '0.5xCO2', '2xCO2', '3xCO2', '8xCO2', 'PI CO2', 'PI CH4', 'PI N2O', 'PI O3', 'PI HCs', '+4K', '+4K, const. RH', 'PI all', '"future" all', 'LGM'])


if __name__ == "__main__":
basetest.run()
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@
mpicc="mpicc"
subprocess.check_call([mpicc,"--version"])
os.environ["CC"]=mpicc
os.environ["CFLAGS"]="-w -g"
os.environ["CFLAGS"]="-w -g -O0"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we really want -O0?

Copy link
Copy Markdown
Contributor Author

@dnadeau4 dnadeau4 Feb 14, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we have -g, -O0 helps for not optimizing some local variables, especially counter like i,j. Otherwise, they are optimized and we can't access their value. We should really get rid for -g -O0 when we distribute to make the program go faster.

except:
os.environ["CFLAGS"]="-w -g"
os.environ["CFLAGS"]="-w -g -O0"
pass

libs_pth = os.path.join(sys.prefix,"lib")
Expand Down