Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make further_info_url attribute only be used if required by CV or requested by user #727

Merged
merged 4 commits into from
Feb 27, 2024
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
23 changes: 18 additions & 5 deletions Src/cmor.c
Original file line number Diff line number Diff line change
Expand Up @@ -1321,7 +1321,7 @@ int cmor_dataset_json(char *ressource)
CMOR_DEFAULT_FILE_TEMPLATE, CMOR_MAX_STRING);

strncpytrim(cmor_current_dataset.furtherinfourl,
CMOR_DEFAULT_FURTHERURL_TEMPLATE, CMOR_MAX_STRING);
"", CMOR_MAX_STRING);

strncpytrim(cmor_current_dataset.history_template,
CMOR_DEFAULT_HISTORY_TEMPLATE, CMOR_MAX_STRING);
Expand Down Expand Up @@ -1375,6 +1375,7 @@ int cmor_dataset_json(char *ressource)
} else if (strcmp(key, GLOBAL_ATT_FURTHERINFOURL) == 0) {
strncpytrim(cmor_current_dataset.furtherinfourl,
szVal, CMOR_MAX_STRING);
continue;
}
cmor_set_cur_dataset_attribute_internal(key, szVal, 1);
}
Expand Down Expand Up @@ -2794,14 +2795,27 @@ int cmor_setDefaultGblAttr(int ref_table_id)
if(cmor_has_cur_dataset_attribute(CV_value->key) != 0){
if(CV_value->szValue[0] != '\0'){
ierr |= cmor_set_cur_dataset_attribute_internal(CV_value->key, CV_value->szValue, 0);
if(strncmp(CV_value->key, GLOBAL_ATT_FURTHERINFOURL, CMOR_MAX_STRING) == 0){
strncpytrim(cmor_current_dataset.furtherinfourl, CV_value->szValue, CMOR_MAX_STRING);
if(strncmp(CV_value->key, GLOBAL_ATT_FURTHERINFOURL, CMOR_MAX_STRING) == 0
&& cmor_current_dataset.furtherinfourl[0] == '\0'){
ierr |= cmor_set_cur_dataset_attribute_internal(GLOBAL_ATT_FURTHERINFOURLTMPL, CV_value->szValue, 0);
}
} else if(CV_value->anElements == 1 && isRequired == 1){
ierr |= cmor_set_cur_dataset_attribute_internal(CV_value->key, CV_value->aszValue[0], 0);
}
}
}

/* -------------------------------------------------------------------- */
/* Set further_info_url template if required and not already set. */
/* -------------------------------------------------------------------- */
for (k = 0; k < required_attrs->anElements; k++) {
if(strcmp(required_attrs->aszValue[k], GLOBAL_ATT_FURTHERINFOURL) == 0
&& cmor_current_dataset.furtherinfourl[0] == '\0')
{
ierr |= cmor_set_cur_dataset_attribute_internal(GLOBAL_ATT_FURTHERINFOURLTMPL, CMOR_DEFAULT_FURTHERURL_TEMPLATE, 0);
}
}

cmor_pop_traceback();
return ierr;

Expand Down Expand Up @@ -3033,11 +3047,11 @@ int cmor_setGblAttr(int var_id)
ierr += cmor_CV_setInstitution(cmor_tables[nVarRefTblID].CV);
}

ierr += cmor_CV_checkFurtherInfoURL(nVarRefTblID);

if (cmor_has_cur_dataset_attribute(GLOBAL_IS_CMIP6) == 0) {
ierr += cmor_CV_checkSourceID(cmor_tables[nVarRefTblID].CV);
ierr += cmor_CV_checkExperiment(cmor_tables[nVarRefTblID].CV);
ierr += cmor_CV_checkFurtherInfoURL(nVarRefTblID);
ierr += cmor_CV_checkGrids(cmor_tables[nVarRefTblID].CV);
ierr += cmor_CV_checkParentExpID(cmor_tables[nVarRefTblID].CV);
ierr += cmor_CV_checkSubExpID(cmor_tables[nVarRefTblID].CV);
Expand All @@ -3052,7 +3066,6 @@ int cmor_setGblAttr(int var_id)
//
if ( cmor_current_dataset.furtherinfourl[0] != '\0') {
ierr += cmor_CV_checkSourceID(cmor_tables[nVarRefTblID].CV);
ierr += cmor_CV_checkFurtherInfoURL(nVarRefTblID);
}

ierr += cmor_CV_checkISOTime(GLOBAL_ATT_CREATION_DATE);
Expand Down
10 changes: 10 additions & 0 deletions Src/cmor_CV.c
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,13 @@ int cmor_CV_checkFurtherInfoURL(int nVarRefTblID)
cmor_is_setup();
cmor_add_traceback("_CV_checkFurtherInfoURL");

/* -------------------------------------------------------------------- */
/* If the template is an emtpy string, then skip this check. */
/* -------------------------------------------------------------------- */
if (cmor_current_dataset.furtherinfourl[0] == '\0') {
return (0);
}

/* -------------------------------------------------------------------- */
/* Retrieve default Further URL info */
/* -------------------------------------------------------------------- */
Expand All @@ -391,8 +398,11 @@ int cmor_CV_checkFurtherInfoURL(int nVarRefTblID)
}

if (strcmp(szToken, cmor_current_dataset.furtherinfourl) == 0) {
cmor_set_cur_dataset_attribute_internal(GLOBAL_ATT_FURTHERINFOURL,
cmor_current_dataset.furtherinfourl, 0);
return (0);
}

strncpy(szFurtherInfoURLTemplate, cmor_current_dataset.furtherinfourl,
CMOR_MAX_STRING);
/* -------------------------------------------------------------------- */
Expand Down
1 change: 0 additions & 1 deletion Test/CMIP6Plus_user_input.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
"_controlled_vocabulary_file": "TestTables/CMIP6Plus_CV.json",
"_AXIS_ENTRY_FILE": "mip-cmor-tables/Auxillary_files/MIP_coordinate.json",
"_FORMULA_VAR_FILE": "mip-cmor-tables/Auxillary_files/MIP_formula_terms.json",
"further_info_url": "https://furtherinfo.es-doc.org/",
"mo_runid": "u-be509",
"branch_time_in_parent": 59400.0,
"branch_time_in_child": 59400.0
Expand Down
2 changes: 1 addition & 1 deletion Test/CMOR_input_example_badfurtherinfourl.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@

"mip_era": "CMIP6",
"parent_mip_era": "CMIP6",
"further_info_url": "",
"further_info_url": "bad_url",

"tracking_prefix": "hdl:21.14100",
"_history_template": "%s ;rewrote data to be consistent with <activity_id> for variable <variable_id> found in table <table_id>.",
Expand Down
4 changes: 3 additions & 1 deletion Test/test_cmor_CMIP6Plus.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ def test_multiple_modeling_realms(self):
self.assertEqual(
cmor.write(ivar, data, ntimes_passed=ntimes_passed),
0)


self.assertFalse(cmor.has_cur_dataset_attribute('further_info_url'))

realms = cmor.get_cur_dataset_attribute('realm')
self.assertEqual(realms, "ocean seaIce")

Expand Down
3 changes: 1 addition & 2 deletions Test/test_python_CMIP6_CV_badfurtherinfourl.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ def testCMIP6(self):
# ------------------------------------------
# Check error after signal handler is back
# ------------------------------------------
self.assertCV("The further info URL value of \"\" is invalid.")

self.assertCV("Error: The attribute \"further_info_url\" could not be validated.")

if __name__ == '__main__':
run()