Index: trunk/ippTasks/Makefile.am
===================================================================
--- trunk/ippTasks/Makefile.am	(revision 19353)
+++ trunk/ippTasks/Makefile.am	(revision 19381)
@@ -23,11 +23,11 @@
 	chiphosts.manoa.config \
 	chiphosts.mhpcc.config \
-	simtest.basic.config \
 	site.manoa.pro \
 	site.mhpcc.pro \
 	simtest.pro \
-	simtest.auto \
-	simtest.det \
-	isp.det
+	simtest.basic.config \
+	simtest.basic.auto \
+	simtest.flatcorr.config \
+	simtest.flatcorr.auto
 
 pantasksdir = $(datadir)/pantasks
Index: trunk/ippTasks/automate.pro
===================================================================
--- trunk/ippTasks/automate.pro	(revision 19353)
+++ trunk/ippTasks/automate.pro	(revision 19381)
@@ -23,6 +23,6 @@
 
 macro automate.load
-  if ($0 != 3)
-    echo "USAGE: automate.load (filename) (dbname)"
+  if ($0 != 4)
+    echo "USAGE: automate.load (filename) (camera) (dbname)"
     break
   end
@@ -32,5 +32,6 @@
 
   ## interpolate standard values
-  queuesubstr tmp @DBNAME@ $2
+  queuesubstr tmp @CAMERA@ $2
+  queuesubstr tmp @DBNAME@ $3
   queuesubstr tmp @CWD@ $cwd
 
Index: trunk/ippTasks/notes.txt
===================================================================
--- trunk/ippTasks/notes.txt	(revision 19353)
+++ trunk/ippTasks/notes.txt	(revision 19381)
@@ -34,9 +34,26 @@
    * add an entry to ppMerge/src/ppMergeArguments.c
    * add an entry to ippconfig/recipes/ppMerge.config
+
    * add an entry to ippconfig/recipes/rejections.config
-   
+   * add a section to ippconfig/recipes/reductionClasses.mdc
+
+   * ippScripts/scripts/detrend_norm_apply.pl : entry in DETTYPE table
+   * ippScripts/scripts/detrend_norm_calc.pl : entry in NORMALIZE table
+   * ippScripts/scripts/detrend_resid_imfile.pl : entry in DETRENDS table
+   * ippScripts/scripts/detrend_stack.pl : entry in FILERULES and STATRECIPES tables
+   * ippScripts/scripts/detrend_resid_imfile.pl : entry in DETRENDS table
+
   * need a block in simtest.auto (or equiv) to check for when the chip processing / cam processing is complete
 
   * need to modify the detselect -inst arguments in simtest.auto (use @INST@ or equiv)
+
+  * reductions currently being used:
+    ** CHIP -- chip-level analysis
+    ** JPEG.BIN1, JPEG.BIN2 -- camera jpeg terms
+    ** JPEG_BIN1_IMAGE_(dettype), JPEG_BIN2_IMAGE_(dettype) 
+    ** JPEG_BIN1_RESID_(dettype), JPEG_BIN2_RESID_(dettype) 
+    ** (dettype)_STACK, 
+    ** (dettype)_PROCESS, 
+    ** FAKEPHOT
 
 2008.01.22
Index: trunk/ippTasks/simtest.basic.auto
===================================================================
--- trunk/ippTasks/simtest.basic.auto	(revision 19381)
+++ trunk/ippTasks/simtest.basic.auto	(revision 19381)
@@ -0,0 +1,119 @@
+
+automate MULTI
+
+# we run in the sequence BLOCK -> CHECK -> LAUNCH -> BLOCK -> CHECK
+# success on CHECK -> LAUNCH
+# failure on BLOCK -> CHECK
+
+# XXX these steps all refer to "@DBNAME@"; they need to be more generic, even for the basic simtest analysis
+
+automate METADATA
+  name       STR BIAS
+  check      STR "regtool -processedexp -exp_type BIAS -inst @CAMERA@ -dbname @DBNAME@"
+  ncheck     S32 20
+  launch     STR "dettool -definebyquery -workdir file://@CWD@/detwork -inst @CAMERA@ -det_type BIAS -select_exp_type BIAS -dbname @DBNAME@"
+  block      STR "dettool -runs -active -det_type BIAS -dbname @DBNAME@"
+END
+
+automate METADATA
+  name       STR DARK
+  check      STR "detselect -search -inst @CAMERA@ -det_type BIAS -dbname @DBNAME@"
+  launch     STR "dettool -definebyquery -workdir file://@CWD@/detwork -inst @CAMERA@ -det_type DARK -select_exp_type DARK -dbname @DBNAME@"
+  block      STR "dettool -runs -active -det_type DARK -dbname @DBNAME@"
+END
+ 
+automate METADATA
+  name       STR SHUTTER
+  check      STR "detselect -search -inst @CAMERA@ -det_type DARK -dbname @DBNAME@"
+  launch     STR "dettool -definebyquery -workdir file://@CWD@/detwork -inst @CAMERA@ -det_type SHUTTER -filter r -select_exp_type FLAT -select_filter r -dbname @DBNAME@"
+  block      STR "dettool -runs -active -det_type SHUTTER -dbname @DBNAME@"
+END
+
+automate METADATA
+  name       STR FLAT-r
+  check      STR "detselect -search -inst @CAMERA@ -det_type SHUTTER -dbname @DBNAME@"
+  launch     STR "dettool -definebyquery -workdir file://@CWD@/detwork -inst @CAMERA@ -det_type FLAT -filter r -select_exp_type FLAT -select_filter r -dbname @DBNAME@"
+  block      STR "dettool -runs -active -det_type FLAT -filter r -dbname @DBNAME@"
+END
+
+automate METADATA
+  name       STR FLAT-i
+  check      STR "detselect -search -inst @CAMERA@ -det_type SHUTTER -dbname @DBNAME@"
+  launch     STR "dettool -definebyquery -workdir file://@CWD@/detwork -inst @CAMERA@ -det_type FLAT -filter i -select_exp_type FLAT -select_filter i -dbname @DBNAME@"
+  block      STR "dettool -runs -active -det_type FLAT -filter i -dbname @DBNAME@"
+END
+
+automate METADATA
+  name       STR OBJECT-i
+  check      STR "detselect -dbname @DBNAME@ -search    -inst @CAMERA@ -filter i -det_type FLAT"
+  launch     STR "chiptool  -dbname @DBNAME@ -updaterun -inst @CAMERA@ -filter i -label wait -set_label proc"
+  block      STR NONE
+END
+
+automate METADATA
+  name       STR OBJECT-r
+  check      STR "detselect -dbname @DBNAME@ -search    -inst @CAMERA@ -filter r -det_type FLAT"
+  launch     STR "chiptool  -dbname @DBNAME@ -updaterun -inst @CAMERA@ -filter r -label wait -set_label proc"
+  block      STR NONE
+END
+
+### Stack automation???
+automate METADATA
+  name       STR STACK
+  regular    STR "stacktool -definebyquery -all -workdir file://@CWD@/stack -min_new 4 -min_frac 2 -select_good_frac_min 0.2 -dbname @DBNAME@"
+END
+
+### Diff automation???
+automate METADATA
+  name       STR DIFF
+  regular    STR "difftool -definebyquery -workdir file://@CWD@/diff -good_frac 0.2 -dbname @DBNAME@"
+END
+
+### Magic automation???
+automate METADATA
+  name       STR MAGIC
+  regular    STR "magictool -definebyquery -workdir file://@CWD@/magic -good_frac 0.2 -dbname @DBNAME@"
+END
+
+
+
+
+### automate METADATA
+###   name       STR OBJECT-r
+###   check      STR "detselect -search -inst @CAMERA@ -det_type FLAT -dbname @DBNAME@ -filter r"
+###   launch     STR "chiptool -unblock -label simtest-r -dbname @DBNAME@"
+###   block      STR "chiptool -unmasked -label simtest-r -dbname @DBNAME@"
+### END
+
+### automate METADATA
+###   name       STR OBJECT-i
+###   check      STR "detselect -search -inst @CAMERA@ -det_type FLAT -dbname @DBNAME@ -filter i"
+###   launch     STR "chiptool -unblock -label simtest-i -dbname @DBNAME@"
+###   block      STR "chiptool -unmasked -label simtest-i -dbname @DBNAME@"
+### END
+
+### there is a weakness in the label / block business: the labels are
+### generic, and the blocks are against those fairly generic words.
+### that makes it difficult to block and unblock science exposures
+### based on different detrend types that are available.  For example,
+### to block the r-band against the absence of the desired r-band
+### flat, we would need to specify a label specific to the r-band
+### images and remove that block when ready.
+
+### a better approach might be to modify the labels rather than the
+### blocks.  we can define, eg, chiptool -set_label -definebyquery to
+### turn assign the label names based on various properties of the
+### interesting images.
+
+### here is what the automate element might look like for such a circumstance:
+
+### automate METADATA
+###   name       STR OBJECT-i
+###   block      STR "chiptool -dbname @DBNAME@ -unmasked -label wait -filter i -time_begin 2008/1/1 -time_end 2008/1/2"
+###   check      STR "detselect -dbname @DBNAME@ -search -inst @CAMERA@ -det_type FLAT -dbname @DBNAME@ -filter i -time_begin 2008/1/1 -time_end 2008/1/2" 
+###   launch     STR "chiptool -dbname @DBNAME@ -set_label proc -label wait -dbname @DBNAME@ -time_begin 2008/1/1 -time_end 2008/1/2"
+### END
+
+### XXX still not quite there....
+### the 'checks' or maybe the 'launch' needs to include a '-n_exp_min' ?
+### 
Index: trunk/ippTasks/simtest.flatcorr.auto
===================================================================
--- trunk/ippTasks/simtest.flatcorr.auto	(revision 19353)
+++ trunk/ippTasks/simtest.flatcorr.auto	(revision 19381)
@@ -5,4 +5,7 @@
 # success on CHECK -> LAUNCH
 # failure on BLOCK -> CHECK
+
+# this is a simplified automate script which only models BIAS and FLAT.  
+# generate appropriate simulated data with the FLATCORR recipe
 
 # wait until 20 bias frames are registered, then define a new bias run
@@ -22,5 +25,5 @@
   block      STR "dettool -runs -active -det_type DARK -dbname @DBNAME@"
 END
- 
+
 # wait until the master dark frame is registered, then define a new shutter run
 automate METADATA
@@ -31,43 +34,44 @@
 END
 
-# wait until the master shutter frame is registered, then define a new flat-r run
+# wait until the master bias frame is registered, then define a new flat-r run
 automate METADATA
-  name       STR FLAT-r
+  name       STR RAWFLAT-r
   check      STR "detselect -search -inst @CAMERA@ -det_type SHUTTER -dbname @DBNAME@"
-  launch     STR "dettool -definebyquery -workdir file://@CWD@/detwork -inst @CAMERA@ -det_type FLAT -filter r -select_exp_type FLAT -select_filter r -dbname @DBNAME@"
-  block      STR "dettool -runs -active -det_type FLAT -filter r -dbname @DBNAME@"
+  launch     STR "dettool -definebyquery -workdir file://@CWD@/detwork -inst @CAMERA@ -det_type FLAT_RAW -filter r -select_exp_type FLAT -select_filter r -dbname @DBNAME@"
+  block      STR "dettool -runs -active -det_type FLAT_RAW -filter r -dbname @DBNAME@"
 END
 
-# wait until the master shutter frame is registered, then define a new flat-i run
+# wait until the master bias frame is registered, then define a new flat-i run
 automate METADATA
-  name       STR FLAT-i
+  name       STR RAWFLAT-i
   check      STR "detselect -search -inst @CAMERA@ -det_type SHUTTER -dbname @DBNAME@"
-  launch     STR "dettool -definebyquery -workdir file://@CWD@/detwork -inst @CAMERA@ -det_type FLAT -filter i -select_exp_type FLAT -select_filter i -dbname @DBNAME@"
-  block      STR "dettool -runs -active -det_type FLAT -filter i -dbname @DBNAME@"
+  launch     STR "dettool -definebyquery -workdir file://@CWD@/detwork -inst @CAMERA@ -det_type FLAT_RAW -filter i -select_exp_type FLAT -select_filter i -dbname @DBNAME@"
+  block      STR "dettool -runs -active -det_type FLAT_RAW -filter i -dbname @DBNAME@"
 END
 
-# wait until the master flat-r frame is registered, then unblock the r-band data for chip-level processing
-automate METADATA
-  name       STR OBJECT-i
-  check      STR "detselect -dbname @DBNAME@ -search    -inst @CAMERA@ -filter i -det_type FLAT"
-  launch     STR "chiptool  -dbname @DBNAME@ -updaterun -inst @CAMERA@ -filter i -label wait -set_label proc"
-  block      STR NONE
-END
+## # wait until the master flat-r frame is registered, then unblock the r-band data for chip-level processing
+## automate METADATA
+##   name       STR OBJECT-i
+##   check      STR "detselect -dbname @DBNAME@ -search    -inst @CAMERA@ -filter i -det_type FLAT"
+##   launch     STR "chiptool  -dbname @DBNAME@ -updaterun -inst @CAMERA@ -filter i -label wait -set_label proc"
+##   block      STR NONE
+## END
+## 
+## # wait until the master flat-i frame is registered, then unblock the i-band data for chip-level processing
+## automate METADATA
+##   name       STR OBJECT-r
+##   check      STR "detselect -dbname @DBNAME@ -search    -inst @CAMERA@ -filter r -det_type FLAT"
+##   launch     STR "chiptool  -dbname @DBNAME@ -updaterun -inst @CAMERA@ -filter r -label wait -set_label proc"
+##   block      STR NONE
+## END
+## 
+## # wait until the r-band is done with camera, then define a new flat-correction run
+## automate METADATA
+##   name       STR FLATCORR-i
+##   check      STR "camtool -dbname @DBNAME@ -search -inst @CAMERA@ -filter r"
+##   ncheck     S32 8
+##   launch     STR "chiptool  -dbname @DBNAME@ -updaterun -inst @CAMERA@ -filter i -label wait -set_label proc"
+##   block      STR NONE
+## END
 
-# wait until the master flat-i frame is registered, then unblock the i-band data for chip-level processing
-automate METADATA
-  name       STR OBJECT-r
-  check      STR "detselect -dbname @DBNAME@ -search    -inst @CAMERA@ -filter r -det_type FLAT"
-  launch     STR "chiptool  -dbname @DBNAME@ -updaterun -inst @CAMERA@ -filter r -label wait -set_label proc"
-  block      STR NONE
-END
-
-# wait until the r-band is done with camera, then define a new flat-correction run
-automate METADATA
-  name       STR FLATCORR-i
-  check      STR "camtool -dbname @DBNAME@ -search -inst @CAMERA@ -filter r"
-  ncheck     S32 8
-  launch     STR "chiptool  -dbname @DBNAME@ -updaterun -inst @CAMERA@ -filter i -label wait -set_label proc"
-  block      STR NONE
-END
-
+## flatcorr -definebyquery -dbname eamtest -filter r -set_workdir /data/alala.0/eugene/swtests/simtest/test.f1/work -set_reduction FLATCORR -set_dvodb /data/alala.0/eugene/swtests/simtest/test.f1/catdir.flatcorr -set_region 270.6,270.9:-23.8,-23.5 -set_filter r
Index: trunk/ippTasks/simtest.flatcorr.config
===================================================================
--- trunk/ippTasks/simtest.flatcorr.config	(revision 19381)
+++ trunk/ippTasks/simtest.flatcorr.config	(revision 19381)
@@ -0,0 +1,189 @@
+
+# generate a simple fake data set with 2x2 dithers at offset of
+# 50, 100, 200 arcsec (camera is 530 arcsec on a side)
+
+# define the simulated data to be generated
+SEQUENCE MULTI
+
+SEQUENCE METADATA
+  OBSTYPE    STR BIAS
+  CAMERA     STR SIMTEST
+  NIMAGES    S32  20
+END
+
+SEQUENCE METADATA
+  OBSTYPE    STR DARK
+  CAMERA     STR SIMTEST
+  @EXPTIMES  F32  30.0, 300.0
+  @NIMAGES   S32  10,   10
+END
+
+SEQUENCE METADATA
+  OBSTYPE    STR FLAT
+  CAMERA     STR SIMTEST
+
+  FILTERS    STR r,r,i
+  @EXPTIMES  F32 0.1,20.0,20.0
+
+  NSETUP     S32 5
+END
+
+SEQUENCE METADATA
+  OBSTYPE    STR FLAT
+  CAMERA     STR SIMTEST
+
+  FILTERS    STR r,r,r,r,r
+  @EXPTIMES  F32 0.5,1.0,2.0,5.0,10.0
+
+  NSETUP     S32 1
+END
+
+# a single image at the field center
+SEQUENCE METADATA
+  OBSTYPE    STR OBJECT
+  CAMERA     STR SIMTEST
+
+  ### Carina (modestly high density)
+  CENTER.RA  F32 270.75
+  CENTER.DEC F32 -23.7
+
+  # the simtest camera is 2k x 2k, 530 arcsec on a side
+  # XXX note that we cannot define the offsets in terms of the camera dimensions...
+
+  OFFSET.RA  F32 0.0 # linear offset in arcsec (do not include cos(DEC) correction)
+  OFFSET.DEC F32 0.0 # linear offset in arcsec (do not include cos(DEC) correction)
+  OFFSET.NR  S32 1
+  OFFSET.ND  S32 1
+
+  DITHER.RA  F32 0.0   # linear offset in arcsec (do not include cos(DEC) correction)
+  DITHER.DEC F32 0.0   # linear offset in arcsec (do not include cos(DEC) correction)
+  DITHER.NR  S32 1
+  DITHER.ND  S32 1
+
+  # XXX is DVODB used?
+  DVODB      STR /data/alala.0/ipp/ippRefs/catdir.synth.simtest 
+  FILTERS    STR r,i
+  @EXPTIMES  F32 10.00,10.00
+  @SKYMAGS   F32 20.86,20.15
+
+  # modest IQ range here
+  IQ_MIN     F32 0.70
+  IQ_MAX     F32 0.90
+  
+  # rotation sequence
+  POS_MIN    F32 0.0
+  POS_MAX    F32 0.0
+  POS_DELTA  F32 1.0
+
+END
+
+# dither set @ scale 1 = 60 arcsec
+SEQUENCE METADATA
+  OBSTYPE    STR OBJECT
+  CAMERA     STR SIMTEST
+
+  ### Carina (modestly high density)
+  CENTER.RA  F32 270.75
+  CENTER.DEC F32 -23.7
+
+  # XXX note that we cannot define the offsets in terms of the camera dimensions...
+  OFFSET.RA  F32 0.0 # linear offset in arcsec (do not include cos(DEC) correction)
+  OFFSET.DEC F32 0.0 # linear offset in arcsec (do not include cos(DEC) correction)
+  OFFSET.NR  S32 1
+  OFFSET.ND  S32 1
+
+  DITHER.RA  F32 60.0   # linear offset in arcsec (do not include cos(DEC) correction)
+  DITHER.DEC F32 60.0   # linear offset in arcsec (do not include cos(DEC) correction)
+  DITHER.NR  S32 2
+  DITHER.ND  S32 2
+
+  # XXX is DVODB used?
+  DVODB      STR /data/alala.0/ipp/ippRefs/catdir.synth.simtest 
+  FILTERS    STR r,i
+  @EXPTIMES  F32 10.00,10.00
+  @SKYMAGS   F32 20.86,20.15
+
+  # modest IQ range here
+  IQ_MIN     F32 0.70
+  IQ_MAX     F32 0.90
+  
+  # rotation sequence
+  POS_MIN    F32 0.0
+  POS_MAX    F32 0.0
+  POS_DELTA  F32 1.0
+
+END
+
+# dither set @ scale 2 = 120 arcsec
+SEQUENCE METADATA
+  OBSTYPE    STR OBJECT
+  CAMERA     STR SIMTEST
+
+  ### Carina (modestly high density)
+  CENTER.RA  F32 270.75
+  CENTER.DEC F32 -23.7
+
+  # XXX note that we cannot define the offsets in terms of the camera dimensions...
+  OFFSET.RA  F32 0.0 # linear offset in arcsec (do not include cos(DEC) correction)
+  OFFSET.DEC F32 0.0 # linear offset in arcsec (do not include cos(DEC) correction)
+  OFFSET.NR  S32 1
+  OFFSET.ND  S32 1
+
+  DITHER.RA  F32 120.0   # linear offset in arcsec (do not include cos(DEC) correction)
+  DITHER.DEC F32 120.0   # linear offset in arcsec (do not include cos(DEC) correction)
+  DITHER.NR  S32 2
+  DITHER.ND  S32 2
+
+  # XXX is DVODB used?
+  DVODB      STR /data/alala.0/ipp/ippRefs/catdir.synth.simtest 
+  FILTERS    STR r,i
+  @EXPTIMES  F32 10.00,10.00
+  @SKYMAGS   F32 20.86,20.15
+
+  # modest IQ range here
+  IQ_MIN     F32 0.70
+  IQ_MAX     F32 0.90
+  
+  # rotation sequence
+  POS_MIN    F32 0.0
+  POS_MAX    F32 0.0
+  POS_DELTA  F32 1.0
+
+END
+
+# dither set @ scale 3 = 240 arcsec
+SEQUENCE METADATA
+  OBSTYPE    STR OBJECT
+  CAMERA     STR SIMTEST
+
+  ### Carina (modestly high density)
+  CENTER.RA  F32 270.75
+  CENTER.DEC F32 -23.7
+
+  # XXX note that we cannot define the offsets in terms of the camera dimensions...
+  OFFSET.RA  F32 0.0 # linear offset in arcsec (do not include cos(DEC) correction)
+  OFFSET.DEC F32 0.0 # linear offset in arcsec (do not include cos(DEC) correction)
+  OFFSET.NR  S32 1
+  OFFSET.ND  S32 1
+
+  DITHER.RA  F32 240.0   # linear offset in arcsec (do not include cos(DEC) correction)
+  DITHER.DEC F32 240.0   # linear offset in arcsec (do not include cos(DEC) correction)
+  DITHER.NR  S32 2
+  DITHER.ND  S32 2
+
+  # XXX is DVODB used?
+  DVODB      STR /data/alala.0/ipp/ippRefs/catdir.synth.simtest 
+  FILTERS    STR r,i
+  @EXPTIMES  F32 10.00,10.00
+  @SKYMAGS   F32 20.86,20.15
+
+  # modest IQ range here
+  IQ_MIN     F32 0.70
+  IQ_MAX     F32 0.90
+  
+  # rotation sequence
+  POS_MIN    F32 0.0
+  POS_MAX    F32 0.0
+  POS_DELTA  F32 1.0
+
+END
Index: trunk/ippTasks/simtest.pro
===================================================================
--- trunk/ippTasks/simtest.pro	(revision 19353)
+++ trunk/ippTasks/simtest.pro	(revision 19381)
@@ -1,19 +1,58 @@
 ## simtest.pro : automatic full-suite simulated IPP test : -*- sh -*-
 
+## there are four features which define a simtest run:
+## the camera : any camera can be used, the sim... cameras are defined to be quick tests
+## the sequence : this file defines the set of observations generated
+## the auto : the automation file defines the sequence of analysis performed
+## the recipe : the ppsim recipe defines the features which are included in the generate data
+
+## these are not completely independent: a certain sequence may be
+## required to yield a sensible result for a specific auto, and a
+## specific recipe may also be needed
+
+if ($?PPSIM_RECIPE == 0) 
+  $PPSIM_RECIPE = default
+end
+if ($?SIMTEST_CAMERA == 0)
+  $SIMTEST_CAMERA = SIMTEST
+end
+if ($?SIMTEST_SEQUENCE == 0)
+  $SIMTEST_SEQUENCE = simtest.basic.config
+end
+if ($?SIMTEST_AUTO == 0)
+  $SIMTEST_AUTO = simtest.basic.auto
+end
+if ($?SIMTEST_THREADS == 0) 
+  $SIMTEST_THREADS = 0
+end
+
 macro simtest
-  if ($0 != 6)
-    echo "USAGE: simtest (testroot) (dbname) (hostname) (threads) (init)"
-    echo " if (init) == 0, just run the analysis tasks"
-    echo " if (init) == 1, (re)create the database and (re)inject the images"
-    echo " if (init) == 2, restart completely from scratch"
+  if ($0 != 4)
+    echo "USAGE: simtest (dbname) (hostname) (init)"
+    echo " if (init) == run    : just run the analysis tasks"
+    echo " if (init) == inject : (re)create the database and (re)inject the images"
+    echo " if (init) == new    : restart completely from scratch"
+    echo ""
+    echo "there are additional options which may be specified by setting the following variable names:" 
+    echo "  PPSIM_RECIPE     : define the recipe to use when generating the fake data"
+    echo "  SIMTEST_CAMERA   : define an alternate camera (otherwise uses entry in sequence file)"
+    echo "  SIMTEST_SEQUENCE : define the set of observations generated (simtest.basic.config)"
+    echo "  SIMTEST_AUTO     : define the analysis steps to perform (simtest.auto)"
+    echo "  SIMTEST_THREADS  : set the number of threads for the processing node (0)"
     break
   end
 
-  $testroot = $1
-  $dbname = $2
-  $hostname = $3
-  $threads = $4
+  $dbname = $1
+  $hostname = $2
+  $init = $3
+  if (("$init" != "run") && ("$init" != "inject") && ("$init" != "new"))
+    echo "USAGE: simtest (dbname) (hostname) (init)"
+    echo " if (init) == run    : just run the analysis tasks"
+    echo " if (init) == inject : (re)create the database and (re)inject the images"
+    echo " if (init) == new    : restart completely from scratch"
+    break
+  end    
  
-  if ($5 > 0)
+  if (("$init" == "new") || ("$init" == "new"))  
     # XXX this will fail and exit the script if the db does not exist or is old...
     exec pxadmin -delete -dbname $dbname
@@ -22,12 +61,18 @@
     exec pxadmin -create -dbname $dbname
 
-    if ($5 == 2)
+    if ("$init" == "new")
       # the labels "wait" and "proc" are special names used in automate.pro
-      exec ppSimSequence $MODULES:0/$testroot.config $testroot.mkimages $testroot.inject -path raw -workdir work -dbname $dbname -label wait -dvodb DVO -tess_id TESS 
-      # not ready for this yet
-      # -ppsim_recipe FLATCORR
+    
+      $ppsim = "ppSimSequence $MODULES:0/$SIMTEST_SEQUENCE simtest.mkimages simtest.inject -path raw -workdir work -dbname $dbname -label wait -dvodb DVO -tess_id TESS"
+      if ("$PPSIM_RECIPE" != "default") 
+         $ppsim = $ppsim -ppsim_recipe $PPSIM_RECIPE
+      end
+      $ppsim = $ppsim -camera $SIMTEST_CAMERA
 
-      exec source $testroot.mkimages
+      exec $ppsim
 
+      exec source simtest.mkimages
+
+      ## XXX this will need to be optional as well 
       file TESS/Images.dat found
       if ($found == 0)
@@ -37,5 +82,5 @@
 
     exec chiptool -dbname $dbname -block -label wait
-    exec source $testroot.inject
+    exec source simtest.inject
   end
 
@@ -45,10 +90,26 @@
   module.tasks
 
-  controller host add $hostname
+  if ($SIMTEST_THREADS == 0) 
+    controller host add $hostname
+  else
+    controller host add $hostname -threads $SIMTEST_THREADS
+  end
+
   add.database $dbname
 
-  automate.load simtest.auto $dbname
+  automate.load $SIMTEST_AUTO $SIMTEST_CAMERA $dbname
   run
 end
 
 # XXX add a test function to pxadmin to check for db existence
+
+## currently defined options for sequence, etc:
+
+# sequence: simtest.basic.config, simtest.flatcorr.config
+# auto: simtest.basic.auto, simtest.flatcorr.auto
+
+macro simtest.setup.flatcorr
+  $PPSIM_RECIPE = FLATCORR
+  $SIMTEST_SEQUENCE = simtest.flatcorr.config
+  $SIMTEST_AUTO = simtest.flatcorr.auto
+end
