File: metar_compare.sh

package info (click to toggle)
eccodes 2.45.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 154,456 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: 278; xml: 183; awk: 66
file content (149 lines) | stat: -rwxr-xr-x 4,489 bytes parent folder | download | duplicates (3)
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
#!/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}/metar

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

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

# Define tmp METAR file
fMetarTmp=${label}".metar.tmp"

#----------------------------------------------------
# Test: comparing same files
#----------------------------------------------------
metar_file="metar.txt"
echo "Test: comparing the same files" >> $fLog
echo "file: $metar_file" >> $fLog
${tools_dir}/metar_compare $metar_file $metar_file


#----------------------------------------------------
# Test: comparing with skip
#----------------------------------------------------
metar_file="metar.txt"
${tools_dir}/metar_compare -w CCCC=VILK $metar_file $metar_file

#----------------------------------------------------
# Test: comparing two different files
#----------------------------------------------------
sed -e 's:^METAR VECC 022350Z 00000KT 1600 BR NSC 15/13 Q1013 NOSIG:METAR VECC 022349Z 00000KT 1600 BR NSC 15/13 Q1013 NOSIG:' < metar.txt > $fMetarTmp
set +e
${tools_dir}/metar_compare -v -d -f $metar_file $fMetarTmp
status=$?
set -e
if [ $status -eq 0 ]; then
   echo "ERROR: metar_compare should have failed if files are different" >&2
   exit 1
fi

# Compare using a namespace
set +e
${tools_dir}/metar_compare -c ls:n $metar_file $fMetarTmp > $fLog 2>&1
status=$?
set -e
[ $status -ne 0 ]
grep -q "DIFFERENCE == string.*dateTime" $fLog

set +e
${tools_dir}/metar_compare -a -c ls:n $metar_file $fMetarTmp > $fLog 2>&1
status=$?
set -e
[ $status -ne 0 ]
grep -q "DIFFERENCE == string.*dateTime" $fLog
grep -q "DIFFERENCE == string.*theMessage" $fLog


# The -d option should have created these files
rm -f error1_1.metar error2_1.metar error1_2.metar error2_2.metar

#----------------------------------------------------
# Compare a key of type double
#----------------------------------------------------
temp1=temp.$label.metar.1
temp2=temp.$label.metar.2
${tools_dir}/metar_copy -w count=1 $metar_file $temp1
${tools_dir}/metar_copy -w count=2 $metar_file $temp2
# absolute diff. = 16.53, relative diff. = 0.381315
${tools_dir}/metar_compare -c latitude -R latitude=0.4 $temp1 $temp2
${tools_dir}/metar_compare -c latitude -A 17 $temp1 $temp2
rm -f $temp1 $temp2

#----------------------------------------------------
# Comparing with and without the -b switch
#----------------------------------------------------
if [ $ECCODES_ON_WINDOWS -eq 0 ]; then
   # Add wrong blocklist. Should still fail
   set +e
   ${tools_dir}/metar_compare -b CCCC $metar_file $fMetarTmp
   status=$?
   set -e
   [ $status -eq 1 ]
   # Add correct blocklist
   ${tools_dir}/metar_compare -b minute,theMessage $metar_file $fMetarTmp
fi

#----------------------------------------------------
# Compare doubles
#----------------------------------------------------
temp1=temp.$label.1.metar
temp2=temp.$label.2.metar
echo 'METAR LQMO 022350Z 09003KT 6000 FEW010 SCT035 BKN060 09/09 Q1003=' > $temp1
${tools_dir}/metar_copy -w count=1 $metar_file $temp2
set +e
${tools_dir}/metar_compare -b theMessage -f -v $temp1 $temp2 > $fLog
status=$?
set -e
[ $status -ne 0 ]
grep -q "temperature .*1 different" $fLog
grep -q "dewPointTemperature .*1 different" $fLog

# dewPointTemperature diffs: absolute diff. = 1, relative diff. = 0.111111
${tools_dir}/metar_compare -b temperature,theMessage -R dewPointTemperature=0.12 $temp1 $temp2

rm -f $temp1 $temp2

#----------------------------------------------------
# Test with file of the same name in a dir
#----------------------------------------------------
tempDir=temp.$label.dir
rm -fr $tempDir
mkdir $tempDir
cp $metar_file $tempDir
${tools_dir}/metar_compare $metar_file $tempDir
rm -r $tempDir

# Non-existence
set +e
${tools_dir}/metar_compare non-exist1 non-exist2 > $fLog 2>&1
status=$?
set -e
[ $status -ne 0 ]
grep -q "No such file or directory" $fLog

# Options
set +e
${tools_dir}/metar_compare -a $metar_file $metar_file > $fLog 2>&1
status=$?
set -e
[ $status -ne 0 ]
grep -q "option requires" $fLog


# Clean up
rm -f $fLog $fMetarTmp