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