Index: trunk/ippTasks/detrend.resid.pro
===================================================================
--- trunk/ippTasks/detrend.resid.pro	(revision 9104)
+++ trunk/ippTasks/detrend.resid.pro	(revision 9338)
@@ -4,13 +4,13 @@
 # dettool -toresid -simple
 # 0    bias 1      850131b mc       o_850131b.mc.fit PPIMAGE_O 1.492870 2.848350 292.565582
-# ITER TYPE DET_ID EXP_KEY CLASS_ID URI-IN           
+# ITER TYPE DET_ID EXP_TAG CLASS_ID URI-IN           
 
 # detrend_create_resid.pl 1      0    850131b mc       bias bias_mc_1_0.fit o_850131b.mc.fit 850131b
-# detrend_create_resid.pl DET_ID ITER EXP_KEY CLASS_ID TYPE (URI-DET)       (URL-IN)         (EXP_KEY)
+# detrend_create_resid.pl DET_ID ITER EXP_TAG CLASS_ID TYPE (URI-DET)       (URL-IN)         (EXP_TAG)
 # URL-DET: $TYPE\_$CLASS_ID\_$DET_ID\_$ITER.fit
 
 ## these tasks use the queue DetrendResidImfiles
 ## the DetrendResidImfiles queue contains:
-## STATE ITER TYPE DET_ID EXP_KEY CLASS_ID URI_IN
+## STATE ITER TYPE DET_ID EXP_TAG CLASS_ID URI_IN
 
 queueinit DetrendResidImfiles
@@ -52,10 +52,11 @@
       $DET_TYPE = $word:1
       $DET_ID   = $word:2
-      $EXP_KEY  = $word:3
+      $EXP_TAG  = $word:3
       $CLASS_ID = $word:4
       $URI_IN   = $word:5
-      ## XXX need to include the detID and iter in the key (if we have two running at the same time...)
+      $CAMERA   = $word:13
+      ## must include the detID and iter in the key (if we have two running at the same time...)
       ## Also needed to be in the output file (or path)
-      queuepush DetrendResidImfiles -uniq -key 1:3:4:5 "NEW $ITER $DET_TYPE $DET_ID $EXP_KEY $CLASS_ID $URI_IN"
+      queuepush DetrendResidImfiles -uniq -key 1:3:4:5 "NEW $ITER $DET_TYPE $DET_ID $EXP_TAG $CLASS_ID $URI_IN $CAMERA"
     end
 
@@ -97,5 +98,5 @@
 
     ## the DetrendResidImfiles queue contains:
-    ## STATE ITER TYPE DET_ID EXP_KEY CLASS_ID URI_IN
+    ## STATE ITER TYPE DET_ID EXP_TAG CLASS_ID URI_IN
     ## NOTE: the queue has the STATE prepended 
     list word -split $line
@@ -103,11 +104,14 @@
     $DET_TYPE = $word:1
     $DET_ID   = $word:2
-    $EXP_KEY  = $word:3
+    $EXP_TAG  = $word:3
     $CLASS_ID = $word:4
     $URI_IN   = $word:5
     $CAMERA   = $word:6
 
-    stdout $EXP_KEY.detresid.$DET_ID.$ITER.$CLASS_ID.log
-    stderr $EXP_KEY.detresid.$DET_ID.$ITER.$CLASS_ID.log
+    $DET_DIR = `dirname $URI_IN`
+    $LOG_DIR = $WORKDIR/$DET_DIR
+
+    stdout $LOG_DIR/$EXP_TAG.detresid.$DET_ID.$ITER.$CLASS_ID.log
+    stderr $LOG_DIR/$EXP_TAG.detresid.$DET_ID.$ITER.$CLASS_ID.log
 
     # specify choice of remote host:
@@ -120,9 +124,9 @@
     # create example job options as a demonstration
     options "$line"
-    # detrend_create_resid.pl DET_ID ITER EXP_KEY CLASS_ID TYPE (URI-DET) (URL-IN) (EXP_KEY ???)
-    # $URL_DET = isp.$DET_TYPE.$DET_ID.$ITER.$CLASS_ID.fits
-    $URL_DET = $CAMERA.$DET_TYPE.$DET_ID.$ITER.$CLASS_ID.fits
-    echo command detrend_create_resid.pl --det_id $DET_ID --iteration $ITER --exp_id $EXP_KEY --class_id $CLASS_ID --det_type $DET_TYPE --detrend $URL_DET --input_uri $URI_IN
-    command detrend_create_resid.pl --det_id $DET_ID --iteration $ITER --exp_id $EXP_KEY --class_id $CLASS_ID --det_type $DET_TYPE --detrend $URL_DET --input_uri $URI_IN
+    # detrend_create_resid.pl DET_ID ITER EXP_TAG CLASS_ID TYPE (URI-DET) (URL-IN) (EXP_TAG ???)
+    # need to parse the subdir path for the detrend URL
+    $DET_URL = $DET_DIR/$CAMERA.$DET_TYPE.$DET_ID.$ITER.$CLASS_ID.fits
+    echo command detrend_resid.pl --det_id $DET_ID --iteration $ITER --exp_tag $EXP_TAG --class_id $CLASS_ID --det_type $DET_TYPE --detrend $DET_URL --input_uri $URI_IN
+    command detrend_resid.pl --det_id $DET_ID --iteration $ITER --exp_tag $EXP_TAG --class_id $CLASS_ID --det_type $DET_TYPE --detrend $DET_URL --input_uri $URI_IN
   end
 
@@ -172,7 +176,7 @@
       $ITER     = $word:1
       $DET_TYPE = $word:2
-      $EXP_KEY  = $word:3
+      $EXP_TAG  = $word:3
       $INCLUDE  = $word:4
-      queuepush DetrendResidExposures -uniq -key 1:2:4 "NEW $DET_ID $ITER $DET_TYPE $EXP_KEY $INCLUDE"
+      queuepush DetrendResidExposures -uniq -key 1:2:4 "NEW $DET_ID $ITER $DET_TYPE $EXP_TAG $INCLUDE"
     end
 
@@ -214,5 +218,5 @@
 
     ## the DetrendResidExposures queue contains:
-    ## STATE ITER TYPE DET_ID EXP_KEY CLASS_ID URI_IN
+    ## STATE ITER TYPE DET_ID EXP_TAG CLASS_ID URI_IN
     ## NOTE: the queue has the STATE prepended 
     list word -split $line
@@ -220,9 +224,10 @@
     $ITER     = $word:1
     $DET_TYPE = $word:2
-    $EXP_KEY  = $word:3
+    $EXP_TAG  = $word:3
     $INCLUDE  = $word:4
 
-    stdout $EXP_KEY.detresid.$DET_ID.$ITER.log
-    stderr $EXP_KEY.detresid.$DET_ID.$ITER.log
+    # XXX add $WORKDIR/$LOG_DIR
+    stdout $EXP_TAG.detresid.$DET_ID.$ITER.log
+    stderr $EXP_TAG.detresid.$DET_ID.$ITER.log
 
     # specify choice of remote host:
@@ -233,8 +238,20 @@
     end
 
+    ### XXX artificially reject a few randomly
+    if ($ITER == 0)
+      $drop = (rnd(0) < 0.33)
+    else
+      $drop = ("$INCLUDE" == "F")
+    end
+
     # create example job options as a demonstration
     options "$line"
-    echo command detrend_reject_imfile.pl --det_id $DET_ID --iteration $ITER --exp_id $EXP_KEY --det_type $DET_TYPE
-    command detrend_reject_imfile.pl --det_id $DET_ID --iteration $ITER --exp_id $EXP_KEY --det_type $DET_TYPE
+    if ($drop) 
+      echo command detrend_reject_imfile.pl --det_id $DET_ID --iteration $ITER --exp_tag $EXP_TAG --det_type $DET_TYPE --reject
+      command detrend_reject_imfile.pl --det_id $DET_ID --iteration $ITER --exp_tag $EXP_TAG --det_type $DET_TYPE --reject
+    else 
+      echo command detrend_reject_imfile.pl --det_id $DET_ID --iteration $ITER --exp_tag $EXP_TAG --det_type $DET_TYPE
+      command detrend_reject_imfile.pl --det_id $DET_ID --iteration $ITER --exp_tag $EXP_TAG --det_type $DET_TYPE
+    end
   end
 
