Index: trunk/ippScripts/scripts/detrend_stack.pl
===================================================================
--- trunk/ippScripts/scripts/detrend_stack.pl	(revision 8983)
+++ trunk/ippScripts/scripts/detrend_stack.pl	(revision 9004)
@@ -15,5 +15,5 @@
 use Pod::Usage qw( pod2usage );
 
-my ($det_id, $iter, $class_id, $det_type);
+my ($det_id, $iter, $class_id, $det_type, $camera);
 GetOptions(
     'det_id|d=s'        => \$det_id,
@@ -21,14 +21,16 @@
     'class_id|i=s'      => \$class_id,
     'det_type|t=s'      => \$det_type,
+    'camera|c=s'        => \$camera,
 ) or pod2usage( 2 );
 
 pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV;
 pod2usage(
-    -msg => "Required options: --det_id --iteration --class_id --det_type",
+    -msg => "Required options: --det_id --iteration --class_id --det_type --camera",
     -exitval => 3,
 ) unless defined $det_id
     and defined $iter
     and defined $class_id
-    and defined $det_type;
+    and defined $det_type
+    and defined $camera;
 
 # Recipes to use as a function of detrend type
@@ -44,7 +46,8 @@
     'dark' => 0,
     'flat' => 1
-    };    
+    };
 
-die "Unrecognised detrend type: $det_type\n" if not defined RECIPES()->{$det_type};
+die "Unrecognised detrend type: $det_type\n" if not defined RECIPES()->{$det_type}
+                                             or not defined NORMALISE()->{$det_type};
 my $recipe = RECIPES()->{$det_type}; # Recipe to use in stacking
 
@@ -70,8 +73,9 @@
 
 # Stack the files
-my $output = $det_type . '_' . $class_id . '_' . $det_id . '_' . $iter . '.fit'; # Output name
-my $outputStats = $det_type . '_' . $class_id . '_' . $det_id . '_' . $iter . '.stats'; # Statistics name
+my $outputRoot = $camera . '.' . $det_type . '.' . $det_id . '.' . $iter . '.' . $class_id; # Root name
+my $outputStack = $outputRoot . '.fits'; # Output name
+my $outputStats = $outputRoot . '.stats'; # Statistics name
 {
-    my $command = "$ppMerge $output"; # Command to run
+    my $command = "$ppMerge $outputStack"; # Command to run
     foreach my $file (@$files) {
 	my $uri = $file->{uri};	# URI for input file
@@ -85,5 +89,5 @@
 	run(command => $command, verbose => 1);
     die "Unable to perform ppMerge: $error_code\n" if not $success;
-    die "Unable to find expected output file: $output\n" if not -f $output;
+    die "Unable to find expected output file: $outputStack\n" if not -f $outputStack;
     die "Unable to find expected output file: $outputStats\n" if not -f $outputStats;
 }
@@ -109,5 +113,5 @@
 {
     my $command = "$dettool -addstacked -det_id $det_id -iteration $iter -class_id $class_id" .
-	" -uri $output -recip $recipe";	# Command to run
+	" -uri $outputStack -recip $recipe"; # Command to run
     $command .= ' -bg ' . $stats->bg_mean();
     if (defined($stats->bg_stdev())) {
