#!/usr/bin/perl
#
#
# Insert copies of an artificial star into an image
#     Do several times, modifying the star so that it appears
#     to be at larger and larger distances
#
# MWR 3/10/2011

$debug = 1;

# this is the original star 
$orig = "orig_star.fts";
$cmd = "pstar sky=0 photon nrow=30 ncol=30 star=3000,15,15,3.0 outfile=$orig";
$ret = exec_cmd($cmd);


# this is the background field
$field = "pstar.fts";

# insert the star's little image into the field at this location
$ins_row = 290;
$ins_col = 315;


# Insert the star with its original appearance
$new = "star1.fts";
$cmd = "cp $field $new";
$ret = exec_cmd($cmd);
$cmd = "implant $new $orig,$ins_row,$ins_col overlay ";
$ret = exec_cmd($cmd);

# Insert a copy of the star as if it were 2 times farther away
$temp = "temp.fts";
$cmd = "cp $orig $temp";
$ret = exec_cmd($cmd);
$cmd = "div $temp const=4 ";
$ret = exec_cmd($cmd);
$new = "star2.fts";
$cmd = "cp $field $new";
$ret = exec_cmd($cmd);
$cmd = "implant $new $temp,$ins_row,$ins_col overlay ";
$ret = exec_cmd($cmd);

# Insert a copy of the star as if it were 4 times farther away
$temp = "temp.fts";
$cmd = "cp $orig $temp";
$ret = exec_cmd($cmd);
$cmd = "div $temp const=16 ";
$ret = exec_cmd($cmd);
$new = "star3.fts";
$cmd = "cp $field $new";
$ret = exec_cmd($cmd);
$cmd = "implant $new $temp,$ins_row,$ins_col overlay ";
$ret = exec_cmd($cmd);

# Insert a copy of the star as if it were 8 times farther away
$temp = "temp.fts";
$cmd = "cp $orig $temp";
$ret = exec_cmd($cmd);
$cmd = "div $temp const=64 ";
$ret = exec_cmd($cmd);
$new = "star4.fts";
$cmd = "cp $field $new";
$ret = exec_cmd($cmd);
$cmd = "implant $new $temp,$ins_row,$ins_col overlay ";
$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);
}


