#!/usr/bin/perl
#
# Create 1-D-ish images from the "sbf" output files
#
# MWR 4/27/2011

$debug = 1;

  $nrow = 10;
  $scale = 10000;

for ($dist = 1; $dist <= 10000; $dist *= 10) {

  $file = sprintf "sbf_10_$dist.out";
  $outfile = sprintf "makeim.$dist.dat";

  $cmd = " cp /dev/null $outfile ";
  $ret = exec_cmd($cmd);
  for ($i = 0; $i < $nrow; $i++) {
    $cmd =   "grep -v avg $file | head -100 | awk '{ print \$2/$dist }' ";
    $cmd .=  "  >> $outfile ";
    $ret = exec_cmd($cmd);
  }

  $cmd =  "makeim $outfile nrow=$nrow ncol=100 scale=$scale ";
  $cmd .= "  outfile=makeim.$dist.fts ";
  $ret = exec_cmd($cmd);

}



exit 0;




##############################################################################
# PROCEDURE: exec_cmd
#
# DESCRIPTION: Execute the given shell command line.  If the $debug flag
#              is set, we print to stdout the command line, and
#              also print out the result string.
#
# RETURNS:
#              the result of the command
#
#
sub exec_cmd {

  my($cmd, $ret);

  $cmd = $_[0];

  if ($debug > 0) {
    printf "cmd is ..$cmd.. \n";
  }
  $ret = `$cmd`;
  if ($debug > 0) {
    printf "ret is ..$ret.. \n";
  }

  return($ret);
}


