Index: trunk/ippScripts/scripts/detrend_resid.pl
===================================================================
--- trunk/ippScripts/scripts/detrend_resid.pl	(revision 17671)
+++ trunk/ippScripts/scripts/detrend_resid.pl	(revision 17941)
@@ -39,5 +39,5 @@
     'outroot|w=s'       => \$outroot,   # output file base name
     'dbname|d=s'        => \$dbname, # Database name
-    'reduction=s'       => \$reduction,	# Reduction class
+    'reduction=s'       => \$reduction, # Reduction class
     'verbose'           => \$verbose,   # Print to stdout
     'no-update'         => \$no_update,
@@ -47,15 +47,15 @@
 pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV;
 pod2usage( -msg => "Required options: --det_id --iteration --exp_id --exp_tag --class_id --det_type --camera --input_uri --mode --detrend --outroot (not for 'verify' mode)",
-	   -exitval => 3) unless 
-    defined $det_id    and 
-    defined $iter      and 
-    defined $exp_id    and 
-    defined $exp_tag   and 
-    defined $class_id  and 
-    defined $det_type  and 
-    defined $input_uri and 
-    defined $camera    and 
-    defined $mode      and 
-    defined $outroot   and 
+           -exitval => 3) unless
+    defined $det_id    and
+    defined $iter      and
+    defined $exp_id    and
+    defined $exp_tag   and
+    defined $class_id  and
+    defined $det_type  and
+    defined $input_uri and
+    defined $camera    and
+    defined $mode      and
+    defined $outroot   and
     (defined $detrend or lc($mode) eq 'verify');
 
@@ -64,5 +64,5 @@
 # Recipes to use as a function of detrend type and mode
 $reduction = 'DETREND' unless defined $reduction;
-my $recipe;			# Name of recipe to use
+my $recipe;                     # Name of recipe to use
 if ($mode eq 'master') {
     $recipe = uc($det_type) . '_RESID';
@@ -75,15 +75,15 @@
 
 # values to extract from output metadata and the stats to calculate
-my $STATS = 
+my $STATS =
    [
        #          PPSTATS KEYWORD         STATISTIC          CHIPTOOL FLAG
        { name => "ROBUST_MEDIAN",      type => "mean",  flag => "-bg",             dtype => "float" },
        { name => "ROBUST_MEDIAN",      type => "stdev", flag => "-bg_mean_stdev",  dtype => "float" },
-       { name => "ROBUST_STDEV",       type => "rms",   flag => "-bg_stdev",	   dtype => "float" },
+       { name => "ROBUST_STDEV",       type => "rms",   flag => "-bg_stdev",       dtype => "float" },
        { name => "SAMPLE_SKEWNESS",    type => "mean",  flag => "-bg_skewness",    dtype => "float" },
        { name => "SAMPLE_KURTOSIS",    type => "mean",  flag => "-bg_kurtosis",    dtype => "float" },
-       { name => "FRINGE_0",           type => "mean",  flag => "-fringe_0",	   dtype => "float" },
-       { name => "FRINGE_ERR_0",       type => "rms",   flag => "-fringe_1",	   dtype => "float" },
-       { name => "FRINGE_0",           type => "stdev", flag => "-fringe_2",	   dtype => "float" },
+       { name => "FRINGE_0",           type => "mean",  flag => "-fringe_0",       dtype => "float" },
+       { name => "FRINGE_ERR_0",       type => "rms",   flag => "-fringe_1",       dtype => "float" },
+       { name => "FRINGE_0",           type => "stdev", flag => "-fringe_2",       dtype => "float" },
        { name => "FRINGE_RESID_0",     type => "mean",  flag => "-fringe_resid_0", dtype => "float" },
        { name => "FRINGE_RESID_ERR_0", type => "rms",   flag => "-fringe_resid_1", dtype => "float" },
@@ -92,5 +92,5 @@
 my $stats = PS::IPP::Metadata::Stats->new($STATS); # Stats parser
 
-my $BINNED_STATS = 
+my $BINNED_STATS =
    [
        { name => "ROBUST_STDEV",   type => "rms",   flag => "-bin_stdev" },
@@ -100,17 +100,17 @@
 # Flags to specify the particular detrend to use
 use constant DETRENDS => {
-    'bias'     => '-bias',	# Specify the bias frame
-    'dark'     => '-dark',	# Specify the dark frame
-    'shutter'  => '-shutter',	# Specify the shutter frame
-    'flat'     => '-flat',	# Specify the flat frame
-    'domeflat' => '-flat',	# Specify the flat frame
-    'skyflat'  => '-flat',	# Specify the flat frame
-    'fringe'   => '-fringe',	# Specify the fringe frame
-    'mask'     => '-mask',	# Specify the mask frame
-    'darkmask' => '-mask',	# Specify the mask frame
-    'flatmask' => '-mask',	# Specify the mask frame
+    'bias'     => '-bias',      # Specify the bias frame
+    'dark'     => '-dark',      # Specify the dark frame
+    'shutter'  => '-shutter',   # Specify the shutter frame
+    'flat'     => '-flat',      # Specify the flat frame
+    'domeflat' => '-flat',      # Specify the flat frame
+    'skyflat'  => '-flat',      # Specify the flat frame
+    'fringe'   => '-fringe',    # Specify the fringe frame
+    'mask'     => '-mask',      # Specify the mask frame
+    'darkmask' => '-mask',      # Specify the mask frame
+    'flatmask' => '-mask',      # Specify the mask frame
 };
 
-use constant DELETE_STATS => 0;	# Delete the statistics file when done?
+use constant DELETE_STATS => 0; # Delete the statistics file when done?
 
 # Look for programs we need
@@ -119,7 +119,7 @@
 my $ppImage = can_run('ppImage') or (warn "Can't find ppImage" and $missing_tools = 1);
 my $ppStats = can_run('ppStats') or (warn "Can't find ppStats" and $missing_tools = 1);
-if ($missing_tools) { 
+if ($missing_tools) {
     warn("Can't find required tools.");
-    exit($PS_EXIT_CONFIG_ERROR); 
+    exit($PS_EXIT_CONFIG_ERROR);
 }
 $ppImage .= " -dbname $dbname" if defined $dbname;
@@ -147,17 +147,18 @@
     $command .= " -stats $outputStats";
     $command .= " -tracedest $traceDest -log $logDest";
+    $command .= " -dbname $dbname" if defined $dbname;
 
     # Detrend to use in processing
     if (lc($mode) ne 'verify') {
-	my $detFlag = DETRENDS->{lc($det_type)};
-	&my_die("Unrecognised detrend type: $det_type", $det_id, $iter, $exp_id, $class_id, $PS_EXIT_PROG_ERROR) unless defined $detFlag;
-	$command .= " $detFlag $detrend";
+        my $detFlag = DETRENDS->{lc($det_type)};
+        &my_die("Unrecognised detrend type: $det_type", $det_id, $iter, $exp_id, $class_id, $PS_EXIT_PROG_ERROR) unless defined $detFlag;
+        $command .= " $detFlag $detrend";
     }
 
     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
-	run(command => $command, verbose => $verbose);
+        run(command => $command, verbose => $verbose);
     unless ($success) {
-	$error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
-	&my_die("Unable to perform ppImage: $error_code", $det_id, $iter, $exp_id, $class_id, $error_code);
+        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
+        &my_die("Unable to perform ppImage: $error_code", $det_id, $iter, $exp_id, $class_id, $error_code);
     }
     &my_die("Couldn't find expected output file: $outputName", $det_id, $iter, $exp_id, $class_id, $PS_EXIT_SYS_ERROR) unless -f $ipprc->file_resolve($outputName);
@@ -167,5 +168,5 @@
 
     # Load the raw output stats file
-    my $statsFile;		# File handle
+    my $statsFile;              # File handle
     open $statsFile, $ipprc->file_resolve($outputStats) or &my_die("Can't open statistics file $outputStats: $!", $det_id, $iter, $exp_id, $class_id, $PS_EXIT_SYS_ERROR);
     my @contents = <$statsFile>; # Contents of file
@@ -173,5 +174,5 @@
 
     # Parse the stats file contents into a metadata
-    my $mdcParser = PS::IPP::Metadata::Config->new;	# Parser for metadata config files
+    my $mdcParser = PS::IPP::Metadata::Config->new;     # Parser for metadata config files
     my $metadata = $mdcParser->parse(join "", @contents) or &my_die("Unable to parse metadata config doc", $det_id, $iter, $exp_id, $class_id, $PS_EXIT_PROG_ERROR);
 
@@ -182,8 +183,8 @@
     $command = "$ppStats -recipe PPSTATS RESIDUAL $bin2Name";
     ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
-	run(command => $command, verbose => $verbose);
+        run(command => $command, verbose => $verbose);
     unless ($success) {
-	$error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
-	&my_die("Unable to perform ppStats: $error_code", $det_id, $iter, $exp_id, $class_id, $error_code);
+        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
+        &my_die("Unable to perform ppStats: $error_code", $det_id, $iter, $exp_id, $class_id, $error_code);
     }
 
@@ -211,9 +212,9 @@
 unless ($no_update) {
     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
-	run(command => $command, verbose => $verbose);
+        run(command => $command, verbose => $verbose);
     unless ($success) {
-	$error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
-	warn("Unable to perform dettool -addresidimfile: $error_code\n");
-	exit($error_code);
+        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
+        warn("Unable to perform dettool -addresidimfile: $error_code\n");
+        exit($error_code);
     }
 } else {
@@ -224,6 +225,6 @@
 {
     my $msg = shift; # Warning message on die
-    my $det_id = shift;		# Detrend identifier
-    my $iter = shift;		# Iteration
+    my $det_id = shift;         # Detrend identifier
+    my $iter = shift;           # Iteration
     my $exp_id = shift; # Exposure tag
     my $class_id = shift; # Class identifier
@@ -232,11 +233,11 @@
     carp($msg);
     if (defined $det_id and defined $iter and defined $exp_id and not $no_update) {
-	my $command = "$dettool -addresidimfile";
-	$command .= " -det_id $det_id";
-	$command .= " -iteration $iter";
-	$command .= " -exp_id $exp_id";
-	$command .= " -class_id $class_id";
-	$command .= " -code $exit_code";
-	$command .= " -dbname $dbname" if defined $dbname;
+        my $command = "$dettool -addresidimfile";
+        $command .= " -det_id $det_id";
+        $command .= " -iteration $iter";
+        $command .= " -exp_id $exp_id";
+        $command .= " -class_id $class_id";
+        $command .= " -code $exit_code";
+        $command .= " -dbname $dbname" if defined $dbname;
         system ($command);
     }
