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