Index: trunk/ippScripts/scripts/detrend_create_resid.pl
===================================================================
--- trunk/ippScripts/scripts/detrend_create_resid.pl	(revision 8976)
+++ trunk/ippScripts/scripts/detrend_create_resid.pl	(revision 8983)
@@ -120,5 +120,10 @@
 	"-b2_uri $bin2Name"; # Command to run dettool
     $command .= " -bg " . $stats->bg_mean();
-    $command .= " -bg_stdev " . $stats->bg_stdev();
+    if (defined($stats->bg_stdev())) {
+	$command .= " -bg_stdev " . $stats->bg_stdev();
+    } else {
+	# May be undefined if there is only a single imfile
+	$command .= ' -bg_stdev 0';
+    }
     $command .= " -bg_mean_stdev " . $stats->bg_mean_stdev();
 
Index: trunk/ippScripts/scripts/detrend_process.pl
===================================================================
--- trunk/ippScripts/scripts/detrend_process.pl	(revision 8976)
+++ trunk/ippScripts/scripts/detrend_process.pl	(revision 8983)
@@ -99,5 +99,10 @@
 	"-class_id $class_id -recip $recipe -uri $outputImage"; # Command to run dettool
     $command .= " -bg " . $stats->bg_mean();
-    $command .= " -bg_stdev " . $stats->bg_stdev();
+    if (defined($stats->bg_stdev())) {
+	$command .= " -bg_stdev " . $stats->bg_stdev();
+    } else {
+	# May be undefined if there's only a single imfile
+	$command .= " -bg_stdev 0";
+    }
     $command .= " -bg_mean_stdev " . $stats->bg_mean_stdev();
 
Index: trunk/ippScripts/scripts/detrend_stack.pl
===================================================================
--- trunk/ippScripts/scripts/detrend_stack.pl	(revision 8976)
+++ trunk/ippScripts/scripts/detrend_stack.pl	(revision 8983)
@@ -111,5 +111,10 @@
 	" -uri $output -recip $recipe";	# Command to run
     $command .= ' -bg ' . $stats->bg_mean();
+    if (defined($stats->bg_stdev())) {
     $command .= ' -bg_stdev ' . $stats->bg_stdev();
+    } else {
+	# May be undefined if there is only a single imfile
+	$command .= ' -bg_stdev 0';
+    }
     $command .= ' -bg_mean_stdev ' . $stats->bg_mean_stdev();
     $command .= ' -pleasenormalize' if NORMALISE()->{$det_type};
Index: trunk/ippScripts/scripts/phase0imfile.pl
===================================================================
--- trunk/ippScripts/scripts/phase0imfile.pl	(revision 8976)
+++ trunk/ippScripts/scripts/phase0imfile.pl	(revision 8983)
@@ -103,7 +103,12 @@
         $command .= " " . VARIABLES->{$variable} . " " . ($stats->data($variable))->{mean};
     }
-    
+
     $command .= " " . P0TOOL_BG_MEAN() . " " . $stats->bg_mean();
-    $command .= " " . P0TOOL_BG_STDEV() . " " . $stats->bg_stdev();
+    if (defined($stats->bg_stdev())) {
+	$command .= " " . P0TOOL_BG_STDEV() . " " . $stats->bg_stdev();
+    } else {
+	# Will not be defined if there is only a single imfile
+	$command .= " " . P0TOOL_BG_STDEV() . " 0";
+    }
     $command .= " " . P0TOOL_BG_MEAN_STDEV() . " " . $stats->bg_mean_stdev();
  
