#!/usr/bin/perl
#
#

$debug = 1;

$center_ra = 202.4676;
$center_dec = 47.1932;

# project (RA, Dec) coordinates from catalog onto plane 
$cmd =  "~/tass/match/project_coords m51_nice.dat ";
$cmd .= "  9 10 202.4676 47.1932 ";
$cmd .= "  outfile=m51_proj.dat ";

$ret = exec_cmd($cmd);

# run the "match" program to find transformation from
#       pixels (X, Y) onto coordinate plane
$cmd =  "~/tass/match/match ";
$cmd .=  " m51.pht 1 2 5 ";
$cmd .=  " m51_proj.dat 9 10 11 ";
$cmd .=  " id1=0 id2=0 ";
$cmd .=  " matchrad=0.000024 ";
$cmd .=  " nobj=30 ";
$cmd .=  " linear ";
$cmd .=  " trirad=0.001 ";
$cmd .=  " recalc ";
$ret = exec_cmd($cmd);

# grab a, b, c, d, e, f from the resulting TRANS
@words = split(/\s+/, $ret);
$a = $words[1];
$a =~ s/a=//;
$b = $words[2];
$b =~ s/b=//;
$c = $words[3];
$c =~ s/c=//;
$d = $words[4];
$d =~ s/d=//;
$e = $words[5];
$e =~ s/e=//;
$f = $words[6];
$f =~ s/f=//;

# and run the "apply_match" program
$cmd  = "~/tass/match/apply_match ";
$cmd .= "m51.pht 1 2 $center_ra $center_dec ";
$cmd .= " linear ";
$cmd .= " $a $b $c $d $e $f ";
$cmd .= " outfile=m51.radec ";
$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);
}


