/[MITgcm]/MITgcm/verification/testscript2
ViewVC logotype

Contents of /MITgcm/verification/testscript2

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


Revision 1.1 - (show annotations) (download)
Sat Aug 16 14:01:08 2003 UTC (20 years, 8 months ago) by edhill
Branch: MAIN
CVS Tags: checkpoint51f_post, checkpoint51h_pre, branchpoint-genmake2, checkpoint51g_post, checkpoint51j_post
Branch point for: branch-genmake2
This is the first version of "genmake2" and "testscript2" (and support files)
that pass all the standard verification tests on faulks.  Since they have new
names, they can be run side-by-side (no known conflicts) with the existing
genmake and testscript versions.  If you get a chance, please try them on your
system and mail the output to <eh3@mit.edu>.

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

  ViewVC Help
Powered by ViewVC 1.1.22