Index: /trunk/ippTasks/detrend.norm.pro
===================================================================
--- /trunk/ippTasks/detrend.norm.pro	(revision 9337)
+++ /trunk/ippTasks/detrend.norm.pro	(revision 9338)
@@ -14,4 +14,115 @@
 if ($?parallel == 0)
   $parallel = 0
+end
+
+# select images ready for copy 
+# new entries are added to queue DetrendNormStat
+# compare the new list with the ones already selected
+task	       dettool.normstat.load
+  command      dettool -tonormalizedstat -simple
+  host         local
+
+  periods      -poll 1
+  periods      -exec 5
+  periods      -timeout 5
+
+  stdout dettool.normstat.log
+  stderr dettool.normstat.log
+
+  # success
+  task.exit    0
+    # XXX is it necessary for these to be local?
+    # drop after this task macro is done?
+    local i Nqueue
+
+    # compare output with newImage queue
+    # only add entries which don't exist in queue
+    queuesize stdout -var Nqueue
+    for i 0 $Nqueue
+      queuepop stdout -var line
+      list word -split $line
+      $DET_ID   = $word:0
+      $DET_TYPE = $word:1
+      $ITER     = $word:2
+      $CAMERA   = $word:3
+      queuepush DetrendNormStat -uniq -key 1:3 "NEW $DET_ID $DET_TYPE $ITER $CAMERA"
+    end
+
+    # delete existing entries which are DONE
+    queuedrop DetrendNormStat -key 0 DONE
+  end
+
+  # locked list
+  # default exit status
+  task.exit    default
+    echo       "detrend.norm: failure"
+  end
+
+  # operation times out?
+  task.exit    timeout
+    echo       "detrend.norm: timeout"
+  end
+end
+
+# copy new images, sending job to desired host
+task	       dettool.normstat.process
+  periods      -poll 0.5
+  periods      -exec 5.0
+  periods      -timeout 30
+
+  task.exec
+    queuesize DetrendNormStat -var N
+   
+    if ($N == 0) break
+    if ($network == 0) break
+    
+    # look for new images on the internal DetrendNormStat queue
+    # caution with these 'if' statements: syntax errors 
+    # will make the task fail without given a good status
+    queuepop DetrendNormStat -var line -key 0 NEW
+    if ("$line" == "NULL") break
+
+    strpop line state
+    queuepush DetrendNormStat -replace -key 1:3 "RUN $line"
+
+    # the DetrendNormStat queue contains:
+    # STATE DET_ID ITER
+    list word -split $line
+    $DET_ID   = $word:0
+    $DET_TYPE = $word:1
+    $ITER     = $word:2
+    $CAMERA   = $word:3
+
+    # XXX add $WORKDIR/$LOG_DIR
+    stdout $CAMERA.$DET_TYPE.$DET_ID.$ITER.log
+    stderr $CAMERA.$DET_TYPE.$DET_ID.$ITER.log
+
+    # specify choice of remote host:
+    if ($parallel)
+      host anyhost
+    else
+      host local
+    end
+
+    # create example job options as a demonstration
+    options "$line"
+    echo command detrend_norm_calc.pl --det_id $DET_ID --iteration $ITER --det_type $DET_TYPE
+    command detrend_norm_calc.pl --det_id $DET_ID --iteration $ITER --det_type $DET_TYPE
+  end
+
+  # success
+  task.exit 0
+    queuepush DetrendNormStat -replace -key 1:3 "DONE $options:0"
+  end
+
+  # default exit status
+  task.exit    default
+    queuepush DetrendNormStat -replace -key 1:3 "FAIL $options:0"
+  end
+
+  # operation times out?
+  task.exit    timeout
+    queuepush DetrendNormStat -replace -key 1:3 "TIMEOUT $options:0"
+  end
 end
 
@@ -41,5 +152,13 @@
     for i 0 $Nqueue
       queuepop stdout -var line
-      queuepush DetrendNormalize -uniq -key 1:2 "NEW $line"
+      list word -split $line
+      $DET_TYPE = $word:0
+      $CAMERA   = $word:1
+      $URI      = $word:2
+      $DET_ID   = $word:3
+      $ITER     = $word:4
+      $CLASS_ID = $word:5
+      $NORM     = $word:6
+      queuepush DetrendNormalize -uniq -key 4:5 "NEW $DET_TYPE $CAMERA $URI $DET_ID $ITER $CLASS_ID $NORM"
     end
 
@@ -79,17 +198,21 @@
 
     strpop line state
-    queuepush DetrendNormalize -replace -key 1:2 "RUN $line"
+    queuepush DetrendNormalize -replace -key 4:5 "RUN $line"
 
     # the DetrendNormalize queue contains:
     # STATE DET_ID ITER
     list word -split $line
-    $DET_ID   = $word:0
-    $ITER     = $word:1
-
-    # XXX we need to get CAMERA and TYPE from this query
-    # stdout $CAMERA.$TYPE.$DET_ID.$ITER.log
-    # stderr $CAMERA.$TYPE.$DET_ID.$ITER.log
-    stdout isp.flat.$DET_ID.$ITER.log
-    stderr isp.flat.$DET_ID.$ITER.log
+    $DET_TYPE = $word:0
+    $CAMERA   = $word:1
+    $URI      = $word:2
+    $DET_ID   = $word:3
+    $ITER     = $word:4
+    $CLASS_ID = $word:5
+    $NORM     = $word:6
+
+    $LOG_DIR = `dirname $URI`
+
+    stdout $WORKDIR/$LOG_DIR/$CAMERA.$DET_TYPE.$DET_ID.$ITER.log
+    stderr $WORKDIR/$LOG_DIR/$CAMERA.$DET_TYPE.$DET_ID.$ITER.log
 
     # specify choice of remote host:
@@ -102,127 +225,21 @@
     # create example job options as a demonstration
     options "$line"
-    echo command detrend_norm_calc.pl --det_id $DET_ID --iteration $ITER
-    command detrend_norm_calc.pl --det_id $DET_ID --iteration $ITER
+    echo command detrend_norm_apply.pl --det_id $DET_ID --iteration $ITER --class_id $CLASS_ID --value $NORM --input_uri $URI --camera $CAMERA --det_type $DET_TYPE
+    command detrend_norm_apply.pl --det_id $DET_ID --iteration $ITER --class_id $CLASS_ID --value $NORM --input_uri $URI --camera $CAMERA --det_type $DET_TYPE
   end
 
   # success
   task.exit 0
-    queuepush DetrendNormalize -replace -key 1:2 "DONE $options:0"
-  end
-
-  # default exit status
-  task.exit    default
-    queuepush DetrendNormalize -replace -key 1:2 "FAIL $options:0"
-  end
-
-  # operation times out?
-  task.exit    timeout
-    queuepush DetrendNormalize -replace -key 1:2 "TIMEOUT $options:0"
-  end
-end
-
-# select images ready for copy 
-# new entries are added to queue DetrendNormStat
-# compare the new list with the ones already selected
-task	       dettool.normstat.load
-  command      dettool -normstat -simple
-  host         local
-
-  periods      -poll 1
-  periods      -exec 5
-  periods      -timeout 5
-
-  stdout dettool.normstat.log
-  stderr dettool.normstat.log
-
-  # success
-  task.exit    0
-    # XXX is it necessary for these to be local?
-    # drop after this task macro is done?
-    local i Nqueue
-
-    # compare output with newImage queue
-    # only add entries which don't exist in queue
-    queuesize stdout -var Nqueue
-    for i 0 $Nqueue
-      queuepop stdout -var line
-      queuepush DetrendNormStat -uniq -key 1:2 "NEW $line"
-    end
-
-    # delete existing entries which are DONE
-    queuedrop DetrendNormStat -key 0 DONE
-  end
-
-  # locked list
-  # default exit status
-  task.exit    default
-    echo       "detrend.norm: failure"
-  end
-
-  # operation times out?
-  task.exit    timeout
-    echo       "detrend.norm: timeout"
-  end
-end
-
-# copy new images, sending job to desired host
-task	       dettool.normstat.process
-  periods      -poll 0.5
-  periods      -exec 5.0
-  periods      -timeout 30
-
-  task.exec
-    queuesize DetrendNormStat -var N
-   
-    if ($N == 0) break
-    if ($network == 0) break
-    
-    # look for new images on the internal DetrendNormStat queue
-    # caution with these 'if' statements: syntax errors 
-    # will make the task fail without given a good status
-    queuepop DetrendNormStat -var line -key 0 NEW
-    if ("$line" == "NULL") break
-
-    strpop line state
-    queuepush DetrendNormStat -replace -key 1:2 "RUN $line"
-
-    # the DetrendNormStat queue contains:
-    # STATE DET_ID ITER
-    list word -split $line
-    $DET_ID   = $word:0
-    $ITER     = $word:1
-
-    # XXX we need to get CAMERA and TYPE from this query
-    # stdout $CAMERA.$TYPE.$DET_ID.$ITER.log
-    # stderr $CAMERA.$TYPE.$DET_ID.$ITER.log
-    stdout isp.flat.$DET_ID.$ITER.log
-    stderr isp.flat.$DET_ID.$ITER.log
-
-    # specify choice of remote host:
-    if ($parallel)
-      host anyhost
-    else
-      host local
-    end
-
-    # create example job options as a demonstration
-    options "$line"
-    echo command detrend_norm_apply.pl --det_id $DET_ID --iteration $ITER
-    command detrend_norm_apply.pl --det_id $DET_ID --iteration $ITER
-  end
-
-  # success
-  task.exit 0
-    queuepush DetrendNormStat -replace -key 1:2 "DONE $options:0"
-  end
-
-  # default exit status
-  task.exit    default
-    queuepush DetrendNormStat -replace -key 1:2 "FAIL $options:0"
-  end
-
-  # operation times out?
-  task.exit    timeout
-    queuepush DetrendNormStat -replace -key 1:2 "TIMEOUT $options:0"
+    queuepush DetrendNormalize -replace -key 4:5 "DONE $options:0"
+  end
+
+  # default exit status
+  task.exit    default
+    queuepush DetrendNormalize -replace -key 4:5 "FAIL $options:0"
+  end
+
+  # operation times out?
+  task.exit    timeout
+    queuepush DetrendNormalize -replace -key 4:5 "TIMEOUT $options:0"
   end
 end
@@ -253,5 +270,13 @@
     for i 0 $Nqueue
       queuepop stdout -var line
-      queuepush DetrendNormalizeExposures -uniq -key 1:2 "NEW $line"
+      list word -split $line
+      $DET_ID   = $word:0
+      $ITER     = $word:1
+      $DET_TYPE = $word:2
+      $CAMERA   = $word:3
+      #$TELESCOPE= $word:4
+      #$EXP_TYPE = $word:5
+      #$IMFILES  = $word:6
+      queuepush DetrendNormalizeExposures -uniq -key 1:2 "NEW $DET_ID $ITER $DET_TYPE $CAMERA"
     end
 
@@ -298,10 +323,13 @@
     $DET_ID   = $word:0
     $ITER     = $word:1
-
-    # XXX we need to get CAMERA and TYPE from this query
-    # stdout $CAMERA.$TYPE.$DET_ID.$ITER.log
-    # stderr $CAMERA.$TYPE.$DET_ID.$ITER.log
-    stdout isp.flat.$DET_ID.$ITER.log
-    stderr isp.flat.$DET_ID.$ITER.log
+    $DET_TYPE = $word:2
+    $CAMERA   = $word:3
+    #$TELESCOPE= $word:4
+    #$EXP_TYPE = $word:5
+    #$IMFILES  = $word:6
+
+    # XXX add $WORKDIR/$LOG_DIR
+    stdout $CAMERA.$DET_TYPE.$DET_ID.$ITER.log
+    stderr $CAMERA.$DET_TYPE.$DET_ID.$ITER.log
 
     # specify choice of remote host:
@@ -314,6 +342,6 @@
     # create example job options as a demonstration
     options "$line"
-    echo command detrend_norm_apply.pl --det_id $DET_ID --iteration $ITER
-    command detrend_norm_apply.pl --det_id $DET_ID --iteration $ITER
+    echo command detrend_norm_exp.pl --det_id $DET_ID --iteration $ITER --camera $CAMERA --det_type $DET_TYPE
+    command detrend_norm_exp.pl --det_id $DET_ID --iteration $ITER --camera $CAMERA --det_type $DET_TYPE
   end
 
Index: /trunk/ippTasks/detrend.process.pro
===================================================================
--- /trunk/ippTasks/detrend.process.pro	(revision 9337)
+++ /trunk/ippTasks/detrend.process.pro	(revision 9338)
@@ -11,5 +11,5 @@
 ## these tasks use the queue DetrendProcessImfiles
 ## the DetrendProcessImfiles queue contains:
-## STATE DET_ID TYPE EXP_KEY CLASS CLASS_ID URI 
+## STATE DET_ID TYPE EXP_TAG CLASS CLASS_ID URI 
 
 queueinit DetrendProcessImfiles
@@ -26,5 +26,5 @@
 # compare the new list with the ones already selected
 task	       dettool.process.load
-  command      dettool -raw -simple
+  command      dettool -toprocess -simple
   host         local
 
@@ -49,10 +49,10 @@
       list word -split $line
       $DET_ID   = $word:0
-      $TYPE     = $word:1
-      $EXP_KEY  = $word:2
+      $DET_TYPE = $word:1
+      $EXP_TAG  = $word:2
       $CLASS    = $word:3
       $CLASS_ID = $word:4
       $URI      = $word:5
-      queuepush DetrendProcessImfiles -uniq -key 1:3:5 "NEW $DET_ID $TYPE $EXP_KEY $CLASS $CLASS_ID $URI"
+      queuepush DetrendProcessImfiles -uniq -key 1:3:5 "NEW $DET_ID $DET_TYPE $EXP_TAG $CLASS $CLASS_ID $URI"
     end
 
@@ -93,16 +93,17 @@
 
     ## the DetrendProcessImfiles queue contains:
-    # STATE DET_ID TYPE EXP_KEY CLASS CLASS_ID URI 
+    # STATE DET_ID TYPE EXP_TAG CLASS CLASS_ID URI 
     ## NOTE: the queue has the STATE prepended 
     list word -split $line
     $DET_ID   = $word:0
-    $TYPE     = $word:1
-    $EXP_KEY  = $word:2
+    $DET_TYPE = $word:1
+    $EXP_TAG  = $word:2
     $CLASS    = $word:3
     $CLASS_ID = $word:4
     $URI      = $word:5
 
-    stdout $EXP_KEY.detproc.$CLASS_ID.log
-    stderr $EXP_KEY.detproc.$CLASS_ID.log
+    $LOG_DIR = `dirname $URI`
+    stdout $WORKDIR/$LOG_DIR/$EXP_TAG.detproc.$DET_ID.$CLASS_ID.log
+    stderr $WORKDIR/$LOG_DIR/$EXP_TAG.detproc.$DET_ID.$CLASS_ID.log
 
     # specify choice of remote host:
@@ -115,10 +116,11 @@
     # create example job options as a demonstration
     options "$line"
-    echo command detrend_process_imfile.pl --det_id $DET_ID --exp_id $EXP_KEY --class $CLASS --class_id $CLASS_ID --det_type bias --input_uri $URI
-    command detrend_process_imfile.pl --det_id $DET_ID --exp_id $EXP_KEY --class $CLASS --class_id $CLASS_ID --det_type bias --input_uri $URI
+    echo command detrend_process_imfile.pl --det_id $DET_ID --exp_tag $EXP_TAG --class $CLASS --class_id $CLASS_ID --det_type $DET_TYPE --input_uri $URI
+    command detrend_process_imfile.pl --det_id $DET_ID --exp_tag $EXP_TAG --class $CLASS --class_id $CLASS_ID --det_type $DET_TYPE --input_uri $URI
   end
 
   # success
   task.exit 0
+    echo "success detrend_process_imfile.pl $options:0"
     queuepush DetrendProcessImfiles -replace -key 1:3:5 "DONE $options:0"
   end
@@ -126,4 +128,5 @@
   # default exit status
   task.exit    default
+    echo "failure detrend_process_imfile.pl $options:0"
     queuepush DetrendProcessImfiles -replace -key 1:3:5 "FAIL $options:0"
   end
@@ -131,4 +134,5 @@
   # operation times out?
   task.exit    timeout
+    echo "timeout detrend_process_imfile.pl $options:0"
     queuepush DetrendProcessImfiles -replace -key 1:3:5 "TIMEOUT $options:0"
   end
@@ -139,5 +143,5 @@
 # compare the new list with the ones already selected
 task	       dettool.processexp.load
-  command      dettool -toprocessdexp -simple
+  command      dettool -toprocessedexp -simple
   host         local
 
@@ -162,7 +166,8 @@
       list word -split $line
       $DET_ID   = $word:0
-      $TYPE     = $word:1
-      $EXP_KEY  = $word:2
-      queuepush DetrendProcessExposures -uniq -key 1:3 "NEW $DET_ID $TYPE $EXP_KEY"
+      $ITER     = $word:1
+      $DET_TYPE = $word:2
+      $EXP_TAG  = $word:3
+      queuepush DetrendProcessExposures -uniq -key 1:2:4 "NEW $DET_ID $ITER $DET_TYPE $EXP_TAG"
     end
 
@@ -200,16 +205,17 @@
 
     strpop line state
-    queuepush DetrendProcessExposures -replace -key 1:3:5 "RUN $line"
-
-    ## the DetrendProcessExposures queue contains:
-    # STATE DET_ID TYPE EXP_KEY CLASS CLASS_ID URI 
-    ## NOTE: the queue has the STATE prepended 
+    queuepush DetrendProcessExposures -replace -key 1:2:4 "RUN $line"
+
+
     list word -split $line
     $DET_ID   = $word:0
-    $TYPE     = $word:1
-    $EXP_KEY  = $word:2
-
-    stdout $EXP_KEY.detproc.$CLASS_ID.log
-    stderr $EXP_KEY.detproc.$CLASS_ID.log
+    $ITER     = $word:1
+    $DET_TYPE = $word:2
+    $EXP_TAG  = $word:3
+
+    # XXX need the classID in dettool -toprocessedexp -simple output
+    $CLASS_ID = isp
+    stdout $EXP_TAG.detproc.$DET_ID.log
+    stderr $EXP_TAG.detproc.$DET_ID.log
 
     # specify choice of remote host:
@@ -222,21 +228,21 @@
     # create example job options as a demonstration
     options "$line"
-    echo command detrend_process_exp.pl --det_id $DET_ID --exp_id $EXP_KEY --det_type bias
-    command detrend_process_exp.pl --det_id $DET_ID --exp_id $EXP_KEY --det_type bias
+    echo command detrend_process_exp.pl --det_id $DET_ID --exp_tag $EXP_TAG
+    command detrend_process_exp.pl --det_id $DET_ID --exp_tag $EXP_TAG
   end
 
   # success
   task.exit 0
-    queuepush DetrendProcessExposures -replace -key 1:3:5 "DONE $options:0"
+    queuepush DetrendProcessExposures -replace -key 1:2:4 "DONE $options:0"
   end
 
   # default exit status
   task.exit    default
-    queuepush DetrendProcessExposures -replace -key 1:3:5 "FAIL $options:0"
-  end
-
-  # operation times out?
-  task.exit    timeout
-    queuepush DetrendProcessExposures -replace -key 1:3:5 "TIMEOUT $options:0"
-  end
-end
+    queuepush DetrendProcessExposures -replace -key 1:2:4 "FAIL $options:0"
+  end
+
+  # operation times out?
+  task.exit    timeout
+    queuepush DetrendProcessExposures -replace -key 1:2:4 "TIMEOUT $options:0"
+  end
+end
Index: /trunk/ippTasks/detrend.reject.pro
===================================================================
--- /trunk/ippTasks/detrend.reject.pro	(revision 9337)
+++ /trunk/ippTasks/detrend.reject.pro	(revision 9338)
@@ -48,5 +48,6 @@
       $ITER     = $word:1
       $DET_TYPE = $word:2
-      queuepush DetrendRejectExposure -uniq -key 1:2 "NEW $DET_ID $ITER $DET_TYPE"
+      $CAMERA   = $word:3
+      queuepush DetrendRejectExposure -uniq -key 1:2 "NEW $DET_ID $ITER $DET_TYPE $CAMERA"
     end
 
@@ -93,8 +94,9 @@
     $ITER     = $word:1
     $DET_TYPE = $word:2
+    $CAMERA   = $word:3
 
     # I'd like to add CAMERA to the log file...
-    stdout isp.$DET_TYPE.$DET_ID.$ITER.log
-    stderr isp.$DET_TYPE.$DET_ID.$ITER.log
+    stdout $CAMERA.$DET_TYPE.$DET_ID.$ITER.log
+    stderr $CAMERA.$DET_TYPE.$DET_ID.$ITER.log
 
     # specify choice of remote host:
Index: /trunk/ippTasks/detrend.resid.pro
===================================================================
--- /trunk/ippTasks/detrend.resid.pro	(revision 9337)
+++ /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
 
Index: /trunk/ippTasks/detrend.stack.pro
===================================================================
--- /trunk/ippTasks/detrend.stack.pro	(revision 9337)
+++ /trunk/ippTasks/detrend.stack.pro	(revision 9338)
@@ -39,6 +39,4 @@
   # success
   task.exit    0
-    # XXX is it necessary for these to be local?
-    # drop after this task macro is done?
     local i Nqueue
 
@@ -51,9 +49,8 @@
       $DET_ID   = $word:0
       $ITER     = $word:1
-      $TYPE     = $word:2
+      $DET_TYPE = $word:2
       $CLASS_ID = $word:3
       $CAMERA   = $word:4
-      echo queuepush DetrendStackClass -uniq -key 1:2:4 "NEW $DET_ID $ITER $TYPE $CLASS_ID $CAMERA"
-      queuepush DetrendStackClass -uniq -key 1:2:4 "NEW $DET_ID $ITER $TYPE $CLASS_ID $CAMERA"
+      queuepush DetrendStackClass -uniq -key 1:2:4 "NEW $DET_ID $ITER $DET_TYPE $CLASS_ID $CAMERA"
     end
 
@@ -101,10 +98,11 @@
     $DET_ID   = $word:0
     $ITER     = $word:1
-    $TYPE     = $word:2
+    $DET_TYPE = $word:2
     $CLASS_ID = $word:3
     $CAMERA   = $word:4
 
-    stdout $CAMERA.$TYPE.$DET_ID.$ITER.$CLASS_ID.log
-    stderr $CAMERA.$TYPE.$DET_ID.$ITER.$CLASS_ID.log
+    # XXX add $WORKDIR/$LOG_DIR
+    stdout $CAMERA.$DET_TYPE.$DET_ID.$ITER.$CLASS_ID.log
+    stderr $CAMERA.$DET_TYPE.$DET_ID.$ITER.$CLASS_ID.log
 
     # specify choice of remote host:
@@ -118,6 +116,6 @@
     options "$line"
     # detrend_stack.pl --det_id 1 --iteration 0 --class_id isp --det_type bias --camera ISP || exit 1
-    echo command detrend_stack.pl --det_id $DET_ID --iteration $ITER --class_id $CLASS_ID --det_type $TYPE --camera $CAMERA
-    command detrend_stack.pl --det_id $DET_ID --iteration $ITER --class_id $CLASS_ID --det_type $TYPE --camera $CAMERA
+    echo command detrend_stack.pl --det_id $DET_ID --iteration $ITER --class_id $CLASS_ID --det_type $DET_TYPE --camera $CAMERA
+    command detrend_stack.pl --det_id $DET_ID --iteration $ITER --class_id $CLASS_ID --det_type $DET_TYPE --camera $CAMERA
   end
 
Index: /trunk/ippTasks/pantasks.pro
===================================================================
--- /trunk/ippTasks/pantasks.pro	(revision 9337)
+++ /trunk/ippTasks/pantasks.pro	(revision 9338)
@@ -2,5 +2,6 @@
 $network = 1
 $parallel = 0
-$scripts = /home/kiawe/eugene/src/panstarrs/ipp.full/ippTasks
+$scripts = /home/kiawe/eugene/src/panstarrs/ipp/ippTasks
+$WORKDIR = `ipp_workdir.pl`
 
 macro init
@@ -11,10 +12,40 @@
   exec rm -f *.stats
   exec rm -f *.detproc.*.fits
+  exec rm -f *.detproc.*.jpg
+  exec rm -f *.detproc.*.list
   exec rm -f *.detresid.*.fits
   exec rm -f *.detresid.*.jpg
   exec rm -f *.detresid.*.list
-  exec rm -f isp.bias.*.fits
+  exec rm -f ISP.bias.*.fits
 
-  exec upload.sh
+  exec rm -f ../bias/*.log
+  exec rm -f ../bias/*.stats
+  exec rm -f ../bias/*.detproc.*.fits
+  exec rm -f ../bias/*.detproc.*.jpg
+  exec rm -f ../bias/*.detproc.*.list
+  exec rm -f ../bias/*.detresid.*.fits
+  exec rm -f ../bias/*.detresid.*.jpg
+  exec rm -f ../bias/*.detresid.*.list
+  exec rm -f ../bias/ISP.bias.*.fits
+
+  exec rm -f ../dark/*.log
+  exec rm -f ../dark/*.stats
+  exec rm -f ../dark/*.detproc.*.fits
+  exec rm -f ../dark/*.detproc.*.jpg
+  exec rm -f ../dark/*.detproc.*.list
+  exec rm -f ../dark/*.detresid.*.fits
+  exec rm -f ../dark/*.detresid.*.jpg
+  exec rm -f ../dark/*.detresid.*.list
+  exec rm -f ../dark/ISP.dark.*.fits
+
+  exec rm -f ../flat/*.log
+  exec rm -f ../flat/*.stats
+  exec rm -f ../flat/*.detproc.*.fits
+  exec rm -f ../flat/*.detproc.*.jpg
+  exec rm -f ../flat/*.detproc.*.list
+  exec rm -f ../flat/*.detresid.*.fits
+  exec rm -f ../flat/*.detresid.*.jpg
+  exec rm -f ../flat/*.detresid.*.list
+  exec rm -f ../flat/ISP.flat.*.fits
 end
 
@@ -23,4 +54,5 @@
 macro step1
   init
+  exec upload.sh
   input $scripts/phase0.pro
   run
@@ -28,31 +60,28 @@
 
 # alala: dettool -tostack -simple
-macro step2.bias
+macro define.bias
   exec dettool -definebyquery -det_type bias -exp_type bias -camera isp
-  input $scripts/detrend.process.pro
   run
 end
 
-macro step2.dark
+macro define.dark
   exec dettool -definebyquery -det_type dark -exp_type dark -camera isp
-  input $scripts/detrend.process.pro
   run
 end
 
-macro step2.flat
+macro define.flat
   exec dettool -definebyquery -det_type flat -exp_type flat -camera isp
-  input $scripts/detrend.process.pro
   run
 end
 
-macro step2.both
+macro define.all
   exec dettool -definebyquery -det_type bias -exp_type bias -camera isp
   exec dettool -definebyquery -det_type dark -exp_type dark -camera isp
   exec dettool -definebyquery -det_type flat -exp_type flat -camera isp
-  input $scripts/detrend.process.pro
   run
 end
 
-macro step3
+macro step2
+  input $scripts/detrend.process.pro
   input $scripts/detrend.stack.pro
   input $scripts/detrend.norm.pro
Index: /trunk/ippTasks/phase0.pro
===================================================================
--- /trunk/ippTasks/phase0.pro	(revision 9337)
+++ /trunk/ippTasks/phase0.pro	(revision 9338)
@@ -98,7 +98,7 @@
     end
 
-    # do something better with this output target
-    stdout $EXP_TAG.$CLASS_ID.log
-    stderr $EXP_TAG.$CLASS_ID.log
+    $LOG_DIR = `dirname $URI`
+    stdout $WORKDIR/$LOG_DIR/$EXP_TAG.$CLASS_ID.log
+    stderr $WORKDIR/$LOG_DIR/$EXP_TAG.$CLASS_ID.log
 
     # create the command line
@@ -204,5 +204,5 @@
     $EXP_TAG   = $word:0
 
-    # do something better with this output target
+    # XXX add $WORKDIR/$LOG_DIR
     stdout $EXP_TAG.log
     stderr $EXP_TAG.log
