[cmor] 82/190: 2010-12-17 : when passing character type axes, checking output is suppposed to be character

Alastair McKinstry mckinstry at moszumanska.debian.org
Tue Jul 21 12:54:40 UTC 2015


This is an automated email from the git hooks/post-receive script.

mckinstry pushed a commit to branch debian/master
in repository cmor.

commit b319dcc813faca2b2ea18f8e1b3d44f2c7c413e7
Author: Charles Doutriaux <doutriaux1 at llnl.gov>
Date:   Fri Dec 17 14:44:40 2010 -0800

    2010-12-17 : when passing character type axes, checking output is suppposed to be character
---
 RELEASE-NOTES               |  1 +
 Src/cmor_axes.c             |  5 ++++
 Test/test_python_jamie_9.py | 59 +++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 65 insertions(+)

diff --git a/RELEASE-NOTES b/RELEASE-NOTES
index f24bc57..dff3499 100644
--- a/RELEASE-NOTES
+++ b/RELEASE-NOTES
@@ -1,3 +1,4 @@
+2010-12-17 : when passing character type axes, checking output is suppposed to be character
 2010-12-17 : fixed bug found by Jamie that didn't pass the correct args in get_var_Attribute
 2010-12-16 : added two python test for var with string dimensions
 2010-12-06 : turned off udunits2 warnings when reading database in
diff --git a/Src/cmor_axes.c b/Src/cmor_axes.c
index ca966b7..ce6fc47 100644
--- a/Src/cmor_axes.c
+++ b/Src/cmor_axes.c
@@ -1213,6 +1213,11 @@ int cmor_axis(int *axis_id, char *name,char *units, int length,void *coord_vals,
 /*       for(i=0;i<length;i++) printf("ok we received: %i:%lf\n",i,cmor_axes[cmor_naxes].values[i]); */
     }
     else {
+      /* before we do anything let check that output type is also character */
+      if (type!=refaxis.type) {
+	snprintf(msg,CMOR_MAX_STRING,"You are trying to define axis %s (table: %s) as character when it should be of type: %c\n",cmor_axes[cmor_naxes].id,cmor_tables[CMOR_TABLE].table_id,refaxis.type);
+	cmor_handle_error(msg,CMOR_CRITICAL);
+      }
       cmor_axes[cmor_naxes].cvalues=malloc(length*sizeof(char *));
       if (cmor_axes[cmor_naxes].cvalues == NULL)  {
 	snprintf(msg,CMOR_MAX_STRING,"cannot allocate memory for %i char elts for axis %s (table: %s)",length,cmor_axes[cmor_naxes].id,cmor_tables[CMOR_TABLE].table_id);
diff --git a/Test/test_python_jamie_9.py b/Test/test_python_jamie_9.py
new file mode 100644
index 0000000..26cd1ce
--- /dev/null
+++ b/Test/test_python_jamie_9.py
@@ -0,0 +1,59 @@
+#!/usr/bin/env python
+import cmor
+import numpy
+
+def main():
+    
+    cmor.setup(inpath='Tables',
+               netcdf_file_action = cmor.CMOR_REPLACE_3)
+    cmor.dataset('pre-industrial control', 'ukmo', 'HadCM3', '360_day',
+                 institute_id = 'ukmo',
+                 model_id = 'HadCM3',
+                 history = 'some global history',
+                 forcing = 'N/A',
+                 parent_experiment_id = 'N/A',
+                 parent_experiment_rip = 'N/A',
+                 branch_time = 0,
+                 contact = 'brian clough')
+ 
+    table = 'CMIP5_Amon'
+    cmor.load_table(table)
+    axes = [ {'table_entry': 'time',
+              'units': 'days since 2000-01-01 00:00:00',
+              },
+             {'table_entry': 'plevs',
+              'units': 'Pa',
+              'coord_vals': '100000. 92500. 85000. 70000. 60000. 50000. 40000. 30000. 25000. 20000. 15000. 10000. 7000. 5000. 3000. 2000. 1000.'.split(' ')},
+             {'table_entry': 'latitude',
+              'units': 'degrees_north',
+              'coord_vals': [0],
+              'cell_bounds': [-1, 1]},             
+             {'table_entry': 'longitude',
+              'units': 'degrees_east',
+              'coord_vals': [90],
+              'cell_bounds': [89, 91]},
+             ]
+
+
+    axis_ids = list()
+    for axis in axes:
+        print 'doing:',axis
+        axis_id = cmor.axis(**axis)
+        axis_ids.append(axis_id)
+
+    for var, units, value in (('ta', 'K', 274), ('ua', 'm s-1', 10)):
+        values = numpy.array([value,]*len(axes[1]['coord_vals']), numpy.float32)
+        varid = cmor.variable(var,
+                              units,
+                              axis_ids,
+                              history = 'variable history',
+                              missing_value = -99
+                              )
+        cmor.set_variable_attribute(varid, 'cell_measures', '')
+        cmor.write(varid, values, time_vals = [15], time_bnds = [ [0,30] ])
+
+    cmor.close()
+    
+if __name__ == '__main__':
+
+    main()

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/cmor.git



More information about the debian-science-commits mailing list