Index: trunk/ippScripts/scripts/detrend_stack.pl
===================================================================
--- trunk/ippScripts/scripts/detrend_stack.pl	(revision 17762)
+++ trunk/ippScripts/scripts/detrend_stack.pl	(revision 17941)
@@ -36,5 +36,5 @@
     'outroot|w=s'       => \$outroot,   # output file base name
     'dbname|d=s'        => \$dbname, # Database name
-    'reduction=s'       => \$reduction,	# Reduction class for processing
+    'reduction=s'       => \$reduction, # Reduction class for processing
     'verbose'           => \$verbose,   # Print to stdout
     'save-temps'        => \$save_temps, # Save temporary files?
@@ -44,10 +44,10 @@
 
 pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV;
-pod2usage( -msg => "Required options: --det_id --iteration --class_id --det_type --camera --outroot", 
-	   -exitval => 3) unless 
-    defined $det_id   and 
-    defined $iter     and 
-    defined $class_id and 
-    defined $det_type and 
+pod2usage( -msg => "Required options: --det_id --iteration --class_id --det_type --camera --outroot",
+           -exitval => 3) unless
+    defined $det_id   and
+    defined $iter     and
+    defined $class_id and
+    defined $det_type and
     defined $camera   and
     defined $outroot;
@@ -64,6 +64,6 @@
 # XXX -bg_mean_stdev should take stdev of bg_mean if bg_mean_stdev == 0     (B)
 # XXX  (A) if imfile.Ncomp > 1, (B) if imfile.Ncomp == 1
-my $STATS = 
-   [   
+my $STATS =
+   [
        #          KEYWORD                 STATISTIC          CHIPTOOL FLAG
        { name => "ROBUST_MEDIAN",  type => "mean",  flag => "-bg",             dtype => "float" },
@@ -77,21 +77,21 @@
 my $dettool = can_run('dettool') or (warn "Can't find dettool" and $missing_tools = 1);
 my $ppMerge = can_run('ppMerge') or (warn "Can't find ppMerge" 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);
 }
 
 # The output file rule name depends on the detrend type
 my $FILERULES = { 'FLATMASK' => 'PPMERGE.OUTPUT.MASK',
-		  'DARKMASK' => 'PPMERGE.OUTPUT.MASK',
-		  'MASK'     => 'PPMERGE.OUTPUT.MASK',
-		  'BIAS'     => 'PPMERGE.OUTPUT.BIAS',
-		  'DARK'     => 'PPMERGE.OUTPUT.DARK',
-		  'SHUTTER'  => 'PPMERGE.OUTPUT.SHUTTER',
-		  'FLAT'     => 'PPMERGE.OUTPUT.FLAT',
-		  'DOMEFLAT' => 'PPMERGE.OUTPUT.FLAT',
-		  'SKYFLAT'  => 'PPMERGE.OUTPUT.FLAT',
-		  'FRINGE'   => 'PPMERGE.OUTPUT.FRINGE',
-	      };
+                  'DARKMASK' => 'PPMERGE.OUTPUT.MASK',
+                  'MASK'     => 'PPMERGE.OUTPUT.MASK',
+                  'BIAS'     => 'PPMERGE.OUTPUT.BIAS',
+                  'DARK'     => 'PPMERGE.OUTPUT.DARK',
+                  'SHUTTER'  => 'PPMERGE.OUTPUT.SHUTTER',
+                  'FLAT'     => 'PPMERGE.OUTPUT.FLAT',
+                  'DOMEFLAT' => 'PPMERGE.OUTPUT.FLAT',
+                  'SKYFLAT'  => 'PPMERGE.OUTPUT.FLAT',
+                  'FRINGE'   => 'PPMERGE.OUTPUT.FRINGE',
+              };
 my $output_filerule = $FILERULES->{$det_type}; # File rule for output
 &my_die("Unrecognised detrend type: $det_type", $det_id, $iter, $class_id, $PS_EXIT_SYS_ERROR) unless defined $output_filerule;
@@ -107,15 +107,15 @@
 
     ( $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 dettool -processedimfile: $error_code", $det_id, $iter, $class_id, $error_code);
-    }
-
-    my $mdcParser = PS::IPP::Metadata::Config->new;	# Parser for metadata config files
+        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
+        &my_die("Unable to perform dettool -processedimfile: $error_code", $det_id, $iter, $class_id, $error_code);
+    }
+
+    my $mdcParser = PS::IPP::Metadata::Config->new;     # Parser for metadata config files
     my $metadata = $mdcParser->parse(join "", @$stdout_buf) or
-	&my_die("Unable to parse metadata config doc", $det_id, $iter, $class_id, $PS_EXIT_PROG_ERROR);
-    $files = parse_md_list($metadata) or 
-	&my_die("Unable to parse metadata list", $det_id, $iter, $class_id, $PS_EXIT_PROG_ERROR);
+        &my_die("Unable to parse metadata config doc", $det_id, $iter, $class_id, $PS_EXIT_PROG_ERROR);
+    $files = parse_md_list($metadata) or
+        &my_die("Unable to parse metadata list", $det_id, $iter, $class_id, $PS_EXIT_PROG_ERROR);
 }
 
@@ -129,5 +129,5 @@
     $num++;
 
-    my $image = $file->{uri};	# Image name
+    my $image = $file->{uri};   # Image name
     my $mask = $ipprc->filename( "PPIMAGE.OUTPUT.MASK", $file->{path_base}, $class_id ); # Mask name
     my $weight = $ipprc->filename( "PPIMAGE.OUTPUT.WEIGHT", $file->{path_base}, $class_id ); # Weight name
@@ -137,8 +137,8 @@
 
     if ($ipprc->file_exists( $mask )) {
-	print $listFile "\tMASK\tSTR\t" . $mask . "\n";
+        print $listFile "\tMASK\tSTR\t" . $mask . "\n";
     }
     if ($ipprc->file_exists( $weight )) {
-	print $listFile "\tWEIGHT\tSTR\t" . $weight . "\n";
+        print $listFile "\tWEIGHT\tSTR\t" . $weight . "\n";
     }
 
@@ -166,15 +166,16 @@
 $command .= " -recipe PPMERGE $recipe";
 $command .= ' -type ' . uc($det_type); # Type of stacking to perform
-$command .= " -stats $outputStats";	# Statistics output filename
+$command .= " -stats $outputStats";     # Statistics output filename
 $command .= " -recipe PPSTATS CHIPSTATS";
 $command .= " -tracedest $traceDest -log $logDest";
+$command .= " -dbname $dbname" if defined $dbname;
 
 # Stack the files
 unless ($no_op) {
     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 ppMerge: $error_code", $det_id, $iter, $class_id, $error_code);
+        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
+        &my_die("Unable to perform ppMerge: $error_code", $det_id, $iter, $class_id, $error_code);
     }
     &my_die("Unable to find expected output file: $outputStack\n", $det_id, $iter, $class_id, $PS_EXIT_SYS_ERROR) unless -f $ipprc->file_resolve($outputStack);
@@ -185,14 +186,14 @@
     # Get the statistics on the stacked image
     open(my $statsFile, $ipprc->file_resolve("$outputStats")) or
-	&my_die("Can't open statistics file $outputStats: $!", $det_id, $iter, $class_id, $PS_EXIT_SYS_ERROR);
+        &my_die("Can't open statistics file $outputStats: $!", $det_id, $iter, $class_id, $PS_EXIT_SYS_ERROR);
     my $contents = do { local $/; <$statsFile> }; # Contents of file
     close($statsFile);
-    
-    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($contents) or
-	&my_die("Unable to parse metadata config doc", $det_id, $iter, $class_id, $PS_EXIT_SYS_ERROR);
+        &my_die("Unable to parse metadata config doc", $det_id, $iter, $class_id, $PS_EXIT_SYS_ERROR);
 
     $stats->parse($metadata)  or
-	&my_die("Unable to find all values in statistics output.", $det_id, $iter, $class_id, $PS_EXIT_SYS_ERROR);
+        &my_die("Unable to find all values in statistics output.", $det_id, $iter, $class_id, $PS_EXIT_SYS_ERROR);
 }
 
@@ -209,9 +210,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 -addstacked: $error_code\n");
-	exit($error_code);
+        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
+        warn("Unable to perform dettool -addstacked: $error_code\n");
+        exit($error_code);
     }
 } else {
@@ -222,6 +223,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 $class_id = shift; # Class identifier
     my $exit_code = shift; # Exit code to add
@@ -229,11 +230,11 @@
     carp($msg);
     if (defined $det_id and defined $iter and defined $class_id and not $no_update) {
-	my $command = "$dettool -addstacked";
-	$command .= " -det_id $det_id";
-	$command .= " -iteration $iter";
-	$command .= " -class_id $class_id";
-	$command .= " -code $exit_code";
-	$command .= " -dbname $dbname" if defined $dbname;
-	system ($command);
+        my $command = "$dettool -addstacked";
+        $command .= " -det_id $det_id";
+        $command .= " -iteration $iter";
+        $command .= " -class_id $class_id";
+        $command .= " -code $exit_code";
+        $command .= " -dbname $dbname" if defined $dbname;
+        system ($command);
     }
     exit $exit_code;
