#!/usr/bin/perl
#
# generate a median sky flat from a large set of images 

$do_it = 1;
$filter = "v";

# remove pre-measured mean values
system("sed -e '/mn_/d' < ~/.sym > ~/.sym.tmp; mv ~/.sym.tmp ~/.sym");


# first, we generate the list of files to be combined
$cmd = "median ";
@frames = glob("flatv.???");
$nframes = @frames;
foreach $img (@frames) {
  $cmd = $cmd . " $img"; 
}

$outfile= sprintf("flat%s.fts", $filter);

# usually have iqm here
$cmd = $cmd . " outfile=$outfile verbose ";

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

$datestr = `date`;
$comment = "median of $nframes target frames, created $datestr";
if ($do_it == 1) {
  $result  = `comment $outfile $comment`;
}
printf "result of comment is ..$result..\n";


exit 0;
  
