ECC-1374: GRIB: Add key 'accuracy' that represents the number of bits, whatever the packing

This commit is contained in:
Shahram Najm 2022-03-28 15:55:39 +01:00
parent f25e4f3db6
commit 6eae07b94a
14 changed files with 38 additions and 16 deletions

View File

@ -9,6 +9,12 @@ alias numberOfBitsContainingEachPackedValue = bitsPerValue;
# TODO
codetable[1] precision "grib1/precision.table" = 2 : dump,edition_specific;
concept accuracy(zero) {
32 = { precision = 1; }
64 = { precision = 2; }
128 = { precision = 3; }
} : long_type, no_copy;
position offsetBeforeData;
if( bitmapPresent || !GDSPresent ) {
# For grib1 -> grib2

View File

@ -3,6 +3,7 @@
# moved here to allow different bitsPerValue in second order packing
unsigned[1] bitsPerValue : dump ;
alias numberOfBitsContainingEachPackedValue = bitsPerValue;
alias accuracy = bitsPerValue;
constant constantFieldHalfByte=8;
# For grib1 -> grib2

View File

@ -6,6 +6,7 @@ constant constantFieldHalfByte=0;
# moved here to allow different bitsPerValue in second order packing
unsigned[1] bitsPerValue : dump ;
alias numberOfBitsContainingEachPackedValue = bitsPerValue;
alias accuracy = bitsPerValue;
unsigned[2] octetAtWichPackedDataBegins;
flags[1] extendedFlag "grib1/11-2.table";

View File

@ -3,6 +3,7 @@
# moved here to allow different bitsPerValue in second order packing
unsigned[1] bitsPerValue : dump;
alias numberOfBitsContainingEachPackedValue = bitsPerValue;
alias accuracy = bitsPerValue;
# For grib1 -> grib2

View File

@ -3,6 +3,7 @@
# moved here to allow different bitsPerValue in second order packing
unsigned[1] bitsPerValue : dump;
alias numberOfBitsContainingEachPackedValue = bitsPerValue;
alias accuracy = bitsPerValue;
# For grib1 -> grib2

View File

@ -3,6 +3,7 @@
# moved here to allow different bitsPerValue in second order packing
unsigned[1] bitsPerValue : dump ;
alias numberOfBitsContainingEachPackedValue = bitsPerValue;
alias accuracy = bitsPerValue;
# For grib1 -> grib2
#constant dataRepresentationTemplateNumber = 50;

View File

@ -128,6 +128,7 @@ alias typeOfPacking=packingType;
if( binaryScaleFactor == -32767) {
unsigned[1] bitsPerValue : dump ;
alias numberOfBitsContainingEachPackedValue = bitsPerValue;
alias accuracy = bitsPerValue;
constant dataRepresentationTemplateNumber = 0;
constant bitMapIndicator = 0;

View File

@ -10,3 +10,8 @@ alias numberOfBits = bitsPerValue;
alias numberOfBitsContainingEachPackedValue = bitsPerValue;
codetable[1] precision ('5.7.table',masterDir,localDir) = 1 : edition_specific;
concept accuracy(zero) {
32 = { precision = 1; }
64 = { precision = 2; }
128 = { precision = 3; }
} : long_type, no_copy;

View File

@ -6,7 +6,6 @@
ieeefloat referenceValue : read_only, copy_ok;
meta referenceValueError reference_value_error(referenceValue,ieee);
# Binary scale factor (E)
signed[2] binaryScaleFactor : read_only, copy_ok;
@ -21,3 +20,4 @@ transient optimizeScaleFactor = 0;
unsigned[1] bitsPerValue;
alias numberOfBits = bitsPerValue;
alias numberOfBitsContainingEachPackedValue = bitsPerValue;
alias accuracy = bitsPerValue;

View File

@ -29,6 +29,7 @@ ${tools_dir}/grib_set -s packingType=grid_ccsds $grib2_sample $outfile1
${tools_dir}/grib_set -d1 $outfile1 $outfile2
grib_check_key_equals $grib2_sample packingType,const "grid_simple 0"
grib_check_key_equals $outfile2 packingType,const "grid_ccsds 1"
grib_check_key_equals $outfile2 accuracy 16
rm -f $outfile1 $outfile2
# Change packingType
@ -77,6 +78,7 @@ ${tools_dir}/grib_compare -c data:n $outfile1 $outfile2
# ECC-477: redundant error message during conversion
# ---------------------------------------------------
infile=${data_dir}/ccsds.grib2
grib_check_key_equals $infile accuracy 14
rm -f $outfile2
${tools_dir}/grib_set -r -s packingType=grid_simple $infile $outfile1 >$outfile2 2>&1
# there should be no error messages printed (to stdout or stderr)

View File

@ -51,6 +51,9 @@ test_packing() {
exit 1
fi
result=`${tools_dir}/grib_get -p accuracy $temp`
[ $result -eq 0 -o $result -eq 32 -o $result -eq 64 ]
shift
done
@ -62,6 +65,7 @@ test_packing() {
input=${data_dir}/spherical_model_level.grib2
output=`${tools_dir}/grib_set -r -s packingType=spectral_simple $input $temp 2>&1`
grib_check_key_equals $temp packingType 'spectral_simple'
grib_check_key_equals $temp accuracy 16
# Check no error was posted i.e. output string is empty
[ -z "$output" ]
res1=`${tools_dir}/grib_get '-F%.1f' -p avg,enorm $input`
@ -74,7 +78,9 @@ rm -f $temp
# -----------------------
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 24
stats1=`${tools_dir}/grib_get -F%.2f -p skew,kurt $input`
stats2=`${tools_dir}/grib_get -F%.2f -p skew,kurt $temp`
[ "$stats1" = "$stats2" ]

View File

@ -53,14 +53,14 @@ export GRIB_IEEE_PACKING=32
${tools_dir}/grib_filter -o $out32 w.filter $infile
${tools_dir}/grib_filter r.filter $out32 > $out32.txt
diff $out32.txt ${data_dir}/ieee_test.good
grib_check_key_equals $out32 'packingType,precision' 'grid_ieee 1'
grib_check_key_equals $out32 'packingType,precision,accuracy' 'grid_ieee 1 32'
export GRIB_IEEE_PACKING=64
${tools_dir}/grib_filter -o $out64 w.filter $infile
${tools_dir}/grib_filter r.filter $out64 > $out64.txt
diff $out64.txt ${data_dir}/ieee_test.good
grib_check_key_equals $out64 'packingType,precision' 'grid_ieee 2'
grib_check_key_equals $out64 'packingType,precision,accuracy' 'grid_ieee 2 64'
rm -f $outsimple $out32 $out64 $out32.txt $out64.txt

View File

@ -12,12 +12,6 @@
REDIRECT=/dev/null
# Disable if autotools being used
src_config=${src_dir}/config.h
if [ -f ${src_config} ]; then
exit 0
fi
BLACKLIST="totalLength,section5Length,section7Length,dataRepresentationTemplateNumber,typeOfPacking"
do_tests()
@ -31,6 +25,8 @@ do_tests()
# Test dump
${tools_dir}/grib_dump -Da $infile >/dev/null 2>&1
grib_check_key_equals $infile accuracy 14
${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

View File

@ -48,6 +48,7 @@ infile=${data_dir}/grid_ieee.grib
${tools_dir}/grib_set -r -s packingType=grid_png $infile $temp
# TODO: check results
grib_check_key_equals $temp packingType grid_png
grib_check_key_equals $temp accuracy 0
rm -f $temp