Index: /trunk/ippScripts/scripts/magic_destreak.pl
===================================================================
--- /trunk/ippScripts/scripts/magic_destreak.pl	(revision 24552)
+++ /trunk/ippScripts/scripts/magic_destreak.pl	(revision 24553)
@@ -16,5 +16,5 @@
 use IPC::Cmd 0.36 qw( can_run run );
 use File::Temp qw( tempfile );
-use File::Basename qw( basename );
+use File::Basename qw( basename dirname );
 use PS::IPP::Metadata::Config;
 use PS::IPP::Metadata::List qw( parse_md_list );
@@ -37,5 +37,5 @@
 my ($magic_ds_id, $camera, $streaks, $stage, $stage_id, $component, $uri, $path_base, $inverse, $cam_path_base);
 my ($outroot, $recoveryroot);
-my ($replace, $remove, $release);
+my ($replace, $release);
 my ($dbname, $save_temps, $verbose, $no_update, $no_op, $logfile);
 
@@ -54,5 +54,4 @@
            'recoveryroot=s' => \$recoveryroot,# "directory" for saving the images of excised pixels
            'replace=s'      => \$replace,    # replace the input images with the results.
-           'remove=s'       => \$remove,     # remove the original images when done YIKES!
            'release'        => \$release,    # NAN masked pixels for release
            'save-temps'     => \$save_temps, # Save temporary files?
@@ -96,8 +95,9 @@
 my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files
 
+my $dirname = dirname($path_base);
 my $basename = basename($path_base);
-
-#
-# parse the replace and remove arguments check for errors and set up
+my $nebulousInput = inNebulous($dirname);
+
+# parse replace arguments check for errors and set up
 # the appropriate paths
 if (defined($replace) and ($replace eq "T")) {
@@ -117,16 +117,6 @@
 }
 
-if (defined($remove) and ($remove eq "T")) {
-    $remove = 1;
-} else {
-    $remove = 0;
-}
-
-if ($remove and !$replace) {
-    &my_die("cannot remove without replace", $magic_ds_id, $component, $PS_EXIT_CONFIG_ERROR);
-}
-
 # create the output directories if it is not a nebulous path and it doesn't exist
-if (index($outroot, "neb://") != 0) {
+if (!inNebulous($outroot)) {
     if (! -e $outroot ) {
         my $code = system "mkdir -p $outroot";
@@ -134,14 +124,29 @@
                 $code >> 8) if $code;
     }
+#} elsif ($replace) {
+    # if input is in nebulous and we've been asked to replace the input with the destreaked
+    # version the output must be in nebulous as well
+    # XXX Is this necessary? if ($replace) the outputs are going to the nebulous "directory" of the
+    # input anyways. Why require that other files (log) be in nebulous
 }
 
 my $backup_path_base;
-if (! $remove) {
-    $backup_path_base = "$outroot/$basename";
+my $tmproot;
+if ($replace) {
+    # in replace mode, we place the output files in the same "directory" as the inputs
+    # Nebulous requires this for the two inputs to nebSwap which we use
+    # We prepend the path with SR_ This causes the filenames for instances of the swapped files to
+    # have SR in them.
+    $tmproot = $dirname . "/SR_";
+    $backup_path_base = $tmproot . "$basename";
+} else {
+    # note: trailing / is necessary
+    $tmproot = "$outroot/";
+    $backup_path_base = $tmproot . $basename;
 }
 
 my $recovery_path_base;
 if ($recoveryroot) {
-    if (index($recoveryroot, "neb://") != 0) {
+    if (!inNebulous($recoveryroot)) {
         if (! -e $recoveryroot ) {
             my $code = system "mkdir -p $recoveryroot";
@@ -150,5 +155,6 @@
         }
     }
-    $recovery_path_base = "$recoveryroot/$basename";
+    # note: trailing / is necessary
+    $recovery_path_base = "$recoveryroot/$basename/";
 }
 
@@ -209,5 +215,5 @@
 
 {
-    my $command = "$streaksremove -stage $stage -tmproot $outroot -streaks $streaks -image $image";
+    my $command = "$streaksremove -stage $stage -tmproot $tmproot -streaks $streaks -image $image";
 
     $command .= " -class_id $class_id" if defined $class_id;
@@ -219,5 +225,4 @@
     $command .= " -skycelllist $skycell_list" if defined $skycell_list;
     $command .= " -replace" if $replace;
-    $command .= " -remove" if $remove;
     $command .= " -release" if $release;
     $command .= " -dbname $dbname" if defined $dbname;
@@ -272,4 +277,14 @@
 }
 
+sub inNebulous
+{
+    my $path = shift;
+
+    my $scheme = file_scheme($path);
+
+    return $scheme and ($scheme eq "neb");
+}
+
+
 sub my_die
 {
