File: bufr_get.sh

package info (click to toggle)
eccodes 2.44.2-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 150,256 kB
  • sloc: cpp: 163,056; ansic: 26,308; sh: 21,602; f90: 6,854; perl: 6,363; python: 5,087; java: 2,226; javascript: 1,427; yacc: 854; fortran: 543; lex: 359; makefile: 274; xml: 183; awk: 66
file content (156 lines) | stat: -rwxr-xr-x 4,507 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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#!/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

# Define a common label for all the tmp files
label="bufr_get_test"

# Create log file
fLog=${label}".log"
rm -f $fLog
touch $fLog

# Define tmp file
fTmp=${label}".tmp.txt"
tempRef=${label}".tmp.ref.txt"
rm -f $fTmp $tempRef

# Define another tmp file to store the test results
res_get=${label}".get.test"
rm -f $res_get

# Check identidier. Edition 3 and 4
id=`${tools_dir}/bufr_get -p edition,identifier avhn_87.bufr`
[ "$id" = "3 BUFR" ]
id=`${tools_dir}/bufr_get -p edition,identifier aaen_55.bufr`
[ "$id" = "4 BUFR" ]

set +e
${tools_dir}/bufr_get -p identifier:d avhn_87.bufr
status=$?
set -e
[ $status -ne 0 ]

#-------------------------------------------
# Test "-p" switch
#-------------------------------------------
f="aaen_55.bufr"

# The reference is the same as for ls
ref_get=$f".ls.ref"

echo "Test: -p switch" >> $fLog
echo "file: $f" >> $fLog
${tools_dir}/bufr_get -p totalLength,bufrHeaderCentre,bufrHeaderSubCentre,masterTableNumber,masterTablesVersionNumber,localTablesVersionNumber,numberOfSubsets,localNumberOfObservations $f > $fTmp

# Write the values into a file and compare with ref
cat $fTmp | awk '{split($0,a," "); for (i=1; i<=8; i++) print a[i]}' > $res_get
diff $ref_get $res_get

#-------------------------------------------
# ECC-236
#-------------------------------------------
result=`${tools_dir}/bufr_get -s unpack=1 -p nonCoordinatePressure syno_1.bufr`
[ "$result" = "100910" ]
result=`${tools_dir}/bufr_get -s unpack=1 -p stationOrSiteName bssh_176.bufr`
[ "$result" = "Helgoland" ]
result=`${tools_dir}/bufr_get -s unpack=1 -p majorFrameCount aaen_55.bufr`
[ "$result" = "MISSING" ]
result=`${tools_dir}/bufr_get -s unpack=1 -p satelliteIdentifier wavb_134.bufr`
[ "$result" = "MISSING" ]

#-------------------------------------------
# ECC-315: BUFR keys in the MARS namespace
#-------------------------------------------
result=`${tools_dir}/bufr_get -m aaen_55.bufr`
[ "$result" = "55 20121102 0000" ]
result=`${tools_dir}/bufr_get -m syno_1.bufr`
[ "$result" = "1 20121030 0000 91334" ]
${tools_dir}/bufr_ls -j -m syno_1.bufr > $fTmp
cat > $tempRef <<EOF
{ "messages" : [ 
  {
    "obstype": 1,
    "date": 20121030,
    "time": "0000",
    "ident": 91334
  }
]}
EOF
cat $tempRef
diff $tempRef $fTmp

#-------------------------------------------
# Local ECMWF section: 'ident' key
#-------------------------------------------
result=`${tools_dir}/bufr_get -p isSatellite,ident syno_1.bufr`
[ "$result" = "0 91334" ]
result=`${tools_dir}/bufr_get -p isSatellite,ident temp_102.bufr`
[ "$result" = "0 ASDE3" ]
result=`${tools_dir}/bufr_get -p isSatellite,ident b004_145.bufr`
[ "$result" = "0 FAVRTLZA" ]

result=`${tools_dir}/bufr_get -f -p isSatellite,ident b003_56.bufr`
[ "$result" = "1 not_found" ]


# Check key 'file'
result=`${tools_dir}/bufr_get -p file b004_145.bufr`
[ "$result" = "b004_145.bufr" ]

# Decoding the "unpack" key also decodes the whole Data Section
result=`${tools_dir}/bufr_get -f -p heightOfStation aaen_55.bufr`
[ "$result" = "not_found" ]
result=`${tools_dir}/bufr_get -p unpack,heightOfStation aaen_55.bufr`
[ "$result" = "0 858000" ]
result=`${tools_dir}/bufr_get -p unpack:d,heightOfStation aaen_55.bufr`
[ "$result" = "0 858000" ]
result=`${tools_dir}/bufr_get -p unpack:s,heightOfStation aaen_55.bufr`
[ "$result" = "0 858000" ]

# ----------------------------------------
# Wrong message type
# ----------------------------------------
f=$data_dir/sample.grib2
set +e
${tools_dir}/bufr_get -p edition $f > $fLog 2>&1
status=$?
set -e
[ $status -ne 0 ]
grep -q "Input file seems to be GRIB" $fLog

f=$ECCODES_SAMPLES_PATH/budg.tmpl
set +e
${tools_dir}/bufr_get -p edition $f > $fLog 2>&1
status=$?
set -e
[ $status -ne 0 ]
grep -q "Input file seems to be GRIB" $fLog


# ----------------------------------------
# Unreadable message
# ----------------------------------------
echo BUFR > $fTmp
set +e
${tools_dir}/bufr_get -p edition $fTmp > $fLog 2>&1
status=$?
set -e
[ $status -ne 0 ]
grep -q "unreadable message" $fLog


# Clean up
rm -f $fLog $fTmp $res_get $tempRef