/[MITgcm]/MITgcm/verification/testsh
ViewVC logotype

Contents of /MITgcm/verification/testsh

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


Revision 1.3 - (show annotations) (download)
Fri Aug 3 20:18:40 2001 UTC (22 years, 8 months ago) by adcroft
Branch: MAIN
CVS Tags: HEAD
Changes since 1.2: +0 -0 lines
FILE REMOVED
Finally moved over to /bin/sh

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

  ViewVC Help
Powered by ViewVC 1.1.22