NAME:
   hststarfit
 PURPOSE: (one line)
   Fit a model to single source in HST WFC3 data.
 DESCRIPTION:
 Using approximate (or previous fit) positions from database table stars,
 and model psf's from wfc3model, we fit the x,y and flux for a source
 using POWELL. Results are saved in the pos data table.  If the position isn't
 in pos, the starting locations are pulled from nav.
 CATEGORY:
   Astrometry
 CALLING SEQUENCE:
   hststarfit, visitid, pattstep

 INPUTS:
  filestem - String that is used to select a set of file for processing.
             The search string for files will be
               filestem+'*.flc.fits.gz'
 OPTIONAL INPUT PARAMETERS:

 KEYWORD PARAMETERS:
  ASK   - Flag, if set, user will be prompted after each fit- once per
          rootname- whether to update the data base with the new fit values.
  FORCE   - Flag, if set, a rootname that has already been fit will be fit
              again. If the 'info' field in the pos table is 'auto', it is
              assumed the fit was done.
  FTOL  - tolerance value passed to POWELL, by default .0001
  MAXTODO - How many images to process, default=0 which means all of them.
  NOFIT - Flag, if set, will suppress the fitting call and just calculate
            the model based on what is known and print out the chisq.
 OUTPUTS:
   Everything is saved to the database
 CONFIGURATION: (optional, overrides xtrack.in)
   File: config.ini
   [global]
     subdir   - naem of sub-directory  added to base path to find data
     hstpsf   - directory for psf cache
     satur    - Saturation signal level, default=80000L
 objectid
   [ddir]   - section to list potential root directories to find data
     XXX - 
       XXX is a unique string (eg., D01)
        is a directory path
       for additional details see getddir.pro
 COMMON BLOCKS:
    com_fithstpsf  :  Used for communication of data between this routine and
                    the chi-square function used for the Powell
                    fit..
 SIDE EFFECTS:
 Uses HST PSF images which may cause the memory and disk PSF caches to be
 populated. Modifies entries in hst1i data base table pos. These entries
 reflect the most recent values obtained from the fit,

 RESTRICTIONS:
 Requires hst1i database table header and plchpos.
 nav must be populated

 Currently can fit for the following parameters:
 x, y, flux

 The sky background is measured with robomean local to the object.

 PROCEDURE:

 MODIFICATION HISTORY:
  2011/03/24, Written by Marc W. Buie, Southwest Research Institute, cloned
                 from autofit.pro in the hst15 reduction directory.
  2011/05/07, Added NOFIT keyword, restructuring for changes to chimodplch
  2011/09/15, MWB, added mask support
  2012/07/06, MWB, added ONEPASS keyword
  2014/07/04, MWB, cloned from pcfit.pro from hst20
  2015/11/24, MWB, changed to save full precision WCS position to database
  2016/07/15, MWB, added PROPID keyword
  2017/01/03, MWB, heavily restructured to pull init out into init_star.pro
  2020/06/23, MWB, generalized version