Index: /trunk/ippScripts/scripts/magic_destreak.pl
===================================================================
--- /trunk/ippScripts/scripts/magic_destreak.pl	(revision 25028)
+++ /trunk/ippScripts/scripts/magic_destreak.pl	(revision 25029)
@@ -207,4 +207,8 @@
     my ($image, $mask, $ch_mask, $weight, $astrom, $sources);
 
+    # if we're destreaking a bothways diff need to combine the
+    # two streaks files
+    my ($allstreaks_fh, $allstreaks_name);
+
     if ($stage eq "raw") {
         $image = $uri;
@@ -239,4 +243,16 @@
         $weight = $ipprc->filename("PPSUB.OUTPUT.VARIANCE", $path_base);
         $sources    = $ipprc->filename("PPSUB.OUTPUT.SOURCES", $path_base);
+
+        if ($inv_streaks) {
+            # create a temporary file containing the contents of the 
+            # two streaks files
+            ($allstreaks_fh, $allstreaks_name) = tempfile ("/tmp/all.streaks.XXXX",
+                    UNLINK => !$save_temps);
+
+            combine_streaks($allstreaks_fh, $streaks, $inv_streaks);
+
+            # apply the combined streaks to both the forward and inverse diffs
+            $streaks = $allstreaks_name;
+        }
     }
 
@@ -272,5 +288,5 @@
         $sources = $ipprc->filename("PPSUB.INVERSE.SOURCES", $path_base);
 
-        my $command = "$streaksremove -stage $stage -tmproot $tmproot -streaks $inv_streaks -image $image";
+        my $command = "$streaksremove -stage $stage -tmproot $tmproot -streaks $streaks -image $image";
 
         $command .= " -recovery $recoveryroot" if defined $recoveryroot;
@@ -402,4 +418,52 @@
 }
 
+sub combine_streaks
+{
+    my $fout = shift;
+    my $fn1 = shift;
+    my $fn2 = shift;
+
+    my ($n1, @streaks1) = read_streaks_file($fn1);
+    my_die("failed to read streaks from $fn1", $magic_ds_id, $component,
+        $PS_EXIT_UNKNOWN_ERROR) if $n1 < 0;
+
+    my ($n2, @streaks2) = read_streaks_file($fn2);
+    my_die("failed to read streaks from $fn2", $magic_ds_id, $component,
+        $PS_EXIT_UNKNOWN_ERROR) if $n2 < 0;
+
+    print $fout $n1 + $n2 . "\n";
+
+    foreach my $line (@streaks1, @streaks2) {
+        print $fout $line;
+    }
+
+    close $fout 
+        or my_die("failed to close combined streaks file", $magic_ds_id,
+                     $component, $PS_EXIT_UNKNOWN_ERROR);
+}
+
+sub read_streaks_file
+{
+    my $filename = shift;
+    my $fh;
+    open $fh, "<$filename" or my_die("failed to open $filename",
+                    $magic_ds_id, $component, $PS_EXIT_UNKNOWN_ERROR);
+
+    # first line is the number of streaks
+    my $line = <$fh>;
+    chomp $line;
+    my $nstreaks = $line;
+
+    my @streaks;
+
+    foreach $line (<$fh>) {
+        push @streaks, $line;
+    }
+
+    close $fh;
+
+    return ($nstreaks, @streaks);
+}
+
 
 sub my_die
