Index: /tags/ipp-20141024/ippScripts/scripts/diff_skycell.pl
===================================================================
--- /tags/ipp-20141024/ippScripts/scripts/diff_skycell.pl	(revision 38733)
+++ /tags/ipp-20141024/ippScripts/scripts/diff_skycell.pl	(revision 38734)
@@ -78,6 +78,8 @@
 # XXX camera is not known here; cannot use filerules... 
 my $logDest = "$outroot.log";
+my $updateMode = 0;
 if ($run_state eq 'update') {
     $logDest .= '.update';
+    $updateMode = 1;
 }
 $ipprc->redirect_to_logfile($logDest) or my_die( "Unable to redirect output", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR ) if $redirect;
@@ -128,4 +130,20 @@
 #     $use_convolved = 1; ## This is a hack to do a test for mops, and should not be committed.
 # }
+
+# Re-implement prescan to decide if this is a warp-stack or warp-warp.  Or stack-stack, but that's what we don't care about now.
+my $diff_type = '';
+
+if ((${ $files }[0]->{warp_id} != 0)&&(${ $files }[1]->{warp_id} != 0)) {
+    $diff_type = "WW";
+}
+elsif ((${ $files }[0]->{stack_id} != 0)&&(${ $files }[1]->{stack_id} != 0)) {
+    $diff_type = "SS";
+}
+elsif (((${ $files }[0]->{warp_id} != 0)&&(${ $files }[1]->{stack_id} != 0))) {
+    $diff_type = "WS";
+}
+else {  # Something has gone horribly wrong.
+    $diff_type = "WW"; # just pretend it never happened, and let it fail elsewhere.
+}
 
 # ppSub does (input) - (template) after PSF-match convolution.  
@@ -254,5 +272,19 @@
 &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: $templateSources", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($templateSources);
+
+if ($diff_type eq 'WS') {
+    # LANL processed stack images do not have a set of sources transferred back, so we need to choose a different source list.
+    unless($ipprc->file_exists($templateSources)) {
+	if ($ipprc->file_exists($inputSources)) {
+	    $templateSources = $inputSources;
+	    print "CHANGED:templateSources: $templateSources\n";
+	}
+    }
+    &my_die("Couldn't find input: $templateSources", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($templateSources);
+}
+else {
+    &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);
@@ -292,5 +324,6 @@
     }
 
-    # use WARPSTATS if we're updating, as we don't care about the new stuff from the STACK and DIFF STATS recipes
+    # use WARPSTATS if we're updating, as we don't care about the new stuff from the STACK and DIFF STATS recipes.
+    # The only value that we use is -quality
     $recipe_ppstats = 'WARPSTATS';
 }
@@ -321,4 +354,5 @@
 {
     my $command = "$ppSub $outroot";
+    $command .= " -updatemode" if $updateMode;
     $command .= " -inimage $input";
     $command .= " -refimage $template";
