#!/usr/bin/perl
#
# Run "div2" on all .fit images
#
# MWR 6/21/2014

$debug = 1;

$div2_exe = "~/junk/xvista-0.1.10/div2";
$tempfile = "./dodiv.tmp";

@files = glob("asas14cv*.fit");
#@files = glob("dqher*.fit");
#@files = glob("ugc*.fit");
#@files = glob("*.fit");
foreach $file (@files) {
  if ($debug > 0) {
    printf "next is file $file \n";
  }
  
  $cmd = "$div2_exe $file outfile=$tempfile ";
  $ret = exec_cmd($cmd);
  $cmd = "mv $tempfile $file";
  $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);
}


