mirror of https://github.com/ecmwf/eccodes.git
Tools: Error messages
This commit is contained in:
parent
4aec267301
commit
7e882a34c4
|
@ -118,7 +118,7 @@ static void new_keys_list()
|
|||
grib_context* c = grib_context_get_default();
|
||||
keys_list = (grib_string_list*)grib_context_malloc_clear(c, sizeof(grib_string_list));
|
||||
if (!keys_list) {
|
||||
fprintf(stderr, "Failed to allocate memory for keys list");
|
||||
fprintf(stderr, "%s: Failed to allocate memory for keys list", tool_name);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
@ -281,11 +281,11 @@ int grib_tool_init(grib_runtime_options* options)
|
|||
headerMode = 0;
|
||||
|
||||
if (grib_options_on("H") && grib_options_on("c:")) {
|
||||
fprintf(stderr, "Error: -H and -c options are incompatible. Choose one of the two please.\n");
|
||||
fprintf(stderr, "%s: -H and -c options are incompatible. Choose one of the two please.\n",tool_name);
|
||||
exit(1);
|
||||
}
|
||||
if (grib_options_on("a") && !grib_options_on("c:")) {
|
||||
fprintf(stderr, "Error: -a option requires -c option. Please define a list of keys with the -c option.\n");
|
||||
fprintf(stderr, "%s: -a option requires -c option. Please define a list of keys with the -c option.\n",tool_name);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
@ -314,8 +314,8 @@ int grib_tool_init(grib_runtime_options* options)
|
|||
options->idx = grib_fieldset_new_from_files(context, filename,
|
||||
nfiles, 0, 0, 0, orderby, &ret);
|
||||
if (ret) {
|
||||
fprintf(stderr, "unable to create index for input file %s (%s)",
|
||||
options->infile_extra->name, grib_get_error_message(ret));
|
||||
fprintf(stderr, "%s: Unable to create index for input file %s (%s)",
|
||||
tool_name, options->infile_extra->name, grib_get_error_message(ret));
|
||||
exit(ret);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -307,7 +307,7 @@ static void bufr_dump_descriptors(grib_handle* h)
|
|||
GRIB_CHECK_NOLINE(grib_get_size(h, the_key, &size_desc), 0);
|
||||
array_descriptors = (long*)malloc(size_desc * sizeof(long));
|
||||
if (!array_descriptors) {
|
||||
fprintf(stderr, "%s: Memory allocation error", the_key);
|
||||
fprintf(stderr, "%s: Memory allocation error. Key %s\n", tool_name, the_key);
|
||||
exit(GRIB_OUT_OF_MEMORY);
|
||||
}
|
||||
GRIB_CHECK_NOLINE(grib_get_long_array(h, the_key, array_descriptors, &size_desc), 0);
|
||||
|
@ -325,7 +325,7 @@ static void bufr_dump_descriptors(grib_handle* h)
|
|||
GRIB_CHECK_NOLINE(grib_get_size(h, the_key, &size_abbrevs), 0);
|
||||
array_abbrevs = (char**)malloc(size_abbrevs * sizeof(char*));
|
||||
if (!array_abbrevs) {
|
||||
fprintf(stderr, "%s: Memory allocation error", the_key);
|
||||
fprintf(stderr, "%s: Memory allocation error. Key %s\n", tool_name, the_key);
|
||||
exit(GRIB_OUT_OF_MEMORY);
|
||||
}
|
||||
GRIB_CHECK_NOLINE(grib_get_string_array(h, the_key, array_abbrevs, &size_abbrevs), 0);
|
||||
|
@ -335,7 +335,7 @@ static void bufr_dump_descriptors(grib_handle* h)
|
|||
GRIB_CHECK_NOLINE(grib_get_size(h, the_key, &size_names), 0);
|
||||
array_names = (char**)malloc(size_names * sizeof(char*));
|
||||
if (!array_names) {
|
||||
fprintf(stderr, "%s: Memory allocation error", the_key);
|
||||
fprintf(stderr, "%s: Memory allocation error. Key %s\n", tool_name, the_key);
|
||||
exit(GRIB_OUT_OF_MEMORY);
|
||||
}
|
||||
GRIB_CHECK_NOLINE(grib_get_string_array(h, the_key, array_names, &size_names), 0);
|
||||
|
@ -345,7 +345,7 @@ static void bufr_dump_descriptors(grib_handle* h)
|
|||
GRIB_CHECK_NOLINE(grib_get_size(h, the_key, &size_units), 0);
|
||||
array_units = (char**)malloc(size_units * sizeof(char*));
|
||||
if (!array_units) {
|
||||
fprintf(stderr, "%s: Memory allocation error", the_key);
|
||||
fprintf(stderr, "%s: Memory allocation error. Key %s\n", tool_name, the_key);
|
||||
exit(GRIB_OUT_OF_MEMORY);
|
||||
}
|
||||
GRIB_CHECK_NOLINE(grib_get_string_array(h, the_key, array_units, &size_units), 0);
|
||||
|
@ -423,7 +423,7 @@ int grib_tool_new_handle_action(grib_runtime_options* options, grib_handle* h)
|
|||
char* str = grib_options_get_option("S:");
|
||||
err = grib_get_long(h, "numberOfSubsets", &numberOfSubsets);
|
||||
if (err) {
|
||||
fprintf(stderr, "ERROR: Failed to get numberOfSubsets.\n");
|
||||
fprintf(stderr, "%s: Failed to get numberOfSubsets.\n", tool_name);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
@ -451,7 +451,7 @@ int grib_tool_new_handle_action(grib_runtime_options* options, grib_handle* h)
|
|||
}
|
||||
}
|
||||
else {
|
||||
fprintf(stderr, "ERROR: -S option: Please specify a subset number > 0 and < %ld\n", numberOfSubsets + 1);
|
||||
fprintf(stderr, "%s: -S option: Please specify a subset number > 0 and < %ld\n", tool_name, numberOfSubsets + 1);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
@ -470,8 +470,8 @@ int grib_tool_new_handle_action(grib_runtime_options* options, grib_handle* h)
|
|||
err = grib_set_long(h, "unpack", 2);
|
||||
if (err) {
|
||||
if (options->fail) {
|
||||
fprintf(stderr, "ERROR: unable to unpack data section: %s (message=%d)\n",
|
||||
grib_get_error_message(err), options->handle_count);
|
||||
fprintf(stderr, "%s: Unable to unpack data section: %s (message=%d)\n",
|
||||
tool_name, grib_get_error_message(err), options->handle_count);
|
||||
exit(err);
|
||||
}
|
||||
else {
|
||||
|
@ -489,8 +489,8 @@ int grib_tool_new_handle_action(grib_runtime_options* options, grib_handle* h)
|
|||
err = grib_set_long(h, "unpack", 1);
|
||||
if (err) {
|
||||
if (options->fail) {
|
||||
fprintf(stderr, "ERROR: unable to unpack data section: %s (message=%d)\n",
|
||||
grib_get_error_message(err), options->handle_count);
|
||||
fprintf(stderr, "%s: Unable to unpack data section: %s (message=%d)\n",
|
||||
tool_name, grib_get_error_message(err), options->handle_count);
|
||||
exit(err);
|
||||
}
|
||||
else {
|
||||
|
@ -505,8 +505,8 @@ int grib_tool_new_handle_action(grib_runtime_options* options, grib_handle* h)
|
|||
err = grib_set_long(h, "unpack", 1);
|
||||
if (err) {
|
||||
if (options->fail) {
|
||||
fprintf(stderr, "ERROR: unable to unpack data section: %s (message=%d)\n",
|
||||
grib_get_error_message(err), options->handle_count);
|
||||
fprintf(stderr, "%s: Unable to unpack data section: %s (message=%d)\n",
|
||||
tool_name, grib_get_error_message(err), options->handle_count);
|
||||
exit(err);
|
||||
}
|
||||
else {
|
||||
|
@ -519,7 +519,7 @@ int grib_tool_new_handle_action(grib_runtime_options* options, grib_handle* h)
|
|||
grib_dump_content(h, stdout, options->dump_mode, options->dump_flags, 0);
|
||||
break;
|
||||
default:
|
||||
printf("Unknown JSON option %s\n", json_option);
|
||||
fprintf(stderr, "%s: Unknown JSON option %s\n", tool_name, json_option);
|
||||
exit(1);
|
||||
}
|
||||
if (!strcmp(options->dump_mode, "default")) {
|
||||
|
@ -546,7 +546,7 @@ int grib_tool_new_handle_action(grib_runtime_options* options, grib_handle* h)
|
|||
err = grib_set_long(h, "unpack", 1);
|
||||
if (err) {
|
||||
if (options->fail) {
|
||||
fprintf(stderr, "ERROR: unable to unpack data section: %s\n", grib_get_error_message(err));
|
||||
fprintf(stderr, "%s: unable to unpack data section: %s\n", tool_name, grib_get_error_message(err));
|
||||
exit(err);
|
||||
}
|
||||
else {
|
||||
|
|
|
@ -22,6 +22,7 @@ static int verbose = 0;
|
|||
static const char* OUTPUT_FILENAME_DEFAULT = "split_rdbSubtype.undef.bufr";
|
||||
static const char* OUTPUT_FILENAME_SUBTYPE = "split_rdbSubtype.%ld.bufr";
|
||||
|
||||
const char* tool_name = "bufr_split_by_rdbSubtype";
|
||||
|
||||
static void usage(const char* prog)
|
||||
{
|
||||
|
@ -56,7 +57,7 @@ static int decode_rdbSubtype(const void* msg, long* rdbSubtype)
|
|||
|
||||
edition = (long)grib_decode_unsigned_long(message, &pos_edition, nbits_edition);
|
||||
if (edition != 2 && edition != 3 && edition != 4) {
|
||||
fprintf(stderr, "ERROR: Unsupported BUFR edition: %ld", edition);
|
||||
fprintf(stderr, "%s: Unsupported BUFR edition: %ld", tool_name, edition);
|
||||
return GRIB_DECODING_ERROR;
|
||||
}
|
||||
section1Length = (long)grib_decode_unsigned_long(message, &pos_section1Length, nbits_section1Length);
|
||||
|
@ -73,7 +74,7 @@ static int decode_rdbSubtype(const void* msg, long* rdbSubtype)
|
|||
|
||||
section1Flags = (long)grib_decode_unsigned_long(message, &pos_section1Flags, nbits_section1Flags);
|
||||
if (section1Flags != 0 && section1Flags != 128) {
|
||||
fprintf(stderr, "ERROR: Invalid BUFR section1 flags: %ld", section1Flags);
|
||||
fprintf(stderr, "%s: Invalid BUFR section1 flags: %ld\n", tool_name, section1Flags);
|
||||
return GRIB_DECODING_ERROR;
|
||||
}
|
||||
ecmwfLocalSectionPresent = (bufrHeaderCentre == 98 && section1Flags != 0);
|
||||
|
@ -121,7 +122,7 @@ static int split_file_by_subtype(FILE* in, const char* filename, unsigned long*
|
|||
long rdbSubtype = 0;
|
||||
int status = decode_rdbSubtype(mesg, &rdbSubtype);
|
||||
if (status != GRIB_SUCCESS) {
|
||||
fprintf(stderr, "ERROR: Failed to decode rdbSubtype from message %lu\n", *count);
|
||||
fprintf(stderr, "%s: Failed to decode rdbSubtype from message %lu\n", tool_name, *count);
|
||||
return status;
|
||||
}
|
||||
|
||||
|
@ -135,12 +136,12 @@ static int split_file_by_subtype(FILE* in, const char* filename, unsigned long*
|
|||
}
|
||||
out = fopen(ofilename, "ab");
|
||||
if (!out) {
|
||||
fprintf(stderr, "ERROR: Failed to open output file '%s'\n", ofilename);
|
||||
fprintf(stderr, "%s: Failed to open output file '%s'\n", tool_name, ofilename);
|
||||
perror(ofilename);
|
||||
return GRIB_IO_PROBLEM;
|
||||
}
|
||||
if (fwrite(mesg, 1, size, out) != size) {
|
||||
fprintf(stderr, "ERROR: Failed to append to file '%s'\n", ofilename);
|
||||
fprintf(stderr, "%s: Failed to append to file '%s'\n", tool_name, ofilename);
|
||||
perror(ofilename);
|
||||
fclose(out);
|
||||
return GRIB_IO_PROBLEM;
|
||||
|
@ -178,7 +179,7 @@ int main(int argc, char* argv[])
|
|||
|
||||
filename = argv[i];
|
||||
if (path_is_directory(filename)) {
|
||||
fprintf(stderr, "ERROR: %s: Is a directory\n", filename);
|
||||
fprintf(stderr, "%s: %s: Is a directory\n", tool_name, filename);
|
||||
return 1;
|
||||
}
|
||||
infh = fopen(filename, "rb");
|
||||
|
@ -190,8 +191,7 @@ int main(int argc, char* argv[])
|
|||
count = 0;
|
||||
err = split_file_by_subtype(infh, filename, &count);
|
||||
if (err) {
|
||||
fprintf(stderr, "ERROR: Failed to split BUFR file %s", filename);
|
||||
fprintf(stderr, "\n");
|
||||
fprintf(stderr, "%s: Failed to split BUFR file %s\n", tool_name, filename);
|
||||
status = 1;
|
||||
}
|
||||
else {
|
||||
|
|
Loading…
Reference in New Issue