Index: trunk/ippScripts/scripts/detrend_resid.pl
===================================================================
--- trunk/ippScripts/scripts/detrend_resid.pl	(revision 11829)
+++ trunk/ippScripts/scripts/detrend_resid.pl	(revision 11837)
@@ -34,5 +34,5 @@
 
 my ($det_id, $iter, $exp_tag, $class_id, $det_type, $detrend,
-        $input_uri, $camera, $mode, $dbname, $workdir, $no_update);
+        $input_uri, $camera, $mode, $dbname, $workdir, $no_update, $no_op);
 GetOptions(
     'det_id|d=s'        => \$det_id,
@@ -48,4 +48,5 @@
     'workdir|w=s'       => \$workdir,	# Working directory, for output files
     'no-update'         => \$no_update,
+    'no-op'             => \$no_op,
 ) or pod2usage( 2 );
 
@@ -138,5 +139,6 @@
 
 # Run ppImage
-{
+my $stats = PS::IPP::Metadata::Stats->new(); # Stats parser
+unless ($no_op) {
     my $command = "$ppImage -file $input_uri $outputRoot -recipe PPIMAGE $recipe" .
 	" -stat $outputStats "; # Command to run ppImage
@@ -159,9 +161,6 @@
     &my_die("Couldn't find expected output file: $bin1Name", $det_id, $iter, $exp_tag, $class_id, $PS_EXIT_SYS_ERROR) unless -f $bin1Name;
     &my_die("Couldn't find expected output file: $bin2Name", $det_id, $iter, $exp_tag, $class_id, $PS_EXIT_SYS_ERROR) unless -f $bin2Name;
-}
-
-# Get the statistics on the residual image
-my $stats;			# Statistics from ppImage
-{
+
+    # Get the statistics on the residual image
     my $statsFile;		# File handle
     open $statsFile, $outputStats or &my_die("Can't open statistics file $outputStats: $!", $det_id, $iter, $exp_tag, $class_id, $PS_EXIT_SYS_ERROR);
@@ -179,18 +178,14 @@
 $bin1Name = $ipprc->convert_filename_relative( $bin1Name );
 $bin2Name = $ipprc->convert_filename_relative( $bin2Name );
+
+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');
+
 unless ($no_update) {
     my $command = "$dettool -addresidimfile -det_id $det_id -iteration $iter -exp_tag $exp_tag " .
 	"-class_id $class_id -recip $recipe -uri $outputName -b1_uri $outputRoot"; # Command to run dettool
-    $command .= " -bg " . $stats->bg_mean();
+    $command .= " -bg $bg -bg_stdev $bg_stdev -bg_mean_stdev $bg_mean_stdev";
     $command .= " -dbname $dbname" if defined $dbname;
-
-    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();
 
     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
