File: grib_copy.sh

package info (click to toggle)
eccodes 2.45.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 154,404 kB
  • sloc: cpp: 162,953; ansic: 26,308; sh: 21,742; f90: 6,854; perl: 6,361; python: 5,172; java: 2,226; javascript: 1,427; yacc: 854; fortran: 543; lex: 359; makefile: 283; xml: 183; awk: 66
file content (129 lines) | stat: -rwxr-xr-x 3,553 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#!/bin/sh
# (C) Copyright 2005- ECMWF.
#
# 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.
#

. ./include.ctest.sh

# Enter data dir
cd ${data_dir}

# Define a common label for all the tmp files
label="grib_copy_test"
temp=temp.$label.grib
fLog=temp.$label.log

echo "Test: The -g option..."
# -----------------------------------
input=gts.grib
${tools_dir}/grib_copy -w count=1 -g $input $temp
val1=`${tools_dir}/gts_get -wcount=1 -p AA $input`
val2=`${tools_dir}/gts_get -p AA $temp`
[ "$val1" = "$val2" ]
[ "$val1" = "XK" ]

${tools_dir}/grib_copy -p edition -w count=1 $input $temp
${tools_dir}/grib_copy -p shortName -w count=2 $input $temp
set +e
${tools_dir}/gts_get -p AA $temp
status=$?
set -e
[ $status -ne 0 ]


echo "Test: The -X option..."
# -------------------------------
echo "Test: use of -X option"
input=tigge_pf_ecmwf.grib2
${tools_dir}/grib_copy -w count=1 -X 0 $input $temp #First msg
r1=`${tools_dir}/grib_get -w count=1 -n ls $input`
r2=`${tools_dir}/grib_get -n ls $temp`
[ "$r1" = "$r2" ]


echo "Test: ECC-1086 invalid message ..."
# -------------------------
# This file is 179 bytes long. We chop the last byte to create
# an invalid GRIB message (Final 7777 is 777)
input=$ECCODES_SAMPLES_PATH/GRIB2.tmpl
badGrib=temp.$label.bad.grib
head -c 178 $input > $badGrib
set +e
${tools_dir}/grib_copy $badGrib /dev/null  # Only the bad GRIB
status=$?
set -e
[ $status -ne 0 ]

set +e
${tools_dir}/grib_copy $input $badGrib /dev/null # Good followed by bad
status=$?
set -e
[ $status -ne 0 ]

set +e
${tools_dir}/grib_copy $badGrib $input /dev/null # Bad followed by good
status=$?
set -e
[ $status -ne 0 ]

# If there is a bad message, make sure the rest (good ones) get copied
combinedGrib=${label}".combined.grib"
cat $badGrib tigge_cf_ecmwf.grib2 > $combinedGrib
set +e
${tools_dir}/grib_copy $combinedGrib $temp
status=$?
set -e
[ $status -ne 0 ]
count=`${tools_dir}/grib_count $temp`
[ $count -eq 43 ]


echo "Test: ECC-539 input=output ..."
# -----------------------
set +e
${tools_dir}/grib_copy  $temp $temp
status=$?
set -e
[ $status -ne 0 ]

#-------------------------------------------------------------------
echo "Test: corner cases ..."
#-------------------------------------------------------------------
echo GRIB > $badGrib
set +e
${tools_dir}/grib_copy $badGrib /dev/null > $fLog 2>&1
status=$?
set -e
[ $status -ne 0 ]
grep -w "unreadable message" $fLog


#-------------------------------------------------------------------
echo "Test: dummy field ..."
#-------------------------------------------------------------------
input=${data_dir}/missing_field.grib1
${tools_dir}/grib_copy -r $input $temp

#${tools_dir}/grib_copy -w count=1 -X 57143 $input $temp #Last msg
#r1=`${tools_dir}/grib_get -w count=37 -n ls $input`
#r2=`${tools_dir}/grib_get -n ls $temp`
#[ "$r1" = "$r2" ]

# Get two messages
#${tools_dir}/grib_copy -w count=1/2 -X 25071 $input $temp
#count=`${tools_dir}/grib_count $temp`
#[ $count -eq 2 ]

#r=`${tools_dir}/grib_get -w count=1 -p typeOfLevel,level,shortName $temp`
#[ "$r" = "heightAboveGround 2 mx2t6" ]
#r=`${tools_dir}/grib_get -w count=2 -p typeOfLevel,level,shortName $temp`
#[ "$r" = "heightAboveGround 2 mn2t6" ]

# Clean up
#-----------
rm -f $temp $badGrib $combinedGrib $fLog