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 [ $longtest -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 |
if [ $ieee -eq 0 ]; then |
126 |
../../../tools/genmake -mods=../code > make.log 2>&1 |
127 |
else |
128 |
../../../tools/genmake -ieee -mods=../code > make.log 2>&1 |
129 |
fi |
130 |
if [ $? -ne 0 ]; then |
131 |
tail make.log |
132 |
echo genmakemodel: genmake failed 1>&2 |
133 |
return 1 |
134 |
else |
135 |
echo succesful 1>&2 |
136 |
fi |
137 |
fi |
138 |
) |
139 |
} |
140 |
|
141 |
makeclean() |
142 |
{ |
143 |
# makedependmodel directory |
144 |
( cd $1; |
145 |
if [ $clean -gt 0 ]; then |
146 |
printf 'make clean ... ' 2>&1 |
147 |
make CLEAN >> make.log 2>&1 |
148 |
if [ $? -ne 0 ]; then |
149 |
tail make.log |
150 |
echo makeclean: make clean failed 1>&2 |
151 |
return 1 |
152 |
else |
153 |
echo succesful 1>&2 |
154 |
fi |
155 |
fi |
156 |
) |
157 |
} |
158 |
|
159 |
makedependmodel() |
160 |
{ |
161 |
# makedependmodel directory |
162 |
( cd $1; |
163 |
if [ $quick -eq 0 -o ! -r Makefile ]; then |
164 |
printf 'make depend ... ' 1>&2 |
165 |
make cleanlinks >> make.log 2>&1 |
166 |
make depend >> make.log 2>&1 |
167 |
if [ $? -ne 0 ]; then |
168 |
tail make.log |
169 |
echo makemodel: make depend failed 1>&2 |
170 |
return 1 |
171 |
else |
172 |
echo succesful 1>&2 |
173 |
fi |
174 |
fi |
175 |
) |
176 |
} |
177 |
|
178 |
makemodel() |
179 |
{ |
180 |
# makemodel directory |
181 |
( cd $1; |
182 |
if [ -r Makefile ]; then |
183 |
printf 'make ... ' 1>&2 |
184 |
make >> make.log 2>&1 |
185 |
if [ $? -ne 0 ]; then |
186 |
tail make.log |
187 |
echo failed 1>&2 |
188 |
return 1 |
189 |
else |
190 |
echo succesful 1>&2 |
191 |
fi |
192 |
fi |
193 |
) |
194 |
} |
195 |
|
196 |
runmodel() |
197 |
{ |
198 |
# runmodel directory exe |
199 |
# |
200 |
# runs the model "exe" in "directory" (exe is relative to directory) |
201 |
|
202 |
( cd $1 |
203 |
if [ -x $2 ]; then |
204 |
if [ ! -r output.txt -o $quick -eq 0 ]; then |
205 |
echo runmodel: running... 1>&2 |
206 |
( ./$2 > output.txt 2>&1 ) && return 0 |
207 |
return 1 |
208 |
else |
209 |
echo runmodel: output.txt is newer than executable 1>&2 |
210 |
return 0 |
211 |
fi |
212 |
else |
213 |
echo runmodel: executable \"$1/$2\" is missing 1>&2 |
214 |
return 1 |
215 |
fi |
216 |
) |
217 |
} |
218 |
|
219 |
createcodelet() |
220 |
{ |
221 |
# create codelet for comparing model output |
222 |
cat > tmp_cmpnum.f <<EOFA |
223 |
program cmpnum |
224 |
implicit none |
225 |
real*8 a,b,diff |
226 |
integer linnum,best |
227 |
best=-16 |
228 |
99 read(*,*,end=70,err=60) linnum,a,b |
229 |
diff=0.5*(abs(a)+abs(b)) |
230 |
c print *,a,b,diff,abs(a-b)/diff |
231 |
if (diff.gt.1.e-12) then |
232 |
diff=abs(a-b)/diff |
233 |
if (diff.gt.0.) then |
234 |
c print *,int(log10(diff)),diff |
235 |
linnum=int(log10(diff)) |
236 |
best=max(best,linnum) |
237 |
endif |
238 |
else |
239 |
if (best.eq.-16.and.diff.ne.0.) best=-22 |
240 |
endif |
241 |
goto 99 |
242 |
60 stop 'cmpnum: An error occured reading a,b' |
243 |
70 print *,-best |
244 |
end |
245 |
EOFA |
246 |
f77 tmp_cmpnum.f |
247 |
if [ -x ./a.out ]; then |
248 |
return 0 |
249 |
else |
250 |
echo createcodelet: failed to compile codelet 1>&2 |
251 |
exit 1 |
252 |
fi |
253 |
} |
254 |
|
255 |
formatresults() |
256 |
{ |
257 |
# formatresults expt genmake depend make run results* |
258 |
|
259 |
nm=$1 |
260 |
printf '%s %s %s %s' $2 $3 $4 $5 |
261 |
shift; shift; shift; shift; shift; |
262 |
printf '%3s' $@ |
263 |
|
264 |
if [ $1 = '--' ]; then |
265 |
printf ' N/O ' |
266 |
else |
267 |
if [ $1 -gt 12 ]; then |
268 |
printf ' pass' |
269 |
else |
270 |
printf ' FAIL' |
271 |
fi |
272 |
fi |
273 |
printf ' %s' $nm |
274 |
printf '\n' |
275 |
|
276 |
} |
277 |
|
278 |
show_help() |
279 |
{ |
280 |
cat - << EOF |
281 |
$0 [-help] [-quick] [-verbose] dir1 [dir2] [...] |
282 |
-help Show this help message |
283 |
-quick Skip "genmake" and "make depend" if the Makefile exists |
284 |
-quiet Reduce the amount of output |
285 |
-verbose Produce copious amounts of output |
286 |
-debug Produce even more output which will mean nothing to most |
287 |
-clean Do "make CLEAN" before compiling. This forces a complete rebuild. |
288 |
-longtest Compare numeric output for mean and s.d. of variables. |
289 |
-noieee By default, $0 uses the -ieee option for genmake. This turns it off. |
290 |
|
291 |
Normal usage: |
292 |
$0 * Configure, compile, run and analyze in all experiment directories |
293 |
EOF |
294 |
} |
295 |
|
296 |
scandirs() |
297 |
{ |
298 |
if [ $# -eq 0 ]; then |
299 |
for arg in * |
300 |
do |
301 |
test -d $arg/input && echo $arg |
302 |
done |
303 |
else |
304 |
echo $* |
305 |
fi |
306 |
} |
307 |
|
308 |
############################################################################### |
309 |
|
310 |
# Main function |
311 |
|
312 |
# Default properties |
313 |
debug=0 |
314 |
verbose=1 |
315 |
quick=0 |
316 |
clean=0 |
317 |
ieee=1 |
318 |
longtest=0 |
319 |
expts='' |
320 |
|
321 |
# Process arguments |
322 |
for arg in $@ |
323 |
do |
324 |
case $arg in |
325 |
-quick) quick=1;; |
326 |
-verbose) verbose=2;; |
327 |
-debug) debug=1;; |
328 |
-clean) clean=1;; |
329 |
-noieee) ieee=0;; |
330 |
-longtest) longtest=1;; |
331 |
-quiet) verbose=0;; |
332 |
-help) show_help; exit 0;; |
333 |
-*) echo Unrecognized option:$arg; exit 9;; |
334 |
*) test -d $arg && expts=`echo $expts $arg`;; |
335 |
esac |
336 |
done |
337 |
|
338 |
#if [ ${#expts} -eq 0 ]; then |
339 |
# echo Scanning all directories |
340 |
# for arg in * |
341 |
# do |
342 |
# test -d $arg && expts=`echo $expts $arg` |
343 |
# done |
344 |
#fi |
345 |
expts=`scandirs $expts` |
346 |
|
347 |
createcodelet |
348 |
|
349 |
if [ $longtest -gt 0 ]; then |
350 |
cat << EOF > summary.txt |
351 |
T S U V |
352 |
C D M c m s m s m s m s |
353 |
n p a R g m m e . m m e . m m e . m m e . |
354 |
f n k u 2 i a a d i a a d i a a d i a a d |
355 |
g d e n d n x n . n x n . n x n . n x n . |
356 |
|
357 |
EOF |
358 |
else |
359 |
cat << EOF > summary.txt |
360 |
T S U V |
361 |
C D M c |
362 |
n p a R g m m m m m m m m |
363 |
f n k u 2 i a i a i a i a |
364 |
g d e n d n x n x n x n x |
365 |
|
366 |
EOF |
367 |
fi |
368 |
|
369 |
# Now configue, make, run and test in each directory |
370 |
for dir in $expts |
371 |
do |
372 |
if [ -r $dir/results/output.txt ]; then |
373 |
echo ------------------------------------------------------------------------------- |
374 |
echo |
375 |
echo Experiment: $dir |
376 |
echo |
377 |
unset genmake makedepend make run |
378 |
if [ $longtest -gt 0 ]; then |
379 |
results='-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --' |
380 |
else |
381 |
results='-- -- -- -- -- -- -- -- --' |
382 |
fi |
383 |
genmakemodel $dir/input && genmake=Y \ |
384 |
&& makeclean $dir/input \ |
385 |
&& makedependmodel $dir/input && makedepend=Y \ |
386 |
&& makemodel $dir/input && make=Y \ |
387 |
&& runmodel $dir/input mitgcmuv && run=Y \ |
388 |
&& results=`testoutput $dir` |
389 |
echo |
390 |
formatresults $dir ${genmake:-N} ${makedepend:-N} ${make:-N} ${run:-N} $results |
391 |
echo |
392 |
formatresults $dir ${genmake:-N} ${makedepend:-N} ${make:-N} ${run:-N} $results >> summary.txt |
393 |
fi |
394 |
done |
395 |
|
396 |
rm tmp_cmpnum.f a.out |
397 |
|
398 |
echo ------------------------------------------------------------------------------- |
399 |
echo |
400 |
cat summary.txt |