Index: trunk/ippScripts/scripts/diff_skycell.pl
===================================================================
--- trunk/ippScripts/scripts/diff_skycell.pl	(revision 23397)
+++ trunk/ippScripts/scripts/diff_skycell.pl	(revision 23417)
@@ -91,5 +91,5 @@
 
 # Identify the input and the template
-my ($input, $inputMask, $inputVariance, $inputPath); # Input files and path
+my ($input, $inputMask, $inputVariance, $inputPath, $inputSources); # Input files and path
 my ($template, $templateMask, $templateVariance, $templatePath, $templateSources); # Template files and path
 my $tess_id;                    # Tesselation identifier
@@ -115,7 +115,9 @@
             $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
         } else {
             $inputMask = "PSWARP.OUTPUT.MASK";
             $inputVariance = "PSWARP.OUTPUT.VARIANCE";
+            $inputSources = "PSWARP.OUTPUT.SOURCES";
         }
     }
@@ -160,4 +162,5 @@
 # print "inputVariance: $inputVariance\n";
 # print "templateSources: $templateSources\n";
+# print "inputSources: $inputSources\n";
 
 $templateMask = $ipprc->filename($templateMask, $templatePath);
@@ -174,12 +177,14 @@
 print "inputVariance: $inputVariance\n";
 print "templateSources: $templateSources\n";
+print "inputSources: $inputSources\n";
 
 &my_die("Couldn't find input: $template", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($template);
 &my_die("Couldn't find input: $templateMask", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($templateMask);
 &my_die("Couldn't find input: $templateVariance", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($templateVariance);
+&my_die("Couldn't find input: $templateSources", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($templateSources);
 &my_die("Couldn't find input: $input", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($input);
 &my_die("Couldn't find input: $inputMask", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($inputMask);
 &my_die("Couldn't find input: $inputVariance", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($inputVariance);
-&my_die("Couldn't find input: $templateSources", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($templateSources);
+&my_die("Couldn't find input: $inputSources", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($inputSources);
 
 # Get the output filenames
@@ -198,9 +203,13 @@
 # Perform subtraction
 unless ($no_op) {
-    my $command = "$ppSub -inimage $input -refimage $template $outroot";
+    my $command = "$ppSub $outroot";
+    $command .= " -inimage $input";
+    $command .= " -refimage $template";
     $command .= " -inmask $inputMask";
     $command .= " -refmask $templateMask";
     $command .= " -invariance $inputVariance";
     $command .= " -refvariance $templateVariance";
+    $command .= " -insources $inputSources";
+    $command .= " -refsources $templateSources";
     $command .= " -stats $outputStats";
     $command .= " -threads $threads" if defined $threads;
@@ -211,5 +220,4 @@
     $command .= " -F PSPHOT.OUTPUT PSPHOT.OUT.CMF.MEF";
     $command .= " -F PSPHOT.BACKMDL PSPHOT.BACKMDL.MEF";
-    $command .= " -sources $templateSources";
     $command .= " -photometry";
     $command .= " -tracedest $traceDest -log $logDest";
