From 5a5eac1b36e5de4a29fcbf3873aab38379a34593 Mon Sep 17 00:00:00 2001 From: shahramn Date: Wed, 10 Jul 2024 13:10:56 +0100 Subject: [PATCH] ECC-1866: GRIB: Setting step on interval-based message with dataDate=0 --- .../grib_accessor_class_g2end_step.cc | 11 ++++++++-- tests/grib_step.sh | 21 ++++++++++++++++++- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/src/accessor/grib_accessor_class_g2end_step.cc b/src/accessor/grib_accessor_class_g2end_step.cc index 78fdfb129..b4a3a2a25 100644 --- a/src/accessor/grib_accessor_class_g2end_step.cc +++ b/src/accessor/grib_accessor_class_g2end_step.cc @@ -413,8 +413,8 @@ int grib_accessor_class_g2end_step_t::unpack_double(grib_accessor* a, double* va static int pack_long_(grib_accessor* a, const long end_step_value, const long end_step_unit) { grib_accessor_g2end_step_t* self = (grib_accessor_g2end_step_t*)a; - grib_handle* h = grib_handle_of_accessor(a); - int err = 0; + grib_handle* h = grib_handle_of_accessor(a); + int err = 0; long year; long month; @@ -491,6 +491,13 @@ static int pack_long_(grib_accessor* a, const long end_step_value, const long en return GRIB_WRONG_STEP; } + if (!is_date_valid(year, month, day, hour, minute, second)) { // ECC-1866 + grib_context_log(h->context, GRIB_LOG_ERROR, "%s:%s: Date/Time is not valid! " + "year=%ld month=%ld day=%ld hour=%ld minute=%ld second=%ld", + a->cclass->name, __func__, year, month, day, hour, minute, second); + return GRIB_DECODING_ERROR; + } + err = grib_datetime_to_julian(year, month, day, hour, minute, second, &dend); if (err != GRIB_SUCCESS) return err; diff --git a/tests/grib_step.sh b/tests/grib_step.sh index 4ed45a3f1..0e0ddebda 100755 --- a/tests/grib_step.sh +++ b/tests/grib_step.sh @@ -256,9 +256,28 @@ cat >$tempFilt < $tempLog -cat $tempLog grep -q "255 8 7" $tempLog +# ECC-1866: Setting step on interval-based message with dataDate=0000 +# ------------------------------------------------------------------- +tempGrbA=${data_dir}/temp.$label.A.grib +tempGrbB=${data_dir}/temp.$label.B.grib +${tools_dir}/grib_set -s stepType=accum $ECCODES_SAMPLES_PATH/GRIB2.tmpl $tempGrbA +set +e +${tools_dir}/grib_set -s year=0,month=0,day=0,step=0 $tempGrbA $tempGrbB 2>$tempLog +status=$? +set -e +[ $status -ne 0 ] +grep -q "Date/Time is not valid" $tempLog + +set +e +${tools_dir}/grib_set -s year=0,month=0,day=0,stepUnits=1 $tempGrbA $tempGrbB 2>$tempLog +status=$? +set -e +[ $status -ne 0 ] +grep -q "Date/Time is not valid" $tempLog +rm -f $tempGrbA $tempGrbB + # Clean up rm -f $temp $tempLog $tempFilt rm -f $grib2File.p8tmp ${grib2File}.tmp x.grib