Index: branches/czw_branch/20101203/ippScripts/scripts/diff_skycell.pl
===================================================================
--- branches/czw_branch/20101203/ippScripts/scripts/diff_skycell.pl	(revision 30587)
+++ branches/czw_branch/20101203/ippScripts/scripts/diff_skycell.pl	(revision 30631)
@@ -117,7 +117,12 @@
 }
 
+# ppSub does (input) - (template) after PSF-match convolution.  
+# one of the files needs to be assigned to 'input' and the other to 'template'.
+# if either of these is a WARP, then we can perform magic on it.  If we are going to 
+# run magic, then we need to save the convolved version of the OTHER image
+# (see magic_process.pl:155)
+
 foreach my $file (@$files) {
     if (defined $file->{template} and $file->{template}) {
-#        $template = $file->{uri};
         $templatePath = $file->{path_base};
         if ($file->{warp_id} == 0) {
@@ -142,8 +147,7 @@
             $templateSources = "PSWARP.OUTPUT.SOURCES";
             $templateMagic = $file->{magicked};
-            $saveRefConv = 1;
-        }
-    } else {
-#        $input = $file->{uri};
+            $saveInConv = 1;
+        }
+    } else {
         $inputPath = $file->{path_base};
         $inputMagic = $file->{magicked};    # if input is a stack the output can't be "magicked"
@@ -165,5 +169,5 @@
             $inputVariance = "PSWARP.OUTPUT.VARIANCE";
             $inputSources = "PSWARP.OUTPUT.SOURCES";
-            $saveInConv = 1;
+            $saveRefConv = 1;
         }
     }
Index: branches/czw_branch/20101203/ippScripts/scripts/ipp_cleanup.pl
===================================================================
--- branches/czw_branch/20101203/ippScripts/scripts/ipp_cleanup.pl	(revision 30587)
+++ branches/czw_branch/20101203/ippScripts/scripts/ipp_cleanup.pl	(revision 30631)
@@ -1900,36 +1900,12 @@
 {
     my $files = shift; # reference to a list of files to unlink
-#     my $test_verbose = 1;
-
-#     if ($test_verbose == 1) {
-#       open(TMPLOG,">>/tmp/czw.cleanup.log");
-#       flock(TMPLOG,2);
-#     }
-
-    # this script is, of course, very dangerous.
+
     foreach my $file (@$files) {
         print STDERR "unlinking $stage $stage_id $file";
-        unless ($ipprc->file_exists($file)) {
-            print STDERR "\t File not found\n";
-        }
-        else {
-            print STDERR "\n";
-        }
-
-#       if ($test_verbose == 1) {
-#           print TMPLOG "$stage $stage_id $file";
-
-#           else {
-#               print TMPLOG "\n";
-#           }
-#       }
-
-        $ipprc->file_delete($file);
-    }
-
-#     if ($test_verbose == 1) {
-#       flock(TMPLOG,8);
-#       close(TMPLOG);
-#     }
+
+        my $error_code = $ipprc->kill_file($file);
+
+        &my_die("failed to kill $file", $stage, $stage_id, $PS_EXIT_CONFIG_ERROR) if $error_code;
+    }
 
     return 1;
Index: branches/czw_branch/20101203/ippScripts/scripts/magic_destreak_cleanup.pl
===================================================================
--- branches/czw_branch/20101203/ippScripts/scripts/magic_destreak_cleanup.pl	(revision 30587)
+++ branches/czw_branch/20101203/ippScripts/scripts/magic_destreak_cleanup.pl	(revision 30631)
@@ -44,5 +44,5 @@
            'magic_ds_id=s'  => \$magic_ds_id,# Magic destreak run identifier
            'camera=s'       => \$camera,     # camera for evaluating file rules
-           'stage=s'        => \$stage,     # camera for evaluating file rules
+           'stage=s'        => \$stage,      # ipp stage for this magicDSRun
            'save-temps'     => \$save_temps, # Save temporary files?
            'dbname=s'       => \$dbname,     # Database name
@@ -160,5 +160,5 @@
         my $backup_path_base = $comp->{backup_path_base};
         my ($bimage, $bmask, $bch_mask, $bweight, $bsources, $bastrom);
-        my ($rimage, $rmask, $rch_mask, $rweight, $rsources, $rastrom);
+#        my ($rimage, $rmask, $rch_mask, $rweight, $rsources, $rastrom);
 
         if ($stage eq "chip") {
@@ -219,5 +219,5 @@
         }
 
-        delete_files($bimage, $bmask, $bweight, $bsources, $bastrom, $bch_mask, $rch_mask);
+        delete_files($bimage, $bmask, $bweight, $bsources, $bastrom, $bch_mask);
 
         if ($stage eq "diff" and $warp_warp) {
@@ -252,14 +252,6 @@
     foreach my $file (@_) {
         if ($file) {
-            if ($ipprc->file_exists($file)) {
-                if (!$no_update) {
-                    print STDERR "deleting $file\n" if $verbose;
-                    $ipprc->file_delete($file, 1) or my_die("Failed to delete $file", $magic_ds_id, $PS_EXIT_UNKNOWN_ERROR);
-                    } else {
-                    print STDERR "skipping delete $file\n";
-                }
-            } else {
-                print STDERR "$file not found\n" if $verbose;
-            }
+            my $error_code = $ipprc->kill_file($file);
+            my_die("Failed to delete $file", $magic_ds_id, $error_code) if $error_code;
         }
     }
Index: branches/czw_branch/20101203/ippScripts/scripts/magic_process.pl
===================================================================
--- branches/czw_branch/20101203/ippScripts/scripts/magic_process.pl	(revision 30587)
+++ branches/czw_branch/20101203/ippScripts/scripts/magic_process.pl	(revision 30631)
@@ -151,4 +151,8 @@
             &my_die("failed to resolve inputs", $magic_id, $node, $PS_EXIT_DATA_ERROR);
         }
+
+	# to run magic on a diff image, we need the convolved version
+	# of the corresponding TEMPLATE image
+	# (see diff_skycell.pl:124)
 
         my $diff_base = $innode->{diff_path_base}; # Base name for diff
Index: branches/czw_branch/20101203/ippScripts/scripts/stack_skycell.pl
===================================================================
--- branches/czw_branch/20101203/ippScripts/scripts/stack_skycell.pl	(revision 30587)
+++ branches/czw_branch/20101203/ippScripts/scripts/stack_skycell.pl	(revision 30631)
@@ -270,4 +270,9 @@
     $command .= " -image_id $image_id" if defined $image_id;
     $command .= " -source_id $source_id" if defined $source_id;
+
+    $command .= " -stack_id   $stack_id"   if defined $stack_id;
+    $command .= " -skycell_id $skycell_id" if defined $skycell_id;
+    $command .= " -tess_id    $tess_base"  if defined $tess_base;
+
     if ($run_state eq 'new') {
         $command .= " -dumpconfig $configuration";
Index: branches/czw_branch/20101203/ippScripts/scripts/warp_skycell.pl
===================================================================
--- branches/czw_branch/20101203/ippScripts/scripts/warp_skycell.pl	(revision 30587)
+++ branches/czw_branch/20101203/ippScripts/scripts/warp_skycell.pl	(revision 30631)
@@ -159,5 +159,5 @@
 my $outputWeight = prepare_output ("PSWARP.OUTPUT.VARIANCE", $outroot, $skycell_id, 1);
 my $outputSources = prepare_output ("PSWARP.OUTPUT.SOURCES", $outroot, $skycell_id, 1);
-my $outputPSF = prepare_output ("PSPHOT.PSF.SKY.SAVE", $outroot, 1);
+my $outputPSF = prepare_output ("PSPHOT.PSF.SKY.SAVE", $outroot, $skycell_id, 1);
 my $outputBin1 = prepare_output ("PSWARP.BIN1", $outroot, $skycell_id, 1);
 my $outputBin2 = prepare_output ("PSWARP.BIN2", $outroot, $skycell_id, 1);
