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.
|
|
|
|
#
|
|
|
|
# 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
|
|
|
#set -x
|
|
|
|
|
|
|
|
REDIRECT=/dev/null
|
2021-08-12 15:59:01 +00:00
|
|
|
sample_g1=$ECCODES_SAMPLES_PATH/reduced_gg_pl_640_grib1.tmpl
|
|
|
|
sample_g2=$ECCODES_SAMPLES_PATH/reduced_gg_pl_640_grib2.tmpl
|
2013-03-25 12:04:10 +00:00
|
|
|
|
|
|
|
cd ${data_dir}
|
2015-01-26 15:50:33 +00:00
|
|
|
rm -f local.log
|
2013-03-25 12:04:10 +00:00
|
|
|
|
2021-07-14 16:43:25 +00:00
|
|
|
# Check all GRIB2 local def files and definitions/grib2/grib2LocalSectionNumber.98.table
|
|
|
|
# Each number should appear in the table
|
2021-08-12 15:59:01 +00:00
|
|
|
# -----------------------------------------
|
2021-07-14 16:43:25 +00:00
|
|
|
g2lds=${ECCODES_DEFINITION_PATH}/grib2/local.98.*.def
|
|
|
|
for g2ld in $g2lds; do
|
2021-07-14 18:39:26 +00:00
|
|
|
bname=`basename $g2ld`
|
|
|
|
dnum=`echo $bname | cut -d. -f3`
|
2021-07-14 16:43:25 +00:00
|
|
|
grep -q "^$dnum" ${ECCODES_DEFINITION_PATH}/grib2/grib2LocalSectionNumber.98.table
|
|
|
|
done
|
|
|
|
|
2021-08-12 15:59:01 +00:00
|
|
|
# Use of subCentre=98 for other centre GRIBs
|
|
|
|
# ------------------------------------------
|
|
|
|
temp=temp.grib_local.grib
|
|
|
|
${tools_dir}/grib_set -s centre=edzw,subCentre=98,setLocalDefinition=1,localDefinitionNumber=1 \
|
|
|
|
$ECCODES_SAMPLES_PATH/GRIB2.tmpl $temp
|
|
|
|
grib_check_key_equals $temp section2Length,centre,expver,marsClass:i,marsType:i,marsStream:i "17 edzw 0001 1 2 1025"
|
|
|
|
rm -f $temp
|
|
|
|
|
2021-07-14 16:43:25 +00:00
|
|
|
|
2017-02-03 14:21:24 +00:00
|
|
|
${tools_dir}/grib_set -s edition=2,setLocalDefinition=1 reduced_gaussian_model_level.grib1 loc.grib2
|
|
|
|
${tools_dir}/grib_set -s setLocalDefinition=1 reduced_gaussian_model_level.grib1 loc.grib1
|
2013-03-25 12:04:10 +00:00
|
|
|
|
2021-08-12 15:59:01 +00:00
|
|
|
# Conversion 1->2
|
|
|
|
# ----------------
|
2013-03-25 12:04:10 +00:00
|
|
|
for localDefinitionNumber in 1 15 26 30
|
|
|
|
do
|
2017-04-20 17:23:56 +00:00
|
|
|
${tools_dir}/grib_set -s localDefinitionNumber=$localDefinitionNumber,perturbationNumber=2,numberOfForecastsInEnsemble=50 loc.grib1 eps.grib1
|
|
|
|
${tools_dir}/grib_set -s edition=2 eps.grib1 eps.grib2
|
2013-03-25 12:04:10 +00:00
|
|
|
|
2017-04-20 17:23:56 +00:00
|
|
|
${tools_dir}/grib_get -p localDefinitionNumber,perturbationNumber,numberOfForecastsInEnsemble,productDefinitionTemplateNumber eps.grib2 >> local.log
|
|
|
|
${tools_dir}/grib_compare -e -b param eps.grib1 eps.grib2
|
2013-03-25 12:04:10 +00:00
|
|
|
|
2017-04-20 17:23:56 +00:00
|
|
|
${tools_dir}/grib_set -s localDefinitionNumber=$localDefinitionNumber,numberOfForecastsInEnsemble=0 loc.grib1 eps.grib1
|
|
|
|
${tools_dir}/grib_set -s edition=2 eps.grib1 eps.grib2
|
2013-03-25 12:04:10 +00:00
|
|
|
|
2017-04-20 17:23:56 +00:00
|
|
|
${tools_dir}/grib_get -f -p localDefinitionNumber,perturbationNumber,productDefinitionTemplateNumber eps.grib2 >> local.log
|
|
|
|
${tools_dir}/grib_compare -e -b param eps.grib1 eps.grib2
|
2013-03-25 12:04:10 +00:00
|
|
|
done
|
|
|
|
|
2021-08-12 15:59:01 +00:00
|
|
|
# Local -> local
|
|
|
|
# ---------------
|
2013-03-25 12:04:10 +00:00
|
|
|
for localStart in 1 7 9 20 25 26 30
|
|
|
|
do
|
2017-04-20 17:23:56 +00:00
|
|
|
${tools_dir}/grib_set -s localDefinitionNumber=$localStart loc.grib1 loc1.grib1
|
|
|
|
${tools_dir}/grib_set -s edition=2 loc1.grib1 loc1.grib2
|
|
|
|
${tools_dir}/grib_get -p localDefinitionNumber loc1.grib1 >> local.log
|
|
|
|
${tools_dir}/grib_get -p localDefinitionNumber loc1.grib2 >> local.log
|
|
|
|
|
|
|
|
for localEps in 1 15 26 30
|
|
|
|
do
|
|
|
|
${tools_dir}/grib_set -s localDefinitionNumber=$localEps,eps=1,perturbationNumber=2,numberOfForecastsInEnsemble=50 loc1.grib2 eps.grib2
|
|
|
|
${tools_dir}/grib_get -p localDefinitionNumber,perturbationNumber,numberOfForecastsInEnsemble,productDefinitionTemplateNumber eps.grib2 >> local.log
|
|
|
|
done
|
2013-03-25 12:04:10 +00:00
|
|
|
done
|
|
|
|
|
2021-08-12 15:59:01 +00:00
|
|
|
# Special types/streams
|
|
|
|
# ----------------------
|
2017-02-03 14:21:24 +00:00
|
|
|
${tools_dir}/grib_set -s localDefinitionNumber=1,numberOfForecastsInEnsemble=0 loc.grib1 loc1.grib1
|
|
|
|
${tools_dir}/grib_set -s edition=2 loc1.grib1 loc1.grib2
|
|
|
|
${tools_dir}/grib_get -f -p localDefinitionNumber,perturbationNumber loc1.grib2 >> local.log
|
|
|
|
${tools_dir}/grib_set -s type=em loc1.grib2 eps.grib2
|
|
|
|
${tools_dir}/grib_get -p localDefinitionNumber,productDefinitionTemplateNumber,derivedForecast eps.grib2 >> local.log
|
|
|
|
${tools_dir}/grib_set -s type=es loc1.grib2 eps.grib2
|
|
|
|
${tools_dir}/grib_get -p localDefinitionNumber,productDefinitionTemplateNumber,derivedForecast eps.grib2 >> local.log
|
|
|
|
${tools_dir}/grib_set -s stream=enda loc1.grib2 eps.grib2 #2> $REDIRECT
|
|
|
|
${tools_dir}/grib_get -p localDefinitionNumber,productDefinitionTemplateNumber eps.grib2 >> local.log
|
2013-03-25 12:04:10 +00:00
|
|
|
|
|
|
|
diff local.log local.good.log
|
|
|
|
|
|
|
|
rm -f local.log loc.grib1 loc.grib2 loc1.grib1 loc1.grib2 eps.grib1 eps.grib2
|
|
|
|
|
2019-12-08 17:23:28 +00:00
|
|
|
|
2017-04-20 16:38:38 +00:00
|
|
|
# Delete Local Definition
|
|
|
|
# -----------------------
|
|
|
|
temp=temp.grib_local.grib
|
|
|
|
grib_check_key_equals $sample_g1 localUsePresent 1
|
|
|
|
${tools_dir}/grib_set -s deleteLocalDefinition=1 $sample_g1 $temp
|
|
|
|
grib_check_key_equals $temp localUsePresent 0
|
|
|
|
|
|
|
|
grib_check_key_equals $sample_g2 "localUsePresent,section2Used" "1 1"
|
|
|
|
${tools_dir}/grib_set -s deleteLocalDefinition=1 $sample_g2 $temp
|
|
|
|
grib_check_key_equals $temp "localUsePresent,section2Used" "0 0"
|
2017-04-20 17:23:56 +00:00
|
|
|
rm -f $temp
|
|
|
|
|
2019-12-08 17:23:28 +00:00
|
|
|
|
2017-04-20 17:23:56 +00:00
|
|
|
# Empty local section for GRIB2
|
|
|
|
# ------------------------------
|
|
|
|
sample_g2=$ECCODES_SAMPLES_PATH/reduced_gg_pl_640_grib2.tmpl
|
|
|
|
temp=temp.grib_local.grib
|
|
|
|
${tools_dir}/grib_set -s setLocalDefinition=1,addEmptySection2=1 $sample_g2 $temp
|
|
|
|
grib_check_key_equals $temp section2Length 5
|
|
|
|
|
|
|
|
sample_g2=$ECCODES_SAMPLES_PATH/reduced_gg_pl_400_grib2.tmpl
|
|
|
|
grib_check_key_equals $sample_g2 section2Length 17
|
|
|
|
${tools_dir}/grib_set -s addEmptySection2=1 $sample_g2 $temp
|
|
|
|
grib_check_key_equals $temp section2Length 5
|
|
|
|
rm -f $temp
|
2017-04-20 16:38:38 +00:00
|
|
|
|
2019-12-08 17:23:28 +00:00
|
|
|
|
2021-08-20 13:51:14 +00:00
|
|
|
# Local Definition 4: Ocean model data
|
|
|
|
# ---------------------------------------
|
|
|
|
${tools_dir}/grib_set -s \
|
|
|
|
localDefinitionNumber=4,coordinate2Flag=2,averaging1Flag=1,coordinate1Flag=1,coordinate2Start=1234 \
|
|
|
|
$sample_g1 $temp
|
|
|
|
grib_check_key_equals $temp "mars.levelist,roundedMarsLevelist:d,roundedMarsLevelist:s" "1 1.234 1.234"
|
|
|
|
|
|
|
|
|
2024-01-18 15:52:10 +00:00
|
|
|
# Local Definition 192
|
|
|
|
# ---------------------------------------
|
|
|
|
${tools_dir}/grib_set -s setLocalDefinition=1,localDefinitionNumber=192 $sample_g2 $temp
|
|
|
|
${tools_dir}/grib_set -s stepType=accum,setLocalDefinition=1,localDefinitionNumber=192 $sample_g2 $temp
|
|
|
|
|
|
|
|
|
2021-08-20 13:51:14 +00:00
|
|
|
# Local Definition 5: Forecast probability data
|
|
|
|
# ---------------------------------------------
|
2017-04-07 09:51:48 +00:00
|
|
|
sample_g1=$ECCODES_SAMPLES_PATH/GRIB1.tmpl
|
|
|
|
temp=temp.grib_local.grib
|
|
|
|
${tools_dir}/grib_set -s setLocalDefinition=1,localDefinitionNumber=5 $sample_g1 $temp.1
|
|
|
|
${tools_dir}/grib_set -s \
|
|
|
|
forecastProbabilityNumber=2,totalNumberOfForecastProbabilities=25,thresholdIndicator=3,lowerThreshold=54,upperThreshold=56 \
|
|
|
|
$temp.1 $temp.2
|
|
|
|
${tools_dir}/grib_set -s edition=2 $temp.2 $temp.3
|
|
|
|
# Now check all LD5 keys from grib1 made it into grib2
|
|
|
|
grib_check_key_equals $temp.3 edition,productDefinitionTemplateNumber "2 5"
|
|
|
|
grib_check_key_equals $temp.3 forecastProbabilityNumber,totalNumberOfForecastProbabilities "2 25"
|
|
|
|
grib_check_key_equals $temp.3 probabilityType,scaledValueOfLowerLimit,scaledValueOfUpperLimit "2 54 56"
|
|
|
|
|
2019-12-20 17:05:52 +00:00
|
|
|
# ECC-1045
|
|
|
|
${tools_dir}/grib_set -s localDefinitionNumber=5,lowerThreshold=missing,upperThreshold=missing \
|
|
|
|
$sample_g1 $temp.1
|
|
|
|
grib_check_key_equals $temp.1 'lowerThreshold,upperThreshold' 'MISSING MISSING'
|
|
|
|
|
2019-12-08 17:23:28 +00:00
|
|
|
|
2018-01-30 17:54:17 +00:00
|
|
|
# Local Definition 42 for GRIB2 (LC-WFV)
|
|
|
|
# ---------------------------------------
|
2018-02-12 13:48:05 +00:00
|
|
|
${tools_dir}/grib_set -s setLocalDefinition=1,localDefinitionNumber=42,lcwfvSuiteName=9 $sample_g2 $temp
|
|
|
|
grib_check_key_equals $temp 'mars.origin:s' 'lops'
|
2018-01-30 17:54:17 +00:00
|
|
|
|
2019-12-08 17:23:28 +00:00
|
|
|
|
2018-04-23 11:22:27 +00:00
|
|
|
# Extra key in Local Definition 16 for GRIB1. ECC-679
|
2021-06-20 13:41:58 +00:00
|
|
|
# ----------------------------------------------------
|
|
|
|
${tools_dir}/grib_set -s \
|
2021-06-21 14:24:06 +00:00
|
|
|
setLocalDefinition=1,localDefinitionNumber=16,numberOfForecastsInEnsemble=51,verifyingMonth=11 \
|
2021-06-20 13:41:58 +00:00
|
|
|
$sample_g1 $temp
|
2021-06-21 14:24:06 +00:00
|
|
|
grib_check_key_equals $temp 'totalNumber' '51'
|
|
|
|
grib_check_key_equals $temp 'yearOfEndOfOverallTimeInterval,monthOfEndOfOverallTimeInterval,dayOfEndOfOverallTimeInterval' '0 11 30'
|
2019-12-08 17:23:28 +00:00
|
|
|
|
2020-01-07 15:18:28 +00:00
|
|
|
# Local Definition 49 for GRIB1
|
|
|
|
# -----------------------------
|
|
|
|
${tools_dir}/grib_set -s localDefinitionNumber=49,type=35 $sample_g1 $temp
|
|
|
|
grib_check_key_equals $temp 'perturbationNumber,numberOfForecastsInEnsemble' '0 0'
|
|
|
|
|
|
|
|
|
2020-06-19 16:42:48 +00:00
|
|
|
# Local Definition 39 and type 'eme' for GRIB2
|
|
|
|
# --------------------------------------------
|
|
|
|
${tools_dir}/grib_set -s \
|
|
|
|
setLocalDefinition=1,localDefinitionNumber=39,type=eme,stream=elda,componentIndex=11,offsetToEndOf4DvarWindow=12 \
|
|
|
|
$sample_g2 $temp
|
|
|
|
grib_check_key_equals $temp 'mars.number,mars.anoffset' '11 12'
|
|
|
|
${tools_dir}/grib_set -s setLocalDefinition=1,localDefinitionNumber=39,type=eme,stream=enda,componentIndex=11 $sample_g2 $temp
|
|
|
|
grib_check_key_equals $temp 'mars.number' '11'
|
|
|
|
|
2020-01-07 15:18:28 +00:00
|
|
|
|
2019-12-08 17:23:28 +00:00
|
|
|
# Local Definition 18 (list of ascii keys)
|
|
|
|
# ----------------------------------------
|
|
|
|
${tools_dir}/grib_filter -o $temp - $sample_g1 << EOF
|
|
|
|
set setLocalDefinition=1;
|
|
|
|
set localDefinitionNumber=18;
|
|
|
|
set consensusCount=3;
|
|
|
|
set ccccIdentifiers={"kwbc","ecmf","sabm"};
|
|
|
|
write;
|
|
|
|
EOF
|
|
|
|
|
|
|
|
result=`echo 'print "[ccccIdentifiers]";' | ${tools_dir}/grib_filter - $temp`
|
|
|
|
[ "$result" = "kwbc ecmf sabm" ]
|
|
|
|
|
|
|
|
|
2022-06-22 11:33:01 +00:00
|
|
|
# ECC-1413: Local Definition 38
|
|
|
|
# --------------------------------
|
|
|
|
${tools_dir}/grib_set -s \
|
|
|
|
setLocalDefinition=1,localDefinitionNumber=38,type=4i,stream=elda,iterationNumber=23 \
|
|
|
|
$sample_g2 $temp
|
|
|
|
grib_check_key_equals $temp 'mars.iteration' '23'
|
|
|
|
${tools_dir}/grib_ls -jm $temp > $temp.1
|
|
|
|
grep -q "iteration.* 23" $temp.1
|
|
|
|
|
2023-03-07 17:47:58 +00:00
|
|
|
# ECC-1540: Local Definition 36
|
|
|
|
# --------------------------------
|
|
|
|
${tools_dir}/grib_set -s \
|
|
|
|
setLocalDefinition=1,localDefinitionNumber=36,paramId=210170,class=rd,type=4v,stream=elda \
|
|
|
|
$sample_g2 $temp
|
|
|
|
grib_check_key_exists $temp mars.number,constituentType,sourceSinkChemicalPhysicalProcess
|
|
|
|
${tools_dir}/grib_set -s localDefinitionNumber=36 $temp $temp.1
|
|
|
|
${tools_dir}/grib_compare $temp $temp.1
|
2021-08-20 13:51:14 +00:00
|
|
|
|
2024-01-18 15:52:10 +00:00
|
|
|
# Chemicals, aerosols etc (check GRIB2 templates are selected)
|
|
|
|
${tools_dir}/grib_set -s paramId=211123,setLocalDefinition=1,localDefinitionNumber=36 $sample_g2 $temp
|
|
|
|
grib_check_key_equals $temp productDefinitionTemplateNumber 40
|
|
|
|
|
2024-07-08 10:42:45 +00:00
|
|
|
# Also see ECC-1760: is_chemical_srcsink removed so no automaric selection of product definition template
|
|
|
|
${tools_dir}/grib_set -s productDefinitionTemplateNumber=76,paramId=456000,setLocalDefinition=1,localDefinitionNumber=36 $sample_g2 $temp
|
|
|
|
grib_check_key_equals $temp shortName drydep_vel_vol
|
2024-01-18 15:52:10 +00:00
|
|
|
|
|
|
|
${tools_dir}/grib_set -s paramId=215225,setLocalDefinition=1,localDefinitionNumber=36 $sample_g2 $temp
|
|
|
|
grib_check_key_equals $temp productDefinitionTemplateNumber 48
|
|
|
|
|
|
|
|
${tools_dir}/grib_set -s paramId=210251,setLocalDefinition=1,localDefinitionNumber=36 $sample_g2 $temp
|
|
|
|
|
|
|
|
|
2022-06-22 11:33:01 +00:00
|
|
|
# Clean up
|
2017-04-20 17:23:56 +00:00
|
|
|
rm -f $temp $temp.1 $temp.2 $temp.3
|