mirror of https://github.com/ecmwf/eccodes.git
ECC-1792: GRIB: headers_only cloning does not work as expected after changing geography
This commit is contained in:
parent
0075df3c3b
commit
dbc307dd59
|
@ -221,6 +221,13 @@ static int value_count(grib_accessor* a, long* len)
|
|||
}
|
||||
*len = size;
|
||||
|
||||
// See ECC-1792
|
||||
// Give priority to the Grid Section (rather than the Data Section)
|
||||
long numberOfDataPoints = 0;
|
||||
if (grib_get_long(h, "numberOfDataPoints", &numberOfDataPoints) == GRIB_SUCCESS) {
|
||||
*len = numberOfDataPoints;
|
||||
}
|
||||
|
||||
if (self->distinct) {
|
||||
ret = get_distinct(a, &val, len);
|
||||
if (ret != GRIB_SUCCESS)
|
||||
|
|
|
@ -196,6 +196,13 @@ static int value_count(grib_accessor* a, long* len)
|
|||
}
|
||||
*len = size;
|
||||
|
||||
// See ECC-1792
|
||||
// Give priority to the Grid Section (rather than the Data Section)
|
||||
long numberOfDataPoints = 0;
|
||||
if (grib_get_long(h, "numberOfDataPoints", &numberOfDataPoints) == GRIB_SUCCESS) {
|
||||
*len = numberOfDataPoints;
|
||||
}
|
||||
|
||||
if (self->distinct) {
|
||||
ret = get_distinct(a, &val, len);
|
||||
if (ret != GRIB_SUCCESS)
|
||||
|
|
|
@ -193,12 +193,21 @@ static int init(grib_iterator* iter, grib_handle* h, grib_arguments* args)
|
|||
if ((err = grib_get_long_internal(h, s_numPoints, &numberOfPoints)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
|
||||
if (numberOfPoints != dli) {
|
||||
grib_context_log(h->context, GRIB_LOG_ERROR, "Geoiterator: %s != size(%s) (%ld!=%ld)",
|
||||
s_numPoints, s_rawData, numberOfPoints, dli);
|
||||
return GRIB_WRONG_GRID;
|
||||
// See ECC-1792. If we don't want to decode the Data Section, we should not do a check
|
||||
// to see if it is consistent with the Grid Section
|
||||
if (iter->flags & GRIB_GEOITERATOR_NO_VALUES) {
|
||||
// Iterator's number of values taken from the Grid Section
|
||||
iter->nv = numberOfPoints;
|
||||
} else {
|
||||
// Check for consistency between the Grid and Data Sections
|
||||
if (numberOfPoints != dli) {
|
||||
grib_context_log(h->context, GRIB_LOG_ERROR, "Geoiterator: %s != size(%s) (%ld!=%ld)",
|
||||
s_numPoints, s_rawData, numberOfPoints, dli);
|
||||
return GRIB_WRONG_GRID;
|
||||
}
|
||||
iter->nv = dli;
|
||||
}
|
||||
iter->nv = dli;
|
||||
|
||||
if (iter->nv == 0) {
|
||||
grib_context_log(h->context, GRIB_LOG_ERROR, "Geoiterator: size(%s) is %ld", s_rawData, dli);
|
||||
return GRIB_WRONG_GRID;
|
||||
|
|
|
@ -266,6 +266,7 @@ if( HAVE_BUILD_TOOLS )
|
|||
grib_ecc-1425
|
||||
grib_ecc-1467
|
||||
grib_ecc-1764
|
||||
grib_ecc-1792
|
||||
grib_sub_hourly
|
||||
grib_set_bytes
|
||||
grib_set_force
|
||||
|
|
|
@ -0,0 +1,57 @@
|
|||
#!/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
|
||||
|
||||
REDIRECT=/dev/null
|
||||
|
||||
label="grib_ecc-1792_test"
|
||||
tempGrib=temp.$label.grib
|
||||
tempFilt=temp.$label.filt
|
||||
tempLog=temp.$label.log
|
||||
tempRef=temp.$label.ref
|
||||
|
||||
sample_grib2=$ECCODES_SAMPLES_PATH/GRIB2.tmpl
|
||||
|
||||
# Create a message with its Data Section out-of-sync with its Grid
|
||||
${tools_dir}/grib_set -s numberOfValues=2 $sample_grib2 $tempGrib
|
||||
grib_check_key_equals $tempGrib numberOfDataPoints 496
|
||||
|
||||
# grib_get_data should fail
|
||||
set +e
|
||||
${tools_dir}/grib_get_data $tempGrib > $tempLog 2>&1
|
||||
status=$?
|
||||
set -e
|
||||
[ $status -ne 0 ]
|
||||
grep "Grid description is wrong" $tempLog
|
||||
|
||||
# Just getting lats and lons; no need for Data Section to be in-sync
|
||||
cat >$tempFilt<<EOF
|
||||
print "latitudes = [latitudes]";
|
||||
print "longitudes = [longitudes]";
|
||||
print "distinctLatitudes = [distinctLatitudes]";
|
||||
print "distinctLongitudes = [distinctLongitudes]";
|
||||
EOF
|
||||
${tools_dir}/grib_filter -o $tempGrib $tempFilt $tempGrib
|
||||
|
||||
# latLonValues does require Data Section to be in-sync
|
||||
cat >$tempFilt<<EOF
|
||||
print "[latLonValues]";
|
||||
EOF
|
||||
set +e
|
||||
${tools_dir}/grib_filter -o $tempGrib $tempFilt $tempGrib > $tempLog 2>&1
|
||||
status=$?
|
||||
set -e
|
||||
[ $status -ne 0 ]
|
||||
grep "Grid description is wrong" $tempLog
|
||||
|
||||
|
||||
# Clean up
|
||||
rm -f $tempGrib $tempFilt $tempLog $tempRef
|
Loading…
Reference in New Issue