NAME:
  photiso
 PURPOSE:   (one line only)
  Compute aperture photometry and grade sources for field contamination
 DESCRIPTION:
  This program takes a list of sources on an astronomical image and the
    image and categorizes the sources into two types.  The two types are
    sources that are isolated and those that are not isolated.  Isolated
    means that a source does not have anything nearby that affects its
    brightness as measured with the aperture radius provided.  This is
    used most often with somewhat crowded fields where you want to measure
    object brightnesses of only those that can be directly measured with
    aperture photometry.
 CATEGORY:
  CCD data processing
 CALLING SEQUENCE:
  photiso,gain,image,exptime,xloc,yloc,radius,sky1,sky2,ngood,zgood
 INPUTS:
  gain       - Gain of the CCD.  Photons per count (DN).
  image      - CCD image array.
  exptime    - Exposure time for the image in seconds.
  xloc, yloc - Current location of the cursor in image coordinates.
  radius     - Current aperture radius in pixels.
  sky1       - Inner radius of the sky annulus (in pixels).
  sky2       - Outer radius of the sky annulus (in pixels).
                 If sky2<0 then sky1 is taken to be the actual sky signal
                 in DN/pixel and |sky2| is the error on the sky.
  Note: these inputs work exactly the same as for basphote.pro

 OPTIONAL INPUT PARAMETERS:
 KEYWORD INPUT PARAMETERS:
  BOXMRAD - Size of the box to look for local max in.  Default=radius.
               If boxmrad is negative, then the call to BOXM that finds the
               local max is suppressed.  In effect, basphote assumes that
               the input location is already the maximum.  You still need
               to provide a non-zero number for boxmrad so that a local
               area is defined for the fwhm calculation.
  PSCALE  - Plate scale in arc-sec per pixel (default=1.0).
  RDNOISE - Optional CCD readout noise in (e-/pixel).   Default=10 e-,
               default is also used if RDNOISE is given as a negative number.
  VERBOSE - Flag, if set will generate some diagnostic printed output and
               a bunch of histograms.

 OUTPUTS:
  ngood   - This is the number of input sources that are considered to be
               isolated.  This value can be zero and you must test for this
               possibility.
  zgood   - Vector of indicies into the input position array for those sources
               considered to be isolated.  The value of this variable is
               ill-defined if ngood=0.

 KEYWORD OUTPUT PARAMETERS:
  ERR     - Optional return of the magnitude error.
  FLERR   - Uncertainty (1 sigma) of object flux.
  FLUX    - Object flux (photons per second)
  FWHM    - FWHM of object image(s), in arcsec if PSCALE provided, otherwise
               returned in pixels
  MAG     - Optional return of the instrumental magnitude.
  XCEN    - Optional output of centroid x-position(s).
  YCEN    - Optional output of centroid y-position(s).
  SKYMEAN - Sky signal computed for each source (DN/pixel).
  SKYERR  - Uncertainty on the sky signal.

 COMMON BLOCKS:
 SIDE EFFECTS:
 RESTRICTIONS:
 PROCEDURE:
  This program uses multiple aperture sizes to measure fluxes and positions
    of all the sources.  The ensemble of these measurements is used to
    find those that are well behaved in both position as a function of
    aperture and magnitude as a function of aperture.  Everything that is
    isolated will act the same.  Robust statistics are performed on quite
    a few metrics to whittle the list down to the good ones.
 MODIFICATION HISTORY:
  2010/12/28 - Written by Marc W. Buie, Southwest Research Institute
  2012/03/08 - MWB, fixed a problem with the first cleanup cut.  It was much
                  too agressive, letting far too few sources survive to the end