Index: branches/cnb_branch_20081104/ippTasks/Makefile.am
===================================================================
--- branches/cnb_branch_20081011/ippTasks/Makefile.am	(revision 20067)
+++ branches/cnb_branch_20081104/ippTasks/Makefile.am	(revision 20530)
@@ -6,4 +6,6 @@
 	detrend.resid.pro \
 	detrend.stack.pro \
+	detrend.correct.pro \
+	flatcorr.pro \
 	automate.pro \
 	pantasks.pro \
@@ -25,4 +27,5 @@
 	site.manoa.pro \
 	site.mhpcc.pro \
+	surveys.mhpcc.config \
 	simtest.pro \
 	simtest.basic.config \
Index: branches/cnb_branch_20081104/ippTasks/detrend.correct.pro
===================================================================
--- branches/cnb_branch_20081011/ippTasks/detrend.correct.pro	(revision 20067)
+++ branches/cnb_branch_20081104/ippTasks/detrend.correct.pro	(revision 20530)
@@ -1,22 +1,18 @@
 ## detrend.correct.pro : globals and support macros : -*- sh -*-
 ## this file contains the tasks for running the detrend correction stage
-## these tasks use the books detPendingCorrectedImfile and detPendingCorrectedExp
+## these tasks use the books detPendingCorrectImfile
 
 # test for required global variables
 check.globals
 
-book init detPendingCorrectedImfile
-book init detPendingCorrectedExp
+book init detPendingCorrectImfile
 
 macro detcorr.reset
-  book init detPendingCorrectedImfile
-  book init detPendingCorrectedExp
+  book init detPendingCorrectImfile
 end
 
 macro detcorr.status
-  echo detPendingCorrectedImfile
-  book listbook detPendingCorrectedImfile
-  echo detPendingCorrectedExp
-  book listbook detPendingCorrectedExp
+  echo detPendingCorrectImfile
+  book listbook detPendingCorrectImfile
 end
 
@@ -26,10 +22,4 @@
   end
   task detrend.correct.run
-    active true
-  end
-  task detrend.correctexp.load
-    active true
-  end
-  task detrend.correctexp.run
     active true
   end
@@ -43,19 +33,12 @@
     active false
   end
-  task detrend.correctexp.load
-    active false
-  end
-  task detrend.correctexp.run
-    active false
-  end
 end
 
 
 # these variables will cycle through the known database names
-$detPendingCorrectedImfile_DB = 0
-$detPendingCorrectedExp_DB = 0
+$detPendingCorrectImfile_DB = 0
 
 # select images ready for copy 
-# new entries are added to detPendingCorrectedImfile
+# new entries are added to detPendingCorrectImfile
 # compare the new list with the ones already selected
 task	       detrend.correct.load
@@ -71,15 +54,15 @@
 
   task.exec
-    $run = dettool -tocorrectedimfile
+    $run = dettool -tocorrectimfile
     if ($DB:n == 0)
       option DEFAULT
     else
       # save the DB name for the exit tasks
-      option $DB:$detPendingCorrectedImfile_DB
-      $run = $run -dbname $DB:$detPendingCorrectedImfile_DB
-      $detPendingCorrectedImfile_DB ++
-      if ($detPendingCorrectedImfile_DB >= $DB:n) set detPendingCorrectedImfile_DB = 0
+      option $DB:$detPendingCorrectImfile_DB
+      $run = $run -dbname $DB:$detPendingCorrectImfile_DB
+      $detPendingCorrectImfile_DB ++
+      if ($detPendingCorrectImfile_DB >= $DB:n) set detPendingCorrectImfile_DB = 0
     end
-    add_poll_args run
+    # add_poll_args run
     command $run
   end
@@ -88,11 +71,11 @@
   task.exit    0
     # convert 'stdout' to book format
-    ipptool2book stdout detPendingCorrectedImfile -key det_id:exp_id:class_id -uniq -setword dbname $options:0 -setword pantaskState INIT
+    ipptool2book stdout detPendingCorrectImfile -key det_id:class_id -uniq -setword dbname $options:0 -setword pantaskState INIT
     if ($VERBOSE > 2)
-      book listbook detPendingCorrectedImfile
+      book listbook detPendingCorrectImfile
     end
 
     # delete existing entries in the appropriate pantaskStates
-    process_cleanup detPendingCorrectedImfile
+    process_cleanup detPendingCorrectImfile
   end
 
@@ -115,24 +98,20 @@
 
   task.exec
-    book npages detPendingCorrectedImfile -var N
+    book npages detPendingCorrectImfile -var N
     if ($N == 0) break
     if ($NETWORK == 0) break
     
-    # look for new images in detPendingCorrectedImfile
-    book getpage detPendingCorrectedImfile 0 -var pageName -key pantaskState INIT
+    # look for new images in detPendingCorrectImfile
+    book getpage detPendingCorrectImfile 0 -var pageName -key pantaskState INIT
     if ("$pageName" == "NULL") break
 
-    book setword detPendingCorrectedImfile $pageName pantaskState RUN
-    book getword detPendingCorrectedImfile $pageName det_id    -var DET_ID   
-    book getword detPendingCorrectedImfile $pageName exp_id    -var EXP_ID  
-    book getword detPendingCorrectedImfile $pageName class_id  -var CLASS_ID 
-    book getword detPendingCorrectedImfile $pageName exp_tag   -var EXP_TAG  XXX where does this come from
-    book getword detPendingCorrectedImfile $pageName det_type  -var DET_TYPE  XXX where does this come from
-    book getword detPendingCorrectedImfile $pageName camera    -var CAMERA  XXX where does this come from
-    book getword detPendingCorrectedImfile $pageName uri       -var URI      
-    book getword detPendingCorrectedImfile $pageName corr_id   -var CORR_ID
-    book getword detPendingCorrectedImfile $pageName corr_type -var CORR_TYPE
-    book getword detPendingCorrectedImfile $pageName workdir   -var WORKDIR_TEMPLATE
-    book getword detPendingCorrectedImfile $pageName dbname    -var DBNAME
+    book setword detPendingCorrectImfile $pageName pantaskState RUN
+    book getword detPendingCorrectImfile $pageName det_id    -var DET_ID   
+    book getword detPendingCorrectImfile $pageName class_id  -var CLASS_ID 
+    book getword detPendingCorrectImfile $pageName det_type  -var DET_TYPE
+    book getword detPendingCorrectImfile $pageName camera    -var CAMERA
+    book getword detPendingCorrectImfile $pageName uri       -var URI      
+    book getword detPendingCorrectImfile $pageName workdir   -var WORKDIR_TEMPLATE
+    book getword detPendingCorrectImfile $pageName dbname    -var DBNAME
 
     # specify choice of local or remote host based on camera and chip (class_id)
@@ -143,16 +122,10 @@
 
     ## generate outroot specific to this exposure (& chip)
-    sprintf outroot "%s/%s.%s.%s/%s/%s.detcorr.%s" $WORKDIR $CAMERA $DET_TYPE $DET_ID $EXP_TAG $EXP_TAG $DET_ID
+    sprintf outroot "%s/%s.%s.%s/%s.%s.%s" $WORKDIR $CAMERA $DET_TYPE $DET_ID $CAMERA $DET_TYPE $DET_ID
 
     stdout $LOGDIR/detcorr.run.log
     stderr $LOGDIR/detcorr.run.log
 
-    $run = detrend_correct_imfile.pl --det_id $DET_ID --exp_id $EXP_ID --class_id $CLASS_ID --exp_tag $EXP_TAG --input_uri $URI --corr_id $CORR_ID --corr_type $CORR_TYPE --camera $CAMERA --outroot $outroot --redirect-output --verbose
-    if ("$WORKDIR" != "NULL")
-      $run = $run --workdir $WORKDIR
-    end
-    if ("$REDUCTION" != "NULL")
-      $run = $run --reduction $REDUCTION
-    end
+    $run = detrend_correct_imfile.pl --det_id $DET_ID --class_id $CLASS_ID --det_type $DET_TYPE --input_uri $URI --camera $CAMERA --outroot $outroot --redirect-output --verbose
     add_standard_args run
 
@@ -169,5 +142,5 @@
   # default exit status
   task.exit    default
-    process_exit detPendingCorrectedImfile $options:0 $JOB_STATUS
+    process_exit detPendingCorrectImfile $options:0 $JOB_STATUS
   end
 
@@ -175,124 +148,6 @@
   task.exit    timeout
     showcommand timeout
-    book setword detPendingCorrectedImfile $options:0 pantaskState TIMEOUT
+    book setword detPendingCorrectImfile $options:0 pantaskState TIMEOUT
  end
 end
 
-# select images ready for copy 
-# new entries are added to detPendingCorrectedExp
-# compare the new list with the ones already selected
-task	       detrend.correctexp.load
-  host         local
-
-  periods      -poll $LOADPOLL
-  periods      -exec $LOADEXEC
-  periods      -timeout 30
-  npending     1
-
-  stdout NULL
-  stderr $LOGDIR/detcorr.exp.load.log
-
-  task.exec
-    $run = dettool -tocorrectedexp
-    if ($DB:n == 0)
-      option DEFAULT
-    else
-      # save the DB name for the exit tasks
-      option $DB:$detPendingCorrectedExp_DB
-      $run = $run -dbname $DB:$detPendingCorrectedExp_DB
-      $detPendingCorrectedExp_DB ++
-      if ($detPendingCorrectedExp_DB >= $DB:n) set detPendingCorrectedExp_DB = 0
-    end
-    add_poll_args run
-    command $run
-  end
-
-  # success
-  task.exit    0
-    # convert 'stdout' to book format
-    ipptool2book stdout detPendingCorrectedExp -key det_id:exp_id -uniq -setword dbname $options:0 -setword pantaskState INIT
-    if ($VERBOSE > 2)
-      book listbook detPendingCorrectedExp
-    end
-
-    # delete existing entries in the appropriate pantaskStates
-    process_cleanup detPendingCorrectedExp
-  end
-
-  # error
-  task.exit    default
-    showcommand failure
-  end
-
-  # operation times out?
-  task.exit    timeout
-    showcommand timeout
-  end
-end
-
-# copy new images, sending job to desired host
-task	       detrend.correctexp.run
-  periods      -poll $RUNPOLL
-  periods      -exec $RUNEXEC
-  periods      -timeout 30
-
-  task.exec
-    book npages detPendingCorrectedExp -var N
-    if ($N == 0) break
-    if ($NETWORK == 0) break
-    
-    # look for new exposures in detPendingCorrectedExp
-    book getpage detPendingCorrectedExp 0 -var pageName -key pantaskState INIT
-    if ("$pageName" == "NULL") break
-
-    book setword detPendingCorrectedExp $pageName pantaskState RUN
-    book getword detPendingCorrectedExp $pageName det_id    -var DET_ID
-    book getword detPendingCorrectedExp $pageName exp_id    -var EXP_ID
-    book getword detPendingCorrectedExp $pageName det_type  -var DET_TYPE
-    book getword detPendingCorrectedExp $pageName camera    -var CAMERA  
-    book getword detPendingCorrectedExp $pageName exp_tag   -var EXP_TAG
-    book getword detPendingCorrectedExp $pageName corr_id   -var CORR_ID
-    book getword detPendingCorrectedExp $pageName corr_type -var CORR_TYPE
-    book getword detPendingCorrectedExp $pageName workdir   -var WORKDIR_TEMPLATE
-    book getword detPendingCorrectedExp $pageName dbname    -var DBNAME
-
-    # specify choice of local or remote host based on camera and chip (class_id)
-    set.host.for.camera $camera FPA
-
-    # set workdir (interpolate host; see camera.pro for examples)
-    set.workdir.by.camera $CAMERA FPA $WORKDIR_TEMPLATE $default_host WORKDIR
-
-    ## generate outroot specific to this exposure (& chip)
-    sprintf outroot "%s/%s.%s.%s/%s/%s.detcorr.%s" $WORKDIR $CAMERA $DET_TYPE $DET_ID $EXP_TAG $EXP_TAG $DET_ID
-
-    stdout $LOGDIR/detcorr.exp.run.log
-    stderr $LOGDIR/detcorr.exp.run.log
-
-    $run = detrend_correct_exp.pl --det_id $DET_ID --exp_id $EXP_ID --exp_tag $EXP_TAG --det_type $DET_TYPE --camera $CAMERA --corr_id $CORR_ID --corr_type $CORR_TYPE --camera $CAMERA --redirect-output --verbose
-
-    if ("$WORKDIR" != "NULL")
-      $run = $run --workdir $WORKDIR
-    end
-    add_standard_args run
-
-    # save the pageName for future reference below
-    options $pageName
-
-    # create example job options as a demonstration
-    if ($VERBOSE > 1)
-      echo command $run
-    end
-    command $run
-  end
-
-  # success
-  task.exit    default
-    process_exit detPendingCorrectedExp $options:0 $JOB_STATUS
-  end
-
-  # operation times out?
-  task.exit    timeout
-    showcommand timeout
-    book setword detPendingCorrectedExp $options:0 pantaskState TIMEOUT
-  end
-end
Index: branches/cnb_branch_20081104/ippTasks/flatcorr.pro
===================================================================
--- branches/cnb_branch_20081011/ippTasks/flatcorr.pro	(revision 20067)
+++ branches/cnb_branch_20081104/ippTasks/flatcorr.pro	(revision 20530)
@@ -17,4 +17,7 @@
 
 macro flatcorr.on
+  task flatcorr.addcamera
+    active true
+  end
   task flatcorr.load
     active true
@@ -26,4 +29,7 @@
 
 macro flatcorr.off
+  task flatcorr.addcamera
+    active false
+  end
   task flatcorr.load
     active false
@@ -66,19 +72,21 @@
 
   # check the list of pending flatcorr runs
-  periods      -poll 10
-  periods      -exec 120
+  periods      -poll $LOADPOLL
+  periods      -exec $LOADEXEC
   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
+  task.exec
+    # 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
   end
 
@@ -108,20 +116,24 @@
 
   # check the list of pending flatcorr runs
-  periods      -poll 10
-  periods      -exec 900
+  periods      -poll $LOADPOLL
+  periods      -exec $LOADEXEC
   periods      -timeout 60
   npending 1
 
   # define the command (does not depend on previous queries)
-  $run = flatcorr -pendingprocess
-  if ($DB:n != 0)
-    # save the DB name for the exit tasks
-    option $DB:$flatcorr_pendingprocess_DB
-    $run = $run -dbname $DB:$flatcorr_pendingprocess_DB
-    $flatcorr_pendingprocess_DB ++
-    if ($flatcorr_pendingprocess_DB >= $DB:n) set flatcorr_pendingprocess_DB = 0
-  end
-  add_poll_args run
-  command $run
+  task.exec
+    if ($DB:n == 0)
+      $run = flatcorr -pendingprocess
+    else 
+      $run = flatcorr -pendingprocess
+      # save the DB name for the exit tasks
+      option $DB:$flatcorr_pendingprocess_DB
+      $run = $run -dbname $DB:$flatcorr_pendingprocess_DB
+      $flatcorr_pendingprocess_DB ++
+      if ($flatcorr_pendingprocess_DB >= $DB:n) set flatcorr_pendingprocess_DB = 0
+    end
+    # add_poll_args run
+    command $run
+  end
 
   # silently drop stdout
@@ -175,10 +187,12 @@
 
     # XXX probably need to set the output / log based on WORKDIR...
-    book getword flatcorrBook $pageName corr_id     -var ID
+    book getword flatcorrBook $pageName corr_id     -var CORR_ID
+    book getword flatcorrBook $pageName det_type    -var DET_TYPE
     book getword flatcorrBook $pageName dvodb       -var DVODB
+    book getword flatcorrBook $pageName camera      -var CAMERA
     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
+    book getword flatcorrBook $pageName workdir     -var WORKDIR_TEMPLATE
 
     # specify choice of remote host
@@ -193,6 +207,12 @@
     options $pageName
 
+    # see chip.pro for examples
+    set.workdir.by.camera $CAMERA FPA $WORKDIR_TEMPLATE $default_host WORKDIR
+
+    ## generate outroot specific to this exposure (& chip)
+    sprintf outroot "%s/%s.flatcorr.%s" $WORKDIR $CAMERA $CORR_ID
+
     # XXX get these arguments right
-    $run = flatcorr_proc.pl --corr_id $ID --dvodb $DVODB --region $REGION --filter $FILTER
+    $run = flatcorr_proc.pl --corr_id $CORR_ID --det_type $DET_TYPE --dvodb $DVODB --camera $CAMERA --region $REGION --filter $FILTER --workdir $outroot
     add_standard_args run
 
Index: branches/cnb_branch_20081104/ippTasks/pantasks.pro
===================================================================
--- branches/cnb_branch_20081011/ippTasks/pantasks.pro	(revision 20067)
+++ branches/cnb_branch_20081104/ippTasks/pantasks.pro	(revision 20530)
@@ -110,4 +110,5 @@
   detresid.on
   detreject.on
+  detcorr.on
 end
 
@@ -118,4 +119,5 @@
   detresid.off
   detreject.off
+  detcorr.off
 end
 
@@ -131,4 +133,5 @@
   register.on
   detrend.on
+  flatcorr.on
   chip.on
   camera.on
@@ -142,4 +145,5 @@
   register.off
   detrend.off
+  flatcorr.off
   chip.off
   camera.off
@@ -157,4 +161,6 @@
   module detrend.resid.pro
   module detrend.reject.pro
+  module detrend.correct.pro
+  module flatcorr.pro
   module chip.pro
   module camera.pro
Index: branches/cnb_branch_20081104/ippTasks/pstamp.pro
===================================================================
--- branches/cnb_branch_20081011/ippTasks/pstamp.pro	(revision 20067)
+++ branches/cnb_branch_20081104/ippTasks/pstamp.pro	(revision 20530)
@@ -170,6 +170,10 @@
 
 
+    task.exit $EXIT_SUCCESS
+        process_exit pstampRequest $options:0 $JOB_STATUS
+    end
+
     task.exit default
-#        echo pstamp.request.run task.exit status: $JOB_STATUS
+        showcommand failure
         process_exit pstampRequest $options:0 $JOB_STATUS
     end
@@ -251,7 +255,12 @@
     end
 
+    task.exit $EXIT_SUCCESS
+        process_exit pstampFinish $options:0 $JOB_STATUS
+    end
+
     task.exit default
         # echo request.finish.run task.exit status: $JOB_STATUS
         process_exit pstampFinish $options:0 $JOB_STATUS
+        showcommand failure
     end
 
@@ -283,5 +292,4 @@
 
     task.exit $EXIT_SUCCESS
-        # echo ipptool2book stdout pstampJob -key job_id -setword dbname $options:0 -setword pantaskState INIT
         ipptool2book stdout pstampJob -key job_id -uniq -setword dbname $options:0 -setword pantaskState INIT
 
@@ -340,8 +348,15 @@
 
 
+    task.exit $EXIT_SUCCESS
+        if ($VERBOSE > 1)
+            echo pstamp.job.run task.exit $JOB_ID status: $JOB_STATUS
+        end
+        process_exit pstampJob $options:0 $JOB_STATUS
+    end
     task.exit default
         if ($VERBOSE > 1)
             echo pstamp.job.run task.exit $JOB_ID status: $JOB_STATUS
         end
+        showcommand failure
         process_exit pstampJob $options:0 $JOB_STATUS
     end
Index: branches/cnb_branch_20081104/ippTasks/register.pro
===================================================================
--- branches/cnb_branch_20081011/ippTasks/register.pro	(revision 20067)
+++ branches/cnb_branch_20081104/ippTasks/register.pro	(revision 20530)
@@ -47,4 +47,81 @@
     active false
   end
+end
+
+macro replace.survey.values
+  if ($0 != 5)
+    echo "USAGE: replace.survey.values (varname) (CAMERA) (FILTER) (DATE)"
+    break
+  end
+
+  strsub $$1 @CAMERA@ $2 -var $1
+  strsub $$1 @FILTER@ $3 -var $1
+  strsub $$1 @DATE@   $4 -var $1
+  if ($VERBOSE > 2)
+        echo "adding $$1"
+  end
+end
+
+# we want to set the following arguments to register_exp.pl
+# --label ($myLABEL) --dvodb ($myDVODB) --workdir ($myWORKDIR) 
+macro set.survey.data
+  if ($0 != 7)
+    echo "USAGE: set.survey.data (surveyID) (camera) (filter) (datestr) (workdir) (cmdflags)"
+    break
+  end
+
+  local surveyID myCAMERA myFILTER myDATE myUPDATE 
+
+  $surveyID = $1
+  $myCAMERA = $2
+  $myFILTER = $3
+  $myDATE   = $4
+
+  $$6 = ""
+
+  # we will find a more elegant solution for this later
+  if ("$myFILTER" == "z.00000") return
+  if ("$myFILTER" == "w.00000") return
+
+  $myUPDATE1 = ""
+  book getword surveys $surveyID label -var myLABEL
+  if ("$myLABEL" != "NULL") 
+    replace.survey.values myLABEL $myCAMERA $myFILTER $myDATE
+    $myUPDATE1 = --label $myLABEL
+  end
+
+  $myUPDATE2 = ""
+  book getword surveys $surveyID dvodb -var myDVODB
+  if ("$myDVODB" != "NULL") 
+    replace.survey.values myDVODB $myCAMERA $myFILTER $myDATE
+    $myUPDATE2 = --dvodb $myDVODB
+  end
+
+  $myUPDATE3 = ""
+  book getword surveys $surveyID end_stage -var myENDSTAGE
+  if ("$myENDSTAGE" != "NULL") 
+    replace.survey.values myENDSTAGE $myCAMERA $myFILTER $myDATE
+    $myUPDATE3 = --end_stage $myENDSTAGE
+  end
+
+  $myUPDATE4 = ""
+  book getword surveys $surveyID tess_id -var myTESSID
+  if ("$myTESSID" != "NULL") 
+    replace.survey.values myTESSID $myCAMERA $myFILTER $myDATE
+    $myUPDATE4 = --tess_id $myTESSID
+  end
+
+  $$6  = $myUPDATE1 $myUPDATE2 $myUPDATE3 $myUPDATE4
+
+  book getword surveys $surveyID worksubdir -var myWORKSUB
+  if ("$myWORKSUB" != "NULL") 
+    replace.survey.values myWORKSUB $myCAMERA $myFILTER $myDATE
+    $$5 = $$5/$myWORKSUB
+  end
+end
+
+macro load.surveys
+  queueload tmp -x "cat $MODULES:0/surveys.mhpcc.config"
+  ipptool2book tmp surveys -key survey
 end
 
@@ -258,18 +335,34 @@
     book getword regPendingExp $pageName workdir      -var WORKDIR_TEMPLATE
     book getword regPendingExp $pageName dbname       -var DBNAME
+    book getword regPendingExp $pageName camera       -var CAMERA
+    book getword regPendingExp $pageName filter       -var FILTER
+    book getword regPendingExp $pageName dateobs      -var DATEOBS
+    book getword regPendingExp $pageName obs_mode     -var OBS_MODE
+    book getword regPendingExp $pageName obs_group    -var OBS_GROUP
 
     # EXP_TAG is used to generate the unique, but human-readable, filenames
     sprintf EXP_TAG "%s.%s" $TMP_EXP_NAME $EXP_ID
 
+    # 2007-08-30T05:09:59Z
+    strlen $DATEOBS length
+    if ($length > 10)
+      substr $DATEOBS 0 4 YEAR
+      substr $DATEOBS 5 2 MONTH
+      $datestr = "$YEAR\$MONTH"
+    end
+
+    # look up label, dvodb based on survey
+    set.survey.data $OBS_MODE $CAMERA $FILTER $datestr WORKDIR_TEMPLATE CMDFLAGS
+
     # specify choice of remote host
-    set.host.for.camera $TMP_CAMERA $TMP_CLASS_ID 
+    set.host.for.camera $TMP_CAMERA FPA
 
     # set the WORKDIR variable
-    set.workdir.by.camera $TMP_CAMERA $TMP_CLASS_ID $WORKDIR_TEMPLATE $default_host WORKDIR
+    set.workdir.by.camera $TMP_CAMERA FPA $WORKDIR_TEMPLATE $default_host WORKDIR
 
     # notes on how this works:
     # -- raw workdir examples:
     # file://data/@HOST@.0/gpc1/20080130
-    # neb:///@HOST@-vol0/gpc1/20080130 (need to supply volname?, or are we re-defining this each time?)
+    # neb:///@HOST@.0/gpc1/20080130
     # -- out workdir examples:
     # file://data/ipp004.0/gpc1/20080130
@@ -281,5 +374,5 @@
     stderr $LOGDIR/register.exp.run.log
 
-    $run = register_exp.pl --exp_id $EXP_ID --exp_tag $EXP_TAG --logfile $logfile
+    $run = register_exp.pl --exp_id $EXP_ID --exp_tag $EXP_TAG --logfile $logfile $CMDFLAGS
     add_standard_args run
 
Index: branches/cnb_branch_20081104/ippTasks/simtest.flatcorr.auto
===================================================================
--- branches/cnb_branch_20081011/ippTasks/simtest.flatcorr.auto	(revision 20067)
+++ branches/cnb_branch_20081104/ippTasks/simtest.flatcorr.auto	(revision 20530)
@@ -13,5 +13,5 @@
   name       STR BIAS
   check      STR "regtool -processedexp -exp_type BIAS -inst @CAMERA@ -dbname @DBNAME@"
-  ncheck     S32 20
+  ncheck     S32 10
   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@"
@@ -42,10 +42,27 @@
 END
 
-# wait until the master bias frame is registered, then define a new flat-i run
+# wait until the master flat-r frame is registered, then initiate a flat-field correction analysis
 automate METADATA
-  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_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@"
+  name       STR FLATCORR-r
+  check      STR "detselect -dbname @DBNAME@ -search -inst @CAMERA@ -filter r -det_type FLAT_RAW"
+  launch     STR "flatcorr -definebyquery -dbname @DBNAME@ -det_type FLATCORR -inst @CAMERA@ -exp_type OBJECT -filter r -set_workdir file://@CWD@/detwork -set_reduction FLATCORR -set_dvodb @CWD@/catdir.flatcorr -set_region 270.6,270.9:-23.8,-23.5 -set_filter r"
+  block      STR "dettool -runs -active -det_type FLATCORR -filter r -dbname @DBNAME@"
+END
+
+# wait until the flat-r correction frame is registered, then define the flat-fields to be corrected
+# XXX for the moment, the det_id here is hard-wired
+automate METADATA
+  name       STR FLATFIX-r
+  check      STR "detselect -dbname @DBNAME@ -search -inst @CAMERA@ -filter r -det_type FLATCORR"
+  launch     STR "dettool -makecorrection -dbname @DBNAME@ -det_id 4 -iteration 0 -det_type FLAT -workdir file://@CWD@/detwork"
+  block      STR "dettool -runs -active -det_type FLAT -filter r -dbname @DBNAME@"
+END
+
+# wait until the corrected master flat-r frame is registered, then initiate a second flat-field correction analysis
+automate METADATA
+  name       STR FLATTEST-r
+  check      STR "detselect -dbname @DBNAME@ -search -inst @CAMERA@ -filter r -det_type FLAT"
+  launch     STR "flatcorr -definebyquery -dbname @DBNAME@ -det_type FLATTEST -inst @CAMERA@ -exp_type OBJECT -filter r -set_workdir file://@CWD@/detwork -set_reduction FLATTEST -set_dvodb @CWD@/catdir.flattest -set_region 270.6,270.9:-23.8,-23.5 -set_filter r"
+  block      STR "dettool -runs -active -det_type FLATCORR -filter r -dbname @DBNAME@"
 END
 
@@ -58,20 +75,2 @@
 ## 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: branches/cnb_branch_20081104/ippTasks/simtest.flatcorr.config
===================================================================
--- branches/cnb_branch_20081011/ippTasks/simtest.flatcorr.config	(revision 20067)
+++ branches/cnb_branch_20081104/ippTasks/simtest.flatcorr.config	(revision 20530)
@@ -9,5 +9,5 @@
   OBSTYPE    STR BIAS
   CAMERA     STR SIMTEST
-  NIMAGES    S32  20
+  NIMAGES    S32  10
 END
 
@@ -16,5 +16,5 @@
   CAMERA     STR SIMTEST
   @EXPTIMES  F32  30.0, 300.0
-  @NIMAGES   S32  10,   10
+  @NIMAGES   S32  5,   5
 END
 
@@ -23,8 +23,8 @@
   CAMERA     STR SIMTEST
 
-  FILTERS    STR r,r,i
-  @EXPTIMES  F32 0.1,20.0,20.0
+  FILTERS    STR r,r
+  @EXPTIMES  F32 0.1,20.0
 
-  NSETUP     S32 5
+  NSETUP     S32 3
 END
 
@@ -63,7 +63,7 @@
   # 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
+  FILTERS    STR r
+  @EXPTIMES  F32 10.00
+  @SKYMAGS   F32 20.86
 
   # modest IQ range here
@@ -100,7 +100,7 @@
   # 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
+  FILTERS    STR r
+  @EXPTIMES  F32 10.00
+  @SKYMAGS   F32 20.86
 
   # modest IQ range here
@@ -137,7 +137,7 @@
   # 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
+  FILTERS    STR r
+  @EXPTIMES  F32 10.00
+  @SKYMAGS   F32 20.86
 
   # modest IQ range here
@@ -174,7 +174,7 @@
   # 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
+  FILTERS    STR r
+  @EXPTIMES  F32 10.00
+  @SKYMAGS   F32 20.86
 
   # modest IQ range here
Index: branches/cnb_branch_20081104/ippTasks/site.mhpcc.pro
===================================================================
--- branches/cnb_branch_20081011/ippTasks/site.mhpcc.pro	(revision 20067)
+++ branches/cnb_branch_20081104/ippTasks/site.mhpcc.pro	(revision 20530)
@@ -66,4 +66,8 @@
   queueload tmp -x "cat $MODULES:0/ipphosts.mhpcc.config"
   ipptool2book tmp ipphosts -key camera
+
+  # set autoprocessing for chip
+  queueload tmp -x "cat $MODULES:0/surveys.mhpcc.config"
+  ipptool2book tmp surveys -key survey
 end
 
Index: branches/cnb_branch_20081104/ippTasks/summit.copy.pro
===================================================================
--- branches/cnb_branch_20081011/ippTasks/summit.copy.pro	(revision 20067)
+++ branches/cnb_branch_20081104/ippTasks/summit.copy.pro	(revision 20530)
@@ -87,5 +87,5 @@
 
     # timeout shorter than exec so jobs do not build up
-    periods      -exec      10
+    periods      -exec       1
     periods      -poll       1
     periods      -timeout   20
@@ -105,4 +105,5 @@
         if ($pztoolDatastore_DB >= $DB:n) set pztoolDatastore_DB = 0
       end
+      periods -exec 120
     end
 
@@ -129,5 +130,5 @@
 # and inserting these into a db table on the local cluster (pzPendingExp)
 task pzgetexp
-  periods      -exec     60
+  periods      -exec     30
   periods      -poll     1
   periods      -timeout  700
Index: branches/cnb_branch_20081104/ippTasks/surveys.mhpcc.config
===================================================================
--- branches/cnb_branch_20081104/ippTasks/surveys.mhpcc.config	(revision 20530)
+++ branches/cnb_branch_20081104/ippTasks/surveys.mhpcc.config	(revision 20530)
@@ -0,0 +1,58 @@
+# Note from Ken Chambers on the OBS_MODE keyword:
+# OBS_MODE - Official Keyword - string use for Survey ID, 3PI, MD, SS, STS, M31, CAL, AF1, AF2, AF3, ENG, NA - from scheduler
+
+surveys MULTI
+
+surveys METADATA
+  survey     STR 3PI
+  label      STR ThreePi.@CAMERA@.@FILTER@.@DATE@
+  dvodb      STR /data/ipp004.0/gpc1/catdir.ThreePi
+  worksubdir STR ThreePi
+  end_stage  STR warp
+  tess_id    STR ALLSKY
+END
+
+surveys METADATA
+  survey     STR MD
+  label      STR MediumDeep.@CAMERA@.@FILTER@.@DATE@
+  dvodb      STR /data/ipp004.0/gpc1/MediumDeep
+  worksubdir STR MediumDeep
+  end_stage  STR warp
+  tess_id    STR ALLSKY
+END
+
+surveys METADATA
+  survey     STR SS
+  label      STR SolarSystem.@CAMERA@.@FILTER@.@DATE@
+  dvodb      STR /data/ipp004.0/gpc1/SolarSystem
+  worksubdir STR SolarSystem
+  end_stage  STR warp
+  tess_id    STR ALLSKY
+END
+
+surveys METADATA
+  survey     STR STS
+  label      STR STS.@CAMERA@.@FILTER@.@DATE@
+  dvodb      STR /data/ipp004.0/gpc1/STS
+  worksubdir STR STS
+  end_stage  STR warp
+  tess_id    STR ALLSKY
+END
+
+surveys METADATA
+  survey     STR M31
+  label      STR M31.@CAMERA@.@FILTER@.@DATE@
+  dvodb      STR /data/ipp004.0/gpc1/M31
+  worksubdir STR M31
+  end_stage  STR warp
+  tess_id    STR ALLSKY
+END
+
+surveys METADATA
+  survey     STR CAL
+  label      STR CalFields.@CAMERA@.@FILTER@.@DATE@
+  dvodb      STR /data/ipp004.0/gpc1/CalFields
+  worksubdir STR CalFields
+  end_stage  STR warp
+  tess_id    STR ALLSKY
+END
