NAME:
  astsolve
 PURPOSE:
  Solve for astrometric transformation from image to sky coordinates.
 DESCRIPTION:

 CATEGORY:
  Astrometry
 CALLING SEQUENCE:
  astsolve,x,y,xi,eta,xiterms,etaterms,renormfac,bad,cxi,ceta
 INPUTS:
  x        - Image x-coordinate  (should be "normalized" to range from -1 to 1)
  y        - Image y-coordinate  (should be "normalized" to range from -1 to 1)
  xi       - Standard tanget plane coordinate (should be in arcsec)
  eta      - Standard tanget plane coordinate (should be in arcsec)
  xiterms  - Which fitting terms to use (see ASTTERMS.PRO)
  etaterms - Which fitting terms to use (see ASTTERMS.PRO)
  renormfac - Re-normalization factor for converting from normalized x,y to
                the original x,y values.
  bad      - array of flags that mark bad data on input (modified).

 OPTIONAL INPUT PARAMETERS:

 KEYWORD INPUT PARAMETERS:
  EDIT - Flag, if set allows interactive bad point editing.
  XFLIP - Flag, if set flips x axis plot when editing bad points.
  YFLIP - Flag, if set flips y axis plot when editing bad points.

 OUTPUTS:
  cxi  - coefficients of xi fit.
  ceta - coefficients of eta fit.
  bad  - array of flags that mark bad data on output.

 KEYWORD OUTPUT PARAMETERS:
  WORSTRESID - Worst residual in "good" data in either axis (arcsec)
  XISCAT     - Scatter of xi fit (arcsec).
  ETASCAT    - Scatter of eta fit (arcsec).

 COMMON BLOCKS:

 SIDE EFFECTS:

 RESTRICTIONS:

 PROCEDURE:

 MODIFICATION HISTORY:
  98/03/13, Written by Marc W. Buie, Lowell Observatory
  98/11/23, MWB, added renormfac and fixed documentation
  2000/09/14, MWB, added WORSTRESID keyword
  2001/08/27, MWB, changed to auto-scale errors with /edit
  2003/06/24, MWB, changed call to MARKDATA to use new features.
  2003/10/27, MWB, fixed subtle bug during bad point cleanup.  The test
                       was done on O-C against the std deviation of a
                       robust mean.  The test needs to remove the mean of
                       the surviving sample.
  2006/02/03, MWB, added XISCAT and ETASCAT output keywords.