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

Annotation of /MITgcm/verification/testreport

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


Revision 1.5 - (hide annotations) (download)
Sat Sep 6 02:45:07 2003 UTC (17 years, 9 months ago) by edhill
Branch: MAIN
Changes since 1.4: +15 -8 lines
small changes to get testing working on bluesky.ucar.edu

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

  ViewVC Help
Powered by ViewVC 1.1.22