/[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.8 by adcroft, Fri Aug 3 20:18:40 2001 UTC revision 1.22 by adcroft, Thu Nov 7 21:53:34 2002 UTC
# Line 1  Line 1 
1  #!/bin/sh  #!/bin/sh
2    
 similar()  
 {  
 # similar digits a b  
 #  
 #  compare the floating point number a and b and successively reduced  
 #  truncation until a match is found  
  for digits in 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0  
  do  
    a=`printf '%22.'$digits'e\n' $1`  
    b=`printf '%22.'$digits'e\n' $2`  
    if [ $a = $b ]; then  
     if [ $verbose -gt 1 ]; then  
      echo $1 $2 $a 1>&2  
     fi  
     break  
    fi  
  done  
  return $digits  
 }  
   
3  compare_lines()  compare_lines()
4  {  {
 # compare_lines digits < file  
 #  
 #  read each line of file and test the 2nd and 3rd column values for  
 #  similarity based on the function similar()  
  worst_so_far=$1  
  while read linenum a b  
  do  
   if [ $debug -gt 0 ]; then  
    echo compare_lines: similar a=$a b=$b 1>&2  
   fi  
   similar $a $b  
   digits=$?  
   if [ $digits -lt $worst_so_far ]; then  
    worst_so_far=$digits  
   fi  
  done  
   if [ $debug -gt 0 ]; then  
    echo compare_lines: worst_so_far=$worst_so_far 1>&2  
   fi  
  return $worst_so_far  
 }  
   
 compare_lines2()  
 {  
5  # use codelet to compare lines  # use codelet to compare lines
6     if [ $verbose -gt 1 ]; then
7      cat tmp3.txt 1>&2
8     fi
9   return `./a.out < tmp3.txt`   return `./a.out < tmp3.txt`
10  }  }
11    
# Line 62  testoutput_for_prop() Line 21  testoutput_for_prop()
21   fi   fi
22   if [ -r $1/input/output.txt ]; then   if [ -r $1/input/output.txt ]; then
23    grep "$2" $1/input/output.txt | sed 's/.*=//' | nl > tmp1.txt    grep "$2" $1/input/output.txt | sed 's/.*=//' | nl > tmp1.txt
24      lncnt=`wc -l tmp1.txt | awk '{print $1}' `
25      if [ $lncnt -lt 3 ]; then
26       if [ $verbose -gt 0 ]; then
27        echo Not enough lines of output when searching for "$2" 1>&2
28       fi
29       return 99
30      fi
31   else   else
32    echo testoutput_for_prop: output.txt from model run was not readable 1>&2    echo testoutput_for_prop: output.txt from model run was not readable 1>&2
33    return 99    return 99
# Line 70  testoutput_for_prop() Line 36  testoutput_for_prop()
36    echo testoutput_for_prop: grep "$2" $1/results/output.txt 1>&2    echo testoutput_for_prop: grep "$2" $1/results/output.txt 1>&2
37   fi   fi
38   grep "$2" $1/results/output.txt | sed 's/.*=//' | nl > tmp2.txt   grep "$2" $1/results/output.txt | sed 's/.*=//' | nl > tmp2.txt
39      lncnt=`wc -l tmp2.txt | awk '{print $1}' `
40      if [ $lncnt -lt 3 ]; then
41       if [ $verbose -gt 0 ]; then
42        echo Not enough lines of output when searching for "$2" 1>&2
43       fi
44       return 99
45      fi
46   if [ $debug -gt 0 ]; then   if [ $debug -gt 0 ]; then
47    echo testoutput_for_prop: join tmp1.txt tmp2.txt 1>&2    echo testoutput_for_prop: join tmp1.txt tmp2.txt 1>&2
48   fi   fi
# Line 77  testoutput_for_prop() Line 50  testoutput_for_prop()
50   if [ $debug -gt 0 ]; then   if [ $debug -gt 0 ]; then
51    echo testoutput_for_prop: compare_lines 1>&2    echo testoutput_for_prop: compare_lines 1>&2
52   fi   fi
53   #compare_lines 99 < tmp3.txt   compare_lines
  compare_lines2  
54   digits_of_similarity=$?   digits_of_similarity=$?
55   if [ $digits_of_similarity -eq 99 ]; then   if [ $digits_of_similarity -eq 99 ]; then
56    if [ $verbose -gt 0 ]; then    if [ $verbose -gt 0 ]; then
# Line 124  if [ $debug -gt 0 ]; then Line 96  if [ $debug -gt 0 ]; then
96   echo testoutput: cg2dres=$cg2dres 1>&2   echo testoutput: cg2dres=$cg2dres 1>&2
97  fi  fi
98    
99  if [ $testmore -gt 0 ]; then  if [ $longtest -gt 0 ]; then
100  testoutput_for_prop $1 "dynstat_theta_min" "theta minimum"; tmin=$?  testoutput_for_prop $1 "dynstat_theta_min" "theta minimum"; tmin=$?
101  testoutput_for_prop $1 "dynstat_theta_max" "theta maximum"; tmax=$?  testoutput_for_prop $1 "dynstat_theta_max" "theta maximum"; tmax=$?
102  testoutput_for_prop $1 "dynstat_theta_mean" "theta mean"; tmean=$?  testoutput_for_prop $1 "dynstat_theta_mean" "theta mean"; tmean=$?
# Line 164  genmakemodel() Line 136  genmakemodel()
136   ( cd $1;   ( cd $1;
137     if [ $quick -eq 0 -o ! -r Makefile ]; then     if [ $quick -eq 0 -o ! -r Makefile ]; then
138      printf 'genmake ... ' 1>&2      printf 'genmake ... ' 1>&2
139      ../../../tools/genmake -mods=../code > make.log 2>&1      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      if [ $? -ne 0 ]; then
145       tail make.log       tail make.log
146       echo makemodel: genmake failed 1>&2       echo genmakemodel: genmake failed 1>&2
147       return 1       return 1
148      else      else
149        echo succesful 1>&2        echo succesful 1>&2
# Line 176  genmakemodel() Line 152  genmakemodel()
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()  makedependmodel()
194  {  {
195  # makedependmodel directory  # makedependmodel directory
# Line 221  runmodel() Line 235  runmodel()
235    
236   ( cd $1   ( cd $1
237     if [ -x $2 ]; then     if [ -x $2 ]; then
238      if [ ! -r output.txt -o $quick -eq 0 ]; then      if [ $quick -eq 0 ]; then
239       echo runmodel: running... 1>&2       rm -f output.txt
      ( ./$2 > output.txt 2>&1 ) && return 0  
      return 1  
     else  
      echo runmodel: output.txt is newer than executable 1>&2  
      return 0  
240      fi      fi
241     else      printf 'runmodel: ' 1>&2
242      echo runmodel: executable \"$1/$2\" is missing 1>&2      make output.txt && return 0
243      return 1  #   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     fi
258   )   )
259  }  }
# Line 247  cat > tmp_cmpnum.f <<EOFA Line 269  cat > tmp_cmpnum.f <<EOFA
269        best=-16        best=-16
270    99  read(*,*,end=70,err=60) linnum,a,b    99  read(*,*,end=70,err=60) linnum,a,b
271        diff=0.5*(abs(a)+abs(b))        diff=0.5*(abs(a)+abs(b))
272        if (diff.gt.0.) then  c     print *,a,b,diff,abs(a-b)/diff
273          if (diff.gt.1.e-12) then
274          diff=abs(a-b)/diff          diff=abs(a-b)/diff
275          if (diff.gt.0.) then          if (diff.gt.0.) then
276  c         print *,int(log10(diff)),diff  c         print *,int(log10(diff)),diff
277            linnum=int(log10(diff))            linnum=int(log10(diff))
278            best=max(best,linnum)            best=max(best,linnum)
 c       else  
 c         print *,-16  
279          endif          endif
280  c     else        else
281  c       diff=0.          if (best.eq.-16.and.diff.ne.0.) best=-22
 c       print *,-16  
282        endif        endif
283        goto 99        goto 99
284    60  stop 'cmpnum: An error occured reading a,b'    60  stop 'cmpnum: An error occured reading a,b'
# Line 305  $0 [-help] [-quick] [-verbose] dir1 [dir Line 325  $0 [-help] [-quick] [-verbose] dir1 [dir
325   -quick     Skip "genmake" and "make depend" if the Makefile exists   -quick     Skip "genmake" and "make depend" if the Makefile exists
326   -quiet     Reduce the amount of output   -quiet     Reduce the amount of output
327   -verbose   Produce copious amounts of output   -verbose   Produce copious amounts of output
328     -debug     Produce even more output which will mean nothing to most
329     -force     Do "make CLEAN" before compiling. This forces a complete rebuild.
330     -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:  Normal usage:
337   $0 *       Configure, compile, run and analyze in all experiment directories   $0 *       Configure, compile, run and analyze in all experiment directories
338  EOF  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  # Main function
# Line 319  EOF Line 369  EOF
369  debug=0  debug=0
370  verbose=1  verbose=1
371  quick=0  quick=0
372  testmore=0  force=0
373    clean=0
374    ieee=1
375    longtest=1
376  expts=''  expts=''
377    
378  # Process arguments  # Process arguments
379  for arg in $@  for arg in $@
380  do  do
381   case $arg in   case $arg in
382       -cleanup) clean_up; exit 0;;
383     -quick) quick=1;;     -quick) quick=1;;
384     -verbose) verbose=2;;     -verbose) verbose=2;;
385     -debug) debug=1;;     -debug) debug=1;;
386     -testmore) testmore=1;;     -force) force=1;;
387       -clean) clean=1;;
388       -noieee) ieee=0;;
389       -shorttest) longtest=0;;
390     -quiet) verbose=0;;     -quiet) verbose=0;;
391     -help) show_help; exit 0;;     -help) show_help; exit 0;;
392       -*) echo Unrecognized option:$arg; exit 9;;
393     *) test -d $arg && expts=`echo $expts $arg`;;     *) test -d $arg && expts=`echo $expts $arg`;;
394   esac   esac
395  done  done
396    
397  if [ ${#expts} -eq 0 ]; then  if [ $force -gt 0 -a $quick -gt 0 ]; then
398   echo Scanning all directories   echo You specified -quick and -force together which conflict.
399   for arg in *   echo Please specify either -quick or -force or neither but not both.
400    do   exit 1
    test -d $arg && expts=`echo $expts $arg`  
  done  
401  fi  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  createcodelet
413    
414  if [ $testmore -eq 0 ]; then  if [ $longtest -gt 0 ]; then
415  cat << EOF > summary.txt  cat << EOF > summary.txt
416                  T           S           U           V                  T           S           U           V
417  C D M    c        m  s        m  s        m  s        m  s  C D M    c        m  s        m  s        m  s        m  s
# Line 375  do Line 440  do
440   echo Experiment: $dir   echo Experiment: $dir
441   echo   echo
442   unset genmake makedepend make run   unset genmake makedepend make run
443   results='-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --'   if [ $longtest -gt 0 ]; then
444   results='-- -- -- -- -- -- -- -- --'    results='-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --'
445     else
446      results='-- -- -- -- -- -- -- -- --'
447     fi
448   genmakemodel $dir/input && genmake=Y \   genmakemodel $dir/input && genmake=Y \
449     && makecleancompile $dir/input \
450   && makedependmodel $dir/input && makedepend=Y \   && makedependmodel $dir/input && makedepend=Y \
451   && makemodel $dir/input && make=Y \   && makemodel $dir/input && make=Y \
452   && runmodel $dir/input mitgcmuv && run=Y \   && runmodel $dir/input mitgcmuv && run=Y \
453   && results=`testoutput $dir`   && results=`testoutput $dir` \
454     && makecleanupafter $dir/input
455   echo   echo
456   formatresults $dir ${genmake:-N} ${makedepend:-N} ${make:-N} ${run:-N} $results   formatresults $dir ${genmake:-N} ${makedepend:-N} ${make:-N} ${run:-N} $results
457   echo   echo

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

  ViewVC Help
Powered by ViewVC 1.1.22