From 1f99dc511df8a2008a79331a32b3ebf300ae8722 Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Thu, 14 May 2020 20:21:31 +0100 Subject: [PATCH] Examples: write errors to stderr --- examples/C/bufr_attributes.c | 4 ++-- examples/C/bufr_copy_data.c | 8 ++++---- examples/C/bufr_expanded.c | 4 ++-- examples/C/bufr_get_keys.c | 4 ++-- examples/C/bufr_get_string_array.c | 6 +++--- examples/C/bufr_keys_iterator.c | 6 +++--- examples/C/bufr_missing.c | 4 ++-- examples/C/bufr_read_header.c | 4 ++-- examples/C/bufr_read_scatterometer.c | 10 +++++----- examples/C/bufr_read_synop.c | 5 ++--- examples/C/bufr_read_temp.c | 10 +++++----- examples/C/bufr_set_keys.c | 4 ++-- examples/C/get_product_kind.c | 4 ++-- examples/C/grib_ensemble_index.c | 2 +- examples/C/grib_get_data.c | 10 +++++----- examples/C/grib_get_keys.c | 4 ++-- examples/C/grib_index.c | 8 ++++---- examples/C/grib_iterator.c | 2 +- examples/C/grib_keys_iterator.c | 4 ++-- examples/C/grib_list.c | 4 ++-- examples/C/grib_multi.c | 2 +- examples/C/grib_precipitation.c | 2 +- examples/C/grib_precision.c | 6 +++--- examples/C/grib_print_data.c | 4 ++-- examples/C/grib_set_bitmap.c | 7 +++---- examples/C/grib_set_data.c | 2 +- examples/C/grib_set_keys.c | 6 +++--- examples/C/set_missing.c | 6 +++--- examples/C/values_check.c | 6 +++--- 29 files changed, 73 insertions(+), 75 deletions(-) diff --git a/examples/C/bufr_attributes.c b/examples/C/bufr_attributes.c index d234a2b45..1fad88652 100644 --- a/examples/C/bufr_attributes.c +++ b/examples/C/bufr_attributes.c @@ -36,14 +36,14 @@ int main(int argc, char* argv[]) in = fopen(infile, "rb"); if (!in) { - printf("ERROR: unable to open file %s\n", infile); + fprintf(stderr, "Error: unable to open file %s\n", infile); return 1; } /* loop over the messages in the bufr file */ while ((h = codes_handle_new_from_file(NULL, in, PRODUCT_BUFR, &err)) != NULL || err != CODES_SUCCESS) { if (h == NULL) { - printf("Error: unable to create handle for message %d\n", cnt); + fprintf(stderr, "Error: unable to create handle for message %d\n", cnt); cnt++; continue; } diff --git a/examples/C/bufr_copy_data.c b/examples/C/bufr_copy_data.c index b2447c21f..eb816163f 100644 --- a/examples/C/bufr_copy_data.c +++ b/examples/C/bufr_copy_data.c @@ -53,7 +53,7 @@ int main(int argc, char* argv[]) } ho = codes_bufr_handle_new_from_samples(NULL, sampleName); if (ho == NULL) { - fprintf(stderr, "ERROR creating BUFR from %s\n", sampleName); + fprintf(stderr, "Error: creating BUFR from %s\n", sampleName); fclose(f); return 1; } @@ -80,14 +80,14 @@ int main(int argc, char* argv[]) while ((h = codes_handle_new_from_file(0, f, PRODUCT_BUFR, &err)) != NULL) { if (!h) { - printf("ERROR: Unable to create BUFR handle\n"); + fprintf(stderr, "Error: Unable to create BUFR handle\n"); return 1; } /* codes_copy_key(h,ho,"unexpandedDescriptors",0); */ err = codes_set_long(h, "unpack", 1); if (err) { - printf("ERROR: Unable to unpack BUFR message. Quitting\n"); - printf(" %s\n", codes_get_error_message(err)); + fprintf(stderr, "Error: Unable to unpack BUFR message. Quitting\n"); + fprintf(stderr, " %s\n", codes_get_error_message(err)); return 1; } diff --git a/examples/C/bufr_expanded.c b/examples/C/bufr_expanded.c index 53f393971..a18d1040c 100644 --- a/examples/C/bufr_expanded.c +++ b/examples/C/bufr_expanded.c @@ -43,14 +43,14 @@ int main(int argc, char* argv[]) /* open bufr file */ in = fopen(filename, "rb"); if (!in) { - printf("ERROR: unable to open file %s\n", filename); + fprintf(stderr, "Error: unable to open file %s\n", filename); return 1; } /* loop over the messages in the bufr file */ while ((h = codes_handle_new_from_file(NULL, in, PRODUCT_BUFR, &err)) != NULL || err != CODES_SUCCESS) { if (h == NULL) { - printf("Error: unable to create handle for message %d\n", cnt); + fprintf(stderr, "Error: unable to create handle for message %d\n", cnt); cnt++; continue; } diff --git a/examples/C/bufr_get_keys.c b/examples/C/bufr_get_keys.c index e12538c2a..c475c8c6b 100644 --- a/examples/C/bufr_get_keys.c +++ b/examples/C/bufr_get_keys.c @@ -36,14 +36,14 @@ int main(int argc, char* argv[]) in = fopen(infile, "rb"); if (!in) { - printf("ERROR: unable to open file %s\n", infile); + fprintf(stderr, "Error: unable to open file %s\n", infile); return 1; } /* loop over the messages in the bufr file */ while ((h = codes_handle_new_from_file(NULL, in, PRODUCT_BUFR, &err)) != NULL || err != CODES_SUCCESS) { if (h == NULL) { - printf("Error: unable to create handle for message %d\n", cnt); + fprintf(stderr, "Error: unable to create handle for message %d\n", cnt); cnt++; continue; } diff --git a/examples/C/bufr_get_string_array.c b/examples/C/bufr_get_string_array.c index 5c2eb1a0a..1220f04c7 100644 --- a/examples/C/bufr_get_string_array.c +++ b/examples/C/bufr_get_string_array.c @@ -29,14 +29,14 @@ int main(int argc, char* argv[]) FILE* in = fopen(infile, "rb"); if (!in) { - printf("ERROR: unable to open file %s\n", infile); + fprintf(stderr, "Error: unable to open file %s\n", infile); return 1; } /* loop over the messages in the bufr file */ while ((h = codes_handle_new_from_file(NULL, in, PRODUCT_BUFR, &err)) != NULL || err != CODES_SUCCESS) { if (h == NULL) { - printf("Error: unable to create handle for message %d\n", cnt); + fprintf(stderr, "Error: unable to create handle for message %d\n", cnt); cnt++; continue; } @@ -49,7 +49,7 @@ int main(int argc, char* argv[]) CODES_CHECK(codes_get_size(h, "stationOrSiteName", &len), 0); strArray = (char**)malloc(len * sizeof(char*)); if (!strArray) { - printf("Error: Could not allocate memory\n"); + fprintf(stderr, "Error: Could not allocate memory\n"); return 1; } CODES_CHECK(codes_get_string_array(h, "stationOrSiteName", strArray, &size), 0); diff --git a/examples/C/bufr_keys_iterator.c b/examples/C/bufr_keys_iterator.c index 780456333..d3544873a 100644 --- a/examples/C/bufr_keys_iterator.c +++ b/examples/C/bufr_keys_iterator.c @@ -47,7 +47,7 @@ int main(int argc, char* argv[]) in = fopen(filename, "rb"); if (!in) { - printf("ERROR: unable to open file %s\n", filename); + fprintf(stderr, "Error: unable to open file %s\n", filename); return 1; } @@ -55,7 +55,7 @@ int main(int argc, char* argv[]) while ((h = codes_handle_new_from_file(NULL, in, PRODUCT_BUFR, &err)) != NULL || err != CODES_SUCCESS) { codes_bufr_keys_iterator* kiter = NULL; if (h == NULL) { - printf("Error: unable to create handle for message %d\n", cnt); + fprintf(stderr, "Error: unable to create handle for message %d\n", cnt); cnt++; continue; } @@ -68,7 +68,7 @@ int main(int argc, char* argv[]) /* get BUFR key iterator */ kiter = codes_bufr_keys_iterator_new(h, 0); if (!kiter) { - printf("ERROR: Unable to create BUFR keys iterator\n"); + fprintf(stderr, "Error: Unable to create BUFR keys iterator\n"); exit(1); } diff --git a/examples/C/bufr_missing.c b/examples/C/bufr_missing.c index 10a582924..2ff58225f 100644 --- a/examples/C/bufr_missing.c +++ b/examples/C/bufr_missing.c @@ -31,14 +31,14 @@ int main(int argc, char* argv[]) in = fopen(infile, "rb"); if (!in) { - printf("ERROR: unable to open file %s\n", infile); + fprintf(stderr, "Error: unable to open file %s\n", infile); return 1; } /* loop over the messages in the bufr file */ while ((h = codes_handle_new_from_file(NULL, in, PRODUCT_BUFR, &err)) != NULL || err != CODES_SUCCESS) { if (h == NULL) { - printf("Error: unable to create handle for message %d\n", cnt); + fprintf(stderr, "Error: unable to create handle for message %d\n", cnt); cnt++; continue; } diff --git a/examples/C/bufr_read_header.c b/examples/C/bufr_read_header.c index c29482117..125d521ca 100644 --- a/examples/C/bufr_read_header.c +++ b/examples/C/bufr_read_header.c @@ -39,14 +39,14 @@ int main(int argc, char* argv[]) in = fopen(filename, "rb"); if (!in) { - printf("ERROR: unable to open file %s\n", filename); + fprintf(stderr, "Error: unable to open file %s\n", filename); return 1; } /* loop over the messages in the bufr file */ while ((h = codes_handle_new_from_file(NULL, in, PRODUCT_BUFR, &err)) != NULL || err != CODES_SUCCESS) { if (h == NULL) { - printf("Error: unable to create handle for message %d\n", cnt); + fprintf(stderr, "Error: unable to create handle for message %d\n", cnt); cnt++; continue; } diff --git a/examples/C/bufr_read_scatterometer.c b/examples/C/bufr_read_scatterometer.c index 914fe0753..244d8878f 100644 --- a/examples/C/bufr_read_scatterometer.c +++ b/examples/C/bufr_read_scatterometer.c @@ -40,14 +40,14 @@ int main(int argc, char* argv[]) in = fopen(infile, "rb"); if (!in) { - printf("ERROR: unable to open file %s\n", infile); + fprintf(stderr, "Error: unable to open file %s\n", infile); return 1; } /* Loop over the messages in the bufr file */ while ((h = codes_handle_new_from_file(NULL, in, PRODUCT_BUFR, &err)) != NULL || err != CODES_SUCCESS) { if (h == NULL) { - printf("Error: unable to create handle for message %d\n", cnt); + fprintf(stderr, "Error: unable to create handle for message %d\n", cnt); cnt++; continue; } @@ -76,7 +76,7 @@ int main(int argc, char* argv[]) /* Check the size (including all the subsets) */ CODES_CHECK(codes_get_size(h, key_name, &len), 0); if (len != numObs) { - printf("inconsistent number of %s values found!\n", key_name); + fprintf(stderr, "Error: inconsistent number of %s values found!\n", key_name); return 1; } @@ -93,7 +93,7 @@ int main(int argc, char* argv[]) /* Check the size (including all the subsets) */ CODES_CHECK(codes_get_size(h, key_name, &len), 0); if (len != numObs) { - printf("inconsistent number of %s values found!\n", key_name); + fprintf(stderr, "Error: inconsistent number of %s values found!\n", key_name); return 1; } @@ -107,7 +107,7 @@ int main(int argc, char* argv[]) /* Check the size (including all the subsets) */ CODES_CHECK(codes_get_size(h, key_name, &len), 0); if (len != numObs) { - printf("inconsistent number of %s values found!\n", key_name); + fprintf(stderr, "Error: inconsistent number of %s values found!\n", key_name); return 1; } diff --git a/examples/C/bufr_read_synop.c b/examples/C/bufr_read_synop.c index 280c17bba..8e0d8557a 100644 --- a/examples/C/bufr_read_synop.c +++ b/examples/C/bufr_read_synop.c @@ -21,7 +21,6 @@ * example. It is advised to use bufr_dump to understand the structure of the messages. */ - #include "eccodes.h" int main(int argc, char* argv[]) @@ -39,14 +38,14 @@ int main(int argc, char* argv[]) in = fopen(infile, "rb"); if (!in) { - printf("ERROR: unable to open file %s\n", infile); + fprintf(stderr, "Error: unable to open file %s\n", infile); return 1; } /* loop over the messages in the bufr file */ while ((h = codes_handle_new_from_file(NULL, in, PRODUCT_BUFR, &err)) != NULL || err != CODES_SUCCESS) { if (h == NULL) { - printf("Error: unable to create handle for message %d\n", cnt); + fprintf(stderr, "Error: unable to create handle for message %d\n", cnt); cnt++; continue; } diff --git a/examples/C/bufr_read_temp.c b/examples/C/bufr_read_temp.c index 2b8247459..0e7056372 100644 --- a/examples/C/bufr_read_temp.c +++ b/examples/C/bufr_read_temp.c @@ -47,14 +47,14 @@ int main(int argc, char* argv[]) in = fopen(infile, "rb"); if (!in) { - printf("ERROR: unable to open file %s\n", infile); + fprintf(stderr, "Error: unable to open file %s\n", infile); return 1; } /* Loop over the messages in the bufr file */ while ((h = codes_handle_new_from_file(NULL, in, PRODUCT_BUFR, &err)) != NULL || err != CODES_SUCCESS) { if (h == NULL) { - printf("Error: unable to create handle for message %d\n", cnt); + fprintf(stderr, "Error: unable to create handle for message %d\n", cnt); cnt++; continue; } @@ -104,7 +104,7 @@ int main(int argc, char* argv[]) /* Check the size */ CODES_CHECK(codes_get_size(h, key_name, &len), 0); if (len != sigt_len) { - printf("inconsistent number of geopotential values found!\n"); + fprintf(stderr, "Error: inconsistent number of geopotential values found!\n"); free_memory(sigt_pres, sigt_geo, sigt_t, sigt_td); return 1; } @@ -114,7 +114,7 @@ int main(int argc, char* argv[]) /* Get temperature */ if (len != sigt_len) { /* Check the size */ - printf("inconsistent number of temperature values found!\n"); + fprintf(stderr, "Error: inconsistent number of temperature values found!\n"); free_memory(sigt_pres, sigt_geo, sigt_t, sigt_td); return 1; } @@ -125,7 +125,7 @@ int main(int argc, char* argv[]) /* Get dew point */ if (len != sigt_len) { /* Check the size */ - printf("inconsistent number of dewpoint temperature values found!\n"); + fprintf(stderr, "Error: inconsistent number of dewpoint temperature values found!\n"); free_memory(sigt_pres, sigt_geo, sigt_t, sigt_td); return 1; } diff --git a/examples/C/bufr_set_keys.c b/examples/C/bufr_set_keys.c index b56d490c3..a3f383d4d 100644 --- a/examples/C/bufr_set_keys.c +++ b/examples/C/bufr_set_keys.c @@ -48,7 +48,7 @@ int main(int argc, char* argv[]) out = fopen(argv[1], "wb"); if (!in || !out) { - perror("ERROR: unable to open files"); + perror("Error: unable to open files"); if (out) fclose(out); if (in) fclose(in); return 1; @@ -57,7 +57,7 @@ int main(int argc, char* argv[]) /* loop over the messages in the bufr file */ while ((h = codes_handle_new_from_file(NULL, in, PRODUCT_BUFR, &err)) != NULL || err != CODES_SUCCESS) { if (h == NULL) { - printf("Error: unable to create handle for message %d\n", cnt); + fprintf(stderr, "Error: unable to create handle for message %d\n", cnt); cnt++; continue; } diff --git a/examples/C/get_product_kind.c b/examples/C/get_product_kind.c index 30b471352..6ce47d6d2 100644 --- a/examples/C/get_product_kind.c +++ b/examples/C/get_product_kind.c @@ -36,13 +36,13 @@ int main(int argc, char* argv[]) infile = argv[1]; in = fopen(infile, "rb"); if (!in) { - printf("ERROR: unable to open file %s\n", infile); + fprintf(stderr, "Error: unable to open file %s\n", infile); return 1; } while ((h = codes_handle_new_from_file(NULL, in, PRODUCT_ANY, &err)) != NULL || err != CODES_SUCCESS) { if (h == NULL) { - printf("Error: unable to create handle for message %d\n", cnt); + fprintf(stderr, "Error: unable to create handle for message %d\n", cnt); cnt++; continue; } diff --git a/examples/C/grib_ensemble_index.c b/examples/C/grib_ensemble_index.c index 1d461f76c..0de9fc260 100644 --- a/examples/C/grib_ensemble_index.c +++ b/examples/C/grib_ensemble_index.c @@ -65,7 +65,7 @@ int main(int argc, char* argv[]) /* create handle for next GRIB message */ h = codes_handle_new_from_index(index, &ret); if (ret) { - printf("Error: %s\n", codes_get_error_message(ret)); + fprintf(stderr, "Error: %s\n", codes_get_error_message(ret)); exit(ret); } diff --git a/examples/C/grib_get_data.c b/examples/C/grib_get_data.c index 04ca6f14c..7670aa66e 100644 --- a/examples/C/grib_get_data.c +++ b/examples/C/grib_get_data.c @@ -32,14 +32,14 @@ int main(int argc, char** argv) in = fopen(filename, "rb"); if (!in) { - printf("ERROR: unable to open input file %s\n", filename); + fprintf(stderr, "Error: unable to open input file %s\n", filename); return 1; } /* create new handle from a message in a file */ h = codes_handle_new_from_file(0, in, PRODUCT_GRIB, &err); if (h == NULL) { - printf("Error: unable to create handle from file %s\n", filename); + fprintf(stderr, "Error: unable to create handle from file %s\n", filename); return 1; } @@ -48,18 +48,18 @@ int main(int argc, char** argv) lats = (double*)malloc(numberOfPoints * sizeof(double)); if (!lats) { - printf("unable to allocate %ld bytes\n", (long)(numberOfPoints * sizeof(double))); + fprintf(stderr, "Error: unable to allocate %ld bytes\n", (long)(numberOfPoints * sizeof(double))); return 1; } lons = (double*)malloc(numberOfPoints * sizeof(double)); if (!lons) { - printf("unable to allocate %ld bytes\n", (long)(numberOfPoints * sizeof(double))); + fprintf(stderr, "Error: unable to allocate %ld bytes\n", (long)(numberOfPoints * sizeof(double))); free(lats); return 1; } values = (double*)malloc(numberOfPoints * sizeof(double)); if (!values) { - printf("unable to allocate %ld bytes\n", (long)(numberOfPoints * sizeof(double))); + fprintf(stderr, "Error: unable to allocate %ld bytes\n", (long)(numberOfPoints * sizeof(double))); free(lats); free(lons); return 1; diff --git a/examples/C/grib_get_keys.c b/examples/C/grib_get_keys.c index 916a48171..59d5034fe 100644 --- a/examples/C/grib_get_keys.c +++ b/examples/C/grib_get_keys.c @@ -46,14 +46,14 @@ int main(int argc, char** argv) in = fopen(filename, "rb"); if (!in) { - printf("ERROR: unable to open file %s\n", filename); + fprintf(stderr, "Error: unable to open file %s\n", filename); return 1; } /* create new handle from the first message in the file*/ h = codes_handle_new_from_file(0, in, PRODUCT_GRIB, &err); if (h == NULL) { - printf("Error: unable to create handle from file %s\n", filename); + fprintf(stderr, "Error: unable to create handle from file %s\n", filename); return 1; } fclose(in); diff --git a/examples/C/grib_index.c b/examples/C/grib_index.c index 1faf3cd92..1967948d8 100644 --- a/examples/C/grib_index.c +++ b/examples/C/grib_index.c @@ -45,14 +45,14 @@ int main(int argc, char* argv[]) /* Create an index given set of keys*/ index = codes_index_new(0, "shortName,level,number,step", &ret); if (ret) { - printf("error: %s\n", codes_get_error_message(ret)); + fprintf(stderr, "Error: %s\n", codes_get_error_message(ret)); exit(ret); } /* Indexes a file */ ret = codes_index_add_file(index, infile); if (ret) { - printf("error: %s\n", codes_get_error_message(ret)); + fprintf(stderr, "Error: %s\n", codes_get_error_message(ret)); exit(ret); } printf("end indexing...\n"); @@ -128,7 +128,7 @@ int main(int argc, char* argv[]) while ((h = codes_handle_new_from_index(index, &ret)) != NULL) { count++; if (ret) { - printf("error: %d\n", ret); + fprintf(stderr, "Error: %d\n", ret); exit(ret); } lenshortName = 200; @@ -143,7 +143,7 @@ int main(int argc, char* argv[]) codes_handle_delete(h); } if (ret && ret != GRIB_END_OF_INDEX) { - printf("error: %s\n", codes_get_error_message(ret)); + fprintf(stderr, "Error: %s\n", codes_get_error_message(ret)); exit(ret); } } diff --git a/examples/C/grib_iterator.c b/examples/C/grib_iterator.c index 122160817..92d8650f6 100644 --- a/examples/C/grib_iterator.c +++ b/examples/C/grib_iterator.c @@ -46,7 +46,7 @@ int main(int argc, char** argv) in = fopen(filename, "rb"); if (!in) { - printf("ERROR: unable to open file %s\n", filename); + fprintf(stderr, "Error: unable to open file %s\n", filename); return 1; } diff --git a/examples/C/grib_keys_iterator.c b/examples/C/grib_keys_iterator.c index dcff27c21..62a71f8a8 100644 --- a/examples/C/grib_keys_iterator.c +++ b/examples/C/grib_keys_iterator.c @@ -69,13 +69,13 @@ int main(int argc, char* argv[]) msg_count++; printf("-- GRIB N. %d --\n", msg_count); if (!h) { - printf("ERROR: Unable to create grib handle\n"); + fprintf(stderr, "Error: Unable to create grib handle\n"); exit(1); } kiter = codes_keys_iterator_new(h, key_iterator_filter_flags, name_space); if (!kiter) { - printf("ERROR: Unable to create keys iterator\n"); + fprintf(stderr, "Error: Unable to create keys iterator\n"); exit(1); } diff --git a/examples/C/grib_list.c b/examples/C/grib_list.c index aabfc0381..9ce006919 100644 --- a/examples/C/grib_list.c +++ b/examples/C/grib_list.c @@ -37,14 +37,14 @@ int main(int argc, char** argv) in = fopen(filename, "rb"); if (!in) { - printf("ERROR: unable to open input file %s\n", filename); + fprintf(stderr, "Error: unable to open input file %s\n", filename); return 1; } /* create new handle from a message in a file*/ h = codes_handle_new_from_file(0, in, PRODUCT_GRIB, &err); if (h == NULL) { - printf("Error: unable to create handle from file %s\n", filename); + fprintf(stderr, "Error: unable to create handle from file %s\n", filename); } CODES_CHECK(codes_get_long(h, "numberOfContributingSpectralBands", &numberOfContributingSpectralBands), 0); diff --git a/examples/C/grib_multi.c b/examples/C/grib_multi.c index 1f29975a6..93ea8ad02 100644 --- a/examples/C/grib_multi.c +++ b/examples/C/grib_multi.c @@ -37,7 +37,7 @@ int main(int argc, char** argv) in = fopen(filename, "rb"); if (!in) { - printf("ERROR: unable to open file %s\n", filename); + fprintf(stderr, "Error: unable to open file %s\n", filename); return 1; } diff --git a/examples/C/grib_precipitation.c b/examples/C/grib_precipitation.c index 2a0431502..5e6297364 100644 --- a/examples/C/grib_precipitation.c +++ b/examples/C/grib_precipitation.c @@ -47,7 +47,7 @@ int main(int argc, char** argv) in = fopen(filename, "rb"); if (!in) { - printf("ERROR: unable to open file %s\n", filename); + fprintf(stderr, "ERROR: unable to open file %s\n", filename); return 1; } diff --git a/examples/C/grib_precision.c b/examples/C/grib_precision.c index a1838cf22..d24f20793 100644 --- a/examples/C/grib_precision.c +++ b/examples/C/grib_precision.c @@ -47,13 +47,13 @@ int main(int argc, char** argv) in = fopen(infile, "rb"); if (!in) { - printf("ERROR: unable to open input file %s\n", infile); + fprintf(stderr, "Error: unable to open input file %s\n", infile); return 1; } out = fopen(outfile, "wb"); if (!out) { - printf("ERROR: unable to open output file %s\n", outfile); + fprintf(stderr, "Error: unable to open output file %s\n", outfile); fclose(in); return 1; } @@ -61,7 +61,7 @@ int main(int argc, char** argv) /* create a new handle from a message in a file */ h = codes_handle_new_from_file(0, in, PRODUCT_GRIB, &err); if (h == NULL) { - printf("Error: unable to create handle from file %s\n", infile); + fprintf(stderr, "Error: unable to create handle from file %s\n", infile); } /* bitsPerValue before changing the packing parameters */ diff --git a/examples/C/grib_print_data.c b/examples/C/grib_print_data.c index 915ea4cac..beab7a4d6 100644 --- a/examples/C/grib_print_data.c +++ b/examples/C/grib_print_data.c @@ -41,14 +41,14 @@ int main(int argc, char** argv) in = fopen(filename, "rb"); if (!in) { - printf("ERROR: unable to open file %s\n", filename); + fprintf(stderr, "Error: unable to open file %s\n", filename); return 1; } /* create new handle from a message in a file*/ h = codes_handle_new_from_file(0, in, PRODUCT_GRIB, &err); if (h == NULL) { - printf("Error: unable to create handle from file %s\n", filename); + fprintf(stderr, "Error: unable to create handle from file %s\n", filename); } /* get the size of the values array*/ diff --git a/examples/C/grib_set_bitmap.c b/examples/C/grib_set_bitmap.c index 16baafe9e..2db451cff 100644 --- a/examples/C/grib_set_bitmap.c +++ b/examples/C/grib_set_bitmap.c @@ -13,7 +13,6 @@ * * Description: how to set a bitmap in a GRIB message * - * */ #include @@ -39,20 +38,20 @@ int main(int argc, char** argv) in = fopen(infile, "rb"); if (!in) { - printf("ERROR: unable to open input file %s\n", infile); + fprintf(stderr, "Error: unable to open input file %s\n", infile); return 1; } out = fopen(outfile, "wb"); if (!out) { - printf("ERROR: unable to open output file %s\n", outfile); + fprintf(stderr, "Error: unable to open output file %s\n", outfile); fclose(in); return 1; } h = codes_handle_new_from_file(0, in, PRODUCT_GRIB, &err); if (h == NULL) { - printf("Error: unable to create handle from file %s\n", infile); + fprintf(stderr, "Error: unable to create handle from file %s\n", infile); } CODES_CHECK(codes_set_double(h, "missingValue", missing), 0); diff --git a/examples/C/grib_set_data.c b/examples/C/grib_set_data.c index 2b5918763..a23bdf0ac 100644 --- a/examples/C/grib_set_data.c +++ b/examples/C/grib_set_data.c @@ -49,7 +49,7 @@ int main(int argc, char** argv) printf("Using samples path: %s\n", samples_path); h = codes_grib_handle_new_from_samples(0, sample_filename); if (h == NULL) { - printf("Error: unable to create handle from sample file %s\n", sample_filename); + fprintf(stderr, "Error: unable to create handle from sample file %s\n", sample_filename); exit(1); } diff --git a/examples/C/grib_set_keys.c b/examples/C/grib_set_keys.c index f800dea93..bd623008f 100644 --- a/examples/C/grib_set_keys.c +++ b/examples/C/grib_set_keys.c @@ -38,13 +38,13 @@ int main(int argc, char** argv) in = fopen(infile, "rb"); if (!in) { - printf("ERROR: unable to open file %s\n", infile); + fprintf(stderr, "Error: unable to open file %s\n", infile); return 1; } out = fopen(outfile, "wb"); if (!out) { - printf("ERROR: unable to open file %s\n", outfile); + fprintf(stderr, "Error: unable to open file %s\n", outfile); fclose(in); return 1; } @@ -52,7 +52,7 @@ int main(int argc, char** argv) /* create a new handle from a message in a file */ h = codes_handle_new_from_file(0, in, PRODUCT_GRIB, &err); if (h == NULL) { - printf("Error: unable to create handle from file %s\n", infile); + fprintf(stderr, "Error: unable to create handle from file %s\n", infile); } /* set centre as a long */ diff --git a/examples/C/set_missing.c b/examples/C/set_missing.c index cae2ab76a..487306999 100644 --- a/examples/C/set_missing.c +++ b/examples/C/set_missing.c @@ -36,13 +36,13 @@ int main(int argc, char** argv) in = fopen(infile, "rb"); if (!in) { - printf("ERROR: unable to open input file %s\n", infile); + fprintf(stderr, "Error: unable to open input file %s\n", infile); return 1; } out = fopen(outfile, "wb"); if (!out) { - printf("ERROR: unable to open output file %s\n", outfile); + fprintf(stderr, "Error: unable to open output file %s\n", outfile); fclose(in); return 1; } @@ -50,7 +50,7 @@ int main(int argc, char** argv) /* create a new handle from a message in a file */ h = codes_handle_new_from_file(0, in, PRODUCT_GRIB, &err); if (h == NULL) { - printf("Error: unable to create handle from file %s\n", infile); + fprintf(stderr, "Error: unable to create handle from file %s\n", infile); } CODES_CHECK(codes_set_string(h, "typeOfFirstFixedSurface", str, &str_len), 0); diff --git a/examples/C/values_check.c b/examples/C/values_check.c index abb155487..0db03e54d 100644 --- a/examples/C/values_check.c +++ b/examples/C/values_check.c @@ -29,7 +29,7 @@ int main(int argc, char* argv[]) h = codes_handle_new_from_file(c, f, PRODUCT_GRIB, &err); if (!h) { - printf("unable to create handle from file %s\n", infile); + fprintf(stderr, "unable to create handle from file %s\n", infile); exit(err); } fclose(f); @@ -48,7 +48,7 @@ int main(int argc, char* argv[]) for (i = 0; i < nvalues; i++) { if (values[i].error == err) name = (char*)values[i].name; } - printf("ERROR: \"%s\" %s\n", name, codes_get_error_message(err)); + fprintf(stderr, "Error: \"%s\" %s\n", name, codes_get_error_message(err)); } values[1].name = "levelll"; @@ -57,7 +57,7 @@ int main(int argc, char* argv[]) for (i = 0; i < nvalues; i++) { if (values[i].error == err) name = (char*)values[i].name; } - printf("ERROR: \"%s\" %s\n", name, codes_get_error_message(err)); + fprintf(stderr, "Error: \"%s\" %s\n", name, codes_get_error_message(err)); } return 0;