From 1e456b745fc1b50d74451ad48935a8de71b13cb0 Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Thu, 16 Jun 2022 20:16:00 +0100 Subject: [PATCH] ECC-1406: GRIB: grib_ls -l reports last grid point is out of area --- src/grib_iterator_class_latlon.c | 4 +++ src/grib_iterator_class_regular.c | 4 +++ tests/CMakeLists.txt | 1 + tests/grib_ecc-1406.sh | 49 +++++++++++++++++++++++++++++++ 4 files changed, 58 insertions(+) create mode 100755 tests/grib_ecc-1406.sh diff --git a/src/grib_iterator_class_latlon.c b/src/grib_iterator_class_latlon.c index 246969cbf..deab88802 100644 --- a/src/grib_iterator_class_latlon.c +++ b/src/grib_iterator_class_latlon.c @@ -211,6 +211,10 @@ static int init(grib_iterator* iter, grib_handle* h, grib_arguments* args) self->las[lai] = lat1; lat1 -= jdir; } + /* ECC-1406: Due to rounding, errors can accumulate. + * So we ensure the last latitude is latitudeOfLastGridPointInDegrees + */ + self->las[self->Nj-1] = lat2; iter->e = -1; return err; diff --git a/src/grib_iterator_class_regular.c b/src/grib_iterator_class_regular.c index ef988b9c3..d4e5c652b 100644 --- a/src/grib_iterator_class_regular.c +++ b/src/grib_iterator_class_regular.c @@ -220,6 +220,10 @@ static int init(grib_iterator* i, grib_handle* h, grib_arguments* args) self->los[loi] = lon1; lon1 += idir; } + /* ECC-1406: Due to rounding, errors can accumulate. + * So we ensure the last longitude is longitudeOfLastGridPointInDegrees + */ + self->los[Ni-1] = lon2; return ret; } diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 98a13d72e..5f915d6e5 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -96,6 +96,7 @@ if( HAVE_BUILD_TOOLS ) grib_ecc-1315 grib_ecc-1322 grib_ecc-1319 + grib_ecc-1406 bufr_ecc-1028 bufr_ecc-1195 bufr_ecc-1259 diff --git a/tests/grib_ecc-1406.sh b/tests/grib_ecc-1406.sh new file mode 100755 index 000000000..ace8e0031 --- /dev/null +++ b/tests/grib_ecc-1406.sh @@ -0,0 +1,49 @@ +#!/bin/sh +# (C) Copyright 2005- ECMWF. +# +# This software is licensed under the terms of the Apache Licence Version 2.0 +# which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. +# +# In applying this licence, ECMWF does not waive the privileges and immunities granted to it by +# virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. +# + +. ./include.ctest.sh +set -u +REDIRECT=/dev/null +label="grib_ecc-1406_test" + +tempGrib=temp.$label.grib +tempFilt=temp.${label}.filt +tempOut=temp.${label}.txt + +sample2="$samp_dir/GRIB2.tmpl" + +cat > $tempFilt < $tempOut + +grep -q "Grid Point chosen #1 index=5016590" $tempOut +grep -q "grid_simple 42" $tempOut + +${tools_dir}/grib_ls -j -l 37.5,16.0,1 $tempGrib > $tempOut +grep -q 'latitude" : 37.5, "longitude" : 16, "distance" : 0,.*"value" : 42 ,' $tempOut + +rm -f $tempGrib $tempFilt $tempOut