Index: /branches/eam_branches/eam_branch_00/ippTasks/.cvsignore
===================================================================
--- /branches/eam_branches/eam_branch_00/ippTasks/.cvsignore	(revision 22131)
+++ /branches/eam_branches/eam_branch_00/ippTasks/.cvsignore	(revision 22131)
@@ -0,0 +1,2 @@
+.pantasks
+.pcontrol
Index: /branches/eam_branches/eam_branch_00/ippTasks/detrend.mkruns.pro
===================================================================
--- /branches/eam_branches/eam_branch_00/ippTasks/detrend.mkruns.pro	(revision 22131)
+++ /branches/eam_branches/eam_branch_00/ippTasks/detrend.mkruns.pro	(revision 22131)
@@ -0,0 +1,97 @@
+## XXX this script needs to be updated to use books, not queues
+## XXX this script needs to be reconsidered...
+
+## This script defines tasks which regularly initiate the detrend
+## runs.  Each detrend type is given its own task, which are run once
+## (or twice) per day to build the relevant detrend data
+
+## when one of these tasks is run, it creates a new detrend run ID in
+## the database, and selects the exposures for that run on the basis
+## of the specified filters
+
+# create a new detrend bias-creation run
+task mkdetruns.megacam
+  # command      dettool -select -time NOW -24h -type bias -camera megacam
+  command      mkdetruns.megacam
+  host         local
+
+  periods      -poll 1
+  periods      -exec 60
+  periods      -timeout 30
+  trange        18:00 19:00 -nmax 1
+
+  # success: a new detrend run was created
+  task.exit    0
+    echo "new MEGACAM detrend runs"
+    queueprint stdout
+  end
+
+  # default exit status
+  task.exit default
+    echo "unable to define a new detrend run"
+  end
+
+  # operation timed out?  is the database down?
+  task.exit timeout
+    # send someone email?
+    echo "unable to define a new detrend run"
+  end
+end
+
+# create a new detrend bias-creation run
+task mkdetruns.isp
+  # command      dettool -select -time NOW -24h -type bias -camera megacam
+  command      mkdetruns.isp
+  host         local
+
+  periods      -poll 1
+  periods      -exec 60
+  periods      -timeout 30
+  trange        18:00 19:00 -nmax 1
+
+  # success: a new detrend run was created
+  task.exit    0
+    echo "new ISP detrend runs"
+    queueprint stdout
+  end
+
+  # default exit status
+  task.exit default
+    echo "unable to define a new detrend run"
+  end
+
+  # operation timed out?  is the database down?
+  task.exit timeout
+    # send someone email?
+    echo "unable to define a new detrend run"
+  end
+end
+
+# create a new detrend bias-creation run
+task mkdetruns.gpc
+  # command      dettool -select -time NOW -24h -type bias -camera megacam
+  command      mkdetruns.gpc
+  host         local
+
+  periods      -poll 1
+  periods      -exec 60
+  periods      -timeout 30
+  trange        18:00 19:00 -nmax 1
+
+  # success: a new detrend run was created
+  task.exit    0
+    echo "new GPC detrend runs"
+    queueprint stdout
+  end
+
+  # default exit status
+  task.exit default
+    echo "unable to define a new detrend run"
+  end
+
+  # operation timed out?  is the database down?
+  task.exit timeout
+    # send someone email?
+    echo "unable to define a new detrend run"
+  end
+end
Index: /branches/eam_branches/eam_branch_00/ippTasks/detrend.norm.pro
===================================================================
--- /branches/eam_branches/eam_branch_00/ippTasks/detrend.norm.pro	(revision 22131)
+++ /branches/eam_branches/eam_branch_00/ippTasks/detrend.norm.pro	(revision 22131)
@@ -0,0 +1,316 @@
+## this file contains the tasks for running the detrend normalization stages
+## these tasks use the books detPendingNormStatImfile detPendingNormImfile detPendingNormExp
+
+if ($?network == 0)
+  $network = 1
+end
+if ($?parallel == 0)
+  $parallel = 0
+end
+if ($?VERBOSE == 0)
+  echo "VERBOSE not defined: load pantasks.pro first"
+  break
+end
+if ($?LOGDIR == 0)
+  echo "LOGDIR not defined: load pantasks.pro first"
+  break
+end
+
+$LOGSUBDIR = $LOGDIR/detrend
+exec mkdir -p $LOGSUBDIR
+
+book init detPendingNormStatImfile
+book init detPendingNormImfile
+book init detPendingNormExp
+
+macro detnorm.status
+  book listbook detPendingNormStatImfile
+  book listbook detPendingNormImfile
+  book listbook detPendingNormExp
+end
+
+# select images ready for copy 
+# new entries are added to detPendingNormStatImfile
+# compare the new list with the ones already selected
+task	       dettool.normstat.load
+  host         local
+
+  periods      -poll $loadpoll
+  periods      -exec $loadexec
+  periods      -timeout 30
+
+  stdout NULL
+  stderr $LOGSUBDIR/dettool.normstat.log
+
+  task.exec
+    command dettool -tonormalizedstat -limit 20
+  end
+
+  # success
+  task.exit    0
+    # convert 'stdout' to book format
+    ipptool2book stdout detPendingNormStatImfile -key det_id:iteration -uniq
+    if ($VERBOSE > 2)
+      book listbook detPendingNormStatImfile
+    end
+
+    # delete existing entries which are DONE
+    book delpage detPendingNormStatImfile -key state DONE
+  end
+
+  # default exit status
+  task.exit    default
+    showcommand failure
+  end
+
+  # operation times out?
+  task.exit    timeout
+    showcommand timeout
+  end
+end
+
+# copy new images, sending job to desired host
+task	       dettool.normstat.process
+  periods      -poll $runpoll
+  periods      -exec $runexec
+  periods      -timeout 30
+
+  task.exec
+    book npages detPendingNormStatImfile -var N
+    if ($N == 0) break
+    if ($network == 0) break
+    
+    # look for new images in detPendingNormStatImfile
+    book getpage detPendingNormStatImfile 0 -var pageName -key state NULL
+    if ($pageName == NULL) break
+
+    book setword detPendingNormStatImfile $pageName state RUN
+    book getword detPendingNormStatImfile $pageName det_id    -var DET_ID
+    book getword detPendingNormStatImfile $pageName det_type  -var DET_TYPE
+    book getword detPendingNormStatImfile $pageName iteration -var ITERATION
+    book getword detPendingNormStatImfile $pageName camera    -var CAMERA  
+
+    # specify choice of remote host:
+    if ($parallel)
+      host anyhost
+    else
+      host local
+    end
+
+    # XXX add $WORKDIR/$LOG_DIR
+    # XXX use ipp_filename.pl to lookup output file names
+    stdout $LOGSUBDIR/$CAMERA.$DET_TYPE.$DET_ID.$ITERATION.log
+    stderr $LOGSUBDIR/$CAMERA.$DET_TYPE.$DET_ID.$ITERATIION.log
+
+    # save the pageName for future reference below
+    options $pageName
+
+    # create example job options as a demonstration
+    if ($VERBOSE > 1)
+      echo command detrend_norm_calc.pl --det_id $DET_ID --iteration $ITERATION --det_type $DET_TYPE
+    end
+    command detrend_norm_calc.pl --det_id $DET_ID --iteration $ITERATION --det_type $DET_TYPE
+  end
+
+  # default exit status
+  task.exit    default
+    process_exit detPendingNormStatImfile $options:0 $JOB_STATUS
+  end
+
+  # operation times out?
+  task.exit    timeout
+    showcommand timeout
+    book setword detPendingNormStatImfile $options:0 state TIMEOUT
+  end
+end
+
+# select images ready for copy 
+# new entries are added to detPendingNormImfile
+# compare the new list with the ones already selected
+task	       dettool.norm.load
+  host         local
+
+  periods      -poll $loadpoll
+  periods      -exec $loadexec
+  periods      -timeout 30
+
+  stdout NULL
+  stderr $LOGSUBDIR/dettool.norm.log
+
+  task.exec
+    command dettool -tonormalize -limit 20
+  end
+
+  # success
+  task.exit    0
+    # convert 'stdout' to book format
+    ipptool2book stdout detPendingNormImfile -key det_id:iteration -uniq
+    if ($VERBOSE > 2)
+      book listbook detPendingNormImfile
+    end
+
+    # delete existing entries which are DONE
+    book delpage detPendingNormImfile -key state DONE
+  end
+
+  # default exit status
+  task.exit    default
+    showcommand failure
+  end
+
+  # operation times out?
+  task.exit    timeout
+    showcommand timeout
+  end
+end
+
+# copy new images, sending job to desired host
+task	       dettool.norm.process
+  periods      -poll $runpoll
+  periods      -exec $runexec
+  periods      -timeout 30
+
+  task.exec
+    book npages detPendingNormImfile -var N
+    if ($N == 0) break
+    if ($network == 0) break
+    
+    # look for new images in detPendingNormImfile
+    book getpage detPendingNormImfile 0 -var pageName -key state NULL
+    if ($pageName == NULL) break
+
+    book setword detPendingNormImfile $pageName state RUN
+    book getword detPendingNormImfile $pageName det_type  -var DET_TYPE 
+    book getword detPendingNormImfile $pageName camera    -var CAMERA   
+    book getword detPendingNormImfile $pageName uri       -var URI      
+    book getword detPendingNormImfile $pageName det_id    -var DET_ID   
+    book getword detPendingNormImfile $pageName iteration -var ITERATION     
+    book getword detPendingNormImfile $pageName class_id  -var CLASS_ID 
+    book getword detPendingNormImfile $pageName norm      -var NORM     
+
+    # specify choice of remote host:
+    if ($parallel)
+      host anyhost
+    else
+      host local
+    end
+
+    # XXX use ipp_filename.pl to lookup output file names
+    stdout $LOGSUBDIR/$CAMERA.$DET_TYPE.$DET_ID.$ITERATION.log
+    stderr $LOGSUBDIR/$CAMERA.$DET_TYPE.$DET_ID.$ITERATION.log
+
+    # save the pageName for future reference below
+    options $pageName
+
+    # create example job options as a demonstration
+    if ($VERBOSE > 1)
+      echo command detrend_norm_apply.pl --det_id $DET_ID --iteration $ITERATION --class_id $CLASS_ID --value $NORM --input_uri $URI --camera $CAMERA --det_type $DET_TYPE
+    end
+    command detrend_norm_apply.pl --det_id $DET_ID --iteration $ITERATION --class_id $CLASS_ID --value $NORM --input_uri $URI --camera $CAMERA --det_type $DET_TYPE
+  end
+
+  # default exit status
+  task.exit    default
+    process_exit detPendingNormImfile $options:0 state FAIL
+  end
+
+  # operation times out?
+  task.exit    timeout
+    showcommand timeout
+    book setword detPendingNormImfile $options:0 state TIMEOUT
+  end
+end
+
+# select images ready for copy 
+# new entries are added to detPendingNormExp
+# compare the new list with the ones already selected
+task	       dettool.normexp.load
+  host         local
+
+  periods      -poll $loadpoll
+  periods      -exec $loadexec
+  periods      -timeout 30
+
+  stdout NULL
+  stderr $LOGSUBDIR/dettool.normexp.log
+
+  task.exec
+    command dettool -tonormalizedexp -limit 20
+  end
+
+  # success
+  task.exit    0
+    # convert 'stdout' to book format
+    ipptool2book stdout detPendingNormExp -key det_id:iteration -uniq
+    if ($VERBOSE > 2)
+      book listbook detPendingNormExp
+    end
+
+    # delete existing entries which are DONE
+    book delpage detPendingNormExp -key state DONE
+  end
+
+  # default exit status
+  task.exit    default
+    showcommand failure
+  end
+
+  # operation times out?
+  task.exit    timeout
+    showcommand timeout
+  end
+end
+
+# copy new images, sending job to desired host
+task	       dettool.normexp.process
+  periods      -poll $runpoll
+  periods      -exec $runexec
+  periods      -timeout 30
+
+  task.exec
+    book npages detPendingNormExp -var N
+    if ($N == 0) break
+    if ($network == 0) break
+    
+    # look for new images in detPendingNormExp
+    book getpage detPendingNormExp 0 -var pageName -key state NULL
+    if ($pageName == NULL) break
+
+    book setword detPendingNormExp $pageName state RUN
+    book getword detPendingNormExp $pageName det_id    -var DET_ID  
+    book getword detPendingNormExp $pageName iteration -var ITERATION    
+    book getword detPendingNormExp $pageName det_type  -var DET_TYPE
+    book getword detPendingNormExp $pageName camera    -var CAMERA  
+
+    # specify choice of remote host:
+    if ($parallel)
+      host anyhost
+    else
+      host local
+    end
+
+    # XXX add $WORKDIR/$LOG_DIR
+    stdout $LOGSUBDIR/$CAMERA.$DET_TYPE.$DET_ID.$ITERATION.log
+    stderr $LOGSUBDIR/$CAMERA.$DET_TYPE.$DET_ID.$ITERATION.log
+
+    # save the pageName for future reference below
+    options $pageName
+
+    # create example job options as a demonstration
+    if ($VERBOSE > 1)
+      echo command detrend_norm_exp.pl --det_id $DET_ID --iteration $ITERATION --camera $CAMERA --det_type $DET_TYPE
+    end
+    command detrend_norm_exp.pl --det_id $DET_ID --iteration $ITERATION --camera $CAMERA --det_type $DET_TYPE
+  end
+
+  # default exit status
+  task.exit    default
+    process_exit detPendingNormExp $options:0 $JOB_STATUS
+  end
+
+  # operation times out?
+  task.exit    timeout
+    showcommand timeout
+    book setword detPendingNormExp $options:0 state TIMEOUT
+  end
+end
Index: /branches/eam_branches/eam_branch_00/ippTasks/detrend.process.pro
===================================================================
--- /branches/eam_branches/eam_branch_00/ippTasks/detrend.process.pro	(revision 22131)
+++ /branches/eam_branches/eam_branch_00/ippTasks/detrend.process.pro	(revision 22131)
@@ -0,0 +1,230 @@
+## this file contains the tasks for running the detrend processing stage
+## these tasks use the books detPendingProcessedImfile and detPendingProcessedExp
+
+if ($?network == 0)
+  $network = 1
+end
+if ($?parallel == 0)
+  $parallel = 0
+end
+if ($?VERBOSE == 0)
+  echo "VERBOSE not defined: load pantasks.pro first"
+  break
+end
+if ($?LOGDIR == 0)
+  echo "LOGDIR not defined: load pantasks.pro first"
+  break
+end
+
+$LOGSUBDIR = $LOGDIR/detrend
+exec mkdir -p $LOGSUBDIR
+
+book init detPendingProcessedImfile
+book init detPendingProcessedExp
+
+macro detproc.status
+  book listbook detPendingProcessedImfile
+  book listbook detPendingProcessedExp
+end
+
+# select images ready for copy 
+# new entries are added to detPendingProcessedImfile
+# compare the new list with the ones already selected
+task	       dettool.process.load
+  host         local
+
+  periods      -poll $loadpoll
+  periods      -exec $loadexec
+  periods      -timeout 30
+
+  stdout NULL
+  stderr $LOGSUBDIR/detproc.imfile.log
+
+  task.exec
+    command dettool -toprocessedimfile -limit 20
+  end
+
+  # success
+  task.exit    0
+    # convert 'stdout' to book format
+    ipptool2book stdout detPendingProcessedImfile -key det_id:exp_tag:class_id -uniq
+    if ($VERBOSE > 2)
+      book listbook detPendingProcessedImfile
+    end
+
+    # delete existing entries which are DONE
+    book delpage detPendingProcessedImfile -key state DONE
+  end
+
+  # error
+  task.exit    default
+    showcommand failure
+  end
+
+  # operation times out?
+  task.exit    timeout
+    showcommand
+  end
+end
+
+# run detrend_process_imfile.ps on pending images
+task	       dettool.process.run
+  periods      -poll $runpoll
+  periods      -exec $runexec
+  periods      -timeout 30
+
+  task.exec
+    book npages detPendingProcessedImfile -var N
+    if ($N == 0) break
+    if ($network == 0) break
+    
+    # look for new images in detPendingProcessedImfile
+    book getpage detPendingProcessedImfile 0 -var pageName -key state NULL
+    if ($pageName == NULL) break
+
+    book setword detPendingProcessedImfile $pageName state RUN
+    book getword detPendingProcessedImfile $pageName det_id   -var DET_ID   
+    book getword detPendingProcessedImfile $pageName det_type -var DET_TYPE 
+    book getword detPendingProcessedImfile $pageName exp_tag  -var EXP_TAG  
+    book getword detPendingProcessedImfile $pageName class    -var CLASS    
+    book getword detPendingProcessedImfile $pageName class_id -var CLASS_ID 
+    book getword detPendingProcessedImfile $pageName uri      -var URI      
+    book getword detPendingProcessedImfile $pageName camera   -var CAMERA   
+
+    # specify choice of remote host:
+    if ($parallel)
+      host anyhost
+    else
+      host local
+    end
+
+    ## generate output log based on filerule
+    ## XXX use OUTPATH from db to set output path
+    ## XXX use ipp_filename.pl DETPROC.LOG $outroot $CLASS_ID`
+    $word = `basename $EXP_TAG | tr '.' ' '`
+    list word -split $word
+    $base = $word:0
+    stdout $LOGSUBDIR/$base/$EXP_TAG.detproc.$DET_ID.$CLASS_ID.log
+    stderr $LOGSUBDIR/$base/$EXP_TAG.detproc.$DET_ID.$CLASS_ID.log
+    exec mkdir -p $LOGSUBDIR/$base
+
+    # save the pageName for future reference below
+    options $pageName
+
+    # create example job options as a demonstration
+    if ($VERBOSE > 1)
+      echo command detrend_process_imfile.pl --det_id $DET_ID --det_type $DET_TYPE --exp_tag $EXP_TAG --class $CLASS --class_id $CLASS_ID --input_uri $URI --camera $CAMERA
+    end
+    command detrend_process_imfile.pl --det_id $DET_ID --det_type $DET_TYPE --exp_tag $EXP_TAG --class $CLASS --class_id $CLASS_ID --input_uri $URI --camera $CAMERA
+  end
+
+  # default exit status
+  task.exit    default
+    process_exit detPendingProcessedImfile $options:0 $JOB_STATUS
+  end
+
+  # operation times out?
+  task.exit    timeout
+    showcommand timeout
+    book setword detPendingProcessedImfile $options:0 state TIMEOUT
+ end
+end
+
+# select images ready for copy 
+# new entries are added to detPendingProcessedExp
+# compare the new list with the ones already selected
+task	       dettool.processexp.load
+  host         local
+
+  periods      -poll $loadpoll
+  periods      -exec $loadexec
+  periods      -timeout 30
+
+  stdout NULL
+  stderr $LOGSUBDIR/detproc.exp.log
+
+  task.exec
+    command dettool -toprocessedexp -limit 20
+  end
+
+  # success
+  task.exit    0
+    # convert 'stdout' to book format
+    ipptool2book stdout detPendingProcessedExp -key det_id:iteration:exp_tag -uniq
+    if ($VERBOSE > 2)
+      book listbook detPendingProcessedExp
+    end
+
+    # delete existing entries which are DONE
+    book delpage detPendingProcessedExp -key state DONE
+  end
+
+  # error
+  task.exit    default
+    showcommand failure
+  end
+
+  # operation times out?
+  task.exit    timeout
+    showcommand timeout
+  end
+end
+
+# copy new images, sending job to desired host
+task	       dettool.processexp.run
+  periods      -poll $runpoll
+  periods      -exec $runexec
+  periods      -timeout 30
+
+  task.exec
+    book npages detPendingProcessedExp -var N
+    if ($N == 0) break
+    if ($network == 0) break
+    
+    # look for new exposures in detPendingProcessedExp
+    book getpage detPendingProcessedExp 0 -var pageName -key state NULL
+    if ($pageName == NULL) break
+
+    book setword detPendingProcessedExp $pageName state RUN
+    book getword detPendingProcessedExp $pageName det_id    -var DET_ID
+    book getword detPendingProcessedExp $pageName iteration -var ITERATION
+    book getword detPendingProcessedExp $pageName det_type  -var DET_TYPE
+    book getword detPendingProcessedExp $pageName exp_tag   -var EXP_TAG
+    book getword detPendingProcessedExp $pageName camera    -var CAMERA  
+
+    # specify choice of remote host:
+    if ($parallel)
+      host anyhost
+    else
+      host local
+    end
+
+    # XXX this is still a lame rule
+    $word = `basename $EXP_TAG | tr '.' ' '`
+    list word -split $word
+    $base = $word:0
+    stdout $LOGSUBDIR/$base/$EXP_TAG.detproc.$DET_ID.log
+    stderr $LOGSUBDIR/$base/$EXP_TAG.detproc.$DET_ID.log
+    exec mkdir -p $LOGSUBDIR/$base
+
+    # save the pageName for future reference below
+    options $pageName
+
+    # create example job options as a demonstration
+    if ($VERBOSE > 1)
+      echo command detrend_process_exp.pl --det_id $DET_ID --exp_tag $EXP_TAG --camera $CAMERA
+    end
+    command detrend_process_exp.pl --det_id $DET_ID --exp_tag $EXP_TAG --camera $CAMERA
+  end
+
+  # success
+  task.exit    default
+    process_exit detPendingProcessedExp $options:0 $JOB_STATUS
+  end
+
+  # operation times out?
+  task.exit    timeout
+    showcommand timeout
+    book setword detPendingProcessedExp $options:0 state TIMEOUT
+  end
+end
Index: /branches/eam_branches/eam_branch_00/ippTasks/detrend.reject.pro
===================================================================
--- /branches/eam_branches/eam_branch_00/ippTasks/detrend.reject.pro	(revision 22131)
+++ /branches/eam_branches/eam_branch_00/ippTasks/detrend.reject.pro	(revision 22131)
@@ -0,0 +1,121 @@
+## this file contains the tasks for running the detrend processing stage
+## these tasks use the book detRejectExp
+
+if ($?network == 0)
+  $network = 1
+end
+if ($?parallel == 0)
+  $parallel = 0
+end
+if ($?VERBOSE == 0)
+  echo "VERBOSE not defined: load pantasks.pro first"
+  break
+end
+if ($?LOGDIR == 0)
+  echo "LOGDIR not defined: load pantasks.pro first"
+  break
+end
+
+$LOGSUBDIR = $LOGDIR/detrend
+exec mkdir -p $LOGSUBDIR
+
+book init detRejectExp
+
+macro detreject.status
+  book listbook detRejectExp
+end
+
+# select images ready for copy 
+# new entries are added to detRejectExp
+# compare the new list with the ones already selected
+task	       dettool.reject.load
+  host         local
+
+  periods      -poll $loadpoll
+  periods      -exec $loadexec
+  periods      -timeout 30
+
+  stdout NULL
+  stderr $LOGSUBDIR/dettool.reject.log
+
+  task.exec
+    command dettool -residdetrun -limit 20
+  end
+
+  # success
+  task.exit    0
+    # convert 'stdout' to book format
+    ipptool2book stdout detRejectExp -key det_id:iteration -uniq
+    if ($VERBOSE > 2)
+      book listbook detRejectExp
+    end
+
+    # delete existing entries which are DONE
+    book delpage detRejectExp -key state DONE
+  end
+
+  # locked list
+  task.exit    default
+    showcommand failure
+  end
+
+  # operation times out?
+  task.exit    timeout
+    showcommand failure
+  end
+end
+
+# copy new images, sending job to desired host
+task	       dettool.reject.run
+  periods      -poll $runpoll
+  periods      -exec $runexec
+  periods      -timeout 30
+
+  task.exec
+    book npages detRejectExp -var N
+    if ($N == 0) break
+    if ($network == 0) break
+    
+    # look for new images in detRejectExp
+    book getpage detRejectExp 0 -var pageName -key state NULL
+    if ($pageName == NULL) break
+
+    book setword detRejectExp $pageName state RUN
+    book getword detRejectExp $pageName det_id    -var DET_ID   
+    book getword detRejectExp $pageName iteration -var ITERATION     
+    book getword detRejectExp $pageName det_type  -var DET_TYPE 
+    book getword detRejectExp $pageName mode      -var MODE     
+    book getword detRejectExp $pageName camera    -var CAMERA   
+
+    # specify choice of remote host:
+    if ($parallel)
+      host anyhost
+    else
+      host local
+    end
+
+    # I'd like to add CAMERA to the log file...
+    stdout $LOGSUBDIR/$CAMERA.$DET_TYPE.$DET_ID.$ITERATION.log
+    stderr $LOGSUBDIR/$CAMERA.$DET_TYPE.$DET_ID.$ITERATION.log
+
+    # save the pageName for future reference below
+    options $pageName
+
+    # create example job options as a demonstration
+    if ($VERBOSE > 1)
+      echo command detrend_reject_exp.pl --det_id $DET_ID --iteration $ITERATION --det_type $DET_TYPE --camera $CAMERA
+    end
+    command detrend_reject_exp.pl --det_id $DET_ID --iteration $ITERATION --det_type $DET_TYPE --camera $CAMERA
+ end
+
+  # default exit status
+  task.exit    default
+    process_exit detRejectExp $options:0 state FAIL
+  end
+
+  # operation times out?
+  task.exit    timeout
+    showcommand failure
+    book setword detRejectExp $options:0 state TIMEOUT
+  end
+end
Index: /branches/eam_branches/eam_branch_00/ippTasks/detrend.resid.pro
===================================================================
--- /branches/eam_branches/eam_branch_00/ippTasks/detrend.resid.pro	(revision 22131)
+++ /branches/eam_branches/eam_branch_00/ippTasks/detrend.resid.pro	(revision 22131)
@@ -0,0 +1,232 @@
+## this file contains the tasks for running the detrend processing stage
+## these tasks use the books detPendingResidImfile and detPendingResidExp
+
+if ($?network == 0)
+  $network = 1
+end
+if ($?parallel == 0)
+  $parallel = 0
+end
+if ($?VERBOSE == 0)
+  echo "VERBOSE not defined: load pantasks.pro first"
+  break
+end
+if ($?LOGDIR == 0)
+  echo "LOGDIR not defined: load pantasks.pro first"
+  break
+end
+
+$LOGSUBDIR = $LOGDIR/detrend
+exec mkdir -p $LOGSUBDIR
+
+book init detPendingResidImfile
+book init detPendingResidExp
+
+macro detresid.status
+  book listbook detPendingResidImfile
+  book listbook detPendingResidExp
+end
+
+# select images ready for copy 
+# new entries are added to detPendingResidImfile
+# compare the new list with the ones already selected
+task	       dettool.resid.load
+  host         local
+
+  periods      -poll $loadpoll
+  periods      -exec $loadexec
+  periods      -timeout 30
+
+  stdout NULL
+  stderr $LOGSUBDIR/detresid.log
+
+  task.exec
+    command dettool -toresidimfile -limit 20
+  end
+
+  # success
+  task.exit    0
+    # convert 'stdout' to book format
+    ipptool2book stdout detPendingResidImfile -key det_id:iteration:exp_tag:class_id -uniq
+    if ($VERBOSE > 2)
+      book listbook detPendingResidImfile
+    end
+
+    # delete existing entries which are DONE
+    book delpage detPendingResidImfile -key state DONE
+  end
+
+  # default exit status
+  task.exit    default
+    showcommand failure
+  end
+
+  # operation times out?
+  task.exit    timeout
+    showcommand timeout
+  end
+end
+
+# copy new images, sending job to desired host
+task	       dettool.resid.run
+  periods      -poll $runpoll
+  periods      -exec $runexec
+  periods      -timeout 30
+
+  task.exec
+    book npages detPendingResidImfile -var N
+    if ($N == 0) break
+    if ($network == 0) break
+    
+    # look for new images in detPendingResidImfile
+    book getpage detPendingResidImfile 0 -var pageName -key state NULL
+    if ($pageName == NULL) break
+
+    book setword detPendingResidImfile $pageName state RUN
+    book getword detPendingResidImfile $pageName det_id    -var DET_ID   
+    book getword detPendingResidImfile $pageName iteration -var ITERATION     
+    book getword detPendingResidImfile $pageName det_type  -var DET_TYPE 
+    book getword detPendingResidImfile $pageName mode      -var MODE     
+    book getword detPendingResidImfile $pageName exp_tag   -var EXP_TAG  
+    book getword detPendingResidImfile $pageName class_id  -var CLASS_ID 
+    book getword detPendingResidImfile $pageName uri       -var URI      
+    book getword detPendingResidImfile $pageName det_uri   -var DET_URI  
+    book getword detPendingResidImfile $pageName camera    -var CAMERA   
+
+    # specify choice of remote host:
+    if ($parallel)
+      host anyhost
+    else
+      host local
+    end
+
+    # XXX use ipp_filename.pl to lookup output file names
+    $word = `basename $EXP_TAG | tr '.' ' '`
+    list word -split $word
+    $base = $word:0
+    stdout $LOGSUBDIR/$base/$EXP_TAG.detresid.$DET_ID.$ITERATION.$CLASS_ID.log
+    stderr $LOGSUBDIR/$base/$EXP_TAG.detresid.$DET_ID.$ITERATION.$CLASS_ID.log
+    exec mkdir -p $LOGSUBDIR/$base
+
+    # save the pageName for future reference below
+    options $pageName
+
+    # create command
+    if ($VERBOSE > 1)
+      echo command detrend_resid.pl --det_id $DET_ID --iteration $ITERATION --exp_tag $EXP_TAG --class_id $CLASS_ID --det_type $DET_TYPE --detrend $DET_URI --input_uri $URI --camera $CAMERA --mode $MODE
+    end
+    command detrend_resid.pl --det_id $DET_ID --iteration $ITERATION --exp_tag $EXP_TAG --class_id $CLASS_ID --det_type $DET_TYPE --detrend $DET_URI --input_uri $URI --camera $CAMERA --mode $MODE
+  end
+
+  # default exit status
+  task.exit    default
+    process_exit detPendingResidImfile $options:0 $JOB_STATUS
+  end
+
+  # operation times out?
+  task.exit    timeout
+    showcommand timeout
+    book setword detPendingResidImfile $options:0 state TIMEOUT
+  end
+end
+
+# select images ready for copy 
+# new entries are added to detPendingResidExp
+# compare the new list with the ones already selected
+task	       dettool.residexp.load
+  host         local
+
+  periods      -poll $loadpoll
+  periods      -exec $loadexec
+  periods      -timeout 30
+
+  stdout NULL
+  stderr $LOGSUBDIR/detresid.exp.log
+
+  task.exec
+    command dettool -toresidexp -limit 20
+  end
+
+  # success
+  task.exit    0
+    # convert 'stdout' to book format
+    ipptool2book stdout detPendingResidExp -key det_id:iteration:exp_tag -uniq
+    if ($VERBOSE > 2)
+      book listbook detPendingResidExp
+    end
+
+    # delete existing entries which are DONE
+    book delpage detPendingResidExp -key state DONE
+  end
+
+  # default exit status
+  task.exit    default
+    showcommand failure
+  end
+
+  # operation times out?
+  task.exit    timeout
+    showcommand timeout
+  end
+end
+
+# copy new images, sending job to desired host
+task	       dettool.residexp.run
+  periods      -poll $runpoll
+  periods      -exec $runexec
+  periods      -timeout 30
+
+  task.exec
+    book npages detPendingResidExp -var N
+    if ($N == 0) break
+    if ($network == 0) break
+    
+    # look for new images in detPendingResidExp
+    book getpage detPendingResidExp 0 -var pageName -key state NULL
+    if ($pageName == NULL) break
+
+    book setword detPendingResidExp $pageName state RUN
+    book getword detPendingResidExp $pageName det_id    -var DET_ID  
+    book getword detPendingResidExp $pageName iteration -var ITERATION    
+    book getword detPendingResidExp $pageName det_type  -var DET_TYPE
+    book getword detPendingResidExp $pageName mode      -var MODE    
+    book getword detPendingResidExp $pageName exp_tag   -var EXP_TAG 
+    book getword detPendingResidExp $pageName include   -var INCLUDE 
+    book getword detPendingResidExp $pageName camera    -var CAMERA  
+
+    # specify choice of remote host:
+    if ($parallel)
+      host anyhost
+    else
+      host local
+    end
+
+    # XXX use ipp_filename.pl to lookup output file names
+    $word = `basename $EXP_TAG | tr '.' ' '`
+    list word -split $word
+    $base = $word:0
+    stdout $LOGSUBDIR/$base/$EXP_TAG.detresid.$DET_ID.$ITERATION.log
+    stderr $LOGSUBDIR/$base/$EXP_TAG.detresid.$DET_ID.$ITERATION.log
+    exec mkdir -p $LOGSUBDIR/$base
+
+    # save the pageName for future reference below
+    options $pageName
+
+    # create example job options as a demonstration
+    if ($VERBOSE > 1)
+      echo command detrend_reject_imfile.pl --det_id $DET_ID --iteration $ITERATION --exp_tag $EXP_TAG --det_type $DET_TYPE --camera $CAMERA
+    end
+    command detrend_reject_imfile.pl --det_id $DET_ID --iteration $ITERATION --exp_tag $EXP_TAG --det_type $DET_TYPE --camera $CAMERA
+  end
+
+  # default exit status
+  task.exit    default
+    process_exit detPendingResidExp $options:0 $JOB_STATUS
+  end
+
+  # operation times out?
+  task.exit    timeout
+    showcommand timeout
+    book setword detPendingResidExp $options:0 state TIMEOUT
+  end
+end
Index: /branches/eam_branches/eam_branch_00/ippTasks/detrend.stack.pro
===================================================================
--- /branches/eam_branches/eam_branch_00/ippTasks/detrend.stack.pro	(revision 22131)
+++ /branches/eam_branches/eam_branch_00/ippTasks/detrend.stack.pro	(revision 22131)
@@ -0,0 +1,122 @@
+## this file contains the tasks for running the detrend stacking stage
+## these tasks use the book detPendingStackedImfile
+
+if ($?network == 0)
+  $network = 1
+end
+if ($?parallel == 0)
+  $parallel = 0
+end
+if ($?VERBOSE == 0)
+  echo "VERBOSE not defined: load pantasks.pro first"
+  break
+end
+if ($?LOGDIR == 0)
+  echo "LOGDIR not defined: load pantasks.pro first"
+  break
+end
+
+$LOGSUBDIR = $LOGDIR/detrend
+exec mkdir -p $LOGSUBDIR
+
+book init detPendingStackedImfile
+
+macro detstack.status
+  book listbook detPendingStackedImfile
+end
+
+# select images ready for detrend_stack.pl
+# new entries are added to detPendingStackedImfile
+# compare the new list with the ones already selected
+task	       dettool.stack.load
+  host         local
+
+  periods      -poll $loadpoll
+  periods      -exec $loadexec
+  periods      -timeout 30
+
+  stdout NULL
+  stderr $LOGSUBDIR/detstack.log
+
+  task.exec
+    command dettool -tostacked -limit 20
+  end
+
+  # success
+  task.exit    0
+    # convert 'stdout' to book format
+    ipptool2book stdout detPendingStackedImfile -key det_id:iteration:class_id -uniq
+    if ($VERBOSE > 2)
+      book listbook detPendingStackedImfile
+    end
+
+    # delete existing entries which are DONE
+    book delpage detPendingStackedImfile -key state DONE
+  end
+
+  # locked list
+  task.exit    default
+    showcommand failure
+  end
+
+  # operation times out?
+  task.exit    timeout
+    showcommand timeout
+  end
+end
+
+# copy new images, sending job to desired host
+task	       dettool.stack.run
+  periods      -poll $runpoll
+  periods      -exec $runexec
+  periods      -timeout 120
+
+  task.exec
+    book npages detPendingStackedImfile -var N
+    if ($N == 0) break
+    if ($network == 0) break
+    
+    # look for new images in detPendingStackedImfile
+    book getpage detPendingStackedImfile 0 -var pageName -key state NULL
+    if ($pageName == NULL) break
+
+    book setword detPendingStackedImfile $pageName state RUN
+    book getword detPendingStackedImfile $pageName det_id    -var DET_ID
+    book getword detPendingStackedImfile $pageName iteration -var ITERATION
+    book getword detPendingStackedImfile $pageName det_type  -var DET_TYPE
+    book getword detPendingStackedImfile $pageName class_id  -var CLASS_ID
+    book getword detPendingStackedImfile $pageName camera    -var CAMERA  
+
+    # specify choice of remote host:
+    if ($parallel)
+      host anyhost
+    else
+      host local
+    end
+
+    # XXX add $WORKDIR/$LOG_DIR
+    # XXX use ipp_filename.pl to lookup output file names
+    stdout $LOGSUBDIR/$CAMERA.$DET_TYPE.$DET_ID.$ITERATION.$CLASS_ID.log
+    stderr $LOGSUBDIR/$CAMERA.$DET_TYPE.$DET_ID.$ITERATION.$CLASS_ID.log
+
+    # save the pageName for future reference below
+    options $pageName
+
+    # create the command line
+    if ($VERBOSE > 1)
+      echo command detrend_stack.pl --det_id $DET_ID --iteration $ITERATION --class_id $CLASS_ID --det_type $DET_TYPE --camera $CAMERA
+    end
+    command detrend_stack.pl --det_id $DET_ID --iteration $ITERATION --class_id $CLASS_ID --det_type $DET_TYPE --camera $CAMERA
+  end
+
+  # default exit status
+  task.exit    default
+    process_exit detPendingStackedImfile $options:0 $JOB_STATUS
+  end
+
+  # operation times out?
+  task.exit    timeout
+    showcommand timeout
+    book setword detPendingStackedImfile $options:0 state TIMEOUT
+  end
+end
Index: /branches/eam_branches/eam_branch_00/ippTasks/mkdetrend.pro
===================================================================
--- /branches/eam_branches/eam_branch_00/ippTasks/mkdetrend.pro	(revision 22131)
+++ /branches/eam_branches/eam_branch_00/ippTasks/mkdetrend.pro	(revision 22131)
@@ -0,0 +1,8 @@
+
+input detrend.mkruns.pro
+input detrend.process.pro
+input detrend.stack.pro
+input detrend.norm.pro
+input detrend.resid.pro
+input detrend.assess.pro
+
Index: /branches/eam_branches/eam_branch_00/ippTasks/notes.txt
===================================================================
--- /branches/eam_branches/eam_branch_00/ippTasks/notes.txt	(revision 22131)
+++ /branches/eam_branches/eam_branch_00/ippTasks/notes.txt	(revision 22131)
@@ -0,0 +1,192 @@
+
+2007.01.08
+
+  I have updated pantasks to used named tags in named groups to make
+  life much easier when changing the schema of the db tables.  The
+  function ipptool2book convernts the output from an ippTool query in
+  the form of a set of metadata structures (saved in stdout) into a
+  book format.
+
+  dettool -tonormalizedstat     DetrendNormStat
+  dettool -tonormalize          DetrendNorm
+  dettool -tonormalizedexp      DetrendNormExp
+  dettool -toprocessedimfile    DetrendProcessImfiles
+  dettool -toprocessedexp       DetrendProcessExposures
+  dettool -residdetrun          DetrendRejectExp
+  dettool -toresidimfile        DetrendResidImfiles
+  dettool -toresidexp           DetrendResidExposures
+  dettool -tostacked            DetrendStackClass
+  p0tool -pendingimfile         Phase0Imfiles
+  p0tool -pendingexp            Phase0Exposures
+  p2tool -pendingimfile         Phase2Imfiles
+  p3tool -pendingexp            Phase3Exposures
+
+2006.08.28
+
+- ipptools need to use expID:camera:telescope as unique key (ie, not expID alone)
+- p0tool -pendingimfile -simple needs to report the expKey (ie, not expID)
+- 
+
+
+This directory contains the PanTasks scripts which define the steps
+performed by the IPP.  These scripts use the ippTools to decide what
+images need to be processed, and to update the Metadata Database with
+the current state of the analysis.  The analysis is performed using
+IPP programs which are distributed to the cluster computers as needed.
+
+1. The Detrend Creation Scripts
+
+The detrend creation process is among the more complex elements of the
+IPP.  There are N major steps which must be performed:
+
+1.1. Define New Detrend Runs
+
+The script 'detrend.mkruns.pro' defines tasks which initiate new
+Detrend Runs.  There is a separate task for each camera automatically
+processed by the system (mkdetruns.CAMERA).  These tasks are executed
+on a regular, but infrequent basis.  The tasks call external helper
+programs which actually run the command dettools -define.  The helper
+programs are thus responsible for identifying all of the types of
+detrend images to be run for a given camera, as well as the correct
+set of filters to apply.  These tasks are run locally and only affect
+the database.  PanTasks does not track the detrend runs which are
+created.  
+
+- we may need to define these within the PanTasks scripts
+- how frequently are these tasks run (1/day?)
+- if no raw images are selected by the query, no new detrun should be
+  created.
+- we may need different schedules for the dark (bias/dark) and the
+  light (flat/fringe) data.  And yet another schedule for sky data
+  (skyflat/skyfringe).
+
+1.2. Process new raw imfiles
+
+The script 'detrend.process.pro' defines tasks which processes the new
+raw imfiles for any detrend run.  This script defines two tasks,
+'dettool.raw.load' and 'dettool.raw.process'.  The first script
+occasionally polls the Metadata Database to select raw imfiles which
+have been identified as part of a detrend run.  The identified raw
+imfiles are added to an internal queue, DetrendImfilesToProcess.  Any
+raw imfile already in the list is ignored.  The imfiles are added to
+the queue with a state of NEW.  The second task examines the queue for
+imfiles with state NEW and defines a ppImage analysis job for that
+imfile.  The job is sent to pcontrol for processing on the distributed
+cluster.  At this point, the corresponding queue entry is set to the
+state RUN. Upon success, the queue entry is set to DONE and the
+database is notified of the successful operation.  The DONE entries
+are occasionally pruned from the queue; this must be done in the same
+task as the initial query and the update of the list based on the
+database results.  
+
+- we need to define the columns in the output of dettool -raw
+- we need a method to associate an imfile with a node in the cluster
+- we need to perform some appropriate action when the queries fail.
+- we need a method to generate the output URIs
+- we need a method to identify the correct recipe (function of type?)
+
+1.3. Stack new processed imfiles
+
+The script 'detrend.stack.pro' defines tasks which stack the newly
+processed imfiles for any detrend run iteration.  This script defines
+two tasks, 'dettool.stack.load and 'dettool.stack.process.  The first
+script occasionally polls the Metadata Database to select class IDs
+for detrend runs for which the input imfiles have all been processed.
+The identified detRun/classID combination is added to an internal
+queue, DetrendClassIDtoStack.  The entries are added to the queue with
+a state of NEW.  The second task examines the queue for entries with a
+state of NEW.  It defines a ppMerge analysis job for that
+detID/classID.  The helper script selects the corresponding input
+imfiles and passes them to ppMerge.  The job is sent to pcontrol for
+processing on the distributed cluster.  At this point, the
+corresponding queue entry is set to the state RUN. Upon success, the
+queue entry is set to DONE and the database is notified of the
+successful operation.  The DONE entries are occasionally pruned from
+the queue; this must be done in the same task as the initial query and
+the update of the list based on the database results.
+
+- we need to define the columns in the output of dettool -chip -processed
+- we need a method to associate a classID with a node in the cluster
+- we need to perform some appropriate action when the queries fail.
+- we need a method to generate the output URIs (not a function of the imfiles...)
+- we need a method to identify the correct recipe (function of type?)
+
+
+1.4. Normalize stacked masters
+
+The script 'detrend.norm.pro' defines tasks which normalize the newly
+processed stacks for any detrend run iteration.  This script defines
+two tasks, 'dettool.norm.load and 'dettool.norm.process.  The first
+script occasionally polls the Metadata Database to select detrun IDs
+for which the classes have all been stacked.  The identified
+detRunID/iteration combination is added to an internal queue,
+DetrendRunToNormalize.  The entries are added to the queue with a
+state of NEW.  The second task examines the queue for entries with a
+state of NEW.  It defines a ppNorm analysis job for that
+detID/iteration.  The job is sent to pcontrol for processing on the
+distributed cluster.  At this point, the corresponding queue entry is
+set to the state RUN. Upon success, the queue entry is set to DONE and
+the database is notified of the successful operation.  The DONE
+entries are occasionally pruned from the queue; this must be done in
+the same task as the initial query and the update of the list based on
+the database results.
+
+- we need to define the columns in the output of dettool
+- we need to perform some appropriate action when the queries fail.
+- we need a method to generate the output URIs (not a function of the imfiles...)
+- we need a method to identify the correct recipe (function of type?)
+- we need to define the ppNorm operation inputs and outputs better
+
+
+1.5. Generate Resid Imfiles
+
+The script 'detrend.resid.pro' defines tasks which apply the newly
+generated detrend image to the corresponding input images to generate
+the residual images.  This script defines two tasks,
+'dettool.resid.load and 'dettool.resid.process.  The first script
+occasionally polls the Metadata Database to select imfiles for which
+the master detrend images has been normalized.  The identified imfiles
+are added to an internal queue, DetrendResidImfiles.  The entries are
+added to the queue with a state of NEW.  The second task examines the
+queue for entries with a state of NEW.  It defines a ppImage analysis
+job for that imfile.  The job is sent to pcontrol for processing on
+the distributed cluster.  At this point, the corresponding queue entry
+is set to the state RUN. Upon success, the queue entry is set to DONE
+and the database is notified of the successful operation.  The DONE
+entries are occasionally pruned from the queue; this must be done in
+the same task as the initial query and the update of the list based on
+the database results.
+
+- we need to define the columns in the output of dettool
+- can we select the imfiles here without apriori knowledge that the
+  master has been normalized?
+- we need to perform some appropriate action when the queries fail.
+- we need a method to generate the output URIs (not a function of the imfiles...)
+- we need a method to identify the correct recipe (function of type?)
+- we need a method to pass the matching detrend image to ppImage in
+  the correct context (ie, a bias needs to be supplied to the -bias element...)
+
+1.6. Assess Detrend Results
+
+The script 'detrend.assess.pro' defines tasks which assess the
+residual statistics for completed detrend runs.  This script defines
+two tasks, 'dettool.assess.load and 'dettool.assess.process.  The
+first script occasionally polls the Metadata Database to select
+detrunIDs/iterations for which the resid imfiles have all been
+generated.  The identified detruns are added to an internal queue,
+DetrendRunToAssess.  The entries are added to the queue with a state
+of NEW.  The second task examines the queue for entries with a state
+of NEW.  It defines an analysis job for that collection.  The job is
+sent to pcontrol for processing on the distributed cluster.  At this
+point, the corresponding queue entry is set to the state RUN. Upon
+success, the queue entry is set to DONE and the database is notified
+of the successful operation.  The DONE entries are occasionally pruned
+from the queue; this must be done in the same task as the initial
+query and the update of the list based on the database results.
+
+- the assess tool needs to trigger a new run, if needed.
+- what is the command to run on the resid statistics?
+- we need to define the columns in the output of dettool
+- can we select the detrend runs here?
+- we need to perform some appropriate action when the queries fail.
+- we need a method to generate the output URIs (not a function of the imfiles...)
Index: /branches/eam_branches/eam_branch_00/ippTasks/p0tool.sh
===================================================================
--- /branches/eam_branches/eam_branch_00/ippTasks/p0tool.sh	(revision 22131)
+++ /branches/eam_branches/eam_branch_00/ippTasks/p0tool.sh	(revision 22131)
@@ -0,0 +1,7 @@
+#!/bin/csh -f
+if ($#argv != 1) then
+  echo "USAGE: p0tool.sh (Nselect)"
+  exit 2
+endif
+
+p0tool -pendingimfile -simple | head -n $1
Index: /branches/eam_branches/eam_branch_00/ippTasks/pantasks.pro
===================================================================
--- /branches/eam_branches/eam_branch_00/ippTasks/pantasks.pro	(revision 22131)
+++ /branches/eam_branches/eam_branch_00/ippTasks/pantasks.pro	(revision 22131)
@@ -0,0 +1,163 @@
+
+# XXX make these upper-case
+$network = 1
+$parallel = 1
+$VERBOSE = 1
+
+# $scripts = $HOME/src/pantasks/ipp/ippTasks
+$scripts = .
+# $LOGDIR = `ipp_datapath.pl path://ESSENCE`
+# $LOGDIR = `ipp_datapath.pl path://SIMTEST`
+# $LOGDIR = `ipp_datapath.pl path://ISPTEST`
+# $LOGDIR = $LOGDIR/logs
+# exec mkdir -p $LOGDIR
+
+$loadpoll = 1
+$loadexec = 5
+$runpoll = 0.5
+$runexec = 1
+
+$EXIT_SUCCESS     = 0
+$EXIT_UNKNOWN_ERR = 1
+$EXIT_SYS_ERR     = 2
+$EXIT_CONFIG_ERR  = 3
+$EXIT_PROG_ERR    = 4
+$EXIT_DATA_ERR    = 5
+
+$DB:n = 0
+
+macro init.simtest
+  $LOGDIR = `ipp_datapath.pl path://SIMTEST`
+  $LOGDIR = $LOGDIR/logs
+  exec mkdir -p $LOGDIR
+
+  list DB -add simtest
+
+  if ($parallel) 
+    controller exit true
+    controller host add alala
+  end
+end
+
+macro init.essence
+  $LOGDIR = `ipp_datapath.pl path://ESSENCE`
+  $LOGDIR = $LOGDIR/logs
+  exec mkdir -p $LOGDIR
+
+  list DB -add essence_v2
+
+  if ($parallel) 
+    controller exit true
+    controller host add sn2
+    controller host add sn3
+    controller host add sn4
+    controller host add sn5
+  end
+end
+
+macro init.isptest
+  $LOGDIR = `ipp_datapath.pl path://ISPTEST`
+  $LOGDIR = $LOGDIR/logs
+  exec mkdir -p $LOGDIR
+
+  list DB -add isptest
+
+  if ($parallel) 
+    controller exit true
+    controller host add po02
+    controller host add po03
+    controller host add po04
+    controller host add po05
+    controller host add po06
+    controller host add po07
+    controller host add po08
+    controller host add po09
+    controller host add po10
+  end
+end
+
+# need the ability to activate or deactivate specific tasks...
+
+macro load.tasks
+  input $scripts/phase0.pro
+#  input $scripts/phase2.pro
+# input $scripts/phase3.pro
+
+  input $scripts/detrend.process.pro
+  input $scripts/detrend.stack.pro
+  input $scripts/detrend.norm.pro
+  input $scripts/detrend.resid.pro
+  input $scripts/detrend.reject.pro
+end
+
+macro showcommand
+  local n 
+
+  if ($VERBOSE)
+    $command = $taskarg:0
+    for n 1 $taskarg:n
+      $command = $command $taskarg:$n
+    end
+    if ($0 == 2)
+      echo "$1 for: $command"
+      echo "job exit status: $JOB_STATUS"
+      echo "job dtime: $JOB_DTIME"
+    else
+      echo "command: $command"
+    end    
+  end
+end
+
+macro process_exit
+  if ($0 != 4)
+    echo "USAGE: process_exit (bookName) (pageName) (exitCode)"
+    break
+  end
+
+  $bookName = $1
+  $pageName = $2
+  $exitCode = $3
+
+  # success
+  if ($exitCode == $EXIT_SUCCESS) 
+    # the handler scripts update DB the tables; here we just update the page
+    book setword $bookName $pageName state DONE
+    return
+  end
+
+  # failure related to the data files
+  # jobs which result in DATAERR must have db state updated 
+  if ($exitCode == $EXIT_DATA_ERR)
+    showcommand failure
+    book setword $bookName $pageName state DATA_ERR
+    return
+  end
+
+  # failure related to the data files
+  if ($exitCode == $EXIT_SYS_ERR)
+    halt
+    showcommand "system failure"
+    book setword $bookName $pageName state SYS_ERR
+    return
+  end
+
+  # failure related to the data files
+  if ($exitCode == $EXIT_CONFIG_ERR)
+    halt
+    showcommand "config error"
+    book setword $bookName $pageName state CONFIG_ERR
+    return
+  end
+
+  # failure related to the data files
+  if ($exitCode == $EXIT_PROG_ERR)
+    halt
+    showcommand "programming error"
+    book setword $bookName $pageName state PROG_ERR
+    return
+  end
+
+  # any other exit status
+  showcommand failure
+  book setword $bookName $pageName state UNKNOWN_ERR
+end
Index: /branches/eam_branches/eam_branch_00/ippTasks/phase0.pro
===================================================================
--- /branches/eam_branches/eam_branch_00/ippTasks/phase0.pro	(revision 22131)
+++ /branches/eam_branches/eam_branch_00/ippTasks/phase0.pro	(revision 22131)
@@ -0,0 +1,239 @@
+## this file contains the tasks for running the phase 0 stage
+## these tasks use the books p0PendingImfile and p0PendingExp
+
+if ($?network == 0)
+  $network = 1
+end
+if ($?parallel == 0)
+  $parallel = 0
+end
+if ($?VERBOSE == 0)
+  echo "VERBOSE not defined: load pantasks.pro first"
+  break
+end
+if ($?LOGDIR == 0)
+  echo "LOGDIR not defined: load pantasks.pro first"
+  break
+end
+
+$LOGSUBDIR = $LOGDIR/phase0
+exec mkdir -p $LOGSUBDIR
+
+book init p0PendingImfile
+book init p0PendingExp
+
+macro phase0.status
+  book listbook p0PendingImfile
+  book listbook p0PendingExp
+end
+
+$phase0_DB = 0
+
+# select images ready for phase0 analysis
+# new entries are added to p0PendingImfile
+# compare the new list with the ones already selected
+task	       phase0.imfile.load
+  host         local
+
+  periods      -poll $loadpoll
+  periods      -exec $loadexec
+  periods      -timeout 30
+
+  # XXX test that this option works
+  npending     1
+
+  # silently drop stdout
+  stdout NULL
+  stderr $LOGSUBDIR/phase0.imfile.log
+
+  # select entries from the current DB; cycle to the next DB, if it exists
+  # if the DB list is not set, use the value defined in .ipprc
+  task.exec
+    if ($DB:n == 0)
+      command p0tool -pendingimfile -limit 20
+    else
+      command p0tool -pendingimfile -limit 20 -dbname $DB:$phase0_DB
+      $phase0_DB ++
+      if ($phase0_DB >= $DB:n) set phase0_DB = 0
+    end
+  end
+
+  # success
+  task.exit $EXIT_SUCCESS
+    # convert 'stdout' to book format
+    ipptool2book stdout p0PendingImfile -key exp_tag -uniq
+    if ($VERBOSE > 2)
+      book listbook p0PendingImfile
+    end
+
+    # delete existing entries which are DONE or DATAERR
+    book delpage p0PendingImfile -key state DONE
+    book delpage p0PendingImfile -key state DATA_ERR
+  end
+
+  # locked list
+  task.exit    default
+    showcommand failure
+  end
+
+  # operation times out?
+  task.exit    timeout
+    showcommand timeout
+  end
+end
+
+# run the phase0_imfile.pl script on pending images
+task	       phase0.imfile.run
+  periods      -poll $runpoll
+  periods      -exec $runexec
+  periods      -timeout 30
+
+  task.exec
+    book npages p0PendingImfile -var N
+    if ($N == 0) break
+    if ($network == 0) break
+    
+    # look for new images in p0PendingImfile
+    book getpage p0PendingImfile 0 -var pageName -key state NULL
+    if ($pageName == NULL) break
+
+    book setword p0PendingImfile $pageName state RUN
+
+    book getword p0PendingImfile $pageName exp_tag -var EXP_TAG
+    book getword p0PendingImfile $pageName class -var CLASS
+    book getword p0PendingImfile $pageName class_id -var CLASS_ID
+    book getword p0PendingImfile $pageName uri -var URI
+    book getword p0PendingImfile $pageName outpath -var OUTPATH
+    book getword p0PendingImfile $pageName dbname -var DBNAME
+
+    # specify choice of remote host
+    if ($parallel)
+      host anyhost
+    else
+      host local
+    end
+
+    ## generate output log based on filerule
+    $outroot = $OUTPATH/$EXP_TAG
+    $logfile = `ipp_filename.pl PHASE0.LOG $outroot $CLASS_ID`
+    stdout $logfile
+    stderr $logfile
+    exec mkdir -p $OUTPATH
+
+    # save the pageName for future reference below
+    options $pageName
+
+    # create the command line
+    if ($VERBOSE > 1)
+      echo command phase0_imfile.pl --exp_tag $EXP_TAG --class_id $CLASS_ID --uri $URI --dbname $DBNAME
+    end
+    command phase0_imfile.pl --exp_tag $EXP_TAG --class_id $CLASS_ID --uri $URI --dbname $DBNAME
+  end
+
+  # default exit status
+  task.exit default
+    process_exit p0PendingImfile $options:0 $JOB_STATUS
+  end
+
+  # operation timed out?
+  task.exit    timeout
+    showcommand timeout
+    book setword p0PendingImfile $options:0 state TIMEOUT
+  end
+end
+
+# select exposures ready for phase0_exp.pl
+task	       phase0.exp.load
+  host         local
+
+  periods      -poll $loadpoll
+  periods      -exec $loadexec
+  periods      -timeout 30
+
+  stdout NULL
+  stderr $LOGSUBDIR/phase0.exp.log
+
+  task.exec
+    command p0tool -pendingexp -limit 20
+  end
+
+  # success
+  task.exit    0
+    # convert 'stdout' to book format
+    ipptool2book stdout p0PendingExp -key exp_tag -uniq
+    if ($VERBOSE > 2)
+      book listbook p0PendingExp
+    end
+
+    # delete existing entries which are DONE
+    book delpage p0PendingExp -key state DONE
+    book delpage p0PendingExp -key state DATA_ERR
+  end
+
+  # default exit status
+  task.exit    default
+    showcommand failure
+  end
+
+  # operation times out?
+  task.exit    timeout
+    showcommand timeout
+  end
+end
+
+# run the phase0_exp.pl script on pending exposures
+task	       phase0.exp.run
+  periods      -poll $runpoll
+  periods      -exec $runexec
+  periods      -timeout 30
+
+  task.exec
+    book npages p0PendingExp -var N
+    if ($N == 0) break
+    if ($network == 0) break
+    
+    # look for new images in p0PendingExp (state == NULL)
+    book getpage p0PendingExp 0 -var pageName -key state NULL
+    if ($pageName == NULL) break
+
+    book setword p0PendingExp $pageName state RUN
+    book getword p0PendingExp $pageName exp_tag -var EXP_TAG
+    book getword p0PendingExp $pageName outpath -var OUTPATH
+
+    # specify choice of remote host:(need to choose based on chips)
+    if ($parallel)
+      host anyhost
+    else
+      host local
+    end
+
+    ## generate output log based on filerule
+    $outroot = $OUTPATH/$EXP_TAG
+    $logfile = `ipp_filename.pl PHASE0.LOG $outroot FPA`
+    stdout $logfile
+    stderr $logfile
+    exec mkdir -p $OUTPATH
+
+    # save the pageName for future reference below
+    options $pageName
+
+    # create the command line
+    if ($VERBOSE > 1)
+      echo command phase0_exp.pl --exp_tag $EXP_TAG
+    end
+    command phase0_exp.pl --exp_tag $EXP_TAG
+  end
+
+  # success
+  task.exit default
+    process_exit p0PendingExp $options:0 $JOB_STATUS
+  end
+
+  # operation times out?
+  task.exit    timeout
+    showcommand timeout
+    book setword p0PendingExp $options:0 state TIMEOUT
+  end
+end
+
+## XXX add a global path to output files  
Index: /branches/eam_branches/eam_branch_00/ippTasks/phase2.pro
===================================================================
--- /branches/eam_branches/eam_branch_00/ippTasks/phase2.pro	(revision 22131)
+++ /branches/eam_branches/eam_branch_00/ippTasks/phase2.pro	(revision 22131)
@@ -0,0 +1,125 @@
+## this file contains the tasks for running the phase 0 stage
+## these tasks use the book p2PendingImfile
+
+if ($?network == 0)
+  $network = 1
+end
+if ($?parallel == 0)
+  $parallel = 0
+end
+if ($?VERBOSE == 0)
+  echo "VERBOSE not defined: load pantasks.pro first"
+  break
+end
+if ($?LOGDIR == 0)
+  echo "LOGDIR not defined: load pantasks.pro first"
+  break
+end
+
+$LOGSUBDIR = $LOGDIR/phase2
+exec mkdir -p $LOGSUBDIR
+
+book init p2PendingImfile
+
+macro phase2.status
+  book listbook p2PendingImfile
+end
+
+# select images ready for phase2 analysis
+# new entries are added to p2PendingImfile
+# skip already-present entries
+task	       phase2.imfile.load
+  host         local
+
+  periods      -poll $loadpoll
+  periods      -exec $loadexec
+  periods      -timeout 30
+
+  stdout NULL
+  stderr $LOGSUBDIR/phase2.imfile.log
+
+  task.exec
+    command p2tool -pendingimfile -limit 20
+  end
+
+  # success
+  task.exit    0
+    # convert 'stdout' to book format
+    ipptool2book stdout p2PendingImfile -key exp_tag:class_id -uniq
+    if ($VERBOSE > 2)
+      book listbook p2PendingImfile
+    end
+
+    # delete existing entries which are DONE
+    book delpage p2PendingImfile -key state DONE
+  end
+
+  # locked list
+  task.exit    default
+    showcommand failure
+  end
+
+  # operation times out?
+  task.exit    timeout
+    showcommand timeout
+  end
+end
+
+# run the phase2.pl script on pending images
+task	       phase2.imfile.run
+  periods      -poll $runpoll
+  periods      -exec $runexec
+  periods      -timeout 60
+
+  task.exec
+    book npages p2PendingImfile -var N
+    if ($N == 0) break
+    if ($network == 0) break
+    
+    # look for new images in p2PendingImfile (state == NULL)
+    book getpage p2PendingImfile 0 -var pageName -key state NULL
+    if ($pageName == NULL) break
+
+    book setword p2PendingImfile $pageName state RUN
+    book getword p2PendingImfile $pageName camera -var CAMERA
+    book getword p2PendingImfile $pageName exp_tag -var EXP_TAG
+    book getword p2PendingImfile $pageName outpath -var OUTPATH
+    book getword p2PendingImfile $pageName class_id -var CLASS_ID
+    book getword p2PendingImfile $pageName uri -var URI
+
+    # specify choice of remote host
+    # XXX need to choose based on chips
+    if ($parallel)
+      host anyhost
+    else
+      host local
+    end
+
+    ## generate output log based on filerule
+    $outroot = $OUTPATH/$EXP_TAG
+    $logfile = `ipp_filename.pl PHASE2.LOG $outroot $CLASS_ID`
+    stdout $logfile
+    stderr $logfile
+    exec mkdir -p $OUTPATH
+
+    # save the pageName for future reference below
+    options $pageName
+
+    # create the command line
+    if ($VERBOSE > 1)
+      echo command phase2.pl --exp_tag $EXP_TAG --class_id $CLASS_ID --uri $URI --camera $CAMERA
+    end
+    command phase2.pl --exp_tag $EXP_TAG --class_id $CLASS_ID --uri $URI --camera $CAMERA --outpath $OUTPATH
+  end
+
+  # default exit status
+  task.exit    default
+    process_exit p2PendingImfile $options:0 $JOB_STATUS
+  end
+
+  # operation timed out?
+  task.exit    timeout
+    showcommand timeout
+    book setword p2PendingImfile $options:0 state TIMEOUT
+  end
+end
Index: /branches/eam_branches/eam_branch_00/ippTasks/phase3.pro
===================================================================
--- /branches/eam_branches/eam_branch_00/ippTasks/phase3.pro	(revision 22131)
+++ /branches/eam_branches/eam_branch_00/ippTasks/phase3.pro	(revision 22131)
@@ -0,0 +1,131 @@
+## this file contains the tasks for running the phase 3 stage
+## these tasks use the book p3PendingExp
+
+if ($?network == 0)
+  $network = 1
+end
+if ($?parallel == 0)
+  $parallel = 0
+end
+if ($?VERBOSE == 0)
+  echo "VERBOSE not defined: load pantasks.pro first"
+  break
+end
+if ($?LOGDIR == 0)
+  echo "LOGDIR not defined: load pantasks.pro first"
+  break
+end
+
+$LOGSUBDIR = $LOGDIR/phase3
+exec mkdir -p $LOGSUBDIR
+
+book init p3PendingExp
+
+macro phase3.status
+  book listbook p3PendingExp
+end
+
+# select images ready for phase3 analysis
+# new entries are added to p3PendingExp
+# skip already-present entries
+task	       phase3.exp.load
+  host         local
+
+  periods      -poll $loadpoll
+  periods      -exec $loadexec
+  periods      -timeout 30
+
+  stdout $LOGSUBDIR/phase3.exp.log
+  stderr $LOGSUBDIR/phase3.exp.log
+
+  task.exec
+    command p3tool -pendingexp -limit 20
+  end
+
+  # success
+  task.exit    0
+    # convert 'stdout' to book format
+    ipptool2book stdout p3PendingExp -key exp_tag -uniq
+    if ($VERBOSE > 2)
+      book listbook p3PendingExp
+    end
+
+    # delete existing entries which are DONE
+    book delpage p3PendingExp -key state DONE
+  end
+
+  # default exit status
+  task.exit    default
+    showcommand failure
+  end
+
+  # operation times out?
+  task.exit    timeout
+    showcommand timeout
+  end
+end
+
+# run the phase3exposure script on pending images
+task	       phase3.exp.run
+  periods      -poll $runpoll
+  periods      -exec $runexec
+  periods      -timeout 5
+
+  task.exec
+    book npages p3PendingExp -var N
+    if ($N == 0) break
+    if ($network == 0) break
+    
+    # look for new images in p3PendingExp (state == NULL)
+    book getpage p3PendingExp 0 -var pageName -key state NULL
+    if ($pageName == NULL) break
+
+    book setword p3PendingExp $pageName state RUN
+    book getword p3PendingExp $pageName camera -var CAMERA
+    book getword p3PendingExp $pageName exp_tag -var EXP_TAG
+
+    # specify choice of remote host:(need to choose based on chips)
+    if ($parallel)
+      host anyhost
+    else
+      host local
+    end
+
+    # XXX this is still a lame rule
+    $word = `basename $EXP_TAG | tr '.' ' '`
+    list word -split $word
+    $base = $word:0
+    stdout $LOGSUBDIR/$base/$EXP_TAG.log
+    stderr $LOGSUBDIR/$base/$EXP_TAG.log
+    exec mkdir -p $LOGSUBDIR/$base
+
+    # save the pageName for future reference below
+    options $pageName
+
+    # create the command line
+    if ($VERBOSE > 1)
+      echo command phase3.pl --exp_tag $EXP_TAG
+    end
+    command phase3.pl --exp_tag $EXP_TAG --camera $CAMERA
+  end
+
+  # success
+  task.exit 0
+    # phase3exp.pl updates DB tables, here we just update the page
+    book setword p3PendingExp $options:0 state DONE
+  end
+
+  # default exit status
+  task.exit    default
+    showcommand failure
+    book setword p3PendingExp $options:0 state FAIL
+  end
+
+  # operation times out?
+  task.exit    timeout
+    showcommand timeout
+    book setword p3PendingExp $options:0 state TIMEOUT
+  end
+end
+
+## XXX add a global path to output files  
Index: /branches/eam_branches/eam_branch_00/ippTasks/summit.copy.pro
===================================================================
--- /branches/eam_branches/eam_branch_00/ippTasks/summit.copy.pro	(revision 22131)
+++ /branches/eam_branches/eam_branch_00/ippTasks/summit.copy.pro	(revision 22131)
@@ -0,0 +1,308 @@
+## PanTasks scripts for Summit Copy
+
+$uri        = http://otis/ds/skyprobe/
+$camera     = skyprobe
+$telescope  = ps1
+$workdir    = /home/moanui/jhoblitt/workdir
+
+if ($?parallel == 0)
+  $parallel = 0
+end
+
+# queue for summit exps that need to be queried
+queueinit pzPendingExp
+# queue for summit imfiles that need to be downloaded
+queueinit pzPendingImfile
+# queue for downloaded files that need to registered with pztool -copydone
+queueinit pzCopyDone
+
+# run pzgetexp periodically to populate pzPendingExp
+task pzgetexp
+  command      pzgetexp -uri $uri -inst $camera -telescope $telescope
+  host         local
+
+  # timeout shorter than exec so jobs do not build up
+  periods      -exec     30
+  periods      -poll     10
+  periods      -timeout  30
+
+  task.exit     0
+  end
+
+  task.exit     default
+    echo "phaseZ pzgetexp: failure"
+  end
+  task.exit     timeout
+    echo "phaseZ pzgetexp: timeout"
+  end
+end
+
+# build a queue of exps/filesetids that need to be queried
+task pztool.pendingexp
+    command      pztool -pendingexp -simple
+    host         local
+
+    # timeout shorter than exec so jobs do not build up
+    periods      -exec     30
+    periods      -poll     10
+    periods      -timeout  30
+
+    # success
+    task.exit    0
+        local i Nstdout
+        queuesize stdout -var Nstdout
+        for i 0 $Nstdout
+            queuepop stdout -var line
+#            list word -split $line
+#            $exp_id     = $word:0
+#            $camera     = $word:1
+#            $telescope  = $word:2
+#            $dateobs    = $word:3
+#            $exp_type   = $word:4
+#            $uri        = $word:5
+#            $imfiles    = $word:6
+#            queuepush pzPendingExp -uniq -key 1:2:3 "NEW $uri $exp_id $camera $telescope $dateobs $exp_type $uri $imfiles"
+            queuepush pzPendingExp -uniq -key 1:2:3 "NEW $line"
+        end
+
+        queuedrop pzPendingExp -key 0 DONE
+    end
+
+    task.exit     default
+        echo "phaseZ pending exp: failure"
+    end
+    task.exit     timeout
+        echo "phaseZ pending exp: timeout"
+    end
+end
+
+# run pzgetimfiles on pending exps
+task pzgetimfile 
+    periods      -exec     5
+    periods      -poll     5
+    periods      -timeout  15
+
+    task.exec
+        queuesize pzPendingExp -var N
+        if ($N == 0) break
+
+        # get a line out of the queue
+        queuepop pzPendingExp -var line -key 0 NEW
+
+        # take the state out of the line
+        strpop line state
+
+        # put the line back into the queue with a stea of RUN
+        queuepush pzPendingExp -replace -key 1:2:3 "RUN $line"
+
+        # the STATE has already been removed from the line
+        list word -split $line
+        $exp_id     = $word:0
+        $camera     = $word:1
+        $telescope  = $word:2
+        $dateobs    = $word:3
+        $exp_type   = $word:4
+        $uri        = $word:5
+        $imfiles    = $word:6
+
+        # specify choice of remote host:(need to choose based on chips)
+#        if ($parallel)
+#            host anyhost
+#        else
+#            host local
+#        end
+        
+        # store the current line
+        options "$line"
+
+        echo command pzgetimfiles -uri $uri -filesetid $exp_id -inst $camera -telescope $telescope
+        command pzgetimfiles -uri $uri -filesetid $exp_id -inst $camera -telescope $telescope
+    end
+
+    # success
+    task.exit 0
+        queuepush pzPendingExp -replace -key 1:2:3 "DONE $options:0"
+    end
+
+    task.exit default
+        queuepush pzPendingExp -replace -key 1:2:3 "FAIL $options:0"
+    end
+
+    task.exit timeout
+        queuepush pzPendingExp -replace -key 1:2:3 "TIMEOUT $options:0"
+    end
+end
+
+# build a queue of imfiles/files that need to be downloaded
+task pztool.pendingimfile
+    command      pztool -pendingimfile -simple
+    host         local
+
+    # timeout shorter than exec so jobs do not build up
+    periods      -exec     30
+    periods      -poll     10
+    periods      -timeout  30
+
+    # success
+    task.exit    0
+        local i Nstdout
+        queuesize stdout -var Nstdout
+        for i 0 $Nstdout
+            queuepop stdout -var line
+#            list word -split $line
+#            $exp_id     = $word:0
+#            $camera     = $word:1
+#            $telescope  = $word:2
+#            $file_id    = $word:3
+#            $bytes      = $word:4
+#            $md5sum     = $word:5
+#            $class      = $word:6
+#            $class_id   = $word:7
+#            $uri        = $word:8
+#            $exp_tag    = $word:9
+
+            queuepush pzPendingImfile -uniq -key 1:2:3:7:8 "NEW $line"
+        end
+
+        # delete existing entries which are DONE
+        queuedrop pzPendingImfile -key 0 DONE
+    end
+
+    task.exit     default
+        echo "phaseZ pending exp: failure"
+    end
+    task.exit     timeout
+        echo "phaseZ pending exp: timeout"
+    end
+end
+
+# get dsget to retreive an imfile and then call pztool -copydone
+task dsget
+    periods      -exec     5
+    periods      -poll     5
+    periods      -timeout  30
+
+    task.exec
+        queuesize pzPendingImfile -var N
+        if ($N == 0) break
+
+        # get a line out of the queue
+        queuepop pzPendingImfile -var line -key 0 NEW
+
+        # take the state out of the line
+        strpop line state
+
+        # put the line back into the queue with a stea of RUN
+        queuepush pzPendingImfile -replace -key 1:2:3:7:8 "RUN $line"
+
+        # the STATE has already been removed from the line
+        list word -split $line
+        $exp_id     = $word:0
+        $camera     = $word:1
+        $telescope  = $word:2
+        $file_id    = $word:3
+        $bytes      = $word:4
+        $md5sum     = $word:5
+        $class      = $word:6
+        $class_id   = $word:7
+        $uri        = $word:8
+        $exp_tag    = $word:9
+
+#        # specify choice of remote host:(need to choose based on chips)
+#        if ($parallel)
+#            host anyhost
+#        else
+#            host local
+#        end
+        
+        # store the current line without the state
+        options "$line"
+
+        echo "parsing line $line"
+        echo command dsget --uri $uri --filename $workdir/$exp_id.$class_id.fits --bytes $bytes --md5 $md5sum
+        command dsget --uri $uri --filename $workdir/$exp_id.$class_id.fits --bytes $bytes --md5 $md5sum
+    end
+
+    # success
+    task.exit 0
+        # could run copydone from here but how would the exit status be
+        # handled?
+
+        list word -split $options:0
+        $exp_id     = $word:0
+        $camera     = $word:1
+        $telescope  = $word:2
+        $file_id    = $word:3
+        $bytes      = $word:4
+        $md5sum     = $word:5
+        $class      = $word:6
+        $class_id   = $word:7
+        $uri        = $word:8
+        $exp_tag    = $word:9
+        queuepush pzCopyDone -key 1:2:3:7:8 "NEW $options:0 $workdir/$exp_id.$class_id.fits"
+        queuepush pzPendingExp -replace -key 1:2:3:7:8 "DONE $options:0"
+    end
+
+    task.exit default
+        queuepush pzPendingExp -replace -key 1:2:3:7:8 "FAIL $options:0"
+    end
+
+    task.exit timeout
+        queuepush pzPendingExp -replace -key 1:2:3:7:8 "TIMEOUT $options:0"
+    end
+end
+
+task pztool.copydone
+    periods      -exec     5
+    periods      -poll     5
+    periods      -timeout  15
+
+    host local
+
+    task.exec
+        queuesize pzCopyDone -var N
+        if ($N == 0) break
+
+        # get a line out of the queue
+        queuepop pzCopyDone -var line -key 0 NEW
+
+        # take the state out of the line
+        strpop line state
+
+        # put the line back into the queue with a stea of RUN
+        queuepush pzCopyDone -replace -key 1:2:3:7:8 "RUN $line"
+
+        # the STATE has already been removed from the line
+        list word -split $line
+        $exp_id     = $word:0
+        $camera     = $word:1
+        $telescope  = $word:2
+        $file_id    = $word:3
+        $bytes      = $word:4
+        $md5sum     = $word:5
+        $class      = $word:6
+        $class_id   = $word:7
+        $uri        = $word:8
+        $exp_tag    = $word:9
+        $new_uri    = $word:10
+
+        # store the current line without the state
+        options "$line"
+
+        echo command pztool -copydone -exp_id $exp_id -inst $camera -telescope $telescope -class $class -class_id $class_id -uri $uri 
+        command pztool -copydone -exp_id $exp_id -inst $camera -telescope $telescope -class $class -class_id $class_id -uri $new_uri 
+    end
+
+    # success
+    task.exit 0
+        queuepush pzCopyDone -replace -key 1:2:3:6:7 "DONE $options:0"
+    end
+
+    task.exit default
+        queuepush pzCopyDone -replace -key 1:2:3:6:7 "FAIL $options:0"
+    end
+
+    task.exit timeout
+        queuepush pzCopyDone -replace -key 1:2:3:6:7 "TIMEOUT $options:0"
+    end
+end
Index: /branches/eam_branches/eam_branch_00/ippTasks/testscript.pro
===================================================================
--- /branches/eam_branches/eam_branch_00/ippTasks/testscript.pro	(revision 22131)
+++ /branches/eam_branches/eam_branch_00/ippTasks/testscript.pro	(revision 22131)
@@ -0,0 +1,80 @@
+# test for pcontrol
+macro test.pcontrol.simple
+  stop
+  for i 0 100
+   job ls -R /etc
+  end
+
+  status
+  host add alala
+
+  status
+  run
+end
+
+# test for pcontrol
+macro test.pcontrol
+  exec p0tool -pendingimfile -simple | head -n 100 > list.dat
+
+  stop
+  list line -x "cat list.dat"
+  echo $line:0
+  for i 0 $line:n
+   list word -split $line:$i
+   job phase0_imfile.pl --exp_tag $word:0 --class_id fpa --uri $word:3
+  end
+
+  status
+  host add sn2
+  host add sn3
+  host add sn4
+  host add sn5
+
+  status
+  run
+end
+
+# test for pclient
+macro test.pclient
+  exec p0tool -pendingimfile -simple | head -n 100 > list.dat
+
+  list line -x "cat list.dat"
+  echo $line:0
+  for i 0 $line:n
+   list word -split $line:$i
+   job phase0_imfile.pl --exp_tag $word:0 --class_id fpa --uri $word:3
+
+   for i 0 50
+    check
+    output /dev/null
+    status
+    output stdout
+    if ($JOBSTATUS == EXIT)
+      $i = 50
+      reset
+      echo "DONE"
+    else
+      usleep 200000
+    end
+   end
+   if ($JOBSTATUS != EXIT)
+     echo TIMEOUT***
+   end
+  end
+end
+
+macro simple.test
+  for j 0 100
+   job ls
+   for i 0 50
+    check
+    status
+    if ($JOBSTATUS == EXIT)
+      $i = 50
+      reset
+    else
+      usleep 10000
+    end
+   end
+ end
+end
