2013-03-25 12:04:10 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
# --- check nothing bombs when changing packing
|
|
|
|
# --- for now limited to just a few packing schemes
|
|
|
|
|
2022-04-03 22:02:48 +00:00
|
|
|
. ./include.ctest.sh
|
2013-03-25 12:04:10 +00:00
|
|
|
|
2022-02-16 15:43:38 +00:00
|
|
|
label="grib_change_packing_test"
|
|
|
|
temp=temp.$label.grib
|
2023-07-18 15:53:17 +00:00
|
|
|
temp_err=temp.$label.err
|
|
|
|
rm -f $temp $temp_err
|
2013-03-25 12:04:10 +00:00
|
|
|
|
|
|
|
grib1=${data_dir}/reduced_latlon_surface_constant.grib1
|
|
|
|
grib2=${data_dir}/reduced_latlon_surface_constant.grib2
|
|
|
|
|
|
|
|
packing1="
|
2018-11-09 12:55:32 +00:00
|
|
|
grid_ieee
|
|
|
|
grid_simple
|
|
|
|
grid_simple_matrix"
|
2013-03-25 12:04:10 +00:00
|
|
|
|
|
|
|
packing2="
|
2018-11-09 12:55:32 +00:00
|
|
|
grid_ieee
|
|
|
|
grid_simple
|
2020-02-20 13:05:36 +00:00
|
|
|
grid_simple_matrix
|
|
|
|
grid_simple_log_preprocessing"
|
2013-03-25 12:04:10 +00:00
|
|
|
|
2018-11-27 17:39:55 +00:00
|
|
|
if [ $HAVE_JPEG -eq 1 ]; then
|
|
|
|
packing2="grid_jpeg "$packing2
|
|
|
|
fi
|
|
|
|
|
2013-03-25 12:04:10 +00:00
|
|
|
|
|
|
|
# --- test changing the packing
|
|
|
|
# arg 1 : input grib file
|
|
|
|
# arg 2-n : packing types to test
|
2018-11-27 16:43:08 +00:00
|
|
|
test_packing() {
|
2018-11-09 12:55:32 +00:00
|
|
|
grib=$1
|
2013-03-25 12:04:10 +00:00
|
|
|
|
2018-11-09 12:55:32 +00:00
|
|
|
if [ ! -f $grib ]; then
|
|
|
|
echo "Input data missing"
|
|
|
|
exit 1
|
|
|
|
fi
|
2013-03-25 12:04:10 +00:00
|
|
|
|
2018-11-09 12:55:32 +00:00
|
|
|
shift
|
|
|
|
while [ $# -gt 0 ]; do
|
|
|
|
packing=$1
|
2013-03-25 12:04:10 +00:00
|
|
|
|
2018-11-09 12:55:32 +00:00
|
|
|
${tools_dir}/grib_set -r -s packingType=$packing $grib $temp
|
|
|
|
result=`${tools_dir}/grib_get -p packingType $temp`
|
2022-03-28 14:55:39 +00:00
|
|
|
|
2018-11-09 12:55:32 +00:00
|
|
|
if [ "$result" != "$packing" ]; then
|
|
|
|
echo "Setting packing did not go right"
|
|
|
|
exit 1
|
|
|
|
fi
|
2013-03-25 12:04:10 +00:00
|
|
|
|
2022-03-28 14:55:39 +00:00
|
|
|
result=`${tools_dir}/grib_get -p accuracy $temp`
|
|
|
|
[ $result -eq 0 -o $result -eq 32 -o $result -eq 64 ]
|
|
|
|
|
2023-08-20 13:43:09 +00:00
|
|
|
temp1=$temp.1
|
|
|
|
${tools_dir}/grib_set -s setPackingType=$packing $grib $temp1
|
|
|
|
${tools_dir}/grib_compare $temp $temp1
|
|
|
|
rm -f $temp1
|
|
|
|
|
2018-11-09 12:55:32 +00:00
|
|
|
shift
|
|
|
|
done
|
2013-03-25 12:04:10 +00:00
|
|
|
|
2018-11-09 12:55:32 +00:00
|
|
|
rm -f $temp
|
2013-03-25 12:04:10 +00:00
|
|
|
}
|
|
|
|
|
2018-11-09 12:55:32 +00:00
|
|
|
# ECC-774
|
|
|
|
# ------------
|
|
|
|
input=${data_dir}/spherical_model_level.grib2
|
|
|
|
output=`${tools_dir}/grib_set -r -s packingType=spectral_simple $input $temp 2>&1`
|
2021-06-14 16:29:47 +00:00
|
|
|
grib_check_key_equals $temp packingType 'spectral_simple'
|
2022-03-28 14:55:39 +00:00
|
|
|
grib_check_key_equals $temp accuracy 16
|
2018-11-09 12:55:32 +00:00
|
|
|
# Check no error was posted i.e. output string is empty
|
|
|
|
[ -z "$output" ]
|
|
|
|
res1=`${tools_dir}/grib_get '-F%.1f' -p avg,enorm $input`
|
|
|
|
res2=`${tools_dir}/grib_get '-F%.1f' -p avg,enorm $temp`
|
|
|
|
[ "$res1" = "$res2" ]
|
|
|
|
rm -f $temp
|
|
|
|
|
|
|
|
|
2019-11-27 13:37:40 +00:00
|
|
|
# IEEE to Simple Packing
|
|
|
|
# -----------------------
|
2022-06-25 21:10:40 +00:00
|
|
|
if [ $ECCODES_ON_WINDOWS -eq 0 ]; then
|
|
|
|
input=${data_dir}/grid_ieee.grib
|
|
|
|
${tools_dir}/grib_set -r -s packingType=grid_simple $input $temp
|
|
|
|
grib_check_key_equals $input accuracy 32
|
|
|
|
grib_check_key_equals $temp packingType 'grid_simple'
|
|
|
|
grib_check_key_equals $temp accuracy,bitsPerValue '32 32'
|
|
|
|
stats1=`${tools_dir}/grib_get -F%.2f -p skew,kurt $input`
|
|
|
|
stats2=`${tools_dir}/grib_get -F%.2f -p skew,kurt $temp`
|
|
|
|
[ "$stats1" = "$stats2" ]
|
|
|
|
|
|
|
|
# 64bit IEEE - We can only do max. 32 with CCSDS
|
|
|
|
input=${data_dir}/reduced_gaussian_model_level.grib2
|
|
|
|
${tools_dir}/grib_set -r -s packingType=grid_ieee,precision=2 $input $temp
|
|
|
|
grib_check_key_equals $temp packingType,accuracy 'grid_ieee 64'
|
|
|
|
${tools_dir}/grib_set -r -s packingType=grid_simple $temp $temp.simple
|
|
|
|
grib_check_key_equals $temp.simple packingType,accuracy 'grid_simple 32'
|
|
|
|
rm -f $temp.simple
|
|
|
|
fi
|
2022-04-26 11:03:24 +00:00
|
|
|
|
|
|
|
# Test 'accuracy' key
|
|
|
|
# -----------------------
|
|
|
|
input=${data_dir}/reduced_gaussian_model_level.grib1
|
|
|
|
${tools_dir}/grib_set -r -s packingType=grid_ieee,accuracy=64 $input $temp
|
|
|
|
grib_check_key_equals $temp precision '2'
|
|
|
|
stats1=`${tools_dir}/grib_get -F%.2f -p skew,kurt $input`
|
|
|
|
stats2=`${tools_dir}/grib_get -F%.2f -p skew,kurt $temp`
|
2019-11-27 13:37:40 +00:00
|
|
|
[ "$stats1" = "$stats2" ]
|
|
|
|
|
|
|
|
|
2018-11-09 12:55:32 +00:00
|
|
|
# Change grib packing test
|
|
|
|
# -------------------------
|
2013-03-25 12:04:10 +00:00
|
|
|
test_packing $grib1 $packing1
|
|
|
|
test_packing $grib2 $packing2
|
2018-11-09 12:55:32 +00:00
|
|
|
|
2021-06-14 16:29:47 +00:00
|
|
|
|
|
|
|
# spectral_simple for GRIB1
|
|
|
|
# -------------------------
|
|
|
|
input=${data_dir}/spherical_model_level.grib1
|
|
|
|
${tools_dir}/grib_set -r -s packingType=spectral_simple $input $temp
|
|
|
|
grib_check_key_equals $temp packingType 'spectral_simple'
|
|
|
|
${tools_dir}/grib_ls -p numberOfCodedValues $temp
|
2021-08-20 12:20:35 +00:00
|
|
|
${tools_dir}/grib_ls -n statistics $temp
|
|
|
|
stats=`${tools_dir}/grib_get -F%.1f -p average,standardDeviation $temp`
|
|
|
|
[ "$stats" = "195.1 12.0" ]
|
2021-06-14 16:29:47 +00:00
|
|
|
|
|
|
|
|
2022-02-16 15:43:38 +00:00
|
|
|
# ECC-1352: Check CCSDS
|
|
|
|
# ----------------------------
|
|
|
|
if [ $HAVE_AEC -eq 0 ]; then
|
|
|
|
# Check we get an error if we try to decode this packing
|
|
|
|
[ -f "${data_dir}/ccsds.grib2" ]
|
|
|
|
set +e
|
|
|
|
${tools_dir}/grib_get -p min,max ${data_dir}/ccsds.grib2 2>$temp_err
|
|
|
|
status=$?
|
|
|
|
set -e
|
|
|
|
[ $status -ne 0 ]
|
|
|
|
grep -q "CCSDS support not enabled. Please rebuild with -DENABLE_AEC=ON" $temp_err
|
|
|
|
fi
|
|
|
|
|
2023-08-11 12:46:57 +00:00
|
|
|
# grid_simple_log_preprocessing
|
|
|
|
# -----------------------------
|
|
|
|
input=${data_dir}/sample.grib2
|
2024-08-03 13:44:40 +00:00
|
|
|
${tools_dir}/grib_set -r -s packingType=grid_simple_log_preprocessing $input $temp 2> $temp_err
|
2023-08-11 12:46:57 +00:00
|
|
|
grib_check_key_equals $temp packingType 'grid_simple_log_preprocessing'
|
|
|
|
${tools_dir}/grib_compare -c data:n -R packedValues=2e-6 $input $temp
|
2024-08-03 13:44:40 +00:00
|
|
|
# ECC-1897
|
|
|
|
grep -q "ECCODES WARNING.*is experimental" $temp_err
|
|
|
|
|
|
|
|
${tools_dir}/grib_set -r -s packingType=grid_simple_matrix $input $temp 2> $temp_err
|
|
|
|
grep -q "ECCODES WARNING.*is experimental" $temp_err
|
|
|
|
|
2023-08-11 12:46:57 +00:00
|
|
|
|
2022-05-31 15:47:00 +00:00
|
|
|
# Large constant fields
|
|
|
|
# -----------------------
|
|
|
|
input=${data_dir}/sample.grib2
|
|
|
|
ECCODES_GRIB_LARGE_CONSTANT_FIELDS=0 ${tools_dir}/grib_set -d1 $input $temp
|
|
|
|
grib_check_key_equals $temp const,bitsPerValue,section7Length '1 0 5'
|
|
|
|
|
|
|
|
ECCODES_GRIB_LARGE_CONSTANT_FIELDS=1 ${tools_dir}/grib_set -d1 $input $temp
|
|
|
|
grib_check_key_equals $temp const,bitsPerValue,section7Length '1 16 997'
|
|
|
|
|
|
|
|
${tools_dir}/grib_set -s produceLargeConstantFields=0 -d1 $input $temp
|
|
|
|
grib_check_key_equals $temp const,bitsPerValue,section7Length '1 0 5'
|
|
|
|
|
|
|
|
${tools_dir}/grib_set -s produceLargeConstantFields=1 -d1 $input $temp
|
|
|
|
grib_check_key_equals $temp const,bitsPerValue,section7Length '1 16 997'
|
|
|
|
|
2022-06-01 14:18:56 +00:00
|
|
|
# GRIB1: when GRIBEX mode is enabled, we also get a large constant field
|
|
|
|
input=${data_dir}/simple.grib
|
|
|
|
${tools_dir}/grib_set -d1 $input $temp
|
|
|
|
grib_check_key_equals $temp const,bitsPerValue,section4Length '1 0 12'
|
|
|
|
ECCODES_GRIBEX_MODE_ON=1 ${tools_dir}/grib_set -d1 $input $temp
|
|
|
|
grib_check_key_equals $temp const,bitsPerValue,section4Length '1 12 8966'
|
|
|
|
|
2023-07-18 15:53:17 +00:00
|
|
|
# Error in packingType value
|
|
|
|
# ---------------------------
|
|
|
|
set +e
|
|
|
|
${tools_dir}/grib_set -s packingType="xxxxx" $ECCODES_SAMPLES_PATH/GRIB2.tmpl $temp > $temp_err 2>&1
|
|
|
|
status=$?
|
|
|
|
set -e
|
|
|
|
[ $status -ne 0 ]
|
|
|
|
grep -q "ECCODES ERROR.*no match for packingType=xxxxx" $temp_err
|
|
|
|
cat $temp_err
|
|
|
|
|
2023-08-11 12:36:42 +00:00
|
|
|
# Set packingType when it is disabled
|
|
|
|
# -----------------------------------
|
|
|
|
if [ $HAVE_PNG -eq 0 ]; then
|
|
|
|
set +e
|
|
|
|
${tools_dir}/grib_set -s packingType=grid_png $ECCODES_SAMPLES_PATH/GRIB2.tmpl $temp > $temp_err 2>&1
|
|
|
|
status=$?
|
|
|
|
set -e
|
|
|
|
[ $status -ne 0 ]
|
|
|
|
grep -q "ECCODES ERROR.*PNG support not enabled" $temp_err
|
|
|
|
fi
|
|
|
|
|
2023-07-18 15:53:17 +00:00
|
|
|
# Clean up
|
2022-02-16 15:43:38 +00:00
|
|
|
rm -f $temp $temp_err
|