#!/usr/bin/perl
#
#
#  find stars in a small subset of the SXDS field
#
# MWR 4/26/2011

$debug = 1;

$do_stars = 0;
$do_phot = 1;

$fwhm = 4.5;
$sky = -5;
$skysig = 6;

$image = "./sxdsr_16.fts";

#$cmd = "sky $image bin=5 min=-100 max=100 ";
#$ret = exec_cmd($cmd);

# find stars in the original image
if ($do_stars == 1) {
  $cmd =  "stars $image ";
  $cmd .= " sky=$sky skysig=$skysig minsig=10 ";
  $cmd .= " outfile=sxdsr_16.coo ";
  #$cmd .= " show ";
  $ret = exec_cmd($cmd);
}

# now measure stars
if ($do_phot == 1) {
  $cmd =  "phot $image ";
  $cmd .= " infile=sxdsr_16.coo outfile=sxdsr_16.pht ";
  $cmd .= " skyinner=10 skyouter=20 ";
  $cmd .= " aper=5 ";
  $cmd .= " saturate=22000 ";
  $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);
}


