NAME:
    hsttargfit
 PURPOSE: (one line)
    Fit a model of a single point source target to HST WF3 data.
 DESCRIPTION:
 Using approximate (or previous fit) positions from database table plchpos,
 and model psf's from wfc3model, we fit the x,y and flux for a TNO
 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:
    hsttargfit, filestem

 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
          object- whether to update the data base with the new fit values.
  FORCE   - Flag, if set, a image 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.
  RESETPOS - If in the NOFIT mode, this will copy x,y from nav to pos and
               will also ask for new flux value.
  ONEPASS - Flag, if set just does a single fitting pass.  Watch out,
              if you do this it won't be fully converged, though it
              will be close.
  SHOWDW - If NOFIT is set, this keyword allows you to override the fitting
              dw value set for the object and let you temporarily show a
              different (usually larger) region.
  EXTRAFUNC - String with the name of an external function to call at the end
                if NOFIT is set.  This is a procedure that takes one input
                argument which will be the internal information structure
                and does something.  The default is an empty string in which
                case this option is ignored.

 OUTPUTS:

 CONFIGURATION: (optional, overrides xtrack.in)
   File: config.ini
   [global]
     subdir   - naem of sub-directory  added to base path to find data
 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_hsttargfit  :  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
  2014/07/09, MWB, added RESETPOS
  2020/06/29, MWB, generalized version
  2020/09/25, MWB, added SHOWDW keyword
  2020/10/01, MWB, added EXTRAFUNC keyword