/[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.22 by adcroft, Thu Nov 7 21:53:34 2002 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
24        echo Entering $dr    lncnt=`wc -l tmp1.txt | awk '{print $1}' `
25        cd $dr/input    if [ $lncnt -lt 3 ]; then
26        echo ""     if [ $verbose -gt 0 ]; then
27        make CLEAN      echo Not enough lines of output when searching for "$2" 1>&2
28        \rm -f {*output,*high,*low}.txt *.log     fi
29        \rm -f ?ake*     return 99
30        cd ../..    fi
     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)  
31   else   else
32    set config=NO    echo testoutput_for_prop: output.txt from model run was not readable 1>&2
33    cd input    return 99
34    echo -n "  generating Makefile ..."   fi
35    ../../../tools/genmake -mods=../code >&! make.log   if [ $debug -gt 0 ]; then
36    if ($status == 0) set config=Yes    echo testoutput_for_prop: grep "$2" $1/results/output.txt 1>&2
37    set makedepend=NO   fi
38    echo " done."   grep "$2" $1/results/output.txt | sed 's/.*=//' | nl > tmp2.txt
39    echo -n "  make depend ..."    lncnt=`wc -l tmp2.txt | awk '{print $1}' `
40    make cleanlinks depend >>& make.log    if [ $lncnt -lt 3 ]; then
41    if ($status == 0) set makedepend=Yes     if [ $verbose -gt 0 ]; then
42    echo " done."      echo Not enough lines of output when searching for "$2" 1>&2
43    echo -n "  make ..."     fi
44    make >>& make.log     return 99
45    if ($status) then    fi
46     echo "               ***** An error occurred during make *****"   if [ $debug -gt 0 ]; then
47     cat make.log    echo testoutput_for_prop: join tmp1.txt tmp2.txt 1>&2
48     echo The error during compilation occured in \"$dr\"   fi
49     set compile=NO   join tmp1.txt tmp2.txt | awk '{print $1 " " $2 " " $3}' > tmp3.txt
50     if ($?on_error_die) exit 1   if [ $debug -gt 0 ]; then
51    else    echo testoutput_for_prop: compare_lines 1>&2
52     set compile=Yes   fi
53     set execute=NO   compare_lines
54    endif   digits_of_similarity=$?
55    echo " done."   if [ $digits_of_similarity -eq 99 ]; then
56    echo -n "  running model ..."    if [ $verbose -gt 0 ]; then
57    if ($compile == 'Yes') then     echo testoutput_for_prop: No comparison was available for \"$2\" 1>&2
58    ./mitgcmuv > & output.txt    fi
59    if ($status == 0) then    digits_of_similarity=99
60      set execute=Yes   else
61      set exactmatch=NO    if [ $verbose -gt 0 ]; then
62      set accuracy=-     echo There were $digits_of_similarity decimal places of similarity for \"$2\" 1>&2
63      echo " done."    fi
64     fi
65  # Compare output based on cg2d residual   rm tmp1.txt tmp2.txt tmp3.txt
66      grep "cg2d_init_res" output.txt | sed 's/.*=//' | nl > high.txt  
67      grep "cg2d_init_res" ../results/output.txt | sed 's/.*=//' | nl > oldhigh.txt   return $digits_of_similarity
68      join high.txt oldhigh.txt > low.txt  }
69      set nlines=`wc -l low.txt | awk '{print $1}'`  
70      echo "  comparing $nlines lines of output"  dashnum()
71      @ line = 1  {
72      set bestacc=99;  # dashnum n1 n2 n3 ...
73      set worstline='Exact match'  #
74      while ($line <= $nlines)  #  print numbers using %3i format or "--" if number = 99
75       set vals=(`grep "^$line" low.txt | awk '{print $2,$3}'`)  for num in $@
76       @ line += 1  do
77       unset acc   if [ $num = 99 ]; then
78       foreach dp (14 13 12 11 10 9 8 7 6 5 4 3 2 1 0)    printf ' --'
79        set cmp=(`printf '%23.'$dp'e %23.'$dp'e\n' $vals[1] $vals[2]`)   else
80        if ($cmp[1] =~ $cmp[2]) then    printf '%3i' $num
81         if (! $?acc) then   fi
82          set acc=$dp  done
83          break  }
84         endif  
85    testoutput()
86    {
87    # testoutput diretory
88    #
89    #  test output in "directory"
90    
91    if [ $debug -gt 0 ]; then
92     echo testoutput: testoutput_for_prop $1 cg2d_init_res 1>&2
93    fi
94    testoutput_for_prop $1 "cg2d_init_res" "cg2d init. residual"; cg2dres=$?
95    if [ $debug -gt 0 ]; then
96     echo testoutput: cg2dres=$cg2dres 1>&2
97    fi
98    
99    if [ $longtest -gt 0 ]; then
100    testoutput_for_prop $1 "dynstat_theta_min" "theta minimum"; tmin=$?
101    testoutput_for_prop $1 "dynstat_theta_max" "theta maximum"; tmax=$?
102    testoutput_for_prop $1 "dynstat_theta_mean" "theta mean"; tmean=$?
103    testoutput_for_prop $1 "dynstat_theta_sd" "theta s.d."; tsd=$?
104    testoutput_for_prop $1 "dynstat_salt_min" "salt minimum"; smin=$?
105    testoutput_for_prop $1 "dynstat_salt_max" "salt maximum"; smax=$?
106    testoutput_for_prop $1 "dynstat_salt_mean" "salt mean"; smean=$?
107    testoutput_for_prop $1 "dynstat_salt_sd" "salt s.d."; ssd=$?
108    testoutput_for_prop $1 "dynstat_uvel_min" "U minimum"; umin=$?
109    testoutput_for_prop $1 "dynstat_uvel_max" "U maximum"; umax=$?
110    testoutput_for_prop $1 "dynstat_uvel_mean" "U mean"; umean=$?
111    testoutput_for_prop $1 "dynstat_uvel_sd" "U s.d."; usd=$?
112    testoutput_for_prop $1 "dynstat_vvel_min" "V minimum"; vmin=$?
113    testoutput_for_prop $1 "dynstat_vvel_max" "V maximum"; vmax=$?
114    testoutput_for_prop $1 "dynstat_vvel_mean" "V mean"; vmean=$?
115    testoutput_for_prop $1 "dynstat_vvel_sd" "V s.d."; vsd=$?
116    else
117    testoutput_for_prop $1 "dynstat_theta_min" "theta minimum"; tmin=$?
118    testoutput_for_prop $1 "dynstat_theta_max" "theta maximum"; tmax=$?
119    testoutput_for_prop $1 "dynstat_salt_min" "salt minimum"; smin=$?
120    testoutput_for_prop $1 "dynstat_salt_max" "salt maximum"; smax=$?
121    testoutput_for_prop $1 "dynstat_uvel_min" "U minimum"; umin=$?
122    testoutput_for_prop $1 "dynstat_uvel_max" "U maximum"; umax=$?
123    testoutput_for_prop $1 "dynstat_vvel_min" "V minimum"; vmin=$?
124    testoutput_for_prop $1 "dynstat_vvel_max" "V maximum"; vmax=$?
125    fi
126    
127    dashnum $cg2dres $tmin $tmax $tmean $tsd $smin $smax $smean $ssd \
128            $umin $umax $umean $usd $vmin $vmax $vmean $vsd
129    #printf '%3i' $cg2dres $tmin $tmax $tmean $tsd $smin $smax $smean $ssd \
130    #       $umin $umax $umean $usd $vmin $vmax $vmean $vsd
131    }
132    
133    genmakemodel()
134    {
135    # genmakemodel directory
136     ( cd $1;
137       if [ $quick -eq 0 -o ! -r Makefile ]; then
138        printf 'genmake ... ' 1>&2
139        if [ $ieee -eq 0 ]; then
140         ../../../tools/genmake -mods=../code > make.log 2>&1
141        else
142         ../../../tools/genmake -ieee -mods=../code > make.log 2>&1
143        fi
144        if [ $? -ne 0 ]; then
145         tail make.log
146         echo genmakemodel: genmake failed 1>&2
147         return 1
148        else
149          echo succesful 1>&2
150        fi
151       fi
152     )
153    }
154    
155    makecleancompile()
156    {
157    # makecleancompile directory
158     ( cd $1;
159       if [ $force -gt 0 ]; then
160        rm -f output.txt
161        printf 'make clean ... ' 2>&1
162        make CLEAN >> make.log 2>&1
163        if [ $? -ne 0 ]; then
164          tail make.log
165          echo makecleancompile: make clean failed 1>&2
166          return 1
167        else
168          echo succesful 1>&2
169        fi
170       fi
171     )
172    }
173    
174    makecleanupafter()
175    {
176    # makeupafter directory
177     ( cd $1;
178       if [ $clean -gt 0 ]; then
179        rm -f output.txt
180        printf 'make clean ... ' 2>&1
181        make CLEAN >> make.log 2>&1
182        if [ $? -ne 0 ]; then
183          tail make.log
184          echo makeupafter: make clean failed 1>&2
185          return 1
186        else
187          echo succesful 1>&2
188        fi
189       fi
190     )
191    }
192    
193    makedependmodel()
194    {
195    # makedependmodel directory
196     ( cd $1;
197       if [ $quick -eq 0 -o ! -r Makefile ]; then
198        printf 'make depend ... ' 1>&2
199        make cleanlinks >> make.log 2>&1
200        make depend >> make.log 2>&1
201        if [ $? -ne 0 ]; then
202          tail make.log
203          echo makemodel: make depend failed 1>&2
204          return 1
205        else
206          echo succesful 1>&2
207        fi
208       fi
209     )
210    }
211    
212    makemodel()
213    {
214    # makemodel directory
215     ( cd $1;
216       if [ -r Makefile ]; then
217        printf 'make ... ' 1>&2
218        make >> make.log 2>&1
219        if [ $? -ne 0 ]; then
220         tail make.log
221         echo failed 1>&2
222         return 1
223        else
224         echo succesful 1>&2
225        fi
226       fi
227     )
228    }
229    
230    runmodel()
231    {
232    # runmodel directory exe
233    #
234    #  runs the model "exe" in "directory" (exe is relative to directory)
235    
236     ( cd $1
237       if [ -x $2 ]; then
238        if [ $quick -eq 0 ]; then
239         rm -f output.txt
240        fi
241        printf 'runmodel: ' 1>&2
242        make output.txt && return 0
243    #   if [ ! -r output.txt -o $quick -eq 0 ]; then
244    #    echo runmodel: running... 1>&2
245    #    ( ./$2 > output.txt 2>&1 ) && return 0
246    #    rm -f output.txt
247    #    ( make output.txt ) && return 0
248    #    return 1
249    #   else
250    #    echo runmodel: output.txt is newer than executable 1>&2
251    #    ( make output.txt ) && return 0
252    #    return 0
253    #   fi
254    #  else
255    #   echo runmodel: executable \"$1/$2\" is missing 1>&2
256    #   return 1
257       fi
258     )
259    }
260    
261    createcodelet()
262    {
263    # create codelet for comparing model output
264    cat > tmp_cmpnum.f <<EOFA
265          program cmpnum
266          implicit none
267          real*8 a,b,diff
268          integer linnum,best
269          best=-16
270      99  read(*,*,end=70,err=60) linnum,a,b
271          diff=0.5*(abs(a)+abs(b))
272    c     print *,a,b,diff,abs(a-b)/diff
273          if (diff.gt.1.e-12) then
274            diff=abs(a-b)/diff
275            if (diff.gt.0.) then
276    c         print *,int(log10(diff)),diff
277              linnum=int(log10(diff))
278              best=max(best,linnum)
279            endif
280          else
281            if (best.eq.-16.and.diff.ne.0.) best=-22
282        endif        endif
283       end        goto 99
284       if (! $?acc) set acc=0    60  stop 'cmpnum: An error occured reading a,b'
285       if ($acc < $bestacc) then    70  print *,-best
286         set worstline=($line $vals[1] $vals[2] `printf '%23.'$acc'e' $vals[1]` $acc)        end
287         set bestacc=$acc  EOFA
288       endif  f77 tmp_cmpnum.f
289  #    echo $line $vals[1] $vals[2] `printf '%23.'$acc'e' $vals[1]` $acc  if [ -x ./a.out ]; then
290      end   return 0
291      if ($nlines == 0) then  else
292       set bestacc=0   echo createcodelet: failed to compile codelet 1>&2
293       set worstline="Could find no lines in output.txt to compare"   exit 1
294      endif  fi
295      if ($bestacc == 14 & $?exactmatch) then  }
296       set exactmatch=Yes  
297       echo " "  formatresults()
298       echo "                        ***** EXACT MATCH *****"  {
299      endif  # formatresults expt genmake depend make run results*
300      if ($bestacc > $digitsOfAccuracy) then  
301       set pass=Pass   nm=$1
302       echo " "   printf '%s %s %s %s' $2 $3 $4 $5
303       echo "                      ***** PASS (digits=$bestacc) *****"   shift; shift; shift; shift; shift;
304       echo " "   printf '%3s' $@
305       echo " worstline: " $worstline  
306      else   if [ $1 = '--' ]; then
307       echo " "    printf ' N/O '
308       echo "                      ***** FAIL (digits=$bestacc) *****"   else
309       echo " "    if [ $1 -gt 12 ]; then
310       echo " worstline: " $worstline     printf ' pass'
     endif  
     set accuracy=$bestacc  
311    else    else
312      echo " error"     printf ' FAIL'
313      echo "               ***** An error occured running the model *****"    fi
314      tail output.txt   fi
315      echo The runtime error occured in \"$dr\"   printf '  %s' $nm
316      if ($?on_error_die) exit 1   printf '\n'
317      set pass=-  
318    endif  }
319    rm -f high.txt oldhigh.txt low.txt oldlow.txt output.txt make.log  
320    endif  show_help()
321    cd ..  {
322   endif  cat - << EOF
323   echo ""  $0 [-help] [-quick] [-verbose] dir1 [dir2] [...]
324   cd ..   -help      Show this help message
325  # Pretty summary   -quick     Skip "genmake" and "make depend" if the Makefile exists
326   printresults:   -quiet     Reduce the amount of output
327   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
328  end   -debug     Produce even more output which will mean nothing to most
329  echo ==============================================================================   -force     Do "make CLEAN" before compiling. This forces a complete rebuild.
330  echo ""   -clean     Do "make CLEAN" after compiling and testing.
331     -shorttest Don't compare numeric output for mean and s.d. of variables.
332     -noieee    By default, $0 uses the -ieee option for genmake. This turns it off.
333     -cleanup   Aggresively removes all model output, executables and object files
334                and then exits. Use with care.
335    
336    Normal usage:
337     $0 *       Configure, compile, run and analyze in all experiment directories
338    EOF
339    }
340    
341    scandirs()
342    {
343    if [ $# -eq 0 ]; then
344     for arg in *
345      do
346       test -d $arg/input && echo $arg
347     done
348    else
349     echo $*
350    fi
351    }
352    
353    clean_up()
354    {
355    # Find all executables, object files, CPP'd source and model output
356    # and DELETE it.
357    for opt in '-name mitgcmuv*' '-name *.o' '-name *.f' '-name *.c' '-path *results -prune -o -name *.meta' '-path *results -prune -o -name *.data' '-type l'
358     do
359       echo Cleaning: find . $opt -exec rm {} \;
360       find . $opt -exec rm {} \;
361    done
362    }
363    
364    ###############################################################################
365    
366    # Main function
367    
368    # Default properties
369    debug=0
370    verbose=1
371    quick=0
372    force=0
373    clean=0
374    ieee=1
375    longtest=1
376    expts=''
377    
378    # Process arguments
379    for arg in $@
380    do
381     case $arg in
382       -cleanup) clean_up; exit 0;;
383       -quick) quick=1;;
384       -verbose) verbose=2;;
385       -debug) debug=1;;
386       -force) force=1;;
387       -clean) clean=1;;
388       -noieee) ieee=0;;
389       -shorttest) longtest=0;;
390       -quiet) verbose=0;;
391       -help) show_help; exit 0;;
392       -*) echo Unrecognized option:$arg; exit 9;;
393       *) test -d $arg && expts=`echo $expts $arg`;;
394     esac
395    done
396    
397    if [ $force -gt 0 -a $quick -gt 0 ]; then
398     echo You specified -quick and -force together which conflict.
399     echo Please specify either -quick or -force or neither but not both.
400     exit 1
401    fi
402    
403    #if [ ${#expts} -eq 0 ]; then
404    # echo Scanning all directories
405    # for arg in *
406    #  do
407    #   test -d $arg && expts=`echo $expts $arg`
408    # done
409    #fi
410    expts=`scandirs $expts`
411    
412    createcodelet
413    
414    if [ $longtest -gt 0 ]; then
415    cat << EOF > summary.txt
416                    T           S           U           V
417    C D M    c        m  s        m  s        m  s        m  s
418    n p a R  g  m  m  e  .  m  m  e  .  m  m  e  .  m  m  e  .
419    f n k u  2  i  a  a  d  i  a  a  d  i  a  a  d  i  a  a  d
420    g d e n  d  n  x  n  .  n  x  n  .  n  x  n  .  n  x  n  .
421    
422    EOF
423    else
424    cat << EOF > summary.txt
425                  T     S     U     V
426    C D M    c                        
427    n p a R  g  m  m  m  m  m  m  m  m
428    f n k u  2  i  a  i  a  i  a  i  a
429    g d e n  d  n  x  n  x  n  x  n  x
430    
431    EOF
432    fi
433    
434    # Now configue, make, run and test in each directory
435    for dir in $expts
436    do
437     if [ -r $dir/results/output.txt ]; then
438     echo -------------------------------------------------------------------------------
439     echo
440     echo Experiment: $dir
441     echo
442     unset genmake makedepend make run
443     if [ $longtest -gt 0 ]; then
444      results='-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --'
445     else
446      results='-- -- -- -- -- -- -- -- --'
447     fi
448     genmakemodel $dir/input && genmake=Y \
449     && makecleancompile $dir/input \
450     && makedependmodel $dir/input && makedepend=Y \
451     && makemodel $dir/input && make=Y \
452     && runmodel $dir/input mitgcmuv && run=Y \
453     && results=`testoutput $dir` \
454     && makecleanupafter $dir/input
455     echo
456     formatresults $dir ${genmake:-N} ${makedepend:-N} ${make:-N} ${run:-N} $results
457     echo
458     formatresults $dir ${genmake:-N} ${makedepend:-N} ${make:-N} ${run:-N} $results >> summary.txt
459     fi
460    done
461    
462    rm tmp_cmpnum.f a.out
463    
464  echo "Summary:"  echo -------------------------------------------------------------------------------
465  echo ""  echo
466  cat summary.txt  cat summary.txt

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

  ViewVC Help
Powered by ViewVC 1.1.22