#! /usr/bin/perl -w
# summarF <how_many> <results>
#   go through direcories starting with the current and then adding
#   "2" successively up to how_many (default 1), analyze and
#   print the results of the run from several sources
#  
$N = 0;
if (defined($ARGV[0])) {
  $N = $ARGV[0]; 
}
if ($N > 12 || $N <= 0) {die "bad number";}
if (defined($ARGV[1])) {
  $res = $ARGV[1];
}
else {
  $res = "results";
}
chop($dir = `pwd`);
for ($i=1; $i <= $N; $i++) {
  system ("avesubF $res");
  system ("scanres $res");
  system ("rm -f results0");
  system ("XcompF > results0");
  system ("scanres results0");
#if (0) { #omit component approx code
  open(SP, "system.pscf") || die "can't open system.pscf file";
  $k = <SP>;  #discard Polish line
  $avev = 0;
  $aver = 0;
  $k = 0;
  while ($f = <SP>) {
    chop($f);
    system ("rm -f results1");
    system ("XcuteF $f | grep Weighted > results1");
    $foo = `scanres results1`;
    @bar = split(" ",$foo);
#print "$f: $bar[2]\n";
    $avev += $bar[2];
    $aver += $bar[6];
    $k++
  }
  close(SP);
  $avev /= $k; 
  $aver /= $k; 
  printf "fun: %3.2f  run: %3.2f\n",$avev,$aver;
#} #end omitted code
  $dir = $dir."2";
  chdir $dir;
}
