1 |
#! /usr/bin/env bash |
2 |
|
3 |
# $Header: /u/gcmpack/mitgcm.org/scripts/check_outp,v 1.5 2009/02/02 19:29:46 jmc Exp $ |
4 |
# |
5 |
# The purpose of this script is to compare |
6 |
# the latest output with the previous one (from the same platform with |
7 |
# same optfile) |
8 |
|
9 |
|
10 |
usage() |
11 |
{ |
12 |
echo |
13 |
echo "Usage: $0 [OPTIONS]" |
14 |
echo |
15 |
echo "where possible OPTIONS are:" |
16 |
echo " (-h|-help) print usage" |
17 |
echo " (-v|-verbose) verbose mode" |
18 |
echo " (-l |-list )MACHINES check platforms from this list" |
19 |
echo " [def=\"$MACHINES\"]" |
20 |
echo " (-d |-day )FIRSTDAY select output from day=\"YYYYMMDD\"" |
21 |
echo " (argument of \"date -d\" is allowed)" |
22 |
echo " [def=\"$FIRSTDAY\"]" |
23 |
echo " (-u |-upto )LASTDAY until last day=\"YYYYMMDD\" (=selected period)" |
24 |
echo " [def=\"FIRSTDAY\"]" |
25 |
echo " (-o |-outp )OUTPFIL output file (-1 removed when exit)" |
26 |
echo " [def=\"$OUTPFIL\"]" |
27 |
echo " (-n |-nldf )NBLDIFF max number of diff lines to echo" |
28 |
echo " [def=\"$NBLDIFF\"]" |
29 |
echo " (-a |-addr )ADDRESS send summary to mail ADDRESS list" |
30 |
echo " [def=\"$ADDRESS\"]" |
31 |
echo |
32 |
exit 1 |
33 |
} |
34 |
|
35 |
#CURR_PER=`date +%Y`"_"`date +%m` |
36 |
CURR_DAY=`date +%Y%m%d` |
37 |
# defaults |
38 |
MACHINES='_All_' |
39 |
FIRSTDAY=$CURR_DAY |
40 |
LASTDAY="30000000" |
41 |
OUTPFIL=`basename $0`'.log' |
42 |
NBLDIFF=5 |
43 |
ADDRESS='none' |
44 |
dBug=f |
45 |
sTime=`date` |
46 |
|
47 |
# Parse options |
48 |
ac_prev= |
49 |
for ac_option ; do |
50 |
|
51 |
# If the previous option needs an argument, assign it. |
52 |
if test -n "$ac_prev"; then |
53 |
eval "$ac_prev=\$ac_option" |
54 |
ac_prev= |
55 |
continue |
56 |
fi |
57 |
|
58 |
ac_optarg=`expr "x$ac_option" : 'x[^=]*=\(.*\)'` |
59 |
|
60 |
case $ac_option in |
61 |
|
62 |
-help | --help | -h | --h) |
63 |
usage ;; |
64 |
-verbose | --verbose | -v | --v) |
65 |
dBug=t ;; |
66 |
|
67 |
-list | --list | -l | --l) |
68 |
ac_prev=MACHINES ;; |
69 |
-list=* | --list=*) |
70 |
MACHINES=$ac_optarg ;; |
71 |
|
72 |
-day | --day | -d | --d) |
73 |
ac_prev=FIRSTDAY ;; |
74 |
-day=* | --day=*) |
75 |
FIRSTDAY=$ac_optarg ;; |
76 |
|
77 |
-upto | --upto | -u | --u) |
78 |
ac_prev=LASTDAY ;; |
79 |
-upto=* | --upto=*) |
80 |
LASTDAY=$ac_optarg ;; |
81 |
|
82 |
-outp | --outp | -o | --o) |
83 |
ac_prev=OUTPFIL ;; |
84 |
-outp=* | --outp=*) |
85 |
OUTPFIL=$ac_optarg ;; |
86 |
|
87 |
-nldf | --nldf | -n | --n) |
88 |
ac_prev=NBLDIFF ;; |
89 |
-nldf=* | --nldf=*) |
90 |
NBLDIFF=$ac_optarg ;; |
91 |
|
92 |
-addr | --addr | -a | --a) |
93 |
ac_prev=ADDRESS ;; |
94 |
-addr=* | --addr=*) |
95 |
ADDRESS=$ac_optarg ;; |
96 |
|
97 |
*) |
98 |
echo "Error: don't understand argument \"$ac_option\"" |
99 |
usage |
100 |
;; |
101 |
|
102 |
esac |
103 |
|
104 |
done |
105 |
#-- test FIRSTDAY content ; interpret as "date -d" arg. if not YYYYMMDD |
106 |
ttt=`echo "y$FIRSTDAY" | sed 's/[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]/z/'` |
107 |
if test "x$ttt" != 'xyz' ; then |
108 |
FIRSTDAY=`date -d "$FIRSTDAY" +%Y%m%d` |
109 |
fi |
110 |
ttt=`echo "y$FIRSTDAY" | sed 's/[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]/z/'` |
111 |
if test "x$ttt" != 'xyz' ; then |
112 |
echo "Error: FIRSTDAY='$FIRSDAY' not recognized" |
113 |
exit 2 |
114 |
fi |
115 |
if test $LASTDAY = "30000000" ; then LASTDAY=$FIRSTDAY ; fi |
116 |
CMDLINE=$0 |
117 |
for xx in "$@" ; do nw=`echo $xx | wc -w` |
118 |
if test $nw = '1' ; then CMDLINE="$CMDLINE $xx" |
119 |
else CMDLINE="$CMDLINE '$xx'" ; fi |
120 |
done |
121 |
|
122 |
PERIOD=`echo $FIRSTDAY | sed 's/[0-9][0-9]$//'` |
123 |
PP=`expr $PERIOD - 1` |
124 |
PM=`echo $PP | sed 's/^[0-9][0-9][0-9][0-9]//'` |
125 |
PY=`echo $PP | sed 's/[0-9][0-9]$//'` |
126 |
if test $PM == '00' ; then PM='12' ; PY=`expr $PY - 1` ; fi |
127 |
PREV_P="${PY}_${PM}"; |
128 |
PERIOD=`echo $PERIOD | sed 's/^[0-9][0-9][0-9][0-9]/&_/'` |
129 |
|
130 |
#INDIR="/net/orwell/export/export-9/mitgcm-testing/results/$PERIOD" |
131 |
INDIR="/u/u0/httpd/html/testing/results/$PERIOD" |
132 |
#INDIR="/export/export-7/u/u2/jmc/mitgcm/test_web/results/$PERIOD" |
133 |
|
134 |
if test $OUTPFIL = '-1' ; then |
135 |
OUTPFIL='TTT.'$$ |
136 |
elif test -e $OUTPFIL ; then |
137 |
mv -f $OUTPFIL $OUTPFIL'_bak' |
138 |
fi |
139 |
echo "CMDLINE='$CMDLINE'" > $OUTPFIL |
140 |
echo "PERIOD='$PERIOD' , PREV_P='$PREV_P'" >> $OUTPFIL |
141 |
echo "INDIR='$INDIR'" >> $OUTPFIL |
142 |
echo "Checking latest output from $FIRSTDAY until $LASTDAY" >> $OUTPFIL |
143 |
|
144 |
if test $dBug = 't' ; then |
145 |
echo "PERIOD='$PERIOD' , PREV_P='$PREV_P'" |
146 |
echo "FIRSTDAY='$FIRSTDAY' , LASTDAY='$LASTDAY'" |
147 |
fi |
148 |
if test -d $INDIR ; then |
149 |
dirP=`echo $INDIR | sed "s/$PERIOD/$PREV_P/"` |
150 |
if test -d $dirP ; then |
151 |
listNum='1 2' |
152 |
else |
153 |
echo "$dirP is not a directory" |
154 |
listNum='1' |
155 |
fi |
156 |
else |
157 |
echo "$INDIR is not a directory" |
158 |
exit 3 |
159 |
fi |
160 |
|
161 |
#- a short summary of this checking : |
162 |
OUTPSUM=`echo $FIRSTDAY | sed 's/^20../_/'` |
163 |
OUTPSUM=`basename $0`"$OUTPSUM.txt" |
164 |
if test -e $OUTPSUM ; then mv -f $OUTPSUM $OUTPSUM'_bak' ; fi |
165 |
echo ' '$CMDLINE > $OUTPSUM |
166 |
|
167 |
if test $FIRSTDAY = $LASTDAY ; then |
168 |
echo -n "Checking latest output from $FIRSTDAY" | tee -a $OUTPSUM |
169 |
else |
170 |
echo -n "Checking latest output from $FIRSTDAY until $LASTDAY" | tee -a $OUTPSUM |
171 |
fi |
172 |
echo " versus latest prior to this period" | tee -a $OUTPSUM |
173 |
echo " Machine Tot. Nb. no Nb with Nb diff" >> $OUTPSUM |
174 |
echo " name checked comp Diff lines" >> $OUTPSUM |
175 |
|
176 |
( cd $INDIR ; ls -1 -t */summary.txt | sed 's/\/summary.txt//' ) > ./dir_all |
177 |
|
178 |
if test "x$MACHINES" = "x_All_" ; then |
179 |
MACHINES="faulks aces eddy bay meander lagoon hugo" |
180 |
MACHINES="$MACHINES columbia edvir rays solasrv sx8 xd1" |
181 |
MACHINES="$MACHINES beagle batsi starp" |
182 |
|
183 |
MALL=`cat ./dir_all | sed -e 's|_| |g' | awk '{print $2}' | sort | uniq` |
184 |
for madd in $MALL ; do |
185 |
present=0 |
186 |
for m in $MACHINES ; do |
187 |
echo $madd | grep $m > /dev/null 2>&1 |
188 |
RETVAL=$? |
189 |
test $RETVAL = 0 && present=1 |
190 |
continue |
191 |
done |
192 |
test $present = 0 && MACHINES="$MACHINES $madd" |
193 |
done |
194 |
fi |
195 |
|
196 |
for mname in $MACHINES ; do |
197 |
|
198 |
if test $dBug = 't' ; then echo " $mname" ; fi |
199 |
echo " name='$mname'" >> $OUTPFIL |
200 |
ctot=0 ; cmis=0 ; cdif=0 |
201 |
|
202 |
# put results from selected period in "slist", |
203 |
# results from previous period in "plist" |
204 |
rm -f ./plist ./slist ; touch ./plist ./slist |
205 |
|
206 |
for n in $listNum ; do |
207 |
num1=`wc -l ./slist | awk '{print $1}'` |
208 |
num0=`wc -l ./plist | awk '{print $1}'` |
209 |
if test $n == 2 ; then |
210 |
num2=`expr $num1 \* $n` |
211 |
if [ $num0 -lt $num2 ] ; then |
212 |
dir_list=`( cd $INDIR ; ls -1 -t ../$PREV_P/*${mname}*/summary.txt 2> /dev/null | sed 's/\/summary.txt//' )` |
213 |
#echo "dir_list='$dir_list'" |
214 |
fi |
215 |
else |
216 |
num2=$n |
217 |
dir_list=`grep $mname ./dir_all` |
218 |
fi |
219 |
if [ $num0 -lt $num2 ] ; then |
220 |
for i in $dir_list ; do |
221 |
|
222 |
dir=$INDIR"/"$i |
223 |
OPTFILE= |
224 |
if test -r $dir/summary.txt ; then |
225 |
comm=`grep 'OPTFILE=' $dir/summary.txt` |
226 |
eval $comm |
227 |
OPTFILE=${OPTFILE##*/} |
228 |
fi |
229 |
if test "x$OPTFILE" = x -a -r "$dir/genmake_state" ; then |
230 |
comm=`grep 'OPTFILE=' $dir/genmake_state 2>/dev/null` |
231 |
eval $comm |
232 |
OPTFILE=${OPTFILE##*/} |
233 |
fi |
234 |
if test "x$OPTFILE" = x ; then |
235 |
comm=`grep '^# OPTFILE=' $dir/*/Makefile* 2>/dev/null | head -1` |
236 |
comm=${comm##*#} |
237 |
eval $comm |
238 |
OPTFILE=${OPTFILE##*/} |
239 |
fi |
240 |
if test "x$OPTFILE" = x ; then |
241 |
OPTFILE="not_explicitly_specified" |
242 |
fi |
243 |
|
244 |
ADJOINT= |
245 |
RESTART=0 |
246 |
NOI3E=0 |
247 |
if test -r $dir/summary.txt ; then |
248 |
comm=`grep 'ADJOINT=true' $dir/summary.txt 2>/dev/null` |
249 |
eval $comm |
250 |
RESTART=`grep -c 'test 2+2=4 summary' $dir/summary.txt` |
251 |
NOI3E=`grep -c "^run: .*testreport .* '*-noieee'* " $dir/summary.txt` |
252 |
fi |
253 |
if test "x$RESTART" = x0 ; then |
254 |
kind="forward" |
255 |
test "x$ADJOINT" = xtrue && kind="adjoint" |
256 |
else |
257 |
kind="restart" |
258 |
fi |
259 |
if test "x$NOI3E" = x1 ; then |
260 |
OPTFILE="${OPTFILE}.noieee" |
261 |
fi |
262 |
day=`echo $i | sed -e 's/_[0-9]$//' | sed -e 's/_[0-9][0-9]$//'` |
263 |
ttt=`echo $day | sed -e 's/_[0-9]$//' | sed -e 's/_[0-9][0-9]$//'` |
264 |
day=`echo $ttt | sed -e 's|_| |g' |awk '{print $NF}'` |
265 |
|
266 |
if [ $day -lt $FIRSTDAY ] ; then |
267 |
echo "$OPTFILE$kind $day $OPTFILE $kind $i" >> ./plist |
268 |
elif [ $day -le $LASTDAY ] ; then |
269 |
echo "$OPTFILE$kind $day $OPTFILE $kind $i" >> ./slist |
270 |
else |
271 |
if test $dBug = 't' ; then |
272 |
echo "discard day='$day' from: $i" | tee -a $OUTPFIL |
273 |
fi |
274 |
fi |
275 |
|
276 |
done |
277 |
if test $dBug = 't' ; then |
278 |
if test $n == 1 ; then |
279 |
echo "---- current list (n=$n) :" | tee -a $OUTPFIL |
280 |
cat ./slist | tee -a $OUTPFIL |
281 |
fi |
282 |
echo ".... previous list (n=$n):" | tee -a $OUTPFIL |
283 |
cat ./plist | tee -a $OUTPFIL |
284 |
fi |
285 |
|
286 |
fi |
287 |
done |
288 |
if test $dBug = 't' ; then echo "----" | tee -a $OUTPFIL ; fi |
289 |
|
290 |
# Do we have any data? If so, create the latest pointer. |
291 |
num=`wc -l ./slist | awk '{print $1}'` |
292 |
if test $num -gt 0 ; then |
293 |
|
294 |
keys=`cat ./slist | cut -d " " -f 1 | sort | uniq` |
295 |
|
296 |
for key in $keys ; do |
297 |
ctot=`expr $ctot + 1` |
298 |
sline=`grep "^$key " ./slist | head -1` |
299 |
sdir=`echo $sline | cut -d " " -f 5` |
300 |
kind=`echo $sline | cut -d " " -f 4` |
301 |
optf=`echo $sline | cut -d " " -f 3` |
302 |
num=`grep -c "^$key" ./plist` |
303 |
#- discard unsafe test: |
304 |
dd=`echo $optf | grep -c 'gfortran.*mth'` |
305 |
#if [ $dd -ge 1 ] ; then num=-1 ; fi |
306 |
if test $num -gt 0 ; then |
307 |
pline=`grep "^$key " ./plist | head -1` |
308 |
if test $dBug = 't' ; then |
309 |
echo "s='$sline'" | tee -a $OUTPFIL |
310 |
echo "p='$pline'" | tee -a $OUTPFIL |
311 |
fi |
312 |
pdir=`echo $pline | cut -d " " -f 5` |
313 |
outs="$INDIR/$sdir/summary.txt" |
314 |
sed -n "5,$ p" $outs | sed '/^[YN] [YN] [YN] [YN]/ s/ \. //g' \ |
315 |
| sed 's/ OPTFILE=.*\// OPTFILE=/g' \ |
316 |
| grep -v '^[A-S][a-t]* time: ' > tmpfs |
317 |
outp="$INDIR/$pdir/summary.txt" |
318 |
sed -n "5,$ p" $outp | sed '/^[YN] [YN] [YN] [YN]/ s/ \. //g' \ |
319 |
| sed 's/ OPTFILE=.*\// OPTFILE=/g' \ |
320 |
| grep -v '^[A-S][a-t]* time: ' > tmpfp |
321 |
echo -n "=== diff $sdir $pdir :" | tee -a $OUTPFIL |
322 |
diff tmpfs tmpfp > tmpdf |
323 |
yy=$? |
324 |
if test $yy != '0' ; then |
325 |
echo " $kind , of='$optf'" | tee -a $OUTPFIL |
326 |
#grep '^run: ' $outp |
327 |
#grep '^run: ' $outs |
328 |
#-- score for each test: |
329 |
grep '^[YN] [YN] [YN] [YN]' tmpfs > tmploc 2>/dev/null |
330 |
t_tot=`cat tmploc | wc -l | sed -e 's| ||g'` |
331 |
t_pass=`grep '^Y Y Y Y' tmploc | grep 'pass ' | wc -l | sed -e 's| ||g'` |
332 |
score_s=`printf '%2i' $t_pass`":$t_tot" |
333 |
grep '^[YN] [YN] [YN] [YN]' tmpfp > tmploc 2>/dev/null |
334 |
t_tot=`cat tmploc | wc -l | sed -e 's| ||g'` |
335 |
t_pass=`grep '^Y Y Y Y' tmploc | grep 'pass ' | wc -l | sed -e 's| ||g'` |
336 |
score_p=`printf '%2i' $t_pass`":$t_tot" |
337 |
rm -f tmploc |
338 |
#-- count Nb of different lines |
339 |
ndf=`wc -l tmpdf | awk '{print $1}'` |
340 |
ndf=`expr $ndf / 2` |
341 |
nn=`grep -c '^---' tmpdf` |
342 |
ndf=`expr $ndf - $nn` |
343 |
if [ $ndf -le $NBLDIFF ] ; then |
344 |
cat tmpdf |
345 |
else |
346 |
echo " $ndf lines differ ( $score_s , $score_p )" |
347 |
fi |
348 |
echo "< "`head -1 $outs`" ( $score_s )" >> $OUTPFIL |
349 |
echo "> "`head -1 $outp`" ( $score_p )" >> $OUTPFIL |
350 |
cat tmpdf >> $OUTPFIL |
351 |
if [ $cdif -eq 0 ] ; then |
352 |
clin=`printf '%3i (%5s,%5s)' $ndf $score_s $score_p` |
353 |
else |
354 |
clin="$clin,"`printf '%3i (%5s,%5s)' $ndf $score_s $score_p` |
355 |
fi |
356 |
cdif=`expr $cdif + 1` |
357 |
echo '----------------------------------------' | tee -a $OUTPFIL |
358 |
else |
359 |
echo "" | tee -a $OUTPFIL |
360 |
fi |
361 |
rm -f tmpfs tmpfp tmpdf |
362 |
elif test $num = '0' ; then |
363 |
echo "no previous test for:" $key | tee -a $OUTPFIL |
364 |
cmis=`expr $cmis + 1` |
365 |
else |
366 |
cmis=`expr $cmis + 1` |
367 |
fi |
368 |
done |
369 |
if [ $cmis -gt 0 ] ; then tmis='(-'$cmis')' ; else tmis='(--)' ; fi |
370 |
printf '%11s : %3i %4s %3i ' $mname $ctot $tmis $cdif >> $OUTPSUM |
371 |
if [ $cdif -gt 0 ] ; then |
372 |
echo " $clin" >> $OUTPSUM |
373 |
else echo "" >> $OUTPSUM ; fi |
374 |
fi |
375 |
|
376 |
done |
377 |
|
378 |
echo "Start time: $sTime" | tee -a $OUTPFIL |
379 |
echo "End time: "`date` | tee -a $OUTPFIL | tee -a $OUTPSUM |
380 |
|
381 |
rm -f ./dir_all ./slist ./plist |
382 |
if test $OUTPFIL = "TTT.$$" ; then rm -f $OUTPFIL ; fi |
383 |
if test "x$ADDRESS" != 'xnone' ; then |
384 |
echo ".. send $OUTPSUM to $ADDRESS" |
385 |
mail -s $OUTPSUM $ADDRESS < $OUTPSUM |
386 |
fi |
387 |
echo ".. cat $OUTPSUM" |
388 |
cat $OUTPSUM |
389 |
exit 0 |