diff --git a/Src/cdTime/timeArith.c b/Src/cdTime/timeArith.c index e64a45f9..c7a8c481 100644 --- a/Src/cdTime/timeArith.c +++ b/Src/cdTime/timeArith.c @@ -157,7 +157,7 @@ CdDivDelTime(double begEtm, double endEtm, CdDeltaTime delTime, CdTimeType timeT range = (ehtime.month - bhtime.month); if(range < 0) range += 12; } - *nDel = abs(range)/delMonths; + *nDel = labs(range)/delMonths; break; case CdWeek: case CdDay: case CdHour: case CdMinute: case CdSecond: delHours *= (double)delTime.count; diff --git a/Src/cmor.c b/Src/cmor.c index a8e60f6d..9b02b0e1 100644 --- a/Src/cmor.c +++ b/Src/cmor.c @@ -1,5 +1,6 @@ #include #include +#include #include #include #include @@ -129,7 +130,7 @@ int bAppendMode = 0; volatile sig_atomic_t stop = 0; /**************************************************************************/ -/* reset signal code +/* reset signal code */ /**************************************************************************/ int cmor_get_terminate_signal() { return CMOR_TERMINATE_SIGNAL; @@ -259,8 +260,8 @@ void cmor_cat_unique_string(char *dest, char *src) /**************************************************************************/ int cmor_check_forcing_validity(int table_id, char *value) { - int i, j, n, found = 0; - char msg[CMOR_MAX_STRING]; + int i, j, n, msg_len, found = 0; + char *msg; char astr[CMOR_MAX_STRING]; char **bstr; @@ -296,17 +297,34 @@ int cmor_check_forcing_validity(int table_id, char *value) } } if (found == 0) { - sprintf(msg, "forcing attribute elt %i (%s) is not valid for\n! " - "table %s, valid values are:", i, bstr[i], - cmor_tables[table_id].szTable_id); + msg_len = 0; for (j = 0; j < cmor_tables[table_id].nforcings; j++) { - strncat(msg, " ", CMOR_MAX_STRING - strlen(msg)); - strncat(msg, cmor_tables[table_id].forcings[j], - CMOR_MAX_STRING - strlen(msg)); - strncat(msg, ",", CMOR_MAX_STRING - strlen(msg)); + if(j == 0) { + msg_len += snprintf(NULL, 0, " %s", + cmor_tables[table_id].forcings[j]); + } else { + msg_len += snprintf(NULL, 0, ", %s", + cmor_tables[table_id].forcings[j]); + } + } + msg_len += 1; + msg = (char *)malloc(msg_len * sizeof(char)); + msg_len = 0; + for (j = 0; j < cmor_tables[table_id].nforcings; j++) { + if(j == 0) { + msg_len += sprintf(&msg[msg_len], "%s", + cmor_tables[table_id].forcings[j]); + } else { + msg_len += sprintf(&msg[msg_len], ", %s", + cmor_tables[table_id].forcings[j]); + } } - msg[strlen(msg) - 1] = '\0'; - cmor_handle_error(msg, CMOR_NORMAL); + cmor_handle_error_variadic( + "forcing attribute elt %i (%s) is not valid for\n! " + "table %s, valid values are: %s", + CMOR_NORMAL, + i, bstr[i], cmor_tables[table_id].szTable_id, msg); + free(msg); cmor_pop_traceback(); return (-1); } @@ -406,16 +424,14 @@ void cmor_is_setup(void) { extern int CMOR_HAS_BEEN_SETUP; - char msg[CMOR_MAX_STRING]; - extern void cmor_handle_error(char error_msg[CMOR_MAX_STRING], int level); stop = 0; cmor_add_traceback("cmor_is_setup"); if (CMOR_HAS_BEEN_SETUP == 0) { - snprintf(msg, CMOR_MAX_STRING, - "You need to run cmor_setup before calling any cmor_function"); - cmor_handle_error(msg, CMOR_NOT_SETUP); + cmor_handle_error_variadic( + "You need to run cmor_setup before calling any cmor_function", + CMOR_NOT_SETUP); } cmor_pop_traceback(); return; @@ -487,16 +503,14 @@ int cmor_prep_units(char *uunits, extern ut_system *ut_read; char local_unit[CMOR_MAX_STRING]; - char msg[CMOR_MAX_STRING]; - extern void cmor_handle_error(char error_msg[CMOR_MAX_STRING], int level); cmor_add_traceback("cmor_prep_units"); cmor_is_setup(); *cmor_units = ut_parse(ut_read, cunits, UT_ASCII); if (ut_get_status() != UT_SUCCESS) { - snprintf(msg, CMOR_MAX_STRING, - "Udunits: analyzing units from cmor (%s)", cunits); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "Udunits: analyzing units from cmor (%s)", + CMOR_CRITICAL, cunits); cmor_pop_traceback(); return (1); } @@ -506,18 +520,17 @@ int cmor_prep_units(char *uunits, *user_units = ut_parse(ut_read, local_unit, UT_ASCII); if (ut_get_status() != UT_SUCCESS) { - snprintf(msg, CMOR_MAX_STRING, - "Udunits: analyzing units from user (%s)", local_unit); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "Udunits: analyzing units from user (%s)", + CMOR_CRITICAL, local_unit); cmor_pop_traceback(); return (1); } if (ut_are_convertible(*cmor_units, *user_units) == 0) { - snprintf(msg, CMOR_MAX_STRING, - "Udunits: cmor and user units are incompatible: %s and %s", - cunits, uunits); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "Udunits: cmor and user units are incompatible: %s and %s", + CMOR_CRITICAL, cunits, uunits); cmor_pop_traceback(); return (1); } @@ -528,10 +541,9 @@ int cmor_prep_units(char *uunits, } if (ut_get_status() != UT_SUCCESS) { - snprintf(msg, CMOR_MAX_STRING, - "Udunits: Error getting converter from %s to %s", cunits, - local_unit); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "Udunits: Error getting converter from %s to %s", + CMOR_CRITICAL, cunits, local_unit); cmor_pop_traceback(); return (1); } @@ -568,18 +580,16 @@ int cmor_have_NetCDF41min(void) } /************************************************************************/ -/* cmor_handle_error() */ +/* cmor_handle_error_internal() */ /************************************************************************/ -void cmor_handle_error(char error_msg[CMOR_MAX_STRING], int level) +void cmor_handle_error_internal(char *error_msg, int level) { int i; - char msg[CMOR_MAX_STRING]; extern FILE *output_logfile; if (output_logfile == NULL) output_logfile = stderr; - msg[0] = '\0'; if (CMOR_VERBOSITY != CMOR_QUIET) { fprintf(output_logfile, "\n"); } @@ -603,8 +613,6 @@ void cmor_handle_error(char error_msg[CMOR_MAX_STRING], int level) #ifdef COLOREDOUTPUT fprintf(output_logfile, "%c[%d;%d;%dm", 0X1B, 1, 34, 47); #endif - - snprintf(msg, CMOR_MAX_STRING, "! Warning: %s", error_msg); } } else { cmor_nerrors++; @@ -625,8 +633,6 @@ void cmor_handle_error(char error_msg[CMOR_MAX_STRING], int level) #ifdef COLOREDOUTPUT fprintf(output_logfile, "%c[%d;%d;%dm", 0X1B, 1, 31, 47); #endif - - snprintf(msg, CMOR_MAX_STRING, "! Error: %s", error_msg); } // fprintf(stderr, "%s ERROR LEVEL %d\n", error_msg, level); if (CMOR_VERBOSITY != CMOR_QUIET || level != CMOR_WARNING) { @@ -635,7 +641,12 @@ void cmor_handle_error(char error_msg[CMOR_MAX_STRING], int level) } fprintf(output_logfile, "\n"); fprintf(output_logfile, "!\n"); - fprintf(output_logfile, "%s\n", msg); + + if (level == CMOR_WARNING) + fprintf(output_logfile, "! Warning: %s\n", error_msg); + else + fprintf(output_logfile, "! Error: %s\n", error_msg); + fprintf(output_logfile, "!\n"); for (i = 0; i < 25; i++) @@ -661,11 +672,66 @@ void cmor_handle_error(char error_msg[CMOR_MAX_STRING], int level) fflush(output_logfile); } -void cmor_handle_error_var(char error_msg[CMOR_MAX_STRING], int level, - int var_id) +void cmor_handle_error(char *error_msg, int level) +{ + cmor_handle_error_internal(error_msg, level); +} + +void cmor_handle_error_variadic(char *error_msg, int level, ...) +{ + va_list args; + size_t size; + char *msg; + + if (output_logfile == NULL) + output_logfile = stderr; + + va_start (args, level); + size = vsnprintf(NULL, 0, error_msg, args); + va_end (args); + + size++; + msg = (char *)malloc(size*sizeof(char)); + + va_start (args, level); + vsnprintf(msg, size, error_msg, args); + va_end (args); + + cmor_handle_error_internal(msg, level); + + free(msg); +} + +void cmor_handle_error_var(char *error_msg, int level, int var_id) +{ + cmor_vars[var_id].error = 1; + cmor_handle_error_internal(error_msg, level); +} + +void cmor_handle_error_var_variadic(char *error_msg, int level, int var_id, ...) { + va_list args; + size_t size; + char *msg; + + if (output_logfile == NULL) + output_logfile = stderr; + + va_start (args, var_id); + size = vsnprintf(NULL, 0, error_msg, args); + va_end (args); + + size++; + msg = (char *)malloc(size*sizeof(char)); + + va_start (args, var_id); + vsnprintf(msg, size, error_msg, args); + va_end (args); + cmor_vars[var_id].error = 1; - cmor_handle_error(error_msg, level); + cmor_handle_error_internal(msg, level); + + free(msg); } /************************************************************************/ @@ -816,16 +882,16 @@ int cmor_setup(char *path, if (cmor_have_NetCDF4() == 0) { USE_NETCDF_4 = 1; if (cmor_have_NetCDF41min() != 0) { - sprintf(msg, + cmor_handle_error_variadic( "You are using a wrong version of NetCDF4 (%s), \n! " - "you need 4.1", nc_inq_libvers()); - cmor_handle_error(msg, CMOR_CRITICAL); + "you need 4.1", + CMOR_CRITICAL, nc_inq_libvers()); } } else { - sprintf(msg, + cmor_handle_error_variadic( "You are using a wrong version of NetCDF (%s), you need \n! " - "4.1 or an earlier netCDF release.", nc_inq_libvers()); - cmor_handle_error(msg, CMOR_CRITICAL); + "4.1 or an earlier netCDF release.", + CMOR_CRITICAL, nc_inq_libvers()); } did_history = 0; CMOR_HAS_BEEN_SETUP = 1; @@ -846,10 +912,9 @@ int cmor_setup(char *path, if (*mode != CMOR_EXIT_ON_WARNING && *mode != CMOR_EXIT_ON_MAJOR && *mode != CMOR_NORMAL) { - snprintf(msg, CMOR_MAX_STRING, + cmor_handle_error_variadic( "exit mode can be either CMOR_EXIT_ON_WARNING CMOR_NORMAL " - "or CMOR_EXIT_ON_MAJOR"); - cmor_handle_error(msg, CMOR_CRITICAL); + "or CMOR_EXIT_ON_MAJOR", CMOR_CRITICAL); } CMOR_MODE = *mode; @@ -862,9 +927,9 @@ int cmor_setup(char *path, } else { if (*verbosity != CMOR_QUIET && *verbosity != CMOR_NORMAL) { - snprintf(msg, CMOR_MAX_STRING, - "verbosity mode can be either CMOR_QUIET or CMOR_NORMAL"); - cmor_handle_error(msg, CMOR_NORMAL); + cmor_handle_error_variadic( + "verbosity mode can be either CMOR_QUIET or CMOR_NORMAL", + CMOR_NORMAL); } CMOR_VERBOSITY = *verbosity; } @@ -895,25 +960,24 @@ int cmor_setup(char *path, fclose(output_logfile); rename(tmplogfile, msg); - snprintf(msg2, CMOR_MAX_STRING, - "Logfile %s already exist.\n! Renamed to: %s", tmplogfile, - msg); output_logfile = NULL; output_logfile = fopen(tmplogfile, "w"); if (output_logfile == NULL) { - snprintf(msg2, CMOR_MAX_STRING, - "Could not open logfile %s for writing", tmplogfile); - cmor_handle_error(msg2, CMOR_CRITICAL); + cmor_handle_error_variadic( + "Could not open logfile %s for writing", + CMOR_CRITICAL, tmplogfile); } - cmor_handle_error(msg2, CMOR_WARNING); + cmor_handle_error_variadic( + "Logfile %s already exist.\n! Renamed to: %s", + CMOR_WARNING, tmplogfile, msg); } else { output_logfile = fopen(tmplogfile, "w"); if (output_logfile == NULL) { - snprintf(msg2, CMOR_MAX_STRING, - "Could not open logfile %s for writing", tmplogfile); - cmor_handle_error(msg2, CMOR_CRITICAL); + cmor_handle_error_variadic( + "Could not open logfile %s for writing", + CMOR_CRITICAL, tmplogfile); } } } @@ -925,12 +989,11 @@ int cmor_setup(char *path, if (*netcdf != CMOR_PRESERVE_4 && *netcdf != CMOR_APPEND_4 && *netcdf != CMOR_REPLACE_4 && *netcdf != CMOR_PRESERVE_3 && *netcdf != CMOR_APPEND_3 && *netcdf != CMOR_REPLACE_3) { - snprintf(msg, CMOR_MAX_STRING, + cmor_handle_error_variadic( "file mode can be either CMOR_PRESERVE, CMOR_APPEND, " "CMOR_REPLACE, CMOR_PRESERVE_4, CMOR_APPEND_4, " "CMOR_REPLACE_4, CMOR_PRESERVE_3, CMOR_APPEND_3 or " - "CMOR_REPLACE_3"); - cmor_handle_error(msg, CMOR_CRITICAL); + "CMOR_REPLACE_3", CMOR_CRITICAL); } CMOR_NETCDF_MODE = *netcdf; @@ -940,10 +1003,9 @@ int cmor_setup(char *path, if (((CMOR_NETCDF_MODE == CMOR_PRESERVE_4) || (CMOR_NETCDF_MODE == CMOR_REPLACE_4) || (CMOR_NETCDF_MODE == CMOR_APPEND_4)) && (USE_NETCDF_4 == 0)) { - sprintf(msg, + cmor_handle_error_variadic( "You are trying to use a NetCDF4 mode but linked against " - "NetCDF3 libraries"); - cmor_handle_error(msg, CMOR_CRITICAL); + "NetCDF3 libraries", CMOR_CRITICAL); } @@ -1013,9 +1075,9 @@ int cmor_setup(char *path, if ((CMOR_CREATE_SUBDIRECTORIES != 1) && (CMOR_CREATE_SUBDIRECTORIES != 0)) { - snprintf(msg, CMOR_MAX_STRING, - "cmor_setup: create_subdirectories must be 0 or 1"); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "cmor_setup: create_subdirectories must be 0 or 1", + CMOR_CRITICAL); } /* -------------------------------------------------------------------- */ @@ -1030,8 +1092,8 @@ int cmor_setup(char *path, ut_read = ut_read_xml(NULL); if (ut_get_status() != UT_SUCCESS) { - snprintf(msg, CMOR_MAX_STRING, "Udunits: Error reading units system"); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "Udunits: Error reading units system", CMOR_CRITICAL); } ut_set_error_message_handler(ut_ignore); @@ -1043,18 +1105,16 @@ int cmor_setup(char *path, newequnit = ut_new_base_unit(ut_read); if (ut_get_status() != UT_SUCCESS) { - snprintf(msg, CMOR_MAX_STRING, - "Udunits: creating dimlessnew base unit"); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "Udunits: creating dimlessnew base unit", CMOR_CRITICAL); } myutstatus = ut_map_name_to_unit("eq", UT_ASCII, newequnit); ut_free(newequnit); if (myutstatus != UT_SUCCESS) { - snprintf(msg, CMOR_MAX_STRING, - "Udunits: Error mapping dimless 'eq' unit"); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "Udunits: Error mapping dimless 'eq' unit", CMOR_CRITICAL); } if (dimlessunit != NULL) @@ -1063,15 +1123,15 @@ int cmor_setup(char *path, dimlessunit = ut_new_dimensionless_unit(ut_read); if (ut_get_status() != UT_SUCCESS) { - snprintf(msg, CMOR_MAX_STRING, "Udunits: creating dimless unit"); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "Udunits: creating dimless unit", CMOR_CRITICAL); } myutstatus = ut_map_name_to_unit("dimless", UT_ASCII, dimlessunit); if (myutstatus != UT_SUCCESS) { - snprintf(msg, CMOR_MAX_STRING, "Udunits: Error mapping dimless unit"); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "Udunits: Error mapping dimless unit", CMOR_CRITICAL); } if (perunit != NULL) @@ -1079,13 +1139,13 @@ int cmor_setup(char *path, perunit = ut_scale(.01, dimlessunit); if (ut_get_status() != UT_SUCCESS) { - snprintf(msg, CMOR_MAX_STRING, "Udunits: Error creating percent unit"); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "Udunits: Error creating percent unit", CMOR_CRITICAL); } myutstatus = ut_map_name_to_unit("%", UT_ASCII, perunit); if (myutstatus != UT_SUCCESS) { - snprintf(msg, CMOR_MAX_STRING, "Udunits: Error mapping percent unit"); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "Udunits: Error mapping percent unit", CMOR_CRITICAL); } // ----------------------- // Create "psu" unit @@ -1096,8 +1156,8 @@ int cmor_setup(char *path, psuunit = ut_new_dimensionless_unit(ut_read); if (ut_get_status() != UT_SUCCESS) { - snprintf(msg, CMOR_MAX_STRING, "Udunits: creating psuunit unit"); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "Udunits: creating psuunit unit", CMOR_CRITICAL); } if (perunit != NULL) @@ -1106,8 +1166,8 @@ int cmor_setup(char *path, myutstatus = ut_map_name_to_unit("psu", UT_ASCII, perunit); if (myutstatus != UT_SUCCESS) { - snprintf(msg, CMOR_MAX_STRING, "Udunits: Error mapping psu unit"); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "Udunits: Error mapping psu unit", CMOR_CRITICAL); } // ----------------------- // Create "PSS-78" unit @@ -1118,8 +1178,8 @@ int cmor_setup(char *path, pss78unit = ut_new_dimensionless_unit(ut_read); if (ut_get_status() != UT_SUCCESS) { - snprintf(msg, CMOR_MAX_STRING, "Udunits: creating dimless unit"); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "Udunits: creating dimless unit", CMOR_CRITICAL); } if (perunit != NULL) @@ -1128,8 +1188,8 @@ int cmor_setup(char *path, myutstatus = ut_map_name_to_unit("PSS", UT_UTF8, perunit); if (myutstatus != UT_SUCCESS) { - snprintf(msg, CMOR_MAX_STRING, "Udunits: Error mapping PSS-78 unit"); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "Udunits: Error mapping PSS-78 unit", CMOR_CRITICAL); } // ----------------------- // Create "Practical Salinity Scale 78" unit @@ -1140,9 +1200,9 @@ int cmor_setup(char *path, PracticalSSunit = ut_new_dimensionless_unit(ut_read); if (ut_get_status() != UT_SUCCESS) { - snprintf(msg, CMOR_MAX_STRING, - "Udunits: creating Practical Salinity Scale 78 unit"); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "Udunits: creating Practical Salinity Scale 78 unit", + CMOR_CRITICAL); } if (perunit != NULL) ut_free(perunit); @@ -1151,9 +1211,9 @@ int cmor_setup(char *path, ut_map_name_to_unit("practical_salinity_scale_", UT_UTF8, perunit); if (myutstatus != UT_SUCCESS) { - snprintf(msg, CMOR_MAX_STRING, - "Udunits: Error mapping Practical Salinity Scale 78 unit"); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "Udunits: Error mapping Practical Salinity Scale 78 unit", + CMOR_CRITICAL); } ut_free(PracticalSSunit); ut_free(pss78unit); @@ -1227,7 +1287,6 @@ json_object *cmor_open_inpathFile(char *szFilename) { FILE *table_file; char szFullName[CMOR_MAX_STRING]; - char msg[CMOR_MAX_STRING]; char *buffer; int nFileSize; json_object *oJSON; @@ -1249,9 +1308,9 @@ json_object *cmor_open_inpathFile(char *szFilename) } if (table_file == NULL) { - snprintf(szFullName, CMOR_MAX_STRING, "Could not find file: %s", - szFilename); - cmor_handle_error(szFullName, CMOR_NORMAL); + cmor_handle_error_variadic( + "Could not find file: %s", + CMOR_NORMAL, szFilename); cmor_ntables -= 1; cmor_pop_traceback(); return (NULL); @@ -1274,10 +1333,9 @@ json_object *cmor_open_inpathFile(char *szFilename) if (buffer[0] != '{') { free(buffer); buffer = NULL; - snprintf(msg, CMOR_MAX_STRING, - "Could not understand file \"%s\" Is this a JSON CMOR table?", - szFullName); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "Could not understand file \"%s\" Is this a JSON CMOR table?", + CMOR_CRITICAL, szFullName); cmor_ntables--; cmor_pop_traceback(); return (NULL); @@ -1288,9 +1346,9 @@ json_object *cmor_open_inpathFile(char *szFilename) if (nFileSize != read_size) { free(buffer); buffer = NULL; - snprintf(msg, CMOR_MAX_STRING, - "Could not read file %s check file permission", szFullName); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "Could not read file %s check file permission", + CMOR_CRITICAL, szFullName); cmor_ntables--; cmor_pop_traceback(); return (NULL); @@ -1301,11 +1359,11 @@ json_object *cmor_open_inpathFile(char *szFilename) /* -------------------------------------------------------------------- */ oJSON = json_tokener_parse(buffer); if (oJSON == NULL) { - snprintf(msg, CMOR_MAX_STRING, + cmor_handle_error_variadic( "Please validate JSON File!\n! " "USE: http://jsonlint.com/\n! " - "Syntax Error in file: %s\n! " "%s", szFullName, buffer); - cmor_handle_error(msg, CMOR_CRITICAL); + "Syntax Error in file: %s\n! " "%s", + CMOR_CRITICAL, szFullName, buffer); } cmor_pop_traceback(); if (buffer != NULL) { @@ -1421,7 +1479,6 @@ int cmor_dataset_json(char *ressource) int cmor_put_nc_num_attribute(int ncid, int nc_var_id, char *name, char type, double value, char *var_name) { - char msg[CMOR_MAX_STRING]; int ierr; cmor_add_traceback("cmor_put_nc_num_attribute"); @@ -1436,10 +1493,11 @@ int cmor_put_nc_num_attribute(int ncid, int nc_var_id, char *name, char type, ierr = nc_put_att_double(ncid, nc_var_id, name, NC_DOUBLE, 1, &value); } if (ierr != NC_NOERR) { - snprintf(msg, CMOR_MAX_STRING, - "NetCDF Error (%i: %s) setting numerical attribute" - " %s on variable %s", ierr, nc_strerror(ierr), name, var_name); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "NetCDF Error (%i: %s) setting numerical attribute" + " %s on variable %s", + CMOR_CRITICAL, + ierr, nc_strerror(ierr), name, var_name); } cmor_pop_traceback(); return (ierr); @@ -1453,7 +1511,6 @@ int cmor_put_nc_char_attribute(int ncid, char *name, char *value, char *var_name) { int k, ierr; - char msg[CMOR_MAX_STRING]; ierr = 0; cmor_add_traceback("cmor_put_nc_char_attribute"); @@ -1462,11 +1519,11 @@ int cmor_put_nc_char_attribute(int ncid, value[k] = '\0'; ierr = nc_put_att_text(ncid, nc_var_id, name, k + 1, value); if (ierr != NC_NOERR) { - snprintf(msg, CMOR_MAX_STRING, - "NetCDF Error (%i: %s) setting attribute: '%s' " - "on variable (%s)", - ierr, nc_strerror(ierr), name, var_name); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "NetCDF Error (%i: %s) setting attribute: '%s' " + "on variable (%s)", + CMOR_CRITICAL, + ierr, nc_strerror(ierr), name, var_name); } } cmor_pop_traceback(); @@ -1504,11 +1561,11 @@ int cmor_set_cur_dataset_attribute_internal(char *name, char *value, cmor_trim_string(value, msg); if ((int)strlen(name) > CMOR_MAX_STRING) { - snprintf(msg, CMOR_MAX_STRING, - "Dataset error, attribute name: %s; length (%i) is " - "greater than limit: %i", - name, (int)strlen(name), CMOR_MAX_STRING); - cmor_handle_error(msg, CMOR_NORMAL); + cmor_handle_error_variadic( + "Dataset error, attribute name: %s; length (%i) is " + "greater than limit: %i", + CMOR_NORMAL, + name, (int)strlen(name), CMOR_MAX_STRING); cmor_pop_traceback(); return (1); } @@ -1534,10 +1591,9 @@ int cmor_set_cur_dataset_attribute_internal(char *name, char *value, cmor_pop_traceback(); return (0); } else { - snprintf(msg, CMOR_MAX_STRING, - "Dataset error, required attribute %s was not " - "passed or blanked", name); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "Dataset error, required attribute %s was not " + "passed or blanked", CMOR_CRITICAL, name); cmor_pop_traceback(); return (1); } @@ -1556,11 +1612,11 @@ int cmor_set_cur_dataset_attribute_internal(char *name, char *value, } if (n >= CMOR_MAX_ATTRIBUTES) { - sprintf(msg, - "Setting dataset attribute: %s, we already have %i " - "elements set which is the max, this element won't be set", - name, CMOR_MAX_ELEMENTS); - cmor_handle_error(msg, CMOR_NORMAL); + cmor_handle_error_variadic( + "Setting dataset attribute: %s, we already have %i " + "elements set which is the max, this element won't be set", + CMOR_NORMAL, + name, CMOR_MAX_ELEMENTS); cmor_pop_traceback(); return (1); } @@ -1596,16 +1652,14 @@ int cmor_set_cur_dataset_attribute_internal(char *name, char *value, int cmor_get_cur_dataset_attribute(char *name, char *value) { int i, n; - char msg[CMOR_MAX_STRING]; extern cmor_dataset_def cmor_current_dataset; cmor_add_traceback("cmor_get_cur_dataset_attribute"); cmor_is_setup(); if (strlen(name) > CMOR_MAX_STRING) { - snprintf(msg, CMOR_MAX_STRING, - "Dataset: %s length is greater than limit: %i", - name, CMOR_MAX_STRING); - cmor_handle_error(msg, CMOR_NORMAL); + cmor_handle_error_variadic( + "Dataset: %s length is greater than limit: %i", + CMOR_NORMAL, name, CMOR_MAX_STRING); cmor_pop_traceback(); return (1); } @@ -1615,9 +1669,9 @@ int cmor_get_cur_dataset_attribute(char *name, char *value) n = i; } if (n == -1) { - snprintf(msg, CMOR_MAX_STRING, - "Dataset: current dataset does not have attribute : %s", name); - cmor_handle_error(msg, CMOR_NORMAL); + cmor_handle_error_variadic( + "Dataset: current dataset does not have attribute : %s", + CMOR_NORMAL, name); cmor_pop_traceback(); return (1); } @@ -1632,17 +1686,16 @@ int cmor_get_cur_dataset_attribute(char *name, char *value) int cmor_has_cur_dataset_attribute(char *name) { int i, n; - char msg[CMOR_MAX_STRING]; extern cmor_dataset_def cmor_current_dataset; cmor_add_traceback("cmor_has_cur_dataset_attribute"); cmor_is_setup(); if ((int)strlen(name) > CMOR_MAX_STRING) { - snprintf(msg, CMOR_MAX_STRING, - "Dataset: attribute name (%s) length\n! " - "(%i) is greater than limit: %i", - name, (int)strlen(name), CMOR_MAX_STRING); - cmor_handle_error(msg, CMOR_NORMAL); + cmor_handle_error_variadic( + "Dataset: attribute name (%s) length\n! " + "(%i) is greater than limit: %i", + CMOR_NORMAL, + name, (int)strlen(name), CMOR_MAX_STRING); cmor_pop_traceback(); return (1); } @@ -1678,19 +1731,19 @@ int cmor_outpath_exist(char *outpath) /* -------------------------------------------------------------------- */ if (stat(cmor_current_dataset.outpath, &buf) == 0) { if (S_ISREG(buf.st_mode) != 0) { - sprintf(msg, - "You defined your output directory to be: '%s',\n! " - "but it appears to be a regular file not a directory", - cmor_current_dataset.outpath); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "You defined your output directory to be: '%s',\n! " + "but it appears to be a regular file not a directory", + CMOR_CRITICAL, + cmor_current_dataset.outpath); cmor_pop_traceback(); return (1); } else if (S_ISDIR(buf.st_mode) == 0) { - sprintf(msg, - "You defined your output directory to be: '%s',\n! " - "but it appears to be a special file not a directory", - cmor_current_dataset.outpath); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "You defined your output directory to be: '%s',\n! " + "but it appears to be a special file not a directory", + CMOR_CRITICAL, + cmor_current_dataset.outpath); cmor_pop_traceback(); return (1); @@ -1705,11 +1758,11 @@ int cmor_outpath_exist(char *outpath) test_file = fopen(msg, "w"); if (test_file == NULL) { - sprintf(msg, - "You defined your output directory to be: '%s', but\n! " - "you do not have read/write permissions on it", - cmor_current_dataset.outpath); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "You defined your output directory to be: '%s', but\n! " + "you do not have read/write permissions on it", + CMOR_CRITICAL, + cmor_current_dataset.outpath); cmor_pop_traceback(); return (1); @@ -1719,32 +1772,32 @@ int cmor_outpath_exist(char *outpath) } } } else if (errno == ENOENT) { - sprintf(msg, - "You defined your output directory to be: '%s', but this\n! " - "directory does not exist. CMOR will create it!", - cmor_current_dataset.outpath); - cmor_handle_error(msg, CMOR_WARNING); + cmor_handle_error_variadic( + "You defined your output directory to be: '%s', but this\n! " + "directory does not exist. CMOR will create it!", + CMOR_WARNING, + cmor_current_dataset.outpath); /* -------------------------------------------------------------------- */ /* Create directory with 755 permission for user */ /* -------------------------------------------------------------------- */ ierr = mkdir(cmor_current_dataset.outpath, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); if (ierr != 0) { - sprintf(msg, - "CMOR was unable to create this directory %s\n! " - "You do not have write permissions!", - cmor_current_dataset.outpath); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "CMOR was unable to create this directory %s\n! " + "You do not have write permissions!", + CMOR_CRITICAL, + cmor_current_dataset.outpath); cmor_pop_traceback(); return (1); } } else if (errno == EACCES) { - sprintf(msg, - "You defined your output directory to be: '%s', but we\n! " - "cannot access it, please check permissions", - cmor_current_dataset.outpath); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "You defined your output directory to be: '%s', but we\n! " + "cannot access it, please check permissions", + CMOR_CRITICAL, + cmor_current_dataset.outpath); cmor_pop_traceback(); return (1); @@ -1801,15 +1854,15 @@ int cmor_convert_string_to_list(char *invalues, char type, void **target, else if (type == 'c') *target = (char **)malloc(j * sizeof(char *)); else { - snprintf(msg, CMOR_MAX_STRING, - "unknown conversion '%c' for list: %s", type, values); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "unknown conversion '%c' for list: %s", + CMOR_CRITICAL, type, values); } if (*target == NULL) { - snprintf(msg, CMOR_MAX_STRING, "mallocing '%c' for list: %s", - type, values); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "mallocing '%c' for list: %s", + CMOR_CRITICAL, type, values); } j = 0; @@ -1971,16 +2024,17 @@ int cmor_define_zfactors_vars(int var_id, int ncid, int *nc_dim, } } if (found == 0) { - snprintf(msg, CMOR_MAX_STRING, - "could not find the zfactor variable: %s. \n! " - "Please define zfactor before defining the\n! " - "variable %s (table %s).\n! \n! " - "Also zfactor dimensions must match variable's" - " dimensions.\n! ", ctmp, - cmor_vars[var_id].id, - cmor_tables[cmor_vars[var_id].ref_table_id]. - szTable_id); - cmor_handle_error_var(msg, CMOR_CRITICAL, var_id); + cmor_handle_error_var_variadic( + "could not find the zfactor variable: %s. \n! " + "Please define zfactor before defining the\n! " + "variable %s (table %s).\n! \n! " + "Also zfactor dimensions must match variable's" + " dimensions.\n! ", + CMOR_CRITICAL, var_id, + ctmp, + cmor_vars[var_id].id, + cmor_tables[cmor_vars[var_id].ref_table_id]. + szTable_id); cmor_pop_traceback(); return (1); } @@ -2030,16 +2084,17 @@ int cmor_define_zfactors_vars(int var_id, int ncid, int *nc_dim, } } if (found == 0) { - snprintf(msg, CMOR_MAX_STRING, - "variable \"%s\" (table: %s) has axis \"%s\"\n! " - "defined with formula terms, but term \"%s\"\n! " - "depends on axis \"%s\" which is not part of\n! " - "the variable", cmor_vars[var_id].id, - cmor_tables[cmor_vars[var_id].ref_table_id]. - szTable_id, - cmor_axes[cmor_vars[var_id].axes_ids[i]].id, ctmp, - cmor_axes[cmor_vars[l].axes_ids[k]].id); - cmor_handle_error_var(msg, CMOR_CRITICAL, var_id); + cmor_handle_error_var_variadic( + "variable \"%s\" (table: %s) has axis \"%s\"\n! " + "defined with formula terms, but term \"%s\"\n! " + "depends on axis \"%s\" which is not part of\n! " + "the variable", + CMOR_CRITICAL, var_id, + cmor_vars[var_id].id, + cmor_tables[cmor_vars[var_id].ref_table_id]. + szTable_id, + cmor_axes[cmor_vars[var_id].axes_ids[i]].id, ctmp, + cmor_axes[cmor_vars[l].axes_ids[k]].id); } } /* -------------------------------------------------------------------- */ @@ -2063,13 +2118,14 @@ int cmor_define_zfactors_vars(int var_id, int ncid, int *nc_dim, cmor_vars[l].ndims, &dim_holder[0], &nc_zfactors[lnzfactors]); if (ierr != NC_NOERR) { - snprintf(msg, CMOR_MAX_STRING, - "NC Error (%i: %s) for variable %s (table %s)\n! " - "error defining zfactor var: %i (%s)", ierr, - nc_strerror(ierr), cmor_vars[var_id].id, - cmor_tables[cmor_vars[var_id].ref_table_id]. - szTable_id, lnzfactors, cmor_vars[l].id); - cmor_handle_error_var(msg, CMOR_CRITICAL, var_id); + cmor_handle_error_var_variadic( + "NC Error (%i: %s) for variable %s (table %s)\n! " + "error defining zfactor var: %i (%s)", + CMOR_CRITICAL, var_id, + ierr, + nc_strerror(ierr), cmor_vars[var_id].id, + cmor_tables[cmor_vars[var_id].ref_table_id]. + szTable_id, lnzfactors, cmor_vars[l].id); } /* -------------------------------------------------------------------- */ @@ -2104,14 +2160,15 @@ int cmor_define_zfactors_vars(int var_id, int ncid, int *nc_dim, } if (ierr != NC_NOERR) { - snprintf(msg, CMOR_MAX_STRING, - "NCError (%i: %s) defining compression\n! " - "parameters for zfactor variable %s for\n! " - "variable '%s' (table %s)", ierr, - nc_strerror(ierr), cmor_vars[l].id, - cmor_vars[var_id].id, - cmor_tables[nTableID].szTable_id); - cmor_handle_error_var(msg, CMOR_CRITICAL, var_id); + cmor_handle_error_var_variadic( + "NCError (%i: %s) defining compression\n! " + "parameters for zfactor variable %s for\n! " + "variable '%s' (table %s)", + CMOR_CRITICAL, var_id, + ierr, + nc_strerror(ierr), cmor_vars[l].id, + cmor_vars[var_id].id, + cmor_tables[nTableID].szTable_id); } } } @@ -2148,16 +2205,16 @@ int cmor_define_zfactors_vars(int var_id, int ncid, int *nc_dim, NC_INT, nelts, int_list); if (ierr != NC_NOERR) { - snprintf(msg, CMOR_MAX_STRING, - "NetCDF Error (%i: %s) setting flags\n! " - "numerical attribute on zfactor\n! " - "variable %s for variable %s (table %s)", - ierr, nc_strerror(ierr), cmor_vars[l].id, - cmor_vars[var_id].id, - cmor_tables[cmor_vars - [var_id]. - ref_table_id].szTable_id); - cmor_handle_error_var(msg, CMOR_CRITICAL, var_id); + cmor_handle_error_var_variadic( + "NetCDF Error (%i: %s) setting flags\n! " + "numerical attribute on zfactor\n! " + "variable %s for variable %s (table %s)", + CMOR_CRITICAL, var_id, + ierr, nc_strerror(ierr), cmor_vars[l].id, + cmor_vars[var_id].id, + cmor_tables[cmor_vars + [var_id]. + ref_table_id].szTable_id); } free(int_list); } else if (cmor_vars[l].attributes_type[k] == 'c') { @@ -2207,13 +2264,14 @@ int cmor_define_zfactors_vars(int var_id, int ncid, int *nc_dim, cmor_vars[l].ndims + 1, &dim_holder[0], &nc_zfactors[lnzfactors]); if (ierr != NC_NOERR) { - snprintf(msg, CMOR_MAX_STRING, - "NC Error (%i: %s) for variable %s (table: %s),\n! " - "error defining zfactor var: %i (%s)", ierr, - nc_strerror(ierr), cmor_vars[var_id].id, - cmor_tables[cmor_vars[var_id].ref_table_id]. - szTable_id, lnzfactors, cmor_vars[l].id); - cmor_handle_error_var(msg, CMOR_CRITICAL, var_id); + cmor_handle_error_var_variadic( + "NC Error (%i: %s) for variable %s (table: %s),\n! " + "error defining zfactor var: %i (%s)", + CMOR_CRITICAL, var_id, + ierr, + nc_strerror(ierr), cmor_vars[var_id].id, + cmor_tables[cmor_vars[var_id].ref_table_id]. + szTable_id, lnzfactors, cmor_vars[l].id); } /* -------------------------------------------------------------------- */ @@ -2248,17 +2306,17 @@ int cmor_define_zfactors_vars(int var_id, int ncid, int *nc_dim, NC_INT, nelts, int_list); if (ierr != NC_NOERR) { - snprintf(msg, - CMOR_MAX_STRING, - "NetCDF Error (%i: %s) setting flags numerical " - "attribute on zfactor variable %s for variable " - "%s (table: %s)", ierr, - nc_strerror(ierr), cmor_vars[l].id, - cmor_vars[var_id].id, - cmor_tables[cmor_vars - [var_id]. - ref_table_id].szTable_id); - cmor_handle_error_var(msg, CMOR_CRITICAL, var_id); + cmor_handle_error_var_variadic( + "NetCDF Error (%i: %s) setting flags numerical " + "attribute on zfactor variable %s for variable " + "%s (table: %s)", + CMOR_CRITICAL, var_id, + ierr, + nc_strerror(ierr), cmor_vars[l].id, + cmor_vars[var_id].id, + cmor_tables[cmor_vars + [var_id]. + ref_table_id].szTable_id); } free(int_list); @@ -2440,7 +2498,6 @@ int cmor_set_refvar(int var_id, int *refvar, int ntimes_passed) /* Return either associated variable id or passed variable id */ /* -------------------------------------------------------------------- */ int nRefVarID = var_id; - char msg[CMOR_MAX_STRING]; int nVarRefTblID = cmor_vars[var_id].ref_table_id; int ierr; @@ -2449,15 +2506,15 @@ int cmor_set_refvar(int var_id, int *refvar, int ntimes_passed) nRefVarID = (int)*refvar; if (cmor_vars[nRefVarID].initialized == -1) { - snprintf(msg, CMOR_MAX_STRING, - "You are trying to write variable \"%s\" in association\n! " - "with variable \"%s\" (table %s), but you you need to\n! " - "write the associated variable first in order to\n! " - "initialize the file and dimensions.", - cmor_vars[nRefVarID].id, - cmor_vars[var_id].id, - cmor_tables[nVarRefTblID].szTable_id); - cmor_handle_error_var(msg, CMOR_CRITICAL, var_id); + cmor_handle_error_var_variadic( + "You are trying to write variable \"%s\" in association\n! " + "with variable \"%s\" (table %s), but you you need to\n! " + "write the associated variable first in order to\n! " + "initialize the file and dimensions.", + CMOR_CRITICAL, var_id, + cmor_vars[nRefVarID].id, + cmor_vars[var_id].id, + cmor_tables[nVarRefTblID].szTable_id); } /* -------------------------------------------------------------------- */ /* ok now we need to scan the netcdf file */ @@ -2467,13 +2524,13 @@ int cmor_set_refvar(int var_id, int *refvar, int ntimes_passed) cmor_vars[var_id].id, &cmor_vars[var_id].nc_var_id); if (ierr != NC_NOERR) { - sprintf(msg, - "Could not find variable: '%s' (table: %s) in file of\n! " - "associated variable: '%s'", - cmor_vars[var_id].id, - cmor_tables[nVarRefTblID].szTable_id, - cmor_vars[*refvar].id); - cmor_handle_error_var(msg, CMOR_CRITICAL, var_id); + cmor_handle_error_var_variadic( + "Could not find variable: '%s' (table: %s) in file of\n! " + "associated variable: '%s'", + CMOR_CRITICAL, var_id, + cmor_vars[var_id].id, + cmor_tables[nVarRefTblID].szTable_id, + cmor_vars[*refvar].id); } cmor_vars[var_id].ntimes_written = cmor_vars[nRefVarID].ntimes_written - ntimes_passed; @@ -2500,7 +2557,6 @@ int cmor_validate_activity_id(int nVarRefTblID) /************************************************************************/ void cmor_checkMissing(int varid, int var_id, char type) { - char msg[CMOR_MAX_STRING]; int nVarRefTblID; cmor_add_traceback("cmor_checkMissing"); @@ -2508,14 +2564,15 @@ void cmor_checkMissing(int varid, int var_id, char type) if (cmor_vars[varid].nomissing == 0) { if (cmor_vars[varid].itype != type) { - snprintf(msg, CMOR_MAX_STRING, - "You defined variable \"%s\" (table %s) with a missing\n! " - "value of type \"%c\", but you are now writing data of\n! " - "type: \"%c\" this may lead to some spurious handling\n! " - "of the missing values", cmor_vars[varid].id, - cmor_tables[nVarRefTblID].szTable_id, - cmor_vars[varid].itype, type); - cmor_handle_error(msg, CMOR_WARNING); + cmor_handle_error_variadic( + "You defined variable \"%s\" (table %s) with a missing\n! " + "value of type \"%c\", but you are now writing data of\n! " + "type: \"%c\" this may lead to some spurious handling\n! " + "of the missing values", + CMOR_WARNING, + cmor_vars[varid].id, + cmor_tables[nVarRefTblID].szTable_id, + cmor_vars[varid].itype, type); } } cmor_pop_traceback(); @@ -2617,11 +2674,11 @@ int cmor_validateFilename(char *outname, char *file_suffix, int var_id) fperr = NULL; fperr = fopen(outname, "r"); if (fperr != NULL) { - snprintf(msg, CMOR_MAX_STRING, - "Output file ( %s ) already exists, remove file\n! " - "or use CMOR_REPLACE or CMOR_APPEND for\n! " - "CMOR_NETCDF_MODE value in cmor_setup", outname); - cmor_handle_error_var(msg, CMOR_CRITICAL, var_id); + cmor_handle_error_var_variadic( + "Output file ( %s ) already exists, remove file\n! " + "or use CMOR_REPLACE or CMOR_APPEND for\n! " + "CMOR_NETCDF_MODE value in cmor_setup", + CMOR_CRITICAL, var_id, outname); ierr = fclose(fperr); fperr = NULL; } @@ -2648,52 +2705,53 @@ int cmor_validateFilename(char *outname, char *file_suffix, int var_id) ierr = nc_open(outname, NC_WRITE, &ncid); if (ierr != NC_NOERR) { - snprintf(msg, CMOR_MAX_STRING, - "NetCDF Error (%i: %s) opening file: %s", ierr, - nc_strerror(ierr), outname); - cmor_handle_error_var(msg, CMOR_CRITICAL, var_id); + cmor_handle_error_var_variadic( + "NetCDF Error (%i: %s) opening file: %s", + CMOR_CRITICAL, var_id, + ierr, nc_strerror(ierr), outname); } ierr = nc_inq_dimid(ncid, "time", &i); if (ierr != NC_NOERR) { - snprintf(msg, CMOR_MAX_STRING, - "NetCDF Error (%i: %s) looking for time\n! " - "dimension in file: %s", ierr, - nc_strerror(ierr), outname); - cmor_handle_error_var(msg, CMOR_CRITICAL, var_id); + cmor_handle_error_var_variadic( + "NetCDF Error (%i: %s) looking for time\n! " + "dimension in file: %s", + CMOR_CRITICAL, var_id, + ierr, nc_strerror(ierr), outname); } ierr = nc_inq_dimlen(ncid, i, &nctmp); cmor_vars[var_id].ntimes_written = (int)nctmp; if (ierr != NC_NOERR) { - snprintf(msg, CMOR_MAX_STRING, - "NetCDF Error (%i: %s) looking for time\n! " - "dimension length in file: %s", ierr, - nc_strerror(ierr), outname); - cmor_handle_error_var(msg, CMOR_CRITICAL, var_id); + cmor_handle_error_var_variadic( + "NetCDF Error (%i: %s) looking for time\n! " + "dimension length in file: %s", + CMOR_CRITICAL, var_id, + ierr, nc_strerror(ierr), outname); } ierr = nc_inq_varid(ncid, cmor_vars[var_id].id, &cmor_vars[var_id].nc_var_id); if (ierr != NC_NOERR) { - snprintf(msg, CMOR_MAX_STRING, - "NetCDF Error (%i: %s) looking for variable\n! " - "'%s' in file: %s", ierr, nc_strerror(ierr), - cmor_vars[var_id].id, outname); - cmor_handle_error_var(msg, CMOR_CRITICAL, var_id); + cmor_handle_error_var_variadic( + "NetCDF Error (%i: %s) looking for variable\n! " + "'%s' in file: %s", + CMOR_CRITICAL, var_id, + ierr, nc_strerror(ierr), + cmor_vars[var_id].id, outname); } ierr = nc_inq_varid(ncid, "time", &cmor_vars[var_id].time_nc_id); if (ierr != NC_NOERR) { - snprintf(msg, CMOR_MAX_STRING, - "NetCDF Error (%i: %s) looking for time of\n! " - "variable '%s' in file: %s", ierr, - nc_strerror(ierr), cmor_vars[var_id].id, outname); - cmor_handle_error_var(msg, CMOR_CRITICAL, var_id); + cmor_handle_error_var_variadic( + "NetCDF Error (%i: %s) looking for time of\n! " + "variable '%s' in file: %s", + CMOR_CRITICAL, var_id, + ierr, nc_strerror(ierr), cmor_vars[var_id].id, outname); } /* -------------------------------------------------------------------- */ @@ -2725,11 +2783,11 @@ int cmor_validateFilename(char *outname, char *file_suffix, int var_id) ierr = nc_inq_varid(ncid, ctmp, &i); if (ierr != NC_NOERR) { - snprintf(msg, CMOR_MAX_STRING, - "NetCDF Error (%i: %s) looking for time bounds\n! " - "of variable '%s' in file: %s", ierr, - nc_strerror(ierr), cmor_vars[var_id].id, outname); - cmor_handle_error(msg, CMOR_WARNING); + cmor_handle_error_variadic( + "NetCDF Error (%i: %s) looking for time bounds\n! " + "of variable '%s' in file: %s", + CMOR_WARNING, + ierr, nc_strerror(ierr), cmor_vars[var_id].id, outname); ierr = NC_NOERR; } else { cmor_vars[var_id].time_bnds_nc_id = i; @@ -2753,15 +2811,16 @@ int cmor_validateFilename(char *outname, char *file_suffix, int var_id) cmor_vars[var_id].initialized = ncid; } } else { - snprintf(msg, CMOR_MAX_STRING, "Unknown CMOR_NETCDF_MODE file mode: %i", - CMOR_NETCDF_MODE); - cmor_handle_error_var(msg, CMOR_CRITICAL, var_id); + cmor_handle_error_var_variadic( + "Unknown CMOR_NETCDF_MODE file mode: %i", + CMOR_CRITICAL, var_id, + CMOR_NETCDF_MODE); } if (ierr != NC_NOERR) { - snprintf(msg, CMOR_MAX_STRING, - "NetCDF Error (%i: %s) creating file: %s", ierr, - nc_strerror(ierr), outname); - cmor_handle_error_var(msg, CMOR_CRITICAL, var_id); + cmor_handle_error_var_variadic( + "NetCDF Error (%i: %s) creating file: %s", + CMOR_CRITICAL, var_id, + ierr, nc_strerror(ierr), outname); } cmor_pop_traceback(); return (ncid); @@ -2795,9 +2854,9 @@ int cmor_setDefaultGblAttr(int ref_table_id) ierr = cmor_get_cur_dataset_attribute(GLOBAL_ATT_SOURCE_ID, source_id); if (ierr != 0) { - snprintf(msg, CMOR_MAX_STRING, "Can't read dataset attribute %s", - GLOBAL_ATT_SOURCE_ID); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "Can't read dataset attribute %s", + CMOR_CRITICAL, GLOBAL_ATT_SOURCE_ID); return (1); } @@ -3028,14 +3087,14 @@ int cmor_setGblAttr(int var_id) rc = regexec(®ex, ctmp, n_matches, m, 0); if (rc == REG_NOMATCH) { - snprintf(msg, CMOR_MAX_STRING, - "Your table (%s) does not contains CELL_MEASURES\n! " - "that matches 'area: volume: \n! " - "CMOR cannot build the 'external_variable' attribute.\n! " - "Check the following variable: '%s'.\n!", - cmor_tables[nVarRefTblID].szTable_id, - cmor_vars[var_id].id); - cmor_handle_error_var(msg, CMOR_CRITICAL, var_id); + cmor_handle_error_var_variadic( + "Your table (%s) does not contains CELL_MEASURES\n! " + "that matches 'area: volume: \n! " + "CMOR cannot build the 'external_variable' attribute.\n! " + "Check the following variable: '%s'.\n!", + CMOR_CRITICAL, var_id, + cmor_tables[nVarRefTblID].szTable_id, + cmor_vars[var_id].id); regfree(®ex); return (-1); @@ -3152,14 +3211,14 @@ int cmor_writeGblAttr(int var_id, int ncid, int ncafid) afloat += d; if (cmor_tables[nVarRefTblID].cf_version > afloat) { - snprintf(msg, CMOR_MAX_STRING, - "Your table (%s) claims to enforce CF version %f but\n! " - "this version of the library is designed for CF up\n! " - "to: %i.%i, you were writing variable: %s\n! ", - cmor_tables[nVarRefTblID].szTable_id, - cmor_tables[nVarRefTblID].cf_version, CMOR_CF_VERSION_MAJOR, - CMOR_CF_VERSION_MINOR, cmor_vars[var_id].id); - cmor_handle_error(msg, CMOR_WARNING); + cmor_handle_error_variadic( + "Your table (%s) claims to enforce CF version %f but\n! " + "this version of the library is designed for CF up\n! " + "to: %i.%i, you were writing variable: %s\n! ", + CMOR_WARNING, + cmor_tables[nVarRefTblID].szTable_id, + cmor_tables[nVarRefTblID].cf_version, CMOR_CF_VERSION_MAJOR, + CMOR_CF_VERSION_MINOR, cmor_vars[var_id].id); } /* -------------------------------------------------------------------- */ /* cmor_ver */ @@ -3169,12 +3228,13 @@ int cmor_writeGblAttr(int var_id, int ncid, int ncafid) ierr = nc_put_att_text(ncid, NC_GLOBAL, GLOBAL_ATT_CMORVERSION, strlen(msg) + 1, msg); if (ierr != NC_NOERR) { - snprintf(msg, CMOR_MAX_STRING, - "NetCDF error (%i: %s) writing variable %s (table: %s)\n! " - "global att cmor_version (%f)", ierr, nc_strerror(ierr), - cmor_vars[var_id].id, cmor_tables[nVarRefTblID].szTable_id, - afloat); - cmor_handle_error_var(msg, CMOR_CRITICAL, var_id); + cmor_handle_error_var_variadic( + "NetCDF error (%i: %s) writing variable %s (table: %s)\n! " + "global att cmor_version (%f)", + CMOR_CRITICAL, var_id, + ierr, nc_strerror(ierr), + cmor_vars[var_id].id, cmor_tables[nVarRefTblID].szTable_id, + afloat); } if (ncid != ncafid) { @@ -3185,12 +3245,13 @@ int cmor_writeGblAttr(int var_id, int ncid, int ncafid) ierr = nc_put_att_text(ncid, NC_GLOBAL, GLOBAL_ATT_CMORVERSION, strlen(msg) + 1, msg); if (ierr != NC_NOERR) { - snprintf(msg, CMOR_MAX_STRING, - "NetCDF error (%i: %s) writing variable %s\n! " - "(table: %s) global att cmor_version (%f)", ierr, - nc_strerror(ierr), cmor_vars[var_id].id, - cmor_tables[nVarRefTblID].szTable_id, afloat); - cmor_handle_error_var(msg, CMOR_CRITICAL, var_id); + cmor_handle_error_var_variadic( + "NetCDF error (%i: %s) writing variable %s\n! " + "(table: %s) global att cmor_version (%f)", + CMOR_CRITICAL, var_id, + ierr, + nc_strerror(ierr), cmor_vars[var_id].id, + cmor_tables[nVarRefTblID].szTable_id, afloat); } } cmor_pop_traceback(); @@ -3302,30 +3363,30 @@ void cmor_write_all_attributes(int ncid, int ncafid, int var_id) cmor_current_dataset.attributes[i].names, NC_DOUBLE, 1, &tmps[0]); if (ierr != NC_NOERR) { - snprintf(msg, CMOR_MAX_STRING, - "NetCDF error (%i: %s) for variable %s\n! " - "(table: %s) writing global att: %s (%s)\n! ", - ierr, nc_strerror(ierr), cmor_vars[var_id].id, - cmor_tables[nVarRefTblID].szTable_id, - cmor_current_dataset.attributes[i].names, - cmor_current_dataset.attributes[i].values); - cmor_handle_error_var(msg, CMOR_CRITICAL, var_id); - + cmor_handle_error_var_variadic( + "NetCDF error (%i: %s) for variable %s\n! " + "(table: %s) writing global att: %s (%s)\n! ", + CMOR_CRITICAL, var_id, + ierr, nc_strerror(ierr), cmor_vars[var_id].id, + cmor_tables[nVarRefTblID].szTable_id, + cmor_current_dataset.attributes[i].names, + cmor_current_dataset.attributes[i].values); } if (ncid != ncafid) { ierr = nc_put_att_double(ncafid, NC_GLOBAL, cmor_current_dataset.attributes[i]. names, NC_DOUBLE, 1, &tmps[0]); if (ierr != NC_NOERR) { - snprintf(msg, CMOR_MAX_STRING, - "NetCDF error (%i: %s) for variable\n! " - "%s (table: %s), writing global att\n! " - "to metafile: %s (%s)", ierr, - nc_strerror(ierr), cmor_vars[var_id].id, - cmor_tables[nVarRefTblID].szTable_id, - cmor_current_dataset.attributes[i].names, - cmor_current_dataset.attributes[i].values); - cmor_handle_error_var(msg, CMOR_CRITICAL, var_id); + cmor_handle_error_var_variadic( + "NetCDF error (%i: %s) for variable\n! " + "%s (table: %s), writing global att\n! " + "to metafile: %s (%s)", + CMOR_CRITICAL, var_id, + ierr, + nc_strerror(ierr), cmor_vars[var_id].id, + cmor_tables[nVarRefTblID].szTable_id, + cmor_current_dataset.attributes[i].names, + cmor_current_dataset.attributes[i].values); } } } else if ((strcmp(cmor_current_dataset.attributes[i].names, @@ -3341,15 +3402,14 @@ void cmor_write_all_attributes(int ncid, int ncafid, int var_id) cmor_current_dataset.attributes[i].names, NC_INT, 1, &itmp2); if (ierr != NC_NOERR) { - snprintf(msg, CMOR_MAX_STRING, - "NetCDF error (%i: %s) for variable %s\n! " - "(table: %s) writing global att: %s (%s)\n! ", - ierr, nc_strerror(ierr), cmor_vars[var_id].id, - cmor_tables[nVarRefTblID].szTable_id, - cmor_current_dataset.attributes[i].names, - cmor_current_dataset.attributes[i].values); - cmor_handle_error_var(msg, CMOR_CRITICAL, var_id); - + cmor_handle_error_var_variadic( + "NetCDF error (%i: %s) for variable %s\n! " + "(table: %s) writing global att: %s (%s)\n! ", + CMOR_CRITICAL, var_id, + ierr, nc_strerror(ierr), cmor_vars[var_id].id, + cmor_tables[nVarRefTblID].szTable_id, + cmor_current_dataset.attributes[i].names, + cmor_current_dataset.attributes[i].values); } } else { itmp2 = strlen(cmor_current_dataset.attributes[i].values); @@ -3376,14 +3436,14 @@ void cmor_write_all_attributes(int ncid, int ncafid, int var_id) values); if (ierr != NC_NOERR) { - snprintf(msg, CMOR_MAX_STRING, - "NetCDF error (%i: %s) for variable %s\n! " - "(table: %s) writing global att: %s (%s)", - ierr, nc_strerror(ierr), cmor_vars[var_id].id, - cmor_tables[nVarRefTblID].szTable_id, - cmor_current_dataset.attributes[i].names, - cmor_current_dataset.attributes[i].values); - cmor_handle_error_var(msg, CMOR_CRITICAL, var_id); + cmor_handle_error_var_variadic( + "NetCDF error (%i: %s) for variable %s\n! " + "(table: %s) writing global att: %s (%s)", + CMOR_CRITICAL, var_id, + ierr, nc_strerror(ierr), cmor_vars[var_id].id, + cmor_tables[nVarRefTblID].szTable_id, + cmor_current_dataset.attributes[i].names, + cmor_current_dataset.attributes[i].values); } if (ncid != ncafid) { ierr = nc_put_att_text(ncafid, NC_GLOBAL, @@ -3392,15 +3452,16 @@ void cmor_write_all_attributes(int ncid, int ncafid, int var_id) cmor_current_dataset.attributes[i]. values); if (ierr != NC_NOERR) { - snprintf(msg, CMOR_MAX_STRING, - "NetCDF error (%i: %s) for variable %s\n! " - "(table %s), writing global att to\n! " - "metafile: %s (%s)", ierr, - nc_strerror(ierr), cmor_vars[var_id].id, - cmor_tables[nVarRefTblID].szTable_id, - cmor_current_dataset.attributes[i].names, - cmor_current_dataset.attributes[i].values); - cmor_handle_error_var(msg, CMOR_CRITICAL, var_id); + cmor_handle_error_var_variadic( + "NetCDF error (%i: %s) for variable %s\n! " + "(table %s), writing global att to\n! " + "metafile: %s (%s)", + CMOR_CRITICAL, var_id, + ierr, + nc_strerror(ierr), cmor_vars[var_id].id, + cmor_tables[nVarRefTblID].szTable_id, + cmor_current_dataset.attributes[i].names, + cmor_current_dataset.attributes[i].values); } } } @@ -3418,26 +3479,27 @@ void cmor_write_all_attributes(int ncid, int ncafid, int var_id) value); if (ierr != NC_NOERR) { - snprintf(msg, CMOR_MAX_STRING, - "NetCDF error (%i: %s) for variable %s\n! " - "(table: %s) writing global att: %s (%s)", - ierr, nc_strerror(ierr), cmor_vars[var_id].id, - cmor_tables[nVarRefTblID].szTable_id, - GLOBAL_ATT_LICENSE, value); - cmor_handle_error_var(msg, CMOR_CRITICAL, var_id); + cmor_handle_error_var_variadic( + "NetCDF error (%i: %s) for variable %s\n! " + "(table: %s) writing global att: %s (%s)", + CMOR_CRITICAL, var_id, + ierr, nc_strerror(ierr), cmor_vars[var_id].id, + cmor_tables[nVarRefTblID].szTable_id, + GLOBAL_ATT_LICENSE, value); } if (ncid != ncafid) { ierr = nc_put_att_text(ncafid, NC_GLOBAL, GLOBAL_ATT_LICENSE, itmp2, value); if (ierr != NC_NOERR) { - snprintf(msg, CMOR_MAX_STRING, - "NetCDF error (%i: %s) for variable %s\n! " - "(table %s), writing global att to\n! " - "metafile: %s (%s)", ierr, - nc_strerror(ierr), cmor_vars[var_id].id, - cmor_tables[nVarRefTblID].szTable_id, - GLOBAL_ATT_LICENSE, value); - cmor_handle_error_var(msg, CMOR_CRITICAL, var_id); + cmor_handle_error_var_variadic( + "NetCDF error (%i: %s) for variable %s\n! " + "(table %s), writing global att to\n! " + "metafile: %s (%s)", + CMOR_CRITICAL, var_id, + ierr, + nc_strerror(ierr), cmor_vars[var_id].id, + cmor_tables[nVarRefTblID].szTable_id, + GLOBAL_ATT_LICENSE, value); } } } @@ -3506,27 +3568,28 @@ void cmor_define_dimensions(int var_id, int ncid, ierr = nc_def_dim(ncid, cmor_axes[nAxisID].id, j, &nc_dim[i]); if (ierr != NC_NOERR) { - snprintf(msg, CMOR_MAX_STRING, - "NetCDF error (%i:%s) for dimension definition of\n! " - "axis: %s (%i), for variable %i (%s, table: %s)", - ierr, nc_strerror(ierr), cmor_axes[nAxisID].id, nAxisID, - var_id, cmor_vars[var_id].id, - cmor_tables[nVarRefTblID].szTable_id); ierr = nc_enddef(ncid); - cmor_handle_error_var(msg, CMOR_CRITICAL, var_id); + cmor_handle_error_var_variadic( + "NetCDF error (%i:%s) for dimension definition of\n! " + "axis: %s (%i), for variable %i (%s, table: %s)", + CMOR_CRITICAL, var_id, + ierr, nc_strerror(ierr), cmor_axes[nAxisID].id, nAxisID, + var_id, cmor_vars[var_id].id, + cmor_tables[nVarRefTblID].szTable_id); } nc_dim_af[i] = nc_dim[i]; if (ncid != ncafid) { ierr = nc_def_dim(ncafid, cmor_axes[nAxisID].id, j, &nc_dim_af[i]); if (ierr != NC_NOERR) { - snprintf(msg, CMOR_MAX_STRING, - "NetCDF error (%i: %s) for dimension definition\n! " - "of axis: %s (%i) in metafile, variable %s " - "(table: %s)", ierr, nc_strerror(ierr), - cmor_axes[cmor_vars[var_id].axes_ids[i]].id, i, - cmor_vars[var_id].id, - cmor_tables[nVarRefTblID].szTable_id); - cmor_handle_error_var(msg, CMOR_CRITICAL, var_id); + cmor_handle_error_var_variadic( + "NetCDF error (%i: %s) for dimension definition\n! " + "of axis: %s (%i) in metafile, variable %s " + "(table: %s)", + CMOR_CRITICAL, var_id, + ierr, nc_strerror(ierr), + cmor_axes[cmor_vars[var_id].axes_ids[i]].id, i, + cmor_vars[var_id].id, + cmor_tables[nVarRefTblID].szTable_id); } } /* -------------------------------------------------------------------- */ @@ -3565,12 +3628,12 @@ void cmor_define_dimensions(int var_id, int ncid, /* -------------------------------------------------------------------- */ ierr = nc_def_dim(ncafid, "bnds", 2, dim_bnds); if (ierr != NC_NOERR) { - snprintf(msg, CMOR_MAX_STRING, + cmor_handle_error_var_variadic( "NC error (%i: %s), error creating bnds dimension to\n! " - "metafile, variable %s (table: %s)", ierr, - nc_strerror(ierr), cmor_vars[var_id].id, + "metafile, variable %s (table: %s)", + CMOR_CRITICAL, var_id, + ierr, nc_strerror(ierr), cmor_vars[var_id].id, cmor_tables[nVarRefTblID].szTable_id); - cmor_handle_error_var(msg, CMOR_CRITICAL, var_id); } /* -------------------------------------------------------------------- */ @@ -3606,12 +3669,12 @@ void cmor_define_dimensions(int var_id, int ncid, ierr = nc_def_var(ncid, pAxis->id, j, 1, &nc_dim[i], &nc_vars[i]); if (ierr != NC_NOERR) { - snprintf(msg, CMOR_MAX_STRING, - "NetCDF Error (%i: %s) for variable %s\n! " - "(table: %s) error defining dim var: %i (%s)", - ierr, nc_strerror(ierr), cmor_vars[var_id].id, - cmor_tables[nVarRefTblID].szTable_id, i, pAxis->id); - cmor_handle_error_var(msg, CMOR_CRITICAL, var_id); + cmor_handle_error_var_variadic( + "NetCDF Error (%i: %s) for variable %s\n! " + "(table: %s) error defining dim var: %i (%s)", + CMOR_CRITICAL, var_id, + ierr, nc_strerror(ierr), cmor_vars[var_id].id, + cmor_tables[nVarRefTblID].szTable_id, i, pAxis->id); } // // Define Chunking if NETCDF4 @@ -3629,12 +3692,12 @@ void cmor_define_dimensions(int var_id, int ncid, } } if (ierr != NC_NOERR) { - snprintf(msg, CMOR_MAX_STRING, - "NetCDF Error (%i: %s) for variable %s\n! " - "(table: %s) error defining dim var: %i (%s)", - ierr, nc_strerror(ierr), cmor_vars[var_id].id, - cmor_tables[nVarRefTblID].szTable_id, i, pAxis->id); - cmor_handle_error_var(msg, CMOR_CRITICAL, var_id); + cmor_handle_error_var_variadic( + "NetCDF Error (%i: %s) for variable %s\n! " + "(table: %s) error defining dim var: %i (%s)", + CMOR_CRITICAL, var_id, + ierr, nc_strerror(ierr), cmor_vars[var_id].id, + cmor_tables[nVarRefTblID].szTable_id, i, pAxis->id); } nc_vars_af[i] = nc_vars[i]; if (ncid != ncafid) { @@ -3642,14 +3705,15 @@ void cmor_define_dimensions(int var_id, int ncid, &nc_vars_af[i]); if (ierr != NC_NOERR) { - snprintf(msg, CMOR_MAX_STRING, - "NetCDF Error (%i: %s ) for variable %s\n! " - "(table: %s) error defining dim var: %i\n! " - "(%s) in metafile", ierr, nc_strerror(ierr), - cmor_vars[var_id].id, - cmor_tables[nVarRefTblID].szTable_id, i, - pAxis->id); - cmor_handle_error_var(msg, CMOR_CRITICAL, var_id); + cmor_handle_error_var_variadic( + "NetCDF Error (%i: %s ) for variable %s\n! " + "(table: %s) error defining dim var: %i\n! " + "(%s) in metafile", + CMOR_CRITICAL, var_id, + ierr, nc_strerror(ierr), + cmor_vars[var_id].id, + cmor_tables[nVarRefTblID].szTable_id, i, + pAxis->id); } } @@ -3701,25 +3765,25 @@ void cmor_define_dimensions(int var_id, int ncid, nc_def_dim(ncid, "strlen", maxStrLen, &tmp_dims[1]); } if (ierr != NC_NOERR) { - snprintf(msg, CMOR_MAX_STRING, - "NetCDF error (%i: %s) for dummy 'strlen'\n! " - "dimension definition of axis: %s (%i) in\n! " - "metafile, while writing variable %s (table: %s)", - ierr, nc_strerror(ierr), pAxis->id, i, - cmor_vars[var_id].id, - cmor_tables[nVarRefTblID].szTable_id); - cmor_handle_error_var(msg, CMOR_CRITICAL, var_id); + cmor_handle_error_var_variadic( + "NetCDF error (%i: %s) for dummy 'strlen'\n! " + "dimension definition of axis: %s (%i) in\n! " + "metafile, while writing variable %s (table: %s)", + CMOR_CRITICAL, var_id, + ierr, nc_strerror(ierr), pAxis->id, i, + cmor_vars[var_id].id, + cmor_tables[nVarRefTblID].szTable_id); } tmp_dims[0] = nc_dim[i]; ierr = nc_def_var(ncid, ctmp, NC_CHAR, 2, &tmp_dims[0], &nc_vars[i]); if (ierr != NC_NOERR) { - snprintf(msg, CMOR_MAX_STRING, - "NetCDF Error (%i: %s) for variable %s\n! " - "(table: %s) error defining dim var: %i (%s)", - ierr, nc_strerror(ierr), cmor_vars[var_id].id, - cmor_tables[nVarRefTblID].szTable_id, i, pAxis->id); - cmor_handle_error_var(msg, CMOR_CRITICAL, var_id); + cmor_handle_error_var_variadic( + "NetCDF Error (%i: %s) for variable %s\n! " + "(table: %s) error defining dim var: %i (%s)", + CMOR_CRITICAL, var_id, + ierr, nc_strerror(ierr), cmor_vars[var_id].id, + cmor_tables[nVarRefTblID].szTable_id, i, pAxis->id); } nc_vars_af[i] = nc_vars[i]; @@ -3732,14 +3796,15 @@ void cmor_define_dimensions(int var_id, int ncid, } if (ierr != NC_NOERR) { - snprintf(msg, CMOR_MAX_STRING, - "NetCDF error (%i: %s) for dummy 'strlen'\n! " - "dimension definition of axis: %s (%i) in\n! " - "metafile, while writing variable %s " - "(table: %s)", ierr, nc_strerror(ierr), - pAxis->id, i, cmor_vars[var_id].id, - cmor_tables[nVarRefTblID].szTable_id); - cmor_handle_error_var(msg, CMOR_CRITICAL, var_id); + cmor_handle_error_var_variadic( + "NetCDF error (%i: %s) for dummy 'strlen'\n! " + "dimension definition of axis: %s (%i) in\n! " + "metafile, while writing variable %s " + "(table: %s)", + CMOR_CRITICAL, var_id, + ierr, nc_strerror(ierr), + pAxis->id, i, cmor_vars[var_id].id, + cmor_tables[nVarRefTblID].szTable_id); } tmp_dims[0] = nc_dim_af[i]; @@ -3747,14 +3812,14 @@ void cmor_define_dimensions(int var_id, int ncid, &nc_vars_af[i]); if (ierr != NC_NOERR) { - snprintf(msg, CMOR_MAX_STRING, - "NetCDF Error (%i: %s) for variable %s\n! " - "(table: %s) error defining dim var:\n! " - "%i (%s) in metafile", ierr, - nc_strerror(ierr), cmor_vars[var_id].id, - cmor_tables[nVarRefTblID].szTable_id, i, - pAxis->id); - cmor_handle_error_var(msg, CMOR_CRITICAL, var_id); + cmor_handle_error_var_variadic( + "NetCDF Error (%i: %s) for variable %s\n! " + "(table: %s) error defining dim var:\n! " + "%i (%s) in metafile", + CMOR_CRITICAL, var_id, + ierr, nc_strerror(ierr), cmor_vars[var_id].id, + cmor_tables[nVarRefTblID].szTable_id, i, + pAxis->id); } } } @@ -3797,12 +3862,12 @@ void cmor_define_dimensions(int var_id, int ncid, ierr = nc_def_var(ncafid, ctmp, j, 2, &dims_bnds_ids[0], &nc_bnds_vars[i]); if (ierr != NC_NOERR) { - snprintf(msg, CMOR_MAX_STRING, - "NetCDF Error (%i: %s) for variable %s\n! " - "(table: %s) error defining bounds dim var: %i (%s)", - ierr, nc_strerror(ierr), cmor_vars[var_id].id, - cmor_tables[nVarRefTblID].szTable_id, i, pAxis->id); - cmor_handle_error_var(msg, CMOR_CRITICAL, var_id); + cmor_handle_error_var_variadic( + "NetCDF Error (%i: %s) for variable %s\n! " + "(table: %s) error defining bounds dim var: %i (%s)", + CMOR_CRITICAL, var_id, + ierr, nc_strerror(ierr), cmor_vars[var_id].id, + cmor_tables[nVarRefTblID].szTable_id, i, pAxis->id); } /* -------------------------------------------------------------------- */ @@ -3834,13 +3899,14 @@ void cmor_define_dimensions(int var_id, int ncid, icz); } if (ierr != NC_NOERR) { - snprintf(msg, CMOR_MAX_STRING, - "NCError (%i: %s) defining compression\n! " - "parameters for bounds variable %s for\n! " - "variable '%s' (table: %s)", ierr, - nc_strerror(ierr), ctmp, cmor_vars[var_id].id, - cmor_tables[nVarRefTblID].szTable_id); - cmor_handle_error_var(msg, CMOR_CRITICAL, var_id); + cmor_handle_error_var_variadic( + "NCError (%i: %s) defining compression\n! " + "parameters for bounds variable %s for\n! " + "variable '%s' (table: %s)", + CMOR_CRITICAL, var_id, + ierr, + nc_strerror(ierr), ctmp, cmor_vars[var_id].id, + cmor_tables[nVarRefTblID].szTable_id); } } @@ -3853,13 +3919,14 @@ void cmor_define_dimensions(int var_id, int ncid, ierr = nc_put_att_text(ncafid, nc_vars[i], msg, strlen(ctmp) + 1, ctmp); if (ierr != NC_NOERR) { - snprintf(msg, CMOR_MAX_STRING, - "NetCDF Error (%i: %s) for variable %s\n! " - "(table: %s) error defining bounds attribute\n! " - "var: %i (%s)", ierr, nc_strerror(ierr), - cmor_vars[var_id].id, - cmor_tables[nVarRefTblID].szTable_id, i, pAxis->id); - cmor_handle_error_var(msg, CMOR_CRITICAL, var_id); + cmor_handle_error_var_variadic( + "NetCDF Error (%i: %s) for variable %s\n! " + "(table: %s) error defining bounds attribute\n! " + "var: %i (%s)", + CMOR_CRITICAL, var_id, + ierr, nc_strerror(ierr), + cmor_vars[var_id].id, + cmor_tables[nVarRefTblID].szTable_id, i, pAxis->id); } } /* -------------------------------------------------------------------- */ @@ -3881,29 +3948,30 @@ void cmor_define_dimensions(int var_id, int ncid, ierr = nc_put_att_text(ncid, nc_vars[i], "formula_terms", n, msg); if (ierr != NC_NOERR) { - snprintf(ctmp, CMOR_MAX_STRING, - "NetCDF error (%i: %s) writing formula term " - "att (%s) for axis %i (%s), variable %s " - "(table: %s)", ierr, nc_strerror(ierr), msg, - i, cmor_axes[cmor_vars[var_id].axes_ids[i]].id, - cmor_vars[var_id].id, - cmor_tables[nVarRefTblID].szTable_id); - cmor_handle_error_var(msg, CMOR_CRITICAL, var_id); + cmor_handle_error_var_variadic( + "NetCDF error (%i: %s) writing formula term " + "att (%s) for axis %i (%s), variable %s " + "(table: %s)", + CMOR_CRITICAL, var_id, + ierr, nc_strerror(ierr), msg, + i, cmor_axes[cmor_vars[var_id].axes_ids[i]].id, + cmor_vars[var_id].id, + cmor_tables[nVarRefTblID].szTable_id); } if (ncid != ncafid) { ierr = nc_put_att_text(ncafid, nc_vars_af[i], "formula_terms", n, msg); if (ierr != NC_NOERR) { - snprintf(ctmp, CMOR_MAX_STRING, - "NetCDF error (%i: %s) writing formula " - "term att (%s) for axis %i (%s), variable " - "%s (table: %s)", ierr, - nc_strerror(ierr), msg, i, - cmor_axes[cmor_vars[var_id].axes_ids[i]].id, - cmor_vars[var_id].id, - cmor_tables[nVarRefTblID].szTable_id); - cmor_handle_error_var(ctmp, CMOR_CRITICAL, var_id); + cmor_handle_error_var_variadic( + "NetCDF error (%i: %s) writing formula " + "term att (%s) for axis %i (%s), variable " + "%s (table: %s)", + CMOR_CRITICAL, var_id, + ierr, nc_strerror(ierr), msg, i, + cmor_axes[cmor_vars[var_id].axes_ids[i]].id, + cmor_vars[var_id].id, + cmor_tables[nVarRefTblID].szTable_id); } } ierr = cmor_define_zfactors_vars(var_id, ncafid, &nc_dim_af[0], @@ -4106,13 +4174,14 @@ int cmor_grids_def(int var_id, int nGridID, int ncafid, int *nc_dim_af, &nc_dims_associated[0], &m); if (ierr != NC_NOERR) { - snprintf(msg, CMOR_MAX_STRING, - "NetCDF error (%i: %s) while defining\n! " - "associated grid mapping variable %s for\n! " - "variable %s (table: %s)", ierr, nc_strerror(ierr), - cmor_grids[nGridID].mapping, cmor_vars[var_id].id, - cmor_tables[nVarRefTblID].szTable_id); - cmor_handle_error_var(msg, CMOR_CRITICAL, var_id); + cmor_handle_error_var_variadic( + "NetCDF error (%i: %s) while defining\n! " + "associated grid mapping variable %s for\n! " + "variable %s (table: %s)", + CMOR_CRITICAL, var_id, + ierr, nc_strerror(ierr), + cmor_grids[nGridID].mapping, cmor_vars[var_id].id, + cmor_tables[nVarRefTblID].szTable_id); } /* -------------------------------------------------------------------- */ /* Creates attributes related to that variable */ @@ -4145,13 +4214,14 @@ int cmor_grids_def(int var_id, int nGridID, int ncafid, int *nc_dim_af, NC_DOUBLE, 1, &tmps[0]); } if (ierr != NC_NOERR) { - snprintf(msg, CMOR_MAX_STRING, - "NetCDF Error (%i: %s) writing\n! " - "standard_parallel to file, variable:\n! " - "%s (table: %s)", ierr, nc_strerror(ierr), - cmor_vars[var_id].id, - cmor_tables[nVarRefTblID].szTable_id); - cmor_handle_error_var(msg, CMOR_NORMAL, var_id); + cmor_handle_error_var_variadic( + "NetCDF Error (%i: %s) writing\n! " + "standard_parallel to file, variable:\n! " + "%s (table: %s)", + CMOR_NORMAL, var_id, + ierr, nc_strerror(ierr), + cmor_vars[var_id].id, + cmor_tables[nVarRefTblID].szTable_id); cmor_pop_traceback(); return (1); } @@ -4234,13 +4304,14 @@ int cmor_grids_def(int var_id, int nGridID, int ncafid, int *nc_dim_af, [cmor_vars[j].ndims - 1]].length, &nc_dims_associated[l]); if (ierr != NC_NOERR) { - snprintf(msg, CMOR_MAX_STRING, - "NetCDF error (%i: %s) while defining\n! " - "vertices dimension, variable %s\n! " - "(table: %s)", ierr, nc_strerror(ierr), - cmor_vars[var_id].id, - cmor_tables[nVarRefTblID].szTable_id); - cmor_handle_error_var(msg, CMOR_CRITICAL, var_id); + cmor_handle_error_var_variadic( + "NetCDF error (%i: %s) while defining\n! " + "vertices dimension, variable %s\n! " + "(table: %s)", + CMOR_CRITICAL, var_id, + ierr, nc_strerror(ierr), + cmor_vars[var_id].id, + cmor_tables[nVarRefTblID].szTable_id); } } mtype = cmor_vars[j].type; @@ -4262,13 +4333,14 @@ int cmor_grids_def(int var_id, int nGridID, int ncafid, int *nc_dim_af, cmor_vars[j].ndims, &nc_dims_associated[0], &nc_associated_vars[i]); if (ierr != NC_NOERR) { - snprintf(msg, CMOR_MAX_STRING, - "NetCDF error (%i: %s) while defining\n! " - "associated variable %s, of variable\n! " - "%s (table: %s)", ierr, nc_strerror(ierr), - cmor_vars[j].id, cmor_vars[var_id].id, - cmor_tables[nVarRefTblID].szTable_id); - cmor_handle_error_var(msg, CMOR_CRITICAL, var_id); + cmor_handle_error_var_variadic( + "NetCDF error (%i: %s) while defining\n! " + "associated variable %s, of variable\n! " + "%s (table: %s)", + CMOR_CRITICAL, var_id, + ierr, nc_strerror(ierr), + cmor_vars[j].id, cmor_vars[var_id].id, + cmor_tables[nVarRefTblID].szTable_id); } /* -------------------------------------------------------------------- */ @@ -4301,15 +4373,15 @@ int cmor_grids_def(int var_id, int nGridID, int ncafid, int *nc_dim_af, int_list); if (ierr != NC_NOERR) { - snprintf(msg, CMOR_MAX_STRING, - "NetCDF Error (%i: %s) setting\n! " - "flags numerical attribute on\n! " - "associated variable %s, for\n! " - "variable %s (table: %s)", ierr, - nc_strerror(ierr), cmor_vars[j].id, - cmor_vars[var_id].id, - cmor_tables[nVarRefTblID].szTable_id); - cmor_handle_error_var(msg, CMOR_CRITICAL, var_id); + cmor_handle_error_var_variadic( + "NetCDF Error (%i: %s) setting\n! " + "flags numerical attribute on\n! " + "associated variable %s, for\n! " + "variable %s (table: %s)", + CMOR_CRITICAL, var_id, + ierr, nc_strerror(ierr), cmor_vars[j].id, + cmor_vars[var_id].id, + cmor_tables[nVarRefTblID].szTable_id); } free(int_list); } else if (cmor_vars[j].attributes_type[k] == 'c') { @@ -4376,15 +4448,15 @@ int cmor_grids_def(int var_id, int nGridID, int ncafid, int *nc_dim_af, icz); } if (ierr != NC_NOERR) { - snprintf(msg, CMOR_MAX_STRING, - "NetCDF Error (%i: %s) defining\n! " - "compression parameters for\n! " - "associated variable '%s' for\n! " - "variable %s (table: %s)", ierr, - nc_strerror(ierr), cmor_vars[j].id, - cmor_vars[var_id].id, - cmor_tables[nVarRefTblID].szTable_id); - cmor_handle_error_var(msg, CMOR_CRITICAL, var_id); + cmor_handle_error_var_variadic( + "NetCDF Error (%i: %s) defining\n! " + "compression parameters for\n! " + "associated variable '%s' for\n! " + "variable %s (table: %s)", + CMOR_CRITICAL, var_id, + ierr, nc_strerror(ierr), cmor_vars[j].id, + cmor_vars[var_id].id, + cmor_tables[nVarRefTblID].szTable_id); } } } @@ -4447,13 +4519,13 @@ void create_singleton_dimensions(int var_id, int ncid, int *nc_singletons, &nc_singletons[i], &nc_singletons[i]); } if (ierr != NC_NOERR) { - snprintf(msg, CMOR_MAX_STRING, - "NetCDF Error (%i: %s) defining scalar variable\n! " - "%s for variable %s (table: %s)", ierr, - nc_strerror(ierr), cmor_axes[j].id, - cmor_vars[var_id].id, - cmor_tables[nVarRefTblID].szTable_id); - cmor_handle_error_var(msg, CMOR_CRITICAL, var_id); + cmor_handle_error_var_variadic( + "NetCDF Error (%i: %s) defining scalar variable\n! " + "%s for variable %s (table: %s)", + CMOR_CRITICAL, var_id, + ierr, nc_strerror(ierr), cmor_axes[j].id, + cmor_vars[var_id].id, + cmor_tables[nVarRefTblID].szTable_id); } /* -------------------------------------------------------------------- */ /* now puts on its attributes */ @@ -4490,13 +4562,13 @@ void create_singleton_dimensions(int var_id, int ncid, int *nc_singletons, nc_def_var(ncid, msg, NC_DOUBLE, 1, dim_bnds, &nc_singletons_bnds[i]); if (ierr != NC_NOERR) { - snprintf(msg, CMOR_MAX_STRING, - "NetCDF Error (%i: %s) defining scalar\n! " - "bounds variable %s for variable %s (table: %s)", - ierr, nc_strerror(ierr), cmor_axes[j].id, - cmor_vars[var_id].id, - cmor_tables[nVarRefTblID].szTable_id); - cmor_handle_error_var(msg, CMOR_CRITICAL, var_id); + cmor_handle_error_var_variadic( + "NetCDF Error (%i: %s) defining scalar\n! " + "bounds variable %s for variable %s (table: %s)", + CMOR_CRITICAL, var_id, + ierr, nc_strerror(ierr), cmor_axes[j].id, + cmor_vars[var_id].id, + cmor_tables[nVarRefTblID].szTable_id); } } } @@ -4512,37 +4584,35 @@ int compare_txt_attributes(int ncid, int srcid, int destid, char* name) { size_t attlen; char *srcattr; char *destattr; - char msg[CMOR_MAX_STRING]; - int ierr; int ret; - if (ierr = nc_inq_attlen(ncid, srcid, name, &attlen)) { - snprintf(msg, CMOR_MAX_STRING, "cannot determine size of attribute %s", name); - cmor_handle_error(msg, CMOR_CRITICAL); + if (nc_inq_attlen(ncid, srcid, name, &attlen)) { + cmor_handle_error_variadic( + "cannot determine size of attribute %s", CMOR_CRITICAL, name); }; srcattr = malloc(attlen * sizeof(char)); - if (ierr = nc_get_att_text(ncid, srcid, name, srcattr)) { - snprintf(msg, CMOR_MAX_STRING, "cannot retrieve value of attribute %s", name); - cmor_handle_error(msg, CMOR_CRITICAL); + if (nc_get_att_text(ncid, srcid, name, srcattr)) { + cmor_handle_error_variadic( + "cannot retrieve value of attribute %s", CMOR_CRITICAL, name); }; - if (ierr = nc_inq_attlen(ncid, destid, name, &attlen)) { - snprintf(msg, CMOR_MAX_STRING, "cannot determine size of attribute %s", name); - cmor_handle_error(msg, CMOR_CRITICAL); + if (nc_inq_attlen(ncid, destid, name, &attlen)) { + cmor_handle_error_variadic( + "cannot determine size of attribute %s", CMOR_CRITICAL, name); }; destattr = malloc(attlen * sizeof(char)); - if (ierr = nc_get_att_text(ncid, destid, name, destattr)) { - snprintf(msg, CMOR_MAX_STRING, "cannot retrieve value of attribute %s", name); - cmor_handle_error(msg, CMOR_CRITICAL); + if (nc_get_att_text(ncid, destid, name, destattr)) { + cmor_handle_error_variadic( + "cannot retrieve value of attribute %s", CMOR_CRITICAL, name); }; ret = strcmp(srcattr, destattr); free(destattr); free(srcattr); if (ret != 0) { - snprintf(msg, CMOR_MAX_STRING, "'%s' attribute does not match", name); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "'%s' attribute does not match", CMOR_CRITICAL, name); } return ret; } @@ -4554,20 +4624,19 @@ int copy_txt_attribute(int ncid, int srcid, int destid, char* name, char* suffix size_t attlen; char *srcattr; char *destattr; - char msg[CMOR_MAX_STRING]; int ierr; - if (ierr = nc_inq_attlen(ncid, srcid, name, &attlen)) { - snprintf(msg, CMOR_MAX_STRING, "cannot determine size of attribute %s", name); - cmor_handle_error(msg, CMOR_CRITICAL); + if (nc_inq_attlen(ncid, srcid, name, &attlen)) { + cmor_handle_error_variadic( + "cannot determine size of attribute %s", CMOR_CRITICAL, name); }; srcattr = malloc(attlen * sizeof(char)); - if (ierr = nc_get_att_text(ncid, srcid, name, srcattr)) { - snprintf(msg, CMOR_MAX_STRING, "cannot retrieve value of attribute %s", name); - cmor_handle_error(msg, CMOR_CRITICAL); + if (nc_get_att_text(ncid, srcid, name, srcattr)) { + cmor_handle_error_variadic( + "cannot retrieve value of attribute %s", CMOR_CRITICAL, name); }; - if (suffix == "") { + if (strcmp(suffix, "") == 0) { destattr = srcattr; } else { destattr = malloc(strlen(srcattr) + strlen(suffix) + 1); @@ -4575,11 +4644,11 @@ int copy_txt_attribute(int ncid, int srcid, int destid, char* name, char* suffix strcat(destattr, suffix); } - if (ierr = nc_put_att_text(ncid, destid, name, strlen(destattr) + 1, destattr)) { - snprintf(msg, CMOR_MAX_STRING, "cannot copy attribute %s", name); - cmor_handle_error(msg, CMOR_CRITICAL); + if (nc_put_att_text(ncid, destid, name, strlen(destattr) + 1, destattr)) { + cmor_handle_error_variadic( + "cannot copy attribute %s", CMOR_CRITICAL, name); } - if (suffix != "") { + if (strcmp(suffix, "") != 0) { free(destattr); } free(srcattr); @@ -4590,11 +4659,9 @@ int copy_txt_attribute(int ncid, int srcid, int destid, char* name, char* suffix /* set_txt_attribute() */ /************************************************************************/ int set_txt_attribute(int ncid, int destid, char* name, char* val){ - char msg[CMOR_MAX_STRING]; - int ierr; - if (ierr = nc_put_att_text(ncid, destid, name, strlen(val) + 1, val)) { - snprintf(msg, CMOR_MAX_STRING, "cannot write '%s' to attribute %s", val, name); - cmor_handle_error(msg, CMOR_CRITICAL); + if (nc_put_att_text(ncid, destid, name, strlen(val) + 1, val)) { + cmor_handle_error_variadic( + "cannot write '%s' to attribute %s", CMOR_CRITICAL, val, name); } return (0); } @@ -4611,7 +4678,6 @@ int calculate_leadtime_coord(int var_id) { int time_dim = 0; int reftime = 0; int time = 0; - char msg[CMOR_MAX_STRING]; size_t timelen; double *time_vals; double *leadtime_vals; @@ -4626,21 +4692,21 @@ int calculate_leadtime_coord(int var_id) { ncid = cmor_current_dataset.associated_file; /* need both time and reftime for leadtime calculation */ - if (ierr = nc_inq_dimid(ncid, "time", &time_dim)) { - snprintf(msg, CMOR_MAX_STRING, "'time' dimension not present in the file"); - cmor_handle_error(msg, CMOR_CRITICAL); + if (nc_inq_dimid(ncid, "time", &time_dim)) { + cmor_handle_error_variadic( + "'time' dimension not present in the file", CMOR_CRITICAL); } - if (ierr = nc_inq_dimlen(ncid, time_dim, &timelen)) { - snprintf(msg, CMOR_MAX_STRING, "cannot determine length of the time dimension"); - cmor_handle_error(msg, CMOR_CRITICAL); + if (nc_inq_dimlen(ncid, time_dim, &timelen)) { + cmor_handle_error_variadic( + "cannot determine length of the time dimension", CMOR_CRITICAL); } - if (ierr = nc_inq_varid(ncid, "reftime", &reftime)) { - snprintf(msg, CMOR_MAX_STRING, "'reftime' variable not present in the file"); - cmor_handle_error(msg, CMOR_CRITICAL); + if (nc_inq_varid(ncid, "reftime", &reftime)) { + cmor_handle_error_variadic( + "'reftime' variable not present in the file", CMOR_CRITICAL); } - if (ierr = nc_inq_varid(ncid, "time", &time)) { - snprintf(msg, CMOR_MAX_STRING, "'time' variable not present in the file"); - cmor_handle_error(msg, CMOR_CRITICAL); + if (nc_inq_varid(ncid, "time", &time)) { + cmor_handle_error_variadic( + "'time' variable not present in the file", CMOR_CRITICAL); } if (compare_txt_attributes(ncid, time, reftime, "units") || compare_txt_attributes(ncid, time, reftime, "calendar")) { cmor_pop_traceback(); @@ -4654,34 +4720,34 @@ int calculate_leadtime_coord(int var_id) { /* get values for the calculation */ /* reftime is scalar */ - if (ierr = nc_get_var_double(ncid, reftime, reftime_val)) { - snprintf(msg, CMOR_MAX_STRING, "cannot retrieve value of 'reftime' variable"); - cmor_handle_error(msg, CMOR_CRITICAL); + if (nc_get_var_double(ncid, reftime, reftime_val)) { + cmor_handle_error_variadic( + "cannot retrieve value of 'reftime' variable", CMOR_CRITICAL); } /* update length of the vector for time coord */ count[0] = timelen; - if (ierr = nc_get_vara_double(ncid, time, start, count, time_vals)) { - snprintf(msg, CMOR_MAX_STRING, "cannot retrieve values of 'time' variable"); - cmor_handle_error(msg, CMOR_CRITICAL); + if (nc_get_vara_double(ncid, time, start, count, time_vals)) { + cmor_handle_error_variadic( + "cannot retrieve values of 'time' variable", CMOR_CRITICAL); } /* calculate leadtime */ for (i = 0; i < timelen; i++) { leadtime_vals[i] = time_vals[i] - reftime_val[0]; if (leadtime_vals[i] < 0.0) { - snprintf(msg, CMOR_MAX_STRING, "'leadtime' for timestep %i is negative", i); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "'leadtime' for timestep %i is negative", CMOR_CRITICAL, i); } } /* activate define mode */ nc_redef(ncid); /* add leadtime */ - if (ierr = nc_inq_varid(ncid, "leadtime", &leadtime)) { - if (ierr = nc_def_var(ncid, "leadtime", NC_DOUBLE, 1, &time_dim, &leadtime)) { - snprintf(msg, CMOR_MAX_STRING, "cannot add 'leadtime' variable"); - cmor_handle_error(msg, CMOR_CRITICAL); + if (nc_inq_varid(ncid, "leadtime", &leadtime)) { + if (nc_def_var(ncid, "leadtime", NC_DOUBLE, 1, &time_dim, &leadtime)) { + cmor_handle_error_variadic( + "cannot add 'leadtime' variable", CMOR_CRITICAL); } } @@ -4697,12 +4763,14 @@ int calculate_leadtime_coord(int var_id) { /* deactivate define mode */ ierr = nc_enddef(ncid); if (ierr != NC_NOERR) { - snprintf(msg, CMOR_MAX_STRING, "NetCDF Error (%i: %s) leaving definition mode", ierr, nc_strerror(ierr)); - cmor_handle_error_var(msg, CMOR_CRITICAL, var_id); + cmor_handle_error_var_variadic( + "NetCDF Error (%i: %s) leaving definition mode", + CMOR_CRITICAL, var_id, + ierr, nc_strerror(ierr)); } - if (ierr = nc_put_vara_double(ncid, leadtime, start, count, leadtime_vals)) { - snprintf(msg, CMOR_MAX_STRING, "cannot save 'leadtime' coordinates"); - cmor_handle_error(msg, CMOR_CRITICAL); + if (nc_put_vara_double(ncid, leadtime, start, count, leadtime_vals)) { + cmor_handle_error_variadic( + "cannot save 'leadtime' coordinates", CMOR_CRITICAL); } free(leadtime_vals); @@ -4762,8 +4830,7 @@ int cmor_write(int var_id, void *data, char type, char *file_suffix, cmor_is_setup(); if (var_id > cmor_nvars) { - - cmor_handle_error("var_id %i not defined", CMOR_CRITICAL); + cmor_handle_error_variadic("var_id %i not defined", CMOR_CRITICAL, var_id); cmor_pop_traceback(); return (-1); }; @@ -4779,9 +4846,9 @@ int cmor_write(int var_id, void *data, char type, char *file_suffix, ( cmor_tables[refTableID].axes[refAxisID].must_have_bounds == 1 && time_bounds == NULL ) ) { - cmor_handle_error("time_vals and time_bounds must be passed through cmor_write " - "when in append mode", - CMOR_CRITICAL); + cmor_handle_error_variadic( + "time_vals and time_bounds must be passed through cmor_write " + "when in append mode", CMOR_CRITICAL); cmor_pop_traceback(); return (-1); }; @@ -4856,22 +4923,21 @@ int cmor_write(int var_id, void *data, char type, char *file_suffix, } if (ierr != 0) { - sprintf(ctmp, - "Cannot continue until you fix the errors listed above: %d", - ierr); - cmor_handle_error_var(ctmp, CMOR_CRITICAL, var_id); + cmor_handle_error_var_variadic( + "Cannot continue until you fix the errors listed above: %d", + CMOR_CRITICAL, var_id, ierr); cmor_pop_traceback(); return (1); } ierr = cmor_mkdir(outname); if ((ierr != 0) && (errno != EEXIST)) { - sprintf(ctmp, - "creating outpath: %s, for variable %s (table: %s). " - "Not enough permission?", - outname, cmor_vars[var_id].id, - cmor_tables[cmor_vars[var_id].ref_table_id].szTable_id); - cmor_handle_error_var(ctmp, CMOR_CRITICAL, var_id); + cmor_handle_error_var_variadic( + "creating outpath: %s, for variable %s (table: %s). " + "Not enough permission?", + CMOR_CRITICAL, var_id, + outname, cmor_vars[var_id].id, + cmor_tables[cmor_vars[var_id].ref_table_id].szTable_id); cmor_pop_traceback(); return (1); @@ -4884,12 +4950,12 @@ int cmor_write(int var_id, void *data, char type, char *file_suffix, for (i = 0; i < strlen(cmor_vars[var_id].id); i++) { if ((cmor_vars[var_id].id[i] == '_') || (cmor_vars[var_id].id[i] == '-')) { - snprintf(outname, CMOR_MAX_STRING, - "var_id cannot contain %c you passed: %s " - "(table: %s). Please check your input tables\n! ", - cmor_vars[var_id].id[i], cmor_vars[var_id].id, - cmor_tables[nVarRefTblID].szTable_id); - cmor_handle_error_var(outname, CMOR_CRITICAL, var_id); + cmor_handle_error_var_variadic( + "var_id cannot contain %c you passed: %s " + "(table: %s). Please check your input tables\n! ", + CMOR_CRITICAL, var_id, + cmor_vars[var_id].id[i], cmor_vars[var_id].id, + cmor_tables[nVarRefTblID].szTable_id); cmor_pop_traceback(); return (1); @@ -4938,10 +5004,10 @@ int cmor_write(int var_id, void *data, char type, char *file_suffix, /* define global attributes */ /* -------------------------------------------------------------------- */ if (cmor_current_dataset.initiated == 0) { - snprintf(msg, CMOR_MAX_STRING, - "you need to initialize the dataset by calling " - "cmor_dataset_json before calling cmor_write"); - cmor_handle_error_var(msg, CMOR_NORMAL, var_id); + cmor_handle_error_var_variadic( + "you need to initialize the dataset by calling " + "cmor_dataset_json before calling cmor_write", + CMOR_NORMAL, var_id); cmor_pop_traceback(); return (1); } @@ -4954,15 +5020,15 @@ int cmor_write(int var_id, void *data, char type, char *file_suffix, /* -------------------------------------------------------------------- */ ierr = nc_redef(ncafid); if (ierr != NC_NOERR && ierr != NC_EINDEFINE) { - snprintf(msg, CMOR_MAX_STRING, + cmor_handle_error_var_variadic( "NetCDF Error (%i: %s) putting metadata file (%s) in\n! " - "def mode, nc file id was: %i, you were writing\n! " - "variable %s (table: %s)", ierr, - nc_strerror(ierr), + "def mode, nc file id was: %i, you were writing\n! " + "variable %s (table: %s)", + CMOR_CRITICAL, var_id, + ierr, nc_strerror(ierr), cmor_current_dataset.associated_file_name, ncafid, cmor_vars[var_id].id, cmor_tables[nVarRefTblID].szTable_id); - cmor_handle_error_var(msg, CMOR_CRITICAL, var_id); cmor_pop_traceback(); return (1); } @@ -5025,11 +5091,11 @@ int cmor_write(int var_id, void *data, char type, char *file_suffix, cmor_vars[var_id].ndims, &nc_dim[0], &nc_vars[cmor_vars[var_id].ndims]); if (ierr != NC_NOERR) { - snprintf(msg, CMOR_MAX_STRING, - "NetCDF Error (%i: %s) writing variable: %s (table: %s)", - ierr, nc_strerror(ierr), cmor_vars[var_id].id, - cmor_tables[nVarRefTblID].szTable_id); - cmor_handle_error_var(msg, CMOR_CRITICAL, var_id); + cmor_handle_error_var_variadic( + "NetCDF Error (%i: %s) writing variable: %s (table: %s)", + CMOR_CRITICAL, var_id, + ierr, nc_strerror(ierr), cmor_vars[var_id].id, + cmor_tables[nVarRefTblID].szTable_id); } /* -------------------------------------------------------------------- */ @@ -5061,13 +5127,13 @@ int cmor_write(int var_id, void *data, char type, char *file_suffix, ierr = nc_put_att_text(ncid, NC_GLOBAL, GLOBAL_ATT_TRACKING_ID, strlen(ctmp2), ctmp2); if (ierr != NC_NOERR) { - snprintf(msg, CMOR_MAX_STRING, - "NetCDF error (%i: %s) for variable %s (table: %s)\n! " - "writing global attribute: %s (%s)", - ierr, nc_strerror(ierr), cmor_vars[var_id].id, - cmor_tables[nVarRefTblID].szTable_id, - "tracking_id", (char *)ctmp2); - cmor_handle_error_var(msg, CMOR_CRITICAL, var_id); + cmor_handle_error_var_variadic( + "NetCDF error (%i: %s) for variable %s (table: %s)\n! " + "writing global attribute: %s (%s)", + CMOR_CRITICAL, var_id, + ierr, nc_strerror(ierr), cmor_vars[var_id].id, + cmor_tables[nVarRefTblID].szTable_id, + "tracking_id", (char *)ctmp2); cmor_pop_traceback(); return (1); @@ -5189,12 +5255,12 @@ void cmor_create_var_attributes(int var_id, int ncid, int ncafid, nc_put_att_int(ncid, cmor_vars[var_id].nc_var_id, "flag_values", NC_INT, nelts, int_list); if (ierr != NC_NOERR) { - snprintf(msg, CMOR_MAX_STRING, - "NetCDF Error (%i: %s) setting flags numerical\n! " - "attribute on variable %s (table: %s)", ierr, - nc_strerror(ierr), cmor_vars[var_id].id, - cmor_tables[nVarRefTblID].szTable_id); - cmor_handle_error_var(msg, CMOR_CRITICAL, var_id); + cmor_handle_error_var_variadic( + "NetCDF Error (%i: %s) setting flags numerical\n! " + "attribute on variable %s (table: %s)", + CMOR_CRITICAL, var_id, + ierr, nc_strerror(ierr), cmor_vars[var_id].id, + cmor_tables[nVarRefTblID].szTable_id); cmor_pop_traceback(); return; @@ -5247,12 +5313,12 @@ void cmor_create_var_attributes(int var_id, int ncid, int ncafid, } if (ierr != NC_NOERR) { - snprintf(msg, CMOR_MAX_STRING, - "NetCDF Error (%i: %s) defining compression\n! " - "parameters for variable '%s' (table: %s)", ierr, - nc_strerror(ierr), cmor_vars[var_id].id, - cmor_tables[nVarRefTblID].szTable_id); - cmor_handle_error_var(msg, CMOR_CRITICAL, var_id); + cmor_handle_error_var_variadic( + "NetCDF Error (%i: %s) defining compression\n! " + "parameters for variable '%s' (table: %s)", + CMOR_CRITICAL, var_id, + ierr, nc_strerror(ierr), cmor_vars[var_id].id, + cmor_tables[nVarRefTblID].szTable_id); cmor_pop_traceback(); return; @@ -5275,12 +5341,12 @@ void cmor_create_var_attributes(int var_id, int ncid, int ncafid, nc_def_var_chunking(ncid, cmor_vars[var_id].nc_var_id, NC_CHUNKED, NULL); if (ierr != NC_NOERR) { - snprintf(msg, CMOR_MAX_STRING, - "NetCDFTestTables/CMIP6_chunking.json: Error (%i: %s) defining chunking\n! " - "parameters for variable '%s' (table: %s)", - ierr, nc_strerror(ierr), cmor_vars[var_id].id, - cmor_tables[nVarRefTblID].szTable_id); - cmor_handle_error_var(msg, CMOR_CRITICAL, var_id); + cmor_handle_error_var_variadic( + "NetCDFTestTables/CMIP6_chunking.json: Error (%i: %s) defining chunking\n! " + "parameters for variable '%s' (table: %s)", + CMOR_CRITICAL, var_id, + ierr, nc_strerror(ierr), cmor_vars[var_id].id, + cmor_tables[nVarRefTblID].szTable_id); cmor_pop_traceback(); return; @@ -5294,21 +5360,21 @@ void cmor_create_var_attributes(int var_id, int ncid, int ncafid, ierr = nc_enddef(ncid); if (ierr != NC_NOERR && ierr != NC_ENOTINDEFINE) { - snprintf(msg, CMOR_MAX_STRING, - "NetCDF Error (%i: %s) leaving definition mode for file %s", - ierr, nc_strerror(ierr), outname); - cmor_handle_error_var(msg, CMOR_CRITICAL, var_id); + cmor_handle_error_var_variadic( + "NetCDF Error (%i: %s) leaving definition mode for file %s", + CMOR_CRITICAL, var_id, + ierr, nc_strerror(ierr), outname); cmor_pop_traceback(); return; } ierr = nc_enddef(ncafid); if (ierr != NC_NOERR && ierr != NC_ENOTINDEFINE) { - snprintf(msg, CMOR_MAX_STRING, - "NetCDF Error (%i: %s) leaving definition mode for metafile %s", - ierr, nc_strerror(ierr), - cmor_current_dataset.associated_file_name); - cmor_handle_error_var(msg, CMOR_CRITICAL, var_id); + cmor_handle_error_var_variadic( + "NetCDF Error (%i: %s) leaving definition mode for metafile %s", + CMOR_CRITICAL, var_id, + ierr, nc_strerror(ierr), + cmor_current_dataset.associated_file_name); cmor_pop_traceback(); return; @@ -5355,13 +5421,13 @@ void cmor_create_var_attributes(int var_id, int ncid, int ncafid, break; } if (k == -1) { - snprintf(msg, CMOR_MAX_STRING, - "could not find 'a' coeff for axis: %s,\n! " - "for variable %s (table: %s)", - cmor_axes[cmor_vars[var_id].axes_ids[i]].id, - cmor_vars[var_id].id, - cmor_tables[nVarRefTblID].szTable_id); - cmor_handle_error_var(msg, CMOR_CRITICAL, var_id); + cmor_handle_error_var_variadic( + "could not find 'a' coeff for axis: %s,\n! " + "for variable %s (table: %s)", + CMOR_CRITICAL, var_id, + cmor_axes[cmor_vars[var_id].axes_ids[i]].id, + cmor_vars[var_id].id, + cmor_tables[nVarRefTblID].szTable_id); cmor_pop_traceback(); return; @@ -5384,13 +5450,13 @@ void cmor_create_var_attributes(int var_id, int ncid, int ncafid, break; } if (k == -1) { - snprintf(msg, CMOR_MAX_STRING, - "could find 'b' coeff for axis: %s,\n! " - "for variable %s (table: %s)", - cmor_axes[cmor_vars[var_id].axes_ids[i]].id, - cmor_vars[var_id].id, - cmor_tables[nVarRefTblID].szTable_id); - cmor_handle_error_var(msg, CMOR_CRITICAL, var_id); + cmor_handle_error_var_variadic( + "could find 'b' coeff for axis: %s,\n! " + "for variable %s (table: %s)", + CMOR_CRITICAL, var_id, + cmor_axes[cmor_vars[var_id].axes_ids[i]].id, + cmor_vars[var_id].id, + cmor_tables[nVarRefTblID].szTable_id); cmor_pop_traceback(); return; @@ -5415,13 +5481,13 @@ void cmor_create_var_attributes(int var_id, int ncid, int ncafid, break; } if (k == -1) { - snprintf(msg, CMOR_MAX_STRING, - "could not find 'a_bnds' coeff for\n! " - "axis: %s, for variable %s (table: %s)", - cmor_axes[cmor_vars[var_id].axes_ids[i]]. - id, cmor_vars[var_id].id, - cmor_tables[nVarRefTblID].szTable_id); - cmor_handle_error_var(msg, CMOR_CRITICAL, var_id); + cmor_handle_error_var_variadic( + "could not find 'a_bnds' coeff for\n! " + "axis: %s, for variable %s (table: %s)", + CMOR_CRITICAL, var_id, + cmor_axes[cmor_vars[var_id].axes_ids[i]]. + id, cmor_vars[var_id].id, + cmor_tables[nVarRefTblID].szTable_id); cmor_pop_traceback(); return; @@ -5441,13 +5507,13 @@ void cmor_create_var_attributes(int var_id, int ncid, int ncafid, break; } if (k == -1) { - snprintf(msg, CMOR_MAX_STRING, - "could find 'b_bnds' coef for axis:\n! " - " %s, for variable %s (table: %s)", - cmor_axes[cmor_vars[var_id].axes_ids[i]]. - id, cmor_vars[var_id].id, - cmor_tables[nVarRefTblID].szTable_id); - cmor_handle_error_var(msg, CMOR_CRITICAL, var_id); + cmor_handle_error_var_variadic( + "could find 'b_bnds' coef for axis:\n! " + " %s, for variable %s (table: %s)", + CMOR_CRITICAL, var_id, + cmor_axes[cmor_vars[var_id].axes_ids[i]].id, + cmor_vars[var_id].id, + cmor_tables[nVarRefTblID].szTable_id); cmor_pop_traceback(); return; @@ -5476,13 +5542,13 @@ void cmor_create_var_attributes(int var_id, int ncid, int ncafid, break; } if (k == -1) { - snprintf(msg, CMOR_MAX_STRING, - "could not find 'ap' coeff for axis:\n! " - "%s, for variable %s (table: %s)", - cmor_axes[cmor_vars[var_id].axes_ids[i]].id, - cmor_vars[var_id].id, - cmor_tables[nVarRefTblID].szTable_id); - cmor_handle_error_var(msg, CMOR_CRITICAL, var_id); + cmor_handle_error_var_variadic( + "could not find 'ap' coeff for axis:\n! " + "%s, for variable %s (table: %s)", + CMOR_CRITICAL, var_id, + cmor_axes[cmor_vars[var_id].axes_ids[i]].id, + cmor_vars[var_id].id, + cmor_tables[nVarRefTblID].szTable_id); cmor_pop_traceback(); return; @@ -5504,13 +5570,13 @@ void cmor_create_var_attributes(int var_id, int ncid, int ncafid, break; } if (k == -1) { - snprintf(msg, CMOR_MAX_STRING, - "could find 'b' coef for axis: %s,\n! " - "for variable %s (table: %s)", - cmor_axes[cmor_vars[var_id].axes_ids[i]].id, - cmor_vars[var_id].id, - cmor_tables[nVarRefTblID].szTable_id); - cmor_handle_error_var(msg, CMOR_CRITICAL, var_id); + cmor_handle_error_var_variadic( + "could find 'b' coef for axis: %s,\n! " + "for variable %s (table: %s)", + CMOR_CRITICAL, var_id, + cmor_axes[cmor_vars[var_id].axes_ids[i]].id, + cmor_vars[var_id].id, + cmor_tables[nVarRefTblID].szTable_id); cmor_pop_traceback(); return; @@ -5535,14 +5601,14 @@ void cmor_create_var_attributes(int var_id, int ncid, int ncafid, break; } if (k == -1) { - snprintf(msg, CMOR_MAX_STRING, - "could not find 'ap_bnds' coeff for\n! " - "axis: %s, for variable %s\n! " - "(table: %s)", - cmor_axes[cmor_vars[var_id].axes_ids[i]]. - id, cmor_vars[var_id].id, - cmor_tables[nVarRefTblID].szTable_id); - cmor_handle_error_var(msg, CMOR_CRITICAL, var_id); + cmor_handle_error_var_variadic( + "could not find 'ap_bnds' coeff for\n! " + "axis: %s, for variable %s\n! " + "(table: %s)", + CMOR_CRITICAL, var_id, + cmor_axes[cmor_vars[var_id].axes_ids[i]]. + id, cmor_vars[var_id].id, + cmor_tables[nVarRefTblID].szTable_id); cmor_pop_traceback(); return; @@ -5563,13 +5629,13 @@ void cmor_create_var_attributes(int var_id, int ncid, int ncafid, break; } if (k == -1) { - snprintf(msg, CMOR_MAX_STRING, - "could find 'b_bnds' coef for axis:\n! " - "%s, for variable %s (table: %s)", - cmor_axes[cmor_vars[var_id].axes_ids[i]]. - id, cmor_vars[var_id].id, - cmor_tables[nVarRefTblID].szTable_id); - cmor_handle_error_var(msg, CMOR_CRITICAL, var_id); + cmor_handle_error_var_variadic( + "could find 'b_bnds' coef for axis:\n! " + "%s, for variable %s (table: %s)", + CMOR_CRITICAL, var_id, + cmor_axes[cmor_vars[var_id].axes_ids[i]]. + id, cmor_vars[var_id].id, + cmor_tables[nVarRefTblID].szTable_id); cmor_pop_traceback(); return; @@ -5595,13 +5661,13 @@ void cmor_create_var_attributes(int var_id, int ncid, int ncafid, break; } if (k == -1) { - snprintf(msg, CMOR_MAX_STRING, - "could not find 'sigma' coeff for axis:\n! " - "%s, for variable %s (table: %s)", - cmor_axes[cmor_vars[var_id].axes_ids[i]].id, - cmor_vars[var_id].id, - cmor_tables[nVarRefTblID].szTable_id); - cmor_handle_error_var(msg, CMOR_CRITICAL, var_id); + cmor_handle_error_var_variadic( + "could not find 'sigma' coeff for axis:\n! " + "%s, for variable %s (table: %s)", + CMOR_CRITICAL, var_id, + cmor_axes[cmor_vars[var_id].axes_ids[i]].id, + cmor_vars[var_id].id, + cmor_tables[nVarRefTblID].szTable_id); cmor_pop_traceback(); return; @@ -5625,13 +5691,13 @@ void cmor_create_var_attributes(int var_id, int ncid, int ncafid, break; } if (k == -1) { - snprintf(msg, CMOR_MAX_STRING, - "could not find 'sigma_bnds' coeff\n! " - "for axis: %s, for variable %s (table: %s)", - cmor_axes[cmor_vars[var_id].axes_ids[i]]. - id, cmor_vars[var_id].id, - cmor_tables[nVarRefTblID].szTable_id); - cmor_handle_error_var(msg, CMOR_CRITICAL, var_id); + cmor_handle_error_var_variadic( + "could not find 'sigma_bnds' coeff\n! " + "for axis: %s, for variable %s (table: %s)", + CMOR_CRITICAL, var_id, + cmor_axes[cmor_vars[var_id].axes_ids[i]].id, + cmor_vars[var_id].id, + cmor_tables[nVarRefTblID].szTable_id); cmor_pop_traceback(); return; @@ -5653,14 +5719,14 @@ void cmor_create_var_attributes(int var_id, int ncid, int ncafid, cmor_axes[cmor_vars[var_id].axes_ids [i]].values); if (ierr != NC_NOERR) { - snprintf(msg, CMOR_MAX_STRING, - "NetCDF Error (%i: %s) writing axis '%s'\n! " - "values for variable %s (table: %s)", ierr, - nc_strerror(ierr), - cmor_axes[cmor_vars[var_id].axes_ids[i]].id, - cmor_vars[var_id].id, - cmor_tables[nVarRefTblID].szTable_id); - cmor_handle_error_var(msg, CMOR_CRITICAL, var_id); + cmor_handle_error_var_variadic( + "NetCDF Error (%i: %s) writing axis '%s'\n! " + "values for variable %s (table: %s)", + CMOR_CRITICAL, var_id, + ierr, nc_strerror(ierr), + cmor_axes[cmor_vars[var_id].axes_ids[i]].id, + cmor_vars[var_id].id, + cmor_tables[nVarRefTblID].szTable_id); cmor_pop_traceback(); return; @@ -5671,14 +5737,15 @@ void cmor_create_var_attributes(int var_id, int ncid, int ncafid, [var_id]. axes_ids[i]].values); if (ierr != NC_NOERR) { - snprintf(msg, CMOR_MAX_STRING, - "NetCDF Error (%i: %s) writing axis '%s'\n! " - "values to metafile, for variable %s " - "(table: %s)", ierr, nc_strerror(ierr), - cmor_axes[cmor_vars[var_id].axes_ids[i]].id, - cmor_vars[var_id].id, - cmor_tables[nVarRefTblID].szTable_id); - cmor_handle_error_var(msg, CMOR_CRITICAL, var_id); + cmor_handle_error_var_variadic( + "NetCDF Error (%i: %s) writing axis '%s'\n! " + "values to metafile, for variable %s " + "(table: %s)", + CMOR_CRITICAL, var_id, + ierr, nc_strerror(ierr), + cmor_axes[cmor_vars[var_id].axes_ids[i]].id, + cmor_vars[var_id].id, + cmor_tables[nVarRefTblID].szTable_id); cmor_pop_traceback(); return; @@ -5698,15 +5765,16 @@ void cmor_create_var_attributes(int var_id, int ncid, int ncafid, cmor_axes[cmor_vars[var_id].axes_ids[i]]. cvalues[j]); if (ierr != NC_NOERR) { - snprintf(msg, CMOR_MAX_STRING, - "NetCDF Error (%i: %s) writing axis '%s'\n! " - "value number %d (%s), for variable %s " - "(table: %s)", ierr, nc_strerror(ierr), - cmor_axes[cmor_vars[var_id].axes_ids[i]].id, j, - cmor_axes[cmor_vars[var_id].axes_ids[i]]. - cvalues[j], cmor_vars[var_id].id, - cmor_tables[nVarRefTblID].szTable_id); - cmor_handle_error_var(msg, CMOR_CRITICAL, var_id); + cmor_handle_error_var_variadic( + "NetCDF Error (%i: %s) writing axis '%s'\n! " + "value number %d (%s), for variable %s " + "(table: %s)", + CMOR_CRITICAL, var_id, + ierr, nc_strerror(ierr), + cmor_axes[cmor_vars[var_id].axes_ids[i]].id, j, + cmor_axes[cmor_vars[var_id].axes_ids[i]]. + cvalues[j], cmor_vars[var_id].id, + cmor_tables[nVarRefTblID].szTable_id); cmor_pop_traceback(); return; @@ -5718,14 +5786,15 @@ void cmor_create_var_attributes(int var_id, int ncid, int ncafid, cmor_axes[cmor_vars[var_id].axes_ids[i]]. cvalues[j]); if (ierr != NC_NOERR) { - snprintf(msg, CMOR_MAX_STRING, - "NetCDF Error (%i: %s) writing axis '%s'\n! " - "values to metafile, for variable %s\n! " - "(table: %s)", ierr, nc_strerror(ierr), - cmor_axes[cmor_vars[var_id].axes_ids[i]].id, - cmor_vars[var_id].id, - cmor_tables[nVarRefTblID].szTable_id); - cmor_handle_error_var(msg, CMOR_CRITICAL, var_id); + cmor_handle_error_var_variadic( + "NetCDF Error (%i: %s) writing axis '%s'\n! " + "values to metafile, for variable %s\n! " + "(table: %s)", + CMOR_CRITICAL, var_id, + ierr, nc_strerror(ierr), + cmor_axes[cmor_vars[var_id].axes_ids[i]].id, + cmor_vars[var_id].id, + cmor_tables[nVarRefTblID].szTable_id); cmor_pop_traceback(); return; @@ -5741,15 +5810,16 @@ void cmor_create_var_attributes(int var_id, int ncid, int ncafid, cmor_axes[cmor_vars[var_id].axes_ids[i]]. bounds); if (ierr != NC_NOERR) { - snprintf(msg, CMOR_MAX_STRING, - "NC error (%i: %s) on variable %s writing\n! " - "bounds for dim %i (%s), for variable %s\n! " - "(table: %s)", ierr, nc_strerror(ierr), - cmor_vars[var_id].id, i, - cmor_axes[cmor_vars[var_id].axes_ids[i]].id, - cmor_vars[var_id].id, - cmor_tables[nVarRefTblID].szTable_id); - cmor_handle_error_var(msg, CMOR_CRITICAL, var_id); + cmor_handle_error_var_variadic( + "NC error (%i: %s) on variable %s writing\n! " + "bounds for dim %i (%s), for variable %s\n! " + "(table: %s)", + CMOR_CRITICAL, var_id, + ierr, nc_strerror(ierr), + cmor_vars[var_id].id, i, + cmor_axes[cmor_vars[var_id].axes_ids[i]].id, + cmor_vars[var_id].id, + cmor_tables[nVarRefTblID].szTable_id); cmor_pop_traceback(); return; @@ -5840,14 +5910,14 @@ void cmor_create_var_attributes(int var_id, int ncid, int ncafid, cmor_axes[j].values); } if (ierr != NC_NOERR) { - snprintf(msg, CMOR_MAX_STRING, - "NetCDF Error (%i: %s) writing scalar variable\n! " - "%s for variable %s (table: %s), value: %lf", - ierr, nc_strerror(ierr), cmor_axes[j].id, - cmor_vars[var_id].id, - cmor_tables[nVarRefTblID].szTable_id, - cmor_axes[j].values[0]); - cmor_handle_error_var(msg, CMOR_CRITICAL, var_id); + cmor_handle_error_var_variadic( + "NetCDF Error (%i: %s) writing scalar variable\n! " + "%s for variable %s (table: %s), value: %lf", + CMOR_CRITICAL, var_id, + ierr, nc_strerror(ierr), cmor_axes[j].id, + cmor_vars[var_id].id, + cmor_tables[nVarRefTblID].szTable_id, + cmor_axes[j].values[0]); cmor_pop_traceback(); return; @@ -5859,14 +5929,15 @@ void cmor_create_var_attributes(int var_id, int ncid, int ncafid, ierr = nc_put_var_double(ncid, nc_singletons_bnds[i], cmor_axes[j].bounds); if (ierr != NC_NOERR) { - snprintf(msg, CMOR_MAX_STRING, - "NetCDF Error (%i: %s) writing scalar bounds\n! " - "variable %s for variable %s (table: %s),\n! " - "values: %lf, %lf", ierr, nc_strerror(ierr), - cmor_axes[j].id, cmor_vars[var_id].id, - cmor_tables[nVarRefTblID].szTable_id, - cmor_axes[j].bounds[0], cmor_axes[j].bounds[1]); - cmor_handle_error_var(msg, CMOR_CRITICAL, var_id); + cmor_handle_error_var_variadic( + "NetCDF Error (%i: %s) writing scalar bounds\n! " + "variable %s for variable %s (table: %s),\n! " + "values: %lf, %lf", + CMOR_CRITICAL, var_id, + ierr, nc_strerror(ierr), + cmor_axes[j].id, cmor_vars[var_id].id, + cmor_tables[nVarRefTblID].szTable_id, + cmor_axes[j].bounds[0], cmor_axes[j].bounds[1]); cmor_pop_traceback(); return; @@ -5953,7 +6024,8 @@ int cmor_CreateFromTemplate(int nVarRefTblID, char *templateSTH, } else { char szInternalAtt[CMOR_MAX_STRING]; strcpy(szInternalAtt, GLOBAL_INTERNAL); - strncat(szInternalAtt, szToken, strlen(szToken)); + strncat(szInternalAtt, szToken, + CMOR_MAX_STRING - strlen(szInternalAtt)); if (cmor_has_cur_dataset_attribute(szInternalAtt) == 0) { cmor_get_cur_dataset_attribute(szInternalAtt, tmp); if (!optional) { @@ -6028,8 +6100,6 @@ int cmor_addRIPF(char *variant) char szValue[CMOR_MAX_STRING]; char szVariant[CMOR_MAX_STRING]; - char msg[CMOR_MAX_STRING]; - cmor_add_traceback("cmor_addRipf"); cmor_is_setup(); reti = regcomp(®ex, "^[[:digit:]]\\{1,\\}$", 0); @@ -6040,20 +6110,19 @@ int cmor_addRIPF(char *variant) if (cmor_has_cur_dataset_attribute(GLOBAL_ATT_REALIZATION) == 0) { cmor_get_cur_dataset_attribute(GLOBAL_ATT_REALIZATION, tmp); if (strlen(tmp) > 4) { - snprintf(msg, CMOR_MAX_STRING, - "Your realization_index \"%s\" is invalid. \n! " - "It cannot contains more than 4 digits. \n! ", tmp); - cmor_handle_error(msg, CMOR_NORMAL); + cmor_handle_error_variadic( + "Your realization_index \"%s\" is invalid. \n! " + "It cannot contains more than 4 digits. \n! ", + CMOR_NORMAL, tmp); ierr += -1; } reti = regexec(®ex, tmp, 0, NULL, 0); if (reti) { - snprintf(msg, CMOR_MAX_STRING, - "Your realization_index \"%s\" is invalid. \n! " - "It must contain only characters between 0 and 9 \n!", - tmp); - cmor_handle_error(msg, CMOR_NORMAL); + cmor_handle_error_variadic( + "Your realization_index \"%s\" is invalid. \n! " + "It must contain only characters between 0 and 9 \n!", + CMOR_NORMAL, tmp); ierr += -1; } @@ -6067,20 +6136,19 @@ int cmor_addRIPF(char *variant) if (cmor_has_cur_dataset_attribute(GLOBAL_ATT_INITIA_IDX) == 0) { cmor_get_cur_dataset_attribute(GLOBAL_ATT_INITIA_IDX, tmp); if (strlen(tmp) > 4) { - snprintf(msg, CMOR_MAX_STRING, - "Your initialization_index \"%s\" is invalid. \n! " - "It cannot contains more than 4 digits. \n! ", tmp); - cmor_handle_error(msg, CMOR_NORMAL); + cmor_handle_error_variadic( + "Your initialization_index \"%s\" is invalid. \n! " + "It cannot contains more than 4 digits. \n! ", + CMOR_NORMAL, tmp); ierr += -1; } reti = regexec(®ex, tmp, 0, NULL, 0); if (reti) { - snprintf(msg, CMOR_MAX_STRING, - "Your initialization_index \"%s\" is invalid. \n! " - "It must contain only characters between 0 and 9 \n!", - tmp); - cmor_handle_error(msg, CMOR_NORMAL); + cmor_handle_error_variadic( + "Your initialization_index \"%s\" is invalid. \n! " + "It must contain only characters between 0 and 9 \n!", + CMOR_NORMAL, tmp); ierr += -1; } @@ -6095,20 +6163,19 @@ int cmor_addRIPF(char *variant) if (cmor_has_cur_dataset_attribute(GLOBAL_ATT_PHYSICS_IDX) == 0) { cmor_get_cur_dataset_attribute(GLOBAL_ATT_PHYSICS_IDX, tmp); if (strlen(tmp) > 4) { - snprintf(msg, CMOR_MAX_STRING, - "Your physics_index \"%s\" is invalid. \n! " - "It cannot contains more than 4 digits. \n! ", tmp); - cmor_handle_error(msg, CMOR_NORMAL); + cmor_handle_error_variadic( + "Your physics_index \"%s\" is invalid. \n! " + "It cannot contains more than 4 digits. \n! ", + CMOR_NORMAL, tmp); ierr += -1; } reti = regexec(®ex, tmp, 0, NULL, 0); if (reti) { - snprintf(msg, CMOR_MAX_STRING, - "Your physics_index \"%s\" is invalid. \n! " - "It must contain only characters between 0 and 9 \n!", - tmp); - cmor_handle_error(msg, CMOR_NORMAL); + cmor_handle_error_variadic( + "Your physics_index \"%s\" is invalid. \n! " + "It must contain only characters between 0 and 9 \n!", + CMOR_NORMAL, tmp); ierr += -1; } @@ -6122,20 +6189,19 @@ int cmor_addRIPF(char *variant) if (cmor_has_cur_dataset_attribute(GLOBAL_ATT_FORCING_IDX) == 0) { cmor_get_cur_dataset_attribute(GLOBAL_ATT_FORCING_IDX, tmp); if (strlen(tmp) > 4) { - snprintf(msg, CMOR_MAX_STRING, - "Your forcing_index \"%s\" is invalid. \n! " - "It cannot contains more than 4 digits. \n! ", tmp); - cmor_handle_error(msg, CMOR_NORMAL); + cmor_handle_error_variadic( + "Your forcing_index \"%s\" is invalid. \n! " + "It cannot contains more than 4 digits. \n! ", + CMOR_NORMAL, tmp); ierr += -1; } reti = regexec(®ex, tmp, 0, NULL, 0); if (reti) { - snprintf(msg, CMOR_MAX_STRING, - "Your forcing_index \"%s\" is invalid. \n! " - "It must contain only characters between 0 and 9 \n!", - tmp); - cmor_handle_error(msg, CMOR_NORMAL); + cmor_handle_error_variadic( + "Your forcing_index \"%s\" is invalid. \n! " + "It must contain only characters between 0 and 9 \n!", + CMOR_NORMAL, tmp); ierr += -1; } @@ -6190,12 +6256,12 @@ int cmor_build_outname(int var_id, char *outname ) { cmor_get_cur_dataset_attribute("calendar", msg2); if (cmor_calendar_c2i(msg2, &icalo) != 0) { - snprintf(msg, CMOR_MAX_STRING, - "Cannot convert times for calendar: %s,\n! " - "closing variable %s (table: %s)", msg2, - cmor_vars[var_id].id, - cmor_tables[cmor_vars[var_id].ref_table_id].szTable_id); - cmor_handle_error_var(msg, CMOR_CRITICAL, var_id); + cmor_handle_error_var_variadic( + "Cannot convert times for calendar: %s,\n! " + "closing variable %s (table: %s)", + CMOR_CRITICAL, var_id, + msg2, cmor_vars[var_id].id, + cmor_tables[cmor_vars[var_id].ref_table_id].szTable_id); cmor_pop_traceback(); return (1); } @@ -6344,11 +6410,11 @@ int cmor_build_outname(int var_id, char *outname ) { /* don't need to do anything, time string will ignored in next step */ break; default: - snprintf(msg, CMOR_MAX_STRING, - "Cannot find frequency %s. Closing variable %s (table: %s)", - frequency, cmor_vars[var_id].id, - cmor_tables[cmor_vars[var_id].ref_table_id].szTable_id); - cmor_handle_error_var(msg, CMOR_CRITICAL, var_id); + cmor_handle_error_var_variadic( + "Cannot find frequency %s. Closing variable %s (table: %s)", + CMOR_CRITICAL, var_id, + frequency, cmor_vars[var_id].id, + cmor_tables[cmor_vars[var_id].ref_table_id].szTable_id); cmor_pop_traceback(); return (1); } @@ -6429,11 +6495,11 @@ int cmor_close_variable(int var_id, char *file_name, int *preserve) ierr = nc_close(cmor_vars[var_id].initialized); if (ierr != NC_NOERR) { - snprintf(msg, CMOR_MAX_STRING, - "NetCDF Error (%i: %s) closing variable %s (table: %s)\n! ", - ierr, nc_strerror(ierr), cmor_vars[var_id].id, - cmor_tables[cmor_vars[var_id].ref_table_id].szTable_id); - cmor_handle_error_var(msg, CMOR_CRITICAL, var_id); + cmor_handle_error_var_variadic( + "NetCDF Error (%i: %s) closing variable %s (table: %s)\n! ", + CMOR_CRITICAL, var_id, + ierr, nc_strerror(ierr), cmor_vars[var_id].id, + cmor_tables[cmor_vars[var_id].ref_table_id].szTable_id); cmor_pop_traceback(); return (1); } @@ -6479,23 +6545,23 @@ int cmor_close_variable(int var_id, char *file_name, int *preserve) sprintf(ctmp, "%i", cmor_vars[var_id].ntimes_written_coords[i]); } - snprintf(msg, CMOR_MAX_STRING, - "while closing variable %i (%s, table %s)\n! " - "we noticed it has a time varying grid, \n! " - "you wrote %s time steps for the variable,\n! " - "but its associated variable %i (%s) has\n! " - "%s times written", - cmor_vars[var_id].self, - cmor_vars[var_id].id, - cmor_tables[cmor_vars[var_id]. - ref_table_id].szTable_id, ctmp2, - cmor_vars[cmor_grids - [cmor_vars[var_id].grid_id]. - associated_variables[i]].self, - cmor_vars[cmor_grids - [cmor_vars[var_id].grid_id]. - associated_variables[i]].id, ctmp); - cmor_handle_error_var(msg, CMOR_CRITICAL, var_id); + cmor_handle_error_var_variadic( + "while closing variable %i (%s, table %s)\n! " + "we noticed it has a time varying grid, \n! " + "you wrote %s time steps for the variable,\n! " + "but its associated variable %i (%s) has\n! " + "%s times written", + CMOR_CRITICAL, var_id, + cmor_vars[var_id].self, + cmor_vars[var_id].id, + cmor_tables[cmor_vars[var_id]. + ref_table_id].szTable_id, ctmp2, + cmor_vars[cmor_grids + [cmor_vars[var_id].grid_id]. + associated_variables[i]].self, + cmor_vars[cmor_grids + [cmor_vars[var_id].grid_id]. + associated_variables[i]].id, ctmp); cmor_pop_traceback(); return (1); @@ -6510,20 +6576,20 @@ int cmor_close_variable(int var_id, char *file_name, int *preserve) sprintf(ctmp2, "%i", cmor_vars[var_id].ntimes_written); sprintf(ctmp, "%i", cmor_vars[var_id].ntimes_written_associated[i]); - snprintf(msg, CMOR_MAX_STRING, - "while closing variable %i (%s, table %s) we\n! " - "noticed it has a time varying associated\n! " - "variable, you wrote %s time steps for the\n! " - "variable, but its associated variable %i (%s)\n! " - "has %s times written", - cmor_vars[var_id].self, cmor_vars[var_id].id, - cmor_tables[cmor_vars[var_id].ref_table_id]. - szTable_id, ctmp2, - cmor_vars[cmor_vars[var_id].associated_ids[i]]. - self, - cmor_vars[cmor_vars[var_id].associated_ids[i]].id, - ctmp); - cmor_handle_error_var(msg, CMOR_CRITICAL, var_id); + cmor_handle_error_var_variadic( + "while closing variable %i (%s, table %s) we\n! " + "noticed it has a time varying associated\n! " + "variable, you wrote %s time steps for the\n! " + "variable, but its associated variable %i (%s)\n! " + "has %s times written", + CMOR_CRITICAL, var_id, + cmor_vars[var_id].self, cmor_vars[var_id].id, + cmor_tables[cmor_vars[var_id].ref_table_id]. + szTable_id, ctmp2, + cmor_vars[cmor_vars[var_id].associated_ids[i]]. + self, + cmor_vars[cmor_vars[var_id].associated_ids[i]].id, + ctmp); cmor_pop_traceback(); return (1); @@ -6540,18 +6606,17 @@ int cmor_close_variable(int var_id, char *file_name, int *preserve) && cmor_axes[cmor_vars[var_id].axes_ids[i]].length > 0 && (cmor_vars[var_id].ntimes_written < cmor_axes[cmor_vars[var_id].axes_ids[i]].length)) { - snprintf(msg, CMOR_MAX_STRING, - "while closing variable %i (%s, table %s)\n! " - "we noticed you wrote %i time steps for the variable,\n! " - "but its time axis %i (%s) has %i time steps", - cmor_vars[var_id].self, - cmor_vars[var_id].id, - cmor_tables[cmor_vars[var_id].ref_table_id].szTable_id, - cmor_vars[var_id].ntimes_written, i, - cmor_axes[cmor_vars[var_id].axes_ids[i]].id, - cmor_axes[cmor_vars[var_id].axes_ids[i]].length); - - cmor_handle_error_var(msg, CMOR_WARNING, var_id); + cmor_handle_error_var_variadic( + "while closing variable %i (%s, table %s)\n! " + "we noticed you wrote %i time steps for the variable,\n! " + "but its time axis %i (%s) has %i time steps", + CMOR_WARNING, var_id, + cmor_vars[var_id].self, + cmor_vars[var_id].id, + cmor_tables[cmor_vars[var_id].ref_table_id].szTable_id, + cmor_vars[var_id].ntimes_written, i, + cmor_axes[cmor_vars[var_id].axes_ids[i]].id, + cmor_axes[cmor_vars[var_id].axes_ids[i]].length); } } @@ -6586,12 +6651,12 @@ int cmor_close_variable(int var_id, char *file_name, int *preserve) "you were trying to write has been saved\n! " "at: %s.copy", outname, outname); } else { - snprintf(msg, CMOR_MAX_STRING, - "Output file ( %s ) already exists,\n! " - "remove file or use CMOR_REPLACE or\n! " - "CMOR_APPEND for CMOR_NETCDF_MODE value in\n! " - "cmor_setup.", outname); - cmor_handle_error_var(msg, CMOR_CRITICAL, var_id); + cmor_handle_error_var_variadic( + "Output file ( %s ) already exists,\n! " + "remove file or use CMOR_REPLACE or\n! " + "CMOR_APPEND for CMOR_NETCDF_MODE value in\n! " + "cmor_setup.", + CMOR_CRITICAL, var_id, outname); } ierr = fclose(fperr); fperr = NULL; @@ -6599,10 +6664,11 @@ int cmor_close_variable(int var_id, char *file_name, int *preserve) } ierr = rename(cmor_vars[var_id].current_path, outname); if (ierr != 0) { - snprintf(msg, CMOR_MAX_STRING, - "could not rename temporary file: %s to final file\n" - "name: %s", cmor_vars[var_id].current_path, outname); - cmor_handle_error_var(msg, CMOR_CRITICAL, var_id); + cmor_handle_error_var_variadic( + "could not rename temporary file: %s to final file\n" + "name: %s", + CMOR_CRITICAL, var_id, + cmor_vars[var_id].current_path, outname); } if (file_name != NULL) { strncpy(file_name, outname, CMOR_MAX_STRING); @@ -6665,7 +6731,6 @@ int cmor_close(void) { int i, j, k; extern int cmor_nvars; - char msg[CMOR_MAX_STRING]; extern ut_system *ut_read; extern FILE *output_logfile; @@ -6681,11 +6746,12 @@ int cmor_close(void) } } else if ((cmor_vars[i].needsinit == 1) && (cmor_vars[i].closed != 1)) { - snprintf(msg, CMOR_MAX_STRING, - "variable %s (%i, table: %s) has been defined\n! " - "but never initialized", cmor_vars[i].id, i, - cmor_tables[cmor_vars[i].ref_table_id].szTable_id); - cmor_handle_error(msg, CMOR_WARNING); + cmor_handle_error_variadic( + "variable %s (%i, table: %s) has been defined\n! " + "but never initialized", + CMOR_WARNING, + cmor_vars[i].id, i, + cmor_tables[cmor_vars[i].ref_table_id].szTable_id); } else if (cmor_vars[i].zaxis != -1) { cmor_reset_variable(i); } diff --git a/Src/cmor_CV.c b/Src/cmor_CV.c index ac8f46c9..eeb71229 100644 --- a/Src/cmor_CV.c +++ b/Src/cmor_CV.c @@ -357,7 +357,6 @@ int cmor_CV_checkFurtherInfoURL(int nVarRefTblID) char szFurtherInfoBaseURL[CMOR_MAX_STRING]; char szFurtherInfoFileURL[CMOR_MAX_STRING]; char szValue[CMOR_MAX_STRING]; - char msg[CMOR_MAX_STRING]; char CV_Filename[CMOR_MAX_STRING]; char *baseURL; @@ -388,11 +387,10 @@ int cmor_CV_checkFurtherInfoURL(int nVarRefTblID) /* -------------------------------------------------------------------- */ szToken = strtok(szFurtherInfoURLTemplate, "<>"); if (szToken == NULL) { - snprintf(msg, CMOR_MAX_STRING, - "The further info URL value of \"%s\" is invalid. \n! ", - szFurtherInfoURLTemplate); - - cmor_handle_error(msg, CMOR_NORMAL); + cmor_handle_error_variadic( + "The further info URL value of \"%s\" is invalid. \n! ", + CMOR_NORMAL, + szFurtherInfoURLTemplate); cmor_pop_traceback(); return (-1); } @@ -420,21 +418,19 @@ int cmor_CV_checkFurtherInfoURL(int nVarRefTblID) strncpy(szFurtherInfoURL, szFurtherInfoBaseURL, CMOR_MAX_STRING); strcat(szFurtherInfoURL, "/"); strncat(szFurtherInfoURL, szFurtherInfoFileURL, - strlen(szFurtherInfoFileURL)); + CMOR_MAX_STRING - strlen(szFurtherInfoURL)); if (cmor_has_cur_dataset_attribute(GLOBAL_ATT_FURTHERINFOURL) == 0) { cmor_get_cur_dataset_attribute(GLOBAL_ATT_FURTHERINFOURL, szValue); if (strncmp(szFurtherInfoURL, szValue, CMOR_MAX_STRING) != 0) { cmor_get_cur_dataset_attribute(CV_INPUTFILENAME, CV_Filename); - snprintf(msg, CMOR_MAX_STRING, + cmor_handle_error_variadic( "The further info in attribute does not match " "the one found in your Control Vocabulary(CV) File. \n! " "We found \"%s\" and \n! " "CV requires \"%s\" \n! " "Check your Control Vocabulary file \"%s\".\n! ", - szValue, szFurtherInfoURL, CV_Filename); - - cmor_handle_error(msg, CMOR_WARNING); + CMOR_WARNING, szValue, szFurtherInfoURL, CV_Filename); cmor_pop_traceback(); return (-1); @@ -468,7 +464,6 @@ int cmor_CV_checkSourceType(cmor_CV_def_t * CV_exp, char *szExptID) char szReqSourceTypeCpy[CMOR_MAX_STRING]; char szSourceType[CMOR_MAX_STRING]; - char msg[CMOR_MAX_STRING]; char CV_Filename[CMOR_MAX_STRING]; int i, j; char *szTokenRequired; @@ -538,12 +533,11 @@ int cmor_CV_checkSourceType(cmor_CV_def_t * CV_exp, char *szExptID) while (szTokenRequired != NULL) { reti = regcomp(®ex, szTokenRequired, REG_EXTENDED); if (reti) { - snprintf(msg, CMOR_MAX_STRING, + cmor_handle_error_variadic( "You regular expression \"%s\" is invalid. \n! " "Please refer to the CMIP6 documentations.\n! ", - szTokenRequired); + CMOR_NORMAL, szTokenRequired); regfree(®ex); - cmor_handle_error(msg, CMOR_NORMAL); cmor_pop_traceback(); return (-1); } @@ -552,15 +546,14 @@ int cmor_CV_checkSourceType(cmor_CV_def_t * CV_exp, char *szExptID) /* -------------------------------------------------------------------- */ reti = regexec(®ex, szSourceType, 0, NULL, 0); if (reti == REG_NOMATCH) { - snprintf(msg, CMOR_MAX_STRING, + cmor_handle_error_variadic( "The following source type(s) \"%s\" are required and\n! " "some source type(s) could not be found in your " "input file. \n! " "Your file contains a source type of \"%s\".\n! " "Check your Control Vocabulary file \"%s\".\n! ", - szReqSourceTypeCpy, szSourceType, CV_Filename); + CMOR_NORMAL, szReqSourceTypeCpy, szSourceType, CV_Filename); regfree(®ex); - cmor_handle_error(msg, CMOR_NORMAL); } else { nbGoodType++; } @@ -597,14 +590,13 @@ int cmor_CV_checkSourceType(cmor_CV_def_t * CV_exp, char *szExptID) } if (nbGoodType != nbSourceType) { - snprintf(msg, CMOR_MAX_STRING, + cmor_handle_error_variadic( "You source_type attribute contains invalid source types\n! " "Your source type is set to \"%s\". The required source types\n! " "are \"%s\" and possible additional source types are \"%s\" \n! " "Check your Control Vocabulary file \"%s\".\n! ", - szSourceType, szReqSourceTypeCpy, szAddSourceTypeCpy, + CMOR_NORMAL, szSourceType, szReqSourceTypeCpy, szAddSourceTypeCpy, CV_Filename); - cmor_handle_error(msg, CMOR_NORMAL); cmor_pop_traceback(); return (-1); } @@ -628,7 +620,6 @@ int cmor_CV_checkSourceID(cmor_CV_def_t * CV) char *pos; int nLen; - char msg[CMOR_MAX_STRING]; char CV_Filename[CMOR_MAX_STRING]; char CMOR_Filename[CMOR_MAX_STRING]; int rc; @@ -651,22 +642,20 @@ int cmor_CV_checkSourceID(cmor_CV_def_t * CV) CV_source_ids = cmor_CV_rootsearch(CV, CV_KEY_SOURCE_IDS); if (CV_source_ids == NULL) { - snprintf(msg, CMOR_MAX_STRING, + cmor_handle_error_variadic( "Your \"source_ids\" key could not be found in\n! " - "your Control Vocabulary file.(%s)\n! ", CV_Filename); + "your Control Vocabulary file.(%s)\n! ", CMOR_NORMAL, CV_Filename); - cmor_handle_error(msg, CMOR_NORMAL); cmor_pop_traceback(); return (-1); } // retrieve source_id rc = cmor_get_cur_dataset_attribute(GLOBAL_ATT_SOURCE_ID, szSource_ID); if (rc != 0) { - snprintf(msg, CMOR_MAX_STRING, + cmor_handle_error_variadic( "Your \"%s\" is not defined, check your required attributes\n! " "See Control Vocabulary JSON file.(%s)\n! ", - GLOBAL_ATT_SOURCE_ID, CV_Filename); - cmor_handle_error(msg, CMOR_NORMAL); + CMOR_NORMAL, GLOBAL_ATT_SOURCE_ID, CV_Filename); cmor_pop_traceback(); return (-1); } @@ -682,11 +671,10 @@ 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) { - snprintf(msg, CMOR_MAX_STRING, + cmor_handle_error_variadic( "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_CRITICAL); + CMOR_CRITICAL, CV_KEY_SOURCE_LABEL, szSource_ID, CV_Filename); return(-1); } for (j = 0; j < CV_source_id->nbObjects; j++) { @@ -696,11 +684,10 @@ int cmor_CV_checkSourceID(cmor_CV_def_t * CV) } } if (j == CV_source_id->nbObjects) { - snprintf(msg, CMOR_MAX_STRING, + cmor_handle_error_variadic( "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_CRITICAL); + CMOR_CRITICAL, CV_KEY_SOURCE_LABEL, CV_Filename); return(-1); } pos = strchr(CV_source_id->oValue[j].szValue, ')'); @@ -712,14 +699,13 @@ int cmor_CV_checkSourceID(cmor_CV_def_t * CV) } szSubstring[nLen] = '\0'; if (strncmp(szSubstring, szSource, nLen) != 0) { - snprintf(msg, CMOR_MAX_STRING, + cmor_handle_error_variadic( "Your input attribute \"%s\" with value \n! \"%s\" " "will be replaced with " "value \n! \"%s\".\n! \n! \n! " "See Control Vocabulary JSON file.(%s)\n! ", - GLOBAL_ATT_SOURCE, szSource, + CMOR_WARNING, GLOBAL_ATT_SOURCE, szSource, CV_source_id->oValue[j].szValue, CV_Filename); - cmor_handle_error(msg, CMOR_WARNING); } break; } @@ -727,7 +713,7 @@ int cmor_CV_checkSourceID(cmor_CV_def_t * CV) // We could not found the Source ID in the CV file if (i == CV_source_ids->nbObjects) { - snprintf(msg, CMOR_MAX_STRING, + cmor_handle_error_variadic( "The source_id, \"%s\", found in your \n! " "input file (%s) could not be found in \n! " "your Controlled Vocabulary file. (%s) \n! \n! " @@ -738,9 +724,8 @@ int cmor_CV_checkSourceID(cmor_CV_def_t * CV) "Contact \"pcmdi-cmip@llnl.gov\" for additional guidance. \n! \n! " "See \"http://cmor.llnl.gov/mydoc_cmor3_CV/\" for further information about\n! " "the \"source_id\" and \"source\" global attributes. ", - szSource_ID, CMOR_Filename, CV_Filename, CV_Filename); + CMOR_NORMAL, szSource_ID, CMOR_Filename, CV_Filename, CV_Filename); - cmor_handle_error(msg, CMOR_NORMAL); cmor_pop_traceback(); return (-1); } @@ -759,7 +744,6 @@ int cmor_CV_checkSourceID(cmor_CV_def_t * CV) /************************************************************************/ int CV_VerifyNBElement(cmor_CV_def_t * CV) { - char msg[CMOR_MAX_STRING]; char CV_Filename[CMOR_MAX_STRING]; cmor_get_cur_dataset_attribute(CV_INPUTFILENAME, CV_Filename); cmor_add_traceback("_CV_VerifyNBElement"); @@ -769,21 +753,19 @@ int CV_VerifyNBElement(cmor_CV_def_t * CV) // printf("**** CV->szValue: %s\n", CV->szValue); if (CV->anElements > 1) { - snprintf(msg, CMOR_MAX_STRING, + cmor_handle_error_variadic( "Your %s has more than 1 element\n! " "only the first one will be used\n! " "Check your Control Vocabulary file \"%s\".\n! ", - CV->key, CV_Filename); - cmor_handle_error(msg, CMOR_NORMAL); + CMOR_NORMAL, CV->key, CV_Filename); cmor_pop_traceback(); return (-1); } else if (CV->anElements == -1) { - snprintf(msg, CMOR_MAX_STRING, + cmor_handle_error_variadic( "Your %s has more than 0 element\n! " "Check your Control Vocabulary file \"%s\".\n! ", - CV->key, CV_Filename); + CMOR_NORMAL, CV->key, CV_Filename); - cmor_handle_error(msg, CMOR_NORMAL); cmor_pop_traceback(); return (-1); } @@ -796,19 +778,17 @@ int CV_VerifyNBElement(cmor_CV_def_t * CV) /************************************************************************/ int CV_CompareNoParent(char *szKey) { - char msg[CMOR_MAX_STRING]; char szValue[CMOR_MAX_STRING]; cmor_add_traceback("_CV_CompareNoParent"); if (cmor_has_cur_dataset_attribute(szKey) == 0) { cmor_get_cur_dataset_attribute(szKey, szValue); if (strcmp(szValue, NO_PARENT) != 0) { - snprintf(msg, CMOR_MAX_STRING, + cmor_handle_error_variadic( "Your input attribute %s with value \"%s\" \n! " - "will be replaced with value \"%s\".\n! ", szKey, - szValue, NO_PARENT); + "will be replaced with value \"%s\".\n! ", + CMOR_WARNING, szKey, szValue, NO_PARENT); cmor_set_cur_dataset_attribute_internal(szKey, NO_PARENT, 1); - cmor_handle_error(msg, CMOR_WARNING); } } cmor_pop_traceback(); @@ -852,7 +832,6 @@ int cmor_CV_checkSubExpID(cmor_CV_def_t * CV) char szValue[CMOR_MAX_STRING]; char szVariant[CMOR_MAX_STRING]; - char msg[CMOR_MAX_STRING]; int ierr = 0; cmor_add_traceback("_CV_checkSubExperiment"); @@ -860,42 +839,38 @@ int cmor_CV_checkSubExpID(cmor_CV_def_t * CV) cmor_get_cur_dataset_attribute(CV_INPUTFILENAME, CV_Filename); ierr = cmor_get_cur_dataset_attribute(GLOBAL_ATT_EXPERIMENTID, szExperiment_ID); if (ierr != 0) { - snprintf(msg, CMOR_MAX_STRING, + cmor_handle_error_variadic( "Your \"%s\" is not defined, check your required attributes\n! " "See Control Vocabulary JSON file.(%s)\n! ", - GLOBAL_ATT_EXPERIMENTID, CV_Filename); - cmor_handle_error(msg, CMOR_NORMAL); + CMOR_NORMAL, GLOBAL_ATT_EXPERIMENTID, CV_Filename); cmor_pop_traceback(); return (-1); } // Look for sub_experiment_id section CV_sub_experiment_id = cmor_CV_rootsearch(CV, CV_KEY_SUB_EXPERIMENT_ID); if (CV_sub_experiment_id == NULL) { - snprintf(msg, CMOR_MAX_STRING, + cmor_handle_error_variadic( "Your \"sub_experiment_id\" key could not be found in\n! " - "your Control Vocabulary file.(%s)\n! ", CV_Filename); - cmor_handle_error(msg, CMOR_NORMAL); + "your Control Vocabulary file.(%s)\n! ", CMOR_NORMAL, CV_Filename); cmor_pop_traceback(); return (-1); } // Look for experiment_id section CV_experiment_id = cmor_CV_rootsearch(CV, CV_KEY_EXPERIMENT_ID); if (CV_experiment_id == NULL) { - snprintf(msg, CMOR_MAX_STRING, + cmor_handle_error_variadic( "Your \"experiment_id\" key could not be found in\n! " - "your Control Vocabulary file.(%s)\n! ", CV_Filename); - cmor_handle_error(msg, CMOR_NORMAL); + "your Control Vocabulary file.(%s)\n! ", CMOR_NORMAL, CV_Filename); cmor_pop_traceback(); return (-1); } // Get specified experiment CV_experiment = cmor_CV_search_child_key(CV_experiment_id, szExperiment_ID); if (CV_experiment == NULL) { - snprintf(msg, CMOR_MAX_STRING, + cmor_handle_error_variadic( "Your experiment_id \"%s\" defined in your input file\n! " "could not be found in your Control Vocabulary file.(%s)\n! ", - szExperiment_ID, CV_Filename); - cmor_handle_error(msg, CMOR_NORMAL); + CMOR_NORMAL, szExperiment_ID, CV_Filename); cmor_pop_traceback(); return (-1); } @@ -903,11 +878,10 @@ int cmor_CV_checkSubExpID(cmor_CV_def_t * CV) CV_experiment_sub_exp_id = cmor_CV_search_child_key(CV_experiment, GLOBAL_ATT_SUB_EXPT_ID); if (CV_experiment_sub_exp_id == NULL) { - snprintf(msg, CMOR_MAX_STRING, + cmor_handle_error_variadic( "Your \"%s\" defined in your input file\n! " "could not be found in your Control Vocabulary file.(%s)\n! ", - GLOBAL_ATT_SUB_EXPT_ID, CV_Filename); - cmor_handle_error(msg, CMOR_NORMAL); + CMOR_NORMAL, GLOBAL_ATT_SUB_EXPT_ID, CV_Filename); cmor_pop_traceback(); return (-1); } @@ -915,22 +889,20 @@ int cmor_CV_checkSubExpID(cmor_CV_def_t * CV) if (cmor_has_cur_dataset_attribute(GLOBAL_ATT_SUB_EXPT_ID) != 0) { // sub_experiment_id not found and set to "none" if (CV_IsStringInArray(CV_experiment_sub_exp_id, NONE)) { - snprintf(msg, CMOR_MAX_STRING, + cmor_handle_error_variadic( "Your input attribute \"%s\" was not defined and \n! " "will be set to \"%s\"\n! " "as defined in your Control Vocabulary file \"%s\".\n! ", - GLOBAL_ATT_SUB_EXPT_ID, NONE, CV_Filename); - cmor_handle_error(msg, CMOR_WARNING); + CMOR_WARNING, GLOBAL_ATT_SUB_EXPT_ID, NONE, CV_Filename); cmor_set_cur_dataset_attribute_internal(GLOBAL_ATT_SUB_EXPT_ID, NONE, 1); } else { // can't be "none". - snprintf(msg, CMOR_MAX_STRING, + cmor_handle_error_variadic( "Your input attribute \"%s\" is not defined properly \n! " "for your experiment \"%s\" \n! \n! " "See Control Vocabulary JSON file.(%s)\n! ", - GLOBAL_ATT_SUB_EXPT_ID, szExperiment_ID, CV_Filename); - cmor_handle_error(msg, CMOR_NORMAL); + CMOR_NORMAL, GLOBAL_ATT_SUB_EXPT_ID, szExperiment_ID, CV_Filename); cmor_pop_traceback(); return (-1); @@ -943,26 +915,24 @@ int cmor_CV_checkSubExpID(cmor_CV_def_t * CV) if (!CV_IsStringInArray(CV_experiment_sub_exp_id, szSubExptID)) { // only 1 element in list set it! if (CV_experiment_sub_exp_id->anElements == 1) { - snprintf(msg, CMOR_MAX_STRING, + cmor_handle_error_variadic( "Your input attribute \"%s\" defined as \"%s\" " "will be replaced with \n! " "\"%s\" as defined in your Control Vocabulary file.\n! ", - GLOBAL_ATT_SUB_EXPT_ID, szSubExptID, + CMOR_WARNING, GLOBAL_ATT_SUB_EXPT_ID, szSubExptID, CV_experiment_sub_exp_id->aszValue[0]); - cmor_handle_error(msg, CMOR_WARNING); cmor_set_cur_dataset_attribute_internal(GLOBAL_ATT_SUB_EXPT_ID, CV_experiment_sub_exp_id->aszValue [0], 1); } else { // too many options. - snprintf(msg, CMOR_MAX_STRING, + cmor_handle_error_variadic( "Your input attribute \"%s\" is not defined properly \n! " "for your experiment \"%s\"\n! " "There is more than 1 option for this sub_experiment.\n! " "See Control Vocabulary JSON file.(%s)\n! ", - GLOBAL_ATT_SUB_EXPT_ID, szExperiment_ID, CV_Filename); - cmor_handle_error(msg, CMOR_NORMAL); + CMOR_NORMAL, GLOBAL_ATT_SUB_EXPT_ID, szExperiment_ID, CV_Filename); cmor_pop_traceback(); return (-1); } @@ -970,36 +940,33 @@ int cmor_CV_checkSubExpID(cmor_CV_def_t * CV) } // sub_experiment has not been defined! if (cmor_has_cur_dataset_attribute(GLOBAL_ATT_SUB_EXPT) != 0) { - snprintf(msg, CMOR_MAX_STRING, + cmor_handle_error_variadic( "Your input attribute \"%s\" was not defined and \n! " "will be set to \"%s\" \n! " "as defined in your Control Vocabulary file \"%s\".\n! ", - GLOBAL_ATT_SUB_EXPT, NONE, CV_Filename); - cmor_handle_error(msg, CMOR_WARNING); + CMOR_WARNING, GLOBAL_ATT_SUB_EXPT, NONE, CV_Filename); cmor_set_cur_dataset_attribute_internal(GLOBAL_ATT_SUB_EXPT, NONE, 1); } else { cmor_get_cur_dataset_attribute(GLOBAL_ATT_SUB_EXPT, szValue); CV_sub_experiment_id_key = cmor_CV_search_child_key(CV_sub_experiment_id, szSubExptID); if (CV_sub_experiment_id_key == NULL) { - snprintf(msg, CMOR_MAX_STRING, + cmor_handle_error_variadic( "Your \"sub_experiment\" text describing \n! " "sub_experiment_id \"%s\" could not be found in \n! " - "your Control Vocabulary file.(%s)\n! ", szSubExptID, - CV_Filename); - cmor_handle_error(msg, CMOR_NORMAL); + "your Control Vocabulary file.(%s)\n! ", + CMOR_NORMAL, szSubExptID, CV_Filename); cmor_pop_traceback(); return (-1); } if (strcmp(szValue, CV_sub_experiment_id_key->szValue) != 0) { - snprintf(msg, CMOR_MAX_STRING, + cmor_handle_error_variadic( "Your input attribute \"%s\" defined as \"%s\" " "will be replaced with \n! " "\"%s\" as defined in your Control Vocabulary file.\n! ", - GLOBAL_ATT_SUB_EXPT, szValue, + CMOR_WARNING, GLOBAL_ATT_SUB_EXPT, szValue, CV_sub_experiment_id_key->szValue); - cmor_handle_error(msg, CMOR_WARNING); cmor_set_cur_dataset_attribute_internal(GLOBAL_ATT_SUB_EXPT, CV_sub_experiment_id_key->szValue, 1); @@ -1051,7 +1018,6 @@ int cmor_CV_checkParentExpID(cmor_CV_def_t * CV) regex_t regex; char CV_Filename[CMOR_MAX_STRING]; - char msg[CMOR_MAX_STRING]; int rc; int ierr = 0; @@ -1061,22 +1027,20 @@ int cmor_CV_checkParentExpID(cmor_CV_def_t * CV) cmor_get_cur_dataset_attribute(CV_INPUTFILENAME, CV_Filename); ierr = cmor_get_cur_dataset_attribute(GLOBAL_ATT_EXPERIMENTID, szExperiment_ID); if (ierr != 0) { - snprintf(msg, CMOR_MAX_STRING, + cmor_handle_error_variadic( "Your \"%s\" is not defined, check your required attributes\n! " "See Control Vocabulary JSON file.(%s)\n! ", - GLOBAL_ATT_EXPERIMENTID, CV_Filename); - cmor_handle_error(msg, CMOR_NORMAL); + CMOR_NORMAL, GLOBAL_ATT_EXPERIMENTID, CV_Filename); cmor_pop_traceback(); return (-1); } // Look for experiment_id section CV_experiment_ids = cmor_CV_rootsearch(CV, CV_KEY_EXPERIMENT_ID); if (CV_experiment_ids == NULL) { - snprintf(msg, CMOR_MAX_STRING, + cmor_handle_error_variadic( "Your \"experiment_id\" key could not be found in\n! " - "your Control Vocabulary file.(%s)\n! ", CV_Filename); + "your Control Vocabulary file.(%s)\n! ", CMOR_NORMAL, CV_Filename); - cmor_handle_error(msg, CMOR_NORMAL); cmor_pop_traceback(); return (-1); } @@ -1084,11 +1048,10 @@ int cmor_CV_checkParentExpID(cmor_CV_def_t * CV) CV_experiment = cmor_CV_search_child_key(CV_experiment_ids, szExperiment_ID); if (CV_experiment == NULL) { - snprintf(msg, CMOR_MAX_STRING, + cmor_handle_error_variadic( "Your experiment_id \"%s\" defined in your input file\n! " "could not be found in your Control Vocabulary file.(%s)\n! ", - szExperiment_ID, CV_Filename); - cmor_handle_error(msg, CMOR_NORMAL); + CMOR_NORMAL, szExperiment_ID, CV_Filename); cmor_pop_traceback(); return (-1); } @@ -1097,22 +1060,20 @@ int cmor_CV_checkParentExpID(cmor_CV_def_t * CV) CV_parent_exp_id = cmor_CV_search_child_key(CV_experiment, PARENT_EXPERIMENT_ID); if (CV_IsStringInArray(CV_parent_exp_id, NO_PARENT)) { - snprintf(msg, CMOR_MAX_STRING, + cmor_handle_error_variadic( "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_WARNING, PARENT_EXPERIMENT_ID, NO_PARENT); cmor_set_cur_dataset_attribute_internal(PARENT_EXPERIMENT_ID, NO_PARENT, 1); } else { - snprintf(msg, CMOR_MAX_STRING, + cmor_handle_error_variadic( "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, + CMOR_NORMAL, GLOBAL_ATT_PARENT_EXPT_ID, CV_experiment->key, CV_Filename); - cmor_handle_error(msg, CMOR_NORMAL); cmor_pop_traceback(); return (-1); } @@ -1135,11 +1096,10 @@ int cmor_CV_checkParentExpID(cmor_CV_def_t * CV) szBranchTimeInChild); rc = sscanf(szBranchTimeInChild, "%lf", &dBranchTimeInChild); if ((rc == 0) || (rc == EOF)) { - snprintf(msg, CMOR_MAX_STRING, + cmor_handle_error_variadic( "Your input attribute branch_time_in_child \"%s\" " "is not a double floating point \n! ", - szBranchTimeInChild); - cmor_handle_error(msg, CMOR_WARNING); + CMOR_WARNING, szBranchTimeInChild); } } @@ -1147,26 +1107,24 @@ int cmor_CV_checkParentExpID(cmor_CV_def_t * CV) if (cmor_has_cur_dataset_attribute(BRANCH_TIME_IN_PARENT) == 0) { cmor_get_cur_dataset_attribute(BRANCH_TIME_IN_PARENT, szValue); if (strcmp(szValue, "0.0") != 0) { - snprintf(msg, CMOR_MAX_STRING, + cmor_handle_error_variadic( "Your input attribute %s %s \n! " "has been replaced with 0.0 \n! ", - BRANCH_TIME_IN_PARENT, szValue); + CMOR_WARNING, BRANCH_TIME_IN_PARENT, szValue); cmor_set_cur_dataset_attribute_internal (BRANCH_TIME_IN_PARENT, "0.0", 1); - cmor_handle_error(msg, CMOR_WARNING); } } } else { // real parent case // Parent Activity ID if (cmor_has_cur_dataset_attribute(PARENT_ACTIVITY_ID) != 0) { - snprintf(msg, CMOR_MAX_STRING, + cmor_handle_error_variadic( "Your input attribute \"%s\" is not defined properly \n! " "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_NORMAL); + CMOR_NORMAL, PARENT_ACTIVITY_ID, CV_experiment->key, CV_Filename); ierr = -1; } else { cmor_get_cur_dataset_attribute(PARENT_ACTIVITY_ID, szValue); @@ -1174,103 +1132,94 @@ int cmor_CV_checkParentExpID(cmor_CV_def_t * CV) PARENT_ACTIVITY_ID); if (CV_IsStringInArray(CV_parent_activity_id, szValue) == 0) { if (CV_parent_activity_id->anElements == 1) { - snprintf(msg, CMOR_MAX_STRING, + cmor_handle_error_variadic( "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, + CMOR_WARNING, PARENT_ACTIVITY_ID, szValue, CV_parent_activity_id->aszValue[0]); - cmor_handle_error(msg, CMOR_WARNING); cmor_set_cur_dataset_attribute_internal (PARENT_ACTIVITY_ID, CV_parent_activity_id->aszValue[0], 1); } else { - snprintf(msg, CMOR_MAX_STRING, + cmor_handle_error_variadic( "Your input attribute \"%s\" is not defined properly \n! " "for your experiment \"%s\"\n! " "There is more than 1 option for this experiment.\n! " "See Control Vocabulary JSON file.(%s)\n! ", - PARENT_ACTIVITY_ID, CV_experiment->key, + CMOR_WARNING, PARENT_ACTIVITY_ID, CV_experiment->key, CV_Filename); - cmor_handle_error(msg, CMOR_WARNING); } } } // branch method if (cmor_has_cur_dataset_attribute(BRANCH_METHOD) != 0) { - snprintf(msg, CMOR_MAX_STRING, + cmor_handle_error_variadic( "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_NORMAL); + CMOR_NORMAL, BRANCH_METHOD, szExperiment_ID); ierr = -1; } else { cmor_get_cur_dataset_attribute(BRANCH_METHOD, szBranchMethod); if (strlen(szBranchMethod) == 0) { - snprintf(msg, CMOR_MAX_STRING, + cmor_handle_error_variadic( "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); + "in CMIP6 documentations.\n! ", CMOR_NORMAL, BRANCH_METHOD); ierr = -1; } } // branch_time_in_child if (cmor_has_cur_dataset_attribute(BRANCH_TIME_IN_CHILD) != 0) { - snprintf(msg, CMOR_MAX_STRING, + cmor_handle_error_variadic( "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_NORMAL); + CMOR_NORMAL, BRANCH_TIME_IN_CHILD, szExperiment_ID); ierr = -1; } else { cmor_get_cur_dataset_attribute(BRANCH_TIME_IN_CHILD, szBranchTimeInChild); rc = sscanf(szBranchTimeInChild, "%lf", &dBranchTimeInChild); if ((rc == 0) || (rc == EOF)) { - snprintf(msg, CMOR_MAX_STRING, + cmor_handle_error_variadic( "Your input attribute branch_time_in_child \"%s\" " "is not a double floating point \n! ", - szBranchTimeInChild); - cmor_handle_error(msg, CMOR_NORMAL); + CMOR_NORMAL, szBranchTimeInChild); ierr = -1; } } // branch_time_in_parent if (cmor_has_cur_dataset_attribute(BRANCH_TIME_IN_PARENT) != 0) { - snprintf(msg, CMOR_MAX_STRING, + cmor_handle_error_variadic( "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_NORMAL); + CMOR_NORMAL, BRANCH_TIME_IN_PARENT, szExperiment_ID); ierr = -1; } else { cmor_get_cur_dataset_attribute(BRANCH_TIME_IN_PARENT, szBranchTimeInParent); rc = sscanf(szBranchTimeInParent, "%lf", &dBranchTimeInParent); if ((rc == 0) || (rc == EOF)) { - snprintf(msg, CMOR_MAX_STRING, + cmor_handle_error_variadic( "Your input attribute branch_time_in_parent \"%s\" " "is not a double floating point \n! ", - szBranchTimeInParent); - cmor_handle_error(msg, CMOR_NORMAL); + CMOR_NORMAL, szBranchTimeInParent); ierr = -1; } } // parent_time_units if (cmor_has_cur_dataset_attribute(PARENT_TIME_UNITS) != 0) { - snprintf(msg, CMOR_MAX_STRING, + cmor_handle_error_variadic( "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_NORMAL); + CMOR_NORMAL, PARENT_TIME_UNITS, szExperiment_ID); ierr = -1; } else { char template[CMOR_MAX_STRING]; @@ -1282,22 +1231,20 @@ int cmor_CV_checkParentExpID(cmor_CV_def_t * CV) reti = regcomp(®ex, template, 0); if (reti) { - snprintf(msg, CMOR_MAX_STRING, + cmor_handle_error_variadic( "You regular expression \"%s\" is invalid. \n! " "Please refer to the CMIP6 documentations.\n! ", - template); + CMOR_NORMAL, template); regfree(®ex); - cmor_handle_error(msg, CMOR_NORMAL); ierr = -1; } else { // Execute regular expression reti = regexec(®ex, szParentTimeUnits, 0, NULL, 0); if (reti == REG_NOMATCH) { - snprintf(msg, CMOR_MAX_STRING, + cmor_handle_error_variadic( "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); + CMOR_NORMAL, PARENT_TIME_UNITS, szParentTimeUnits); ierr = -1; } } @@ -1305,12 +1252,11 @@ int cmor_CV_checkParentExpID(cmor_CV_def_t * CV) } // parent_variant_label if (cmor_has_cur_dataset_attribute(PARENT_VARIANT_LABEL) != 0) { - snprintf(msg, CMOR_MAX_STRING, + cmor_handle_error_variadic( "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_NORMAL); + CMOR_NORMAL, PARENT_VARIANT_LABEL, szExperiment_ID); ierr = -1; } else { char template[CMOR_MAX_STRING]; @@ -1322,21 +1268,19 @@ int cmor_CV_checkParentExpID(cmor_CV_def_t * CV) reti = regcomp(®ex, template, 0); if (reti) { - snprintf(msg, CMOR_MAX_STRING, + cmor_handle_error_variadic( "You regular expression \"%s\" is invalid. \n! " "Please refer to the CMIP6 documentations.\n! ", - template); - cmor_handle_error(msg, CMOR_NORMAL); + CMOR_NORMAL, template); ierr = -1; } else { // Execute regular expression reti = regexec(®ex, szParentVariantLabel, 0, NULL, 0); if (reti == REG_NOMATCH) { - snprintf(msg, CMOR_MAX_STRING, + cmor_handle_error_variadic( "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); + CMOR_NORMAL, PARENT_VARIANT_LABEL, szParentVariantLabel); ierr = -1; } } @@ -1344,23 +1288,21 @@ int cmor_CV_checkParentExpID(cmor_CV_def_t * CV) } // parent_source_id if (cmor_has_cur_dataset_attribute(PARENT_SOURCE_ID) != 0) { - snprintf(msg, CMOR_MAX_STRING, + cmor_handle_error_variadic( "Your input attribute \"%s\" is not defined \n! " "properly for %s \n! " "Please refer to the CMIP6 documentations.\n! ", - PARENT_SOURCE_ID, szExperiment_ID); - cmor_handle_error(msg, CMOR_NORMAL); + CMOR_NORMAL, PARENT_SOURCE_ID, szExperiment_ID); ierr = -1; } else { cmor_get_cur_dataset_attribute(PARENT_SOURCE_ID, szParentSourceId); CV_source_id = cmor_CV_rootsearch(CV, CV_KEY_SOURCE_IDS); if (CV_source_id == NULL) { - snprintf(msg, CMOR_MAX_STRING, + cmor_handle_error_variadic( "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_NORMAL, CV_Filename); ierr = -1; } else { // Get specified experiment @@ -1369,33 +1311,30 @@ int cmor_CV_checkParentExpID(cmor_CV_def_t * CV) CV_source = cmor_CV_search_child_key(CV_source_id, szParentSourceId); if (CV_source == NULL) { - snprintf(msg, CMOR_MAX_STRING, + cmor_handle_error_variadic( "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_NORMAL, szParentSourceId, CV_Filename); ierr = -1; } } } // parent_mip_era if (cmor_has_cur_dataset_attribute(PARENT_MIP_ERA) != 0) { - snprintf(msg, CMOR_MAX_STRING, + cmor_handle_error_variadic( "Your input attribute \"%s\" is not defined \n! " "properly for %s \n! " "Please refer to the CMIP6 documentations.\n! ", - PARENT_MIP_ERA, szExperiment_ID); - cmor_handle_error(msg, CMOR_NORMAL); + CMOR_NORMAL, PARENT_MIP_ERA, szExperiment_ID); ierr = -1; } else { cmor_get_cur_dataset_attribute(PARENT_MIP_ERA, szValue); if (strcmp(CMIP6, szValue) != 0) { - snprintf(msg, CMOR_MAX_STRING, + cmor_handle_error_variadic( "Your input attribute \"%s\" defined as \"%s\" " "will be replaced with \n! " "\"%s\" as defined in your Control Vocabulary file.\n! ", - PARENT_MIP_ERA, szValue, CMIP6); - cmor_handle_error(msg, CMOR_WARNING); + CMOR_WARNING, PARENT_MIP_ERA, szValue, CMIP6); cmor_set_cur_dataset_attribute_internal(PARENT_MIP_ERA, szValue, 1); } @@ -1416,7 +1355,6 @@ int cmor_CV_checkExperiment(cmor_CV_def_t * CV) cmor_CV_def_t *CV_experiment_attr; char szExperiment_ID[CMOR_MAX_STRING]; - char msg[CMOR_MAX_STRING]; char szValue[CMOR_MAX_STRING]; char szExpValue[CMOR_MAX_STRING]; char CV_Filename[CMOR_MAX_STRING]; @@ -1432,11 +1370,10 @@ int cmor_CV_checkExperiment(cmor_CV_def_t * CV) cmor_get_cur_dataset_attribute(CV_INPUTFILENAME, CV_Filename); ierr = cmor_get_cur_dataset_attribute(GLOBAL_ATT_EXPERIMENTID, szExperiment_ID); if (ierr != 0) { - snprintf(msg, CMOR_MAX_STRING, + cmor_handle_error_variadic( "Your \"%s\" is not defined, check your required attributes\n! " "See Control Vocabulary JSON file.(%s)\n! ", - GLOBAL_ATT_EXPERIMENTID, CV_Filename); - cmor_handle_error(msg, CMOR_NORMAL); + CMOR_NORMAL, GLOBAL_ATT_EXPERIMENTID, CV_Filename); cmor_pop_traceback(); return (-1); } @@ -1445,11 +1382,10 @@ int cmor_CV_checkExperiment(cmor_CV_def_t * CV) /* -------------------------------------------------------------------- */ CV_experiment_ids = cmor_CV_rootsearch(CV, CV_KEY_EXPERIMENT_ID); if (CV_experiment_ids == NULL) { - snprintf(msg, CMOR_MAX_STRING, + cmor_handle_error_variadic( "Your \"experiment_ids\" key could not be found in\n! " - "your Control Vocabulary file.(%s)\n! ", CV_Filename); + "your Control Vocabulary file.(%s)\n! ", CMOR_NORMAL, CV_Filename); - cmor_handle_error(msg, CMOR_NORMAL); cmor_pop_traceback(); return (-1); } @@ -1457,12 +1393,11 @@ int cmor_CV_checkExperiment(cmor_CV_def_t * CV) szExperiment_ID); if (CV_experiment == NULL) { - snprintf(msg, CMOR_MAX_STRING, + cmor_handle_error_variadic( "Your experiment_id \"%s\" defined in your input file\n! " "could not be found in your Control Vocabulary file.(%s)\n! ", - szExperiment_ID, CV_Filename); + CMOR_NORMAL, szExperiment_ID, CV_Filename); - cmor_handle_error(msg, CMOR_NORMAL); cmor_pop_traceback(); return (-1); } @@ -1504,15 +1439,15 @@ int cmor_CV_checkExperiment(cmor_CV_def_t * CV) strcpy(szExpValue, CV_experiment_attr->aszValue[0]); bError = 1; } else { - snprintf(msg, CMOR_MAX_STRING, + cmor_handle_error_variadic( "Your input attribute \"%s\" with value \n! \"%s\" " "is not set properly and \n! " "has multiple possible candidates \n! " "defined for experiment_id \"%s\".\n! \n! " "See Control Vocabulary JSON file.(%s)\n! ", + CMOR_CRITICAL, CV_experiment_attr->key, szValue, CV_experiment->key, CV_Filename); - cmor_handle_error(msg, CMOR_CRITICAL); cmor_pop_traceback(); return (-1); @@ -1532,15 +1467,15 @@ int cmor_CV_checkExperiment(cmor_CV_def_t * CV) } } if (bError == 1) { - snprintf(msg, CMOR_MAX_STRING, + cmor_handle_error_variadic( "Your input attribute \"%s\" with value \n! \"%s\" " "needs to be replaced with " "value \"%s\"\n! " "as defined for experiment_id \"%s\".\n! \n! " "See Control Vocabulary JSON file.(%s)\n! ", + CMOR_NORMAL, CV_experiment_attr->key, szValue, szExpValue, CV_experiment->key, CV_Filename); - cmor_handle_error(msg, CMOR_NORMAL); ierr = -1; } // Set/replace attribute. @@ -1565,7 +1500,6 @@ int cmor_CV_checkFilename(cmor_CV_def_t * CV, int var_id, char outname[CMOR_MAX_STRING]; char CV_Filename[CMOR_MAX_STRING]; char szTmp[CMOR_MAX_STRING]; - char msg[CMOR_MAX_STRING]; cdCompTime comptime; int i, j, n; int timeDim; @@ -1600,12 +1534,11 @@ int cmor_CV_checkFilename(cmor_CV_def_t * CV, int var_id, // retrieve calendar if (cmor_calendar_c2i(szInTimeCalendar, &icalo) != 0) { - snprintf(szInTimeUnits, CMOR_MAX_STRING, + cmor_handle_error_var_variadic( "Cannot convert times for calendar: %s,\n! " - "closing variable %s (table: %s)", szInTimeCalendar, - cmor_vars[var_id].id, + "closing variable %s (table: %s)", + CMOR_CRITICAL, var_id, szInTimeCalendar, cmor_vars[var_id].id, cmor_tables[cmor_vars[var_id].ref_table_id].szTable_id); - cmor_handle_error_var(szInTimeCalendar, CMOR_CRITICAL, var_id); cmor_pop_traceback(); return (-1); } @@ -1762,11 +1695,10 @@ int cmor_CV_checkFilename(cmor_CV_def_t * CV, int var_id, /* don't need to do anything, time string will ignored in next step */ break; default: - snprintf(msg, CMOR_MAX_STRING, + cmor_handle_error_var_variadic( "Cannot find frequency %s. Closing variable %s (table: %s)", - frequency, cmor_vars[var_id].id, + CMOR_CRITICAL, var_id, frequency, cmor_vars[var_id].id, cmor_tables[cmor_vars[var_id].ref_table_id].szTable_id); - cmor_handle_error_var(msg, CMOR_CRITICAL, var_id); cmor_pop_traceback(); return (-1); } @@ -1818,17 +1750,18 @@ int cmor_CV_checkFilename(cmor_CV_def_t * CV, int var_id, } strncat(outname, ".nc", CMOR_MAX_STRING - strlen(outname)); if (strcmp(infile, outname) != 0) { - snprintf(szTmp, CMOR_MAX_STRING, "Your filename \n! " + cmor_handle_error_var_variadic( + "Your filename \n! " "\"%s\" \n! " "does not match the CMIP6 requirement.\n! \n! " "Your output filename should be: \n! " "\"%s\"\n! \n! " "and should follow this template: \n!" "\"%s\"\n! \n! " - "See your Control Vocabulary file.(%s)\n! ", infile, outname, + "See your Control Vocabulary file.(%s)\n! ", + CMOR_NORMAL, var_id, infile, outname, cmor_current_dataset.file_template, CV_Filename); - cmor_handle_error_var(szTmp, CMOR_NORMAL, var_id); cmor_pop_traceback(); return (-1); } @@ -1848,7 +1781,6 @@ int cmor_CV_setInstitution(cmor_CV_def_t * CV) char szInstitution_ID[CMOR_MAX_STRING]; char szInstitution[CMOR_MAX_STRING]; - char msg[CMOR_MAX_STRING]; char CMOR_Filename[CMOR_MAX_STRING]; char CV_Filename[CMOR_MAX_STRING]; int rc; @@ -1872,12 +1804,11 @@ int cmor_CV_setInstitution(cmor_CV_def_t * CV) /* -------------------------------------------------------------------- */ CV_institution_ids = cmor_CV_rootsearch(CV, CV_KEY_INSTITUTION_ID); if (CV_institution_ids == NULL) { - snprintf(msg, CMOR_MAX_STRING, + cmor_handle_error_variadic( "Your \"%s\" key could not be found in\n! " "your Control Vocabulary file.(%s)\n! ", - CV_KEY_INSTITUTION_ID, CV_Filename); + CMOR_NORMAL, CV_KEY_INSTITUTION_ID, CV_Filename); - cmor_handle_error(msg, CMOR_NORMAL); cmor_pop_traceback(); return (-1); } @@ -1885,7 +1816,7 @@ int cmor_CV_setInstitution(cmor_CV_def_t * CV) szInstitution_ID); if (CV_institution == NULL) { - snprintf(msg, CMOR_MAX_STRING, + cmor_handle_error_variadic( "The institution_id, \"%s\", found in your \n! " "input file (%s) could not be found in \n! " "your Controlled Vocabulary file. (%s) \n! \n! " @@ -1896,8 +1827,7 @@ int cmor_CV_setInstitution(cmor_CV_def_t * CV) "Contact \"pcmdi-cmip@llnl.gov\" for additional guidance. \n! \n! " "See \"http://cmor.llnl.gov/mydoc_cmor3_CV/\" for further information about\n! " "the \"institution_id\" and \"institution\" global attributes. ", - szInstitution_ID, CMOR_Filename, CV_Filename, CV_Filename); - cmor_handle_error(msg, CMOR_NORMAL); + CMOR_NORMAL, szInstitution_ID, CMOR_Filename, CV_Filename, CV_Filename); cmor_pop_traceback(); return (-1); } @@ -1919,12 +1849,11 @@ int cmor_CV_setInstitution(cmor_CV_def_t * CV) /* Check if an institution has been defined! If not we exit. */ /* -------------------------------------------------------------------- */ if (CV_institution->szValue[0] == '\0') { - snprintf(msg, CMOR_MAX_STRING, + cmor_handle_error_variadic( "There is no institution associated to institution_id \"%s\"\n! " "in your Control Vocabulary file.\n! " - "Check your \"%s\" dictionary!!\n! ", - CV_KEY_INSTITUTION_ID, szInstitution_ID); - cmor_handle_error(msg, CMOR_NORMAL); + "Check your \"%s\" dictionary!!\n! ", + CMOR_NORMAL, CV_KEY_INSTITUTION_ID, szInstitution_ID); cmor_pop_traceback(); return (-1); } @@ -1933,11 +1862,10 @@ int cmor_CV_setInstitution(cmor_CV_def_t * CV) /* -------------------------------------------------------------------- */ if (strncmp(szInstitution, CV_institution->szValue, CMOR_MAX_STRING) != 0) { - snprintf(msg, CMOR_MAX_STRING, + cmor_handle_error_variadic( "Your input attribute institution \"%s\" will be replaced with \n! " "\"%s\" as defined in your Control Vocabulary file.\n! ", - szInstitution, CV_institution->szValue); - cmor_handle_error(msg, CMOR_WARNING); + CMOR_WARNING, szInstitution, CV_institution->szValue); } } /* -------------------------------------------------------------------- */ @@ -1974,7 +1902,6 @@ int cmor_CV_ValidateAttribute(cmor_CV_def_t * CV, char *szKey) cmor_CV_def_t *CV_key; cmor_CV_def_t *required_attrs; char szValue[CMOR_MAX_STRING]; - char msg[CMOR_MAX_STRING]; char CV_Filename[CMOR_MAX_STRING]; char szValids[CMOR_MAX_STRING]; char szOutput[CMOR_MAX_STRING]; @@ -2023,12 +1950,11 @@ int cmor_CV_ValidateAttribute(cmor_CV_def_t * CV, char *szKey) strncpy(attr_CV->aszValue[i], szTmp, CMOR_MAX_STRING); reti = regcomp(®ex, attr_CV->aszValue[i], 0); if (reti) { - snprintf(msg, CMOR_MAX_STRING, + cmor_handle_error_variadic( "You regular expression \"%s\" is invalid. \n! " "Check your Control Vocabulary file \"%s\".\n! ", - attr_CV->aszValue[i], CV_Filename); + CMOR_NORMAL, attr_CV->aszValue[i], CV_Filename); regfree(®ex); - cmor_handle_error(msg, CMOR_NORMAL); cmor_pop_traceback(); return (-1); @@ -2079,19 +2005,17 @@ int cmor_CV_ValidateAttribute(cmor_CV_def_t * CV, char *szKey) if(szTmp[0] != '\0' && strcmp(CV_key->szValue, szTmp) != 0){ reti = cmor_get_table_attr(CV_key->key, &cmor_tables[CMOR_TABLE], tableValue); if(reti == 0 && strcmp(tableValue, szTmp) == 0){ - snprintf(msg, CMOR_MAX_STRING, + cmor_handle_error_variadic( "The registered CV attribute \"%s\" as defined as \"%s\" " "will be replaced with \n! " "\"%s\" as defined in the table %s\n! ", - CV_key->key, CV_key->szValue, szTmp, cmor_tables[CMOR_TABLE].szTable_id); - cmor_handle_error(msg, CMOR_WARNING); + CMOR_WARNING, CV_key->key, CV_key->szValue, szTmp, cmor_tables[CMOR_TABLE].szTable_id); } else { - snprintf(msg, CMOR_MAX_STRING, + cmor_handle_error_variadic( "The registered CV attribute \"%s\" as defined as \"%s\" " "will be replaced with \n! " "\"%s\" as defined in your user input file\n! ", - CV_key->key, CV_key->szValue, szTmp); - cmor_handle_error(msg, CMOR_WARNING); + CMOR_WARNING, CV_key->key, CV_key->szValue, szTmp); } } else { cmor_set_cur_dataset_attribute_internal(CV_key->key, @@ -2107,19 +2031,17 @@ int cmor_CV_ValidateAttribute(cmor_CV_def_t * CV, char *szKey) if(szTmp[0] != '\0' && strcmp(CV_key->aszValue[0], szTmp) != 0){ reti = cmor_get_table_attr(CV_key->key, &cmor_tables[CMOR_TABLE], tableValue); if(reti == 0 && strcmp(tableValue, szTmp) == 0){ - snprintf(msg, CMOR_MAX_STRING, + cmor_handle_error_variadic( "The registered CV attribute \"%s\" as defined as \"%s\" " "will be replaced with \n! " "\"%s\" as defined in the table %s\n! ", - CV_key->key, CV_key->aszValue[0], szTmp, cmor_tables[CMOR_TABLE].szTable_id); - cmor_handle_error(msg, CMOR_WARNING); + CMOR_WARNING, CV_key->key, CV_key->aszValue[0], szTmp, cmor_tables[CMOR_TABLE].szTable_id); } else { - snprintf(msg, CMOR_MAX_STRING, + cmor_handle_error_variadic( "The registered CV attribute \"%s\" as defined as \"%s\" " "will be replaced with \n! " "\"%s\" as defined in your user input file\n! ", - CV_key->key, CV_key->aszValue[0], szTmp); - cmor_handle_error(msg, CMOR_WARNING); + CMOR_WARNING, CV_key->key, CV_key->aszValue[0], szTmp); } } else { cmor_set_cur_dataset_attribute_internal(CV_key->key, @@ -2131,12 +2053,11 @@ int cmor_CV_ValidateAttribute(cmor_CV_def_t * CV, char *szKey) } } else if (CV_key->anElements > 1 && isRequired == 1) { if(cmor_has_cur_dataset_attribute(CV_key->key) != 0) { - snprintf(msg, CMOR_MAX_STRING, + cmor_handle_error_variadic( "The registered CV attribute \"%s\" has multiple values \n! " "defined in \"%s\"\n! " "Please select one from the entry %s.%s.%s.", - CV_key->key, CV_Filename, szKey, szValue, CV_key->key); - cmor_handle_error(msg, CMOR_NORMAL); + CMOR_NORMAL, CV_key->key, CV_Filename, szKey, szValue, CV_key->key); cmor_pop_traceback(); return (-1); } @@ -2148,15 +2069,14 @@ int cmor_CV_ValidateAttribute(cmor_CV_def_t * CV, char *szKey) /* We could not validate this attribute, exit. */ /* -------------------------------------------------------------------- */ if (i == (attr_CV->anElements)) { - snprintf(msg, CMOR_MAX_STRING, + cmor_handle_error_variadic( "The attribute \"%s\" could not be validated. \n! " "The current input value is " "\"%s\", which is not valid. \n! \n! " "Valid values must match those found in the \"%s\" " "section\n! of your Controlled Vocabulary (CV) file \"%s\".\n! ", - szKey, szValue, szKey, CV_Filename); + CMOR_NORMAL, szKey, szValue, szKey, CV_Filename); - cmor_handle_error(msg, CMOR_NORMAL); cmor_pop_traceback(); return (-1); } @@ -2172,7 +2092,6 @@ int cmor_CV_checkGrids(cmor_CV_def_t * CV) int rc; char szGridLabel[CMOR_MAX_STRING]; char szGridResolution[CMOR_MAX_STRING]; - char msg[CMOR_MAX_STRING]; char CV_Filename[CMOR_MAX_STRING]; char szCompare[CMOR_MAX_STRING]; @@ -2196,11 +2115,10 @@ int cmor_CV_checkGrids(cmor_CV_def_t * CV) CV_grid_labels = cmor_CV_rootsearch(CV, CV_KEY_GRID_LABELS); if (CV_grid_labels == NULL) { - snprintf(msg, CMOR_MAX_STRING, + cmor_handle_error_variadic( "Your \"grid_labels\" key could not be found in\n! " - "your Control Vocabulary file.(%s)\n! ", CV_Filename); + "your Control Vocabulary file.(%s)\n! ", CMOR_NORMAL, CV_Filename); - cmor_handle_error(msg, CMOR_NORMAL); cmor_pop_traceback(); return (-1); } @@ -2219,11 +2137,10 @@ int cmor_CV_checkGrids(cmor_CV_def_t * CV) } } if (i == CV_grid_labels->anElements) { - snprintf(msg, CMOR_MAX_STRING, + cmor_handle_error_variadic( "Your attribute grid_label is set to \"%s\" which is invalid." "\n! \n! Check your Control Vocabulary file \"%s\".\n! ", - szGridLabel, CV_Filename); - cmor_handle_error(msg, CMOR_NORMAL); + CMOR_NORMAL, szGridLabel, CV_Filename); cmor_pop_traceback(); return (-1); @@ -2231,22 +2148,20 @@ int cmor_CV_checkGrids(cmor_CV_def_t * CV) } else { CV_grid_child = cmor_CV_search_child_key(CV_grid_labels, szGridLabel); if (CV_grid_child == NULL) { - snprintf(msg, CMOR_MAX_STRING, + cmor_handle_error_variadic( "Your attribute grid_label is set to \"%s\" which is invalid." "\n! \n! Check your Control Vocabulary file \"%s\".\n! ", - szGridLabel, CV_Filename); - cmor_handle_error(msg, CMOR_NORMAL); + CMOR_NORMAL, szGridLabel, CV_Filename); cmor_pop_traceback(); return (-1); } } CV_grid_resolution = cmor_CV_rootsearch(CV, CV_KEY_GRID_RESOLUTION); if (CV_grid_resolution == NULL) { - snprintf(msg, CMOR_MAX_STRING, + cmor_handle_error_variadic( "Your attribute grid_label is set to \"%s\" which is invalid." "\n! \n! Check your Control Vocabulary file \"%s\".\n! ", - szGridLabel, CV_Filename); - cmor_handle_error(msg, CMOR_NORMAL); + CMOR_NORMAL, szGridLabel, CV_Filename); cmor_pop_traceback(); return (-1); @@ -2269,11 +2184,10 @@ int cmor_CV_checkGrids(cmor_CV_def_t * CV) } } if (i == CV_grid_resolution->anElements) { - snprintf(msg, CMOR_MAX_STRING, + cmor_handle_error_variadic( "Your attribute grid_resolution is set to \"%s\" which is invalid." "\n! \n! Check your Control Vocabulary file \"%s\".\n! ", - szGridResolution, CV_Filename); - cmor_handle_error(msg, CMOR_NORMAL); + CMOR_NORMAL, szGridResolution, CV_Filename); cmor_pop_traceback(); return (-1); @@ -2292,7 +2206,6 @@ int cmor_CV_checkGblAttributes(cmor_CV_def_t * CV) cmor_CV_def_t *required_attrs; int i; int rc; - char msg[CMOR_MAX_STRING]; int bCriticalError = 0; int ierr = 0; cmor_add_traceback("_CV_checkGblAttributes"); @@ -2301,13 +2214,12 @@ int cmor_CV_checkGblAttributes(cmor_CV_def_t * CV) for (i = 0; i < required_attrs->anElements; i++) { rc = cmor_has_cur_dataset_attribute(required_attrs->aszValue[i]); if (rc != 0) { - snprintf(msg, CMOR_MAX_STRING, + cmor_handle_error_variadic( "Your Control Vocabulary file specifies one or more\n! " "required attributes. The following\n! " "attribute was not properly set.\n! \n! " "Please set attribute: \"%s\" in your input file.", - required_attrs->aszValue[i]); - cmor_handle_error(msg, CMOR_NORMAL); + CMOR_NORMAL, required_attrs->aszValue[i]); bCriticalError = 1; ierr += -1; } @@ -2319,7 +2231,7 @@ int cmor_CV_checkGblAttributes(cmor_CV_def_t * CV) } } if (bCriticalError) { - cmor_handle_error("Please fix required attributes mentioned in\n! " + cmor_handle_error_variadic("Please fix required attributes mentioned in\n! " "the warnings/error above and rerun. (aborting!)\n! ", CMOR_NORMAL); } @@ -2398,7 +2310,6 @@ int cmor_CV_checkISOTime(char *szAttribute) int rc; char *szReturn; char szDate[CMOR_MAX_STRING]; - char msg[CMOR_MAX_STRING]; rc = cmor_has_cur_dataset_attribute(szAttribute); if (rc == 0) { @@ -2413,12 +2324,11 @@ int cmor_CV_checkISOTime(char *szAttribute) memset(&tm, 0, sizeof(struct tm)); szReturn = strptime(szDate, "%FT%H:%M:%SZ", &tm); if (szReturn == NULL) { - snprintf(msg, CMOR_MAX_STRING, + cmor_handle_error_variadic( "Your global attribute " "\"%s\" set to \"%s\" is not a valid date.\n! " "ISO 8601 date format \"YYYY-MM-DDTHH:MM:SSZ\" is required." - "\n! ", szAttribute, szDate); - cmor_handle_error(msg, CMOR_NORMAL); + "\n! ", CMOR_NORMAL, szAttribute, szDate); cmor_pop_traceback(); return (-1); } @@ -2438,7 +2348,6 @@ int cmor_CV_variable(int *var_id, char *name, char *units, int vrid = -1; int i; int iref; - char msg[CMOR_MAX_STRING]; char ctmp[CMOR_MAX_STRING]; cmor_var_def_t refvar; @@ -2447,7 +2356,7 @@ int cmor_CV_variable(int *var_id, char *name, char *units, cmor_add_traceback("cmor_CV_variable"); if (CMOR_TABLE == -1) { - cmor_handle_error("You did not define a table yet!", CMOR_CRITICAL); + cmor_handle_error_variadic("You did not define a table yet!", CMOR_CRITICAL); cmor_pop_traceback(); return (-1); } @@ -2478,9 +2387,8 @@ int cmor_CV_variable(int *var_id, char *name, char *units, } if (iref == -1) { - snprintf(msg, CMOR_MAX_STRING, - "Could not find a matching variable for name: '%s'", ctmp); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "Could not find a matching variable for name: '%s'", CMOR_CRITICAL, ctmp); cmor_pop_traceback(); return (-1); } @@ -2561,11 +2469,11 @@ int cmor_CV_variable(int *var_id, char *name, char *units, VARIABLE_ATT_LONGNAME, 'c', refvar.long_name); - if ((refvar.flag_values != NULL) && (refvar.flag_values[0] != '\0')) { + if (refvar.flag_values[0] != '\0') { cmor_set_variable_attribute_internal(vrid, VARIABLE_ATT_FLAGVALUES, 'c', refvar.flag_values); } - if ((refvar.flag_meanings != NULL) && (refvar.flag_meanings[0] != '\0')) { + if (refvar.flag_meanings[0] != '\0') { cmor_set_variable_attribute_internal(vrid, VARIABLE_ATT_FLAGMEANINGS, 'c', refvar.flag_meanings); diff --git a/Src/cmor_axes.c b/Src/cmor_axes.c index b20aad8f..7eb6941f 100644 --- a/Src/cmor_axes.c +++ b/Src/cmor_axes.c @@ -54,7 +54,6 @@ double cmor_convert_interval_to_seconds(double interv, char *inunits) /* -------------------------------------------------------------------- */ int i, oui, n; char msg[CMOR_MAX_STRING]; - char ctmp[CMOR_MAX_STRING]; char sshort[6]; extern ut_system *ut_read; ut_unit *user_units = NULL, *cmor_units = NULL; @@ -84,10 +83,10 @@ double cmor_convert_interval_to_seconds(double interv, char *inunits) } } if (oui == -1) { - snprintf(msg, CMOR_MAX_STRING, - "Time units conversion, output units must\n! " - "contain the 'since' word, you defined: %s", inunits); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "Time units conversion, output units must\n! " + "contain the 'since' word, you defined: %s", + CMOR_CRITICAL, inunits); } strncpy(msg, inunits, oui - 1); @@ -101,43 +100,43 @@ double cmor_convert_interval_to_seconds(double interv, char *inunits) user_units = ut_parse(ut_read, msg, UT_ASCII); if (ut_get_status() != UT_SUCCESS) { - snprintf(msg, CMOR_MAX_STRING, - "In udunits parsing user units: %s", msg); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "In udunits parsing user units: %s", + CMOR_CRITICAL, msg); } if (ut_are_convertible(cmor_units, user_units) == 0) { - snprintf(ctmp, CMOR_MAX_STRING, - "axis interval units (%s) are incompatible with seconds", msg); + cmor_handle_error_variadic( + "axis interval units (%s) are incompatible with seconds", + CMOR_CRITICAL, msg); ut_free(user_units); ut_free(cmor_units); - cmor_handle_error(ctmp, CMOR_CRITICAL); cmor_pop_traceback(); return (1); } ut_cmor_converter = ut_get_converter(user_units, cmor_units); if (ut_get_status() != UT_SUCCESS) { - snprintf(msg, CMOR_MAX_STRING, "In udunits getting converter"); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic("In udunits getting converter", + CMOR_CRITICAL); } tmp = cv_convert_double(ut_cmor_converter, interv); if (ut_get_status() != UT_SUCCESS) { - snprintf(msg, CMOR_MAX_STRING, "In udunits converting"); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic("In udunits converting", + CMOR_CRITICAL); } cv_free(ut_cmor_converter); if (ut_get_status() != UT_SUCCESS) { - snprintf(msg, CMOR_MAX_STRING, "Udunits: Error freeing converter"); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic("Udunits: Error freeing converter", + CMOR_CRITICAL); } ut_free(user_units); if (ut_get_status() != UT_SUCCESS) { - snprintf(msg, CMOR_MAX_STRING, "Udunits: Error freeing units"); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic("Udunits: Error freeing units", + CMOR_CRITICAL); } ut_free(cmor_units); if (ut_get_status() != UT_SUCCESS) { - snprintf(msg, CMOR_MAX_STRING, "Udunits: Error freeing units"); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic("Udunits: Error freeing units", + CMOR_CRITICAL); } cmor_pop_traceback(); @@ -173,10 +172,9 @@ int cmor_convert_time_units(char *inunits, char *outunits, char *loutunits) } } if (oui == -1) { - snprintf(msg, CMOR_MAX_STRING, - "Time units conversion, output units must contain\n! " - "the 'since' word"); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "Time units conversion, output units must contain\n! " + "the 'since' word", CMOR_CRITICAL); } /* ok now check if output units have a "?" */ @@ -198,10 +196,9 @@ int cmor_convert_time_units(char *inunits, char *outunits, char *loutunits) } } if (iui == -1) { - snprintf(msg, CMOR_MAX_STRING, - "Time units conversion, input units must contain the\n! " - "'since' word"); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "Time units conversion, input units must contain the\n! " + "'since' word", CMOR_CRITICAL); } /* now construct the output units in case of a ? */ if (hasqm != -1) { /* there is a ? */ @@ -227,7 +224,6 @@ int cmor_convert_time_values(void *values_in, char type, int nvalues, /* this converts times values from some units to some others */ /* -------------------------------------------------------------------- */ int i; - char msg[CMOR_MAX_STRING]; char loutunits[CMOR_MAX_STRING]; double dtmp; cdCalenType icali, icalo; @@ -237,16 +233,14 @@ int cmor_convert_time_values(void *values_in, char type, int nvalues, cmor_is_setup(); if (cmor_calendar_c2i(calin, &icali) != 0) { - snprintf(msg, CMOR_MAX_STRING, - "Cannot convert times for calendar: %s", calin); - cmor_handle_error(msg, CMOR_NORMAL); + cmor_handle_error_variadic( + "Cannot convert times for calendar: %s", CMOR_NORMAL, calin); cmor_pop_traceback(); return (1); } if (cmor_calendar_c2i(calout, &icalo) != 0) { - snprintf(msg, CMOR_MAX_STRING, - "Cannot convert times for calendar: %s", calout); - cmor_handle_error(msg, CMOR_NORMAL); + cmor_handle_error_variadic( + "Cannot convert times for calendar: %s", CMOR_NORMAL, calout); cmor_pop_traceback(); return (1); } @@ -262,9 +256,8 @@ int cmor_convert_time_values(void *values_in, char type, int nvalues, else if (type == 'i') dtmp = (double)((int *)values_in)[i]; else { - snprintf(msg, CMOR_MAX_STRING, - "cannot convert time value from '%c' type", type); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "cannot convert time value from '%c' type", CMOR_CRITICAL, type); } /* -------------------------------------------------------------------- */ /* ok makes a comptime out of input */ @@ -328,14 +321,14 @@ int cmor_set_axis_attribute(int id, char *attribute_name, char type, else if (type == 'l') cmor_axes[id].attributes_values_num[index] = (double)*(long *)value; else { - snprintf(msg, CMOR_MAX_STRING, - "unknown type %c allowed types are c,i,l,f,d, for " - "attribute %s of axis %s (table: %s)", - type, - attribute_name, - cmor_axes[id].id, - cmor_tables[cmor_axes[id].ref_table_id].szTable_id); - cmor_handle_error(msg, CMOR_NORMAL); + cmor_handle_error_variadic( + "unknown type %c allowed types are c,i,l,f,d, for " + "attribute %s of axis %s (table: %s)", + CMOR_NORMAL, + type, + attribute_name, + cmor_axes[id].id, + cmor_tables[cmor_axes[id].ref_table_id].szTable_id); cmor_pop_traceback(); return (1); } @@ -350,7 +343,6 @@ int cmor_get_axis_attribute(int id, char *attribute_name, char type, void *value) { extern cmor_axis_t cmor_axes[]; - char msg[CMOR_MAX_STRING]; int i, index; cmor_add_traceback("cmor_get_axis_attribute"); @@ -363,11 +355,11 @@ int cmor_get_axis_attribute(int id, char *attribute_name, char type, } /* we found it */ } if (index == -1) { - snprintf(msg, CMOR_MAX_STRING, - "Attribute %s could not be found for axis %i (%s, table: %s)", - attribute_name, id, cmor_axes[id].id, - cmor_tables[cmor_axes[id].ref_table_id].szTable_id); - cmor_handle_error(msg, CMOR_NORMAL); + cmor_handle_error_variadic( + "Attribute %s could not be found for axis %i (%s, table: %s)", + CMOR_NORMAL, + attribute_name, id, cmor_axes[id].id, + cmor_tables[cmor_axes[id].ref_table_id].szTable_id); cmor_pop_traceback(); return (1); } @@ -418,7 +410,6 @@ int cmor_check_values_inside_bounds(double *values, double *bounds, int length, char *name) { int i; - char msg[CMOR_MAX_STRING]; cmor_add_traceback("cmor_check_values_inside_bounds"); for (i = 0; i < length; i++) { @@ -426,11 +417,12 @@ int cmor_check_values_inside_bounds(double *values, double *bounds, int length, if (((bounds[2 * i] < values[i]) && (bounds[2 * i + 1] < values[i])) || ((bounds[2 * i] > values[i]) && (bounds[2 * i + 1] > values[i]))) { - snprintf(msg, CMOR_MAX_STRING, - "axis %s has values not within bounds at indice:\n! " - "%i: %lf not within: %lf, %lf", name, i, values[i], - bounds[2 * i], bounds[2 * i + 1]); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "axis %s has values not within bounds at indice:\n! " + "%i: %lf not within: %lf, %lf", + CMOR_CRITICAL, + name, i, values[i], + bounds[2 * i], bounds[2 * i + 1]); } } cmor_pop_traceback(); @@ -456,11 +448,11 @@ int cmor_check_monotonic(double *values, int length, char *name, int isbounds, int axis_id) { int i, treatlon = 0, j = 0; - char msg[CMOR_MAX_STRING]; cmor_axis_def_t *refaxis; int mono; int nloop; double *values2, tmp; + int error_level; cmor_add_traceback("cmor_check_monotonic"); @@ -478,18 +470,20 @@ int cmor_check_monotonic(double *values, int length, char *name, int isbounds, if (cmor_isLongitude(refaxis) == 1) { treatlon = 1; } else { - snprintf(msg, CMOR_MAX_STRING, - "axis %s (table: %s) has non monotonic\n! " - "bounds values : %lf, %lf, %lf", name, - cmor_tables[cmor_axes[axis_id]. - ref_table_id].szTable_id, - values[2 * i], values[2 * i + 2], - values[2 * i + 4]); if (refaxis->climatology == 0) { - cmor_handle_error(msg, CMOR_CRITICAL); + error_level = CMOR_CRITICAL; } else { - cmor_handle_error(msg, CMOR_WARNING); + error_level = CMOR_WARNING; } + cmor_handle_error_variadic( + "axis %s (table: %s) has non monotonic\n! " + "bounds values : %lf, %lf, %lf", + error_level, + name, + cmor_tables[cmor_axes[axis_id]. + ref_table_id].szTable_id, + values[2 * i], values[2 * i + 2], + values[2 * i + 4]); } } } @@ -529,13 +523,13 @@ int cmor_check_monotonic(double *values, int length, char *name, int isbounds, mono = -1; nloop += 1; if (nloop == length) { - sprintf(msg, - "longitude axis bounds are not monotonic,\n! " - "axis %s (table: %s)", - cmor_axes[axis_id].id, - cmor_tables[cmor_axes[axis_id]. - ref_table_id].szTable_id); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "longitude axis bounds are not monotonic,\n! " + "axis %s (table: %s)", + CMOR_CRITICAL, + cmor_axes[axis_id].id, + cmor_tables[cmor_axes[axis_id]. + ref_table_id].szTable_id); } } } @@ -578,14 +572,14 @@ int cmor_check_monotonic(double *values, int length, char *name, int isbounds, /* need to flip that axis */ /* -------------------------------------------------------------------- */ if (cmor_axes[axis_id].revert == 1) { - snprintf(msg, - CMOR_MAX_STRING, - "bounds of axis %s (table: %s) need to be\n! " - "flipped but axis values did not need to.\n! " - "This is inconsistent", name, - cmor_tables[cmor_axes[axis_id]. - ref_table_id].szTable_id); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "bounds of axis %s (table: %s) need to be\n! " + "flipped but axis values did not need to.\n! " + "This is inconsistent", + CMOR_CRITICAL, + name, + cmor_tables[cmor_axes[axis_id]. + ref_table_id].szTable_id); } for (i = 0; i < length / 2; i++) { @@ -599,11 +593,12 @@ int cmor_check_monotonic(double *values, int length, char *name, int isbounds, /* ok make sure we have data spanning only 1 modulo */ /* -------------------------------------------------------------------- */ if (fabs(values[length - 1] - values[0]) > 360.) { - snprintf(msg, CMOR_MAX_STRING, - "axis %s has bounds values spanning\n! " - "more 360 degrees %lf, %lf", name, values[0], - values[length - 1]); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "axis %s has bounds values spanning\n! " + "more 360 degrees %lf, %lf", + CMOR_CRITICAL, + name, values[0], + values[length - 1]); } /* -------------------------------------------------------------------- */ /* ok now check the monotonic again */ @@ -611,13 +606,14 @@ int cmor_check_monotonic(double *values, int length, char *name, int isbounds, for (i = 0; i < length / 2 - 2; i++) { if (((values[2 * i] - values[2 * i + 2]) * (values[2 * i + 2] - values[2 * i + 4])) <= 0.) { - snprintf(msg, CMOR_MAX_STRING, - "axis %s (table: %s), has really non monotonic\n! " - "bounds values : %lf, %lf, %lf", name, - cmor_tables[cmor_axes[axis_id]. - ref_table_id].szTable_id, values[i], - values[i + 2], values[i + 4]); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "axis %s (table: %s), has really non monotonic\n! " + "bounds values : %lf, %lf, %lf", + CMOR_CRITICAL, + name, + cmor_tables[cmor_axes[axis_id]. + ref_table_id].szTable_id, values[i], + values[i + 2], values[i + 4]); } } /* First of all need to check if bounds needs to be flipped */ @@ -625,28 +621,30 @@ int cmor_check_monotonic(double *values, int length, char *name, int isbounds, for (i = 0; i < length - 2; i += 2) { if ((values[i] < values[i + 1]) && (values[i] > values[i + 2])) { - sprintf(msg, - "Axis: '%s' (table: %s), your bounds direction seems\n! " - "to be decreasing, but within cell %i they are stored\n! " - "increasingly: you have [%lf, %lf], but the next set\n! " - "is: [%lf, %lf]", name, - cmor_tables[cmor_axes[axis_id]. - ref_table_id].szTable_id, i, values[i], - values[i + 1], values[i + 2], values[i + 3]); - cmor_handle_error(msg, CMOR_WARNING); + cmor_handle_error_variadic( + "Axis: '%s' (table: %s), your bounds direction seems\n! " + "to be decreasing, but within cell %i they are stored\n! " + "increasingly: you have [%lf, %lf], but the next set\n! " + "is: [%lf, %lf]", + CMOR_WARNING, + name, + cmor_tables[cmor_axes[axis_id]. + ref_table_id].szTable_id, i, values[i], + values[i + 1], values[i + 2], values[i + 3]); j++; } if ((values[i] > values[i + 1]) && (values[i] < values[i + 2])) { - sprintf(msg, - "Axis: '%s' (table: %s), your bounds direction seems\n! " - "to be increasing, but within cell %i they are stored\n! " - "decreasingly: you have [%lf, %lf], but the next set\n! " - "is: [%lf, %lf]", name, - cmor_tables[cmor_axes[axis_id]. - ref_table_id].szTable_id, i, values[i], - values[i + 1], values[i + 2], values[i + 3]); - cmor_handle_error(msg, CMOR_WARNING); + cmor_handle_error_variadic( + "Axis: '%s' (table: %s), your bounds direction seems\n! " + "to be increasing, but within cell %i they are stored\n! " + "decreasingly: you have [%lf, %lf], but the next set\n! " + "is: [%lf, %lf]", + CMOR_WARNING, + name, + cmor_tables[cmor_axes[axis_id]. + ref_table_id].szTable_id, i, values[i], + values[i + 1], values[i + 2], values[i + 3]); j++; } } @@ -657,13 +655,14 @@ int cmor_check_monotonic(double *values, int length, char *name, int isbounds, values[i + 1] = tmp; } } else if (j != 1) { - sprintf(msg, - "Some but not all of your longitude bounds need to be\n! " - "flipped, see warnings ot see which ones, axis: %s \n! " - "(table: %s)", cmor_axes[axis_id].id, - cmor_tables[cmor_axes[axis_id]. - ref_table_id].szTable_id); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "Some but not all of your longitude bounds need to be\n! " + "flipped, see warnings ot see which ones, axis: %s \n! " + "(table: %s)", + CMOR_CRITICAL, + cmor_axes[axis_id].id, + cmor_tables[cmor_axes[axis_id]. + ref_table_id].szTable_id); } } @@ -686,25 +685,27 @@ int cmor_check_monotonic(double *values, int length, char *name, int isbounds, && (values[i + 2] < values[i + 1])) || ((values[i] > values[i + 1]) && (values[i + 2] > values[i + 1]))) { - snprintf(msg, CMOR_MAX_STRING, - "axis %s (table: %s) has overlapping bounds values:\n! " - "%lf, %lf, %lf at index: %i", name, - cmor_tables[cmor_axes[axis_id]. - ref_table_id].szTable_id, values[i], - values[i + 1], values[i + 2], i); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "axis %s (table: %s) has overlapping bounds values:\n! " + "%lf, %lf, %lf at index: %i", + CMOR_CRITICAL, + name, + cmor_tables[cmor_axes[axis_id]. + ref_table_id].szTable_id, values[i], + values[i + 1], values[i + 2], i); } } for (i = 0; i < length - 2; i = i + 2) { //printf("i=%d: [i+1]%f [i+2]%f\n",i,values[i+1],values[i+2]); if (values[i + 1] != values[i + 2]) { - snprintf(msg, CMOR_MAX_STRING, - "axis %s (table: %s) has bounds values that leave gaps\n! " - "(index %i): %lf, %lf, %lf", name, - cmor_tables[cmor_axes[axis_id]. - ref_table_id].szTable_id, i, values[i], - values[i + 1], values[i + 2]); - cmor_handle_error(msg, CMOR_WARNING); + cmor_handle_error_variadic( + "axis %s (table: %s) has bounds values that leave gaps\n! " + "(index %i): %lf, %lf, %lf", + CMOR_WARNING, + name, + cmor_tables[cmor_axes[axis_id]. + ref_table_id].szTable_id, i, values[i], + values[i + 1], values[i + 2]); } } } @@ -716,13 +717,14 @@ int cmor_check_monotonic(double *values, int length, char *name, int isbounds, treatlon = 1; break; } else { - snprintf(msg, CMOR_MAX_STRING, - "axis %s (table: %s) has non monotonic values:\n! " - "%lf, %lf and %lf", name, - cmor_tables[cmor_axes[axis_id]. - ref_table_id].szTable_id, values[i], - values[i + 1], values[i + 2]); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "axis %s (table: %s) has non monotonic values:\n! " + "%lf, %lf and %lf", + CMOR_CRITICAL, + name, + cmor_tables[cmor_axes[axis_id]. + ref_table_id].szTable_id, values[i], + values[i + 1], values[i + 2]); } } } @@ -766,12 +768,13 @@ int cmor_check_monotonic(double *values, int length, char *name, int isbounds, mono = -1; nloop += 1; if (nloop == length) { - sprintf(msg, - "longitude axis is not monotonic (axis: %s, " - "table: %s)", cmor_axes[axis_id].id, - cmor_tables[cmor_axes[axis_id]. - ref_table_id].szTable_id); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "longitude axis is not monotonic (axis: %s, " + "table: %s)", + CMOR_CRITICAL, + cmor_axes[axis_id].id, + cmor_tables[cmor_axes[axis_id]. + ref_table_id].szTable_id); } } } @@ -814,13 +817,14 @@ int cmor_check_monotonic(double *values, int length, char *name, int isbounds, /* need to flip that axis */ /* -------------------------------------------------------------------- */ if ((isbounds == 1) && (cmor_axes[axis_id].revert == 1)) { - snprintf(msg, CMOR_MAX_STRING, - "bounds of axis %s (table: %s), need to be\n! " - "flipped but axis values did not need to.\n! " - "This is inconsistent", name, - cmor_tables[cmor_axes[axis_id]. - ref_table_id].szTable_id); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "bounds of axis %s (table: %s), need to be\n! " + "flipped but axis values did not need to.\n! " + "This is inconsistent", + CMOR_CRITICAL, + name, + cmor_tables[cmor_axes[axis_id]. + ref_table_id].szTable_id); } cmor_axes[axis_id].revert = -1; for (i = 0; i < length / 2; i++) { @@ -834,13 +838,14 @@ int cmor_check_monotonic(double *values, int length, char *name, int isbounds, /* ok make sure we have data spanning only 1 modulo */ /* -------------------------------------------------------------------- */ if (fabs(values[length - 1] - values[0]) > 360.) { - snprintf(msg, CMOR_MAX_STRING, - "axis %s (table: %s) has values spanning more\n! " - "360 degrees %lf, %lf", name, - cmor_tables[cmor_axes[axis_id]. - ref_table_id].szTable_id, values[0], - values[length - 1]); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "axis %s (table: %s) has values spanning more\n! " + "360 degrees %lf, %lf", + CMOR_CRITICAL, + name, + cmor_tables[cmor_axes[axis_id]. + ref_table_id].szTable_id, values[0], + values[length - 1]); } /* -------------------------------------------------------------------- */ @@ -849,13 +854,13 @@ int cmor_check_monotonic(double *values, int length, char *name, int isbounds, for (i = 0; i < length - 2; i++) { if (((values[i] - values[i + 1]) * (values[i + 1] - values[i + 2])) <= 0.) { - snprintf(msg, CMOR_MAX_STRING, - "axis %s (table: %s) has non monotonic values : %lf, %lf and %lf", - name, - cmor_tables[cmor_axes[axis_id]. - ref_table_id].szTable_id, values[i], - values[i + 1], values[i + 2]); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "axis %s (table: %s) has non monotonic values : %lf, %lf and %lf", + CMOR_CRITICAL, + name, + cmor_tables[cmor_axes[axis_id]. + ref_table_id].szTable_id, values[i], + values[i + 1], values[i + 2]); } } } @@ -898,10 +903,9 @@ int cmor_treat_axis_values(int axis_id, double *values, int length, /* -------------------------------------------------------------------- */ cmor_get_cur_dataset_attribute("calendar", &msg[0]); if (cmor_calendar_c2i(msg, &acal) != 0) { - snprintf(msg, CMOR_MAX_STRING, - "non-standard calendar... hum we will try to accommodate\n! " - "this later"); - cmor_handle_error(msg, CMOR_NORMAL); + cmor_handle_error_variadic( + "non-standard calendar... hum we will try to accommodate\n! " + "this later", CMOR_NORMAL); cmor_pop_traceback(); return (1); } @@ -918,12 +922,12 @@ int cmor_treat_axis_values(int axis_id, double *values, int length, user_units = ut_parse(ut_read, local_unit, UT_ASCII); if (ut_get_status() != UT_SUCCESS) { - snprintf(msg, CMOR_MAX_STRING, - "In udunits analyzing units from user (%s),\n! " - "axis %s (table: %s)", - local_unit, cmor_axes[axis_id].id, - cmor_tables[cmor_axes[axis_id].ref_table_id].szTable_id); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "In udunits analyzing units from user (%s),\n! " + "axis %s (table: %s)", + CMOR_CRITICAL, + local_unit, cmor_axes[axis_id].id, + cmor_tables[cmor_axes[axis_id].ref_table_id].szTable_id); cmor_pop_traceback(); return (1); } @@ -937,24 +941,24 @@ int cmor_treat_axis_values(int axis_id, double *values, int length, cmor_units = ut_parse(ut_read, local_unit, UT_ASCII); if (ut_get_status() != UT_SUCCESS) { - snprintf(msg, CMOR_MAX_STRING, - "In udunits analyzing table defined units (%s)\n! " - "for axis: %s (table: %s)", - local_unit, refaxis->id, - cmor_tables[cmor_axes[axis_id].ref_table_id].szTable_id); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "In udunits analyzing table defined units (%s)\n! " + "for axis: %s (table: %s)", + CMOR_CRITICAL, + local_unit, refaxis->id, + cmor_tables[cmor_axes[axis_id].ref_table_id].szTable_id); cmor_pop_traceback(); return (1); } if (ut_are_convertible(cmor_units, user_units) == 0) { - snprintf(msg, CMOR_MAX_STRING, - "axis %i (%s, table: %s): cmor and user units are\n! " - "incompatible: %s and %s", - axis_id, cmor_axes[axis_id].id, - cmor_tables[cmor_axes[axis_id].ref_table_id].szTable_id, - refaxis->units, units); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "axis %i (%s, table: %s): cmor and user units are\n! " + "incompatible: %s and %s", + CMOR_CRITICAL, + axis_id, cmor_axes[axis_id].id, + cmor_tables[cmor_axes[axis_id].ref_table_id].szTable_id, + refaxis->units, units); cmor_pop_traceback(); return (1); } @@ -962,11 +966,11 @@ int cmor_treat_axis_values(int axis_id, double *values, int length, ut_cmor_converter = ut_get_converter(user_units, cmor_units); if (ut_get_status() != UT_SUCCESS) { - snprintf(msg, CMOR_MAX_STRING, - "In udunits getting converter, for axis %s (table: %s)", - cmor_axes[axis_id].id, - cmor_tables[cmor_axes[axis_id].ref_table_id].szTable_id); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "In udunits getting converter, for axis %s (table: %s)", + CMOR_CRITICAL, + cmor_axes[axis_id].id, + cmor_tables[cmor_axes[axis_id].ref_table_id].szTable_id); cmor_pop_traceback(); return (1); } @@ -974,11 +978,11 @@ int cmor_treat_axis_values(int axis_id, double *values, int length, cv_convert_doubles(ut_cmor_converter, values, length, values); if (ut_get_status() != UT_SUCCESS) { - snprintf(msg, CMOR_MAX_STRING, - "In udunits converting values, for axis %s (table: %s)", - cmor_axes[axis_id].id, - cmor_tables[cmor_axes[axis_id].ref_table_id].szTable_id); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "In udunits converting values, for axis %s (table: %s)", + CMOR_CRITICAL, + cmor_axes[axis_id].id, + cmor_tables[cmor_axes[axis_id].ref_table_id].szTable_id); cmor_pop_traceback(); return (1); } @@ -986,31 +990,31 @@ int cmor_treat_axis_values(int axis_id, double *values, int length, cv_free(ut_cmor_converter); if (ut_get_status() != UT_SUCCESS) { - snprintf(msg, CMOR_MAX_STRING, - "Udunits: Error freeing converter, for axis %s (table: %s)", - cmor_axes[axis_id].id, - cmor_tables[cmor_axes[axis_id].ref_table_id].szTable_id); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "Udunits: Error freeing converter, for axis %s (table: %s)", + CMOR_CRITICAL, + cmor_axes[axis_id].id, + cmor_tables[cmor_axes[axis_id].ref_table_id].szTable_id); } ut_free(cmor_units); if (ut_get_status() != UT_SUCCESS) { - snprintf(msg, CMOR_MAX_STRING, - "Udunits: Error freeing units, for axis %s (table: %s)", - cmor_axes[axis_id].id, - cmor_tables[cmor_axes[axis_id].ref_table_id].szTable_id); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "Udunits: Error freeing units, for axis %s (table: %s)", + CMOR_CRITICAL, + cmor_axes[axis_id].id, + cmor_tables[cmor_axes[axis_id].ref_table_id].szTable_id); } ut_free(user_units); if (ut_get_status() != UT_SUCCESS) { - snprintf(msg, CMOR_MAX_STRING, - "Udunits: Error freeing units, for axis %s (table: %s)", - cmor_axes[axis_id].id, - cmor_tables[cmor_axes[axis_id].ref_table_id].szTable_id); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "Udunits: Error freeing units, for axis %s (table: %s)", + CMOR_CRITICAL, + cmor_axes[axis_id].id, + cmor_tables[cmor_axes[axis_id].ref_table_id].szTable_id); } } @@ -1046,12 +1050,12 @@ int cmor_treat_axis_values(int axis_id, double *values, int length, } if (found == 0) { - snprintf(msg, CMOR_MAX_STRING, - "requested value %f for axis %s (table: %s) was not found", - refaxis->requested[j], name, - cmor_tables[cmor_axes[axis_id].ref_table_id]. - szTable_id); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "requested value %f for axis %s (table: %s) was not found", + CMOR_CRITICAL, + refaxis->requested[j], name, + cmor_tables[cmor_axes[axis_id].ref_table_id]. + szTable_id); } } } @@ -1064,14 +1068,14 @@ int cmor_treat_axis_values(int axis_id, double *values, int length, if ((isbounds == 1) && (axis->revert == 1)) { if (length > 2) { - snprintf(msg, CMOR_MAX_STRING, - "bounds of axis %s (table: %s) need to be\n! " - "flipped but axis values did not need to.\n! " - "This is inconsistent", - name, - cmor_tables[cmor_axes[axis_id].ref_table_id]. - szTable_id); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "bounds of axis %s (table: %s) need to be\n! " + "flipped but axis values did not need to.\n! " + "This is inconsistent", + CMOR_CRITICAL, + name, + cmor_tables[cmor_axes[axis_id].ref_table_id]. + szTable_id); } } @@ -1178,13 +1182,13 @@ int cmor_treat_axis_values(int axis_id, double *values, int length, } } if (found == 0) { - snprintf(msg, CMOR_MAX_STRING, - "requested value %f for axis %s (table: %s)\n! " - "was not found", - refaxis->requested_bounds[j], name, - cmor_tables[cmor_axes[axis_id].ref_table_id]. - szTable_id); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "requested value %f for axis %s (table: %s)\n! " + "was not found", + CMOR_CRITICAL, + refaxis->requested_bounds[j], name, + cmor_tables[cmor_axes[axis_id].ref_table_id]. + szTable_id); } } } @@ -1197,14 +1201,14 @@ int cmor_treat_axis_values(int axis_id, double *values, int length, if (cmor_isLongitude(refaxis) == 1) { treatlon = 1; } else { - snprintf(msg, CMOR_MAX_STRING, - "axis %s (table: %s), detected value at: %f when\n! " - "valid_min is %f", - name, - cmor_tables[cmor_axes[axis_id]. - ref_table_id].szTable_id, values[i], - refaxis->valid_min); - cmor_handle_error(msg, CMOR_NORMAL); + cmor_handle_error_variadic( + "axis %s (table: %s), detected value at: %f when\n! " + "valid_min is %f", + CMOR_NORMAL, + name, + cmor_tables[cmor_axes[axis_id]. + ref_table_id].szTable_id, values[i], + refaxis->valid_min); cmor_pop_traceback(); return (1); } @@ -1241,14 +1245,14 @@ int cmor_treat_axis_values(int axis_id, double *values, int length, if (cmor_isLongitude(refaxis) == 1) { treatlon = 1; } else { - snprintf(msg, CMOR_MAX_STRING, - "axis %s (table: %s) , detected value at:\n! " - "%f when valid_max is %f", - name, - cmor_tables[cmor_axes[axis_id]. - ref_table_id].szTable_id, values[i], - refaxis->valid_max); - cmor_handle_error(msg, CMOR_NORMAL); + cmor_handle_error_variadic( + "axis %s (table: %s) , detected value at:\n! " + "%f when valid_max is %f", + CMOR_NORMAL, + name, + cmor_tables[cmor_axes[axis_id]. + ref_table_id].szTable_id, values[i], + refaxis->valid_max); cmor_pop_traceback(); return (1); } @@ -1347,12 +1351,12 @@ int cmor_check_interval(int axis_id, char *interval, double *values, nval = nvalues / 2 + 1; tmp_values = malloc(sizeof(double) * nval); if (tmp_values == NULL) { - snprintf(ctmp, CMOR_MAX_STRING, - "Error allocating memory for %i values in " - "check_interval (%s), axis: %s (table: %s)", - nval, interval, cmor_axes[axis_id].id, - cmor_tables[cmor_axes[axis_id].ref_table_id].szTable_id); - cmor_handle_error(ctmp, CMOR_CRITICAL); + cmor_handle_error_variadic( + "Error allocating memory for %i values in " + "check_interval (%s), axis: %s (table: %s)", + CMOR_CRITICAL, + nval, interval, cmor_axes[axis_id].id, + cmor_tables[cmor_axes[axis_id].ref_table_id].szTable_id); } for (i = 0; i < nval - 1; i++) tmp_values[i] = values[i * 2]; @@ -1384,58 +1388,58 @@ int cmor_check_interval(int axis_id, char *interval, double *values, cmor_units = ut_parse(ut_read, msg, UT_ASCII); user_units = ut_parse(ut_read, ctmp2, UT_ASCII); if (ut_get_status() != UT_SUCCESS) { - snprintf(msg, CMOR_MAX_STRING, - "In udunuits parsing user units: %s, axis: %s (table: %s)", - ctmp2, cmor_axes[axis_id].id, - cmor_tables[cmor_axes[axis_id].ref_table_id].szTable_id); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "In udunuits parsing user units: %s, axis: %s (table: %s)", + CMOR_CRITICAL, + ctmp2, cmor_axes[axis_id].id, + cmor_tables[cmor_axes[axis_id].ref_table_id].szTable_id); } if (ut_are_convertible(cmor_units, user_units) == 0) { - snprintf(ctmp, CMOR_MAX_STRING, - "axis interval units (%s) are incompatible with\n! " - "seconds, axis: %s (table: %s)", - ctmp2, cmor_axes[axis_id].id, - cmor_tables[cmor_axes[axis_id].ref_table_id].szTable_id); - cmor_handle_error(ctmp, CMOR_CRITICAL); + cmor_handle_error_variadic( + "axis interval units (%s) are incompatible with\n! " + "seconds, axis: %s (table: %s)", + CMOR_CRITICAL, + ctmp2, cmor_axes[axis_id].id, + cmor_tables[cmor_axes[axis_id].ref_table_id].szTable_id); cmor_pop_traceback(); return (1); } ut_cmor_converter = ut_get_converter(user_units, cmor_units); if (ut_get_status() != UT_SUCCESS) { - snprintf(msg, CMOR_MAX_STRING, - "In udunuits getting converter, axis: %s (table: %s)", - cmor_axes[axis_id].id, - cmor_tables[cmor_axes[axis_id].ref_table_id].szTable_id); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "In udunuits getting converter, axis: %s (table: %s)", + CMOR_CRITICAL, + cmor_axes[axis_id].id, + cmor_tables[cmor_axes[axis_id].ref_table_id].szTable_id); } tmp = cv_convert_double(ut_cmor_converter, interv); if (ut_get_status() != UT_SUCCESS) { - snprintf(msg, CMOR_MAX_STRING, - "In udunuits converting, axis: %s (table: %s)", - cmor_axes[axis_id].id, - cmor_tables[cmor_axes[axis_id].ref_table_id].szTable_id); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "In udunuits converting, axis: %s (table: %s)", + CMOR_CRITICAL, + cmor_axes[axis_id].id, + cmor_tables[cmor_axes[axis_id].ref_table_id].szTable_id); } interv = tmp; cv_free(ut_cmor_converter); if (ut_get_status() != UT_SUCCESS) { - snprintf(msg, CMOR_MAX_STRING, - "Udunits: Error freeing converter, axis: %s (table: %s)", - cmor_axes[axis_id].id, - cmor_tables[cmor_axes[axis_id].ref_table_id].szTable_id); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "Udunits: Error freeing converter, axis: %s (table: %s)", + CMOR_CRITICAL, + cmor_axes[axis_id].id, + cmor_tables[cmor_axes[axis_id].ref_table_id].szTable_id); } ut_free(user_units); if (ut_get_status() != UT_SUCCESS) { - snprintf(msg, CMOR_MAX_STRING, - "Udunits: Error freeing units, axis: %s (table: %s)", - cmor_axes[axis_id].id, - cmor_tables[cmor_axes[axis_id].ref_table_id].szTable_id); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "Udunits: Error freeing units, axis: %s (table: %s)", + CMOR_CRITICAL, + cmor_axes[axis_id].id, + cmor_tables[cmor_axes[axis_id].ref_table_id].szTable_id); } /* at this point we need to figure out the axis units interval */ @@ -1452,19 +1456,19 @@ int cmor_check_interval(int axis_id, char *interval, double *values, user_units = ut_parse(ut_read, ctmp2, UT_ASCII); if (ut_get_status() != UT_SUCCESS) { - snprintf(msg, CMOR_MAX_STRING, - "In udunits parsing user units: %s, axis: %s (table: %s)", - ctmp2, cmor_axes[axis_id].id, - cmor_tables[cmor_axes[axis_id].ref_table_id].szTable_id); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "In udunits parsing user units: %s, axis: %s (table: %s)", + CMOR_CRITICAL, + ctmp2, cmor_axes[axis_id].id, + cmor_tables[cmor_axes[axis_id].ref_table_id].szTable_id); } if (ut_are_convertible(cmor_units, user_units) == 0) { - snprintf(ctmp, CMOR_MAX_STRING, - "axis interval units (%s) are incompatible with seconds, axis: %s (table: %s)", - ctmp2, cmor_axes[axis_id].id, - cmor_tables[cmor_axes[axis_id].ref_table_id].szTable_id); - cmor_handle_error(ctmp, CMOR_CRITICAL); + cmor_handle_error_variadic( + "axis interval units (%s) are incompatible with seconds, axis: %s (table: %s)", + CMOR_CRITICAL, + ctmp2, cmor_axes[axis_id].id, + cmor_tables[cmor_axes[axis_id].ref_table_id].szTable_id); cmor_pop_traceback(); return (1); } @@ -1472,11 +1476,11 @@ int cmor_check_interval(int axis_id, char *interval, double *values, ut_cmor_converter = ut_get_converter(user_units, cmor_units); if (ut_get_status() != UT_SUCCESS) { - snprintf(msg, CMOR_MAX_STRING, - "Udunits: Error getting converter from %s to %s, axis: %s (table: %s)", - ctmp2, msg, cmor_axes[axis_id].id, - cmor_tables[cmor_axes[axis_id].ref_table_id].szTable_id); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "Udunits: Error getting converter from %s to %s, axis: %s (table: %s)", + CMOR_CRITICAL, + ctmp2, msg, cmor_axes[axis_id].id, + cmor_tables[cmor_axes[axis_id].ref_table_id].szTable_id); } tmp = 0.; @@ -1487,11 +1491,11 @@ int cmor_check_interval(int axis_id, char *interval, double *values, /* -------------------------------------------------------------------- */ tmp = cv_convert_double(ut_cmor_converter, diff); if (ut_get_status() != UT_SUCCESS) { - snprintf(msg, CMOR_MAX_STRING, - "In udunits converting, axis: %s (table: %s)", - cmor_axes[axis_id].id, - cmor_tables[cmor_axes[axis_id].ref_table_id].szTable_id); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "In udunits converting, axis: %s (table: %s)", + CMOR_CRITICAL, + cmor_axes[axis_id].id, + cmor_tables[cmor_axes[axis_id].ref_table_id].szTable_id); } diff2 = tmp; @@ -1503,47 +1507,49 @@ int cmor_check_interval(int axis_id, char *interval, double *values, if (tmp > cmor_tables[cmor_axes[axis_id].ref_table_id].interval_error) { if (isbounds == 1) { - snprintf(ctmp, CMOR_MAX_STRING, - "approximate time axis interval is defined as %f " - "seconds (%s), for value %i we got a difference " - "(based on bounds) of %f seconds, (%f %s), which " - "is %f %% , seems too big, check your values", - interv, interval, i + 1, diff2, diff, ctmp2, - tmp * 100.); + cmor_handle_error_variadic( + "approximate time axis interval is defined as %f " + "seconds (%s), for value %i we got a difference " + "(based on bounds) of %f seconds, (%f %s), which " + "is %f %% , seems too big, check your values", + CMOR_CRITICAL, + interv, interval, i + 1, diff2, diff, ctmp2, + tmp * 100.); } else { if (isbounds == 1) { - snprintf(ctmp, CMOR_MAX_STRING, - "approximate time axis interval is defined as " - "%f seconds (%s), for value %i we got a difference " - "(based on bounds) of %f seconds (%f %s), which is " - "%f %% , seems too big, check your values", - interv, interval, i + 1, diff2, diff, ctmp2, - tmp * 100.); + cmor_handle_error_variadic( + "approximate time axis interval is defined as " + "%f seconds (%s), for value %i we got a difference " + "(based on bounds) of %f seconds (%f %s), which is " + "%f %% , seems too big, check your values", + CMOR_CRITICAL, + interv, interval, i + 1, diff2, diff, ctmp2, + tmp * 100.); } else { - snprintf(ctmp, CMOR_MAX_STRING, - "approximate time axis interval is defined as %f " - "seconds (%s), for value %i we got a difference of " - "%f seconds (%f %s), which is %f %% , seems too big, " - "check your values", - interv, interval, i + 1, diff2, diff, ctmp2, - tmp * 100.); + cmor_handle_error_variadic( + "approximate time axis interval is defined as %f " + "seconds (%s), for value %i we got a difference of " + "%f seconds (%f %s), which is %f %% , seems too big, " + "check your values", + CMOR_CRITICAL, + interv, interval, i + 1, diff2, diff, ctmp2, + tmp * 100.); } } - cmor_handle_error(ctmp, CMOR_CRITICAL); } else if (tmp > cmor_tables[cmor_axes[axis_id].ref_table_id]. interval_warning) { /* -------------------------------------------------------------------- */ /* more than 10% diff issues a warning */ /* -------------------------------------------------------------------- */ - snprintf(ctmp, CMOR_MAX_STRING, - "approximate time axis interval is defined as %f " - "seconds (%s), for value %i we got a difference of %f " - "seconds (%f %s), which is %f %% , seems too big, check " - "your values", - interv, interval, i + 1, diff2, diff, ctmp2, tmp * 100.); - cmor_handle_error(ctmp, CMOR_WARNING); + cmor_handle_error_variadic( + "approximate time axis interval is defined as %f " + "seconds (%s), for value %i we got a difference of %f " + "seconds (%f %s), which is %f %% , seems too big, check " + "your values", + CMOR_WARNING, + interv, interval, i + 1, diff2, diff, ctmp2, tmp * 100.); } } @@ -1554,9 +1560,8 @@ int cmor_check_interval(int axis_id, char *interval, double *values, && (fabs(interv - 2592000.) / 2592000. < .1)) { cmor_get_cur_dataset_attribute("calendar", ctmp); if (cmor_calendar_c2i(ctmp, &icali) != 0) { - snprintf(ctmp, CMOR_MAX_STRING, - "Cannot convert times for calendar: %s", ctmp); - cmor_handle_error(ctmp, CMOR_NORMAL); + cmor_handle_error_variadic( + "Cannot convert times for calendar: %s", CMOR_NORMAL, ctmp); cmor_pop_traceback(); return (1); } @@ -1567,11 +1572,11 @@ int cmor_check_interval(int axis_id, char *interval, double *values, axes[axis->ref_axis_id].units, ctmp); cdRel2Comp(icali, ctmp, values[i], &comptime); if (comptime.day != 1) { - snprintf(ctmp, CMOR_MAX_STRING, - "Bounds value %ld-%d-%d is not beg or end of month\n! " - "and you seem to be writing monthly data, please check", - comptime.year, comptime.month, comptime.day); - cmor_handle_error(ctmp, CMOR_WARNING); + cmor_handle_error_variadic( + "Bounds value %ld-%d-%d is not beg or end of month\n! " + "and you seem to be writing monthly data, please check", + CMOR_WARNING, + comptime.year, comptime.month, comptime.day); } } } @@ -1579,31 +1584,31 @@ int cmor_check_interval(int axis_id, char *interval, double *values, cv_free(ut_cmor_converter); if (ut_get_status() != UT_SUCCESS) { - snprintf(msg, CMOR_MAX_STRING, - "Udunits: Error freeing converter, axis: %s (table: %s)", - cmor_axes[axis_id].id, - cmor_tables[cmor_axes[axis_id].ref_table_id].szTable_id); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "Udunits: Error freeing converter, axis: %s (table: %s)", + CMOR_CRITICAL, + cmor_axes[axis_id].id, + cmor_tables[cmor_axes[axis_id].ref_table_id].szTable_id); } ut_free(cmor_units); if (ut_get_status() != UT_SUCCESS) { - snprintf(msg, CMOR_MAX_STRING, - "Udunits: Error freeing units, axis: %s (table: %s)", - cmor_axes[axis_id].id, - cmor_tables[cmor_axes[axis_id].ref_table_id].szTable_id); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "Udunits: Error freeing units, axis: %s (table: %s)", + CMOR_CRITICAL, + cmor_axes[axis_id].id, + cmor_tables[cmor_axes[axis_id].ref_table_id].szTable_id); } ut_free(user_units); if (ut_get_status() != UT_SUCCESS) { - snprintf(msg, CMOR_MAX_STRING, - "Udunits: Error freeing units, axis: %s (table: %s)", - cmor_axes[axis_id].id, - cmor_tables[cmor_axes[axis_id].ref_table_id].szTable_id); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "Udunits: Error freeing units, axis: %s (table: %s)", + CMOR_CRITICAL, + cmor_axes[axis_id].id, + cmor_tables[cmor_axes[axis_id].ref_table_id].szTable_id); } if (isbounds == 1) @@ -1659,11 +1664,12 @@ int cmor_axis(int *axis_id, char *name, char *units, int length, } if (iref == -1) { - snprintf(ctmp, CMOR_MAX_STRING, - "Could not find all axes for this variable. \n! " - "Check that all your axes name matches the ones found in \n! " - "the table %s. \n!", cmor_tables[CMOR_TABLE].szTable_id); - cmor_handle_error(ctmp, CMOR_CRITICAL); + cmor_handle_error_variadic( + "Could not find all axes for this variable. \n! " + "Check that all your axes name matches the ones found in \n! " + "the table %s. \n!", + CMOR_CRITICAL, + cmor_tables[CMOR_TABLE].szTable_id); } refaxis = cmor_tables[CMOR_TABLE].axes[iref]; @@ -1741,11 +1747,11 @@ int cmor_axis(int *axis_id, char *name, char *units, int length, if ((strcmp(name, "standard_hybrid_sigma") != 0) && (strcmp(name, "alternate_hybrid_sigma") != 0) && (strcmp(name, "standard_sigma") != 0)) { - snprintf(msg, CMOR_MAX_STRING, - "axis: %s (table: %s) converting to \"standard_hybrid_sigma\" from unknown type: %s", - cmor_axes[cmor_naxes].id, - cmor_tables[CMOR_TABLE].szTable_id, name); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "axis: %s (table: %s) converting to \"standard_hybrid_sigma\" from unknown type: %s", + CMOR_CRITICAL, + cmor_axes[cmor_naxes].id, + cmor_tables[CMOR_TABLE].szTable_id, name); } cmor_axis(axis_id, refaxis.convert_to, units, length, @@ -1757,13 +1763,13 @@ int cmor_axis(int *axis_id, char *name, char *units, int length, cmor_pop_traceback(); return (0); } else { - snprintf(msg, CMOR_MAX_STRING, - "axis: %s (table: %s) is declared to be converted " - "to unknown type: %s", - cmor_axes[cmor_naxes].id, - cmor_tables[CMOR_TABLE].szTable_id, - refaxis.convert_to); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "axis: %s (table: %s) is declared to be converted " + "to unknown type: %s", + CMOR_CRITICAL, + cmor_axes[cmor_naxes].id, + cmor_tables[CMOR_TABLE].szTable_id, + refaxis.convert_to); } } } else { @@ -1784,23 +1790,23 @@ int cmor_axis(int *axis_id, char *name, char *units, int length, if ((cell_bounds == NULL) && (refaxis.must_have_bounds == 1)) { if (refaxis.axis != 'T') { - snprintf(msg, CMOR_MAX_STRING, - "axis: %s (table: %s) must have bounds, you did not " - "pass any when creating it via cmor_axis", - cmor_axes[cmor_naxes].id, - cmor_tables[CMOR_TABLE].szTable_id); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "axis: %s (table: %s) must have bounds, you did not " + "pass any when creating it via cmor_axis", + CMOR_CRITICAL, + cmor_axes[cmor_naxes].id, + cmor_tables[CMOR_TABLE].szTable_id); } else if (coord_vals != NULL) { /* -------------------------------------------------------------------- */ /* we passed time values that means we */ /* do not intend to pass them later */ /* -------------------------------------------------------------------- */ - snprintf(msg, CMOR_MAX_STRING, - "axis: %s (table: %s) must have bounds, you did not " - "pass any when creating it via cmor_axis", - cmor_axes[cmor_naxes].id, - cmor_tables[CMOR_TABLE].szTable_id); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "axis: %s (table: %s) must have bounds, you did not " + "pass any when creating it via cmor_axis", + CMOR_CRITICAL, + cmor_axes[cmor_naxes].id, + cmor_tables[CMOR_TABLE].szTable_id); } } /* -------------------------------------------------------------------- */ @@ -1820,12 +1826,12 @@ int cmor_axis(int *axis_id, char *name, char *units, int length, } if (cmor_axes[cmor_naxes].values == NULL) { - snprintf(msg, CMOR_MAX_STRING, - "cannot allocate memory for %i double elts for " - "axis %s (table: %s)", - length, cmor_axes[cmor_naxes].id, - cmor_tables[CMOR_TABLE].szTable_id); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "cannot allocate memory for %i double elts for " + "axis %s (table: %s)", + CMOR_CRITICAL, + length, cmor_axes[cmor_naxes].id, + cmor_tables[CMOR_TABLE].szTable_id); } if (type == 'f') { @@ -1855,23 +1861,23 @@ int cmor_axis(int *axis_id, char *name, char *units, int length, /* check that output type is also character */ /* -------------------------------------------------------------------- */ if (type != refaxis.type) { - snprintf(msg, CMOR_MAX_STRING, - "You are trying to define axis %s (table: %s) as " - "character when it should be of type: %c\n! ", - cmor_axes[cmor_naxes].id, - cmor_tables[CMOR_TABLE].szTable_id, refaxis.type); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "You are trying to define axis %s (table: %s) as " + "character when it should be of type: %c\n! ", + CMOR_CRITICAL, + cmor_axes[cmor_naxes].id, + cmor_tables[CMOR_TABLE].szTable_id, refaxis.type); } cmor_axes[cmor_naxes].cvalues = malloc(length * sizeof(char *)); if (cmor_axes[cmor_naxes].cvalues == NULL) { - snprintf(msg, CMOR_MAX_STRING, - "cannot allocate memory for %i char elts for axis " - "%s (table: %s)", - length, cmor_axes[cmor_naxes].id, - cmor_tables[CMOR_TABLE].szTable_id); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "cannot allocate memory for %i char elts for axis " + "%s (table: %s)", + CMOR_CRITICAL, + length, cmor_axes[cmor_naxes].id, + cmor_tables[CMOR_TABLE].szTable_id); } if (cell_bounds_ndim == 0) @@ -1888,12 +1894,12 @@ int cmor_axis(int *axis_id, char *name, char *units, int length, malloc((j + 1) * sizeof(char)); if (cmor_axes[cmor_naxes].cvalues[i] == NULL) { - snprintf(msg, CMOR_MAX_STRING, - "cannot allocate memory for %i char elts for axis " - "%s (table: %s)", - j + 1, cmor_axes[cmor_naxes].id, - cmor_tables[CMOR_TABLE].szTable_id); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "cannot allocate memory for %i char elts for axis " + "%s (table: %s)", + CMOR_CRITICAL, + j + 1, cmor_axes[cmor_naxes].id, + cmor_tables[CMOR_TABLE].szTable_id); } strncpy(cmor_axes[cmor_naxes].cvalues[i], @@ -1927,12 +1933,12 @@ int cmor_axis(int *axis_id, char *name, char *units, int length, } if (k == -1) { - snprintf(msg, CMOR_MAX_STRING, - "Requested region for axis '%s' (table: %s) " - "is not passed: '%s'", - cmor_axes[cmor_naxes].id, - cmor_tables[CMOR_TABLE].szTable_id, ctmp); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "Requested region for axis '%s' (table: %s) " + "is not passed: '%s'", + CMOR_CRITICAL, + cmor_axes[cmor_naxes].id, + cmor_tables[CMOR_TABLE].szTable_id, ctmp); } } } @@ -1957,13 +1963,13 @@ int cmor_axis(int *axis_id, char *name, char *units, int length, cmor_axes[cmor_naxes].bounds = malloc(2 * length * sizeof(double)); if (cmor_axes[cmor_naxes].bounds == NULL) { - snprintf(msg, CMOR_MAX_STRING, - "cannot allocate memory for %i bounds elts for axis " - "%s (table: %s)", - 2 * length, cmor_axes[cmor_naxes].id, - cmor_tables[CMOR_TABLE].szTable_id); + cmor_handle_error_variadic( + "cannot allocate memory for %i bounds elts for axis " + "%s (table: %s)", + CMOR_CRITICAL, + 2 * length, cmor_axes[cmor_naxes].id, + cmor_tables[CMOR_TABLE].szTable_id); free(cmor_axes[cmor_naxes].bounds); - cmor_handle_error(msg, CMOR_CRITICAL); } if (cell_bounds_ndim == 2) { @@ -1996,12 +2002,12 @@ int cmor_axis(int *axis_id, char *name, char *units, int length, (double)((int *)cell_bounds)[2 * i + 1]; } } else { /* ??? charcter axis code here */ - snprintf(msg, CMOR_MAX_STRING, - "CMOR cannot handle axes of type %c please " - "change type, axis: %s (table: %s)", - type, cmor_axes[cmor_naxes].id, - cmor_tables[CMOR_TABLE].szTable_id); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "CMOR cannot handle axes of type %c please " + "change type, axis: %s (table: %s)", + CMOR_CRITICAL, + type, cmor_axes[cmor_naxes].id, + cmor_tables[CMOR_TABLE].szTable_id); } } else if (cell_bounds_ndim == 1) { if (type == 'f') { @@ -2033,12 +2039,12 @@ int cmor_axis(int *axis_id, char *name, char *units, int length, (double)((long *)cell_bounds)[i + 1]; } } else { /* ??? charcter axis code here */ - snprintf(msg, CMOR_MAX_STRING, - "CMOR cannot handle axes of type %c please " - "change type, axis: %s (table: %s)", - type, cmor_axes[cmor_naxes].id, - cmor_tables[CMOR_TABLE].szTable_id); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "CMOR cannot handle axes of type %c please " + "change type, axis: %s (table: %s)", + CMOR_CRITICAL, + type, cmor_axes[cmor_naxes].id, + cmor_tables[CMOR_TABLE].szTable_id); } } @@ -2089,11 +2095,11 @@ int cmor_axis(int *axis_id, char *name, char *units, int length, } } else { if ((refaxis.axis != 'T') && (refaxis.index_only == 'n')) { - snprintf(msg, CMOR_MAX_STRING, - "function called for axis '%s' (table: %s) w/o any values", - cmor_axes[cmor_naxes].id, - cmor_tables[CMOR_TABLE].szTable_id); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "function called for axis '%s' (table: %s) w/o any values", + CMOR_CRITICAL, + cmor_axes[cmor_naxes].id, + cmor_tables[CMOR_TABLE].szTable_id); } if (refaxis.index_only != 'n') { /* -------------------------------------------------------------------- */ @@ -2171,12 +2177,10 @@ void cmor_init_axis_def(cmor_axis_def_t * axis, int table_id) /* cmor_set_axis_def_att() */ /************************************************************************/ -int cmor_set_axis_def_att(cmor_axis_def_t * axis, char att[CMOR_MAX_STRING], - char val[CMOR_MAX_STRING]) +int cmor_set_axis_def_att(cmor_axis_def_t * axis, char *att, char *val) { int i, n, j; char dim[CMOR_MAX_STRING]; - char msg[CMOR_MAX_STRING]; double vals[CMOR_MAX_ELEMENTS]; double *tmp = NULL; @@ -2350,25 +2354,25 @@ int cmor_set_axis_def_att(cmor_axis_def_t * axis, char att[CMOR_MAX_STRING], /* -------------------------------------------------------------------- */ if (axis->requested_bounds == NULL) { - snprintf(msg, CMOR_MAX_STRING, - "axis (%s, table: %s): looks like we already read " - "%d requested bounds but they are not stored in the " - "internal tables, maybe some bad cleanup", - axis->id, cmor_tables[axis->table_id].szTable_id, - axis->n_requested_bounds); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "axis (%s, table: %s): looks like we already read " + "%d requested bounds but they are not stored in the " + "internal tables, maybe some bad cleanup", + CMOR_CRITICAL, + axis->id, cmor_tables[axis->table_id].szTable_id, + axis->n_requested_bounds); } tmp = malloc(axis->n_requested_bounds * sizeof(double)); if (tmp == NULL) { - snprintf(msg, CMOR_MAX_STRING, - "axis (%s, table: %s): cannot allocate memory for " - "%i requested bounds elts for axis %s", - axis->id, cmor_tables[axis->table_id].szTable_id, - axis->n_requested, axis->id); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "axis (%s, table: %s): cannot allocate memory for " + "%i requested bounds elts for axis %s", + CMOR_CRITICAL, + axis->id, cmor_tables[axis->table_id].szTable_id, + axis->n_requested, axis->id); } for (i = 0; i < axis->n_requested_bounds; i++) { @@ -2384,12 +2388,12 @@ int cmor_set_axis_def_att(cmor_axis_def_t * axis, char att[CMOR_MAX_STRING], axis->requested_bounds = malloc(axis->n_requested_bounds * sizeof(double)); if (axis->requested_bounds == NULL) { - snprintf(msg, CMOR_MAX_STRING, - "axis (%s, table: %s): cannot allocate memory for %i " - "requested bounds elts for axis %s", - axis->id, cmor_tables[axis->table_id].szTable_id, - axis->n_requested, axis->id); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "axis (%s, table: %s): cannot allocate memory for %i " + "requested bounds elts for axis %s", + CMOR_CRITICAL, + axis->id, cmor_tables[axis->table_id].szTable_id, + axis->n_requested, axis->id); } for (i = 0; i < n; i++) { @@ -2442,24 +2446,24 @@ int cmor_set_axis_def_att(cmor_axis_def_t * axis, char att[CMOR_MAX_STRING], /* -------------------------------------------------------------------- */ if (axis->n_requested != 0) { if (axis->requested == NULL) { - snprintf(msg, CMOR_MAX_STRING, - "axis (%s, table: %s): looks like we already read " - "%d requested values but they are not stored in " - "the internal tables, maybe some bad cleanup", - axis->id, cmor_tables[axis->table_id].szTable_id, - axis->n_requested); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "axis (%s, table: %s): looks like we already read " + "%d requested values but they are not stored in " + "the internal tables, maybe some bad cleanup", + CMOR_CRITICAL, + axis->id, cmor_tables[axis->table_id].szTable_id, + axis->n_requested); } tmp = malloc(axis->n_requested * sizeof(double)); if (tmp == NULL) { - snprintf(msg, CMOR_MAX_STRING, - "axis (%s, table: %s): cannot allocate memory for " - "%i requested elts for axis %s", - axis->id, cmor_tables[axis->table_id].szTable_id, - axis->n_requested, axis->id); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "axis (%s, table: %s): cannot allocate memory for " + "%i requested elts for axis %s", + CMOR_CRITICAL, + axis->id, cmor_tables[axis->table_id].szTable_id, + axis->n_requested, axis->id); } for (i = 0; i < axis->n_requested; i++) { tmp[i] = axis->requested[i]; @@ -2471,12 +2475,12 @@ int cmor_set_axis_def_att(cmor_axis_def_t * axis, char att[CMOR_MAX_STRING], } axis->requested = malloc(axis->n_requested * sizeof(double)); if (axis->requested == NULL) { - snprintf(msg, CMOR_MAX_STRING, - "axis (%s, table: %s): cannot allocate memory for %i " - "requested elts for axis %s", - axis->id, cmor_tables[axis->table_id].szTable_id, - axis->n_requested, axis->id); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "axis (%s, table: %s): cannot allocate memory for %i " + "requested elts for axis %s", + CMOR_CRITICAL, + axis->id, cmor_tables[axis->table_id].szTable_id, + axis->n_requested, axis->id); } for (i = 0; i < n; i++) { axis->requested[i] = vals[i]; @@ -2496,22 +2500,22 @@ int cmor_set_axis_def_att(cmor_axis_def_t * axis, char att[CMOR_MAX_STRING], axis->crequested = malloc((strlen(val) + 1) * sizeof(char)); if (axis->crequested == NULL) { - snprintf(msg, CMOR_MAX_STRING, - "axis (%s, table: %s): cannot allocate memory " - "for %ld requested char elts for axis %s", - axis->id, cmor_tables[axis->table_id].szTable_id, - (long int)strlen(val) + 1, axis->id); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "axis (%s, table: %s): cannot allocate memory " + "for %ld requested char elts for axis %s", + CMOR_CRITICAL, + axis->id, cmor_tables[axis->table_id].szTable_id, + (long int)strlen(val) + 1, axis->id); } strcpy(axis->crequested, val); } } else { - snprintf(msg, CMOR_MAX_STRING, - "Unknown attribute >>>%s<<< for axis section " - "(%s, table: %s), value: %s", - att, axis->id, cmor_tables[axis->table_id].szTable_id, val); - cmor_handle_error(msg, CMOR_WARNING); + cmor_handle_error_variadic( + "Unknown attribute >>>%s<<< for axis section " + "(%s, table: %s), value: %s", + CMOR_WARNING, + att, axis->id, cmor_tables[axis->table_id].szTable_id, val); } cmor_pop_traceback(); return (0); diff --git a/Src/cmor_grids.c b/Src/cmor_grids.c index c19224af..5cac4e9b 100644 --- a/Src/cmor_grids.c +++ b/Src/cmor_grids.c @@ -42,7 +42,6 @@ void cmor_init_grid_mapping(cmor_mappings_t * mapping, char *id) int cmor_copy_data(double **dest1, void *data, char type, int nelts) { int i; - char msg[CMOR_MAX_STRING]; double *dest; cmor_add_traceback("cmor_copy_data"); @@ -64,8 +63,8 @@ int cmor_copy_data(double **dest1, void *data, char type, int nelts) else if (type == 'd') dest[i] = (double)((double *)data)[i]; else { - snprintf(msg, CMOR_MAX_STRING, "wrong data type: %c", type); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "wrong data type: %c", CMOR_CRITICAL, type); } } *dest1 = dest; @@ -124,7 +123,6 @@ void cmor_convert_value(char *units, char *ctmp, double *tmp) ut_unit *user_units = NULL, *cmor_units = NULL; cv_converter *ut_cmor_converter = NULL; double value; - char msg[CMOR_MAX_STRING]; cmor_add_traceback("cmor_convert_value"); @@ -134,26 +132,26 @@ void cmor_convert_value(char *units, char *ctmp, double *tmp) &ut_cmor_converter); *tmp = cv_convert_double(ut_cmor_converter, value); if (ut_get_status() != UT_SUCCESS) { - snprintf(msg, CMOR_MAX_STRING, - "Udunits: Error converting units from %s to %s", - units, ctmp); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "Udunits: Error converting units from %s to %s", + CMOR_CRITICAL, + units, ctmp); } cv_free(ut_cmor_converter); if (ut_get_status() != UT_SUCCESS) { - snprintf(msg, CMOR_MAX_STRING, "Udunits: Error freeing converter"); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "Udunits: Error freeing converter", CMOR_CRITICAL); } ut_free(cmor_units); if (ut_get_status() != UT_SUCCESS) { - snprintf(msg, CMOR_MAX_STRING, "Udunits: Error freeing units"); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "Udunits: Error freeing units", CMOR_CRITICAL); } ut_free(user_units); if (ut_get_status() != UT_SUCCESS) { - snprintf(msg, CMOR_MAX_STRING, "Udunits: Error freeing units"); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "Udunits: Error freeing units", CMOR_CRITICAL); } } else *tmp = value; @@ -170,7 +168,6 @@ int cmor_set_grid_attribute(int gid, char *name, double *value, char *units) int i, j, iatt; int grid_id; char ctmp[CMOR_MAX_STRING]; - char msg[CMOR_MAX_STRING]; double tmp; cmor_add_traceback("cmor_set_grid_attribute"); @@ -203,9 +200,12 @@ int cmor_set_grid_attribute(int gid, char *name, double *value, char *units) j = i; } if (j == -1) { - snprintf(ctmp, CMOR_MAX_STRING, - "grid mapping attribute: 'false easting' must be set in conjunction with ut_cmor_a 'projection_x_coordinate' axis, I could not find such an axis on your grid, we will not set this attribute"); - cmor_handle_error(ctmp, CMOR_NORMAL); + cmor_handle_error_variadic( + "grid mapping attribute: 'false easting' " + "must be set in conjunction with ut_cmor_a " + "'projection_x_coordinate' axis, I could not find " + "such an axis on your grid, we will not set this attribute", + CMOR_NORMAL); cmor_pop_traceback(); return (1); } @@ -221,9 +221,12 @@ int cmor_set_grid_attribute(int gid, char *name, double *value, char *units) j = i; } if (j == -1) { - snprintf(ctmp, CMOR_MAX_STRING, - "grid mapping attribute: 'false northing' must be set in conjunction with a 'projection_y_coordinate' axis, I could not find such an axis on your grid, we will not set this attribute"); - cmor_handle_error(ctmp, CMOR_NORMAL); + cmor_handle_error_variadic( + "grid mapping attribute: 'false northing' " + "must be set in conjunction with a 'projection_y_coordinate' " + "axis, I could not find such an axis on your grid, " + "we will not set this attribute", + CMOR_NORMAL); cmor_pop_traceback(); return (1); } @@ -238,10 +241,10 @@ int cmor_set_grid_attribute(int gid, char *name, double *value, char *units) strcpy(ctmp, "degrees_north"); cmor_convert_value(units, ctmp, &tmp); if ((tmp < -90) || (tmp > 90.)) { - snprintf(msg, CMOR_MAX_STRING, - "%s parameter must be between -90 and 90 %s, will not be set", - name, ctmp); - cmor_handle_error(msg, CMOR_NORMAL); + cmor_handle_error_variadic( + "%s parameter must be between -90 and 90 %s, will not be set", + CMOR_NORMAL, + name, ctmp); cmor_pop_traceback(); return (1); } @@ -254,10 +257,10 @@ int cmor_set_grid_attribute(int gid, char *name, double *value, char *units) strcpy(ctmp, "degrees_east"); cmor_convert_value(units, ctmp, &tmp); if ((tmp < -180) || (tmp > 180.)) { - snprintf(msg, CMOR_MAX_STRING, - "%s parameter must be between -180 and 180 %s, will not be set", - name, ctmp); - cmor_handle_error(msg, CMOR_NORMAL); + cmor_handle_error_variadic( + "%s parameter must be between -180 and 180 %s, will not be set", + CMOR_NORMAL, + name, ctmp); cmor_pop_traceback(); return (1); } @@ -271,10 +274,10 @@ int cmor_set_grid_attribute(int gid, char *name, double *value, char *units) strcpy(ctmp, "m"); cmor_convert_value(units, ctmp, &tmp); if (tmp < 0) { - snprintf(msg, CMOR_MAX_STRING, - "%s parameter must be between positive, will not be set", - name); - cmor_handle_error(msg, CMOR_NORMAL); + cmor_handle_error_variadic( + "%s parameter must be between positive, will not be set", + CMOR_NORMAL, + name); cmor_pop_traceback(); return (1); } @@ -468,7 +471,6 @@ void cmor_set_mapping_attribute(cmor_mappings_t * mapping, char val[CMOR_MAX_STRING]) { int i, n; - char msg[CMOR_MAX_STRING]; cmor_add_traceback("cmor_set_mapping_attribute"); @@ -497,10 +499,10 @@ void cmor_set_mapping_attribute(cmor_mappings_t * mapping, } else { - snprintf(msg, CMOR_MAX_STRING, - "Unknown attribute: '%s' for mapping '%s' (value was: '%s')", - att, mapping->id, val); - cmor_handle_error(msg, CMOR_WARNING); + cmor_handle_error_variadic( + "Unknown attribute: '%s' for mapping '%s' (value was: '%s')", + CMOR_WARNING, + att, mapping->id, val); } cmor_pop_traceback(); @@ -516,25 +518,24 @@ int cmor_set_grid_mapping(int gid, char *name, int nparam, attributes_values[CMOR_MAX_GRID_ATTRIBUTES], char *units, int lnunits) { - int grid_id, nattributes, ndims; + int grid_id, nattributes, ndims, msg_len; int i, j, k, l; - char *achar, *bchar; + char *achar, *bchar, *axes_msg; char lattributes_names[CMOR_MAX_GRID_ATTRIBUTES][CMOR_MAX_STRING]; char lunits[CMOR_MAX_GRID_ATTRIBUTES][CMOR_MAX_STRING]; char grid_attributes[CMOR_MAX_GRID_ATTRIBUTES][CMOR_MAX_STRING]; char msg[CMOR_MAX_STRING]; - char msg2[CMOR_MAX_STRING]; char grid_dimensions[CMOR_MAX_DIMENSIONS][CMOR_MAX_STRING]; cmor_add_traceback("cmor_set_grid_mapping"); if (nparam >= CMOR_MAX_GRID_ATTRIBUTES) { - snprintf(msg, CMOR_MAX_STRING, - "CMOR allows only %i grid parameters too be defined, " - "you are trying to define %i parameters, if you really " - "need that many recompile cmor changing the value of " - "parameter: CMOR_MAX_GRID_ATTRIBUTES", - CMOR_MAX_GRID_ATTRIBUTES, nparam); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "CMOR allows only %i grid parameters too be defined, " + "you are trying to define %i parameters, if you really " + "need that many recompile cmor changing the value of " + "parameter: CMOR_MAX_GRID_ATTRIBUTES", + CMOR_CRITICAL, + CMOR_MAX_GRID_ATTRIBUTES, nparam); } achar = (char *)attributes_names; bchar = (char *)units; @@ -554,11 +555,11 @@ int cmor_set_grid_mapping(int gid, char *name, int nparam, &ndims, grid_dimensions); if (ndims != cmor_grids[grid_id].ndims) { - snprintf(msg, CMOR_MAX_STRING, - "you defined your grid with %i axes but grid_mapping " - "'%s' requires exactly %i axes", - cmor_grids[grid_id].ndims, name, ndims); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "you defined your grid with %i axes but grid_mapping " + "'%s' requires exactly %i axes", + CMOR_CRITICAL, + cmor_grids[grid_id].ndims, name, ndims); cmor_pop_traceback(); return (-1); @@ -597,14 +598,22 @@ int cmor_set_grid_mapping(int gid, char *name, int nparam, } if (k != ndims) { - snprintf(msg, CMOR_MAX_STRING, - "setting grid mapping to '%s' we could not find all " - "the required axes, required axes are:", name); + msg_len = 0; + for (i = 0; i < ndims; i++) { + msg_len += snprintf(NULL, 0, " %s", grid_dimensions[i]); + } + msg_len += 1; + axes_msg = (char *)malloc(msg_len * sizeof(char)); + msg_len = 0; for (i = 0; i < ndims; i++) { - snprintf(msg2, CMOR_MAX_STRING, " %s", grid_dimensions[i]); - strncat(msg, msg2, CMOR_MAX_STRING - strlen(msg)); + msg_len += sprintf(&axes_msg[msg_len], " %s", grid_dimensions[i]); } - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "setting grid mapping to '%s' we could not find all " + "the required axes, required axes are:%s", + CMOR_CRITICAL, + name, axes_msg); + free(axes_msg); cmor_pop_traceback(); return (-1); @@ -625,10 +634,11 @@ int cmor_set_grid_mapping(int gid, char *name, int nparam, cmor_set_grid_attribute(gid, lattributes_names[i], &attributes_values[i], lunits[i]); } else { - snprintf(msg, CMOR_MAX_STRING, - "in grid_mapping, attribute '%s' (with value: %lf) is not a known attribute for grid mapping: '%s'", - lattributes_names[i], attributes_values[i], name); - cmor_handle_error(msg, CMOR_WARNING); + cmor_handle_error_variadic( + "in grid_mapping, attribute '%s' (with value: %lf) " + "is not a known attribute for grid mapping: '%s'", + CMOR_WARNING, + lattributes_names[i], attributes_values[i], name); cmor_pop_traceback(); return (-1); } @@ -644,10 +654,11 @@ int cmor_set_grid_mapping(int gid, char *name, int nparam, for (i = 0; i < nattributes - 6; i++) { if (cmor_has_grid_attribute(gid, grid_attributes[i]) == 1) { - snprintf(msg, CMOR_MAX_STRING, - "Grid mapping attribute %s has not been set, you should consider setting it", - grid_attributes[i]); - cmor_handle_error(msg, CMOR_WARNING); + cmor_handle_error_variadic( + "Grid mapping attribute %s has not been set, " + "you should consider setting it", + CMOR_WARNING, + grid_attributes[i]); } } @@ -722,11 +733,12 @@ int cmor_time_varying_grid_coordinate(int *coord_grid_id, int grid_id, break; case (2): if (nvertices == 0) { - sprintf(msg, - "your defining a vertices dependent variable (%s) " - "associated with grid %i, but you declared this grid " - "as having 0 vertices", table_entry, grid_id); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "your defining a vertices dependent variable (%s) " + "associated with grid %i, but you declared this grid " + "as having 0 vertices", + CMOR_CRITICAL, + table_entry, grid_id); } if (cmor_grids[cmor_vars[*coord_grid_id].grid_id].associated_variables [3] @@ -788,12 +800,14 @@ int cmor_time_varying_grid_coordinate(int *coord_grid_id, int grid_id, case (3): if (nvertices == 0) { - sprintf(msg, "your defining a vertices dependent " - "variable (%s) associated with grid %i, " - "but you declared this grid as having " - "0 vertices", table_entry, grid_id); + cmor_handle_error_variadic( + "your defining a vertices dependent " + "variable (%s) associated with grid %i, " + "but you declared this grid as having " + "0 vertices", + CMOR_CRITICAL, + table_entry, grid_id); - cmor_handle_error(msg, CMOR_CRITICAL); } if (cmor_grids[cmor_vars[*coord_grid_id].grid_id].associated_variables @@ -851,8 +865,8 @@ int cmor_time_varying_grid_coordinate(int *coord_grid_id, int grid_id, break; default: - sprintf(msg, "unknown coord type: %i", ctype); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "unknown coord type: %i", CMOR_CRITICAL, ctype); cmor_pop_traceback(); return (-1); @@ -878,18 +892,18 @@ int cmor_grid(int *grid_id, int ndims, int *axes_ids, char type, cmor_add_traceback("cmor_grid"); if ((axes_ids == NULL) || (ndims == 0)) { - snprintf(msg, CMOR_MAX_STRING, - "You need to define the grid axes first"); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "You need to define the grid axes first", CMOR_CRITICAL); } cmor_ngrids += 1; if (cmor_ngrids >= CMOR_MAX_GRIDS) { - snprintf(msg, CMOR_MAX_STRING, - "Too many grids defined, maximum possible " - "grids is currently set to %i", CMOR_MAX_GRIDS); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "Too many grids defined, maximum possible " + "grids is currently set to %i", + CMOR_CRITICAL, + CMOR_MAX_GRIDS); } n = 1; @@ -897,9 +911,10 @@ int cmor_grid(int *grid_id, int ndims, int *axes_ids, char type, for (i = 0; i < ndims; i++) { if (axes_ids[i] > cmor_naxes) { - snprintf(msg, CMOR_MAX_STRING, - "Defining grid, Axis %i not defined yet", axes_ids[i]); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "Defining grid, Axis %i not defined yet", + CMOR_CRITICAL, + axes_ids[i]); } if (cmor_tables[cmor_axes[axes_ids[i]].ref_table_id].axes @@ -919,9 +934,9 @@ int cmor_grid(int *grid_id, int ndims, int *axes_ids, char type, if (lat == NULL) { if (cmor_grids[cmor_ngrids].istimevarying != 1) { - snprintf(msg, CMOR_MAX_STRING, - "you need to pass the latitude values when defining a grid"); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "you need to pass the latitude values when defining a grid", + CMOR_CRITICAL); } } else { @@ -939,10 +954,9 @@ int cmor_grid(int *grid_id, int ndims, int *axes_ids, char type, if (lon == NULL) { if (cmor_grids[cmor_ngrids].istimevarying != 1) { - snprintf(msg, CMOR_MAX_STRING, - "you need to pass the longitude values when " - "defining a grid"); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "you need to pass the longitude values when " + "defining a grid", CMOR_CRITICAL); } } else { @@ -957,10 +971,9 @@ int cmor_grid(int *grid_id, int ndims, int *axes_ids, char type, } if (blat == NULL) { if (cmor_grids[cmor_ngrids].istimevarying != 1) { - snprintf(msg, CMOR_MAX_STRING, - "it is recommended you pass the latitude bounds " - "values when defining a grid"); - cmor_handle_error(msg, CMOR_WARNING); + cmor_handle_error_variadic( + "it is recommended you pass the latitude bounds " + "values when defining a grid", CMOR_WARNING); } } else { cmor_copy_data(&cmor_grids[cmor_ngrids].blats, blat, type, @@ -1009,9 +1022,9 @@ int cmor_grid(int *grid_id, int ndims, int *axes_ids, char type, if (blon == NULL) { if (cmor_grids[cmor_ngrids].istimevarying != 1) { - snprintf(msg, CMOR_MAX_STRING, - "it is recommended you pass the longitude bounds values when defining a grid"); - cmor_handle_error(msg, CMOR_WARNING); + cmor_handle_error_variadic( + "it is recommended you pass the longitude bounds values when defining a grid", + CMOR_WARNING); } } else { diff --git a/Src/cmor_tables.c b/Src/cmor_tables.c index 125f7a5a..6c41eb24 100644 --- a/Src/cmor_tables.c +++ b/Src/cmor_tables.c @@ -114,7 +114,6 @@ int cmor_set_formula_entry(cmor_table_t * table, { extern int cmor_ntables; char szValue[CMOR_MAX_STRING]; - char msg[CMOR_MAX_STRING]; int nFormulaId; char *szTableId; cmor_var_def_t *formula; @@ -134,9 +133,10 @@ int cmor_set_formula_entry(cmor_table_t * table, formula = &cmor_table->formula[nFormulaId]; if (nFormulaId >= CMOR_MAX_FORMULA) { - snprintf(msg, CMOR_MAX_STRING, - "Too many formula defined for table: %s", szTableId); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "Too many formula defined for table: %s", + CMOR_CRITICAL, + szTableId); cmor_ntables--; cmor_pop_traceback(); return (1); @@ -169,7 +169,6 @@ int cmor_set_variable_entry(cmor_table_t * table, { extern int cmor_ntables; char szValue[CMOR_MAX_STRING]; - char msg[CMOR_MAX_STRING]; int nVarId; char *szTableId; array_list *jsonArray; @@ -192,9 +191,10 @@ int cmor_set_variable_entry(cmor_table_t * table, variable = &cmor_table->vars[nVarId]; if (nVarId >= CMOR_MAX_ELEMENTS) { - snprintf(msg, CMOR_MAX_STRING, - "Too many variables defined for table: %s", szTableId); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "Too many variables defined for table: %s", + CMOR_CRITICAL, + szTableId); cmor_ntables--; cmor_pop_traceback(); return (1); @@ -246,7 +246,6 @@ int cmor_set_axis_entry(cmor_table_t * table, { extern int cmor_ntables; char szValue[CMOR_MAX_STRING * 20]; - char msg[CMOR_MAX_STRING]; int nAxisId; char *szTableId; cmor_axis_def_t *axis; @@ -266,9 +265,10 @@ int cmor_set_axis_entry(cmor_table_t * table, axis = &cmor_table->axes[nAxisId]; if (nAxisId >= CMOR_MAX_ELEMENTS) { - snprintf(msg, CMOR_MAX_STRING, "Too many axes defined for table: %s", - szTableId); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "Too many axes defined for table: %s", + CMOR_CRITICAL, + szTableId); cmor_ntables--; cmor_pop_traceback(); return (1); @@ -302,7 +302,6 @@ int cmor_set_experiments(cmor_table_t * table, char att[CMOR_MAX_STRING], char val[CMOR_MAX_STRING]) { extern int cmor_ntables; - char szError[CMOR_MAX_STRING]; cmor_add_traceback("cmor_set_experiments"); cmor_is_setup(); @@ -311,9 +310,10 @@ int cmor_set_experiments(cmor_table_t * table, char att[CMOR_MAX_STRING], /* Check number of experiments */ /* -------------------------------------------------------------------- */ if (table->nexps > CMOR_MAX_ELEMENTS) { - snprintf(szError, CMOR_MAX_STRING, - "Table %s: Too many experiments defined", table->szTable_id); - cmor_handle_error(szError, CMOR_CRITICAL); + cmor_handle_error_variadic( + "Table %s: Too many experiments defined", + CMOR_CRITICAL, + table->szTable_id); cmor_ntables--; cmor_pop_traceback(); return (1); @@ -360,13 +360,13 @@ int cmor_set_dataset_att(cmor_table_t * table, char att[CMOR_MAX_STRING], d2 += d; sscanf(value, "%f", &d); if (d > d2) { - snprintf(value2, CMOR_MAX_STRING, - "Table %s is defined for cmor_version %f, " - "this library version is: %i.%i.%i, %f", - table->szTable_id, d, - CMOR_VERSION_MAJOR, CMOR_VERSION_MINOR, - CMOR_VERSION_PATCH, d2); - cmor_handle_error(value2, CMOR_CRITICAL); + cmor_handle_error_variadic( + "Table %s is defined for cmor_version %f, " + "this library version is: %i.%i.%i, %f", + CMOR_CRITICAL, + table->szTable_id, d, + CMOR_VERSION_MAJOR, CMOR_VERSION_MINOR, + CMOR_VERSION_PATCH, d2); cmor_ntables--; cmor_pop_traceback(); return (1); @@ -422,9 +422,10 @@ int cmor_set_dataset_att(cmor_table_t * table, char att[CMOR_MAX_STRING], } else if (strcmp(att, TABLE_HEADER_TABLE_ID) == 0) { for (n = 0; n == cmor_ntables; n++) { if (strcmp(cmor_tables[n].szTable_id, value) == 0) { - snprintf(value2, CMOR_MAX_STRING, - "Table %s is already defined", table->szTable_id); - cmor_handle_error(value2, CMOR_CRITICAL); + cmor_handle_error_variadic( + "Table %s is already defined", + CMOR_CRITICAL, + table->szTable_id); cmor_ntables--; cmor_pop_traceback(); return (1); @@ -449,10 +450,10 @@ int cmor_set_dataset_att(cmor_table_t * table, char att[CMOR_MAX_STRING], } else if (strcmp(att, TABLE_EXPIDS) == 0) { table->nexps++; if (table->nexps > CMOR_MAX_ELEMENTS) { - snprintf(value2, CMOR_MAX_STRING, - "Table %s: Too many experiments defined", - table->szTable_id); - cmor_handle_error(value2, CMOR_CRITICAL); + cmor_handle_error_variadic( + "Table %s: Too many experiments defined", + CMOR_CRITICAL, + table->szTable_id); cmor_ntables--; cmor_pop_traceback(); return (1); @@ -519,12 +520,12 @@ int cmor_set_dataset_att(cmor_table_t * table, char att[CMOR_MAX_STRING], } else { - snprintf(value, CMOR_MAX_STRING, - "table: %s, This keyword: %s value (%s) " - "is not a valid table header entry.!\n " - "Use the user input JSON file to add custom attributes.", - table->szTable_id, att, value); - cmor_handle_error(value, CMOR_WARNING); + cmor_handle_error_variadic( + "table: %s, This keyword: %s value (%s) " + "is not a valid table header entry.!\n " + "Use the user input JSON file to add custom attributes.", + CMOR_WARNING, + table->szTable_id, att, value); } cmor_pop_traceback(); return (0); @@ -537,18 +538,17 @@ int cmor_set_dataset_att(cmor_table_t * table, char att[CMOR_MAX_STRING], int cmor_set_table(int table) { extern int CMOR_TABLE; - char msg[CMOR_MAX_STRING]; cmor_add_traceback("cmor_set_table"); cmor_is_setup(); if (table > cmor_ntables) { - snprintf(msg, CMOR_MAX_STRING, "Invalid table number: %i", table); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic("Invalid table number: %i", CMOR_CRITICAL, table); } if (cmor_tables[table].szTable_id[0] == '\0') { - snprintf(msg, CMOR_MAX_STRING, "Invalid table: %i , not loaded yet!", - table); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "Invalid table: %i , not loaded yet!", + CMOR_CRITICAL, + table); } CMOR_TABLE = table; cmor_pop_traceback(); @@ -569,15 +569,15 @@ int cmor_load_table(char szTable[CMOR_MAX_STRING], int *table_id) char szCV[CMOR_MAX_STRING]; char szAxisEntryFN[CMOR_MAX_STRING]; char szFormulaVarFN[CMOR_MAX_STRING]; - char msg[CMOR_MAX_STRING]; struct stat st; cmor_add_traceback("cmor_load_table"); if (cmor_ntables == (CMOR_MAX_TABLES - 1)) { - snprintf(msg, CMOR_MAX_STRING, "You cannot load more than %d tables", - CMOR_MAX_TABLES); cmor_pop_traceback(); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "You cannot load more than %d tables", + CMOR_CRITICAL, + CMOR_MAX_TABLES); return (-1); } @@ -640,30 +640,34 @@ int cmor_load_table(char szTable[CMOR_MAX_STRING], int *table_id) szControlFilenameJSON, 1); rc = cmor_load_table_internal(szAxisEntryFilenameJSON, table_id); if (rc != TABLE_SUCCESS) { - snprintf(msg, CMOR_MAX_STRING, "Can't open/read JSON table %s", - szAxisEntryFilenameJSON); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "Can't open/read JSON table %s", + CMOR_CRITICAL, + szAxisEntryFilenameJSON); return (1); } rc = cmor_load_table_internal(szTable, table_id); if (rc != TABLE_SUCCESS) { - snprintf(msg, CMOR_MAX_STRING, "Can't open/read JSON table %s", - szTable); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "Can't open/read JSON table %s", + CMOR_CRITICAL, + szTable); return (1); } rc = cmor_load_table_internal(szFormulaVarFilenameJSON, table_id); if (rc != TABLE_SUCCESS) { - snprintf(msg, CMOR_MAX_STRING, "Can't open/read JSON table %s", - szFormulaVarFilenameJSON); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "Can't open/read JSON table %s", + CMOR_CRITICAL, + szFormulaVarFilenameJSON); return (1); } rc = cmor_load_table_internal(szControlFilenameJSON, table_id); if (rc != TABLE_SUCCESS) { - snprintf(msg, CMOR_MAX_STRING, "Can't open/read JSON table %s", - szControlFilenameJSON); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "Can't open/read JSON table %s", + CMOR_CRITICAL, + szControlFilenameJSON); return (1); } @@ -708,7 +712,6 @@ int cmor_load_table_internal(char szTable[CMOR_MAX_STRING], int *table_id) int done = 0; extern int CMOR_TABLE, cmor_ntables; extern char cmor_input_path[CMOR_MAX_STRING]; - char msg[CMOR_MAX_STRING]; char szVal[1024000]; char *buffer = NULL; int nTableSize, read_size; @@ -729,8 +732,10 @@ int cmor_load_table_internal(char szTable[CMOR_MAX_STRING], int *table_id) table_file = fopen(word, "r"); } if (table_file == NULL) { - snprintf(word, CMOR_MAX_STRING, "Could not find file: %s", szTable); - cmor_handle_error(word, CMOR_NORMAL); + cmor_handle_error_variadic( + "Could not find file: %s", + CMOR_NORMAL, + szTable); cmor_ntables -= 1; cmor_pop_traceback(); return (TABLE_ERROR); @@ -759,10 +764,10 @@ int cmor_load_table_internal(char szTable[CMOR_MAX_STRING], int *table_id) if (buffer[0] != '{') { free(buffer); buffer = NULL; - snprintf(msg, CMOR_MAX_STRING, - "Could not understand file \"%s\" Is this a JSON CMOR table?", - szTable); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "Could not understand file \"%s\" Is this a JSON CMOR table?", + CMOR_CRITICAL, + szTable); cmor_ntables--; cmor_pop_traceback(); return (TABLE_ERROR); @@ -773,9 +778,10 @@ int cmor_load_table_internal(char szTable[CMOR_MAX_STRING], int *table_id) if (nTableSize != read_size) { free(buffer); buffer = NULL; - snprintf(msg, CMOR_MAX_STRING, - "Could not read file %s check file permission", word); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "Could not read file %s check file permission", + CMOR_CRITICAL, + word); cmor_ntables--; cmor_pop_traceback(); return (TABLE_ERROR); @@ -786,11 +792,12 @@ int cmor_load_table_internal(char szTable[CMOR_MAX_STRING], int *table_id) /* -------------------------------------------------------------------- */ json_obj = json_tokener_parse(buffer); if (json_obj == NULL) { - snprintf(msg, CMOR_MAX_STRING, - "Please validate JSON File!\n" - "USE: http://jsonlint.com/\n" - "Syntax Error in table: %s\n " "%s", szTable, buffer); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "Please validate JSON File!\n" + "USE: http://jsonlint.com/\n" + "Syntax Error in table: %s\n " "%s", + CMOR_CRITICAL, + szTable, buffer); cmor_pop_traceback(); return (TABLE_ERROR); } @@ -799,10 +806,10 @@ int cmor_load_table_internal(char szTable[CMOR_MAX_STRING], int *table_id) /* check for null values in JSON */ /* -------------------------------------------------------------------- */ if(cmor_validate_json(json_obj) != 0) { - snprintf(msg, CMOR_MAX_STRING, - "There are invalid null values in table: %s", - szTable); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "There are invalid null values in table: %s", + CMOR_CRITICAL, + szTable); cmor_pop_traceback(); return (TABLE_ERROR); } @@ -918,10 +925,10 @@ int cmor_load_table_internal(char szTable[CMOR_MAX_STRING], int *table_id) /* -------------------------------------------------------------------- */ cmor_tables[cmor_ntables].nmappings++; if (cmor_tables[cmor_ntables].nmappings >= CMOR_MAX_ELEMENTS) { - snprintf(msg, CMOR_MAX_STRING, - "Too many mappings defined for table: %s", - cmor_tables[cmor_ntables].szTable_id); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "Too many mappings defined for table: %s", + CMOR_CRITICAL, + cmor_tables[cmor_ntables].szTable_id); cmor_ntables--; cmor_pop_traceback(); return (TABLE_ERROR); @@ -950,11 +957,11 @@ int cmor_load_table_internal(char szTable[CMOR_MAX_STRING], int *table_id) strcpy(szCurrMapID, psCurrCmorTable->mappings[n].id); if (strcmp(szLastMapID, szCurrMapID) == 0) { - snprintf(msg, CMOR_MAX_STRING, - "mapping: %s already defined within this table (%s)", - cmor_tables[cmor_ntables].mappings[n].id, - cmor_tables[cmor_ntables].szTable_id); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "mapping: %s already defined within this table (%s)", + CMOR_CRITICAL, + cmor_tables[cmor_ntables].mappings[n].id, + cmor_tables[cmor_ntables].szTable_id); }; } /* -------------------------------------------------------------------- */ @@ -989,10 +996,10 @@ int cmor_load_table_internal(char szTable[CMOR_MAX_STRING], int *table_id) /* nothing known we will not be setting any attributes! */ /* -------------------------------------------------------------------- */ - snprintf(msg, CMOR_MAX_STRING, - "unknown section: %s, for table: %s", key, - cmor_tables[cmor_ntables].szTable_id); - cmor_handle_error(msg, CMOR_WARNING); + cmor_handle_error_variadic( + "unknown section: %s, for table: %s", + CMOR_WARNING, + key, cmor_tables[cmor_ntables].szTable_id); } /* -------------------------------------------------------------------- */ @@ -1002,10 +1009,10 @@ int cmor_load_table_internal(char szTable[CMOR_MAX_STRING], int *table_id) if (done == 1) { done = 0; } else { - snprintf(msg, CMOR_MAX_STRING, - "attribute for unknown section: %s,%s (table: %s)", - key, szVal, cmor_tables[cmor_ntables].szTable_id); - cmor_handle_error(msg, CMOR_WARNING); + cmor_handle_error_variadic( + "attribute for unknown section: %s,%s (table: %s)", + CMOR_WARNING, + key, szVal, cmor_tables[cmor_ntables].szTable_id); /*printf("attribute for unknown section\n"); */ } } diff --git a/Src/cmor_variables.c b/Src/cmor_variables.c index 275cedd2..e98a7ecb 100644 --- a/Src/cmor_variables.c +++ b/Src/cmor_variables.c @@ -60,7 +60,6 @@ int cmor_has_required_variable_attributes(int var_id) { extern cmor_var_t cmor_vars[]; char astr[CMOR_MAX_STRING]; - char msg[CMOR_MAX_STRING]; int i, j; cmor_var_def_t var; cmor_table_t *pTable; @@ -90,12 +89,11 @@ int cmor_has_required_variable_attributes(int var_id) if (cmor_has_variable_attribute(var_id, astr) != 0) { - snprintf(msg, CMOR_MAX_STRING, - "variable %s (table %s) does not have required " - "attribute: %s", - cmor_vars[var_id].id, pTable->szTable_id, astr); - - cmor_handle_error_var(msg, CMOR_NORMAL, var_id); + cmor_handle_error_var_variadic( + "variable %s (table %s) does not have required " + "attribute: %s", + CMOR_NORMAL, var_id, + cmor_vars[var_id].id, pTable->szTable_id, astr); cmor_pop_traceback(); return (-1); } @@ -166,23 +164,24 @@ int cmor_set_variable_attribute_internal(int id, char *attribute_name, cmor_vars[id].attributes_values_num[index] = (double)*(long *)value; } else { - snprintf(msg, CMOR_MAX_STRING, - "unknown type %c for attribute %s of variable %s " - "(table %s),allowed types are c,i,l,f,d", type, - attribute_name, cmor_vars[id].id, - cmor_tables[cmor_vars[id].ref_table_id].szTable_id); - cmor_handle_error_var(msg, CMOR_NORMAL, id); + cmor_handle_error_var_variadic( + "unknown type %c for attribute %s of variable %s " + "(table %s),allowed types are c,i,l,f,d", + CMOR_NORMAL, id, + type, + attribute_name, cmor_vars[id].id, + cmor_tables[cmor_vars[id].ref_table_id].szTable_id); cmor_pop_traceback(); return (1); } if ((type != 'c') && (type != cmor_vars[id].type)) { - snprintf(msg, CMOR_MAX_STRING, - "Type '%c' for attribute '%s' of variable '%s' " - "does not match type variable '%c'", - type, attribute_name, - cmor_vars[id].id, cmor_vars[id].type); - cmor_handle_error_var(msg, CMOR_WARNING, id); + cmor_handle_error_var_variadic( + "Type '%c' for attribute '%s' of variable '%s' " + "does not match type variable '%c'", + CMOR_WARNING, id, + type, attribute_name, + cmor_vars[id].id, cmor_vars[id].type); } cmor_pop_traceback(); @@ -195,8 +194,6 @@ int cmor_set_variable_attribute_internal(int id, char *attribute_name, int cmor_set_variable_attribute(int id, char *attribute_name, char type, void *value) { - char msg[CMOR_MAX_STRING]; - cmor_add_traceback("cmor_set_variable_attribute"); /* -------------------------------------------------------------------- */ @@ -216,13 +213,13 @@ int cmor_set_variable_attribute(int id, char *attribute_name, char type, (strcmp(attribute_name, VARIABLE_ATT_ORIGINALUNITS) == 0) || (strcmp(attribute_name, VARIABLE_ATT_POSITIVE) == 0) || (strcmp(attribute_name, VARIABLE_ATT_CELLMETHODS) == 0)) { - snprintf(msg, CMOR_MAX_STRING, - "variable attribute %s (vor variable %s, table %s) must be " - "set via a call to cmor_variable or it is automatically set " - "via the tables", - attribute_name, cmor_vars[id].id, - cmor_tables[cmor_vars[id].ref_table_id].szTable_id); - cmor_handle_error_var(msg, CMOR_NORMAL, id); + cmor_handle_error_var_variadic( + "variable attribute %s (vor variable %s, table %s) must be " + "set via a call to cmor_variable or it is automatically set " + "via the tables", + CMOR_NORMAL, id, + attribute_name, cmor_vars[id].id, + cmor_tables[cmor_vars[id].ref_table_id].szTable_id); cmor_pop_traceback(); return (1); } @@ -231,14 +228,14 @@ int cmor_set_variable_attribute(int id, char *attribute_name, char type, /* has been initialized */ /* -------------------------------------------------------------------- */ if (cmor_vars[id].initialized != -1) { - snprintf(msg, CMOR_MAX_STRING, - "attribute %s on variable %s (table %s) will probably not be " - "set as the variable has already been created into the output " - "NetCDF file, please place this call BEFORE any cal to " - "cmor_write", - attribute_name, cmor_vars[id].id, - cmor_tables[cmor_vars[id].ref_table_id].szTable_id); - cmor_handle_error_var(msg, CMOR_NORMAL, id); + cmor_handle_error_var_variadic( + "attribute %s on variable %s (table %s) will probably not be " + "set as the variable has already been created into the output " + "NetCDF file, please place this call BEFORE any cal to " + "cmor_write", + CMOR_NORMAL, id, + attribute_name, cmor_vars[id].id, + cmor_tables[cmor_vars[id].ref_table_id].szTable_id); cmor_pop_traceback(); return (1); } @@ -254,7 +251,6 @@ int cmor_get_variable_attribute(int id, char *attribute_name, void *value) { extern cmor_var_t cmor_vars[]; int i, index; - char msg[CMOR_MAX_STRING]; char type; cmor_add_traceback("cmor_get_variable_attribute"); @@ -267,11 +263,11 @@ int cmor_get_variable_attribute(int id, char *attribute_name, void *value) } /* we found it */ } if (index == -1) { - snprintf(msg, CMOR_MAX_STRING, - "Attribute %s could not be found for variable %i (%s, table: %s)", - attribute_name, id, cmor_vars[id].id, - cmor_tables[cmor_vars[id].ref_table_id].szTable_id); - cmor_handle_error_var(msg, CMOR_NORMAL, id); + cmor_handle_error_var_variadic( + "Attribute %s could not be found for variable %i (%s, table: %s)", + CMOR_NORMAL, id, + attribute_name, id, cmor_vars[id].id, + cmor_tables[cmor_vars[id].ref_table_id].szTable_id); cmor_pop_traceback(); return (1); } @@ -357,7 +353,6 @@ int cmor_get_variable_attribute_type(int id, char *attribute_name, char *type) extern cmor_var_t cmor_vars[]; int i, index; - char msg[CMOR_MAX_STRING]; cmor_add_traceback("cmor_get_variable_attribute_type"); cmor_is_setup(); @@ -371,11 +366,11 @@ int cmor_get_variable_attribute_type(int id, char *attribute_name, char *type) } if (index == -1) { - snprintf(msg, CMOR_MAX_STRING, - "Attribute %s could not be found for variable %i (%s, table: %s)", - attribute_name, id, cmor_vars[id].id, - cmor_tables[cmor_vars[id].ref_table_id].szTable_id); - cmor_handle_error_var(msg, CMOR_NORMAL, id); + cmor_handle_error_var_variadic( + "Attribute %s could not be found for variable %i (%s, table: %s)", + CMOR_NORMAL, id, + attribute_name, id, cmor_vars[id].id, + cmor_tables[cmor_vars[id].ref_table_id].szTable_id); cmor_pop_traceback(); return (1); } @@ -440,14 +435,14 @@ int cmor_zfactor(int *zvar_id, int axis_id, char *name, char *units, } cmor_vars[var_id].values = malloc(n * sizeof(double)); if (cmor_vars[var_id].values == NULL) { - snprintf(msg, CMOR_MAX_STRING, - "cmor_zfactor: zaxis %s, cannot allocate " - "memory for %i double elts %s var '%s' (table: %s)", - cmor_axes[axis_id].id, n, cmor_vars[var_id].id, - cmor_vars[var_id].id, - cmor_tables[cmor_vars[var_id].ref_table_id]. - szTable_id); - cmor_handle_error_var(msg, CMOR_CRITICAL, var_id); + cmor_handle_error_var_variadic( + "cmor_zfactor: zaxis %s, cannot allocate " + "memory for %i double elts %s var '%s' (table: %s)", + CMOR_CRITICAL, var_id, + cmor_axes[axis_id].id, n, cmor_vars[var_id].id, + cmor_vars[var_id].id, + cmor_tables[cmor_vars[var_id].ref_table_id]. + szTable_id); } for (i = 0; i < n; i++) { @@ -469,14 +464,14 @@ int cmor_zfactor(int *zvar_id, int axis_id, char *name, char *units, cmor_units = ut_parse(ut_read, local_unit, UT_ASCII); if (ut_get_status() != UT_SUCCESS) { - snprintf(msg, CMOR_MAX_STRING, - "Udunits: Error parsing units: %s, zaxis: " - "%s, variable %s (table: %s)", - local_unit, cmor_axes[axis_id].id, - cmor_vars[var_id].id, - cmor_tables[cmor_vars[var_id].ref_table_id]. - szTable_id); - cmor_handle_error_var(msg, CMOR_CRITICAL, var_id); + cmor_handle_error_var_variadic( + "Udunits: Error parsing units: %s, zaxis: " + "%s, variable %s (table: %s)", + CMOR_CRITICAL, var_id, + local_unit, cmor_axes[axis_id].id, + cmor_vars[var_id].id, + cmor_tables[cmor_vars[var_id].ref_table_id]. + szTable_id); } strncpy(local_unit, units, CMOR_MAX_STRING); @@ -484,27 +479,27 @@ int cmor_zfactor(int *zvar_id, int axis_id, char *name, char *units, user_units = ut_parse(ut_read, local_unit, UT_ASCII); if (ut_get_status() != UT_SUCCESS) { - snprintf(msg, CMOR_MAX_STRING, + cmor_handle_error_var_variadic( "Udunits: Error parsing units: %s, zaxis %s, " "variable %s (table: %s)", + CMOR_CRITICAL, var_id, local_unit, cmor_axes[axis_id].id, cmor_vars[var_id].id, cmor_tables[cmor_vars[var_id].ref_table_id]. szTable_id); - cmor_handle_error_var(msg, CMOR_CRITICAL, var_id); } ut_cmor_converter = ut_get_converter(user_units, cmor_units); if (ut_get_status() != UT_SUCCESS) { - snprintf(msg, CMOR_MAX_STRING, - "Udunits: Error getting converter from %s to %s, " - "zaxis: %s, variable %s (table: %s)", - units, cmor_vars[var_id].ounits, - cmor_axes[axis_id].id, cmor_vars[var_id].id, - cmor_tables[cmor_vars[var_id].ref_table_id]. - szTable_id); - cmor_handle_error_var(msg, CMOR_CRITICAL, var_id); + cmor_handle_error_var_variadic( + "Udunits: Error getting converter from %s to %s, " + "zaxis: %s, variable %s (table: %s)", + CMOR_CRITICAL, var_id, + units, cmor_vars[var_id].ounits, + cmor_axes[axis_id].id, cmor_vars[var_id].id, + cmor_tables[cmor_vars[var_id].ref_table_id]. + szTable_id); } cv_convert_doubles(ut_cmor_converter, @@ -512,45 +507,45 @@ int cmor_zfactor(int *zvar_id, int axis_id, char *name, char *units, &cmor_vars[var_id].values[0]); if (ut_get_status() != UT_SUCCESS) { - snprintf(msg, CMOR_MAX_STRING, - "Udunits: Error with converter (from %s to %s), zaxis: %s, variable %s (table: %s)", - units, cmor_vars[var_id].ounits, - cmor_axes[axis_id].id, cmor_vars[var_id].id, - cmor_tables[cmor_vars[var_id].ref_table_id]. - szTable_id); - cmor_handle_error_var(msg, CMOR_CRITICAL, var_id); + cmor_handle_error_var_variadic( + "Udunits: Error with converter (from %s to %s), zaxis: %s, variable %s (table: %s)", + CMOR_CRITICAL, var_id, + units, cmor_vars[var_id].ounits, + cmor_axes[axis_id].id, cmor_vars[var_id].id, + cmor_tables[cmor_vars[var_id].ref_table_id]. + szTable_id); } cv_free(ut_cmor_converter); if (ut_get_status() != UT_SUCCESS) { - snprintf(msg, CMOR_MAX_STRING, - "Udunits: Error freeing converter, zaxis %s, variable %s (table: %s)", - cmor_axes[axis_id].id, cmor_vars[var_id].id, - cmor_tables[cmor_vars[var_id].ref_table_id]. - szTable_id); - cmor_handle_error_var(msg, CMOR_CRITICAL, var_id); + cmor_handle_error_var_variadic( + "Udunits: Error freeing converter, zaxis %s, variable %s (table: %s)", + CMOR_CRITICAL, var_id, + cmor_axes[axis_id].id, cmor_vars[var_id].id, + cmor_tables[cmor_vars[var_id].ref_table_id]. + szTable_id); } ut_free(cmor_units); if (ut_get_status() != UT_SUCCESS) { - snprintf(msg, CMOR_MAX_STRING, - "Udunits: Error freeing units %s, zaxis %s, variable %s (table: %s)", - cmor_vars[var_id].ounits, cmor_axes[axis_id].id, - cmor_vars[var_id].id, - cmor_tables[cmor_vars[var_id].ref_table_id]. - szTable_id); - cmor_handle_error_var(msg, CMOR_CRITICAL, var_id); + cmor_handle_error_var_variadic( + "Udunits: Error freeing units %s, zaxis %s, variable %s (table: %s)", + CMOR_CRITICAL, var_id, + cmor_vars[var_id].ounits, cmor_axes[axis_id].id, + cmor_vars[var_id].id, + cmor_tables[cmor_vars[var_id].ref_table_id]. + szTable_id); } ut_free(user_units); if (ut_get_status() != UT_SUCCESS) { - snprintf(msg, CMOR_MAX_STRING, - "Udunits: Error freeing units %s, zaxis %s,variable %s (table: %s)", - units, cmor_axes[axis_id].id, - cmor_vars[var_id].id, - cmor_tables[cmor_vars[var_id].ref_table_id]. - szTable_id); - cmor_handle_error_var(msg, CMOR_CRITICAL, var_id); + cmor_handle_error_var_variadic( + "Udunits: Error freeing units %s, zaxis %s,variable %s (table: %s)", + CMOR_CRITICAL, var_id, + units, cmor_axes[axis_id].id, + cmor_vars[var_id].id, + cmor_tables[cmor_vars[var_id].ref_table_id]. + szTable_id); } cmor_vars[var_id].itype = 'd'; @@ -577,27 +572,27 @@ int cmor_zfactor(int *zvar_id, int axis_id, char *name, char *units, } if (k == 0) { - snprintf(msg, CMOR_MAX_STRING, - "zfactor: axis %s, variable %s (table %s), is " - "not time dependent and you did not provide " - "any values", - cmor_axes[axis_id].id, name, - cmor_tables[cmor_vars[var_id].ref_table_id]. - szTable_id); - cmor_handle_error_var(msg, CMOR_CRITICAL, var_id); + cmor_handle_error_var_variadic( + "zfactor: axis %s, variable %s (table %s), is " + "not time dependent and you did not provide " + "any values", + CMOR_CRITICAL, var_id, + cmor_axes[axis_id].id, name, + cmor_tables[cmor_vars[var_id].ref_table_id]. + szTable_id); } *zvar_id = var_id; } if (bounds != NULL) { if (ndims != 1) { - snprintf(msg, CMOR_MAX_STRING, - "zfactor axis %s, variable %s (table: %s): you " - "passed bounds values but you also declared %i " - "dimensions, we will ignore you bounds", - cmor_axes[axis_id].id, name, - cmor_tables[cmor_vars[var_id].ref_table_id].szTable_id, - ndims); - cmor_handle_error(msg, CMOR_WARNING); + cmor_handle_error_variadic( + "zfactor axis %s, variable %s (table: %s): you " + "passed bounds values but you also declared %i " + "dimensions, we will ignore you bounds", + CMOR_WARNING, + cmor_axes[axis_id].id, name, + cmor_tables[cmor_vars[var_id].ref_table_id].szTable_id, + ndims); } else { strncpy(msg, name, CMOR_MAX_STRING); strncat(msg, "_bnds", CMOR_MAX_STRING - strlen(msg)); @@ -608,15 +603,15 @@ int cmor_zfactor(int *zvar_id, int axis_id, char *name, char *units, n = cmor_axes[axes_ids[0]].length; cmor_vars[var_id].values = malloc(2 * n * sizeof(double)); if (cmor_vars[var_id].values == NULL) { - snprintf(msg, CMOR_MAX_STRING, - "cmor_zfactor: zaxis %s, cannot allocate " - "memory for %i double bounds elts %s var '%s' " - "(table: %s)", - cmor_axes[axis_id].id, 2 * n, - cmor_vars[var_id].id, cmor_vars[var_id].id, - cmor_tables[cmor_vars[var_id].ref_table_id]. - szTable_id); - cmor_handle_error_var(msg, CMOR_CRITICAL, var_id); + cmor_handle_error_var_variadic( + "cmor_zfactor: zaxis %s, cannot allocate " + "memory for %i double bounds elts %s var '%s' " + "(table: %s)", + CMOR_CRITICAL, var_id, + cmor_axes[axis_id].id, 2 * n, + cmor_vars[var_id].id, cmor_vars[var_id].id, + cmor_tables[cmor_vars[var_id].ref_table_id]. + szTable_id); } cmor_vars[var_id].isbounds = 1; @@ -656,14 +651,13 @@ int cmor_zfactor(int *zvar_id, int axis_id, char *name, char *units, cmor_units = ut_parse(ut_read, local_unit, UT_ASCII); if (ut_get_status() != UT_SUCCESS) { - snprintf(msg, CMOR_MAX_STRING, - "Udunits: Error parsing units: %s, for zaxis %s, variable %s (table: %s)", - local_unit, cmor_axes[axis_id].id, - cmor_vars[var_id].id, - cmor_tables[cmor_vars[var_id].ref_table_id]. - szTable_id); - - cmor_handle_error_var(msg, CMOR_CRITICAL, var_id); + cmor_handle_error_var_variadic( + "Udunits: Error parsing units: %s, for zaxis %s, variable %s (table: %s)", + CMOR_CRITICAL, var_id, + local_unit, cmor_axes[axis_id].id, + cmor_vars[var_id].id, + cmor_tables[cmor_vars[var_id].ref_table_id]. + szTable_id); } @@ -673,26 +667,26 @@ int cmor_zfactor(int *zvar_id, int axis_id, char *name, char *units, user_units = ut_parse(ut_read, local_unit, UT_ASCII); if (ut_get_status() != UT_SUCCESS) { - snprintf(msg, CMOR_MAX_STRING, - "Udunits: Error parsing units: %s, zaxis %s, variable %s (table: %s)", - local_unit, cmor_axes[axis_id].id, - cmor_vars[var_id].id, - cmor_tables[cmor_vars[var_id].ref_table_id]. - szTable_id); - cmor_handle_error_var(msg, CMOR_CRITICAL, var_id); + cmor_handle_error_var_variadic( + "Udunits: Error parsing units: %s, zaxis %s, variable %s (table: %s)", + CMOR_CRITICAL, var_id, + local_unit, cmor_axes[axis_id].id, + cmor_vars[var_id].id, + cmor_tables[cmor_vars[var_id].ref_table_id]. + szTable_id); } ut_cmor_converter = ut_get_converter(user_units, cmor_units); if (ut_get_status() != UT_SUCCESS) { - snprintf(msg, CMOR_MAX_STRING, - "Udunits: Error getting converter from %s to %s, zaxis %s, variable %s (table: %s)", - units, cmor_vars[var_id].ounits, - cmor_axes[axis_id].id, cmor_vars[var_id].id, - cmor_tables[cmor_vars[var_id].ref_table_id]. - szTable_id); - cmor_handle_error_var(msg, CMOR_CRITICAL, var_id); + cmor_handle_error_var_variadic( + "Udunits: Error getting converter from %s to %s, zaxis %s, variable %s (table: %s)", + CMOR_CRITICAL, var_id, + units, cmor_vars[var_id].ounits, + cmor_axes[axis_id].id, cmor_vars[var_id].id, + cmor_tables[cmor_vars[var_id].ref_table_id]. + szTable_id); } cv_convert_doubles(ut_cmor_converter, @@ -701,13 +695,13 @@ int cmor_zfactor(int *zvar_id, int axis_id, char *name, char *units, if (ut_get_status() != UT_SUCCESS) { - snprintf(msg, CMOR_MAX_STRING, - "Udunits: Error converting units from %s to %s, zaxis %s, variable %s (table: %s)", - units, cmor_vars[var_id].ounits, - cmor_axes[axis_id].id, cmor_vars[var_id].id, - cmor_tables[cmor_vars[var_id].ref_table_id]. - szTable_id); - cmor_handle_error_var(msg, CMOR_CRITICAL, var_id); + cmor_handle_error_var_variadic( + "Udunits: Error converting units from %s to %s, zaxis %s, variable %s (table: %s)", + CMOR_CRITICAL, var_id, + units, cmor_vars[var_id].ounits, + cmor_axes[axis_id].id, cmor_vars[var_id].id, + cmor_tables[cmor_vars[var_id].ref_table_id]. + szTable_id); } @@ -715,13 +709,13 @@ int cmor_zfactor(int *zvar_id, int axis_id, char *name, char *units, if (ut_get_status() != UT_SUCCESS) { - snprintf(msg, CMOR_MAX_STRING, - "Udunits: Error freeing converter, zaxis %s, " - "variable %s (table: %s)", - cmor_axes[axis_id].id, cmor_vars[var_id].id, - cmor_tables[cmor_vars[var_id].ref_table_id]. - szTable_id); - cmor_handle_error_var(msg, CMOR_CRITICAL, var_id); + cmor_handle_error_var_variadic( + "Udunits: Error freeing converter, zaxis %s, " + "variable %s (table: %s)", + CMOR_CRITICAL, var_id, + cmor_axes[axis_id].id, cmor_vars[var_id].id, + cmor_tables[cmor_vars[var_id].ref_table_id]. + szTable_id); } @@ -729,14 +723,14 @@ int cmor_zfactor(int *zvar_id, int axis_id, char *name, char *units, if (ut_get_status() != UT_SUCCESS) { - snprintf(msg, CMOR_MAX_STRING, - "Udunits: Error freeing cmor units %s, zaxis " - "%s, variable %s (table: %s)", - cmor_vars[var_id].ounits, - cmor_axes[axis_id].id, cmor_vars[var_id].id, - cmor_tables[cmor_vars[var_id].ref_table_id]. - szTable_id); - cmor_handle_error_var(msg, CMOR_CRITICAL, var_id); + cmor_handle_error_var_variadic( + "Udunits: Error freeing cmor units %s, zaxis " + "%s, variable %s (table: %s)", + CMOR_CRITICAL, var_id, + cmor_vars[var_id].ounits, + cmor_axes[axis_id].id, cmor_vars[var_id].id, + cmor_tables[cmor_vars[var_id].ref_table_id]. + szTable_id); } @@ -744,14 +738,14 @@ int cmor_zfactor(int *zvar_id, int axis_id, char *name, char *units, if (ut_get_status() != UT_SUCCESS) { - snprintf(msg, CMOR_MAX_STRING, - "Udunits: Error freeing units %s, zaxis %s, " - "variable %s (table: %s)", - units, cmor_axes[axis_id].id, - cmor_vars[var_id].id, - cmor_tables[cmor_vars[var_id].ref_table_id]. - szTable_id); - cmor_handle_error_var(msg, CMOR_CRITICAL, var_id); + cmor_handle_error_var_variadic( + "Udunits: Error freeing units %s, zaxis %s, " + "variable %s (table: %s)", + CMOR_CRITICAL, var_id, + units, cmor_axes[axis_id].id, + cmor_vars[var_id].id, + cmor_tables[cmor_vars[var_id].ref_table_id]. + szTable_id); } @@ -787,88 +781,88 @@ int cmor_zfactor(int *zvar_id, int axis_id, char *name, char *units, user_units = ut_parse(ut_read, local_unit, UT_ASCII); if (ut_get_status() != UT_SUCCESS) { - snprintf(msg, CMOR_MAX_STRING, - "Udunits: Error parsing user units: %s, " - "zaxis %s (table: %s), when creating " - "zfactor: %s", - local_unit, cmor_axes[axis_id].id, - cmor_tables[cmor_axes[axis_id].ref_table_id]. - szTable_id, name); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "Udunits: Error parsing user units: %s, " + "zaxis %s (table: %s), when creating " + "zfactor: %s", + CMOR_CRITICAL, + local_unit, cmor_axes[axis_id].id, + cmor_tables[cmor_axes[axis_id].ref_table_id]. + szTable_id, name); } if (ut_are_convertible(cmor_units, user_units) == 0) { - snprintf(msg, CMOR_MAX_STRING, - "Udunuits: Pa and user units (%s) are " - "incompatible, zaxis %s (table: %s), when " - "creating zfactor: %s", - units, cmor_axes[axis_id].id, - cmor_tables[cmor_axes[axis_id].ref_table_id]. - szTable_id, name); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "Udunuits: Pa and user units (%s) are " + "incompatible, zaxis %s (table: %s), when " + "creating zfactor: %s", + CMOR_CRITICAL, + units, cmor_axes[axis_id].id, + cmor_tables[cmor_axes[axis_id].ref_table_id]. + szTable_id, name); cmor_pop_traceback(); return (1); } ut_cmor_converter = ut_get_converter(cmor_units, user_units); if (ut_get_status() != UT_SUCCESS) { - snprintf(msg, CMOR_MAX_STRING, - "Udunits: Error getting converter from Pa " - "to %s,variable %s (table %s), when creating " - "zfactor: %s", - units, cmor_axes[axis_id].id, - cmor_tables[cmor_axes[axis_id].ref_table_id]. - szTable_id, name); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "Udunits: Error getting converter from Pa " + "to %s,variable %s (table %s), when creating " + "zfactor: %s", + CMOR_CRITICAL, + units, cmor_axes[axis_id].id, + cmor_tables[cmor_axes[axis_id].ref_table_id]. + szTable_id, name); } tmp = (double)1.e5; tmp = cv_convert_double(ut_cmor_converter, tmp); /* free units thing */ if (ut_get_status() != UT_SUCCESS) { - snprintf(msg, CMOR_MAX_STRING, - "Udunits: Error converting units from Pa " - "to %s, zaxis %s (table: %s), when creating " - "zfactor: %s", - local_unit, cmor_axes[axis_id].id, - cmor_tables[cmor_axes[axis_id].ref_table_id]. - szTable_id, name); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "Udunits: Error converting units from Pa " + "to %s, zaxis %s (table: %s), when creating " + "zfactor: %s", + CMOR_CRITICAL, + local_unit, cmor_axes[axis_id].id, + cmor_tables[cmor_axes[axis_id].ref_table_id]. + szTable_id, name); } cv_free(ut_cmor_converter); if (ut_get_status() != UT_SUCCESS) { - snprintf(msg, CMOR_MAX_STRING, - "Udunits: Error freeing converter, zaxis %s " - "(table: %s), when creating zfactor: %s", - cmor_axes[axis_id].id, - cmor_tables[cmor_axes[axis_id].ref_table_id]. - szTable_id, name); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "Udunits: Error freeing converter, zaxis %s " + "(table: %s), when creating zfactor: %s", + CMOR_CRITICAL, + cmor_axes[axis_id].id, + cmor_tables[cmor_axes[axis_id].ref_table_id]. + szTable_id, name); } ut_free(cmor_units); if (ut_get_status() != UT_SUCCESS) { - snprintf(msg, CMOR_MAX_STRING, - "Udunits: Error freeing units Pa, zaxis: %s " - "(table: %s), when creating zfactor: %s", - cmor_axes[axis_id].id, - cmor_tables[cmor_axes[axis_id].ref_table_id]. - szTable_id, name); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "Udunits: Error freeing units Pa, zaxis: %s " + "(table: %s), when creating zfactor: %s", + CMOR_CRITICAL, + cmor_axes[axis_id].id, + cmor_tables[cmor_axes[axis_id].ref_table_id]. + szTable_id, name); } ut_free(user_units); if (ut_get_status() != UT_SUCCESS) { - snprintf(msg, CMOR_MAX_STRING, - "Udunits: Error freeing units %s, zaxis %s " - "(table: %s), when creating zfactor: %s", - local_unit, cmor_axes[axis_id].id, - cmor_tables[cmor_axes[axis_id].ref_table_id]. - szTable_id, name); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "Udunits: Error freeing units %s, zaxis %s " + "(table: %s), when creating zfactor: %s", + CMOR_CRITICAL, + local_unit, cmor_axes[axis_id].id, + cmor_tables[cmor_axes[axis_id].ref_table_id]. + szTable_id, name); } @@ -910,14 +904,14 @@ int cmor_zfactor(int *zvar_id, int axis_id, char *name, char *units, } if (j == -1) { /* we did not find the ztop! */ - snprintf(msg, CMOR_MAX_STRING, - "zfactor variable \"ptop\" for zfactor axis: " - "%i (%s, table: %s), is not defined when " - "creating zfactor %s, please define ptop first", - axis_id, cmor_axes[axis_id].id, - cmor_tables[cmor_axes[axis_id].ref_table_id]. - szTable_id, name); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "zfactor variable \"ptop\" for zfactor axis: " + "%i (%s, table: %s), is not defined when " + "creating zfactor %s, please define ptop first", + CMOR_CRITICAL, + axis_id, cmor_axes[axis_id].id, + cmor_tables[cmor_axes[axis_id].ref_table_id]. + szTable_id, name); } tmp = (double)1.e5; @@ -1086,9 +1080,8 @@ int cmor_variable(int *var_id, char *name, char *units, int ndims, } if (iref == -1) { - snprintf(msg, CMOR_MAX_STRING, - "Could not find a matching variable for name: '%s'", ctmp); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "Could not find a matching variable for name: '%s'", CMOR_CRITICAL, ctmp); } if (iref > CMOR_MAX_ELEMENTS) { @@ -1164,11 +1157,11 @@ int cmor_variable(int *var_id, char *name, char *units, int ndims, cmor_set_variable_attribute_internal(vrid, VARIABLE_ATT_LONGNAME, 'c', refvar.long_name); - if ((refvar.flag_values != NULL) && (refvar.flag_values[0] != '\0')) { + if (refvar.flag_values[0] != '\0') { cmor_set_variable_attribute_internal(vrid, VARIABLE_ATT_FLAGVALUES, 'c', refvar.flag_values); } - if ((refvar.flag_meanings != NULL) && (refvar.flag_meanings[0] != '\0')) { + if (refvar.flag_meanings[0] != '\0') { cmor_set_variable_attribute_internal(vrid, VARIABLE_ATT_FLAGMEANINGS, 'c', refvar.flag_meanings); @@ -1242,14 +1235,14 @@ int cmor_variable(int *var_id, char *name, char *units, int ndims, if ((positive != NULL) && (positive[0] != '\0')) { if ((positive[0] != 'd') && positive[0] != 'u') { - snprintf(msg, CMOR_MAX_STRING, - "variable '%s' (table %s): unknown value for " - "positive : %s (only first character is considered, " - "which was: %c)", - cmor_vars[vrid].id, - cmor_tables[cmor_vars[vrid].ref_table_id].szTable_id, - positive, positive[0]); - cmor_handle_error_var(msg, CMOR_CRITICAL, vrid); + cmor_handle_error_var_variadic( + "variable '%s' (table %s): unknown value for " + "positive : %s (only first character is considered, " + "which was: %c)", + CMOR_CRITICAL, vrid, + cmor_vars[vrid].id, + cmor_tables[cmor_vars[vrid].ref_table_id].szTable_id, + positive, positive[0]); } if (refvar.positive == 'u') { @@ -1283,25 +1276,26 @@ int cmor_variable(int *var_id, char *name, char *units, int ndims, cmor_update_history(vrid, "Changed sign"); } } else { - snprintf(msg, CMOR_MAX_STRING, - "variable '%s' (table %s) you passed positive " - "value:%s, but table does not mention it, will " - "be ignored, if you really want this in your " - "variable output use " - "cmor_set_variable_attribute_internal function", - cmor_vars[vrid].id, - cmor_tables[cmor_vars[vrid].ref_table_id].szTable_id, - positive); - cmor_handle_error(msg, CMOR_WARNING); + cmor_handle_error_variadic( + "variable '%s' (table %s) you passed positive " + "value:%s, but table does not mention it, will " + "be ignored, if you really want this in your " + "variable output use " + "cmor_set_variable_attribute_internal function", + CMOR_WARNING, + cmor_vars[vrid].id, + cmor_tables[cmor_vars[vrid].ref_table_id].szTable_id, + positive); } } else { if (cmor_is_required_variable_attribute(refvar, VARIABLE_ATT_POSITIVE) == 0) { - snprintf(msg, CMOR_MAX_STRING, - "you need to provide the 'positive' argument for " - "variable: %s (table %s)", cmor_vars[vrid].id, - cmor_tables[cmor_vars[vrid].ref_table_id].szTable_id); - cmor_handle_error_var(msg, CMOR_CRITICAL, vrid); + cmor_handle_error_var_variadic( + "you need to provide the 'positive' argument for " + "variable: %s (table %s)", + CMOR_CRITICAL, vrid, + cmor_vars[vrid].id, + cmor_tables[cmor_vars[vrid].ref_table_id].szTable_id); } if (refvar.positive != '\0') { if (refvar.positive == 'u') { @@ -1313,11 +1307,12 @@ int cmor_variable(int *var_id, char *name, char *units, int ndims, 'c', "up"); } - snprintf(msg, CMOR_MAX_STRING, - "you did not provide the 'positive' argument " - "for variable: %s (table %s)", - cmor_vars[vrid].id, - cmor_tables[cmor_vars[vrid].ref_table_id].szTable_id); + cmor_handle_error_var_variadic( + "you did not provide the 'positive' argument " + "for variable: %s (table %s)", + CMOR_CRITICAL, vrid, + cmor_vars[vrid].id, + cmor_tables[cmor_vars[vrid].ref_table_id].szTable_id); } else if (refvar.positive == 'd') { @@ -1328,12 +1323,12 @@ int cmor_variable(int *var_id, char *name, char *units, int ndims, VARIABLE_ATT_POSITIVE, 'c', "down"); } - snprintf(msg, CMOR_MAX_STRING, - "you did not provide the 'positive' argument for variable: %s (table %s)", - cmor_vars[vrid].id, - cmor_tables[cmor_vars[vrid].ref_table_id].szTable_id); + cmor_handle_error_var_variadic( + "you did not provide the 'positive' argument for variable: %s (table %s)", + CMOR_CRITICAL, vrid, + cmor_vars[vrid].id, + cmor_tables[cmor_vars[vrid].ref_table_id].szTable_id); } - cmor_handle_error_var(msg, CMOR_CRITICAL, vrid); } } /* -------------------------------------------------------------------- */ @@ -1381,12 +1376,12 @@ int cmor_variable(int *var_id, char *name, char *units, int ndims, } } if (j == 0) { - sprintf(msg, - "Variable %s (table %s) must be defined using a " - "grid (a call to cmor_grid)", - cmor_vars[vrid].id, - cmor_tables[cmor_vars[vrid].ref_table_id].szTable_id); - cmor_handle_error_var(msg, CMOR_CRITICAL, vrid); + cmor_handle_error_var_variadic( + "Variable %s (table %s) must be defined using a " + "grid (a call to cmor_grid)", + CMOR_CRITICAL, vrid, + cmor_vars[vrid].id, + cmor_tables[cmor_vars[vrid].ref_table_id].szTable_id); } } @@ -1402,24 +1397,24 @@ int cmor_variable(int *var_id, char *name, char *units, int ndims, /* -------------------------------------------------------------------- */ for (i = 0; i < ndims; i++) { if (laxes_ids[i] > cmor_naxes) { - sprintf(msg, - "For variable %s (table %s) you requested axis_id " - "(%i) that has not been defined yet", - cmor_vars[vrid].id, - cmor_tables[cmor_vars[vrid].ref_table_id].szTable_id, - laxes_ids[i]); - cmor_handle_error_var(msg, CMOR_CRITICAL, vrid); + cmor_handle_error_var_variadic( + "For variable %s (table %s) you requested axis_id " + "(%i) that has not been defined yet", + CMOR_CRITICAL, vrid, + cmor_vars[vrid].id, + cmor_tables[cmor_vars[vrid].ref_table_id].szTable_id, + laxes_ids[i]); } if (laxes_ids[i] < -CMOR_MAX_GRIDS + 1) { grid_id = -laxes_ids[i] - CMOR_MAX_GRIDS; if (grid_id > cmor_ngrids) { - sprintf(msg, - "For variable %s (table: %s) you requested " - "grid_id (%i) that has not been defined yet", - cmor_vars[vrid].id, - cmor_tables[cmor_vars[vrid].ref_table_id].szTable_id, - laxes_ids[i]); - cmor_handle_error_var(msg, CMOR_CRITICAL, vrid); + cmor_handle_error_var_variadic( + "For variable %s (table: %s) you requested " + "grid_id (%i) that has not been defined yet", + CMOR_CRITICAL, vrid, + cmor_vars[vrid].id, + cmor_tables[cmor_vars[vrid].ref_table_id].szTable_id, + laxes_ids[i]); } /* -------------------------------------------------------------------- */ /* here we need to know if the refvar has been defined with */ @@ -1539,13 +1534,13 @@ int cmor_variable(int *var_id, char *name, char *units, int ndims, } if ((j != 0) && (j != -1)) { - snprintf(msg, CMOR_MAX_STRING, - "You are defining variable '%s' (table %s) with %i " - "dimensions, when it should have %i", - name, - cmor_tables[cmor_vars[vrid].ref_table_id].szTable_id, - ndims, refvar.ndims); - cmor_handle_error_var(msg, CMOR_CRITICAL, vrid); + cmor_handle_error_var_variadic( + "You are defining variable '%s' (table %s) with %i " + "dimensions, when it should have %i", + CMOR_CRITICAL, vrid, + name, + cmor_tables[cmor_vars[vrid].ref_table_id].szTable_id, + ndims, refvar.ndims); cmor_pop_traceback(); return (1); } else { @@ -1597,19 +1592,19 @@ int cmor_variable(int *var_id, char *name, char *units, int ndims, (cmor_tables[cmor_axes[laxes_ids[i]].ref_table_id].axes [cmor_axes[laxes_ids[i]].ref_axis_id].generic_level_name[0] != '\0') ) { - snprintf(msg, CMOR_MAX_STRING, - "You defined variable '%s' (table %s) with axis " - "id '%s', the variable calls for a generic axis of type '%s' " - "according to your table, the axis you are providing is of generic type '%s'", - refvar.id, - cmor_tables[cmor_vars[vrid].ref_table_id].szTable_id, - cmor_tables[cmor_axes[laxes_ids[i]].ref_table_id]. - axes[cmor_axes[laxes_ids[i]].ref_axis_id].id, - refvar.generic_level_name, - cmor_tables[cmor_axes[laxes_ids[i]].ref_table_id].axes - [cmor_axes[laxes_ids[i]].ref_axis_id].generic_level_name - ); - cmor_handle_error_var(msg, CMOR_CRITICAL, vrid); + cmor_handle_error_var_variadic( + "You defined variable '%s' (table %s) with axis " + "id '%s', the variable calls for a generic axis of type '%s' " + "according to your table, the axis you are providing is of generic type '%s'", + CMOR_CRITICAL, vrid, + refvar.id, + cmor_tables[cmor_vars[vrid].ref_table_id].szTable_id, + cmor_tables[cmor_axes[laxes_ids[i]].ref_table_id]. + axes[cmor_axes[laxes_ids[i]].ref_axis_id].id, + refvar.generic_level_name, + cmor_tables[cmor_axes[laxes_ids[i]].ref_table_id].axes + [cmor_axes[laxes_ids[i]].ref_axis_id].generic_level_name + ); } } } @@ -1650,25 +1645,24 @@ int cmor_variable(int *var_id, char *name, char *units, int ndims, for (i = 0; i < lndims; i++) { if (laxes_ids[i] > cmor_naxes) { - snprintf(msg, CMOR_MAX_STRING, "Axis %i not defined", axes_ids[i]); - cmor_handle_error_var(msg, CMOR_CRITICAL, vrid); + cmor_handle_error_var_variadic("Axis %i not defined", CMOR_CRITICAL, vrid, axes_ids[i]); cmor_pop_traceback(); return (1); } if (cmor_axes[laxes_ids[i]].ref_table_id != CMOR_TABLE && cmor_axes[laxes_ids[i]].isgridaxis != 1) { - snprintf(msg, CMOR_MAX_STRING, - "While creating variable %s, you are " - "passing axis %i (named %s) which has been " - "defined using table %i (%s) but the current " - "table is %i (%s) (and isgridaxis says: %i)", - cmor_vars[vrid].id, laxes_ids[i], - cmor_axes[laxes_ids[i]].id, - cmor_axes[laxes_ids[i]].ref_table_id, - cmor_tables[cmor_axes[laxes_ids[i]].ref_table_id]. - szTable_id, CMOR_TABLE, cmor_tables[CMOR_TABLE].szTable_id, - cmor_axes[laxes_ids[i]].isgridaxis); - cmor_handle_error_var(msg, CMOR_CRITICAL, vrid); + cmor_handle_error_var_variadic( + "While creating variable %s, you are " + "passing axis %i (named %s) which has been " + "defined using table %i (%s) but the current " + "table is %i (%s) (and isgridaxis says: %i)", + CMOR_CRITICAL, vrid, + cmor_vars[vrid].id, laxes_ids[i], + cmor_axes[laxes_ids[i]].id, + cmor_axes[laxes_ids[i]].ref_table_id, + cmor_tables[cmor_axes[laxes_ids[i]].ref_table_id]. + szTable_id, CMOR_TABLE, cmor_tables[CMOR_TABLE].szTable_id, + cmor_axes[laxes_ids[i]].isgridaxis); } if (cmor_tables[cmor_axes[laxes_ids[i]].ref_table_id].axes [cmor_axes[laxes_ids[i]].ref_axis_id].value != 1.e20) { @@ -1915,12 +1909,10 @@ void cmor_init_var_def(cmor_var_def_t * var, int table_id) /* cmor_set_var_def_att() */ /************************************************************************/ -int cmor_set_var_def_att(cmor_var_def_t * var, char att[CMOR_MAX_STRING], - char val[CMOR_MAX_STRING]) +int cmor_set_var_def_att(cmor_var_def_t * var, char *att, char *val) { int i, n, j, n0, k; char dim[CMOR_MAX_STRING]; - char msg[CMOR_MAX_STRING]; cmor_add_traceback("cmor_set_var_def_att"); cmor_is_setup(); @@ -1963,11 +1955,12 @@ int cmor_set_var_def_att(cmor_var_def_t * var, char att[CMOR_MAX_STRING], dim[j] = '\0'; if (var->ndims > CMOR_MAX_DIMENSIONS) { - snprintf(msg, CMOR_MAX_STRING, - "Too many dimensions (%i) defined for variable " - "(%s), max is: %i", var->ndims, var->id, - CMOR_MAX_DIMENSIONS); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "Too many dimensions (%i) defined for variable " + "(%s), max is: %i", + CMOR_CRITICAL, + var->ndims, var->id, + CMOR_MAX_DIMENSIONS); } /* -------------------------------------------------------------------- */ @@ -2013,14 +2006,14 @@ int cmor_set_var_def_att(cmor_var_def_t * var, char att[CMOR_MAX_STRING], /* "latitude" it is probably a grid variable */ /* -------------------------------------------------------------------- */ - snprintf(msg, CMOR_MAX_STRING, - "Reading table %s: axis name: '%s' for " - "variable: '%s' is not defined in table. " - "Table defines dimensions: '%s' for this " - "variable", - cmor_tables[var->table_id].szTable_id, dim, - var->id, val); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "Reading table %s: axis name: '%s' for " + "variable: '%s' is not defined in table. " + "Table defines dimensions: '%s' for this " + "variable", + CMOR_CRITICAL, + cmor_tables[var->table_id].szTable_id, dim, + var->id, val); } else { var->dimensions[var->ndims] = -CMOR_MAX_GRIDS; } @@ -2099,22 +2092,21 @@ int cmor_set_var_def_att(cmor_var_def_t * var, char att[CMOR_MAX_STRING], if (atoi(val) != 0) { if (USE_NETCDF_4 == 0) { - sprintf(msg, - "Reading a table (%s) that calls for NetCDF4 " - "features, you are using NetCDF3 library", - cmor_tables[var->table_id].szTable_id); - cmor_handle_error(msg, CMOR_WARNING); + cmor_handle_error_variadic( + "Reading a table (%s) that calls for NetCDF4 " + "features, you are using NetCDF3 library", + CMOR_WARNING, + cmor_tables[var->table_id].szTable_id); } else if ((CMOR_NETCDF_MODE == CMOR_APPEND_3) || (CMOR_NETCDF_MODE == CMOR_REPLACE_3) || (CMOR_NETCDF_MODE == CMOR_PRESERVE_3)) { - sprintf(msg, - "Reading a table (%s) that calls for NetCDF4 " - "features, you asked for NetCDF3 features", - cmor_tables[var->table_id].szTable_id); - - cmor_handle_error(msg, CMOR_WARNING); + cmor_handle_error_variadic( + "Reading a table (%s) that calls for NetCDF4 " + "features, you asked for NetCDF3 features", + CMOR_WARNING, + cmor_tables[var->table_id].szTable_id); } } } else if (strcmp(att, VARIABLE_ATT_DEFLATE) == 0) { @@ -2123,17 +2115,17 @@ int cmor_set_var_def_att(cmor_var_def_t * var, char att[CMOR_MAX_STRING], if (atoi(val) != 0) { if (USE_NETCDF_4 == 0) { - sprintf(msg, - "Reading a table (%s) that calls for NetCDF4 features, you are using NetCDF3 library", - cmor_tables[var->table_id].szTable_id); - cmor_handle_error(msg, CMOR_WARNING); + cmor_handle_error_variadic( + "Reading a table (%s) that calls for NetCDF4 features, you are using NetCDF3 library", + CMOR_WARNING, + cmor_tables[var->table_id].szTable_id); } else if ((CMOR_NETCDF_MODE == CMOR_APPEND_3) || (CMOR_NETCDF_MODE == CMOR_REPLACE_3) || (CMOR_NETCDF_MODE == CMOR_PRESERVE_3)) { - sprintf(msg, - "Reading a table (%s) that calls for NetCDF4 features, you asked for NetCDF3 features", - cmor_tables[var->table_id].szTable_id); - cmor_handle_error(msg, CMOR_WARNING); + cmor_handle_error_variadic( + "Reading a table (%s) that calls for NetCDF4 features, you asked for NetCDF3 features", + CMOR_WARNING, + cmor_tables[var->table_id].szTable_id); } } } else if (strcmp(att, VARIABLE_ATT_DEFLATELEVEL) == 0) { @@ -2173,10 +2165,10 @@ int cmor_set_var_def_att(cmor_var_def_t * var, char att[CMOR_MAX_STRING], strncpy(var->out_name, val, CMOR_MAX_STRING); } else { - snprintf(msg, CMOR_MAX_STRING, - "Table %s, unknown variable attribute: >>>>%s<<<< value: (%s)", - cmor_tables[var->table_id].szTable_id, att, val); - cmor_handle_error(msg, CMOR_WARNING); + cmor_handle_error_variadic( + "Table %s, unknown variable attribute: >>>>%s<<<< value: (%s)", + CMOR_WARNING, + cmor_tables[var->table_id].szTable_id, att, val); } cmor_pop_traceback(); return (0); @@ -2275,16 +2267,15 @@ int cmor_set_chunking(int var_id, int nTableID, size_t nc_dim_chunking[]) /************************************************************************/ int cmor_set_deflate(int var_id, int shuffle, int deflate, int deflate_level) { - char msg[CMOR_MAX_STRING]; - cmor_add_traceback("cmor_get_original_shape"); cmor_is_setup(); if (cmor_vars[var_id].self != var_id) { - snprintf(msg, CMOR_MAX_STRING, - "You attempt to deflate variable id(%d) which was " - "not initialized", var_id); - cmor_handle_error_var(msg, CMOR_CRITICAL, var_id); + cmor_handle_error_var_variadic( + "You attempt to deflate variable id(%d) which was " + "not initialized", + CMOR_CRITICAL, var_id, + var_id); cmor_pop_traceback(); return (-1); @@ -2302,16 +2293,15 @@ int cmor_set_deflate(int var_id, int shuffle, int deflate, int deflate_level) /************************************************************************/ int cmor_set_zstandard(int var_id, int zstandard_level) { - char msg[CMOR_MAX_STRING]; - cmor_add_traceback("cmor_set_zstandard"); cmor_is_setup(); if (cmor_vars[var_id].self != var_id) { - snprintf(msg, CMOR_MAX_STRING, - "You attempted to set the zstandard level of " - "variable id(%d) which was not initialized", var_id); - cmor_handle_error_var(msg, CMOR_CRITICAL, var_id); + cmor_handle_error_var_variadic( + "You attempted to set the zstandard level of " + "variable id(%d) which was not initialized", + CMOR_CRITICAL, var_id, + var_id); cmor_pop_traceback(); return (-1); @@ -2327,16 +2317,15 @@ int cmor_set_zstandard(int var_id, int zstandard_level) /************************************************************************/ int cmor_set_quantize(int var_id, int quantize_mode, int quantize_nsd) { - char msg[CMOR_MAX_STRING]; - cmor_add_traceback("cmor_set_quantize"); cmor_is_setup(); if (cmor_vars[var_id].self != var_id) { - snprintf(msg, CMOR_MAX_STRING, - "You attempted to set the quantize mode of " - "variable id(%d) which was not initialized", var_id); - cmor_handle_error_var(msg, CMOR_CRITICAL, var_id); + cmor_handle_error_var_variadic( + "You attempted to set the quantize mode of " + "variable id(%d) which was not initialized", + CMOR_CRITICAL, var_id, + var_id); cmor_pop_traceback(); return (-1); @@ -2375,7 +2364,6 @@ int cmor_get_original_shape(int *var_id, int *shape_array, int *rank, { int i; cmor_var_t avar; - char msg[CMOR_MAX_STRING]; cmor_add_traceback("cmor_get_original_shape"); avar = cmor_vars[*var_id]; @@ -2383,12 +2371,12 @@ int cmor_get_original_shape(int *var_id, int *shape_array, int *rank, shape_array[i] = -1; /* init array */ if (*rank < avar.ndims) { - snprintf(msg, CMOR_MAX_STRING, - "trying to retrieve shape of variable %s (table: %s) into a %id " - "array but this variable is %id", - avar.id, cmor_tables[avar.ref_table_id].szTable_id, *rank, - avar.ndims); - cmor_handle_error_var(msg, CMOR_CRITICAL, *var_id); + cmor_handle_error_var_variadic( + "trying to retrieve shape of variable %s (table: %s) into a %id " + "array but this variable is %id", + CMOR_CRITICAL, *var_id, + avar.id, cmor_tables[avar.ref_table_id].szTable_id, *rank, + avar.ndims); } for (i = 0; i < avar.ndims; i++) { if ((blank_time == 1) @@ -2417,6 +2405,8 @@ int cmor_write_var_to_file(int ncid, cmor_var_t * avar, void *data, size_t counter_orig[CMOR_MAX_DIMENSIONS]; size_t counter_orig2[CMOR_MAX_DIMENSIONS]; size_t counter2[CMOR_MAX_DIMENSIONS]; + size_t max_counter[CMOR_MAX_DIMENSIONS]; + size_t min_counter[CMOR_MAX_DIMENSIONS]; size_t starts[CMOR_MAX_DIMENSIONS]; size_t nelements, loc, add, nelts; double *data_tmp = NULL, tmp = 0., tmp2, amean; @@ -2434,11 +2424,12 @@ int cmor_write_var_to_file(int ncid, cmor_var_t * avar, void *data, char local_unit[CMOR_MAX_STRING]; size_t n_lower_min = 0, n_greater_max = 0; double emax, emin, first_time; - char msg_min[CMOR_MAX_STRING]; - char msg_max[CMOR_MAX_STRING]; extern ut_system *ut_read; size_t tmpindex = 0; size_t index; + char *msg_min; + char *msg_max; + size_t msg_len; cmor_add_traceback("cmor_write_var_to_file"); cmor_is_setup(); @@ -2459,13 +2450,13 @@ int cmor_write_var_to_file(int ncid, cmor_var_t * avar, void *data, if (ntimes_passed != 0) { counts[0] = ntimes_passed; if (cmor_axes[avar->axes_ids[0]].axis != 'T') { - snprintf(msg, CMOR_MAX_STRING, - "you are passing %i time steps for a static " - "(no time dimension) variable (%s, table: %s), " - "please pass 0 (zero) as the number of times", - ntimes_passed, avar->id, - cmor_tables[avar->ref_table_id].szTable_id); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "you are passing %i time steps for a static " + "(no time dimension) variable (%s, table: %s), " + "please pass 0 (zero) as the number of times", + CMOR_CRITICAL, + ntimes_passed, avar->id, + cmor_tables[avar->ref_table_id].szTable_id); } } else { /* -------------------------------------------------------------------- */ @@ -2529,48 +2520,48 @@ int cmor_write_var_to_file(int ncid, cmor_var_t * avar, void *data, if (mtype == 'i') { idata_tmp = malloc(sizeof(int) * nelements); if (idata_tmp == NULL) { - snprintf(msg, CMOR_MAX_STRING, - "cannot allocate memory for %lu int tmp elts var '%s' " - "(table: %s)", - nelements, avar->id, - cmor_tables[avar->ref_table_id].szTable_id); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "cannot allocate memory for %lu int tmp elts var '%s' " + "(table: %s)", + CMOR_CRITICAL, + nelements, avar->id, + cmor_tables[avar->ref_table_id].szTable_id); } } else if (mtype == 'l') { ldata_tmp = malloc(sizeof(long) * nelements); if (ldata_tmp == NULL) { - snprintf(msg, CMOR_MAX_STRING, - "cannot allocate memory for %lu long tmp elts var '%s' " - "(table: %s)", - nelements, avar->id, - cmor_tables[avar->ref_table_id].szTable_id); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "cannot allocate memory for %lu long tmp elts var '%s' " + "(table: %s)", + CMOR_CRITICAL, + nelements, avar->id, + cmor_tables[avar->ref_table_id].szTable_id); } } else if (mtype == 'd') { data_tmp = malloc(sizeof(double) * nelements); if (data_tmp == NULL) { - snprintf(msg, CMOR_MAX_STRING, - "cannot allocate memory for %lu double tmp elts var '%s' " - "(table: %s)", - nelements, avar->id, - cmor_tables[avar->ref_table_id].szTable_id); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "cannot allocate memory for %lu double tmp elts var '%s' " + "(table: %s)", + CMOR_CRITICAL, + nelements, avar->id, + cmor_tables[avar->ref_table_id].szTable_id); } } else { fdata_tmp = malloc(sizeof(float) * nelements); if (fdata_tmp == NULL) { - snprintf(msg, CMOR_MAX_STRING, - "cannot allocate memory for %lu float tmp elts var '%s' " - "(table: %s)", - nelements, avar->id, - cmor_tables[avar->ref_table_id].szTable_id); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "cannot allocate memory for %lu float tmp elts var '%s' " + "(table: %s)", + CMOR_CRITICAL, + nelements, avar->id, + cmor_tables[avar->ref_table_id].szTable_id); } } @@ -2584,12 +2575,12 @@ int cmor_write_var_to_file(int ncid, cmor_var_t * avar, void *data, cmor_units = ut_parse(ut_read, local_unit, UT_ASCII); if (ut_get_status() != UT_SUCCESS) { - snprintf(msg, CMOR_MAX_STRING, - "in udunits analyzing units from cmor table " - "(%s) for variable %s (table: %s)", - local_unit, avar->id, - cmor_tables[avar->ref_table_id].szTable_id); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "in udunits analyzing units from cmor table " + "(%s) for variable %s (table: %s)", + CMOR_CRITICAL, + local_unit, avar->id, + cmor_tables[avar->ref_table_id].szTable_id); cmor_pop_traceback(); return (1); } @@ -2599,23 +2590,23 @@ int cmor_write_var_to_file(int ncid, cmor_var_t * avar, void *data, user_units = ut_parse(ut_read, local_unit, UT_ASCII); if (ut_get_status() != UT_SUCCESS) { - snprintf(msg, CMOR_MAX_STRING, - "in udunits analyzing units from user (%s) " - "for variable %s (table: %s)", - local_unit, avar->id, - cmor_tables[avar->ref_table_id].szTable_id); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "in udunits analyzing units from user (%s) " + "for variable %s (table: %s)", + CMOR_CRITICAL, + local_unit, avar->id, + cmor_tables[avar->ref_table_id].szTable_id); cmor_pop_traceback(); return (1); } if (ut_are_convertible(cmor_units, user_units) == 0) { - snprintf(msg, CMOR_MAX_STRING, - "variable: %s, cmor and user units are incompatible: " - "%s and %s for variable %s (table: %s)", - avar->id, avar->ounits, avar->iunits, avar->id, - cmor_tables[avar->ref_table_id].szTable_id); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "variable: %s, cmor and user units are incompatible: " + "%s and %s for variable %s (table: %s)", + CMOR_CRITICAL, + avar->id, avar->ounits, avar->iunits, avar->id, + cmor_tables[avar->ref_table_id].szTable_id); cmor_pop_traceback(); return (1); } @@ -2623,11 +2614,11 @@ int cmor_write_var_to_file(int ncid, cmor_var_t * avar, void *data, ut_cmor_converter = ut_get_converter(user_units, cmor_units); if (ut_get_status() != UT_SUCCESS) { - snprintf(msg, CMOR_MAX_STRING, - " in udunits, getting converter for variable %s " - "(table: %s)", - avar->id, cmor_tables[avar->ref_table_id].szTable_id); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + " in udunits, getting converter for variable %s " + "(table: %s)", + CMOR_CRITICAL, + avar->id, cmor_tables[avar->ref_table_id].szTable_id); cmor_pop_traceback(); return (1); } @@ -2712,12 +2703,12 @@ int cmor_write_var_to_file(int ncid, cmor_var_t * avar, void *data, tmp = cv_convert_double(ut_cmor_converter, tmp); if (ut_get_status() != UT_SUCCESS) { - snprintf(msg, CMOR_MAX_STRING, - "in udunits, converting values from %s to %s " - "for variable %s (table: %s)", - avar->iunits, avar->ounits, avar->id, - cmor_tables[avar->ref_table_id].szTable_id); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "in udunits, converting values from %s to %s " + "for variable %s (table: %s)", + CMOR_CRITICAL, + avar->iunits, avar->ounits, avar->id, + cmor_tables[avar->ref_table_id].szTable_id); cmor_pop_traceback(); return (1); } @@ -2732,63 +2723,18 @@ int cmor_write_var_to_file(int ncid, cmor_var_t * avar, void *data, n_lower_min += 1; if ((n_lower_min == 1) || (tmp < emin)) { /*minimum val */ emin = tmp; - snprintf(msg_min, CMOR_MAX_STRING, - "Invalid value(s) detected for variable '%s' " - "(table: %s): %%i values were lower than minimum " - "valid value (%.4g). Minimum encountered bad " - "value (%.5g) was at (axis: index/value):", - avar->id, - cmor_tables[avar->ref_table_id].szTable_id, - avar->valid_min, tmp); - for (j = 0; j < avar->ndims; j++) { - cmor_axis_t *pAxis; - pAxis = &cmor_axes[avar->axes_ids[j]]; - if (pAxis->values != NULL) { - snprintf(msg2, CMOR_MAX_STRING, " %s: %lu/%.5g", - pAxis->id, counter2[j], - pAxis->values[counter2[j]]); - - } else { - snprintf(msg2, CMOR_MAX_STRING, " %s: %lu/%.5g", - pAxis->id, counter2[j], - time_vals[counter2[j]]); - } - strncat(msg_min, msg2, CMOR_MAX_STRING - strlen(msg)); + min_counter[j] = counter2[j]; } } } if ((avar->valid_max != (float)1.e20) && (tmp > avar->valid_max)) { n_greater_max += 1; - if ((n_greater_max == 1) || (tmp > emax)) { - emax = tmp; - snprintf(msg_max, CMOR_MAX_STRING, - "Invalid value(s) detected for variable '%s' " - "(table: %s): %%i values were greater than " - "maximum valid value (%.4g).Maximum encountered " - "bad value (%.5g) was at (axis: index/value):", - avar->id, - cmor_tables[avar->ref_table_id].szTable_id, - avar->valid_max, tmp); - for (j = 0; j < avar->ndims; j++) { - cmor_axis_t *pAxis; - pAxis = &cmor_axes[avar->axes_ids[j]]; - - if (pAxis->values != NULL) { - snprintf(msg2, CMOR_MAX_STRING, " %s: %lu/%.5g", - pAxis->id, counter2[j], - pAxis->values[counter2[j]]); - } else { - snprintf(msg2, CMOR_MAX_STRING, " %s: %lu/%.5g", - pAxis->id, counter2[j], - time_vals[counter2[j]]); - } - - strncat(msg_max, msg2, CMOR_MAX_STRING - strlen(msg)); + max_counter[j] = counter2[j]; } } } @@ -2805,61 +2751,140 @@ int cmor_write_var_to_file(int ncid, cmor_var_t * avar, void *data, } if (n_lower_min != 0) { + msg_len = 0; + for (j = 0; j < avar->ndims; j++) { + cmor_axis_t *pAxis; + pAxis = &cmor_axes[avar->axes_ids[j]]; + double val = 0.f; + if (pAxis->values != NULL) { + val = pAxis->values[min_counter[j]]; + } else { + val = time_vals[min_counter[j]]; + } + msg_len += snprintf(NULL, 0, " %s: %lu/%.5g", + pAxis->id, min_counter[j], val); + } + msg_len += 1; + + msg_min = (char *)malloc(msg_len * sizeof(char)); + + msg_len = 0; + for (j = 0; j < avar->ndims; j++) { + cmor_axis_t *pAxis; + pAxis = &cmor_axes[avar->axes_ids[j]]; + double val = 0.f; + if (pAxis->values != NULL) { + val = pAxis->values[min_counter[j]]; + } else { + val = time_vals[min_counter[j]]; + } + msg_len += sprintf(&msg_min[msg_len], " %s: %lu/%.5g", + pAxis->id, min_counter[j], val); + } + + cmor_handle_error_variadic( + "Invalid value(s) detected for variable '%s' " + "(table: %s): %zu values were lower than minimum " + "valid value (%.4g). Minimum encountered bad " + "value (%.5g) was at (axis: index/value):%s", + CMOR_WARNING, + avar->id, + cmor_tables[avar->ref_table_id].szTable_id, + n_lower_min, avar->valid_max, emin, msg_min); - snprintf(msg, CMOR_MAX_STRING, msg_min, n_lower_min); - cmor_handle_error(msg, CMOR_WARNING); + free(msg_min); } if (n_greater_max != 0) { + msg_len = 0; + for (j = 0; j < avar->ndims; j++) { + cmor_axis_t *pAxis; + pAxis = &cmor_axes[avar->axes_ids[j]]; + double val = 0.; + if (pAxis->values != NULL) { + val = pAxis->values[max_counter[j]]; + } else { + val = time_vals[max_counter[j]]; + } + msg_len += snprintf(NULL, 0, " %s: %lu/%.5g", + pAxis->id, max_counter[j], val); + } + msg_len += 1; - snprintf(msg, CMOR_MAX_STRING, msg_max, n_greater_max); - cmor_handle_error(msg, CMOR_WARNING); + msg_max = (char *)malloc(msg_len * sizeof(char)); + + msg_len = 0; + for (j = 0; j < avar->ndims; j++) { + cmor_axis_t *pAxis; + pAxis = &cmor_axes[avar->axes_ids[j]]; + double val = 0.; + if (pAxis->values != NULL) { + val = pAxis->values[max_counter[j]]; + } else { + val = time_vals[max_counter[j]]; + } + msg_len += sprintf(&msg_max[msg_len], " %s: %lu/%.5g", + pAxis->id, max_counter[j], val); + } + + cmor_handle_error_variadic( + "Invalid value(s) detected for variable '%s' " + "(table: %s): %zu values were greater than " + "maximum valid value (%.4g).Maximum encountered " + "bad value (%.5g) was at (axis: index/value):%s", + CMOR_WARNING, + avar->id, + cmor_tables[avar->ref_table_id].szTable_id, + n_greater_max, avar->valid_max, emax, msg_max); + + free(msg_max); } if (avar->ok_min_mean_abs != (float)1.e20) { if (amean / nelts < .1 * avar->ok_min_mean_abs) { - snprintf(msg, CMOR_MAX_STRING, - "Invalid Absolute Mean for variable '%s' (table: %s) " - "(%.5g) is lower by more than an order of magnitude " - "than minimum allowed: %.4g", avar->id, - cmor_tables[avar->ref_table_id].szTable_id, amean / nelts, - avar->ok_min_mean_abs); - - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "Invalid Absolute Mean for variable '%s' (table: %s) " + "(%.5g) is lower by more than an order of magnitude " + "than minimum allowed: %.4g", + CMOR_CRITICAL, + avar->id, + cmor_tables[avar->ref_table_id].szTable_id, amean / nelts, + avar->ok_min_mean_abs); } if (amean / nelts < avar->ok_min_mean_abs) { - snprintf(msg, CMOR_MAX_STRING, - "Invalid Absolute Mean for variable '%s' " - "(table: %s) (%.5g) is lower than minimum allowed: %.4g", - avar->id, cmor_tables[avar->ref_table_id].szTable_id, - amean / nelts, avar->ok_min_mean_abs); - cmor_handle_error(msg, CMOR_WARNING); + cmor_handle_error_variadic( + "Invalid Absolute Mean for variable '%s' " + "(table: %s) (%.5g) is lower than minimum allowed: %.4g", + CMOR_WARNING, + avar->id, cmor_tables[avar->ref_table_id].szTable_id, + amean / nelts, avar->ok_min_mean_abs); } } if (avar->ok_max_mean_abs != (float)1.e20) { if (amean / nelts > 10. * avar->ok_max_mean_abs) { - snprintf(msg, CMOR_MAX_STRING, - "Invalid Absolute Mean for variable '%s' " - "(table: %s) (%.5g) is greater by more than " - "an order of magnitude than maximum allowed: %.4g", - avar->id, cmor_tables[avar->ref_table_id].szTable_id, - amean / nelts, avar->ok_max_mean_abs); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "Invalid Absolute Mean for variable '%s' " + "(table: %s) (%.5g) is greater by more than " + "an order of magnitude than maximum allowed: %.4g", + CMOR_CRITICAL, + avar->id, cmor_tables[avar->ref_table_id].szTable_id, + amean / nelts, avar->ok_max_mean_abs); } if (amean / nelts > avar->ok_max_mean_abs) { - snprintf(msg, CMOR_MAX_STRING, - "Invalid Absolute Mean for variable '%s' " - "(table: %s) (%.5g) is greater than maximum " - "allowed: %.4g", avar->id, - cmor_tables[avar->ref_table_id].szTable_id, amean / nelts, - avar->ok_max_mean_abs); - cmor_handle_error(msg, CMOR_WARNING); + cmor_handle_error_variadic( + "Invalid Absolute Mean for variable '%s' " + "(table: %s) (%.5g) is greater than maximum " + "allowed: %.4g", + CMOR_WARNING, + avar->id, + cmor_tables[avar->ref_table_id].szTable_id, amean / nelts, + avar->ok_max_mean_abs); } } @@ -2869,31 +2894,32 @@ int cmor_write_var_to_file(int ncid, cmor_var_t * avar, void *data, if (ut_get_status() != UT_SUCCESS) { - snprintf(msg, CMOR_MAX_STRING, - "Udunits: Error freeing converter, variable %s " - "(table: %s)", avar->id, - cmor_tables[avar->ref_table_id].szTable_id); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "Udunits: Error freeing converter, variable %s " + "(table: %s)", + CMOR_CRITICAL, + avar->id, + cmor_tables[avar->ref_table_id].szTable_id); } ut_free(cmor_units); if (ut_get_status() != UT_SUCCESS) { - snprintf(msg, CMOR_MAX_STRING, - "Udunits: Error freeing units, variable %s (table: %s)", - avar->id, cmor_tables[avar->ref_table_id].szTable_id); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "Udunits: Error freeing units, variable %s (table: %s)", + CMOR_CRITICAL, + avar->id, cmor_tables[avar->ref_table_id].szTable_id); } ut_free(user_units); if (ut_get_status() != UT_SUCCESS) { - snprintf(msg, CMOR_MAX_STRING, - "Udunits: Error freeing units, variable %s (table: %s)", - avar->id, cmor_tables[avar->ref_table_id].szTable_id); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "Udunits: Error freeing units, variable %s (table: %s)", + CMOR_CRITICAL, + avar->id, cmor_tables[avar->ref_table_id].szTable_id); } } @@ -2912,12 +2938,13 @@ int cmor_write_var_to_file(int ncid, cmor_var_t * avar, void *data, if (ntimes_passed != 0) { if (time_vals != NULL) { if (cmor_axes[avar->axes_ids[0]].values != NULL) { - snprintf(msg, CMOR_MAX_STRING, - "variable '%s' (table %s) you are passing " - "time values but you already defined them " - "via cmor_axis, this is not allowed", avar->id, - cmor_tables[avar->ref_table_id].szTable_id); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "variable '%s' (table %s) you are passing " + "time values but you already defined them " + "via cmor_axis, this is not allowed", + CMOR_CRITICAL, + avar->id, + cmor_tables[avar->ref_table_id].szTable_id); } if (time_bounds != NULL) { @@ -2929,12 +2956,12 @@ int cmor_write_var_to_file(int ncid, cmor_var_t * avar, void *data, tmp_vals = malloc((ntimes_passed + 1) * 2 * sizeof(double)); if (tmp_vals == NULL) { - snprintf(msg, CMOR_MAX_STRING, - "cannot malloc %i tmp bounds time vals " - "for variable '%s' (table: %s)", - ntimes_passed * 2, avar->id, - cmor_tables[avar->ref_table_id].szTable_id); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "cannot malloc %i tmp bounds time vals " + "for variable '%s' (table: %s)", + CMOR_CRITICAL, + ntimes_passed * 2, avar->id, + cmor_tables[avar->ref_table_id].szTable_id); } if (avar->ntimes_written > 0) { if ((avar->last_time != -999.) @@ -2986,10 +3013,10 @@ int cmor_write_var_to_file(int ncid, cmor_var_t * avar, void *data, counts2, &tmp_vals[2 * tmpindex]); if (ierr != NC_NOERR) { - snprintf(msg, CMOR_MAX_STRING, - "NetCDF error (%i) writing time bounds for variable '%s', already written in file: %i", - ierr, avar->id, avar->ntimes_written); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "NetCDF error (%i) writing time bounds for variable '%s', already written in file: %i", + CMOR_CRITICAL, + ierr, avar->id, avar->ntimes_written); } /* -------------------------------------------------------------------- */ /* ok first time around the we need to store bounds */ @@ -3044,11 +3071,11 @@ int cmor_write_var_to_file(int ncid, cmor_var_t * avar, void *data, ierr = nc_put_vara_double(ncid, avar->time_nc_id, starts, counts, &tmp_vals[0]); if (ierr != NC_NOERR) { - snprintf(msg, CMOR_MAX_STRING, - "NetCDF error (%i: %s) writing time values for variable '%s' (%s)", - ierr, nc_strerror(ierr), avar->id, - cmor_tables[avar->ref_table_id].szTable_id); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "NetCDF error (%i: %s) writing time values for variable '%s' (%s)", + CMOR_CRITICAL, + ierr, nc_strerror(ierr), avar->id, + cmor_tables[avar->ref_table_id].szTable_id); } @@ -3066,14 +3093,14 @@ int cmor_write_var_to_file(int ncid, cmor_var_t * avar, void *data, } else { if (tmp_vals[0] < avar->last_time) { - snprintf(msg, CMOR_MAX_STRING, - "Time point: %lf ( %lf in output units) " - "is not monotonic last time was: %lf " - "(in output units), variable %s (table: %s)", - time_vals[0], tmp_vals[0], avar->last_time, - avar->id, - cmor_tables[avar->ref_table_id].szTable_id); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "Time point: %lf ( %lf in output units) " + "is not monotonic last time was: %lf " + "(in output units), variable %s (table: %s)", + CMOR_CRITICAL, + time_vals[0], tmp_vals[0], avar->last_time, + avar->id, + cmor_tables[avar->ref_table_id].szTable_id); } } @@ -3088,12 +3115,12 @@ int cmor_write_var_to_file(int ncid, cmor_var_t * avar, void *data, if (cmor_tables[cmor_axes[avar->axes_ids[0]].ref_table_id].axes [cmor_axes[avar->axes_ids[0]].ref_axis_id]. must_have_bounds == 1) { - snprintf(msg, CMOR_MAX_STRING, - "time axis must have bounds, please pass them to " - "cmor_write along with time values, variable %s, table %s", - avar->id, - cmor_tables[avar->ref_table_id].szTable_id); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "time axis must have bounds, please pass them to " + "cmor_write along with time values, variable %s, table %s", + CMOR_CRITICAL, + avar->id, + cmor_tables[avar->ref_table_id].szTable_id); } @@ -3106,11 +3133,12 @@ int cmor_write_var_to_file(int ncid, cmor_var_t * avar, void *data, tmp_vals = malloc(ntimes_passed * sizeof(double)); if (tmp_vals == NULL) { - snprintf(msg, CMOR_MAX_STRING, - "cannot malloc %i time vals for variable " - "'%s' (table: %s)", ntimes_passed, avar->id, - cmor_tables[avar->ref_table_id].szTable_id); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "cannot malloc %i time vals for variable " + "'%s' (table: %s)", + CMOR_CRITICAL, + ntimes_passed, avar->id, + cmor_tables[avar->ref_table_id].szTable_id); } ierr = cmor_convert_time_values(time_vals, 'd', ntimes_passed, &tmp_vals[0], @@ -3132,13 +3160,13 @@ int cmor_write_var_to_file(int ncid, cmor_var_t * avar, void *data, free(tmp_vals); if (ierr != NC_NOERR) { - snprintf(msg, CMOR_MAX_STRING, - "NetCDF error (%i: %s) writing times for variable '%s' " - "(table: %s), already written in file: %i", - ierr, nc_strerror(ierr), avar->id, - cmor_tables[avar->ref_table_id].szTable_id, - avar->ntimes_written); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "NetCDF error (%i: %s) writing times for variable '%s' " + "(table: %s), already written in file: %i", + CMOR_CRITICAL, + ierr, nc_strerror(ierr), avar->id, + cmor_tables[avar->ref_table_id].szTable_id, + avar->ntimes_written); } } } else { @@ -3148,13 +3176,14 @@ int cmor_write_var_to_file(int ncid, cmor_var_t * avar, void *data, /* -------------------------------------------------------------------- */ if (cmor_axes[avar->axes_ids[0]].values == NULL) { - snprintf(msg, CMOR_MAX_STRING, - "variable '%s' (table: %s) you are passing %i " - "times but no values and you did not define " - "them via cmor_axis", avar->id, - cmor_tables[avar->ref_table_id].szTable_id, - ntimes_passed); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "variable '%s' (table: %s) you are passing %i " + "times but no values and you did not define " + "them via cmor_axis", + CMOR_CRITICAL, + avar->id, + cmor_tables[avar->ref_table_id].szTable_id, + ntimes_passed); } if (cmor_axes[avar->axes_ids[0]].bounds != NULL) { /* -------------------------------------------------------------------- */ @@ -3171,12 +3200,12 @@ int cmor_write_var_to_file(int ncid, cmor_var_t * avar, void *data, [0] * 2]); if (ierr != NC_NOERR) { - snprintf(msg, CMOR_MAX_STRING, - "NCError (%i: %s) writing time bounds values for " - "variable '%s' (table: %s)", - ierr, nc_strerror(ierr), avar->id, - cmor_tables[avar->ref_table_id].szTable_id); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "NCError (%i: %s) writing time bounds values for " + "variable '%s' (table: %s)", + CMOR_CRITICAL, + ierr, nc_strerror(ierr), avar->id, + cmor_tables[avar->ref_table_id].szTable_id); } /* -------------------------------------------------------------------- */ /* ok we need to store first and last bounds */ @@ -3195,11 +3224,12 @@ int cmor_write_var_to_file(int ncid, cmor_var_t * avar, void *data, if (cmor_tables[cmor_axes[avar->axes_ids[0]].ref_table_id].axes [cmor_axes[avar->axes_ids[0]].ref_axis_id]. must_have_bounds == 1) { - snprintf(msg, CMOR_MAX_STRING, - "time axis must have bounds, you defined it w/o " - "any for variable %s (table: %s)", avar->id, - cmor_tables[avar->ref_table_id].szTable_id); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "time axis must have bounds, you defined it w/o " + "any for variable %s (table: %s)", + CMOR_CRITICAL, + avar->id, + cmor_tables[avar->ref_table_id].szTable_id); } avar->first_bound = 1.e20; avar->last_bound = 1.e20; @@ -3209,11 +3239,11 @@ int cmor_write_var_to_file(int ncid, cmor_var_t * avar, void *data, axes_ids[0]].values[starts [0]]); if (ierr != NC_NOERR) { - snprintf(msg, CMOR_MAX_STRING, - "NCError (%i: %s) writing time values for variable '%s' (table: %s)", - ierr, nc_strerror(ierr), avar->id, - cmor_tables[avar->ref_table_id].szTable_id); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "NCError (%i: %s) writing time values for variable '%s' (table: %s)", + CMOR_CRITICAL, + ierr, nc_strerror(ierr), avar->id, + cmor_tables[avar->ref_table_id].szTable_id); } /* -------------------------------------------------------------------- */ /* ok now we need to store first and last stuff */ @@ -3247,13 +3277,14 @@ int cmor_write_var_to_file(int ncid, cmor_var_t * avar, void *data, if (ierr != -1) { if (cmor_axes[avar->axes_ids[ierr]].values == NULL) { - snprintf(msg, CMOR_MAX_STRING, - "variable '%s' (table: %s) you are passing %i " - "times but no values and you did not define " - "them via cmor_axis", avar->id, - cmor_tables[avar->ref_table_id].szTable_id, - ntimes_passed); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "variable '%s' (table: %s) you are passing %i " + "times but no values and you did not define " + "them via cmor_axis", + CMOR_CRITICAL, + avar->id, + cmor_tables[avar->ref_table_id].szTable_id, + ntimes_passed); } @@ -3278,12 +3309,12 @@ int cmor_write_var_to_file(int ncid, cmor_var_t * avar, void *data, 2]); if (ierr != NC_NOERR) { - snprintf(msg, CMOR_MAX_STRING, - "NCError (%i: %s) writing time bounds values for " - "variable '%s' (table: %s)", - ierr, nc_strerror(ierr), avar->id, - cmor_tables[avar->ref_table_id].szTable_id); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "NCError (%i: %s) writing time bounds values for " + "variable '%s' (table: %s)", + CMOR_CRITICAL, + ierr, nc_strerror(ierr), avar->id, + cmor_tables[avar->ref_table_id].szTable_id); } avar->first_bound = cmor_axes[avar->axes_ids[0]].bounds[0]; avar->last_bound = cmor_axes[avar->axes_ids[0]].bounds[counts[0] @@ -3297,12 +3328,12 @@ int cmor_write_var_to_file(int ncid, cmor_var_t * avar, void *data, if (ierr != NC_NOERR) { - snprintf(msg, CMOR_MAX_STRING, - "NCError (%i: %s) writing time values for " - "variable '%s' (table: %s)", - ierr, nc_strerror(ierr), avar->id, - cmor_tables[avar->ref_table_id].szTable_id); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "NCError (%i: %s) writing time values for " + "variable '%s' (table: %s)", + CMOR_CRITICAL, + ierr, nc_strerror(ierr), avar->id, + cmor_tables[avar->ref_table_id].szTable_id); } /* -------------------------------------------------------------------- */ @@ -3336,11 +3367,11 @@ int cmor_write_var_to_file(int ncid, cmor_var_t * avar, void *data, } if (ierr != NC_NOERR) { - snprintf(msg, CMOR_MAX_STRING, - "NetCDF Error (%i: %s), writing variable '%s' (table %s) to file", - ierr, nc_strerror(ierr), avar->id, - cmor_tables[avar->ref_table_id].szTable_id); - cmor_handle_error(msg, CMOR_CRITICAL); + cmor_handle_error_variadic( + "NetCDF Error (%i: %s), writing variable '%s' (table %s) to file", + CMOR_CRITICAL, + ierr, nc_strerror(ierr), avar->id, + cmor_tables[avar->ref_table_id].szTable_id); } avar->ntimes_written += ntimes_passed; diff --git a/include/cmor_func_def.h b/include/cmor_func_def.h index c452392e..82e43041 100644 --- a/include/cmor_func_def.h +++ b/include/cmor_func_def.h @@ -8,6 +8,7 @@ #include #include "cdmsint.h" #include +#include #include extern void cmor_md5( FILE * inputfile, unsigned char checksum[16] ); @@ -26,10 +27,13 @@ extern int cmor_have_NetCDF4( void ); extern int cmor_have_NetCDF41min( void ); extern int cmor_have_NetCDF3( void ); extern int cmor_have_NetCDF363( void ); -extern void cmor_handle_error( char error_msg[CMOR_MAX_STRING], - int level ); -extern void cmor_handle_error_var( char error_msg[CMOR_MAX_STRING], int level, - int var_id ); +extern void cmor_handle_error_internal( char *error_msg, int level ); +extern void cmor_handle_error( char *error_msg, int level ); +extern void cmor_handle_error_variadic( char *error_msg, int level, ... ) + __attribute__ ((__format__(printf, 1, 3))); +extern void cmor_handle_error_var( char *error_msg, int level, int var_id ); +extern void cmor_handle_error_var_variadic( char *error_msg, int level, int var_id, ... ) + __attribute__ ((__format__(printf, 1, 4))); extern int cmor_setup( char *path, int *netcdf, int *verbosity, int *mode, char *logfile, int *cmor_create_subdirectories); @@ -156,9 +160,8 @@ extern int cmor_CV_ValidateAttribute(cmor_CV_def_t *CV, char *szValue); /* ==================================================================== */ extern void cmor_init_axis_def( cmor_axis_def_t * axis, int table_id ); -extern int cmor_set_axis_def_att( cmor_axis_def_t * axis, - char att[CMOR_MAX_STRING], - char val[CMOR_MAX_STRING] ); +extern int cmor_set_axis_def_att( cmor_axis_def_t * axis, char *att, + char *val ); extern void cmor_trim_string( char *in, char *out ); extern int cmor_calendar_c2i( char *calendar, cdCalenType * ical ); extern int cmor_convert_time_units( char *inunits, char *outunits, @@ -228,9 +231,8 @@ extern int cmor_set_quantize( int var_id, int quantize_mode, extern int cmor_set_chunking( int var_id, int nTableID, size_t nc_dim_chunking[]); -extern int cmor_set_var_def_att( cmor_var_def_t * var, - char att[CMOR_MAX_STRING], - char val[CMOR_MAX_STRING] ); +extern int cmor_set_var_def_att( cmor_var_def_t * var, char *att, + char *val); extern int cmor_get_variable_time_length( int *var_id, int *length ); extern int cmor_get_original_shape( int *var_id, int *shape_array, int *rank, int blank_time );