Index: trunk/ippScripts/scripts/detrend_norm_exp.pl
===================================================================
--- trunk/ippScripts/scripts/detrend_norm_exp.pl	(revision 13490)
+++ trunk/ippScripts/scripts/detrend_norm_exp.pl	(revision 13552)
@@ -56,7 +56,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_IMAGE_B',	# Bias only
+	'dark'     => 'PPIMAGE_J1_IMAGE_B',	# Dark only
+	'shutter'  => 'PPIMAGE_J1_IMAGE_B',	# Shutter only
+	'flat'     => 'PPIMAGE_J1_IMAGE_F',	# Flat-field only
+	'domeflat' => 'PPIMAGE_J1_IMAGE_F',	# Flat-field only
+	'skyflat'  => 'PPIMAGE_J1_IMAGE_F',	# Flat-field only
+	'fringe'   => 'PPIMAGE_J1_IMAGE_F',	# Fringe only
+    },
+    'bin2' => {		# We're checking the master --- input is not already processed
+	'bias'     => 'PPIMAGE_J2_IMAGE_B',	# Bias only
+	'dark'     => 'PPIMAGE_J2_IMAGE_B',	# Dark only
+	'shutter'  => 'PPIMAGE_J2_IMAGE_B',	# Shutter only
+	'flat'     => 'PPIMAGE_J2_IMAGE_F',	# Flat-field only
+	'domeflat' => 'PPIMAGE_J2_IMAGE_F',	# Flat-field only
+	'skyflat'  => 'PPIMAGE_J2_IMAGE_F',	# Flat-field only
+	'fringe'   => 'PPIMAGE_J2_IMAGE_F',	# Fringe only
+    },
+};
 
 # Look for programs we need
@@ -134,8 +152,15 @@
 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);
@@ -145,5 +170,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);
@@ -153,7 +178,7 @@
 
 unless ($no_update) {
-    my $command = "$dettool -addnormalizedexp -det_id $det_id -iteration $iter " .
-	"-recip " . RECIPE1() . "," . RECIPE2() . " -path_base $outputRoot " .
-	"-bg $bg -bg_stdev $bg_stdev -bg_mean_stdev $bg_mean_stdev"; # Command to run
+    my $command = "$dettool -addnormalizedexp -det_id $det_id -iteration $iter";
+    $command .= " -recip $recipe1,$recipe2 -path_base $outputRoot ";
+    $command .= " -bg $bg -bg_stdev $bg_stdev -bg_mean_stdev $bg_mean_stdev";
     $command .= " -dbname $dbname" if defined $dbname;
     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
Index: trunk/ippScripts/scripts/detrend_process_exp.pl
===================================================================
--- trunk/ippScripts/scripts/detrend_process_exp.pl	(revision 13490)
+++ trunk/ippScripts/scripts/detrend_process_exp.pl	(revision 13552)
@@ -56,7 +56,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_IMAGE_B',	# Bias only
+	'dark'     => 'PPIMAGE_J1_IMAGE_B',	# Dark only
+	'shutter'  => 'PPIMAGE_J1_IMAGE_B',	# Shutter only
+	'flat'     => 'PPIMAGE_J1_IMAGE_F',	# Flat-field only
+	'domeflat' => 'PPIMAGE_J1_IMAGE_F',	# Flat-field only
+	'skyflat'  => 'PPIMAGE_J1_IMAGE_F',	# Flat-field only
+	'fringe'   => 'PPIMAGE_J1_IMAGE_F',	# Fringe only
+    },
+    'bin2' => {		# We're checking the master --- input is not already processed
+	'bias'     => 'PPIMAGE_J2_IMAGE_B',	# Bias only
+	'dark'     => 'PPIMAGE_J2_IMAGE_B',	# Dark only
+	'shutter'  => 'PPIMAGE_J2_IMAGE_B',	# Shutter only
+	'flat'     => 'PPIMAGE_J2_IMAGE_F',	# Flat-field only
+	'domeflat' => 'PPIMAGE_J2_IMAGE_F',	# Flat-field only
+	'skyflat'  => 'PPIMAGE_J2_IMAGE_F',	# Flat-field only
+	'fringe'   => 'PPIMAGE_J2_IMAGE_F',	# Fringe only
+    },
+};
 
 # Look for programs we need
@@ -135,8 +153,15 @@
 my $jpeg2 = $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);
@@ -150,5 +175,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);
@@ -162,7 +187,7 @@
 
 unless ($no_update) {
-    my $command = "$dettool -addprocessedexp -det_id $det_id -exp_tag $exp_tag " .
-	"-recip " . RECIPE1() . "," . RECIPE2() . " -path_base $outputRoot " .
-	"-bg $bg -bg_stdev $bg_stdev -bg_mean_stdev $bg_mean_stdev"; # Command to run
+    my $command = "$dettool -addprocessedexp -det_id $det_id -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 .= " -dbname $dbname" if defined $dbname;
     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
Index: trunk/ippScripts/scripts/detrend_reject_imfile.pl
===================================================================
--- trunk/ippScripts/scripts/detrend_reject_imfile.pl	(revision 13490)
+++ 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;
Index: trunk/ippScripts/scripts/detrend_resid.pl
===================================================================
--- trunk/ippScripts/scripts/detrend_resid.pl	(revision 13490)
+++ trunk/ippScripts/scripts/detrend_resid.pl	(revision 13552)
@@ -69,20 +69,20 @@
 use constant RECIPES => {
     'master' => {		# We're creating a master --- already processed the input
-	'bias' => 'PPIMAGE_B',	# Bias only
-	'dark' => 'PPIMAGE_D',	# Dark only
-	'shutter' => 'PPIMAGE_S',	# Shutter only
-	'flat' => 'PPIMAGE_F',	# Flat-field only
+	'bias'     => 'PPIMAGE_B',	# Bias only
+	'dark'     => 'PPIMAGE_D',	# Dark only
+	'shutter'  => 'PPIMAGE_S',	# Shutter only
+	'flat'     => 'PPIMAGE_F',	# Flat-field only
 	'domeflat' => 'PPIMAGE_F',	# Flat-field only
-	'skyflat' => 'PPIMAGE_F',	# Flat-field only
-	'fringe' => 'PPIMAGE_R',	# Fringe only
+	'skyflat'  => 'PPIMAGE_F',	# Flat-field only
+	'fringe'   => 'PPIMAGE_R',	# Fringe only
     },
     'verify' => {		# We're checking the master --- input is not already processed
-	'bias' => 'PPIMAGE_OB',	# Bias only
-	'dark' => 'PPIMAGE_OBD',	# Dark only
-	'shutter' => 'PPIMAGE_OBDS',	# Shutter only
-	'flat' => 'PPIMAGE_OBDSF',	# Flat-field only
+	'bias'     => 'PPIMAGE_OB',	# Bias only
+	'dark'     => 'PPIMAGE_OBD',	# Dark only
+	'shutter'  => 'PPIMAGE_OBDS',	# Shutter only
+	'flat'     => 'PPIMAGE_OBDSF',	# Flat-field only
 	'domeflat' => 'PPIMAGE_OBDSF',	# Flat-field only
-	'skyflat' => 'PPIMAGE_OBDSF',	# Flat-field only
-	'fringe' => 'PPIMAGE_OBDSFR',	# Fringe only
+	'skyflat'  => 'PPIMAGE_OBDSF',	# Flat-field only
+	'fringe'   => 'PPIMAGE_OBDSFR',	# Fringe only
     },
 };
@@ -94,9 +94,8 @@
     'shutter' => '-shutter',	# Specify the shutter frame
     'flat' => '-flat',		# Specify the flat frame
-    'domeflat' => '-flat',		# Specify the flat frame
-    'skyflat' => '-flat',		# Specify the flat frame
+    'domeflat' => '-flat',	# Specify the flat frame
+    'skyflat' => '-flat',	# Specify the flat frame
     'fringe' => '-fringe',	# Specify the fringe frame
 };
-
 
 use constant DELETE_STATS => 0;	# Delete the statistics file when done?
