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

Contents of /MITgcm/verification/testscript

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


Revision 1.9 - (show annotations) (download)
Mon Aug 6 15:11:03 2001 UTC (19 years, 11 months ago) by adcroft
Branch: MAIN
Changes since 1.8: +10 -54 lines
Added -ieee flag to genmake (only affect Linux for now) to see if we can
pin-down this rediculous sensitivity of model to small changes in code.
Testscript uses -ieee by default.

1 #!/bin/sh
2
3 compare_lines()
4 {
5 # use codelet to compare lines
6 if [ $verbose -gt 1 ]; then
7 cat tmp3.txt 1>&2
8 fi
9 return `./a.out < tmp3.txt`
10 }
11
12 testoutput_for_prop()
13 {
14 # testoutput_for_prop dir s1 label
15 #
16 # compares files in $dir/input/output.txt and $dir/results.output.txt
17 # using search strings s1 and text label
18
19 if [ $debug -gt 0 ]; then
20 echo testoutput_for_prop: grep "$2" $1/input/output.txt 1>&2
21 fi
22 if [ -r $1/input/output.txt ]; then
23 grep "$2" $1/input/output.txt | sed 's/.*=//' | nl > tmp1.txt
24 else
25 echo testoutput_for_prop: output.txt from model run was not readable 1>&2
26 return 99
27 fi
28 if [ $debug -gt 0 ]; then
29 echo testoutput_for_prop: grep "$2" $1/results/output.txt 1>&2
30 fi
31 grep "$2" $1/results/output.txt | sed 's/.*=//' | nl > tmp2.txt
32 if [ $debug -gt 0 ]; then
33 echo testoutput_for_prop: join tmp1.txt tmp2.txt 1>&2
34 fi
35 join tmp1.txt tmp2.txt | awk '{print $1 " " $2 " " $3}' > tmp3.txt
36 if [ $debug -gt 0 ]; then
37 echo testoutput_for_prop: compare_lines 1>&2
38 fi
39 compare_lines
40 digits_of_similarity=$?
41 if [ $digits_of_similarity -eq 99 ]; then
42 if [ $verbose -gt 0 ]; then
43 echo testoutput_for_prop: No comparison was available for \"$2\" 1>&2
44 fi
45 digits_of_similarity=99
46 else
47 if [ $verbose -gt 0 ]; then
48 echo There were $digits_of_similarity decimal places of similarity for \"$2\" 1>&2
49 fi
50 fi
51 rm tmp1.txt tmp2.txt tmp3.txt
52
53 return $digits_of_similarity
54 }
55
56 dashnum()
57 {
58 # dashnum n1 n2 n3 ...
59 #
60 # print numbers using %3i format or "--" if number = 99
61 for num in $@
62 do
63 if [ $num = 99 ]; then
64 printf ' --'
65 else
66 printf '%3i' $num
67 fi
68 done
69 }
70
71 testoutput()
72 {
73 # testoutput diretory
74 #
75 # test output in "directory"
76
77 if [ $debug -gt 0 ]; then
78 echo testoutput: testoutput_for_prop $1 cg2d_init_res 1>&2
79 fi
80 testoutput_for_prop $1 "cg2d_init_res" "cg2d init. residual"; cg2dres=$?
81 if [ $debug -gt 0 ]; then
82 echo testoutput: cg2dres=$cg2dres 1>&2
83 fi
84
85 if [ $testmore -gt 0 ]; then
86 testoutput_for_prop $1 "dynstat_theta_min" "theta minimum"; tmin=$?
87 testoutput_for_prop $1 "dynstat_theta_max" "theta maximum"; tmax=$?
88 testoutput_for_prop $1 "dynstat_theta_mean" "theta mean"; tmean=$?
89 testoutput_for_prop $1 "dynstat_theta_sd" "theta s.d."; tsd=$?
90 testoutput_for_prop $1 "dynstat_salt_min" "salt minimum"; smin=$?
91 testoutput_for_prop $1 "dynstat_salt_max" "salt maximum"; smax=$?
92 testoutput_for_prop $1 "dynstat_salt_mean" "salt mean"; smean=$?
93 testoutput_for_prop $1 "dynstat_salt_sd" "salt s.d."; ssd=$?
94 testoutput_for_prop $1 "dynstat_uvel_min" "U minimum"; umin=$?
95 testoutput_for_prop $1 "dynstat_uvel_max" "U maximum"; umax=$?
96 testoutput_for_prop $1 "dynstat_uvel_mean" "U mean"; umean=$?
97 testoutput_for_prop $1 "dynstat_uvel_sd" "U s.d."; usd=$?
98 testoutput_for_prop $1 "dynstat_vvel_min" "V minimum"; vmin=$?
99 testoutput_for_prop $1 "dynstat_vvel_max" "V maximum"; vmax=$?
100 testoutput_for_prop $1 "dynstat_vvel_mean" "V mean"; vmean=$?
101 testoutput_for_prop $1 "dynstat_vvel_sd" "V s.d."; vsd=$?
102 else
103 testoutput_for_prop $1 "dynstat_theta_min" "theta minimum"; tmin=$?
104 testoutput_for_prop $1 "dynstat_theta_max" "theta maximum"; tmax=$?
105 testoutput_for_prop $1 "dynstat_salt_min" "salt minimum"; smin=$?
106 testoutput_for_prop $1 "dynstat_salt_max" "salt maximum"; smax=$?
107 testoutput_for_prop $1 "dynstat_uvel_min" "U minimum"; umin=$?
108 testoutput_for_prop $1 "dynstat_uvel_max" "U maximum"; umax=$?
109 testoutput_for_prop $1 "dynstat_vvel_min" "V minimum"; vmin=$?
110 testoutput_for_prop $1 "dynstat_vvel_max" "V maximum"; vmax=$?
111 fi
112
113 dashnum $cg2dres $tmin $tmax $tmean $tsd $smin $smax $smean $ssd \
114 $umin $umax $umean $usd $vmin $vmax $vmean $vsd
115 #printf '%3i' $cg2dres $tmin $tmax $tmean $tsd $smin $smax $smean $ssd \
116 # $umin $umax $umean $usd $vmin $vmax $vmean $vsd
117 }
118
119 genmakemodel()
120 {
121 # genmakemodel directory
122 ( cd $1;
123 if [ $quick -eq 0 -o ! -r Makefile ]; then
124 printf 'genmake ... ' 1>&2
125 ../../../tools/genmake -ieee -mods=../code > make.log 2>&1
126 if [ $? -ne 0 ]; then
127 tail make.log
128 echo makemodel: genmake failed 1>&2
129 return 1
130 else
131 echo succesful 1>&2
132 fi
133 fi
134 )
135 }
136
137 makedependmodel()
138 {
139 # makedependmodel directory
140 ( cd $1;
141 if [ $quick -eq 0 -o ! -r Makefile ]; then
142 printf 'make depend ... ' 1>&2
143 make cleanlinks >> make.log 2>&1
144 make depend >> make.log 2>&1
145 if [ $? -ne 0 ]; then
146 tail make.log
147 echo makemodel: make depend failed 1>&2
148 return 1
149 else
150 echo succesful 1>&2
151 fi
152 fi
153 )
154 }
155
156 makemodel()
157 {
158 # makemodel directory
159 ( cd $1;
160 if [ -r Makefile ]; then
161 printf 'make ... ' 1>&2
162 make >> make.log 2>&1
163 if [ $? -ne 0 ]; then
164 tail make.log
165 echo failed 1>&2
166 return 1
167 else
168 echo succesful 1>&2
169 fi
170 fi
171 )
172 }
173
174 runmodel()
175 {
176 # runmodel directory exe
177 #
178 # runs the model "exe" in "directory" (exe is relative to directory)
179
180 ( cd $1
181 if [ -x $2 ]; then
182 if [ ! -r output.txt -o $quick -eq 0 ]; then
183 echo runmodel: running... 1>&2
184 ( ./$2 > output.txt 2>&1 ) && return 0
185 return 1
186 else
187 echo runmodel: output.txt is newer than executable 1>&2
188 return 0
189 fi
190 else
191 echo runmodel: executable \"$1/$2\" is missing 1>&2
192 return 1
193 fi
194 )
195 }
196
197 createcodelet()
198 {
199 # create codelet for comparing model output
200 cat > tmp_cmpnum.f <<EOFA
201 program cmpnum
202 implicit none
203 real*8 a,b,diff
204 integer linnum,best
205 best=-16
206 99 read(*,*,end=70,err=60) linnum,a,b
207 diff=0.5*(abs(a)+abs(b))
208 c print *,a,b,diff,abs(a-b)/diff
209 if (diff.gt.1.e-12) then
210 diff=abs(a-b)/diff
211 if (diff.gt.0.) then
212 c print *,int(log10(diff)),diff
213 linnum=int(log10(diff))
214 best=max(best,linnum)
215 endif
216 else
217 if (best.eq.-16.and.diff.ne.0.) best=-22
218 endif
219 goto 99
220 60 stop 'cmpnum: An error occured reading a,b'
221 70 print *,-best
222 end
223 EOFA
224 f77 tmp_cmpnum.f
225 if [ -x ./a.out ]; then
226 return 0
227 else
228 echo createcodelet: failed to compile codelet 1>&2
229 exit 1
230 fi
231 }
232
233 formatresults()
234 {
235 # formatresults expt genmake depend make run results*
236
237 nm=$1
238 printf '%s %s %s %s' $2 $3 $4 $5
239 shift; shift; shift; shift; shift;
240 printf '%3s' $@
241
242 if [ $1 = '--' ]; then
243 printf ' N/O '
244 else
245 if [ $1 -gt 12 ]; then
246 printf ' pass'
247 else
248 printf ' FAIL'
249 fi
250 fi
251 printf ' %s' $nm
252 printf '\n'
253
254 }
255
256 show_help()
257 {
258 cat - << EOF
259 $0 [-help] [-quick] [-verbose] dir1 [dir2] [...]
260 -help Show this help message
261 -quick Skip "genmake" and "make depend" if the Makefile exists
262 -quiet Reduce the amount of output
263 -verbose Produce copious amounts of output
264
265 Normal usage:
266 $0 * Configure, compile, run and analyze in all experiment directories
267 EOF
268 }
269
270 ###############################################################################
271
272 # Main function
273
274 # Default properties
275 debug=0
276 verbose=1
277 quick=0
278 testmore=0
279 expts=''
280
281 # Process arguments
282 for arg in $@
283 do
284 case $arg in
285 -quick) quick=1;;
286 -verbose) verbose=2;;
287 -debug) debug=1;;
288 -testmore) testmore=1;;
289 -quiet) verbose=0;;
290 -help) show_help; exit 0;;
291 *) test -d $arg && expts=`echo $expts $arg`;;
292 esac
293 done
294
295 if [ ${#expts} -eq 0 ]; then
296 echo Scanning all directories
297 for arg in *
298 do
299 test -d $arg && expts=`echo $expts $arg`
300 done
301 fi
302
303 createcodelet
304
305 if [ $testmore -gt 0 ]; then
306 cat << EOF > summary.txt
307 T S U V
308 C D M c m s m s m s m s
309 n p a R g m m e . m m e . m m e . m m e .
310 f n k u 2 i a a d i a a d i a a d i a a d
311 g d e n d n x n . n x n . n x n . n x n .
312
313 EOF
314 else
315 cat << EOF > summary.txt
316 T S U V
317 C D M c
318 n p a R g m m m m m m m m
319 f n k u 2 i a i a i a i a
320 g d e n d n x n x n x n x
321
322 EOF
323 fi
324
325 # Now configue, make, run and test in each directory
326 for dir in $expts
327 do
328 if [ -r $dir/results/output.txt ]; then
329 echo -------------------------------------------------------------------------------
330 echo
331 echo Experiment: $dir
332 echo
333 unset genmake makedepend make run
334 results='-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --'
335 results='-- -- -- -- -- -- -- -- --'
336 genmakemodel $dir/input && genmake=Y \
337 && makedependmodel $dir/input && makedepend=Y \
338 && makemodel $dir/input && make=Y \
339 && runmodel $dir/input mitgcmuv && run=Y \
340 && results=`testoutput $dir`
341 echo
342 formatresults $dir ${genmake:-N} ${makedepend:-N} ${make:-N} ${run:-N} $results
343 echo
344 formatresults $dir ${genmake:-N} ${makedepend:-N} ${make:-N} ${run:-N} $results >> summary.txt
345 fi
346 done
347
348 rm tmp_cmpnum.f a.out
349
350 echo -------------------------------------------------------------------------------
351 echo
352 cat summary.txt

  ViewVC Help
Powered by ViewVC 1.1.22