mkdetrend tools

dettool -define [options]
 * define a new detRun, specifying the constraints, and adding it to
 the run table.  if the detRun ID already exists, creates a new
 version.  the initial state is set to START.  the iteration is set to
 0. also creates a new master detrend frame entry
 (detID.version.iteration define this frame uniquely).
 
options : 
  -ID ID : a free-form string; if not specified, a unique string is constructed
  -type type : bias dark (mask?) flat fringe (other?)
  -camera camera 
  -filter filter
  -time start stop
  -exptime min max
  -airmass min max
  -expgroup groupID

  (-type and -camera are mandatory)
  (-filter is mandatory for 'light' types)
  (-exptime is mandatory for dark)

dettool -getinput
 * select the input matching a given detRun.  selects the input
 exposures and the input files.
 - this function could be merged with -define
 - an alternate implementation would define a detRun ID for a given
 stack of input exposures

dettool -select raw [-state state] [-outmode mode]
 * select the unprocessed input infiles
 - output of this program is used by pantasks to schedule the ppImage
 run on each image

dettool -select stack [-state state] [-outmode mode]
 * select the files to be stacked for a given detRun, if exposures are ready
 - output of this program is used by ppMerge to build a master stack

dettool -select rawresid [-state state]
 * select the residual imfiles to be generated
 - output of this program is used for another ppImage run 

dettool -update raw
 * select the raw input exposures, count processed imfiles, update if done

dettool -update resid
 * select the resid exposures, count processed resid imfiles, update if done
 - for a given resid exposure, compile the results from the stacks for
 each chip and renormalize the output files as needed.

dettool -select norm
 * select the master detrend frames & imfiles to be normalized

dettool -resid
 * construct the resid exposures and imfiles given 

dettool -assess
 * for a given master detrend frame, compile the results from the
 residual exposures and assess the validity of the input exposures and of
 the complete stack.  if too many input images are rejected, the
 affect the master detrend frame state.  if input images are rejected
 and a new set of master stacks should be made, create a new master
 detrend image, incrementing the iteration by one.

** NOTE the sequence is: 

   process, stack, merge, residual, assess
              ^--------------------------<

   IF we have no relevant detrend image for comparison.  otherwise,
   the sequence should skip from process to residual on the first
   pass, with a lower rejection threshold for the first assess pass.
   the tools above allow either option; it is the choice of state
   after process that determines which happens next.



States:
 input detrend exposures:
  RAW
  PROCESSED

 input detrend imfiles:
  RAW
  PROCESSED
  
 master detrend frames
  RAW
  NORMALIZED
  MKRESID
  SUCCESS
  FAILURE
  RETRY
  (also has NEW/PRIOR flag)

 master detrend imfiles
  NEW (not yet created)
  RAW (created, but not normalized)
  NORMALIZED

 resid exposure
  RAW
  PROCESSED
  ASSESSED

 resid imfiles:
  RAW
  PROCESSED

 master detrend run:
  NEW
  DONE
