Skip to content

Commit

Permalink
Testing: Element encoding for integers/doubles
Browse files Browse the repository at this point in the history
  • Loading branch information
shahramn committed Nov 27, 2024
1 parent 87f5931 commit af10b60
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
6 changes: 6 additions & 0 deletions src/accessor/grib_accessor_class_element.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
13 changes: 9 additions & 4 deletions tests/grib_element.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit af10b60

Please sign in to comment.