Index: /trunk/ippTasks/Makefile.am
===================================================================
--- /trunk/ippTasks/Makefile.am	(revision 16491)
+++ /trunk/ippTasks/Makefile.am	(revision 16492)
@@ -6,5 +6,5 @@
 	detrend.resid.pro \
 	detrend.stack.pro \
-	mkdetrend.pro \
+	automate.pro \
 	pantasks.pro \
 	register.pro \
Index: /trunk/ippTasks/automate.pro
===================================================================
--- /trunk/ippTasks/automate.pro	(revision 16492)
+++ /trunk/ippTasks/automate.pro	(revision 16492)
@@ -0,0 +1,155 @@
+## mkdetrend.pro : autorun the detrend analysis : -*- sh -*-
+
+# example automation stage
+# automate METADATA
+#   name       STR DARK
+#   check      STR "detselect -search -inst SIMTEST -det_type BIAS -dbname eamtest"
+#   launch     STR "dettool -definebyquery -workdir path://EAMWORK -inst SIMTEST -det_type DARK -select_exp_type DARK -dbname eamtest"
+# END
+
+# an entry in the 'automate' book goes through the following states:
+# INIT (book loaded from input file)
+# CHECK (stage prereqs being checked)
+# READY (prereqs satisfield, ready to be launched)
+# LAUNCH (action being performed)
+# DONE (action finished)
+
+# XXX since the state is ephemeral, any stages for which the prereq
+# exists will be re-launched every time this tasks is loaded in
+# pantasks.  We can add a 'block' stage to test if a given stage has
+# already been performed or not...
+
+macro load.automate
+  if ($0 != 2)
+    echo "USAGE: load.automate (filename)"
+    break
+  end
+  queueload tmp -x "cat $MODULES:0/$1"
+  ipptool2book tmp automate -key name -uniq -setword pantaskState INIT
+  queuedelete tmp
+end
+
+$automate_Ncheck = 0
+
+task automate.check
+  host         local
+
+  periods      -poll 1
+  periods      -exec 10
+  periods      -timeout 30
+  active       true
+  npending     1
+
+  task.exec
+    local N Npage pageName
+
+    # how many pages are waiting to be started?
+    book npages automate -var N -key pantaskState INIT
+    if ($N == 0) break
+
+    # total number of pages in book
+    book npages automate -var Npage
+
+    $automate_Ncheck ++
+    if ($automate_Ncheck >= $Npage) set automate_Ncheck = 0
+
+    # search the automate book for an entry which is unstarted (state INIT) 
+    book getpage automate $automate_Ncheck -var pageName -key pantaskState INIT
+    if ("$pageName" == "NULL") break 
+ 
+    book getword automate $pageName check -var checkCommand
+    if (("$checkCommand" == "NULL") || ("$checkCommand" == "NONE"))
+      # if there is no check needed, we can immediate progress to READY
+      book setword automate $pageName pantaskState READY
+      break
+    end
+
+    book setword automate $pageName pantaskState CHECK
+
+    if ($VERBOSE >= 1)
+      echo "starting automate check for $pageName"
+      echo "command $checkCommand"
+    end
+
+    options $pageName
+    command $checkCommand
+  end
+
+  task.exit $EXIT_SUCCESS
+    local pageName Npage
+
+    $pageName = $options:0
+
+    # convert 'stdout' to book format
+    # XXX to use other tests, we'll need to modify this 
+    ipptool2book stdout detExp -key det_id -uniq
+    if ($VERBOSE > 2)
+      book listbook detExp
+    end
+
+    book npages detExp -var Npage 
+    if ($Npage == 0) break
+
+    # we should have launched only a single detRun
+    book setword automate $pageName pantaskState READY
+
+    # drop the detExt book after we've grabbed the state
+    book delete detExp
+  end
+end
+
+$automate_Nlaunch = 0
+
+task automate.launch
+  host         local
+
+  periods      -poll 1
+  periods      -exec 10
+  periods      -timeout 30
+  active       true
+  npending     1
+
+  task.exec
+    local N Npage pageName
+
+    # how many pages are waiting to be started?
+    book npages automate -var N -key pantaskState READY
+    if ($N == 0) break
+
+    # total number of pages in book
+    book npages automate -var Npage
+
+    $automate_Nlaunch ++
+    if ($automate_Nlaunch >= $Npage) set automate_Nlaunch = 0
+
+    # search the automate book for an entry which is ready (state READY) 
+    book getpage automate $automate_Nlaunch -var pageName -key pantaskState READY
+    if ("$pageName" == "NULL") break 
+ 
+    book getword automate $pageName launch -var launchCommand
+    if (("$launchCommand" == "NULL") || ("$launchCommand" == "NONE"))
+      # if there is no launch needed, we can immediate progress to READY
+      book setword automate $pageName pantaskState DONE
+      break
+    end
+
+    book setword automate $pageName pantaskState LAUNCH
+
+    if ($VERBOSE >= 1)
+      echo "starting automate launch for $pageName"
+      echo "command $launchCommand"
+    end
+
+    options $pageName
+    command $launchCommand
+  end
+
+  task.exit $EXIT_SUCCESS
+    local pageName
+
+    $pageName = $options:0
+
+    # we should have launched only a single detRun
+    book setword automate $pageName pantaskState DONE
+  end
+end
Index: /trunk/ippTasks/simtest.auto
===================================================================
--- /trunk/ippTasks/simtest.auto	(revision 16492)
+++ /trunk/ippTasks/simtest.auto	(revision 16492)
@@ -0,0 +1,45 @@
+
+automate MULTI
+
+automate METADATA
+  name       STR BIAS
+  check      STR NONE
+  launch     STR "dettool -definebyquery -workdir path://EAMWORK -inst SIMTEST -det_type BIAS -select_exp_type BIAS -dbname eamtest"
+END
+
+automate METADATA
+  name       STR DARK
+  check      STR "detselect -search -inst SIMTEST -det_type BIAS -dbname eamtest"
+  launch     STR "dettool -definebyquery -workdir path://EAMWORK -inst SIMTEST -det_type DARK -select_exp_type DARK -dbname eamtest"
+END
+
+automate METADATA
+  name       STR SHUTTER
+  check      STR "detselect -search -inst SIMTEST -det_type DARK -dbname eamtest"
+  launch     STR "dettool -definebyquery -workdir path://EAMWORK -inst SIMTEST -det_type SHUTTER -filter r -select_exp_type FLAT -select_filter r -dbname eamtest"
+END
+
+automate METADATA
+  name       STR FLAT-r
+  check      STR "detselect -search -inst SIMTEST -det_type SHUTTER -dbname eamtest"
+  launch     STR "dettool -definebyquery -workdir path://EAMWORK -inst SIMTEST -det_type FLAT -filter r -select_exp_type FLAT -select_filter r -dbname eamtest"
+END
+
+automate METADATA
+  name       STR FLAT-i
+  check      STR "detselect -search -inst SIMTEST -det_type SHUTTER -dbname eamtest"
+  launch     STR "dettool -definebyquery -workdir path://EAMWORK -inst SIMTEST -det_type FLAT -filter i -select_exp_type FLAT -select_filter i -dbname eamtest"
+END
+
+automate METADATA
+  name       STR OBJECT-r
+  check      STR "detselect -search -inst SIMTEST -det_type FLAT -dbname eamtest -filter r"
+  launch     STR "chiptool -unblock -label object.r -dbname eamtest"
+END
+
+automate METADATA
+  name       STR OBJECT-i
+  check      STR "detselect -search -inst SIMTEST -det_type FLAT -dbname eamtest -filter i"
+  launch     STR "chiptool -unblock -label object.i -dbname eamtest"
+END
+
