#!/usr/bin/perl

# This script should generate an offset list for ircombine given a file of
# centroids from imexam.  The name of that centoid file and the magnification
# factor desired can appear as the first and second arguments, respectively,
# or they will be prompted for if absent.   10/24/95  (CWE)
#
# e.g.  offlist.pl imexam.log 4

# check to see if arguments are there
if ($ARGV[0]) {
   $file = $ARGV[0];
   }
else {
   print "Please enter name of centroid file: ";
   chop ($file = <STDIN>);
   }
if ($ARGV[1]) {
   $mag = $ARGV[1];
   }
else {
   print "Please enter magnification factor (1-9): ";
   chop ($mag = <STDIN>);
   }

# open centroid file and output file
open (INPUT, $file) || die "Cannot find $file";
open (OUTPUT, "> offlist") || die "Cannot open offlist";

# read data in file and output offlist
while (<INPUT>) {
   next if /^#/;		# ignore lines that start with '#'
   next if /^$/;		# ignore blank lines
   @line = split (' ');
   $x = @line[0];
   $y = @line[1];
   if (!($x0 && $y0)) {
      $x0 = $x;
      $y0 = $y;
      print OUTPUT "0 0\n";
      }
   else {
      $x = (int(($x0 - $x) * $mag));
      $y = (int(($y0 - $y) * $mag));
      print OUTPUT "$x $y\n";
      }
   }

# close files
close (OUTPUT);
close (INPUT);
