Index: trunk/ippTasks/flatcorr.pro
===================================================================
--- trunk/ippTasks/flatcorr.pro	(revision 16298)
+++ trunk/ippTasks/flatcorr.pro	(revision 19329)
@@ -6,8 +6,5 @@
 check.globals
 
-$LOGSUBDIR = $LOGDIR/flatcorr
-exec mkdir -p $LOGSUBDIR
-
-book init flatcoorBook
+book init flatcorrBook
 
 macro flatcorr.reset
@@ -20,22 +17,88 @@
 
 macro flatcorr.on
-  task flatcorr.init
+  task flatcorr.load
     active true
   end
+  task flatcorr.run
+    active true
+  end
 end
 
 macro flatcorr.off
-  task flatcorr.init
+  task flatcorr.load
     active false
   end
+  task flatcorr.run
+    active false
+  end
 end
 
 # these variables will cycle through the known ippdb database names
-$calInit_DB = 0
-
-# we have three steps here:
-# 1) get the list of dvo databases:  caltool -dbs
-# 2) define a new flatcorr run for each of the dvo dbs
-#    caltool 
+$flatcorr_addcamera_DB = 0
+$flatcorr_pendingprocess_DB = 0
+
+# a flat-field correction run is initiated (manually) with a command like:
+# flatcorr -definebyquery -filter r ...
+# the result is a flatcorrRun entry, a set of chipRun entries, a linking list in flatcorrChipList.  
+# the chipRun entries are all set to stop at the "chip" stage.
+
+# we also can define a run with:
+# flatcorr -definerun 
+# flatcorr -addchip ...
+
+# as the chip analysis progresses, we need to occasionally migrate the
+# completed chips to the camera stage by calling:
+# flatcorr -addcamera 
+
+# we wait for the completed chip and camera analysis and search for
+# completed processing analysis with:
+# flatcorr -pendingprocess
+
+# these define arguments to an analysis run.  successful completion of
+# the analysis is marked with:
+# flatcorr -addprocess
+# and failures with:
+# flatcorr -addprocess -fault N
+
+# migrate complete flatcorr chips to the camera stage analysis
+task	       flatcorr.addcamera
+  host         local
+
+  # check the list of pending flatcorr runs
+  periods      -poll 10
+  periods      -exec 120
+  periods      -timeout 60
+  npending 1
+
+  # define the command (does not depend on previous queries)
+  if ($DB:n == 0)
+    command flatcorr -addcamera
+  else
+    # save the DB name for the exit tasks
+    # note that this DB name refers to the ippdb, not the dvodb
+    option $DB:$flatcorr_addcamera_DB
+    command flatcorr -addcamera -dbname $DB:$flatcorr_addcamera_DB
+    $flatcorr_addcamera_DB ++
+    if ($flatcorr_addcamera_DB >= $DB:n) set flatcorr_addcamera_DB = 0
+  end
+
+  # silently drop stdout
+  stdout NULL
+  stderr $LOGDIR/flatcorr.log
+
+  # success (no action required)
+  task.exit $EXIT_SUCCESS
+  end
+
+  # locked list
+  task.exit    default
+    showcommand failure
+  end
+
+  # operation times out?
+  task.exit    timeout
+    showcommand timeout
+  end
+end
 
 # create new flatcorr entries for the currently known DVO databases
@@ -52,23 +115,20 @@
   # define the command (does not depend on previous queries)
   if ($DB:n == 0)
-    command flatcorr -pending
+    command flatcorr -pendingprocess
   else
     # save the DB name for the exit tasks
-    # note that this DB name refers to the ippdb, not the dvodb
-    option $DB:$calInit_DB
-    command flatcorr -pending -dbname $DB:$calInit_DB
-    $calInit_DB ++
-    if ($calInit_DB >= $DB:n) set calInit_DB = 0
+    option $DB:$flatcorr_pendingprocess_DB
+    command flatcorr -pendingprocess -dbname $DB:$flatcorr_pendingprocess_DB
+    $flatcorr_pendingprocess_DB ++
+    if ($flatcorr_pendingprocess_DB >= $DB:n) set flatcorr_pendingprocess_DB = 0
   end
 
   # silently drop stdout
   stdout NULL
-  stderr $LOGSUBDIR/flatcorr.log
+  stderr $LOGDIR/flatcorr.log
 
   # success
   task.exit $EXIT_SUCCESS
-    # convert 'stdout' to book format
-    # XXX have ippTools report the dbname?
-    ipptool2book stdout flatcorrBook -key dbname:corr_id -uniq -setword dbname $options:0 -setword pantaskState INIT
+    ipptool2book stdout flatcorrBook -key corr_id -uniq -setword dbname $options:0 -setword pantaskState INIT
     if ($VERBOSE > 2)
       book listbook flatcorrBook
@@ -90,7 +150,5 @@
 end
 
-# create new flatcorr entries for the currently known DVO databases
-# run this multiple times once an hour - one pass for each db
-# can we include information that the db has been updated without a recent cal analysis?
+# check for flatcorr runs which are ready to go
 task	       flatcorr.run
   host         local
@@ -99,11 +157,8 @@
   periods      -exec $LOADEXEC
   periods      -timeout 60
-  # trange     Hourly@00:00 Hourly@00:10
-  # every hour on the hour
-  npending     1
 
   # silently drop stdout
-  stdout NULL
-  stderr $LOGSUBDIR/flatcorr.log
+  stdout $LOGDIR/flatcorr.log
+  stderr $LOGDIR/flatcorr.log
 
   task.exec
@@ -112,18 +167,17 @@
     if ($NETWORK == 0) break
     
-    # look for new images in flatcorrBook
-    # the sequencing in this task set is by the pantasksState (see notes.txt)
+    # look for new entries in flatcorrBook
     book getpage flatcorrBook 0 -var pageName -key pantaskState INIT
     if ("$pageName" == "NULL") break
 
     book setword flatcorrBook $pageName pantaskState     RUN
-    book setword flatcorrBook $pageName region           $REGION
 
     # XXX probably need to set the output / log based on WORKDIR...
-    book getword flatcorrBook $pageName cal_id      -var ID
+    book getword flatcorrBook $pageName corr_id     -var ID
     book getword flatcorrBook $pageName dvodb       -var DVODB
     book getword flatcorrBook $pageName region      -var REGION
     book getword flatcorrBook $pageName filter      -var FILTER
     book getword flatcorrBook $pageName dbname      -var DBNAME
+    book getword flatcorrBook $pageName workdir     -var WORKDIR
 
     # specify choice of remote host
@@ -138,4 +192,5 @@
     options $pageName
 
+    # XXX get these arguments right
     $run = flatcorr_proc.pl --corr_id $ID --dvodb $DVODB --region $REGION --filter $FILTER
     add_standard_args run
