Index: trunk/ippTasks/detrend.stack.pro
===================================================================
--- trunk/ippTasks/detrend.stack.pro	(revision 10745)
+++ trunk/ippTasks/detrend.stack.pro	(revision 11210)
@@ -1,17 +1,5 @@
 ## this file contains the tasks for running the detrend stacking stage
+## these tasks use the book detPendingStackedImfile
 
-# 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 +8,4 @@
   $parallel = 0
 end
-
-$DetrendStackClassFail = 0
-
 if ($?VERBOSE == 0)
   echo "VERBOSE not defined: load pantasks.pro first"
@@ -31,14 +16,16 @@
   break
 end
+
 $LOGSUBDIR = $LOGDIR/detrend
 exec mkdir -p $LOGSUBDIR
 
+book init detPendingStackedImfile
+
 macro detstack.status
-  queueprint DetrendStackClass
-  echo "DetrendStackClassFail: $DetrendStackClassFail"
+  book listbook detPendingStackedImfile
 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 detPendingStackedImfile
 # compare the new list with the ones already selected
 task	       dettool.stack.load
@@ -49,34 +36,21 @@
   periods      -timeout 30
 
-  stdout $LOGSUBDIR/detstack.log
+  stdout NULL
   stderr $LOGSUBDIR/detstack.log
 
   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 detPendingStackedImfile -key det_id:iteration:class_id -uniq
+    if ($VERBOSE > 2)
+      book listbook detPendingStackedImfile
     end
 
     # delete existing entries which are DONE
-    queuedrop DetrendStackClass -key 0 DONE
+    book delpage detPendingStackedImfile -key state DONE
   end
 
@@ -99,31 +73,18 @@
 
   task.exec
-    queuesize DetrendStackClass -var N
+    book npages detPendingStackedImfile -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 detPendingStackedImfile
+    book getpage detPendingStackedImfile 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 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:
@@ -134,22 +95,22 @@
     end
 
-    # create example job options as a demonstration
-    options "$line"
+    # 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 $ITER --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
     end
-    command detrend_stack.pl --det_id $DET_ID --iteration $ITER --class_id $CLASS_ID --det_type $DET_TYPE --camera $CAMERA
-  end
-
-  # success
-  task.exit 0
-    queuepush DetrendStackClass -replace -key 1:2:4 "DONE $options:0"
+    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
-    showcommand failure
-   queuepush DetrendStackClass -replace -key 1:2:4 "FAIL $options:0"
-   $DetrendStackClassFail ++
+    process_exit detPendingStackedImfile $options:0 $JOB_STATUS
   end
 
@@ -157,6 +118,5 @@
   task.exit    timeout
     showcommand timeout
-    queuepush DetrendStackClass -replace -key 1:2:4 "TIMEOUT $options:0"
-    $DetrendStackClassFail ++
+    book setword detPendingStackedImfile $options:0 state TIMEOUT
   end
 end
