/[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.2 by edhill, Mon Sep 1 16:50:27 2003 UTC revision 1.112 by jmc, Sat Feb 9 18:30:25 2008 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)                   compile and run using MPI"
16      echo "  (-t|-tdir)STRING         list of \"test\" dirs"      echo "  (-ieee|-noieee)          if possible, use IEEE compiler flags"
17        echo "                             (DEF=\"-ieee\")"
18        echo "  (-gsl)                   compile with \"-gsl\" flag"
19        echo "  (-of=|-optfile=)STRING   list of optfiles to use"
20        echo "  (-a|-addr) STRING        list of email recipients"
21        echo "                             (DEF=\"\" no email is sent)"
22        echo "  (-t|-tdir) STRING        list of group and/or exp. dirs to test"
23        echo "                             (recognized groups: basic, tutorials)"
24        echo "                             (DEF=\"\" which test all)"
25        echo "  (-skd|-skipdir) STRING   list of exp. dirs to skip"
26        echo "                             (DEF=\"\" which test all)"
27        echo "  (-b|-bash) STRING        preferred location of a \"bash\" or"
28        echo "                             Bourne-compatible \"sh\" shell"
29        echo "                             (DEF=\"\" for \"bash\")"
30        echo "  (-adm|-ad)               perform an adjoint run"
31        echo "  (-command) STRING        command to run"
32        echo "                             (DEF=\"make output.txt\")"
33        echo "  (-m|-make) STRING        command to use for \"make\""
34        echo "                             (DEF=\"make\")"
35        echo "  (-odir) STRING           used to build output directory name"
36        echo "                             (DEF=\"hostname\")"
37        echo "  (-ptr|-ptracers) STRING  specify which ptracers to test"
38        echo "                             (DEF=\"1 2 3 4 5\")"
39        echo "  (-match) NUMBER          Matching Criteria (number of digits)"
40        echo "                             (DEF=\"12\")"
41        echo "  (-j) JOBS                use \"make -j JOBS\" for parallel builds"
42        echo "  (-clean)                 *ONLY* run \"make CLEAN\""
43        echo "  (-quick|-q)              same as \"-nogenmake -noclean -nodepend\""
44        echo "  (-nogenmake|-ng)         skip the genmake stage"
45        echo "  (-noclean|-nc)           skip the \"make clean\" stage"
46        echo "  (-nodepend|-nd)          skip the \"make depend\" stage"
47        echo "  (-deldir|-dd)            on success, delete the output directory"
48        echo "  (-ts)                    provide timing information per timestep"
49        echo "  (-papis)                 provide MFlop/s per timestep using PAPI"
50        echo "  (-pcls)                  provide MFlop/s per timestep using PCL"
51        echo
52        echo "and where STRING can be a whitespace-delimited list"
53        echo "such as:"
54        echo
55        echo "  -t 'exp0 exp2 exp3' "
56        echo "  -addr='abc@123.com testing@home.org'"
57        echo
58        echo "provided that the expression is properly quoted within the current"
59        echo "shell (note the use of single quotes to protect white space)."
60      echo      echo
61      exit 1      exit 1
62  }  }
# Line 20  usage() Line 64  usage()
64  #  build the mpack utility  #  build the mpack utility
65  build_mpack()  build_mpack()
66  {  {
67      echo -n "building the mpack utility...  "      printf "building the mpack utility...  "
68      if test ! -x "$MPACKDIR/mpack" ; then      if test ! -x "$MPACKDIR/mpack" ; then
69          if test ! -d $MPACKDIR ; then          if test ! -d $MPACKDIR ; then
70                echo
71              echo "Error: can't find \"$MPACKDIR\""              echo "Error: can't find \"$MPACKDIR\""
72              echo "  are you sure this program is being run in the correct "              echo "  are you sure this program is being run in the correct "
73              echo "  (that is, \"MITGCM_ROOT\verification\") directory?"              echo "  (that is, \"MITGCM_ROOT\verification\") directory?"
74              exit 1              echo
75                HAVE_MPACK=f
76            fi
77            if test "x$CC" = x ; then
78                export CC=cc
79          fi          fi
80          echo -n "building mpack...  "          printf "building mpack (using CC=$CC)...  "
81          ( cd $MPACKDIR && ./configure && make ) > build_mpack.out 2>&1          ( cd $MPACKDIR && ./configure && $MAKE ) > tr_build_mpack.out 2>&1
82          RETVAL=$?          RETVAL=$?
83          if test "x$RETVAL" != x0 ; then          if test "x$RETVAL" != x0 ; then
84              echo              echo
85              echo "Error building the mpack tools at: $MPACK_DIR"              echo "Error building the mpack tools at: $MPACK_DIR"
86              exit 1              echo
87                HAVE_MPACK=f
88            else
89                rm -f tr_build_mpack.out
90                HAVE_MPACK=t
91                echo "OK"
92          fi          fi
93        else
94            HAVE_MPACK=t
95            echo "done"
96      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`  
97  }  }
98    
99  testoutput_for_prop()  testoutput_var()
100  {  {
101      # testoutput_for_prop dir s1 label subdir      # testoutput_var dir s1 label subdir reference_output
102      #      #
103      #  compares files in $dir/$subdir/output.txt and $dir/results/output.txt      #  compares 1 variable output selected from file $dir/$subdir/$OUTPUTFILE
104      #  using search strings s1 and text label      #     with same output from reference file $dir/results/$reference_output
105        #  using search strings s1 and text label
106    
107      if [ $debug -gt 0 ]; then      if [ $debug -gt 0 ]; then
108          echo testoutput_for_prop: grep "$2" $1/$4/output.txt 1>&2          echo testoutput_var: grep "$2" $1/$4/$OUTPUTFILE 1>&2
109      fi      fi
110      if [ -r $1/$4/output.txt ]; then      if [ -r $1/$4/$OUTPUTFILE ]; then
111          grep "$2" $1/$4/output.txt | sed 's/.*=//' | nl > tmp1.txt          grep "$2" $1/$4/$OUTPUTFILE | sed 's/.*=//' | cat -n > tmp1.txt
112          lncnt=`wc -l tmp1.txt | awk '{print $1}' `          lncntA=`wc -l tmp1.txt | awk '{print $1}' `
113          if [ $lncnt -lt 3 ]; then          if [ $lncntA -lt 2 ]; then
114              if [ $verbose -gt 0 ]; then              if [ $verbose -gt 0 ]; then
115                  echo Not enough lines of output when searching for "$2" 1>&2                  echo Not enough lines of output when searching for "$2" 1>&2
116              fi              fi
117              return 99              return 99
118          fi          fi
119      else      else
120          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
121          return 99          return 99
122      fi      fi
123      if [ $debug -gt 0 ]; then      if [ $debug -gt 0 ]; then
124          echo testoutput_for_prop: grep "$2" $1/results/output.txt 1>&2          echo testoutput_var: grep "$2" $1/results/$5 1>&2
125      fi      fi
126      grep "$2" $1/results/output.txt | sed 's/.*=//' | nl > tmp2.txt      grep "$2" $1/results/$5 | sed 's/.*=//' | cat -n > tmp2.txt
127      lncnt=`wc -l tmp2.txt | awk '{print $1}' `      lncntB=`wc -l tmp2.txt | awk '{print $1}' `
128      if [ $lncnt -lt 3 ]; then      if [ $lncntB -lt 2 ]; then
129          if [ $verbose -gt 0 ]; then          if [ $verbose -gt 0 ]; then
130              echo Not enough lines of output when searching for "$2" 1>&2              echo Not enough lines of output when searching for "$2" 1>&2
131          fi          fi
132          return 99          return 99
133      fi      fi
134        if [ $lncntA -ne $lncntB ]; then
135            if [ $verbose -gt 0 ]; then
136                echo Not same Nb of lines when searching for "$2" ":" $lncntA $lncntB 1>&2
137            fi
138            return 99
139        fi
140        has_nan=`cat tmp1.txt | grep -i nan | wc -l`
141        if [ $has_nan -gt 0  ] ; then
142            echo testoutput_var: $OUTPUTFILE contains $has_nan NaN values  1>&2
143            return 99
144        fi
145        has_inf=`cat tmp1.txt | grep -i inf | wc -l`
146        if [ $has_inf -gt 0  ] ; then
147            echo testoutput_var: $OUTPUTFILE contains $has_inf Inf values  1>&2
148            return 99
149        fi
150      if [ $debug -gt 0 ]; then      if [ $debug -gt 0 ]; then
151          echo testoutput_for_prop: join tmp1.txt tmp2.txt 1>&2          echo testoutput_var: join tmp1.txt tmp2.txt 1>&2
152      fi      fi
153      join tmp1.txt tmp2.txt | awk '{print $1 " " $2 " " $3}' > tmp3.txt      join tmp1.txt tmp2.txt | awk '{print $1 " " $2 " " $3}' > tmp3.txt
154      if [ $debug -gt 0 ]; then      if [ $debug -gt 0 ]; then
155          echo testoutput_for_prop: compare_lines 1>&2          echo testoutput_var: compare_lines 1>&2
156      fi      fi
157      compare_lines      if [ $verbose -gt 1 ]; then
158      digits_of_similarity=$?          cat tmp3.txt 1>&2
159        fi
160        echo "-1" >> tmp3.txt
161        # On the SGI O3K (*not* the O2K), "cat -n" inserts a ":" after the line number
162        cat tmp3.txt | sed -e 's|:||g' > tmp4.txt
163        digits_of_similarity=`./tr_cmpnum < tmp4.txt`
164      if [ $digits_of_similarity -eq 99 ]; then      if [ $digits_of_similarity -eq 99 ]; then
165          if [ $verbose -gt 0 ]; then          if [ $verbose -gt 0 ]; then
166              echo testoutput_for_prop: No comparison was available for \"$2\" 1>&2              echo testoutput_var: No comparison was available for \"$3\" 1>&2
167          fi          fi
168          digits_of_similarity=99          digits_of_similarity=99
169      else      else
170          if [ $verbose -gt 0 ]; then          if [ $verbose -gt 0 ]; then
171              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
172          fi          fi
173      fi      fi
174      rm tmp1.txt tmp2.txt tmp3.txt      rm -f tmp1.txt tmp2.txt tmp3.txt tmp4.txt
175            
176      return $digits_of_similarity      return $digits_of_similarity
177  }  }
178    
179  dashnum()  check_for_add_mon_output()
180  {  {
181      # dashnum n1 n2 n3 ...      # Check for additional types of monitor output
182      #      if test "x$1" = x ; then
183      #  print numbers using %3i format or "--" if number = 99          return
184        fi
185    
186      for num in $@ ; do      for ii in $PTRACERS_NUM ; do
187          if [ $num = 99 ]; then          eval "HAVE_PTR0"$ii"=f"
188              printf ' --'      done
189          else  
190              printf '%3i' $num      ptr_add="trcstat_ptracerXX_min trcstat_ptracerXX_max"
191          fi      ptr_add="$ptr_add trcstat_ptracerXX_mean trcstat_ptracerXX_sd"
192        for ii in $PTRACERS_NUM ; do
193            for jj in $ptr_add ; do
194                name=`eval "echo $jj | sed -e 's|XX|0"$ii"|g'"`
195                tst=`grep $name $1 | wc -l | awk '{print $1}'`
196                if test ! "x$tst" = x0 ; then
197                    eval "HAVE_PTR0"$ii"=t"
198                fi
199            done
200            #  eval 'echo "HAVE_PTR0'$ii' = $HAVE_PTR0'$ii'"'
201      done      done
202  }  }
203    
204  testoutput()  testoutput_run()
205  {  {
206      # testoutput diretory subdir      # testoutput_run directory subdir reference_output
207      #      #
208      #  test output in "directory"      #  test output from 1 run in "directory"
209    # --> same processing for adjoint & forward test
210      if [ $debug -gt 0 ]; then          # default list of output variables to be checked:
211          echo testoutput: testoutput_for_prop $1 cg2d_init_res 1>&2          #  1rst : main variable used to decide if it pass or FAIL
212      fi          #  others : number of matching digits to be printed in summary.txt
213      testoutput_for_prop $1 "cg2d_init_res" "cg2d init. residual" $2; cg2dres=$?          listChk=$DEF_CHECK_LIST
214      if [ $debug -gt 0 ]; then          #  load experiment-specific list from file "tr_checklist" (if it exist)
215          echo testoutput: cg2dres=$cg2dres 1>&2          if test -r $1/$2/tr_checklist ; then listChk=`cat $1/$2/tr_checklist` ; fi
216      fi          sVar=`echo $listChk | awk '{print $1}'`
217                # remove 1rst var and expand the list: + => min max mean s.d
218      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' \
219      testoutput_for_prop $1 "dynstat_theta_max" "theta maximum" $2; tmax=$?                                 | sed 's/+//g' | sed "s/^$sVar//"`
220      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
221      testoutput_for_prop $1 "dynstat_theta_sd" "theta s.d." $2; tsd=$?          for ii in 1 2 3 4 5 6 7 8 9 ; do
222      testoutput_for_prop $1 "dynstat_salt_min" "salt minimum" $2; smin=$?            tst=`eval 'echo "$HAVE_PTR0'$ii'"'`
223      testoutput_for_prop $1 "dynstat_salt_max" "salt maximum" $2; smax=$?           #echo "-- ptr test=" $tst "number of var=" `echo $listVar | awk '{print NF}'` 1>&2
224      testoutput_for_prop $1 "dynstat_salt_mean" "salt mean" $2; smean=$?            if test "x$tst" != xt ; then listVar=`echo "$listVar" | sed "s/ pt$ii..//g"` ; fi
225      testoutput_for_prop $1 "dynstat_salt_sd" "salt s.d." $2; ssd=$?          done
226      testoutput_for_prop $1 "dynstat_uvel_min" "U minimum" $2; umin=$?          tst=`echo $sVar $listVar | awk '{ for(i=2;i<=NF;i++){t+=($i==$1)}; print t }'`
227      testoutput_for_prop $1 "dynstat_uvel_max" "U maximum" $2; umax=$?          if test $tst != 1 ; then
228      testoutput_for_prop $1 "dynstat_uvel_mean" "U mean" $2; umean=$?            if test $tst = 0 ; then echo "==> WARNING: selected var >$sVar< not found" 1>&2
229      testoutput_for_prop $1 "dynstat_uvel_sd" "U s.d." $2; usd=$?                   else echo "==> WARNING: found selected var >$sVar< $tst times" 1>&2 ; fi
230      testoutput_for_prop $1 "dynstat_vvel_min" "V minimum" $2; vmin=$?            echo "==> WARNING: in checked list:" $listVar 1>&2
231      testoutput_for_prop $1 "dynstat_vvel_max" "V maximum" $2; vmax=$?          #- put it back once:
232      testoutput_for_prop $1 "dynstat_vvel_mean" "V mean" $2; vmean=$?            listVar=" $sVar "`echo "$listVar " | sed "s/ $sVar / /g"`
233      testoutput_for_prop $1 "dynstat_vvel_sd" "V s.d." $2; vsd=$?          fi
234                if [ $debug -gt 0 ]; then echo "testoutput_run: listVar(M)='$listVar'" 1>&2 ; fi
235      dashnum $cg2dres $tmin $tmax $tmean $tsd $smin $smax $smean $ssd \          echo "listVar='$listVar'" > $CDIR"/summary.txt"
236          $umin $umax $umean $usd $vmin $vmax $vmean $vsd          allargs=""
237            for xx in $listVar
238            do
239              case $xx in
240               'PS')  if [ $debug -gt 0 ]
241                      then echo testoutput_run: testoutput_var $1 cg2d_init_res 1>&2 ; fi
242                      testoutput_var $1 "cg2d_init_res" "Press. Solver (cg2d)" $2 $3; yy=$?
243                      if [ $debug -gt 0 ] ; then echo testoutput_run: cg2dres=$yy 1>&2 ; fi ;;
244              'Cost') testoutput_var $1 "ADM  precision_derivative_cost" "ADM Cost" $2 $3; yy=$? ;;
245              'Grad') testoutput_var $1 "ADM  precision_derivative_grad" "ADM Grad" $2 $3; yy=$? ;;
246               'Tmn') testoutput_var $1 "dynstat_theta_min"  "Theta minimum"  $2 $3; yy=$? ;;
247               'Tmx') testoutput_var $1 "dynstat_theta_max"  "Theta maximum"  $2 $3; yy=$? ;;
248               'Tav') testoutput_var $1 "dynstat_theta_mean" "Theta mean"     $2 $3; yy=$? ;;
249               'Tsd') testoutput_var $1 "dynstat_theta_sd"   "Theta Std.Dev"  $2 $3; yy=$? ;;
250               'Smn') testoutput_var $1 "dynstat_salt_min"  "Salt minimum"    $2 $3; yy=$? ;;
251               'Smx') testoutput_var $1 "dynstat_salt_max"  "Salt maximum"    $2 $3; yy=$? ;;
252               'Sav') testoutput_var $1 "dynstat_salt_mean" "Salt mean"       $2 $3; yy=$? ;;
253               'Ssd') testoutput_var $1 "dynstat_salt_sd"   "Salt Std.Dev"    $2 $3; yy=$? ;;
254               'Umn') testoutput_var $1 "dynstat_uvel_min"  "U minimum"       $2 $3; yy=$? ;;
255               'Umx') testoutput_var $1 "dynstat_uvel_max"  "U maximum"       $2 $3; yy=$? ;;
256               'Uav') testoutput_var $1 "dynstat_uvel_mean" "U mean"          $2 $3; yy=$? ;;
257               'Usd') testoutput_var $1 "dynstat_uvel_sd"   "U Std.Dev"       $2 $3; yy=$? ;;
258               'Vmn') testoutput_var $1 "dynstat_vvel_min"  "V minimum"       $2 $3; yy=$? ;;
259               'Vmx') testoutput_var $1 "dynstat_vvel_max"  "V maximum"       $2 $3; yy=$? ;;
260               'Vav') testoutput_var $1 "dynstat_vvel_mean" "V mean"          $2 $3; yy=$? ;;
261               'Vsd') testoutput_var $1 "dynstat_vvel_sd"   "V Std.Dev"       $2 $3; yy=$? ;;
262            'pt1mn'|'pt2mn'|'pt3mn'|'pt4mn'|'pt5mn') ii=`echo $xx | sed 's/pt//' | sed 's/..$//'`
263               testoutput_var $1 "trcstat_ptracer0"$ii"_min"  "p0"$ii"_min"   $2 $3; yy=$? ;;
264            'pt1mx'|'pt2mx'|'pt3mx'|'pt4mx'|'pt5mx') ii=`echo $xx | sed 's/pt//' | sed 's/..$//'`
265               testoutput_var $1 "trcstat_ptracer0"$ii"_max"  "p0"$ii"_max"   $2 $3; yy=$? ;;
266            'pt1av'|'pt2av'|'pt3av'|'pt4av'|'pt5av') ii=`echo $xx | sed 's/pt//' | sed 's/..$//'`
267               testoutput_var $1 "trcstat_ptracer0"$ii"_mean" "p0"$ii"_mean" $2 $3; yy=$? ;;
268            'pt1sd'|'pt2sd'|'pt3sd'|'pt4sd'|'pt5sd') ii=`echo $xx | sed 's/pt//' | sed 's/..$//'`
269               testoutput_var $1 "trcstat_ptracer0"$ii"_sd"   "p0"$ii"_StDv"  $2 $3; yy=$? ;;
270             'Qntmn') testoutput_var $1 "extforcing_qnet_min" "Qnet minimum"  $2 $3; yy=$? ;;
271             'Qntmx') testoutput_var $1 "extforcing_qnet_max" "Qnet maximum"  $2 $3; yy=$? ;;
272             'Qntav') testoutput_var $1 "extforcing_qnet_mean" "Qnet mean"    $2 $3; yy=$? ;;
273             'Qntsd') testoutput_var $1 "extforcing_qnet_sd"  "Qnet Std.Dev"  $2 $3; yy=$? ;;
274             'aSImn') testoutput_var $1 "seaice_area_min"   "SIce Area min"   $2 $3; yy=$? ;;
275             'aSImx') testoutput_var $1 "seaice_area_max"   "SIce Area max"   $2 $3; yy=$? ;;
276             'aSIav') testoutput_var $1 "seaice_area_mean"  "SIce Area mean"  $2 $3; yy=$? ;;
277             'aSIsd') testoutput_var $1 "seaice_area_sd"    "SIce Area StDv"  $2 $3; yy=$? ;;
278             'hSImn') testoutput_var $1 "seaice_heff_min"   "SIce Heff min"   $2 $3; yy=$? ;;
279             'hSImx') testoutput_var $1 "seaice_heff_max"   "SIce Hell max"   $2 $3; yy=$? ;;
280             'hSIav') testoutput_var $1 "seaice_heff_mean"  "SIce Hell mean"  $2 $3; yy=$? ;;
281             'hSIsd') testoutput_var $1 "seaice_heff_sd"    "SIce Hell StDv"  $2 $3; yy=$? ;;
282            'AthSiG') testoutput_var $1 "thSI_Ice_Area_G" "thSIc Area Global" $2 $3; yy=$? ;;
283            'AthSiS') testoutput_var $1 "thSI_Ice_Area_S" "thSIc Area South"  $2 $3; yy=$? ;;
284            'AthSiN') testoutput_var $1 "thSI_Ice_Area_N" "thSIc Area North"  $2 $3; yy=$? ;;
285            'HthSiG') testoutput_var $1 "thSI_IceH_ave_G" "thSIc H Global"    $2 $3; yy=$? ;;
286            'HthSiS') testoutput_var $1 "thSI_IceH_ave_S" "thSIc H South"     $2 $3; yy=$? ;;
287            'HthSiN') testoutput_var $1 "thSI_IceH_ave_N" "thSIc H North"     $2 $3; yy=$? ;;
288                  *) yy=99; echo "WARNING: asking for var=$xx : not recognized !" 1>&2 ;;
289              esac
290              if test $xx = $sVar
291              then allargs="$allargs > $yy <"
292              else allargs="$allargs $yy"
293              fi
294            done
295    
296            nbVar=`echo $listVar | awk '{print NF}'`
297            if [ $nbVar -lt $LEN_CHECK_LIST ] ; then
298            #-- fill line (up to standard length) with dot:
299              adNul=`expr $LEN_CHECK_LIST - $nbVar | awk '{for(i=1;i<=$1;i++){print "."}}'`
300              echo $allargs $adNul
301            else
302              echo $allargs
303            fi
304    # <-- same processing for adjoint & forward test
305  }  }
306    
307  genmakemodel()  genmakemodel()
308  {  {
309      # genmakemodel directory      # genmakemodel directory
310      GENMAKE2="../../../tools/genmake2"      if test "x$NOGENMAKE" = xt ; then
311      (          echo "genmake skipped!"
312          cd $1;      else
313          printf 'genmake ... ' 1>&2          if test "x$BASH" = x ; then
314          # ../../../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  
315          else          else
316              echo "succesful" 1>&2              GENMAKE2="$BASH ../../../tools/genmake2 -bash $BASH"
317          fi          fi
318      )          (
319                cd $1;
320                command="$GENMAKE2  -ds -m $MAKE"
321                if test "x$ADM" = x ; then
322                    command="$command --mods=../code"
323                else
324                    command="$command --mods=../code_ad"
325                fi
326                if test "x$OPTFILE" != xNONE ; then
327                    command="$command --optfile=$OPTFILE"
328                fi
329                if test "x$IEEE" != x ; then
330                    command="$command -ieee"
331                fi
332                if test "x$GSL" = xt ; then
333                    command="$command -gsl"
334                fi
335                if test "x$MPI" = xt ; then
336                    command="$command -mpi"
337                fi
338                if test "x$TS" = xt ; then
339                    command="$command -ts"
340                fi
341                if test "x$PAPIS" = xt ; then
342                    command="$command -papis"
343                else
344                if test "x$PCLS" = xt ; then
345                    command="$command -pcls"
346                fi
347                fi
348                printf 'genmake ... ' 1>&2
349                $command > make.log 2>&1
350                RETVAL=$?
351                #  Reduce the size of the testing emails!
352                head -100 Makefile > $CDIR/Makefile_head
353                if test "x$RETVAL" != x0 ; then
354                    tail make.log
355                    echo "genmakemodel: genmake failed" 1>&2
356                    cp genmake_* make.log $CDIR
357                    return 1
358                else
359                    echo "successful" 1>&2
360                fi
361            )
362        fi
363  }  }
364    
365  makeclean()  makeclean()
366  {  {
367      # makeclean directory      # makeclean directory
368      (      if test "x$NOCLEAN" = xt ; then
369          cd $1;          echo "make Clean skipped!"
370          rm -f output.txt      else
371          printf 'make CLEAN ... ' 2>&1          (
372          if test -r Makefile ; then              cd $1;
373              make CLEAN >> make.log 2>&1              #if test -e $OUTPUTFILE ; then rm -f $OUTPUTFILE ; fi
374              RETVAL=$?              if test -r Makefile ; then
375              if test "x$RETVAL" != x0 ; then                  printf 'clean build-dir: make Clean ... ' 2>&1
376                  tail make.log                  $MAKE Clean >> make.log 2>&1
377                  echo "makeclean: \"make CLEAN\" failed" 1>&2                  RETVAL=$?
378                  cp make.log $CDIR"/make.log"                  if test "x$RETVAL" != x0 ; then
379                  return 1                      tail make.log
380                        echo "makeclean: \"make Clean\" failed" 1>&2
381                        cp make.log $CDIR"/make.log"
382                        return 1
383                    fi
384              fi              fi
385          fi              echo successful 1>&2
386          echo succesful 1>&2              exit 0
387          exit 0          )
388      )      fi
389    }
390    
391    run_clean()
392    {
393        # run_clean directory
394        if test "x$NOCLEAN" = xt ; then
395            echo "run_clean skipped!"
396        else
397            (
398                cd $1;
399                printf 'clean run-dir ... ' 2>&1
400                # part of what is done after "make clean" when doing "make CLEAN"
401                find . -name "*.meta" -exec rm {} \;
402                find . -name "*.data" -exec rm {} \;
403                find . -name "fort.*" -exec rm {} \;
404                find . -type l -exec rm {} \;
405                rm -f $EXECUTABLE *.txt STD* *diagnostics.log datetime
406                rm -rf mnc_test_*
407                rm -f *_MIT_CE_000.opt0000 costfunction*0000
408                echo successful 1>&2
409                exit 0
410            )
411        fi
412  }  }
413    
414  makedependmodel()  makedependmodel()
415  {  {
416      # makedependmodel directory      # makedependmodel directory
417      (      if test "x$NODEPEND" = xt ; then
418          cd $1;          echo "make depend skipped!"
419          printf 'make depend ... ' 1>&2      else
420          make depend >> make.log 2>&1          (
421          RETVAL=$?              cd $1;
422          if test "x$RETVAL" != x0 ; then              printf 'make depend ... ' 1>&2
423              tail make.log              $MAKE depend >> make.log 2>&1
424              echo "makedependmodel: make depend failed" 1>&2              RETVAL=$?
425              cp make.log $CDIR"/make.log"              if test "x$RETVAL" != x0 ; then
426              return 1                  tail make.log
427          else                  echo "makedependmodel: make depend failed" 1>&2
428              echo succesful 1>&2                  cp make.log $CDIR"/make.log"
429          fi                  return 1
430      )              else
431                    echo successful 1>&2
432                fi
433            )
434        fi
435  }  }
436    
437  makemodel()  makemodel()
# Line 231  makemodel() Line 441  makemodel()
441          cd $1;          cd $1;
442          if test -r Makefile ; then          if test -r Makefile ; then
443              printf 'make ... ' 1>&2              printf 'make ... ' 1>&2
444              make >> make.log 2>&1              if test "x$ADM" = x ; then
445                    if test "x$JOBS" = x ; then
446                        $MAKE >> make.log 2>&1
447                    else
448                        $MAKE -j $JOBS >> make.log 2>&1
449                    fi
450                else
451                    $MAKE adall >> make.log 2>&1
452                fi
453              RETVAL=$?              RETVAL=$?
454              if test "x$RETVAL" != x0 ; then              if test "x$RETVAL" != x0 ; then
455                  tail make.log                  tail make.log
# Line 239  makemodel() Line 457  makemodel()
457                  cp make.log $CDIR"/make.log"                  cp make.log $CDIR"/make.log"
458                  return 1                  return 1
459              else              else
460                  echo succesful 1>&2                  echo successful 1>&2
461              fi              fi
462          fi          fi
463      )      )
464  }  }
465    
466    symlink_mpifiles()
467    {
468        # Put special links so that MPI specific files are used
469        # This MUST be invoked between makeclean and makelinks because
470        # the Makefile will link to non-mpi files by default
471    
472        dir=$1
473        code_dir=$2
474        BUILD_DIR=$dir/$3
475        CODE_DIR=$dir/$code_dir
476        
477        # These are files that should replace their counter-part when using -mpi
478        MPI_FILES=`(cd $CODE_DIR; find . -name "*_mpi" -print)`
479    
480        #  Is this an MPI run?
481        if test "x$MPI" = xt ; then
482            # YES: We symbolically link these files to the build
483            # dir so long as there is no real file in place
484            for ii in $MPI_FILES ; do
485                i=`echo $ii | sed 's:^\./::'`
486                name=`echo $i | sed 's:_mpi::' `
487                cmp $CODE_DIR/$i $BUILD_DIR/$name > /dev/null 2>&1
488                RETVAL=$?
489                if test "x$RETVAL" != x0 ; then
490                    if ! test -f $BUILD_DIR/$i ; then
491                        #echo Linking $name to $i
492                        (cd $BUILD_DIR; ln -sf ../$code_dir/$i $name)
493                    fi
494                fi
495            done
496        else
497            # NO: We undo any _mpi symbolically linked files
498            for ii in $MPI_FILES ; do
499                i=`echo $ii | sed 's:^\./::'`
500                name=`echo $i | sed 's:_mpi::' `
501                if test -L $BUILD_DIR/$name ; then
502                    cmp $BUILD_DIR/$name "../$code_dir/$name"_mpi > /dev/null 2>&1
503                    RETVAL=$?
504                    if test "x$RETVAL" = x0 ; then
505                        #echo Un-linking $name from $linktarg
506                        rm -f $BUILD_DIR/$name
507                    fi
508                fi
509            done
510        fi
511        
512    }
513    
514  linkdata()  linkdata()
515  {  {
516      # linkdata flag      # linkdata run_dir input_dir_1 input_dir_2 ...
517      #      #
518      # symbolically link data files to run directory      # symbolically link data files to run directory
519      if [ $1 -ne 0 ]; then      if test -d $1 ; then
520          ( cd $2 ;  ln -sf ../input/* . )          (
521                cd $1 ; shift
522                if test -r "../"$1"/eedata.mth" ; then
523                # found eedata.mth in 1rst input dir and it is readable
524                    if test "x$MULTI_THREAD" = "xt" ; then
525                    # multi-threaded test: remove symbolic link & link eedata.mth
526                        if test -h eedata ; then rm -f eedata ; fi
527                        if test ! -r eedata ; then
528                            ln -sf "../"$1"/eedata.mth" eedata ;
529                            printf 'eedata.mth ' 1>&2
530                        fi
531                    else
532                    # not multi-threaded test: remove eedata symbolic link
533                        if test -h eedata ; then rm -f eedata ; fi
534                    fi
535                fi
536                prevDir='NONE'
537                for ldir in $* ; do
538                    if test -d "../"$ldir -a $ldir != $prevDir ; then
539                        printf 'ldir='${ldir} 1>&2
540                        files=`( cd "../"$ldir ; ls -1 | grep -v CVS )`
541                        for i in $files ; do
542                            if test ! -d "../"$ldir/$i ; then
543                                if test ! -r $i  ; then
544                                    printf ' '$i 1>&2
545                                    ln -sf "../"$ldir"/"$i $i
546                                fi
547                            fi
548                        done
549                        if test -x "../"$ldir"/"prepare_run ; then
550                            "../"$ldir"/"prepare_run
551                        fi
552                        printf ' ; ' 1>&2
553                    fi
554                    prevDir=$ldir
555                done
556            )
557      fi      fi
558  }  }
559    
560  runmodel()  runmodel()
561  {  {
562      # runmodel directory exe      # runmodel directory
563      #      #
564      #  runs the model "exe" in "directory" (exe is relative to directory)      #  runs "$COMMAND in "directory"
565        #  (where "$COMMAND" is relative to "directory")
566      (      (
567          cd $1          cd $1
568          if [ -x $2 ]; then          printf 'runmodel in %s ...' $1 1>&2
569              if [ $quick -eq 0 ]; then          # make output.txt
570                  rm -f output.txt          echo
571              fi          if test -L $EXECUTABLE -a -x "../"$builddir"/"$EXECUTABLE ; then
572              printf 'runmodel: ' 1>&2              diff -q $EXECUTABLE "../"$builddir"/"$EXECUTABLE > /dev/null 2>&1
573              make output.txt              outD=$? ; if test $outD != 0 ; then rm -f $EXECUTABLE ; rm -f run.log ; fi
574              RETVAL=$?          fi
575              if test "x$RETVAL" = x0 ; then          if test ! -x $EXECUTABLE -a -x "../"$builddir"/"$EXECUTABLE ; then
576                  cp output.txt $CDIR"/output.txt"              echo " link" $EXECUTABLE "from dir ../"$builddir > run.log_00
577                  return 0              ln -sf "../"$builddir"/"$EXECUTABLE .
578            fi
579            if test ! -x $EXECUTABLE ; then
580                    rm -f run.log ; touch run.log
581                    if test -f run.log_00 ; then cat run.log_00 >> run.log ; fi
582                    echo " no executable:" $EXECUTABLE >> run.log
583                    RETVAL=8
584                    ENDVAL=-1
585            else
586                if test ! -f $OUTPUTFILE -o $OUTPUTFILE -ot $EXECUTABLE ; then
587                  # output do not exist or is older than executable:
588                    rm -f run.log ; touch run.log
589                    if test -f run.log_00 ; then cat run.log_00 >> run.log ; fi
590                    ( eval $COMMAND ) >> run.log 2>&1
591                    RETVAL=$?
592              else              else
593                  return 1                  RETVAL=0
594                    if test -f run.log ; then
595                        if test -f run.log_00 ; then cat run.log_00 >> run.log ; fi
596                        echo "---------->> $OUTPUTFILE is up to date " >> run.log 2>&1
597                    else
598                        touch run.log
599                        if test -f run.log_00 ; then cat run.log_00 >> run.log ; fi
600                        echo "---------->> $OUTPUTFILE is up to date " >> run.log 2>&1
601                        echo " no previous run.log: assume NORMAL END" >> run.log 2>&1
602                    fi
603              fi              fi
604                ENDVAL=`cat run.log | grep -v 'ABNORMAL END' | grep -c 'NORMAL END'`
605            fi
606            rm -f run.log_00
607            #if test "x$RETVAL" = x0 ; then
608            if [ $RETVAL -eq 0 -a $ENDVAL -gt 0 ] ; then
609                tail run.log
610                echo successful 1>&2
611                # === Reduce the size of the testing emails!
612                #cp $OUTPUTFILE $CDIR"/"$OUTPUTFILE
613                if test -s STDERR.0000 ; then cp STDERR.0000 $CDIR"/STDERR.0000" ; fi
614                return 0
615            else
616                tail run.log
617                echo failed '(run:' $RETVAL ' end:' $ENDVAL ')' 1>&2
618                cp run.log $CDIR"/run.log"
619                if test -s STDERR.0000 ; then cp STDERR.0000 $CDIR"/STDERR.0000" ; fi
620                return 1
621          fi          fi
622      )      )
623  }  }
# Line 283  createcodelet() Line 626  createcodelet()
626  {  {
627      # create codelet for comparing model output      # create codelet for comparing model output
628    
629      echo -n "creating the comparison code...  "      printf "creating the comparison code (using CC=$CC)...  "
630      cat > tmp_cmpnum.f <<EOFA      cat > tr_cmpnum.c <<EOF
631        program cmpnum  #include <stdio.h>
632        implicit none  #include <math.h>
633        real*8 a,b,diff  int main( int argc, char** argv )  {
634        integer linnum,best    int linnum,cmplin,best,lncnt;
635        best=-16    double a,b,abave,relerr;
636    99  read(*,*,end=70,err=60) linnum,a,b    best = -22;
637        diff=0.5*(abs(a)+abs(b))    lncnt = 0;
638  c     print *,a,b,diff,abs(a-b)/diff    while( 1 & ( (lncnt+=1) < 999 ) )  {
639        if (diff.gt.1.e-12) then      scanf("%d", &linnum);
640          diff=abs(a-b)/diff      if (linnum == -1)  break;
641          if (diff.gt.0.) then      scanf("%lf", &a);  scanf("%lf", &b);
642  c         print *,int(log10(diff)),diff      abave = 0.5*(fabs(a)+fabs(b));
643            linnum=int(log10(diff))      if ( abave == abave ) {
644            best=max(best,linnum)        if (abave > 0.0) {
645          endif          relerr=fabs(a-b)/abave;
646        else          if (relerr > 0.0) { cmplin = (int)rint(log10(relerr)); }
647          if (best.eq.-16.and.diff.ne.0.) best=-22          else { cmplin = -16 ; }
648        endif          best = (best > cmplin) ? best : cmplin; }
649        goto 99        else { cmplin = -22 ; }
650    60  stop 'cmpnum: An error occured reading a,b'     /* printf("%d ; %lf ; %lf\n",cmplin,a,b); */
651    70  print *,-best        }
652        end     else {
653  EOFA     /* printf("%lf ; %lf ; %lf\n",abave,a,b); */
654          break; }
655      }
656      if (lncnt == 999) best=-29;
657      if (linnum != -1) best=-99;
658      printf("%d\n", -best);
659      return 0;
660    }
661    EOF
662        $CC -o tr_cmpnum tr_cmpnum.c -lm
663    
664      f77 tmp_cmpnum.f      if [ -x ./tr_cmpnum ]; then
     if [ -x ./a.out ]; then  
665          echo "OK"          echo "OK"
666          return 0          return 0
667      else      else
668          echo          echo
669          echo "createcodelet: failed to compile codelet" | tee          echo "ERROR: failed to compile comparison code -- please specify"
670            echo "  a C compiler using the CC environment variable."
671          exit 1          exit 1
672      fi      fi
673  }  }
# Line 327  formatresults() Line 679  formatresults()
679      nm=$1      nm=$1
680      printf '%s %s %s %s' $2 $3 $4 $5      printf '%s %s %s %s' $2 $3 $4 $5
681      shift; shift; shift; shift; shift;      shift; shift; shift; shift; shift;
682      printf '%3s' $@      listPrt=$@
683        listRes=`echo $listPrt | sed 's/>//' | sed 's/<//'`
684        xx=`echo $listPrt | sed 's/.*>//' | sed 's/<.*//' | awk '{print $1}'`
685        printf '%3s' $listPrt
686    #   line below does not work on hp-ux_ia64 : do those substitutions later on
687    #   printf '%3s' $listPrt | sed 's/ 99/ --/g' | sed 's/  > />/' | sed 's/  < /</'
688            
689      if [ $1 = '--' ]; then      if [ $xx = '..' ]; then
690            printf ' N/O '
691        elif [ $xx = '--' ]; then
692            printf ' N/O '
693        elif [ $xx = 99 ]; then
694          printf ' N/O '          printf ' N/O '
695      else      else
696          if [ $1 -gt 12 ]; then          if [ $xx -ge $MATCH_CRIT ]; then
697              printf ' pass'              printf ' pass'
698          else          else
699              printf ' FAIL'              printf ' FAIL'
# Line 343  formatresults() Line 704  formatresults()
704            
705  }  }
706    
 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  
 }  
   
707  scandirs()  scandirs()
708  {  {
709      if [ $# -eq 0 ]; then      if [ $# -eq 1 ]; then
710          for arg in * ; do          for arg in * ; do
711              test -d $arg/input && echo $arg              test -f $arg/$1 && echo $arg
712          done          done
713      else      else
714          echo $*          echo $*
715      fi      fi
716  }  }
717    
718    
719  ###############################################################################  ###############################################################################
 ###############################################################################  
 ###############################################################################  
720    
721    
722  #  Default properties  #  Default properties
723  debug=0  debug=0
724  verbose=1  verbose=1
 quick=0  
725  clean=0  clean=0
 ieee=1  
 expts=''  
726    
727  OPTFILES=  IEEE=true
728  ADDRESSES=edhill@mitgcm.org  if test "x$MITGCM_IEEE" != x ; then
729        IEEE=$MITGCM_IEEE
730    fi
731    GSL=f
732    
733    CLEANUP=f
734    QUICK=f
735    NOGENMAKE=f
736    NOCLEAN=f
737    NODEPEND=f
738    POSTCLEAN=f
739    
740    BASH=
741    OPTFILE=NONE
742    ADDRESSES=
743  TESTDIRS=  TESTDIRS=
744    SKIPDIRS=
745  MPACKDIR="../tools/mpack-1.6"  MPACKDIR="../tools/mpack-1.6"
746    HAVE_MPACK=
747  MPACK="$MPACKDIR/mpack"  MPACK="$MPACKDIR/mpack"
748    COMMAND=
749    if test "x$MAKE" = x ; then
750        MAKE=make
751    fi
752    if test "x$CC" = x ; then
753        CC=cc
754    fi
755    JOBS=
756    MPI=f
757    MULTI_THREAD=f
758    OUTDIR=
759    DELDIR=
760    
761    ADM=
762    
763    # Additional monitor types
764    PTRACERS_NUM="1 2 3 4 5"
765    
766    MATCH_CRIT=13
767    
768  echo -n "parsing options...  "  printf "parsing options...  "
769    
770  ac_prev=  ac_prev=
771  for ac_option ; do  for ac_option ; do
# Line 414  for ac_option ; do Line 785  for ac_option ; do
785              usage ;;              usage ;;
786                    
787          -optfile | --optfile | -of | --of)          -optfile | --optfile | -of | --of)
788              ac_prev=OPTFILES ;;              ac_prev=OPTFILE ;;
789          -optfile=* | --optfile=* | -of=* | --of=*)          -optfile=* | --optfile=* | -of=* | --of=*)
790              OPTFILES=$ac_optarg ;;              OPTFILE=$ac_optarg ;;
791                    
792          -addr | --addr | -a | --a)          -addr | --addr | -a | --a)
793              ac_prev=ADDRESSES ;;              ac_prev=ADDRESSES ;;
# Line 428  for ac_option ; do Line 799  for ac_option ; do
799          -tdir=* | --tdir=*)          -tdir=* | --tdir=*)
800              TESTDIRS=$ac_optarg ;;              TESTDIRS=$ac_optarg ;;
801    
802          -quick) quick=1 ;;          -skipdir | --skipdir | -skd | --skd)
803                ac_prev=SKIPDIRS ;;
804            -skipdir=* | --skipdir=*)
805                SKIPDIRS=$ac_optarg ;;
806    
807            -bash | --bash | -b | --b)
808                ac_prev=BASH ;;
809            -bash=* | --bash=*)
810                BASH=$ac_optarg ;;
811    
812            -command | --command | -c | --c)
813                ac_prev=COMMAND ;;
814            -command=* | --command=*)
815                COMMAND=$ac_optarg ;;
816    
817            -make | --make | -m | --m)
818                ac_prev=MAKE ;;
819            -make=* | --make=*)
820                MAKE=$ac_optarg ;;
821    
822            -odir | --odir)
823                ac_prev=OUTDIR ;;
824            -odir=* | --odir=*)
825                OUTDIR=$ac_optarg ;;
826    
827            -ptracers | --ptracers | -ptr | --ptr)
828                ac_prev=PTRACERS_NUM ;;
829            -ptracers=* | --ptracers=* | -ptr=* | --ptr=*)
830                PTRACERS_NUM=$ac_optarg ;;
831    
832            -match | --match ) ac_prev=MATCH_CRIT ;;
833            -match=* | --match=* ) MATCH_CRIT=$ac_optarg ;;
834    
835            -j) ac_prev=JOBS ;;
836            -j=*) JOBS=$ac_optarg ;;
837    
838            -clean | --clean)
839                CLEANUP=t ; DELDIR=t ;;
840    
841            -quick | --quick | -q | --q)
842                QUICK=t ;;
843            -nogenmake | --nogenmake | -ng | --ng)
844                NOGENMAKE=t ;;
845            -noclean | --noclean | -nc | --nc)
846                NOCLEAN=t ;;
847            -nodepend | --nodepend | -nd | --nd)
848                NODEPEND=t ;;
849    
850            -postclean | --postclean | -pc | --pc)
851                POSTCLEAN=t ;;
852    
853            -mpi) MPI=t ;;
854    
855            -mth) MULTI_THREAD=t ;;
856    
857            -adm | -ad) ADM=t ;;
858    
859            -ieee) IEEE=true ;;
860            -noieee) IEEE= ;;
861            -gsl) GSL=t ;;
862    
863          -verbose) verbose=2 ;;          -verbose) verbose=2 ;;
864          -debug) debug=1 ;;          -debug) debug=1 ;;
         -clean) clean=1 ;;  
         -noieee) ieee=0 ;;  
865          -quiet) verbose=0 ;;          -quiet) verbose=0 ;;
866    
867            -deldir | -dd) DELDIR=t ;;
868    
869            -ts) TS=t;;
870    
871            -papis) PAPIS=t;;
872    
873            -pcls) PCL=t;;
874    
875          -*)          -*)
876              echo "Error: unrecognized option: "$ac_option              echo "Error: unrecognized option: "$ac_option
877              usage              usage
# Line 449  for ac_option ; do Line 886  for ac_option ; do
886            
887  done  done
888    
889    if test "x$QUICK" = xt ; then
890        NOGENMAKE=t
891        NOCLEAN=t
892        NODEPEND=t
893    fi
894    
895    #- setting for forward or ADM testing
896    if test "x$ADM" = xt ; then
897        code_dir=code_ad
898        inputdir=input_ad
899        ref_outp="output_adm.txt"
900        EXECUTABLE="mitgcmuv_ad"
901    else
902        code_dir=code
903        inputdir=input
904        ref_outp="output.txt"
905        EXECUTABLE="mitgcmuv"
906    fi
907    
908  if test "x$TESTDIRS" = x ; then  if test "x$TESTDIRS" = x ; then
909      TESTDIRS=`scandirs`      LIST=`scandirs results/$ref_outp`
910    else
911        #- expand group of experiments:
912        LIST=" "
913        for xx in $TESTDIRS
914        do
915          case $xx in
916            'basic') LIST=${LIST}" aim.5l_cs hs94.128x64x5 ideal_2D_oce"
917                     LIST=${LIST}" lab_sea tutorial_baroclinic_gyre"
918                     LIST=${LIST}" tutorial_global_oce_latlon tutorial_plume_on_slope"
919                    ;;
920            'tutorials')
921                     LIST=${LIST}" "`ls | grep 'tutorial_'` ;;
922            *)       LIST=${LIST}" "$xx ;;
923          esac
924        done
925    fi
926    #echo 'LIST='${LIST}'<'
927    #- skip dirs, remove duplicate and non-directory:
928    TESTDIRS=" "
929    count=0
930    for xx in $LIST
931    do
932        yy=`echo $SKIPDIRS | grep -c $xx`
933        if test $yy = 0 ; then
934            if test -d $xx ; then
935                yy=`echo $TESTDIRS | grep -c $xx`
936                if test $yy = 0 ; then TESTDIRS=${TESTDIRS}" "$xx ; fi
937            else count=1 ;
938                echo ""; echo -n " -- skip \"$xx\" (not a directory !)"
939            fi
940        else
941            if test $count = 1 ; then echo -n ", \"$xx\""
942            else count=1 ; echo "" ;  echo -n " skip: \"$xx\""
943            fi
944        fi
945    done
946    if test $count = 1 ; then echo "" ; echo -n " ... " ; fi
947    #echo 'TESTDIRS='${TESTDIRS}'<'
948    
949    if test "x$OPTFILE" = xNONE -a "x$MITGCM_OF" != x ; then
950        OPTFILE=$MITGCM_OF
951  fi  fi
952    
953  echo "OK"  OUTPUTFILE=$ref_outp
954    if test "x$COMMAND" = x ; then
955        COMMAND="./$EXECUTABLE > $OUTPUTFILE"
956    fi
957    if test "x$MPI" = xt ; then
958        OUTPUTFILE="STDOUT.0000"
959    fi
960    
961    echo "OK (COMMAND= $COMMAND )"
962    
963    # set the Default List of output variables to be checked:
964    #  (use default or load experiment-specific list from file "tr_checklist")
965    # content : 1rst = main variable used to decide if it pass or FAIL
966    #         others = number of matching digits to be printed in summary.txt
967    if test "x$ADM" = x ; then
968        DEF_CHECK_LIST='PS PS T+ S+ U+ V+ pt1+ pt2+ pt3+ pt4+ pt5+'
969        EMPTY_RESULTS='.. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. ..'
970        LEN_CHECK_LIST=`echo $DEF_CHECK_LIST | sed 's/ [a-zA-Z0-9]*+/&mn &mx &av &sd/g' | awk '{print NF-1}'`
971        ii=`echo $EMPTY_RESULTS | awk '{print NF}'`
972        EMPTY_RESULTS=$EMPTY_RESULTS`expr $LEN_CHECK_LIST - $ii | awk 'BEGIN{FS=":"}{for(i=1;i<=$1;i++){printf "  ."}}'`
973    else
974        DEF_CHECK_LIST='Grad Cost Grad'
975        EMPTY_RESULTS='.. ..'
976        LEN_CHECK_LIST=`echo $DEF_CHECK_LIST | sed 's/ [a-zA-Z0-9]*+/&mn &mx &av &sd/g' | awk '{print NF-1}'`
977    fi
978    
979  #  create the FORTRAN comparison code  #  create the FORTRAN comparison code
980  createcodelet  createcodelet
981    
982  #  build the mpack utility  #  build the mpack utility (if ADDRESSES = NONE, do it to test the build)
983  build_mpack  if test "x$ADDRESSES" = x ; then
984        echo "skipping mpack build"
985    else
986        build_mpack
987    fi
988    
989  #  Create a uniquely named directory to store results  #  Create a uniquely named directory to store results
990    CMDLINE=$0
991    for xx in "$@" ; do CMDLINE="$CMDLINE '$xx'" ; done
992  MACH=`hostname`  MACH=`hostname`
993  UNAMEA=`uname -a`  UNAMEA=`uname -a`
994  DATE=`date +%Y%m%d`  DATE=`date +%Y%m%d`
995  BASE=$MACH"_"$DATE"_"  BASE="tr_"$MACH"_"$DATE"_"
996    if test "x$OUTDIR" != x ; then
997        BASE="tr_"$OUTDIR"_"$DATE"_"
998    fi
999  DNUM=0  DNUM=0
1000  DRESULTS="$BASE$DNUM"  DRESULTS="$BASE$DNUM"
1001  while test -e $DRESULTS ; do  while test -e $DRESULTS ; do
# Line 475  done Line 1005  done
1005  mkdir $DRESULTS  mkdir $DRESULTS
1006  RETVAL=$?  RETVAL=$?
1007  if test "x$RETVAL" != x0 ; then  if test "x$RETVAL" != x0 ; then
1008      echo "Error: can't create results directory \"./$DRESULTS\""      echo "ERROR: Can't create results directory \"./$DRESULTS\""
1009      exit 1      exit 1
1010  fi  fi
1011  SUMMARY="$DRESULTS/summary.txt"  SUMMARY="$DRESULTS/summary.txt"
1012  date > $SUMMARY  start_date=`date`
1013  cat << EOF >> $SUMMARY  echo $start_date > $SUMMARY
1014                  T           S           U           V  echo 'run:' $CMDLINE >> $SUMMARY
1015  G D M    c        m  s        m  s        m  s        m  s  echo 'on :' $UNAMEA  >> $SUMMARY
1016  E p a R  g  m  m  e  .  m  m  e  .  m  m  e  .  m  m  e  .  
1017  N n k u  2  i  a  a  d  i  a  a  d  i  a  a  d  i  a  a  d  of_path=
1018  2 d e n  d  n  x  n  .  n  x  n  .  n  x  n  .  n  x  n  .  if test "x$OPTFILE" != xNONE ; then
1019        if test -r $OPTFILE ; then
1020            # get the path
1021            path=${OPTFILE%/*}
1022            if test "x$path" = x ; then
1023                of_path=`pwd`
1024            else
1025                of_path=`( cd $path > /dev/null 2>&1 ; pwd )`
1026            fi
1027            file=${OPTFILE##*/}
1028            OPTFILE=$of_path/$file
1029            cp $OPTFILE $DRESULTS
1030            echo >> $SUMMARY
1031            echo "  OPTFILE=$OPTFILE" >> $SUMMARY
1032        else
1033            echo | tee $SUMMARY
1034            echo "ERROR: can't read OPTFILE=\"$OPTFILE\"" | tee $SUMMARY
1035            exit 1
1036        fi
1037    else
1038        echo >> $SUMMARY
1039        echo "No \"OPTFILE\" was explicitly specified by testreport," >> $SUMMARY
1040        echo "   so the genmake default will be used." >> $SUMMARY
1041    fi
1042    echo
1043    echo >> $SUMMARY
1044    if test "x$ADM" = x ; then
1045        if [ $MATCH_CRIT -lt 10 ] ;
1046        then line_0="default  "$MATCH_CRIT ;
1047        else line_0="default "$MATCH_CRIT ; fi
1048           line_0="$line_0  ----T-----  ----S-----  ----U-----  ----V-----"
1049    #   line_0="            ----T-----  ----S-----  ----U-----  ----V-----"
1050        line_1="G D M    c        m  s        m  s        m  s        m  s"
1051        line_2="E p a R  g  m  m  e  .  m  m  e  .  m  m  e  .  m  m  e  ."
1052        line_3="N n k u  2  i  a  a  d  i  a  a  d  i  a  a  d  i  a  a  d"
1053        line_4="2 d e n  d  n  x  n  .  n  x  n  .  n  x  n  .  n  x  n  ."
1054        for ii in $PTRACERS_NUM ; do
1055            #  tst=`eval 'echo $HAVE_PTR0'$ii`
1056            #  if test "x$tst" = xt ; then
1057            line_0="$line_0  --PTR 0"$ii"--"
1058            line_1="$line_1        m  s"
1059            line_2="$line_2  m  m  e  ."
1060            line_3="$line_3  i  a  a  d"
1061            line_4="$line_4  n  x  n  ."
1062            #  fi
1063        done
1064        echo "$line_0" | tee -a $SUMMARY
1065        echo "$line_1" | tee -a $SUMMARY
1066        echo "$line_2" | tee -a $SUMMARY
1067        echo "$line_3" | tee -a $SUMMARY
1068        echo "$line_4" | tee -a $SUMMARY
1069        echo " "       | tee -a $SUMMARY
1070    else
1071        echo "ADJOINT=true" >> $SUMMARY
1072        echo >> $SUMMARY
1073        if [ $MATCH_CRIT -lt 10 ] ;
1074        then line_0="default     "$MATCH_CRIT ;
1075        else line_0="default    "$MATCH_CRIT ; fi
1076        echo "$line_0" | tee -a $SUMMARY
1077        cat << EOF | tee -a $SUMMARY
1078    G D M    C  G
1079    E p a R  o  r
1080    N n k u  s  a
1081    2 d e n  t  d
1082    
1083  EOF  EOF
1084    fi
1085    
1086  NDIR=0  #  ...and each test directory...
1087    for dir in $TESTDIRS ; do
1088        
1089        # set builddir & rundir:
1090        builddir="build"
1091        if test ! -d $dir/$builddir ; then mkdir $dir/$builddir ; fi
1092        rundir="run"
1093        if test ! -d $dir/$rundir ; then
1094            rundir=$builddir
1095        fi
1096        CODE_DIR=$dir/$code_dir
1097        BUILD_DIR=$dir/$builddir
1098    
1099  #  For each optfile...      #  Cleanup only!
1100  for OPTFILE in $OPTFILES ; do      if test "x$CLEANUP" = xt ; then
1101            if test -r $BUILD_DIR/Makefile ; then
1102                echo '  ------  clean dir:' $dir/build
1103                ( cd $BUILD_DIR ; make CLEAN )
1104            fi
1105            if test -d $dir/$rundir/CVS ; then
1106                echo '  ------  clean dir:' $dir/$rundir
1107                run_clean $dir/$rundir
1108            fi
1109            (
1110                cd $dir
1111                rm -rf tr_run.*
1112            )
1113            continue
1114        fi
1115    
1116      OPTFILE=`pwd`"/$OPTFILE"      #  Verify that the testdir exists and contains previous
1117      if test ! -r $OPTFILE ; then      #  results in the correct location--or skip this directory!
1118          echo "Error: can't read optfile \"$OPTFILE\""      fout=$dir"/results/"$ref_outp
1119          exit 1      if test ! -r $fout ; then
1120            echo "can't read \"$fout\" -- skipping $dir"
1121            continue
1122        fi
1123        if test "x$ADM" = x ; then
1124            check_for_add_mon_output  $fout
1125      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"/"$DRESULTS"_"$NDIR  
         mkdir $CDIR  
         CDIR=`pwd`"/$CDIR"  
1126    
1127          #  ...configue, make, run, and compare the output.      # Check for additional types of monitor output
1128          echo "-------------------------------------------------------------------------------"  
1129          echo      if test ! -r $CODE_DIR"/SIZE.h_mpi" -a "x$MPI" = "xt" ; then
1130          echo "Experiment:  $dir"          echo "can't find \"$CODE_DIR/SIZE.h_mpi\" -- skipping $dir"
1131          echo          continue
1132          unset genmake makedepend make run      fi
1133          results='-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --'      if test ! -r $dir"/input/eedata.mth" -a "x$MULTI_THREAD" = "xt" ; then
1134          ( 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"
1135          if [ -r $dir/build ]; then          continue
1136              seperatebuilddir=1      fi
             builddir=build  
             rundir=build  
             ( cd $dir/build; ln -sf ../input/* . )  
         else  
             seperatebuilddir=0  
             builddir=input  
             rundir=input  
         fi  
1137    
1138          #  Verify that the testdir exists and contains previous      #  Check whether there are "extra runs" for this testdir
1139          #  results in the correct location--or skip this directory!      extra_runs=
1140          if test ! -r $dir"/results/output.txt" ; then      ex_run_dirs=`( cd $dir ; echo $inputdir.* )`
1141              echo | tee $SUMMARY      #echo "ex_run_dirs='$ex_run_dirs'"
1142              echo "can't read \"$dir/results/output.txt\" -- skipping $dir" \      for exd in $ex_run_dirs ; do
1143                  | tee $SUMMARY          name=`echo $exd | sed -e "s/$inputdir\.//"`
1144              continue          refExOut=`echo $ref_outp | sed "s/\./.${name}./"`
1145            outf="$dir/results/$refExOut"
1146            if test -f $outf -a -r $outf ; then
1147                if test "x$MULTI_THREAD" = "xt" ; then
1148                    if test -r $dir"/"$exd"/eedata.mth" ; then
1149                        extra_runs="$extra_runs $name"
1150                    #else echo $dir"/"$exd"/eedata.mth: not found"
1151                    fi
1152                else
1153                    extra_runs="$extra_runs $name"
1154                fi
1155          fi          fi
1156        done
1157    
1158        echo "-------------------------------------------------------------------------------"
1159        echo
1160        if test "x$extra_runs" = "x" ; then
1161           echo "Experiment:  $dir"
1162        else
1163           echo "Experiment:  $dir ; extra_runs=$extra_runs"
1164        fi
1165        echo
1166        unset genmake makedepend make run
1167        results=$EMPTY_RESULTS
1168    
1169        #  Create an output dir for each OPTFILE/tdir combination
1170        rel_CDIR=$DRESULTS"/"$dir
1171        mkdir $rel_CDIR
1172        CDIR=`pwd`"/$rel_CDIR"
1173        
1174        if test "x$CLEANUP" = xt ; then
1175            echo '====>>> this is to check that we never go through this part <<< ==='
1176            makeclean $dir/$builddir \
1177                && run_clean $dir/$rundir
1178        else
1179          genmakemodel $dir/$builddir && genmake=Y \          genmakemodel $dir/$builddir && genmake=Y \
1180              && makeclean $dir/$builddir \              && makeclean $dir/$builddir \
1181                && run_clean $dir/$rundir \
1182                && symlink_mpifiles $dir $code_dir $builddir \
1183              && makedependmodel $dir/$builddir && makedepend=Y \              && makedependmodel $dir/$builddir && makedepend=Y \
1184              && makemodel $dir/$builddir && make=Y \              && makemodel $dir/$builddir && make=Y \
1185              && linkdata $seperatebuilddir $dir/$rundir \              && linkdata $dir/$rundir $inputdir input \
1186              && runmodel $dir/$builddir mitgcmuv && run=Y \              && runmodel $dir/$rundir && run=Y \
1187              && results=`testoutput $dir $rundir`              && results=`testoutput_run $dir $rundir $ref_outp`
1188          echo      fi
1189          formatresults $dir ${genmake:-N} ${makedepend:-N} ${make:-N} \      
1190              ${run:-N} $results      echo
1191            fres=`formatresults $dir ${genmake:-N} ${makedepend:-N} ${make:-N} ${run:-N} $results`
1192          echo          echo
1193          formatresults $dir ${genmake:-N} ${makedepend:-N} ${make:-N} \          echo "$fres" | sed 's/ 99/ --/g' | sed 's/  > />/' | sed 's/  < /</' >> $SUMMARY
1194              ${run:-N} $results >> $SUMMARY          touch $CDIR"/summary.txt"
1195          echo "fresults='" > $CDIR"/summary.txt"          echo "fresults='$fres'" | sed 's/ 99/ --/g' >> $CDIR"/summary.txt"
         formatresults $dir ${genmake:-N} ${makedepend:-N} ${make:-N} \  
             ${run:-N} $results >> $CDIR"/summary.txt"  
         echo "'" >> $CDIR"/summary.txt"  
1196          echo "MACH='$MACH'" >> $CDIR"/summary.txt"          echo "MACH='$MACH'" >> $CDIR"/summary.txt"
1197          echo "UNAMEA='$UNAMEA'" >> $CDIR"/summary.txt"          echo "UNAMEA='$UNAMEA'" >> $CDIR"/summary.txt"
1198          echo "DATE='$DATE'" >> $CDIR"/summary.txt"          echo "DATE='$DATE'" >> $CDIR"/summary.txt"
1199          echo "tdir='$dir'" >> $CDIR"/summary.txt"          echo "tdir='$dir'" >> $CDIR"/summary.txt"
1200            if test "x$ADM" = xt ; then
1201                head -1 $dir/$builddir/taf_ad.log >> $CDIR"/summary.txt"
1202                grep -A3 'Seconds in section "ALL' $dir/$rundir/$OUTPUTFILE \
1203                                    >> $CDIR"/summary.txt"
1204            fi
1205    
1206          (          for ex in $extra_runs ; do
1207              cd $DRESULTS              unset run
1208              tar -cf $NDIR".tar" $DRESULTS"_"$NDIR > /dev/null 2>&1              results=$EMPTY_RESULTS
1209              gzip $NDIR".tar"              #  reference output file
1210          )              refExOut=`echo $ref_outp | sed "s/\./.${ex}./g"`
1211                #  Create an output dir for each OPTFILE/tdir.ex combination
1212                rel_CDIR=$DRESULTS"/"$dir"."$ex
1213                mkdir $rel_CDIR
1214                CDIR=`pwd`"/$rel_CDIR"
1215                test ! -e "$dir/tr_run.$ex" && mkdir "$dir/tr_run.$ex"
1216                run_clean $dir/tr_run.$ex
1217                linkdata $dir/tr_run.$ex $inputdir.$ex $inputdir input
1218                runmodel $dir/tr_run.$ex && run=Y \
1219                && results=`testoutput_run $dir tr_run.$ex $refExOut`
1220                fres=`formatresults $dir ${genmake:-N} ${makedepend:-N} ${make:-N} ${run:-N} $results`
1221                fres="$fres.$ex"
1222                echo
1223                echo "$fres" | sed 's/ 99/ --/g' | sed 's/  > />/' | sed 's/  < /</' >> $SUMMARY
1224                touch $CDIR"/summary.txt"
1225                echo "fresults='$fres'" | sed 's/ 99/ --/g' >> $CDIR"/summary.txt"
1226                echo "MACH='$MACH'" >> $CDIR"/summary.txt"
1227                echo "UNAMEA='$UNAMEA'" >> $CDIR"/summary.txt"
1228                echo "DATE='$DATE'" >> $CDIR"/summary.txt"
1229                echo "tdir='$dir.$ex'" >> $CDIR"/summary.txt"
1230                if test "x$ADM" = xt ; then
1231                    head -1 $dir/$builddir/taf_ad.log >> $CDIR"/summary.txt"
1232                    grep -A3 'Seconds in section "ALL' $dir/tr_run.$ex/$OUTPUTFILE \
1233                                       >> $CDIR"/summary.txt"
1234                fi
1235                if test "x$POSTCLEAN" = xt ; then
1236                    run_clean $dir/tr_run.$ex
1237                fi
1238            done
1239    
1240        #postclean $dir/$builddir
1241        if test "x$POSTCLEAN" = xt ; then
1242            makeclean $dir/$builddir \
1243                && run_clean $dir/$rundir
1244        fi
1245        
1246        echo "-------------------------------------------------------------------------------"
1247        
1248    done
1249    
1250          $MPACK -s MITgcm-test -m 1000000 $DRESULTS"/"$NDIR".tar.gz" $ADDRESSES  printf "Start time:  " >> $SUMMARY
1251    echo $start_date >> $SUMMARY
1252    printf "End time:    " >> $SUMMARY
1253    date >> $SUMMARY
1254    
1255    #  If addresses were supplied and mpack built successfully, then try
1256    #  to send email using mpack.
1257    if test "x$ADDRESSES" = xNONE -o "x$ADDRESSES" = x ; then
1258        echo "No results email was sent."
1259    else
1260        if test "x$HAVE_MPACK" = xt ; then
1261            tar -cf $DRESULTS".tar" $DRESULTS > /dev/null 2>&1 \
1262                && gzip $DRESULTS".tar" \
1263                && $MPACK -s MITgcm-test -m 3555000 $DRESULTS".tar.gz" $ADDRESSES
1264          RETVAL=$?          RETVAL=$?
1265          if test "x$RETVAL" != x0 ; then          if test "x$RETVAL" != x0 ; then
1266              echo "Warning: \"$MPACK\" failed -- please contact <edhill@mitgcm.org>"              echo
1267                echo "Warning: The tar, gzip, & mpack step failed.  Please send email"
1268                echo "  to <MITgcm-support@mitgcm.org> for help.  You may copy the "
1269                echo "  summary of results from the directory \"$DRESULTS\"."
1270                echo
1271          else          else
1272              rm -f $DRESULTS"/"$NDIR".tar*"              echo
1273                echo "An email containing results was sent to the following addresses:"
1274                echo "  \"$ADDRESSES\""
1275                echo
1276          fi          fi
1277            test -f $DRESULTS".tar"  &&  rm -f $DRESULTS".tar"
1278            test -f $DRESULTS".tar.gz"  &&  rm -f $DRESULTS".tar.gz"
1279        fi
1280    fi
1281    
1282          NDIR=$(( $NDIR + 1 ))  rm -f tr_cmpnum.c tr_cmpnum
           
     done  
 done  
1283    
1284  rm tmp_cmpnum.f a.out  if test "x$CLEANUP" != xt ; then
1285        cat $SUMMARY | sed 's/ \.  \.  \.  \.  \.  \.  \.  \.  \.  \.  \.  \. //'
1286        if test -e tr_out.txt ; then
1287            mv tr_out.txt tr_out.txt.old
1288        fi
1289        cat $SUMMARY | sed '/^[YN] [YN] [YN] [YN]/ s/ \. //g' > tr_out.txt
1290    fi
1291    
1292  cat $SUMMARY  if test "x$DELDIR" = xt ; then
1293        rm -rf $DRESULTS
1294    fi
1295    

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.112

  ViewVC Help
Powered by ViewVC 1.1.22