#!/usr/bin/perl

#this script takes the corners file, and a Parameters file, and 
#finds where the corners are in each other frame.  Each line
#in the output "Corners.txt" file,  corresponds to the corners
#in the coordinate system of the frame corresponding to the
#same line in the Parameters_pairwise.txt file
#e.g.: the first line of the Parameters_pairwise.txt file
#      has the parameters for the first frame, and thus
#      the first line of the Corners.txt file has the 
#      position of the corners relative to this first frame

$cornersfile = sprintf("corners.txt");
$paramsfile  = sprintf("Parameters_pairwise.txt");

`rm Corners.txt`;

#count the lines in the paramsfile to see how many images we
#will need to generate coords for
$numimages = `cat $paramsfile | wc -l`;
$corners = `cat $cornersfile`;

for ($counter=1; $counter<=$numimages; $counter++) 
{
  # e.g. to get 4th entry: head -4 Parameters_pairwise.txt | tail -1
  my $pchirp_parameters= `head -$counter $paramsfile | tail -1`;
  chomp($pchirp_parameters);
  chomp($corners);
  `p_of_points $pchirp_parameters $corners >> Corners.txt`;
}
