NAME:
    pc2model
 PURPOSE: (one line)
    Generate synthetic PSF images for the HST WFPC2 Planetary Camera.
 DESCRIPTION:
    A generated PSF is added to the output array.  If the array is not
 defined, it is created with dimensions 800 by 800.  Successive calls
 will add objects (PSF's) to the array.
 CATEGORY:
  CCD data processing
 CALLING SEQUENCE:
    pc2model, xsrc, ysrc, inten, filter, bmvnum, back, image
 INPUTS:
 xsrc, ysrc : Position of the PSF in the output array.
    inten   : Intensity of PSF relative to TinyTim output PSF
    filter  : Filter name in the form Fxxx(W,LP,M,N).
    bmvnum  : B-V list value (TinyTim V6.2 values):
                BMVNUM    TYPE       B-V
                1           O5      -0.34
                2           O8F     -0.32
                3           O6      -0.31
                4           B1V     -0.27
                5           B3V     -0.21
                6           B6V     -0.12
                7           A0V     -0.04
                8           A5V      0.12
                9           F6V      0.37
               10           F8V      0.48
               11           G2V      0.56
               12           G5V      0.66
               13           G8V      0.75
               14           K4V      0.92
               15           K7V      1.28
               16           M1.5V    1.45
               17           M3V      1.44
    back    : Background to be added.

 KEYWORD PARAMETERS:
  DISTORT   : If set the input x,y are taken to be in an undistorted reference
              plane. They will be converted to the instrumental (distorted)
              frame before generating the psf's for the model image, which is 
              in distorted space as always.
  GRID      : Grid spacing for psf files.
  HSTPATH   : Alternate path for HST PSF's.
  JITTER    : If set contains the gaussian smearing to apply to the image.
                This is in units of 1/e half width.  If not set, no smearing
                is applied. This calculation is done in double precision
                or float according to the type of image. The values passed
                to the exp function ( e - (((x/j)^2 + y/j)^2/2)) are 
                restricted to a maximum based on the computational precision
                to avoid floating point underflow.
               
  NEW       : If set, clears the output array to zeros before building the
              PSF image(s).

  OBJRAD    : Radius of object in pixels.  If not set, assumed to be a point
              source.  If set and radius is greater than 0.5, then PSF is
              convolved with a circular function of this radius.  This models
              the object as a Lambert disk, crude but useful for barely
              resolved objects.
  PSFSIZE   : Size of requested PSF, in arcseconds (default: 5).
  SAMPFACT  : Sample factor (default: 3).
  VERBOSE   : If set, prints informational message.
  Z4        : setting for fourth (focus) Zernicke coefficient. If not set,
              the default value for the WFPC2 instrument generated by HSTPSF 
              will be used.

 OUTPUTS:
    image  : The image array into which the PSF is placed.
 COMMON BLOCKS:

 SIDE EFFECTS:

 RESTRICTIONS:

 PROCEDURE:
    The Tiny Tim programs are used, via the procedure HSTPSF, to generate
 a (usually) 2X (7.5 micron spacing) PSF at the nearest grid location to the 
 requested position. (This grid and default spacing are defined in hstpsf).
    From the interpolated maximum returned by hstpsf, shift amounts for x
 and y are computed.
    The PSF is shifted by these amounts and then compressed to a 1X
 (15 micron spacing) PSF.
    Finally, the resulting PSF is multiplied by the intensity parameter and
 added into the output array.
    Calls external procedures BADPAR, BOXM, HSTPSF, and SSHIFT2D.
 MODIFICATION HISTORY:
    Written by Peter L. Collins, Lowell Observatory, June, 2007.
      Based on p6model.pro by Doug Loucks.
    2007/6/26, PLC, add keywords GRID, PSFSIZE, Z4. Rename x,y inputs
                    to xsrc, ysrc, to avoid JITTER clobbering.
  2007/07/08, MWB, psf placement reworked (was busted from long ago).
  2007/08/08, MWB, fixed minor bug when pasting psf near top and right edge
  2007/09/05, MWB, changed to permit multiple calls on same output image.
                      Added pixel response function.
  2007/09/12, PLC, provide DISTORT flag to use undistorted input x,y
                   to generate psf's in the usual distorted (instrumental)
                   frame.
  2019/12/20, MWB, incorporated new routine, mkxyarr