#!/usr/bin/perl
#
# find and measure stars in each frame, generating .coo and .pht files

# set to 1 to see pictures, one frame at a time
$interactive = 0;

# first, we generate the list of files to be reduced
#@files1 = glob("v603g-02[0-3].fit");
@files1 = glob("01??.fits");
#@files1 = glob("rxc-00[456].fit");
#@files2 = glob("be87_?.???");
#@files2 = glob("be87_?.???");
$nframes = 0;
foreach $file (@files1) {
  $frame_array[$nframes] = $file;
  $nframes++;
}

`box 1 cr=104 cc=168 nr=20 nc=20`;

# now process each frame in turn
foreach $file (@frame_array) {
  $base = $file;
  $base =~ s/\./_/;
  printf "now working on $file = $base\n";

  `sky $file`;
  if ($interactive == 1) {
    system("tv $file zoom=2 z=sky-30 l=100; sleep 2");
    $ret = `stars $file box=1 minsig=5 minfwhm=3.0 maxfwhm=9.0 minsharp=0.1 maxsharp=1.5 minround=-1.5 maxround=1.5 movemax=4 show verbose`;
    printf "ret is ..$ret.. \n";
  } else {
    `stars $file box=1 minsig=5 minfwhm=3.0 maxfwhm=9.0 minsharp=0.1 maxsharp=1.5 minround=-1.5 maxround=1.5 movemax=4 outfile=$base.coo`;
  }
  `phot $file infile=$base.coo outfile=$base.pht aper=6 aper=8`;
  if ($interactive == 1) {
    printf "\nhit return to continue: \n";
    $a = <STDIN>;
    `killall -1 tv`;
  }
  
}


exit 0;
  
