Alpine3D

Alpine3D Svn Source Tree

Root/trunk/tests/basics/run_basics.sh

  • Property svn:executable set to *
1#!/bin/bash
2#This test assumes that run_simple has successfully completed, so it can analyze its results
3#it takes as first argument the reference MET file to use for the test
4
5RUN_NAME=`basename $1 .bz2`
6DIRNAME=`dirname $1`
7INPUT_REF="${DIRNAME}/${RUN_NAME}"
8INPUT_TEST=${INPUT_REF/output_ref/output}
9
10TMP_REF="/tmp/run_basics_$$_ref"
11TMP_NEW="/tmp/run_basics_$$_new"
12
13# Print a special line to prevent CTest from truncating the test output
14printf "CTEST_FULL_OUTPUT (line required by CTest to avoid output truncation)\n\n"
15
16function compare_result {
17param=$1
18prec=$2
19
20comp=`numdiff ${prec} ${TMP_REF} ${TMP_NEW}`
21comp_result=`echo "${comp}" | grep "+++" | grep -vE "are equal$"`
22printf "Comparing %-36s" "${param}"
23if [ -z "${comp_result}" ]; then
24printf "[OK]\n"
25else
26#nr_errors=`echo "${comp}" | grep -E "^@.* error " | wc -l`
27#printf "[fail]\t${nr_errors} error(s)\n"
28printf "[fail] → "
29echo "${comp}" | awk '
30function isNumeric(str) {
31return str ~ /^(\+|\-)*([0-9]|\.)+e*(\+|\-)*[0-9]*$/
32}
33/^##/ {
34if (first=="") {
35gsub("#", "")
36first=$1
37}
38}
39/@.* error / {
40count++
41gsub(",","")
42if (isNumeric($5)) {
43count_abs++
44sum_abs+=$5
45}
46if (isNumeric($9)) {
47count_rel++
48sum_rel+=$9
49}
50}
51END {
52if (count==1)
53printf("%3d error ", count)
54else
55printf("%3d errors", count)
56if (count_abs>0)
57printf(" µ_abs=%-5.3g", sum_abs/count_abs)
58else
59printf(" ")
60if (count_rel>0)
61printf(" µ_rel=%-7.3g", sum_rel/count_rel)
62else
63printf(" ")
64
65cmd=sprintf("head -n %d %s | tail -1 | cut -f1 -d\" \"", first, "'"${TMP_REF}"'")
66cmd | getline datum
67printf(" @ %s\n", datum)
68}
69'
70fi
71}
72
73#prepare the reference file
74rm -f ${INPUT_REF}
75bunzip2 -k ${INPUT_REF}.bz2
76
77printf "*** Checking simulation ${RUN_NAME}\n"
78printf "*** basic checks:\n"
79#check the snow height
80../SnExtract.sh ${INPUT_REF} 30 > ${TMP_REF}
81../SnExtract.sh ${INPUT_TEST} 30 > ${TMP_NEW}
82compare_result "snow height (HS)" "-a 1."
83#check the surface temperature
84../SnExtract.sh ${INPUT_REF} 13 > ${TMP_REF}
85../SnExtract.sh ${INPUT_TEST} 13 > ${TMP_NEW}
86compare_result "surface temperature (TSS)" "-a 1."
87#check the albedo
88../SnExtract.sh ${INPUT_REF} 11 > ${TMP_REF}
89../SnExtract.sh ${INPUT_TEST} 11 > ${TMP_NEW}
90compare_result "albedo (ALB)" "-a 0.05"
91
92
93
94printf "\n**** check the mass balance:\n"
95#check the snow water equivalent
96../SnExtract.sh ${INPUT_REF} 36 > ${TMP_REF}
97../SnExtract.sh ${INPUT_TEST} 36 > ${TMP_NEW}
98compare_result "snow water equiv. (SWE)" "-a .5"
99#check the snow rate
100../SnExtract.sh ${INPUT_REF} 29 > ${TMP_REF}
101../SnExtract.sh ${INPUT_TEST} 29 > ${TMP_NEW}
102compare_result "snow rate" "-a .1"
103#check the rain rate
104../SnExtract.sh ${INPUT_REF} 38 > ${TMP_REF}
105../SnExtract.sh ${INPUT_TEST} 38 > ${TMP_NEW}
106compare_result "rain rate" "-a .1"
107#check the snowpack runoff
108../SnExtract.sh ${INPUT_REF} 39 > ${TMP_REF}
109../SnExtract.sh ${INPUT_TEST} 39 > ${TMP_NEW}
110compare_result "snowpack runoff" "-a .5"
111
112
113
114printf "\n**** check the energy balance components:\n"
115#check the sensible heat
116../SnExtract.sh ${INPUT_REF} 3 > ${TMP_REF}
117../SnExtract.sh ${INPUT_TEST} 3 > ${TMP_NEW}
118compare_result "sensible heat" "-r 1e-2"
119#check the latent heat
120../SnExtract.sh ${INPUT_REF} 4 > ${TMP_REF}
121../SnExtract.sh ${INPUT_TEST} 4 > ${TMP_NEW}
122compare_result "latent heat" "-r 1e-2"
123#check olwr
124../SnExtract.sh ${INPUT_REF} 5 > ${TMP_REF}
125../SnExtract.sh ${INPUT_TEST} 5 > ${TMP_NEW}
126compare_result "OLWR" "-r 1e-2"
127#check ilwr
128../SnExtract.sh ${INPUT_REF} 6 > ${TMP_REF}
129../SnExtract.sh ${INPUT_TEST} 6 > ${TMP_NEW}
130compare_result "ILWR" "-r 1e-2"
131#check rswr
132../SnExtract.sh ${INPUT_REF} 8 > ${TMP_REF}
133../SnExtract.sh ${INPUT_TEST} 8 > ${TMP_NEW}
134compare_result "RSWR" "-r 1e-2"
135#check iswr
136../SnExtract.sh ${INPUT_REF} 9 > ${TMP_REF}
137../SnExtract.sh ${INPUT_TEST} 9 > ${TMP_NEW}
138compare_result "ISWR" "-r 1e-2"
139#ground flux
140../SnExtract.sh ${INPUT_REF} 16 > ${TMP_REF}
141../SnExtract.sh ${INPUT_TEST} 16 > ${TMP_NEW}
142compare_result "ground flux" "-r 1e-2"
143#rain heat flux
144../SnExtract.sh ${INPUT_REF} 19 > ${TMP_REF}
145../SnExtract.sh ${INPUT_TEST} 19 > ${TMP_NEW}
146compare_result "rain heat flux" "-r 1e-2"
147#surface input heat flux
148../SnExtract.sh ${INPUT_REF} 97 > ${TMP_REF}
149../SnExtract.sh ${INPUT_TEST} 97 > ${TMP_NEW}
150compare_result "surface input heat flux" "-r 1e-2"
151
152
153
154printf "\n**** check the internal energy state:\n"
155#internal energy change
156../SnExtract.sh ${INPUT_REF} 96 > ${TMP_REF}
157../SnExtract.sh ${INPUT_TEST} 96 > ${TMP_NEW}
158compare_result "internal energy change" "-r 1e-2"
159#phase change heat flux
160../SnExtract.sh ${INPUT_REF} 102 > ${TMP_REF}
161../SnExtract.sh ${INPUT_TEST} 102 > ${TMP_NEW}
162compare_result "phase change heat flux" "-r 1e-2"
163#check the liquid water content
164../SnExtract.sh ${INPUT_REF} 54 > ${TMP_REF}
165../SnExtract.sh ${INPUT_TEST} 54 > ${TMP_NEW}
166compare_result "liquid water content (LWC)" "-a 1."
167
168##Cleanup
169rm -f ${INPUT_REF}
170rm -f ${TMP_REF}
171rm -f ${TMP_NEW}

Archive Download this file

Revision: HEAD