Merge pull request #189 from ecmwf/feature/pack_expression_improvement

Expression packing: Use the type of the expression and not the accessor
This commit is contained in:
shahramn 2024-01-26 11:49:43 +00:00 committed by GitHub
commit b186eccc4c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 25 additions and 3 deletions

View File

@ -404,7 +404,8 @@ static int pack_expression(grib_accessor* a, grib_expression* e)
int ret = 0;
grib_handle* hand = grib_handle_of_accessor(a);
switch (grib_accessor_get_native_type(a)) {
// Use the native type of the expression not the accessor
switch (grib_expression_native_type(hand, e)) {
case GRIB_TYPE_LONG: {
len = 1;
ret = grib_expression_evaluate_long(hand, e, &lval);
@ -542,7 +543,7 @@ static int pack_string(grib_accessor* a, const char* v, size_t* len)
double val = strtod(v, &endPtr);
if (*endPtr) {
grib_context_log(a->context, GRIB_LOG_ERROR,
"%s: Invalid value (%s) for %s. String cannot be converted to a double",
"%s: Invalid value (%s) for key '%s'. String cannot be converted to a double",
__func__, v, a->name);
return GRIB_WRONG_TYPE;
}

View File

@ -30,7 +30,7 @@ set -e
[ $status -ne 0 ]
#cat $tempErr
grep -q "Unable to set values as double" $tempErr
grep -q "String cannot be converted to a double" $tempErr
# Clean up

View File

@ -468,6 +468,27 @@ grib_check_key_equals $temp "-p $keys_s" "18$HOUR-24$HOUR 18$HOUR 24$HOUR"
grib_check_key_equals $temp "-p $keys_i" "24 18 24"
grib_check_key_equals $temp "-p $keys_d" "24 18 24"
# Pack expression
cat >$tempFilt<<EOF
set step="16m"; write;
EOF
${tools_dir}/grib_filter -o $temp $tempFilt $sample_g2
grib_check_key_equals $temp "-p indicatorOfUnitOfTimeRange,forecastTime" "0 16"
cat >$tempFilt<<EOF
set stepUnits="s"; set step="16"; write;
EOF
${tools_dir}/grib_filter -o $temp $tempFilt $sample_g2
grib_check_key_equals $temp "-p indicatorOfUnitOfTimeRange,forecastTime" "13 16"
cat >$tempFilt<<EOF
set stepUnits="s"; set step=16; write;
EOF
${tools_dir}/grib_filter -o $temp $tempFilt $sample_g2
grib_check_key_equals $temp "-p indicatorOfUnitOfTimeRange,forecastTime" "13 16"
cat >$tempFilt<<EOF
set stepUnits="m"; print "[step]";
EOF