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

Annotation of /MITgcm/verification/testscript

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


Revision 1.26 - (hide annotations) (download)
Wed Dec 3 19:43:51 2003 UTC (20 years, 4 months ago) by adcroft
Branch: MAIN
CVS Tags: checkpoint52e_pre, checkpoint52e_post, checkpoint52d_post, checkpoint52f_post, checkpoint52h_pre, checkpoint52f_pre
Branch point for: netcdf-sm0
Changes since 1.25: +3 -5 lines
Permanently switching to genmake2

1 adcroft 1.8 #!/bin/sh
2 adcroft 1.1
3 adcroft 1.8 compare_lines()
4     {
5     # use codelet to compare lines
6 adcroft 1.9 if [ $verbose -gt 1 ]; then
7     cat tmp3.txt 1>&2
8     fi
9 adcroft 1.8 return `./a.out < tmp3.txt`
10     }
11    
12     testoutput_for_prop()
13     {
14 adcroft 1.23 # testoutput_for_prop dir s1 label subdir
15 adcroft 1.8 #
16 adcroft 1.23 # compares files in $dir/$subdir/output.txt and $dir/results/output.txt
17 adcroft 1.8 # using search strings s1 and text label
18    
19     if [ $debug -gt 0 ]; then
20 adcroft 1.23 echo testoutput_for_prop: grep "$2" $1/$4/output.txt 1>&2
21 adcroft 1.8 fi
22 adcroft 1.23 if [ -r $1/$4/output.txt ]; then
23     grep "$2" $1/$4/output.txt | sed 's/.*=//' | nl > tmp1.txt
24 adcroft 1.22 lncnt=`wc -l tmp1.txt | awk '{print $1}' `
25     if [ $lncnt -lt 3 ]; then
26     if [ $verbose -gt 0 ]; then
27     echo Not enough lines of output when searching for "$2" 1>&2
28     fi
29     return 99
30     fi
31 adcroft 1.1 else
32 adcroft 1.8 echo testoutput_for_prop: output.txt from model run was not readable 1>&2
33     return 99
34     fi
35     if [ $debug -gt 0 ]; then
36     echo testoutput_for_prop: grep "$2" $1/results/output.txt 1>&2
37     fi
38     grep "$2" $1/results/output.txt | sed 's/.*=//' | nl > tmp2.txt
39 adcroft 1.22 lncnt=`wc -l tmp2.txt | awk '{print $1}' `
40     if [ $lncnt -lt 3 ]; then
41     if [ $verbose -gt 0 ]; then
42     echo Not enough lines of output when searching for "$2" 1>&2
43     fi
44     return 99
45     fi
46 adcroft 1.8 if [ $debug -gt 0 ]; then
47     echo testoutput_for_prop: join tmp1.txt tmp2.txt 1>&2
48     fi
49     join tmp1.txt tmp2.txt | awk '{print $1 " " $2 " " $3}' > tmp3.txt
50     if [ $debug -gt 0 ]; then
51     echo testoutput_for_prop: compare_lines 1>&2
52     fi
53 adcroft 1.9 compare_lines
54 adcroft 1.8 digits_of_similarity=$?
55     if [ $digits_of_similarity -eq 99 ]; then
56     if [ $verbose -gt 0 ]; then
57     echo testoutput_for_prop: No comparison was available for \"$2\" 1>&2
58     fi
59     digits_of_similarity=99
60     else
61     if [ $verbose -gt 0 ]; then
62     echo There were $digits_of_similarity decimal places of similarity for \"$2\" 1>&2
63     fi
64     fi
65     rm tmp1.txt tmp2.txt tmp3.txt
66    
67     return $digits_of_similarity
68     }
69    
70     dashnum()
71     {
72     # dashnum n1 n2 n3 ...
73     #
74     # print numbers using %3i format or "--" if number = 99
75     for num in $@
76     do
77     if [ $num = 99 ]; then
78     printf ' --'
79     else
80     printf '%3i' $num
81     fi
82     done
83     }
84    
85     testoutput()
86     {
87 adcroft 1.23 # testoutput diretory subdir
88 adcroft 1.8 #
89     # test output in "directory"
90    
91     if [ $debug -gt 0 ]; then
92     echo testoutput: testoutput_for_prop $1 cg2d_init_res 1>&2
93     fi
94 adcroft 1.23 testoutput_for_prop $1 "cg2d_init_res" "cg2d init. residual" $2; cg2dres=$?
95 adcroft 1.8 if [ $debug -gt 0 ]; then
96     echo testoutput: cg2dres=$cg2dres 1>&2
97     fi
98    
99 adcroft 1.10 if [ $longtest -gt 0 ]; then
100 adcroft 1.23 testoutput_for_prop $1 "dynstat_theta_min" "theta minimum" $2; tmin=$?
101     testoutput_for_prop $1 "dynstat_theta_max" "theta maximum" $2; tmax=$?
102     testoutput_for_prop $1 "dynstat_theta_mean" "theta mean" $2; tmean=$?
103     testoutput_for_prop $1 "dynstat_theta_sd" "theta s.d." $2; tsd=$?
104     testoutput_for_prop $1 "dynstat_salt_min" "salt minimum" $2; smin=$?
105     testoutput_for_prop $1 "dynstat_salt_max" "salt maximum" $2; smax=$?
106     testoutput_for_prop $1 "dynstat_salt_mean" "salt mean" $2; smean=$?
107     testoutput_for_prop $1 "dynstat_salt_sd" "salt s.d." $2; ssd=$?
108     testoutput_for_prop $1 "dynstat_uvel_min" "U minimum" $2; umin=$?
109     testoutput_for_prop $1 "dynstat_uvel_max" "U maximum" $2; umax=$?
110     testoutput_for_prop $1 "dynstat_uvel_mean" "U mean" $2; umean=$?
111     testoutput_for_prop $1 "dynstat_uvel_sd" "U s.d." $2; usd=$?
112     testoutput_for_prop $1 "dynstat_vvel_min" "V minimum" $2; vmin=$?
113     testoutput_for_prop $1 "dynstat_vvel_max" "V maximum" $2; vmax=$?
114     testoutput_for_prop $1 "dynstat_vvel_mean" "V mean" $2; vmean=$?
115     testoutput_for_prop $1 "dynstat_vvel_sd" "V s.d." $2; vsd=$?
116 adcroft 1.8 else
117 adcroft 1.23 testoutput_for_prop $1 "dynstat_theta_min" "theta minimum" $2; tmin=$?
118     testoutput_for_prop $1 "dynstat_theta_max" "theta maximum" $2; tmax=$?
119     testoutput_for_prop $1 "dynstat_salt_min" "salt minimum" $2; smin=$?
120     testoutput_for_prop $1 "dynstat_salt_max" "salt maximum" $2; smax=$?
121     testoutput_for_prop $1 "dynstat_uvel_min" "U minimum" $2; umin=$?
122     testoutput_for_prop $1 "dynstat_uvel_max" "U maximum" $2; umax=$?
123     testoutput_for_prop $1 "dynstat_vvel_min" "V minimum" $2; vmin=$?
124     testoutput_for_prop $1 "dynstat_vvel_max" "V maximum" $2; vmax=$?
125 adcroft 1.8 fi
126    
127     dashnum $cg2dres $tmin $tmax $tmean $tsd $smin $smax $smean $ssd \
128     $umin $umax $umean $usd $vmin $vmax $vmean $vsd
129     #printf '%3i' $cg2dres $tmin $tmax $tmean $tsd $smin $smax $smean $ssd \
130     # $umin $umax $umean $usd $vmin $vmax $vmean $vsd
131     }
132    
133     genmakemodel()
134     {
135     # genmakemodel directory
136     ( cd $1;
137     if [ $quick -eq 0 -o ! -r Makefile ]; then
138     printf 'genmake ... ' 1>&2
139 adcroft 1.13 if [ $ieee -eq 0 ]; then
140 adcroft 1.26 ../../../tools/genmake2 -mods=../code > make.log 2>&1
141 adcroft 1.13 else
142 adcroft 1.26 ../../../tools/genmake2 -ieee -mods=../code > make.log 2>&1
143 adcroft 1.13 fi
144 adcroft 1.8 if [ $? -ne 0 ]; then
145     tail make.log
146 edhill 1.25 echo genmakemodel: $genmake failed 1>&2
147 adcroft 1.8 return 1
148     else
149     echo succesful 1>&2
150     fi
151     fi
152     )
153     }
154    
155 adcroft 1.18 makecleancompile()
156 adcroft 1.10 {
157 adcroft 1.18 # makecleancompile directory
158     ( cd $1;
159     if [ $force -gt 0 ]; then
160     rm -f output.txt
161     printf 'make clean ... ' 2>&1
162     make CLEAN >> make.log 2>&1
163     if [ $? -ne 0 ]; then
164     tail make.log
165     echo makecleancompile: make clean failed 1>&2
166     return 1
167     else
168     echo succesful 1>&2
169     fi
170     fi
171     )
172     }
173    
174     makecleanupafter()
175     {
176     # makeupafter directory
177 adcroft 1.10 ( cd $1;
178     if [ $clean -gt 0 ]; then
179 adcroft 1.15 rm -f output.txt
180 adcroft 1.10 printf 'make clean ... ' 2>&1
181     make CLEAN >> make.log 2>&1
182     if [ $? -ne 0 ]; then
183     tail make.log
184 adcroft 1.18 echo makeupafter: make clean failed 1>&2
185 adcroft 1.10 return 1
186     else
187     echo succesful 1>&2
188     fi
189     fi
190     )
191     }
192    
193 adcroft 1.8 makedependmodel()
194     {
195     # makedependmodel directory
196     ( cd $1;
197     if [ $quick -eq 0 -o ! -r Makefile ]; then
198     printf 'make depend ... ' 1>&2
199     make cleanlinks >> make.log 2>&1
200     make depend >> make.log 2>&1
201     if [ $? -ne 0 ]; then
202     tail make.log
203     echo makemodel: make depend failed 1>&2
204     return 1
205     else
206     echo succesful 1>&2
207     fi
208     fi
209     )
210     }
211    
212     makemodel()
213     {
214     # makemodel directory
215     ( cd $1;
216     if [ -r Makefile ]; then
217     printf 'make ... ' 1>&2
218     make >> make.log 2>&1
219     if [ $? -ne 0 ]; then
220     tail make.log
221     echo failed 1>&2
222     return 1
223     else
224     echo succesful 1>&2
225     fi
226     fi
227     )
228     }
229    
230 adcroft 1.23 linkdata()
231     {
232     # linkdata flag
233     # symbolically link data files to run directory
234     if [ $1 -ne 0 ]; then
235     # if [ ! -r $2 ]; then
236     # mkdir $2
237     # fi
238 adcroft 1.26 ( cd $2; ln -sf ../input/{eedata,data*,*.bin,POLY3*,pickup*} .)
239 adcroft 1.23 fi
240     }
241    
242 adcroft 1.8 runmodel()
243     {
244     # runmodel directory exe
245     #
246     # runs the model "exe" in "directory" (exe is relative to directory)
247    
248     ( cd $1
249     if [ -x $2 ]; then
250 adcroft 1.16 if [ $quick -eq 0 ]; then
251 adcroft 1.15 rm -f output.txt
252 adcroft 1.8 fi
253 adcroft 1.19 printf 'runmodel: ' 1>&2
254 adcroft 1.23 make output.txt && return 0
255     return 1
256 adcroft 1.8 fi
257     )
258     }
259    
260     createcodelet()
261     {
262     # create codelet for comparing model output
263     cat > tmp_cmpnum.f <<EOFA
264     program cmpnum
265     implicit none
266     real*8 a,b,diff
267     integer linnum,best
268     best=-16
269     99 read(*,*,end=70,err=60) linnum,a,b
270     diff=0.5*(abs(a)+abs(b))
271 adcroft 1.9 c print *,a,b,diff,abs(a-b)/diff
272     if (diff.gt.1.e-12) then
273 adcroft 1.8 diff=abs(a-b)/diff
274     if (diff.gt.0.) then
275     c print *,int(log10(diff)),diff
276     linnum=int(log10(diff))
277     best=max(best,linnum)
278     endif
279 adcroft 1.9 else
280     if (best.eq.-16.and.diff.ne.0.) best=-22
281 adcroft 1.1 endif
282 adcroft 1.8 goto 99
283     60 stop 'cmpnum: An error occured reading a,b'
284     70 print *,-best
285     end
286     EOFA
287     f77 tmp_cmpnum.f
288     if [ -x ./a.out ]; then
289     return 0
290     else
291     echo createcodelet: failed to compile codelet 1>&2
292     exit 1
293     fi
294     }
295    
296     formatresults()
297     {
298     # formatresults expt genmake depend make run results*
299    
300     nm=$1
301     printf '%s %s %s %s' $2 $3 $4 $5
302     shift; shift; shift; shift; shift;
303     printf '%3s' $@
304    
305     if [ $1 = '--' ]; then
306     printf ' N/O '
307     else
308     if [ $1 -gt 12 ]; then
309     printf ' pass'
310 adcroft 1.1 else
311 adcroft 1.8 printf ' FAIL'
312     fi
313     fi
314     printf ' %s' $nm
315     printf '\n'
316    
317     }
318    
319     show_help()
320     {
321     cat - << EOF
322     $0 [-help] [-quick] [-verbose] dir1 [dir2] [...]
323     -help Show this help message
324     -quick Skip "genmake" and "make depend" if the Makefile exists
325     -quiet Reduce the amount of output
326     -verbose Produce copious amounts of output
327 adcroft 1.10 -debug Produce even more output which will mean nothing to most
328 adcroft 1.18 -force Do "make CLEAN" before compiling. This forces a complete rebuild.
329     -clean Do "make CLEAN" after compiling and testing.
330 adcroft 1.20 -shorttest Don't compare numeric output for mean and s.d. of variables.
331 adcroft 1.14 -noieee By default, $0 uses the -ieee option for genmake. This turns it off.
332 adcroft 1.21 -cleanup Aggresively removes all model output, executables and object files
333     and then exits. Use with care.
334 adcroft 1.8
335     Normal usage:
336     $0 * Configure, compile, run and analyze in all experiment directories
337     EOF
338     }
339    
340 adcroft 1.11 scandirs()
341     {
342     if [ $# -eq 0 ]; then
343     for arg in *
344     do
345     test -d $arg/input && echo $arg
346     done
347     else
348     echo $*
349     fi
350     }
351    
352 adcroft 1.21 clean_up()
353     {
354     # Find all executables, object files, CPP'd source and model output
355     # and DELETE it.
356 adcroft 1.23 for opt in '-name "mitgcmuv*"' '-name "*.o"' '-name "*.f"' '-name "*.c"' '-name "fort.*"' '-name "make.log"' '-path *results -prune -o -name "*.meta"' '-path *results -prune -o -name "*.data"' '-type l'
357 adcroft 1.21 do
358     echo Cleaning: find . $opt -exec rm {} \;
359     find . $opt -exec rm {} \;
360     done
361     }
362    
363 adcroft 1.8 ###############################################################################
364 adcroft 1.23 ###############################################################################
365     ###############################################################################
366 adcroft 1.8
367     # Main function
368    
369     # Default properties
370     debug=0
371     verbose=1
372     quick=0
373 adcroft 1.18 force=0
374 adcroft 1.10 clean=0
375 adcroft 1.14 ieee=1
376 adcroft 1.20 longtest=1
377 adcroft 1.8 expts=''
378 edhill 1.25 genmake=genmake
379 adcroft 1.8
380     # Process arguments
381     for arg in $@
382     do
383     case $arg in
384 adcroft 1.21 -cleanup) clean_up; exit 0;;
385 adcroft 1.8 -quick) quick=1;;
386     -verbose) verbose=2;;
387     -debug) debug=1;;
388 adcroft 1.18 -force) force=1;;
389 adcroft 1.10 -clean) clean=1;;
390 adcroft 1.14 -noieee) ieee=0;;
391 adcroft 1.20 -shorttest) longtest=0;;
392 adcroft 1.8 -quiet) verbose=0;;
393     -help) show_help; exit 0;;
394 adcroft 1.13 -*) echo Unrecognized option:$arg; exit 9;;
395 adcroft 1.8 *) test -d $arg && expts=`echo $expts $arg`;;
396     esac
397     done
398 adcroft 1.15
399 adcroft 1.18 if [ $force -gt 0 -a $quick -gt 0 ]; then
400     echo You specified -quick and -force together which conflict.
401     echo Please specify either -quick or -force or neither but not both.
402 adcroft 1.15 exit 1
403     fi
404 adcroft 1.8
405 adcroft 1.11 #if [ ${#expts} -eq 0 ]; then
406     # echo Scanning all directories
407     # for arg in *
408     # do
409     # test -d $arg && expts=`echo $expts $arg`
410     # done
411     #fi
412     expts=`scandirs $expts`
413 adcroft 1.8
414     createcodelet
415    
416 jmc 1.24 date > summary.txt
417 adcroft 1.10 if [ $longtest -gt 0 ]; then
418 jmc 1.24 cat << EOF >> summary.txt
419 adcroft 1.8 T S U V
420     C D M c m s m s m s m s
421     n p a R g m m e . m m e . m m e . m m e .
422     f n k u 2 i a a d i a a d i a a d i a a d
423     g d e n d n x n . n x n . n x n . n x n .
424    
425     EOF
426     else
427 jmc 1.24 cat << EOF >> summary.txt
428 adcroft 1.8 T S U V
429     C D M c
430     n p a R g m m m m m m m m
431     f n k u 2 i a i a i a i a
432     g d e n d n x n x n x n x
433    
434     EOF
435     fi
436    
437     # Now configue, make, run and test in each directory
438     for dir in $expts
439     do
440     if [ -r $dir/results/output.txt ]; then
441     echo -------------------------------------------------------------------------------
442     echo
443     echo Experiment: $dir
444     echo
445 edhill 1.25 unset genmakepass makedepend make run
446 adcroft 1.12 if [ $longtest -gt 0 ]; then
447     results='-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --'
448     else
449     results='-- -- -- -- -- -- -- -- --'
450     fi
451 adcroft 1.23 if [ -r $dir/build ]; then
452     seperatebuilddir=1
453     builddir=build
454     rundir=build
455     (cd $dir/input; rm -f *.{o,f,c,F} work* output.txt Make* make.log; )
456     (cd $dir/build; ln -sf ../input/* .)
457     else
458     seperatebuilddir=0
459     builddir=input
460     rundir=input
461     fi
462 edhill 1.25 genmakemodel $dir/$builddir && genmakepass=Y \
463 adcroft 1.23 && makecleancompile $dir/$builddir \
464     && makedependmodel $dir/$builddir && makedepend=Y \
465     && makemodel $dir/$builddir && make=Y \
466     && linkdata $seperatebuilddir $dir/$rundir \
467     && runmodel $dir/$builddir mitgcmuv && run=Y \
468     && results=`testoutput $dir $rundir` \
469     && makecleanupafter $dir/$builddir
470 adcroft 1.8 echo
471 edhill 1.25 formatresults $dir ${genmakepass:-N} ${makedepend:-N} ${make:-N} ${run:-N} $results
472 adcroft 1.8 echo
473 edhill 1.25 formatresults $dir ${genmakepass:-N} ${makedepend:-N} ${make:-N} ${run:-N} $results >> summary.txt
474 adcroft 1.8 fi
475     done
476    
477     rm tmp_cmpnum.f a.out
478 adcroft 1.1
479 adcroft 1.8 echo -------------------------------------------------------------------------------
480     echo
481 jmc 1.24 date >> summary.txt
482 adcroft 1.1 cat summary.txt

  ViewVC Help
Powered by ViewVC 1.1.22