[cmor] 07/12: 2.9.3 from github
Alastair McKinstry
mckinstry at moszumanska.debian.org
Mon Aug 8 08:05:51 UTC 2016
This is an automated email from the git hooks/post-receive script.
mckinstry pushed a commit to branch debian/master
in repository cmor.
commit 9ccbe9a7e9d63130847c86afdd3e0c9ea4f13b50
Author: Alastair McKinstry <mckinstry at debian.org>
Date: Mon Jun 13 10:47:52 2016 +0100
2.9.3 from github
---
INSTALL | 27 +++--
Lib/__init__.py | 3 +-
Makefile.in | 5 +-
Src/cmor.c | 71 +++++++++++++-
Src/cmor_axes.c | 6 +-
Src/cmor_grids.c | 1 +
Src/cmor_md5.c | 2 +-
Src/cmor_tables.c | 4 +
Test/test_non_monotonic_climo_bonds_ok.py | 54 ++++++++++
Test/test_python_2Gb_slice.py | 8 +-
Test/test_python_free_wrapping_issue.py | 157 ++++++++++++++++++++++++++++++
include/cmor.h | 7 +-
12 files changed, 325 insertions(+), 20 deletions(-)
diff --git a/INSTALL b/INSTALL
index c7f7454..8c659c4 100644
--- a/INSTALL
+++ b/INSTALL
@@ -5,8 +5,10 @@ Climate Model Output Rewriter (CMOR) version 2.0 installation instructions.
DOWNLOAD
--------
-You can get the latest version of the software from the CMOR homepage
-http://www2-pcmdi.llnl.gov/cmor/
+You can get the latest version of the software from the CMOR homepage on
+github.
+git clone http://github.com/PCMDI/CMOR
+cd CMOR
INSTALLATION
@@ -32,7 +34,8 @@ FIRST:
DOT NOT FORGET to build with --enable-netcdf-4 option
Always:
- udunits2: (not 1) http://www.unidata.ucar.edu/software/udunits/udunits-2/udunits2.html
- - libuuid: I used the version at http://www.ossp.org/pkg/lib/uuid
+ - libuuid: I used the version at http://www.ossp.org/pkg/lib/uuid,
+ and you need one with a calling convention compatible with it
NOTES: it strongly recommend to use the --disable-shared argument to the
./configure when building udunits2, hdf5 and netcdf4. Otherwise make
@@ -42,15 +45,25 @@ FIRST:
counter-intuitive) to add the --enable-netcdf-4 argument, otherwise
support for netcdf4 will not be enabled...
- NOTES2: You only need to install the C libraries for these. Usually you can turn off
- the fortran using --disable-fortran
+ NOTES2: You only need to install the C libraries for these. Usually
+ you can turn off the fortran using --disable-fortran
- NOTES3: on 64bit systems make SURE both C and FORTRAN compiler are running in same 32/64 bit mode. This is especially true for users migrating their Mac OS 10.5 machines to 10.6 since gfortran does not come standard the old 32bit is usually transfered.
+ NOTES3: on 64bit systems make SURE both C and FORTRAN compiler are
+ running in same 32/64 bit mode. This is especially true for
+ users migrating their Mac OS 10.5 machines to 10.6 since
+ gfortran does not come standard the old 32bit is usually
+ transfered.
+
+ NOTES4: CMOR uses the NetCDF 'nc-config' command to guess some
+ options for compilation. Once you have installed NetCDF
+ check that 'nc-config --libs' and 'nc-config --cflags' give
+ reasonable answers.
+
SECOND: Install CMOR (version 2) library
run the configuration script, build and install
- ./configure --prefix=/path/to/where/you/want/cmor --with-netcdf=/path/to/NetCDF4 --with-hdf5=/path/to/HDF5 --with-udunits2=/path/to/udunits2
+ ./configure --prefix=/path/to/where/you/want/cmor --with-netcdf=/path/to/NetCDF4 --with-udunits2=/path/to/udunits2
make
make install
diff --git a/Lib/__init__.py b/Lib/__init__.py
index 4b54fa6..22cd541 100644
--- a/Lib/__init__.py
+++ b/Lib/__init__.py
@@ -4,6 +4,5 @@ from pywrapper import axis,variable,write,setup,load_table,dataset,set_table,zfa
try:
from check_CMOR_compliant import checkCMOR
-except Exception,err:
- print err
+except:
pass
diff --git a/Makefile.in b/Makefile.in
index b7c3164..bdd92db 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -153,8 +153,8 @@ test_python: python
@env TEST_NAME=Test/test_python_joerg_8.py make test_a_python
# @env TEST_NAME=Test/test_python_joerg_9.py make test_a_python
@env TEST_NAME=Test/test_python_joerg_10.py make test_a_python
- @env TEST_NAME=Test/test_python_joerg_11.py make test_a_python
- @env TEST_NAME=Test/test_python_joerg_12.py make test_a_python
+ @env TEST_NAME=Test/test_python_joerg_11.py make test_a_python
+ @env TEST_NAME=Test/test_python_joerg_12.py make test_a_python
@env TEST_NAME=Test/test_python_YYYMMDDHH_exp_fmt.py make test_a_python
@env TEST_NAME=Test/test_python_region.py make test_a_python
@env TEST_NAME=Test/jamie_hybrid_height.py make test_a_python
@@ -177,6 +177,7 @@ test_python: python
@env TEST_NAME=Test/test_python_jamie_11.py make test_a_python
@env TEST_NAME=Test/test_python_joerg_tim2_clim_02.py make test_a_python
@env TEST_NAME=Test/test_site_ts.py make test_a_python
+ @env TEST_NAME=Test/test_python_free_wrapping_issue.py make test_a_python
test_case:
@echo "${OK_COLOR}Testing: "${TEST_NAME}" with input file: ${INPUT_FILE}${NO_COLOR}"
diff --git a/Src/cmor.c b/Src/cmor.c
index 0b70837..660a073 100644
--- a/Src/cmor.c
+++ b/Src/cmor.c
@@ -24,12 +24,19 @@ int nc_def_var_deflate(int i,int j,int k,int l, int m) {return 0;};
int nc_def_var_chunking(int i,int j,int k,size_t *l) {return 0;};
#endif
+extern int cmor_set_cur_dataset_attribute_internal(char *name, char *value, int optional);
+extern int cmor_set_variable_attribute_internal(int id, char *attribute_name, char type, void *value);
+extern int cmor_history_contains(int var_id,char *add);
+extern void cdCompAdd(cdCompTime comptime, double value, cdCalenType calendar, cdCompTime *result);
+extern void cdCompAddMixed(cdCompTime ct, double value, cdCompTime *result);
int USE_NETCDF_4;
int cleanup_varid=-1;
const char CMOR_VALID_CALENDARS[CMOR_N_VALID_CALS][CMOR_MAX_STRING] = { "gregorian","standard", "proleptic_gregorian","noleap","365_day","360_day","julian","none"};
+const char cmor_tracking_prefix_project_filter[CMOR_MAX_TRACKING_PREFIX_PROJECT_FILTER][CMOR_MAX_STRING] = { "CMIP6" };
+
cmor_dataset_def cmor_current_dataset;
cmor_table_t cmor_tables[CMOR_MAX_TABLES];
cmor_var_t cmor_vars[CMOR_MAX_VARIABLES];
@@ -65,7 +72,7 @@ int cmor_stringinstring (char* dest, char* src) {
internal to a word.
*/
char* pstr=dest;
- while (pstr=strstr(pstr, src)) {
+ while ((pstr=strstr(pstr, src))) {
/* if this word is at the beginning of msg or preceeded by a space */
if (pstr==dest || pstr[-1]==' ') {
/* if it isn't a substring match */
@@ -89,7 +96,7 @@ void cmor_cat_unique_string (char* dest, char* src) {
if (cmor_stringinstring(dest, src)) {
/* do nothing */
} else {
- if (offset=strlen(dest)) {
+ if ((offset=strlen(dest))) {
strcat(dest+offset, " ");
offset++;
spare_space=CMOR_MAX_STRING-offset-1;
@@ -277,6 +284,17 @@ int strncattrim(char *in, char *add, int max) {
/* } */
+int cmor_filter_tracking_prefix(char *project_id) {
+ // Checks given project_id string against values from constant array
+ // containing allowed projects. Returns 1 if there is an exact match.
+ int i;
+ for (i = 0; i < CMOR_MAX_TRACKING_PREFIX_PROJECT_FILTER; i++) {
+ if ( (strlen(project_id) == strlen(cmor_tracking_prefix_project_filter[i]))
+ && (strcmp(project_id, cmor_tracking_prefix_project_filter[i]) == 0)) return 1;
+ }
+ return 0;
+}
+
int CMOR_HAS_BEEN_SETUP=0;
ut_system *ut_read=NULL;
FILE *output_logfile;
@@ -760,6 +778,7 @@ int cmor_setup(char *path,int *netcdf, int *verbosity, int *mode, char *logfile,
cmor_axes[i].hybrid_in=0;
cmor_axes[i].hybrid_out=0;
cmor_axes[i].store_in_netcdf = 1;
+ cmor_axes[i].wrapping = NULL;
ierr = cmor_set_axis_attribute(i,"units",'c',"");
ierr = cmor_set_axis_attribute(i,"interval",'c',"");
}
@@ -792,6 +811,7 @@ int cmor_setup(char *path,int *netcdf, int *verbosity, int *mode, char *logfile,
cmor_handle_error(msg,CMOR_CRITICAL);
}
myutstatus = ut_map_name_to_unit("eq",UT_ASCII,newequnit);
+ if (newequnit!= NULL) ut_free(newequnit);
if (myutstatus != UT_SUCCESS) {
snprintf(msg,CMOR_MAX_STRING,"Udunits: Error mapping dimless 'eq' unit");
cmor_handle_error(msg,CMOR_CRITICAL);
@@ -809,11 +829,13 @@ int cmor_setup(char *path,int *netcdf, int *verbosity, int *mode, char *logfile,
}
if (perunit!=NULL) ut_free(perunit);
perunit = ut_scale(.01,dimlessunit);
+ if (dimlessunit!= NULL) ut_free(dimlessunit);
if (myutstatus != UT_SUCCESS) {
snprintf(msg,CMOR_MAX_STRING,"Udunits: Error creating percent unit");
cmor_handle_error(msg,CMOR_CRITICAL);
}
myutstatus = ut_map_name_to_unit("%",UT_ASCII,perunit);
+ if (perunit!=NULL) ut_free(perunit);
if (myutstatus != UT_SUCCESS) {
snprintf(msg,CMOR_MAX_STRING,"Udunits: Error mapping percent unit");
cmor_handle_error(msg,CMOR_CRITICAL);
@@ -1809,6 +1831,7 @@ int cmor_write(int var_id,void *data, char type, char *suffix, int ntimes_passed
uuid_fmt_t fmt;
void *myuuid_str=NULL;
size_t uuidlen;
+ int tracking_id_set;
extern int cmor_convert_char_to_hyphen(char c);
@@ -2478,7 +2501,24 @@ int cmor_write(int var_id,void *data, char type, char *suffix, int ntimes_passed
myuuid_str = NULL;
fmt = UUID_FMT_STR;
uuid_export(myuuid,fmt,&myuuid_str,&uuidlen);
- strncpy(cmor_current_dataset.tracking_id,(char *)myuuid_str,CMOR_MAX_STRING);
+ tracking_id_set = 0;
+
+ if (cmor_filter_tracking_prefix(cmor_tables[cmor_vars[var_id].ref_table_id].project_id) == 1) {
+ // filter matched, now either include the prefix or complain
+ if (strlen(cmor_tables[cmor_vars[var_id].ref_table_id].tracking_prefix) > 0) {
+ strncpy(cmor_current_dataset.tracking_id, cmor_tables[cmor_vars[var_id].ref_table_id].tracking_prefix, CMOR_MAX_STRING);
+ strcat(cmor_current_dataset.tracking_id, "/");
+ strcat(cmor_current_dataset.tracking_id, (char *) myuuid_str);
+ tracking_id_set = 1;
+ }
+ else {
+ sprintf(msg,"Project requires tracking prefixes, but no tracking_prefix was specified for table %s",tmps[0],cmor_tables[cmor_vars[var_id].ref_table_id].table_id);
+ cmor_handle_error(msg,CMOR_WARNING);
+ }
+ }
+ if (!tracking_id_set) {
+ strncpy(cmor_current_dataset.tracking_id,(char *)myuuid_str,CMOR_MAX_STRING);
+ }
cmor_set_cur_dataset_attribute_internal("tracking_id",cmor_current_dataset.tracking_id,0);
free(myuuid_str);
uuid_destroy(myuuid);
@@ -3341,7 +3381,30 @@ int cmor_write(int var_id,void *data, char type, char *suffix, int ntimes_passed
myuuid_str = NULL;
fmt = UUID_FMT_STR;
uuid_export(myuuid,fmt,&myuuid_str,&uuidlen);
- strncpy(cmor_current_dataset.tracking_id,(char *)myuuid_str,CMOR_MAX_STRING);
+ tracking_id_set = 0;
+
+ if (cmor_filter_tracking_prefix(cmor_tables[cmor_vars[var_id].ref_table_id].project_id) == 1) {
+ // filter matched, now either include the prefix or complain
+ if (strlen(cmor_tables[cmor_vars[var_id].ref_table_id].tracking_prefix) > 0) {
+ strncpy(cmor_current_dataset.tracking_id, cmor_tables[cmor_vars[var_id].ref_table_id].tracking_prefix, CMOR_MAX_STRING);
+ strcat(cmor_current_dataset.tracking_id, "/");
+ strcat(cmor_current_dataset.tracking_id, (char *) myuuid_str);
+ /* now copy concatenated string over to myuuid_str, as this
+ is the thing that will actually be written further below */
+ uuidlen = strlen(cmor_current_dataset.tracking_id);
+ free(myuuid_str);
+ myuuid_str = (char *)malloc(uuidlen*sizeof(char));
+ strcpy(myuuid_str, cmor_current_dataset.tracking_id);
+ tracking_id_set = 1;
+ }
+ else {
+ sprintf(msg,"Project requires tracking prefixes, but no tracking_prefix was specified for table %s",tmps[0],cmor_tables[cmor_vars[var_id].ref_table_id].table_id);
+ cmor_handle_error(msg,CMOR_WARNING);
+ }
+ }
+ if (!tracking_id_set) {
+ strncpy(cmor_current_dataset.tracking_id,(char *)myuuid_str,CMOR_MAX_STRING);
+ }
cmor_set_cur_dataset_attribute_internal("tracking_id",cmor_current_dataset.tracking_id,0);
ierr = nc_put_att_text(ncid, NC_GLOBAL, "tracking_id",(int)uuidlen,myuuid_str);
diff --git a/Src/cmor_axes.c b/Src/cmor_axes.c
index 3a8955b..01c3369 100644
--- a/Src/cmor_axes.c
+++ b/Src/cmor_axes.c
@@ -324,7 +324,11 @@ int cmor_check_monotonic(double *values,int length, char *name,int isbounds, int
}
else {
snprintf(msg,CMOR_MAX_STRING,"axis %s (table: %s) has non monotonic bounds values : %lf, %lf, %lf",name,cmor_tables[cmor_axes[axis_id].ref_table_id].table_id,values[2*i],values[2*i+2],values[2*i+4]);
- cmor_handle_error(msg,CMOR_CRITICAL);
+ if (refaxis->climatology==0) {
+ cmor_handle_error(msg,CMOR_CRITICAL);
+ } else {
+ cmor_handle_error(msg,CMOR_WARNING);
+ }
}
}
}
diff --git a/Src/cmor_grids.c b/Src/cmor_grids.c
index 93f87d1..db397bc 100644
--- a/Src/cmor_grids.c
+++ b/Src/cmor_grids.c
@@ -6,6 +6,7 @@
/* functions prototyping */
extern int CMOR_TABLE;
+extern int cmor_set_variable_attribute_internal(int id, char *attribute_name, char type, void *value);
void cmor_init_grid_mapping(cmor_mappings_t *mapping,char *id)
{
diff --git a/Src/cmor_md5.c b/Src/cmor_md5.c
index a0d8bd3..af124ad 100644
--- a/Src/cmor_md5.c
+++ b/Src/cmor_md5.c
@@ -174,7 +174,7 @@ cvs_MD5Final (unsigned char digest[16], struct cvs_MD5Context *ctx)
putu32(ctx->buf[1], digest + 4);
putu32(ctx->buf[2], digest + 8);
putu32(ctx->buf[3], digest + 12);
- memset(ctx, 0, sizeof(ctx)); /* In case it's sensitive */
+ memset(ctx, 0, sizeof(&ctx)); /* In case it's sensitive */
}
#ifndef ASM_MD5
diff --git a/Src/cmor_tables.c b/Src/cmor_tables.c
index 04415ab..e8954fc 100644
--- a/Src/cmor_tables.c
+++ b/Src/cmor_tables.c
@@ -37,6 +37,7 @@ void cmor_init_table(cmor_table_t *table, int id)
table->interval_warning=.1;
table->interval_error=.2;
table->URL[0]='\0';
+ table->tracking_prefix[0]='\0';
strcpy(table->product,"output");
table->path[0]='\0';
table->required_gbl_att[0]='\0';
@@ -112,6 +113,9 @@ int cmor_set_dataset_att(cmor_table_t *table, char att[CMOR_MAX_STRING],char val
else if (strcmp(att,"baseURL")==0) {
strncpy(table->URL,value,CMOR_MAX_STRING);
}
+ else if (strcmp(att,"tracking_prefix")==0) {
+ strncpy(table->tracking_prefix,value,CMOR_MAX_STRING);
+ }
else if (strcmp(att,"forcings")==0) {
cmor_convert_string_to_list(value,'c',(void **)&table->forcings,&table->nforcings);
}
diff --git a/Test/test_non_monotonic_climo_bonds_ok.py b/Test/test_non_monotonic_climo_bonds_ok.py
new file mode 100644
index 0000000..2cd0ad8
--- /dev/null
+++ b/Test/test_non_monotonic_climo_bonds_ok.py
@@ -0,0 +1,54 @@
+import cmor
+
+## Hypothetical data are going from march 2000 thru feb 2010
+times = [72,75,78]
+times_bnds = [[11,134],[2,125],[5,128]] # first full djf one year later than first full mam
+
+
+def path_test():
+ cmor.setup(inpath='TestTables',netcdf_file_action=cmor.CMOR_REPLACE)
+
+ cmor.dataset('historical', 'ukmo', 'HadCM3', '360_day',model_id='HadCM3',forcing='Nat',
+ contact="J.T. Snow",
+ institute_id="PCMDI",
+ parent_experiment_id="N/A",
+ parent_experiment_rip="N/A",
+ branch_time=0)
+
+ table='CMIP5_Amon'
+ cmor.load_table(table)
+ axes = [ {'table_entry': 'time2',
+ 'units': 'months since 2000-01-01 00:00:00',
+ 'coord_vals': times,
+ 'cell_bounds': times_bnds,
+ },
+ {'table_entry': 'plevs',
+ 'units': 'Pa',
+ 'coord_vals': [100000., 92500., 85000., 70000., 60000., 50000.,
+ 40000., 30000., 25000., 20000., 15000.,
+ 10000., 7000., 5000., 3000., 2000., 1000.]},
+ {'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:
+ axis_id = cmor.axis(**axis)
+ axis_ids.append(axis_id)
+ varid = cmor.variable('co2Clim', '1.e-6', axis_ids)
+ import numpy
+ data =numpy.array([3,4,5])
+ data.resize((3,17,1,1))
+ cmor.write(varid, data)
+ path=cmor.close(varid, file_name=True)
+
+ print path
+
+if __name__ == '__main__':
+ path_test()
diff --git a/Test/test_python_2Gb_slice.py b/Test/test_python_2Gb_slice.py
index 7490405..d17facc 100644
--- a/Test/test_python_2Gb_slice.py
+++ b/Test/test_python_2Gb_slice.py
@@ -37,15 +37,19 @@ axes=[itim,ilev,ilat,ilon]
var = cmor.variable(table_entry='ta',units='K',axis_ids=axes)
+print "allocating mem for data"
data = numpy.random.random((nlev,nlat,nlon))*30+273.15
+print "moving on to writing"
for i in range(ntimes):
- if i%10==0 : print 'Writing time:',i
+ print 'Writing time:',i
cmor.write(var,data,time_vals=numpy.array([float(i),]),time_bnds=numpy.array([i,i+1.]))
+print "closing var"
print cmor.close(var_id=var,file_name=True)
+print "closing cmor"
cmor.close()
-
+print "done"
print 'hello'
diff --git a/Test/test_python_free_wrapping_issue.py b/Test/test_python_free_wrapping_issue.py
new file mode 100644
index 0000000..98fe6de
--- /dev/null
+++ b/Test/test_python_free_wrapping_issue.py
@@ -0,0 +1,157 @@
+# This is a dummy version of the ACCESS Post Processor.
+# Peter Uhe 24 July 2014
+# Martin Dix 21 Nov 2014
+#
+import numpy as np
+import datetime
+import cmor
+
+def save(opts,threeD=True):
+
+ cmor.setup(inpath=opts['table_path'],
+ netcdf_file_action=cmor.CMOR_REPLACE_3,
+ set_verbosity=cmor.CMOR_NORMAL,
+ exit_control=cmor.CMOR_NORMAL,
+ logfile=None, create_subdirectories=1)
+
+ cmor.dataset(outpath=opts['outpath'],
+ experiment_id='historical',
+ institution='CMOR-test',
+ source='CMOR-test',
+ calendar='gregorian',
+ realization=1,
+ contact='dummy',
+ history='dummy',
+ model_id='CMOR-test',
+ forcing='GHG',
+ institute_id='CMOR-test',
+ parent_experiment_id='piControl',
+ branch_time=109207.0,
+ parent_experiment_rip='r1i1p1')
+
+ # Load the CMIP tables into memory.
+ tables=[]
+ tables.append(cmor.load_table('CMIP5_grids'))
+ tables.append(cmor.load_table(opts['cmip_table']))
+
+ # Create the dimension axes
+
+ # Monthly time axis
+ min_tvals=[]
+ max_tvals=[]
+ cmor_tName='time'
+ tvals=[]
+ axis_ids=[]
+ for year in range(1850,1851):
+ for mon in range(1,13):
+ tvals.append(datetime.date(year,mon,15).toordinal()-1)
+ # set up time values and bounds
+ for i,ordinaldate in enumerate(tvals):
+ model_date = datetime.date.fromordinal(int(ordinaldate)+1)
+ #min bound is first day of month
+ model_date=model_date.replace(day=1)
+ min_tvals.append(model_date.toordinal()-1)
+ #max_bound is first day of next month
+ tyr=model_date.year+model_date.month/12
+ tmon=model_date.month%12+1
+ model_date=model_date.replace(year=tyr,month=tmon)
+ max_tvals.append(model_date.toordinal()-1)
+ #correct date to middle of month
+ mid=(max_tvals[i]-min_tvals[i])/2.
+ tvals[i]=min_tvals[i]+mid
+ tval_bounds = np.column_stack((min_tvals, max_tvals))
+ cmor.set_table(tables[1])
+ time_axis_id = cmor.axis(table_entry=cmor_tName,
+ units='days since 0001-01-01', length=len(tvals),
+ coord_vals=tvals[:], cell_bounds=tval_bounds[:],
+ interval=None)
+ axis_ids.append(time_axis_id)
+
+ if not threeD:
+ # Pressure
+ plev = np.array([100000, 92500, 85000, 70000, 60000, 50000,
+ 40000, 30000, 25000, 20000, 15000, 10000,
+ 7000, 5000, 3000, 2000, 1000])
+ plev_bounds = np.array([
+ [103750, 96250],
+ [96250, 88750],
+ [88750, 77500],
+ [77500, 65000],
+ [65000, 55000],
+ [55000, 45000],
+ [45000, 35000],
+ [35000, 27500],
+ [27500, 22500],
+ [22500, 17500],
+ [17500, 12500],
+ [12500, 8500],
+ [8500, 6000],
+ [6000, 4000],
+ [4000, 2500],
+ [2500, 1500],
+ [1500, 500]])
+ plev_axis_id = cmor.axis(table_entry='plevs',
+ units='Pa', length=len(plev),
+ coord_vals=plev[:], cell_bounds=plev_bounds[:],
+ interval=None)
+ axis_ids.append(plev_axis_id)
+
+ # 1 degree resolution latitude and longitude
+ lat = np.linspace(-89.5,89.5,180)
+ lat_bounds = np.column_stack((np.linspace(-90.,89.,180.),
+ np.linspace(-89.,90.,180.)))
+ lat_axis_id = cmor.axis(table_entry='latitude',
+ units='degrees_north', length=len(lat),
+ coord_vals=lat[:], cell_bounds=lat_bounds[:],
+ interval=None)
+ axis_ids.append(lat_axis_id)
+
+ lon = np.linspace(0.5,359.5,360)
+ lon_bounds = np.column_stack((np.linspace(0.,359.,360.),
+ np.linspace(1.,360.,360.)))
+ lon_axis_id = cmor.axis(table_entry='longitude',
+ units='degrees_north', length=len(lon),
+ coord_vals=lon[:], cell_bounds=lon_bounds[:],
+ interval=None)
+ axis_ids.append(lon_axis_id)
+
+ #
+ # Define the CMOR variable.
+ #
+ cmor.set_table(tables[1])
+ in_missing = float(1.e20)
+ if threeD:
+ variable_id = cmor.variable(table_entry='ts', units='K', \
+ axis_ids=axis_ids, type='f', missing_value=in_missing)
+ else:
+ variable_id = cmor.variable(table_entry='ta', units='K', \
+ axis_ids=axis_ids, type='f', missing_value=in_missing)
+
+ #
+ # Write the data
+ #
+ if threeD:
+ data_vals = np.zeros((len(tvals), len(lat), len(lon)), np.float32) + 290.
+ else:
+ data_vals = np.zeros((len(tvals), len(plev), len(lat), len(lon)), np.float32) + 290.
+ try:
+ print 'writing...'
+ cmor.write(variable_id, data_vals[:], ntimes_passed=np.shape(data_vals)[0]) #assuming time is the first dimension
+ except Exception, e:
+ raise Exception("ERROR writing data!")
+
+ try:
+ path = cmor.close(variable_id, file_name=True)
+ except:
+ raise Exception("ERROR closing cmor file!")
+
+ print path
+
+if __name__ == "__main__":
+
+ opts={'cmip_table': 'CMIP5_Amon',
+ 'outpath': 'Test',
+ 'table_path': 'Tables'}
+
+ save(opts,threeD=True)
+ save(opts,threeD=False)
diff --git a/include/cmor.h b/include/cmor.h
index 88ebc44..4e27edf 100644
--- a/include/cmor.h
+++ b/include/cmor.h
@@ -3,7 +3,7 @@
#define CMOR_VERSION_MAJOR 2
#define CMOR_VERSION_MINOR 9
-#define CMOR_VERSION_PATCH 1
+#define CMOR_VERSION_PATCH 3
#define CMOR_CF_VERSION_MAJOR 1
#define CMOR_CF_VERSION_MINOR 4
@@ -42,6 +42,8 @@
#define CMOR_APPEND CMOR_APPEND_3
#define CMOR_REPLACE CMOR_REPLACE_3
+#define CMOR_MAX_TRACKING_PREFIX_PROJECT_FILTER 1
+
extern int USE_NETCDF_4;
extern int CMOR_MODE;
extern int CMOR_TABLE;
@@ -261,6 +263,7 @@ typedef struct cmor_table_ {
float interval_warning;
float interval_error;
char URL[CMOR_MAX_STRING];
+ char tracking_prefix[CMOR_MAX_STRING];
char product[CMOR_MAX_STRING];
char realm[CMOR_MAX_STRING];
char path[CMOR_MAX_STRING];
@@ -274,6 +277,8 @@ typedef struct cmor_table_ {
extern cmor_table_t cmor_tables[CMOR_MAX_TABLES];
+extern const char cmor_tracking_prefix_project_filter[CMOR_MAX_TRACKING_PREFIX_PROJECT_FILTER][CMOR_MAX_STRING];
+
typedef struct cmor_dataset_def_ {
char outpath[CMOR_MAX_STRING];
char conventions[CMOR_MAX_STRING];
--
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