Index: trunk/pstamp/scripts/pstamp_finish.pl
===================================================================
--- trunk/pstamp/scripts/pstamp_finish.pl	(revision 18982)
+++ trunk/pstamp/scripts/pstamp_finish.pl	(revision 18983)
@@ -18,18 +18,8 @@
 use PS::IPP::Metadata::List qw( parse_md_list );
 
-use PS::IPP::Config qw($PS_EXIT_SUCCESS
-		       $PS_EXIT_UNKNOWN_ERROR
-		       $PS_EXIT_SYS_ERROR
-		       $PS_EXIT_CONFIG_ERROR
-		       $PS_EXIT_PROG_ERROR
-		       $PS_EXIT_DATA_ERROR
-		       $PS_EXIT_TIMEOUT_ERROR
-		       metadataLookupStr
-		       metadataLookupBool
-		       caturi
-		       );
-
-
-my ( $req_id, $req_name, $product, $dbname, $verbose, $save_temps );
+use PS::IPP::Config qw( :standard );
+use PStamp::RequestFile qw( :standard );
+
+my ( $req_id, $req_name, $req_file, $product, $dbname, $verbose, $save_temps );
 
 # the char to the right of the bar may be used as a single - alias for the longer name
@@ -38,4 +28,5 @@
            'req_id=s'   => \$req_id,
            'req_name=s' => \$req_name,
+           'req_file=s' => \$req_file,
            'product=s'  => \$product,
 	   'dbname=s'   => \$dbname,
@@ -45,4 +36,7 @@
 
 pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV;
+
+die "usage: --req_id id --req_name name --req_file file --product product [--dbname dbname --verbose]\n"
+    if !$req_id or !$req_name or !$req_file or !$product;
 
 my $missing_tools;
@@ -88,4 +82,9 @@
     }
 
+
+                        # this function is PStamp::RequestFile::read_request_file
+    my ($header, $rows) = read_request_file($req_file);
+
+    die "failed to read request_file $req_file" if !$header or !$rows;
 
     # at this point we need to find out what kind of request type it is and
@@ -145,4 +144,6 @@
         my $rownum = $job->{rownum};
         my $fault = $job->{fault};
+
+        my $row_info = get_request_info($rows, $rownum);
         # rownum fault img_name job_id
         if (($job_type eq "stamp") || ($job_type eq "get_image")) {
@@ -157,8 +158,19 @@
                     my ($img_name, undef) = split '\|', $line;
 
+                    # XXX TODO: need to get these from somewhere. Maybe the stamp.
+                    #
+                    # ra_deg and dec_deg are the coordinates of center of the stamp
+                    # the rest of the metadata come from the original FPA.
+                    # we could get these out of the rawExp table in the database....
+                    #
+                    # Much of those data do not apply to stamps from Stack images.
+                    my ($ra_deg, $dec_deg, $mjd_obs, $ra_obs, $dec_obs, $filter, $exp_time, $fpa_id) =
+                        (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 );
+
                     # add line to the table definition file
                     print $tdf "$rownum|$fault|$img_name|$job_id|";
-                    # XXX TODO: need to lookup the rest of this stuff
-                    print $tdf "0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|\n";
+                    print $tdf "$ra_deg|$dec_deg|$mjd_obs|$ra_obs|$dec_obs|$filter|$exp_time|$fpa_id|";
+                    print $tdf "$row_info";
+                    print $tdf "\n";
                 }
                 close JRL;
@@ -166,7 +178,8 @@
                 print STDERR "no reglist file for job $job_id\n" if $verbose;
                 print $tdf "$rownum|$fault|0|$job_id|";
-                print $tdf "0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|\n";
+                print $tdf "0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|\n";
             }
         } else {
+            # XXX do list jobs
             print STDERR "Unknown jobType: $job_type";
             next;
@@ -227,2 +240,18 @@
     }
 }
+
+sub get_request_info {
+    my $rows = shift;
+    my $rownum = shift;
+
+    my $row = $rows->{$rownum};
+
+    # This is ugly, error prone and hard to change.
+    # Create a results file module and provide a list of the names (we have the data in the columns)
+    my $rowinfo = "$row->{PROJECT}|$row->{JOB_TYPE}|$row->{REQ_TYPE}|$row->{IMG_TYPE}|";
+    $rowinfo   .= "$row->{ID}|$row->{CLASS_ID}|$row->{OPTION_MASK}|$row->{MJD_MIN}|$row->{MJD_MAX}|";
+    $rowinfo   .= "$row->{REQFILT}|$row->{COORD_MASK}|$row->{CENTER_X}|$row->{CENTER_Y}|";
+    $rowinfo   .= "$row->{WIDTH}|$row->{HEIGHT}|";
+
+    return $rowinfo;
+}
