From d0e0764a65078bcc30a4d70469681e39070ff4e8 Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Mon, 30 Apr 2018 15:42:52 +0100 Subject: [PATCH] ECC-685: grib_to_netcdf: fails with GRIB message with almost constant values --- tools/grib_to_netcdf.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tools/grib_to_netcdf.c b/tools/grib_to_netcdf.c index 6c8f34f4b..cdde4f1a5 100644 --- a/tools/grib_to_netcdf.c +++ b/tools/grib_to_netcdf.c @@ -2398,6 +2398,12 @@ static int compute_scale(dataset_t *subset) scaled_min = rint((min - ao) / sf); scaled_median = rint((median - ao) / sf); + if (scaled_max > nc_type_values[idx].nc_type_max) { + grib_context_log(ctx, GRIB_LOG_DEBUG, "grib_to_netcdf: scaled_max (=%lld) > nc_type_max (=%lf). Set sf to 1.0", + scaled_max, nc_type_values[idx].nc_type_max); + sf = 1.0; /* ECC-685 */ + } + test_scaled_max = (char) scaled_max; test_scaled_min = (char) scaled_min; test_scaled_median = (char) scaled_median;