ECC-1906: GRIB2: Templates for wave spectra with direction/frequency array do not set section 4 length correctly if adapting the array size

This commit is contained in:
Shahram Najm 2024-08-16 11:37:19 +00:00
parent 634134ea14
commit ec75063014
3 changed files with 33 additions and 12 deletions

View File

@ -1,21 +1,21 @@
# (C) Copyright 2005- ECMWF.
# Template for wave parameters
## Direction part
# Direction part
unsigned[2] waveDirectionNumber : dump;
alias mars.direction = waveDirectionNumber;
alias directionNumber = waveDirectionNumber;
unsigned[2] numberOfWaveDirections = 1 : dump;
unsigned[2] numberOfWaveDirections = 0 : dump;
alias totalNumberOfWaveDirections = numberOfWaveDirections;
alias numberOfDirections = totalNumberOfWaveDirections;
## Frequency part
# Frequency part
unsigned[2] waveFrequencyNumber : dump;
alias mars.frequency = waveFrequencyNumber;
alias frequencyNumber = waveFrequencyNumber;
unsigned[2] numberOfWaveFrequencies = 1 : dump;
unsigned[2] numberOfWaveFrequencies = 0 : dump;
alias totalNumberOfWaveFrequencies = numberOfWaveFrequencies;
alias numberOfFrequencies = totalNumberOfWaveFrequencies;

View File

@ -2,18 +2,22 @@
# Template for wave spectra defined using an array of frequencies and directions
## Direction part
# Direction part
signed[1] scaleFactorOfWaveDirections : dump;
alias integerScalingFactorAppliedToDirections = scaleFactorOfWaveDirections;
alias directionScalingFactor = integerScalingFactorAppliedToDirections;
unsigned[4] scaledValuesOfWaveDirections[numberOfWaveDirections] : dump;
alias scaledDirections = scaledValuesOfWaveDirections ;
if (numberOfWaveDirections > 0) {
unsigned[4] scaledValuesOfWaveDirections[numberOfWaveDirections] : dump;
alias scaledDirections = scaledValuesOfWaveDirections ;
}
## Frequency part
# Frequency part
signed[1] scaleFactorOfWaveFrequencies : dump;
alias integerScalingFactorAppliedToFrequencies = scaleFactorOfWaveFrequencies;
alias frequencyScalingFactor = integerScalingFactorAppliedToFrequencies;
unsigned[4] scaledValuesOfWaveFrequencies[numberOfWaveFrequencies] : dump;
alias scaledFrequencies = scaledValuesOfWaveFrequencies;
if (numberOfWaveFrequencies > 0) {
unsigned[4] scaledValuesOfWaveFrequencies[numberOfWaveFrequencies] : dump;
alias scaledFrequencies = scaledValuesOfWaveFrequencies;
}

View File

@ -15,6 +15,9 @@ temp=temp.$label
tempGribA=temp.$label.A.grib
tempGribB=temp.$label.B.grib
tempSample=temp.$label.tmpl
tempRef=temp.$label.ref
tempOut=temp.$label.txt
sample2=$ECCODES_SAMPLES_PATH/GRIB2.tmpl
latest=`${tools_dir}/grib_get -p tablesVersionLatest $sample2`
@ -23,9 +26,23 @@ latest=`${tools_dir}/grib_get -p tablesVersionLatest $sample2`
${tools_dir}/grib_set -s tablesVersion=$latest,productDefinitionTemplateNumber=99 $sample2 $tempSample
${tools_dir}/grib_set -s numberOfWaveDirections=3,numberOfWaveFrequencies=3 $tempSample $temp
# ECC-1906
# --------
${tools_dir}/grib_set -s productDefinitionTemplateNumber=99,numberOfWaveDirections=5 $sample2 $tempGribA
echo 'print "[numberOfWaveDirections=] [scaledValuesOfWaveDirections=!0]";' | ${tools_dir}/grib_filter - $tempGribA > $tempOut
cat > $tempRef <<EOF
numberOfWaveDirections=5 scaledValuesOfWaveDirections=0 0 0 0 0
EOF
diff $tempRef $tempOut
echo 'set productDefinitionTemplateNumber=99; set numberOfWaveDirections=5; write;' | ${tools_dir}/grib_filter -o $tempGribB - $sample2
${tools_dir}/grib_compare $tempGribA $tempGribB
rm -f $tempGribA $tempGribB
# Wave 2D spectra with explicit list of frequencies and directions, ensemble
${tools_dir}/grib_set -s tablesVersion=$latest,productDefinitionTemplateNumber=100 $sample2 $tempSample
grib_check_key_equals $tempSample numberOfWaveDirections,numberOfWaveFrequencies,perturbationNumber '1 1 0'
grib_check_key_equals $tempSample numberOfWaveDirections,numberOfWaveFrequencies,perturbationNumber '0 0 0'
# Wave 2D spectra with frequencies and directions defined by formulae
${tools_dir}/grib_set -s tablesVersion=$latest,productDefinitionTemplateNumber=101 $sample2 $tempSample
@ -68,4 +85,4 @@ ${tools_dir}/grib_compare -b marsType,typeOfProcessedData,typeOfGeneratingProces
# Clean up
rm -f $tempSample $temp $tempGribA $tempGribB
rm -f $tempSample $temp $tempGribA $tempGribB $tempRef $tempOut