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
|
|
|
|
|
|
|
REDIRECT=/dev/null
|
|
|
|
|
2021-11-25 16:41:46 +00:00
|
|
|
label=grib_step_test
|
|
|
|
tempGrb=${data_dir}/temp.$label.out.grib
|
|
|
|
templog=${data_dir}/temp.$label.log
|
|
|
|
rm -f $templog $tempGrb
|
|
|
|
|
2023-10-13 11:28:32 +00:00
|
|
|
grib1_sample=$ECCODES_SAMPLES_PATH/GRIB1.tmpl
|
|
|
|
grib2_sample=$ECCODES_SAMPLES_PATH/GRIB2.tmpl
|
|
|
|
|
2013-03-25 12:04:10 +00:00
|
|
|
for i in 0 10
|
|
|
|
do
|
|
|
|
for s in 0 1200 600 6000
|
|
|
|
do
|
|
|
|
for key in stepRange:s startStep endStep
|
|
|
|
do
|
2021-11-25 16:41:46 +00:00
|
|
|
rm -f $tempGrb
|
|
|
|
${tools_dir}/grib_set -s ${key}=$s ${data_dir}/timeRangeIndicator_${i}.grib $tempGrb
|
|
|
|
#echo grib_set -s ${key}=$s ${data_dir}/timeRangeIndicator_${i}.grib $tempGrb
|
|
|
|
#grib_get -p step,startStep,endStep,P1,P2,timeRangeIndicator,indicatorOfUnitOfTimeRange ${data_dir}/timeRangeIndicator_${i}.grib $tempGrb
|
|
|
|
${tools_dir}/grib_get -p mars.step,stepRange,startStep,endStep,P1,P2,timeRangeIndicator,indicatorOfUnitOfTimeRange:l \
|
|
|
|
${data_dir}/timeRangeIndicator_${i}.grib $tempGrb >> ${templog}
|
2013-03-25 12:04:10 +00:00
|
|
|
done
|
|
|
|
done
|
|
|
|
done
|
|
|
|
|
|
|
|
i=5
|
|
|
|
key=stepRange:s
|
|
|
|
for s in "0-24" "600-1200" "24-48" "36-66"
|
|
|
|
do
|
2021-11-25 16:41:46 +00:00
|
|
|
${tools_dir}/grib_set -s ${key}=$s ${data_dir}/timeRangeIndicator_${i}.grib $tempGrb
|
|
|
|
#echo grib_set -s ${key}=$s ${data_dir}/timeRangeIndicator_${i}.grib $tempGrb
|
|
|
|
#grib_ls -p step,startStep,endStep,P1,P2,timeRangeIndicator,indicatorOfUnitOfTimeRange ${data_dir}/timeRangeIndicator_${i}.grib $tempGrb
|
|
|
|
${tools_dir}/grib_get -p mars.step,stepRange,startStep,endStep,P1,P2,timeRangeIndicator,indicatorOfUnitOfTimeRange:l \
|
|
|
|
${data_dir}/timeRangeIndicator_${i}.grib $tempGrb >> ${templog}
|
2013-03-25 12:04:10 +00:00
|
|
|
done
|
|
|
|
|
2021-11-25 16:41:46 +00:00
|
|
|
rm -f $tempGrb
|
2013-03-25 12:04:10 +00:00
|
|
|
|
|
|
|
# test added for ifs stepType=max,min
|
2021-11-25 16:41:46 +00:00
|
|
|
${tools_dir}/grib_set -s stepType=max,startStep=3,endStep=6 ${data_dir}/reduced_gaussian_model_level.grib1 $tempGrb
|
|
|
|
${tools_dir}/grib_get -p mars.step,stepRange,startStep,endStep,P1,P2,timeRangeIndicator,indicatorOfUnitOfTimeRange:l \
|
|
|
|
${data_dir}/reduced_gaussian_model_level.grib1 $tempGrb >> ${templog}
|
2013-03-25 12:04:10 +00:00
|
|
|
|
2021-11-25 16:41:46 +00:00
|
|
|
rm -f $tempGrb
|
2013-03-25 12:04:10 +00:00
|
|
|
|
2021-11-25 16:41:46 +00:00
|
|
|
diff ${data_dir}/step.log ${templog}
|
2013-03-25 12:04:10 +00:00
|
|
|
|
2017-02-03 14:21:24 +00:00
|
|
|
(${tools_dir}/grib_filter ${data_dir}/step_grib1.filter ${data_dir}/timeRangeIndicator_0.grib > ${templog}) 2>$REDIRECT
|
2013-03-25 12:04:10 +00:00
|
|
|
|
2021-11-25 16:41:46 +00:00
|
|
|
diff ${data_dir}/step_grib1.log ${templog}
|
2013-03-25 12:04:10 +00:00
|
|
|
|
2020-07-04 14:30:10 +00:00
|
|
|
rm -f ${templog}
|
2013-03-25 12:04:10 +00:00
|
|
|
|
|
|
|
# GRIB-180
|
2022-07-26 12:23:32 +00:00
|
|
|
# ------------
|
2013-03-25 12:04:10 +00:00
|
|
|
# Set PDT 4.8 where you can find the EndOfOverallTimeInterval keys
|
2014-08-28 09:03:16 +00:00
|
|
|
grib2File=${data_dir}/reduced_latlon_surface_constant.grib2
|
2017-02-03 14:21:24 +00:00
|
|
|
${tools_dir}/grib_set -sproductDefinitionTemplateNumber=8 $grib2File ${grib2File}.p8tmp
|
2013-03-25 12:04:10 +00:00
|
|
|
|
|
|
|
# 78 hours is 3 days and 6 hours
|
2017-02-03 14:21:24 +00:00
|
|
|
${tools_dir}/grib_set -s step=78 $grib2File.p8tmp ${grib2File}.tmp
|
|
|
|
set `${tools_dir}/grib_get -p hourOfEndOfOverallTimeInterval,dayOfEndOfOverallTimeInterval ${grib2File}.tmp`
|
2013-03-25 12:04:10 +00:00
|
|
|
hourEnd=$1; dayEnd=$2
|
|
|
|
[ "$hourEnd" = "18" ]
|
2014-08-28 09:03:16 +00:00
|
|
|
[ "$dayEnd" = "8" ]
|
2013-03-25 12:04:10 +00:00
|
|
|
|
2017-02-03 14:21:24 +00:00
|
|
|
${tools_dir}/grib_set -s step=12 $grib2File.p8tmp ${grib2File}.tmp
|
|
|
|
set `${tools_dir}/grib_get -p hourOfEndOfOverallTimeInterval,dayOfEndOfOverallTimeInterval ${grib2File}.tmp`
|
2013-03-25 12:04:10 +00:00
|
|
|
hourEnd=$1; dayEnd=$2
|
|
|
|
[ "$hourEnd" = "0" ]
|
2014-08-28 09:03:16 +00:00
|
|
|
[ "$dayEnd" = "6" ]
|
2013-03-25 12:04:10 +00:00
|
|
|
|
2015-06-23 12:34:03 +00:00
|
|
|
|
|
|
|
# ECC-134 case-sensitivity
|
2023-10-15 14:28:46 +00:00
|
|
|
# ------------------------
|
2015-06-23 12:34:03 +00:00
|
|
|
temp=temp.step.$$.grib
|
|
|
|
# M is for Month (code 3)
|
2017-02-03 14:21:24 +00:00
|
|
|
${tools_dir}/grib_set -s indicatorOfUnitOfTimeRange=M $grib1_sample $temp
|
|
|
|
unit=`${tools_dir}/grib_get -p unitOfTimeRange $temp`
|
2015-06-23 12:34:03 +00:00
|
|
|
[ "$unit" = "3" ]
|
2017-02-03 14:21:24 +00:00
|
|
|
${tools_dir}/grib_set -s indicatorOfUnitOfTimeRange=M $grib2_sample $temp
|
|
|
|
unit=`${tools_dir}/grib_get -p indicatorOfUnitOfTimeRange $temp`
|
2015-06-23 12:34:03 +00:00
|
|
|
[ "$unit" = "3" ]
|
|
|
|
|
|
|
|
# m is for Minute (code 0)
|
2023-10-15 14:28:46 +00:00
|
|
|
# ------------------------
|
2017-02-03 14:21:24 +00:00
|
|
|
${tools_dir}/grib_set -s indicatorOfUnitOfTimeRange=m $grib1_sample $temp
|
|
|
|
unit=`${tools_dir}/grib_get -p unitOfTimeRange $temp`
|
2015-06-23 12:34:03 +00:00
|
|
|
[ "$unit" = "0" ]
|
2017-02-03 14:21:24 +00:00
|
|
|
${tools_dir}/grib_set -s indicatorOfUnitOfTimeRange=m $grib2_sample $temp
|
|
|
|
unit=`${tools_dir}/grib_get -p indicatorOfUnitOfTimeRange $temp`
|
2015-06-23 12:34:03 +00:00
|
|
|
[ "$unit" = "0" ]
|
|
|
|
|
2017-04-11 10:27:59 +00:00
|
|
|
# ECC-457
|
2022-07-26 12:23:32 +00:00
|
|
|
# ---------
|
2017-04-11 10:27:59 +00:00
|
|
|
input=${data_dir}/tp_ecmwf.grib
|
|
|
|
stepRange=`${tools_dir}/grib_get -w count=1 -p stepRange,startStep,endStep,stepType $input`
|
|
|
|
[ "$stepRange" = "12 12 12 instant" ]
|
|
|
|
|
2022-07-26 12:23:32 +00:00
|
|
|
# ECC-1430: stepType: 'severity' and 'mode'
|
|
|
|
# -----------------------------------------
|
|
|
|
${tools_dir}/grib_set -s stepType=severity,paramId=260318 $grib2_sample $temp
|
|
|
|
grib_check_key_equals $temp productDefinitionTemplateNumber,typeOfStatisticalProcessing '8 100'
|
|
|
|
${tools_dir}/grib_set -s stepType=mode,paramId=260320 $grib2_sample $temp
|
|
|
|
grib_check_key_equals $temp productDefinitionTemplateNumber,typeOfStatisticalProcessing '8 101'
|
|
|
|
|
2023-05-03 15:51:37 +00:00
|
|
|
# ECC-1577: stepType when typeOfTimeIncrement=255
|
|
|
|
# -----------------------------------------------
|
|
|
|
${tools_dir}/grib_set -s stepType=accum,typeOfTimeIncrement=255 $grib2_sample $temp
|
|
|
|
grib_check_key_equals $temp stepType accum
|
|
|
|
${tools_dir}/grib_set -s stepType=accum $grib2_sample $temp
|
|
|
|
grib_check_key_equals $temp typeOfTimeIncrement 2
|
|
|
|
|
|
|
|
${tools_dir}/grib_set -s stepType=avg,typeOfTimeIncrement=255 $grib2_sample $temp
|
|
|
|
grib_check_key_equals $temp stepType avg
|
|
|
|
${tools_dir}/grib_set -s stepType=avg $grib2_sample $temp
|
|
|
|
grib_check_key_equals $temp typeOfTimeIncrement 3
|
|
|
|
|
2023-06-26 16:12:29 +00:00
|
|
|
# Decode/Encode stepRange as an int and double
|
2023-06-26 15:55:08 +00:00
|
|
|
${tools_dir}/grib_set -s stepType=accum,stepRange=23-28 $grib2_sample $temp
|
|
|
|
grib_check_key_equals $temp "stepRange:s" "23-28"
|
|
|
|
grib_check_key_equals $temp "stepRange:i" "28"
|
|
|
|
grib_check_key_equals $temp "stepRange:d" "28"
|
2023-05-03 15:51:37 +00:00
|
|
|
|
2023-06-26 16:12:29 +00:00
|
|
|
${tools_dir}/grib_set -s stepRange:i=24 $grib2_sample $temp
|
|
|
|
grib_check_key_equals $temp "stepRange,startStep,endStep" "24 24 24"
|
|
|
|
# Should this be an error? currently this gets cast from double to int
|
|
|
|
${tools_dir}/grib_set -s stepRange:d=14.56 $grib2_sample $temp
|
|
|
|
grib_check_key_equals $temp "stepRange,startStep,endStep" "14 14 14"
|
|
|
|
|
2023-08-11 12:02:58 +00:00
|
|
|
# Key validityDateTime
|
2023-10-15 14:28:46 +00:00
|
|
|
# --------------------
|
2023-08-11 12:02:58 +00:00
|
|
|
input=${data_dir}/constant_field.grib2
|
|
|
|
grib_check_key_equals $input "dataDate,dataTime,step" "20061205 1200 6"
|
|
|
|
grib_check_key_equals $input "validityDate,validityTime" "20061205 1800"
|
|
|
|
grib_check_key_equals $input "validityDateTime:s" "20061205 001800"
|
|
|
|
|
2023-10-13 11:28:32 +00:00
|
|
|
# ECC-1704: Key validityTime as string
|
2023-10-15 14:28:46 +00:00
|
|
|
# -------------------------------------
|
2023-10-13 11:28:32 +00:00
|
|
|
result=$( ${tools_dir}/grib_get -p validityTime:s -s dataTime=0000 $grib2_sample )
|
|
|
|
[ "$result" = "0000" ]
|
|
|
|
input=$data_dir/simple.grib
|
|
|
|
grib_check_key_equals $input "validityTime:s" "0600"
|
|
|
|
|
|
|
|
|
2023-08-11 13:18:52 +00:00
|
|
|
# Key julianDay
|
2023-10-15 14:28:46 +00:00
|
|
|
# -------------
|
2023-08-11 13:18:52 +00:00
|
|
|
input=${data_dir}/sample.grib2
|
|
|
|
grib_check_key_equals $input 'julianDay:i' '2454503'
|
|
|
|
${tools_dir}/grib_set -s julianDay=2454504 $input $temp
|
|
|
|
grib_check_key_equals $input day 6
|
|
|
|
grib_check_key_equals $temp day 7
|
|
|
|
|
2023-08-23 13:17:27 +00:00
|
|
|
# Seconds (ignored)
|
2023-10-15 14:28:46 +00:00
|
|
|
# -----------------
|
2023-08-23 13:17:27 +00:00
|
|
|
${tools_dir}/grib_ls -s second=9 -n time $grib2_sample 2>$templog
|
|
|
|
# Something should have been written to stderr
|
|
|
|
[ -s $templog ]
|
|
|
|
grep -q "Truncating time: non-zero seconds.* ignored" $templog
|
2023-06-26 16:12:29 +00:00
|
|
|
|
2023-10-15 14:28:46 +00:00
|
|
|
# Hour or minute set to 255
|
|
|
|
# ---------------------------
|
|
|
|
input=${data_dir}/simple.grib
|
|
|
|
result=$( ${tools_dir}/grib_get -p dataTime -s hour=255 $input )
|
|
|
|
[ "$result" = "1200" ]
|
|
|
|
result=$( ${tools_dir}/grib_get -p dataTime -s hour=2,minute=255 $input )
|
|
|
|
[ "$result" = "200" ]
|
|
|
|
|
2022-07-26 12:23:32 +00:00
|
|
|
# Clean up
|
2023-08-23 13:17:27 +00:00
|
|
|
rm -f $temp $templog
|
2015-12-01 16:04:09 +00:00
|
|
|
rm -f $grib2File.p8tmp ${grib2File}.tmp x.grib
|