Back to home page

MITgcm

 
 

    


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

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