/[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.7 by adcroft, Fri Jun 29 18:28:44 2001 UTC revision 1.17 by heimbach, Tue Aug 21 15:21:10 2001 UTC
# Line 1  Line 1 
1  #!/bin/csh -f  #!/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 digitsOfAccuracy=8  testoutput_for_prop()
13  set SKIP=( )  {
14  printf '%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n' " " Make " " " " Exact "# of" " " " " > summary.txt  # testoutput_for_prop dir s1 label
15  printf '%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n' Config Depend Compile Execute Match Digits Status Experiment >> summary.txt  #
16    #  compares files in $dir/input/output.txt and $dir/results.output.txt
17  # Pass any arguments  #  using search strings s1 and text label
18  foreach arg ($argv)  
19   switch ($arg)   if [ $debug -gt 0 ]; then
20    case -clean:    echo testoutput_for_prop: grep "$2" $1/input/output.txt 1>&2
21     echo Cleaning ...   fi
22     foreach dr ([a-zA-Z01-9]*)   if [ -r $1/input/output.txt ]; then
23      if (-d $dr/input) then    grep "$2" $1/input/output.txt | sed 's/.*=//' | nl > tmp1.txt
       echo Entering $dr  
       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  
   case -skip=*:  
    set SKIP = ( $SKIP `echo $arg | sed 's/-skip=//' | sed 's/,/ /g' `)  
    breaksw  
   default:  
    echo Unknown argument given to $0  
    exit 1  
  endsw  
 end  
   
 # Need to make sure we don't meet non-model problems ...  
 unlimit  
   
 foreach dr ([a-zA-Z01-9]*)  
   
  if (! -d $dr/input ) continue  
  foreach skip ($SKIP)  
   if ( `echo $dr | sed s/$skip.'*'//` == '' ) continue;continue  
  end  
  set config=-  
  set makedepend=-  
  set compile=-  
  set execute=-  
  set exactmatch=-  
  set accuracy=-  
  set pass=FAIL  
  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 > & 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    {
58  # Compare output based on cg2d residual  # dashnum n1 n2 n3 ...
59      grep "cg2d_init_res" output.txt | sed 's/.*=//' | nl > high.txt  #
60      grep "cg2d_init_res" ../results/output.txt | sed 's/.*=//' | nl > oldhigh.txt  #  print numbers using %3i format or "--" if number = 99
61      join high.txt oldhigh.txt > low.txt  for num in $@
62      set nlines=`wc -l low.txt | awk '{print $1}'`  do
63      echo "  comparing $nlines lines of output"   if [ $num = 99 ]; then
64      @ line = 1    printf ' --'
65      set bestacc=99;   else
66      set worstline='Exact match'    printf '%3i' $num
67      while ($line <= $nlines)   fi
68       set vals=(`grep "^$line" low.txt | awk '{print $2,$3}'`)  done
69       @ line += 1  }
70       unset acc  
71       foreach dp (14 13 12 11 10 9 8 7 6 5 4 3 2 1 0)  testoutput()
72        set cmp=(`printf '%23.'$dp'e %23.'$dp'e\n' $vals[1] $vals[2]`)  {
73        if ($cmp[1] =~ $cmp[2]) then  # testoutput diretory
74         if (! $?acc) then  #
75          set acc=$dp  #  test output in "directory"
76          break  
77         endif  if [ $debug -gt 0 ]; then
78        endif   echo testoutput: testoutput_for_prop $1 cg2d_init_res 1>&2
79       end  fi
80       if (! $?acc) set acc=0  testoutput_for_prop $1 "cg2d_init_res" "cg2d init. residual"; cg2dres=$?
81       if ($acc < $bestacc) then  if [ $debug -gt 0 ]; then
82         set worstline=($line $vals[1] $vals[2] `printf '%23.'$acc'e' $vals[1]` $acc)   echo testoutput: cg2dres=$cg2dres 1>&2
83         set bestacc=$acc  fi
84       endif  
85  #    echo $line $vals[1] $vals[2] `printf '%23.'$acc'e' $vals[1]` $acc  if [ $longtest -gt 0 ]; then
86      end  testoutput_for_prop $1 "dynstat_theta_min" "theta minimum"; tmin=$?
87      if ($nlines == 0) then  testoutput_for_prop $1 "dynstat_theta_max" "theta maximum"; tmax=$?
88       set bestacc=0  testoutput_for_prop $1 "dynstat_theta_mean" "theta mean"; tmean=$?
89       set worstline="Could find no lines in output.txt to compare"  testoutput_for_prop $1 "dynstat_theta_sd" "theta s.d."; tsd=$?
90      endif  testoutput_for_prop $1 "dynstat_salt_min" "salt minimum"; smin=$?
91      if ($bestacc == 14 & $?exactmatch) then  testoutput_for_prop $1 "dynstat_salt_max" "salt maximum"; smax=$?
92       set exactmatch=Yes  testoutput_for_prop $1 "dynstat_salt_mean" "salt mean"; smean=$?
93       echo " "  testoutput_for_prop $1 "dynstat_salt_sd" "salt s.d."; ssd=$?
94       echo "                        ***** EXACT MATCH *****"  testoutput_for_prop $1 "dynstat_uvel_min" "U minimum"; umin=$?
95      endif  testoutput_for_prop $1 "dynstat_uvel_max" "U maximum"; umax=$?
96      if ($bestacc > $digitsOfAccuracy) then  testoutput_for_prop $1 "dynstat_uvel_mean" "U mean"; umean=$?
97       set pass=Pass  testoutput_for_prop $1 "dynstat_uvel_sd" "U s.d."; usd=$?
98       echo " "  testoutput_for_prop $1 "dynstat_vvel_min" "V minimum"; vmin=$?
99       echo "                      ***** PASS (digits=$bestacc) *****"  testoutput_for_prop $1 "dynstat_vvel_max" "V maximum"; vmax=$?
100       echo " "  testoutput_for_prop $1 "dynstat_vvel_mean" "V mean"; vmean=$?
101       echo " worstline: " $worstline  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        if [ $ieee -eq 0 ]; then
126         ../../../tools/genmake -mods=../code > make.log 2>&1
127        else
128         ../../../tools/genmake -ieee -mods=../code > make.log 2>&1
129        fi
130        if [ $? -ne 0 ]; then
131         tail make.log
132         echo genmakemodel: genmake failed 1>&2
133         return 1
134        else
135          echo succesful 1>&2
136        fi
137       fi
138     )
139    }
140    
141    makeclean()
142    {
143    # makedependmodel directory
144     ( cd $1;
145       if [ $clean -gt 0 ]; then
146        rm -f output.txt
147        printf 'make clean ... ' 2>&1
148        make CLEAN >> make.log 2>&1
149        if [ $? -ne 0 ]; then
150          tail make.log
151          echo makeclean: make clean failed 1>&2
152          return 1
153        else
154          echo succesful 1>&2
155        fi
156       fi
157     )
158    }
159    
160    makedependmodel()
161    {
162    # makedependmodel directory
163     ( cd $1;
164       if [ $quick -eq 0 -o ! -r Makefile ]; then
165        printf 'make depend ... ' 1>&2
166        make cleanlinks >> make.log 2>&1
167        make depend >> make.log 2>&1
168        if [ $? -ne 0 ]; then
169          tail make.log
170          echo makemodel: make depend failed 1>&2
171          return 1
172      else      else
173       echo " "        echo succesful 1>&2
174       echo "                      ***** FAIL (digits=$bestacc) *****"      fi
175       echo " "     fi
176       echo " worstline: " $worstline   )
177      endif  }
178      set accuracy=$bestacc  
179    makemodel()
180    {
181    # makemodel directory
182     ( cd $1;
183       if [ -r Makefile ]; then
184        printf 'make ... ' 1>&2
185        make >> make.log 2>&1
186        if [ $? -ne 0 ]; then
187         tail make.log
188         echo failed 1>&2
189         return 1
190        else
191         echo succesful 1>&2
192        fi
193       fi
194     )
195    }
196    
197    runmodel()
198    {
199    # runmodel directory exe
200    #
201    #  runs the model "exe" in "directory" (exe is relative to directory)
202    
203     ( cd $1
204       if [ -x $2 ]; then
205        if [ $quick -eq 0 ]; then
206         rm -f output.txt
207        fi
208        echo -n "runmodel: " 1>&2
209        make output.txt && return 0
210    #   if [ ! -r output.txt -o $quick -eq 0 ]; then
211    #    echo runmodel: running... 1>&2
212    #    ( ./$2 > output.txt 2>&1 ) && return 0
213    #    rm -f output.txt
214    #    ( make output.txt ) && return 0
215    #    return 1
216    #   else
217    #    echo runmodel: output.txt is newer than executable 1>&2
218    #    ( make output.txt ) && return 0
219    #    return 0
220    #   fi
221    #  else
222    #   echo runmodel: executable \"$1/$2\" is missing 1>&2
223    #   return 1
224       fi
225     )
226    }
227    
228    createcodelet()
229    {
230    # create codelet for comparing model output
231    cat > tmp_cmpnum.f <<EOFA
232          program cmpnum
233          implicit none
234          real*8 a,b,diff
235          integer linnum,best
236          best=-16
237      99  read(*,*,end=70,err=60) linnum,a,b
238          diff=0.5*(abs(a)+abs(b))
239    c     print *,a,b,diff,abs(a-b)/diff
240          if (diff.gt.1.e-12) then
241            diff=abs(a-b)/diff
242            if (diff.gt.0.) then
243    c         print *,int(log10(diff)),diff
244              linnum=int(log10(diff))
245              best=max(best,linnum)
246            endif
247          else
248            if (best.eq.-16.and.diff.ne.0.) best=-22
249          endif
250          goto 99
251      60  stop 'cmpnum: An error occured reading a,b'
252      70  print *,-best
253          end
254    EOFA
255    f77 tmp_cmpnum.f
256    if [ -x ./a.out ]; then
257     return 0
258    else
259     echo createcodelet: failed to compile codelet 1>&2
260     exit 1
261    fi
262    }
263    
264    formatresults()
265    {
266    # formatresults expt genmake depend make run results*
267    
268     nm=$1
269     printf '%s %s %s %s' $2 $3 $4 $5
270     shift; shift; shift; shift; shift;
271     printf '%3s' $@
272    
273     if [ $1 = '--' ]; then
274      printf ' N/O '
275     else
276      if [ $1 -gt 12 ]; then
277       printf ' pass'
278    else    else
279      echo " error"     printf ' FAIL'
280      echo "               ***** An error occured running the model *****"    fi
281      tail output.txt   fi
282      echo The runtime error occured in \"$dr\"   printf '  %s' $nm
283      if ($?on_error_die) exit 1   printf '\n'
284      set pass=-  
285    endif  }
286    rm -f high.txt oldhigh.txt low.txt oldlow.txt output.txt make.log  
287    endif  show_help()
288    cd ..  {
289   endif  cat - << EOF
290   echo ""  $0 [-help] [-quick] [-verbose] dir1 [dir2] [...]
291   cd ..   -help      Show this help message
292  # Pretty summary   -quick     Skip "genmake" and "make depend" if the Makefile exists
293   printresults:   -quiet     Reduce the amount of output
294   printf '  %s\t  %s\t  %s\t  %s\t  %s\t %s\t %s\t%s\n' $config $makedepend $compile $execute $exactmatch $accuracy $pass $dr >> summary.txt   -verbose   Produce copious amounts of output
295  end   -debug     Produce even more output which will mean nothing to most
296  echo ==============================================================================   -clean     Do "make CLEAN" before compiling. This forces a complete rebuild.
297  echo ""   -longtest  Compare numeric output for mean and s.d. of variables.
298     -noieee    By default, $0 uses the -ieee option for genmake. This turns it off.
299    
300    Normal usage:
301     $0 *       Configure, compile, run and analyze in all experiment directories
302    EOF
303    }
304    
305    scandirs()
306    {
307    if [ $# -eq 0 ]; then
308     for arg in *
309      do
310       test -d $arg/input && echo $arg
311     done
312    else
313     echo $*
314    fi
315    }
316    
317    ###############################################################################
318    
319    # Main function
320    
321    # Default properties
322    debug=0
323    verbose=1
324    quick=0
325    clean=0
326    ieee=1
327    longtest=0
328    expts=''
329    
330    # Process arguments
331    for arg in $@
332    do
333     case $arg in
334       -quick) quick=1;;
335       -verbose) verbose=2;;
336       -debug) debug=1;;
337       -clean) clean=1;;
338       -noieee) ieee=0;;
339       -longtest) longtest=1;;
340       -quiet) verbose=0;;
341       -help) show_help; exit 0;;
342       -*) echo Unrecognized option:$arg; exit 9;;
343       *) test -d $arg && expts=`echo $expts $arg`;;
344     esac
345    done
346    
347    if [ $clean -gt 0 -a $quick -gt 0 ]; then
348     echo You specified -quick and -clean together which conflict.
349     echo Please specify either -quick or -clean or neither but not both.
350     exit 1
351    fi
352    
353    #if [ ${#expts} -eq 0 ]; then
354    # echo Scanning all directories
355    # for arg in *
356    #  do
357    #   test -d $arg && expts=`echo $expts $arg`
358    # done
359    #fi
360    expts=`scandirs $expts`
361    
362    createcodelet
363    
364    if [ $longtest -gt 0 ]; then
365    cat << EOF > summary.txt
366                    T           S           U           V
367    C D M    c        m  s        m  s        m  s        m  s
368    n p a R  g  m  m  e  .  m  m  e  .  m  m  e  .  m  m  e  .
369    f n k u  2  i  a  a  d  i  a  a  d  i  a  a  d  i  a  a  d
370    g d e n  d  n  x  n  .  n  x  n  .  n  x  n  .  n  x  n  .
371    
372    EOF
373    else
374    cat << EOF > summary.txt
375                  T     S     U     V
376    C D M    c                        
377    n p a R  g  m  m  m  m  m  m  m  m
378    f n k u  2  i  a  i  a  i  a  i  a
379    g d e n  d  n  x  n  x  n  x  n  x
380    
381    EOF
382    fi
383    
384    # Now configue, make, run and test in each directory
385    for dir in $expts
386    do
387     if [ -r $dir/results/output.txt ]; then
388     echo -------------------------------------------------------------------------------
389     echo
390     echo Experiment: $dir
391     echo
392     unset genmake makedepend make run
393     if [ $longtest -gt 0 ]; then
394      results='-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --'
395     else
396      results='-- -- -- -- -- -- -- -- --'
397     fi
398     genmakemodel $dir/input && genmake=Y \
399     && makeclean $dir/input \
400     && makedependmodel $dir/input && makedepend=Y \
401     && makemodel $dir/input && make=Y \
402     && runmodel $dir/input mitgcmuv && run=Y \
403     && results=`testoutput $dir` \
404     && makeclean $dir/input
405     echo
406     formatresults $dir ${genmake:-N} ${makedepend:-N} ${make:-N} ${run:-N} $results
407     echo
408     formatresults $dir ${genmake:-N} ${makedepend:-N} ${make:-N} ${run:-N} $results >> summary.txt
409     fi
410    done
411    
412    rm tmp_cmpnum.f a.out
413    
414  echo "Summary:"  echo -------------------------------------------------------------------------------
415  echo ""  echo
416  cat summary.txt  cat summary.txt

Legend:
Removed from v.1.7  
changed lines
  Added in v.1.17

  ViewVC Help
Powered by ViewVC 1.1.22