Index: trunk/ippScripts/scripts/detrend_resid_imfile.pl
===================================================================
--- trunk/ippScripts/scripts/detrend_resid_imfile.pl	(revision 19561)
+++ trunk/ippScripts/scripts/detrend_resid_imfile.pl	(revision 19621)
@@ -24,9 +24,11 @@
 use Pod::Usage qw( pod2usage );
 
-my ( $det_id, $iter, $exp_id, $exp_tag, $class_id, $det_type, $detrend, $input_uri, $camera, $mode, $outroot,
+my ( $det_id, $iter, $ref_det_id, $ref_iter, $exp_id, $exp_tag, $class_id, $det_type, $detrend, $input_uri, $camera, $mode, $outroot,
      $dbname, $reduction, $threads, $verbose, $no_update, $no_op, $redirect );
 GetOptions(
     'det_id|d=s'        => \$det_id,
     'iteration=s'       => \$iter,
+    'ref_det_id=s'      => \$ref_det_id,
+    'ref_iter=s'        => \$ref_iter,
     'exp_id|e=s'        => \$exp_id,
     'exp_tag|=s'        => \$exp_tag,
@@ -48,17 +50,19 @@
 
 pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV;
-pod2usage( -msg => "Required options: --det_id --iteration --exp_id --exp_tag --class_id --det_type --camera --input_uri --mode --detrend --outroot (not for 'verify' mode)",
+pod2usage( -msg => "Required options: --det_id --iteration --ref_det_id --ref_iter --exp_id --exp_tag --class_id --det_type --camera --input_uri --mode --detrend --outroot (not for 'verify' mode)",
            -exitval => 3) unless
-    defined $det_id    and
-    defined $iter      and
-    defined $exp_id    and
-    defined $exp_tag   and
-    defined $class_id  and
-    defined $det_type  and
-    defined $input_uri and
-    defined $camera    and
-    defined $mode      and
-    defined $outroot   and
-    (defined $detrend or lc($mode) eq 'verify');
+    defined $det_id     and
+    defined $iter       and
+    defined $ref_det_id and
+    defined $ref_iter   and
+    defined $exp_id     and
+    defined $exp_tag    and
+    defined $class_id   and
+    defined $det_type   and
+    defined $input_uri  and
+    defined $camera     and
+    defined $mode       and
+    defined $outroot    and
+    defined $detrend;
 
 $ipprc->define_camera($camera);
@@ -69,4 +73,5 @@
 
 # Recipes to use as a function of detrend type and mode
+# XXX probably can drop the distinct 'verify' recipes
 $reduction = 'DETREND' unless defined $reduction;
 my $recipe;                     # Name of recipe to use
@@ -78,5 +83,8 @@
     &my_die("Unrecognised mode: $mode", $det_id, $iter, $exp_id, $class_id, $PS_EXIT_PROG_ERROR);
 }
+
+print "raw recipe: $recipe\n";
 $recipe = $ipprc->reduction($reduction, $recipe);
+print "real recipe: $recipe\n";
 
 # values to extract from output metadata and the stats to calculate
@@ -166,9 +174,7 @@
 
     # Detrend to use in processing
-    if (lc($mode) ne 'verify') {
-        my $detFlag = DETRENDS->{lc($det_type)};
-        &my_die("Unrecognised detrend type: $det_type", $det_id, $iter, $exp_id, $class_id, $PS_EXIT_PROG_ERROR) unless defined $detFlag;
-        $command .= " $detFlag $detrend";
-    }
+    my $detFlag = DETRENDS->{lc($det_type)};
+    &my_die("Unrecognised detrend type: $det_type", $det_id, $iter, $exp_id, $class_id, $PS_EXIT_PROG_ERROR) unless defined $detFlag;
+    $command .= " $detFlag $detrend";
 
     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
@@ -216,4 +222,6 @@
 $command .= " -det_id $det_id";
 $command .= " -iteration $iter";
+$command .= " -ref_det_id $ref_det_id";
+$command .= " -ref_iter $ref_iter";
 $command .= " -exp_id $exp_id";
 $command .= " -class_id $class_id";
@@ -252,4 +260,6 @@
         $command .= " -det_id $det_id";
         $command .= " -iteration $iter";
+	$command .= " -ref_det_id $ref_det_id";
+	$command .= " -ref_iter $ref_iter";
         $command .= " -exp_id $exp_id";
         $command .= " -class_id $class_id";
