Index: trunk/ippScripts/scripts/detrend_norm_apply.pl
===================================================================
--- trunk/ippScripts/scripts/detrend_norm_apply.pl	(revision 18107)
+++ trunk/ippScripts/scripts/detrend_norm_apply.pl	(revision 18128)
@@ -64,8 +64,25 @@
 my $RECIPE_PPSTATS = 'CHIPSTATS'; # Recipe to use with ppStats
 
-my $isMaskType = 0;
-if (lc($det_type) eq "mask") { $isMaskType = 1; }
-if (lc($det_type) eq "darkmask") { $isMaskType = 1; }
-if (lc($det_type) eq "flatmask") { $isMaskType = 1; }
+# Define which detrend types we normalise
+use constant DETTYPE => {
+    'bias'     	       => 'bias',
+    'dark'     	       => 'dark',   
+    'dark_premask'     => 'dark',
+    'shutter'  	       => 'shutter',
+    'flat'     	       => 'flat',
+    'domeflat' 	       => 'flat',
+    'skyflat'  	       => 'flat',   
+    'flat_premask'     => 'flat',
+    'domeflat_premask' => 'flat',
+    'skyflat_premask'  => 'flat',
+    'fringe'   	       => 'fringe',   
+    'mask'     	       => 'mask',
+    'darkmask' 	       => 'mask',
+    'flatmask' 	       => 'mask',
+    }; 
+
+# convert supplied detrend type to a controlled namespace
+&my_die("Unrecognised detrend type: $det_type", $det_id, $iter, $class_id, $PS_EXIT_PROG_ERROR) unless exists DETTYPE()->{lc($det_type)};
+my $det_type_real = DETTYPE()->{lc($det_type)};
 
 # values to extract from output metadata and the stats to calculate
@@ -98,5 +115,5 @@
 $ipprc->outroot_prepare($outroot);
 
-my $outFile = $isMaskType ? 'PPIMAGE.OUTPUT.DETMASK' : 'PPIMAGE.OUTPUT';; # XXXX something of a hack (too many places to control things...)
+my $outFile = ($det_type_real eq "mask") ? 'PPIMAGE.OUTPUT.DETMASK' : 'PPIMAGE.OUTPUT';; # 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);
@@ -113,6 +130,6 @@
     $command .= " -recipe PPSTATS $RECIPE_PPSTATS";
     $command .= " -F PPIMAGE.OUTPUT $outFile" unless $outFile eq 'PPIMAGE.OUTPUT';
-    $command .= ' -isfringe' if lc($det_type) eq 'fringe';
-    $command .= ' -isdark' if lc($det_type) eq 'dark';
+    $command .= ' -isfringe' if $det_type_real eq 'fringe';
+    $command .= ' -isdark' if $det_type_real eq 'dark';
     $command .= " -tracedest $traceDest -log $logDest";
     $command .= " -dbname $dbname" if defined $dbname;
Index: trunk/ippScripts/scripts/detrend_norm_calc.pl
===================================================================
--- trunk/ippScripts/scripts/detrend_norm_calc.pl	(revision 18107)
+++ trunk/ippScripts/scripts/detrend_norm_calc.pl	(revision 18128)
@@ -49,14 +49,18 @@
 # Define which detrend types we normalise
 use constant NORMALIZE => {
-    'bias'     => 0,
-    'dark'     => 0,
-    'shutter'  => 0,
-    'flat'     => 1,
-    'domeflat' => 1,
-    'skyflat'  => 1,
-    'fringe'   => 0,
-    'mask'     => 0,
-    'darkmask' => 0,
-    'flatmask' => 0,
+    'bias'     	       => 0,
+    'dark'     	       => 0,   
+    'dark_premask'     => 0,
+    'shutter'  	       => 0,
+    'flat'     	       => 1,
+    'domeflat' 	       => 1,
+    'skyflat'  	       => 1,   
+    'flat_premask'     => 1,
+    'domeflat_premask' => 1,
+    'skyflat_premask'  => 1,
+    'fringe'   	       => 0,   
+    'mask'     	       => 0,
+    'darkmask' 	       => 0,
+    'flatmask' 	       => 0,
     }; 
 
Index: trunk/ippScripts/scripts/detrend_resid.pl
===================================================================
--- trunk/ippScripts/scripts/detrend_resid.pl	(revision 18107)
+++ trunk/ippScripts/scripts/detrend_resid.pl	(revision 18128)
@@ -105,14 +105,18 @@
 # Flags to specify the particular detrend to use
 use constant DETRENDS => {
-    'bias'     => '-bias',      # Specify the bias frame
-    'dark'     => '-dark',      # Specify the dark frame
-    'shutter'  => '-shutter',   # Specify the shutter frame
-    'flat'     => '-flat',      # Specify the flat frame
-    'domeflat' => '-flat',      # Specify the flat frame
-    'skyflat'  => '-flat',      # Specify the flat frame
-    'fringe'   => '-fringe',    # Specify the fringe frame
-    'mask'     => '-mask',      # Specify the mask frame
-    'darkmask' => '-mask',      # Specify the mask frame
-    'flatmask' => '-mask',      # Specify the mask frame
+    'bias'     	       => '-bias',      # Specify the bias frame
+    'dark'     	       => '-dark',      # Specify the dark frame
+    'dark_premask'     => '-dark',      # Specify the dark frame
+    'shutter'  	       => '-shutter',   # Specify the shutter frame
+    'flat'     	       => '-flat',      # Specify the flat frame
+    'domeflat' 	       => '-flat',      # Specify the flat frame
+    'skyflat'  	       => '-flat',      # Specify the flat frame
+    'flat_premask'     => '-flat',      # Specify the flat frame
+    'domeflat_premask' => '-flat',      # Specify the flat frame
+    'skyflat_premask'  => '-flat',      # Specify the flat frame
+    'fringe'   	       => '-fringe',    # Specify the fringe frame
+    'mask'     	       => '-mask',      # Specify the mask frame
+    'darkmask' 	       => '-mask',      # Specify the mask frame
+    'flatmask' 	       => '-mask',      # Specify the mask frame
 };
 
