From 9c5df40768641bf48e0e4c24e30e8563a1f46fab Mon Sep 17 00:00:00 2001 From: shahramn Date: Sat, 9 Mar 2024 19:47:41 +0000 Subject: [PATCH] Testing: bitsPerValue --- tests/grib_bpv_limit.cc | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/tests/grib_bpv_limit.cc b/tests/grib_bpv_limit.cc index 97be2e39c..896e0cff7 100644 --- a/tests/grib_bpv_limit.cc +++ b/tests/grib_bpv_limit.cc @@ -34,28 +34,24 @@ static int check_error_code(int err) int main(int argc, char** argv) { - int err = 0, i; + int err = 0, i; size_t values_len = 0; - double* values = NULL; - char error_msg[100]; const double tolerance = 1e-5; - size_t slong = sizeof(long) * 8; - grib_handle* h; - char* filename; + size_t slong = sizeof(long) * 8; Assert(argc == 2); - filename = argv[1]; + char* filename = argv[1]; for (i = 0; i < 255; i++) { FILE* in = fopen(filename, "rb"); Assert(in); - h = grib_handle_new_from_file(0, in, &err); + grib_handle* h = grib_handle_new_from_file(0, in, &err); Assert(h); /* get the size of the values array*/ GRIB_CHECK(grib_get_size(h, "values", &values_len), 0); - values = (double*)malloc(values_len * sizeof(double)); + double* values = (double*)malloc(values_len * sizeof(double)); err = grib_get_double_array(h, "values", values, &values_len); if (compare_double_absolute(values[0], 2.7900000000e+02, tolerance) != 0) @@ -82,9 +78,8 @@ int main(int argc, char** argv) /* do nothing */ } else { - snprintf(error_msg, sizeof(error_msg), "Error decoding when bpv=%d. Error message:%s", i, grib_get_error_message(err)); - perror(error_msg); - exit(1); + fprintf(stderr, "Error decoding when bpv=%d. Error message:%s\n", i, grib_get_error_message(err)); + return 1; } values = (double*)malloc(values_len * sizeof(double)); @@ -102,9 +97,8 @@ int main(int argc, char** argv) /* do nothing */ } else { - snprintf(error_msg, sizeof(error_msg), "Error decoding when bpv=%d. Error message:%s", i, grib_get_error_message(err)); - perror(error_msg); - exit(1); + fprintf(stderr, "Error decoding when bpv=%d. Error message:%s\n", i, grib_get_error_message(err)); + return 1; } free(values);