From 59c22e4baa997b9557723a58c84ac4767590d60b Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Fri, 25 Jul 2014 11:13:00 +0100 Subject: [PATCH] GRIB-541 and GRIB-564 --- ...ta_g1second_order_general_extended_packing.c | 9 +++++---- src/grib_accessor_class_data_jpeg2000_packing.c | 6 ++++-- tests/jpeg.sh | 4 ++++ tests/second_order.sh | 17 +++++++++++++++++ 4 files changed, 30 insertions(+), 6 deletions(-) diff --git a/src/grib_accessor_class_data_g1second_order_general_extended_packing.c b/src/grib_accessor_class_data_g1second_order_general_extended_packing.c index 4971d52d7..7fc0ad389 100644 --- a/src/grib_accessor_class_data_g1second_order_general_extended_packing.c +++ b/src/grib_accessor_class_data_g1second_order_general_extended_packing.c @@ -293,13 +293,15 @@ static int unpack_double_element(grib_accessor* a, size_t idx, double* val) size_t size; double* values; int err=0; + + /* GRIB-564: The index idx relates to codedValues NOT values! */ - err=grib_get_size(a->parent->h,"values",&size); + err=grib_get_size(a->parent->h,"codedValues",&size); if (err) return err; - if (idx > size) return GRIB_INVALID_NEAREST; + if (idx >= size) return GRIB_INVALID_NEAREST; values=grib_context_malloc_clear(a->parent->h->context,size*sizeof(double)); - err=grib_get_double_array(a->parent->h,"values",values,&size); + err=grib_get_double_array(a->parent->h,"codedValues",values,&size); if (err) return err; *val=values[idx]; grib_context_free(a->parent->h->context,values); @@ -1162,7 +1164,6 @@ static int pack_double(grib_accessor* a, const double* val, size_t *len) count+=groupLengths[i]; #endif } - } grib_buffer_replace(a, buffer, size,1,1); diff --git a/src/grib_accessor_class_data_jpeg2000_packing.c b/src/grib_accessor_class_data_jpeg2000_packing.c index 694346d0d..e066d1dd2 100644 --- a/src/grib_accessor_class_data_jpeg2000_packing.c +++ b/src/grib_accessor_class_data_jpeg2000_packing.c @@ -550,12 +550,14 @@ static int unpack_double_element(grib_accessor* a, size_t idx, double* val) double* values; int err=0; - err=grib_get_size(a->parent->h,"values",&size); + /* GRIB-564: The index idx relates to codedValues NOT values! */ + + err=grib_get_size(a->parent->h,"codedValues",&size); if (err) return err; if (idx > size) return GRIB_INVALID_NEAREST; values=grib_context_malloc_clear(a->parent->h->context,size*sizeof(double)); - err=grib_get_double_array(a->parent->h,"values",values,&size); + err=grib_get_double_array(a->parent->h,"codedValues",values,&size); if (err) return err; *val=values[idx]; grib_context_free(a->parent->h->context,values); diff --git a/tests/jpeg.sh b/tests/jpeg.sh index b154bb046..9e460a654 100755 --- a/tests/jpeg.sh +++ b/tests/jpeg.sh @@ -47,5 +47,9 @@ res3=`${tools_dir}grib_get '-F%1.2f' -p min,max,avg $infile.2` [ "$res1" = "$res2" ] [ "$res1" = "$res3" ] +# GRIB-564 nearest 4 neighbours with JPEG packing +res=`${tools_dir}grib_get -l 0,50 $infile.1` +[ "$res" = "2.47244 2.47244 2.5115 2.51931 " ] + rm -f $infile.1 $infile.2 || true rm -f ${data_dir}/reduced_latlon_surface.grib2 diff --git a/tests/second_order.sh b/tests/second_order.sh index 3f7275ecb..f621650b3 100755 --- a/tests/second_order.sh +++ b/tests/second_order.sh @@ -81,5 +81,22 @@ test_data # See GRIB-147 ${tools_dir}grib_dump second_ord_rbr.grib1 > $REDIRECT +# Test nearest neighbour on second order with a bitmap +# GRIB-541 +sec_ord_bmp=sec_ord_bmp.$$.grib1 +# Convert to second order packing +${tools_dir}grib_set -r -s packingType=grid_second_order gen_bitmap.grib $sec_ord_bmp +# Check there are missing values +nums=`${tools_dir}grib_get -p numberOfDataPoints,numberOfCodedValues,numberOfMissing $sec_ord_bmp` +[ "$nums" = "5969 4 5965" ] + +res=`${tools_dir}grib_get -l 33,88.5 $sec_ord_bmp` +[ "$res" = "9999 5.51552 9999 9999 " ] + +res=`${tools_dir}/grib_get -l 28.5,90 $sec_ord_bmp` +[ "$res" = "3.51552 9999 5.26552 9999 " ] + + +rm -f $sec_ord_bmp rm -f test.filter