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