From e85de787cea0284c1c344b4fac94e5b07bc004a6 Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Mon, 13 Feb 2023 14:18:15 +0000 Subject: [PATCH] ECC-1510: Fix the statistics keys: min, max and average --- definitions/grib2/section.6.def | 4 ++++ src/grib_accessor_class_data_run_length_packing.cc | 7 +++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/definitions/grib2/section.6.def b/definitions/grib2/section.6.def index b01be8b5b..5de24c487 100644 --- a/definitions/grib2/section.6.def +++ b/definitions/grib2/section.6.def @@ -50,6 +50,10 @@ if (bitMapIndicator == 255) if (dataRepresentationTemplateNumber == 2 || dataRepresentationTemplateNumber == 3) { transient missingValuesPresent = (missingValueManagementUsed != 0) : read_only; } + if (dataRepresentationTemplateNumber == 200) { + # This template can have undefined values within its Data Section + transient missingValuesPresent = 1; + } } meta md5Section6 md5(offsetSection6,section6Length); diff --git a/src/grib_accessor_class_data_run_length_packing.cc b/src/grib_accessor_class_data_run_length_packing.cc index f5dca1094..46e835716 100644 --- a/src/grib_accessor_class_data_run_length_packing.cc +++ b/src/grib_accessor_class_data_run_length_packing.cc @@ -183,6 +183,7 @@ static int unpack_double(grib_accessor* a, double* val, size_t* len) double level_scale_factor = 0; double* levels = NULL; unsigned char* buf = NULL; + double missingValue = 9999.0; if ((err = grib_get_long_internal(gh, self->seclen, &seclen)) != GRIB_SUCCESS) return err; @@ -196,6 +197,8 @@ static int unpack_double(grib_accessor* a, double* val, size_t* len) return err; if ((err = grib_get_long_internal(gh, self->decimal_scale_factor, &decimal_scale_factor)) != GRIB_SUCCESS) return err; + if ((err = grib_get_double(gh, "missingValue", &missingValue)) != GRIB_SUCCESS) + return err; level_values = (long*)grib_context_malloc_clear(a->context, sizeof(long) * number_of_level_values); level_values_size = number_of_level_values; @@ -206,7 +209,7 @@ static int unpack_double(grib_accessor* a, double* val, size_t* len) number_of_compressed_values = ((seclen - 5) * 8) / bits_per_value; if (number_of_compressed_values == 0 || max_level_value == 0) { for (i = 0; i < number_of_values; i++) { - val[i] = GRIB_MISSING_DOUBLE; + val[i] = missingValue; } return GRIB_SUCCESS; } @@ -220,7 +223,7 @@ static int unpack_double(grib_accessor* a, double* val, size_t* len) } level_scale_factor = grib_power(-decimal_scale_factor, 10.0); levels = (double*)grib_context_malloc_clear(a->context, sizeof(double) * (number_of_level_values + 1)); - levels[0] = 0; + levels[0] = missingValue; for (i = 0; i < number_of_level_values; i++) { levels[i + 1] = level_values[i] * level_scale_factor; }