diff --git a/Src/cmor.c b/Src/cmor.c index aa2e2451..597c7f39 100644 --- a/Src/cmor.c +++ b/Src/cmor.c @@ -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); @@ -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); } @@ -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; @@ -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); @@ -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); diff --git a/Src/cmor_CV.c b/Src/cmor_CV.c index 956f3c9c..fa9da49e 100644 --- a/Src/cmor_CV.c +++ b/Src/cmor_CV.c @@ -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 */ /* -------------------------------------------------------------------- */ @@ -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); /* -------------------------------------------------------------------- */ diff --git a/Test/CMIP6Plus_user_input.json b/Test/CMIP6Plus_user_input.json index 237f9354..e22c3e57 100644 --- a/Test/CMIP6Plus_user_input.json +++ b/Test/CMIP6Plus_user_input.json @@ -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 diff --git a/Test/CMOR_input_example_badfurtherinfourl.json b/Test/CMOR_input_example_badfurtherinfourl.json index ad8be76f..84bd2934 100644 --- a/Test/CMOR_input_example_badfurtherinfourl.json +++ b/Test/CMOR_input_example_badfurtherinfourl.json @@ -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 for variable found in table .", diff --git a/Test/test_cmor_CMIP6Plus.py b/Test/test_cmor_CMIP6Plus.py index ea7db18a..7f641737 100644 --- a/Test/test_cmor_CMIP6Plus.py +++ b/Test/test_cmor_CMIP6Plus.py @@ -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") diff --git a/Test/test_python_CMIP6_CV_badfurtherinfourl.py b/Test/test_python_CMIP6_CV_badfurtherinfourl.py index 22b87fe5..baa835ba 100644 --- a/Test/test_python_CMIP6_CV_badfurtherinfourl.py +++ b/Test/test_python_CMIP6_CV_badfurtherinfourl.py @@ -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()