#!/usr/bin/perl
#
# pick out the photometry (in flux units) for one star at a time
#    from all the .pht files
#
# MWR 11/3/2017

use POSIX;

$debug = 1;

$match_rad = 5.0;
$star_row = 227.0;
$star_col = 202.0;

@phtfiles = glob("v404*pht");
$pht_count = 0;
foreach $phtfile (@phtfiles) {

  open(PHTFILE, "$phtfile") || die("can't open file $phtfile");
  while (<PHTFILE>) {
    $line = $_;
    @words = split(/\s+/, $line);
    $row = $words[2];
    $col = $words[3];
    $flux = $words[6];
    $fluxerr = $words[7];

    $mag = 25.0 - 2.5*log10($flux);

    $drow = $row - $star_row;
    $dcol = $col - $star_col;
    $dist = sqrt($drow*$drow + $dcol*$dcol);
    if ($dist < $match_rad) {
      printf "  %5d  %9.2f %9.2f   %10.2f %8.2f   %6.1f   \n", 
          $pht_count, $row, $col, $flux, $fluxerr, $dist;
    }
  }
  close(PHTFILE);

  $pht_count++;



}


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);
}


