From def66fe512bad1f3fef121a2bce855570c433817 Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Wed, 21 Dec 2022 11:23:48 +0000 Subject: [PATCH] Testing: Error messages should go to stderr --- examples/C/grib_multi.c | 2 +- examples/C/grib_values_check.c | 4 ++-- examples/C/grib_values_check.sh | 13 ++++++------- examples/C/large_grib1.c | 2 +- examples/F90/multi_fortran.f90 | 2 +- 5 files changed, 11 insertions(+), 12 deletions(-) diff --git a/examples/C/grib_multi.c b/examples/C/grib_multi.c index e5271f250..24479075d 100644 --- a/examples/C/grib_multi.c +++ b/examples/C/grib_multi.c @@ -14,7 +14,7 @@ * Description: How to decode GRIB2 multi-field messages. * Try to turn the multi support on and off to * see the difference. Default is OFF. - * For all the tools default is multi support ON. + * For all the tools (e.g., grib_ls etc) multi support is ON. */ #include #include diff --git a/examples/C/grib_values_check.c b/examples/C/grib_values_check.c index 3c382bfcd..5582c6af6 100644 --- a/examples/C/grib_values_check.c +++ b/examples/C/grib_values_check.c @@ -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)); } codes_handle_delete(h); diff --git a/examples/C/grib_values_check.sh b/examples/C/grib_values_check.sh index 7ac41b52d..4a86131dc 100755 --- a/examples/C/grib_values_check.sh +++ b/examples/C/grib_values_check.sh @@ -10,9 +10,8 @@ . ./include.ctest.sh -#Define a common label for all the tmp files +# Define a common label for all the tmp files label="grib_values_check_c" -tempOut=${label}.tmp.out tempErr=${label}.tmp.err tempRef=${label}.tmp.ref @@ -22,11 +21,11 @@ Error: "levelll" Key/value not found EOF # Input GRIB file path is hard coded in the example -${examples_dir}/c_grib_values_check > $tempOut +${examples_dir}/c_grib_values_check 2> $tempErr -# Compare output with the reference -cat $tempOut -diff $tempRef $tempOut +# Compare stderr with the reference +cat $tempErr +diff $tempRef $tempErr # Clean up -rm -f $tempRef $tempErr $tempOut +rm -f $tempRef $tempErr diff --git a/examples/C/large_grib1.c b/examples/C/large_grib1.c index 0b4b21620..6f5b3dc7a 100644 --- a/examples/C/large_grib1.c +++ b/examples/C/large_grib1.c @@ -26,7 +26,7 @@ int main() numbytes = ni * nj * sizeof(double); values = (double*)malloc(numbytes); if (!values) { - printf("Malloc failed - requested %lu bytes\n", (unsigned long)numbytes); + fprintf(stderr, "Malloc failed - requested %zu bytes\n", numbytes); return 1; } diff --git a/examples/F90/multi_fortran.f90 b/examples/F90/multi_fortran.f90 index 3714ee465..41515fec9 100644 --- a/examples/F90/multi_fortran.f90 +++ b/examples/F90/multi_fortran.f90 @@ -10,7 +10,7 @@ ! Description: How to decode GRIB messages containing multiple ! fields. Try to turn on and off multi support to ! see the difference. Default is OFF. -! For all the tools default is multi support ON. +! For all the tools (e.g., grib_ls etc) multi support is ON. ! ! program multi