ECC-802: Problem with various packing types

This commit is contained in:
Shahram Najm 2022-12-23 19:02:50 +00:00
parent 8a05412b73
commit 6bf7f93712
3 changed files with 38 additions and 3 deletions

View File

@ -479,7 +479,12 @@ static int pack_double(grib_accessor* a, const double* cval, size_t* len)
"grib_accessor_class_data_jpeg2000_packing pack_double: width=%ld height=%ld len=%ld."
" width*height should equal len!",
(long)width, (long)height, (long)*len);
return GRIB_INTERNAL_ERROR;
/* ECC-802: We cannot bomb out here as the user might have changed Ni/Nj and the packingType
* but has not yet submitted the new data values. So len will be out of sync!
* So issue a warning but proceed.
*/
/*return GRIB_INTERNAL_ERROR;*/
return GRIB_SUCCESS;
}
switch (type_of_compression_used) {

View File

@ -503,8 +503,15 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len)
}
if (width * height != *len) {
fprintf(stderr, "width=%ld height=%ld len=%ld\n", (long)width, (long)height, (long)(*len));
Assert(width * height == *len);
grib_context_log(a->context, GRIB_LOG_ERROR,
"grib_accessor_class_data_png_packing pack_double: width=%ld height=%ld len=%ld."
" width*height should equal len!",
(long)width, (long)height, (long)*len);
/* ECC-802: We cannot bomb out here as the user might have changed Ni/Nj and the packingType
* but has not yet submitted the new data values. So len will be out of sync!
* So issue a warning but proceed.
*/
return GRIB_SUCCESS;
}
d = grib_power(decimal_scale_factor, 10);

View File

@ -10,6 +10,8 @@
. ./include.ctest.sh
label="grib_jpeg_test"
REDIRECT=/dev/null
BLACKLIST="totalLength,section5Length,section7Length,dataRepresentationTemplateNumber,typeOfPacking"
@ -102,3 +104,24 @@ if [ "x$HAVE_LIBOPENJPEG" != x ]; then
do_tests
fi
fi
# ECC-802
# -------
sample2=$ECCODES_SAMPLES_PATH/GRIB2.tmpl
tempFilt=temp.$label.filt
tempGrib=temp.$label.grib
cat > $tempFilt <<EOF
set Ni = 2;
set Nj = 2;
set bitsPerValue = 12;
set packingType = 'grid_jpeg';
set values = {-0.01, 11.99, 56.11, 98.99 };
write;
EOF
${tools_dir}/grib_filter -o $tempGrib $tempFilt $sample2 2>/dev/null
grib_check_key_equals $tempGrib 'packingType,numberOfValues' 'grid_jpeg 4'
stats=`${tools_dir}/grib_get -M -F%.2f -p min,max $tempGrib`
[ "$stats" = "-0.01 98.99" ]
rm -f $tempFilt $tempGrib