/[MITgcm]/MITgcm/verification/testreport
ViewVC logotype

Contents of /MITgcm/verification/testreport

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


Revision 1.4 - (show annotations) (download)
Wed Sep 3 20:02:47 2003 UTC (20 years, 6 months ago) by edhill
Branch: MAIN
Changes since 1.3: +9 -2 lines
add -bash option to deal with dreadful sysadmins who insist on installing
bash in obscure locations like "/usr/ulocal/bin/bash"

1 #!/bin/bash
2 #
3 # $Header: /u/u3/gcmpack/MITgcm/verification/testreport,v 1.3 2003/09/02 21:06:21 edhill Exp $
4 #
5
6 usage()
7 {
8 echo
9 echo "Usage: $0 [OPTIONS]"
10 echo
11 echo "where possible OPTIONS are:"
12 echo " (-help|-h) print usage"
13 echo " (-optfile=|-of=)STRING list of genmake2 \"optfiles\""
14 echo " (-a|-addr)STRING list of email recipients"
15 echo " (-t|-tdir)STRING list of \"test\" dirs"
16 echo " (-b|-bash)STRING location of \"bash\" executable"
17 echo
18 exit 1
19 }
20
21 # build the mpack utility
22 build_mpack()
23 {
24 echo -n "building the mpack utility... "
25 if test ! -x "$MPACKDIR/mpack" ; then
26 if test ! -d $MPACKDIR ; then
27 echo "Error: can't find \"$MPACKDIR\""
28 echo " are you sure this program is being run in the correct "
29 echo " (that is, \"MITGCM_ROOT\verification\") directory?"
30 exit 1
31 fi
32 echo -n "building mpack... "
33 ( cd $MPACKDIR && ./configure && make ) > build_mpack.out 2>&1
34 RETVAL=$?
35 if test "x$RETVAL" != x0 ; then
36 echo
37 echo "Error building the mpack tools at: $MPACK_DIR"
38 exit 1
39 fi
40 fi
41 echo "OK"
42 }
43
44 compare_lines()
45 {
46 # use codelet to compare lines
47 if [ $verbose -gt 1 ]; then
48 cat tmp3.txt 1>&2
49 fi
50 return `./a.out < tmp3.txt`
51 }
52
53 testoutput_for_prop()
54 {
55 # testoutput_for_prop dir s1 label subdir
56 #
57 # compares files in $dir/$subdir/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/$4/output.txt 1>&2
62 fi
63 if [ -r $1/$4/output.txt ]; then
64 grep "$2" $1/$4/output.txt | sed 's/.*=//' | nl > tmp1.txt
65 lncnt=`wc -l tmp1.txt | awk '{print $1}' `
66 if [ $lncnt -lt 3 ]; then
67 if [ $verbose -gt 0 ]; then
68 echo Not enough lines of output when searching for "$2" 1>&2
69 fi
70 return 99
71 fi
72 else
73 echo testoutput_for_prop: output.txt from model run was not readable 1>&2
74 return 99
75 fi
76 if [ $debug -gt 0 ]; then
77 echo testoutput_for_prop: grep "$2" $1/results/output.txt 1>&2
78 fi
79 grep "$2" $1/results/output.txt | sed 's/.*=//' | nl > tmp2.txt
80 lncnt=`wc -l tmp2.txt | awk '{print $1}' `
81 if [ $lncnt -lt 3 ]; then
82 if [ $verbose -gt 0 ]; then
83 echo Not enough lines of output when searching for "$2" 1>&2
84 fi
85 return 99
86 fi
87 if [ $debug -gt 0 ]; then
88 echo testoutput_for_prop: join tmp1.txt tmp2.txt 1>&2
89 fi
90 join tmp1.txt tmp2.txt | awk '{print $1 " " $2 " " $3}' > tmp3.txt
91 if [ $debug -gt 0 ]; then
92 echo testoutput_for_prop: compare_lines 1>&2
93 fi
94 compare_lines
95 digits_of_similarity=$?
96 if [ $digits_of_similarity -eq 99 ]; then
97 if [ $verbose -gt 0 ]; then
98 echo testoutput_for_prop: No comparison was available for \"$2\" 1>&2
99 fi
100 digits_of_similarity=99
101 else
102 if [ $verbose -gt 0 ]; then
103 echo There were $digits_of_similarity decimal places of similarity for \"$2\" 1>&2
104 fi
105 fi
106 rm tmp1.txt tmp2.txt tmp3.txt
107
108 return $digits_of_similarity
109 }
110
111 dashnum()
112 {
113 # dashnum n1 n2 n3 ...
114 #
115 # print numbers using %3i format or "--" if number = 99
116
117 for num in $@ ; do
118 if [ $num = 99 ]; then
119 printf ' --'
120 else
121 printf '%3i' $num
122 fi
123 done
124 }
125
126 testoutput()
127 {
128 # testoutput diretory subdir
129 #
130 # test output in "directory"
131
132 if [ $debug -gt 0 ]; then
133 echo testoutput: testoutput_for_prop $1 cg2d_init_res 1>&2
134 fi
135 testoutput_for_prop $1 "cg2d_init_res" "cg2d init. residual" $2; cg2dres=$?
136 if [ $debug -gt 0 ]; then
137 echo testoutput: cg2dres=$cg2dres 1>&2
138 fi
139
140 testoutput_for_prop $1 "dynstat_theta_min" "theta minimum" $2; tmin=$?
141 testoutput_for_prop $1 "dynstat_theta_max" "theta maximum" $2; tmax=$?
142 testoutput_for_prop $1 "dynstat_theta_mean" "theta mean" $2; tmean=$?
143 testoutput_for_prop $1 "dynstat_theta_sd" "theta s.d." $2; tsd=$?
144 testoutput_for_prop $1 "dynstat_salt_min" "salt minimum" $2; smin=$?
145 testoutput_for_prop $1 "dynstat_salt_max" "salt maximum" $2; smax=$?
146 testoutput_for_prop $1 "dynstat_salt_mean" "salt mean" $2; smean=$?
147 testoutput_for_prop $1 "dynstat_salt_sd" "salt s.d." $2; ssd=$?
148 testoutput_for_prop $1 "dynstat_uvel_min" "U minimum" $2; umin=$?
149 testoutput_for_prop $1 "dynstat_uvel_max" "U maximum" $2; umax=$?
150 testoutput_for_prop $1 "dynstat_uvel_mean" "U mean" $2; umean=$?
151 testoutput_for_prop $1 "dynstat_uvel_sd" "U s.d." $2; usd=$?
152 testoutput_for_prop $1 "dynstat_vvel_min" "V minimum" $2; vmin=$?
153 testoutput_for_prop $1 "dynstat_vvel_max" "V maximum" $2; vmax=$?
154 testoutput_for_prop $1 "dynstat_vvel_mean" "V mean" $2; vmean=$?
155 testoutput_for_prop $1 "dynstat_vvel_sd" "V s.d." $2; vsd=$?
156
157 dashnum $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 GENMAKE2="$BASH ../../../tools/genmake2"
165 (
166 cd $1;
167 printf 'genmake ... ' 1>&2
168 # ../../../tools/genmake -ieee -mods=../code > make.log 2>&1
169 $GENMAKE2 -ds --mods=../code "--optfile="$OPTFILE > make.log 2>&1
170 RETVAL=$?
171 for i in gm_state gm_optfile gm_local Makefile ; do
172 if test -r $i ; then
173 cp $i $CDIR
174 fi
175 done
176 if test "x$RETVAL" != x0 ; then
177 tail make.log
178 echo "genmakemodel: genmake failed" 1>&2
179 cp make.log $CDIR
180 return 1
181 else
182 echo "succesful" 1>&2
183 fi
184 )
185 }
186
187 makeclean()
188 {
189 # makeclean directory
190 (
191 cd $1;
192 rm -f output.txt
193 printf 'make CLEAN ... ' 2>&1
194 if test -r Makefile ; then
195 make CLEAN >> make.log 2>&1
196 RETVAL=$?
197 if test "x$RETVAL" != x0 ; then
198 tail make.log
199 echo "makeclean: \"make CLEAN\" failed" 1>&2
200 cp make.log $CDIR"/make.log"
201 return 1
202 fi
203 fi
204 echo succesful 1>&2
205 exit 0
206 )
207 }
208
209 makedependmodel()
210 {
211 # makedependmodel directory
212 (
213 cd $1;
214 printf 'make depend ... ' 1>&2
215 make depend >> make.log 2>&1
216 RETVAL=$?
217 if test "x$RETVAL" != x0 ; then
218 tail make.log
219 echo "makedependmodel: make depend failed" 1>&2
220 cp make.log $CDIR"/make.log"
221 return 1
222 else
223 echo succesful 1>&2
224 fi
225 )
226 }
227
228 makemodel()
229 {
230 # makemodel directory
231 (
232 cd $1;
233 if test -r Makefile ; then
234 printf 'make ... ' 1>&2
235 make >> make.log 2>&1
236 RETVAL=$?
237 if test "x$RETVAL" != x0 ; then
238 tail make.log
239 echo failed 1>&2
240 cp make.log $CDIR"/make.log"
241 return 1
242 else
243 echo succesful 1>&2
244 fi
245 fi
246 )
247 }
248
249 linkdata()
250 {
251 # linkdata flag
252 #
253 # symbolically link data files to run directory
254 if [ $1 -ne 0 ]; then
255 ( cd $2 ; ln -sf ../input/* . )
256 fi
257 }
258
259 runmodel()
260 {
261 # runmodel directory exe
262 #
263 # runs the model "exe" in "directory" (exe is relative to directory)
264 (
265 cd $1
266 if [ -x $2 ]; then
267 if [ $quick -eq 0 ]; then
268 rm -f output.txt
269 fi
270 printf 'runmodel: ' 1>&2
271 make output.txt
272 RETVAL=$?
273 if test "x$RETVAL" = x0 ; then
274 cp output.txt $CDIR"/output.txt"
275 return 0
276 else
277 return 1
278 fi
279 fi
280 )
281 }
282
283 createcodelet()
284 {
285 # create codelet for comparing model output
286
287 echo -n "creating the comparison code... "
288 cat > tmp_cmpnum.f <<EOFA
289 program cmpnum
290 implicit none
291 real*8 a,b,diff
292 integer linnum,best
293 best=-16
294 99 read(*,*,end=70,err=60) linnum,a,b
295 diff=0.5*(abs(a)+abs(b))
296 c print *,a,b,diff,abs(a-b)/diff
297 if (diff.gt.1.e-12) then
298 diff=abs(a-b)/diff
299 if (diff.gt.0.) then
300 c print *,int(log10(diff)),diff
301 linnum=int(log10(diff))
302 best=max(best,linnum)
303 endif
304 else
305 if (best.eq.-16.and.diff.ne.0.) best=-22
306 endif
307 goto 99
308 60 stop 'cmpnum: An error occured reading a,b'
309 70 print *,-best
310 end
311 EOFA
312
313 f77 tmp_cmpnum.f
314 if [ -x ./a.out ]; then
315 echo "OK"
316 return 0
317 else
318 echo
319 echo "createcodelet: failed to compile codelet"
320 exit 1
321 fi
322 }
323
324 formatresults()
325 {
326 # formatresults expt genmake depend make run results*
327
328 nm=$1
329 printf '%s %s %s %s' $2 $3 $4 $5
330 shift; shift; shift; shift; shift;
331 printf '%3s' $@
332
333 if [ $1 = '--' ]; then
334 printf ' N/O '
335 else
336 if [ $1 -gt 12 ]; then
337 printf ' pass'
338 else
339 printf ' FAIL'
340 fi
341 fi
342 printf ' %s' $nm
343 printf '\n'
344
345 }
346
347 show_help()
348 {
349 cat - << EOF
350 $0 [-help] [-quick] [-verbose] dir1 [dir2] [...]
351 -help Show this help message
352 -quick Skip "genmake" and "make depend" if the Makefile exists
353 -quiet Reduce the amount of output
354 -verbose Produce copious amounts of output
355 -debug Produce even more output which will mean nothing to most
356 -force Do "make CLEAN" before compiling. This forces a complete rebuild.
357 -clean Do "make CLEAN" after compiling and testing.
358 -noieee By default, $0 uses the -ieee option for genmake. This turns it off.
359 -cleanup Aggresively removes all model output, executables and object files
360 and then exits. Use with care.
361
362 Normal usage:
363 $0 * Configure, compile, run and analyze in all experiment directories
364 EOF
365 }
366
367 scandirs()
368 {
369 if [ $# -eq 0 ]; then
370 for arg in * ; do
371 test -d $arg/input && echo $arg
372 done
373 else
374 echo $*
375 fi
376 }
377
378
379 ###############################################################################
380 ###############################################################################
381 ###############################################################################
382
383
384 # Default properties
385 debug=0
386 verbose=1
387 quick=0
388 clean=0
389 ieee=1
390 expts=''
391
392 BASH=
393 OPTFILES=
394 ADDRESSES=edhill@mitgcm.org
395 TESTDIRS=
396 MPACKDIR="../tools/mpack-1.6"
397 MPACK="$MPACKDIR/mpack"
398
399 echo -n "parsing options... "
400
401 ac_prev=
402 for ac_option ; do
403
404 # If the previous option needs an argument, assign it.
405 if test -n "$ac_prev"; then
406 eval "$ac_prev=\$ac_option"
407 ac_prev=
408 continue
409 fi
410
411 ac_optarg=`expr "x$ac_option" : 'x[^=]*=\(.*\)'`
412
413 case $ac_option in
414
415 -help | --help | -h | --h)
416 usage ;;
417
418 -optfile | --optfile | -of | --of)
419 ac_prev=OPTFILES ;;
420 -optfile=* | --optfile=* | -of=* | --of=*)
421 OPTFILES=$ac_optarg ;;
422
423 -addr | --addr | -a | --a)
424 ac_prev=ADDRESSES ;;
425 -addr=* | --addr=*)
426 ADDRESSES=$ac_optarg ;;
427
428 -tdir | --tdir | -t | --t)
429 ac_prev=TESTDIRS ;;
430 -tdir=* | --tdir=*)
431 TESTDIRS=$ac_optarg ;;
432
433 -bash | --bash | -b | --b)
434 ac_prev=BASH ;;
435 -bash=* | --bash=*)
436 BASH=$ac_optarg ;;
437
438 -quick) quick=1 ;;
439 -verbose) verbose=2 ;;
440 -debug) debug=1 ;;
441 -clean) clean=1 ;;
442 -noieee) ieee=0 ;;
443 -quiet) verbose=0 ;;
444
445 -*)
446 echo "Error: unrecognized option: "$ac_option
447 usage
448 ;;
449
450 *)
451 echo "Error: unrecognized argument: "$ac_option
452 usage
453 ;;
454
455 esac
456
457 done
458
459 if test "x$TESTDIRS" = x ; then
460 TESTDIRS=`scandirs`
461 fi
462
463 echo "OK"
464
465 # create the FORTRAN comparison code
466 createcodelet
467
468 # build the mpack utility
469 build_mpack
470
471 # Create a uniquely named directory to store results
472 MACH=`hostname`
473 UNAMEA=`uname -a`
474 DATE=`date +%Y%m%d`
475 BASE=$MACH"_"$DATE"_"
476 DNUM=0
477 DRESULTS="$BASE$DNUM"
478 while test -e $DRESULTS ; do
479 DNUM=$(( $DNUM + 1 ))
480 DRESULTS="$BASE$DNUM"
481 done
482 mkdir $DRESULTS
483 RETVAL=$?
484 if test "x$RETVAL" != x0 ; then
485 echo "Error: can't create results directory \"./$DRESULTS\""
486 exit 1
487 fi
488 SUMMARY="$DRESULTS/summary.txt"
489 date > $SUMMARY
490 cat << EOF >> $SUMMARY
491 T S U V
492 G D M c m s m s m s m s
493 E p a R g m m e . m m e . m m e . m m e .
494 N n k u 2 i a a d i a a d i a a d i a a d
495 2 d e n d n x n . n x n . n x n . n x n .
496
497 EOF
498
499 NDIR=0
500
501 # For each optfile...
502 for OPTFILE in $OPTFILES ; do
503
504 OPTFILE=`pwd`"/$OPTFILE"
505 if test ! -r $OPTFILE ; then
506 echo "Error: can't read optfile \"$OPTFILE\""
507 exit 1
508 fi
509 echo
510 echo "OPTFILE=$OPTFILE" >> $SUMMARY
511 echo >> $SUMMARY
512
513 # ...and each test directory...
514 for dir in $TESTDIRS ; do
515
516 # Verify that the testdir exists and contains previous
517 # results in the correct location--or skip this directory!
518 if test ! -r $dir"/results/output.txt" ; then
519 echo | tee -a $SUMMARY
520 echo "can't read \"$dir/results/output.txt\" -- skipping $dir" \
521 | tee -a $SUMMARY
522 continue
523 fi
524
525 # Create an output dir for each OPTFILE/tdir combination
526 CDIR=$DRESULTS"/"$DRESULTS"_"$NDIR
527 mkdir $CDIR
528 CDIR=`pwd`"/$CDIR"
529
530 # ...configue, make, run, and compare the output.
531 echo "-------------------------------------------------------------------------------"
532 echo
533 echo "Experiment: $dir"
534 echo
535 unset genmake makedepend make run
536 results='-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --'
537 ( cd $dir/input; rm -f *.{o,f,c,F} *.[f,F]90 work* output.txt Make* make.log; )
538 if [ -r $dir/build ]; then
539 seperatebuilddir=1
540 builddir=build
541 rundir=build
542 ( cd $dir/build; ln -sf ../input/* . )
543 else
544 seperatebuilddir=0
545 builddir=input
546 rundir=input
547 fi
548
549 genmakemodel $dir/$builddir && genmake=Y \
550 && makeclean $dir/$builddir \
551 && makedependmodel $dir/$builddir && makedepend=Y \
552 && makemodel $dir/$builddir && make=Y \
553 && linkdata $seperatebuilddir $dir/$rundir \
554 && runmodel $dir/$builddir mitgcmuv && run=Y \
555 && results=`testoutput $dir $rundir`
556 echo
557 formatresults $dir ${genmake:-N} ${makedepend:-N} ${make:-N} \
558 ${run:-N} $results
559 echo
560 formatresults $dir ${genmake:-N} ${makedepend:-N} ${make:-N} \
561 ${run:-N} $results >> $SUMMARY
562 echo "fresults='" > $CDIR"/summary.txt"
563 formatresults $dir ${genmake:-N} ${makedepend:-N} ${make:-N} \
564 ${run:-N} $results >> $CDIR"/summary.txt"
565 echo "'" >> $CDIR"/summary.txt"
566 echo "MACH='$MACH'" >> $CDIR"/summary.txt"
567 echo "UNAMEA='$UNAMEA'" >> $CDIR"/summary.txt"
568 echo "DATE='$DATE'" >> $CDIR"/summary.txt"
569 echo "tdir='$dir'" >> $CDIR"/summary.txt"
570
571 (
572 cd $DRESULTS
573 tar -cf $NDIR".tar" $DRESULTS"_"$NDIR > /dev/null 2>&1
574 gzip $NDIR".tar"
575 )
576
577 $MPACK -s MITgcm-test -m 1000000 $DRESULTS"/"$NDIR".tar.gz" $ADDRESSES
578 RETVAL=$?
579 if test "x$RETVAL" != x0 ; then
580 echo "Warning: \"$MPACK\" failed -- please contact <edhill@mitgcm.org>"
581 else
582 rm -f $DRESULTS"/"$NDIR".tar*"
583 fi
584
585 NDIR=$(( $NDIR + 1 ))
586
587 done
588 done
589
590 rm tmp_cmpnum.f a.out
591
592 cat $SUMMARY

  ViewVC Help
Powered by ViewVC 1.1.22