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

Legend:
Removed from v.1.9.2.5  
changed lines
  Added in v.1.164

  ViewVC Help
Powered by ViewVC 1.1.22