Index: trunk/ippScripts/scripts/detrend_stack.pl
===================================================================
--- trunk/ippScripts/scripts/detrend_stack.pl	(revision 18877)
+++ trunk/ippScripts/scripts/detrend_stack.pl	(revision 19071)
@@ -25,5 +25,5 @@
 use Pod::Usage qw( pod2usage );
 
-my ( $det_id, $iter, $class_id, $det_type, $camera, $outroot, $dbname, $reduction, $verbose, $save_temps,
+my ( $det_id, $iter, $class_id, $det_type, $camera, $outroot, $dbname, $reduction, $threads, $verbose, $save_temps,
      $no_update, $no_op, $redirect );
 GetOptions(
@@ -36,4 +36,5 @@
     'dbname|d=s'        => \$dbname,    # Database name
     'reduction=s'       => \$reduction, # Reduction class for processing
+    'threads=s'         => \$threads,
     'verbose'           => \$verbose,   # Print to stdout
     'save-temps'        => \$save_temps, # Save temporary files?
@@ -42,5 +43,4 @@
     'redirect-output'   => \$redirect,
 ) or pod2usage( 2 );
-
 
 pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV;
@@ -106,4 +106,19 @@
 &my_die("Unrecognised detrend type: $det_type", $det_id, $iter, $class_id, $PS_EXIT_SYS_ERROR) unless defined $output_filerule;
 
+# The output file rule name depends on the detrend type
+my $STATRECIPES = { 'FLATMASK'     => 'CHIPSTATS',
+                   'DARKMASK'     => 'CHIPSTATS',
+                   'MASK'         => 'CHIPSTATS',
+                   'BIAS'         => 'CHIPSTATS',
+                   'DARK'         => 'DARKSTATS',
+                   'DARK_PREMASK' => 'DARKSTATS',
+                   'SHUTTER'      => 'DARKSTATS',
+                   'FLAT'         => 'CHIPSTATS',
+                   'FLAT_PREMASK' => 'CHIPSTATS',
+                   'DOMEFLAT'     => 'CHIPSTATS',
+                   'SKYFLAT'      => 'CHIPSTATS',
+                   'FRINGE'       => 'CHIPSTATS',
+              };
+my $statrecipe = $STATRECIPES->{$det_type}; # File rule for output
 
 # Get list of files to stack
@@ -176,7 +191,8 @@
 $command .= ' -type ' . uc($det_type); # Type of stacking to perform
 $command .= " -stats $outputStats";     # Statistics output filename
-$command .= " -recipe PPSTATS CHIPSTATS";
+$command .= " -recipe PPSTATS $statrecipe";
 $command .= " -tracedest $traceDest -log $logDest";
 $command .= " -dbname $dbname" if defined $dbname;
+$command .= " -threads $threads" if defined $threads;
 
 # Stack the files
