Index: trunk/ippScripts/scripts/detrend_norm_apply.pl
===================================================================
--- trunk/ippScripts/scripts/detrend_norm_apply.pl	(revision 19012)
+++ trunk/ippScripts/scripts/detrend_norm_apply.pl	(revision 19071)
@@ -62,5 +62,4 @@
 
 my $RECIPE_PPIMAGE = 'PPIMAGE_N'; # Recipe to use with ppImage
-my $RECIPE_PPSTATS = 'CHIPSTATS'; # Recipe to use with ppStats
 
 # Define which detrend types we normalise
@@ -117,4 +116,6 @@
 my $outFile = ($det_type_real eq "mask") ? 'PPIMAGE.OUTPUT.DETMASK' : 'PPIMAGE.OUTPUT';; # XXXX something of a hack (too many places to control things...)
 
+my $RECIPE_PPSTATS = ($det_type_real eq "dark") ? 'DARKSTATS' : 'CHIPSTATS';; # XXXX something of a hack (too many places to control things...)
+
 my $output    = $ipprc->filename($outFile,        $outroot, $class_id) or &my_die("Missing entry from camera config", $det_id, $iter, $class_id, $PS_EXIT_CONFIG_ERROR);
 my $b1name    = $ipprc->filename("PPIMAGE.BIN1",  $outroot, $class_id) or &my_die("Missing entry from camera config", $det_id, $iter, $class_id, $PS_EXIT_CONFIG_ERROR);
Index: trunk/ippScripts/scripts/detrend_stack.pl
===================================================================
--- trunk/ippScripts/scripts/detrend_stack.pl	(revision 19012)
+++ 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
