From e1576f3aa76088fe8afc077adeb5df71263803e8 Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Wed, 19 Jul 2023 15:58:28 +0000 Subject: [PATCH] ECC-1642: Geoiterator: No error for badly encoded regular grids --- src/grib_iterator_class_regular.cc | 5 ++++ tests/grib_iterator.sh | 37 ++++++++++++++++++++++++------ 2 files changed, 35 insertions(+), 7 deletions(-) diff --git a/src/grib_iterator_class_regular.cc b/src/grib_iterator_class_regular.cc index cc870e70a..3a614a85b 100644 --- a/src/grib_iterator_class_regular.cc +++ b/src/grib_iterator_class_regular.cc @@ -177,6 +177,11 @@ static int init(grib_iterator* iter, grib_handle* h, grib_arguments* args) return GRIB_WRONG_GRID; } + if (Ni*Nj != iter->nv) { + grib_context_log(h->context, GRIB_LOG_ERROR, "Geoiterator: Ni*Nj!=numberOfDataPoints (%ld*%ld!=%zu)", Ni,Nj,iter->nv); + return GRIB_WRONG_GRID; + } + if ((ret = grib_get_long_internal(h, s_iScansNeg, &self->iScansNegatively))) return ret; diff --git a/tests/grib_iterator.sh b/tests/grib_iterator.sh index c8e0ffe78..1c63056cb 100755 --- a/tests/grib_iterator.sh +++ b/tests/grib_iterator.sh @@ -11,7 +11,8 @@ . ./include.ctest.sh label="grib_iterator_test" -temp=temp.$label.txt +tempText=temp.$label.txt +tempGrib=temp.$label.grib files="reduced_latlon_surface.grib1 \ reduced_gaussian_pressure_level.grib1 \ @@ -32,15 +33,37 @@ for f in $files; do [ $numberOfPoints = ${iterator_count} ] done -# ECC-822: Increase lat/lon decimals using default grib_get_data -${tools_dir}/grib_get_data -L%12.6f%11.5f ${data_dir}/regular_latlon_surface.grib2 -${tools_dir}/grib_get_data -p shortName,level ${data_dir}/regular_latlon_surface.grib2 > $temp -grep -q "Latitude Longitude Value shortName level" $temp +# ECC-822: Increase lat/lon decimals using default grib_get_data +${tools_dir}/grib_get_data -L%12.6f%11.5f ${data_dir}/regular_latlon_surface.grib2 > $tempText + +${tools_dir}/grib_get_data -p shortName,level ${data_dir}/regular_latlon_surface.grib2 > $tempText +grep -q "Latitude Longitude Value shortName level" $tempText + # Run on a spectral field - should just print out its values -${tools_dir}/grib_get_data "$samp_dir/sh_ml_grib2.tmpl" +${tools_dir}/grib_get_data "$samp_dir/sh_ml_grib2.tmpl" > $tempText + + +# ECC-1642: badly encoded regular grids +# ------------------------------------- +${tools_dir}/grib_set -s Ni=33 $samp_dir/GRIB2.tmpl $tempGrib +set +e +${tools_dir}/grib_get_data $tempGrib > $tempText 2>&1 +status=$? +set +e +[ $status -ne 0 ] +grep -q "Grid description is wrong or inconsistent" $tempText + + +${tools_dir}/grib_set -s Ni=MISSING $samp_dir/GRIB2.tmpl $tempGrib +set +e +${tools_dir}/grib_get_data $tempGrib > $tempText 2>&1 +status=$? +set +e +[ $status -ne 0 ] +grep -q "Grid description is wrong or inconsistent" $tempText # Clean up -rm -f $temp +rm -f $tempText $tempGrib