2013-03-25 12:04:10 +00:00
|
|
|
#!/bin/sh
|
2018-01-02 11:31:02 +00:00
|
|
|
# Copyright 2005-2018 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.
|
2013-03-25 14:23:07 +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.
|
|
|
|
#
|
|
|
|
|
|
|
|
. ./include.sh
|
|
|
|
|
|
|
|
REDIRECT=/dev/null
|
2015-02-01 16:35:46 +00:00
|
|
|
|
|
|
|
# First check if jpeg decode/encode feature is enabled
|
|
|
|
skip_test=0
|
|
|
|
src_config=${src_dir}/config.h
|
|
|
|
if [ -f ${src_config} ]; then
|
|
|
|
set +e
|
|
|
|
grep '#undef HAVE_JPEG' ${src_config} >/dev/null
|
|
|
|
status=$?
|
|
|
|
set -e
|
|
|
|
if [ $status -eq 0 ]; then
|
|
|
|
# Found the string so feature is disabled
|
|
|
|
skip_test=1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
if [ $skip_test -eq 1 ]; then
|
|
|
|
echo "JPEG feature was not enabled. Skipping this test."
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
echo "JPEG feature was enabled."
|
|
|
|
|
2013-10-21 09:44:36 +00:00
|
|
|
BLACKLIST="totalLength,section5Length,section7Length,dataRepresentationTemplateNumber,typeOfPacking"
|
2013-03-25 12:04:10 +00:00
|
|
|
|
|
|
|
infile=${data_dir}/jpeg.grib2
|
2015-02-18 10:37:58 +00:00
|
|
|
outfile1=$infile.tmp_jpeg.1
|
|
|
|
outfile2=$infile.tmp_jpeg.2
|
2013-03-25 12:04:10 +00:00
|
|
|
|
2016-08-12 13:33:51 +00:00
|
|
|
rm -f $outfile1 $outfile2
|
2013-03-25 12:04:10 +00:00
|
|
|
|
2017-12-18 17:39:45 +00:00
|
|
|
# Test dump
|
|
|
|
${tools_dir}/grib_dump -Da $infile >/dev/null 2>&1
|
|
|
|
|
2017-02-03 14:21:24 +00:00
|
|
|
${tools_dir}/grib_set -s packingType=grid_simple $infile $outfile1
|
|
|
|
${tools_dir}/grib_compare -P -b $BLACKLIST,typeOfCompressionUsed,targetCompressionRatio $infile $outfile1 > $REDIRECT
|
|
|
|
${tools_dir}/grib_set -s packingType=grid_jpeg $outfile1 $outfile2
|
|
|
|
${tools_dir}/grib_compare -P -b $BLACKLIST $outfile1 $outfile2 > $REDIRECT
|
2013-03-25 12:04:10 +00:00
|
|
|
|
2017-02-03 14:21:24 +00:00
|
|
|
templateNumber=`${tools_dir}/grib_get -p dataRepresentationTemplateNumber $outfile2`
|
2013-03-25 12:04:10 +00:00
|
|
|
|
|
|
|
if [ $templateNumber -ne 40 ]
|
|
|
|
then
|
|
|
|
echo dataRepresentationTemplateNumber=$templateNumber
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2016-08-12 13:33:51 +00:00
|
|
|
rm -f $outfile1 $outfile2
|
2013-03-25 12:04:10 +00:00
|
|
|
|
|
|
|
infile=${data_dir}/reduced_latlon_surface.grib2
|
2015-02-18 10:37:58 +00:00
|
|
|
outfile1=$infile.tmp_jpeg.1
|
|
|
|
outfile2=$infile.tmp_jpeg.2
|
2017-02-03 14:21:24 +00:00
|
|
|
${tools_dir}/grib_set -s packingType=grid_jpeg $infile $outfile1
|
|
|
|
${tools_dir}/grib_compare -P -b $BLACKLIST $infile $outfile1 > $REDIRECT
|
|
|
|
${tools_dir}/grib_set -s packingType=grid_simple $outfile1 $outfile2
|
|
|
|
${tools_dir}/grib_compare -P -b $BLACKLIST,typeOfCompressionUsed,targetCompressionRatio $outfile1 $outfile2 > $REDIRECT
|
|
|
|
|
|
|
|
res1=`${tools_dir}/grib_get '-F%1.2f' -p min,max,avg $infile`
|
|
|
|
res2=`${tools_dir}/grib_get '-F%1.2f' -p min,max,avg $outfile1`
|
|
|
|
res3=`${tools_dir}/grib_get '-F%1.2f' -p min,max,avg $outfile2`
|
2013-10-21 09:44:36 +00:00
|
|
|
[ "$res1" = "$res2" ]
|
|
|
|
[ "$res1" = "$res3" ]
|
2013-03-25 12:04:10 +00:00
|
|
|
|
2016-08-12 13:33:51 +00:00
|
|
|
rm -f $outfile2
|
|
|
|
|
2014-07-25 10:13:00 +00:00
|
|
|
# GRIB-564 nearest 4 neighbours with JPEG packing
|
2017-02-03 14:21:24 +00:00
|
|
|
res=`${tools_dir}/grib_get -l 0,50 $outfile1`
|
2014-07-25 10:13:00 +00:00
|
|
|
[ "$res" = "2.47244 2.47244 2.5115 2.51931 " ]
|
|
|
|
|
2016-11-17 17:08:22 +00:00
|
|
|
rm -f $outfile1
|
|
|
|
|
2016-08-12 13:33:51 +00:00
|
|
|
# ECC-317: Constant JPEG field numberOfValues
|
|
|
|
# Create a JPEG encoded GRIB message to have all constant values and one more value
|
|
|
|
# than input GRIB message
|
|
|
|
infile=${data_dir}/jpeg.grib2
|
2016-11-17 17:08:22 +00:00
|
|
|
outfile=$infile.temp.const
|
2016-08-12 13:33:51 +00:00
|
|
|
tempFilter1=temp.grib_jpeg_test1.filt
|
|
|
|
tempFilter2=temp.grib_jpeg_test2.filt
|
2017-02-03 14:21:24 +00:00
|
|
|
numberOfValuesOrig=`${tools_dir}/grib_get -p numberOfValues $infile`
|
2016-08-12 13:33:51 +00:00
|
|
|
# Create a filter to print the values. This will be used to create another filter
|
|
|
|
cat > $tempFilter1 <<EOF
|
|
|
|
print "set values={[values!1',']};";
|
|
|
|
print "write;";
|
|
|
|
EOF
|
|
|
|
# Run the filter on the input. Change the output to set all values to 1 with an additional entry
|
|
|
|
# so the output file should have original numberOfValues+1
|
2017-02-03 14:21:24 +00:00
|
|
|
${tools_dir}/grib_filter $tempFilter1 $infile |\
|
2016-08-12 13:33:51 +00:00
|
|
|
sed -e 's/[0-9][0-9]*/1/' |\
|
|
|
|
sed -e 's/set values={1,/set values={1,1,/' > $tempFilter2
|
|
|
|
# Apply the new filter to create the constant field JPEG file
|
2017-02-03 14:21:24 +00:00
|
|
|
${tools_dir}/grib_filter -o $outfile $tempFilter2 $infile
|
2016-08-12 13:33:51 +00:00
|
|
|
numberOfValuesNew=`expr $numberOfValuesOrig + 1`
|
2016-11-17 17:08:22 +00:00
|
|
|
grib_check_key_equals $outfile "numberOfValues" $numberOfValuesNew
|
2016-08-12 13:33:51 +00:00
|
|
|
rm -f $tempFilter1 $tempFilter2
|
|
|
|
|
2016-11-17 17:08:22 +00:00
|
|
|
rm -f $outfile $outfile2
|