Index: trunk/ippTasks/detrend.assess.pro
===================================================================
--- trunk/ippTasks/detrend.assess.pro	(revision 8193)
+++ trunk/ippTasks/detrend.assess.pro	(revision 8691)
@@ -1,12 +1,21 @@
 
-## this file contains the tasks for running the detrend normalization stage
+## this file contains the tasks for running the detrend processing stage
 
-## these tasks use the queue DetrendRunToAssess
+# dettool -toresidexp -simple
+# 1      0    bias 850131b T
+# DET_ID ITER TYPE EXP_KEY INCLUDE         
+
+# detrend_reject_imfile.pl 1      0    850131b bias
+# detrend_reject_imfile.pl DET_ID ITER EXP_KEY TYPE
+
+## these tasks use the queue DetrendResidExp
+## the DetrendResidExp queue contains:
+## STATE DET_ID ITER TYPE EXP_KEY INCLUDE
 
 # select images ready for copy 
-# new entries are added to queue DetrendRunToAssess
+# new entries are added to queue DetrendResidExp
 # compare the new list with the ones already selected
 task	       dettool.assess.load
-  command      dettool -stacked -runs
+  command      dettool -toresidexp -simple
   host         local
 
@@ -17,6 +26,4 @@
   # success
   task.exit    0
-    # XXX is it necessary for these to be local?
-    # drop after this task macro is done?
     local i Nqueue
 
@@ -26,9 +33,15 @@
     for i 0 $Nqueue
       queuepop stdout -var line
-      queuepush DetrendRunToAssess -uniq -key 1:2:4 "NEW $line"
+      list word -split $line
+      $DET_ID   = $word:0
+      $ITER     = $word:1
+      $TYPE     = $word:2
+      $EXP_KEY  = $word:3
+      $INCLUDE  = $word:4
+      queuepush DetrendResidExp -uniq -key 1:2:4 "NEW $DET_ID $ITER $TYPE $EXP_KEY $INCLUDE"
     end
 
     # delete existing entries which are DONE
-    queuedrop DetrendRunToAssess -key 0 DONE
+    queuedrop DetrendResidExp -key 0 DONE
   end
 
@@ -50,5 +63,5 @@
 
 # copy new images, sending job to desired host
-task	       dettool.assess.process
+task	       dettool.resid.process
   periods      -poll 0.5
   periods      -exec 1.0
@@ -56,55 +69,50 @@
 
   task.exec
-    queuesize DetrendRunToAssess -var N
-   
+    queuesize DetrendResidExp -var N
     if ($N == 0) break
     if ($network == 0) break
     
-    # look for new images on the internal DetrendRunToAssess queue
+    # look for new images on the internal DetrendResidExp queue
     # caution with these 'if' statements: syntax errors 
     # will make the task fail without given a good status
-    queuepop DetrendRunToAssess -var line -key 0 NEW
+    queuepop DetrendResidExp -var line -key 0 NEW
     if ("$line" == "NULL") break
 
     strpop line state
-    queuepush DetrendRunToAssess -replace -key 0 "RUN $line"
+    queuepush DetrendResidExp -replace -key 1:2:4 "RUN $line"
+
+    ## the DetrendResidExp queue contains:
+    ## STATE DET_ID ITER TYPE EXP_KEY INCLUDE
+    ## NOTE: the queue has the STATE prepended 
+    list word -split $line
+    $DET_ID   = $word:1
+    $ITER     = $word:2
+    $TYPE     = $word:3
+    $EXP_KEY  = $word:4
+    $INCLUDE  = $word:5
 
     # specify choice of remote host:
-    # 'anyhost' specified random remote host
-    # if we needed to specify a host explicitly, use a command like
-    # one of the following.  the -required forces execution on the
-    # named host, and blocks the task until the host is available
-    # host kiawe
-    # host alala -required 
     host anyhost
-
-    # choose the default recipe appropriate to this type of file
-    $recipe = `get.recipe $type`
 
     # create example job options as a demonstration
     options "$line"
-
-    # we can put the dettool and ppMerge commands here, or wrap them in a single script
-    # $urilist = `dettool -stacked -det_id $det_id -iteration $iteration -chip"
-    # $uri_out = ???
-    # command ppNorm $uri_out $uri $uri ... -recipe PPMERGE $recipe ???
-    command ASSESS?? $uri_out -det_id $det_id -iteration $iteration -recipe PPMERGE $recipe
+    # detrend_reject_imfile.pl 1      0    850131b bias
+    # detrend_reject_imfile.pl DET_ID ITER EXP_KEY TYPE
+    command detrend_reject_imfile.pl $DET_ID $ITER $EXP_KEY $TYPE
   end
 
   # success
   task.exit 0
-    # XXX need to parse the options to identify the values below (if not part of cmdline?)
-    exec dettool -addstacked -det_id $det_id -iteration $iteration -class_id $class_id -procrecipe $recipe
-    queuepush DetrendRunToAssess -replace -key 1:2:4 "DONE $options:0"
+    queuepush DetrendResidExp -replace -key 1:2:4 "DONE $options:0"
   end
 
   # default exit status
   task.exit    default
-    queuepush DetrendRunToAssess -replace -key 0 "FAIL $options:0"
+    queuepush DetrendResidExp -replace -key 1:2:4 "FAIL $options:0"
   end
 
   # operation times out?
   task.exit    timeout
-    queuepush DetrendRunToAssess -replace -key 0 "FAIL $options:0"
+    queuepush DetrendResidExp -replace -key 1:2:4 "FAIL $options:0"
   end
 end
Index: trunk/ippTasks/detrend.process.pro
===================================================================
--- trunk/ippTasks/detrend.process.pro	(revision 8193)
+++ trunk/ippTasks/detrend.process.pro	(revision 8691)
@@ -1,8 +1,15 @@
+## this file contains the tasks for running the detrend processing stage
 
-## this file contains the tasks for running the detrend processing stage
+# query for pending imfiles to process:
+# dettool -raw -simple
+# 1 bias 850131b fpa mc 850131b.fits BIAS r.MP9601 1.656000 5.496118 0.349071 0.000000 1155.934692 107.037283 46.214947 37.160000 105.480000 -133.067001 0.000000
+# this returns many columns for manual operations. we strip all but the first few:
+
+# process a single imfile
+# detrend_process.pl 1 850131b mc bias 850131b.fits 850131b
 
 ## these tasks use the queue DetrendImfilesToProcess
 ## the DetrendImfilesToProcess queue contains:
-## STATE .....
+## STATE DET_ID TYPE EXP_KEY CLASS CLASS_ID URI 
 
 # select images ready for copy 
@@ -10,5 +17,5 @@
 # compare the new list with the ones already selected
 task	       dettool.raw.load
-  command      dettool -raw
+  command      dettool -raw -simple
   host         local
 
@@ -29,5 +36,12 @@
     for i 0 $Nqueue
       queuepop stdout -var line
-      queuepush DetrendImfilesToProcess -uniq -key 1:2:4 "NEW $line"
+      list word -split $line
+      $DET_ID   = $word:0
+      $TYPE     = $word:1
+      $EXP_KEY  = $word:2
+      $CLASS    = $word:3
+      $CLASS_ID = $word:4
+      $URI      = $word:5
+      queuepush DetrendImfilesToProcess -uniq -key 1:3:5 "NEW $DET_ID $TYPE $EXP_KEY $CLASS $CLASS_ID $URI"
     end
 
@@ -70,38 +84,39 @@
 
     strpop line state
-    queuepush DetrendImfilesToProcess -replace -key 0 "RUN $line"
+    queuepush DetrendImfilesToProcess -replace -key 1:3:5 "RUN $line"
+
+    ## the DetrendImfilesToProcess queue contains:
+    # STATE DET_ID TYPE EXP_KEY CLASS CLASS_ID URI 
+    ## NOTE: the queue has the STATE prepended 
+    list word -split $line
+    $DET_ID   = $word:1
+    $TYPE     = $word:2
+    $EXP_KEY  = $word:3
+    $CLASS    = $word:4
+    $CLASS_ID = $word:5
+    $URI      = $word:6
 
     # specify choice of remote host:
-    # 'anyhost' specified random remote host
-    # if we needed to specify a host explicitly, use a command like
-    # one of the following.  the -required forces execution on the
-    # named host, and blocks the task until the host is available
-    # host kiawe
-    # host alala -required 
     host anyhost
-
-    # choose the default recipe appropriate to this type of file
-    $recipe = `get.recipe $type`
 
     # create example job options as a demonstration
     options "$line"
-    command ppImage -file $uri $uri_out -recipe PPIMAGE $recipe
+    # ~/ipp/helpers/detrend_process.pl 1 850131b mc bias 850131b.fits 850131b
+    command detrend_process.pl $DET_ID $EXP_KEY $CLASS_ID $TYPE $URI $EXP_KEY
   end
 
   # success
   task.exit 0
-    # XXX need to parse the options to identify the values below (if not part of cmdline?)
-    exec dettool -addprocessed -det_id $det_id -exp_id $exp_id -class_id $class_id -uri $output_uri -procrecipe $recipe
-    queuepush DetrendImfilesToProcess -replace -key 1:2:4 "DONE $options:0"
+    queuepush DetrendImfilesToProcess -replace -key 1:3:5 "DONE $options:0"
   end
 
   # default exit status
   task.exit    default
-    queuepush DetrendImfilesToProcess -replace -key 0 "FAIL $options:0"
+    queuepush DetrendImfilesToProcess -replace -key 1:3:5 "FAIL $options:0"
   end
 
   # operation times out?
   task.exit    timeout
-    queuepush DetrendImfilesToProcess -replace -key 0 "FAIL $options:0"
+    queuepush DetrendImfilesToProcess -replace -key 1:3:5 "FAIL $options:0"
   end
 end
Index: trunk/ippTasks/detrend.reject.pro
===================================================================
--- trunk/ippTasks/detrend.reject.pro	(revision 8691)
+++ trunk/ippTasks/detrend.reject.pro	(revision 8691)
@@ -0,0 +1,114 @@
+
+## this file contains the tasks for running the detrend processing stage
+
+# dettool -residdetrun -simple
+# 1      0    bias
+# DET_ID ITER TYPE
+
+# detrend_reject_exp.pl 1      0    bias
+# detrend_reject_exp.pl DET_ID ITER TYPE
+
+## these tasks use the queue DetrendResidExp
+## the DetrendRejectExp queue contains:
+## STATE DET_ID ITER TYPE
+
+# select images ready for copy 
+# new entries are added to queue DetrendRejectExp
+# compare the new list with the ones already selected
+task	       dettool.assess.load
+  command      dettool -residdetrun -simple
+  host         local
+
+  periods      -poll 1
+  periods      -exec 5
+  periods      -timeout 30
+
+  # success
+  task.exit    0
+    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
+      $ITER     = $word:1
+      $TYPE     = $word:2
+      queuepush DetrendRejectExp -uniq -key 1:2 "NEW $DET_ID $ITER $TYPE"
+    end
+
+    # delete existing entries which are DONE
+    queuedrop DetrendRejectExp -key 0 DONE
+  end
+
+  # locked list
+  task.exit    1
+    echo       "new.images: exec failure"
+  end
+
+  # default exit status
+  task.exit    default
+    echo       "new.images: unknown exit status: $EXIT"
+  end
+
+  # operation times out?
+  task.exit    timeout
+    echo       "new.images: timeout"
+  end
+end
+
+# copy new images, sending job to desired host
+task	       dettool.resid.process
+  periods      -poll 0.5
+  periods      -exec 1.0
+  periods      -timeout 5
+
+  task.exec
+    queuesize DetrendRejectExp -var N
+    if ($N == 0) break
+    if ($network == 0) break
+    
+    # look for new images on the internal DetrendRejectExp queue
+    # caution with these 'if' statements: syntax errors 
+    # will make the task fail without given a good status
+    queuepop DetrendRejectExp -var line -key 0 NEW
+    if ("$line" == "NULL") break
+
+    strpop line state
+    queuepush DetrendRejectExp -replace -key 1:2 "RUN $line"
+
+    ## the DetrendRejectExp queue contains:
+    ## STATE DET_ID ITER TYPE
+    ## NOTE: the queue has the STATE prepended 
+    list word -split $line
+    $DET_ID   = $word:1
+    $ITER     = $word:2
+    $TYPE     = $word:3
+
+    # specify choice of remote host:
+    host anyhost
+
+    # create example job options as a demonstration
+    options "$line"
+    # detrend_reject_exp.pl 1      0    bias
+    # detrend_reject_exp.pl DET_ID ITER TYPE
+    command detrend_reject_imfile.pl $DET_ID $ITER $TYPE
+  end
+
+  # success
+  task.exit 0
+    queuepush DetrendRejectExp -replace -key 1:2 "DONE $options:0"
+  end
+
+  # default exit status
+  task.exit    default
+    queuepush DetrendRejectExp -replace -key 1:2 "FAIL $options:0"
+  end
+
+  # operation times out?
+  task.exit    timeout
+    queuepush DetrendRejectExp -replace -key 1:2 "FAIL $options:0"
+  end
+end
Index: trunk/ippTasks/detrend.resid.pro
===================================================================
--- trunk/ippTasks/detrend.resid.pro	(revision 8193)
+++ trunk/ippTasks/detrend.resid.pro	(revision 8691)
@@ -2,7 +2,15 @@
 ## this file contains the tasks for running the detrend processing stage
 
+# 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           
+
+# 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)
+# URL-DET: $TYPE\_$CLASS_ID\_$DET_ID\_$ITER.fit
+
 ## these tasks use the queue DetrendResidImfiles
 ## the DetrendResidImfiles queue contains:
-## STATE .....
+## STATE ITER TYPE DET_ID EXP_KEY CLASS_ID URI_IN
 
 # select images ready for copy 
@@ -10,5 +18,5 @@
 # compare the new list with the ones already selected
 task	       dettool.resid.load
-  command      dettool -resid
+  command      dettool -toresid -simple
   host         local
 
@@ -16,5 +24,4 @@
   periods      -exec 5
   periods      -timeout 30
-  trange       18:00 23:59
 
   # success
@@ -29,5 +36,12 @@
     for i 0 $Nqueue
       queuepop stdout -var line
-      queuepush DetrendResidImfiles -uniq -key 1:2:4 "NEW $line"
+      list word -split $line
+      $ITER     = $word:0
+      $TYPE     = $word:1
+      $DET_ID   = $word:2
+      $EXP_KEY  = $word:3
+      $CLASS_ID = $word:4
+      $URI_IN   = $word:5
+      queuepush DetrendResidImfiles -uniq -key 1:3:4:5 "NEW $ITER $TYPE $DET_ID $EXP_KEY $CLASS_ID $URI_IN"
     end
 
@@ -70,42 +84,40 @@
 
     strpop line state
-    queuepush DetrendResidImfiles -replace -key 0 "RUN $line"
+    queuepush DetrendResidImfiles -replace -key 1:3:4:5 "RUN $line"
+
+    ## the DetrendResidImfiles queue contains:
+    ## STATE ITER TYPE DET_ID EXP_KEY CLASS_ID URI_IN
+    ## NOTE: the queue has the STATE prepended 
+    list word -split $line
+    $ITER     = $word:1
+    $TYPE     = $word:2
+    $DET_ID   = $word:3
+    $EXP_KEY  = $word:4
+    $CLASS_ID = $word:5
+    $URI_IN   = $word:6
 
     # specify choice of remote host:
-    # 'anyhost' specified random remote host
-    # if we needed to specify a host explicitly, use a command like
-    # one of the following.  the -required forces execution on the
-    # named host, and blocks the task until the host is available
-    # host kiawe
-    # host alala -required 
     host anyhost
-
-    # choose the default recipe appropriate to this type of file
-    $recipe = `get.recipe $type`
 
     # create example job options as a demonstration
     options "$line"
-
-    # need to choose different variations based on the type
-    # need to supply the matched detrend images...
-    command ppImage -file $uri $uri_out -recipe PPIMAGE $recipe -bias $master
-    command ppImage -file $uri $uri_out -recipe PPIMAGE $recipe -flat $master
+    # detrend_create_resid.pl DET_ID ITER EXP_KEY CLASS_ID TYPE (URI-DET) (URL-IN) (EXP_KEY ???)
+    $URL_DET = $TYPE\_$CLASS_ID\_$DET_ID\_$ITER.fit
+    command detrend_create_resid.pl $DET_ID $ITER $EXP_KEY $CLASS_ID $TYPE $URI_DET $URL_IN $EXP_KEY
   end
 
   # success
   task.exit 0
-    # XXX need to parse the options to identify the values below (if not part of cmdline?)
-    exec dettool -addprocessed -det_id $det_id -exp_id $exp_id -class_id $class_id -uri $output_uri -procrecipe $recipe
-    queuepush DetrendResidImfiles -replace -key 1:2:4 "DONE $options:0"
+    queuepush DetrendResidImfiles -replace -key 1:3:4:5 "DONE $options:0"
   end
 
   # default exit status
   task.exit    default
-    queuepush DetrendResidImfiles -replace -key 0 "FAIL $options:0"
+    queuepush DetrendResidImfiles -replace -key 1:3:4:5 "FAIL $options:0"
   end
 
   # operation times out?
   task.exit    timeout
-    queuepush DetrendResidImfiles -replace -key 0 "FAIL $options:0"
+    queuepush DetrendResidImfiles -replace -key 1:3:4:5 "FAIL $options:0"
   end
 end
Index: trunk/ippTasks/detrend.stack.pro
===================================================================
--- trunk/ippTasks/detrend.stack.pro	(revision 8193)
+++ trunk/ippTasks/detrend.stack.pro	(revision 8691)
@@ -1,6 +1,17 @@
-
 ## this file contains the tasks for running the detrend stacking stage
 
+# get a list of imfiles to stack
+# dettool -tostack -simple
+# 1 0 bias mc
+# DET_ID ITER TYPE CLASS_ID 
+
+# function to stack the imfiles:
+# detrend_stack.pl 1 0 mc bias
+
 ## these tasks use the queue DetrendClassIDtoStack
+
+## these tasks use the queue DetrendImfilesToProcess
+## the DetrendClassIDtoStack queue contains:
+## STATE DET_ID ITER TYPE CLASS_ID 
 
 # select images ready for copy 
@@ -8,5 +19,5 @@
 # compare the new list with the ones already selected
 task	       dettool.stack.load
-  command      dettool -chip -processed
+  command      dettool -tostack -simple
   host         local
 
@@ -22,9 +33,14 @@
 
     # compare output with newImage queue
-    # only add entries which don't exist in queue
+    # only add entries which do not exist in queue
     queuesize stdout -var Nqueue
     for i 0 $Nqueue
       queuepop stdout -var line
-      queuepush DetrendClassIDtoStack -uniq -key 1:2:4 "NEW $line"
+      list word -split $line
+      $DET_ID   = $word:0
+      $ITER     = $word:1
+      $TYPE     = $word:2
+      $CLASS_ID = $word:3
+      queuepush DetrendClassIDtoStack -uniq -key 1:2:4 "NEW $DET_ID $ITER $TYPE $CLASS_ID"
     end
 
@@ -68,32 +84,26 @@
 
     strpop line state
-    queuepush DetrendClassIDtoStack -replace -key 0 "RUN $line"
+    queuepush DetrendClassIDtoStack -replace -key 1:2:4 "RUN $line"
+
+    # the DetrendClassIDtoStack queue contains:
+    # STATE DET_ID ITER TYPE CLASS_ID 
+    ## NOTE: the queue has the STATE prepended 
+    list word -split $line
+    $DET_ID   = $word:1
+    $ITER     = $word:2
+    $TYPE     = $word:3
+    $CLASS_ID = $word:4
 
     # specify choice of remote host:
-    # 'anyhost' specified random remote host
-    # if we needed to specify a host explicitly, use a command like
-    # one of the following.  the -required forces execution on the
-    # named host, and blocks the task until the host is available
-    # host kiawe
-    # host alala -required 
     host anyhost
-
-    # choose the default recipe appropriate to this type of file
-    $recipe = `get.recipe $type`
 
     # create example job options as a demonstration
     options "$line"
-
-    # we can put the dettool and ppMerge commands here, or wrap them in a single script
-    # $urilist = `dettool -processed -det_id $det_id -iteration $iteration -chip"
-    # $uri_out = ???
-    # command ppMerge $uri_out $uri $uri ... -recipe PPMERGE $recipe
-    command ppMerge.dettool $uri_out -det_id $det_id -iteration $iteration -recipe PPMERGE $recipe
+    # detrend_stack.pl 1 0 mc bias
+    command detrend_stack.pl $DET_ID $ITER $CLASS_ID $TYPE
   end
 
   # success
   task.exit 0
-    # XXX need to parse the options to identify the values below (if not part of cmdline?)
-    exec dettool -addstacked -det_id $det_id -iteration $iteration -class_id $class_id -procrecipe $recipe
     queuepush DetrendClassIDtoStack -replace -key 1:2:4 "DONE $options:0"
   end
@@ -101,10 +111,10 @@
   # default exit status
   task.exit    default
-    queuepush DetrendClassIDtoStack -replace -key 0 "FAIL $options:0"
+    queuepush DetrendClassIDtoStack -replace -key 1:2:4 "FAIL $options:0"
   end
 
   # operation times out?
   task.exit    timeout
-    queuepush DetrendClassIDtoStack -replace -key 0 "FAIL $options:0"
+    queuepush DetrendClassIDtoStack -replace -key 1:2:4 "FAIL $options:0"
   end
 end
Index: trunk/ippTasks/phase0.pro
===================================================================
--- trunk/ippTasks/phase0.pro	(revision 8691)
+++ trunk/ippTasks/phase0.pro	(revision 8691)
@@ -0,0 +1,209 @@
+
+## this file contains the tasks for running the phase 0 stage
+
+## these tasks use the queue Phase0PendingImfiles
+## the Phase0PendingImfiles queue contains:
+## STATE EXP_KEY CLASS CLASS_ID URI-FITS
+## queue keys are counted from 0
+
+# select images ready for phase0 analysis
+# new entries are added to queue Phase0PendingImfiles
+# compare the new list with the ones already selected
+task	       phase0.imfile.load
+  command      p0tool -pendingimfile -simple
+  host         local
+
+  periods      -poll 1
+  periods      -exec 5
+  periods      -timeout 30
+
+  # success
+  task.exit    0
+    local i Nqueue
+
+    # compare output with Phase0PendingImfiles queue
+    # only add entries which don't exist in queue
+    queuesize stdout -var Nqueue
+    for i 0 $Nqueue
+      queuepop stdout -var line
+      queuepush Phase0PendingImfiles -uniq -key 1 "NEW $line"
+    end
+
+    # delete existing entries which are DONE
+    queuedrop Phase0PendingImfiles -key 0 DONE
+  end
+
+  # locked list
+  task.exit    1
+    echo       "phase0 pending imfiles: exec failure"
+  end
+
+  # default exit status
+  task.exit    default
+    echo       "phase0 pending imfiles: unknown exit status: $EXIT"
+  end
+
+  # operation times out?
+  task.exit    timeout
+    echo       "phase0 pending imfiles: timeout"
+  end
+end
+
+# run the phase0imfile script on pending images
+task	       phase0.imfile.process
+  periods      -poll 0.5
+  periods      -exec 1.0
+  periods      -timeout 5
+
+  task.exec
+    queuesize Phase0PendingImfiles -var N
+    if ($N == 0) break
+    if ($network == 0) break
+    
+    # look for new images on the internal DetrendImfilesToProcess queue
+    # caution with these 'if' statements: syntax errors 
+    # will make the task fail without given a good status
+    queuepop Phase0PendingImfiles -var line -key 0 NEW
+    if ("$line" == "NULL") break
+
+    strpop line state
+    queuepush Phase0PendingImfiles -replace -key 1 "RUN $line"
+
+    ## the Phase0PendingImfiles queue contains:
+    ## STATE EXP_KEY CLASS CLASS_ID URI-FITS
+    list word -split $line
+
+    # specify choice of remote host:
+    # 'anyhost' specifies random remote host
+    # if we needed to specify a host explicitly, use a command like
+    # one of the following.  the -required forces execution on the
+    # named host, and blocks the task until the host is available
+    # host kiawe
+    # host alala -required 
+    ## XXX need to determine the appropriate host
+    host anyhost
+
+    # create the command line
+    options "$line"
+    command phase0imfile.pl $word:1 $word:3 $word:$4
+  end
+
+  # success
+  task.exit 0
+    # phase0imfile.pl updates DB tables, here we just update the queue
+    queuepush Phase0PendingImfiles -replace -key 1 "DONE $options:0"
+  end
+
+  # default exit status
+  task.exit    default
+    queuepush Phase0PendingImfiles -replace -key 1 "FAIL $options:0"
+  end
+
+  # operation times out?
+  task.exit    timeout
+    queuepush Phase0PendingImfiles -replace -key 1 "FAIL $options:0"
+  end
+end
+
+## these tasks use the queue Phase0PendingExposures
+## the Phase0PendingExposures queue contains:
+## STATE EXP_KEY CAMERA TELESCOPE TYPE NCLASS
+
+# select images ready for phase0 analysis
+# new entries are added to queue Phase0PendingExposures
+# compare the new list with the ones already selected
+task	       phase0.exp.load
+  command      p0tool -pendingexp -simple
+  host         local
+
+  periods      -poll 1
+  periods      -exec 5
+  periods      -timeout 30
+
+  # success
+  task.exit    0
+    local i Nqueue
+
+    # compare output with Phase0PendingExposures queue
+    # only add entries which don't exist in queue
+    queuesize stdout -var Nqueue
+    for i 0 $Nqueue
+      queuepop stdout -var line
+      queuepush Phase0PendingExposures -uniq -key 1 "NEW $line"
+    end
+
+    # delete existing entries which are DONE
+    queuedrop Phase0PendingExposures -key 0 DONE
+  end
+
+  # locked list
+  task.exit    1
+    echo       "phase0 pending exp: exec failure"
+  end
+
+  # default exit status
+  task.exit    default
+    echo       "phase0 pending exp: unknown exit status: $EXIT"
+  end
+
+  # operation times out?
+  task.exit    timeout
+    echo       "phase0 pending exp: timeout"
+  end
+end
+
+# run the phase0imfile script on pending images
+task	       phase0.exp.process
+  periods      -poll 0.5
+  periods      -exec 1.0
+  periods      -timeout 5
+
+  task.exec
+    queuesize Phase0PendingExposures -var N
+    if ($N == 0) break
+    if ($network == 0) break
+    
+    # look for new images on the internal DetrendImfilesToProcess queue
+    # caution with these 'if' statements: syntax errors 
+    # will make the task fail without given a good status
+    queuepop Phase0PendingExposures -var line -key 0 NEW
+    if ("$line" == "NULL") break
+
+    strpop line state
+    queuepush Phase0PendingExposures -replace -key 1 "RUN $line"
+
+    ## the Phase0PendingExposures queue contains:
+    ## STATE EXP_KEY CAMERA TELESCOPE TYPE NCLASS
+    list word -split $line
+
+    # specify choice of remote host:
+    # 'anyhost' specifies random remote host
+    # if we needed to specify a host explicitly, use a command like
+    # one of the following.  the -required forces execution on the
+    # named host, and blocks the task until the host is available
+    # host kiawe
+    # host alala -required 
+    ## XXX need to determine the appropriate host
+    host anyhost
+
+    # create the command line
+    options "$line"
+    command phase0exp.pl $word:1
+  end
+
+  # success
+  task.exit 0
+    # phase0exp.pl updates DB tables, here we just update the queue
+    queuepush Phase0PendingExposures -replace -key 1 "DONE $options:0"
+  end
+
+  # default exit status
+  task.exit    default
+    queuepush Phase0PendingExposures -replace -key 1 "FAIL $options:0"
+  end
+
+  # operation times out?
+  task.exit    timeout
+    queuepush Phase0PendingExposures -replace -key 1 "FAIL $options:0"
+  end
+end
