/[MITgcm]/MITgcm/verification/testsh
ViewVC logotype

Contents of /MITgcm/verification/testsh

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.1 - (show annotations) (download)
Fri Jun 29 18:31:55 2001 UTC (22 years, 10 months ago) by adcroft
Branch: MAIN
CVS Tags: checkpoint40pre2, checkpoint40pre1
Better script than testscript:
 o usage: testsh *
 o not replacing testscript yet because have to make work on
   other platforms.  /bin/sh is not so portable...

1 #!/bin/sh
2
3 similar()
4 {
5 # similar digits a b
6 #
7 # compare the floating point number a and b and successively reduced
8 # truncation until a match is found
9 for digits in 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
10 do
11 a=`printf '%22.'$digits'e\n' $1`
12 b=`printf '%22.'$digits'e\n' $2`
13 if [ $a = $b ]; then
14 if [ $verbose -gt 1 ]; then
15 echo $1 $2 $a 1>&2
16 fi
17 break
18 fi
19 done
20 return $digits
21 }
22
23 compare_lines()
24 {
25 # compare_lines digits < file
26 #
27 # read each line of file and test the 2nd and 3rd column values for
28 # similarity based on the function similar()
29 worst_so_far=$1
30 while read linenum a b
31 do
32 if [ $debug -gt 0 ]; then
33 echo compare_lines: similar a=$a b=$b 1>&2
34 fi
35 similar $a $b
36 digits=$?
37 if [ $digits -lt $worst_so_far ]; then
38 worst_so_far=$digits
39 fi
40 done
41 if [ $debug -gt 0 ]; then
42 echo compare_lines: worst_so_far=$worst_so_far 1>&2
43 fi
44 return $worst_so_far
45 }
46
47 testoutput_for_prop()
48 {
49 # testoutput_for_prop dir s1 label
50 #
51 # compares files in $dir/input/output.txt and $dir/results.output.txt
52 # using search strings s1 and text label
53
54 if [ $debug -gt 0 ]; then
55 echo testoutput_for_prop: grep "$2" $1/input/output.txt 1>&2
56 fi
57 if [ -r $1/input/output.txt ]; then
58 grep "$2" $1/input/output.txt | sed 's/.*=//' | nl > tmp1.txt
59 else
60 echo testoutput_for_prop: output.txt from model run was not readable 1>&2
61 return 99
62 fi
63 if [ $debug -gt 0 ]; then
64 echo testoutput_for_prop: grep "$2" $1/results/output.txt 1>&2
65 fi
66 grep "$2" $1/results/output.txt | sed 's/.*=//' | nl > tmp2.txt
67 if [ $debug -gt 0 ]; then
68 echo testoutput_for_prop: join tmp1.txt tmp2.txt 1>&2
69 fi
70 join tmp1.txt tmp2.txt | awk '{print $1 " " $2 " " $3}' > tmp3.txt
71 if [ $debug -gt 0 ]; then
72 echo testoutput_for_prop: compare_lines 1>&2
73 fi
74 compare_lines 99 < tmp3.txt
75 digits_of_similarity=$?
76 if [ $digits_of_similarity -eq 99 ]; then
77 if [ $verbose -gt 0 ]; then
78 echo testoutput_for_prop: No comparison was available for \"$2\" 1>&2
79 fi
80 digits_of_similarity=99
81 else
82 if [ $verbose -gt 0 ]; then
83 echo There were $digits_of_similarity decimal places of similarity for \"$2\" 1>&2
84 fi
85 fi
86 rm tmp1.txt tmp2.txt tmp3.txt
87
88 return $digits_of_similarity
89 }
90
91 dashnum()
92 {
93 # dashnum n1 n2 n3 ...
94 #
95 # print numbers using %3i format or "--" if number = 99
96 for num in $@
97 do
98 if [ $num = 99 ]; then
99 printf ' --'
100 else
101 printf '%3i' $num
102 fi
103 done
104 }
105
106 testoutput()
107 {
108 # testoutput diretory
109 #
110 # test output in "directory"
111
112 if [ $debug -gt 0 ]; then
113 echo testoutput: testoutput_for_prop $1 cg2d_init_res 1>&2
114 fi
115 testoutput_for_prop $1 "cg2d_init_res" "cg2d init. residual"; cg2dres=$?
116 if [ $debug -gt 0 ]; then
117 echo testoutput: cg2dres=$cg2dres 1>&2
118 fi
119 testoutput_for_prop $1 "dynstat_theta_min" "theta minimum"; tmin=$?
120 testoutput_for_prop $1 "dynstat_theta_max" "theta maximum"; tmax=$?
121 testoutput_for_prop $1 "dynstat_salt_min" "salt minimum"; smin=$?
122 testoutput_for_prop $1 "dynstat_salt_max" "salt maximum"; smax=$?
123 testoutput_for_prop $1 "dynstat_uvel_min" "U minimum"; umin=$?
124 testoutput_for_prop $1 "dynstat_uvel_max" "U maximum"; umax=$?
125 testoutput_for_prop $1 "dynstat_vvel_min" "V minimum"; vmin=$?
126 testoutput_for_prop $1 "dynstat_vvel_max" "V maximum"; vmax=$?
127
128 #testoutput_for_prop $1 "dynstat_theta_mean" "theta mean"; tmean=$?
129 #testoutput_for_prop $1 "dynstat_theta_sd" "theta s.d."; tsd=$?
130 #testoutput_for_prop $1 "dynstat_salt_mean" "salt mean"; smean=$?
131 #testoutput_for_prop $1 "dynstat_salt_sd" "salt s.d."; ssd=$?
132 #testoutput_for_prop $1 "dynstat_uvel_mean" "U mean"; umean=$?
133 #testoutput_for_prop $1 "dynstat_uvel_sd" "U s.d."; usd=$?
134 #testoutput_for_prop $1 "dynstat_vvel_mean" "V mean"; vmean=$?
135 #testoutput_for_prop $1 "dynstat_vvel_sd" "V s.d."; vsd=$?
136
137 dashnum $cg2dres $tmin $tmax $tmean $tsd $smin $smax $smean $ssd \
138 $umin $umax $umean $usd $vmin $vmax $vmean $vsd
139 #printf '%3i' $cg2dres $tmin $tmax $tmean $tsd $smin $smax $smean $ssd \
140 # $umin $umax $umean $usd $vmin $vmax $vmean $vsd
141 }
142
143 genmakemodel()
144 {
145 # genmakemodel directory
146 ( cd $1;
147 if [ $quick -eq 0 -o ! -r Makefile ]; then
148 printf 'genmake ... ' 1>&2
149 ../../../tools/genmake -mods=../code > make.log 2>&1
150 if [ $? -ne 0 ]; then
151 tail make.log
152 echo makemodel: genmake failed 1>&2
153 return 1
154 else
155 echo succesful 1>&2
156 fi
157 fi
158 )
159 }
160
161 makedependmodel()
162 {
163 # makedependmodel directory
164 ( cd $1;
165 if [ $quick -eq 0 -o ! -r Makefile ]; then
166 printf 'make depend ... ' 1>&2
167 make depend >> make.log 2>&1
168 if [ $? -ne 0 ]; then
169 tail make.log
170 echo makemodel: make depend failed 1>&2
171 return 1
172 else
173 echo succesful 1>&2
174 fi
175 fi
176 )
177 }
178
179 makemodel()
180 {
181 # makemodel directory
182 ( cd $1;
183 if [ -r Makefile ]; then
184 printf 'make ... ' 1>&2
185 make >> make.log 2>&1
186 if [ $? -ne 0 ]; then
187 tail make.log
188 echo failed 1>&2
189 return 1
190 else
191 echo succesful 1>&2
192 fi
193 fi
194 )
195 }
196
197 runmodel()
198 {
199 # runmodel directory exe
200 #
201 # runs the model "exe" in "directory" (exe is relative to directory)
202
203 ( cd $1
204 if [ -x $2 ]; then
205 if [ ! -r output.txt -o $quick -eq 0 ]; then
206 echo runmodel: running... 1>&2
207 ( ./$2 > output.txt 2>&1 ) && return 0
208 return 1
209 else
210 echo runmodel: output.txt is newer than executable 1>&2
211 return 0
212 fi
213 else
214 echo runmodel: executable \"$1/$2\" is missing 1>&2
215 return 1
216 fi
217 )
218 }
219
220 formatresults()
221 {
222 # formatresults expt genmake depend make run results*
223
224 nm=$1
225 printf '%s %s %s %s' $2 $3 $4 $5
226 shift; shift; shift; shift; shift;
227 printf '%3s' $@
228
229 if [ $1 = '--' ]; then
230 printf ' N/O '
231 else
232 if [ $1 -gt 12 ]; then
233 printf ' pass'
234 else
235 printf ' FAIL'
236 fi
237 fi
238 printf ' %s' $nm
239 printf '\n'
240
241 }
242
243 show_help()
244 {
245 cat - << EOF
246 $0 [-help] [-quick] [-verbose] dir1 [dir2] [...]
247 -help Show this help message
248 -quick Skip "genmake" and "make depend" if the Makefile exists
249 -quiet Reduce the amount of output
250 -verbose Produce copious amounts of output
251
252 Normal usage:
253 $0 * Configure, compile, run and analyze in all experiment directories
254 EOF
255 }
256
257 # Main function
258 dir=$1/input
259
260 # Default properties
261 debug=0
262 verbose=1
263 quick=0
264 expts=''
265
266 # Process arguments
267 for arg in $@
268 do
269 case $arg in
270 -quick) quick=1;;
271 -verbose) verbose=2;;
272 -debug) debug=1;;
273 -quiet) verbose=0;;
274 -help) show_help; exit 0;;
275 *) test -d $arg && expts=`echo $expts $arg`;;
276 esac
277 done
278
279 cat << EOF > summary.txt
280 T S U V
281 C D M c m s m s m s m s
282 n p a R g m m e . m m e . m m e . m m e .
283 f n k u 2 i a a d i a a d i a a d i a a d
284 g d e n d n x n . n x n . n x n . n x n .
285
286 EOF
287 cat << EOF > summary.txt
288 T S U V
289 C D M c
290 n p a R g m m m m m m m m
291 f n k u 2 i a i a i a i a
292 g d e n d n x n x n x n x
293
294 EOF
295
296 # Now configue, make, run and test in each directory
297 for dir in $expts
298 do
299 if [ -r $dir/results/output.txt ]; then
300 echo -------------------------------------------------------------------------------
301 echo
302 echo Experiment: $dir
303 echo
304 unset genmake makedepend make run
305 results='-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --'
306 results='-- -- -- -- -- -- -- -- --'
307 genmakemodel $dir/input && genmake=Y \
308 && makedependmodel $dir/input && makedepend=Y \
309 && makemodel $dir/input && make=Y \
310 && runmodel $dir/input mitgcmuv && run=Y \
311 && results=`testoutput $dir`
312 echo
313 formatresults $dir ${genmake:-N} ${makedepend:-N} ${make:-N} ${run:-N} $results
314 echo
315 formatresults $dir ${genmake:-N} ${makedepend:-N} ${make:-N} ${run:-N} $results >> summary.txt
316 fi
317 done
318
319 echo -------------------------------------------------------------------------------
320 echo
321 cat summary.txt

  ViewVC Help
Powered by ViewVC 1.1.22