NAME:
  frmdxyr
 PURPOSE:
  Given two lists of source on field, find the dx,dy,dr offset between lists.
 DESCRIPTION:

 CATEGORY:
  Astrometry
 CALLING SEQUENCE:
  frmdxyr,x1,y1,x2,y2,thetamin,thetamax,dtheta,xoff,yoff,theta,error
 INPUTS:
  x1 - X coordinate from list 1, in pixels.
  y1 - Y coordinate from list 1, in pixels.
            The first list is the one that is manipulated to get a match.
            The second list is not touched.
  x2 - X coordinate from list 2, in pixels.
  y2 - Y coordinate from list 2, in pixels.
  thetamin - Minimum angle in search range (degrees)
  thetamax - Maximum angle in search range (degrees)
  dtheta   - Angle step size (degrees).  A 0.1 degree step size is fine
               for 2048x2048 data but smaller steps sizes may be necessary
               for larger arrays.
 OPTIONAL INPUT PARAMETERS:

 KEYWORD INPUT PARAMETERS:
  FNDRAD - passthrough to frmdxdy
  NX - maximum extent in X to consider (default is max([x1,x2]))
  NY - maximum extent in Y to consider (default is max([y1,y2]))
        NOTE: if either list of  x,y are negative, they are first shifted
        so that nothing is negative.  The default will make the center of
        the union of the lists be the center of rotation.
  MAXERR - maximum error allowed in initial spread test of position.
              (default=3)
  SILENT - Flag, if set will suppress all printed output to the screen
  TOLERANCE - tolerance on the best angle (degrees).  Default=0.01 deg.
  SCALEFAC - Passed through to frmdxdy (see that routine for further
               discussion).

 OUTPUTS:
  xoff - X offset (2-1) between positions in each list.
  yoff - Y offset (2-1) between positions in each list.
  theta - Angle offset (2-1) between positions in each list (degrees).
  error - Flag, set if something went wrong in correlating the lists.
             This is just a boolean flag.  The details of the errors
             in the individual frmdxdy.  See documentation for frmdxdy.pro
             for the internal error codes that you will see on the printed
             output.
 KEYWORD OUTPUT PARAMETERS:
  FOM - Figure of merit, a number than can be used (differentially) to
           measure how good the spatial correlation is.  This number is
           approximately the fraction of objects in the shortest list that
           ended up spatially correlated.  A number close to 1 should be
           good.
  INDEX- index into list 2 for points in list1, ie, list2[index[i]] is the
         closest, or one of a group of closest points, in list 2 to the
         ith element of list 1, given the xoff, yoff determined.
  SPATIAL- spatial filtering parameters, passed transparently to FRMDXDY.
  XOUT - The shifted and rotated X position from the best match.
  YOUT - The shifted and rotated X position from the best match.

 COMMON BLOCKS:

 SIDE EFFECTS:

 RESTRICTIONS:
 It is conventional (and more optimal speedwise) for list 1 to be the shorter
 of the two lists. However success is indepenedent of the order in which lists 
 are presented.

 PROCEDURE:

 MODIFICATION HISTORY:
  2007/11/28, Written by Marc W. Buie, Lowell Observatory
  2009/07/23, MWB, modified so that x,y input arrays do not have to be
                    positive definite.
  2009/07/24, MWB, added XOUT,YOUT optional output.
  2010/02/14, MWB, merged with alternate version from Peter Collins, this
                     change brings in the INDEX and SPATIAL keywords.
  2010/07/19, MWB, cleanup of error reporting output variable
  2010/11/30, MWB, fixed busted internal check that made routine never succeed
                   maxerr keyword not being passed through to frmdxdy, fixed.
  2012/12/03, MWB, added pass-through support for SCALEFAC
  2016/04/16, MWB, added pass-through support for FNDRAD