Index: trunk/ippScripts/scripts/detrend_stack.pl
===================================================================
--- trunk/ippScripts/scripts/detrend_stack.pl	(revision 17241)
+++ trunk/ippScripts/scripts/detrend_stack.pl	(revision 17250)
@@ -81,4 +81,13 @@
 my $stats = PS::IPP::Metadata::Stats->new($STATS); # Stats parser
 
+# Look for programs we need
+my $missing_tools;
+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) { 
+    warn("Can't find required tools.");
+    exit($PS_EXIT_CONFIG_ERROR); 
+}
+
 # The output file rule name depends on the detrend type
 my $FILERULES = { 'FLATMASK' => 'PPMERGE.OUTPUT.MASK',
@@ -96,12 +105,4 @@
 &my_die("Unrecognised detrend type: $det_type", $det_id, $iter, $class_id, $PS_EXIT_SYS_ERROR) unless defined $output_filerule;
 
-# Look for programs we need
-my $missing_tools;
-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) { 
-    warn("Can't find required tools.");
-    exit($PS_EXIT_CONFIG_ERROR); 
-}
 
 # Get list of files to stack
