NAME:
  skyfit
 PURPOSE:   (one line only)
  Determine a 2-d polynomial fit to sky background in an image.
 DESCRIPTION:
 CATEGORY:
  CCD data processing
 CALLING SEQUENCE:
  skyfit,image,skyimage
 INPUTS:
  image - Array which is the image to be analyzed
 OPTIONAL INPUT PARAMETERS:
 KEYWORD INPUT PARAMETERS:
  DISPLAY - Flag, if set will generate lots of plotting output.
  MASK    - Optional mask image, if set, the pixel in the input image should
              not be used.
  XORDER  - order of fit to X direction (default=0, constant)
  YORDER  - order of fit to Y direction (default=0, constant)
  LOWCLIP - fraction of random sample to clip at the low end of the signal.
              If lowclip=.1 and npts=100, then the 10 lowest values in the
              random sample are excluded BEFORE the robust mean is computed
              for the stretch range.  This option will probably be just a bit
              slower if invoked.  This option will likely be more robust
              against extreme values in the image.  Default=0.0 (no clipping)
  HICLIP  - fraction of random sample to clip at the high end of the signal.
              If hiclip=.9 and npts=100, then the 10 highest values in the
              random sample are excluded BEFORE the robust mean is computed
              for the stretch range.  This option will probably be just a bit
              slower if invoked.  This option will likely be more robust
              against extreme values in the image.  Default=1.0 (no clipping)
  NPTS   - Number of pixels to use in fit (default=601)
  SILENT - Flag, if set will suppress information output to screen.
 OUTPUTS:
  skyimage - Smooth image of sky in image.
 KEYWORD OUTPUT PARAMETERS:
  COEFF   - Coefficients of fit
  ERROR   - Flag, set if there was a failure in the fitting process
  SKYSIG  - Estimate of the sky noise, same units as input image
 COMMON BLOCKS:
 SIDE EFFECTS:
 RESTRICTIONS:
 PROCEDURE:
 MODIFICATION HISTORY:
  Written by Marc W. Buie, Lowell Observatory, 2004/07/02
  2005/06/22, MWB, Added error traps
  2016/04/01, MWB, added (better) plot titles
  2016/04/12, MWB, added MASK keyword