Back to home page

MITgcm

 
 

    


Warning, /verification/testreport is written in an unsupported language. File is not indexed.

view on githubraw file Latest commit 212a5505 on 2024-10-30 14:40:06 UTC
f610331bb1 Ed H*0001 #! /usr/bin/env bash
2ff82eb834 Ed H*0002 
                0003 usage()
                0004 {
                0005     echo
                0006     echo "Usage:  $0 [OPTIONS]"
                0007     echo
                0008     echo "where possible OPTIONS are:"
                0009     echo "  (-help|-h)               print usage"
ee57712ddb Jean*0010     echo " ---- type of test : ----"
b4daa24319 Shre*0011     echo "  (-tlm)                   perform a Tangent-Linear run (defaut: using TAF)"
                0012     echo "  (-adm|-ad)               perform an Adjoint run (default: using TAF)"
                0013     echo "  (-tap)                   use Tapenade for Adjoint or Tangent-Linear run"
ee57712ddb Jean*0014     echo "  (-oad)                   perform an OpenAD adjoint run"
9d0c386f0c dngo*0015     echo "  (-oadsingularity|-oadsngl) STRING"
                0016     echo "                           path to singularity container with OpenAD"
616bf911ff Jean*0017     echo "  (-mth)                   run multi-threaded (using eedata.mth)"
d9ae4e2b34 Jean*0018     echo "  (-mpi)                   use MPI to compile and run on 2 processors"
                0019     echo "  (-MPI)  NUMBER           use MPI to compile and run on max NUMBER procs"
bbea11a65d Jean*0020     echo "  (-mfile|-mf) STRING      MPI: file with list of possible machines to run on"
442de1f446 Jean*0021     echo "  (-command|-c) STRING     command to run (e.g., if non-standard MPI setting)"
                0022     echo "                            DEF='mitgcmuv' or ='mpirun -np TR_NPROC mitgcmuv'"
ee57712ddb Jean*0023     echo " ---- testing options : ----"
e355dad078 Jean*0024     echo "  (-optfile|-of) STRING    optfile to use"
5a67953813 Jean*0025     echo "  (-fast)                  use optfile default for compiler flags (no '-ieee')"
                0026     echo "                            DEF=off => use IEEE numerics option (if available)"
                0027     echo "  (-devel)                 use optfile developement flags (if available)"
232027f18d Jean*0028     echo "  (-gsl)                   compile with \"-gsl\" flag"
416e70d1a2 Jean*0029     echo "  (-use_r4|-ur4)           if allowed, use real*4 type for '_RS' variable"
                0030     echo "  (-tdir|-t) STRING        list of group and/or exp. dirs to test"
35aa6741f4 Jean*0031     echo "                             (recognized groups: basic, tutorials)"
                0032     echo "                             (DEF=\"\" which test all)"
ef1af8ad10 Jean*0033     echo "                             (if list= 'start_from THIS_EXP' then"
                0034     echo "                              test THIS_EXP + all the following)"
416e70d1a2 Jean*0035     echo "  (-skipdir|-skd) STRING   list of exp. dirs to skip"
6d0f07d5b0 Jean*0036     echo "                             (DEF=\"\" which test all)"
ee57712ddb Jean*0037     echo "  (-ts)                    provide timing information per timestep"
                0038     echo "  (-papis)                 provide MFlop/s per timestep using PAPI"
                0039     echo "  (-pcls)                  provide MFlop/s per timestep using PCL"
                0040     echo " ---- system options : ----"
                0041     echo "  (-bash|-b) STRING        preferred location of a \"bash\" or \"sh\" shell"
002054e5e5 Ed H*0042     echo "                             (DEF=\"\" for \"bash\")"
ee57712ddb Jean*0043     echo "  (-ef) STRING             used as genmake2 \"-extra_flag\" argument"
e977410d1b Mart*0044     echo "  (-ncad)                  use genmake2 option \"-nocat4ad\" (-ncad)"
                0045     echo "  (-small_f)               make target small_f before making target all"
ca2316a28b Jean*0046     echo "  (-makedepend|-md) STRING command to use for \"makedepend\""
416e70d1a2 Jean*0047     echo "  (-make|-m) STRING        command to use for \"make\""
fd381e7ade Ed H*0048     echo "                             (DEF=\"make\")"
ee57712ddb Jean*0049     echo "  (-j) JOBS                use \"make -j JOBS\" for parallel builds"
                0050     echo " ---- output options : ----"
aaf4336666 Jean*0051     echo "  (-match) NUMBER          Matching Criteria (number of digits)"
ca2316a28b Jean*0052     echo "                             (DEF=\"$MATCH_CRIT\")"
13cadcbe59 Oliv*0053     echo "  (-pass)                  return non-zero exit code if any exp do not pass"
ee57712ddb Jean*0054     echo "  (-odir) STRING           used to build output directory name"
                0055     echo "                             (DEF=\"hostname\")"
                0056     echo "  (-addr|-a) STRING        list of email recipients"
                0057     echo "                             (DEF=\"\" no email is sent)"
                0058     echo "  (-send)       STRING     sending command (instead of using mpack)"
                0059     echo "  (-savdir|-sd) STRING     location to save output tar file to send (DEF='$SAVDIR')"
                0060     echo "  (-mpackdir|-mpd) DIR     location of the mpack utility"
                0061     echo "                             (DEF=\"../tools/mpack-1.6\")"
                0062     echo " -- do only some parts: --"
bbea11a65d Jean*0063     echo "  (-clean)                 *ONLY* run \"make CLEAN\" & clean run-dir"
ca6d5f1072 Jean*0064     echo "  (-norun|-nr)             skip the \"runmodel\" stage (stop after make)"
1f09e8610e Jean*0065     echo "  (-obj)                   only produces objects (=norun & no executable)"
f6209765b3 Jean*0066     echo "  (-src)                   only produces small '*.f' src files (not even obj)"
                0067     echo "                            + with: '-adm/-tlm', also makes taf outp src code"
416e70d1a2 Jean*0068     echo "  (-runonly|-ro)           *ONLY* run stage (=\"-quick\" without make)"
a986ef8661 Cons*0069     echo "  (-quick|-q)              same as \"-nogenmake -noclean -nodepend\""
                0070     echo "  (-nogenmake|-ng)         skip the genmake stage"
                0071     echo "  (-noclean|-nc)           skip the \"make clean\" stage"
                0072     echo "  (-nodepend|-nd)          skip the \"make depend\" stage"
bbea11a65d Jean*0073     echo "  (-postclean|-pc)         after each exp. test, clean build-dir & run-dir"
                0074     echo "  (-deloutp|-do)           delete output files after successful run"
a986ef8661 Cons*0075     echo "  (-deldir|-dd)            on success, delete the output directory"
96d85cca71 Ed H*0076     echo
a18b9b1964 Ed H*0077     echo "and where STRING can be a whitespace-delimited list"
96d85cca71 Ed H*0078     echo "such as:"
a18b9b1964 Ed H*0079     echo
96d85cca71 Ed H*0080     echo "  -t 'exp0 exp2 exp3' "
                0081     echo "  -addr='abc@123.com testing@home.org'"
2ff82eb834 Ed H*0082     echo
a18b9b1964 Ed H*0083     echo "provided that the expression is properly quoted within the current"
                0084     echo "shell (note the use of single quotes to protect white space)."
                0085     echo
2ff82eb834 Ed H*0086     exit 1
                0087 }
                0088 
                0089 #  build the mpack utility
                0090 build_mpack()
                0091 {
e53112a6cf Ed H*0092     printf "building the mpack utility...  "
d6829a17bc Jean*0093     MPACK="$MPACKDIR/mpack"
                0094     if test ! -x $MPACK ; then
2ff82eb834 Ed H*0095         if test ! -d $MPACKDIR ; then
002054e5e5 Ed H*0096             echo
2ff82eb834 Ed H*0097             echo "Error: can't find \"$MPACKDIR\""
                0098             echo "  are you sure this program is being run in the correct "
                0099             echo "  (that is, \"MITGCM_ROOT\verification\") directory?"
002054e5e5 Ed H*0100             echo
                0101             HAVE_MPACK=f
2ff82eb834 Ed H*0102         fi
2e69e179c3 Ed H*0103         if test "x$CC" = x ; then
                0104             export CC=cc
                0105         fi
63e0800ef7 Jean*0106         printf "building mpack (using CC=$CC)...  "
54db3dc364 Ed H*0107         ( cd $MPACKDIR && ./configure && $MAKE ) > tr_build_mpack.out 2>&1
2ff82eb834 Ed H*0108         RETVAL=$?
                0109         if test "x$RETVAL" != x0 ; then
                0110             echo
                0111             echo "Error building the mpack tools at: $MPACK_DIR"
002054e5e5 Ed H*0112             echo
                0113             HAVE_MPACK=f
                0114         else
54db3dc364 Ed H*0115             rm -f tr_build_mpack.out
002054e5e5 Ed H*0116             HAVE_MPACK=t
d6829a17bc Jean*0117             echo "done"
2ff82eb834 Ed H*0118         fi
002054e5e5 Ed H*0119     else
                0120         HAVE_MPACK=t
d6829a17bc Jean*0121         echo "already exist"
2ff82eb834 Ed H*0122     fi
                0123 }
                0124 
3f7ac1ee60 Jean*0125 testoutput_var()
2ff82eb834 Ed H*0126 {
6d41b7da3e Jean*0127     # testoutput_var dir s1 label subdir reference_output
2ff82eb834 Ed H*0128     #
9750e41317 Jean*0129     #  compares 1 variable output selected from file $dir/$subdir/$OUTPUTFILE
6418c0ec62 Jean*0130     #     with same output from reference file $dir/$reference_output
3f7ac1ee60 Jean*0131     #  using search strings s1 and text label
2ff82eb834 Ed H*0132 
                0133     if [ $debug -gt 0 ]; then
d81415648f Jean*0134         echo testoutput_var: grep "'$2'" $1/$4/$OUTPUTFILE 1>&2
2ff82eb834 Ed H*0135     fi
84370bfea3 Jean*0136     if [ -r $1/$4/$OUTPUTFILE ]; then
deb0ad3aea Mart*0137         grep "$2" $1/$4/$OUTPUTFILE | sed 's/.*=//' | nl > ${TMP}a.txt
ee57712ddb Jean*0138         lncntA=`wc -l ${TMP}a.txt | awk '{print $1}' `
c5e604105c Jean*0139         if [ $lncntA -lt 2 ]; then
2ff82eb834 Ed H*0140             if [ $verbose -gt 0 ]; then
                0141                 echo Not enough lines of output when searching for "$2" 1>&2
                0142             fi
ee57712ddb Jean*0143             rm -f ${TMP}a.txt ; return 99
2ff82eb834 Ed H*0144         fi
                0145     else
3f7ac1ee60 Jean*0146         echo testoutput_var: $OUTPUTFILE from model run was not readable 1>&2
2ff82eb834 Ed H*0147         return 99
                0148     fi
                0149     if [ $debug -gt 0 ]; then
d81415648f Jean*0150         echo testoutput_var: grep "'$2'" $1/$5 1>&2
2ff82eb834 Ed H*0151     fi
deb0ad3aea Mart*0152     grep "$2" $1/$5 | sed 's/.*=//' | nl > ${TMP}b.txt
ee57712ddb Jean*0153     lncntB=`wc -l ${TMP}b.txt | awk '{print $1}' `
c5e604105c Jean*0154     if [ $lncntB -lt 2 ]; then
2ff82eb834 Ed H*0155         if [ $verbose -gt 0 ]; then
                0156             echo Not enough lines of output when searching for "$2" 1>&2
                0157         fi
ee57712ddb Jean*0158         rm -f ${TMP}a.txt ${TMP}b.txt ; return 99
2ff82eb834 Ed H*0159     fi
ce680526d4 Jean*0160     if [ $lncntA -ne $lncntB ]; then
6418c0ec62 Jean*0161         if [ $verbose -gt 0 ]; then
                0162             echo Not same Nb of lines when searching for "$2" ":" $lncntA $lncntB 1>&2
                0163         fi
ee57712ddb Jean*0164         rm -f ${TMP}a.txt ${TMP}b.txt ; return 99
ce680526d4 Jean*0165     fi
ee57712ddb Jean*0166     has_nan=`cat ${TMP}a.txt | grep -i nan | wc -l`
ef3ea31c23 Ed H*0167     if [ $has_nan -gt 0  ] ; then
3f7ac1ee60 Jean*0168         echo testoutput_var: $OUTPUTFILE contains $has_nan NaN values  1>&2
ee57712ddb Jean*0169         rm -f ${TMP}a.txt ${TMP}b.txt ; return 99
ef3ea31c23 Ed H*0170     fi
ee57712ddb Jean*0171     has_inf=`cat ${TMP}a.txt | grep -i inf | wc -l`
ef3ea31c23 Ed H*0172     if [ $has_inf -gt 0  ] ; then
3f7ac1ee60 Jean*0173         echo testoutput_var: $OUTPUTFILE contains $has_inf Inf values  1>&2
ee57712ddb Jean*0174         rm -f ${TMP}a.txt ${TMP}b.txt ; return 99
7bcfb3f76d Jean*0175     fi
2ff82eb834 Ed H*0176     if [ $debug -gt 0 ]; then
ee57712ddb Jean*0177         echo testoutput_var: join ${TMP}a.txt ${TMP}b.txt 1>&2
2ff82eb834 Ed H*0178     fi
ee57712ddb Jean*0179     # On the SGI O3K (*not* the O2K), "cat -n" inserts a ":" after the line number
                0180     join ${TMP}a.txt ${TMP}b.txt | awk '{print $1 " " $2 " " $3}' | sed -e 's|:||g' > ${TMP}c.txt
2ff82eb834 Ed H*0181     if [ $debug -gt 0 ]; then
3f7ac1ee60 Jean*0182         echo testoutput_var: compare_lines 1>&2
2ff82eb834 Ed H*0183     fi
cfc62862f0 Ed H*0184     if [ $verbose -gt 1 ]; then
ee57712ddb Jean*0185         cat ${TMP}c.txt 1>&2
cfc62862f0 Ed H*0186     fi
ee57712ddb Jean*0187     echo "-1" >> ${TMP}c.txt
                0188     digits_of_similarity=`./tr_cmpnum < ${TMP}c.txt`
2ff82eb834 Ed H*0189     if [ $digits_of_similarity -eq 99 ]; then
                0190         if [ $verbose -gt 0 ]; then
6d41b7da3e Jean*0191             echo testoutput_var: No comparison was available for \"$3\" 1>&2
2ff82eb834 Ed H*0192         fi
                0193         digits_of_similarity=99
                0194     else
                0195         if [ $verbose -gt 0 ]; then
6d41b7da3e Jean*0196             echo There were $digits_of_similarity decimal places of similarity for \"$3\" 1>&2
2ff82eb834 Ed H*0197         fi
                0198     fi
ee57712ddb Jean*0199     rm -f ${TMP}a.txt ${TMP}b.txt ${TMP}c.txt
9750e41317 Jean*0200 
2ff82eb834 Ed H*0201     return $digits_of_similarity
                0202 }
                0203 
3f7ac1ee60 Jean*0204 testoutput_run()
2ff82eb834 Ed H*0205 {
6d41b7da3e Jean*0206     # testoutput_run directory subdir reference_output
2ff82eb834 Ed H*0207     #
3f7ac1ee60 Jean*0208     #  test output from 1 run in "directory"
456c314cce Jean*0209 # --> same processing for adjoint & forward test
6418c0ec62 Jean*0210         # default list of output variables to be checked:
                0211         #  1rst : main variable used to decide if it pass or FAIL
                0212         #  others : number of matching digits to be printed in summary.txt
                0213         listChk=$DEF_CHECK_LIST
eb7e5e62ed Jean*0214         #  load experiment-specific list from file "tr_checklist" (if it exist)
6418c0ec62 Jean*0215         if test -r $1/$2/tr_checklist ; then listChk=`cat $1/$2/tr_checklist` ; fi
b4daa24319 Shre*0216         if test $KIND = 1 -o $KIND = 4 ; then kd='g_';
d81415648f Jean*0217           #  TLM use same input_ad/tr_checklist --> convert
c59dd234b1 Jean*0218           listChk=`echo $listChk | sed 's/^adm/tlm/' | sed 's/ adm/ tlm/g'`
                0219           if test -r $1/$2/tr_checklist.tlm ; then listChk=`cat $1/$2/tr_checklist.tlm` ; fi
b4daa24319 Shre*0220         elif test $KIND = 2 -o $KIND = 5 ; then kd='ad';
d81415648f Jean*0221           if test -r $1/$2/tr_checklist.adm ; then listChk=`cat $1/$2/tr_checklist.adm` ; fi
b4daa24319 Shre*0222         elif test $KIND = 6 ; then kd='ad';
d81415648f Jean*0223         else kd=''; fi
                0224         if [ $debug -gt 0 ]; then echo "testoutput_run: listChk='$listChk'" 1>&2 ; fi
6418c0ec62 Jean*0225         # remove 1rst var and expand the list: + => min max mean s.d
d81415648f Jean*0226         sVar=`echo $listChk | awk '{print $1}'`
6418c0ec62 Jean*0227         listVar=`echo $listChk | sed 's/ [a-zA-Z0-9]*+/&mn &mx &av &sd/g' \
                0228                                | sed 's/+//g' | sed "s/^$sVar//"`
                0229         # set ref.outp file-name and, if compressed, uncompress it into subdir
                0230         refoutp=results/$3
                0231         if test ! -r $1/results/$3 ; then
                0232           if test -r $1/results/${3}.gz ; then
                0233             tmpNam1=$3
                0234             tmpNam2=`echo $tmpNam1 | sed 's/\..*\././'`
                0235             if test "x$tmpNam1" = "x$tmpNam2" ; then
                0236                 tmpNam1=`echo $tmpNam2 | sed 's/\./.std./'`
                0237             fi
                0238             refoutp=$2/$tmpNam1
                0239             if [ $debug -gt 0 ]; then
                0240                 echo "testoutput_run: gunzip 'results/$3.gz' into '$refoutp'" 1>&2
                0241             fi
                0242             gzip -cd $1/results/${3}.gz > $1/$refoutp
                0243           else
                0244             echo "missing reference output file '$3' (.gz) in '$1/results/'"
                0245           fi
                0246         fi
                0247         # check for ptracer output in reference_output file :
                0248         if test $KIND = 0 ; then
                0249           ptr_mon="trcstat_ptracerXX_min trcstat_ptracerXX_max"
                0250           ptr_mon="$ptr_mon trcstat_ptracerXX_mean trcstat_ptracerXX_sd"
                0251           for ii in $PTRACERS_NUM ; do
bef69cc95f Jean*0252             ptrfound=0
                0253             for jj in $ptr_mon ; do
                0254                 name=`eval "echo $jj | sed -e 's|XX|0"$ii"|g'"`
6418c0ec62 Jean*0255                 tst=`grep $name $1/$refoutp | wc -l | awk '{print $1}'`
bef69cc95f Jean*0256                 if test ! "x$tst" = x0 ; then ptrfound=1 ; fi
                0257             done
                0258             if test $ptrfound = '1' ; then
                0259                 eval "HAVE_PTR0"$ii"=t"
                0260             else
                0261                 eval "HAVE_PTR0"$ii"=f"
                0262               # remove this ptr from the list of output variable to check
                0263               # echo "-- ptr test=" $tst "number of var=" `echo $listVar | awk '{print NF}'` 1>&2
                0264                 listVar=`echo "$listVar" | sed "s/ pt$ii..//g"`
                0265             fi
6418c0ec62 Jean*0266           # eval 'echo "HAVE_PTR0'$ii' = $HAVE_PTR0'$ii'"' 1>&2
                0267           done
                0268         fi
                0269         tst=`echo $sVar $listVar | awk '{ for(i=2;i<=NF;i++){if($i==$1)t+=1}; print t }'`
                0270         if test $tst != 1 ; then
                0271           if test $tst = 0 ; then echo "==> WARNING: selected var >$sVar< not found" 1>&2
                0272                  else echo "==> WARNING: found selected var >$sVar< $tst times" 1>&2 ; fi
                0273           echo "==> WARNING: in checked list:" $listVar 1>&2
                0274         #- put it back once:
                0275           listVar=" $sVar "`echo "$listVar " | sed "s/ $sVar / /g"`
                0276         fi
d81415648f Jean*0277         if [ $debug -gt 0 ]; then echo "testoutput_run: listVar='$listVar'" 1>&2 ; fi
d9ae4e2b34 Jean*0278         echo "listVar='$listVar'" >> $locDIR"/summary.txt"
6418c0ec62 Jean*0279         #---
                0280         allargs=""
                0281         for xx in $listVar
                0282         do
7ee8179b2a Jean*0283          #ii=`echo $xx | sed 's/^pt[0-9][0-9]*..$/XXX/'`        #- any ptr number
                0284           ii=`echo $xx | sed 's/^pt[1-9]..$/XXX/'`              #- 1 to 9 ptr number
                0285           if test $ii != 'XXX' ; then
                0286           #- all except ptracer stats:
                0287             case $xx in
eb7e5e62ed Jean*0288            'PS')  if [ $debug -gt 0 ]
                0289                   then echo testoutput_run: testoutput_var $1 cg2d_init_res 1>&2 ; fi
6418c0ec62 Jean*0290                   testoutput_var $1 "cg2d_init_res" "Press. Solver (cg2d)" $2 $refoutp ; yy=$?
eb7e5e62ed Jean*0291                   if [ $debug -gt 0 ] ; then echo testoutput_run: cg2dres=$yy 1>&2 ; fi ;;
d81415648f Jean*0292         'admCst') testoutput_var $1 "ADM  ref_cost_function" "ADM CostFct" $2 $refoutp ; yy=$? ;;
                0293         'admGrd') testoutput_var $1 "ADM  adjoint_gradient"  "ADM Ad Grad" $2 $refoutp ; yy=$? ;;
                0294         'admFwd') testoutput_var $1 "ADM  finite-diff_grad"  "ADM FD Grad" $2 $refoutp ; yy=$? ;;
6418c0ec62 Jean*0295         'tlmCst') testoutput_var $1 "TLM  ref_cost_function" "TLM CostFct" $2 $refoutp ; yy=$? ;;
                0296         'tlmGrd') testoutput_var $1 "TLM  tangent-lin_grad"  "TLM TL Grad" $2 $refoutp ; yy=$? ;;
d81415648f Jean*0297         'tlmFwd') testoutput_var $1 "TLM  finite-diff_grad"  "TLM FD Grad" $2 $refoutp ; yy=$? ;;
                0298            'Tmn') testoutput_var $1 "dynstat_${kd}theta_min"  "${kd}Theta minimum" $2 $refoutp ; yy=$? ;;
                0299            'Tmx') testoutput_var $1 "dynstat_${kd}theta_max"  "${kd}Theta maximum" $2 $refoutp ; yy=$? ;;
                0300            'Tav') testoutput_var $1 "dynstat_${kd}theta_mean" "${kd}Theta mean"    $2 $refoutp ; yy=$? ;;
                0301            'Tsd') testoutput_var $1 "dynstat_${kd}theta_sd"   "${kd}Theta Std.Dev" $2 $refoutp ; yy=$? ;;
                0302            'Smn') testoutput_var $1 "dynstat_${kd}salt_min"   "${kd}Salt minimum"  $2 $refoutp ; yy=$? ;;
                0303            'Smx') testoutput_var $1 "dynstat_${kd}salt_max"   "${kd}Salt maximum"  $2 $refoutp ; yy=$? ;;
                0304            'Sav') testoutput_var $1 "dynstat_${kd}salt_mean"  "${kd}Salt mean"     $2 $refoutp ; yy=$? ;;
                0305            'Ssd') testoutput_var $1 "dynstat_${kd}salt_sd"    "${kd}Salt Std.Dev"  $2 $refoutp ; yy=$? ;;
                0306            'Umn') testoutput_var $1 "dynstat_${kd}uvel_min"   "${kd}U minimum"     $2 $refoutp ; yy=$? ;;
                0307            'Umx') testoutput_var $1 "dynstat_${kd}uvel_max"   "${kd}U maximum"     $2 $refoutp ; yy=$? ;;
                0308            'Uav') testoutput_var $1 "dynstat_${kd}uvel_mean"  "${kd}U mean"        $2 $refoutp ; yy=$? ;;
                0309            'Usd') testoutput_var $1 "dynstat_${kd}uvel_sd"    "${kd}U Std.Dev"     $2 $refoutp ; yy=$? ;;
                0310            'Vmn') testoutput_var $1 "dynstat_${kd}vvel_min"   "${kd}V minimum"     $2 $refoutp ; yy=$? ;;
                0311            'Vmx') testoutput_var $1 "dynstat_${kd}vvel_max"   "${kd}V maximum"     $2 $refoutp ; yy=$? ;;
                0312            'Vav') testoutput_var $1 "dynstat_${kd}vvel_mean"  "${kd}V mean"        $2 $refoutp ; yy=$? ;;
                0313            'Vsd') testoutput_var $1 "dynstat_${kd}vvel_sd"    "${kd}V Std.Dev"     $2 $refoutp ; yy=$? ;;
                0314          'Etamn') testoutput_var $1 "dynstat_${kd}eta_min"    "${kd}Eta minimum"   $2 $refoutp ; yy=$? ;;
                0315          'Etamx') testoutput_var $1 "dynstat_${kd}eta_max"    "${kd}Eta maximum"   $2 $refoutp ; yy=$? ;;
                0316          'Etaav') testoutput_var $1 "dynstat_${kd}eta_mean"   "${kd}Eta mean"      $2 $refoutp ; yy=$? ;;
                0317          'Etasd') testoutput_var $1 "dynstat_${kd}eta_sd"     "${kd}Eta Std.Dev"   $2 $refoutp ; yy=$? ;;
                0318          'Qntmn') testoutput_var $1 "forcing_qnet_min"  "Qnet minimum"  $2 $refoutp ; yy=$? ;;
                0319          'Qntmx') testoutput_var $1 "forcing_qnet_max"  "Qnet maximum"  $2 $refoutp ; yy=$? ;;
                0320          'Qntav') testoutput_var $1 "forcing_qnet_mean" "Qnet mean"     $2 $refoutp ; yy=$? ;;
                0321          'Qntsd') testoutput_var $1 "forcing_qnet_sd"   "Qnet Std.Dev"  $2 $refoutp ; yy=$? ;;
                0322          'aSImn') testoutput_var $1 "seaice_${kd}area_min"  "SIce ${kd}Area min"   $2 $refoutp ; yy=$? ;;
                0323          'aSImx') testoutput_var $1 "seaice_${kd}area_max"  "SIce ${kd}Area max"   $2 $refoutp ; yy=$? ;;
                0324          'aSIav') testoutput_var $1 "seaice_${kd}area_mean" "SIce ${kd}Area mean"  $2 $refoutp ; yy=$? ;;
                0325          'aSIsd') testoutput_var $1 "seaice_${kd}area_sd"   "SIce ${kd}Area StDv"  $2 $refoutp ; yy=$? ;;
                0326          'hSImn') testoutput_var $1 "seaice_${kd}heff_min"  "SIce ${kd}Heff min"   $2 $refoutp ; yy=$? ;;
                0327          'hSImx') testoutput_var $1 "seaice_${kd}heff_max"  "SIce ${kd}Heff max"   $2 $refoutp ; yy=$? ;;
                0328          'hSIav') testoutput_var $1 "seaice_${kd}heff_mean" "SIce ${kd}Heff mean"  $2 $refoutp ; yy=$? ;;
                0329          'hSIsd') testoutput_var $1 "seaice_${kd}heff_sd"   "SIce ${kd}Heff StDv"  $2 $refoutp ; yy=$? ;;
                0330          'uSImn') testoutput_var $1 "seaice_${kd}uice_min"  "SIce ${kd}Uice min"   $2 $refoutp ; yy=$? ;;
                0331          'uSImx') testoutput_var $1 "seaice_${kd}uice_max"  "SIce ${kd}Uice max"   $2 $refoutp ; yy=$? ;;
                0332          'uSIav') testoutput_var $1 "seaice_${kd}uice_mean" "SIce ${kd}Uice mean"  $2 $refoutp ; yy=$? ;;
                0333          'uSIsd') testoutput_var $1 "seaice_${kd}uice_sd"   "SIce ${kd}Uice StDv"  $2 $refoutp ; yy=$? ;;
                0334          'vSImn') testoutput_var $1 "seaice_${kd}vice_min"  "SIce ${kd}Vice min"   $2 $refoutp ; yy=$? ;;
                0335          'vSImx') testoutput_var $1 "seaice_${kd}vice_max"  "SIce ${kd}Vice max"   $2 $refoutp ; yy=$? ;;
                0336          'vSIav') testoutput_var $1 "seaice_${kd}vice_mean" "SIce ${kd}Vice mean"  $2 $refoutp ; yy=$? ;;
                0337          'vSIsd') testoutput_var $1 "seaice_${kd}vice_sd"   "SIce ${kd}Vice StDv"  $2 $refoutp ; yy=$? ;;
6418c0ec62 Jean*0338         'AthSiG') testoutput_var $1 "thSI_Ice_Area_G" "thSIc Area Global" $2 $refoutp ; yy=$? ;;
                0339         'AthSiS') testoutput_var $1 "thSI_Ice_Area_S" "thSIc Area South"  $2 $refoutp ; yy=$? ;;
                0340         'AthSiN') testoutput_var $1 "thSI_Ice_Area_N" "thSIc Area North"  $2 $refoutp ; yy=$? ;;
0f2059bcae Jean*0341         'HthSiG') testoutput_var $1 "thSI_IceH_ave_G" "thSIc H Glob-ave"  $2 $refoutp ; yy=$? ;;
                0342         'HthSiS') testoutput_var $1 "thSI_IceH_ave_S" "thSIc H South-av"  $2 $refoutp ; yy=$? ;;
                0343         'HthSiN') testoutput_var $1 "thSI_IceH_ave_N" "thSIc H North-av"  $2 $refoutp ; yy=$? ;;
                0344         'HthMxS') testoutput_var $1 "thSI_IceH_max_S" "thSIc H South-max" $2 $refoutp ; yy=$? ;;
                0345         'HthMxN') testoutput_var $1 "thSI_IceH_max_N" "thSIc H North-max" $2 $refoutp ; yy=$? ;;
ab6a12ddc5 Jean*0346          'sbo_M') testoutput_var $1 "sbo_mass"          "SBO mass"        $2 $refoutp ; yy=$? ;;
                0347          'sboFW') testoutput_var $1 "sbo_mass_fw"       "SBO m-FW"        $2 $refoutp ; yy=$? ;;
                0348          'sboAc') testoutput_var $1 "sbo_zoamc"         "SBO AM-C"        $2 $refoutp ; yy=$? ;;
                0349          'sboAp') testoutput_var $1 "sbo_zoamp"         "SBO AM-P"        $2 $refoutp ; yy=$? ;;
bce14c7299 Jean*0350         'StrmIc') testoutput_var $1 "STREAMICE_FP_ERR" "StreamIce Solver" $2 $refoutp ; yy=$? ;;
6418c0ec62 Jean*0351               *) yy=99; echo "WARNING: asking for var=$xx : not recognized !" 1>&2 ;;
7ee8179b2a Jean*0352             esac
                0353           else
                0354           #- ptracers stats:
                0355             nn=`echo $xx | sed 's/pt//' | sed 's/..$//'`
                0356             ii=`echo $xx | sed 's/^pt[0-9]*//'`
                0357             case $ii in
d81415648f Jean*0358             'mn') testoutput_var $1 "trcstat_${kd}ptracer0"$nn"_min"  "${kd}pTr0"$nn"_min"  $2 $refoutp ; yy=$? ;;
                0359             'mx') testoutput_var $1 "trcstat_${kd}ptracer0"$nn"_max"  "${kd}pTr0"$nn"_max"  $2 $refoutp ; yy=$? ;;
                0360             'av') testoutput_var $1 "trcstat_${kd}ptracer0"$nn"_mean" "${kd}pTr0"$nn"_mean" $2 $refoutp ; yy=$? ;;
                0361             'sd') testoutput_var $1 "trcstat_${kd}ptracer0"$nn"_sd"   "${kd}pTr0"$nn"_StDv" $2 $refoutp ; yy=$? ;;
7ee8179b2a Jean*0362             esac
                0363           fi
6418c0ec62 Jean*0364           if test $xx = $sVar
                0365           then allargs="$allargs > $yy <"
                0366           else allargs="$allargs $yy"
                0367           fi
                0368         done
eb7e5e62ed Jean*0369 
                0370         nbVar=`echo $listVar | awk '{print NF}'`
6418c0ec62 Jean*0371         if [ $nbVar -lt $LEN_CHECK_LIST ] ; then
                0372         #-- fill line (up to standard length) with dot:
                0373           adNul=`expr $LEN_CHECK_LIST - $nbVar | awk '{for(i=1;i<=$1;i++){print "."}}'`
eb7e5e62ed Jean*0374           echo $allargs $adNul
6418c0ec62 Jean*0375         else
eb7e5e62ed Jean*0376           echo $allargs
9750e41317 Jean*0377         fi
456c314cce Jean*0378 # <-- same processing for adjoint & forward test
2ff82eb834 Ed H*0379 }
                0380 
                0381 genmakemodel()
                0382 {
                0383     # genmakemodel directory
6d54cf9ca1 Ed H*0384     if test "x$NOGENMAKE" = xt ; then
                0385         echo "genmake skipped!"
                0386     else
e53112a6cf Ed H*0387         if test "x$BASH" = x ; then
                0388             GENMAKE2="../../../tools/genmake2"
                0389         else
                0390             GENMAKE2="$BASH ../../../tools/genmake2 -bash $BASH"
                0391         fi
6d54cf9ca1 Ed H*0392         (
                0393             cd $1;
4619920a5f Ed H*0394             command="$GENMAKE2  -ds -m $MAKE"
ca2316a28b Jean*0395             if test "x$MKDEPEND" != x ; then
                0396                 command="$command -makedepend=$MKDEPEND"
                0397             fi
b4daa24319 Shre*0398             if test $KIND = 6 ; then
b63206be5d Jean*0399                 command="$command -oad -mods=../$code_dir"
b4daa24319 Shre*0400             elif [ $KIND -ge 3 ] ; then
                0401                 command="$command -tap -mods=../$code_dir"
3907106aba Jean*0402             else
b63206be5d Jean*0403                 command="$command -mods=../$code_dir"
4619920a5f Ed H*0404             fi
6d54cf9ca1 Ed H*0405             if test "x$OPTFILE" != xNONE ; then
a7c0a887cd Jean*0406                 command="$command -optfile=$OPTFILE"
2ff82eb834 Ed H*0407             fi
5a67953813 Jean*0408             if test $OptLev = 1 ; then
6418c0ec62 Jean*0409                 command="$command -ieee"
                0410             fi
5a67953813 Jean*0411             if test $OptLev = 0 ; then
                0412                 command="$command -devel"
6d54cf9ca1 Ed H*0413             fi
232027f18d Jean*0414             if test "x$GSL" = xt ; then
                0415                 command="$command -gsl"
                0416             fi
d9ae4e2b34 Jean*0417             if test "x$MPI" != x0 ; then
152b247de4 Ed H*0418                 command="$command -mpi"
                0419             fi
616bf911ff Jean*0420             if test "x$MULTI_THREAD" = xt ; then
                0421             #- run multi-threaded using OpenMP:
                0422                 command="$command -omp"
                0423             fi
9750e41317 Jean*0424             if test "x$USE_R4" = xt ; then
                0425                 command="$command -use_r4"
                0426             fi
1f09e8610e Jean*0427             if test "x$EXTRFLG" != x ; then
                0428                 command="$command -extra_flag $EXTRFLG"
                0429             fi
72af1157c6 Jean*0430             if test "x$NOCATAD" = xt ; then
                0431                 command="$command -nocat4ad"
                0432             fi
a986ef8661 Cons*0433             if test "x$TS" = xt ; then
                0434                 command="$command -ts"
                0435             fi
                0436             if test "x$PAPIS" = xt ; then
                0437                 command="$command -papis"
9750e41317 Jean*0438             else
a986ef8661 Cons*0439             if test "x$PCLS" = xt ; then
                0440                 command="$command -pcls"
                0441             fi
9d0c386f0c dngo*0442             if test "x$OADSINGULARITY" != x ; then
                0443                 command="$command -oadsingularity \"$OADSINGULARITY\""
                0444             fi
a986ef8661 Cons*0445             fi
6fcdccb64d Jean*0446             printf 'genmake ... '
0093035fc0 Jean*0447             eval $command > genmake.tr_log 2>&1
6d54cf9ca1 Ed H*0448             RETVAL=$?
59e7e2f70f Ed H*0449             #  Reduce the size of the testing emails!
33ebd8ef34 Ed H*0450             head -100 Makefile > $CDIR/Makefile_head
6d54cf9ca1 Ed H*0451             if test "x$RETVAL" != x0 ; then
0093035fc0 Jean*0452                 tail genmake.tr_log
6fcdccb64d Jean*0453                 echo "genmakemodel: genmake failed"
4cc2b2ecef Jean*0454                 cp genmake.log genmake_* genmake.tr_log $CDIR
6d54cf9ca1 Ed H*0455                 return 1
                0456             else
6fcdccb64d Jean*0457                 echo "successful"
6d54cf9ca1 Ed H*0458             fi
                0459         )
                0460     fi
2ff82eb834 Ed H*0461 }
                0462 
                0463 makeclean()
                0464 {
                0465     # makeclean directory
d5ed8695dd Jean*0466     if test "x$NOGENMAKE" = xf ; then rm -f $1/make.tr_log ; fi
6d54cf9ca1 Ed H*0467     if test "x$NOCLEAN" = xt ; then
0e6cc40375 Jean*0468         echo "make Clean skipped!"
6d54cf9ca1 Ed H*0469     else
                0470         (
                0471             cd $1;
84370bfea3 Jean*0472             #if test -e $OUTPUTFILE ; then rm -f $OUTPUTFILE ; fi
6d54cf9ca1 Ed H*0473             if test -r Makefile ; then
6fcdccb64d Jean*0474                 printf 'clean build-dir: make Clean ... '
0093035fc0 Jean*0475                 $MAKE Clean >> make.tr_log 2>&1
6d54cf9ca1 Ed H*0476                 RETVAL=$?
                0477                 if test "x$RETVAL" != x0 ; then
0093035fc0 Jean*0478                     tail make.tr_log
6fcdccb64d Jean*0479                     echo "makeclean: \"make Clean\" failed"
4cc2b2ecef Jean*0480                     cp make.tr_log genmake.log genmake.tr_log $CDIR
6d54cf9ca1 Ed H*0481                     return 1
                0482                 fi
6fcdccb64d Jean*0483                 echo successful
642fbd44e7 Jean*0484             else
                0485                 echo ''
6d54cf9ca1 Ed H*0486             fi
                0487             exit 0
                0488         )
                0489     fi
2ff82eb834 Ed H*0490 }
                0491 
0e6cc40375 Jean*0492 run_clean()
0b035b108c Ed H*0493 {
0e6cc40375 Jean*0494     # run_clean directory
                0495     if test "x$NOCLEAN" = xt ; then
                0496         echo "run_clean skipped!"
                0497     else
e6f2a663b8 Jean*0498       (
                0499         cd $1;
                0500         printf 'clean run-dir ... '
                0501         # part of what is done after "make clean" when doing "make CLEAN"
                0502         find . -name "*.meta" -exec rm {} \;
                0503         find . -name "*.data" -exec rm {} \;
deacece587 Oliv*0504         find . -name "*.tmp"  -exec rm {} \;
e6f2a663b8 Jean*0505         find . -name "fort.*" -exec rm {} \;
                0506         find . -type l -exec rm {} \;
                0507         #- should remove executable only if sym-link (already done above)
                0508         rm -f $RUNLOG *.txt STDOUT.* STDERR.* *diagnostics.log *.[0-9][0-9][0-9][0-9].log
                0509         rm -f datetime costfinal divided.ctrl snapshot* output_adm.*.diva_*
                0510         rm -f *_MIT_CE_000.opt0000 costfunction*0000
5542b50cd2 Jean*0511         rm -f oad_cp.[0-9][0-9][0-9].?????
e6f2a663b8 Jean*0512         rm -rf mnc_test_*
                0513         echo successful
                0514         exit 0
                0515       )
0b035b108c Ed H*0516     fi
                0517 }
                0518 
2ff82eb834 Ed H*0519 makedependmodel()
                0520 {
                0521     # makedependmodel directory
6d54cf9ca1 Ed H*0522     if test "x$NODEPEND" = xt ; then
                0523         echo "make depend skipped!"
                0524     else
                0525         (
                0526             cd $1;
6fcdccb64d Jean*0527             printf 'make depend ... '
0093035fc0 Jean*0528             $MAKE depend >> make.tr_log 2>&1
6d54cf9ca1 Ed H*0529             RETVAL=$?
                0530             if test "x$RETVAL" != x0 ; then
0093035fc0 Jean*0531                 tail make.tr_log
6fcdccb64d Jean*0532                 echo "makedependmodel: make depend failed"
4cc2b2ecef Jean*0533                 cp make.tr_log genmake.log genmake.tr_log $CDIR
6d54cf9ca1 Ed H*0534                 return 1
                0535             else
6fcdccb64d Jean*0536                 echo successful
6d54cf9ca1 Ed H*0537             fi
                0538         )
                0539     fi
2ff82eb834 Ed H*0540 }
                0541 
                0542 makemodel()
                0543 {
                0544     # makemodel directory
                0545     (
f459d64861 Jean*0546     mk_fail=0
416e70d1a2 Jean*0547     if test "x$NOMAKE" = xt ; then
                0548         cd $1;
                0549         if test -x $EXECUTABLE ; then
                0550             echo "make skipped!"
                0551         else
                0552             echo "no executable!"
f459d64861 Jean*0553             mk_fail=3
416e70d1a2 Jean*0554         fi
                0555     else
2ff82eb834 Ed H*0556         cd $1;
                0557         if test -r Makefile ; then
e977410d1b Mart*0558             if test "x$MKSMALLF" = xt ; then
                0559                 printf 'make small_f ... '
                0560                 $MAKE_CMD small_f >> make.tr_log 2>&1
                0561                 RETVAL=$?
                0562                 if test "x$RETVAL" != x0 ; then
                0563                     tail make.tr_log
                0564                     echo failed
                0565                     cp genmake.log genmake.tr_log $CDIR
                0566                     tail -$NBLINES_MKLOG make.tr_log > $CDIR"/make.tr_log_tail"
                0567                     rm -f $EXECUTABLE
                0568                     mk_fail=1
                0569                 else
                0570                     echo successful
                0571                 fi
                0572             fi
cc019522d9 Jean*0573             printf "make $TARG ... "
72af1157c6 Jean*0574             $MAKE_CMD $TARG >> make.tr_log 2>&1
2ff82eb834 Ed H*0575             RETVAL=$?
                0576             if test "x$RETVAL" != x0 ; then
0093035fc0 Jean*0577                 tail make.tr_log
6fcdccb64d Jean*0578                 echo failed
da8170bd49 Jean*0579                 cp genmake.log genmake.tr_log $CDIR
                0580                 tail -$NBLINES_MKLOG make.tr_log > $CDIR"/make.tr_log_tail"
e49dac07a6 Jean*0581                 rm -f $EXECUTABLE
f459d64861 Jean*0582                 mk_fail=1
2ff82eb834 Ed H*0583             else
6fcdccb64d Jean*0584                 echo successful
2ff82eb834 Ed H*0585             fi
f459d64861 Jean*0586         else
                0587             echo "no Makefile !"
                0588             mk_fail=2
2ff82eb834 Ed H*0589         fi
416e70d1a2 Jean*0590     fi
1fff053a17 Jean*0591     if test $KIND = 1 -a -f taf_ftl.log ; then
3513440a2a Jean*0592         grep 'Processing files at' make.tr_log | tail -1 >> $CDIR"/summary.txt"
f561fdaba7 Jean*0593         head -1 taf_ftl.log >> $CDIR"/summary.txt"
1fff053a17 Jean*0594     fi
6418c0ec62 Jean*0595     if test $KIND = 2 -a -f taf_ad.log ; then
3513440a2a Jean*0596         grep 'Processing files at' make.tr_log | tail -1 >> $CDIR"/summary.txt"
f561fdaba7 Jean*0597         head -1 taf_ad.log >> $CDIR"/summary.txt"
                0598         nerr=`grep -c 'TAF *.* ERROR ' taf_ad.log`
9243e50d1e Jean*0599         nwar=`grep -c '^TAF *.* RECOMPUTATION *.* WARNING ' taf_ad.log`
f561fdaba7 Jean*0600         if test -f taf_output ; then
                0601             n2er=`grep -c 'TAF *.* ERROR ' taf_output`
d758744a4f Jean*0602             n3er=`grep -c '\*ERROR\* ' taf_output`
                0603             nerr=`expr $nerr + $n2er + $n3er`
f561fdaba7 Jean*0604         fi
                0605         echo " TAF reports $nerr Errors and $nwar Recomputation Warnings" \
360fa2f691 Jean*0606                                 >> $CDIR"/summary.txt"
49a029e3de Mart*0607         if test -f ad_taf_output.f ; then
                0608             adfile=ad_taf_output.f
                0609         elif test -f ad_taf_output.for ; then
                0610             adfile=ad_taf_output.for
                0611         else
                0612             echo "WARNING: neither ad_output_ad.f nor ad_output_ad.for found" \
                0613                                 >> $CDIR"/summary.txt"
d37c4896c1 Mart*0614             adfile=missing ; nlfd=0 ; ndop=0 ; nsm=0
49a029e3de Mart*0615         fi
                0616         if test $adfile != missing ; then
                0617             # count number of times load_fields_driver and do_oceanic_phys are called
                0618             nlfd=`grep "call load_fields_driver(" ${adfile} | wc -l`
                0619             nlfdmd=`grep "call load_fields_drivermd(" ${adfile} | wc -l`
                0620             if (( $nlfdmd == 0 )) ; then
                0621                 # if there is no load_fields_driver, we can substract one assuming
                0622                 # that load_fields_driver is called once from forward_stepmd
                0623                 nlfd=$((nlfd-1))
                0624             fi
                0625             ndop=`grep "call do_oceanic_phys("    ${adfile} | wc -l`
d37c4896c1 Mart*0626             nsm=`grep "call seaice_model(" ${adfile} | wc -l`
49a029e3de Mart*0627         fi
d37c4896c1 Mart*0628         echo " load_fields_driver, do_oceanic_phys, seaice_model are called " \
                0629              "( $nlfd , $ndop , $nsm ) time(s)" >> $CDIR"/summary.txt"
360fa2f691 Jean*0630     fi
b4daa24319 Shre*0631     if test -f make.tr_log && test $KIND = 4 -o $KIND = 5 ; then
                0632         grep '^Tapenade ' make.tr_log | tail -n 1 >> $CDIR"/summary.txt"
                0633     fi
f459d64861 Jean*0634     if test $mk_fail != 0 ; then return $mk_fail ; fi
2ff82eb834 Ed H*0635     )
                0636 }
                0637 
d9ae4e2b34 Jean*0638 mk_mpi_size()
                0639 {
6c95586363 Jean*0640     # mk_mpi_size input_file output_file proc_Nb threads_Nb_X threads_Nb_Y
d9ae4e2b34 Jean*0641     #
6c95586363 Jean*0642     #  make new SIZE.h (=output_file) from SIZE.h_mpi (=input_file)
d9ae4e2b34 Jean*0643     #     for an MPI build with no more than proc_Nb processors ;
6c95586363 Jean*0644     #  ensure that enough tiles per proc (nSx,nSy) remain for the given
                0645     #     number of threads (nTx,nTy) ;
                0646     #  return the effective number of processors.
d9ae4e2b34 Jean*0647 
                0648     inp=$1
                0649     out=$2
                0650     np=$3
6c95586363 Jean*0651     tx=$4
                0652     ty=$5
d9ae4e2b34 Jean*0653     tmp=TTT.$$
                0654 
6c95586363 Jean*0655     # dirX : select with direction to favor in MPI process repartition
                0656     #   dirX=1 : prefer to put more proc in X direction
                0657     #   dirX=0 : prefer to put more proc in Y direction
                0658     dirX=0
                0659 
d9ae4e2b34 Jean*0660     px=`grep "^     & *nPx *=" $inp | sed "s/^     & *nPx *= *//" | sed 's/, *$//'`
                0661     py=`grep "^     & *nPy *=" $inp | sed "s/^     & *nPy *= *//" | sed 's/, *$//'`
                0662     sx=`grep "^     & *nSx *=" $inp | sed "s/^     & *nSx *= *//" | sed 's/, *$//'`
                0663     sy=`grep "^     & *nSy *=" $inp | sed "s/^     & *nSy *= *//" | sed 's/, *$//'`
                0664 
6c95586363 Jean*0665     #- for each direction, assume # of threads is a multiple of total number of tiles
                0666     nx=$px
                0667     if [ `expr $sx % $tx` -ne 0 -a `expr $sx \* $px % $tx` -eq 0 ] ; then
                0668         nx=`expr $sx \* $px / $tx`
                0669         if [ $verbose -gt 1 ]; then
                0670             echo " change px from $px to $nx to accommodate $tx threads"
                0671         fi
                0672     fi
                0673     ny=$py
                0674     if [ `expr $sy % $ty` -ne 0 -a `expr $sy \* $py % $ty` -eq 0 ] ; then
                0675         ny=`expr $sy \* $py / $ty`
                0676         if [ $verbose -gt 1 ]; then
                0677             echo " change py from $py to $ny to accommodate $ty threads"
                0678         fi
                0679     fi
d9ae4e2b34 Jean*0680     #- find the largest divisor of input_file proc Nb, but not larger than $np
                0681     pp=0
2f7af142fa Jean*0682     i=1
6c95586363 Jean*0683     while [ $i -le $nx ] ; do
                0684       if [ `expr $nx % $i` -eq 0 ] ; then
2f7af142fa Jean*0685         j=1
6c95586363 Jean*0686         while [ $j -le $ny ] ; do
                0687           if [ `expr $ny % $j` -eq 0 ] ; then
2f7af142fa Jean*0688             ij=`expr $i \* $j`
                0689             if [ $ij -gt $pp ] ; then
7ba778f1ca Jean*0690                 flag=1
                0691             elif [ $ij -eq $pp ] ; then
                0692                 flag=$dirX
                0693             else
                0694                 flag=0
                0695             fi
                0696             if test $flag = 1 ; then
2f7af142fa Jean*0697               if [ $ij -le $np ] ; then
                0698                 ix=$i ; jy=$j ; pp=$ij
                0699                 #echo "  ix,jy= $ix,$jy"
                0700               fi
                0701             fi
                0702           fi
                0703           j=`expr $j + 1`
                0704         done
d9ae4e2b34 Jean*0705       fi
2f7af142fa Jean*0706       i=`expr $i + 1`
d9ae4e2b34 Jean*0707     done
                0708 
                0709     #- create new SIZE.h type file:
                0710     sx=`expr $sx \* $px / $ix`
                0711     sy=`expr $sy \* $py / $jy`
                0712     if [ $verbose -gt 1 ]; then
                0713         echo " px,py,np= $px,$py,$np : New MPI size: px,py= $ix,$jy : sx,sy= $sx,$sy"
                0714     fi
                0715     sed "/^     \& *nPx *=/s/[0-9]*,/$ix,/" $inp > $tmp
                0716     sed "/^     \& *nPy *=/s/[0-9]*,/$jy,/" $tmp > $out
                0717     sed "/^     \& *nSx *=/s/[0-9]*,/$sx,/" $out > $tmp
                0718     sed "/^     \& *nSy *=/s/[0-9]*,/$sy,/" $tmp > $out
                0719     rm -f $tmp
                0720     return $pp
                0721 }
                0722 
e61115937c Ed H*0723 symlink_mpifiles()
                0724 {
                0725     # Put special links so that MPI specific files are used
                0726     # This MUST be invoked between makeclean and makelinks because
                0727     # the Makefile will link to non-mpi files by default
                0728 
                0729     dir=$1
                0730     code_dir=$2
d9ae4e2b34 Jean*0731     build_dir=$dir/$3
9750e41317 Jean*0732 
e61115937c Ed H*0733     # These are files that should replace their counter-part when using -mpi
d9ae4e2b34 Jean*0734     MPI_FILES=`(cd $dir/$code_dir; find . -name "*_mpi" -print)`
                0735 
                0736     for ii in $MPI_FILES ; do
                0737         i=`echo $ii | sed 's:^\./::'`
                0738         name=`echo $i | sed 's:_mpi::'`
                0739         file="../$code_dir/$i"
                0740         if test $name = 'SIZE.h' ; then file="SIZE.h.mpi" ; fi
                0741 
                0742         #  Is this an MPI run?
                0743         if test "x$MPI" = x0 ; then
                0744             # NO: We undo any _mpi symbolically linked files
                0745             if test -L $build_dir/$name ; then
                0746                 ( cd $build_dir ; cmp $name $file > /dev/null 2>&1 )
3007f9fbc4 Ed H*0747                 RETVAL=$?
                0748                 if test "x$RETVAL" = x0 ; then
d9ae4e2b34 Jean*0749                     if [ $verbose -gt 1 ]; then
                0750                         echo "  Un-linking $name from ../$code_dir" ; fi
                0751                     rm -f $build_dir/$name
e61115937c Ed H*0752                 fi
                0753             fi
d9ae4e2b34 Jean*0754         else
                0755             # YES: We symbolically link these files to the build
                0756             # dir so long as there is no real file in place
                0757             ( cd $build_dir ; cmp $name $file > /dev/null 2>&1 )
                0758             RETVAL=$?
                0759             if [ $verbose -gt 1 ]; then echo "  cmp $name $file returns: $RETVAL" ; fi
                0760             if test "x$RETVAL" != x0 ; then
                0761                 if test -h $build_dir/$name ; then rm -f $build_dir/$name ; fi
                0762                 if test ! -r $build_dir/$name ; then
                0763                     if [ $verbose -gt 1 ]; then echo "  Linking $name to $file" ; fi
                0764                     (cd $build_dir; ln -sf $file $name)
                0765                 fi
                0766             fi
                0767         fi
                0768     done
e61115937c Ed H*0769 }
                0770 
2ff82eb834 Ed H*0771 linkdata()
                0772 {
0e6cc40375 Jean*0773     # linkdata run_dir input_dir_1 input_dir_2 ...
2ff82eb834 Ed H*0774     #
                0775     # symbolically link data files to run directory
0e6cc40375 Jean*0776     if test -d $1 ; then
474019363f Ed H*0777         (
0e6cc40375 Jean*0778             cd $1 ; shift
6fcdccb64d Jean*0779             echo 'linkdata from dirs:' $*
6418c0ec62 Jean*0780             inpMPI=`(cd ../$1 ; find . -name "*.mpi" -print | sed 's:^\./::')`
8bd4a294c2 Jean*0781             for xx in $inpMPI ; do
                0782               if test -r "../"$1"/"$xx ; then
6418c0ec62 Jean*0783                 # found 1 _mpi sfx file in 1rst input dir and it is readable
8bd4a294c2 Jean*0784                 yy=`echo $xx | sed 's:\.mpi$::'`
d9ae4e2b34 Jean*0785                 if test "x$MPI" = "x0" ; then
                0786                     # not mpi test: remove symbolic link
                0787                     if test -h $yy ; then rm -f $yy ; fi
                0788                 else
                0789                     # mpi test: remove symbolic link & link .mpi sfx file
8bd4a294c2 Jean*0790                     if test -h $yy ; then rm -f $yy ; fi
9750e41317 Jean*0791                     if test ! -r $yy ; then
8bd4a294c2 Jean*0792                         ln -sf "../"$1"/"$xx $yy ;
6fcdccb64d Jean*0793                         printf " $xx" 1>&2
8bd4a294c2 Jean*0794                     fi
                0795                 fi
                0796               fi
                0797             done
0e6cc40375 Jean*0798             if test -r "../"$1"/eedata.mth" ; then
                0799             # found eedata.mth in 1rst input dir and it is readable
                0800                 if test "x$MULTI_THREAD" = "xt" ; then
                0801                 # multi-threaded test: remove symbolic link & link eedata.mth
                0802                     if test -h eedata ; then rm -f eedata ; fi
9750e41317 Jean*0803                     if test ! -r eedata ; then
0e6cc40375 Jean*0804                         ln -sf "../"$1"/eedata.mth" eedata ;
6fcdccb64d Jean*0805                         printf ' eedata.mth' 1>&2
4619920a5f Ed H*0806                     fi
0e6cc40375 Jean*0807                 else
                0808                 # not multi-threaded test: remove eedata symbolic link
                0809                     if test -h eedata ; then rm -f eedata ; fi
23874084ad Jean*0810                 fi
4619920a5f Ed H*0811             fi
878c588496 Jean*0812             prevDir='NONE'
0e6cc40375 Jean*0813             for ldir in $* ; do
878c588496 Jean*0814                 if test -d "../"$ldir -a $ldir != $prevDir ; then
6418c0ec62 Jean*0815                     printf " ldir=${ldir}:" 1>&2
0e6cc40375 Jean*0816                     files=`( cd "../"$ldir ; ls -1 | grep -v CVS )`
                0817                     for i in $files ; do
                0818                         if test ! -d "../"$ldir/$i ; then
                0819                             if test ! -r $i  ; then
                0820                                 printf ' '$i 1>&2
                0821                                 ln -sf "../"$ldir"/"$i $i
                0822                             fi
                0823                         fi
                0824                     done
6fcdccb64d Jean*0825                     printf ' ;' 1>&2
0e6cc40375 Jean*0826                     if test -x "../"$ldir"/"prepare_run ; then
6fcdccb64d Jean*0827                         "../"$ldir"/"prepare_run 1>&2
                0828                     else
                0829                         echo '' 1>&2
0e6cc40375 Jean*0830                     fi
                0831                 fi
878c588496 Jean*0832                 prevDir=$ldir
0e6cc40375 Jean*0833             done
474019363f Ed H*0834         )
2ff82eb834 Ed H*0835     fi
                0836 }
                0837 
                0838 runmodel()
                0839 {
96d85cca71 Ed H*0840     # runmodel directory
2ff82eb834 Ed H*0841     #
d9ae4e2b34 Jean*0842     #  runs $COMMAND in "directory"
96d85cca71 Ed H*0843     #  (where "$COMMAND" is relative to "directory")
2ff82eb834 Ed H*0844     (
                0845         cd $1
6fcdccb64d Jean*0846         printf 'runmodel in %s ... ' $1
360fa2f691 Jean*0847         if test "x$MPI" != x0 ; then
                0848             #- adjust the MPI run command with the right number of Procs
                0849             #echo '' ; echo "  COMMAND='$COMMAND'"
250e8a7757 Jean*0850             COMMAND=`echo $COMMAND | sed "s/ TR_NPROC/ $LOC_NPROC/"`
360fa2f691 Jean*0851             if test "x$MPI_MFILE" != x ; then
                0852               COMMAND=`echo $COMMAND | sed "s/ TR_MFILE / ..\/..\/$LOC_MFILE /"`
                0853             fi
                0854             #echo "  COMMAND='$COMMAND'"
                0855         fi
28b546244a Jean*0856         if test -L $EXECUTABLE ; then
                0857           if test -x "../"$builddir"/"$EXECUTABLE ; then
d9ae4e2b34 Jean*0858             cmp $EXECUTABLE "../"$builddir"/"$EXECUTABLE > /dev/null 2>&1
                0859             outD=$? ; if test "x$outD" != x0 ; then rm -f $EXECUTABLE ; fi
28b546244a Jean*0860           else rm -f $EXECUTABLE
                0861           fi
7e8ef1f316 Jean*0862         fi
6418c0ec62 Jean*0863         if test ! -x $EXECUTABLE -a -x "../"$builddir"/"$EXECUTABLE ; then
baf6258c8a Jean*0864             echo " link" $EXECUTABLE "from dir ../"$builddir > run.log_tmp
0e6cc40375 Jean*0865             ln -sf "../"$builddir"/"$EXECUTABLE .
                0866         fi
6418c0ec62 Jean*0867         if test ! -x $EXECUTABLE ; then
bbea11a65d Jean*0868             rm -f $RUNLOG ; touch $RUNLOG
                0869             if test -f run.log_tmp ; then cat run.log_tmp >> $RUNLOG ; fi
                0870             echo " no executable:" $EXECUTABLE >> $RUNLOG
                0871             RETVAL=8
                0872             ENDVAL=-1
2b043763fc Jean*0873         else
6418c0ec62 Jean*0874           if test ! -f $OUTPUTFILE -o $OUTPUTFILE -ot $EXECUTABLE ; then
                0875             # output do not exist or is older than executable:
840f5814ba Jean*0876             rm -f $OUTPUTFILE $RUNLOG ; touch $RUNLOG
bbea11a65d Jean*0877             if test -f run.log_tmp ; then cat run.log_tmp >> $RUNLOG ; fi
ba205b1a1d Jean*0878         #- Divided Adjoint Run:
                0879         #  get the number of additional runs (add_DIVA_runs) from file "run_ADM_DIVA"
                0880             if test $KIND = 2 -a -f run_ADM_DIVA ; then
aad71d9e67 Mart*0881               adm_diva_nb=`sed -n '/^ *add_DIVA_runs *=/p' run_ADM_DIVA | sed 's/ //g'`
ba205b1a1d Jean*0882               echo " Divided Adjoint Run: $adm_diva_nb" >> $RUNLOG
                0883               eval "let $adm_diva_nb"
                0884               if [ $add_DIVA_runs -ge 1 ] ; then
3a516654c6 Jean*0885                 extraRuns=`expr $add_DIVA_runs - 1`
ba205b1a1d Jean*0886                 rm -f costf* divided.ctrl snapshot*
                0887                 echo -n "(add_DIVA_runs=$add_DIVA_runs) ... "
3a516654c6 Jean*0888                 for ii in `seq 0 $extraRuns` ; do
ba205b1a1d Jean*0889                   ( eval $COMMAND ) >> $RUNLOG 2>&1
                0890                   echo " additional DIVA run # $ii : done" >> $RUNLOG
                0891                   mv -f $OUTPUTFILE ${OUTPUTFILE}.diva_${ii}
                0892                 done
                0893               fi
ebcc29af97 Jean*0894             elif test -f run_ADM_DIVA ; then
                0895                 rm -f costf* divided.ctrl snapshot*
ba205b1a1d Jean*0896             fi
                0897         #- special DIVA processing ends here
bbea11a65d Jean*0898             ( eval $COMMAND ) >> $RUNLOG 2>&1
                0899             RETVAL=$?
                0900             ENDVAL=`tail $OUTPUTFILE | grep -c 'PROGRAM MAIN: Execution ended Normally'`
                0901             if [ $POSTCLEAN -eq 1 -a $ENDVAL -gt 0 ] ; then
                0902                 find . -name "*.meta" -exec rm {} \;
                0903                 find . -name "*.data" -exec rm {} \;
                0904                 rm -rf mnc_test_*
0e6cc40375 Jean*0905             fi
bbea11a65d Jean*0906           else
                0907             RETVAL=0
871a0c28c5 Jean*0908             ENDVAL=`tail $OUTPUTFILE | grep -c 'PROGRAM MAIN: Execution ended Normally'`
bbea11a65d Jean*0909             touch $RUNLOG
                0910             if test -f run.log_tmp ; then cat run.log_tmp >> $RUNLOG ; fi
6418c0ec62 Jean*0911             echo "---------->> $OUTPUTFILE is up to date " >> $RUNLOG 2>&1
bbea11a65d Jean*0912           fi
2b043763fc Jean*0913         fi
baf6258c8a Jean*0914         rm -f run.log_tmp
1fff053a17 Jean*0915         #- in all cases where OutputFile exists, report SIZE and time
360fa2f691 Jean*0916         if test -f $OUTPUTFILE ; then
                0917           grep '(PID\.TID 0000\.0001)      n.. =' $OUTPUTFILE \
1fff053a17 Jean*0918                 | sed 's/(PID.TID 0000.0001)   //' >> $CDIR"/summary.txt"
deb0ad3aea Mart*0919 #         grep -A3 'Seconds in section "ALL' $OUTPUTFILE \
                0920 #               | sed 's/(PID.TID 0000.0001)   //' >> $CDIR"/summary.txt"
                0921 #         some implementations of grep cannot do contextual searches so we
                0922 #         replace the above with a sed command
                0923           cat $OUTPUTFILE | sed -n '/Seconds in section "ALL/{N
                0924           N
                0925           N
                0926           p
                0927           }' | sed 's/(PID.TID 0000.0001)   //' >> $CDIR"/summary.txt"
360fa2f691 Jean*0928         fi
                0929         if test -s STDERR.0000 ; then cp STDERR.0000 $CDIR"/STDERR.0000" ; fi
3f26a348bd Jean*0930         if [ $RETVAL -eq 0 -a $ENDVAL -gt 0 ] ; then
6fcdccb64d Jean*0931             echo successful
                0932             printf '=> output from running in %s :\n' $1 1>&2
                0933             tail $RUNLOG | sed 's/^.*/> &/g' 1>&2
96d85cca71 Ed H*0934             return 0
3cf8d39958 Jean*0935         elif [ $RETVAL -ne 0 -a $ENDVAL -gt 0 ] ; then
                0936             #-- for some weird cases (run is finihed but with error code)
6fcdccb64d Jean*0937             echo 'finished with error (run:' $RETVAL ' end:' $ENDVAL ')'
                0938             printf '=> output from running in %s :\n' $1 1>&2
                0939             tail $RUNLOG | sed 's/^.*/> &/g' 1>&2
3cf8d39958 Jean*0940             return 0
96d85cca71 Ed H*0941         else
6fcdccb64d Jean*0942             echo 'failed (run:' $RETVAL ' end:' $ENDVAL ')'
                0943             printf '=> output from running in %s :\n' $1 1>&2
                0944             tail $RUNLOG | sed 's/^.*/> &/g' 1>&2
baf6258c8a Jean*0945             cp $RUNLOG $CDIR"/"$RUNLOG
96d85cca71 Ed H*0946             return 1
2ff82eb834 Ed H*0947         fi
                0948     )
                0949 }
                0950 
                0951 createcodelet()
                0952 {
                0953     # create codelet for comparing model output
                0954 
63e0800ef7 Jean*0955     printf "creating the comparison code (using CC=$CC)...  "
2366f571a5 Jean*0956     cat > tr_cmpnum.c <<EOF
cfc62862f0 Ed H*0957 #include <stdio.h>
                0958 #include <math.h>
                0959 int main( int argc, char** argv )  {
2366f571a5 Jean*0960   int linnum,cmplin,best,lncnt;
2adbdc8a5e Ed H*0961   double a,b,abave,relerr;
8d90f27f15 Jean*0962   best = -22;
852a4acb3d Alis*0963   lncnt = 0;
3ff2fe3646 Jean*0964   while( 1 & ( (lncnt+=1) < 999 ) )  {
cfc62862f0 Ed H*0965     scanf("%d", &linnum);
                0966     if (linnum == -1)  break;
                0967     scanf("%lf", &a);  scanf("%lf", &b);
2adbdc8a5e Ed H*0968     abave = 0.5*(fabs(a)+fabs(b));
2366f571a5 Jean*0969     if ( abave == abave ) {
                0970       if (abave > 0.0) {
                0971         relerr=fabs(a-b)/abave;
                0972         if (relerr > 0.0) { cmplin = (int)rint(log10(relerr)); }
                0973         else { cmplin = -16 ; }
                0974         best = (best > cmplin) ? best : cmplin; }
                0975       else { cmplin = -22 ; }
                0976    /* printf("%d ; %lf ; %lf\n",cmplin,a,b); */
                0977       }
                0978    else {
                0979    /* printf("%lf ; %lf ; %lf\n",abave,a,b); */
                0980       break; }
cfc62862f0 Ed H*0981   }
852a4acb3d Alis*0982   if (lncnt == 999) best=-29;
2366f571a5 Jean*0983   if (linnum != -1) best=-99;
cfc62862f0 Ed H*0984   printf("%d\n", -best);
                0985   return 0;
                0986 }
                0987 EOF
2366f571a5 Jean*0988     $CC -o tr_cmpnum tr_cmpnum.c -lm
cfc62862f0 Ed H*0989 
2366f571a5 Jean*0990     if [ -x ./tr_cmpnum ]; then
2ff82eb834 Ed H*0991         echo "OK"
                0992         return 0
                0993     else
                0994         echo
9750e41317 Jean*0995         echo "ERROR: failed to compile comparison code -- please specify"
a581267379 Ed H*0996         echo "  a C compiler using the CC environment variable."
2ff82eb834 Ed H*0997         exit 1
                0998     fi
                0999 }
                1000 
                1001 formatresults()
                1002 {
                1003     # formatresults expt genmake depend make run results*
                1004 
                1005     nm=$1
                1006     printf '%s %s %s %s' $2 $3 $4 $5
                1007     shift; shift; shift; shift; shift;
eb7e5e62ed Jean*1008     listPrt=$@
                1009     listRes=`echo $listPrt | sed 's/>//' | sed 's/<//'`
                1010     xx=`echo $listPrt | sed 's/.*>//' | sed 's/<.*//' | awk '{print $1}'`
4d91a93b49 Jean*1011     printf '%3s' $listPrt
44a2688a94 Jean*1012 #   line below does not work on hp-ux_ia64 : do those substitutions later on
6ce7c44299 Jean*1013 #   printf '%3s' $listPrt | sed 's/ 99/ --/g' | sed 's/  > />/' | sed 's/  < /</'
9750e41317 Jean*1014 
eb7e5e62ed Jean*1015     if [ $xx = '..' ]; then
                1016         printf ' N/O '
                1017     elif [ $xx = '--' ]; then
                1018         printf ' N/O '
                1019     elif [ $xx = 99 ]; then
2ff82eb834 Ed H*1020         printf ' N/O '
                1021     else
eb7e5e62ed Jean*1022         if [ $xx -ge $MATCH_CRIT ]; then
2ff82eb834 Ed H*1023             printf ' pass'
                1024         else
                1025             printf ' FAIL'
                1026         fi
                1027     fi
                1028     printf '  %s' $nm
f561fdaba7 Jean*1029     if test $KIND = 2 ; then
49a029e3de Mart*1030         #-- append taf report summary:
f561fdaba7 Jean*1031         tafrep=`grep -c '^ TAF reports ' $CDIR/summary.txt`
                1032         if test $tafrep = 1 ; then
49a029e3de Mart*1033             grep '^ TAF reports ' $CDIR/summary.txt | awk '{printf "  (e=%i, w=%i,",$3,$6}'
                1034             grep '^ load_fields_driver,' $CDIR/summary.txt \
d37c4896c1 Mart*1035                 | awk '{printf " lfd=%i, dop=%i, sm=%i)",$7,$9,$11}'
f561fdaba7 Jean*1036         fi
                1037     fi
2ff82eb834 Ed H*1038     printf '\n'
9750e41317 Jean*1039 
2ff82eb834 Ed H*1040 }
                1041 
                1042 scandirs()
                1043 {
b2fb7c7569 Jean*1044     if [ $# -eq 1 ]; then
                1045         for arg in * ; do
6418c0ec62 Jean*1046            #test -f $arg/$1 && echo $arg
                1047             test -f $arg/$1 -o -f $arg/$1.gz && echo $arg
b2fb7c7569 Jean*1048         done
2ff82eb834 Ed H*1049     else
b2fb7c7569 Jean*1050         echo $*
2ff82eb834 Ed H*1051     fi
                1052 }
                1053 
                1054 
0179fa2c74 Jean*1055 check_eedata()
                1056 {
7ba778f1ca Jean*1057     # check_eedata eedata size.h
0179fa2c74 Jean*1058     if [ $# -eq 2 ] ; then
7ba778f1ca Jean*1059      if test -f $1 -a -f $2 ; then
                1060       nx=`grep "^ *nTx *=" $1 | tail -1 | sed 's/^ *nTx *= *//' | sed "s/, *$//"`
                1061       sx=`grep "^     & *nSx *=" $2 | sed "s/^     & *nSx *=//" | sed 's/, *$//'`
0179fa2c74 Jean*1062       if test "x$nx" = x ; then
                1063         rx=10
                1064       else
                1065         rx=`expr $sx % $nx`
                1066       fi
7ba778f1ca Jean*1067       ny=`grep "^ *nTy *=" $1 | tail -1 | sed 's/^ *nTy *= *//' | sed "s/, *$//"`
                1068       sy=`grep "^     & *nSy *=" $2 | sed "s/^     & *nSy *=//" | sed 's/, *$//'`
0179fa2c74 Jean*1069       if test "x$ny" = x ; then
                1070         ry=20
                1071       else
                1072         ry=`expr $sy % $ny`
                1073       fi
                1074       echo `expr $rx + $ry`
7ba778f1ca Jean*1075      else
0179fa2c74 Jean*1076       echo '-1'
7ba778f1ca Jean*1077      fi
                1078     elif [ $# -eq 1 ] ; then
                1079      if test -f $1 ; then
                1080       nx=`grep "^ *nTx *=" $1 | tail -1 | sed 's/^ *nTx *= *//' | sed "s/, *$//"`
                1081       if test "x$nx" = x ; then nx=1 ; fi
                1082       ny=`grep "^ *nTy *=" $1 | tail -1 | sed 's/^ *nTy *= *//' | sed "s/, *$//"`
                1083       if test "x$ny" = x ; then ny=1 ; fi
                1084      #echo $nx $ny
                1085       echo $nx
                1086      else
                1087       echo '-1'
                1088      fi
0179fa2c74 Jean*1089     else
                1090       echo '-2'
                1091     fi
                1092 
                1093 }
                1094 
2ff82eb834 Ed H*1095 ###############################################################################
                1096 
                1097 
                1098 #  Default properties
                1099 debug=0
                1100 verbose=1
da8170bd49 Jean*1101 NBLINES_MKLOG=16000
6d54cf9ca1 Ed H*1102 
5a67953813 Jean*1103 OptLev=1
232027f18d Jean*1104 GSL=f
6d54cf9ca1 Ed H*1105 
                1106 CLEANUP=f
ca6d5f1072 Jean*1107 NORUN=f
6d54cf9ca1 Ed H*1108 QUICK=f
416e70d1a2 Jean*1109 NOMAKE=f
6d54cf9ca1 Ed H*1110 NOGENMAKE=f
                1111 NOCLEAN=f
                1112 NODEPEND=f
bbea11a65d Jean*1113 POSTCLEAN=0
2ff82eb834 Ed H*1114 
ac4ed47881 Ed H*1115 BASH=
6d54cf9ca1 Ed H*1116 OPTFILE=NONE
                1117 ADDRESSES=
2ff82eb834 Ed H*1118 TESTDIRS=
6d0f07d5b0 Jean*1119 SKIPDIRS=
2ff82eb834 Ed H*1120 MPACKDIR="../tools/mpack-1.6"
002054e5e5 Ed H*1121 HAVE_MPACK=
d6829a17bc Jean*1122 MPACK=
ee57712ddb Jean*1123 SENDCMD=
                1124 SAVDIR='.'
4619920a5f Ed H*1125 COMMAND=
ca2316a28b Jean*1126 MKDEPEND=
df038dc180 Ed H*1127 if test "x$MAKE" = x ; then
                1128     MAKE=make
                1129 fi
72af1157c6 Jean*1130 MAKE_CMD=
df038dc180 Ed H*1131 if test "x$CC" = x ; then
                1132     CC=cc
                1133 fi
8c9e835c69 Ed H*1134 JOBS=
1f09e8610e Jean*1135 TARG=
d9ae4e2b34 Jean*1136 MPI=0
bbea11a65d Jean*1137 MPI_MFILE=
0e6cc40375 Jean*1138 MULTI_THREAD=f
065c45c70d Jean*1139 OUTDIR=
384dccb29e Ed H*1140 DELDIR=
9750e41317 Jean*1141 USE_R4=
1f09e8610e Jean*1142 EXTRFLG=
72af1157c6 Jean*1143 NOCATAD=
e977410d1b Mart*1144 MKSMALLF=
9d0c386f0c dngo*1145 OADSINGULARITY=
13cadcbe59 Oliv*1146 CHECK_PASS=f
2ff82eb834 Ed H*1147 
6418c0ec62 Jean*1148 #- type of testing (KIND):
b4daa24319 Shre*1149 #   KIND=0 : forward (= default) ;     KIND=6 : Adjoint with OpenAD
                1150 #   KIND=1 : Tangent-Linear with TAF ; KIND=2 : Adjoint with TAF ;
                1151 #   KIND=4 : Tang-Lin. with Tapenade ; KIND=5 : Adjoint with Tapenade ;
6418c0ec62 Jean*1152 KIND=0
4619920a5f Ed H*1153 
bef69cc95f Jean*1154 # list of pTracers to check for monitor output
a18b9b1964 Ed H*1155 PTRACERS_NUM="1 2 3 4 5"
68c34fd102 Ed H*1156 
759f576934 Jean*1157 MATCH_CRIT=10
aaf4336666 Jean*1158 
e53112a6cf Ed H*1159 printf "parsing options...  "
2ff82eb834 Ed H*1160 
                1161 ac_prev=
                1162 for ac_option ; do
                1163 
                1164     # If the previous option needs an argument, assign it.
                1165     if test -n "$ac_prev"; then
                1166         eval "$ac_prev=\$ac_option"
                1167         ac_prev=
                1168         continue
                1169     fi
                1170 
                1171     ac_optarg=`expr "x$ac_option" : 'x[^=]*=\(.*\)'`
9750e41317 Jean*1172 
2ff82eb834 Ed H*1173     case $ac_option in
49a029e3de Mart*1174 
bbea11a65d Jean*1175         -help | --help | -h | --h) usage ;;
                1176 
                1177         -optfile | --optfile | -of | --of) ac_prev=OPTFILE ;;
                1178         -optfile=* | --optfile=* | -of=* | --of=*) OPTFILE=$ac_optarg ;;
                1179 
                1180         -addr | --addr | -a | --a) ac_prev=ADDRESSES ;;
                1181         -addr=* | --addr=* | -a=* | --a=*) ADDRESSES=$ac_optarg ;;
                1182         -mpackdir | --mpackdir | -mpd | --mpd) ac_prev=MPACKDIR ;;
                1183         -mpackdir=* | --mpackdir=* | -mpd=* | --mpd=*) MPACKDIR=$ac_optarg ;;
                1184 
ee57712ddb Jean*1185         -send | --send ) ac_prev=SENDCMD ;;
                1186         -send=* | --send=* ) SENDCMD=$ac_optarg ;;
                1187         -savdir | --savdir | -sd | --sd ) ac_prev=SAVDIR ;;
                1188         -savdir=* | --savdir=* | -sd=* | --sd=* ) SAVDIR=$ac_optarg ;;
                1189 
bbea11a65d Jean*1190         -tdir | --tdir | -t | --t) ac_prev=TESTDIRS ;;
                1191         -tdir=* | --tdir=* | -t=* | --t=*) TESTDIRS=$ac_optarg ;;
                1192         -skipdir | --skipdir | -skd | --skd) ac_prev=SKIPDIRS ;;
                1193         -skipdir=* | --skipdir=* | -skd=* | --skd=*) SKIPDIRS=$ac_optarg ;;
                1194 
                1195         -bash | --bash | -b | --b) ac_prev=BASH ;;
                1196         -bash=* | --bash=* | -b=* | --b=*) BASH=$ac_optarg ;;
                1197 
                1198         -command | --command | -c | --c) ac_prev=COMMAND ;;
                1199         -command=* | --command=* | -c=* | --c=*) COMMAND=$ac_optarg ;;
                1200 
                1201         -makedepend | --makedepend | -md | --md) ac_prev=MKDEPEND ;;
                1202         -makedepend=* | --makedepend=* | -md=* | --md=*) MKDEPEND=$ac_optarg ;;
                1203 
                1204         -make | --make | -m | --m) ac_prev=MAKE ;;
                1205         -make=* | --make=* | -m=* | --m=*) MAKE=$ac_optarg ;;
                1206 
72af1157c6 Jean*1207         -repl_mk | --repl_mk ) ac_prev=MAKE_CMD ;;
                1208         -repl_mk=* | --repl_mk=*) MAKE_CMD=$ac_optarg ;;
462ccb31f3 Jean*1209 
bbea11a65d Jean*1210         -odir | --odir) ac_prev=OUTDIR ;;
                1211         -odir=* | --odir=*) OUTDIR=$ac_optarg ;;
                1212 
                1213         -ptracers | --ptracers | -ptr | --ptr) ac_prev=PTRACERS_NUM ;;
                1214         -ptracers=* | --ptracers=* | -ptr=* | --ptr=*) PTRACERS_NUM=$ac_optarg ;;
a18b9b1964 Ed H*1215 
aaf4336666 Jean*1216         -match | --match ) ac_prev=MATCH_CRIT ;;
                1217         -match=* | --match=* ) MATCH_CRIT=$ac_optarg ;;
                1218 
416e70d1a2 Jean*1219         -j | --j) ac_prev=JOBS ;;
                1220         -j=* | --j=*) JOBS=$ac_optarg ;;
8c9e835c69 Ed H*1221 
1f09e8610e Jean*1222         -ef | --ef) ac_prev=EXTRFLG ;;
                1223         -ef=* | --ef=*) EXTRFLG=$ac_optarg ;;
                1224 
bbea11a65d Jean*1225         -clean | --clean) CLEANUP=t ; DELDIR=t ;;
                1226 
                1227         -norun | --norun | -nr | --nr) NORUN=t ;;
1f09e8610e Jean*1228         -obj | --obj ) TARG='obj' ; NORUN=t ;;
f6209765b3 Jean*1229         -src | --src ) TARG='small_f' ; NORUN=t ;;
bbea11a65d Jean*1230         -runonly | --runonly | -ro | --ro) QUICK=t ; NOMAKE=t ;;
                1231         -quick | --quick | -q | --q) QUICK=t ;;
                1232         -nogenmake | --nogenmake | -ng | --ng) NOGENMAKE=t ;;
                1233         -noclean | --noclean | -nc | --nc) NOCLEAN=t ;;
                1234         -nodepend | --nodepend | -nd | --nd) NODEPEND=t ;;
                1235 
                1236         -postclean | --postclean | -pc | --pc) POSTCLEAN=2 ;;
                1237         -deloutp | --deloutp | -do | --do) POSTCLEAN=1 ;;
0b035b108c Ed H*1238 
13cadcbe59 Oliv*1239         -pass) CHECK_PASS=t ;;
                1240 
d9ae4e2b34 Jean*1241         -mpi | --mpi) MPI=2 ;;
                1242         -MPI | --MPI) ac_prev=MPI ;;
                1243         -MPI=* | --MPI=*) MPI=$ac_optarg ;;
6d54cf9ca1 Ed H*1244 
bbea11a65d Jean*1245         -mfile | --mfile | -mf | --mf) ac_prev=MPI_MFILE ;;
                1246         -mfile=* | --mfile=* | -mf=* | --mf=*) MPI_MFILE=$ac_optarg ;;
                1247 
0e6cc40375 Jean*1248         -mth) MULTI_THREAD=t ;;
                1249 
b4daa24319 Shre*1250         -tlm) if test $KIND = 0 -o $KIND = 3 ; then KIND=`expr $KIND + 1`; else
                1251                 echo "Error: '-tlm', '-adm' and '-oad' are exclusive + no duplicate" ; usage
                1252               fi ;;
                1253         -adm | -ad) if test $KIND = 0 -o $KIND = 3 ; then KIND=`expr $KIND + 2` ; else
                1254                 echo "Error: '-tlm', '-adm' and '-oad' are exclusive + no duplicate" ; usage
6418c0ec62 Jean*1255               fi ;;
b4daa24319 Shre*1256         -tap) if [ $KIND -le 2 ] ; then KIND=`expr $KIND + 3` ; else
                1257                 echo "Error: '-tap' and '-oad' are exclusive + no duplicate" ; usage
6418c0ec62 Jean*1258               fi ;;
b4daa24319 Shre*1259         -oad) if test $KIND = 0 ; then KIND=6 ; NODEPEND=t ; else
                1260                 echo "Error: '-tlm', '-adm' and '-oad' are exclusive + no duplicate" ; usage
6418c0ec62 Jean*1261               fi ;;
9d0c386f0c dngo*1262         -oadsingularity | --oadsingularity | -oadsngl | --oadsngl) ac_prev=OADSINGULARITY ;;
                1263         -oadsingularity=* | --oadsingularity=* | -oadsngl=* | --oadsngl=*) OADSINGULARITY=$ac_optarg ;;
                1264 
72af1157c6 Jean*1265         -ncad) NOCATAD=t ;;
e977410d1b Mart*1266         -small_f) MKSMALLF=t ;;
3907106aba Jean*1267 
5a67953813 Jean*1268         -ieee)   echo "Warning: ignore option '-ieee' (already the default)"
6418c0ec62 Jean*1269                  printf " ... " ;;
5a67953813 Jean*1270         -noieee) echo "Warning: will use option '-fast' instead of '-noieee' (obsolete)"
6418c0ec62 Jean*1271                  printf " ... " ; OptLev=`expr $OptLev \* 2` ;;
5a67953813 Jean*1272         -fast)  OptLev=`expr $OptLev \* 2` ;;
                1273         -devel) OptLev=0 ;;
bbea11a65d Jean*1274         -gsl) GSL=t ;;
6d54cf9ca1 Ed H*1275 
2ff82eb834 Ed H*1276         -verbose) verbose=2 ;;
                1277         -debug) debug=1 ;;
                1278         -quiet) verbose=0 ;;
                1279 
384dccb29e Ed H*1280         -deldir | -dd) DELDIR=t ;;
                1281 
416e70d1a2 Jean*1282         -use_r4|-ur4) USE_R4=t ;;
a986ef8661 Cons*1283 
9750e41317 Jean*1284         -ts) TS=t;;
a986ef8661 Cons*1285         -papis) PAPIS=t;;
72af1157c6 Jean*1286         -pcls) PCLS=t;;
a986ef8661 Cons*1287 
bbea11a65d Jean*1288         -*) echo "Error: unrecognized option: "$ac_option
                1289             usage ;;
                1290         *)  echo "Error: unrecognized argument: "$ac_option
                1291             usage ;;
9750e41317 Jean*1292 
2ff82eb834 Ed H*1293      esac
9750e41317 Jean*1294 
2ff82eb834 Ed H*1295 done
                1296 
6d54cf9ca1 Ed H*1297 if test "x$QUICK" = xt ; then
                1298     NOGENMAKE=t
                1299     NOCLEAN=t
                1300     NODEPEND=t
                1301 fi
72af1157c6 Jean*1302 if test "x$MAKE_CMD" = x ; then MAKE_CMD=$MAKE ; fi
6d54cf9ca1 Ed H*1303 
bbea11a65d Jean*1304 #- check length of MPI machine file:
                1305 if test "x$MPI" != x0 -a "x$MPI_MFILE" != x ; then
                1306     if test -r $MPI_MFILE ; then
                1307         nl=`wc -l $MPI_MFILE | awk '{print $1}'`
                1308         if [ $nl -lt $MPI ] ; then
6418c0ec62 Jean*1309           echo "Error: need at least $MPI nodes (currently only $nl) in MPI_MFILE=$MPI_FILE"
                1310           usage
bbea11a65d Jean*1311         fi
                1312         if [ $verbose -gt 1 ]; then
                1313             echo " MPI_MFILE=$MPI_MFILE : $nl procs for MPI=$MPI run"
                1314         fi
                1315     else
6418c0ec62 Jean*1316           echo "Error: cannot access MPI_MFILE=$MPI_FILE"
                1317           usage
bbea11a65d Jean*1318     fi
                1319 fi
                1320 
b4daa24319 Shre*1321 #- setting for forward, TLM or ADM testing
6418c0ec62 Jean*1322 if test $KIND = 1 ; then
c59dd234b1 Jean*1323     if test "x$TARG" = x        ; then TARG=ftlall ; fi
                1324     if test "x$TARG" = xobj     ; then TARG=ftlobj ; fi
                1325     if test "x$TARG" = xsmall_f ; then TARG=ftltaf ; fi
6418c0ec62 Jean*1326     code_dir=code_ad
                1327     inputdir=input_ad
                1328     ref_outp="output_tlm.txt"
                1329     EXECUTABLE="mitgcmuv_ftl"
                1330 elif test $KIND = 2 ; then
f6209765b3 Jean*1331     if test "x$TARG" = x        ; then TARG=adall ; fi
                1332     if test "x$TARG" = xobj     ; then TARG=adobj ; fi
                1333     if test "x$TARG" = xsmall_f ; then TARG=adtaf ; fi
6d41b7da3e Jean*1334     code_dir=code_ad
878c588496 Jean*1335     inputdir=input_ad
6d41b7da3e Jean*1336     ref_outp="output_adm.txt"
                1337     EXECUTABLE="mitgcmuv_ad"
b4daa24319 Shre*1338 elif test $KIND = 4 -o $KIND = 5 ; then
                1339     if test $KIND = 4 ; then TARG=tap_tlm ; else TARG=tap_adj ; fi
                1340     code_dir=code_tap
                1341     inputdir=input_tap
                1342     ref_outp="output_${TARG}.txt"
                1343     EXECUTABLE="mitgcmuv_${TARG}"
                1344 elif test $KIND = 6 ; then
f9b75e9bda Jean*1345     TARG=adAll
3907106aba Jean*1346     code_dir=code_oad
                1347     inputdir=input_oad
                1348     ref_outp="output_oadm.txt"
                1349     EXECUTABLE="mitgcmuv_ad"
6d41b7da3e Jean*1350 else
                1351     code_dir=code
878c588496 Jean*1352     inputdir=input
6d41b7da3e Jean*1353     ref_outp="output.txt"
                1354     EXECUTABLE="mitgcmuv"
                1355 fi
72af1157c6 Jean*1356 if test "x$JOBS" != x ; then TARG="-j $JOBS $TARG" ; fi
6d41b7da3e Jean*1357 
b4daa24319 Shre*1358 if [ $verbose -gt 1 ]; then
                1359     echo ""
                1360     echo "--- print $0 setting:"
                1361     echo " KIND     =  '$KIND'"
                1362     echo " TARG     =  '$TARG'"
                1363     echo " code_dir =  '$code_dir'"
                1364     echo " inputdir =  '$inputdir'"
                1365     echo " ref_outp =  '$ref_outp'"
                1366     echo " EXECUTABLE= '$EXECUTABLE'"
                1367     echo "--- printing ends."
                1368    #exit 0
                1369 fi
                1370 
ed9f439d26 Jean*1371 xx=`echo $TESTDIRS | awk '{print $1}'`
2ff82eb834 Ed H*1372 if test "x$TESTDIRS" = x ; then
456c314cce Jean*1373     LIST=`scandirs results/$ref_outp`
ed9f439d26 Jean*1374 elif test $xx = 'start_from' ; then
                1375     xx=`echo $TESTDIRS | awk '{print $2}'`
                1376     LIST=`scandirs results/$ref_outp | sed -n "/$xx/,$ p"`
35aa6741f4 Jean*1377 else
                1378     #- expand group of experiments:
                1379     LIST=" "
                1380     for xx in $TESTDIRS
                1381     do
                1382       case $xx in
c4ead643ab Jean*1383         'basic') LIST=${LIST}" aim.5l_cs hs94.128x64x5 ideal_2D_oce"
                1384                  LIST=${LIST}" lab_sea tutorial_baroclinic_gyre"
                1385                  LIST=${LIST}" tutorial_global_oce_latlon tutorial_plume_on_slope"
35aa6741f4 Jean*1386                 ;;
                1387         'tutorials')
                1388                  LIST=${LIST}" "`ls | grep 'tutorial_'` ;;
                1389         *)       LIST=${LIST}" "$xx ;;
                1390       esac
9750e41317 Jean*1391     done
6d0f07d5b0 Jean*1392 fi
                1393 #echo 'LIST='${LIST}'<'
                1394 #- skip dirs, remove duplicate and non-directory:
                1395 TESTDIRS=" "
                1396 count=0
                1397 for xx in $LIST
                1398 do
                1399     yy=`echo $SKIPDIRS | grep -c $xx`
                1400     if test $yy = 0 ; then
35aa6741f4 Jean*1401         if test -d $xx ; then
                1402             yy=`echo $TESTDIRS | grep -c $xx`
                1403             if test $yy = 0 ; then TESTDIRS=${TESTDIRS}" "$xx ; fi
6d0f07d5b0 Jean*1404         else count=1 ;
                1405             echo ""; echo -n " -- skip \"$xx\" (not a directory !)"
35aa6741f4 Jean*1406         fi
6d0f07d5b0 Jean*1407     else
6418c0ec62 Jean*1408         if test $count = 1 ; then echo -n ", \"$xx\""
6d0f07d5b0 Jean*1409         else count=1 ; echo "" ;  echo -n " skip: \"$xx\""
                1410         fi
                1411     fi
9750e41317 Jean*1412 done
6d0f07d5b0 Jean*1413 if test $count = 1 ; then echo "" ; echo -n " ... " ; fi
35aa6741f4 Jean*1414 #echo 'TESTDIRS='${TESTDIRS}'<'
2ff82eb834 Ed H*1415 
bbea11a65d Jean*1416 LOC_MFILE='tr_mpi_mfile'
0093035fc0 Jean*1417 RUNLOG="run.tr_log"
442de1f446 Jean*1418 if test "x$MPI" = x0 ; then
                1419   OUTPUTFILE=$ref_outp
                1420   if test "x$COMMAND" = x ; then COMMAND="./$EXECUTABLE > $OUTPUTFILE" ; fi
                1421 else
                1422   OUTPUTFILE="STDOUT.0000"
75c0ee3505 Jean*1423   if test "x$COMMAND" = x ; then COMMAND="mpirun -np TR_NPROC ./$EXECUTABLE" ; fi
84370bfea3 Jean*1424 fi
4619920a5f Ed H*1425 
442de1f446 Jean*1426 echo "OK (COMMAND='$COMMAND')"
2ff82eb834 Ed H*1427 
72af1157c6 Jean*1428 #TMP=./tr_$$
ee57712ddb Jean*1429 #- try to put temporary files in system-local /tmp dir
72af1157c6 Jean*1430 TMP=/tmp/tr_${USER}_$$
                1431 touch $TMP ; retVal=$?
                1432 if [ $retVal -eq 0 ] ; then
                1433   if test ! -r $TMP ; then TMP=./tr_$$ ; fi
                1434 else
                1435   TMP=./tr_$$
                1436 fi
                1437 rm -f $TMP
                1438 if [ $verbose -gt 1 ]; then echo " temp files: $TMP" ; fi
ee57712ddb Jean*1439 
eb7e5e62ed Jean*1440 # set the Default List of output variables to be checked:
                1441 #  (use default or load experiment-specific list from file "tr_checklist")
                1442 # content : 1rst = main variable used to decide if it pass or FAIL
                1443 #         others = number of matching digits to be printed in summary.txt
d81415648f Jean*1444 if test $KIND = 0 ; then
eb7e5e62ed Jean*1445     DEF_CHECK_LIST='PS PS T+ S+ U+ V+ pt1+ pt2+ pt3+ pt4+ pt5+'
                1446     EMPTY_RESULTS='.. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. ..'
4d91a93b49 Jean*1447     LEN_CHECK_LIST=`echo $DEF_CHECK_LIST | sed 's/ [a-zA-Z0-9]*+/&mn &mx &av &sd/g' | awk '{print NF-1}'`
eb7e5e62ed Jean*1448     ii=`echo $EMPTY_RESULTS | awk '{print NF}'`
4d91a93b49 Jean*1449     EMPTY_RESULTS=$EMPTY_RESULTS`expr $LEN_CHECK_LIST - $ii | awk 'BEGIN{FS=":"}{for(i=1;i<=$1;i++){printf "  ."}}'`
d81415648f Jean*1450 elif test $KIND = 2 ; then
                1451     DEF_CHECK_LIST='admGrd admCst admGrd admFwd T+ S+ U+ V+'
                1452     EMPTY_RESULTS='.. .. .. .. .. .. ..  .. .. .. ..  .. .. .. ..  .. .. .. ..'
                1453     LEN_CHECK_LIST=`echo $DEF_CHECK_LIST | sed 's/ [a-zA-Z0-9]*+/&mn &mx &av &sd/g' | awk '{print NF-1}'`
                1454 else
                1455     DEF_CHECK_LIST='admGrd admCst admGrd admFwd'
                1456     EMPTY_RESULTS='.. .. ..'
                1457     LEN_CHECK_LIST=`echo $DEF_CHECK_LIST | sed 's/ [a-zA-Z0-9]*+/&mn &mx &av &sd/g' | awk '{print NF-1}'`
eb7e5e62ed Jean*1458 fi
                1459 
2ff82eb834 Ed H*1460 #  create the FORTRAN comparison code
122c9245be Jean*1461 if test "x$CLEANUP" = xt -o -x tr_cmpnum ; then
ca6d5f1072 Jean*1462     echo "skipping comparison code build"
                1463 else
                1464     createcodelet
                1465 fi
2ff82eb834 Ed H*1466 
63e0800ef7 Jean*1467 #  build the mpack utility (if ADDRESSES = NONE, do it to test the build)
ee57712ddb Jean*1468 if test "x$ADDRESSES" = x -o "x$SENDCMD" != x ; then
7a89945018 Ed H*1469     echo "skipping mpack build"
                1470 else
9cfcd12778 Ed H*1471     build_mpack
ee57712ddb Jean*1472     if test "x$HAVE_MPACK" = xt ; then SENDCMD=$MPACK ; fi
9cfcd12778 Ed H*1473 fi
2ff82eb834 Ed H*1474 
                1475 #  Create a uniquely named directory to store results
e72086803c Jean*1476 CMDLINE=$0
6c32747881 Jean*1477 for xx in "$@" ; do nw=`echo $xx | wc -w`
27d53f6f29 Jean*1478     if test $nw = '1' ; then CMDLINE="$CMDLINE $xx" ; else
                1479       nb=`echo $xx | grep -c '='`
                1480       if test $nb = 0 ; then CMDLINE="$CMDLINE '$xx'"
                1481       else yy=`echo "$xx'" | sed "s/=/='/"` ;
                1482                              CMDLINE="$CMDLINE $yy" ; fi
                1483     fi
6c32747881 Jean*1484 done
2ff82eb834 Ed H*1485 MACH=`hostname`
7d86f89c7f Ed H*1486 UNAMEA=`uname -a`
2ff82eb834 Ed H*1487 DATE=`date +%Y%m%d`
54db3dc364 Ed H*1488 BASE="tr_"$MACH"_"$DATE"_"
065c45c70d Jean*1489 if test "x$OUTDIR" != x ; then
                1490     BASE="tr_"$OUTDIR"_"$DATE"_"
276c0f056b Jean*1491 else
fb06fe5592 Mart*1492    #short_name=`hostname -s | tr '[:upper:]' '[:lower:]'`
                1493    # hostname -s is not universal (does work on AIX system)
72af1157c6 Jean*1494     short_name=`hostname | sed 's/\..*$//' | tr '[:upper:]' '[:lower:]'`
276c0f056b Jean*1495     BASE="tr_"$short_name"_"$DATE"_"
065c45c70d Jean*1496 fi
2ff82eb834 Ed H*1497 DNUM=0
                1498 DRESULTS="$BASE$DNUM"
                1499 while test -e $DRESULTS ; do
                1500     DNUM=$(( $DNUM + 1 ))
                1501     DRESULTS="$BASE$DNUM"
                1502 done
                1503 mkdir $DRESULTS
                1504 RETVAL=$?
                1505 if test "x$RETVAL" != x0 ; then
002054e5e5 Ed H*1506     echo "ERROR: Can't create results directory \"./$DRESULTS\""
2ff82eb834 Ed H*1507     exit 1
                1508 fi
                1509 SUMMARY="$DRESULTS/summary.txt"
67e2869886 Ed H*1510 start_date=`date`
b46c5fdcd4 Ed H*1511 echo $start_date > $SUMMARY
e72086803c Jean*1512 echo 'run:' $CMDLINE >> $SUMMARY
                1513 echo 'on :' $UNAMEA  >> $SUMMARY
2ff82eb834 Ed H*1514 
893b53ecae Ed H*1515 of_path=
6d54cf9ca1 Ed H*1516 if test "x$OPTFILE" != xNONE ; then
                1517     if test -r $OPTFILE ; then
893b53ecae Ed H*1518         # get the path
                1519         path=${OPTFILE%/*}
                1520         if test "x$path" = x ; then
                1521             of_path=`pwd`
                1522         else
                1523             of_path=`( cd $path > /dev/null 2>&1 ; pwd )`
                1524         fi
                1525         file=${OPTFILE##*/}
                1526         OPTFILE=$of_path/$file
2995826769 Ed H*1527         cp $OPTFILE $DRESULTS
                1528         echo >> $SUMMARY
                1529         echo "  OPTFILE=$OPTFILE" >> $SUMMARY
893b53ecae Ed H*1530     else
7509d1d274 Jean*1531         echo | tee -a $SUMMARY
                1532         echo "ERROR: can't read OPTFILE=\"$OPTFILE\"" | tee -a $SUMMARY
2995826769 Ed H*1533         exit 1
2ff82eb834 Ed H*1534     fi
2995826769 Ed H*1535 else
                1536     echo >> $SUMMARY
935c582112 Jean*1537     echo "No \"OPTFILE\" was specified ; genmake2 found and uses:" >> $SUMMARY
                1538     #-note: to be filled later after 1rst run
6d54cf9ca1 Ed H*1539 fi
                1540 echo
                1541 echo >> $SUMMARY
6418c0ec62 Jean*1542 if test $KIND = 0 ; then
                1543     line_0=`printf '%s %2i' 'default' $MATCH_CRIT`
eb7e5e62ed Jean*1544        line_0="$line_0  ----T-----  ----S-----  ----U-----  ----V-----"
68c34fd102 Ed H*1545     line_1="G D M    c        m  s        m  s        m  s        m  s"
4d66dcbdcc Jean*1546     line_2="e p a R  g  m  m  e  .  m  m  e  .  m  m  e  .  m  m  e  ."
                1547     line_3="n n k u  2  i  a  a  d  i  a  a  d  i  a  a  d  i  a  a  d"
68c34fd102 Ed H*1548     line_4="2 d e n  d  n  x  n  .  n  x  n  .  n  x  n  .  n  x  n  ."
a18b9b1964 Ed H*1549     for ii in $PTRACERS_NUM ; do
68c34fd102 Ed H*1550         line_0="$line_0  --PTR 0"$ii"--"
                1551         line_1="$line_1        m  s"
                1552         line_2="$line_2  m  m  e  ."
                1553         line_3="$line_3  i  a  a  d"
                1554         line_4="$line_4  n  x  n  ."
                1555     done
6418c0ec62 Jean*1556 else
                1557   if test $KIND = 1 ; then
fb1e235660 Jean*1558     echo "TangLin generated by TAF" >> $SUMMARY
                1559   elif test $KIND = 2 ; then
                1560     echo "Adjoint generated by TAF" >> $SUMMARY
b4daa24319 Shre*1561   elif test $KIND = 4 ; then
                1562     echo "TangLin generated by Tapenade" >> $SUMMARY
                1563   elif test $KIND = 5 ; then
                1564     echo "Adjoint generated by Tapenade" >> $SUMMARY
fb1e235660 Jean*1565   else
                1566     echo "Adjoint generated by OpenAD" >> $SUMMARY
                1567   fi
d81415648f Jean*1568     line_0=`printf '%s %2i' 'default   ' $MATCH_CRIT`
b4daa24319 Shre*1569   if test $KIND = 1 -o $KIND = 4 ; then
6418c0ec62 Jean*1570     line_1="G D M    C  T  F"
                1571     line_2="e p a R  o  L  D"
                1572   else
                1573     line_1="G D M    C  A  F"
                1574     line_2="e p a R  o  d  D"
                1575   fi
                1576     line_3="n n k u  s  G  G"
                1577     line_4="2 d e n  t  r  r"
                1578     echo >> $SUMMARY
d81415648f Jean*1579   if test $KIND = 2 ; then
                1580     line_0=`printf '%s %2i   ' 'default   ' $MATCH_CRIT`
                1581     line_0="$line_0  ----T-----  ----S-----  ----U-----  ----V-----"
                1582     line_1="$line_1        m  s        m  s        m  s        m  s"
                1583     line_2="$line_2  m  m  e  .  m  m  e  .  m  m  e  .  m  m  e  ."
                1584     line_3="$line_3  i  a  a  d  i  a  a  d  i  a  a  d  i  a  a  d"
                1585     line_4="$line_4  n  x  n  .  n  x  n  .  n  x  n  .  n  x  n  ."
                1586   fi
6418c0ec62 Jean*1587 fi
122c9245be Jean*1588 if test "x$CLEANUP" != xt ; then
68c34fd102 Ed H*1589     echo "$line_0" | tee -a $SUMMARY
                1590     echo "$line_1" | tee -a $SUMMARY
                1591     echo "$line_2" | tee -a $SUMMARY
                1592     echo "$line_3" | tee -a $SUMMARY
                1593     echo "$line_4" | tee -a $SUMMARY
6418c0ec62 Jean*1594     echo ""        | tee -a $SUMMARY
122c9245be Jean*1595 fi
6fcdccb64d Jean*1596 echo "-------------------------------------------------------------------------------"
6d54cf9ca1 Ed H*1597 
13cadcbe59 Oliv*1598 allpass=t
                1599 
6d54cf9ca1 Ed H*1600 #  ...and each test directory...
                1601 for dir in $TESTDIRS ; do
9750e41317 Jean*1602 
7e8ef1f316 Jean*1603     # set builddir & rundir:
                1604     builddir="build"
                1605     if test ! -d $dir/$builddir ; then mkdir $dir/$builddir ; fi
                1606     rundir="run"
cecd4018b3 Jean*1607     pfxdir="tr_$rundir"
7e8ef1f316 Jean*1608     if test ! -d $dir/$rundir ; then
                1609         rundir=$builddir
                1610     fi
                1611     CODE_DIR=$dir/$code_dir
                1612     BUILD_DIR=$dir/$builddir
                1613 
6d54cf9ca1 Ed H*1614     #  Cleanup only!
                1615     if test "x$CLEANUP" = xt ; then
642fbd44e7 Jean*1616         echo -n '  --- dir:' $BUILD_DIR ': '
                1617         makeclean $BUILD_DIR
38c4b22527 Jean*1618         (   cd $BUILD_DIR
                1619             rm -f $EXECUTABLE *.bak
0093035fc0 Jean*1620             rm -f genmake_state genmake_*optfile genmake.log
d9ae4e2b34 Jean*1621             rm -f SIZE.h.mpi genmake.tr_log make.tr_log
e6f2a663b8 Jean*1622             rm -rf mpi_headers
38c4b22527 Jean*1623         )
9527bfb820 Jean*1624         if test -d $dir/$rundir ; then
6418c0ec62 Jean*1625             echo -n '  --- dir:' $dir/$rundir ': '
7e8ef1f316 Jean*1626             run_clean $dir/$rundir
1c1109930c Ed H*1627         fi
cecd4018b3 Jean*1628         trdir=`( cd $dir ; find . -type d -name "$pfxdir.*" -print | sed 's/^.\///')`
642fbd44e7 Jean*1629         ttd=`echo $trdir | wc -w`
                1630         if test $ttd != 0 ; then
                1631             echo '  --- rm dir:' $trdir
                1632             ( cd $dir ; rm -rf $trdir )
                1633         fi
6d54cf9ca1 Ed H*1634         continue
                1635     fi
1c1109930c Ed H*1636 
9750e41317 Jean*1637     #  Verify that the testdir exists and contains previous
6d54cf9ca1 Ed H*1638     #  results in the correct location--or skip this directory!
0d2e560266 Jean*1639     fout=$dir"/results/"$ref_outp
6418c0ec62 Jean*1640    #if test ! -r $fout ; then
                1641     if test ! -r $fout -a ! -r ${fout}.gz ; then
4619920a5f Ed H*1642         echo "can't read \"$fout\" -- skipping $dir"
6d54cf9ca1 Ed H*1643         continue
                1644     fi
2ff82eb834 Ed H*1645 
bef69cc95f Jean*1646     # Check for specific files for particular type of run
68c34fd102 Ed H*1647 
7ba778f1ca Jean*1648     if test ! -r $CODE_DIR"/SIZE.h_mpi"  -a "x$MPI" != "x0" ; then
                1649         echo "can't find \"$CODE_DIR/SIZE.h_mpi\" -- skipping $dir"
                1650         continue
                1651     fi
                1652     if test ! -r $dir"/input/eedata.mth" -a "x$MULTI_THREAD" = "xt" ; then
                1653         echo "can't find \"$dir/input/eedata.mth\" -- skipping $dir"
                1654         continue
                1655     fi
                1656 
d9ae4e2b34 Jean*1657     if test "x$MPI" != "x0" ; then
6c95586363 Jean*1658         ntx=1 ; nty=1
7ba778f1ca Jean*1659         if test "x$MULTI_THREAD" = "xt" ; then
54f370a421 Jean*1660           ff=$dir"/input/eedata.mth"
                1661           ntx=`grep "^ *nTx *=" $ff | tail -1 | sed 's/^ *nTx *= *//' | sed "s/, *$//"`
                1662           nty=`grep "^ *nTy *=" $ff | tail -1 | sed 's/^ *nTy *= *//' | sed "s/, *$//"`
                1663           if test "x$ntx" = x ; then ntx=1 ; fi
                1664           if test "x$nty" = x ; then nty=1 ; fi
d9ae4e2b34 Jean*1665         fi
7ba778f1ca Jean*1666         #- create new SIZE.h with no more than '$MPI' Procs
6c95586363 Jean*1667         mk_mpi_size $CODE_DIR"/SIZE.h_mpi" $BUILD_DIR"/tr_size.mpi" $MPI $ntx $nty
7ba778f1ca Jean*1668         LOC_NPROC=$?
                1669         (   cd $BUILD_DIR
                1670             if test -r SIZE.h.mpi ; then
                1671                 cmp tr_size.mpi SIZE.h.mpi > /dev/null 2>&1 ; RETVAL=$?
                1672             else RETVAL=1
                1673             fi
                1674             if test "x$RETVAL" = x0 ; then
                1675                 rm -f tr_size.mpi
                1676             else
                1677                 rm -f SIZE.h.mpi ; mv tr_size.mpi SIZE.h.mpi
                1678             fi
                1679         )
bbea11a65d Jean*1680         if test "x$MPI_MFILE" != x ; then
                1681             #- create new MPI machine-file with the right number of Procs
                1682             rm -f $LOC_MFILE
                1683             cat $MPI_MFILE | sort | uniq | head -$LOC_NPROC > $LOC_MFILE
                1684             nl=`wc -l $LOC_MFILE | awk '{print $1}'`
                1685             if [ $nl -lt $LOC_NPROC ] ; then
                1686                 rm -f $LOC_MFILE
                1687                 cat $MPI_MFILE | head -$LOC_NPROC > $LOC_MFILE
                1688                 #sed -n "1,$LOC_NPROC p" $MPI_MFILE > $LOC_MFILE
                1689             fi
                1690             if [ $verbose -gt 1 ]; then
                1691                 nl=`wc -l $LOC_MFILE | awk '{print $1}'`
                1692                 echo " new LOC_MFILE=$LOC_MFILE : $nl procs for LOC_NPROC=$LOC_NPROC"
                1693             fi
                1694         fi
7ba778f1ca Jean*1695         if test "x$MULTI_THREAD" = "xt" ; then
                1696             retv=`check_eedata $dir"/input/eedata.mth" $BUILD_DIR"/SIZE.h.mpi"`
                1697             if test $retv != 0 ; then
                1698                 echo "input/eedata.mth tiling misfit -- skipping $dir"
                1699                 continue
                1700             fi
d9ae4e2b34 Jean*1701         fi
0179fa2c74 Jean*1702     fi
0e6cc40375 Jean*1703 
                1704     #  Check whether there are "extra runs" for this testdir
                1705     extra_runs=
ca6d5f1072 Jean*1706     if test "x$NORUN" = xf ; then
fedbb6c3d7 Jean*1707         ex_run_dirs=`( cd $dir ; ls -d $inputdir.* 2> /dev/null )`
ca6d5f1072 Jean*1708     fi
878c588496 Jean*1709     #echo "ex_run_dirs='$ex_run_dirs'"
                1710     for exd in $ex_run_dirs ; do
                1711         name=`echo $exd | sed -e "s/$inputdir\.//"`
                1712         refExOut=`echo $ref_outp | sed "s/\./.${name}./"`
                1713         outf="$dir/results/$refExOut"
6418c0ec62 Jean*1714         if test -r $outf -o -r ${outf}.gz ; then
9750e41317 Jean*1715           if test "x$MULTI_THREAD" = "xt" ; then
0179fa2c74 Jean*1716             if test -r $dir"/"$exd"/eedata.mth" ; then
d9ae4e2b34 Jean*1717               if test "x$MPI" = "x0" ; then
                1718                 extra_runs="$extra_runs $name"
                1719               else
7ba778f1ca Jean*1720                 retv=`check_eedata $dir"/"$exd"/eedata.mth" $BUILD_DIR"/SIZE.h.mpi"`
0179fa2c74 Jean*1721                 if test $retv = 0 ; then
0e6cc40375 Jean*1722                     extra_runs="$extra_runs $name"
0179fa2c74 Jean*1723                 else
                1724                     echo $exd"/eedata.mth tiling misfit -- skipping $dir"
0e6cc40375 Jean*1725                 fi
0179fa2c74 Jean*1726               fi
                1727             #else echo $dir"/"$exd"/eedata.mth: not found"
0e6cc40375 Jean*1728             fi
0179fa2c74 Jean*1729           else
                1730             extra_runs="$extra_runs $name"
                1731           fi
878c588496 Jean*1732         fi
                1733     done
b0b995d6ae Ed H*1734 
                1735     echo
9750e41317 Jean*1736     if test "x$extra_runs" = "x" ; then
6418c0ec62 Jean*1737         echo "Experiment:  $dir"
0e6cc40375 Jean*1738     else
6418c0ec62 Jean*1739         echo "Experiment:  $dir ; extra_runs=$extra_runs"
0e6cc40375 Jean*1740     fi
b0b995d6ae Ed H*1741     echo
                1742     unset genmake makedepend make run
eb7e5e62ed Jean*1743     results=$EMPTY_RESULTS
b0b995d6ae Ed H*1744 
360fa2f691 Jean*1745     #  Create an output dir & summary.txt file for each tested experiment (tdir)
577d52ba66 Jean*1746     locDIR=$DRESULTS"/"$dir
                1747     mkdir $locDIR
360fa2f691 Jean*1748     #- report to this experiment local summary file ---
                1749     echo "DATE='$DATE' ; tdir='$dir'" > $locDIR"/summary.txt"
                1750     echo "MACH='$MACH'" >> $locDIR"/summary.txt"
                1751     echo "UNAMEA='$UNAMEA'" >> $locDIR"/summary.txt"
577d52ba66 Jean*1752     CDIR=`pwd`"/$locDIR"
9750e41317 Jean*1753 
ca6d5f1072 Jean*1754     if test "x$NORUN" = xt ; then
                1755             run=N
                1756         genmakemodel $dir/$builddir && genmake=Y \
                1757             && makeclean $dir/$builddir \
6418c0ec62 Jean*1758             && symlink_mpifiles $dir $code_dir $builddir \
ca6d5f1072 Jean*1759             && makedependmodel $dir/$builddir && makedepend=Y \
                1760             && makemodel $dir/$builddir && make=Y
c67b26333b Jean*1761             echo
6d54cf9ca1 Ed H*1762     else
2ff82eb834 Ed H*1763         genmakemodel $dir/$builddir && genmake=Y \
                1764             && makeclean $dir/$builddir \
6418c0ec62 Jean*1765             && symlink_mpifiles $dir $code_dir $builddir \
2ff82eb834 Ed H*1766             && makedependmodel $dir/$builddir && makedepend=Y \
                1767             && makemodel $dir/$builddir && make=Y \
6fcdccb64d Jean*1768             && run_clean $dir/$rundir \
abed800b6d Jean*1769             && linkdata $dir/$rundir $inputdir \
474019363f Ed H*1770             && runmodel $dir/$rundir && run=Y \
6d41b7da3e Jean*1771             && results=`testoutput_run $dir $rundir $ref_outp`
c67b26333b Jean*1772             echo 1>&2
6d54cf9ca1 Ed H*1773     fi
ca6d5f1072 Jean*1774     #echo "results='$results'"
6fcdccb64d Jean*1775 
4619920a5f Ed H*1776         fres=`formatresults $dir ${genmake:-N} ${makedepend:-N} ${make:-N} ${run:-N} $results`
6418c0ec62 Jean*1777         echo "$fres" | sed 's/ 99/ --/g' | sed 's/  > />/' | sed 's/  < /</' >> $SUMMARY
577d52ba66 Jean*1778         echo "fresults='$fres'" | sed 's/ 99/ --/g' >> $locDIR"/summary.txt"
13cadcbe59 Oliv*1779         if [[ ! "$fres" =~ " pass " ]]; then
                1780             allpass=f
                1781         fi
e53112a6cf Ed H*1782 
                1783         for ex in $extra_runs ; do
c6cea69b38 Jean*1784             unset run
6418c0ec62 Jean*1785             results=$EMPTY_RESULTS
7e8ef1f316 Jean*1786             #  reference output file
                1787             refExOut=`echo $ref_outp | sed "s/\./.${ex}./g"`
360fa2f691 Jean*1788             #  Create an output dir & summary.txt file for each extra run (tdir.ex)
577d52ba66 Jean*1789             locDIR=$DRESULTS"/"$dir"."$ex
                1790             mkdir $locDIR
360fa2f691 Jean*1791             #- report to this experiment local summary file ---
                1792             echo "DATE='$DATE' ; tdir='$dir.$ex'" > $locDIR"/summary.txt"
                1793             #echo "MACH='$MACH'" >> $locDIR"/summary.txt"
                1794             #echo "UNAMEA='$UNAMEA'" >> $locDIR"/summary.txt"
577d52ba66 Jean*1795             CDIR=`pwd`"/$locDIR"
cecd4018b3 Jean*1796             test ! -e "$dir/$pfxdir.$ex" && mkdir "$dir/$pfxdir.$ex"
                1797             run_clean $dir/$pfxdir.$ex
                1798             linkdata $dir/$pfxdir.$ex $inputdir.$ex $inputdir
                1799             runmodel $dir/$pfxdir.$ex && run=Y \
                1800             && results=`testoutput_run $dir $pfxdir.$ex $refExOut`
c67b26333b Jean*1801             echo 1>&2
cc019522d9 Jean*1802 
f561fdaba7 Jean*1803             fres=`formatresults $dir.$ex ${genmake:-N} ${makedepend:-N} ${make:-N} ${run:-N} $results`
c5e604105c Jean*1804             echo "$fres" | sed 's/ 99/ --/g' | sed 's/  > />/' | sed 's/  < /</' >> $SUMMARY
577d52ba66 Jean*1805             echo "fresults='$fres'" | sed 's/ 99/ --/g' >> $locDIR"/summary.txt"
13cadcbe59 Oliv*1806             if [[ ! "$fres" =~ " pass " ]]; then
                1807                 allpass=f
                1808             fi
bbea11a65d Jean*1809             if test "x$POSTCLEAN" = x2 ; then
cecd4018b3 Jean*1810                 run_clean $dir/$pfxdir.$ex
0e6cc40375 Jean*1811             fi
e53112a6cf Ed H*1812         done
0b035b108c Ed H*1813 
6aa14c32e4 Jean*1814     if test ! -f $DRESULTS"/"genmake_state ; then
c14ab91977 Jean*1815         if test -f $dir/$builddir/Makefile ; then
                1816             mkOpt=`grep '^# OPTFILE=' $dir/$builddir/Makefile 2>/dev/null | head -1 | sed 's/^# //'`
                1817             echo "from '$dir/$builddir/Makefile', extract:" > $DRESULTS/genmake_state
fb06fe5592 Mart*1818 #           sed -n '/^# executed by:/,+1 p' $dir/$builddir/Makefile >> $DRESULTS/genmake_state
                1819 # bsd-sed cannot do the above code
                1820             cat $dir/$builddir/Makefile | \
deb0ad3aea Mart*1821                 sed -n '/^# executed by:/{N
                1822                                           p
                1823                                           }' >> $DRESULTS/genmake_state
fe7601e9ab Jean*1824             echo " $mkOpt" >> $DRESULTS/genmake_state
935c582112 Jean*1825             if test "x$OPTFILE" = xNONE ; then
                1826                 eval $mkOpt
fb06fe5592 Mart*1827 #               sed "/^No \"OPTFILE\" was specified ; genmake2/a\  OPTFILE=${OPTFILE}"\
                1828 #                       $SUMMARY > tmp.tr_log
                1829 # bsd-sed requires a newline after "a\":
                1830                 sed "/^No \"OPTFILE\" was specified ; genmake2/a\\
                1831                          OPTFILE=${OPTFILE}" $SUMMARY > tmp.tr_log
935c582112 Jean*1832                 RETVAL=$?
ee57712ddb Jean*1833                 if test "x$RETVAL" = x0 ; then
                1834                     cp -f tmp.tr_log $SUMMARY
935c582112 Jean*1835                 fi
ee57712ddb Jean*1836                 rm -f tmp.tr_log
935c582112 Jean*1837             fi
497802755c Jean*1838             gmkLog=$dir/$builddir/genmake.log
6aa14c32e4 Jean*1839             if test -r $gmkLog ; then
                1840                 grep '^Get compiler version using:' $gmkLog > /dev/null 2>&1
                1841                 RETVAL=$?
                1842                 if test "x$RETVAL" = x0 ; then
8188c8aec7 Jean*1843                   echo -n "from '$gmkLog', "    >> $DRESULTS/genmake_state
6aa14c32e4 Jean*1844                   echo "extract compiler version:"   >> $DRESULTS/genmake_state
                1845                   sed -n '/Get compiler version/,/<-- compiler version/p' \
                1846                      $gmkLog | grep -v '^... compiler version ' > tmp.tr_log
8188c8aec7 Jean*1847                   sed -n '1p' tmp.tr_log        >> $DRESULTS/genmake_state
6aa14c32e4 Jean*1848                   sed -n '2,/^$/p' tmp.tr_log | sed '/^$/d' | sed 's/^./ &/' \
8188c8aec7 Jean*1849                                                 >> $DRESULTS/genmake_state
6aa14c32e4 Jean*1850                   rm -f tmp.tr_log
                1851                 fi
516b08a580 jm-c 1852                 grep ' set FC_CHECK=' $gmkLog   >> $DRESULTS/genmake_state
b48bc6023a Jean*1853             fi
e1cc724aa4 Jean*1854             if test $KIND = 1 -o  $KIND = 2 ; then
                1855               gmkLog=$dir/$builddir/taf_ad.log
                1856               if test $KIND = 1 ; then gmkLog=$dir/$builddir/taf_ftl.log ; fi
                1857               if test -f $gmkLog ; then
                1858                 echo -n "from '$gmkLog', get: " >> $DRESULTS/genmake_state
                1859                 head -1 $gmkLog | sed 's/^.*Algorithms in Fortran //' \
                1860                                                 >> $DRESULTS/genmake_state
                1861                 ADvers=`head -1 $gmkLog | awk '{print $7,$8}'`
                1862                 sed "s/ by TAF/ by TAF $ADvers/" $SUMMARY > tmp.tr_log
                1863                 mv -f tmp.tr_log $SUMMARY
                1864               fi
                1865             fi
                1866             if test $KIND = 4 -o  $KIND = 5 ; then
                1867               gmkLog=$dir/$builddir/make.tr_log
                1868               if test -f $gmkLog ; then
                1869                 ADtool=`grep '^Tapenade ' $gmkLog | tail -n 1`
                1870                 echo "from '$gmkLog', get: $ADtool" >> $DRESULTS/genmake_state
212a55051e Jean*1871                 ADvers=`echo $ADtool | awk '{print $2,$3}'`
                1872                 sed "s/ by Tapenade/ by Tapenade $ADvers/" $SUMMARY > tmp.tr_log
e1cc724aa4 Jean*1873                 mv -f tmp.tr_log $SUMMARY
                1874               fi
                1875             fi
b48bc6023a Jean*1876             gmkLog=$dir/$builddir/genmake_state
                1877             if test -r $gmkLog ; then
8188c8aec7 Jean*1878                 echo -n "from '$gmkLog', "      >> $DRESULTS/genmake_state
                1879                 echo "get genmake settings:"    >> $DRESULTS/genmake_state
b48bc6023a Jean*1880                 sed -n '/^HAVE_/p' $gmkLog | sed 's/^./ &/' \
                1881                                                 >> $DRESULTS/genmake_state
8188c8aec7 Jean*1882                 sed -n '/^THIS[A-Z]*=/p' $gmkLog >> $DRESULTS/genmake_state
497802755c Jean*1883             fi
c14ab91977 Jean*1884         fi
                1885     fi
0e6cc40375 Jean*1886     #postclean $dir/$builddir
bbea11a65d Jean*1887     if test "x$POSTCLEAN" = x2 ; then
6418c0ec62 Jean*1888         makeclean $dir/$builddir \
                1889             && run_clean $dir/$rundir
0e6cc40375 Jean*1890     fi
bbea11a65d Jean*1891     if test "x$MPI" != x0 -a "x$MPI_MFILE" != x ; then rm -f $LOC_MFILE ; fi
9750e41317 Jean*1892 
6d54cf9ca1 Ed H*1893     echo "-------------------------------------------------------------------------------"
9750e41317 Jean*1894 
2ff82eb834 Ed H*1895 done
e05307b8c4 Jean*1896 grep '^HAVE_LAPACK' */$builddir/genmake_state 2> /dev/null \
                1897                         | head -1 >> $DRESULTS/genmake_state
2ff82eb834 Ed H*1898 
e53112a6cf Ed H*1899 printf "Start time:  " >> $SUMMARY
97166278cd Jean*1900 echo "$start_date" >> $SUMMARY
e53112a6cf Ed H*1901 printf "End time:    " >> $SUMMARY
e5e26554e5 Ed H*1902 date >> $SUMMARY
                1903 
002054e5e5 Ed H*1904 #  If addresses were supplied and mpack built successfully, then try
                1905 #  to send email using mpack.
                1906 if test "x$ADDRESSES" = xNONE -o "x$ADDRESSES" = x ; then
                1907     echo "No results email was sent."
                1908 else
ee57712ddb Jean*1909     if test "x$SENDCMD" != x ; then
30f4fad812 Jean*1910         SendOpt='' ; headCMD=`echo $SENDCMD | awk '{print $1}'`
                1911         if test $headCMD != 'scp' ; then SendOpt='-s MITgcm-test -m 3555000' ; fi
ee57712ddb Jean*1912         if [ $verbose -gt 1 ]; then
30f4fad812 Jean*1913            echo " run: $SENDCMD $SendOpt ${SAVDIR}/${DRESULTS}".tar.gz" $ADDRESSES"
ee57712ddb Jean*1914         fi
                1915         tar -cf ${SAVDIR}/${DRESULTS}".tar" $DRESULTS > /dev/null 2>&1 \
                1916             && gzip ${SAVDIR}/${DRESULTS}".tar" \
30f4fad812 Jean*1917             && $SENDCMD $SendOpt ${SAVDIR}/${DRESULTS}".tar.gz" $ADDRESSES
002054e5e5 Ed H*1918         RETVAL=$?
                1919         if test "x$RETVAL" != x0 ; then
                1920             echo
30f4fad812 Jean*1921             echo "Warning: The tar, gzip, & $SENDCMD step failed.  Please send email"
002054e5e5 Ed H*1922             echo "  to <MITgcm-support@mitgcm.org> for help.  You may copy the "
                1923             echo "  summary of results from the directory \"$DRESULTS\"."
                1924             echo
                1925         else
                1926             echo
                1927             echo "An email containing results was sent to the following addresses:"
                1928             echo "  \"$ADDRESSES\""
                1929             echo
ee57712ddb Jean*1930             test -f ${SAVDIR}/${DRESULTS}".tar" &&  rm -f ${SAVDIR}/${DRESULTS}".tar"
                1931             test -f ${SAVDIR}/${DRESULTS}".tar.gz" &&  rm -f ${SAVDIR}/${DRESULTS}".tar.gz"
002054e5e5 Ed H*1932         fi
                1933     fi
                1934 fi
                1935 
ca6d5f1072 Jean*1936 if test "x$QUICK" = xf -a "x$NORUN" = xf ; then
                1937     rm -f tr_cmpnum.c tr_cmpnum
                1938 fi
2ff82eb834 Ed H*1939 
474019363f Ed H*1940 if test "x$CLEANUP" != xt ; then
3de6a095b5 Jean*1941     cat $SUMMARY | sed 's/ \.  \.  \.  \.  \.  \.  \.  \.  \.  \.  \.  \. //'
54db3dc364 Ed H*1942     if test -e tr_out.txt ; then
6418c0ec62 Jean*1943         mv tr_out.txt tr_out.txt.old
5ac39639c8 Ed H*1944     fi
456c314cce Jean*1945     cat $SUMMARY | sed '/^[YN] [YN] [YN] [YN]/ s/ \. //g' > tr_out.txt
474019363f Ed H*1946 fi
2ff82eb834 Ed H*1947 
384dccb29e Ed H*1948 if test "x$DELDIR" = xt ; then
                1949     rm -rf $DRESULTS
                1950 fi
13cadcbe59 Oliv*1951 
                1952 if test "$CHECK_PASS" = t && test "$allpass" = f; then
                1953     exit 1
                1954 fi
                1955 
122c9245be Jean*1956 echo "======== End of testreport execution ========"