Index: trunk/ippScripts/scripts/diff_skycell.pl
===================================================================
--- trunk/ippScripts/scripts/diff_skycell.pl	(revision 26901)
+++ trunk/ippScripts/scripts/diff_skycell.pl	(revision 26929)
@@ -1,3 +1,3 @@
-#!/usr/bin/env perl
+>>#!/usr/bin/env perl
 
 use warnings;
@@ -37,4 +37,5 @@
 my ($diff_id, $dbname, $threads, $outroot, $reduction, $inverse, $run_state, $verbose, $no_update, $no_op, $redirect);
 my ($skycell_id, $diff_skyfile_id);
+my ($use_convolved);
 GetOptions(
     'diff_id=s'         => \$diff_id, # Diff identifier
@@ -47,4 +48,5 @@
     'inverse'           => \$inverse, # Make inverse subtraction?
     'reduction=s'       => \$reduction, # Reduction class
+    'use_convolved'     => \$use_convolved, # Use convolved stacks instead of unconvolved.
     'verbose'           => \$verbose,   # Print to stdout
     'no-update'         => \$no_update, # Don't update the database?
@@ -100,11 +102,32 @@
 my $camera;                     # Camera
 my ($inputMagic, $templateMagic); # Are the inputs been magicked?
+# Prescan to decide if this is or is not a stack stack diff. The check above confirms we only have two entries.
+if ((${ $files }[0]->{warp_id} == 0)&&
+    (${ $files }[1]->{warp_id} == 0)) {
+    # Both are zero, so stack stack diff;
+    unless ($use_convolved) {
+	$use_convolved = 0;
+    }
+}
+else {
+    # We're in some sort of warp stack or warp warp (don't care about the last one.)
+    $use_convolved = 1;
+}
+
 foreach my $file (@$files) {
     if (defined $file->{template} and $file->{template}) {
-        $template = $file->{uri};
+#        $template = $file->{uri};
         $templatePath = $file->{path_base};
         if ($file->{warp_id} == 0) {
-            $templateMask = "PPSTACK.OUTPUT.MASK";
-            $templateVariance = "PPSTACK.OUTPUT.VARIANCE";
+	    if ($use_convolved) {
+		$template = "PPSTACK.OUTPUT";
+		$templateMask = "PPSTACK.OUTPUT.MASK";
+		$templateVariance = "PPSTACK.OUTPUT.VARIANCE";
+	    }
+	    else {
+		$template     = "PPSTACK.UNCONV";
+		$templateMask = "PPSTACK.UNCONV.MASK";
+		$templateVariance = "PPSTACK.UNCONV.VARIANCE";
+	    }
             $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
@@ -112,4 +135,5 @@
             ## use an explicit stack name for psphot output objects
         } else {
+	    $template     = "PSWARP.OUTPUT";
             $templateMask = "PSWARP.OUTPUT.MASK";
             $templateVariance = "PSWARP.OUTPUT.VARIANCE";
@@ -118,12 +142,21 @@
         }
     } else {
-        $input = $file->{uri};
+#        $input = $file->{uri};
         $inputPath = $file->{path_base};
         $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";
+	    if ($use_convolved) {
+		$input = "PPSTACK.OUTPUT";
+		$inputMask = "PPSTACK.OUTPUT.MASK";
+		$inputVariance = "PPSTACK.OUTPUT.VARIANCE";
+	    }
+	    else {
+		$input     = "PPSTACK.UNCONV";
+		$inputMask = "PPSTACK.UNCONV.MASK";
+		$inputVariance = "PPSTACK.UNCONV.VARIANCE";
+	    }
             $inputSources = "PSPHOT.OUT.CMF.MEF";  ## this must be consistent with the value in stack_skycell.pl:161
         } else {
+	    $input     = "PSWARP.OUTPUT";
             $inputMask = "PSWARP.OUTPUT.MASK";
             $inputVariance = "PSWARP.OUTPUT.VARIANCE";
@@ -180,14 +213,18 @@
 # print "inputSources: $inputSources\n";
 
+$input     = $ipprc->filename($input, $inputPath);
 $inputMask = $ipprc->filename($inputMask, $inputPath);
 $inputVariance = $ipprc->filename($inputVariance, $inputPath);
 $inputSources = $ipprc->filename($inputSources, $inputPath);
 
+$template     = $ipprc->filename($template, $templatePath);
 $templateMask = $ipprc->filename($templateMask, $templatePath);
 $templateVariance = $ipprc->filename($templateVariance, $templatePath);
 $templateSources = $ipprc->filename($templateSources, $templatePath);
 
+print "template:     $template\n";
 print "templateMask: $templateMask\n";
 print "templatePath: $templatePath\n";
+print "input:     $input\n";
 print "inputMask: $inputMask\n";
 print "inputPath: $inputPath\n";
