/[MITgcm]/MITgcm/verification/testscript
ViewVC logotype

Contents of /MITgcm/verification/testscript

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


Revision 1.8 - (show annotations) (download)
Fri Aug 3 20:18:40 2001 UTC (22 years, 8 months ago) by adcroft
Branch: MAIN
Changes since 1.7: +390 -174 lines
Finally moved over to /bin/sh

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 compare_lines2()
48 {
49 # use codelet to compare lines
50 return `./a.out < tmp3.txt`
51 }
52
53 testoutput_for_prop()
54 {
55 # testoutput_for_prop dir s1 label
56 #
57 # compares files in $dir/input/output.txt and $dir/results.output.txt
58 # using search strings s1 and text label
59
60 if [ $debug -gt 0 ]; then
61 echo testoutput_for_prop: grep "$2" $1/input/output.txt 1>&2
62 fi
63 if [ -r $1/input/output.txt ]; then
64 grep "$2" $1/input/output.txt | sed 's/.*=//' | nl > tmp1.txt
65 else
66 echo testoutput_for_prop: output.txt from model run was not readable 1>&2
67 return 99
68 fi
69 if [ $debug -gt 0 ]; then
70 echo testoutput_for_prop: grep "$2" $1/results/output.txt 1>&2
71 fi
72 grep "$2" $1/results/output.txt | sed 's/.*=//' | nl > tmp2.txt
73 if [ $debug -gt 0 ]; then
74 echo testoutput_for_prop: join tmp1.txt tmp2.txt 1>&2
75 fi
76 join tmp1.txt tmp2.txt | awk '{print $1 " " $2 " " $3}' > tmp3.txt
77 if [ $debug -gt 0 ]; then
78 echo testoutput_for_prop: compare_lines 1>&2
79 fi
80 #compare_lines 99 < tmp3.txt
81 compare_lines2
82 digits_of_similarity=$?
83 if [ $digits_of_similarity -eq 99 ]; then
84 if [ $verbose -gt 0 ]; then
85 echo testoutput_for_prop: No comparison was available for \"$2\" 1>&2
86 fi
87 digits_of_similarity=99
88 else
89 if [ $verbose -gt 0 ]; then
90 echo There were $digits_of_similarity decimal places of similarity for \"$2\" 1>&2
91 fi
92 fi
93 rm tmp1.txt tmp2.txt tmp3.txt
94
95 return $digits_of_similarity
96 }
97
98 dashnum()
99 {
100 # dashnum n1 n2 n3 ...
101 #
102 # print numbers using %3i format or "--" if number = 99
103 for num in $@
104 do
105 if [ $num = 99 ]; then
106 printf ' --'
107 else
108 printf '%3i' $num
109 fi
110 done
111 }
112
113 testoutput()
114 {
115 # testoutput diretory
116 #
117 # test output in "directory"
118
119 if [ $debug -gt 0 ]; then
120 echo testoutput: testoutput_for_prop $1 cg2d_init_res 1>&2
121 fi
122 testoutput_for_prop $1 "cg2d_init_res" "cg2d init. residual"; cg2dres=$?
123 if [ $debug -gt 0 ]; then
124 echo testoutput: cg2dres=$cg2dres 1>&2
125 fi
126
127 if [ $testmore -gt 0 ]; then
128 testoutput_for_prop $1 "dynstat_theta_min" "theta minimum"; tmin=$?
129 testoutput_for_prop $1 "dynstat_theta_max" "theta maximum"; tmax=$?
130 testoutput_for_prop $1 "dynstat_theta_mean" "theta mean"; tmean=$?
131 testoutput_for_prop $1 "dynstat_theta_sd" "theta s.d."; tsd=$?
132 testoutput_for_prop $1 "dynstat_salt_min" "salt minimum"; smin=$?
133 testoutput_for_prop $1 "dynstat_salt_max" "salt maximum"; smax=$?
134 testoutput_for_prop $1 "dynstat_salt_mean" "salt mean"; smean=$?
135 testoutput_for_prop $1 "dynstat_salt_sd" "salt s.d."; ssd=$?
136 testoutput_for_prop $1 "dynstat_uvel_min" "U minimum"; umin=$?
137 testoutput_for_prop $1 "dynstat_uvel_max" "U maximum"; umax=$?
138 testoutput_for_prop $1 "dynstat_uvel_mean" "U mean"; umean=$?
139 testoutput_for_prop $1 "dynstat_uvel_sd" "U s.d."; usd=$?
140 testoutput_for_prop $1 "dynstat_vvel_min" "V minimum"; vmin=$?
141 testoutput_for_prop $1 "dynstat_vvel_max" "V maximum"; vmax=$?
142 testoutput_for_prop $1 "dynstat_vvel_mean" "V mean"; vmean=$?
143 testoutput_for_prop $1 "dynstat_vvel_sd" "V s.d."; vsd=$?
144 else
145 testoutput_for_prop $1 "dynstat_theta_min" "theta minimum"; tmin=$?
146 testoutput_for_prop $1 "dynstat_theta_max" "theta maximum"; tmax=$?
147 testoutput_for_prop $1 "dynstat_salt_min" "salt minimum"; smin=$?
148 testoutput_for_prop $1 "dynstat_salt_max" "salt maximum"; smax=$?
149 testoutput_for_prop $1 "dynstat_uvel_min" "U minimum"; umin=$?
150 testoutput_for_prop $1 "dynstat_uvel_max" "U maximum"; umax=$?
151 testoutput_for_prop $1 "dynstat_vvel_min" "V minimum"; vmin=$?
152 testoutput_for_prop $1 "dynstat_vvel_max" "V maximum"; vmax=$?
153 fi
154
155 dashnum $cg2dres $tmin $tmax $tmean $tsd $smin $smax $smean $ssd \
156 $umin $umax $umean $usd $vmin $vmax $vmean $vsd
157 #printf '%3i' $cg2dres $tmin $tmax $tmean $tsd $smin $smax $smean $ssd \
158 # $umin $umax $umean $usd $vmin $vmax $vmean $vsd
159 }
160
161 genmakemodel()
162 {
163 # genmakemodel directory
164 ( cd $1;
165 if [ $quick -eq 0 -o ! -r Makefile ]; then
166 printf 'genmake ... ' 1>&2
167 ../../../tools/genmake -mods=../code > make.log 2>&1
168 if [ $? -ne 0 ]; then
169 tail make.log
170 echo makemodel: genmake failed 1>&2
171 return 1
172 else
173 echo succesful 1>&2
174 fi
175 fi
176 )
177 }
178
179 makedependmodel()
180 {
181 # makedependmodel directory
182 ( cd $1;
183 if [ $quick -eq 0 -o ! -r Makefile ]; then
184 printf 'make depend ... ' 1>&2
185 make cleanlinks >> make.log 2>&1
186 make depend >> make.log 2>&1
187 if [ $? -ne 0 ]; then
188 tail make.log
189 echo makemodel: make depend failed 1>&2
190 return 1
191 else
192 echo succesful 1>&2
193 fi
194 fi
195 )
196 }
197
198 makemodel()
199 {
200 # makemodel directory
201 ( cd $1;
202 if [ -r Makefile ]; then
203 printf 'make ... ' 1>&2
204 make >> make.log 2>&1
205 if [ $? -ne 0 ]; then
206 tail make.log
207 echo failed 1>&2
208 return 1
209 else
210 echo succesful 1>&2
211 fi
212 fi
213 )
214 }
215
216 runmodel()
217 {
218 # runmodel directory exe
219 #
220 # runs the model "exe" in "directory" (exe is relative to directory)
221
222 ( cd $1
223 if [ -x $2 ]; then
224 if [ ! -r output.txt -o $quick -eq 0 ]; then
225 echo runmodel: running... 1>&2
226 ( ./$2 > output.txt 2>&1 ) && return 0
227 return 1
228 else
229 echo runmodel: output.txt is newer than executable 1>&2
230 return 0
231 fi
232 else
233 echo runmodel: executable \"$1/$2\" is missing 1>&2
234 return 1
235 fi
236 )
237 }
238
239 createcodelet()
240 {
241 # create codelet for comparing model output
242 cat > tmp_cmpnum.f <<EOFA
243 program cmpnum
244 implicit none
245 real*8 a,b,diff
246 integer linnum,best
247 best=-16
248 99 read(*,*,end=70,err=60) linnum,a,b
249 diff=0.5*(abs(a)+abs(b))
250 if (diff.gt.0.) then
251 diff=abs(a-b)/diff
252 if (diff.gt.0.) then
253 c print *,int(log10(diff)),diff
254 linnum=int(log10(diff))
255 best=max(best,linnum)
256 c else
257 c print *,-16
258 endif
259 c else
260 c diff=0.
261 c print *,-16
262 endif
263 goto 99
264 60 stop 'cmpnum: An error occured reading a,b'
265 70 print *,-best
266 end
267 EOFA
268 f77 tmp_cmpnum.f
269 if [ -x ./a.out ]; then
270 return 0
271 else
272 echo createcodelet: failed to compile codelet 1>&2
273 exit 1
274 fi
275 }
276
277 formatresults()
278 {
279 # formatresults expt genmake depend make run results*
280
281 nm=$1
282 printf '%s %s %s %s' $2 $3 $4 $5
283 shift; shift; shift; shift; shift;
284 printf '%3s' $@
285
286 if [ $1 = '--' ]; then
287 printf ' N/O '
288 else
289 if [ $1 -gt 12 ]; then
290 printf ' pass'
291 else
292 printf ' FAIL'
293 fi
294 fi
295 printf ' %s' $nm
296 printf '\n'
297
298 }
299
300 show_help()
301 {
302 cat - << EOF
303 $0 [-help] [-quick] [-verbose] dir1 [dir2] [...]
304 -help Show this help message
305 -quick Skip "genmake" and "make depend" if the Makefile exists
306 -quiet Reduce the amount of output
307 -verbose Produce copious amounts of output
308
309 Normal usage:
310 $0 * Configure, compile, run and analyze in all experiment directories
311 EOF
312 }
313
314 ###############################################################################
315
316 # Main function
317
318 # Default properties
319 debug=0
320 verbose=1
321 quick=0
322 testmore=0
323 expts=''
324
325 # Process arguments
326 for arg in $@
327 do
328 case $arg in
329 -quick) quick=1;;
330 -verbose) verbose=2;;
331 -debug) debug=1;;
332 -testmore) testmore=1;;
333 -quiet) verbose=0;;
334 -help) show_help; exit 0;;
335 *) test -d $arg && expts=`echo $expts $arg`;;
336 esac
337 done
338
339 if [ ${#expts} -eq 0 ]; then
340 echo Scanning all directories
341 for arg in *
342 do
343 test -d $arg && expts=`echo $expts $arg`
344 done
345 fi
346
347 createcodelet
348
349 if [ $testmore -eq 0 ]; then
350 cat << EOF > summary.txt
351 T S U V
352 C D M c m s m s m s m s
353 n p a R g m m e . m m e . m m e . m m e .
354 f n k u 2 i a a d i a a d i a a d i a a d
355 g d e n d n x n . n x n . n x n . n x n .
356
357 EOF
358 else
359 cat << EOF > summary.txt
360 T S U V
361 C D M c
362 n p a R g m m m m m m m m
363 f n k u 2 i a i a i a i a
364 g d e n d n x n x n x n x
365
366 EOF
367 fi
368
369 # Now configue, make, run and test in each directory
370 for dir in $expts
371 do
372 if [ -r $dir/results/output.txt ]; then
373 echo -------------------------------------------------------------------------------
374 echo
375 echo Experiment: $dir
376 echo
377 unset genmake makedepend make run
378 results='-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --'
379 results='-- -- -- -- -- -- -- -- --'
380 genmakemodel $dir/input && genmake=Y \
381 && makedependmodel $dir/input && makedepend=Y \
382 && makemodel $dir/input && make=Y \
383 && runmodel $dir/input mitgcmuv && run=Y \
384 && results=`testoutput $dir`
385 echo
386 formatresults $dir ${genmake:-N} ${makedepend:-N} ${make:-N} ${run:-N} $results
387 echo
388 formatresults $dir ${genmake:-N} ${makedepend:-N} ${make:-N} ${run:-N} $results >> summary.txt
389 fi
390 done
391
392 rm tmp_cmpnum.f a.out
393
394 echo -------------------------------------------------------------------------------
395 echo
396 cat summary.txt

  ViewVC Help
Powered by ViewVC 1.1.22