Index: trunk/PS-IPP-PStamp/lib/PS/IPP/PStamp/Job.pm
===================================================================
--- trunk/PS-IPP-PStamp/lib/PS/IPP/PStamp/Job.pm	(revision 27140)
+++ trunk/PS-IPP-PStamp/lib/PS/IPP/PStamp/Job.pm	(revision 27211)
@@ -38,5 +38,5 @@
     my $tess_id  = shift;
     my $component= shift;   # class_id or skycell_id
-    my $inverse  = shift;
+    my $option_mask  = shift;
     my $need_magic = shift;
     my $x        = shift;
@@ -48,5 +48,4 @@
     my $verbose  = shift;
 
-
     # we die in response to bad data in request files
     # The wrapper script is responsible for updating the database
@@ -58,4 +57,5 @@
            ($req_type ne "byskycell");
 
+
     my $dateobs_begin;
     my $dateobs_end;
@@ -77,5 +77,5 @@
 
     if ($req_type eq "bycoord") {
-        my $results = lookup_bycoord($ipprc, $image_db, $img_type, $tess_id, $component, $need_magic, $x, $y, $dateobs_begin, $dateobs_end, $filter, $data_group, $verbose);
+        my $results = lookup_bycoord($ipprc, $image_db, $img_type, $tess_id, $component, $need_magic, $x, $y, $dateobs_begin, $dateobs_end, $filter, $data_group, $option_mask, $verbose);
         return $results;
     }
@@ -86,10 +86,10 @@
         # in one place
         $req_type = "bydiff";
-        my $results = lookup_diff($ipprc, $image_db, $id, $component, 1, $inverse, $img_type, $verbose);
+        my $results = lookup_diff($ipprc, $image_db, $id, $component, 1, $option_mask, $img_type, $verbose);
         return $results;
     }
 
     if ($req_type eq "bydiff") {
-        my $results = lookup_diff($ipprc, $image_db, $id, $component, 0, $inverse, $img_type, $verbose);
+        my $results = lookup_diff($ipprc, $image_db, $id, $component, 0, $option_mask, $img_type, $verbose);
         if (!$results) {
             return undef;
@@ -139,5 +139,5 @@
 
     my $results = lookup($ipprc, $image_db, $req_type, $img_type, $id, $tess_id, $component, $need_magic,
-        $dateobs_begin, $dateobs_end, $filter, $data_group, $verbose);
+        $dateobs_begin, $dateobs_end, $filter, $data_group, $option_mask, $verbose);
 
     return $results;
@@ -158,5 +158,9 @@
     my $filter = shift;
     my $data_group = shift;
+    my $option_mask = shift;
     my $verbose  = shift;
+
+    my $inverse = $option_mask & $PSTAMP_SELECT_INVERSE;
+    my $unconvolved = $option_mask & $PSTAMP_SELECT_UNCONV;
 
     my $missing_tools;
@@ -244,7 +248,13 @@
         $component_args = " -skycell_id $skycell_id" if $skycell_id;
 
-        $image_name  = "PPSTACK.OUTPUT";
-        $mask_name   = "PPSTACK.OUTPUT.MASK";
-        $weight_name = "PPSTACK.OUTPUT.VARIANCE";
+        if (!$unconvolved) {
+            $image_name  = "PPSTACK.OUTPUT";
+            $mask_name   = "PPSTACK.OUTPUT.MASK";
+            $weight_name = "PPSTACK.OUTPUT.VARIANCE";
+        } else {
+            $image_name  = "PPSTACK.UNCONV";
+            $mask_name   = "PPSTACK.UNCONV.MASK";
+            $weight_name = "PPSTACK.UNCONV.VARIANCE";
+        }
         # this is wrong but gets the right answer. Need to figure out how to find the
         # rule properly
@@ -351,4 +361,10 @@
         } elsif ($img_type eq "diff") {
             $stage_id = $image->{diff_id};
+            if ($inverse && $image->{bothways}) {
+                $image_name  = "PPSUB.INVERSE";
+                $mask_name   = "PPSUB.INVERSE.MASK";
+                $weight_name = "PPSUB.INVERSE.VARIANCE";
+                $cmf_name    = "PPSUB.INVERSE.SOURCES";
+            }
         } elsif ($img_type eq "stack") {
             $stage_id = $image->{stack_id};
@@ -379,7 +395,9 @@
     my $skycell_id = shift;
     my $byid     = shift;
-    my $inverse  = shift;
+    my $option_mask  = shift;
     my $img_type = shift;
     my $verbose = shift;
+
+    my $inverse = $option_mask & $PSTAMP_SELECT_INVERSE;
 
     my $missing_tools;
@@ -503,4 +521,10 @@
                 $image->{mask}   = $ipprc->filename($filerule_base . ".MASK", $image->{path_base});
                 $image->{weight} = $ipprc->filename($filerule_base . ".VARIANCE", $image->{path_base});
+                $image->{cmf}    = $ipprc->filename($filerule_base . ".SOURCES", $image->{path_base});
+                $image->{psf}    = $ipprc->filename("PSPHOT.PSF.SKY.SAVE", $image->{path_base});
+                $image->{stage_id} = $image->{diff_id};
+                $image->{stage}    = "diff";
+                $image->{image_db} = $image_db;
+                $image->{component} = $image->{skycell_id};
             } else {
                 # XXX this will only happen if the minuend is not a warp. See hack above
@@ -527,4 +551,5 @@
     my $filter     = shift;
     my $data_group = shift;
+    my $option_mask = shift;
     my $verbose    = shift;
 
@@ -549,5 +574,5 @@
             my $these_results = lookup($ipprc, $image_db, "byid", $img_type, $run->{id},
                 $tess_id, $run->{component}, $need_magic, 
-                $dateobs_begin, $dateobs_end, $filter, $data_group, $verbose);
+                $dateobs_begin, $dateobs_end, $filter, $data_group, $option_mask, $verbose);
 
             next if !$these_results;
@@ -565,5 +590,5 @@
             my $these_results = lookup($ipprc, $image_db, "byskycell", $img_type, undef,
                 $skycell->{tess_id}, $skycell->{component}, $need_magic, 
-                $dateobs_begin, $dateobs_end, $filter, $data_group, $verbose);
+                $dateobs_begin, $dateobs_end, $filter, $data_group, $option_mask, $verbose);
 
             next if !$these_results;
Index: trunk/PS-IPP-PStamp/lib/PS/IPP/PStamp/RequestFile.pm
===================================================================
--- trunk/PS-IPP-PStamp/lib/PS/IPP/PStamp/RequestFile.pm	(revision 27140)
+++ trunk/PS-IPP-PStamp/lib/PS/IPP/PStamp/RequestFile.pm	(revision 27211)
@@ -21,4 +21,5 @@
                     $PSTAMP_SELECT_IMAGE
                     $PSTAMP_SELECT_MASK
+                    $PSTAMP_SELECT_VARIANCE
                     $PSTAMP_SELECT_WEIGHT
                     $PSTAMP_SELECT_CMF
@@ -26,4 +27,5 @@
                     $PSTAMP_SELECT_BACKMDL
                     $PSTAMP_SELECT_INVERSE
+                    $PSTAMP_SELECT_UNCONV
                     $PSTAMP_WAIT_FOR_UPDATE
                     $PSTAMP_SUCCESS
@@ -50,4 +52,5 @@
 our $PSTAMP_SELECT_IMAGE     = 1;
 our $PSTAMP_SELECT_MASK      = 2;
+our $PSTAMP_SELECT_VARIANCE  = 4;
 our $PSTAMP_SELECT_WEIGHT    = 4;
 our $PSTAMP_SELECT_CMF       = 8;
@@ -55,6 +58,7 @@
 our $PSTAMP_SELECT_BACKMDL   = 32;
 our $PSTAMP_SELECT_INVERSE   = 1024;
+our $PSTAMP_SELECT_UNCONV    = 2048;
 
-our $PSTAMP_WAIT_FOR_UPDATE  = 2048;
+our $PSTAMP_WAIT_FOR_UPDATE  = 32768;
 
 # job and result codes
