Index: branches/eam_branches/ipp-20110213/ippScripts/scripts/magic_destreak_cleanup.pl
===================================================================
--- branches/eam_branches/ipp-20110213/ippScripts/scripts/magic_destreak_cleanup.pl	(revision 30781)
+++ branches/eam_branches/ipp-20110213/ippScripts/scripts/magic_destreak_cleanup.pl	(revision 30812)
@@ -102,4 +102,5 @@
 my $cam_path_base = $run->{cam_path_base};
 my $cam_reduction = $run->{cam_reduction};
+my $replace = $run->{re_place};
 $cam_reduction = 'DEFAULT' if !$cam_reduction or ($cam_reduction eq 'NULL');
 
@@ -111,5 +112,5 @@
 
 &my_die("unexpected run state found: $state", $magic_ds_id, $PS_EXIT_CONFIG_ERROR) if $state ne "goto_cleaned";
-&my_die("clean not allowed for raw stage, use goto_restore", $magic_ds_id, $PS_EXIT_CONFIG_ERROR) if $stage eq "raw";
+&my_die("cleanup not allowed for raw stage, use goto_restore", $magic_ds_id, $PS_EXIT_CONFIG_ERROR) if $stage eq "raw" and $replace;
 
 my $recipe_psastro;
@@ -217,4 +218,12 @@
                 # $bsources = $ipprc->filename("$name.SOURCES", $backup_path_base);
             }
+        } elsif ($stage eq "raw") {
+            if ($backup_path_base) {
+                if ($backup_path_base =~ /fits/) {
+                    $bimage = $backup_path_base;
+                } else {
+                    $bimage = $backup_path_base . ".fits";
+                }
+            }
         }
 
Index: branches/eam_branches/ipp-20110213/ippScripts/scripts/magic_destreak_revert.pl
===================================================================
--- branches/eam_branches/ipp-20110213/ippScripts/scripts/magic_destreak_revert.pl	(revision 30781)
+++ branches/eam_branches/ipp-20110213/ippScripts/scripts/magic_destreak_revert.pl	(revision 30812)
@@ -78,5 +78,15 @@
     defined $outroot;
 
-&my_die("bytes and md5sum are is required for raw stage stage", $magic_ds_id, $component, $PS_EXIT_CONFIG_ERROR) if ($stage eq 'raw' and (!$bytes or !$md5sum));
+if (defined($replace) and ($replace eq "T")) {
+    $replace = 1;
+} else {
+    $replace = 0;
+}
+
+my $ipprc = PS::IPP::Config->new( $camera ) or my_die( "Unable to set up", $magic_ds_id, $component, $PS_EXIT_CONFIG_ERROR ); # IPP configuration
+
+$ipprc->redirect_output($logfile) or my_die( "Unable to redirect output", $magic_ds_id, $component, $PS_EXIT_SYS_ERROR ) if $logfile;
+
+&my_die("bytes and md5sum are is required for raw stage stage", $magic_ds_id, $component, $PS_EXIT_CONFIG_ERROR) if ($replace and $stage eq 'raw' and (!$bytes or !$md5sum));
 
 &my_die("cam_path_base is required for chip stage", $magic_ds_id, $component, $PS_EXIT_CONFIG_ERROR) if ($stage eq 'chip' and !$cam_path_base);
@@ -84,7 +94,4 @@
 
 
-my $ipprc = PS::IPP::Config->new( $camera ) or my_die( "Unable to set up", $magic_ds_id, $component, $PS_EXIT_CONFIG_ERROR ); # IPP configuration
-
-$ipprc->redirect_output($logfile) or my_die( "Unable to redirect output", $magic_ds_id, $component, $PS_EXIT_SYS_ERROR ) if $logfile;
 
 $cam_reduction = 'DEFAULT' if !defined $cam_reduction or ($cam_reduction eq "NULL");
@@ -118,10 +125,4 @@
 my $basename = basename($path_base);
 my $nebulousInput = inNebulous($dirname);
-
-if (defined($replace) and ($replace eq "T")) {
-    $replace = 1;
-} else {
-    $replace = 0;
-}
 
 &my_die("replace not allowed for non-nebulous files", $magic_ds_id, $component, $PS_EXIT_CONFIG_ERROR)
@@ -162,5 +163,9 @@
         $image = $path_base . ".fits";
     }
-    $bimage = $backup_path_base . ".fits";
+    if ($backup_path_base =~ /.*\.fits$/) {
+        $bimage = $backup_path_base;
+    } else {
+        $bimage = $backup_path_base . ".fits";
+    }
 } elsif ($stage eq "chip") {
     # Check to see if we're using dynamic masks
@@ -302,5 +307,5 @@
 sub revert_files {
     my $replace = shift;
-    return if !$replace;
+#    return if !$replace;
 
     my $image = shift;
@@ -316,10 +321,10 @@
 
     if ($image) {
-        revert_file($image, $bimage) or
+        revert_file($replace, $image, $bimage) or
             &my_die("failed to restore image file", $magic_ds_id, $component, $PS_EXIT_CONFIG_ERROR);
     }
 
     if ($mask) {
-        if (!revert_file($mask, $bmask)) {
+        if (!revert_file($replace, $mask, $bmask)) {
             &my_die("failed to restore mask file", $magic_ds_id, $component, $PS_EXIT_CONFIG_ERROR);
         }
@@ -327,5 +332,5 @@
 
     if ($ch_mask) {
-        if (!revert_file($ch_mask, $bch_mask)) {
+        if (!revert_file($replace, $ch_mask, $bch_mask)) {
             &my_die("failed to restore chip mask file", $magic_ds_id, $component, $PS_EXIT_CONFIG_ERROR);
         }
@@ -334,15 +339,15 @@
 
     if ($weight) {
-        revert_file($weight, $bweight) or
+        revert_file($replace, $weight, $bweight) or
             &my_die("failed to restore variance image", $magic_ds_id, $component, $PS_EXIT_CONFIG_ERROR);
     }
 
     if ($sources) {
-        revert_file($sources, $bsources) or
+        revert_file($replace, $sources, $bsources) or
             &my_die("failed to restore sources file", $magic_ds_id, $component, $PS_EXIT_CONFIG_ERROR);
     }
 
     if ($astrom) {
-        revert_file($astrom, $bastrom) or
+        revert_file($replace, $astrom, $bastrom) or
             &my_die("failed to restore astrometry file", $magic_ds_id, $component, $PS_EXIT_CONFIG_ERROR);
     }
@@ -366,7 +371,20 @@
 sub revert_file
 {
+    my $replace = shift;
     my $original = shift;
     my $backup   = shift;
     my $force = 1; # force deletion of backup files in nebulous
+
+    if (!$replace) {
+        # we don't need to do all of this checking unless the destreak run is
+        # replace mode just delete the backup 
+        my $error_code = $ipprc->kill_file($backup);
+        if ($error_code) {
+            print STDERR "failed to kill $backup: error_code $error_code\n";
+            return 0;
+        } else {
+            return 1;
+        }
+    }
 
     my $o_path = $ipprc->file_resolve($original);
Index: branches/eam_branches/ipp-20110213/ippScripts/scripts/register_imfile.pl
===================================================================
--- branches/eam_branches/ipp-20110213/ippScripts/scripts/register_imfile.pl	(revision 30781)
+++ branches/eam_branches/ipp-20110213/ippScripts/scripts/register_imfile.pl	(revision 30812)
@@ -181,4 +181,5 @@
 if (uc(&value_for_flag ($cmdflags, "NULL", "-exp_type"))  eq "NULL") { &my_die_for_add ("exp_type  not found", $exp_id, $tmp_exp_name, $tmp_class_id, $uri, $PS_EXIT_CONFIG_ERROR); }
 my $dateobs   = &value_for_flag($cmdflags, 0.0, "-dateobs");
+my $exp_type  = &value_for_flag($cmdflags, "NULL", "-exp_type");
 
 my $command = "$regtool -addprocessedimfile";
