From af10b6075220162c98266faabea5ac181ca77ac3 Mon Sep 17 00:00:00 2001 From: shahramn Date: Wed, 27 Nov 2024 09:55:59 +0000 Subject: [PATCH] Testing: Element encoding for integers/doubles --- src/accessor/grib_accessor_class_element.cc | 6 ++++++ tests/grib_element.sh | 13 +++++++++---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/accessor/grib_accessor_class_element.cc b/src/accessor/grib_accessor_class_element.cc index 218c246bf..0889a6eb2 100644 --- a/src/accessor/grib_accessor_class_element.cc +++ b/src/accessor/grib_accessor_class_element.cc @@ -90,6 +90,12 @@ int grib_accessor_element_t::pack_long(const long* val, size_t* len) return ret; } + int atype = GRIB_TYPE_UNDEFINED; + if (grib_get_native_type(hand, array_, &atype) == GRIB_SUCCESS && atype == GRIB_TYPE_DOUBLE) { + const double dVal = *val; + return pack_double(&dVal, len); + } + if ((ret = grib_get_size(hand, array_, &size)) != GRIB_SUCCESS) return ret; diff --git a/tests/grib_element.sh b/tests/grib_element.sh index 926d48b6a..193ef8a41 100755 --- a/tests/grib_element.sh +++ b/tests/grib_element.sh @@ -76,16 +76,21 @@ set -e # Encode a single double element in an array input=$data_dir/sample.grib2 cat > $tempFilt < 310 ); + assert ( avg > avg1 ); + assert ( max > max1 ); write; EOF ${tools_dir}/grib_filter -o $tempGrib $tempFilt $input -${tools_dir}/grib_get -p avg $input $tempGrib # Clean up