File: bufr_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 (115 lines) | stat: -rwxr-xr-x 3,698 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
#!/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}/bufr

label="bufr_copy_test"
fLog=${label}".log"
rm -f $fLog
touch $fLog

fBufrInput=${label}".bufr.input"
fBufrTmp=${label}".bufr.tmp"

# Create a bufr file with various message types
cat syno_multi.bufr temp_101.bufr > $fBufrInput 

#----------------------------------------------------
echo "Test: copy synop messages ..."
#----------------------------------------------------
rm -f $fBufrTmp

echo "Test: copy synop messages " >> $fLog
${tools_dir}/bufr_copy -p typicalDate -w dataCategory=0 $fBufrInput $fBufrTmp >> $fLog

for i in 1 2 3 ;do
    category=`${tools_dir}/bufr_get -w count=$i -p dataCategory:l $fBufrTmp`
    [ $category = "0" ]
done

#----------------------------------------------------
echo "Test: copy non-synop messages ..."
#----------------------------------------------------
rm -f $fBufrTmp

echo "Test: copy non-synop messages " >> $fLog
${tools_dir}/bufr_copy -w dataCategory!=0 $fBufrInput $fBufrTmp >> $fLog

[ `${tools_dir}/bufr_get -p dataCategory:l $fBufrTmp`  = "2" ]

#-------------------------------------------------------------------
echo "Test: use the square brackets to insert the value of a key ..."
#-------------------------------------------------------------------
rm -f ${fBufrTmp}
rm -f ${fBufrTmp}_*.bufr

echo "Test: use the square brackets to insert the value of a key " >> $fLog
${tools_dir}/bufr_copy $fBufrInput ${fBufrTmp}_[dataCategory].bufr >> $fLog

[ -s ${fBufrTmp}_0.bufr ]
[ -s ${fBufrTmp}_2.bufr ]

rm -f ${fBufrTmp}_*.bufr
rm -f $fBufrInput

#-------------------------------------------------------------------
echo "Test: The -X option ..."
#-------------------------------------------------------------------
echo "Test: use of -X option" >> $fLog
fBufrInput=aeolus_wmo_26.bufr
${tools_dir}/bufr_copy -w count=1 -X 0 $fBufrInput $fBufrTmp #First msg
r1=`${tools_dir}/bufr_get -w count=1 -n ls $fBufrInput`
r2=`${tools_dir}/bufr_get -n ls $fBufrTmp`
[ "$r1" = "$r2" ]

#${tools_dir}/bufr_copy -w count=1 -X 19449 $fBufrInput $fBufrTmp #Last msg
#r1=`${tools_dir}/bufr_get -w count=11 -n ls $fBufrInput`
#r2=`${tools_dir}/bufr_get -n ls $fBufrTmp`
#[ "$r1" = "$r2" ]

#${tools_dir}/bufr_copy -w count=1 -X 10972 $fBufrInput $fBufrTmp
#r=`${tools_dir}/bufr_get -p typicalTime,numberOfSubsets $fBufrTmp`
#[ "$r" = "000013 41" ]


#-------------------------------------------------------------------
echo "Test: The -w option with unpack ..."
#-------------------------------------------------------------------
fBufrInput=tropical_cyclone.bufr
rm -f $fBufrTmp
${tools_dir}/bufr_copy -s unpack=1 -w stormIdentifier=70E $fBufrInput $fBufrTmp
num_msgs=`${tools_dir}/bufr_count $fBufrTmp`
[ $num_msgs -eq 1 ]
storm=`${tools_dir}/bufr_get -s unpack=1 -p stormIdentifier $fBufrTmp`
[ "$storm" = "70E" ]

rm -f $fBufrTmp
${tools_dir}/bufr_copy -s unpack=1 -w stormIdentifier=none $fBufrInput $fBufrTmp
[ ! -f "$fBufrTmp" ]


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


# Clean up
#-----------
rm -f $fLog $fBufrTmp