#!/usr/bin/perl
# 
# subtract master darks from a set of raw images
#

# if set to 0, will not actually do work, just print commands
$do_it = 1;

#$dark="dark1.fts";
$dark="dark20.fts";
#$dark="dark30.fts";
#$dark="bias_master.fts";
#$dark="dark12.fts";
#$dark="dark40.fts";
#$dark="dark40_rot.fts";
#$dark="dark60.fts";
#$dark="foo_dark30.fts";
#$dark="dark120.fts";

#@files1 = glob("flatv*.fit");
@files1 = glob("v404*.fit");
#@files1 = glob("m15*fit");
foreach $file (@files1, @files2, @files3) {

  $index = substr($file, 12, 3);
  printf "index is %s \n", $index;

  

  $img = $file;
  $cmd = "sub $img $dark";
  printf "cmd is $cmd\n";
  if ($do_it == 1) {
    $result = `$cmd`;
  }
  printf "result of sub is ..$result..\n";

  $datestr = `date`;
  $comment = "subtracted dark $dark on $datestr";
  $cmd = "comment $img $comment";
  printf "cmd is $cmd\n";
  if ($do_it == 1) {
    $result  = `$cmd`;
  }
  printf "result of comment is ..$result..\n";

}


exit 0;
  
