ECC-1708: grib_get_data returns offset longitudes in some cases

This commit is contained in:
Shahram Najm 2023-10-27 12:07:50 +01:00
parent 4fcb936958
commit c32c4c5bfb
4 changed files with 57 additions and 6 deletions

View File

@ -233,10 +233,14 @@ static int init(grib_iterator* iter, 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] = normalise_longitude_in_degrees(lon2); // Also see ECC-1671
// ECC-1406: Due to rounding, errors can accumulate.
// So we ensure the last longitude is longitudeOfLastGridPointInDegrees
// Also see ECC-1671, ECC-1708
if (lon2 > 0) {
lon2 = normalise_longitude_in_degrees(lon2);
}
self->los[Ni-1] = lon2;
return ret;
}

View File

@ -128,6 +128,7 @@ if( HAVE_BUILD_TOOLS )
grib_ecc-1571
grib_ecc-1654
grib_ecc-1671
grib_ecc-1708
grib_ecc-1691
bufr_ecc-1028
bufr_ecc-1195

View File

@ -16,7 +16,7 @@ tempGrib=temp.$label.grib
tempFilt=temp.${label}.filt
tempOut=temp.${label}.txt
sample2="$samp_dir/GRIB2.tmpl"
sample="$samp_dir/GRIB2.tmpl"
cat > $tempFilt <<EOF
set numberOfDataPoints = 5400000;
@ -32,7 +32,7 @@ cat > $tempFilt <<EOF
write;
EOF
${tools_dir}/grib_filter -o $tempGrib $tempFilt $sample2
${tools_dir}/grib_filter -o $tempGrib $tempFilt $sample
# ${tools_dir}/grib_ls -j -n geography $tempGrib
cat > $tempFilt <<EOF

46
tests/grib_ecc-1708.sh Executable file
View File

@ -0,0 +1,46 @@
#!/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
label="grib_ecc-1708_test"
tempGrib=temp.$label.grib
tempFilt=temp.${label}.filt
tempOut=temp.${label}.txt
sample="$samp_dir/GRIB1.tmpl"
cat > $tempFilt <<EOF
set Ni = 1401;
set Nj = 701;
set latitudeOfFirstGridPoint = 80000;
set longitudeOfFirstGridPoint = -180000;
set latitudeOfLastGridPoint = 10000;
set longitudeOfLastGridPoint = -40000;
set iDirectionIncrement = 100;
set jDirectionIncrement = 100;
write;
EOF
${tools_dir}/grib_filter -o $tempGrib $tempFilt $sample
${tools_dir}/grib_ls -j -n geography $tempGrib
cat > $tempFilt <<EOF
meta last_elem element(distinctLongitudes, 1400);
# print "[last_elem:d]";
if ( last_elem + 40 > 0.001 ) {
print "Error: last longitude is [last_elem:d] but should be -40";
assert(0);
}
EOF
${tools_dir}/grib_filter $tempFilt $tempGrib
rm -f $tempGrib $tempFilt $tempOut