/[MITgcm]/MITgcm/verification/testreport
ViewVC logotype

Diff of /MITgcm/verification/testreport

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.1 by edhill, Wed Aug 27 22:12:31 2003 UTC revision 1.179 by jmc, Thu Aug 23 02:01:27 2012 UTC
# Line 1  Line 1 
1  #!/bin/bash  #! /usr/bin/env bash
2  #  #
3  #  $Header$  #  $Header$
4    #  $Name$
5  #  #
6    
7  usage()  usage()
# Line 10  usage() Line 11  usage()
11      echo      echo
12      echo "where possible OPTIONS are:"      echo "where possible OPTIONS are:"
13      echo "  (-help|-h)               print usage"      echo "  (-help|-h)               print usage"
14      echo "  (-optfile=|-of=)STRING   list of genmake2 \"optfiles\""      echo "  (-mth)                   run multi-threaded (using eedata.mth)"
15      echo "  (-a|-addr)STRING         list of email recipients"      echo "  (-mpi)                   use MPI to compile and run on 2 processors"
16      echo "  (-t|-tdir)STRING         list of \"test\" dirs"      echo "  (-MPI)  NUMBER           use MPI to compile and run on max NUMBER procs"
17        echo "  (-mfile|-mf) STRING      MPI: file with list of possible machines to run on"
18        echo "  (-fast)                  use optfile default for compiler flags (no '-ieee')"
19        echo "                            DEF=off => use IEEE numerics option (if available)"
20        echo "  (-devel)                 use optfile developement flags (if available)"
21        echo "  (-gsl)                   compile with \"-gsl\" flag"
22        echo "  (-use_r4|-ur4)           if allowed, use real*4 type for '_RS' variable"
23        echo "  (-optfile|-of) STRING    list of optfiles to use"
24        echo "  (-addr|-a) STRING        list of email recipients"
25        echo "                             (DEF=\"\" no email is sent)"
26        echo "  (-mpackdir|-mpd) DIR     location of the mpack utility"
27        echo "                             (DEF=\"../tools/mpack-1.6\")"
28        echo "  (-tdir|-t) STRING        list of group and/or exp. dirs to test"
29        echo "                             (recognized groups: basic, tutorials)"
30        echo "                             (DEF=\"\" which test all)"
31        echo "                             (if list= 'start_from THIS_EXP' then"
32        echo "                              test THIS_EXP + all the following)"
33        echo "  (-skipdir|-skd) STRING   list of exp. dirs to skip"
34        echo "                             (DEF=\"\" which test all)"
35        echo "  (-bash|-b) STRING        preferred location of a \"bash\" or"
36        echo "                             Bourne-compatible \"sh\" shell"
37        echo "                             (DEF=\"\" for \"bash\")"
38        echo "  (-tlm)                   perform a Tangent Linear run"
39        echo "  (-adm|-ad)               perform an adjoint run"
40        echo "  (-oad)                   perform an OpenAD adjoint run"
41        echo "  (-command|-c) STRING     command to run"
42        echo "  (-makedepend|-md) STRING command to use for \"makedepend\""
43        echo "  (-make|-m) STRING        command to use for \"make\""
44        echo "                             (DEF=\"make\")"
45        echo "  (-odir) STRING           used to build output directory name"
46        echo "                             (DEF=\"hostname\")"
47    #   echo "  (-ptracers|-ptr) STRING  specify which ptracers to test"
48    #   echo "                             (DEF=\"1 2 3 4 5\")"
49        echo "  (-match) NUMBER          Matching Criteria (number of digits)"
50        echo "                             (DEF=\"$MATCH_CRIT\")"
51        echo "  (-j) JOBS                use \"make -j JOBS\" for parallel builds"
52        echo "  (-ef) STRING             used as genmake2 \"-extra_flag\" argument"
53        echo "  (-clean)                 *ONLY* run \"make CLEAN\" & clean run-dir"
54        echo "  (-norun|-nr)             skip the \"runmodel\" stage (stop after make)"
55        echo "  (-obj)                   only produces objects (=norun & no executable)"
56        echo "  (-runonly|-ro)           *ONLY* run stage (=\"-quick\" without make)"
57        echo "  (-quick|-q)              same as \"-nogenmake -noclean -nodepend\""
58        echo "  (-nogenmake|-ng)         skip the genmake stage"
59        echo "  (-noclean|-nc)           skip the \"make clean\" stage"
60        echo "  (-nodepend|-nd)          skip the \"make depend\" stage"
61        echo "  (-postclean|-pc)         after each exp. test, clean build-dir & run-dir"
62        echo "  (-deloutp|-do)           delete output files after successful run"
63        echo "  (-deldir|-dd)            on success, delete the output directory"
64        echo "  (-ts)                    provide timing information per timestep"
65        echo "  (-papis)                 provide MFlop/s per timestep using PAPI"
66        echo "  (-pcls)                  provide MFlop/s per timestep using PCL"
67        echo
68        echo "and where STRING can be a whitespace-delimited list"
69        echo "such as:"
70        echo
71        echo "  -t 'exp0 exp2 exp3' "
72        echo "  -addr='abc@123.com testing@home.org'"
73        echo
74        echo "provided that the expression is properly quoted within the current"
75        echo "shell (note the use of single quotes to protect white space)."
76      echo      echo
77      exit 1      exit 1
78  }  }
# Line 20  usage() Line 80  usage()
80  #  build the mpack utility  #  build the mpack utility
81  build_mpack()  build_mpack()
82  {  {
83      echo -n "building the mpack utility...  "      printf "building the mpack utility...  "
84      if test ! -x "$MPACKDIR/mpack" ; then      MPACK="$MPACKDIR/mpack"
85        if test ! -x $MPACK ; then
86          if test ! -d $MPACKDIR ; then          if test ! -d $MPACKDIR ; then
87                echo
88              echo "Error: can't find \"$MPACKDIR\""              echo "Error: can't find \"$MPACKDIR\""
89              echo "  are you sure this program is being run in the correct "              echo "  are you sure this program is being run in the correct "
90              echo "  (that is, \"MITGCM_ROOT\verification\") directory?"              echo "  (that is, \"MITGCM_ROOT\verification\") directory?"
91              exit 1              echo
92                HAVE_MPACK=f
93          fi          fi
94          echo -n "building mpack...  "          if test "x$CC" = x ; then
95          ( cd $MPACKDIR && ./configure && make ) > build_mpack.out 2>&1              export CC=cc
96            fi
97            printf "building mpack (using CC=$CC)...  "
98            ( cd $MPACKDIR && ./configure && $MAKE ) > tr_build_mpack.out 2>&1
99          RETVAL=$?          RETVAL=$?
100          if test "x$RETVAL" != x0 ; then          if test "x$RETVAL" != x0 ; then
101              echo              echo
102              echo "Error building the mpack tools at: $MPACK_DIR"              echo "Error building the mpack tools at: $MPACK_DIR"
103              exit 1              echo
104                HAVE_MPACK=f
105            else
106                rm -f tr_build_mpack.out
107                HAVE_MPACK=t
108                echo "done"
109          fi          fi
110        else
111            HAVE_MPACK=t
112            echo "already exist"
113      fi      fi
     echo "OK"  
 }  
   
 compare_lines()  
 {  
     # use codelet to compare lines  
     if [ $verbose -gt 1 ]; then  
         cat tmp3.txt 1>&2  
     fi  
     return `./a.out < tmp3.txt`  
114  }  }
115    
116  testoutput_for_prop()  testoutput_var()
117  {  {
118      # testoutput_for_prop dir s1 label subdir      # testoutput_var dir s1 label subdir reference_output
119      #      #
120      #  compares files in $dir/$subdir/output.txt and $dir/results/output.txt      #  compares 1 variable output selected from file $dir/$subdir/$OUTPUTFILE
121      #  using search strings s1 and text label      #     with same output from reference file $dir/$reference_output
122        #  using search strings s1 and text label
123    
124      if [ $debug -gt 0 ]; then      if [ $debug -gt 0 ]; then
125          echo testoutput_for_prop: grep "$2" $1/$4/output.txt 1>&2          echo testoutput_var: grep "$2" $1/$4/$OUTPUTFILE 1>&2
126      fi      fi
127      if [ -r $1/$4/output.txt ]; then      if [ -r $1/$4/$OUTPUTFILE ]; then
128          grep "$2" $1/$4/output.txt | sed 's/.*=//' | nl > tmp1.txt          grep "$2" $1/$4/$OUTPUTFILE | sed 's/.*=//' | cat -n > tmp1.txt
129          lncnt=`wc -l tmp1.txt | awk '{print $1}' `          lncntA=`wc -l tmp1.txt | awk '{print $1}' `
130          if [ $lncnt -lt 3 ]; then          if [ $lncntA -lt 2 ]; then
131              if [ $verbose -gt 0 ]; then              if [ $verbose -gt 0 ]; then
132                  echo Not enough lines of output when searching for "$2" 1>&2                  echo Not enough lines of output when searching for "$2" 1>&2
133              fi              fi
134              return 99              rm -f tmp1.txt ; return 99
135          fi          fi
136      else      else
137          echo testoutput_for_prop: output.txt from model run was not readable 1>&2          echo testoutput_var: $OUTPUTFILE from model run was not readable 1>&2
138          return 99          return 99
139      fi      fi
140      if [ $debug -gt 0 ]; then      if [ $debug -gt 0 ]; then
141          echo testoutput_for_prop: grep "$2" $1/results/output.txt 1>&2          echo testoutput_var: grep "$2" $1/$5 1>&2
142      fi      fi
143      grep "$2" $1/results/output.txt | sed 's/.*=//' | nl > tmp2.txt      grep "$2" $1/$5 | sed 's/.*=//' | cat -n > tmp2.txt
144      lncnt=`wc -l tmp2.txt | awk '{print $1}' `      lncntB=`wc -l tmp2.txt | awk '{print $1}' `
145      if [ $lncnt -lt 3 ]; then      if [ $lncntB -lt 2 ]; then
146          if [ $verbose -gt 0 ]; then          if [ $verbose -gt 0 ]; then
147              echo Not enough lines of output when searching for "$2" 1>&2              echo Not enough lines of output when searching for "$2" 1>&2
148          fi          fi
149          return 99          rm -f tmp1.txt tmp2.txt ; return 99
150        fi
151        if [ $lncntA -ne $lncntB ]; then
152            if [ $verbose -gt 0 ]; then
153                echo Not same Nb of lines when searching for "$2" ":" $lncntA $lncntB 1>&2
154            fi
155            rm -f tmp1.txt tmp2.txt ; return 99
156        fi
157        has_nan=`cat tmp1.txt | grep -i nan | wc -l`
158        if [ $has_nan -gt 0  ] ; then
159            echo testoutput_var: $OUTPUTFILE contains $has_nan NaN values  1>&2
160            rm -f tmp1.txt tmp2.txt ; return 99
161        fi
162        has_inf=`cat tmp1.txt | grep -i inf | wc -l`
163        if [ $has_inf -gt 0  ] ; then
164            echo testoutput_var: $OUTPUTFILE contains $has_inf Inf values  1>&2
165            rm -f tmp1.txt tmp2.txt ; return 99
166      fi      fi
167      if [ $debug -gt 0 ]; then      if [ $debug -gt 0 ]; then
168          echo testoutput_for_prop: join tmp1.txt tmp2.txt 1>&2          echo testoutput_var: join tmp1.txt tmp2.txt 1>&2
169      fi      fi
170      join tmp1.txt tmp2.txt | awk '{print $1 " " $2 " " $3}' > tmp3.txt      join tmp1.txt tmp2.txt | awk '{print $1 " " $2 " " $3}' > tmp3.txt
171      if [ $debug -gt 0 ]; then      if [ $debug -gt 0 ]; then
172          echo testoutput_for_prop: compare_lines 1>&2          echo testoutput_var: compare_lines 1>&2
173      fi      fi
174      compare_lines      if [ $verbose -gt 1 ]; then
175      digits_of_similarity=$?          cat tmp3.txt 1>&2
176        fi
177        echo "-1" >> tmp3.txt
178        # On the SGI O3K (*not* the O2K), "cat -n" inserts a ":" after the line number
179        cat tmp3.txt | sed -e 's|:||g' > tmp4.txt
180        digits_of_similarity=`./tr_cmpnum < tmp4.txt`
181      if [ $digits_of_similarity -eq 99 ]; then      if [ $digits_of_similarity -eq 99 ]; then
182          if [ $verbose -gt 0 ]; then          if [ $verbose -gt 0 ]; then
183              echo testoutput_for_prop: No comparison was available for \"$2\" 1>&2              echo testoutput_var: No comparison was available for \"$3\" 1>&2
184          fi          fi
185          digits_of_similarity=99          digits_of_similarity=99
186      else      else
187          if [ $verbose -gt 0 ]; then          if [ $verbose -gt 0 ]; then
188              echo There were $digits_of_similarity decimal places of similarity for \"$2\" 1>&2              echo There were $digits_of_similarity decimal places of similarity for \"$3\" 1>&2
189          fi          fi
190      fi      fi
191      rm tmp1.txt tmp2.txt tmp3.txt      rm -f tmp1.txt tmp2.txt tmp3.txt tmp4.txt
192        
193      return $digits_of_similarity      return $digits_of_similarity
194  }  }
195    
196  dashnum()  testoutput_run()
197  {  {
198      # dashnum n1 n2 n3 ...      # testoutput_run directory subdir reference_output
199      #      #
200      #  print numbers using %3i format or "--" if number = 99      #  test output from 1 run in "directory"
201    # --> same processing for adjoint & forward test
202      for num in $@ ; do          # default list of output variables to be checked:
203          if [ $num = 99 ]; then          #  1rst : main variable used to decide if it pass or FAIL
204              printf ' --'          #  others : number of matching digits to be printed in summary.txt
205          else          listChk=$DEF_CHECK_LIST
206              printf '%3i' $num          #  load experiment-specific list from file "tr_checklist" (if it exist)
207            if test -r $1/$2/tr_checklist ; then listChk=`cat $1/$2/tr_checklist` ; fi
208            sVar=`echo $listChk | awk '{print $1}'`
209            # remove 1rst var and expand the list: + => min max mean s.d
210            listVar=`echo $listChk | sed 's/ [a-zA-Z0-9]*+/&mn &mx &av &sd/g' \
211                                   | sed 's/+//g' | sed "s/^$sVar//"`
212            if [ $debug -gt 0 ]; then echo "testoutput_run: listVar(I)='$listVar'" 1>&2 ; fi
213            # set ref.outp file-name and, if compressed, uncompress it into subdir
214            refoutp=results/$3
215            if test ! -r $1/results/$3 ; then
216              if test -r $1/results/${3}.gz ; then
217                tmpNam1=$3
218                tmpNam2=`echo $tmpNam1 | sed 's/\..*\././'`
219                if test "x$tmpNam1" = "x$tmpNam2" ; then
220                    tmpNam1=`echo $tmpNam2 | sed 's/\./.std./'`
221                fi
222                refoutp=$2/$tmpNam1
223                if [ $debug -gt 0 ]; then
224                    echo "testoutput_run: gunzip 'results/$3.gz' into '$refoutp'" 1>&2
225                fi
226                gzip -cd $1/results/${3}.gz > $1/$refoutp
227              else
228                echo "missing reference output file '$3' (.gz) in '$1/results/'"
229              fi
230          fi          fi
231      done          # check for ptracer output in reference_output file :
232  }          if test $KIND = 0 ; then
233              ptr_mon="trcstat_ptracerXX_min trcstat_ptracerXX_max"
234  testoutput()            ptr_mon="$ptr_mon trcstat_ptracerXX_mean trcstat_ptracerXX_sd"
235  {            for ii in $PTRACERS_NUM ; do
236      # testoutput diretory subdir              ptrfound=0
237      #              for jj in $ptr_mon ; do
238      #  test output in "directory"                  name=`eval "echo $jj | sed -e 's|XX|0"$ii"|g'"`
239                    tst=`grep $name $1/$refoutp | wc -l | awk '{print $1}'`
240                    if test ! "x$tst" = x0 ; then ptrfound=1 ; fi
241                done
242                if test $ptrfound = '1' ; then
243                    eval "HAVE_PTR0"$ii"=t"
244                else
245                    eval "HAVE_PTR0"$ii"=f"
246                  # remove this ptr from the list of output variable to check
247                  # echo "-- ptr test=" $tst "number of var=" `echo $listVar | awk '{print NF}'` 1>&2
248                    listVar=`echo "$listVar" | sed "s/ pt$ii..//g"`
249                fi
250              # eval 'echo "HAVE_PTR0'$ii' = $HAVE_PTR0'$ii'"' 1>&2
251              done
252            fi
253            tst=`echo $sVar $listVar | awk '{ for(i=2;i<=NF;i++){if($i==$1)t+=1}; print t }'`
254            if test $tst != 1 ; then
255              if test $tst = 0 ; then echo "==> WARNING: selected var >$sVar< not found" 1>&2
256                     else echo "==> WARNING: found selected var >$sVar< $tst times" 1>&2 ; fi
257              echo "==> WARNING: in checked list:" $listVar 1>&2
258            #- put it back once:
259              listVar=" $sVar "`echo "$listVar " | sed "s/ $sVar / /g"`
260            fi
261            if [ $debug -gt 0 ]; then echo "testoutput_run: listVar(M)='$listVar'" 1>&2 ; fi
262            echo "listVar='$listVar'" >> $locDIR"/summary.txt"
263            #---
264            allargs=""
265            for xx in $listVar
266            do
267              case $xx in
268               'PS')  if [ $debug -gt 0 ]
269                      then echo testoutput_run: testoutput_var $1 cg2d_init_res 1>&2 ; fi
270                      testoutput_var $1 "cg2d_init_res" "Press. Solver (cg2d)" $2 $refoutp ; yy=$?
271                      if [ $debug -gt 0 ] ; then echo testoutput_run: cg2dres=$yy 1>&2 ; fi ;;
272              'Cost') testoutput_var $1 "ADM  ref_cost_function" "ADM CostFct" $2 $refoutp ; yy=$? ;;
273             'AdGrd') testoutput_var $1 "ADM  adjoint_gradient"  "ADM Ad Grad" $2 $refoutp ; yy=$? ;;
274             'FDGrd') testoutput_var $1 "ADM  finite-diff_grad"  "ADM FD Grad" $2 $refoutp ; yy=$? ;;
275            'tlmCst') testoutput_var $1 "TLM  ref_cost_function" "TLM CostFct" $2 $refoutp ; yy=$? ;;
276            'tlmGrd') testoutput_var $1 "TLM  tangent-lin_grad"  "TLM TL Grad" $2 $refoutp ; yy=$? ;;
277            'fwdGrd') testoutput_var $1 "TLM  finite-diff_grad"  "TLM FD Grad" $2 $refoutp ; yy=$? ;;
278               'Tmn') testoutput_var $1 "dynstat_theta_min"  "Theta minimum"  $2 $refoutp ; yy=$? ;;
279               'Tmx') testoutput_var $1 "dynstat_theta_max"  "Theta maximum"  $2 $refoutp ; yy=$? ;;
280               'Tav') testoutput_var $1 "dynstat_theta_mean" "Theta mean"     $2 $refoutp ; yy=$? ;;
281               'Tsd') testoutput_var $1 "dynstat_theta_sd"   "Theta Std.Dev"  $2 $refoutp ; yy=$? ;;
282               'Smn') testoutput_var $1 "dynstat_salt_min"  "Salt minimum"    $2 $refoutp ; yy=$? ;;
283               'Smx') testoutput_var $1 "dynstat_salt_max"  "Salt maximum"    $2 $refoutp ; yy=$? ;;
284               'Sav') testoutput_var $1 "dynstat_salt_mean" "Salt mean"       $2 $refoutp ; yy=$? ;;
285               'Ssd') testoutput_var $1 "dynstat_salt_sd"   "Salt Std.Dev"    $2 $refoutp ; yy=$? ;;
286               'Umn') testoutput_var $1 "dynstat_uvel_min"  "U minimum"       $2 $refoutp ; yy=$? ;;
287               'Umx') testoutput_var $1 "dynstat_uvel_max"  "U maximum"       $2 $refoutp ; yy=$? ;;
288               'Uav') testoutput_var $1 "dynstat_uvel_mean" "U mean"          $2 $refoutp ; yy=$? ;;
289               'Usd') testoutput_var $1 "dynstat_uvel_sd"   "U Std.Dev"       $2 $refoutp ; yy=$? ;;
290               'Vmn') testoutput_var $1 "dynstat_vvel_min"  "V minimum"       $2 $refoutp ; yy=$? ;;
291               'Vmx') testoutput_var $1 "dynstat_vvel_max"  "V maximum"       $2 $refoutp ; yy=$? ;;
292               'Vav') testoutput_var $1 "dynstat_vvel_mean" "V mean"          $2 $refoutp ; yy=$? ;;
293               'Vsd') testoutput_var $1 "dynstat_vvel_sd"   "V Std.Dev"       $2 $refoutp ; yy=$? ;;
294            'pt1mn'|'pt2mn'|'pt3mn'|'pt4mn'|'pt5mn') ii=`echo $xx | sed 's/pt//' | sed 's/..$//'`
295               testoutput_var $1 "trcstat_ptracer0"$ii"_min"  "p0"$ii"_min"   $2 $refoutp ; yy=$? ;;
296            'pt1mx'|'pt2mx'|'pt3mx'|'pt4mx'|'pt5mx') ii=`echo $xx | sed 's/pt//' | sed 's/..$//'`
297               testoutput_var $1 "trcstat_ptracer0"$ii"_max"  "p0"$ii"_max"   $2 $refoutp ; yy=$? ;;
298            'pt1av'|'pt2av'|'pt3av'|'pt4av'|'pt5av') ii=`echo $xx | sed 's/pt//' | sed 's/..$//'`
299               testoutput_var $1 "trcstat_ptracer0"$ii"_mean" "p0"$ii"_mean" $2 $refoutp ; yy=$? ;;
300            'pt1sd'|'pt2sd'|'pt3sd'|'pt4sd'|'pt5sd') ii=`echo $xx | sed 's/pt//' | sed 's/..$//'`
301               testoutput_var $1 "trcstat_ptracer0"$ii"_sd"   "p0"$ii"_StDv"  $2 $refoutp ; yy=$? ;;
302             'Qntmn') testoutput_var $1 "forcing_qnet_min" "Qnet minimum"  $2 $refoutp ; yy=$? ;;
303             'Qntmx') testoutput_var $1 "forcing_qnet_max" "Qnet maximum"  $2 $refoutp ; yy=$? ;;
304             'Qntav') testoutput_var $1 "forcing_qnet_mean" "Qnet mean"       $2 $refoutp ; yy=$? ;;
305             'Qntsd') testoutput_var $1 "forcing_qnet_sd"  "Qnet Std.Dev"  $2 $refoutp ; yy=$? ;;
306             'aSImn') testoutput_var $1 "seaice_area_min"   "SIce Area min"   $2 $refoutp ; yy=$? ;;
307             'aSImx') testoutput_var $1 "seaice_area_max"   "SIce Area max"   $2 $refoutp ; yy=$? ;;
308             'aSIav') testoutput_var $1 "seaice_area_mean"  "SIce Area mean"  $2 $refoutp ; yy=$? ;;
309             'aSIsd') testoutput_var $1 "seaice_area_sd"    "SIce Area StDv"  $2 $refoutp ; yy=$? ;;
310             'hSImn') testoutput_var $1 "seaice_heff_min"   "SIce Heff min"   $2 $refoutp ; yy=$? ;;
311             'hSImx') testoutput_var $1 "seaice_heff_max"   "SIce Heff max"   $2 $refoutp ; yy=$? ;;
312             'hSIav') testoutput_var $1 "seaice_heff_mean"  "SIce Heff mean"  $2 $refoutp ; yy=$? ;;
313             'hSIsd') testoutput_var $1 "seaice_heff_sd"    "SIce Heff StDv"  $2 $refoutp ; yy=$? ;;
314             'uSImn') testoutput_var $1 "seaice_uice_min"   "SIce Uice min"   $2 $refoutp ; yy=$? ;;
315             'uSImx') testoutput_var $1 "seaice_uice_max"   "SIce Uice max"   $2 $refoutp ; yy=$? ;;
316             'uSIav') testoutput_var $1 "seaice_uice_mean"  "SIce Uice mean"  $2 $refoutp ; yy=$? ;;
317             'uSIsd') testoutput_var $1 "seaice_uice_sd"    "SIce Uice StDv"  $2 $refoutp ; yy=$? ;;
318             'vSImn') testoutput_var $1 "seaice_vice_min"   "SIce Vice min"   $2 $refoutp ; yy=$? ;;
319             'vSImx') testoutput_var $1 "seaice_vice_max"   "SIce Vice max"   $2 $refoutp ; yy=$? ;;
320             'vSIav') testoutput_var $1 "seaice_vice_mean"  "SIce Vice mean"  $2 $refoutp ; yy=$? ;;
321             'vSIsd') testoutput_var $1 "seaice_vice_sd"    "SIce Vice StDv"  $2 $refoutp ; yy=$? ;;
322            'AthSiG') testoutput_var $1 "thSI_Ice_Area_G" "thSIc Area Global" $2 $refoutp ; yy=$? ;;
323            'AthSiS') testoutput_var $1 "thSI_Ice_Area_S" "thSIc Area South"  $2 $refoutp ; yy=$? ;;
324            'AthSiN') testoutput_var $1 "thSI_Ice_Area_N" "thSIc Area North"  $2 $refoutp ; yy=$? ;;
325            'HthSiG') testoutput_var $1 "thSI_IceH_ave_G" "thSIc H Global"    $2 $refoutp ; yy=$? ;;
326            'HthSiS') testoutput_var $1 "thSI_IceH_ave_S" "thSIc H South"     $2 $refoutp ; yy=$? ;;
327            'HthSiN') testoutput_var $1 "thSI_IceH_ave_N" "thSIc H North"     $2 $refoutp ; yy=$? ;;
328                  *) yy=99; echo "WARNING: asking for var=$xx : not recognized !" 1>&2 ;;
329              esac
330              if test $xx = $sVar
331              then allargs="$allargs > $yy <"
332              else allargs="$allargs $yy"
333              fi
334            done
335    
336      if [ $debug -gt 0 ]; then          nbVar=`echo $listVar | awk '{print NF}'`
337          echo testoutput: testoutput_for_prop $1 cg2d_init_res 1>&2          if [ $nbVar -lt $LEN_CHECK_LIST ] ; then
338      fi          #-- fill line (up to standard length) with dot:
339      testoutput_for_prop $1 "cg2d_init_res" "cg2d init. residual" $2; cg2dres=$?            adNul=`expr $LEN_CHECK_LIST - $nbVar | awk '{for(i=1;i<=$1;i++){print "."}}'`
340      if [ $debug -gt 0 ]; then            echo $allargs $adNul
341          echo testoutput: cg2dres=$cg2dres 1>&2          else
342      fi            echo $allargs
343                fi
344      testoutput_for_prop $1 "dynstat_theta_min" "theta minimum" $2; tmin=$?  # <-- same processing for adjoint & forward test
     testoutput_for_prop $1 "dynstat_theta_max" "theta maximum" $2; tmax=$?  
     testoutput_for_prop $1 "dynstat_theta_mean" "theta mean" $2; tmean=$?  
     testoutput_for_prop $1 "dynstat_theta_sd" "theta s.d." $2; tsd=$?  
     testoutput_for_prop $1 "dynstat_salt_min" "salt minimum" $2; smin=$?  
     testoutput_for_prop $1 "dynstat_salt_max" "salt maximum" $2; smax=$?  
     testoutput_for_prop $1 "dynstat_salt_mean" "salt mean" $2; smean=$?  
     testoutput_for_prop $1 "dynstat_salt_sd" "salt s.d." $2; ssd=$?  
     testoutput_for_prop $1 "dynstat_uvel_min" "U minimum" $2; umin=$?  
     testoutput_for_prop $1 "dynstat_uvel_max" "U maximum" $2; umax=$?  
     testoutput_for_prop $1 "dynstat_uvel_mean" "U mean" $2; umean=$?  
     testoutput_for_prop $1 "dynstat_uvel_sd" "U s.d." $2; usd=$?  
     testoutput_for_prop $1 "dynstat_vvel_min" "V minimum" $2; vmin=$?  
     testoutput_for_prop $1 "dynstat_vvel_max" "V maximum" $2; vmax=$?  
     testoutput_for_prop $1 "dynstat_vvel_mean" "V mean" $2; vmean=$?  
     testoutput_for_prop $1 "dynstat_vvel_sd" "V s.d." $2; vsd=$?  
       
     dashnum $cg2dres $tmin $tmax $tmean $tsd $smin $smax $smean $ssd \  
         $umin $umax $umean $usd $vmin $vmax $vmean $vsd  
345  }  }
346    
347  genmakemodel()  genmakemodel()
348  {  {
349      # genmakemodel directory      # genmakemodel directory
350      GENMAKE2="../../../tools/genmake2"      if test "x$NOGENMAKE" = xt ; then
351      (          echo "genmake skipped!"
352          cd $1;      else
353          printf 'genmake ... ' 1>&2          if test "x$BASH" = x ; then
354          # ../../../tools/genmake -ieee -mods=../code > make.log 2>&1              GENMAKE2="../../../tools/genmake2"
         $GENMAKE2  -ds --mods=../code "--optfile="$OPTFILE > make.log 2>&1  
         RETVAL=$?  
         for i in gm_state gm_optfile gm_local Makefile ; do  
             if test -r $i ; then  
                 cp $i $CDIR  
             fi  
         done  
         if test "x$RETVAL" != x0 ; then  
             tail make.log  
             echo "genmakemodel: genmake failed" 1>&2  
             cp make.log $CDIR  
             return 1  
355          else          else
356              echo "succesful" 1>&2              GENMAKE2="$BASH ../../../tools/genmake2 -bash $BASH"
357          fi          fi
358      )          (
359                cd $1;
360                command="$GENMAKE2  -ds -m $MAKE"
361                if test "x$MKDEPEND" != x ; then
362                    command="$command -makedepend=$MKDEPEND"
363                fi
364                if test $KIND = 1 -o $KIND = 2 ; then
365                    command="$command --mods=../code_ad"
366                elif test $KIND = 4 ; then
367                    command="$command -adof ../../../tools/adjoint_options/adjoint_oad -mods '../code_oad ../../OpenAD/code_oad_all'"
368                else
369                    command="$command -mods=../code"
370                fi
371                if test "x$OPTFILE" != xNONE ; then
372                    command="$command -optfile=$OPTFILE"
373                fi
374                if test $OptLev = 1 ; then
375                    command="$command -ieee"
376                fi
377                if test $OptLev = 0 ; then
378                    command="$command -devel"
379                fi
380                if test "x$GSL" = xt ; then
381                    command="$command -gsl"
382                fi
383                if test "x$MPI" != x0 ; then
384                    command="$command -mpi"
385                fi
386                if test "x$MULTI_THREAD" = xt ; then
387                #- run multi-threaded using OpenMP:
388                    command="$command -omp"
389                fi
390                if test "x$USE_R4" = xt ; then
391                    command="$command -use_r4"
392                fi
393                if test "x$EXTRFLG" != x ; then
394                    command="$command -extra_flag $EXTRFLG"
395                fi
396                if test "x$TS" = xt ; then
397                    command="$command -ts"
398                fi
399                if test "x$PAPIS" = xt ; then
400                    command="$command -papis"
401                else
402                if test "x$PCLS" = xt ; then
403                    command="$command -pcls"
404                fi
405                fi
406                printf 'genmake ... '
407                eval $command > genmake.tr_log 2>&1
408                RETVAL=$?
409                #  Reduce the size of the testing emails!
410                head -100 Makefile > $CDIR/Makefile_head
411                if test "x$RETVAL" != x0 ; then
412                    tail genmake.tr_log
413                    echo "genmakemodel: genmake failed"
414                    cp genmake.log genmake_* genmake.tr_log $CDIR
415                    return 1
416                else
417                    echo "successful"
418                fi
419            )
420        fi
421  }  }
422    
423  makeclean()  makeclean()
424  {  {
425      # makeclean directory      # makeclean directory
426      (      if test "x$NODEPEND" = xf ; then rm -f $1/make.tr_log ; fi
427          cd $1;      if test "x$NOCLEAN" = xt ; then
428          rm -f output.txt          echo "make Clean skipped!"
429          printf 'make CLEAN ... ' 2>&1      else
430          if test -r Makefile ; then          (
431              make CLEAN >> make.log 2>&1              cd $1;
432              RETVAL=$?              #if test -e $OUTPUTFILE ; then rm -f $OUTPUTFILE ; fi
433              if test "x$RETVAL" != x0 ; then              if test -r Makefile ; then
434                  tail make.log                  printf 'clean build-dir: make Clean ... '
435                  echo "makeclean: \"make CLEAN\" failed" 1>&2                  $MAKE Clean >> make.tr_log 2>&1
436                  cp make.log $CDIR"/make.log"                  RETVAL=$?
437                  return 1                  if test "x$RETVAL" != x0 ; then
438                        tail make.tr_log
439                        echo "makeclean: \"make Clean\" failed"
440                        cp make.tr_log genmake.log genmake.tr_log $CDIR
441                        return 1
442                    fi
443                    echo successful
444                else
445                    echo ''
446              fi              fi
447          fi              exit 0
448          echo succesful 1>&2          )
449          exit 0      fi
450      )  }
451    
452    run_clean()
453    {
454        # run_clean directory
455        if test "x$NOCLEAN" = xt ; then
456            echo "run_clean skipped!"
457        else
458            (
459                cd $1;
460                printf 'clean run-dir ... '
461                # part of what is done after "make clean" when doing "make CLEAN"
462                find . -name "*.meta" -exec rm {} \;
463                find . -name "*.data" -exec rm {} \;
464                find . -name "fort.*" -exec rm {} \;
465                find . -type l -exec rm {} \;
466                #- should remove executable only if sym-link (alredy done above)
467                rm -f $RUNLOG *.txt STD* w2_tile_topology.????.log *diagnostics.log datetime
468                rm -rf mnc_test_*
469                rm -f *_MIT_CE_000.opt0000 costfunction*0000
470                echo successful
471                exit 0
472            )
473        fi
474  }  }
475    
476  makedependmodel()  makedependmodel()
477  {  {
478      # makedependmodel directory      # makedependmodel directory
479      (      if test "x$NODEPEND" = xt ; then
480          cd $1;          echo "make depend skipped!"
481          printf 'make depend ... ' 1>&2      else
482          make depend >> make.log 2>&1          (
483          RETVAL=$?              cd $1;
484          if test "x$RETVAL" != x0 ; then              printf 'make depend ... '
485              tail make.log              $MAKE depend >> make.tr_log 2>&1
486              echo "makedependmodel: make depend failed" 1>&2              RETVAL=$?
487              cp make.log $CDIR"/make.log"              if test "x$RETVAL" != x0 ; then
488              return 1                  tail make.tr_log
489          else                  echo "makedependmodel: make depend failed"
490              echo succesful 1>&2                  cp make.tr_log genmake.log genmake.tr_log $CDIR
491          fi                  return 1
492      )              else
493                    echo successful
494                fi
495            )
496        fi
497  }  }
498    
499  makemodel()  makemodel()
500  {  {
501      # makemodel directory      # makemodel directory
502      (      (
503        mk_fail=0
504        if test "x$NOMAKE" = xt ; then
505            cd $1;
506            if test -x $EXECUTABLE ; then
507                echo "make skipped!"
508            else
509                echo "no executable!"
510                mk_fail=3
511            fi
512        else
513          cd $1;          cd $1;
514          if test -r Makefile ; then          if test -r Makefile ; then
515              printf 'make ... ' 1>&2              printf 'make ... '
516              make >> make.log 2>&1              if test "x$REPLMAKE" = x ; then
517                    $MAKE $TARG >> make.tr_log 2>&1
518                else
519                    $REPLMAKE $TARG >> make.tr_log 2>&1
520                fi
521              RETVAL=$?              RETVAL=$?
522              if test "x$RETVAL" != x0 ; then              if test "x$RETVAL" != x0 ; then
523                  tail make.log                  tail make.tr_log
524                  echo failed 1>&2                  echo failed
525                  cp make.log $CDIR"/make.log"                  cp genmake.log genmake.tr_log $CDIR
526                  return 1                  tail -$NBLINES_MKLOG make.tr_log > $CDIR"/make.tr_log_tail"
527                    rm -f $EXECUTABLE
528                    mk_fail=1
529              else              else
530                  echo succesful 1>&2                  echo successful
531              fi              fi
532            else
533                echo "no Makefile !"
534                mk_fail=2
535          fi          fi
536        fi
537        if test $KIND = 1 -a -f taf_ftl.log ; then
538                head -1 taf_ftl.log >> $CDIR"/summary.txt"
539        fi
540        if test $KIND = 2 -a -f taf_ad.log ; then
541                head -1 taf_ad.log >> $CDIR"/summary.txt"
542                nerr=`grep -c 'TAF *.* ERROR ' taf_ad.log`
543                nwar=`grep -c 'TAF RECOMPUTATION *.* WARNING ' taf_ad.log`
544                echo " TAF reports $nerr Errors and $nwar Recomputation Warnings" \
545                                    >> $CDIR"/summary.txt"
546        fi
547        if test $mk_fail != 0 ; then return $mk_fail ; fi
548      )      )
549  }  }
550    
551    mk_mpi_size()
552    {
553        # mk_mpi_size input_file output_file proc_Nb threads_Nb_X threads_Nb_Y
554        #
555        #  make new SIZE.h (=output_file) from SIZE.h_mpi (=input_file)
556        #     for an MPI build with no more than proc_Nb processors ;
557        #  ensure that enough tiles per proc (nSx,nSy) remain for the given
558        #     number of threads (nTx,nTy) ;
559        #  return the effective number of processors.
560    
561        inp=$1
562        out=$2
563        np=$3
564        tx=$4
565        ty=$5
566        tmp=TTT.$$
567    
568        # dirX : select with direction to favor in MPI process repartition
569        #   dirX=1 : prefer to put more proc in X direction
570        #   dirX=0 : prefer to put more proc in Y direction
571        dirX=0
572    
573        px=`grep "^     & *nPx *=" $inp | sed "s/^     & *nPx *= *//" | sed 's/, *$//'`
574        py=`grep "^     & *nPy *=" $inp | sed "s/^     & *nPy *= *//" | sed 's/, *$//'`
575        sx=`grep "^     & *nSx *=" $inp | sed "s/^     & *nSx *= *//" | sed 's/, *$//'`
576        sy=`grep "^     & *nSy *=" $inp | sed "s/^     & *nSy *= *//" | sed 's/, *$//'`
577    
578        #- for each direction, assume # of threads is a multiple of total number of tiles
579        nx=$px
580        if [ `expr $sx % $tx` -ne 0 -a `expr $sx \* $px % $tx` -eq 0 ] ; then
581            nx=`expr $sx \* $px / $tx`
582            if [ $verbose -gt 1 ]; then
583                echo " change px from $px to $nx to accommodate $tx threads"
584            fi
585        fi
586        ny=$py
587        if [ `expr $sy % $ty` -ne 0 -a `expr $sy \* $py % $ty` -eq 0 ] ; then
588            ny=`expr $sy \* $py / $ty`
589            if [ $verbose -gt 1 ]; then
590                echo " change py from $py to $ny to accommodate $ty threads"
591            fi
592        fi
593        #- find the largest divisor of input_file proc Nb, but not larger than $np
594        pp=0
595        i=1
596        while [ $i -le $nx ] ; do
597          if [ `expr $nx % $i` -eq 0 ] ; then
598            j=1
599            while [ $j -le $ny ] ; do
600              if [ `expr $ny % $j` -eq 0 ] ; then
601                ij=`expr $i \* $j`
602                if [ $ij -gt $pp ] ; then
603                    flag=1
604                elif [ $ij -eq $pp ] ; then
605                    flag=$dirX
606                else
607                    flag=0
608                fi
609                if test $flag = 1 ; then
610                  if [ $ij -le $np ] ; then
611                    ix=$i ; jy=$j ; pp=$ij
612                    #echo "  ix,jy= $ix,$jy"
613                  fi
614                fi
615              fi
616              j=`expr $j + 1`
617            done
618          fi
619          i=`expr $i + 1`
620        done
621    
622        #- create new SIZE.h type file:
623        sx=`expr $sx \* $px / $ix`
624        sy=`expr $sy \* $py / $jy`
625        if [ $verbose -gt 1 ]; then
626            echo " px,py,np= $px,$py,$np : New MPI size: px,py= $ix,$jy : sx,sy= $sx,$sy"
627        fi
628        sed "/^     \& *nPx *=/s/[0-9]*,/$ix,/" $inp > $tmp
629        sed "/^     \& *nPy *=/s/[0-9]*,/$jy,/" $tmp > $out
630        sed "/^     \& *nSx *=/s/[0-9]*,/$sx,/" $out > $tmp
631        sed "/^     \& *nSy *=/s/[0-9]*,/$sy,/" $tmp > $out
632        rm -f $tmp
633        return $pp
634    }
635    
636    symlink_mpifiles()
637    {
638        # Put special links so that MPI specific files are used
639        # This MUST be invoked between makeclean and makelinks because
640        # the Makefile will link to non-mpi files by default
641    
642        dir=$1
643        code_dir=$2
644        build_dir=$dir/$3
645    
646        # These are files that should replace their counter-part when using -mpi
647        MPI_FILES=`(cd $dir/$code_dir; find . -name "*_mpi" -print)`
648    
649        for ii in $MPI_FILES ; do
650            i=`echo $ii | sed 's:^\./::'`
651            name=`echo $i | sed 's:_mpi::'`
652            file="../$code_dir/$i"
653            if test $name = 'SIZE.h' ; then file="SIZE.h.mpi" ; fi
654    
655            #  Is this an MPI run?
656            if test "x$MPI" = x0 ; then
657                # NO: We undo any _mpi symbolically linked files
658                if test -L $build_dir/$name ; then
659                    ( cd $build_dir ; cmp $name $file > /dev/null 2>&1 )
660                    RETVAL=$?
661                    if test "x$RETVAL" = x0 ; then
662                        if [ $verbose -gt 1 ]; then
663                            echo "  Un-linking $name from ../$code_dir" ; fi
664                        rm -f $build_dir/$name
665                    fi
666                fi
667            else
668                # YES: We symbolically link these files to the build
669                # dir so long as there is no real file in place
670                ( cd $build_dir ; cmp $name $file > /dev/null 2>&1 )
671                RETVAL=$?
672                if [ $verbose -gt 1 ]; then echo "  cmp $name $file returns: $RETVAL" ; fi
673                if test "x$RETVAL" != x0 ; then
674                    if test -h $build_dir/$name ; then rm -f $build_dir/$name ; fi
675                    if test ! -r $build_dir/$name ; then
676                        if [ $verbose -gt 1 ]; then echo "  Linking $name to $file" ; fi
677                        (cd $build_dir; ln -sf $file $name)
678                    fi
679                fi
680            fi
681        done
682    }
683    
684  linkdata()  linkdata()
685  {  {
686      # linkdata flag      # linkdata run_dir input_dir_1 input_dir_2 ...
687      #      #
688      # symbolically link data files to run directory      # symbolically link data files to run directory
689      if [ $1 -ne 0 ]; then      if test -d $1 ; then
690          ( cd $2 ;  ln -sf ../input/* . )          (
691                cd $1 ; shift
692                echo 'linkdata from dirs:' $*
693                inpMPI=`(cd ../$1 ; find . -name "*.mpi" -print | sed 's:^\./::')`
694                for xx in $inpMPI ; do
695                  if test -r "../"$1"/"$xx ; then
696                    # found 1 _mpi sfx file in 1rst input dir and it is readable
697                    yy=`echo $xx | sed 's:\.mpi$::'`
698                    if test "x$MPI" = "x0" ; then
699                        # not mpi test: remove symbolic link
700                        if test -h $yy ; then rm -f $yy ; fi
701                    else
702                        # mpi test: remove symbolic link & link .mpi sfx file
703                        if test -h $yy ; then rm -f $yy ; fi
704                        if test ! -r $yy ; then
705                            ln -sf "../"$1"/"$xx $yy ;
706                            printf " $xx" 1>&2
707                        fi
708                    fi
709                  fi
710                done
711                if test -r "../"$1"/eedata.mth" ; then
712                # found eedata.mth in 1rst input dir and it is readable
713                    if test "x$MULTI_THREAD" = "xt" ; then
714                    # multi-threaded test: remove symbolic link & link eedata.mth
715                        if test -h eedata ; then rm -f eedata ; fi
716                        if test ! -r eedata ; then
717                            ln -sf "../"$1"/eedata.mth" eedata ;
718                            printf ' eedata.mth' 1>&2
719                        fi
720                    else
721                    # not multi-threaded test: remove eedata symbolic link
722                        if test -h eedata ; then rm -f eedata ; fi
723                    fi
724                fi
725                prevDir='NONE'
726                for ldir in $* ; do
727                    if test -d "../"$ldir -a $ldir != $prevDir ; then
728                        printf " ldir=${ldir}:" 1>&2
729                        files=`( cd "../"$ldir ; ls -1 | grep -v CVS )`
730                        for i in $files ; do
731                            if test ! -d "../"$ldir/$i ; then
732                                if test ! -r $i  ; then
733                                    printf ' '$i 1>&2
734                                    ln -sf "../"$ldir"/"$i $i
735                                fi
736                            fi
737                        done
738                        printf ' ;' 1>&2
739                        if test -x "../"$ldir"/"prepare_run ; then
740                            "../"$ldir"/"prepare_run 1>&2
741                        else
742                            echo '' 1>&2
743                        fi
744                    fi
745                    prevDir=$ldir
746                done
747            )
748      fi      fi
749  }  }
750    
751  runmodel()  runmodel()
752  {  {
753      # runmodel directory exe      # runmodel directory
754      #      #
755      #  runs the model "exe" in "directory" (exe is relative to directory)      #  runs $COMMAND in "directory"
756        #  (where "$COMMAND" is relative to "directory")
757      (      (
758          cd $1          cd $1
759          if [ -x $2 ]; then          printf 'runmodel in %s ... ' $1
760              if [ $quick -eq 0 ]; then          if test "x$MPI" != x0 ; then
761                  rm -f output.txt              #- adjust the MPI run command with the right number of Procs
762                #echo '' ; echo "  COMMAND='$COMMAND'"
763                COMMAND=`echo $COMMAND | sed "s/ TR_NPROC / $LOC_NPROC /"`
764                if test "x$MPI_MFILE" != x ; then
765                  COMMAND=`echo $COMMAND | sed "s/ TR_MFILE / ..\/..\/$LOC_MFILE /"`
766              fi              fi
767              printf 'runmodel: ' 1>&2              #echo "  COMMAND='$COMMAND'"
768              make output.txt          fi
769            if test -L $EXECUTABLE ; then
770              if test -x "../"$builddir"/"$EXECUTABLE ; then
771                cmp $EXECUTABLE "../"$builddir"/"$EXECUTABLE > /dev/null 2>&1
772                outD=$? ; if test "x$outD" != x0 ; then rm -f $EXECUTABLE ; fi
773              else rm -f $EXECUTABLE
774              fi
775            fi
776            if test ! -x $EXECUTABLE -a -x "../"$builddir"/"$EXECUTABLE ; then
777                echo " link" $EXECUTABLE "from dir ../"$builddir > run.log_tmp
778                ln -sf "../"$builddir"/"$EXECUTABLE .
779            fi
780            if test ! -x $EXECUTABLE ; then
781                rm -f $RUNLOG ; touch $RUNLOG
782                if test -f run.log_tmp ; then cat run.log_tmp >> $RUNLOG ; fi
783                echo " no executable:" $EXECUTABLE >> $RUNLOG
784                RETVAL=8
785                ENDVAL=-1
786            else
787              if test ! -f $OUTPUTFILE -o $OUTPUTFILE -ot $EXECUTABLE ; then
788                # output do not exist or is older than executable:
789                rm -f $OUTPUTFILE $RUNLOG ; touch $RUNLOG
790                if test -f run.log_tmp ; then cat run.log_tmp >> $RUNLOG ; fi
791                ( eval $COMMAND ) >> $RUNLOG 2>&1
792              RETVAL=$?              RETVAL=$?
793              if test "x$RETVAL" = x0 ; then              ENDVAL=`tail $OUTPUTFILE | grep -c 'PROGRAM MAIN: Execution ended Normally'`
794                  cp output.txt $CDIR"/output.txt"              if [ $POSTCLEAN -eq 1 -a $ENDVAL -gt 0 ] ; then
795                  return 0                  find . -name "*.meta" -exec rm {} \;
796              else                  find . -name "*.data" -exec rm {} \;
797                  return 1                  rm -rf mnc_test_*
798              fi              fi
799              else
800                RETVAL=0
801                ENDVAL=`tail $OUTPUTFILE | grep -c 'PROGRAM MAIN: Execution ended Normally'`
802                touch $RUNLOG
803                if test -f run.log_tmp ; then cat run.log_tmp >> $RUNLOG ; fi
804                echo "---------->> $OUTPUTFILE is up to date " >> $RUNLOG 2>&1
805              fi
806            fi
807            rm -f run.log_tmp
808            #- in all cases where OutputFile exists, report SIZE and time
809            if test -f $OUTPUTFILE ; then
810              grep '(PID\.TID 0000\.0001)      n.. =' $OUTPUTFILE \
811                    | sed 's/(PID.TID 0000.0001)   //' >> $CDIR"/summary.txt"
812              grep -A3 'Seconds in section "ALL' $OUTPUTFILE \
813                    | sed 's/(PID.TID 0000.0001)   //' >> $CDIR"/summary.txt"
814            fi
815            if test -s STDERR.0000 ; then cp STDERR.0000 $CDIR"/STDERR.0000" ; fi
816            if [ $RETVAL -eq 0 -a $ENDVAL -gt 0 ] ; then
817                echo successful
818                printf '=> output from running in %s :\n' $1 1>&2
819                tail $RUNLOG | sed 's/^.*/> &/g' 1>&2
820                return 0
821            elif [ $RETVAL -ne 0 -a $ENDVAL -gt 0 ] ; then
822                #-- for some weird cases (run is finihed but with error code)
823                echo 'finished with error (run:' $RETVAL ' end:' $ENDVAL ')'
824                printf '=> output from running in %s :\n' $1 1>&2
825                tail $RUNLOG | sed 's/^.*/> &/g' 1>&2
826                return 0
827            else
828                echo 'failed (run:' $RETVAL ' end:' $ENDVAL ')'
829                printf '=> output from running in %s :\n' $1 1>&2
830                tail $RUNLOG | sed 's/^.*/> &/g' 1>&2
831                cp $RUNLOG $CDIR"/"$RUNLOG
832                return 1
833          fi          fi
834      )      )
835  }  }
# Line 283  createcodelet() Line 838  createcodelet()
838  {  {
839      # create codelet for comparing model output      # create codelet for comparing model output
840    
841      echo -n "creating the comparison code...  "      printf "creating the comparison code (using CC=$CC)...  "
842      cat > tmp_cmpnum.f <<EOFA      cat > tr_cmpnum.c <<EOF
843        program cmpnum  #include <stdio.h>
844        implicit none  #include <math.h>
845        real*8 a,b,diff  int main( int argc, char** argv )  {
846        integer linnum,best    int linnum,cmplin,best,lncnt;
847        best=-16    double a,b,abave,relerr;
848    99  read(*,*,end=70,err=60) linnum,a,b    best = -22;
849        diff=0.5*(abs(a)+abs(b))    lncnt = 0;
850  c     print *,a,b,diff,abs(a-b)/diff    while( 1 & ( (lncnt+=1) < 999 ) )  {
851        if (diff.gt.1.e-12) then      scanf("%d", &linnum);
852          diff=abs(a-b)/diff      if (linnum == -1)  break;
853          if (diff.gt.0.) then      scanf("%lf", &a);  scanf("%lf", &b);
854  c         print *,int(log10(diff)),diff      abave = 0.5*(fabs(a)+fabs(b));
855            linnum=int(log10(diff))      if ( abave == abave ) {
856            best=max(best,linnum)        if (abave > 0.0) {
857          endif          relerr=fabs(a-b)/abave;
858        else          if (relerr > 0.0) { cmplin = (int)rint(log10(relerr)); }
859          if (best.eq.-16.and.diff.ne.0.) best=-22          else { cmplin = -16 ; }
860        endif          best = (best > cmplin) ? best : cmplin; }
861        goto 99        else { cmplin = -22 ; }
862    60  stop 'cmpnum: An error occured reading a,b'     /* printf("%d ; %lf ; %lf\n",cmplin,a,b); */
863    70  print *,-best        }
864        end     else {
865  EOFA     /* printf("%lf ; %lf ; %lf\n",abave,a,b); */
866          break; }
867      }
868      if (lncnt == 999) best=-29;
869      if (linnum != -1) best=-99;
870      printf("%d\n", -best);
871      return 0;
872    }
873    EOF
874        $CC -o tr_cmpnum tr_cmpnum.c -lm
875    
876      f77 tmp_cmpnum.f      if [ -x ./tr_cmpnum ]; then
     if [ -x ./a.out ]; then  
877          echo "OK"          echo "OK"
878          return 0          return 0
879      else      else
880          echo          echo
881          echo "createcodelet: failed to compile codelet" | tee          echo "ERROR: failed to compile comparison code -- please specify"
882            echo "  a C compiler using the CC environment variable."
883          exit 1          exit 1
884      fi      fi
885  }  }
# Line 327  formatresults() Line 891  formatresults()
891      nm=$1      nm=$1
892      printf '%s %s %s %s' $2 $3 $4 $5      printf '%s %s %s %s' $2 $3 $4 $5
893      shift; shift; shift; shift; shift;      shift; shift; shift; shift; shift;
894      printf '%3s' $@      listPrt=$@
895            listRes=`echo $listPrt | sed 's/>//' | sed 's/<//'`
896      if [ $1 = '--' ]; then      xx=`echo $listPrt | sed 's/.*>//' | sed 's/<.*//' | awk '{print $1}'`
897        printf '%3s' $listPrt
898    #   line below does not work on hp-ux_ia64 : do those substitutions later on
899    #   printf '%3s' $listPrt | sed 's/ 99/ --/g' | sed 's/  > />/' | sed 's/  < /</'
900    
901        if [ $xx = '..' ]; then
902            printf ' N/O '
903        elif [ $xx = '--' ]; then
904            printf ' N/O '
905        elif [ $xx = 99 ]; then
906          printf ' N/O '          printf ' N/O '
907      else      else
908          if [ $1 -gt 12 ]; then          if [ $xx -ge $MATCH_CRIT ]; then
909              printf ' pass'              printf ' pass'
910          else          else
911              printf ' FAIL'              printf ' FAIL'
# Line 340  formatresults() Line 913  formatresults()
913      fi      fi
914      printf '  %s' $nm      printf '  %s' $nm
915      printf '\n'      printf '\n'
       
 }  
916    
 show_help()  
 {  
     cat - << EOF  
 $0 [-help] [-quick] [-verbose] dir1 [dir2] [...]  
  -help      Show this help message  
  -quick     Skip "genmake" and "make depend" if the Makefile exists  
  -quiet     Reduce the amount of output  
  -verbose   Produce copious amounts of output  
  -debug     Produce even more output which will mean nothing to most  
  -force     Do "make CLEAN" before compiling. This forces a complete rebuild.  
  -clean     Do "make CLEAN" after compiling and testing.  
  -noieee    By default, $0 uses the -ieee option for genmake. This turns it off.  
  -cleanup   Aggresively removes all model output, executables and object files  
             and then exits. Use with care.  
   
 Normal usage:  
  $0 *       Configure, compile, run and analyze in all experiment directories  
 EOF  
917  }  }
918    
919  scandirs()  scandirs()
920  {  {
921      if [ $# -eq 0 ]; then      if [ $# -eq 1 ]; then
922          for arg in * ; do          for arg in * ; do
923              test -d $arg/input && echo $arg             #test -f $arg/$1 && echo $arg
924          done              test -f $arg/$1 -o -f $arg/$1.gz && echo $arg
925            done
926      else      else
927          echo $*          echo $*
928      fi      fi
929  }  }
930    
931    
932  ###############################################################################  check_eedata()
933  ###############################################################################  {
934        # check_eedata eedata size.h
935        if [ $# -eq 2 ] ; then
936         if test -f $1 -a -f $2 ; then
937          nx=`grep "^ *nTx *=" $1 | tail -1 | sed 's/^ *nTx *= *//' | sed "s/, *$//"`
938          sx=`grep "^     & *nSx *=" $2 | sed "s/^     & *nSx *=//" | sed 's/, *$//'`
939          if test "x$nx" = x ; then
940            rx=10
941          else
942            rx=`expr $sx % $nx`
943          fi
944          ny=`grep "^ *nTy *=" $1 | tail -1 | sed 's/^ *nTy *= *//' | sed "s/, *$//"`
945          sy=`grep "^     & *nSy *=" $2 | sed "s/^     & *nSy *=//" | sed 's/, *$//'`
946          if test "x$ny" = x ; then
947            ry=20
948          else
949            ry=`expr $sy % $ny`
950          fi
951          echo `expr $rx + $ry`
952         else
953          echo '-1'
954         fi
955        elif [ $# -eq 1 ] ; then
956         if test -f $1 ; then
957          nx=`grep "^ *nTx *=" $1 | tail -1 | sed 's/^ *nTx *= *//' | sed "s/, *$//"`
958          if test "x$nx" = x ; then nx=1 ; fi
959          ny=`grep "^ *nTy *=" $1 | tail -1 | sed 's/^ *nTy *= *//' | sed "s/, *$//"`
960          if test "x$ny" = x ; then ny=1 ; fi
961         #echo $nx $ny
962          echo $nx
963         else
964          echo '-1'
965         fi
966        else
967          echo '-2'
968        fi
969    
970    }
971    
972  ###############################################################################  ###############################################################################
973    
974    
975  #  Default properties  #  Default properties
976  debug=0  debug=0
977  verbose=1  verbose=1
978  quick=0  NBLINES_MKLOG=16000
979  clean=0  
980  ieee=1  OptLev=1
981  expts=''  GSL=f
982    
983  OPTFILES=  CLEANUP=f
984  ADDRESSES=edhill@mitgcm.org  NORUN=f
985    QUICK=f
986    NOMAKE=f
987    NOGENMAKE=f
988    NOCLEAN=f
989    NODEPEND=f
990    POSTCLEAN=0
991    
992    BASH=
993    OPTFILE=NONE
994    ADDRESSES=
995  TESTDIRS=  TESTDIRS=
996    SKIPDIRS=
997  MPACKDIR="../tools/mpack-1.6"  MPACKDIR="../tools/mpack-1.6"
998  MPACK="$MPACKDIR/mpack"  HAVE_MPACK=
999    MPACK=
1000    COMMAND=
1001    MKDEPEND=
1002    if test "x$MAKE" = x ; then
1003        MAKE=make
1004    fi
1005    REPLMAKE=
1006    if test "x$CC" = x ; then
1007        CC=cc
1008    fi
1009    JOBS=
1010    TARG=
1011    MPI=0
1012    MPI_MFILE=
1013    MULTI_THREAD=f
1014    OUTDIR=
1015    DELDIR=
1016    USE_R4=
1017    EXTRFLG=
1018    
1019    #- type of testing (KIND):
1020    #   KIND=0 : forward (= default) ;  KIND=1 : Tangent Linear with TAF ;
1021    #   KIND=2 : Adjoint with TAF ;     KIND=4 : Adjoint with OpenAD
1022    KIND=0
1023    
1024    # list of pTracers to check for monitor output
1025    PTRACERS_NUM="1 2 3 4 5"
1026    
1027  echo -n "parsing options...  "  MATCH_CRIT=10
1028    
1029    printf "parsing options...  "
1030    
1031  ac_prev=  ac_prev=
1032  for ac_option ; do  for ac_option ; do
# Line 407  for ac_option ; do Line 1039  for ac_option ; do
1039      fi      fi
1040    
1041      ac_optarg=`expr "x$ac_option" : 'x[^=]*=\(.*\)'`      ac_optarg=`expr "x$ac_option" : 'x[^=]*=\(.*\)'`
1042        
1043      case $ac_option in      case $ac_option in
1044                    
1045          -help | --help | -h | --h)          -help | --help | -h | --h) usage ;;
1046              usage ;;  
1047                    -optfile | --optfile | -of | --of) ac_prev=OPTFILE ;;
1048          -optfile | --optfile | -f | --f)          -optfile=* | --optfile=* | -of=* | --of=*) OPTFILE=$ac_optarg ;;
1049              ac_prev=OPTFILES ;;  
1050          -optfile=* | --optfile=*)          -addr | --addr | -a | --a) ac_prev=ADDRESSES ;;
1051              OPTFILES=$ac_optarg ;;          -addr=* | --addr=* | -a=* | --a=*) ADDRESSES=$ac_optarg ;;
1052                    -mpackdir | --mpackdir | -mpd | --mpd) ac_prev=MPACKDIR ;;
1053          -addr | --addr | -a | --a)          -mpackdir=* | --mpackdir=* | -mpd=* | --mpd=*) MPACKDIR=$ac_optarg ;;
1054              ac_prev=ADDRESSES ;;  
1055          -addr=* | --addr=*)          -tdir | --tdir | -t | --t) ac_prev=TESTDIRS ;;
1056              ADDRESSES=$ac_optarg ;;          -tdir=* | --tdir=* | -t=* | --t=*) TESTDIRS=$ac_optarg ;;
1057            -skipdir | --skipdir | -skd | --skd) ac_prev=SKIPDIRS ;;
1058          -tdir | --tdir | -t | --t)          -skipdir=* | --skipdir=* | -skd=* | --skd=*) SKIPDIRS=$ac_optarg ;;
1059              ac_prev=TESTDIRS ;;  
1060          -tdir=* | --tdir=*)          -bash | --bash | -b | --b) ac_prev=BASH ;;
1061              TESTDIRS=$ac_optarg ;;          -bash=* | --bash=* | -b=* | --b=*) BASH=$ac_optarg ;;
1062    
1063            -command | --command | -c | --c) ac_prev=COMMAND ;;
1064            -command=* | --command=* | -c=* | --c=*) COMMAND=$ac_optarg ;;
1065    
1066            -makedepend | --makedepend | -md | --md) ac_prev=MKDEPEND ;;
1067            -makedepend=* | --makedepend=* | -md=* | --md=*) MKDEPEND=$ac_optarg ;;
1068    
1069            -make | --make | -m | --m) ac_prev=MAKE ;;
1070            -make=* | --make=* | -m=* | --m=*) MAKE=$ac_optarg ;;
1071    
1072            -repl_mk | --repl_mk ) ac_prev=REPLMAKE ;;
1073            -repl_mk=* | --repl_mk=*) REPLMAKE=$ac_optarg ;;
1074    
1075            -odir | --odir) ac_prev=OUTDIR ;;
1076            -odir=* | --odir=*) OUTDIR=$ac_optarg ;;
1077    
1078            -ptracers | --ptracers | -ptr | --ptr) ac_prev=PTRACERS_NUM ;;
1079            -ptracers=* | --ptracers=* | -ptr=* | --ptr=*) PTRACERS_NUM=$ac_optarg ;;
1080    
1081            -match | --match ) ac_prev=MATCH_CRIT ;;
1082            -match=* | --match=* ) MATCH_CRIT=$ac_optarg ;;
1083    
1084            -j | --j) ac_prev=JOBS ;;
1085            -j=* | --j=*) JOBS=$ac_optarg ;;
1086    
1087            -ef | --ef) ac_prev=EXTRFLG ;;
1088            -ef=* | --ef=*) EXTRFLG=$ac_optarg ;;
1089    
1090            -clean | --clean) CLEANUP=t ; DELDIR=t ;;
1091    
1092            -norun | --norun | -nr | --nr) NORUN=t ;;
1093            -obj | --obj ) TARG='obj' ; NORUN=t ;;
1094            -runonly | --runonly | -ro | --ro) QUICK=t ; NOMAKE=t ;;
1095            -quick | --quick | -q | --q) QUICK=t ;;
1096            -nogenmake | --nogenmake | -ng | --ng) NOGENMAKE=t ;;
1097            -noclean | --noclean | -nc | --nc) NOCLEAN=t ;;
1098            -nodepend | --nodepend | -nd | --nd) NODEPEND=t ;;
1099    
1100            -postclean | --postclean | -pc | --pc) POSTCLEAN=2 ;;
1101            -deloutp | --deloutp | -do | --do) POSTCLEAN=1 ;;
1102    
1103            -mpi | --mpi) MPI=2 ;;
1104            -MPI | --MPI) ac_prev=MPI ;;
1105            -MPI=* | --MPI=*) MPI=$ac_optarg ;;
1106    
1107            -mfile | --mfile | -mf | --mf) ac_prev=MPI_MFILE ;;
1108            -mfile=* | --mfile=* | -mf=* | --mf=*) MPI_MFILE=$ac_optarg ;;
1109    
1110            -mth) MULTI_THREAD=t ;;
1111    
1112            -tlm) if test $KIND = 0 ; then KIND=1 ; else
1113                    echo "Error: '-tlm', '-adm' and '-oad' are exclusive" ; usage
1114                  fi ;;
1115            -adm | -ad) if test $KIND = 0 ; then KIND=2 ; else
1116                    echo "Error: '-tlm', '-adm' and '-oad' are exclusive" ; usage
1117                  fi ;;
1118            -oad) if test $KIND = 0 ; then KIND=4 ; NODEPEND=t ; else
1119                    echo "Error: '-tlm', '-adm' and '-oad' are exclusive" ; usage
1120                  fi ;;
1121    
1122            -ieee)   echo "Warning: ignore option '-ieee' (already the default)"
1123                     printf " ... " ;;
1124            -noieee) echo "Warning: will use option '-fast' instead of '-noieee' (obsolete)"
1125                     printf " ... " ; OptLev=`expr $OptLev \* 2` ;;
1126            -fast)  OptLev=`expr $OptLev \* 2` ;;
1127            -devel) OptLev=0 ;;
1128            -gsl) GSL=t ;;
1129    
         -quick) quick=1 ;;  
1130          -verbose) verbose=2 ;;          -verbose) verbose=2 ;;
1131          -debug) debug=1 ;;          -debug) debug=1 ;;
         -clean) clean=1 ;;  
         -noieee) ieee=0 ;;  
1132          -quiet) verbose=0 ;;          -quiet) verbose=0 ;;
1133    
1134          -*)          -deldir | -dd) DELDIR=t ;;
1135              echo "Error: unrecognized option: "$ac_option  
1136              usage          -use_r4|-ur4) USE_R4=t ;;
1137              ;;  
1138                    -ts) TS=t;;
1139          *)          -papis) PAPIS=t;;
1140              echo "Error: unrecognized argument: "$ac_option          -pcls) PCL=t;;
1141              usage  
1142              ;;          -*) echo "Error: unrecognized option: "$ac_option
1143                        usage ;;
1144            *)  echo "Error: unrecognized argument: "$ac_option
1145                usage ;;
1146    
1147       esac       esac
1148        
1149  done  done
1150    
1151    if test "x$QUICK" = xt ; then
1152        NOGENMAKE=t
1153        NOCLEAN=t
1154        NODEPEND=t
1155    fi
1156    
1157    #- check length of MPI machine file:
1158    if test "x$MPI" != x0 -a "x$MPI_MFILE" != x ; then
1159        if test -r $MPI_MFILE ; then
1160            nl=`wc -l $MPI_MFILE | awk '{print $1}'`
1161            if [ $nl -lt $MPI ] ; then
1162              echo "Error: need at least $MPI nodes (currently only $nl) in MPI_MFILE=$MPI_FILE"
1163              usage
1164            fi
1165            if [ $verbose -gt 1 ]; then
1166                echo " MPI_MFILE=$MPI_MFILE : $nl procs for MPI=$MPI run"
1167            fi
1168        else
1169              echo "Error: cannot access MPI_MFILE=$MPI_FILE"
1170              usage
1171        fi
1172    fi
1173    
1174    #- setting for forward or ADM testing
1175    if test $KIND = 1 ; then
1176        TARG=ftlall
1177        code_dir=code_ad
1178        inputdir=input_ad
1179        ref_outp="output_tlm.txt"
1180        EXECUTABLE="mitgcmuv_ftl"
1181    elif test $KIND = 2 ; then
1182        if test "x$TARG" = xobj ; then TARG=adobj ; else TARG=adall ; fi
1183        code_dir=code_ad
1184        inputdir=input_ad
1185        ref_outp="output_adm.txt"
1186        EXECUTABLE="mitgcmuv_ad"
1187    elif test $KIND = 4 ; then
1188        TARG=adAll
1189        code_dir=code_oad
1190        inputdir=input_oad
1191        ref_outp="output_oadm.txt"
1192        EXECUTABLE="mitgcmuv_ad"
1193    else
1194        if test "x$JOBS" != x ; then TARG="-j $JOBS $TARG" ; fi
1195        code_dir=code
1196        inputdir=input
1197        ref_outp="output.txt"
1198        EXECUTABLE="mitgcmuv"
1199    fi
1200    
1201    xx=`echo $TESTDIRS | awk '{print $1}'`
1202  if test "x$TESTDIRS" = x ; then  if test "x$TESTDIRS" = x ; then
1203      TESTDIRS=`scandirs`      LIST=`scandirs results/$ref_outp`
1204    elif test $xx = 'start_from' ; then
1205        xx=`echo $TESTDIRS | awk '{print $2}'`
1206        LIST=`scandirs results/$ref_outp | sed -n "/$xx/,$ p"`
1207    else
1208        #- expand group of experiments:
1209        LIST=" "
1210        for xx in $TESTDIRS
1211        do
1212          case $xx in
1213            'basic') LIST=${LIST}" aim.5l_cs hs94.128x64x5 ideal_2D_oce"
1214                     LIST=${LIST}" lab_sea tutorial_baroclinic_gyre"
1215                     LIST=${LIST}" tutorial_global_oce_latlon tutorial_plume_on_slope"
1216                    ;;
1217            'tutorials')
1218                     LIST=${LIST}" "`ls | grep 'tutorial_'` ;;
1219            *)       LIST=${LIST}" "$xx ;;
1220          esac
1221        done
1222    fi
1223    #echo 'LIST='${LIST}'<'
1224    #- skip dirs, remove duplicate and non-directory:
1225    TESTDIRS=" "
1226    count=0
1227    for xx in $LIST
1228    do
1229        yy=`echo $SKIPDIRS | grep -c $xx`
1230        if test $yy = 0 ; then
1231            if test -d $xx ; then
1232                yy=`echo $TESTDIRS | grep -c $xx`
1233                if test $yy = 0 ; then TESTDIRS=${TESTDIRS}" "$xx ; fi
1234            else count=1 ;
1235                echo ""; echo -n " -- skip \"$xx\" (not a directory !)"
1236            fi
1237        else
1238            if test $count = 1 ; then echo -n ", \"$xx\""
1239            else count=1 ; echo "" ;  echo -n " skip: \"$xx\""
1240            fi
1241        fi
1242    done
1243    if test $count = 1 ; then echo "" ; echo -n " ... " ; fi
1244    #echo 'TESTDIRS='${TESTDIRS}'<'
1245    
1246    if test "x$OPTFILE" = xNONE -a "x$MITGCM_OF" != x ; then
1247        OPTFILE=$MITGCM_OF
1248    fi
1249    
1250    LOC_MFILE='tr_mpi_mfile'
1251    RUNLOG="run.tr_log"
1252    OUTPUTFILE=$ref_outp
1253    if test "x$COMMAND" = x ; then
1254        COMMAND="./$EXECUTABLE > $OUTPUTFILE"
1255    fi
1256    if test "x$MPI" != x0 ; then
1257        OUTPUTFILE="STDOUT.0000"
1258  fi  fi
1259    
1260  echo "OK"  echo "OK (COMMAND= $COMMAND )"
1261    
1262    # set the Default List of output variables to be checked:
1263    #  (use default or load experiment-specific list from file "tr_checklist")
1264    # content : 1rst = main variable used to decide if it pass or FAIL
1265    #         others = number of matching digits to be printed in summary.txt
1266    if test $KIND = 1 ; then
1267        DEF_CHECK_LIST='tlmGrd tlmCst tlmGrd fwdGrd'
1268        EMPTY_RESULTS='.. .. ..'
1269        LEN_CHECK_LIST=`echo $DEF_CHECK_LIST | sed 's/ [a-zA-Z0-9]*+/&mn &mx &av &sd/g' | awk '{print NF-1}'`
1270    elif test $KIND = 2 -o $KIND = 4 ; then
1271        DEF_CHECK_LIST='AdGrd Cost AdGrd FDGrd'
1272        EMPTY_RESULTS='.. .. ..'
1273        LEN_CHECK_LIST=`echo $DEF_CHECK_LIST | sed 's/ [a-zA-Z0-9]*+/&mn &mx &av &sd/g' | awk '{print NF-1}'`
1274    else
1275        DEF_CHECK_LIST='PS PS T+ S+ U+ V+ pt1+ pt2+ pt3+ pt4+ pt5+'
1276        EMPTY_RESULTS='.. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. ..'
1277        LEN_CHECK_LIST=`echo $DEF_CHECK_LIST | sed 's/ [a-zA-Z0-9]*+/&mn &mx &av &sd/g' | awk '{print NF-1}'`
1278        ii=`echo $EMPTY_RESULTS | awk '{print NF}'`
1279        EMPTY_RESULTS=$EMPTY_RESULTS`expr $LEN_CHECK_LIST - $ii | awk 'BEGIN{FS=":"}{for(i=1;i<=$1;i++){printf "  ."}}'`
1280    fi
1281    
1282  #  create the FORTRAN comparison code  #  create the FORTRAN comparison code
1283  createcodelet  if test "x$CLEANUP" = xt -o -x tr_cmpnum ; then
1284        echo "skipping comparison code build"
1285    else
1286        createcodelet
1287    fi
1288    
1289  #  build the mpack utility  #  build the mpack utility (if ADDRESSES = NONE, do it to test the build)
1290  build_mpack  if test "x$ADDRESSES" = x ; then
1291        echo "skipping mpack build"
1292    else
1293        build_mpack
1294    fi
1295    
1296  #  Create a uniquely named directory to store results  #  Create a uniquely named directory to store results
1297    CMDLINE=$0
1298    for xx in "$@" ; do nw=`echo $xx | wc -w`
1299        if test $nw = '1' ; then CMDLINE="$CMDLINE $xx"
1300                            else CMDLINE="$CMDLINE '$xx'" ; fi
1301    done
1302    #for xx in "$@" ; do CMDLINE="$CMDLINE '$xx'" ; done
1303  MACH=`hostname`  MACH=`hostname`
1304    UNAMEA=`uname -a`
1305  DATE=`date +%Y%m%d`  DATE=`date +%Y%m%d`
1306  BASE=$MACH"_"$DATE"_"  BASE="tr_"$MACH"_"$DATE"_"
1307    if test "x$OUTDIR" != x ; then
1308        BASE="tr_"$OUTDIR"_"$DATE"_"
1309    else
1310        short_name=`hostname | sed 's/\..*$//'`
1311        BASE="tr_"$short_name"_"$DATE"_"
1312    fi
1313  DNUM=0  DNUM=0
1314  DRESULTS="$BASE$DNUM"  DRESULTS="$BASE$DNUM"
1315  while test -e $DRESULTS ; do  while test -e $DRESULTS ; do
# Line 474  done Line 1319  done
1319  mkdir $DRESULTS  mkdir $DRESULTS
1320  RETVAL=$?  RETVAL=$?
1321  if test "x$RETVAL" != x0 ; then  if test "x$RETVAL" != x0 ; then
1322      echo "Error: can't create results directory \"./$DRESULTS\""      echo "ERROR: Can't create results directory \"./$DRESULTS\""
1323      exit 1      exit 1
1324  fi  fi
1325  SUMMARY="$DRESULTS/summary.txt"  SUMMARY="$DRESULTS/summary.txt"
1326  date > $SUMMARY  start_date=`date`
1327  cat << EOF >> $SUMMARY  echo $start_date > $SUMMARY
1328                  T           S           U           V  echo 'run:' $CMDLINE >> $SUMMARY
1329  G D M    c        m  s        m  s        m  s        m  s  echo 'on :' $UNAMEA  >> $SUMMARY
1330  E p a R  g  m  m  e  .  m  m  e  .  m  m  e  .  m  m  e  .  
1331  N n k u  2  i  a  a  d  i  a  a  d  i  a  a  d  i  a  a  d  of_path=
1332  2 d e n  d  n  x  n  .  n  x  n  .  n  x  n  .  n  x  n  .  if test "x$OPTFILE" != xNONE ; then
1333        if test -r $OPTFILE ; then
1334            # get the path
1335            path=${OPTFILE%/*}
1336            if test "x$path" = x ; then
1337                of_path=`pwd`
1338            else
1339                of_path=`( cd $path > /dev/null 2>&1 ; pwd )`
1340            fi
1341            file=${OPTFILE##*/}
1342            OPTFILE=$of_path/$file
1343            cp $OPTFILE $DRESULTS
1344            echo >> $SUMMARY
1345            echo "  OPTFILE=$OPTFILE" >> $SUMMARY
1346        else
1347            echo | tee -a $SUMMARY
1348            echo "ERROR: can't read OPTFILE=\"$OPTFILE\"" | tee -a $SUMMARY
1349            exit 1
1350        fi
1351    else
1352        echo >> $SUMMARY
1353        echo "No \"OPTFILE\" was specified ; genmake2 found and uses:" >> $SUMMARY
1354        #-note: to be filled later after 1rst run
1355    fi
1356    echo
1357    echo >> $SUMMARY
1358    if test $KIND = 0 ; then
1359        line_0=`printf '%s %2i' 'default' $MATCH_CRIT`
1360           line_0="$line_0  ----T-----  ----S-----  ----U-----  ----V-----"
1361        line_1="G D M    c        m  s        m  s        m  s        m  s"
1362        line_2="e p a R  g  m  m  e  .  m  m  e  .  m  m  e  .  m  m  e  ."
1363        line_3="n n k u  2  i  a  a  d  i  a  a  d  i  a  a  d  i  a  a  d"
1364        line_4="2 d e n  d  n  x  n  .  n  x  n  .  n  x  n  .  n  x  n  ."
1365        for ii in $PTRACERS_NUM ; do
1366            line_0="$line_0  --PTR 0"$ii"--"
1367            line_1="$line_1        m  s"
1368            line_2="$line_2  m  m  e  ."
1369            line_3="$line_3  i  a  a  d"
1370            line_4="$line_4  n  x  n  ."
1371        done
1372    else
1373        line_0=`printf '%s %2i' 'default   ' $MATCH_CRIT`
1374      if test $KIND = 1 ; then
1375        echo "TANGLIN=true" >> $SUMMARY
1376        line_1="G D M    C  T  F"
1377        line_2="e p a R  o  L  D"
1378      else
1379        echo "ADJOINT=true" >> $SUMMARY
1380        line_1="G D M    C  A  F"
1381        line_2="e p a R  o  d  D"
1382      fi
1383        line_3="n n k u  s  G  G"
1384        line_4="2 d e n  t  r  r"
1385        echo >> $SUMMARY
1386    fi
1387    if test "x$CLEANUP" != xt ; then
1388        echo "$line_0" | tee -a $SUMMARY
1389        echo "$line_1" | tee -a $SUMMARY
1390        echo "$line_2" | tee -a $SUMMARY
1391        echo "$line_3" | tee -a $SUMMARY
1392        echo "$line_4" | tee -a $SUMMARY
1393        echo ""        | tee -a $SUMMARY
1394    fi
1395    echo "-------------------------------------------------------------------------------"
1396    
1397  EOF  #  ...and each test directory...
1398    for dir in $TESTDIRS ; do
1399    
1400  NDIR=0      # set builddir & rundir:
1401        builddir="build"
1402        if test ! -d $dir/$builddir ; then mkdir $dir/$builddir ; fi
1403        rundir="run"
1404        pfxdir="tr_$rundir"
1405        if test ! -d $dir/$rundir ; then
1406            rundir=$builddir
1407        fi
1408        CODE_DIR=$dir/$code_dir
1409        BUILD_DIR=$dir/$builddir
1410    
1411  #  For each optfile...      #  Cleanup only!
1412  for OPTFILE in $OPTFILES ; do      if test "x$CLEANUP" = xt ; then
1413            echo -n '  --- dir:' $BUILD_DIR ': '
1414            makeclean $BUILD_DIR
1415            (   cd $BUILD_DIR
1416                rm -f $EXECUTABLE *.bak
1417                rm -f genmake_state genmake_*optfile genmake.log
1418                rm -f SIZE.h.mpi genmake.tr_log make.tr_log
1419            )
1420            if test -d $dir/$rundir/CVS ; then
1421                echo -n '  --- dir:' $dir/$rundir ': '
1422                run_clean $dir/$rundir
1423            fi
1424            trdir=`( cd $dir ; find . -type d -name "$pfxdir.*" -print | sed 's/^.\///')`
1425            ttd=`echo $trdir | wc -w`
1426            if test $ttd != 0 ; then
1427                echo '  --- rm dir:' $trdir
1428                ( cd $dir ; rm -rf $trdir )
1429            fi
1430            continue
1431        fi
1432    
1433      OPTFILE=`pwd`"/$OPTFILE"      #  Verify that the testdir exists and contains previous
1434      if test ! -r $OPTFILE ; then      #  results in the correct location--or skip this directory!
1435          echo "Error: can't read optfile \"$OPTFILE\""      fout=$dir"/results/"$ref_outp
1436          exit 1     #if test ! -r $fout ; then
1437        if test ! -r $fout -a ! -r ${fout}.gz ; then
1438            echo "can't read \"$fout\" -- skipping $dir"
1439            continue
1440      fi      fi
     echo  
     echo "OPTFILE=$OPTFILE" >> $SUMMARY  
     echo >> $SUMMARY  
       
     #  ...and each test directory...  
     for dir in $TESTDIRS ; do  
           
         #  Create an output dir for each OPTFILE/tdir combination  
         CDIR=$DRESULTS"/"$NDIR  
         mkdir $CDIR  
         CDIR=`pwd`"/$CDIR"  
1441    
1442          #  ...configue, make, run, and compare the output.      # Check for specific files for particular type of run
1443          echo "-------------------------------------------------------------------------------"  
1444          echo      if test ! -r $CODE_DIR"/SIZE.h_mpi"  -a "x$MPI" != "x0" ; then
1445          echo "Experiment:  $dir"          echo "can't find \"$CODE_DIR/SIZE.h_mpi\" -- skipping $dir"
1446          echo          continue
1447          unset genmake makedepend make run      fi
1448          results='-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --'      if test ! -r $dir"/input/eedata.mth" -a "x$MULTI_THREAD" = "xt" ; then
1449          ( cd $dir/input; rm -f *.{o,f,c,F} *.[f,F]90 work* output.txt Make* make.log; )          echo "can't find \"$dir/input/eedata.mth\" -- skipping $dir"
1450          if [ -r $dir/build ]; then          continue
1451              seperatebuilddir=1      fi
1452              builddir=build  
1453              rundir=build      if test "x$MPI" != "x0" ; then
1454              ( cd $dir/build; ln -sf ../input/* . )          ntx=1 ; nty=1
1455          else          if test "x$MULTI_THREAD" = "xt" ; then
1456              seperatebuilddir=0            ff=$dir"/input/eedata.mth"
1457              builddir=input            ntx=`grep "^ *nTx *=" $ff | tail -1 | sed 's/^ *nTx *= *//' | sed "s/, *$//"`
1458              rundir=input            nty=`grep "^ *nTy *=" $ff | tail -1 | sed 's/^ *nTy *= *//' | sed "s/, *$//"`
1459              if test "x$ntx" = x ; then ntx=1 ; fi
1460              if test "x$nty" = x ; then nty=1 ; fi
1461          fi          fi
1462            #- create new SIZE.h with no more than '$MPI' Procs
1463            mk_mpi_size $CODE_DIR"/SIZE.h_mpi" $BUILD_DIR"/tr_size.mpi" $MPI $ntx $nty
1464            LOC_NPROC=$?
1465            (   cd $BUILD_DIR
1466                if test -r SIZE.h.mpi ; then
1467                    cmp tr_size.mpi SIZE.h.mpi > /dev/null 2>&1 ; RETVAL=$?
1468                else RETVAL=1
1469                fi
1470                if test "x$RETVAL" = x0 ; then
1471                    rm -f tr_size.mpi
1472                else
1473                    rm -f SIZE.h.mpi ; mv tr_size.mpi SIZE.h.mpi
1474                fi
1475            )
1476            if test "x$MPI_MFILE" != x ; then
1477                #- create new MPI machine-file with the right number of Procs
1478                rm -f $LOC_MFILE
1479                cat $MPI_MFILE | sort | uniq | head -$LOC_NPROC > $LOC_MFILE
1480                nl=`wc -l $LOC_MFILE | awk '{print $1}'`
1481                if [ $nl -lt $LOC_NPROC ] ; then
1482                    rm -f $LOC_MFILE
1483                    cat $MPI_MFILE | head -$LOC_NPROC > $LOC_MFILE
1484                    #sed -n "1,$LOC_NPROC p" $MPI_MFILE > $LOC_MFILE
1485                fi
1486                if [ $verbose -gt 1 ]; then
1487                    nl=`wc -l $LOC_MFILE | awk '{print $1}'`
1488                    echo " new LOC_MFILE=$LOC_MFILE : $nl procs for LOC_NPROC=$LOC_NPROC"
1489                fi
1490            fi
1491            if test "x$MULTI_THREAD" = "xt" ; then
1492                retv=`check_eedata $dir"/input/eedata.mth" $BUILD_DIR"/SIZE.h.mpi"`
1493                if test $retv != 0 ; then
1494                    echo "input/eedata.mth tiling misfit -- skipping $dir"
1495                    continue
1496                fi
1497            fi
1498        fi
1499    
1500        #  Check whether there are "extra runs" for this testdir
1501        extra_runs=
1502        if test "x$NORUN" = xf ; then
1503            ex_run_dirs=`( cd $dir ; echo $inputdir.* )`
1504        fi
1505        #echo "ex_run_dirs='$ex_run_dirs'"
1506        for exd in $ex_run_dirs ; do
1507            name=`echo $exd | sed -e "s/$inputdir\.//"`
1508            refExOut=`echo $ref_outp | sed "s/\./.${name}./"`
1509            outf="$dir/results/$refExOut"
1510            #if test -f $outf -a -r $outf ; then
1511            if test -r $outf -o -r ${outf}.gz ; then
1512              if test "x$MULTI_THREAD" = "xt" ; then
1513                if test -r $dir"/"$exd"/eedata.mth" ; then
1514                  if test "x$MPI" = "x0" ; then
1515                    extra_runs="$extra_runs $name"
1516                  else
1517                    retv=`check_eedata $dir"/"$exd"/eedata.mth" $BUILD_DIR"/SIZE.h.mpi"`
1518                    if test $retv = 0 ; then
1519                        extra_runs="$extra_runs $name"
1520                    else
1521                        echo $exd"/eedata.mth tiling misfit -- skipping $dir"
1522                    fi
1523                  fi
1524                #else echo $dir"/"$exd"/eedata.mth: not found"
1525                fi
1526              else
1527                extra_runs="$extra_runs $name"
1528              fi
1529            fi
1530        done
1531    
1532        echo
1533        if test "x$extra_runs" = "x" ; then
1534            echo "Experiment:  $dir"
1535        else
1536            echo "Experiment:  $dir ; extra_runs=$extra_runs"
1537        fi
1538        echo
1539        unset genmake makedepend make run
1540        results=$EMPTY_RESULTS
1541    
1542        #  Create an output dir & summary.txt file for each tested experiment (tdir)
1543        locDIR=$DRESULTS"/"$dir
1544        mkdir $locDIR
1545        #- report to this experiment local summary file ---
1546        echo "DATE='$DATE' ; tdir='$dir'" > $locDIR"/summary.txt"
1547        echo "MACH='$MACH'" >> $locDIR"/summary.txt"
1548        echo "UNAMEA='$UNAMEA'" >> $locDIR"/summary.txt"
1549        CDIR=`pwd`"/$locDIR"
1550    
1551        if test "x$NORUN" = xt ; then
1552                run=N
1553            genmakemodel $dir/$builddir && genmake=Y \
1554                && makeclean $dir/$builddir \
1555                && symlink_mpifiles $dir $code_dir $builddir \
1556                && makedependmodel $dir/$builddir && makedepend=Y \
1557                && makemodel $dir/$builddir && make=Y
1558        else
1559          genmakemodel $dir/$builddir && genmake=Y \          genmakemodel $dir/$builddir && genmake=Y \
1560              && makeclean $dir/$builddir \              && makeclean $dir/$builddir \
1561                && symlink_mpifiles $dir $code_dir $builddir \
1562              && makedependmodel $dir/$builddir && makedepend=Y \              && makedependmodel $dir/$builddir && makedepend=Y \
1563              && makemodel $dir/$builddir && make=Y \              && makemodel $dir/$builddir && make=Y \
1564              && linkdata $seperatebuilddir $dir/$rundir \              && run_clean $dir/$rundir \
1565              && runmodel $dir/$builddir mitgcmuv && run=Y \              && linkdata $dir/$rundir $inputdir \
1566              && results=`testoutput $dir $rundir`              && runmodel $dir/$rundir && run=Y \
1567          echo              && results=`testoutput_run $dir $rundir $ref_outp`
1568          formatresults $dir ${genmake:-N} ${makedepend:-N} ${make:-N} ${run:-N} $results      fi
1569          echo      #echo "results='$results'"
         formatresults $dir ${genmake:-N} ${makedepend:-N} ${make:-N} ${run:-N} $results >> $SUMMARY  
1570    
1571          ( cd $DRESULTS"/"$NDIR ; gzip * )          fres=`formatresults $dir ${genmake:-N} ${makedepend:-N} ${make:-N} ${run:-N} $results`
1572            echo 1>&2
1573            echo "$fres" | sed 's/ 99/ --/g' | sed 's/  > />/' | sed 's/  < /</' >> $SUMMARY
1574            echo "fresults='$fres'" | sed 's/ 99/ --/g' >> $locDIR"/summary.txt"
1575    
1576            for ex in $extra_runs ; do
1577                unset run
1578                results=$EMPTY_RESULTS
1579                #  reference output file
1580                refExOut=`echo $ref_outp | sed "s/\./.${ex}./g"`
1581                #  Create an output dir & summary.txt file for each extra run (tdir.ex)
1582                locDIR=$DRESULTS"/"$dir"."$ex
1583                mkdir $locDIR
1584                #- report to this experiment local summary file ---
1585                echo "DATE='$DATE' ; tdir='$dir.$ex'" > $locDIR"/summary.txt"
1586                #echo "MACH='$MACH'" >> $locDIR"/summary.txt"
1587                #echo "UNAMEA='$UNAMEA'" >> $locDIR"/summary.txt"
1588                CDIR=`pwd`"/$locDIR"
1589                test ! -e "$dir/$pfxdir.$ex" && mkdir "$dir/$pfxdir.$ex"
1590                run_clean $dir/$pfxdir.$ex
1591                linkdata $dir/$pfxdir.$ex $inputdir.$ex $inputdir
1592                runmodel $dir/$pfxdir.$ex && run=Y \
1593                && results=`testoutput_run $dir $pfxdir.$ex $refExOut`
1594                fres=`formatresults $dir ${genmake:-N} ${makedepend:-N} ${make:-N} ${run:-N} $results`
1595                fres="$fres.$ex"
1596                echo 1>&2
1597                echo "$fres" | sed 's/ 99/ --/g' | sed 's/  > />/' | sed 's/  < /</' >> $SUMMARY
1598                echo "fresults='$fres'" | sed 's/ 99/ --/g' >> $locDIR"/summary.txt"
1599                if test "x$POSTCLEAN" = x2 ; then
1600                    run_clean $dir/$pfxdir.$ex
1601                fi
1602            done
1603    
1604          tar -cf $DRESULTS"/"$NDIR".tar" $DRESULTS"/"$NDIR      if test ! -f $DRESULTS"/"genmake_state ; then
1605          $MPACK -s MITgcm-test -m 1000000 $DRESULTS"/"$NDIR".tar" $ADDRESSES          if test -f $dir/$builddir/Makefile ; then
1606                mkOpt=`grep '^# OPTFILE=' $dir/$builddir/Makefile 2>/dev/null | head -1 | sed 's/^# //'`
1607                echo "from '$dir/$builddir/Makefile', extract:" > $DRESULTS/genmake_state
1608                sed -n '/^# executed by:/,+1 p' $dir/$builddir/Makefile >> $DRESULTS/genmake_state
1609                echo " $mkOpt" >> $DRESULTS/genmake_state
1610                if test "x$OPTFILE" = xNONE ; then
1611                    eval $mkOpt
1612                    sed "/^No \"OPTFILE\" was specified ; genmake2/a\  OPTFILE=${OPTFILE}"\
1613                            $SUMMARY > tmp.tr_log
1614                    RETVAL=$?
1615                    if test "x$RETVAL" = x0 ; then rm -f $SUMMARY
1616                            cp tmp.tr_log $SUMMARY
1617                    else rm -f tmp.tr_log
1618                    fi
1619                fi
1620                gmkLog=$dir/$builddir/genmake.log
1621                if test -r $gmkLog ; then
1622                    grep '^Get compiler version using:' $gmkLog > /dev/null 2>&1
1623                    RETVAL=$?
1624                    if test "x$RETVAL" = x0 ; then
1625                      echo -n "from '$gmkLog', " >> $DRESULTS/genmake_state
1626                      echo "extract compiler version:"   >> $DRESULTS/genmake_state
1627                      sed -n '/Get compiler version/,/<-- compiler version/p' \
1628                         $gmkLog | grep -v '^... compiler version ' > tmp.tr_log
1629                      sed -n '1p' tmp.tr_log >> $DRESULTS/genmake_state
1630                      sed -n '2,/^$/p' tmp.tr_log | sed '/^$/d' | sed 's/^./ &/' \
1631                                             >> $DRESULTS/genmake_state
1632                      rm -f tmp.tr_log
1633                    fi
1634                    echo -n "from '$gmkLog', " >> $DRESULTS/genmake_state
1635                    echo "get NETCDF & LAPACK settings:" >> $DRESULTS/genmake_state
1636                    sed -n '/set HAVE_NETCDF=/p' $gmkLog >> $DRESULTS/genmake_state
1637                    sed -n '/set HAVE_LAPACK=/p' $gmkLog >> $DRESULTS/genmake_state
1638                fi
1639            fi
1640        fi
1641        #postclean $dir/$builddir
1642        if test "x$POSTCLEAN" = x2 ; then
1643            makeclean $dir/$builddir \
1644                && run_clean $dir/$rundir
1645        fi
1646        if test "x$MPI" != x0 -a "x$MPI_MFILE" != x ; then rm -f $LOC_MFILE ; fi
1647    
1648          NDIR=$(( $NDIR + 1 ))      echo "-------------------------------------------------------------------------------"
           
     done  
 done  
1649    
1650  # rm tmp_cmpnum.f a.out  done
1651    
1652  echo -------------------------------------------------------------------------------  printf "Start time:  " >> $SUMMARY
1653  echo  echo "$start_date" >> $SUMMARY
1654  echo >> $SUMMARY  printf "End time:    " >> $SUMMARY
1655  date >> $SUMMARY  date >> $SUMMARY
 cat $SUMMARY  
1656    
1657  # tar -cf $DRESULTS".tar" $DRESULTS  #  If addresses were supplied and mpack built successfully, then try
1658  #  #  to send email using mpack.
1659  # $MPACK -s MITgcm-test -m 1000000 $DRESULTS".tar" $ADDRESSES  if test "x$ADDRESSES" = xNONE -o "x$ADDRESSES" = x ; then
1660        echo "No results email was sent."
1661    else
1662        if test "x$HAVE_MPACK" = xt ; then
1663            tar -cf $DRESULTS".tar" $DRESULTS > /dev/null 2>&1 \
1664                && gzip $DRESULTS".tar" \
1665                && $MPACK -s MITgcm-test -m 3555000 $DRESULTS".tar.gz" $ADDRESSES
1666            RETVAL=$?
1667            if test "x$RETVAL" != x0 ; then
1668                echo
1669                echo "Warning: The tar, gzip, & mpack step failed.  Please send email"
1670                echo "  to <MITgcm-support@mitgcm.org> for help.  You may copy the "
1671                echo "  summary of results from the directory \"$DRESULTS\"."
1672                echo
1673            else
1674                echo
1675                echo "An email containing results was sent to the following addresses:"
1676                echo "  \"$ADDRESSES\""
1677                echo
1678                test -f $DRESULTS".tar"  &&  rm -f $DRESULTS".tar"
1679                test -f $DRESULTS".tar.gz"  &&  rm -f $DRESULTS".tar.gz"
1680            fi
1681        fi
1682    fi
1683    
1684    if test "x$QUICK" = xf -a "x$NORUN" = xf ; then
1685        rm -f tr_cmpnum.c tr_cmpnum
1686    fi
1687    
1688    if test "x$CLEANUP" != xt ; then
1689        cat $SUMMARY | sed 's/ \.  \.  \.  \.  \.  \.  \.  \.  \.  \.  \.  \. //'
1690        if test -e tr_out.txt ; then
1691            mv tr_out.txt tr_out.txt.old
1692        fi
1693        cat $SUMMARY | sed '/^[YN] [YN] [YN] [YN]/ s/ \. //g' > tr_out.txt
1694    fi
1695    
1696    if test "x$DELDIR" = xt ; then
1697        rm -rf $DRESULTS
1698    fi
1699    echo "======== End of testreport execution ========"

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.179

  ViewVC Help
Powered by ViewVC 1.1.22