Index: branches/eam_branch_00/ippTasks/phase0.pro
===================================================================
--- branches/eam_branch_00/ippTasks/phase0.pro	(revision 10761)
+++ branches/eam_branch_00/ippTasks/phase0.pro	(revision 11011)
@@ -1,11 +1,5 @@
 ## this file contains the tasks for running the phase 0 stage
-
-## these tasks use the queue Phase0Imfiles
-## the Phase0Imfiles queue contains:
-## STATE EXP_TAG CLASS CLASS_ID URI-FITS
-## queue keys are counted from 0
-
-queueinit Phase0Imfiles
-queueinit Phase0Exposures
+## these tasks use the books Phase0Imfiles and Phase0Exposures
+
 if ($?network == 0)
   $network = 1
@@ -14,8 +8,4 @@
   $parallel = 0
 end
-
-$Phase0ImfileFail = 0
-$Phase0ExpFail = 0
-
 if ($?VERBOSE == 0)
   echo "VERBOSE not defined: load pantasks.pro first"
@@ -26,12 +16,14 @@
   break
 end
+
 $LOGSUBDIR = $LOGDIR/phase0
 exec mkdir -p $LOGSUBDIR
 
+book init Phase0Imfiles
+book init Phase0Exposures
+
 macro phase0.status
-  queueprint Phase0Imfiles
-  queueprint Phase0Exposures
-  echo "Phase0ImfileFail: $Phase0ImfileFail"
-  echo "Phase0ExpFail: $Phase0ExpFail"
+  book listbook Phase0Imfiles
+  book listbook Phase0Exposures
 end
 
@@ -50,29 +42,17 @@
 
   task.exec
-    command p0tool -pendingimfile -simple -limit {$Phase0ImfileFail + 20}
+    command p0tool -pendingimfile -limit 20
   end
 
   # success
   task.exit    0
-    local i Nqueue
-
-    # compare output with Phase0Imfiles 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
-      $CLASS    = $word:1
-      $CLASS_ID = $word:2
-      $URI      = $word:3
-      queuepush Phase0Imfiles -uniq -key 1 "NEW $EXP_TAG $CLASS $CLASS_ID $URI"
+    # convert 'stdout' to book format
+    ipptool2book stdout Phase0Imfiles -key exp_tag -uniq
+    if ($VERBOSE > 2)
+      book listbook Phase0Imfiles
     end
 
     # delete existing entries which are DONE
-    queuedrop Phase0Imfiles -key 0 DONE
+    book delpage Phase0Imfiles -key state DONE
   end
 
@@ -88,7 +68,5 @@
 end
 
-
-
-# run the phase0imfile script on pending images
+# run the phase0_imfile.pl script on pending images
 task	       phase0.imfile.run
   periods      -poll $runpoll
@@ -97,26 +75,19 @@
 
   task.exec
-    queuesize Phase0Imfiles -var N
+    book npages Phase0Imfiles -var N
     if ($N == 0) break
     if ($network == 0) break
     
-    # look for new images on the internal DetrendImfilesToProcess queue
-    # caution with these 'if' statements: syntax errors 
-    # will make the task fail without given a good status
-    queuepop Phase0Imfiles -var line -key 0 NEW
-    if ("$line" == "NULL") break
-
-    strpop line state
-    queuepush Phase0Imfiles -replace -key 1 "RUN $line"
-
-    ## the Phase0Imfiles queue contains (line has popped STATE)
-    ## STATE EXP_TAG CLASS CLASS_ID URI-FITS
-    list word -split $line
-    $EXP_TAG  = $word:0
-    $CLASS    = $word:1
-    $CLASS_ID = $word:2
-    $URI      = $word:3
-
-    # specify choice of remote host:(need to choose based on chips)
+    # look for new images in Phase0Imfiles
+    book getpage Phase0Imfiles 0 -var pageName -key state NULL
+    if ($pageName == NULL) break
+
+    book setword Phase0Imfiles $pageName state RUN
+    book getword Phase0Imfiles $pageName exp_tag -var EXP_TAG
+    book getword Phase0Imfiles $pageName class -var CLASS
+    book getword Phase0Imfiles $pageName class_id -var CLASS_ID
+    book getword Phase0Imfiles $pageName uri -var URI
+
+    # specify choice of remote host
     if ($parallel)
       host anyhost
@@ -133,6 +104,8 @@
     exec mkdir -p $LOGSUBDIR/$base
 
+    # save the pageName for future reference below
+    options $pageName
+
     # create the command line
-    options "$line"
     if ($VERBOSE > 1)
       echo command phase0_imfile.pl --exp_tag $EXP_TAG --class_id $CLASS_ID --uri $URI
@@ -143,6 +116,6 @@
   # success
   task.exit 0
-    # phase0imfile.pl updates DB tables, here we just update the queue
-    queuepush Phase0Imfiles -replace -key 1 "DONE $options:0"
+    # phase0_imfile.pl updates DB tables, here we just update the queue
+    book setword Phase0Imfiles $options:0 state DONE
   end
 
@@ -150,6 +123,5 @@
   task.exit    default
     showcommand failure
-    queuepush Phase0Imfiles -replace -key 1 "FAIL $options:0"
-    $Phase0ImfileFail ++
+    book setword Phase0Imfiles $options:0 state FAIL
   end
 
@@ -157,18 +129,9 @@
   task.exit    timeout
     showcommand timeout
-    queuepush Phase0Imfiles -replace -key 1 "TIMEOUT $options:0"
-    $Phase0ImfileFail ++
-  end
-end
-
-
-
-## these tasks use the queue Phase0Exposures
-## the Phase0Exposures queue contains:
-## STATE EXP_TAG CAMERA TELESCOPE TYPE NCLASS
-
-# select images ready for phase0 analysis
-# new entries are added to queue Phase0Exposures
-# compare the new list with the ones already selected
+    book setword Phase0Imfiles $options:0 state TIMEOUT
+  end
+end
+
+# select exposures ready for phase0_exp.pl
 task	       phase0.exp.load
   host         local
@@ -182,48 +145,31 @@
 
   task.exec
-    command p0tool -pendingexp -simple -limit {$Phase0ExpFail + 20}
+    command p0tool -pendingexp -limit 20
   end
 
   # success
   task.exit    0
-    local i Nqueue
-
-    # compare output with Phase0Exposures 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
-      # $EXP_ID    = $word:1
-      # $CAMERA    = $word:2
-      # $TELESCOPE = $word:3
-      # $DATEOBS   = $word:4
-      # $TYPE      = $word:5
-      # $IMFILES   = $word:6
-      queuepush Phase0Exposures -uniq -key 1 "NEW $EXP_TAG"
+    # convert 'stdout' to book format
+    ipptool2book stdout Phase0Exposures -key exp_tag -uniq
+    if ($VERBOSE > 2)
+      book listbook Phase0Exposures
     end
 
     # delete existing entries which are DONE
-    queuedrop Phase0Exposures -key 0 DONE
+    book delpage Phase0Exposures -key state DONE
   end
 
   # default exit status
   task.exit    default
-    showcommand
-  end
-
-  # operation times out?
-  task.exit    timeout
-    showcommand
-  end
-end
-
-
-
-# run the phase0imfile script on pending images
+    showcommand failure
+  end
+
+  # operation times out?
+  task.exit    timeout
+    showcommand timeout
+  end
+end
+
+# run the phase0_exp.pl script on pending exposures
 task	       phase0.exp.run
   periods      -poll $runpoll
@@ -232,21 +178,21 @@
 
   task.exec
-    queuesize Phase0Exposures -var N
+    book npages Phase0Exposures -var N
     if ($N == 0) break
     if ($network == 0) break
     
-    # look for new images on the internal DetrendImfilesToProcess queue
-    # caution with these 'if' statements: syntax errors 
-    # will make the task fail without given a good status
-    queuepop Phase0Exposures -var line -key 0 NEW
-    if ("$line" == "NULL") break
-
-    strpop line state
-    queuepush Phase0Exposures -replace -key 1 "RUN $line"
-
-    ## the Phase0Exposures queue contains:
-    ## STATE EXP_TAG CAMERA TELESCOPE TYPE NCLASS
-    list word -split $line
-    $EXP_TAG   = $word:0
+    # look for new images in Phase0Exposures (state == NULL)
+    book getpage Phase0Exposures 0 -var pageName -key state NULL
+    if ($pageName == NULL) break
+
+    book setword Phase0Exposures $pageName state RUN
+    book getword Phase0Exposures $pageName exp_tag -var EXP_TAG
+
+    # 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
@@ -258,13 +204,8 @@
     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 phase0_exp.pl --exp_tag $EXP_TAG
@@ -276,5 +217,5 @@
   task.exit 0
     # phase0exp.pl updates DB tables, here we just update the queue
-    queuepush Phase0Exposures -replace -key 1 "DONE $options:0"
+    book setword Phase0Exposures $options:0 state DONE
   end
 
@@ -282,6 +223,5 @@
   task.exit    default
     showcommand
-    queuepush Phase0Exposures -replace -key 1 "FAIL $options:0"
-    $Phase0ExpFail
+    book setword Phase0Exposures $options:0 state FAIL
   end
 
@@ -289,6 +229,5 @@
   task.exit    timeout
     showcommand
-    queuepush Phase0Exposures -replace -key 1 "TIMEOUT $options:0"
-    $Phase0ExpFail
+    book setword Phase0Exposures $options:0 state TIMEOUT
   end
 end
