Index: trunk/ippScripts/scripts/diff_skycell.pl
===================================================================
--- trunk/ippScripts/scripts/diff_skycell.pl	(revision 23688)
+++ trunk/ippScripts/scripts/diff_skycell.pl	(revision 23740)
@@ -95,6 +95,6 @@
 my $tess_id;                    # Tesselation identifier
 my $camera;                     # Camera
-my $magicked_0;
-my $magicked_1;
+my ($inputMagic, $templateMagic); # Are the inputs been magicked?
+my $inverse = 1;                # Generate inverse subtraction if warp-warp
 foreach my $file (@$files) {
     if (defined $file->{template} and $file->{template}) {
@@ -106,5 +106,6 @@
             $templateSources = "PSPHOT.OUT.CMF.MEF";  ## this must be consistent with the value in stack_skycell.pl:161
             # template is a stack so it doesn't need to be magicked
-            $magicked_1 = 1;
+            $templateMagic = 1;
+            $inverse = 0;
             ## use an explicit stack name for psphot output objects
         } else {
@@ -112,14 +113,15 @@
             $templateVariance = "PSWARP.OUTPUT.VARIANCE";
             $templateSources = "PSWARP.OUTPUT.SOURCES";
-            $magicked_1 = $file->{magicked};
+            $templateMagic = $file->{magicked};
         }
     } else {
         $input = $file->{uri};
         $inputPath = $file->{path_base};
-        $magicked_0 = $file->{magicked};    # if input is a stack the output can't be "magicked"
+        $inputMagic = $file->{magicked};    # if input is a stack the output can't be "magicked"
         if ($file->{warp_id} == 0) {
             $inputMask = "PPSTACK.OUTPUT.MASK";
             $inputVariance = "PPSTACK.OUTPUT.VARIANCE";
             $inputSources = "PSPHOT.OUT.CMF.MEF";  ## this must be consistent with the value in stack_skycell.pl:161
+            $inverse = 0;
         } else {
             $inputMask = "PSWARP.OUTPUT.MASK";
@@ -145,5 +147,4 @@
         $camera = $file->{camera};
     }
-
 }
 
@@ -158,5 +159,5 @@
 # note that difftool -inputskyfile outputs the magicked boolean as an int not T or F
 # because the output is constructed from a union of two selects
-my $magicked = $magicked_0 && $magicked_1;
+my $magicked = $inputMagic && $templateMagic;
 
 # Recipes to use based on reduction class
@@ -207,10 +208,18 @@
 my $outputMask = $ipprc->filename("PPSUB.OUTPUT.MASK", $outroot);
 my $outputVariance = $ipprc->filename("PPSUB.OUTPUT.VARIANCE", $outroot);
+my $outputSources = $ipprc->filename("PPSUB.OUTPUT.SOURCES", $outroot);
+my $jpeg1Name = $ipprc->filename("PPSUB.OUTPUT.JPEG1", $outroot);
+my $jpeg2Name = $ipprc->filename("PPSUB.OUTPUT.JPEG2", $outroot);
 my $configuration = $ipprc->filename("PPSUB.CONFIG", $outroot);
-my $outputSources = $ipprc->filename("PSPHOT.OUT.CMF.MEF", $outroot);
-#my $bin1Name =  $ipprc->filename("PPSUB.BIN1", $outroot);
-#my $bin2Name =  $ipprc->filename("PPSUB.BIN2", $outroot);
 my $outputStats = $ipprc->filename("SKYCELL.STATS", $outroot);
 my $traceDest = $ipprc->filename("TRACE.EXP", $outroot);
+
+my ($inverseName, $inverseMask, $inverseVariance, $inverseSources);
+if ($inverse) {
+    $inverseName = $ipprc->filename("PPSUB.INVERSE", $outroot);
+    $inverseMask = $ipprc->filename("PPSUB.INVERSE.MASK", $outroot);
+    $inverseVariance = $ipprc->filename("PPSUB.INVERSE.VARIANCE", $outroot);
+    $inverseSources = $ipprc->filename("PPSUB.INVERSE.SOURCES", $outroot);
+}
 
 my $cmdflags;
@@ -236,4 +245,5 @@
     $command .= " -F PSPHOT.BACKMDL PSPHOT.BACKMDL.MEF";
     $command .= " -photometry";
+    $command .= " -inverse" if $inverse;
     $command .= " -tracedest $traceDest -log $logDest";
     $command .= " -dumpconfig $configuration";
@@ -271,7 +281,13 @@
         &my_die("Couldn't find expected output file: $outputMask", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputMask);
         &my_die("Couldn't find expected output file: $outputVariance", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputVariance);
-#        &my_die("Couldn't find expected output file: $outputSources", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputSources);
-#        &my_die("Couldn't find expected output file: $bin1Name",    $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($bin1Name);
-#        &my_die("Couldn't find expected output file: $bin2Name",    $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($bin2Name);
+        &my_die("Couldn't find expected output file: $outputSources", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputSources);
+        &my_die("Couldn't find expected output file: $jpeg1Name",    $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($jpeg1Name);
+        &my_die("Couldn't find expected output file: $jpeg2Name",    $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($jpeg2Name);
+        if ($inverse) {
+            &my_die("Couldn't find expected output file: $inverseName", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($inverseName);
+            &my_die("Couldn't find expected output file: $inverseMask", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($inverseMask);
+            &my_die("Couldn't find expected output file: $inverseVariance", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($inverseVariance);
+            &my_die("Couldn't find expected output file: $inverseSources", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($inverseSources);
+        }
     }
 }
