#!/usr/bin/perl
#
# Generate a nice list of stars in a circular pattern
#   that we can use to illustrate incompleteness
#
# MWR 4/25/2011

use POSIX;

$debug = 1;

$DEGTORAD = (3.14159/180.0);
$nrow = 500;
$ncol = 500;
$center_row = $nrow/2.0;
$center_col = $ncol/2.0;

$sky = 1000.0;
$mag = 13.0;
$fwhm = 3.0;
$zero = 0.0;

$outfile = "./star_list.fts";
$starfile = "./star_list.dat";
open(STARFILE, ">$starfile") || die("can't open $starfile");

$num_star = 0;
for ($radius = 20; $radius < 240; $radius += 30) {
 
  $theta_deg = 0.0;
  while ($theta_deg < 360) {
     $theta_rad = $theta_deg * $DEGTORAD;

     $row = $center_row + $radius*cos($theta_rad);
     $col = $center_row + $radius*sin($theta_rad);

     printf STARFILE " %6d  %8.2f %8.2f  %6.3f  %5.2f %5.2f  %5.2f \n",
          $num_star, $row, $col, $mag, $fwhm, $zero, $zero;
     
     $theta_deg += 80/(0.1 + $radius**0.25);
     $num_star++;
  }

     $mag += 1.0;

}
close(STARFILE);

# now generate the image
$cmd = "pstar nrow=$nrow ncol=$ncol ";
$cmd .= " sky=$sky rms=0 ";
#$cmd .= " sky=$sky ";
$cmd .= " starlist=$starfile ";
$cmd .= " outfile=$outfile ";
$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);
}


