Skip to content

Commit

Permalink
Merge pull request #600 from PCMDI/245_return_error_num_from_cmor_cv
Browse files Browse the repository at this point in the history
Fixing issues in cmor_CV.c
  • Loading branch information
mauzey1 authored May 15, 2020
2 parents db6784f + a011867 commit db9a348
Showing 1 changed file with 83 additions and 109 deletions.
192 changes: 83 additions & 109 deletions Src/cmor_CV.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) ==
Expand All @@ -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,
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -1045,18 +1043,24 @@ 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! "
"for your experiment \"%s\"\n!\n! "
"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);
}
Expand Down Expand Up @@ -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
Expand All @@ -1113,18 +1114,16 @@ 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,
PARENT_ACTIVITY_ID);
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,
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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;
Expand All @@ -1245,36 +1236,30 @@ int cmor_CV_checkParentExpID(cmor_CV_def_t * CV)
template);
regfree(&regex);
cmor_handle_error(msg, CMOR_NORMAL);
cmor_pop_traceback();
return (-1);
}
/* -------------------------------------------------------------------- */
/* Execute regular expression */
/* -------------------------------------------------------------------- */
reti = regexec(&regex, 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(&regex);
cmor_handle_error(msg, CMOR_NORMAL);
cmor_pop_traceback();
return (-1);
ierr = -1;
} else {
// Execute regular expression
reti = regexec(&regex, 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(&regex);
}
// 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;
Expand All @@ -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(&regex);
cmor_handle_error(msg, CMOR_NORMAL);
cmor_pop_traceback();
return (-1);
}
/* -------------------------------------------------------------------- */
/* Execute regular expression */
/* -------------------------------------------------------------------- */
reti = regexec(&regex, 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(&regex);
cmor_handle_error(msg, CMOR_NORMAL);
cmor_pop_traceback();
return (-1);
ierr = -1;
} else {
// Execute regular expression
reti = regexec(&regex, 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(&regex);
}
Expand All @@ -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);
Expand All @@ -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
Expand All @@ -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) {
Expand All @@ -1377,7 +1351,7 @@ int cmor_CV_checkParentExpID(cmor_CV_def_t * CV)
}
}
cmor_pop_traceback();
return (0);
return (ierr);
}

/************************************************************************/
Expand Down

0 comments on commit db9a348

Please sign in to comment.