Testing: Element encoding for integers/doubles

This commit is contained in:
shahramn 2024-11-27 09:55:59 +00:00
parent 87f5931bb8
commit af10b60752
2 changed files with 15 additions and 4 deletions

View File

@ -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;

View File

@ -76,16 +76,21 @@ set -e
# Encode a single double element in an array
input=$data_dir/sample.grib2
cat > $tempFilt <<EOF
print "Before: [min=] [max=]";
transient avg1 = avg;
transient max1 = max;
meta elemN element(values, -1);
assert( elemN < 301 );
print "before: [elemN:d]";
set elemN = 311.0; # value has to be a double
print "after: [elemN:d]";
print "Last elem was: [elemN:d]";
set elemN = 312; # Pass in an integer. Should call pack_double
print "Last elem now: [elemN:d]";
print "After: [min=] [max=]";
assert( elemN > 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