Index: trunk/ippScripts/scripts/detrend_stack.pl
===================================================================
--- trunk/ippScripts/scripts/detrend_stack.pl	(revision 11830)
+++ trunk/ippScripts/scripts/detrend_stack.pl	(revision 11837)
@@ -33,5 +33,5 @@
 use Pod::Usage qw( pod2usage );
 
-my ($det_id, $iter, $class_id, $det_type, $camera, $dbname, $workdir, $no_update);
+my ($det_id, $iter, $class_id, $det_type, $camera, $dbname, $workdir, $no_update, $no_op);
 GetOptions(
     'det_id|d=s'        => \$det_id,
@@ -42,5 +42,6 @@
     'dbname|d=s'        => \$dbname, # Database name
     'workdir|w=s'       => \$workdir,	# Working directory, for output files
-    'no-update'         => \$no_update
+    'no-update'         => \$no_update,
+    'no-op'             => \$no_op,
 ) or pod2usage( 2 );
 
@@ -112,5 +113,6 @@
 my $outputStats = $outputRoot . '.stats'; # Statistics name
 
-{
+my $stats = PS::IPP::Metadata::Stats->new(); # Stats parser
+unless ($no_op) {
     my $command = "$ppMerge $outputStack"; # Command to run
     foreach my $file (@$files) {
@@ -122,5 +124,5 @@
     $command .= ' -type ' . uc($det_type); # Type of stacking to perform
     $command .= " -stats $outputStats";	# Statistics output filename
-
+    
     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
 	run(command => $command, verbose => 1);
@@ -131,14 +133,11 @@
     &my_die("Unable to find expected output file: $outputStack\n", $det_id, $iter, $class_id, $PS_EXIT_SYS_ERROR) unless -f $outputStack;
     &my_die("Unable to find expected output file: $outputStats\n", $det_id, $iter, $class_id, $PS_EXIT_SYS_ERROR) unless -f $outputStats;
-}
 
-# Get the statistics on the stacked image
-my $stats;			# Statistics from ppMerge
-{
+    # Get the statistics on the stacked image
     open(my $statsFile, "$outputStats") or
 	&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 $metadata = $mdcParser->parse($contents) or
@@ -149,4 +148,8 @@
 }
 
+my $bg = ($stats->bg_mean() or 'NAN');
+my $bg_stdev = ($stats->bg_stdev() or 'NAN');
+my $bg_mean_stdev = ($stats->bg_mean_stdev() or 'NAN');
+
 # Add the resultant into the database
 $outputStack = $ipprc->convert_filename_relative($outputStack);
@@ -154,13 +157,7 @@
     my $command = "$dettool -addstacked -det_id $det_id -iteration $iter -class_id $class_id" .
 	" -uri $outputStack -recip $recipe"; # Command to run
-    $command .= ' -bg ' . $stats->bg_mean();
-    if (defined($stats->bg_mean_stdev())) {
-    $command .= ' -bg_mean_stdev ' . $stats->bg_mean_stdev();
-    } else {
-	# May be undefined if there is only a single imfile
-	$command .= ' -bg_mean_stdev 0';
-    }
-    $command .= ' -bg_stdev ' . $stats->bg_stdev();
+    $command .= " -bg $bg -bg_stdev $bg_stdev -bg_mean_stdev $bg_mean_stdev";
     $command .= " -dbname $dbname" if defined $dbname;
+
     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
 	run(command => $command, verbose => 1);
