Index: trunk/ippTasks/detrend.resid.pro
===================================================================
--- trunk/ippTasks/detrend.resid.pro	(revision 11210)
+++ 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
 
