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

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

  ViewVC Help
Powered by ViewVC 1.1.22