Index: /branches/pap/ippScripts/scripts/diff_skycell.pl
===================================================================
--- /branches/pap/ippScripts/scripts/diff_skycell.pl	(revision 23722)
+++ /branches/pap/ippScripts/scripts/diff_skycell.pl	(revision 23723)
@@ -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.JPEG1", $outroot);
+my $jpeg2Name = $ipprc->filename("PPSUB.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);
+        }
     }
 }
Index: /branches/pap/ippTools/src/difftool.c
===================================================================
--- /branches/pap/ippTools/src/difftool.c	(revision 23722)
+++ /branches/pap/ippTools/src/difftool.c	(revision 23723)
@@ -1275,10 +1275,17 @@
     PXOPT_COPY_STR(config->args, selectWhere, "-input_label", "inputWarpRun.label", "==");
     PXOPT_COPY_STR(config->args, selectWhere, "-template_label", "templateWarpRun.label", "==");
+    PXOPT_COPY_F32(config->args, selectWhere, "-rotdiff", "ABS(inputRawExp.posang - templateRawExp.posang)", "<=");
     PXOPT_COPY_F32(config->args, selectWhere, "-timediff",
                    "ABS(TIME_TO_SEC(TIMEDIFF(inputRawExp.dateobs, templateRawExp.dateobs)))", "<=");
-    PXOPT_COPY_F32(config->args, selectWhere, "-rotdiff", "ABS(inputRawExp.posang - templateRawExp.posang)", "<=");
+
     // Haversine formula for great circle distance
     PXOPT_COPY_F32(config->args, selectWhere, "-distance",
                    "DEGREES(2*ASIN(SQRT(POW(SIN(inputRawExp.decl - templateRawExp.decl),2) + COS(inputRawExp.decl)*COS(templateRawExp.decl)*POW(SIN(inputRawExp.ra - templateRawExp.ra),2))))", "<=");
+
+    PXOPT_LOOKUP_BOOL(backwards, config->args, "-backwards", false);
+
+    psMetadataAddF32(selectWhere, PS_LIST_TAIL,
+                     "TIME_TO_SEC(TIMEDIFF(inputRawExp.dateobs, templateRawExp.dateobs))",
+                     PS_META_DUPLICATE_OK, backwards ? "<" : ">", 0.0);
 
     // Restrictions for inserting skycells
Index: /branches/pap/ippTools/src/difftoolConfig.c
===================================================================
--- /branches/pap/ippTools/src/difftoolConfig.c	(revision 23722)
+++ /branches/pap/ippTools/src/difftoolConfig.c	(revision 23723)
@@ -174,4 +174,5 @@
     psMetadataAddStr(definewarpwarpArgs, PS_LIST_TAIL, "-obs_mode", 0, "search by observation mode", NULL);
     psMetadataAddF32(definewarpwarpArgs, PS_LIST_TAIL, "-timediff", 0, "limit time difference between input and template", NAN);
+    psMetadataAddBool(definewarpwarpArgs, PS_LIST_TAIL, "-backwards", 0, "Template comes after input?", false);
     psMetadataAddF32(definewarpwarpArgs, PS_LIST_TAIL, "-rotdiff", 0, "limit rotator difference between input and template", NAN);
     psMetadataAddStr(definewarpwarpArgs, PS_LIST_TAIL, "-input_label", 0, "search by warp label for input", NULL);
Index: /branches/pap/ippconfig/recipes/ppSub.config
===================================================================
--- /branches/pap/ippconfig/recipes/ppSub.config	(revision 23722)
+++ /branches/pap/ippconfig/recipes/ppSub.config	(revision 23723)
@@ -45,5 +45,5 @@
 
 INVERSE		BOOL	FALSE		# Generate inverse subtraction?
-PHOTOMETRY	BOOL	FALSE		# Perform photometry?
+PHOTOMETRY	BOOL	TRUE		# Perform photometry?
 
 
@@ -60,2 +60,7 @@
 DIFF	METADATA
 END
+
+# Difference of two warps
+WARPWARP	METADATA
+	INVERSE		BOOL	TRUE	# Generate inverse subtraction?
+END
Index: /branches/pap/ppSub/src/ppSubArguments.c
===================================================================
--- /branches/pap/ppSub/src/ppSubArguments.c	(revision 23722)
+++ /branches/pap/ppSub/src/ppSubArguments.c	(revision 23723)
@@ -75,4 +75,6 @@
     psMetadataAddS32(arguments, PS_LIST_TAIL, "-threads", 0, "Number of threads", 0);
     psMetadataAddStr(arguments, PS_LIST_TAIL, "-dumpconfig", 0, "file to dump configuration to", NULL);
+    psMetadataAddBool(arguments, PS_LIST_TAIL, "-photometry", 0, "Perform photometry?", NULL);
+    psMetadataAddBool(arguments, PS_LIST_TAIL, "-inverse", 0, "Generate inverse subtractions?", NULL);
     psMetadataAddBool(arguments, PS_LIST_TAIL, "-visual", 0, "Show diagnostic plots", NULL);
 
Index: /branches/pap/ppSub/src/ppSubCamera.c
===================================================================
--- /branches/pap/ppSub/src/ppSubCamera.c	(revision 23722)
+++ /branches/pap/ppSub/src/ppSubCamera.c	(revision 23723)
@@ -202,4 +202,13 @@
         return false;
     }
+    if (psMetadataLookupBool(NULL, config->arguments, "-photometry")) {
+        psMetadataAddBool(config->arguments, PS_LIST_TAIL, "PHOTOMETRY", PS_META_REPLACE,
+                          "Perform photometry?", true);
+    }
+    if (psMetadataLookupBool(NULL, config->arguments, "-inverse")) {
+        psMetadataAddBool(config->arguments, PS_LIST_TAIL, "INVERSE", PS_META_REPLACE,
+                          "Generate inverse subtractions?", true);
+    }
+
     data->inverse = psMetadataLookupBool(NULL, recipe, "INVERSE");
     data->photometry = psMetadataLookupBool(NULL, recipe, "PHOTOMETRY");
