/[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.9.2.8 - (show annotations) (download)
Sat Oct 4 02:10:52 2003 UTC (20 years, 6 months ago) by edhill
Branch: branch-genmake2
Changes since 1.9.2.7: +4 -6 lines
 o fix "-c" options handling

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

  ViewVC Help
Powered by ViewVC 1.1.22