Index: /trunk/dettools/doc/det.define.sh
===================================================================
--- /trunk/dettools/doc/det.define.sh	(revision 6022)
+++ /trunk/dettools/doc/det.define.sh	(revision 6022)
@@ -0,0 +1,53 @@
+
+## PanTasks scripts for mkdetrend
+
+# det.cleanup.resid : search for images to be processed
+task	       det.types
+  command      dettools -dettypes
+  host         local
+
+  # this needs to be an absolute event
+  periods      -exec     sunset + 20min?
+
+  # success
+  task.exit    0
+    local i Nstdout
+    queuesize stdout -var Nstdout
+    for i 0 $Nstdout
+      queuepop stdout -var line
+      queuepush detTypePending line
+    end
+  end
+end
+
+
+# det.process.norm : submit an image for processing by ppImage
+task	       det.define
+  periods      -exec 1
+  periods      -timeout 10
+
+  task.exec
+    local Npending
+    queuesize  detTypePending -var Npending
+    if ($Npending == 0) break
+
+    queuepop detTypePending -var line
+    if ("$line" == "NULL") break
+
+    host local
+    command dettools -define $line
+  end
+
+  # success
+  task.exit    0
+    queueinit stdout
+  end
+
+end
+
+# det.assess
+task	       det.assess
+  command      dettools -assess
+  host         local
+
+end
Index: /trunk/dettools/doc/det.norm.sh
===================================================================
--- /trunk/dettools/doc/det.norm.sh	(revision 6022)
+++ /trunk/dettools/doc/det.norm.sh	(revision 6022)
@@ -0,0 +1,75 @@
+
+## PanTasks scripts for mkdetrend
+
+# tasks: 
+#   det.pending.norm  - select norm input imfiles for processing
+#   det.process.norm  - send norm images to pcontol to be processed
+#   det.update.raw   - update completed exposures
+#   det.cleanup.raw  - retire old input image
+#
+# queues: 
+#   detNormPending: (url) (expID) (cameraID) (chipID) (state)
+#
+# globals: 
+
+# det.pending.norm : search for images to be processed
+task	       det.pending.norm
+  command      dettools -pending norm
+  host         local
+
+  # timeout shorter than exec so jobs do not build up
+  periods      -exec     5
+  periods      -poll     1
+  periods      -timeout  4
+
+  # success
+  task.exit    0
+    local i Nstdout
+    # keep only new, unique entries (URL is key)
+    queuesize stdout -var Nstdout
+    for i 0 $Nstdout
+      queuepop stdout -var line
+      queuepush detNormPending -uniq -key 0 "$line new"
+    end
+  end
+end
+
+# det.process.norm : submit an image for processing by ppImage
+task	       det.process.norm
+  periods      -exec 0.1
+  periods      -timeout 120
+
+  task.exec
+    local Npending
+    queuesize  detNormPending -var Npending
+    if ($Npending == 0) break
+
+    # add in system status interruptions later
+    # if ($network == 0) break
+    
+    queuepop detNormPending -var line -key 4 new
+    if ("$line" == "NULL") break
+
+    list tmp -split $line
+    $url    = $tmp:0
+    $expID  = $tmp:1
+    $camera = $tmp:2
+    $chip   = $tmp:3
+    queuepush detNormPending "$url $expID $camera $chip run"
+
+    # need to decide real name for this function
+    $host = `chip.host $camera $chip`
+    host $host
+    command normalize $url $chip -recipe detrendNorm
+    # the detrend image(s) used by this analysis are determined by 
+    # the recipe : normally, the best available
+  end
+
+  # success
+  task.exit    0
+    # if ppImage updates the DB:
+    queueinit stdout
+    queuepush detPendingNorm $taskargs:0 $taskargs:1 $taskargs:2 $taskargs:3 done
+  end
+
+end
Index: /trunk/dettools/doc/det.process.sh
===================================================================
--- /trunk/dettools/doc/det.process.sh	(revision 6022)
+++ /trunk/dettools/doc/det.process.sh	(revision 6022)
@@ -0,0 +1,99 @@
+
+## PanTasks scripts for mkdetrend
+
+# tasks: 
+#   det.pending.raw  - select raw input imfiles for processing
+#   det.process.raw  - send raw images to pcontol to be processed
+#   det.update.raw   - update completed exposures
+#   det.cleanup.raw  - retire old input image
+#
+# queues: 
+#   detRawPending: (url) (expID) (cameraID) (chipID) (state)
+#
+# globals: 
+
+# det.pending.raw : search for images to be processed
+task	       det.pending.raw
+  command      dettools -pending raw
+  host         local
+
+  # timeout shorter than exec so jobs do not build up
+  periods      -exec     5
+  periods      -poll     1
+  periods      -timeout  4
+
+  # success
+  task.exit    0
+    local i Nstdout
+    # keep only new, unique entries (URL is key)
+    queuesize stdout -var Nstdout
+    for i 0 $Nstdout
+      queuepop stdout -var line
+      queuepush detRawPending -uniq -key 0 "$line new"
+    end
+  end
+end
+
+# det.process.raw : submit an image for processing by ppImage
+task	       det.process.raw
+  periods      -exec 0.1
+  periods      -timeout 120
+
+  task.exec
+    local Npending
+    queuesize  detRawPending -var Npending
+    if ($Npending == 0) break
+
+    # add in system status interruptions later
+    # if ($network == 0) break
+    
+    queuepop detRawPending -var line -key 4 new
+    if ("$line" == "NULL") break
+
+    list tmp -split $line
+    $url    = $tmp:0
+    $expID  = $tmp:1
+    $camera = $tmp:2
+    $chip   = $tmp:3
+    queuepush detRawPending "$url $expID $camera $chip run"
+
+    # need to decide real name for this function
+    $host = `chip.host $camera $chip`
+    host $host
+    command ppImage $url $chip -recipe detrendRaw
+    # the detrend image(s) used by this analysis are determined by 
+    # the recipe : normally, the best available
+  end
+
+  # success
+  task.exit    0
+    # if ppImage updates the DB:
+    queueinit stdout
+    queuepush detPendingRaw $taskargs:0 $taskargs:1 $taskargs:2 $taskargs:3 done
+  end
+
+end
+
+# det.update.raw : search for images to be processed
+task	       det.update.raw
+  command      dettools -update raw
+  host         local
+
+  # timeout shorter than exec so jobs do not build up
+  periods      -exec     5
+  periods      -poll     1
+  periods      -timeout  4
+end
+
+# det.cleanup.raw : search for images to be processed
+task	       det.cleanup.raw
+  command      dettools -cleanup raw
+  host         local
+
+  # timeout shorter than exec so jobs do not build up
+  # this would be better as an absolute event
+  periods      -exec     {86400*3}
+  periods      -poll     10
+  periods      -timeout  120
+end
+
Index: /trunk/dettools/doc/det.resid.sh
===================================================================
--- /trunk/dettools/doc/det.resid.sh	(revision 6022)
+++ /trunk/dettools/doc/det.resid.sh	(revision 6022)
@@ -0,0 +1,101 @@
+
+## PanTasks scripts for mkdetrend
+
+# tasks: 
+#   det.pending.resid  - select resid input imfiles for processing
+#   det.process.resid  - send resid images to pcontol to be processed
+#   det.update.resid   - update completed exposures
+#   det.cleanup.resid  - retire old input image
+#
+# queues: 
+#   detResidPending: (url) (detID) (expID) (cameraID) (chipID) (mode) (state)
+#
+# globals: 
+
+# det.pending.resid : search for images to be processed
+task	       det.pending.resid
+  command      dettools -pending resid
+  host         local
+
+  # timeout shorter than exec so jobs do not build up
+  periods      -exec     5
+  periods      -poll     1
+  periods      -timeout  4
+
+  # success
+  task.exit    0
+    local i Nstdout
+    # keep only new, unique entries (URL is key)
+    queuesize stdout -var Nstdout
+    for i 0 $Nstdout
+      queuepop stdout -var line
+      queuepush detResidPending -uniq -key 0 "$line new"
+    end
+  end
+end
+
+# det.process.resid : submit an image for processing by ppImage
+task	       det.process.resid
+  periods      -exec 0.1
+  periods      -timeout 120
+
+  task.exec
+    local Npending
+    queuesize  detResidPending -var Npending
+    if ($Npending == 0) break
+
+    # add in system status interruptions later
+    # if ($network == 0) break
+    
+    queuepop detResidPending -var line -key 4 new
+    if ("$line" == "NULL") break
+
+    list tmp -split $line
+    $url    = $tmp:0
+    $detID  = $tmp:1
+    $expID  = $tmp:2
+    $camera = $tmp:3
+    $chip   = $tmp:4
+    queuepush detResidPending "$url $detID $expID $camera $chip run"
+
+    # need to decide real name for this function
+    $host = `chip.host $camera $chip`
+    host $host
+    command ppImage $url $chip -recipe detrendResid
+    end
+    # the detrend image(s) used by this analysis are determined by 
+    # the recipe : detrendResid uses the detID to choose the current or previous
+  end
+
+  # success
+  task.exit    0
+    # if ppImage updates the DB:
+    queueinit stdout
+    queuepush detPendingResid $taskargs:0 $taskargs:1 $taskargs:2 $taskargs:3 done
+  end
+
+end
+
+# det.update.resid : search for images to be processed
+task	       det.update.resid
+  command      dettools -update resid
+  host         local
+
+  # timeout shorter than exec so jobs do not build up
+  periods      -exec     5
+  periods      -poll     1
+  periods      -timeout  4
+end
+
+# det.cleanup.resid : search for images to be processed
+task	       det.cleanup.resid
+  command      dettools -cleanup resid
+  host         local
+
+  # timeout shorter than exec so jobs do not build up
+  # this would be better as an absolute event
+  periods      -exec     {86400*3}
+  periods      -poll     10
+  periods      -timeout  120
+end
+
Index: /trunk/dettools/doc/det.stack.sh
===================================================================
--- /trunk/dettools/doc/det.stack.sh	(revision 6022)
+++ /trunk/dettools/doc/det.stack.sh	(revision 6022)
@@ -0,0 +1,75 @@
+
+## PanTasks scripts for mkdetrend
+
+# tasks: 
+#   det.pending.stack  - select stack input imfiles for processing
+#   det.process.stack  - send stack images to pcontol to be processed
+#   det.update.raw   - update completed exposures
+#   det.cleanup.raw  - retire old input image
+#
+# queues: 
+#   detStackPending: (url) (expID) (cameraID) (chipID) (state)
+#
+# globals: 
+
+# det.pending.stack : search for images to be processed
+task	       det.pending.stack
+  command      dettools -pending stack
+  host         local
+
+  # timeout shorter than exec so jobs do not build up
+  periods      -exec     5
+  periods      -poll     1
+  periods      -timeout  4
+
+  # success
+  task.exit    0
+    local i Nstdout
+    # keep only new, unique entries (URL is key)
+    queuesize stdout -var Nstdout
+    for i 0 $Nstdout
+      queuepop stdout -var line
+      queuepush detStackPending -uniq -key 0 "$line new"
+    end
+  end
+end
+
+# det.process.stack : submit an image for processing by ppImage
+task	       det.process.stack
+  periods      -exec 0.1
+  periods      -timeout 120
+
+  task.exec
+    local Npending
+    queuesize  detStackPending -var Npending
+    if ($Npending == 0) break
+
+    # add in system status interruptions later
+    # if ($network == 0) break
+    
+    queuepop detStackPending -var line -key 4 new
+    if ("$line" == "NULL") break
+
+    list tmp -split $line
+    $url    = $tmp:0
+    $expID  = $tmp:1
+    $camera = $tmp:2
+    $chip   = $tmp:3
+    queuepush detStackPending "$url $expID $camera $chip run"
+
+    # need to decide real name for this function
+    $host = `chip.host $camera $chip`
+    host $host
+    command ppMerge $url $chip -recipe detrendStack
+    # the detrend image(s) used by this analysis are determined by 
+    # the recipe : normally, the best available
+  end
+
+  # success
+  task.exit    0
+    # if ppImage updates the DB:
+    queueinit stdout
+    queuepush detPendingStack $taskargs:0 $taskargs:1 $taskargs:2 $taskargs:3 done
+  end
+
+end
Index: /trunk/dettools/doc/dettools.txt
===================================================================
--- /trunk/dettools/doc/dettools.txt	(revision 6021)
+++ /trunk/dettools/doc/dettools.txt	(revision 6022)
@@ -1,5 +1,5 @@
 mkdetrend tools
 
-dettool -define [options]
+dettools -define [options]
  * define a new detRun, specifying the constraints, and adding it to
  the run table.  if the detRun ID already exists, creates a new
@@ -22,5 +22,5 @@
   (-exptime is mandatory for dark)
 
-dettool -getinput
+dettools -getinput
  * select the input matching a given detRun.  selects the input
  exposures and the input files.
@@ -29,32 +29,28 @@
  stack of input exposures
 
-dettool -select raw [-state state] [-outmode mode]
+dettools -pending raw [-state state] [-outmode mode]
  * select the unprocessed input infiles
  - output of this program is used by pantasks to schedule the ppImage
  run on each image
 
-dettool -select stack [-state state] [-outmode mode]
+dettools -pending stack [-state state] [-outmode mode]
  * select the files to be stacked for a given detRun, if exposures are ready
  - output of this program is used by ppMerge to build a master stack
 
-dettool -select rawresid [-state state]
- * select the residual imfiles to be generated
- - output of this program is used for another ppImage run 
-
-dettool -update raw
+dettools -update raw
  * select the raw input exposures, count processed imfiles, update if done
 
-dettool -update resid
+dettools -update resid
  * select the resid exposures, count processed resid imfiles, update if done
  - for a given resid exposure, compile the results from the stacks for
  each chip and renormalize the output files as needed.
 
-dettool -select norm
+dettools -pending norm
  * select the master detrend frames & imfiles to be normalized
 
-dettool -resid
+dettools -resid
  * construct the resid exposures and imfiles given 
 
-dettool -assess
+dettools -assess
  * for a given master detrend frame, compile the results from the
  residual exposures and assess the validity of the input exposures and of
Index: /trunk/dettools/src/dettools.c
===================================================================
--- /trunk/dettools/src/dettools.c	(revision 6021)
+++ /trunk/dettools/src/dettools.c	(revision 6022)
@@ -1,3 +1,3 @@
-# include "p2search.h"
+# include "dettools.h"
 
 int main (int argc, char **argv) {
@@ -39,5 +39,5 @@
     if (config->mode == DET_MODE_UPDATE_RESID) {
 	exposures = detSelectResidUpdateExposures (config);
-	detUpdateResdiExposures (config, exposures);
+	detUpdateResidExposures (config, exposures);
     }
 
Index: /trunk/dettools/src/dettools.h
===================================================================
--- /trunk/dettools/src/dettools.h	(revision 6021)
+++ /trunk/dettools/src/dettools.h	(revision 6022)
@@ -1,10 +1,7 @@
 # include <stdio.h>
-# include <strings.h>  // for strcasecmp
-# include <unistd.h>   // for unlink
+# include <strings.h>
+# include <unistd.h>
 # include <pslib.h>
-# include <pmObjects.h>
-# include <pmPSF.h>
-# include <pmPSFtry.h>
-# include <pmModelGroup.h>
+# include "metadata.h"
 
 typedef enum {
@@ -52,84 +49,10 @@
 } detConfig;
 
-// these structures should be defined using the mddb api tools
-// check definition in p2search.h
-typedef struct ppRawExposure;
-typedef struct ppRawImfile;
-
-// this structure should be defined using the mddb api tools
-typedef struct {
-    char expID[32];			// free-form exposure ID string
-    char class;				// class of file: fpa (0), chip (1), cell (2), readout (3)?
-    int Nclass;				// number of files of this class
-    int Ndone;				// number of files of this class
-    char P1version;
-    char P2version;
-    char state;
-} detInputExposure;
-
-// this structure should be defined using the mddb api tools
-typedef struct {
-    char expID[32];			// free-form exposure ID string
-    char P2version;
-    char class;				// class of file: fpa (0), chip (1), cell (2), readout (3)?
-    char classID[32];			// identifier for class (chip00, cell00, etc)
-    char urlroot[128];			// locator for file (neb / file)
-    char input[16];			// extension for input image
-    char output[16];			// extension for output image
-    char log[16];			// extension for log file
-    char smf[16];			// extension for object table
-    char state;				// current P2 state
-} detInputImfile;
-
-// this structure should be defined using the mddb api tools
-typedef struct {
-    a detID;
-    a version;
-    a iteration;
-    a type;
-    a camera;
-    a filter;
-    a class;
-    int nInput;
-    int nImfiles;
-    detState state;
-    float stats;
-} detMasterExposure;
-
-typedef struct {
-    a detID;
-    a version;
-    a iteration;
-    a classID;
-    a stats;
-    detState state;
-} detMasterImfile;
-
-typedef struct {
-    a detID;
-    a version;
-    a state;
-
-    int nIterations;			// number of iterations STARTED
-
-    detType type;
-    char *camera;
-    char *filter;
-
-    bool groupSelect;
-    char *groupID;
-
-    bool timeSelect;
-    psTime start;
-    psTime stop;
-
-    bool exptimeSelect;
-    float exptimeMin;
-    float exptimeMax;
-
-    bool airmassSelect;
-    float airmassMin;
-    float airmassMax;
-} detMasterRun;
+// these structures are defined in metadata.h using glueforge
+// typedef struct DetrendInputExposure;
+// typedef struct DetrendInputImfile;
+// typedef struct DetrendMasterRun;
+// typedef struct DetrendMasterExposure;
+// typedef struct DetrendMasterImfile;
 
 typedef struct {
Index: /trunk/dettools/src/dettoolsConfig.c
===================================================================
--- /trunk/dettools/src/dettoolsConfig.c	(revision 6021)
+++ /trunk/dettools/src/dettoolsConfig.c	(revision 6022)
@@ -1,5 +1,5 @@
 # include "p2search.h"
 
-bool p2searchConfig (psConfig *config, int argc, char **argv) {
+bool dettoolsConfig (psConfig *config, int argc, char **argv) {
 
     // Parse the configurations (re-org a la ppImage)
Index: /trunk/ippTools/doc/p0tools.sh
===================================================================
--- /trunk/ippTools/doc/p0tools.sh	(revision 6022)
+++ /trunk/ippTools/doc/p0tools.sh	(revision 6022)
@@ -0,0 +1,71 @@
+
+## PanTasks scripts for Phase 0
+
+# tasks: p0ready p0update p0cleanup
+#
+# queues: 
+#   p0pending: (expID) (cameraID) (state)
+#
+# globals: 
+
+# p0pending : search for images to be processed
+task	       p0pending
+  command      p0search -pending
+  host         local
+
+  # timeout shorter than exec so jobs do not build up
+  periods      -exec     5
+  periods      -poll     1
+  periods      -timeout  4
+
+  # success
+  task.exit    0
+    local i Nstdout
+    # keep only new, unique entries (URL is key)
+    queuesize stdout -var Nstdout
+    for i 0 $Nstdout
+      queuepop stdout -var line
+      queuepush p0pending -uniq -key 0 "$line new"
+    end
+  end
+end
+
+# p0update : submit an exposure to be updated
+task	       p0update
+  periods      -exec 1
+  periods      -timeout 10
+
+  task.exec
+    local Npending
+    queuesize  p0pending -var Npending
+    if ($Npending == 0) break
+
+    queuepop p0pending -var line -key 2 new
+    if ("$line" == "NULL") break
+
+    list tmp -split $line
+    $expID  = $tmp:0
+    $camera = $tmp:1
+    queuepush p0pending "$expID $camera run"
+
+    host any
+    command p0search -update $expID $camera
+  end
+
+  # success
+  task.exit    0
+    queueinit stdout
+    queuepush p0pending $taskargs:0 $taskargs:1 done
+  end
+end
+
+# p0update : search for images to be processed
+task	       p0cleanup
+  command      p0search -cleanup
+  host         local
+
+  # timeout shorter than exec so jobs do not build up
+  periods      -exec     30
+  periods      -poll     1
+  periods      -timeout  10
+end
Index: /trunk/ippTools/doc/p0tools.txt
===================================================================
--- /trunk/ippTools/doc/p0tools.txt	(revision 6021)
+++ /trunk/ippTools/doc/p0tools.txt	(revision 6022)
@@ -2,9 +2,10 @@
 Phase 0 pipeline tools:
 
-p0search -ready :
-  * examine the new.imfiles,new.exposures tables and select exposures ready for analysi
+p0search -pending :
+  * examine the new.imfiles,new.exposures tables and select exposures ready for analysis
+  * output is: (expID) (camera)
 
-p0search -update :
-  * select a specified image in the new.imfiles/new.exposures table
+p0search -update (expID) (camera):
+  * select a the corresponding images from the new.imfiles/new.exposures table
   * extract the specified header information
   * search the summit metadata db tables
@@ -16,5 +17,5 @@
     * add an entry to the p2.pending table (single)
 
-p0search -stats :
+p0search -stats (expID) (camera):
   * select a specified image in the new.imfiles/new.exposures table
   * extract the specified header information
@@ -23,5 +24,5 @@
   [-update without output to MDDB]
 
-p0search -mkraw :
+p0search -mkraw (expID) (camera):
   * select a specified image in the new.imfiles/new.exposures table
   * extract the specified header information
@@ -33,2 +34,7 @@
   * remove completed entries from the new.imfiles,new.exposure tables
 
+** note : the division of -pending and -update allows separate processes
+   to be examining the image headers and measuring some stats.  these
+   jobs can be run via pcontrol to reduce the load on the PanTasks
+   machines
+
Index: /trunk/ippTools/doc/p1tools.sh
===================================================================
--- /trunk/ippTools/doc/p1tools.sh	(revision 6022)
+++ /trunk/ippTools/doc/p1tools.sh	(revision 6022)
@@ -0,0 +1,72 @@
+
+## PanTasks scripts for Phase 1
+
+# tasks: p1pending p1astro p1done
+#
+# queues: 
+#   p1pending: (expID) (version) (cameraID) (state)
+#
+# globals: 
+
+# p1pending : search for images to be processed
+task	       p1pending
+  command      p1search -pending
+  host         local
+
+  # timeout shorter than exec so jobs do not build up
+  periods      -exec     5
+  periods      -poll     1
+  periods      -timeout  4
+
+  # success
+  task.exit    0
+    local i Nstdout
+    # keep only new, unique entries (URL is key)
+    queuesize stdout -var Nstdout
+    for i 0 $Nstdout
+      queuepop stdout -var line
+      queuepush p1pending -uniq -key 0 "$line new"
+    end
+  end
+end
+
+# p1update : submit an exposure to be updated
+task	       p1astro
+  periods      -exec 1
+  periods      -timeout 10
+
+  task.exec
+    local expID version camera Npending
+    queuesize  p1pending -var Npending
+    if ($Npending == 0) break
+
+    queuepop p1pending -var line -key 2 new
+    if ("$line" == "NULL") break
+
+    list tmp -split $line
+    $expID  = $tmp:0
+    $version = $tmp:1
+    $camera = $tmp:2
+    queuepush p1pending "$expID $version $camera run"
+
+    host any
+    command p1astro $expID $version $camera
+  end
+
+  # success
+  task.exit    0
+    queueinit stdout
+    queuepush p1pending $taskargs:0 $taskargs:1 $taskargs:2 done
+  end
+end
+
+# p1update : search for images to be processed
+task	       p1done
+  command      p1search -done
+  host         local
+
+  # timeout shorter than exec so jobs do not build up
+  periods      -exec     30
+  periods      -poll     1
+  periods      -timeout  10
+end
Index: /trunk/ippTools/doc/p1tools.txt
===================================================================
--- /trunk/ippTools/doc/p1tools.txt	(revision 6021)
+++ /trunk/ippTools/doc/p1tools.txt	(revision 6022)
@@ -2,5 +2,5 @@
 Phase 1 pipeline tools:
 
-p1search -insert ? :
+p1search -define [constraints]:
   * examine the raw.exposures tables and select exposures matching the given criteria
   * add entries which are allowed (mosaic) to the p1.pending table
@@ -8,7 +8,8 @@
 p1search -pending :
   * examine the p1.pending table and select exposures waiting for p1
-  * output the list for p1.tasks
+  * output: lines consisting of:
+    (expID) (p1version) (camera)
 
-p1search -update :
+p1search -done :
   * select completed entries in the p1.pending table
   * move to the p1.done table
Index: /trunk/ippTools/doc/p3tools.sh
===================================================================
--- /trunk/ippTools/doc/p3tools.sh	(revision 6022)
+++ /trunk/ippTools/doc/p3tools.sh	(revision 6022)
@@ -0,0 +1,72 @@
+
+## PanTasks scripts for Phase 3
+
+# tasks: p3pending p3astro p3done
+#
+# queues: 
+#   p3pending: (expID) (version) (cameraID) (state)
+#
+# globals: 
+
+# p3pending : search for images to be processed
+task	       p3pending
+  command      p3search -pending
+  host         local
+
+  # timeout shorter than exec so jobs do not build up
+  periods      -exec     5
+  periods      -poll     1
+  periods      -timeout  4
+
+  # success
+  task.exit    0
+    local i Nstdout
+    # keep only new, unique entries (URL is key)
+    queuesize stdout -var Nstdout
+    for i 0 $Nstdout
+      queuepop stdout -var line
+      queuepush p3pending -uniq -key 0 "$line new"
+    end
+  end
+end
+
+# p3update : submit an exposure to be updated
+task	       p3astro
+  periods      -exec 1
+  periods      -timeout 10
+
+  task.exec
+    local expID version camera Npending
+    queuesize  p3pending -var Npending
+    if ($Npending == 0) break
+
+    queuepop p3pending -var line -key 2 new
+    if ("$line" == "NULL") break
+
+    list tmp -split $line
+    $expID  = $tmp:0
+    $version = $tmp:1
+    $camera = $tmp:2
+    queuepush p3pending "$expID $version $camera run"
+
+    host any
+    command p3astro $expID $version $camera
+  end
+
+  # success
+  task.exit    0
+    queueinit stdout
+    queuepush p3pending $taskargs:0 $taskargs:1 $taskargs:2 done
+  end
+end
+
+# p3update : search for images to be processed
+task	       p3done
+  command      p3search -done
+  host         local
+
+  # timeout shorter than exec so jobs do not build up
+  periods      -exec     30
+  periods      -poll     1
+  periods      -timeout  10
+end
Index: /trunk/ippTools/doc/p3tools.txt
===================================================================
--- /trunk/ippTools/doc/p3tools.txt	(revision 6021)
+++ /trunk/ippTools/doc/p3tools.txt	(revision 6022)
@@ -2,10 +2,21 @@
 Phase 3 pipeline tools:
 
-p3search -pending :
+p3search -define :
   * examine the raw.exposures tables and select exposures matching the given criteria
   * add entries which are allowed (mosaic) to the p3.pending table
 
-p3search -update :
-  * select completed entries in the p1.pending table
-  * move to the p1.done table
-  * add new entry to the p2.pending tables
+p3search -quick :
+  * examine the raw.exposures tables and select exposures matching the given criteria
+  * return list of entries for p3 processing
+  * output: lines consisting of:
+    (expID) (p3version) (camera)
+
+p3search -pending :
+  * examine the p3.pending exposures table and select exposures waiting for p3
+  * return list of entries for p3 processing
+  * output: lines consisting of:
+    (expID) (p3version) (camera)
+
+p3search -done :
+  * select completed entries in the p3.pending table
+  * move to the p3.done table
