Index: branches/eam_branch_00/ippTasks/phase3.pro
===================================================================
--- branches/eam_branch_00/ippTasks/phase3.pro	(revision 10761)
+++ branches/eam_branch_00/ippTasks/phase3.pro	(revision 11011)
@@ -1,10 +1,5 @@
-## this file contains the tasks for running the phase 0 stage
+## this file contains the tasks for running the phase 3 stage
+## these tasks use the book Phase3Exposures
 
-## these tasks use the queue Phase3Exposures
-## the Phase3Exposures queue contains:
-## STATE EXP_TAG CLASS CLASS_ID URI-FITS
-## queue keys are counted from 0
-
-queueinit Phase3Exposures
 if ($?network == 0)
   $network = 1
@@ -13,7 +8,4 @@
   $parallel = 0
 end
-
-$Phase3ExposureFail = 0
-
 if ($?VERBOSE == 0)
   echo "VERBOSE not defined: load pantasks.pro first"
@@ -24,15 +16,17 @@
   break
 end
+
 $LOGSUBDIR = $LOGDIR/phase3
 exec mkdir -p $LOGSUBDIR
 
+book init Phase3Exposures
+
 macro phase3.status
-  queueprint Phase3Exposures
-  echo "Phase3ExposureFail: $Phase3ExposureFail"
+  book listbook Phase3Exposures
 end
 
 # select images ready for phase3 analysis
-# new entries are added to queue Phase3Exposures
-# compare the new list with the ones already selected
+# new entries are added to Phase3Exposures
+# skip already-present entries
 task	       phase3.exp.load
   host         local
@@ -46,26 +40,17 @@
 
   task.exec
-    command      p3tool -pendingexp -simple
+    command p3tool -pendingexp -limit 20
   end
 
   # success
   task.exit    0
-    local i Nqueue
-
-    # compare output with Phase3Exposures queue
-    # only add entries which don't 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
-      $EXP_TAG   = $word:0
-      queuepush Phase3Exposures -uniq -key 1 "NEW $EXP_TAG"
+    # convert 'stdout' to book format
+    ipptool2book stdout Phase3Exposures -key exp_tag -uniq
+    if ($VERBOSE > 2)
+      book listbook Phase3Exposures
     end
 
     # delete existing entries which are DONE
-    queuedrop Phase3Exposures -key 0 DONE
+    book delpage Phase3Exposures -key state DONE
   end
 
@@ -88,21 +73,22 @@
 
   task.exec
-    queuesize Phase3Exposures -var N
+    book npages Phase3Exposures -var N
     if ($N == 0) break
     if ($network == 0) break
     
-    # look for new images on the internal DetrendExposuresToProcess queue
-    # caution with these 'if' statements: syntax errors 
-    # will make the task fail without given a good status
-    queuepop Phase3Exposures -var line -key 0 NEW
-    if ("$line" == "NULL") break
+    # look for new images in Phase3Exposures (state == NULL)
+    book getpage Phase3Exposures 0 -var pageName -key state NULL
+    if ($pageName == NULL) break
 
-    strpop line state
-    queuepush Phase3Exposures -replace -key 1 "RUN $line"
+    book setword Phase3Exposures $pageName state RUN
+    book getword Phase3Exposures $pageName camera -var CAMERA
+    book getword Phase3Exposures $pageName exp_tag -var EXP_TAG
 
-    ## the Phase3Exposures queue contains:
-    ## STATE EXP_TAG CAMERA TELESCOPE TYPE NCLASS
-    list word -split $line
-    $EXP_TAG   = $word:0
+    # specify choice of remote host:(need to choose based on chips)
+    if ($parallel)
+      host anyhost
+    else
+      host local
+    end
 
     # XXX this is still a lame rule
@@ -114,17 +100,12 @@
     exec mkdir -p $LOGSUBDIR/$base
 
-    # specify choice of remote host:(need to choose based on chips)
-    if ($parallel)
-      host anyhost
-    else
-      host local
-    end
+    # save the pageName for future reference below
+    options $pageName
 
     # create the command line
-    options "$line"
     if ($VERBOSE > 1)
       echo command phase3.pl --exp_tag $EXP_TAG
     end
-    command phase3.pl --exp_tag $EXP_TAG --camera CTIO_MOSAIC2
+    command phase3.pl --exp_tag $EXP_TAG --camera $CAMERA
   end
 
@@ -132,5 +113,5 @@
   task.exit 0
     # phase3exp.pl updates DB tables, here we just update the queue
-    queuepush Phase3Exposures -replace -key 1 "DONE $options:0"
+    book setword Phase3Exposures $options:0 state DONE
   end
 
@@ -138,6 +119,5 @@
   task.exit    default
     showcommand failure
-    queuepush Phase3Exposures -replace -key 1 "FAIL $options:0"
-    $Phase3ExposureFail ++
+    book setword Phase3Exposures $options:0 state FAIL
   end
 
@@ -145,6 +125,5 @@
   task.exit    timeout
     showcommand timeout
-    queuepush Phase3Exposures -replace -key 1 "TIMEOUT $options:0"
-    $Phase3ExposureFail ++
+    book setword Phase3Exposures $options:0 state TIMEOUT
   end
 end
