From 02159affd0d9d9cbf3e31b2d2e60bd282e0fc947 Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Wed, 30 Mar 2022 12:31:02 +0100 Subject: [PATCH] ECC-1375: Cater for Ni missing (reduced grids) --- ...b_accessor_class_change_alternative_row_scanning.c | 11 ++++++++++- tests/grib_change_scanning.sh | 6 ++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/grib_accessor_class_change_alternative_row_scanning.c b/src/grib_accessor_class_change_alternative_row_scanning.c index 2737ddc42..f30c4e50f 100644 --- a/src/grib_accessor_class_change_alternative_row_scanning.c +++ b/src/grib_accessor_class_change_alternative_row_scanning.c @@ -165,11 +165,20 @@ static int pack_long(grib_accessor* a, const long* val, size_t* len) if (*val == 0) return 0; + /* Make sure Ni / Nj are not missing */ + if (grib_is_missing(h, self->Ni, &err) && !err) { + grib_context_log(c, GRIB_LOG_ERROR, "change_alternative_row_scanning: Key %s cannot be 'missing'!", self->Ni); + return GRIB_WRONG_GRID; + } + if (grib_is_missing(h, self->Nj, &err) && !err) { + grib_context_log(c, GRIB_LOG_ERROR, "change_alternative_row_scanning: Key %s cannot be 'missing'!", self->Nj); + return GRIB_WRONG_GRID; + } + if ((err = grib_get_long_internal(h, self->Ni, &Ni)) != GRIB_SUCCESS) return err; if ((err = grib_get_long_internal(h, self->Nj, &Nj)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(h, self->alternativeRowScanning, &alternativeRowScanning)) != GRIB_SUCCESS) return err; diff --git a/tests/grib_change_scanning.sh b/tests/grib_change_scanning.sh index b102d1a21..01295413b 100755 --- a/tests/grib_change_scanning.sh +++ b/tests/grib_change_scanning.sh @@ -115,6 +115,12 @@ Latitude Longitude Value EOF diff $tempRef $tempText +# It must fail when Ni=missing (reduced grids) +set +e +${tools_dir}/grib_set -s swapScanningAlternativeRows=1 $ECCODES_SAMPLES_PATH/reduced_gg_pl_96_grib2.tmpl $tempGribB 2>/dev/null +status=$? +set -e +[ $status -ne 0 ] # Clean up rm -f $tempFilt $tempGribA $tempGribB $tempRef $tempText