/[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.1 by adcroft, Fri Mar 9 17:56:37 2001 UTC revision 1.13 by adcroft, Tue Aug 14 18:29:43 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 passaccuracy=7  
12  printf '%s\t%s\t%s\t%s\t%s\t%s\t%s\n' " " Make " " " " Exact "# of" " " > summary.txt  testoutput_for_prop()
13  printf '%s\t%s\t%s\t%s\t%s\t%s\t%s\n' Config Depend Compile Execute Match Digits experiment >> summary.txt  {
14    # testoutput_for_prop dir s1 label
15  # Pass any arguments  #
16  foreach arg ($argv)  #  compares files in $dir/input/output.txt and $dir/results.output.txt
17   switch ($arg)  #  using search strings s1 and text label
18    case -clean:  
19     echo Cleaning ...   if [ $debug -gt 0 ]; then
20     foreach dr ([a-zA-Z01-9]*)    echo testoutput_for_prop: grep "$2" $1/input/output.txt 1>&2
21      if (-d $dr/input) then   fi
22        echo Entering $dr   if [ -r $1/input/output.txt ]; then
23        cd $dr/input    grep "$2" $1/input/output.txt | sed 's/.*=//' | nl > tmp1.txt
       echo ""  
       make CLEAN  
       \rm -f {*output,*high,*low}.txt *.log  
       \rm -f ?ake*  
       cd ../..  
     endif  
    end  
    rm -f summary.txt  
    exit 0  
   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    set makedepend=NO    return 99
27    set compile=NO   fi
28    set execute=NO   if [ $debug -gt 0 ]; then
29    set exactmatch=NO    echo testoutput_for_prop: grep "$2" $1/results/output.txt 1>&2
30    set accuracy=-   fi
31    cd input   grep "$2" $1/results/output.txt | sed 's/.*=//' | nl > tmp2.txt
32    echo -n "  generating Makefile ..."   if [ $debug -gt 0 ]; then
33    ../../../tools/genmake -mods=../code >&! make.log    echo testoutput_for_prop: join tmp1.txt tmp2.txt 1>&2
34    if ($status == 0) set config=Yes   fi
35    echo " done."   join tmp1.txt tmp2.txt | awk '{print $1 " " $2 " " $3}' > tmp3.txt
36    echo -n "  make depend ..."   if [ $debug -gt 0 ]; then
37    make cleanlinks depend >>& make.log    echo testoutput_for_prop: compare_lines 1>&2
38    if ($status == 0) set makedepend=Yes   fi
39    echo " done."   compare_lines
40    echo -n "  make ..."   digits_of_similarity=$?
41    make >>& make.log   if [ $digits_of_similarity -eq 99 ]; then
42    if ($status) then    if [ $verbose -gt 0 ]; then
43     echo "               ***** An error occurred during make *****"     echo testoutput_for_prop: No comparison was available for \"$2\" 1>&2
44     cat make.log    fi
45     exit 1    digits_of_similarity=99
46    else   else
47     set compile=Yes    if [ $verbose -gt 0 ]; then
48    endif     echo There were $digits_of_similarity decimal places of similarity for \"$2\" 1>&2
49    echo " done."    fi
50    echo -n "  running model ..."   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      echo " done."  }
55      sed 's/.*D iters, err =//' output.txt \  
56      | grep "   0    " \  dashnum()
57      > high.txt  {
58      grep "D iters" ../results/output.txt \  # dashnum n1 n2 n3 ...
59       | sed 's/.*D iters, err =//' \  #
60       | grep "   0    " \  #  print numbers using %3i format or "--" if number = 99
61       > oldhigh.txt  for num in $@
62      diff oldhigh.txt high.txt > /dev/null  do
63      if ($status) then   if [ $num = 99 ]; then
64        echo "  output differs:"    printf ' --'
65        diff oldhigh.txt high.txt   else
66        echo ""    printf '%3i' $num
67        @ lvl=0   fi
68        set accuracy='.'  done
69        set fail  }
70        echo -n Trying reduced accuracy  
71        while ($lvl <= $passaccuracy)  testoutput()
72          @ lvl+=1  {
73          echo -n " " $lvl  # testoutput diretory
74          sed s/{$accuracy}E/E/ high.txt > low.txt  #
75          sed s/{$accuracy}E/E/ oldhigh.txt > oldlow.txt  #  test output in "directory"
76          diff oldlow.txt low.txt > /dev/null  
77          if ($status == 0) then  if [ $debug -gt 0 ]; then
78            unset fail   echo testoutput: testoutput_for_prop $1 cg2d_init_res 1>&2
79            break  fi
80    testoutput_for_prop $1 "cg2d_init_res" "cg2d init. residual"; cg2dres=$?
81    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        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        printf 'make clean ... ' 2>&1
147        make CLEAN >> make.log 2>&1
148        if [ $? -ne 0 ]; then
149          tail make.log
150          echo makeclean: make clean failed 1>&2
151          return 1
152        else
153          echo succesful 1>&2
154        fi
155       fi
156     )
157    }
158    
159    makedependmodel()
160    {
161    # makedependmodel directory
162     ( cd $1;
163       if [ $quick -eq 0 -o ! -r Makefile ]; then
164        printf 'make depend ... ' 1>&2
165        make cleanlinks >> make.log 2>&1
166        make depend >> make.log 2>&1
167        if [ $? -ne 0 ]; then
168          tail make.log
169          echo makemodel: make depend failed 1>&2
170          return 1
171        else
172          echo succesful 1>&2
173        fi
174       fi
175     )
176    }
177    
178    makemodel()
179    {
180    # makemodel directory
181     ( cd $1;
182       if [ -r Makefile ]; then
183        printf 'make ... ' 1>&2
184        make >> make.log 2>&1
185        if [ $? -ne 0 ]; then
186         tail make.log
187         echo failed 1>&2
188         return 1
189        else
190         echo succesful 1>&2
191        fi
192       fi
193     )
194    }
195    
196    runmodel()
197    {
198    # runmodel directory exe
199    #
200    #  runs the model "exe" in "directory" (exe is relative to directory)
201    
202     ( cd $1
203       if [ -x $2 ]; then
204        if [ ! -r output.txt -o $quick -eq 0 ]; then
205         echo runmodel: running... 1>&2
206         ( ./$2 > output.txt 2>&1 ) && return 0
207         return 1
208        else
209         echo runmodel: output.txt is newer than executable 1>&2
210         return 0
211        fi
212       else
213        echo runmodel: executable \"$1/$2\" is missing 1>&2
214        return 1
215       fi
216     )
217    }
218    
219    createcodelet()
220    {
221    # create codelet for comparing model output
222    cat > tmp_cmpnum.f <<EOFA
223          program cmpnum
224          implicit none
225          real*8 a,b,diff
226          integer linnum,best
227          best=-16
228      99  read(*,*,end=70,err=60) linnum,a,b
229          diff=0.5*(abs(a)+abs(b))
230    c     print *,a,b,diff,abs(a-b)/diff
231          if (diff.gt.1.e-12) then
232            diff=abs(a-b)/diff
233            if (diff.gt.0.) then
234    c         print *,int(log10(diff)),diff
235              linnum=int(log10(diff))
236              best=max(best,linnum)
237          endif          endif
         set accuracy=`echo $accuracy | sed 's/\./../'`  
       end  
       echo ""  
       if ($?fail ) then  
         if (! $?fails) set fails  
         set fails=($fails $dr)  
         echo "                        ***** FAIL *****"  
238        else        else
239          if (! $?passes) set passes          if (best.eq.-16.and.diff.ne.0.) best=-22
         set passes=($passes $dr)  
         echo ""  
         echo "                   ***** PASS (grade $lvl) *****"  
240        endif        endif
241        set accuracy=$lvl        goto 99
242      else    60  stop 'cmpnum: An error occured reading a,b'
243        set exactmatch=Yes    70  print *,-best
244        echo ""        end
245        echo Model passed at highest accuracy.  EOFA
246        echo ""  f77 tmp_cmpnum.f
247        echo "                        ***** PASS *****"  if [ -x ./a.out ]; then
248        if (! $?passes) set passes   return 0
249        set passes=($passes $dr)  else
250      endif   echo createcodelet: failed to compile codelet 1>&2
251     exit 1
252    fi
253    }
254    
255    formatresults()
256    {
257    # formatresults expt genmake depend make run results*
258    
259     nm=$1
260     printf '%s %s %s %s' $2 $3 $4 $5
261     shift; shift; shift; shift; shift;
262     printf '%3s' $@
263    
264     if [ $1 = '--' ]; then
265      printf ' N/O '
266     else
267      if [ $1 -gt 12 ]; then
268       printf ' pass'
269    else    else
270      echo " error"     printf ' FAIL'
271      echo "               ***** An error occured running the mode *****"    fi
272      tail output.txt   fi
273      exit 1   printf '  %s' $nm
274    endif   printf '\n'
275    cd ..  
276   endif  }
277   echo ""  
278   cd ..  show_help()
279  # Pretty summary  {
280   printf '  %s\t  %s\t  %s\t  %s\t  %s\t  %s\t%s\n' $config $makedepend $compile $execute $exactmatch $accuracy $dr >> summary.txt  cat - << EOF
281  end  $0 [-help] [-quick] [-verbose] dir1 [dir2] [...]
282  echo ==============================================================================   -help      Show this help message
283  echo ""   -quick     Skip "genmake" and "make depend" if the Makefile exists
284     -quiet     Reduce the amount of output
285     -verbose   Produce copious amounts of output
286     -debug     Produce even more output which will mean nothing to most
287     -clean     Do "make CLEAN" before compiling. This forces a complete rebuild.
288     -longtest  Compare numeric output for mean and s.d. of variables.
289    
290    Normal usage:
291     $0 *       Configure, compile, run and analyze in all experiment directories
292    EOF
293    }
294    
295    scandirs()
296    {
297    if [ $# -eq 0 ]; then
298     for arg in *
299      do
300       test -d $arg/input && echo $arg
301     done
302    else
303     echo $*
304    fi
305    }
306    
307    ###############################################################################
308    
309    # Main function
310    
311    # Default properties
312    debug=0
313    verbose=1
314    quick=0
315    clean=0
316    ieee=0
317    longtest=0
318    expts=''
319    
320    # Process arguments
321    for arg in $@
322    do
323     case $arg in
324       -quick) quick=1;;
325       -verbose) verbose=2;;
326       -debug) debug=1;;
327       -clean) clean=1;;
328       -ieee) ieee=1;;
329       -longtest) longtest=1;;
330       -quiet) verbose=0;;
331       -help) show_help; exit 0;;
332       -*) echo Unrecognized option:$arg; exit 9;;
333       *) test -d $arg && expts=`echo $expts $arg`;;
334     esac
335    done
336    
337    #if [ ${#expts} -eq 0 ]; then
338    # echo Scanning all directories
339    # for arg in *
340    #  do
341    #   test -d $arg && expts=`echo $expts $arg`
342    # done
343    #fi
344    expts=`scandirs $expts`
345    
346    createcodelet
347    
348    if [ $longtest -gt 0 ]; then
349    cat << EOF > summary.txt
350                    T           S           U           V
351    C D M    c        m  s        m  s        m  s        m  s
352    n p a R  g  m  m  e  .  m  m  e  .  m  m  e  .  m  m  e  .
353    f n k u  2  i  a  a  d  i  a  a  d  i  a  a  d  i  a  a  d
354    g d e n  d  n  x  n  .  n  x  n  .  n  x  n  .  n  x  n  .
355    
356    EOF
357    else
358    cat << EOF > summary.txt
359                  T     S     U     V
360    C D M    c                        
361    n p a R  g  m  m  m  m  m  m  m  m
362    f n k u  2  i  a  i  a  i  a  i  a
363    g d e n  d  n  x  n  x  n  x  n  x
364    
365    EOF
366    fi
367    
368    # Now configue, make, run and test in each directory
369    for dir in $expts
370    do
371     if [ -r $dir/results/output.txt ]; then
372     echo -------------------------------------------------------------------------------
373     echo
374     echo Experiment: $dir
375     echo
376     unset genmake makedepend make run
377     if [ $longtest -gt 0 ]; then
378      results='-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --'
379     else
380      results='-- -- -- -- -- -- -- -- --'
381     fi
382     genmakemodel $dir/input && genmake=Y \
383     && makeclean $dir/input \
384     && makedependmodel $dir/input && makedepend=Y \
385     && makemodel $dir/input && make=Y \
386     && runmodel $dir/input mitgcmuv && run=Y \
387     && results=`testoutput $dir`
388     echo
389     formatresults $dir ${genmake:-N} ${makedepend:-N} ${make:-N} ${run:-N} $results
390     echo
391     formatresults $dir ${genmake:-N} ${makedepend:-N} ${make:-N} ${run:-N} $results >> summary.txt
392     fi
393    done
394    
395    rm tmp_cmpnum.f a.out
396    
397  echo "Summary:"  echo -------------------------------------------------------------------------------
398  echo ""  echo
399  cat summary.txt  cat summary.txt

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.13

  ViewVC Help
Powered by ViewVC 1.1.22