      SUBROUTINE BENDXY(X,Y)
*+
*  - - - - - - -
*   B E N D X Y
*  - - - - - - -
*
*  Adjust SuperCosmos measurements to allow for Schmidt distortion.
*
*  Given and returned:
*     X,Y    d    SuperCosmos coordinates, mm, plate centre (177.5,177.5)
*
*  Patrick Wallace   Starlink   1 July 1998
*-
      IMPLICIT NONE

      DOUBLE PRECISION X,Y

*  Nominal plate centre
      DOUBLE PRECISION X0,Y0
      PARAMETER (X0=177.5D0,Y0=X0)

*  Nominal plate half-width in mm
      DOUBLE PRECISION F
      PARAMETER (F=X0)

*  Coefficients of distortion
      DOUBLE PRECISION CA,CB,CC
      PARAMETER (CA=-2.16D-5,
     :           CB=-4.95D-5,
     :           CC=4.92D-5)

      DOUBLE PRECISION XN,YN,A4,R,W,DA,DR


*  Normalize (x,y) so that plate extent is +/-1 in each coordinate.
      XN=(X-X0)/F
      YN=(Y-Y0)/F
      IF (XN.NE.0D0.OR.YN.NE.0D0) THEN

*     Polar coordinates: 4*theta and r.
         A4=4D0*ATAN2(XN,YN)
         R=SQRT(XN*XN+YN*YN)

*     Overall R scaling.
         W=R*R*R*R

*     Distortion in theta and r.
         DA=CA*SIN(A4)*W
         DR=(CB*COS(A4)+CC*SIN(4D0*R))*W

*     Adjust x and y, and restore original scale and zero-points.
         X=X0+F*(XN+DA*YN+DR*XN/R)
         Y=Y0+F*(YN-DA*XN+DR*YN/R)
      END IF

      END
