Index: /trunk/ippTasks/detrend.norm.pro
===================================================================
--- /trunk/ippTasks/detrend.norm.pro	(revision 11322)
+++ /trunk/ippTasks/detrend.norm.pro	(revision 11323)
@@ -29,4 +29,9 @@
   book listbook detPendingNormExp
 end
+
+# these variables will cycle through the known database names
+$detPendingNormStatImfile_DB = 0
+$detPendingNormImfile_DB = 0
+$detPendingNormExp_DB = 0
 
 # select images ready for copy 
@@ -44,5 +49,14 @@
 
   task.exec
-    command dettool -tonormalizedstat -limit 20
+    if ($DB:n == 0)
+      option DEFAULT
+      command dettool -tonormalizedstat -limit 20
+    else
+      # save the DB name for the exit tasks
+      option $DB:$detPendingNormStatImfile_DB
+      command dettool -tonormalizedstat -limit 20 -dbname $DB:$detPendingNormStatImfile_DB
+      $detPendingNormStatImfile_DB ++
+      if ($detPendingNormStatImfile_DB >= $DB:n) set detPendingNormStatImfile_DB = 0
+    end
   end
 
@@ -50,5 +64,5 @@
   task.exit    0
     # convert 'stdout' to book format
-    ipptool2book stdout detPendingNormStatImfile -key det_id:iteration -uniq
+    ipptool2book stdout detPendingNormStatImfile -key det_id:iteration -uniq -setword dbname $options:0
     if ($VERBOSE > 2)
       book listbook detPendingNormStatImfile
@@ -57,4 +71,5 @@
     # delete existing entries which are DONE
     book delpage detPendingNormStatImfile -key state DONE
+    book delpage detPendingNormStatImfile -key state DATA_ERR
   end
 
@@ -90,4 +105,7 @@
     book getword detPendingNormStatImfile $pageName iteration -var ITERATION
     book getword detPendingNormStatImfile $pageName camera    -var CAMERA  
+    book getword detPendingNormStatImfile $pageName workdir   -var WORKDIR
+    book getword detPendingNormStatImfile $pageName dbname    -var DBNAME
+    set_standard_args
 
     # specify choice of remote host:
@@ -108,7 +126,7 @@
     # 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
+      echo command detrend_norm_calc.pl --det_id $DET_ID --iteration $ITERATION --det_type $DET_TYPE $ARGS
+    end
+    command detrend_norm_calc.pl --det_id $DET_ID --iteration $ITERATION --det_type $DET_TYPE $ARGS
   end
 
@@ -139,5 +157,14 @@
 
   task.exec
-    command dettool -tonormalize -limit 20
+    if ($DB:n == 0)
+      option DEFAULT
+      command dettool -tonormalize -limit 20
+    else
+      # save the DB name for the exit tasks
+      option $DB:$detPendingNormImfile_DB
+      command dettool -tonormalize -limit 20 -dbname $DB:$detPendingNormImfile_DB
+      $detPendingNormImfile_DB ++
+      if ($detPendingNormImfile_DB >= $DB:n) set detPendingNormImfile_DB = 0
+    end
   end
 
@@ -145,5 +172,5 @@
   task.exit    0
     # convert 'stdout' to book format
-    ipptool2book stdout detPendingNormImfile -key det_id:iteration -uniq
+    ipptool2book stdout detPendingNormImfile -key det_id:iteration -uniq -setword dbname $options:0
     if ($VERBOSE > 2)
       book listbook detPendingNormImfile
@@ -152,4 +179,5 @@
     # delete existing entries which are DONE
     book delpage detPendingNormImfile -key state DONE
+    book delpage detPendingNormImfile -key state DATA_ERR
   end
 
@@ -188,4 +216,7 @@
     book getword detPendingNormImfile $pageName class_id  -var CLASS_ID 
     book getword detPendingNormImfile $pageName norm      -var NORM     
+    book getword detPendingNormImfile $pageName workdir   -var WORKDIR
+    book getword detPendingNormImfile $pageName dbname    -var DBNAME
+    set_standard_args
 
     # specify choice of remote host:
@@ -205,7 +236,7 @@
     # 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
+      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 $ARGS
+    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 $ARGS
   end
 
@@ -236,5 +267,14 @@
 
   task.exec
-    command dettool -tonormalizedexp -limit 20
+    if ($DB:n == 0)
+      option DEFAULT
+      command dettool -tonormalizedexp -limit 20
+    else
+      # save the DB name for the exit tasks
+      option $DB:$detPendingNormExp_DB
+      command dettool -tonormalizedexp -limit 20 -dbname $DB:$detPendingNormExp_DB
+      $detPendingNormExp_DB ++
+      if ($detPendingNormExp_DB >= $DB:n) set detPendingNormExp_DB = 0
+    end
   end
 
@@ -242,5 +282,5 @@
   task.exit    0
     # convert 'stdout' to book format
-    ipptool2book stdout detPendingNormExp -key det_id:iteration -uniq
+    ipptool2book stdout detPendingNormExp -key det_id:iteration -uniq -setword dbname $options:0
     if ($VERBOSE > 2)
       book listbook detPendingNormExp
@@ -249,4 +289,5 @@
     # delete existing entries which are DONE
     book delpage detPendingNormExp -key state DONE
+    book delpage detPendingNormExp -key state DATA_ERR
   end
 
@@ -282,4 +323,7 @@
     book getword detPendingNormExp $pageName det_type  -var DET_TYPE
     book getword detPendingNormExp $pageName camera    -var CAMERA  
+    book getword detPendingNormExp $pageName workdir   -var WORKDIR
+    book getword detPendingNormExp $pageName dbname    -var DBNAME
+    set_standard_args
 
     # specify choice of remote host:
@@ -299,7 +343,7 @@
     # 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
+      echo command detrend_norm_exp.pl --det_id $DET_ID --iteration $ITERATION --camera $CAMERA --det_type $DET_TYPE $ARGS
+    end
+    command detrend_norm_exp.pl --det_id $DET_ID --iteration $ITERATION --camera $CAMERA --det_type $DET_TYPE $ARGS
   end
 
Index: /trunk/ippTasks/detrend.process.pro
===================================================================
--- /trunk/ippTasks/detrend.process.pro	(revision 11322)
+++ /trunk/ippTasks/detrend.process.pro	(revision 11323)
@@ -27,4 +27,8 @@
   book listbook detPendingProcessedExp
 end
+
+# these variables will cycle through the known database names
+$detPendingProcessedImfile_DB = 0
+$detPendingProcessedExp_DB = 0
 
 # select images ready for copy 
@@ -42,5 +46,14 @@
 
   task.exec
-    command dettool -toprocessedimfile -limit 20
+    if ($DB:n == 0)
+      option DEFAULT
+      command dettool -toprocessedimfile -limit 20
+    else
+      # save the DB name for the exit tasks
+      option $DB:$detPendingProcessedImfile_DB
+      command dettool -toprocessedimfile -limit 20 -dbname $DB:$detPendingProcessedImfile_DB
+      $detPendingProcessedImfile_DB ++
+      if ($detPendingProcessedImfile_DB >= $DB:n) set detPendingProcessedImfile_DB = 0
+    end
   end
 
@@ -48,5 +61,5 @@
   task.exit    0
     # convert 'stdout' to book format
-    ipptool2book stdout detPendingProcessedImfile -key det_id:exp_tag:class_id -uniq
+    ipptool2book stdout detPendingProcessedImfile -key det_id:exp_tag:class_id -uniq -setword dbname $options:0
     if ($VERBOSE > 2)
       book listbook detPendingProcessedImfile
@@ -55,4 +68,5 @@
     # delete existing entries which are DONE
     book delpage detPendingProcessedImfile -key state DONE
+    book delpage detPendingProcessedImfile -key state DATA_ERR
   end
 
@@ -91,4 +105,7 @@
     book getword detPendingProcessedImfile $pageName uri      -var URI      
     book getword detPendingProcessedImfile $pageName camera   -var CAMERA   
+    book getword detPendingProcessedImfile $pageName workdir  -var WORKDIR
+    book getword detPendingProcessedImfile $pageName dbname   -var DBNAME
+    set_standard_args
 
     # specify choice of remote host:
@@ -100,12 +117,9 @@
 
     ## 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
+    $outroot = $WORKDIR/$EXP_TAG
+    $logfile = `ipp_filename.pl DETPROC.LOG $outroot $CLASS_ID`
+    stdout $logfile
+    stderr $logfile
+    exec mkdir -p $WORKDIR
 
     # save the pageName for future reference below
@@ -114,7 +128,7 @@
     # 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
+      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 $ARGS
+    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 $ARGS
   end
 
@@ -145,5 +159,13 @@
 
   task.exec
-    command dettool -toprocessedexp -limit 20
+    if ($DB:n == 0)
+      command dettool -toprocessedexp -limit 20
+    else
+      # save the DB name for the exit tasks
+      option $DB:$detPendingProcessedExp_DB
+      command dettool -toprocessedexp -limit 20 -dbname $DB:$detPendingProcessedExp_DB
+      $detPendingProcessedExp_DB ++
+      if ($detPendingProcessedExp_DB >= $DB:n) set detPendingProcessedExp_DB = 0
+    end
   end
 
@@ -151,5 +173,9 @@
   task.exit    0
     # convert 'stdout' to book format
-    ipptool2book stdout detPendingProcessedExp -key det_id:iteration:exp_tag -uniq
+    if ($options:n == 0)
+      ipptool2book stdout detPendingProcessedExp -key det_id:iteration:exp_tag -uniq
+    else
+      ipptool2book stdout detPendingProcessedExp -key det_id:iteration:exp_tag -uniq -setword DBNAME $options:0
+    end
     if ($VERBOSE > 2)
       book listbook detPendingProcessedExp
@@ -158,4 +184,5 @@
     # delete existing entries which are DONE
     book delpage detPendingProcessedExp -key state DONE
+    book delpage detPendingProcessedExp -key state DATA_ERR
   end
 
@@ -192,4 +219,7 @@
     book getword detPendingProcessedExp $pageName exp_tag   -var EXP_TAG
     book getword detPendingProcessedExp $pageName camera    -var CAMERA  
+    book getword detPendingProcessedExp $pageName workdir   -var WORKDIR
+    book getword detPendingProcessedExp $pageName dbname    -var DBNAME
+    set_standard_args
 
     # specify choice of remote host:
@@ -200,11 +230,10 @@
     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
+    # XXX push this into the filerules?
+    $outroot = $WORKDIR/$EXP_TAG
+    $logfile = $outroot/$EXP_TAG.detproc.$DET_ID.log
+    stdout $logfile
+    stderr $logfile
+    exec mkdir -p $outroot
 
     # save the pageName for future reference below
@@ -213,7 +242,7 @@
     # 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
+      echo command detrend_process_exp.pl --det_id $DET_ID --exp_tag $EXP_TAG --camera $CAMERA $ARGS
+    end
+    command detrend_process_exp.pl --det_id $DET_ID --exp_tag $EXP_TAG --camera $CAMERA $ARGS
   end
 
Index: /trunk/ippTasks/detrend.reject.pro
===================================================================
--- /trunk/ippTasks/detrend.reject.pro	(revision 11322)
+++ /trunk/ippTasks/detrend.reject.pro	(revision 11323)
@@ -26,4 +26,7 @@
 end
 
+# this variable will cycle through the known database names
+$detRejectExp_DB = 0
+
 # select images ready for copy 
 # new entries are added to detRejectExp
@@ -40,5 +43,14 @@
 
   task.exec
-    command dettool -residdetrun -limit 20
+    if ($DB:n == 0)
+      option DEFAULT
+      command dettool -residdetrun -limit 20
+    else
+      # save the DB name for the exit tasks
+      option $DB:$detRejectExp_DB
+      command dettool -residdetrun -limit 20 -dbname $DB:$detRejectExp_DB
+      $detRejectExp_DB ++
+      if ($detRejectExp_DB >= $DB:n) set detRejectExp_DB = 0
+    end
   end
 
@@ -46,5 +58,5 @@
   task.exit    0
     # convert 'stdout' to book format
-    ipptool2book stdout detRejectExp -key det_id:iteration -uniq
+    ipptool2book stdout detRejectExp -key det_id:iteration -uniq -setword dbname $options:0
     if ($VERBOSE > 2)
       book listbook detRejectExp
@@ -53,4 +65,5 @@
     # delete existing entries which are DONE
     book delpage detRejectExp -key state DONE
+    book delpage detRejectExp -key state DATA_ERR
   end
 
@@ -87,4 +100,7 @@
     book getword detRejectExp $pageName mode      -var MODE     
     book getword detRejectExp $pageName camera    -var CAMERA   
+    book getword detRejectExp $pageName workdir   -var WORKDIR
+    book getword detRejectExp $pageName dbname    -var DBNAME
+    set_standard_args
 
     # specify choice of remote host:
@@ -104,7 +120,7 @@
     # 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
+      echo command detrend_reject_exp.pl --det_id $DET_ID --iteration $ITERATION --det_type $DET_TYPE --camera $CAMERA $ARGS
     end
-    command detrend_reject_exp.pl --det_id $DET_ID --iteration $ITERATION --det_type $DET_TYPE --camera $CAMERA
+    command detrend_reject_exp.pl --det_id $DET_ID --iteration $ITERATION --det_type $DET_TYPE --camera $CAMERA $ARGS
  end
 
Index: /trunk/ippTasks/detrend.resid.pro
===================================================================
--- /trunk/ippTasks/detrend.resid.pro	(revision 11322)
+++ /trunk/ippTasks/detrend.resid.pro	(revision 11323)
@@ -27,4 +27,8 @@
   book listbook detPendingResidExp
 end
+
+# these variables will cycle through the known database names
+$detPendingResidImfile_DB = 0
+$detPendingResidExp_DB = 0
 
 # select images ready for copy 
@@ -42,5 +46,14 @@
 
   task.exec
-    command dettool -toresidimfile -limit 20
+    if ($DB:n == 0)
+      option DEFAULT
+      command dettool -toresidimfile -limit 20
+    else
+      # save the DB name for the exit tasks
+      option $DB:$detPendingResidImfile_DB
+      command dettool -toresidimfile -limit 20 -dbname $DB:$detPendingResidImfile_DB
+      $detPendingResidImfile_DB ++
+      if ($detPendingResidImfile_DB >= $DB:n) set detPendingResidImfile_DB = 0
+    end
   end
 
@@ -48,5 +61,5 @@
   task.exit    0
     # convert 'stdout' to book format
-    ipptool2book stdout detPendingResidImfile -key det_id:iteration:exp_tag:class_id -uniq
+    ipptool2book stdout detPendingResidImfile -key det_id:iteration:exp_tag:class_id -uniq -setword dbname $options:0
     if ($VERBOSE > 2)
       book listbook detPendingResidImfile
@@ -55,4 +68,5 @@
     # delete existing entries which are DONE
     book delpage detPendingResidImfile -key state DONE
+    book delpage detPendingResidImfile -key state DATA_ERR
   end
 
@@ -93,4 +107,7 @@
     book getword detPendingResidImfile $pageName det_uri   -var DET_URI  
     book getword detPendingResidImfile $pageName camera    -var CAMERA   
+    book getword detPendingResidImfile $pageName workdir   -var WORKDIR
+    book getword detPendingResidImfile $pageName dbname    -var DBNAME
+    set_standard_args
 
     # specify choice of remote host:
@@ -114,7 +131,7 @@
     # 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
+      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 $ARGS
+    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 $ARGS
   end
 
@@ -145,5 +162,14 @@
 
   task.exec
-    command dettool -toresidexp -limit 20
+    if ($DB:n == 0)
+      option DEFAULT
+      command dettool -toresidexp -limit 20
+    else
+      # save the DB name for the exit tasks
+      option $DB:$detPendingResidExp_DB
+      command dettool -toresidexp -limit 20 -dbname $DB:$detPendingResidExp_DB
+      $detPendingResidExp_DB ++
+      if ($detPendingResidExp_DB >= $DB:n) set detPendingResidExp_DB = 0
+    end
   end
 
@@ -151,5 +177,5 @@
   task.exit    0
     # convert 'stdout' to book format
-    ipptool2book stdout detPendingResidExp -key det_id:iteration:exp_tag -uniq
+    ipptool2book stdout detPendingResidExp -key det_id:iteration:exp_tag -uniq -setword dbname $options:0
     if ($VERBOSE > 2)
       book listbook detPendingResidExp
@@ -158,4 +184,5 @@
     # delete existing entries which are DONE
     book delpage detPendingResidExp -key state DONE
+    book delpage detPendingResidExp -key state DATA_ERR
   end
 
@@ -194,4 +221,7 @@
     book getword detPendingResidExp $pageName include   -var INCLUDE 
     book getword detPendingResidExp $pageName camera    -var CAMERA  
+    book getword detPendingResidExp $pageName workdir   -var WORKDIR
+    book getword detPendingResidExp $pageName dbname    -var DBNAME
+    set_standard_args
 
     # specify choice of remote host:
@@ -215,7 +245,7 @@
     # 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
+      echo command detrend_reject_imfile.pl --det_id $DET_ID --iteration $ITERATION --exp_tag $EXP_TAG --det_type $DET_TYPE --camera $CAMERA $ARGS
+    end
+    command detrend_reject_imfile.pl --det_id $DET_ID --iteration $ITERATION --exp_tag $EXP_TAG --det_type $DET_TYPE --camera $CAMERA $ARGS
   end
 
Index: /trunk/ippTasks/detrend.stack.pro
===================================================================
--- /trunk/ippTasks/detrend.stack.pro	(revision 11322)
+++ /trunk/ippTasks/detrend.stack.pro	(revision 11323)
@@ -26,4 +26,7 @@
 end
 
+# this variable will cycle through the known database names
+$detPendingStackedImfile_DB = 0
+
 # select images ready for detrend_stack.pl
 # new entries are added to detPendingStackedImfile
@@ -40,5 +43,14 @@
 
   task.exec
-    command dettool -tostacked -limit 20
+    if ($DB:n == 0)
+      option DEFAULT
+      command dettool -tostacked -limit 20
+    else
+      # save the DB name for the exit tasks
+      option $DB:$detPendingStackedImfile_DB
+      command dettool -tostacked -limit 20 -dbname $DB:$detPendingStackedImfile_DB
+      $detPendingStackedImfile_DB ++
+      if ($detPendingStackedImfile_DB >= $DB:n) set detPendingStackedImfile_DB = 0
+    end
   end
 
@@ -46,5 +58,5 @@
   task.exit    0
     # convert 'stdout' to book format
-    ipptool2book stdout detPendingStackedImfile -key det_id:iteration:class_id -uniq
+    ipptool2book stdout detPendingStackedImfile -key det_id:iteration:class_id -uniq -setword dbname $options:0
     if ($VERBOSE > 2)
       book listbook detPendingStackedImfile
@@ -53,4 +65,5 @@
     # delete existing entries which are DONE
     book delpage detPendingStackedImfile -key state DONE
+    book delpage detPendingStackedImfile -key state DATA_ERR
   end
 
@@ -87,4 +100,7 @@
     book getword detPendingStackedImfile $pageName class_id  -var CLASS_ID
     book getword detPendingStackedImfile $pageName camera    -var CAMERA  
+    book getword detPendingStackedImfile $pageName workdir   -var WORKDIR
+    book getword detPendingStackedImfile $pageName dbname    -var DBNAME
+    set_standard_args
 
     # specify choice of remote host:
@@ -105,7 +121,7 @@
     # 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
+      echo command detrend_stack.pl --det_id $DET_ID --iteration $ITERATION --class_id $CLASS_ID --det_type $DET_TYPE --camera $CAMERA $ARGS
     end
-    command detrend_stack.pl --det_id $DET_ID --iteration $ITERATION --class_id $CLASS_ID --det_type $DET_TYPE --camera $CAMERA
+    command detrend_stack.pl --det_id $DET_ID --iteration $ITERATION --class_id $CLASS_ID --det_type $DET_TYPE --camera $CAMERA $ARGS
   end
 
Index: /trunk/ippTasks/pantasks.pro
===================================================================
--- /trunk/ippTasks/pantasks.pro	(revision 11322)
+++ /trunk/ippTasks/pantasks.pro	(revision 11323)
@@ -25,5 +25,18 @@
 $EXIT_DATA_ERR    = 5
 
+# DB lists the database names in use; the default ipprc database
+# is only used if DB:n is 0
 $DB:n = 0
+
+macro init.simtest.defDB
+  $LOGDIR = `ipp_datapath.pl path://SIMTEST`
+  $LOGDIR = $LOGDIR/logs
+  exec mkdir -p $LOGDIR
+
+  if ($parallel) 
+    controller exit true
+    controller host add alala
+  end
+end
 
 macro init.simtest
@@ -109,4 +122,16 @@
 end
 
+macro set_standard_args
+  $ARGS = ""
+  if ("$DBNAME" != "DEFAULT")
+    $ARGS = $ARGS --dbname $DBNAME
+  end
+  if ("$WORKDIR" != "")
+    $ARGS = $ARGS --workdir $WORKDIR
+  else
+    echo WORKDIR not set
+  end
+end
+
 macro process_exit
   if ($0 != 4)
Index: /trunk/ippTasks/phase0.pro
===================================================================
--- /trunk/ippTasks/phase0.pro	(revision 11322)
+++ /trunk/ippTasks/phase0.pro	(revision 11323)
@@ -28,5 +28,7 @@
 end
 
-$phase0_DB = 0
+# these variables will cycle through the known database names
+$p0PendingImfile_DB = 0
+$p0PendingExp_DB = 0
 
 # select images ready for phase0 analysis
@@ -39,7 +41,5 @@
   periods      -exec $loadexec
   periods      -timeout 30
-
-  # XXX test that this option works
-#  npending     1
+  npending     1
 
   # silently drop stdout
@@ -48,12 +48,15 @@
 
   # 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
+  # iff the DB list is not set, use the value defined in .ipprc
   task.exec
     if ($DB:n == 0)
+      option DEFAULT
       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
+      # save the DB name for the exit tasks
+      option $DB:$p0PendingImfile_DB
+      command p0tool -pendingimfile -limit 20 -dbname $DB:$p0PendingImfile_DB
+      $p0PendingImfile_DB ++
+      if ($p0PendingImfile_DB >= $DB:n) set p0PendingImfile_DB = 0
     end
   end
@@ -62,5 +65,5 @@
   task.exit $EXIT_SUCCESS
     # convert 'stdout' to book format
-    ipptool2book stdout p0PendingImfile -key exp_tag -uniq
+    ipptool2book stdout p0PendingImfile -key exp_tag -uniq -setword dbname $options:0
     if ($VERBOSE > 2)
       book listbook p0PendingImfile
@@ -105,5 +108,6 @@
     book getword p0PendingImfile $pageName uri -var URI
     book getword p0PendingImfile $pageName workdir -var WORKDIR
-#    book getword p0PendingImfile $pageName dbname -var DBNAME
+    book getword p0PendingImfile $pageName dbname -var DBNAME
+    set_standard_args
 
     # specify choice of remote host
@@ -114,5 +118,5 @@
     end
 
-    ## generate output log based on filerule
+    ## generate output log based on filerule XXX put this in a function?
     $outroot = $WORKDIR/$EXP_TAG
     $logfile = `ipp_filename.pl PHASE0.LOG $outroot $CLASS_ID`
@@ -126,7 +130,7 @@
     # create the command line
     if ($VERBOSE > 1)
-      echo command phase0_imfile.pl --exp_tag $EXP_TAG --class_id $CLASS_ID --uri $URI
-    end
-    command phase0_imfile.pl --exp_tag $EXP_TAG --class_id $CLASS_ID --uri $URI
+      echo command phase0_imfile.pl --exp_tag $EXP_TAG --class_id $CLASS_ID --uri $URI $ARGS
+    end
+    command phase0_imfile.pl --exp_tag $EXP_TAG --class_id $CLASS_ID --uri $URI $ARGS
   end
 
@@ -155,11 +159,20 @@
 
   task.exec
-    command p0tool -pendingexp -limit 20
+    if ($DB:n == 0)
+      option DEFAULT
+      command p0tool -pendingexp -limit 20
+    else
+      # save the DB name for the exit tasks
+      option $DB:$p0PendingExp_DB
+      command p0tool -pendingexp -limit 20 -dbname $DB:$p0PendingExp_DB
+      $p0PendingExp_DB ++
+      if ($p0PendingExp_DB >= $DB:n) set p0PendingExp_DB = 0
+    end
   end
 
   # success
-  task.exit    0
+  task.exit $EXIT_SUCCESS
     # convert 'stdout' to book format
-    ipptool2book stdout p0PendingExp -key exp_tag -uniq
+    ipptool2book stdout p0PendingExp -key exp_tag -uniq -setword dbname $options:0
     if ($VERBOSE > 2)
       book listbook p0PendingExp
@@ -200,4 +213,6 @@
     book getword p0PendingExp $pageName exp_tag -var EXP_TAG
     book getword p0PendingExp $pageName workdir -var WORKDIR
+    book getword p0PendingExp $pageName dbname -var DBNAME
+    set_standard_args
 
     # specify choice of remote host:(need to choose based on chips)
@@ -220,7 +235,7 @@
     # 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
+      echo command phase0_exp.pl --exp_tag $EXP_TAG $ARGS
+    end
+    command phase0_exp.pl --exp_tag $EXP_TAG $ARGS
   end
 
Index: /trunk/ippTasks/phase2.pro
===================================================================
--- /trunk/ippTasks/phase2.pro	(revision 11322)
+++ /trunk/ippTasks/phase2.pro	(revision 11323)
@@ -26,4 +26,7 @@
 end
 
+# this variable will cycle through the known database names
+$phase2_DB = 0
+
 # select images ready for phase2 analysis
 # new entries are added to p2PendingImfile
@@ -40,5 +43,14 @@
 
   task.exec
-    command p2tool -pendingimfile -limit 20
+    if ($DB:n == 0)
+      option DEFAULT
+      command p2tool -pendingimfile -limit 20
+    else
+      # save the DB name for the exit tasks
+      option $DB:$phase2_DB
+      command p2tool -pendingimfile -limit 20 -dbname $DB:$phase2_DB
+      $phase2_DB ++
+      if ($phase2_DB >= $DB:n) set phase2_DB = 0
+    end
   end
 
@@ -46,5 +58,5 @@
   task.exit    0
     # convert 'stdout' to book format
-    ipptool2book stdout p2PendingImfile -key exp_tag:class_id -uniq
+    ipptool2book stdout p2PendingImfile -key exp_tag:class_id -uniq -setword dbname $options:0
     if ($VERBOSE > 2)
       book listbook p2PendingImfile
@@ -53,4 +65,5 @@
     # delete existing entries which are DONE
     book delpage p2PendingImfile -key state DONE
+    book delpage p2PendingImfile -key state DATA_ERR
   end
 
@@ -87,4 +100,7 @@
     book getword p2PendingImfile $pageName class_id -var CLASS_ID
     book getword p2PendingImfile $pageName uri -var URI
+    book getword p2PendingImfile $pageName workdir -var WORKDIR
+    book getword p2PendingImfile $pageName dbname -var DBNAME
+    set_standard_args
 
     # specify choice of remote host
@@ -108,7 +124,7 @@
     # create the command line
     if ($VERBOSE > 1)
-      echo command phase2.pl --exp_tag $EXP_TAG --class_id $CLASS_ID --uri $URI --camera $CAMERA
+      echo command phase2.pl --exp_tag $EXP_TAG --class_id $CLASS_ID --uri $URI --camera $CAMERA $ARGS
     end
-    command phase2.pl --exp_tag $EXP_TAG --class_id $CLASS_ID --uri $URI --camera $CAMERA --workdir $WORKDIR
+    command phase2.pl --exp_tag $EXP_TAG --class_id $CLASS_ID --uri $URI --camera $CAMERA $ARGS
   end
 
Index: /trunk/ippTasks/phase3.pro
===================================================================
--- /trunk/ippTasks/phase3.pro	(revision 11322)
+++ /trunk/ippTasks/phase3.pro	(revision 11323)
@@ -26,4 +26,7 @@
 end
 
+# this variable will cycle through the known database names
+$phase3_DB = 0
+
 # select images ready for phase3 analysis
 # new entries are added to p3PendingExp
@@ -40,5 +43,14 @@
 
   task.exec
-    command p3tool -pendingexp -limit 20
+    if ($DB:n == 0)
+      option DEFAULT
+      command p3tool -pendingexp -limit 20
+    else
+      # save the DB name for the exit tasks
+      option $DB:$phase3_DB
+      command p3tool -pendingexp -limit 20 -dbname $DB:$phase3_DB
+      $phase3_DB ++
+      if ($phase3_DB >= $DB:n) set phase3_DB = 0
+    end
   end
 
@@ -46,5 +58,5 @@
   task.exit    0
     # convert 'stdout' to book format
-    ipptool2book stdout p3PendingExp -key exp_tag -uniq
+    ipptool2book stdout p3PendingExp -key exp_tag -uniq -setword dbname $options:0
     if ($VERBOSE > 2)
       book listbook p3PendingExp
@@ -53,4 +65,5 @@
     # delete existing entries which are DONE
     book delpage p3PendingExp -key state DONE
+    book delpage p3PendingExp -key state DATA_ERR
   end
 
@@ -70,5 +83,5 @@
   periods      -poll $runpoll
   periods      -exec $runexec
-  periods      -timeout 5
+  periods      -timeout 10
 
   task.exec
@@ -84,4 +97,7 @@
     book getword p3PendingExp $pageName camera -var CAMERA
     book getword p3PendingExp $pageName exp_tag -var EXP_TAG
+    book getword p3PendingExp $pageName workdir -var WORKDIR
+    book getword p3PendingExp $pageName dbname -var DBNAME
+    set_standard_args
 
     # specify choice of remote host:(need to choose based on chips)
@@ -92,11 +108,10 @@
     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
+    # output log from filerule
+    $outroot = $WORKDIR/$EXP_TAG
+    $logfile = `ipp_filename.pl PHASE3.LOG $outroot $CLASS_ID`
+    stdout $logfile
+    stderr $logfile
+    exec mkdir -p $WORKDIR
 
     # save the pageName for future reference below
@@ -105,19 +120,12 @@
     # create the command line
     if ($VERBOSE > 1)
-      echo command phase3.pl --exp_tag $EXP_TAG
+      echo command phase3.pl --exp_tag $EXP_TAG $ARGS
     end
-    command phase3.pl --exp_tag $EXP_TAG --camera $CAMERA
+    command phase3.pl --exp_tag $EXP_TAG --camera $CAMERA $ARGS
   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
+  task.exit default
+    process_exit p3PendingExp $options:0 $JOB_STATUS
   end
 
