Index: trunk/ippScripts/scripts/detrend_reject_imfile.pl
===================================================================
--- trunk/ippScripts/scripts/detrend_reject_imfile.pl	(revision 13275)
+++ trunk/ippScripts/scripts/detrend_reject_imfile.pl	(revision 13552)
@@ -60,6 +60,25 @@
 $ipprc->define_camera($camera);
 
-use constant RECIPE1 => 'PPIMAGE_J1'; # Recipe to use for ppImage to make JPEGs
-use constant RECIPE2 => 'PPIMAGE_J2'; # Recipe to use for ppImage to make JPEGs
+# Recipes to use, as a function of the detrend type
+use constant RECIPES => {
+    'bin1' => {		# We're creating a master --- already processed the input
+	'bias'     => 'PPIMAGE_J1_RESID_B',	# Bias only
+	'dark'     => 'PPIMAGE_J1_RESID_B',	# Dark only
+	'shutter'  => 'PPIMAGE_J1_RESID_B',	# Shutter only
+	'flat'     => 'PPIMAGE_J1_RESID_F',	# Flat-field only
+	'domeflat' => 'PPIMAGE_J1_RESID_F',	# Flat-field only
+	'skyflat'  => 'PPIMAGE_J1_RESID_F',	# Flat-field only
+	'fringe'   => 'PPIMAGE_J1_RESID_F',	# Fringe only
+    },
+    'bin2' => {		# We're checking the master --- input is not already processed
+	'bias'     => 'PPIMAGE_J2_RESID_B',	# Bias only
+	'dark'     => 'PPIMAGE_J2_RESID_B',	# Dark only
+	'shutter'  => 'PPIMAGE_J2_RESID_B',	# Shutter only
+	'flat'     => 'PPIMAGE_J2_RESID_F',	# Flat-field only
+	'domeflat' => 'PPIMAGE_J2_RESID_F',	# Flat-field only
+	'skyflat'  => 'PPIMAGE_J2_RESID_F',	# Flat-field only
+	'fringe'   => 'PPIMAGE_J2_RESID_F',	# Fringe only
+    },
+};
 
 # Look for programs we need
@@ -87,11 +106,14 @@
     }
 
+    # XXX report an error message if stdout_buf is empty
+
     my $metadata = $mdcParser->parse(join "", @$stdout_buf) or
 	&my_die("Unable to parse metadata config doc", $det_id, $iter, $exp_tag, $PS_EXIT_PROG_ERROR);
+
     $files = parse_md_list($metadata) or
 	&my_die("Unable to parse metadata list", $det_id, $iter, $exp_tag, $PS_EXIT_PROG_ERROR);
 }
 
-
+# XXX in debug mode, unlink = 0
 my ($list1File, $list1Name) = tempfile( "$exp_tag.detresid.$det_id.$iter.b1.list.XXXX", UNLINK => 1 );
 my ($list2File, $list2Name) = tempfile( "$exp_tag.detresid.$det_id.$iter.b2.list.XXXX", UNLINK => 1 );
@@ -118,9 +140,16 @@
 my $jpeg2Name = $ipprc->filename("PPIMAGE.JPEG2", $outputRoot); # Binned JPEG #2
 
+# Recipes to use in processing
+my $recipe1 = RECIPES->{"bin1"}->{lc($det_type)};
+&my_die("Unrecognised detrend type: $det_type", $det_id, $iter, $exp_tag, $PS_EXIT_PROG_ERROR) unless defined $recipe1;
+
+my $recipe2 = RECIPES->{"bin2"}->{lc($det_type)};
+&my_die("Unrecognised detrend type: $det_type", $det_id, $iter, $exp_tag, $PS_EXIT_PROG_ERROR) unless defined $recipe2;
+
 unless ($no_op) {
 
     # Make the jpeg for binning 1
     {
-	my $command = "$ppImage -list $list1Name $outputRoot -recipe PPIMAGE " . RECIPE1; # Command to run
+	my $command = "$ppImage -list $list1Name $outputRoot -recipe PPIMAGE $recipe1"; # Command to run
 	my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
 	    run(command => $command, verbose => 1);
@@ -134,5 +163,5 @@
     # Make the jpeg for binning 2
     {
-	my $command = "$ppImage -list $list2Name $outputRoot -recipe PPIMAGE " . RECIPE2; # Command to run
+	my $command = "$ppImage -list $list2Name $outputRoot -recipe PPIMAGE $recipe2"; # Command to run
 	my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
 	    run(command => $command, verbose => 1);
@@ -159,4 +188,5 @@
 my $logFile;
 unless ($no_op) {
+    # XXX this will fail if the file exists (because of Nebulous rules)
     $logFile = $ipprc->file_create_open( $logName );
 }
@@ -298,6 +328,6 @@
 
 unless ($no_update) {
-    my $command = "$dettool -addresidexp -det_id $det_id -iteration $iter -exp_tag $exp_tag " .
-	"-recip " . RECIPE1() . "," . RECIPE2() . " -path_base $outputRoot "; # Command to run
+    my $command = "$dettool -addresidexp -det_id $det_id -iteration $iter -exp_tag $exp_tag";
+    $command .= " -recip $recipe1,$recipe2 -path_base $outputRoot ";
     $command .= " -bg $bg -bg_stdev $bg_stdev -bg_mean_stdev $bg_mean_stdev";
     $command .= ' -reject' if $reject;
