Index: trunk/ippTasks/flatcorr.pro
===================================================================
--- trunk/ippTasks/flatcorr.pro	(revision 25785)
+++ trunk/ippTasks/flatcorr.pro	(revision 25816)
@@ -2,45 +2,4 @@
 ## this file contains the tasks for running the flatcorr stage
 ## these tasks use the book 'flatcorrBook'
-
-# test for required global variables
-check.globals
-
-book init flatcorrBook
-
-macro flatcorr.reset
-  book init flatcorrBook
-end
-
-macro flatcorr.status
-  book listbook flatcorrBook
-end
-
-macro flatcorr.on
-  task flatcorr.advancecamera
-    active true
-  end
-  task flatcorr.load
-    active true
-  end
-  task flatcorr.run
-    active true
-  end
-end
-
-macro flatcorr.off
-  task flatcorr.advancecamera
-    active false
-  end
-  task flatcorr.load
-    active false
-  end
-  task flatcorr.run
-    active false
-  end
-end
-
-# these variables will cycle through the known ippdb database names
-$flatcorr_advancecamera_DB = 0
-$flatcorr_pendingprocess_DB = 0
 
 # a flat-field correction run is initiated (manually) with a command like:
@@ -57,5 +16,9 @@
 # flatcorr -advancecamera 
 
-# we wait for the completed chip and camera analysis and search for
+# as the camera analysis progresses, we need to occasionally migrate the
+# completed exposures to the addstar stage by calling:
+# flatcorr -advanceaddstar 
+
+# we wait for the completed addstar jobs and search for
 # completed processing analysis with:
 # flatcorr -pendingprocess
@@ -66,4 +29,52 @@
 # and failures with:
 # flatcorr -addprocess -fault N
+
+# test for required global variables
+check.globals
+
+book init flatcorrBook
+
+macro flatcorr.reset
+  book init flatcorrBook
+end
+
+macro flatcorr.status
+  book listbook flatcorrBook
+end
+
+macro flatcorr.on
+  task flatcorr.advancecamera
+    active true
+  end
+  task flatcorr.advanceaddstar
+    active true
+  end
+  task flatcorr.load
+    active true
+  end
+  task flatcorr.run
+    active true
+  end
+end
+
+macro flatcorr.off
+  task flatcorr.advancecamera
+    active false
+  end
+  task flatcorr.advanceaddstar
+    active false
+  end
+  task flatcorr.load
+    active false
+  end
+  task flatcorr.run
+    active false
+  end
+end
+
+# these variables will cycle through the known ippdb database names
+$flatcorr_advancecamera_DB = 0
+$flatcorr_advanceaddstar_DB = 0
+$flatcorr_pendingprocess_DB = 0
 
 # migrate complete flatcorr chips to the camera stage analysis
@@ -114,4 +125,51 @@
 end
 
+# migrate complete flatcorr exposures to the addstar process
+task	       flatcorr.advanceaddstar
+  host         local
+
+  # check the list of pending flatcorr runs
+  periods      -poll 5
+  periods      -exec 30
+  periods      -timeout 60
+  npending 1
+
+  task.exec
+    # define the command (does not depend on previous queries)
+    if ($DB:n == 0)
+      command flatcorr -advanceaddstar
+    else
+      # save the DB name for the exit tasks
+      # note that this DB name refers to the ippdb, not the dvodb
+      option $DB:$flatcorr_advanceaddstar_DB
+      command flatcorr -advanceaddstar -dbname $DB:$flatcorr_advanceaddstar_DB
+      $flatcorr_advanceaddstar_DB ++
+      if ($flatcorr_advanceaddstar_DB >= $DB:n) set flatcorr_advanceaddstar_DB = 0
+    end
+  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
+
+  task.exit    crash
+    showcommand crash
+  end
+
+  # operation times out?
+  task.exit    timeout
+    showcommand timeout
+  end
+end
+
 # create new flatcorr entries for the currently known DVO databases
 # run this multiple times once an hour - on pass for each db
@@ -123,5 +181,4 @@
   periods      -exec $LOADEXEC
   periods      -timeout 60
-  active false
   npending 1
 
@@ -180,5 +237,4 @@
   periods      -exec $LOADEXEC
   periods      -timeout 60
-  active false
 
   # silently drop stdout
