/[MITgcm]/MITgcm/verification/testscript
ViewVC logotype

Diff of /MITgcm/verification/testscript

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

revision 1.2 by adcroft, Fri Mar 9 19:05:26 2001 UTC revision 1.10 by adcroft, Fri Aug 10 16:49:51 2001 UTC
# Line 1  Line 1 
1  #!/bin/csh  #!/bin/sh
2    
3  # Run this script from the verification directory  compare_lines()
4  # It will automatically configure, compile, run and verify all experiments  {
5  # in the verification directory for whcih there is an results/output.txt  # use codelet to compare lines
6  # file.   if [ $verbose -gt 1 ]; then
7      cat tmp3.txt 1>&2
8  # This is the number of least-significant digits allows to be   fi
9  # in error before the test is classified as a "fail".   return `./a.out < tmp3.txt`
10    }
11  set on_error_die  
12  set passaccuracy=7  testoutput_for_prop()
13  printf '%s\t%s\t%s\t%s\t%s\t%s\t%s\n' " " Make " " " " Exact "# of" " " > summary.txt  {
14  printf '%s\t%s\t%s\t%s\t%s\t%s\t%s\n' Config Depend Compile Execute Match Digits Experiment >> summary.txt  # testoutput_for_prop dir s1 label
15    #
16  # Pass any arguments  #  compares files in $dir/input/output.txt and $dir/results.output.txt
17  foreach arg ($argv)  #  using search strings s1 and text label
18   switch ($arg)  
19    case -clean:   if [ $debug -gt 0 ]; then
20     echo Cleaning ...    echo testoutput_for_prop: grep "$2" $1/input/output.txt 1>&2
21     foreach dr ([a-zA-Z01-9]*)   fi
22      if (-d $dr/input) then   if [ -r $1/input/output.txt ]; then
23        echo Entering $dr    grep "$2" $1/input/output.txt | sed 's/.*=//' | nl > tmp1.txt
       cd $dr/input  
       echo ""  
       make CLEAN  
       \rm -f {*output,*high,*low}.txt *.log  
       \rm -f ?ake*  
       cd ../..  
     endif  
    end  
    rm -f summary.txt  
    exit 0  
    breaksw  
   case -nodie:  
    unset on_error_die  
    breaksw  
   default:  
    echo Unknown argument given to $0  
    exit 1  
  endsw  
 end  
   
 foreach dr ([a-zA-Z01-9]*)  
  if (! -d $dr/input ) continue  
  set config=-  
  set makedepend=-  
  set compile=-  
  set execute=-  
  set exactmatch=-  
  set accuracy=-  
  echo ==============================================================================  
  echo Entering $dr  
  cd $dr  
  echo ""  
  if (! -r results/output.txt) then  
   echo "                ***** No results to compare with *****"  
   if (! $?untested) set untested  
   set untested=($untested $dr)  
24   else   else
25    set config=NO    echo testoutput_for_prop: output.txt from model run was not readable 1>&2
26    cd input    return 99
27    echo -n "  generating Makefile ..."   fi
28    ../../../tools/genmake -mods=../code >&! make.log   if [ $debug -gt 0 ]; then
29    if ($status == 0) set config=Yes    echo testoutput_for_prop: grep "$2" $1/results/output.txt 1>&2
30    set makedepend=NO   fi
31    echo " done."   grep "$2" $1/results/output.txt | sed 's/.*=//' | nl > tmp2.txt
32    echo -n "  make depend ..."   if [ $debug -gt 0 ]; then
33    make cleanlinks depend >>& make.log    echo testoutput_for_prop: join tmp1.txt tmp2.txt 1>&2
34    if ($status == 0) set makedepend=Yes   fi
35    echo " done."   join tmp1.txt tmp2.txt | awk '{print $1 " " $2 " " $3}' > tmp3.txt
36    echo -n "  make ..."   if [ $debug -gt 0 ]; then
37    make >>& make.log    echo testoutput_for_prop: compare_lines 1>&2
38    if ($status) then   fi
39     echo "               ***** An error occurred during make *****"   compare_lines
40     cat make.log   digits_of_similarity=$?
41     echo The error during compilation occured in \"$dr\"   if [ $digits_of_similarity -eq 99 ]; then
42     set compile=NO    if [ $verbose -gt 0 ]; then
43     if ($?on_error_die) exit 1     echo testoutput_for_prop: No comparison was available for \"$2\" 1>&2
44    else    fi
45     set compile=Yes    digits_of_similarity=99
46     set execute=NO   else
47    endif    if [ $verbose -gt 0 ]; then
48    echo " done."     echo There were $digits_of_similarity decimal places of similarity for \"$2\" 1>&2
49    echo -n "  running model ..."    fi
50    if ($compile == 'Yes') then   fi
51    ./mitgcmuv | & grep "D iters" > output.txt   rm tmp1.txt tmp2.txt tmp3.txt
52    if ($status == 0) then  
53      set execute=Yes   return $digits_of_similarity
54      set exactmatch=NO  }
55      set accuracy=-  
56      echo " done."  dashnum()
57      sed 's/.*D iters, err =//' output.txt \  {
58      | grep "   0    " \  # dashnum n1 n2 n3 ...
59      > high.txt  #
60      grep "D iters" ../results/output.txt \  #  print numbers using %3i format or "--" if number = 99
61       | sed 's/.*D iters, err =//' \  for num in $@
62       | grep "   0    " \  do
63       > oldhigh.txt   if [ $num = 99 ]; then
64      diff oldhigh.txt high.txt > /dev/null    printf ' --'
65      if ($status) then   else
66        echo "  output differs:"    printf '%3i' $num
67        diff oldhigh.txt high.txt   fi
68        echo ""  done
69        @ lvl=0  }
70        set accuracy='.'  
71        set fail  testoutput()
72        echo -n Trying reduced accuracy  {
73        while ($lvl <= $passaccuracy)  # testoutput diretory
74          @ lvl+=1  #
75          echo -n " " $lvl  #  test output in "directory"
76          sed s/{$accuracy}E/E/ high.txt > low.txt  
77          sed s/{$accuracy}E/E/ oldhigh.txt > oldlow.txt  if [ $debug -gt 0 ]; then
78          diff oldlow.txt low.txt > /dev/null   echo testoutput: testoutput_for_prop $1 cg2d_init_res 1>&2
79          if ($status == 0) then  fi
80            unset fail  testoutput_for_prop $1 "cg2d_init_res" "cg2d init. residual"; cg2dres=$?
81            break  if [ $debug -gt 0 ]; then
82     echo testoutput: cg2dres=$cg2dres 1>&2
83    fi
84    
85    if [ $longtest -gt 0 ]; then
86    testoutput_for_prop $1 "dynstat_theta_min" "theta minimum"; tmin=$?
87    testoutput_for_prop $1 "dynstat_theta_max" "theta maximum"; tmax=$?
88    testoutput_for_prop $1 "dynstat_theta_mean" "theta mean"; tmean=$?
89    testoutput_for_prop $1 "dynstat_theta_sd" "theta s.d."; tsd=$?
90    testoutput_for_prop $1 "dynstat_salt_min" "salt minimum"; smin=$?
91    testoutput_for_prop $1 "dynstat_salt_max" "salt maximum"; smax=$?
92    testoutput_for_prop $1 "dynstat_salt_mean" "salt mean"; smean=$?
93    testoutput_for_prop $1 "dynstat_salt_sd" "salt s.d."; ssd=$?
94    testoutput_for_prop $1 "dynstat_uvel_min" "U minimum"; umin=$?
95    testoutput_for_prop $1 "dynstat_uvel_max" "U maximum"; umax=$?
96    testoutput_for_prop $1 "dynstat_uvel_mean" "U mean"; umean=$?
97    testoutput_for_prop $1 "dynstat_uvel_sd" "U s.d."; usd=$?
98    testoutput_for_prop $1 "dynstat_vvel_min" "V minimum"; vmin=$?
99    testoutput_for_prop $1 "dynstat_vvel_max" "V maximum"; vmax=$?
100    testoutput_for_prop $1 "dynstat_vvel_mean" "V mean"; vmean=$?
101    testoutput_for_prop $1 "dynstat_vvel_sd" "V s.d."; vsd=$?
102    else
103    testoutput_for_prop $1 "dynstat_theta_min" "theta minimum"; tmin=$?
104    testoutput_for_prop $1 "dynstat_theta_max" "theta maximum"; tmax=$?
105    testoutput_for_prop $1 "dynstat_salt_min" "salt minimum"; smin=$?
106    testoutput_for_prop $1 "dynstat_salt_max" "salt maximum"; smax=$?
107    testoutput_for_prop $1 "dynstat_uvel_min" "U minimum"; umin=$?
108    testoutput_for_prop $1 "dynstat_uvel_max" "U maximum"; umax=$?
109    testoutput_for_prop $1 "dynstat_vvel_min" "V minimum"; vmin=$?
110    testoutput_for_prop $1 "dynstat_vvel_max" "V maximum"; vmax=$?
111    fi
112    
113    dashnum $cg2dres $tmin $tmax $tmean $tsd $smin $smax $smean $ssd \
114            $umin $umax $umean $usd $vmin $vmax $vmean $vsd
115    #printf '%3i' $cg2dres $tmin $tmax $tmean $tsd $smin $smax $smean $ssd \
116    #       $umin $umax $umean $usd $vmin $vmax $vmean $vsd
117    }
118    
119    genmakemodel()
120    {
121    # genmakemodel directory
122     ( cd $1;
123       if [ $quick -eq 0 -o ! -r Makefile ]; then
124        printf 'genmake ... ' 1>&2
125        ../../../tools/genmake -ieee -mods=../code > make.log 2>&1
126        if [ $? -ne 0 ]; then
127         tail make.log
128         echo genmakemodel: genmake failed 1>&2
129         return 1
130        else
131          echo succesful 1>&2
132        fi
133       fi
134     )
135    }
136    
137    makeclean()
138    {
139    # makedependmodel directory
140     ( cd $1;
141       if [ $clean -gt 0 ]; then
142        printf 'make clean ... ' 2>&1
143        make CLEAN >> make.log 2>&1
144        if [ $? -ne 0 ]; then
145          tail make.log
146          echo makeclean: make clean failed 1>&2
147          return 1
148        else
149          echo succesful 1>&2
150        fi
151       fi
152     )
153    }
154    
155    makedependmodel()
156    {
157    # makedependmodel directory
158     ( cd $1;
159       if [ $quick -eq 0 -o ! -r Makefile ]; then
160        printf 'make depend ... ' 1>&2
161        make cleanlinks >> make.log 2>&1
162        make depend >> make.log 2>&1
163        if [ $? -ne 0 ]; then
164          tail make.log
165          echo makemodel: make depend failed 1>&2
166          return 1
167        else
168          echo succesful 1>&2
169        fi
170       fi
171     )
172    }
173    
174    makemodel()
175    {
176    # makemodel directory
177     ( cd $1;
178       if [ -r Makefile ]; then
179        printf 'make ... ' 1>&2
180        make >> make.log 2>&1
181        if [ $? -ne 0 ]; then
182         tail make.log
183         echo failed 1>&2
184         return 1
185        else
186         echo succesful 1>&2
187        fi
188       fi
189     )
190    }
191    
192    runmodel()
193    {
194    # runmodel directory exe
195    #
196    #  runs the model "exe" in "directory" (exe is relative to directory)
197    
198     ( cd $1
199       if [ -x $2 ]; then
200        if [ ! -r output.txt -o $quick -eq 0 ]; then
201         echo runmodel: running... 1>&2
202         ( ./$2 > output.txt 2>&1 ) && return 0
203         return 1
204        else
205         echo runmodel: output.txt is newer than executable 1>&2
206         return 0
207        fi
208       else
209        echo runmodel: executable \"$1/$2\" is missing 1>&2
210        return 1
211       fi
212     )
213    }
214    
215    createcodelet()
216    {
217    # create codelet for comparing model output
218    cat > tmp_cmpnum.f <<EOFA
219          program cmpnum
220          implicit none
221          real*8 a,b,diff
222          integer linnum,best
223          best=-16
224      99  read(*,*,end=70,err=60) linnum,a,b
225          diff=0.5*(abs(a)+abs(b))
226    c     print *,a,b,diff,abs(a-b)/diff
227          if (diff.gt.1.e-12) then
228            diff=abs(a-b)/diff
229            if (diff.gt.0.) then
230    c         print *,int(log10(diff)),diff
231              linnum=int(log10(diff))
232              best=max(best,linnum)
233          endif          endif
         set accuracy=`echo $accuracy | sed 's/\./../'`  
       end  
       echo ""  
       if ($?fail ) then  
         if (! $?fails) set fails  
         set fails=($fails $dr)  
         echo "                        ***** FAIL *****"  
234        else        else
235          if (! $?passes) set passes          if (best.eq.-16.and.diff.ne.0.) best=-22
         set passes=($passes $dr)  
         echo ""  
         echo "                   ***** PASS (grade $lvl) *****"  
236        endif        endif
237        set accuracy=$lvl        goto 99
238      else    60  stop 'cmpnum: An error occured reading a,b'
239        set exactmatch=Yes    70  print *,-best
240        echo ""        end
241        echo Model passed at highest accuracy.  EOFA
242        echo ""  f77 tmp_cmpnum.f
243        echo "                        ***** PASS *****"  if [ -x ./a.out ]; then
244        if (! $?passes) set passes   return 0
245        set passes=($passes $dr)  else
246      endif   echo createcodelet: failed to compile codelet 1>&2
247     exit 1
248    fi
249    }
250    
251    formatresults()
252    {
253    # formatresults expt genmake depend make run results*
254    
255     nm=$1
256     printf '%s %s %s %s' $2 $3 $4 $5
257     shift; shift; shift; shift; shift;
258     printf '%3s' $@
259    
260     if [ $1 = '--' ]; then
261      printf ' N/O '
262     else
263      if [ $1 -gt 12 ]; then
264       printf ' pass'
265    else    else
266      echo " error"     printf ' FAIL'
267      echo "               ***** An error occured running the model *****"    fi
268      tail output.txt   fi
269      echo The runtime error occured in \"$dr\"   printf '  %s' $nm
270      if ($?on_error_die) exit 1   printf '\n'
271    endif  
272    endif  }
273    cd ..  
274   endif  show_help()
275   echo ""  {
276   cd ..  cat - << EOF
277  # Pretty summary  $0 [-help] [-quick] [-verbose] dir1 [dir2] [...]
278   printresults:   -help      Show this help message
279   printf '  %s\t  %s\t  %s\t  %s\t  %s\t  %s\t%s\n' $config $makedepend $compile $execute $exactmatch $accuracy $dr >> summary.txt   -quick     Skip "genmake" and "make depend" if the Makefile exists
280  end   -quiet     Reduce the amount of output
281  echo ==============================================================================   -verbose   Produce copious amounts of output
282  echo ""   -debug     Produce even more output which will mean nothing to most
283     -clean     Do "make CLEAN" before compiling. This forces a complete rebuild.
284     -longtest  Compare numeric output for mean and s.d. of variables.
285    
286    Normal usage:
287     $0 *       Configure, compile, run and analyze in all experiment directories
288    EOF
289    }
290    
291    ###############################################################################
292    
293    # Main function
294    
295    # Default properties
296    debug=0
297    verbose=1
298    quick=0
299    clean=0
300    longtest=0
301    expts=''
302    
303    # Process arguments
304    for arg in $@
305    do
306     case $arg in
307       -quick) quick=1;;
308       -verbose) verbose=2;;
309       -debug) debug=1;;
310       -clean) clean=1;;
311       -longtest) longtest=1;;
312       -quiet) verbose=0;;
313       -help) show_help; exit 0;;
314       *) test -d $arg && expts=`echo $expts $arg`;;
315     esac
316    done
317    
318    if [ ${#expts} -eq 0 ]; then
319     echo Scanning all directories
320     for arg in *
321      do
322       test -d $arg && expts=`echo $expts $arg`
323     done
324    fi
325    
326    createcodelet
327    
328    if [ $longtest -gt 0 ]; then
329    cat << EOF > summary.txt
330                    T           S           U           V
331    C D M    c        m  s        m  s        m  s        m  s
332    n p a R  g  m  m  e  .  m  m  e  .  m  m  e  .  m  m  e  .
333    f n k u  2  i  a  a  d  i  a  a  d  i  a  a  d  i  a  a  d
334    g d e n  d  n  x  n  .  n  x  n  .  n  x  n  .  n  x  n  .
335    
336    EOF
337    else
338    cat << EOF > summary.txt
339                  T     S     U     V
340    C D M    c                        
341    n p a R  g  m  m  m  m  m  m  m  m
342    f n k u  2  i  a  i  a  i  a  i  a
343    g d e n  d  n  x  n  x  n  x  n  x
344    
345    EOF
346    fi
347    
348    # Now configue, make, run and test in each directory
349    for dir in $expts
350    do
351     if [ -r $dir/results/output.txt ]; then
352     echo -------------------------------------------------------------------------------
353     echo
354     echo Experiment: $dir
355     echo
356     unset genmake makedepend make run
357     results='-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --'
358     results='-- -- -- -- -- -- -- -- --'
359     genmakemodel $dir/input && genmake=Y \
360     && makeclean $dir/input \
361     && makedependmodel $dir/input && makedepend=Y \
362     && makemodel $dir/input && make=Y \
363     && runmodel $dir/input mitgcmuv && run=Y \
364     && results=`testoutput $dir`
365     echo
366     formatresults $dir ${genmake:-N} ${makedepend:-N} ${make:-N} ${run:-N} $results
367     echo
368     formatresults $dir ${genmake:-N} ${makedepend:-N} ${make:-N} ${run:-N} $results >> summary.txt
369     fi
370    done
371    
372    rm tmp_cmpnum.f a.out
373    
374  echo "Summary:"  echo -------------------------------------------------------------------------------
375  echo ""  echo
376  cat summary.txt  cat summary.txt

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

  ViewVC Help
Powered by ViewVC 1.1.22