2013-03-25 12:04:10 +00:00
|
|
|
#!/bin/sh
|
2020-01-28 14:32:34 +00:00
|
|
|
# (C) Copyright 2005- ECMWF.
|
2013-03-25 12:04:10 +00:00
|
|
|
#
|
|
|
|
# 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.
|
|
|
|
#
|
|
|
|
|
2022-04-03 22:02:48 +00:00
|
|
|
. ./include.ctest.sh
|
2013-03-25 12:04:10 +00:00
|
|
|
|
|
|
|
workdir=`pwd`
|
|
|
|
REDIRECT=/dev/null
|
2022-06-25 12:01:00 +00:00
|
|
|
label="grib_second_order_test"
|
|
|
|
tempText=temp.$label.txt
|
2013-03-25 12:04:10 +00:00
|
|
|
|
|
|
|
cd ${data_dir}
|
|
|
|
|
|
|
|
encoding=1
|
|
|
|
simple_no_bitmap=simple.grib
|
|
|
|
simple_bitmap=simple_bitmap.grib
|
2024-02-20 13:57:38 +00:00
|
|
|
tempFilt=temp.$label.filter
|
2013-03-25 12:04:10 +00:00
|
|
|
|
|
|
|
files_no_bitmap="gen_ext.grib \
|
|
|
|
gen_ext_boust.grib \
|
|
|
|
gen_ext_spd_2.grib \
|
|
|
|
gen_ext_spd_3.grib \
|
|
|
|
gen.grib row.grib "
|
|
|
|
|
|
|
|
files_bitmap="constant_width_bitmap.grib \
|
|
|
|
constant_width_boust_bitmap.grib \
|
|
|
|
gen_bitmap.grib \
|
|
|
|
gen_ext_bitmap.grib \
|
|
|
|
gen_ext_boust_bitmap.grib \
|
|
|
|
gen_ext_spd_2_bitmap.grib \
|
|
|
|
gen_ext_spd_2_boust_bitmap.grib \
|
|
|
|
gen_ext_spd_3_boust_bitmap.grib \
|
|
|
|
simple_bitmap.grib"
|
|
|
|
|
|
|
|
no_packing="gen.grib|row.grib|gen_bitmap.grib|constant_width_bitmap.grib|constant_width_boust_bitmap.grib"
|
|
|
|
|
|
|
|
test_data() {
|
2024-02-20 13:57:38 +00:00
|
|
|
${tools_dir}/grib_filter $tempFilt $simple > $simple.data
|
2017-03-27 15:23:25 +00:00
|
|
|
|
|
|
|
for f in $files
|
|
|
|
do
|
2024-02-20 13:57:38 +00:00
|
|
|
${tools_dir}/grib_filter $tempFilt $f > $f.data
|
2017-03-27 15:23:25 +00:00
|
|
|
diff $simple.data $f.data > /dev/null
|
|
|
|
${tools_dir}/grib_compare -cvalues $f $simple
|
|
|
|
echo $f decoding test passed > $REDIRECT
|
|
|
|
|
|
|
|
exclude=`echo $f | awk " /$no_packing/ {print \"found\";} "`
|
|
|
|
if [ -z "$exclude" ] && [ $encoding != 0 ]
|
|
|
|
then
|
|
|
|
rm -f $f.copied
|
|
|
|
${tools_dir}/grib_copy -r $f $f.copied
|
2024-02-20 13:57:38 +00:00
|
|
|
${tools_dir}/grib_filter $tempFilt $f.copied > $f.copied.data
|
2017-03-27 15:23:25 +00:00
|
|
|
diff $simple.data $f.copied.data > /dev/null
|
|
|
|
${tools_dir}/grib_compare -cvalues $f.copied $simple
|
|
|
|
echo $f encoding test passed > $REDIRECT
|
|
|
|
echo > $REDIRECT
|
|
|
|
fi
|
|
|
|
|
|
|
|
done
|
|
|
|
rm -f *.data *.copied
|
2013-03-25 12:04:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-02-20 13:57:38 +00:00
|
|
|
cat > $tempFilt<<EOF
|
2013-03-25 12:04:10 +00:00
|
|
|
print "[values!1]!";
|
|
|
|
EOF
|
|
|
|
|
|
|
|
simple=$simple_no_bitmap
|
|
|
|
files=$files_no_bitmap
|
|
|
|
test_data
|
|
|
|
|
|
|
|
simple=$simple_bitmap
|
|
|
|
files=$files_bitmap
|
|
|
|
test_data
|
|
|
|
|
|
|
|
# Now make sure grib_dump works on a second-order row-by-row file
|
|
|
|
# See GRIB-147
|
2017-02-03 14:21:24 +00:00
|
|
|
${tools_dir}/grib_dump second_ord_rbr.grib1 > $REDIRECT
|
2013-03-25 12:04:10 +00:00
|
|
|
|
2014-07-25 10:13:00 +00:00
|
|
|
# Test nearest neighbour on second order with a bitmap
|
|
|
|
# GRIB-541
|
|
|
|
sec_ord_bmp=sec_ord_bmp.$$.grib1
|
2013-03-25 12:04:10 +00:00
|
|
|
|
2014-07-25 10:13:00 +00:00
|
|
|
# Convert to second order packing
|
2017-02-03 14:21:24 +00:00
|
|
|
${tools_dir}/grib_set -r -s packingType=grid_second_order gen_bitmap.grib $sec_ord_bmp
|
2022-03-28 15:18:11 +00:00
|
|
|
grib_check_key_equals $sec_ord_bmp accuracy 4
|
2014-07-25 10:13:00 +00:00
|
|
|
# Check there are missing values
|
2017-02-03 14:21:24 +00:00
|
|
|
nums=`${tools_dir}/grib_get -p numberOfDataPoints,numberOfCodedValues,numberOfMissing $sec_ord_bmp`
|
2014-07-25 10:13:00 +00:00
|
|
|
[ "$nums" = "5969 4 5965" ]
|
|
|
|
|
2024-07-12 08:51:12 +00:00
|
|
|
if [ $HAVE_GEOGRAPHY -eq 1 ]; then
|
|
|
|
res=`${tools_dir}/grib_get -l 33,88.5 $sec_ord_bmp`
|
|
|
|
[ "$res" = "9999 5.51552 9999 9999 " ]
|
2014-07-25 10:13:00 +00:00
|
|
|
|
2024-07-12 08:51:12 +00:00
|
|
|
res=`${tools_dir}/grib_get -l 30,90.0 $sec_ord_bmp`
|
|
|
|
[ "$res" = "5.26552 9999 9999 9999 " ]
|
2022-06-20 18:47:15 +00:00
|
|
|
|
2024-07-12 08:51:12 +00:00
|
|
|
res=`${tools_dir}/grib_get -l 28.5,87 $sec_ord_bmp`
|
|
|
|
[ "$res" = "9999 2.51552 9999 9999 " ]
|
2022-06-20 18:47:15 +00:00
|
|
|
|
2024-07-12 08:51:12 +00:00
|
|
|
res=`${tools_dir}/grib_get -l 28.5,90 $sec_ord_bmp`
|
|
|
|
[ "$res" = "3.51552 9999 5.26552 9999 " ]
|
2014-07-25 10:13:00 +00:00
|
|
|
|
2024-07-12 08:51:12 +00:00
|
|
|
# GRIB-203 nearest on M-F second order boustrophedonic
|
|
|
|
res=`${tools_dir}/grib_get -w count=1 -l 0,0,1 lfpw.grib1`
|
|
|
|
[ "$res" = "20563.4 " ]
|
|
|
|
fi
|
2014-07-25 10:13:00 +00:00
|
|
|
|
2017-03-27 15:23:25 +00:00
|
|
|
# Unpack/pack test for second order grib1 data
|
|
|
|
# --------------------------------------------
|
|
|
|
g1files="lfpw.grib1
|
|
|
|
gen_ext_spd_2.grib
|
|
|
|
gen_ext_spd_3.grib"
|
2022-06-25 12:01:00 +00:00
|
|
|
temp1=temp1.$label.grib
|
|
|
|
temp_stat1=temp.$label.stat1
|
|
|
|
temp_stat2=temp.$label.stat2
|
2017-03-27 15:23:25 +00:00
|
|
|
|
|
|
|
for f1 in $g1files; do
|
|
|
|
# This does unpack and repack
|
2021-03-12 12:23:17 +00:00
|
|
|
${tools_dir}/grib_copy -r $f1 $temp1
|
|
|
|
${tools_dir}/grib_get -n statistics $f1 > $temp_stat1
|
|
|
|
${tools_dir}/grib_get -n statistics $temp1 > $temp_stat2
|
2017-03-27 15:23:25 +00:00
|
|
|
perl ${test_dir}/number_compare.pl $temp_stat1 $temp_stat2
|
|
|
|
done
|
2021-03-12 12:23:17 +00:00
|
|
|
|
|
|
|
# GRIB-883
|
|
|
|
# ------------
|
|
|
|
# Two coded values: Should stay as grid_simple
|
2022-06-25 12:01:00 +00:00
|
|
|
temp2=temp2.$label.grib
|
|
|
|
temp3=temp3.$label.grib
|
2024-02-20 13:57:38 +00:00
|
|
|
cat > $tempFilt<<EOF
|
2021-03-12 12:23:17 +00:00
|
|
|
set values={ 2.1, 3.4 };
|
|
|
|
write;
|
|
|
|
EOF
|
2024-02-20 13:57:38 +00:00
|
|
|
${tools_dir}/grib_filter -o $temp2 $tempFilt $ECCODES_SAMPLES_PATH/GRIB2.tmpl
|
2022-06-25 12:01:00 +00:00
|
|
|
ECCODES_DEBUG=1 ${tools_dir}/grib_set -r -s packingType=grid_second_order $temp2 $temp3 2>$tempText
|
2022-03-28 15:18:11 +00:00
|
|
|
grib_check_key_equals $temp3 packingType,accuracy 'grid_simple 24'
|
2022-06-25 12:01:00 +00:00
|
|
|
grep -q "Packing not changed" $tempText
|
2021-03-12 12:23:17 +00:00
|
|
|
|
|
|
|
# Three coded values: Now we can change to 2nd order
|
2024-02-20 13:57:38 +00:00
|
|
|
cat > $tempFilt<<EOF
|
2021-03-12 12:23:17 +00:00
|
|
|
set values={ 2.1, 3.4, 8.9 };
|
|
|
|
write;
|
|
|
|
EOF
|
2024-02-20 13:57:38 +00:00
|
|
|
${tools_dir}/grib_filter -o $temp2 $tempFilt $ECCODES_SAMPLES_PATH/GRIB2.tmpl
|
2021-03-12 12:23:17 +00:00
|
|
|
${tools_dir}/grib_set -r -s packingType=grid_second_order $temp2 $temp3
|
2022-03-28 15:18:11 +00:00
|
|
|
grib_check_key_equals $temp3 packingType,accuracy 'grid_second_order 24'
|
2021-03-12 12:23:17 +00:00
|
|
|
|
|
|
|
|
2021-05-14 22:40:30 +00:00
|
|
|
# ECC-1219: packingType conversion from grid_ieee to grid_second_order
|
|
|
|
# ---------------------------------------------------------------------
|
2023-02-02 16:59:06 +00:00
|
|
|
ALLOWED_ERROR=3e-06
|
2021-05-20 09:38:51 +00:00
|
|
|
if [ $ECCODES_ON_WINDOWS -eq 0 ]; then
|
|
|
|
infile=grid_ieee.grib
|
|
|
|
${tools_dir}/grib_set -r -s packingType=grid_second_order $infile $temp1
|
|
|
|
grib_check_key_equals $temp1 packingType grid_second_order
|
2021-12-21 11:07:43 +00:00
|
|
|
${tools_dir}/grib_compare -cdata:n -R all=$ALLOWED_ERROR $infile $temp1
|
2021-05-20 09:38:51 +00:00
|
|
|
fi
|
2021-05-14 22:40:30 +00:00
|
|
|
|
2021-12-06 17:59:50 +00:00
|
|
|
# Second order doesn't have a proper representation for constant fields
|
|
|
|
# So we change the packing type to grid_simple
|
|
|
|
# ---------------------------------------------------------------------
|
|
|
|
infile=gen_ext_spd_2.grib
|
|
|
|
grib_check_key_equals $infile packingType grid_second_order
|
|
|
|
${tools_dir}/grib_set -d1 $infile $temp1
|
|
|
|
grib_check_key_equals $temp1 packingType grid_simple
|
|
|
|
|
2023-02-23 20:37:29 +00:00
|
|
|
infile=$ECCODES_SAMPLES_PATH/GRIB1.tmpl
|
|
|
|
${tools_dir}/grib_set -r -s packingType=grid_second_order $infile $temp1
|
|
|
|
grib_check_key_equals $temp1 packingType grid_simple
|
|
|
|
|
|
|
|
infile=$ECCODES_SAMPLES_PATH/GRIB2.tmpl
|
|
|
|
${tools_dir}/grib_set -r -s packingType=grid_second_order $infile $temp1
|
|
|
|
grib_check_key_equals $temp1 packingType grid_simple
|
|
|
|
|
2023-08-05 18:54:50 +00:00
|
|
|
export ECCODES_GRIBEX_BOUSTROPHEDONIC=1
|
|
|
|
${tools_dir}/grib_get -n statistics boustrophedonic.grib1
|
|
|
|
${tools_dir}/grib_set -s scaleValuesBy=1.1 boustrophedonic.grib1 $temp1
|
|
|
|
unset ECCODES_GRIBEX_BOUSTROPHEDONIC
|
|
|
|
|
2021-12-06 17:59:50 +00:00
|
|
|
|
2023-09-03 11:15:48 +00:00
|
|
|
# data_g1second_order_constant_width_packing
|
|
|
|
# ------------------------------------------
|
|
|
|
input=second_ord_rbr.grib1
|
2023-09-03 12:07:46 +00:00
|
|
|
${tools_dir}/grib_set -s Ni=2,Nj=74,secondOrderOfDifferentWidth=0,secondaryBitmapPresent=1 $input $temp1
|
2023-09-03 11:15:48 +00:00
|
|
|
grib_check_key_equals $temp1 packingType grid_second_order_constant_width
|
|
|
|
${tools_dir}/grib_dump -O $temp1 > $REDIRECT
|
|
|
|
set +e
|
|
|
|
${tools_dir}/grib_set -s scaleValuesBy=2 $temp1 $temp2 > $tempText 2>&1
|
|
|
|
status=$?
|
|
|
|
set -e
|
|
|
|
[ $status -ne 0 ]
|
|
|
|
grep -q "Not implemented" $tempText
|
|
|
|
|
2024-07-12 08:51:12 +00:00
|
|
|
if [ $HAVE_GEOGRAPHY -eq 1 ]; then
|
|
|
|
${tools_dir}/grib_get_data $temp1 > $REDIRECT
|
|
|
|
${tools_dir}/grib_ls -l46,1 $temp1 > $REDIRECT
|
|
|
|
${tools_dir}/grib_ls -j -l46,1,1 $temp1 > $REDIRECT
|
|
|
|
fi
|
2023-09-03 11:15:48 +00:00
|
|
|
|
2023-12-27 18:08:22 +00:00
|
|
|
# Encoding
|
|
|
|
input=second_ord_rbr.grib1
|
|
|
|
${tools_dir}/grib_set -s scaleValuesBy=1.01 $input $temp1
|
|
|
|
${tools_dir}/grib_dump $temp1
|
|
|
|
grib_check_key_equals $temp1 packingType grid_second_order
|
|
|
|
|
2024-11-26 10:03:22 +00:00
|
|
|
# ECC-1986: GRIB1: Setting field values in second order packing
|
|
|
|
cat > $tempFilt<<EOF
|
|
|
|
if (count==1) {
|
|
|
|
# min = 19074.9, max = 20717.6
|
|
|
|
assert( min < 20000 );
|
|
|
|
set offsetValuesBy = 1000.0;
|
|
|
|
assert( min > 20000 );
|
|
|
|
}
|
|
|
|
EOF
|
|
|
|
input=lfpw.grib1
|
|
|
|
${tools_dir}/grib_filter $tempFilt $input
|
|
|
|
|
2023-12-27 18:08:22 +00:00
|
|
|
|
2021-03-12 12:23:17 +00:00
|
|
|
# Clean up
|
2017-04-05 11:49:16 +00:00
|
|
|
rm -f $temp_stat1 $temp_stat2
|
2021-03-12 12:23:17 +00:00
|
|
|
rm -f $temp1 $temp2 $temp3 $sec_ord_bmp
|
2024-02-20 13:57:38 +00:00
|
|
|
rm -f $tempFilt $tempText
|