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.
|
2014-08-28 09:03:16 +00:00
|
|
|
#
|
2013-03-25 12:04:10 +00:00
|
|
|
# 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
|
|
|
|
|
|
|
REDIRECT=/dev/null
|
2022-06-06 14:41:18 +00:00
|
|
|
|
2013-03-25 12:04:10 +00:00
|
|
|
grib1=${data_dir}/regular_latlon_surface.grib1
|
|
|
|
grib2=${data_dir}/regular_latlon_surface.grib2
|
|
|
|
infile=${data_dir}/reduced_gaussian_model_level.grib1
|
|
|
|
outfile=${data_dir}/with_bitmap.grib1
|
|
|
|
outfile1=${data_dir}/without_bitmap.grib1
|
2018-03-26 13:05:22 +00:00
|
|
|
temp1=out.bmp.grib1
|
|
|
|
temp2=out.bmp.grib2
|
|
|
|
tempData1=out.bmp.grib1.data
|
|
|
|
tempData2=out.bmp.grib2.data
|
|
|
|
tempRules=bitmap.rules
|
2019-12-16 13:32:22 +00:00
|
|
|
tempRef=grib_bitmap.ref
|
2024-01-23 13:35:09 +00:00
|
|
|
tempOut=grib_bitmap.txt
|
2013-03-25 12:04:10 +00:00
|
|
|
|
2016-10-24 13:55:53 +00:00
|
|
|
rm -f $outfile
|
2013-03-25 12:04:10 +00:00
|
|
|
|
2019-12-16 13:32:22 +00:00
|
|
|
# Add a bitmap
|
|
|
|
# -------------
|
2017-02-03 14:21:24 +00:00
|
|
|
${tools_dir}/grib_set -s bitmapPresent=1 $infile $outfile >$REDIRECT
|
2013-03-25 12:04:10 +00:00
|
|
|
|
2019-12-16 13:32:22 +00:00
|
|
|
${tools_dir}/grib_dump $infile | grep -v FILE > $infile.dump
|
|
|
|
${tools_dir}/grib_dump $outfile | grep -v FILE > $outfile.dump
|
|
|
|
|
|
|
|
grib_check_key_equals $outfile section1Flags,section3Length '192 772'
|
|
|
|
|
2019-12-16 15:42:48 +00:00
|
|
|
if [ $ECCODES_ON_WINDOWS -eq 0 ]; then
|
|
|
|
# There are some minute floating point differences on Windows
|
|
|
|
# so the diff would not work there
|
|
|
|
diff $outfile.dump ${data_dir}/bitmap.diff
|
|
|
|
diff $infile.dump ${data_dir}/no_bitmap.diff
|
|
|
|
fi
|
2019-12-16 13:32:22 +00:00
|
|
|
|
|
|
|
${tools_dir}/grib_dump -O -p bitmap $outfile | grep -v FILE > $outfile.dump
|
|
|
|
cat > $tempRef <<EOF
|
|
|
|
963-1728 bitmap = 766 {
|
|
|
|
ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff,
|
|
|
|
ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff,
|
|
|
|
ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff,
|
|
|
|
ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff,
|
|
|
|
ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff,
|
|
|
|
ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff,
|
|
|
|
ff, ff, ff, ff
|
|
|
|
... 665 more values
|
|
|
|
} # g1bitmap bitmap
|
|
|
|
EOF
|
|
|
|
diff $tempRef $outfile.dump
|
2013-03-25 12:04:10 +00:00
|
|
|
|
2019-12-16 13:32:22 +00:00
|
|
|
rm -f $infile.dump $outfile.dump $tempRef
|
2013-03-25 12:04:10 +00:00
|
|
|
|
|
|
|
|
2019-12-16 13:32:22 +00:00
|
|
|
# Remove the bitmap
|
|
|
|
# -----------------
|
2017-02-03 14:21:24 +00:00
|
|
|
${tools_dir}/grib_set -s bitmapPresent=0 $outfile $outfile1 >$REDIRECT
|
2013-03-25 12:04:10 +00:00
|
|
|
|
2019-12-16 13:32:22 +00:00
|
|
|
${tools_dir}/grib_dump $outfile1 | grep -v FILE > $outfile1.dump
|
|
|
|
${tools_dir}/grib_dump $outfile | grep -v FILE > $outfile.dump
|
2013-03-25 12:04:10 +00:00
|
|
|
|
2019-12-16 15:42:48 +00:00
|
|
|
if [ $ECCODES_ON_WINDOWS -eq 0 ]; then
|
|
|
|
diff $outfile1.dump ${data_dir}/no_bitmap.diff
|
|
|
|
fi
|
2013-03-25 12:04:10 +00:00
|
|
|
|
2019-12-16 13:32:22 +00:00
|
|
|
rm -f $outfile1 $outfile1.dump $outfile $outfile.dump
|
|
|
|
|
2013-03-25 12:04:10 +00:00
|
|
|
|
2018-03-26 13:05:22 +00:00
|
|
|
cat > $tempRules<<EOF
|
2021-04-13 11:49:56 +00:00
|
|
|
set bitmapPresent=1;
|
|
|
|
set missingValue=1111;
|
|
|
|
set Ni=6;
|
|
|
|
set Nj=2;
|
|
|
|
set values={1,2,3,4,5,6,7,1111,1111,8,9,10};
|
|
|
|
write ;
|
2013-03-25 12:04:10 +00:00
|
|
|
EOF
|
|
|
|
|
2021-04-13 11:49:56 +00:00
|
|
|
${tools_dir}/grib_filter -o $temp1 $tempRules $grib1
|
2018-03-26 13:05:22 +00:00
|
|
|
${tools_dir}/grib_filter -o $temp2 $tempRules $grib2
|
2013-03-25 12:04:10 +00:00
|
|
|
|
2024-07-12 08:51:12 +00:00
|
|
|
if [ $HAVE_GEOGRAPHY -eq 1 ]; then
|
|
|
|
${tools_dir}/grib_get_data -m missing $temp1 > $tempData1
|
|
|
|
${tools_dir}/grib_get_data -m missing $temp2 > $tempData2
|
2021-04-13 11:49:56 +00:00
|
|
|
|
2024-07-12 08:51:12 +00:00
|
|
|
diff $tempData1 $tempData2
|
|
|
|
rm -f $tempData1 $tempData2
|
|
|
|
fi
|
2021-04-13 11:49:56 +00:00
|
|
|
|
|
|
|
# ECC-1233: Allow printing of 'byte' keys e.g., bitmap, section paddings
|
|
|
|
# -----------------------------------------------------------------------
|
|
|
|
cat > $tempRules<<EOF
|
|
|
|
print " bitmap=[bitmap]";
|
|
|
|
print " padding_local1_1=[padding_local1_1]";
|
|
|
|
EOF
|
|
|
|
${tools_dir}/grib_filter $tempRules $temp1 > $tempData1
|
|
|
|
cat $tempData1
|
|
|
|
cat > $tempRef <<EOF
|
|
|
|
bitmap=fe70
|
|
|
|
padding_local1_1=00
|
|
|
|
EOF
|
|
|
|
diff $tempRef $tempData1
|
2022-10-22 19:32:32 +00:00
|
|
|
rm -f $tempData1 $temp1 $tempRules $tempRef
|
2014-08-28 09:03:16 +00:00
|
|
|
|
2018-03-26 13:05:22 +00:00
|
|
|
# ECC-511: grid_complex_spatial_differencing
|
|
|
|
# To convert to simple packing, must pass in bitmapPresent=1
|
2022-10-22 19:32:32 +00:00
|
|
|
# ----------------------------------------------------------
|
2018-03-26 13:05:22 +00:00
|
|
|
infile=${data_dir}/gfs.complex.mvmu.grib2
|
2022-10-22 19:32:32 +00:00
|
|
|
tempSimple=temp.grib_bitmap.simple.grib
|
|
|
|
${tools_dir}/grib_set -r -s bitmapPresent=1,packingType=grid_simple $infile $tempSimple
|
|
|
|
grib_check_key_equals $tempSimple bitmapPresent,numberOfMissing,numberOfValues,numberOfPoints "1 556901 481339 1038240"
|
|
|
|
stats=`${tools_dir}/grib_get -F%.2f -p max,min,avg $tempSimple`
|
|
|
|
[ "$stats" = "2.81 0.00 0.30" ]
|
|
|
|
|
2023-03-29 16:06:39 +00:00
|
|
|
# Repack
|
|
|
|
${tools_dir}/grib_copy -r $infile $temp2
|
|
|
|
${tools_dir}/grib_compare -c data:n $infile $temp2
|
2023-04-14 12:42:04 +00:00
|
|
|
grib_check_key_equals $temp2 bitsPerValue 9 # Note: The input file has bpv=9
|
2023-03-29 16:06:39 +00:00
|
|
|
|
|
|
|
|
2022-10-22 19:32:32 +00:00
|
|
|
# Simple to grid_complex
|
|
|
|
tempComplex=temp.grib_bitmap.complex.grib
|
2023-04-21 14:15:19 +00:00
|
|
|
#${tools_dir}/grib_set -r -s packingType=grid_complex $tempSimple $tempComplex # TODO: fix re-packing
|
|
|
|
${tools_dir}/grib_set -s packingType=grid_complex $tempSimple $tempComplex
|
2022-10-22 19:32:32 +00:00
|
|
|
grib_check_key_equals $tempComplex packingType,bitmapPresent,numberOfMissing,numberOfValues,numberOfPoints "grid_complex 1 556901 481339 1038240"
|
|
|
|
stats=`${tools_dir}/grib_get -F%.2f -p max,min,avg $tempComplex`
|
|
|
|
[ "$stats" = "2.81 0.00 0.30" ]
|
|
|
|
rm -f $tempComplex
|
|
|
|
|
|
|
|
# Simple to grid_complex_spatial_differencing
|
|
|
|
tempComplexSD=temp.grib_bitmap.complexSD.grib
|
2023-04-21 14:15:19 +00:00
|
|
|
#${tools_dir}/grib_set -r -s packingType=grid_complex_spatial_differencing $tempSimple $tempComplexSD # TODO: fix re-packing
|
|
|
|
${tools_dir}/grib_set -s packingType=grid_complex_spatial_differencing $tempSimple $tempComplexSD
|
2022-12-01 21:29:10 +00:00
|
|
|
grib_check_key_equals $tempComplexSD packingType "grid_complex_spatial_differencing"
|
|
|
|
grib_check_key_equals $tempComplexSD bitmapPresent,numberOfMissing,numberOfValues,numberOfPoints "1 556901 481339 1038240"
|
2022-10-22 19:32:32 +00:00
|
|
|
stats=`${tools_dir}/grib_get -F%.2f -p max,min,avg $tempComplexSD`
|
|
|
|
[ "$stats" = "2.81 0.00 0.30" ]
|
|
|
|
rm -f $tempComplexSD
|
|
|
|
rm -f $tempSimple
|
|
|
|
|
2024-01-23 13:35:09 +00:00
|
|
|
# Secondary bitmap
|
|
|
|
grib2_sample=$ECCODES_SAMPLES_PATH/GRIB2.tmpl
|
|
|
|
${tools_dir}/grib_set -s bitMapIndicator=254 $grib2_sample $tempData1
|
|
|
|
set +e
|
|
|
|
${tools_dir}/grib_dump -O $tempData1 > $tempOut 2>&1
|
|
|
|
status=$?
|
|
|
|
set -e
|
|
|
|
[ $status -ne 0 ]
|
|
|
|
grep -q "missing bitmap" $tempOut
|
2022-10-22 19:32:32 +00:00
|
|
|
|
2014-08-28 09:03:16 +00:00
|
|
|
|
2024-01-29 12:30:49 +00:00
|
|
|
# bitmap as string
|
|
|
|
cat > $tempRules<<EOF
|
|
|
|
print "[bitmap:s]";
|
|
|
|
EOF
|
2024-01-29 12:53:07 +00:00
|
|
|
${tools_dir}/grib_filter $tempRules $data_dir/boustrophedonic.grib1 > $REDIRECT
|
|
|
|
${tools_dir}/grib_filter $tempRules $data_dir/missing_field.grib1 > $REDIRECT
|
|
|
|
${tools_dir}/grib_filter $tempRules $data_dir/reduced_latlon_surface.grib2 > $REDIRECT
|
2024-01-29 12:30:49 +00:00
|
|
|
|
2018-03-26 13:05:22 +00:00
|
|
|
# Clean up
|
2024-01-23 13:35:09 +00:00
|
|
|
rm -f $tempData1 $tempData2 $temp1 $temp2 $tempRules $tempOut
|