Index: branches/eam_branch_00/ippTasks/detrend.stack.pro
===================================================================
--- branches/eam_branch_00/ippTasks/detrend.stack.pro	(revision 10761)
+++ branches/eam_branch_00/ippTasks/detrend.stack.pro	(revision 11011)
@@ -1,17 +1,4 @@
 ## this file contains the tasks for running the detrend stacking stage
 
-# get a list of imfiles to stack
-# dettool -tostack -simple
-# 1 0 bias mc
-# DET_ID ITER TYPE CLASS_ID 
-
-# function to stack the imfiles:
-# detrend_stack.pl 1 0 mc bias
-
-## these tasks use the queue DetrendStackClass
-## the DetrendStackClass queue contains:
-## STATE DET_ID ITER TYPE CLASS_ID CAMERA
-
-queueinit DetrendStackClass
 if ($?network == 0)
   $network = 1
@@ -20,7 +7,4 @@
   $parallel = 0
 end
-
-$DetrendStackClassFail = 0
-
 if ($?VERBOSE == 0)
   echo "VERBOSE not defined: load pantasks.pro first"
@@ -31,6 +15,9 @@
   break
 end
+
 $LOGSUBDIR = $LOGDIR/detrend
 exec mkdir -p $LOGSUBDIR
+
+book init DetrendStackClass
 
 macro detstack.status
@@ -39,6 +26,6 @@
 end
 
-# select images ready for copy 
-# new entries are added to queue DetrendStackClass
+# select images ready for detrend_stack.pl
+# new entries are added to DetrendStackClass
 # compare the new list with the ones already selected
 task	       dettool.stack.load
@@ -53,30 +40,17 @@
 
   task.exec
-    command dettool -tostacked -simple -limit {$DetrendStackClassFail + 20}
+    command dettool -tostacked -limit 20
   end
 
   # success
   task.exit    0
-    local i Nqueue
-
-    # compare output with newImage queue
-    # only add entries which do not exist in queue
-    queuesize stdout -var Nqueue
-    for i 0 $Nqueue
-      queuepop stdout -var line
-      if ($VERBOSE > 2)
-        echo $line
-      end
-      list word -split $line
-      $DET_ID   = $word:0
-      $ITER     = $word:1
-      $DET_TYPE = $word:2
-      $CLASS_ID = $word:3
-      $CAMERA   = $word:4
-      queuepush DetrendStackClass -uniq -key 1:2:4 "NEW $DET_ID $ITER $DET_TYPE $CLASS_ID $CAMERA"
+    # convert 'stdout' to book format
+    ipptool2book stdout DetrendStackClass -key det_id:iter:class_id -uniq
+    if ($VERBOSE > 2)
+      book listbook DetrendStackClass
     end
 
     # delete existing entries which are DONE
-    queuedrop DetrendStackClass -key 0 DONE
+    book delpage DetrendStackClass -key state DONE
   end
 
@@ -99,31 +73,18 @@
 
   task.exec
-    queuesize DetrendStackClass -var N
+    book npages DetrendStackClass -var N
     if ($N == 0) break
     if ($network == 0) break
     
-    # look for new images on the internal DetrendStackClass queue
-    # caution with these 'if' statements: syntax errors 
-    # will make the task fail without given a good status
-    queuepop DetrendStackClass -var line -key 0 NEW
-    if ("$line" == "NULL") break
+    # look for new images in DetrendStackClass
+    book getpage DetrendStackClass 0 -var pageName -key state NULL
+    if ($pageName == NULL) break
 
-    strpop line state
-    queuepush DetrendStackClass -replace -key 1:2:4 "RUN $line"
-
-    # the DetrendStackClass queue contains:
-    # STATE DET_ID ITER TYPE CLASS_ID 
-    ## NOTE: the queue has the STATE prepended 
-    # use local variables
-    list word -split $line
-    $DET_ID   = $word:0
-    $ITER     = $word:1
-    $DET_TYPE = $word:2
-    $CLASS_ID = $word:3
-    $CAMERA   = $word:4
-
-    # XXX add $WORKDIR/$LOG_DIR
-    stdout $LOGSUBDIR/$CAMERA.$DET_TYPE.$DET_ID.$ITER.$CLASS_ID.log
-    stderr $LOGSUBDIR/$CAMERA.$DET_TYPE.$DET_ID.$ITER.$CLASS_ID.log
+    book setword DetrendStackClass $pageName state RUN
+    book getword DetrendStackClass $pageName det_id   -var DET_ID
+    book getword DetrendStackClass $pageName iter     -var ITER
+    book getword DetrendStackClass $pageName det_type -var DET_TYPE
+    book getword DetrendStackClass $pageName class_id -var CLASS_ID
+    book getword DetrendStackClass $pageName camera   -var CAMERA  
 
     # specify choice of remote host:
@@ -134,6 +95,12 @@
     end
 
-    # create example job options as a demonstration
-    options "$line"
+    # XXX add $WORKDIR/$LOG_DIR
+    stdout $LOGSUBDIR/$CAMERA.$DET_TYPE.$DET_ID.$ITER.$CLASS_ID.log
+    stderr $LOGSUBDIR/$CAMERA.$DET_TYPE.$DET_ID.$ITER.$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 $ITER --class_id $CLASS_ID --det_type $DET_TYPE --camera $CAMERA
@@ -144,5 +111,5 @@
   # success
   task.exit 0
-    queuepush DetrendStackClass -replace -key 1:2:4 "DONE $options:0"
+    book setword DetrendStackClass $options:0 state DONE
   end
 
@@ -150,6 +117,5 @@
   task.exit    default
     showcommand failure
-   queuepush DetrendStackClass -replace -key 1:2:4 "FAIL $options:0"
-   $DetrendStackClassFail ++
+    book setword DetrendStackClass $options:0 state FAIL
   end
 
@@ -157,6 +123,5 @@
   task.exit    timeout
     showcommand timeout
-    queuepush DetrendStackClass -replace -key 1:2:4 "TIMEOUT $options:0"
-    $DetrendStackClassFail ++
+    book setword DetrendStackClass $options:0 state TIMEOUT
   end
 end
