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
7 changes: 7 additions & 0 deletions Src/cmor_tables.c
Original file line number Diff line number Diff line change
Expand Up @@ -225,22 +225,29 @@ int cmor_set_variable_entry(cmor_table_t * table,
strncpy(variable->out_name,
&variable_entry[pmatch[1].rm_so],
pmatch[1].rm_eo - pmatch[1].rm_so);
variable->out_name[pmatch[1].rm_eo - pmatch[1].rm_so] = '\0';
strncpy(variable->temporal_label,
&variable_entry[pmatch[2].rm_so],
pmatch[2].rm_eo - pmatch[2].rm_so);
variable->temporal_label[pmatch[2].rm_eo - pmatch[2].rm_so] = '\0';
strncpy(variable->vertical_label,
&variable_entry[pmatch[3].rm_so],
pmatch[3].rm_eo - pmatch[3].rm_so);
variable->vertical_label[pmatch[3].rm_eo - pmatch[3].rm_so] = '\0';
strncpy(variable->horizontal_label,
&variable_entry[pmatch[4].rm_so],
pmatch[4].rm_eo - pmatch[4].rm_so);
variable->horizontal_label[pmatch[4].rm_eo - pmatch[4].rm_so] = '\0';
strncpy(variable->area_label,
&variable_entry[pmatch[5].rm_so],
pmatch[5].rm_eo - pmatch[5].rm_so);
variable->area_label[pmatch[5].rm_eo - pmatch[5].rm_so] = '\0';
strncpy(variable->branding_suffix,
&variable_entry[pmatch[2].rm_so],
pmatch[5].rm_eo - pmatch[2].rm_so);
variable->branding_suffix[pmatch[5].rm_eo - pmatch[2].rm_so] = '\0';
}
regfree(&regex);

json_object_object_foreach(json, attr, value) {
/* -------------------------------------------------------------------- */
Expand Down
40 changes: 20 additions & 20 deletions Src/cmor_variables.c
Original file line number Diff line number Diff line change
Expand Up @@ -1951,22 +1951,22 @@ void cmor_init_var_def(cmor_var_def_t * var, int table_id)

cmor_is_setup();
var->table_id = table_id;
var->standard_name[0] = '\0';
var->variable_title[0] = '\0';
var->brand_description[0] = '\0';
var->units[0] = '\0';
var->cell_methods[0] = '\0';
var->cell_measures[0] = '\0';
memset(var->standard_name, 0, sizeof(var->standard_name));
memset(var->variable_title, 0, sizeof(var->variable_title));
memset(var->brand_description, 0, sizeof(var->brand_description));
memset(var->units, 0, sizeof(var->units));
memset(var->cell_methods, 0, sizeof(var->cell_methods));
memset(var->cell_measures, 0, sizeof(var->cell_measures));
var->positive = cmor_tables[table_id].positive;
var->long_name[0] = '\0';
var->comment[0] = '\0';
var->realm[0] = '\0';
var->frequency[0] = '\0';
var->out_name[0] = '\0';
memset(var->long_name, 0, sizeof(var->long_name));
memset(var->comment, 0, sizeof(var->comment));
memset(var->realm, 0, sizeof(var->realm));
memset(var->frequency, 0, sizeof(var->frequency));
memset(var->out_name, 0, sizeof(var->out_name));
var->ndims = 0;
var->flag_values[0] = '\0';
var->flag_meanings[0] = '\0';
var->chunking_dimensions[0] = '\0';
memset(var->flag_values, 0, sizeof(var->flag_values));
memset(var->flag_meanings, 0, sizeof(var->flag_meanings));
memset(var->chunking_dimensions, 0, sizeof(var->chunking_dimensions));
for (n = 0; n < CMOR_MAX_DIMENSIONS; n++)
var->dimensions[n] = -1;
var->type = cmor_tables[table_id].type;
Expand All @@ -1978,12 +1978,12 @@ void cmor_init_var_def(cmor_var_def_t * var, int table_id)
var->deflate = 1;
var->deflate_level = 1;
var->zstandard_level = -999999;
var->generic_level_name[0] = '\0';
var->branding_suffix[0] = '\0';
var->temporal_label[0] = '\0';
var->vertical_label[0] = '\0';
var->horizontal_label[0] = '\0';
var->area_label[0] = '\0';
memset(var->generic_level_name, 0, sizeof(var->generic_level_name));
memset(var->branding_suffix, 0, sizeof(var->branding_suffix));
memset(var->temporal_label, 0, sizeof(var->temporal_label));
memset(var->vertical_label, 0, sizeof(var->vertical_label));
memset(var->horizontal_label, 0, sizeof(var->horizontal_label));
memset(var->area_label, 0, sizeof(var->area_label));
}

/************************************************************************/
Expand Down
65 changes: 58 additions & 7 deletions Test/test_cmor_CMIP7.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,8 @@ def setUp(self):
raise RuntimeError("CMOR dataset_json call failed")

def test_cmip7(self):
tos = numpy.array([27, 27, 27, 27,
27, 27, 27, 27,
27, 27, 27, 27,
27, 27, 27, 27,
27, 27, 27, 27,
27, 27, 27, 27
])
data = [27] * (2 * 3 * 4)
tos = numpy.array(data)
tos.shape = (2, 3, 4)
lat = numpy.array([10, 20, 30])
lat_bnds = numpy.array([5, 15, 25, 35])
Expand Down Expand Up @@ -144,6 +139,62 @@ def test_cmip7(self):

ds.close()

def test_secondary_modeling_realm(self):
data = [27] * (2 * 3 * 4)
pr = numpy.array(data)
pr.shape = (2, 3, 4)
lat = numpy.array([10, 20, 30])
lat_bnds = numpy.array([5, 15, 25, 35])
lon = numpy.array([0, 90, 180, 270])
lon_bnds = numpy.array([-45, 45,
135,
225,
315
])
time = numpy.array([15.5, 45])
time_bnds = numpy.array([0, 31, 60])
cmor.load_table("CMIP7_atmos2d.json")
cmorlat = cmor.axis("latitude",
coord_vals=lat,
cell_bounds=lat_bnds,
units="degrees_north")
cmorlon = cmor.axis("longitude",
coord_vals=lon,
cell_bounds=lon_bnds,
units="degrees_east")
cmortime = cmor.axis("time",
coord_vals=time,
cell_bounds=time_bnds,
units="days since 2018")
axes = [cmortime, cmorlat, cmorlon]
cmorpr = cmor.variable("pr_tavg-u-hxy-u", "kg m-2 s-1", axes)
self.assertEqual(cmor.write(cmorpr, pr), 0)
filename = cmor.close(cmorpr, file_name=True)
self.assertEqual(cmor.close(), 0)

ds = Dataset(filename)
attrs = ds.ncattrs()
test_attrs = {
'branding_suffix': 'tavg-u-hxy-u',
'temporal_label': 'tavg',
'vertical_label': 'u',
'horizontal_label': 'hxy',
'area_label': 'u',
'region': 'glb',
'frequency': 'mon',
'archive_id': 'WCRP',
'mip_era': 'CMIP7',
'data_specs_version': 'CMIP-7.0.0.0',
'host_collection': 'CMIP7',
'realm': 'atmos ocean',
}

for attr, val in test_attrs.items():
self.assertTrue(attr in attrs)
self.assertEqual(val, ds.getncattr(attr))

ds.close()


if __name__ == '__main__':
unittest.main()
2 changes: 1 addition & 1 deletion TestTables/CMIP7_atmos2d.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"time"
],
"out_name":"pr",
"realm":[
"modeling_realm":[
"atmos",
"ocean"
],
Expand Down