Index: trunk/ippScripts/scripts/detrend_resid_imfile.pl
===================================================================
--- trunk/ippScripts/scripts/detrend_resid_imfile.pl	(revision 23183)
+++ trunk/ippScripts/scripts/detrend_resid_imfile.pl	(revision 23186)
@@ -17,6 +17,4 @@
 use PS::IPP::Metadata::Config;
 use PS::IPP::Config 1.01 qw( :standard );
-
-my $ipprc = PS::IPP::Config->new(); # IPP configuration
 
 use Getopt::Long qw( GetOptions :config auto_help auto_version gnu_getopt );
@@ -76,13 +74,7 @@
     defined $detrend;
 
-# Unhandled exceptions should be passed on to my_die so they get pushed into the database
-$SIG{__DIE__} = sub { die @_ if $^S;
-                      my_die( $_[0], $det_id, $iter, $exp_id, $class_id, $PS_EXIT_UNKNOWN_ERROR ); };
-
-$ipprc->define_camera($camera);
-my $logDest     = $ipprc->filename("LOG.IMFILE", $outroot, $class_id);
-if ($redirect) {
-    $ipprc->redirect_output($logDest);
-}
+my $ipprc = PS::IPP::Config->new( $camera ) or my_die( "Unable to set up", $det_id, $iter, $exp_id, $class_id, $PS_EXIT_CONFIG_ERROR ); # IPP configuration
+my $logDest = $ipprc->filename("LOG.IMFILE", $outroot, $class_id) or my_die( "Unable to find LOG.IMFILE", $det_id, $iter, $exp_id, $class_id, $PS_EXIT_CONFIG_ERROR );
+$ipprc->redirect_output($logDest) or my_die( "Unable to find LOG.IMFILE", $det_id, $iter, $exp_id, $class_id, $PS_EXIT_SYS_ERROR ) if $redirect;
 
 # Recipes to use as a function of detrend type and mode
@@ -155,5 +147,7 @@
 # my $outputName  = $ipprc->filename("PPIMAGE.OUTPUT", $outroot, $class_id);
 
-my $outputName  = $ipprc->filename("PPIMAGE.OUTPUT.RESID", $outroot, $class_id);
+my $filerule = $FILERULES->{$det_type}; # File rule to use
+
+my $outputName  = $ipprc->filename($filerule,        $outroot, $class_id);
 my $bin1Name    = $ipprc->filename("PPIMAGE.BIN1",   $outroot, $class_id);
 my $bin2Name    = $ipprc->filename("PPIMAGE.BIN2",   $outroot, $class_id);
@@ -169,5 +163,5 @@
     $command .= " -recipe JPEG $jpeg_recipe";
     $command .= " -recipe PPSTATS RESIDUAL";
-    $command .= " -F PPIMAGE.OUTPUT $FILERULES{$det_type}" if defined $FILERULES{$det_type};
+    $command .= " -F PPIMAGE.OUTPUT $filerule";
     $command .= " -stats $outputStats";
     $command .= " -tracedest $traceDest -log $logDest";
