diff --git a/Src/cmor_CV.c b/Src/cmor_CV.c index b353cf1e..aaed0346 100644 --- a/Src/cmor_CV.c +++ b/Src/cmor_CV.c @@ -653,14 +653,13 @@ int cmor_CV_checkSourceID(cmor_CV_def_t * CV) } // Check source with experiment_id label. rc = cmor_get_cur_dataset_attribute(GLOBAL_ATT_SOURCE, szSource); - if(CV_source_id->nbObjects == -1) { + if(CV_source_id->nbObjects < 1) { snprintf(msg, CMOR_MAX_STRING, "You did not define a %s section in your source_id %s.\n! \n! \n! " "See Control Vocabulary JSON file. (%s)\n! ", CV_KEY_SOURCE_LABEL, szSource_ID, CV_Filename); - cmor_handle_error(msg, CMOR_WARNING); - return(1); - break; + cmor_handle_error(msg, CMOR_CRITICAL); + return(-1); } for (j = 0; j < CV_source_id->nbObjects; j++) { if (strcmp(CV_source_id->oValue[j].key, CV_KEY_SOURCE_LABEL) == @@ -673,8 +672,8 @@ int cmor_CV_checkSourceID(cmor_CV_def_t * CV) "Could not find %s string in source_id section.\n! \n! \n! " "See Control Vocabulary JSON file. (%s)\n! ", CV_KEY_SOURCE_LABEL, CV_Filename); - cmor_handle_error(msg, CMOR_WARNING); - break; + cmor_handle_error(msg, CMOR_CRITICAL); + return(-1); } pos = strchr(CV_source_id->oValue[j].szValue, ')'); strncpy(szSubstring, CV_source_id->oValue[j].szValue, @@ -777,8 +776,6 @@ int CV_CompareNoParent(char *szKey) szValue, NO_PARENT); cmor_set_cur_dataset_attribute_internal(szKey, NO_PARENT, 1); cmor_handle_error(msg, CMOR_WARNING); - cmor_pop_traceback(); - return (-1); } } cmor_pop_traceback(); @@ -1013,6 +1010,7 @@ int cmor_CV_checkParentExpID(cmor_CV_def_t * CV) char CV_Filename[CMOR_MAX_STRING]; char msg[CMOR_MAX_STRING]; int rc; + int ierr = 0; szParentExpValue[0] = '\0'; cmor_add_traceback("_CV_checkParentExpID"); @@ -1045,10 +1043,16 @@ int cmor_CV_checkParentExpID(cmor_CV_def_t * CV) // Do we have a parent_experiment_id? if (cmor_has_cur_dataset_attribute(GLOBAL_ATT_PARENT_EXPT_ID) != 0) { CV_parent_exp_id = cmor_CV_search_child_key(CV_experiment, - PARENT_ACTIVITY_ID); + PARENT_EXPERIMENT_ID); if (CV_IsStringInArray(CV_parent_exp_id, NO_PARENT)) { - cmor_pop_traceback(); - return (0); + snprintf(msg, CMOR_MAX_STRING, + "Your input attribute \"%s\" defined as \"\" " + "will be replaced with \n! " + "\"%s\" as defined in your Control Vocabulary file.\n! ", + PARENT_EXPERIMENT_ID, NO_PARENT); + cmor_handle_error(msg, CMOR_WARNING); + cmor_set_cur_dataset_attribute_internal(PARENT_EXPERIMENT_ID, + NO_PARENT, 1); } else { snprintf(msg, CMOR_MAX_STRING, "Your input attribute \"%s\" is not defined properly \n! " @@ -1056,7 +1060,7 @@ int cmor_CV_checkParentExpID(cmor_CV_def_t * CV) "See Control Vocabulary JSON file.(%s)\n! ", GLOBAL_ATT_PARENT_EXPT_ID, CV_experiment->key, CV_Filename); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error(msg, CMOR_NORMAL); cmor_pop_traceback(); return (-1); } @@ -1101,9 +1105,6 @@ int cmor_CV_checkParentExpID(cmor_CV_def_t * CV) cmor_handle_error(msg, CMOR_WARNING); } } - - cmor_pop_traceback(); - return (0); } else { // real parent case // Parent Activity ID @@ -1113,10 +1114,8 @@ int cmor_CV_checkParentExpID(cmor_CV_def_t * CV) "for your experiment \"%s\"\n!\n! " "See Control Vocabulary JSON file.(%s)\n! ", PARENT_ACTIVITY_ID, CV_experiment->key, CV_Filename); - cmor_handle_error(msg, CMOR_CRITICAL); - cmor_pop_traceback(); - return (-1); - + cmor_handle_error(msg, CMOR_NORMAL); + ierr = -1; } else { cmor_get_cur_dataset_attribute(PARENT_ACTIVITY_ID, szValue); CV_parent_activity_id = cmor_CV_search_child_key(CV_experiment, @@ -1124,7 +1123,7 @@ int cmor_CV_checkParentExpID(cmor_CV_def_t * CV) if (CV_IsStringInArray(CV_parent_activity_id, szValue) == 0) { if (CV_parent_activity_id->anElements == 1) { snprintf(msg, CMOR_MAX_STRING, - "Your input attribute parent_activity_id \"%s\" defined as \"%s\" " + "Your input attribute \"%s\" defined as \"%s\" " "will be replaced with \n! " "\"%s\" as defined in your Control Vocabulary file.\n! ", PARENT_ACTIVITY_ID, szValue, @@ -1147,16 +1146,15 @@ int cmor_CV_checkParentExpID(cmor_CV_def_t * CV) } } // branch method - if (cmor_has_cur_dataset_attribute(BRANCH_METHOD)) { + if (cmor_has_cur_dataset_attribute(BRANCH_METHOD) != 0) { snprintf(msg, CMOR_MAX_STRING, "Your input attribute \"%s\" is not defined \n! " "properly for %s \n! " "Please describe the spin-up procedure as defined \n! " "in CMIP6 documentations.\n! ", BRANCH_METHOD, szExperiment_ID); - cmor_handle_error(msg, CMOR_CRITICAL); - cmor_pop_traceback(); - return (-1); + cmor_handle_error(msg, CMOR_NORMAL); + ierr = -1; } else { cmor_get_cur_dataset_attribute(BRANCH_METHOD, szBranchMethod); @@ -1165,19 +1163,19 @@ int cmor_CV_checkParentExpID(cmor_CV_def_t * CV) "Your input attribute %s is an empty string\n! " "Please describe the spin-up procedure as defined \n! " "in CMIP6 documentations.\n! ", BRANCH_METHOD); + cmor_handle_error(msg, CMOR_NORMAL); + ierr = -1; } } // branch_time_in_child - if (cmor_has_cur_dataset_attribute(BRANCH_TIME_IN_CHILD)) { + if (cmor_has_cur_dataset_attribute(BRANCH_TIME_IN_CHILD) != 0) { snprintf(msg, CMOR_MAX_STRING, "Your input attribute \"%s\" is not defined \n! " "properly for %s \n! " "Please refer to the CMIP6 documentations.\n! ", BRANCH_TIME_IN_CHILD, szExperiment_ID); - cmor_handle_error(msg, CMOR_CRITICAL); - cmor_pop_traceback(); - return (-1); - + cmor_handle_error(msg, CMOR_NORMAL); + ierr = -1; } else { cmor_get_cur_dataset_attribute(BRANCH_TIME_IN_CHILD, szBranchTimeInChild); @@ -1187,23 +1185,19 @@ int cmor_CV_checkParentExpID(cmor_CV_def_t * CV) "Your input attribute branch_time_in_child \"%s\" " "is not a double floating point \n! ", szBranchTimeInChild); - cmor_handle_error(msg, CMOR_CRITICAL); - cmor_pop_traceback(); - return (-1); + cmor_handle_error(msg, CMOR_NORMAL); + ierr = -1; } } - // branch_time_in_parent - if (cmor_has_cur_dataset_attribute(BRANCH_TIME_IN_PARENT)) { + if (cmor_has_cur_dataset_attribute(BRANCH_TIME_IN_PARENT) != 0) { snprintf(msg, CMOR_MAX_STRING, "Your input attribute \"%s\" is not defined \n! " "properly for %s \n! " "Please refer to the CMIP6 documentations.\n! ", BRANCH_TIME_IN_PARENT, szExperiment_ID); - cmor_handle_error(msg, CMOR_CRITICAL); - cmor_pop_traceback(); - return (-1); - + cmor_handle_error(msg, CMOR_NORMAL); + ierr = -1; } else { cmor_get_cur_dataset_attribute(BRANCH_TIME_IN_PARENT, szBranchTimeInParent); @@ -1213,22 +1207,19 @@ int cmor_CV_checkParentExpID(cmor_CV_def_t * CV) "Your input attribute branch_time_in_parent \"%s\" " "is not a double floating point \n! ", szBranchTimeInParent); - cmor_handle_error(msg, CMOR_CRITICAL); - cmor_pop_traceback(); - return (-1); + cmor_handle_error(msg, CMOR_NORMAL); + ierr = -1; } } // parent_time_units - if (cmor_has_cur_dataset_attribute(PARENT_TIME_UNITS)) { + if (cmor_has_cur_dataset_attribute(PARENT_TIME_UNITS) != 0) { snprintf(msg, CMOR_MAX_STRING, "Your input attribute \"%s\" is not defined \n! " "properly for %s \n! " "Please refer to the CMIP6 documentations.\n! ", PARENT_TIME_UNITS, szExperiment_ID); - cmor_handle_error(msg, CMOR_CRITICAL); - cmor_pop_traceback(); - return (-1); - + cmor_handle_error(msg, CMOR_NORMAL); + ierr = -1; } else { char template[CMOR_MAX_STRING]; int reti; @@ -1245,36 +1236,30 @@ int cmor_CV_checkParentExpID(cmor_CV_def_t * CV) template); regfree(®ex); cmor_handle_error(msg, CMOR_NORMAL); - cmor_pop_traceback(); - return (-1); - } -/* -------------------------------------------------------------------- */ -/* Execute regular expression */ -/* -------------------------------------------------------------------- */ - reti = regexec(®ex, szParentTimeUnits, 0, NULL, 0); - if (reti == REG_NOMATCH) { - snprintf(msg, CMOR_MAX_STRING, - "Your \"%s\" set to \"%s\" is invalid. \n! " - "Please refer to the CMIP6 documentations.\n! ", - PARENT_TIME_UNITS, szParentTimeUnits); - regfree(®ex); - cmor_handle_error(msg, CMOR_NORMAL); - cmor_pop_traceback(); - return (-1); + ierr = -1; + } else { + // Execute regular expression + reti = regexec(®ex, szParentTimeUnits, 0, NULL, 0); + if (reti == REG_NOMATCH) { + snprintf(msg, CMOR_MAX_STRING, + "Your \"%s\" set to \"%s\" is invalid. \n! " + "Please refer to the CMIP6 documentations.\n! ", + PARENT_TIME_UNITS, szParentTimeUnits); + cmor_handle_error(msg, CMOR_NORMAL); + ierr = -1; + } } regfree(®ex); } // parent_variant_label - if (cmor_has_cur_dataset_attribute(PARENT_VARIANT_LABEL)) { + if (cmor_has_cur_dataset_attribute(PARENT_VARIANT_LABEL) != 0) { snprintf(msg, CMOR_MAX_STRING, "Your input attribute \"%s\" is not defined \n! " "properly for %s \n! " "Please refer to the CMIP6 documentations.\n! ", PARENT_VARIANT_LABEL, szExperiment_ID); - cmor_handle_error(msg, CMOR_CRITICAL); - cmor_pop_traceback(); - return (-1); - + cmor_handle_error(msg, CMOR_NORMAL); + ierr = -1; } else { char template[CMOR_MAX_STRING]; int reti; @@ -1289,24 +1274,19 @@ int cmor_CV_checkParentExpID(cmor_CV_def_t * CV) "You regular expression \"%s\" is invalid. \n! " "Please refer to the CMIP6 documentations.\n! ", template); - regfree(®ex); - cmor_handle_error(msg, CMOR_NORMAL); - cmor_pop_traceback(); - return (-1); - } -/* -------------------------------------------------------------------- */ -/* Execute regular expression */ -/* -------------------------------------------------------------------- */ - reti = regexec(®ex, szParentVariantLabel, 0, NULL, 0); - if (reti == REG_NOMATCH) { - snprintf(msg, CMOR_MAX_STRING, - "You \"%s\" set to \"%s\" is invalid. \n! " - "Please refer to the CMIP6 documentations.\n! ", - PARENT_VARIANT_LABEL, szParentVariantLabel); - regfree(®ex); cmor_handle_error(msg, CMOR_NORMAL); - cmor_pop_traceback(); - return (-1); + ierr = -1; + } else { + // Execute regular expression + reti = regexec(®ex, szParentVariantLabel, 0, NULL, 0); + if (reti == REG_NOMATCH) { + snprintf(msg, CMOR_MAX_STRING, + "You \"%s\" set to \"%s\" is invalid. \n! " + "Please refer to the CMIP6 documentations.\n! ", + PARENT_VARIANT_LABEL, szParentVariantLabel); + cmor_handle_error(msg, CMOR_NORMAL); + ierr = -1; + } } regfree(®ex); } @@ -1318,9 +1298,7 @@ int cmor_CV_checkParentExpID(cmor_CV_def_t * CV) "Please refer to the CMIP6 documentations.\n! ", PARENT_SOURCE_ID, szExperiment_ID); cmor_handle_error(msg, CMOR_NORMAL); - cmor_pop_traceback(); - return (-1); - + ierr = -1; } else { cmor_get_cur_dataset_attribute(PARENT_SOURCE_ID, szParentSourceId); @@ -1330,24 +1308,22 @@ int cmor_CV_checkParentExpID(cmor_CV_def_t * CV) "Your \"source_id\" key could not be found in\n! " "your Control Vocabulary file.(%s)\n! ", CV_Filename); - - cmor_handle_error(msg, CMOR_NORMAL); - cmor_pop_traceback(); - return (-1); - } - // Get specified experiment - cmor_get_cur_dataset_attribute(PARENT_SOURCE_ID, - szParentSourceId); - CV_source = cmor_CV_search_child_key(CV_source_id, - szParentSourceId); - if (CV_source == NULL) { - snprintf(msg, CMOR_MAX_STRING, - "Your parent_source_id \"%s\" defined in your input file\n! " - "could not be found in your Control Vocabulary file.(%s)\n! ", - szParentSourceId, CV_Filename); cmor_handle_error(msg, CMOR_NORMAL); - cmor_pop_traceback(); - return (-1); + ierr = -1; + } else { + // Get specified experiment + cmor_get_cur_dataset_attribute(PARENT_SOURCE_ID, + szParentSourceId); + CV_source = cmor_CV_search_child_key(CV_source_id, + szParentSourceId); + if (CV_source == NULL) { + snprintf(msg, CMOR_MAX_STRING, + "Your parent_source_id \"%s\" defined in your input file\n! " + "could not be found in your Control Vocabulary file.(%s)\n! ", + szParentSourceId, CV_Filename); + cmor_handle_error(msg, CMOR_NORMAL); + ierr = -1; + } } } // parent_mip_era @@ -1357,10 +1333,8 @@ int cmor_CV_checkParentExpID(cmor_CV_def_t * CV) "properly for %s \n! " "Please refer to the CMIP6 documentations.\n! ", PARENT_MIP_ERA, szExperiment_ID); - cmor_handle_error(msg, CMOR_CRITICAL); - cmor_pop_traceback(); - return (-1); - + cmor_handle_error(msg, CMOR_NORMAL); + ierr = -1; } else { cmor_get_cur_dataset_attribute(PARENT_MIP_ERA, szValue); if (strcmp(CMIP6, szValue) != 0) { @@ -1377,7 +1351,7 @@ int cmor_CV_checkParentExpID(cmor_CV_def_t * CV) } } cmor_pop_traceback(); - return (0); + return (ierr); } /************************************************************************/