Index: trunk/ippScripts/scripts/detrend_norm_apply.pl
===================================================================
--- trunk/ippScripts/scripts/detrend_norm_apply.pl	(revision 17941)
+++ trunk/ippScripts/scripts/detrend_norm_apply.pl	(revision 17943)
@@ -28,27 +28,27 @@
      $no_update, $no_op );
 GetOptions(
-    'det_id|d=s'        => \$det_id,     # Detrend ID				
-    'iteration|n=s'	=> \$iter,	 # Iteration				
-    'class_id|i=s'      => \$class_id,	 # Class ID				
-    'value|v=s'		=> \$value,	 # Value to multiple (for normalisation)	
-    'input_uri|u=s'     => \$input_uri,	 # Input file				
-    'camera|c=s'        => \$camera,	 # Camera				
-    'det_type|t=s'      => \$det_type,	 # Detrend type				
+    'det_id|d=s'        => \$det_id,     # Detrend ID
+    'iteration|n=s'     => \$iter,       # Iteration
+    'class_id|i=s'      => \$class_id,   # Class ID
+    'value|v=s'         => \$value,      # Value to multiple (for normalisation)
+    'input_uri|u=s'     => \$input_uri,  # Input file
+    'camera|c=s'        => \$camera,     # Camera
+    'det_type|t=s'      => \$det_type,   # Detrend type
     'outroot|w=s'       => \$outroot,    # output file base name
-    'dbname|d=s'        => \$dbname,	 # Database name				
+    'dbname|d=s'        => \$dbname,     # Database name
     'verbose'           => \$verbose,   # Print to stdout
-    'no-update'         => \$no_update,	 # Don't update the database		
-    'no-op'             => \$no_op,	 # Don't do any operations               
+    'no-update'         => \$no_update,  # Don't update the database
+    'no-op'             => \$no_op,      # Don't do any operations
     ) or pod2usage( 2 );
-    
+
 pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV;
 pod2usage( -msg => "Required options: --det_id --iteration --class_id --value --input_uri --camera --det_type --outroot",
-	   -exitval => 3) unless 
-    defined $det_id    and 
-    defined $iter      and 
-    defined $class_id  and 
-    defined $value     and 
-    defined $input_uri and 
-    defined $camera    and 
+           -exitval => 3) unless
+    defined $det_id    and
+    defined $iter      and
+    defined $class_id  and
+    defined $value     and
+    defined $input_uri and
+    defined $camera    and
     defined $det_type  and
     defined $outroot;
@@ -65,6 +65,6 @@
 
 # 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" },
@@ -78,7 +78,7 @@
 my $dettool = can_run('dettool') or (warn "Can't find dettool" and $missing_tools = 1);
 my $ppImage = can_run('ppImage') or (warn "Can't find ppImage" 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);
 }
 
@@ -100,5 +100,5 @@
 my $statsName = $ipprc->filename("PPIMAGE.STATS", $outroot, $class_id) or &my_die("Missing entry from camera config", $det_id, $iter, $class_id, $PS_EXIT_CONFIG_ERROR);
 my $traceDest = $ipprc->filename("TRACE.IMFILE",  $outroot, $class_id) or &my_die("Missing entry from camera config", $det_id, $iter, $class_id, $PS_EXIT_CONFIG_ERROR);
-my $logDest   = $ipprc->filename("LOG.IMFILE", 	  $outroot, $class_id) or &my_die("Missing entry from camera config", $det_id, $iter, $class_id, $PS_EXIT_CONFIG_ERROR);
+my $logDest   = $ipprc->filename("LOG.IMFILE",    $outroot, $class_id) or &my_die("Missing entry from camera config", $det_id, $iter, $class_id, $PS_EXIT_CONFIG_ERROR);
 
 # Run normalisation
@@ -112,10 +112,11 @@
     $command .= ' -isdark' if lc($det_type) eq 'dark';
     $command .= " -tracedest $traceDest -log $logDest";
+    $command .= " -dbname $dbname" if defined $dbname;
 
     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, $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, $class_id, $error_code);
     }
     &my_die("Can't find expected output file: $output",    $det_id, $iter, $class_id, $PS_EXIT_SYS_ERROR) unless -f $ipprc->file_resolve($output);
@@ -123,5 +124,5 @@
     &my_die("Can't find expected output file: $b2name",    $det_id, $iter, $class_id, $PS_EXIT_SYS_ERROR) unless -f $ipprc->file_resolve($b2name);
     &my_die("Can't find expected output file: $statsName", $det_id, $iter, $class_id, $PS_EXIT_SYS_ERROR) unless -f $ipprc->file_resolve($statsName);
-    
+
     # Get the statistics on the normalised image
     my $statsFile; # File handle
@@ -132,13 +133,13 @@
 
     # parse the statistics MDC file
-    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);
     unless ($metadata) {
-	&my_die("Unable to parse metadata config", $det_id, $iter, $class_id, $PS_EXIT_PROG_ERROR);
+        &my_die("Unable to parse metadata config", $det_id, $iter, $class_id, $PS_EXIT_PROG_ERROR);
     }
 
     # extract the stats from the metadata
     unless ($stats->parse($metadata)) {
-	&my_die("Unable to find all values in statistics output.", $det_id, $iter, $class_id, $PS_EXIT_PROG_ERROR);
+        &my_die("Unable to find all values in statistics output.", $det_id, $iter, $class_id, $PS_EXIT_PROG_ERROR);
     }
 }
@@ -157,9 +158,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 -addnormalizedimfile: $error_code\n");
-	exit($error_code);
+        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
+        warn("Unable to perform dettool -addnormalizedimfile: $error_code\n");
+        exit($error_code);
     }
 } else {
@@ -169,18 +170,18 @@
 sub my_die
 {
-    my $msg = shift;		# Warning message on die
-    my $det_id = shift;		# Detrend identifier
-    my $iter = shift;		# Iteration
-    my $class_id = shift;	# Class identifier
-    my $exit_code = shift;	# Exit code to add
+    my $msg = shift;            # Warning message on die
+    my $det_id = shift;         # Detrend identifier
+    my $iter = shift;           # Iteration
+    my $class_id = shift;       # Class identifier
+    my $exit_code = shift;      # Exit code to add
 
     carp($msg);
     if (defined $det_id and defined $iter and defined $class_id and not $no_update) {
-	my $command = "$dettool -addnormalizedimfile";
-	$command .= " -det_id $det_id";
-	$command .= " -iteration $iter";
-	$command .= " -class_id $class_id";
-	$command .= " -code $exit_code";
-	$command .= " -dbname $dbname" if defined $dbname;
+        my $command = "$dettool -addnormalizedimfile";
+        $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);
     }
Index: trunk/ippScripts/scripts/detrend_norm_exp.pl
===================================================================
--- trunk/ippScripts/scripts/detrend_norm_exp.pl	(revision 17941)
+++ trunk/ippScripts/scripts/detrend_norm_exp.pl	(revision 17943)
@@ -28,23 +28,23 @@
 my ($det_id, $iter, $det_type, $camera, $outroot, $dbname, $reduction, $verbose, $no_update, $no_op, $save_temps);
 GetOptions(
-	   'det_id|d=s'        => \$det_id,
-	   'iteration|i=s'     => \$iter,
-	   'camera|c=s'        => \$camera,
-	   'det_type|t=s'      => \$det_type,
-	   'outroot|w=s'       => \$outroot,   # output file base name
-	   'dbname|d=s'        => \$dbname, # Database name
-	   'reduction|=s'      => \$reduction,
+           'det_id|d=s'        => \$det_id,
+           'iteration|i=s'     => \$iter,
+           'camera|c=s'        => \$camera,
+           'det_type|t=s'      => \$det_type,
+           'outroot|w=s'       => \$outroot,   # output file base name
+           'dbname|d=s'        => \$dbname, # Database name
+           'reduction|=s'      => \$reduction,
            'verbose'           => \$verbose,   # Print to stdout
-	   'no-update'         => \$no_update,
-	   'no-op'             => \$no_op,
-	   'save-temps'        => \$save_temps, # Save temporary files?
-	   ) or pod2usage( 2 );
+           'no-update'         => \$no_update,
+           'no-op'             => \$no_op,
+           'save-temps'        => \$save_temps, # Save temporary files?
+           ) or pod2usage( 2 );
 
 pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV;
 pod2usage( -msg => "Required options: --det_id --iteration --camera --det_type --outroot",
-	   -exitval => 3) unless 
-    defined $det_id   and 
-    defined $iter     and 
-    defined $camera   and 
+           -exitval => 3) unless
+    defined $det_id   and
+    defined $iter     and
+    defined $camera   and
     defined $det_type and
     defined $outroot;
@@ -65,12 +65,12 @@
 # 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 = 
-    [   
-	#          KEYWORD                 STATISTIC          CHIPTOOL FLAG
-	{ name => "bg",             type => "mean",  flag => "-bg",            dtype => "float" },
-	{ name => "bg",             type => "stdev", flag => "-bg_mean_stdev", dtype => "float" },
-	{ name => "bg_stdev",       type => "rms",   flag => "-bg_stdev",      dtype => "float" },
-	# { name => "bg_mean_stdev",  type => "rms",   flag => "-bg_mean_stdev" },
-	];
+my $STATS =
+    [
+        #          KEYWORD                 STATISTIC          CHIPTOOL FLAG
+        { name => "bg",             type => "mean",  flag => "-bg",            dtype => "float" },
+        { name => "bg",             type => "stdev", flag => "-bg_mean_stdev", dtype => "float" },
+        { name => "bg_stdev",       type => "rms",   flag => "-bg_stdev",      dtype => "float" },
+        # { name => "bg_mean_stdev",  type => "rms",   flag => "-bg_mean_stdev" },
+        ];
 my $stats = PS::IPP::Metadata::Stats->new($STATS); # Stats parser
 
@@ -79,7 +79,7 @@
 my $dettool = can_run('dettool') or (warn "Can't find dettool" and $missing_tools = 1);
 my $ppImage = can_run('ppImage') or (warn "Can't find ppImage" 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);
 }
 
@@ -90,22 +90,22 @@
     $command .= " -dbname $dbname" if defined $dbname;
     ( $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 get list of normalized imfiles from dettool: $error_code", $det_id, $iter, $error_code);
+        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
+        &my_die("Unable to get list of normalized imfiles from dettool: $error_code", $det_id, $iter, $error_code);
     }
 
     # convert stdout to 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 "", @$stdout_buf) or
-	&my_die("Unable to parse metadata config doc", $det_id, $iter, $PS_EXIT_PROG_ERROR);
+        &my_die("Unable to parse metadata config doc", $det_id, $iter, $PS_EXIT_PROG_ERROR);
 
     # parse the file info in the metadata
     $files = parse_md_list($metadata) or
-	&my_die("Unable to parse metadata list", $det_id, $iter, $PS_EXIT_PROG_ERROR);
+        &my_die("Unable to parse metadata list", $det_id, $iter, $PS_EXIT_PROG_ERROR);
 
     # parse the stats in the metadata
     unless ($stats->parse($metadata)) {
-	&my_die("Unable to find all values in statistics output.\n", $det_id, $iter, $PS_EXIT_PROG_ERROR);
+        &my_die("Unable to find all values in statistics output.\n", $det_id, $iter, $PS_EXIT_PROG_ERROR);
     }
 }
@@ -134,12 +134,14 @@
     # Make the jpeg for binning 1
     $command = "$ppImage -list $list1Name $outroot -recipe PPIMAGE $recipe1"; # Command to run
+    $command .= " -dbname $dbname" if defined $dbname;
     ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
-	run(command => $command, verbose => $verbose);
+        run(command => $command, verbose => $verbose);
     &my_die("Unable to find expected output file: $jpeg1Name", $det_id, $iter, $PS_EXIT_SYS_ERROR) unless -f $ipprc->file_resolve($jpeg1Name);
-    
+
     # Make the jpeg for binning 2
     $command = "$ppImage -list $list2Name $outroot -recipe PPIMAGE $recipe2"; # Command to run
+    $command .= " -dbname $dbname" if defined $dbname;
     ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
-	run(command => $command, verbose => $verbose);
+        run(command => $command, verbose => $verbose);
     &my_die("Unable to find expected output file: $jpeg2Name", $det_id, $iter, $PS_EXIT_SYS_ERROR) unless -f $ipprc->file_resolve($jpeg2Name);
 
@@ -158,8 +160,8 @@
 unless ($no_update) {
     ( $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 -addnormalizedexp: $error_code", $det_id, $iter, $error_code);
+        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
+        &my_die("Unable to perform dettool -addnormalizedexp: $error_code", $det_id, $iter, $error_code);
     }
 } else {
@@ -170,15 +172,15 @@
 {
     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 $exit_code = shift; # Exit code to add
 
     carp($msg);
     if (defined $det_id and defined $iter and not $no_update) {
-	my $command = "$dettool -addnormalizedexp";
-	$command .= " -det_id $det_id";
-	$command .= " -iteration $iter";
-	$command .= " -code $exit_code";
-	$command .= " -dbname $dbname" if defined $dbname;
+        my $command = "$dettool -addnormalizedexp";
+        $command .= " -det_id $det_id";
+        $command .= " -iteration $iter";
+        $command .= " -code $exit_code";
+        $command .= " -dbname $dbname" if defined $dbname;
         system ($command);
     }
Index: trunk/ippScripts/scripts/detrend_process_exp.pl
===================================================================
--- trunk/ippScripts/scripts/detrend_process_exp.pl	(revision 17941)
+++ trunk/ippScripts/scripts/detrend_process_exp.pl	(revision 17943)
@@ -45,9 +45,9 @@
 pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV;
 pod2usage( -msg => "Required options: --det_id --det_type --exp_id --exp_tag --camera --outroot",
-	   -exitval => 3) unless 
-    defined $det_id   and 
-    defined $det_type and 
-    defined $exp_id   and 
-    defined $exp_tag  and 
+           -exitval => 3) unless
+    defined $det_id   and
+    defined $det_type and
+    defined $exp_id   and
+    defined $exp_tag  and
     defined $camera   and
     defined $outroot;
@@ -68,6 +68,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 => "bg",             type => "mean",  flag => "-bg",            dtype => "float" },
@@ -82,7 +82,7 @@
 my $dettool = can_run('dettool') or (warn "Can't find dettool" and $missing_tools = 1);
 my $ppImage = can_run('ppImage') or (warn "Can't find ppImage" 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);
 }
 
@@ -93,22 +93,22 @@
     $command .= " -dbname $dbname" if defined $dbname;
     ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
-	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, $exp_id, $error_code);
+        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, $exp_id, $error_code);
     }
 
     # convert stdout to 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 "", @$stdout_buf) or
-	&my_die("Unable to parse metadata config doc", $det_id, $exp_id, $PS_EXIT_PROG_ERROR);
+        &my_die("Unable to parse metadata config doc", $det_id, $exp_id, $PS_EXIT_PROG_ERROR);
 
     # parse the file info in the metadata
     $files = parse_md_list($metadata) or
-	&my_die("Unable to parse metadata list", $det_id, $exp_id, $PS_EXIT_PROG_ERROR);
+        &my_die("Unable to parse metadata list", $det_id, $exp_id, $PS_EXIT_PROG_ERROR);
 
     # parse the stats in the metadata
     unless ($stats->parse($metadata)) {
-	&my_die("Unable to find all values in statistics output.\n", $det_id, $exp_id, $PS_EXIT_PROG_ERROR);
+        &my_die("Unable to find all values in statistics output.\n", $det_id, $exp_id, $PS_EXIT_PROG_ERROR);
     }
 }
@@ -138,19 +138,21 @@
     # Make the jpeg for binning 1
     $command = "$ppImage -list $list1Name $outroot -recipe PPIMAGE $recipe1"; # Command to run
-    ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
-	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, $exp_id, $error_code);
+    $command .= " -dbname $dbname" if defined $dbname;
+    ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
+        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, $exp_id, $error_code);
     }
     &my_die("Unable to find expected output file: $jpeg1", $det_id, $exp_id, $PS_EXIT_SYS_ERROR) unless -f $ipprc->file_resolve($jpeg1);
-    
+
     # Make the jpeg for binning 2
     $command = "$ppImage -list $list2Name $outroot -recipe PPIMAGE $recipe2"; # Command to run
-    ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
-	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, $exp_id, $error_code);
+    $command .= " -dbname $dbname" if defined $dbname;
+    ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
+        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, $exp_id, $error_code);
     }
     &my_die("Unable to find expected output file: $jpeg2", $det_id, $exp_id, $PS_EXIT_SYS_ERROR) unless -f $ipprc->file_resolve($jpeg2);
@@ -168,9 +170,9 @@
 unless ($no_update) {
     ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
-	run(command => $command, verbose => $verbose);
-    unless ($success) {
-	$error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
-	warn("Unable to perform dettool -addprocessedexp: $error_code");
-	exit($error_code);
+        run(command => $command, verbose => $verbose);
+    unless ($success) {
+        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
+        warn("Unable to perform dettool -addprocessedexp: $error_code");
+        exit($error_code);
     }
 } else {
@@ -181,5 +183,5 @@
 {
     my $msg = shift; # Warning message on die
-    my $det_id = shift;		# Detrend identifier
+    my $det_id = shift;         # Detrend identifier
     my $exp_id = shift; # Exposure tag
     my $exit_code = shift; # Exit code to add
@@ -187,9 +189,9 @@
     carp($msg);
     if (defined $det_id and defined $exp_id and not $no_update) {
-	my $command = "$dettool -addprocessedexp";
-	$command .= " -det_id $det_id";
-	$command .= " -exp_id $exp_id";
-	$command .= " -code $exit_code";
-	$command .= " -dbname $dbname" if defined $dbname;
+        my $command = "$dettool -addprocessedexp";
+        $command .= " -det_id $det_id";
+        $command .= " -exp_id $exp_id";
+        $command .= " -code $exit_code";
+        $command .= " -dbname $dbname" if defined $dbname;
         system ($command);
     }
Index: trunk/ippScripts/scripts/detrend_reject_imfile.pl
===================================================================
--- trunk/ippScripts/scripts/detrend_reject_imfile.pl	(revision 17941)
+++ trunk/ippScripts/scripts/detrend_reject_imfile.pl	(revision 17943)
@@ -3,7 +3,7 @@
 # this program has two jobs:
 # 1: for the given exp_tag, generate the binned & mosaiced JPEG images
-# 2: examine the collection of per-imfile statistics and reject.  At the moment, 
+# 2: examine the collection of per-imfile statistics and reject.  At the moment,
 #    this program (and the database) only allows rejection at the exposure level,
-#    not at the imfile level. 
+#    not at the imfile level.
 
 use Carp;
@@ -32,5 +32,5 @@
 
 use Getopt::Long qw( GetOptions :config auto_help auto_version gnu_getopt ); # option parsing
-use Pod::Usage qw( pod2usage ); 
+use Pod::Usage qw( pod2usage );
 
 # parse the command-line options
@@ -38,29 +38,29 @@
      $verbose, $no_update, $no_op, $save_temps );
 GetOptions(
-	   'det_id|d=s'        => \$det_id,
-	   'iteration=s'       => \$iter,
-	   'exp_id|e=s'        => \$exp_id,
-	   'exp_tag|=s'        => \$exp_tag,
-	   'det_type|t=s'      => \$det_type,
-	   'camera=s'          => \$camera,
-	   'outroot|w=s'       => \$outroot,   # output file base name
-	   'filter=s'          => \$filter,
-	   'reject'            => \$reject,
-	   'dbname|d=s'        => \$dbname, # Database name
-	   'reduction|=s'      => \$reduction,
-	   'verbose'           => \$verbose,   # Print to stdout
-	   'no-update'         => \$no_update,
-	   'no-op'             => \$no_op,
-	   'save-temps'        => \$save_temps, # Save temporary files?
-	   ) or pod2usage( 2 );
+           'det_id|d=s'        => \$det_id,
+           'iteration=s'       => \$iter,
+           'exp_id|e=s'        => \$exp_id,
+           'exp_tag|=s'        => \$exp_tag,
+           'det_type|t=s'      => \$det_type,
+           'camera=s'          => \$camera,
+           'outroot|w=s'       => \$outroot,   # output file base name
+           'filter=s'          => \$filter,
+           'reject'            => \$reject,
+           'dbname|d=s'        => \$dbname, # Database name
+           'reduction|=s'      => \$reduction,
+           'verbose'           => \$verbose,   # Print to stdout
+           'no-update'         => \$no_update,
+           'no-op'             => \$no_op,
+           'save-temps'        => \$save_temps, # Save temporary files?
+           ) or pod2usage( 2 );
 
 pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV;
 pod2usage( -msg => "Required options: --det_id --iteration --exp_id --exp_tag --det_type --camera --outroot",
-	   -exitval => 3) unless 
-    defined $det_id   and 
-    defined $iter     and 
-    defined $exp_id   and 
-    defined $exp_tag  and 
-    defined $det_type and 
+           -exitval => 3) unless
+    defined $det_id   and
+    defined $iter     and
+    defined $exp_id   and
+    defined $exp_tag  and
+    defined $det_type and
     defined $camera   and
     defined $outroot;
@@ -82,20 +82,20 @@
 # 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 => "bg",             type => "mean",  flag => "-bg",            dtype => "float" },
-	{ name => "bg_mean_stdev",  type => "stdev", flag => "-bg_mean_stdev", dtype => "float" },
-	{ name => "bg_stdev",       type => "rms",   flag => "-bg_stdev",      dtype => "float" },  
-	{ name => "bg_skewness",    type => "mean",  flag => "-bg_skewness",   dtype => "float" },  
-	{ name => "bg_kurtosis",    type => "mean",  flag => "-bg_kurtosis",   dtype => "float" },  
-	{ name => "bin_stdev",      type => "rms",   flag => "-bin_stdev",     dtype => "float" },
-	{ name => "fringe_0",       type => "mean",  flag => "-fringe_0",      dtype => "float" },
-	{ name => "fringe_1",       type => "rms",   flag => "-fringe_1",      dtype => "float" },
-	{ name => "fringe_0",       type => "stdev", flag => "-fringe_2",      dtype => "float" },
-	{ name => "user_1",         type => "mean",  flag => "-user_1",	       dtype => "float" }, # fringe residual
-	{ name => "user_2",         type => "rms",   flag => "-user_2",	       dtype => "float" }, # fringe residual
-	{ name => "user_1",         type => "stdev", flag => "-user_3",	       dtype => "float" }, # fringe residual
-	];
+        #          KEYWORD                 STATISTIC          CHIPTOOL FLAG
+        { name => "bg",             type => "mean",  flag => "-bg",            dtype => "float" },
+        { name => "bg_mean_stdev",  type => "stdev", flag => "-bg_mean_stdev", dtype => "float" },
+        { name => "bg_stdev",       type => "rms",   flag => "-bg_stdev",      dtype => "float" },
+        { name => "bg_skewness",    type => "mean",  flag => "-bg_skewness",   dtype => "float" },
+        { name => "bg_kurtosis",    type => "mean",  flag => "-bg_kurtosis",   dtype => "float" },
+        { name => "bin_stdev",      type => "rms",   flag => "-bin_stdev",     dtype => "float" },
+        { name => "fringe_0",       type => "mean",  flag => "-fringe_0",      dtype => "float" },
+        { name => "fringe_1",       type => "rms",   flag => "-fringe_1",      dtype => "float" },
+        { name => "fringe_0",       type => "stdev", flag => "-fringe_2",      dtype => "float" },
+        { name => "user_1",         type => "mean",  flag => "-user_1",        dtype => "float" }, # fringe residual
+        { name => "user_2",         type => "rms",   flag => "-user_2",        dtype => "float" }, # fringe residual
+        { name => "user_1",         type => "stdev", flag => "-user_3",        dtype => "float" }, # fringe residual
+        ];
 my $stats = PS::IPP::Metadata::Stats->new($STATS); # Stats parser
 
@@ -104,7 +104,7 @@
 my $dettool = can_run('dettool') or (warn "Can't find dettool" and $missing_tools = 1);
 my $ppImage = can_run('ppImage') or (warn "Can't find ppImage" 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);
 }
 
@@ -119,20 +119,20 @@
     $command .= " -dbname $dbname" if defined $dbname;
     ( $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 -residimfile: $error_code\n");
-	exit($error_code);
+        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
+        warn("Unable to perform dettool -residimfile: $error_code\n");
+        exit($error_code);
     }
     # XXX report an error message if stdout_buf is empty
 
     # Parse the stdout buffer into a metadata
-    my $mdcParser = PS::IPP::Metadata::Config->new;	
+    my $mdcParser = PS::IPP::Metadata::Config->new;
     my $metadata = $mdcParser->parse(join "", @$stdout_buf) or
-	&my_die("Unable to parse metadata config doc", $det_id, $iter, $exp_id, $PS_EXIT_PROG_ERROR);
+        &my_die("Unable to parse metadata config doc", $det_id, $iter, $exp_id, $PS_EXIT_PROG_ERROR);
 
     # parse the file info in the metadata
     $files = parse_md_list($metadata) or
-	&my_die("Unable to parse metadata list", $det_id, $iter, $exp_id, $PS_EXIT_PROG_ERROR);
+        &my_die("Unable to parse metadata list", $det_id, $iter, $exp_id, $PS_EXIT_PROG_ERROR);
 
     # Parse the statistics on the residual image
@@ -172,19 +172,21 @@
     # Make the jpeg for binning 1
     $command = "$ppImage -list $list1Name $outroot -recipe PPIMAGE $recipe1"; # Command to run
+    $command .= " -dbname $dbname" if defined $dbname;
     ( $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 run ppImage: $error_code", $det_id, $iter, $exp_id, $error_code);
+        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
+        &my_die("Unable to run ppImage: $error_code", $det_id, $iter, $exp_id, $error_code);
     }
     &my_die("Unable to find expected output file: $jpeg1Name", $det_id, $iter, $exp_id, $PS_EXIT_SYS_ERROR) unless -f $ipprc->file_resolve($jpeg1Name);
-    
+
     # Make the jpeg for binning 2
     $command = "$ppImage -list $list2Name $outroot -recipe PPIMAGE $recipe2"; # Command to run
+    $command .= " -dbname $dbname" if defined $dbname;
     ( $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 run ppImage: $error_code", $det_id, $iter, $exp_id, $error_code);
+        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
+        &my_die("Unable to run ppImage: $error_code", $det_id, $iter, $exp_id, $error_code);
     }
     &my_die("Unable to find expected output file: $jpeg2Name", $det_id, $iter, $exp_id, $PS_EXIT_SYS_ERROR) unless -f $ipprc->file_resolve($jpeg2Name);
@@ -217,5 +219,5 @@
 foreach my $file (@$files) {
     my $name      = $file->{class_id};
-    my $mean      = $file->{bg};	# Mean for this imfile
+    my $mean      = $file->{bg};        # Mean for this imfile
     my $stdev     = $file->{bg_stdev}; # Stdev for this imfile
     my $skewness  = $file->{bg_skewness}; # Skewness for this imfile
@@ -227,7 +229,7 @@
     my $flux;
     if ($file->{exp_time} == 0.0) {
-	$flux = $mean;
-    } else {
-	$flux = $mean / $file->{exp_time};
+        $flux = $mean;
+    } else {
+        $flux = $mean / $file->{exp_time};
     }
     push @fluxes, $flux;
@@ -243,13 +245,13 @@
     # 0.0 for a bias).   in general, use with ADDITIVE components
     if ($reject_imfile_mean > 0) {
-	if (abs($mean) > $reject_imfile_mean * $stdev) {
-	    print $logFile "Rejecting exposure based on bad imfile mean for $name: ";
-	    $reject = 1;
-	} else {
-	    print $logFile "Imfile mean for $name meets requirements: ";
-	}
-	print $logFile "$mean vs $reject_imfile_mean * $stdev\n";
+        if (abs($mean) > $reject_imfile_mean * $stdev) {
+            print $logFile "Rejecting exposure based on bad imfile mean for $name: ";
+            $reject = 1;
+        } else {
+            print $logFile "Imfile mean for $name meets requirements: ";
+        }
+        print $logFile "$mean vs $reject_imfile_mean * $stdev\n";
     }  else {
-	print $logFile "No rejection on imfile mean for $name\n";
+        print $logFile "No rejection on imfile mean for $name\n";
     }
 
@@ -260,13 +262,13 @@
     # for a bias).  in general, use with ADDITIVE components
     if ($reject_imfile_flux > 0) {
-	if (abs($flux) > $reject_imfile_flux) {
-	    print $logFile "Rejecting exposure based on bad imfile flux for $name: ";
-	    $reject = 1;
-	} else {
-	    print $logFile "Imfile flux for $name meets requirements: ";
-	}
-	print $logFile "$flux vs $reject_imfile_flux\n";
+        if (abs($flux) > $reject_imfile_flux) {
+            print $logFile "Rejecting exposure based on bad imfile flux for $name: ";
+            $reject = 1;
+        } else {
+            print $logFile "Imfile flux for $name meets requirements: ";
+        }
+        print $logFile "$flux vs $reject_imfile_flux\n";
     }  else {
-	print $logFile "No rejection on imfile flux for $name\n";
+        print $logFile "No rejection on imfile flux for $name\n";
     }
 
@@ -274,14 +276,14 @@
     # larger than the limit
     if ($reject_imfile_stdev > 0) {
-	if ($stdev > $reject_imfile_stdev) {
-	    print $logFile "Rejecting exposure based on bad imfile stdev for $name: ";
-	    $reject = 1;
-	} else {
-	    print $logFile "Imfile stdev for $name meets requirements: ";
-	}
-	print $logFile "$stdev vs $reject_imfile_stdev\n";
-
-    } else {
-	print $logFile "No rejection on imfile stdev for $name\n";
+        if ($stdev > $reject_imfile_stdev) {
+            print $logFile "Rejecting exposure based on bad imfile stdev for $name: ";
+            $reject = 1;
+        } else {
+            print $logFile "Imfile stdev for $name meets requirements: ";
+        }
+        print $logFile "$stdev vs $reject_imfile_stdev\n";
+
+    } else {
+        print $logFile "No rejection on imfile stdev for $name\n";
     }
 
@@ -289,14 +291,14 @@
     # larger than the limit
     if ($reject_imfile_skewness > 0) {
-	if ($stdev > $reject_imfile_skewness) {
-	    print $logFile "Rejecting exposure based on bad imfile skewness for $name: ";
-	    $reject = 1;
-	} else {
-	    print $logFile "Imfile skewness for $name meets requirements: ";
-	}
-	print $logFile "$skewness vs $reject_imfile_skewness\n";
-
-    } else {
-	print $logFile "No rejection on imfile skewness for $name\n";
+        if ($stdev > $reject_imfile_skewness) {
+            print $logFile "Rejecting exposure based on bad imfile skewness for $name: ";
+            $reject = 1;
+        } else {
+            print $logFile "Imfile skewness for $name meets requirements: ";
+        }
+        print $logFile "$skewness vs $reject_imfile_skewness\n";
+
+    } else {
+        print $logFile "No rejection on imfile skewness for $name\n";
     }
 
@@ -304,14 +306,14 @@
     # larger than the limit
     if ($reject_imfile_kurtosis > 0) {
-	if ($stdev > $reject_imfile_kurtosis) {
-	    print $logFile "Rejecting exposure based on bad imfile kurtosis for $name: ";
-	    $reject = 1;
-	} else {
-	    print $logFile "Imfile kurtosis for $name meets requirements: ";
-	}
-	print $logFile "$kurtosis vs $reject_imfile_kurtosis\n";
-
-    } else {
-	print $logFile "No rejection on imfile kurtosis for $name\n";
+        if ($stdev > $reject_imfile_kurtosis) {
+            print $logFile "Rejecting exposure based on bad imfile kurtosis for $name: ";
+            $reject = 1;
+        } else {
+            print $logFile "Imfile kurtosis for $name meets requirements: ";
+        }
+        print $logFile "$kurtosis vs $reject_imfile_kurtosis\n";
+
+    } else {
+        print $logFile "No rejection on imfile kurtosis for $name\n";
     }
 
@@ -319,13 +321,13 @@
     # component means is larger than the limit
     if ($reject_imfile_meanstdev > 0) {
-	if ($meanStdev > $reject_imfile_meanstdev) {
-	    print $logFile "Rejecting exposure based on bad imfile mean stdev for $name: ";
-	    $reject = 1;
-	} else {
-	    print $logFile "Imfile mean stdev for $name meets requirements: ";
-	}
-	print $logFile "$meanStdev vs $reject_imfile_meanstdev\n";
-    } else {
-	print $logFile "No rejection on imfile mean stdev for $name\n";
+        if ($meanStdev > $reject_imfile_meanstdev) {
+            print $logFile "Rejecting exposure based on bad imfile mean stdev for $name: ";
+            $reject = 1;
+        } else {
+            print $logFile "Imfile mean stdev for $name meets requirements: ";
+        }
+        print $logFile "$meanStdev vs $reject_imfile_meanstdev\n";
+    } else {
+        print $logFile "No rejection on imfile mean stdev for $name\n";
     }
 
@@ -333,15 +335,15 @@
     # the mean counts / total pixel variance) of the imfile component
     # means are less than the limit.  this test is sensible for images
-    # which have finite residual flux such as a flat-field image.  
+    # which have finite residual flux such as a flat-field image.
     if ($reject_imfile_snr > 0) {
-	if ($mean < $stdev * $reject_imfile_snr) {
-	    print $logFile "Rejecting exposure based on bad imfile S/N for $name: ";
-	    $reject = 1;
-	} else {
-	    print $logFile "Imfile S/N for $name meets requirements: ";
-	}
-	print $logFile "mean: $mean vs stdev*SNlimit: " . $stdev * $reject_imfile_snr . "\n";
-    } else {
-	print $logFile "No rejection on imfile S/N for $name\n";
+        if ($mean < $stdev * $reject_imfile_snr) {
+            print $logFile "Rejecting exposure based on bad imfile S/N for $name: ";
+            $reject = 1;
+        } else {
+            print $logFile "Imfile S/N for $name meets requirements: ";
+        }
+        print $logFile "mean: $mean vs stdev*SNlimit: " . $stdev * $reject_imfile_snr . "\n";
+    } else {
+        print $logFile "No rejection on imfile S/N for $name\n";
     }
 
@@ -351,32 +353,32 @@
     # have finite residual flux such as a flat-field image.
     if ($reject_imfile_bin_stdev > 0) {
-	if ($binStdev > $reject_imfile_bin_stdev) {
-	    print $logFile "Rejecting exposure based on bad imfile binned stdev for $name: ";
-	    $reject = 1;
-	} else {
-	    print $logFile "Imfile binned stdev for $name meets requirements: ";
-	}
-	print $logFile "$binStdev vs $reject_imfile_bin_stdev\n";
-    } else {
-	print $logFile "No rejection on imfile binned stdev for $name\n";
+        if ($binStdev > $reject_imfile_bin_stdev) {
+            print $logFile "Rejecting exposure based on bad imfile binned stdev for $name: ";
+            $reject = 1;
+        } else {
+            print $logFile "Imfile binned stdev for $name meets requirements: ";
+        }
+        print $logFile "$binStdev vs $reject_imfile_bin_stdev\n";
+    } else {
+        print $logFile "No rejection on imfile binned stdev for $name\n";
     }
     if ($reject_imfile_bin_snr > 0) {
-	if ($mean < $binStdev * $reject_imfile_bin_snr) {
-	    print $logFile "Rejecting exposure based on bad imfile binned S/N for $name: ";
-	    $reject = 1;
-	} else {
-	    print $logFile "Imfile binned S/N for $name meets requirements: ";
-	}
-	print $logFile "mean: $mean vs binStdev*SNlimit: " . $binStdev * $reject_imfile_bin_snr . "\n";
-    } else {
-	print $logFile "No rejection on imfile binned S/N for $name\n";
+        if ($mean < $binStdev * $reject_imfile_bin_snr) {
+            print $logFile "Rejecting exposure based on bad imfile binned S/N for $name: ";
+            $reject = 1;
+        } else {
+            print $logFile "Imfile binned S/N for $name meets requirements: ";
+        }
+        print $logFile "mean: $mean vs binStdev*SNlimit: " . $binStdev * $reject_imfile_bin_snr . "\n";
+    } else {
+        print $logFile "No rejection on imfile binned S/N for $name\n";
     }
 }
 
 # basic ensemble stats
-my $mean      	       = $stats->value_for_flag ("-bg");
-my $meanStdev 	       = $stats->value_for_flag ("-bg_mean_stdev");
-my $stdev     	       = $stats->value_for_flag ("-bg_stdev");
-my $binStdev  	       = $stats->value_for_flag ("-bin_stdev");
+my $mean               = $stats->value_for_flag ("-bg");
+my $meanStdev          = $stats->value_for_flag ("-bg_mean_stdev");
+my $stdev              = $stats->value_for_flag ("-bg_stdev");
+my $binStdev           = $stats->value_for_flag ("-bin_stdev");
 my $fringe_mean        = $stats->value_for_flag ("-fringe_0");
 my $fringe_err         = $stats->value_for_flag ("-fringe_1");
@@ -387,7 +389,7 @@
 
 # other stats (flux depends on bg and exp_time)
-my $fluxStats = Statistics::Descriptive::Sparse->new();	# Statistics calculator for means
+my $fluxStats = Statistics::Descriptive::Sparse->new(); # Statistics calculator for means
 $fluxStats->add_data(@fluxes);
-my $flux = $fluxStats->mean();	# Mean of the imfile means
+my $flux = $fluxStats->mean();  # Mean of the imfile means
 
 # other stats
@@ -406,13 +408,13 @@
     # for a bias).  in general, use with ADDITIVE components
     if ($reject_exp_mean > 0) {
-	if (abs($mean) > $reject_exp_mean * $stdev) {
-	    print $logFile "Rejecting exposure based on bad mean counts: ";
-	    $reject = 1;
-	} else {
-	    print $logFile "Exposure mean counts meets requirements: ";
-	}
-	print $logFile "mean: $mean, stdev: $stdev (limit is: " . $reject_exp_mean * $stdev . ") \n";
-    } else {
-	print $logFile "No rejection for exp mean\n";
+        if (abs($mean) > $reject_exp_mean * $stdev) {
+            print $logFile "Rejecting exposure based on bad mean counts: ";
+            $reject = 1;
+        } else {
+            print $logFile "Exposure mean counts meets requirements: ";
+        }
+        print $logFile "mean: $mean, stdev: $stdev (limit is: " . $reject_exp_mean * $stdev . ") \n";
+    } else {
+        print $logFile "No rejection for exp mean\n";
     }
 
@@ -423,13 +425,13 @@
     # for a bias).  in general, use with ADDITIVE components
     if ($reject_exp_flux > 0) {
-	if (abs($flux) > $reject_exp_flux * $stdev) {
-	    print $logFile "Rejecting exposure based on bad mean flux: ";
-	    $reject = 1;
-	} else {
-	    print $logFile "Exposure mean flux meets requirements: ";
-	}
-	print $logFile "flux: $flux, stdev: $stdev (limit is: " . $reject_exp_flux * $stdev . ")\n";
-    } else {
-	print $logFile "No rejection for exp mean\n";
+        if (abs($flux) > $reject_exp_flux * $stdev) {
+            print $logFile "Rejecting exposure based on bad mean flux: ";
+            $reject = 1;
+        } else {
+            print $logFile "Exposure mean flux meets requirements: ";
+        }
+        print $logFile "flux: $flux, stdev: $stdev (limit is: " . $reject_exp_flux * $stdev . ")\n";
+    } else {
+        print $logFile "No rejection for exp mean\n";
     }
 
@@ -437,13 +439,13 @@
     # limit
     if ($reject_exp_stdev > 0) {
-	if ($stdev > $reject_exp_stdev) {
-	    print $logFile "Rejecting exposure based on bad stdev: ";
-	    $reject = 1;
-	} else {
-	    print $logFile "Exposure stdev meets requirements: ";
-	}
-	print $logFile "$stdev vs $reject_exp_stdev\n";
-    } else {
-	print $logFile "No rejection for exp stdev\n";
+        if ($stdev > $reject_exp_stdev) {
+            print $logFile "Rejecting exposure based on bad stdev: ";
+            $reject = 1;
+        } else {
+            print $logFile "Exposure stdev meets requirements: ";
+        }
+        print $logFile "$stdev vs $reject_exp_stdev\n";
+    } else {
+        print $logFile "No rejection for exp stdev\n";
     }
 
@@ -451,50 +453,50 @@
     # than the limit
     if ($reject_exp_meanstdev > 0) {
-	if ($meanStdev > $reject_exp_meanstdev) {
-	    print $logFile "Rejecting exposure based on bad mean stdev: ";
-	    $reject = 1;
-	} else {
-	    print $logFile "Exposure mean stdev meets requirements: ";
-	}
-	print $logFile "$meanStdev vs $reject_exp_meanstdev\n";
-    } else {
-	print $logFile "No rejection for exp mean stdev\n";
+        if ($meanStdev > $reject_exp_meanstdev) {
+            print $logFile "Rejecting exposure based on bad mean stdev: ";
+            $reject = 1;
+        } else {
+            print $logFile "Exposure mean stdev meets requirements: ";
+        }
+        print $logFile "$meanStdev vs $reject_exp_meanstdev\n";
+    } else {
+        print $logFile "No rejection for exp mean stdev\n";
     }
 
     # reject if the signal-to-noise is insufficient
     if ($reject_exp_snr > 0) {
-	if (abs($mean) < abs($stdev * $reject_exp_snr)) {
-	    print $logFile "Rejecting exposure based on poor S/N: \n";
-	    $reject = 1;
-	} else {
-	    print $logFile "Exposure S/N meets requirements: \n";
-	}
-	print $logFile "signal: $mean vs noise: $stdev (s/n limit is: $reject_exp_snr)\n";
-    } else {
-	print $logFile "No rejection for exp S/N\n";
+        if (abs($mean) < abs($stdev * $reject_exp_snr)) {
+            print $logFile "Rejecting exposure based on poor S/N: \n";
+            $reject = 1;
+        } else {
+            print $logFile "Exposure S/N meets requirements: \n";
+        }
+        print $logFile "signal: $mean vs noise: $stdev (s/n limit is: $reject_exp_snr)\n";
+    } else {
+        print $logFile "No rejection for exp S/N\n";
     }
     # reject if the exposure ensemble stdev is deviant
     if ($reject_exp_bin_stdev > 0) {
-	if ($binStdev > $reject_exp_bin_stdev) {
-	    print $logFile "Rejecting exposure based on bad binned stdev: ";
-	    $reject = 1;
-	} else {
-	    print $logFile "Exposure binned stdev meets requirements: ";
-	}
-	print $logFile "$stdev vs $reject_exp_bin_stdev\n";
-    } else {
-	print $logFile "No rejection for exp binned stdev\n";
+        if ($binStdev > $reject_exp_bin_stdev) {
+            print $logFile "Rejecting exposure based on bad binned stdev: ";
+            $reject = 1;
+        } else {
+            print $logFile "Exposure binned stdev meets requirements: ";
+        }
+        print $logFile "$stdev vs $reject_exp_bin_stdev\n";
+    } else {
+        print $logFile "No rejection for exp binned stdev\n";
     }
     # reject if the signal-to-noise is insufficient
     if ($reject_exp_bin_snr > 0) {
-	if (abs($mean) < abs($binStdev * $reject_exp_bin_snr)) {
-	    print $logFile "Rejecting exposure based on poor binned S/N: \n";
-	    $reject = 1;
-	} else {
-	    print $logFile "Exposure binned S/N meets requirements: \n";
-	}
-	print $logFile "signal: $mean vs noise: $binStdev (s/n limit is: $reject_exp_bin_snr)\n";
-    } else {
-	print $logFile "No rejection for exp binned S/N\n";
+        if (abs($mean) < abs($binStdev * $reject_exp_bin_snr)) {
+            print $logFile "Rejecting exposure based on poor binned S/N: \n";
+            $reject = 1;
+        } else {
+            print $logFile "Exposure binned S/N meets requirements: \n";
+        }
+        print $logFile "signal: $mean vs noise: $binStdev (s/n limit is: $reject_exp_bin_snr)\n";
+    } else {
+        print $logFile "No rejection for exp binned S/N\n";
     }
 
@@ -510,9 +512,9 @@
 unless ($no_update) {
     ( $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 -addresidexp: $error_code\n");
-	exit($error_code);
+        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
+        warn("Unable to perform dettool -addresidexp: $error_code\n");
+        exit($error_code);
     }
 } else {
@@ -531,6 +533,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 $exit_code = shift; # Exit code to add
@@ -538,10 +540,10 @@
     carp($msg);
     if (defined $det_id and defined $iter and defined $exp_id and not $no_update) {
-	my $command = "$dettool -addresidexp";
-	$command .= " -det_id $det_id";
-	$command .= " -iteration $iter";
-	$command .= " -exp_id $exp_id";
-	$command .= " -code $exit_code";
-	$command .= " -dbname $dbname" if defined $dbname;
+        my $command = "$dettool -addresidexp";
+        $command .= " -det_id $det_id";
+        $command .= " -iteration $iter";
+        $command .= " -exp_id $exp_id";
+        $command .= " -code $exit_code";
+        $command .= " -dbname $dbname" if defined $dbname;
         system ($command);
     }
@@ -552,12 +554,12 @@
 sub rejection_limit
 {
-    my $name = shift;		# Rejection limit to 
-    my $type = shift;		# Type of exposure
-    my $filter = shift;		# Filter
+    my $name = shift;           # Rejection limit to
+    my $type = shift;           # Type of exposure
+    my $filter = shift;         # Filter
 
     my $value = $ipprc->rejection( $name, $det_type, $filter );
     if (not defined $value) {
-	$filter = "(no filter)" if not defined $filter;
-	die "Unable to determine $name rejection limit for $det_type with $filter.\n";
+        $filter = "(no filter)" if not defined $filter;
+        die "Unable to determine $name rejection limit for $det_type with $filter.\n";
     }
 
@@ -589,5 +591,5 @@
 ## 5) is the mean stdev > limit (poor images)
 ## 6) calculate the ensemble stdev (rms) of remaining (excluding rejects)
-## 7) is the ensemble stdev > limit 
+## 7) is the ensemble stdev > limit
 
 ## for flats, the value used for stdev should be the fractional stdev
Index: trunk/ippScripts/scripts/diff_skycell.pl
===================================================================
--- trunk/ippScripts/scripts/diff_skycell.pl	(revision 17941)
+++ trunk/ippScripts/scripts/diff_skycell.pl	(revision 17943)
@@ -178,4 +178,5 @@
     $command .= " -photometry";
     $command .= " -tracedest $traceDest -log $logDest";
+    $command .= " -dbname $dbname" if defined $dbname;
 
     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
Index: trunk/ippScripts/scripts/stack_skycell.pl
===================================================================
--- trunk/ippScripts/scripts/stack_skycell.pl	(revision 17941)
+++ trunk/ippScripts/scripts/stack_skycell.pl	(revision 17943)
@@ -173,4 +173,5 @@
     $command .= " -photometry";
     $command .= " -tracedest $traceDest -log $logDest";
+    $command .= " -dbname $dbname" if defined $dbname;
 
     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
Index: trunk/ippScripts/scripts/warp_skycell.pl
===================================================================
--- trunk/ippScripts/scripts/warp_skycell.pl	(revision 17941)
+++ trunk/ippScripts/scripts/warp_skycell.pl	(revision 17943)
@@ -181,4 +181,5 @@
     $command .= " -psf";        # Turn on PSF determination
     $command .= " -tracedest $traceDest -log $logDest";
+    $command .= " -dbname $dbname" if defined $dbname;
 
     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
