Index: trunk/ippScripts/scripts/magic_destreak.pl
===================================================================
--- trunk/ippScripts/scripts/magic_destreak.pl	(revision 20941)
+++ trunk/ippScripts/scripts/magic_destreak.pl	(revision 21085)
@@ -176,10 +176,13 @@
 my $image = $uri;
 
-my ($mask, $weight, $astrom);
+my ($mask, $ch_mask, $weight, $astrom);
 
 if ($stage eq "raw") {
     $astrom = $ipprc->filename("PSASTRO.OUTPUT", $cam_path_base);
 } elsif ($stage eq "chip") {
-    $mask   = $ipprc->filename("PPIMAGE.CHIP.MASK", $path_base, $class_id);
+    # we use the mask output from the camera stage for input and replace
+    # the output of the chip stage with that mask as well.
+    $mask   = $ipprc->filename("PSASTRO.OUTPUT.MASK", $cam_path_base, $class_id);
+    $ch_mask= $ipprc->filename("PPIMAGE.CHIP.MASK", $path_base, $class_id);
     $weight = $ipprc->filename("PPIMAGE.CHIP.WEIGHT", $path_base, $class_id);
     $astrom = $ipprc->filename("PSASTRO.OUTPUT", $cam_path_base);
@@ -198,4 +201,5 @@
     $command .= " -astrom $astrom" if defined $astrom;
     $command .= " -mask $mask" if defined $mask;
+    $command .= " -chip_mask $ch_mask" if defined $ch_mask;
     $command .= " -weight $weight" if defined $weight;
     $command .= " -skycelllist $skycell_list" if defined $skycell_list;
