source: branches/NERC/dev_sette_NERC/sette_rpt.sh @ 13622

Last change on this file since 13622 was 13622, checked in by smueller, 6 months ago

MEDUSA-specific extension of the test for local working-copy modifications in SETTE

  • Property svn:executable set to *
File size: 15.6 KB
Line 
1#!/bin/bash -f
2# set -vx
3# simple SETTE report generator.
4#
5# This version should be run in the SETTE directory.
6# The machine name will be picked up from the sette.sh script but the location of the
7# validation directory needs to be set here (currently assumed to reside in the ../cfgs directory)
8#
9#########################################################################################
10######################### Start of function definitions #################################
11##
12
13function get_dorv() {
14  if [ $lastchange == 'old' ] ; then
15    dorv=`ls -1rt $vdir/$nam/$mach/ | tail -1l `
16    dorv=`echo $dorv | sed -e 's:.*/::'`
17    dorv2=`ls -1rt $vdir/$nam2/$mach/ | tail -1l `
18    dorv2=`echo $dorv2 | sed -e 's:.*/::'`
19  else
20    dorv=$lastchange
21    dorv2=$lastchange
22  fi
23}
24
25function get_ktdiff() {
26  ktdiff=`diff ${1} ${2} | head -2 | grep it | awk '{ print $4 }'`
27}
28
29function resttest() { 
30#
31# Restartability checks. Expects LONG and SHORT run directories
32# Compares end of LONG stat files with equivalent entries from the SHORT stat files.
33#
34  vdir=$1
35  nam=$2
36  pass=$3
37#
38# get $dorv
39  get_dorv
40#
41# check if directory is here
42  if [ ! -d $vdir/$nam/$mach/$dorv ]; then
43    printf "%-27s %s %s\n" $nam  " directory                  MISSING : " $dorv
44    return
45  fi
46
47  if [ -d $vdir/$nam/$mach/$dorv ]; then
48    # check ocean output
49    runtest $vdir $nam $pass RST
50    #
51    # run restartibility test
52    f1o=$vdir/$nam/$mach/$dorv/LONG/ocean.output
53    f1s=$vdir/$nam/$mach/$dorv/LONG/run.stat
54    f1t=$vdir/$nam/$mach/$dorv/LONG/tracer.stat
55    f2o=$vdir/$nam/$mach/$dorv/SHORT/ocean.output
56    f2s=$vdir/$nam/$mach/$dorv/SHORT/run.stat
57    f2t=$vdir/$nam/$mach/$dorv/SHORT/tracer.stat
58
59    if  [ ! -f $f1s ] &&  [ ! -f $f1t ] ; then
60      printf "%-27s %s\n" $nam " incomplete test";
61      return;
62    fi
63    if  [ ! -f $f2s ] &&  [ ! -f $f2t ] ; then
64      printf "%-27s %s\n" $nam " incomplete test";
65      return;
66    fi
67#
68    done_oce=0
69
70    if  [  -f $f1s ] && [  -f $f2s ]; then
71      nl=(`wc -l $f2s`)
72      tail -${nl[0]} $f1s > f1.tmp$$
73      cmp -s f1.tmp$$ $f2s
74      if [ $? == 0 ]; then
75        if [ $pass == 0 ]; then
76          printf "%-27s %s %s\n" $nam  " run.stat    restartability  passed : " $dorv
77        fi
78      else
79        get_ktdiff f1.tmp$$ $f2s
80        printf "\e[38;5;196m%-27s %s %s %s %-5s %s\e[0m\n" $nam  " run.stat    restartability  FAILED : " $dorv " (results are different after " $ktdiff " time steps)"
81#
82# Offer view of differences on the second pass
83#
84        if [ $pass == 1 ]; then
85          echo "<return> to view run.stat differences"
86          read y
87          sdiff f1.tmp$$ $f2s
88          echo "<return> to view ocean.output differences"
89          read y
90          sdiff $f1o $f2o | grep "|"
91          done_oce=1
92          echo "<return> to continue"
93          read y
94        fi
95      fi
96    fi
97#
98# Check tracer.stat files (if they exist)
99#
100    if  [  -f $f1t ] && [  -f $f2t ]; then
101      nl=(`wc -l $f2t`)
102      tail -${nl[0]} $f1t > f1.tmp$$
103      cmp -s f1.tmp$$ $f2t
104      if [ $? == 0 ]; then
105        if [ $pass == 0 ]; then
106          printf "%-27s %s %s\n" $nam  " tracer.stat restartability  passed : " $dorv
107        fi
108      else
109        get_ktdiff f1.tmp$$ $f2t
110        printf "\e[38;5;196m%-27s %s %s %s %-5s %s\e[0m\n" $nam  " tracer.stat    restartability  FAILED : " $dorv " (results are different after " $ktdiff " time steps)"
111#
112# Offer view of differences on the second pass
113#
114        if [ $pass == 1 ]; then
115          echo "<return> to view tracer.stat differences"
116          read y
117          sdiff f1.tmp$$ $f2t
118#
119# Only offer ocean.output view if it has not been viewed previously
120#
121          if [ $done_oce == 0 ]; then
122            echo "<return> to view ocean.output differences"
123            read y
124            sdiff $f1o $f2o | grep "|"
125          fi
126          echo "<return> to continue"
127          read y
128        fi
129      fi
130    fi
131    rm f1.tmp$$
132  fi
133}
134
135function reprotest(){
136#
137# Reproducibility checks. Expects REPRO_N_M and REPRO_I_J run directories
138# Compares end of stat files from each
139#
140  vdir=$1
141  nam=$2
142  pass=$3
143#
144# get $dorv
145  get_dorv
146#
147# check if directory is here
148  if [ ! -d $vdir/$nam/$mach/$dorv ]; then
149    printf "%-27s %s %s\n" $nam  " directory                  MISSING : " $dorv
150    return
151  fi
152#
153  if [ -d $vdir/$nam/$mach/$dorv ]; then
154    # check ocean output
155    runtest $vdir $nam $pass REPRO
156    #
157    # check reproducibility
158    rep1=`ls -1rt $vdir/$nam/$mach/$dorv/ | grep REPRO | tail -2l | head -1 `
159    rep2=`ls -1rt $vdir/$nam/$mach/$dorv/ | grep REPRO | tail -1l`
160    f1o=$vdir/$nam/$mach/$dorv/$rep1/ocean.output
161    f1s=$vdir/$nam/$mach/$dorv/$rep1/run.stat
162    f1t=$vdir/$nam/$mach/$dorv/$rep1/tracer.stat
163    f2o=$vdir/$nam/$mach/$dorv/$rep2/ocean.output
164    f2s=$vdir/$nam/$mach/$dorv/$rep2/run.stat
165    f2t=$vdir/$nam/$mach/$dorv/$rep2/tracer.stat
166
167    if  [ ! -f $f1s ] && [ ! -f $f1t ] ; then
168      printf "%-27s %s\n" $nam " incomplete test";
169      return;
170    fi
171    if  [ ! -f $f2s ] && [ ! -f $f2t ] ; then
172      printf "%-27s %s\n" $nam " incomplete test";
173      return;
174    fi
175#
176    done_oce=0
177
178    if  [ -f $f1s ] && [ -f $f2s ] ; then
179      cmp -s $f1s $f2s
180      if [ $? == 0 ]; then
181        if [ $pass == 0 ]; then
182          printf "%-27s %s %s\n" $nam  " run.stat    reproducibility passed : " $dorv
183        fi
184      else
185        get_ktdiff $f1s $f2s
186        printf "\e[38;5;196m%-27s %s %s %s %-5s %s\e[0m\n" $nam  " run.stat    reproducibility FAILED : " $dorv " (results are different after " $ktdiff " time steps)"
187#
188# Offer view of differences on the second pass
189#
190        if [ $pass == 1 ]; then
191          echo "<return> to view run.stat differences"
192          read y
193          sdiff $f1s $f2s
194          echo "<return> to view ocean.output differences"
195          read y
196          sdiff $f1o $f2o | grep "|"
197          done_oce=1
198          echo "<return> to continue"
199          read y
200        fi
201      fi
202    fi
203#
204# Check tracer.stat files (if they exist)
205#
206    if  [ -f $f1t ] && [ -f $f2t ] ; then
207      cmp -s $f1t $f2t
208      if [ $? == 0 ]; then
209        if [ $pass == 0 ]; then           printf "%-27s %s %s\n" $nam  " tracer.stat reproducibility passed : " $dorv
210        fi
211      else
212        get_ktdiff $f1t $f2t
213        printf "\e[38;5;196m%-27s %s %s %s %-5s %s\e[0m\n" $nam  " tracer.stat    reproducibility FAILED : " $dorv " (results are different after " $ktdiff " time steps)"
214#
215# Offer view of differences on the second pass
216#
217        if [ $pass == 1 ]; then
218          echo "<return> to view tracer.stat differences"
219          read y
220          sdiff $f1t $f2t
221#
222# Only offer ocean.output view if it has not been viewed previously
223#
224          if [ $done_oce == 0 ]; then
225            echo "<return> to view ocean.output differences"
226            read y
227            sdiff $f1o $f2o | grep "|"
228          fi
229          echo "<return> to continue"
230          read y
231        fi
232      fi
233    fi
234  fi
235}
236function runcmpres(){
237#
238# compare *.stat file with reference file from a previous sette test or previous version
239# store in NEMO_VALID_REF at revision NEMO_REV_REF
240# Compares end of stat files from each
241#
242  vdir=$1
243  nam=$2
244  vdirref=$3
245  dorvref=$4
246  pass=$5
247#
248# get $dorv
249  get_dorv
250#
251# check if reference directory is present
252  if [ ! -d $vdirref/$nam/$mach/$dorvref ]; then
253    printf "%-27s %s\n" $nam " REFERENCE directory at $dorvref is MISSING"
254    return
255  fi
256  if [ ! -d $vdir/$nam/$mach/$dorv ]; then
257    printf "%-27s %s\n" $nam " VALID     directory at $dorv is MISSING"
258    return
259  fi
260
261#
262  if [ -d $vdir/$nam/$mach/$dorv ]; then
263    f1s=$vdir/$nam/$mach/$dorv/LONG/run.stat
264    f1t=$vdir/$nam/$mach/$dorv/LONG/tracer.stat
265    f2s=$vdirref/$nam/$mach/$dorvref/LONG/run.stat
266    f2t=$vdirref/$nam/$mach/$dorvref/LONG/tracer.stat
267    if  [ ! -f $f1s ] && [ ! -f $f1t ] ; then
268      printf "%-20s %s\n" $nam " incomplete test";
269      return;
270    fi
271    if  [ ! -f $f2s ] && [ ! -f $f2t ] ; then
272      printf "%-20s %s\n" $nam " incomplete test";
273      return;
274    fi
275#
276    done_oce=0
277
278    if  [ -f $f1s ] && [ -f $f2s ] ; then
279      cmp -s $f1s $f2s
280      if [ $? == 0 ]; then
281        if [ $pass == 0 ]; then
282          printf "%-20s %s %s\n" $nam  " run.stat    files are identical "
283        fi
284      else
285        printf "%-20s %s %s\n" $nam  " run.stat    files are DIFFERENT "
286#
287# Offer view of differences on the second pass
288#
289        if [ $pass == 1 ]; then
290          echo "<return> to view run.stat differences"
291          read y
292          sdiff $f1s $f2s
293          done_oce=1
294          echo "<return> to continue"
295          read y
296        fi
297      fi
298    fi
299    # Check tracer.stat files (if they exist)
300#
301    if  [ -f $f1t ] && [ -f $f2t ] ; then
302      cmp -s $f1t $f2t
303      if [ $? == 0 ]; then
304        if [ $pass == 0 ]; then         
305          printf "%-20s %s %s\n" $nam  " tracer.stat files are identical "
306        fi
307      else
308        printf "%-20s %s %s\n" $nam  " tracer.stat files are DIFFERENT "
309#
310# Offer view of differences on the second pass
311#
312        if [ $pass == 1 ]; then
313          echo "<return> to view tracer.stat differences"
314          read y
315          sdiff $f1t $f2t
316        fi
317      fi
318    fi
319  fi
320}
321
322function runtest(){
323#
324# Run checks.
325# Check presence of E R R O R in ocean.output from each
326#
327  vdir=$1
328  nam=$2
329  pass=$3
330  ttype=$4
331  [[ $ttype == 'RST' ]] && ttype="LONG|SHORT"
332#
333# get $dorv
334  get_dorv
335#
336# no print needed if the repository is not here (already catch before)
337#
338  if [ -d $vdir/$nam/$mach/$dorv/ ]; then
339    #
340    # apply check for all ttype directory
341    rep1=$(ls -rt $vdir/$nam/$mach/$dorv/ | grep -E $ttype)
342    for tdir in $rep1 ; do
343       f1o=$vdir/$nam/$mach/$dorv/$tdir/ocean.output
344       if  [ ! -f $f1o ] ; then
345          if [ $pass == 0 ]; then printf "%-27s %s %s\n" $nam " ocean.output               MISSING : " $dorv ; fi
346          return;
347       else
348          nerr=`grep 'E R R O R' $f1o | wc -l`
349          if [[ $nerr > 0 ]]; then
350             printf "\e[38;5;196m%-27s %s %s %s\e[0m\n" $nam " run                         FAILED : " $dorv " ( E R R O R in ocean.output) " 
351             if [ $pass == 1 ]; then
352                echo "<return> to view end of ocean.output"
353                read y
354                tail -100 $f1o
355                echo ''
356                echo "full ocean.output available here: $f1o"
357             fi
358             return;
359          fi
360       fi
361    done
362  else
363    if [ $pass == 0 ]; then printf "%-27s %s %s\n" $nam  " directory                  MISSING : " $dorv ; fi
364  fi
365}
366
367function identictest(){
368#
369# Checks AGRIF does not corrupt results with no AGRIF zoom by comparing run.stat files
370#
371  vdir=$1
372  nam=$2
373  nam2=$3
374  pass=$4
375#
376  get_dorv
377#
378  rep=`ls -1rt $vdir/$nam/$mach/$dorv/ |  tail -1l`
379  f1s=${vdir}/${nam}/${mach}/${dorv}/${rep}/run.stat
380  f2s=${vdir}/${nam2}/${mach}/${dorv2}/${rep}/run.stat
381#
382  if  [ -f $f1s ] && [ -f $f2s ] ; then
383      cmp -s $f1s $f2s
384      if [ $? == 0 ]; then
385          if [ $pass == 0 ]; then
386         printf "%-5s %s %-5s %s %s %s\n" $rep "AGRIF vs" $rep "NOAGRIF run.stat    unchanged  -    passed : " $dorv $dorv2
387          fi
388      else
389          get_ktdiff $f1s $f2s
390          printf "\e[38;5;196m%-5s %s %-5s %s %s %s %s %-5s %s\e[0m\n" $rep "AGRIF vs" $rep "NOAGRIF run.stat    changed  -     FAILED : " $dorv $dorv2 " (results are different after " $ktdiff " time steps)"
391#
392# Offer view of differences on the second pass
393#
394          if [ $pass == 1 ]; then
395         echo "<return> to view run.stat differences"
396         read y
397         sdiff $f1s $f2s
398         echo "<return> to continue"
399         read y
400          fi
401      fi
402  else
403      printf "%-27s %-27s %s\n" $nam $nam2 " incomplete test"
404  fi
405}
406########################### END of function definitions #################################
407##                                                                                     ##
408##    Main script                                                                      ##
409##                                                                                     ##
410#########################################################################################
411#
412# LOAD param variable (COMPILER, NEMO_VALIDATION_DIR, SVN_CMD)
413  SETTE_DIR=$(cd $(dirname "$0"); pwd)
414  MAIN_DIR=$(dirname $SETTE_DIR)
415  . ./param.cfg
416
417  mach=${COMPILER}
418  NEMO_VALID=${NEMO_VALIDATION_DIR}
419  NEMO_VALID_REF=${NEMO_VALIDATION_REF}
420  LANG=en_US
421#
422  if [ ! -d $NEMO_VALID ]; then
423    echo "$NEMO_VALID validation directory not found"
424    exit
425  fi
426#
427# Directory to run the tests
428  CONFIG_DIR0=${MAIN_DIR}/cfgs
429  TOOLS_DIR=${MAIN_DIR}/tools
430  NPROC=32
431  SAS_RESTART_DIR=${CONFIG_DIR0}/ORCA2_SAS_ICE_ST
432#
433# Show current revision tag and branch name
434#
435echo ""
436lastchange=`LC_MESSAGES=${LANG} ${SVN_CMD} info ${MAIN_DIR} | grep 'Last Changed Rev' | awk '{print $NF}'`
437revision=`LC_MESSAGES=${LANG} ${SVN_CMD} info ${MAIN_DIR} | grep 'Revision' | awk '{print $NF}'`
438branchname=`LC_MESSAGES=${LANG} ${SVN_CMD} info ${MAIN_DIR} | grep ^URL | awk -F ipsl/forge/projets/nemo/svn/ '{print $NF}'`
439echo "Current code is : $branchname @ r$revision  ( last change @ r$lastchange )"
440# detect local modifications (one MEDUSA-specific exception)
441[ `${SVN_CMD} status -q ${MAIN_DIR}/{cfg,tests,src,src/TOP/MEDUSA,cfgs/SHARED_MEDUSA,cfgs/ORCA2_MEDUSA} | grep -v '~       ../tests/BENCH/EXPREF/namelist_top_cfg' | wc -l` -ge 1 ] && lastchange=${lastchange}+
442
443# overwrite revision is argument 1 present
444[[ $# -eq 1 ]] && lastchange=$1
445
446echo ""
447echo "SETTE validation report generated for : "
448echo ""
449echo "       $branchname @ r$lastchange (last changed revision)"
450echo ""
451echo "       on $COMPILER arch file"
452echo ""
453
454#
455# The script also needs the date or revision tag. Currently this is taken from the latest sub-directory found in each directory
456
457for pass in  0 1
458do
459#
460 if [ $pass == 0 ]; then
461   echo "" 
462   echo "!!---------------1st pass------------------!!"
463 fi
464 if [ $pass == 1 ]; then
465    echo ""
466    echo "!!---------------2nd pass------------------!!"
467 fi
468#
469
470# Restartability test
471 echo ""
472 echo "   !----restart----!   "
473 for restart_test in WGYRE_PISCES_ST WORCA2_ICE_PISCES_ST WORCA2_MEDUSA_ST WORCA2_OFF_PISCES_ST WAMM12_ST WORCA2_SAS_ICE_ST WAGRIF_DEMO_ST WSPITZ12_ST WISOMIP_ST WOVERFLOW_ST WLOCK_EXCHANGE_ST WVORTEX_ST WICE_AGRIF_ST
474 do
475   resttest $NEMO_VALID $restart_test $pass
476 done
477#
478# Reproducibility tests
479 echo ""
480 echo "   !----repro----!   "
481 for repro_test in WGYRE_PISCES_ST WORCA2_ICE_PISCES_ST WORCA2_MEDUSA_ST WORCA2_OFF_PISCES_ST WAMM12_ST WORCA2_SAS_ICE_ST WORCA2_ICE_OBS_ST WAGRIF_DEMO_ST WSPITZ12_ST WISOMIP_ST WVORTEX_ST WICE_AGRIF_ST
482 do
483   reprotest $NEMO_VALID $repro_test $pass
484 done
485
486# AGRIF special check to ensure results are unchanged with and without key_agrif
487 echo ""
488 echo "   !----agrif check----!   "
489 dir1=WAGRIF_DEMO_NOAGRIF_ST
490 dir2=WAGRIF_DEMO_ST
491 identictest $NEMO_VALID $dir1 $dir2 $pass 
492#
493# before/after tests
494 if [ $lastchange == 'old' ] ; then
495    echo ""
496    echo "   !---- 'old' specified as revision => no comparison with reference results ----!   "
497    echo ""
498 else
499   echo ""
500   echo "   !----result comparison check----!   "
501   if [ $NEMO_VALID_REF != "/path/to/reference/sette/results" ]; then
502     echo ''
503     echo 'check result differences between :'
504     echo "VALID directory : $NEMO_VALID at rev $lastchange"
505     echo 'and'
506     echo "REFERENCE directory : $NEMO_VALID_REF at rev $NEMO_REV_REF"
507     echo ''
508     for repro_test in WGYRE_PISCES_ST WORCA2_ICE_PISCES_ST WORCA2_MEDUSA_ST WORCA2_OFF_PISCES_ST WAMM12_ST WISOMIP_ST WORCA2_SAS_ICE_ST WAGRIF_DEMO_ST WSPITZ12_ST WISOMIP_ST WVORTEX_ST WICE_AGRIF_ST
509     do
510       runcmpres $NEMO_VALID $repro_test $NEMO_VALID_REF $NEMO_REV_REF $pass
511     done
512   else
513     echo ''
514     echo ' No path for comparison specified. Result are not compare with any other revision. '
515     echo ' To do it please fill NEMO_VALID_REF and NEMO_REV_REF in param.cfg. '
516     echo ''
517   fi
518 fi
519done
520#
521exit
Note: See TracBrowser for help on using the repository browser.