      FUNCTION DISTXY(X,Y,DX,DY,R,X0,Y0,XP,YP,PHIP)
      DATA PIVALU/3.141593/
      ALEN=SQRT(DX**2+DY**2)
      SINOM=DY/ALEN
      COSOM=DX/ALEN
      G=(X0-X)**2+(Y0-Y)**2+2.*R*((Y0-Y)*COSOM-(X0-X)*SINOM)
      DISTXY=SQTVAL(ABS(R),G,1.,1.E-4)
      IF(
     - R.GT.0.
     -)THEN
         SGNR=1.
      ELSE
         SGNR=-1.
      ENDIF
      A1=DISTXY/ABS(R)
      A2=1./(1.+A1)
      XP=A2*(X0+X*A1+SINOM*SGNR*DISTXY)
      YP=A2*(Y0+Y*A1-COSOM*SGNR*DISTXY)
      SINOMP=A2*((X-X0)/R+SINOM)
      COSOMP=A2*((Y0-Y)/R+COSOM)
      IF(COSOMP.GT.1.) COSOMP=1.
      IF(COSOMP.LT.-1.) COSOMP=-1.
      PHIP=ACOS(COSOMP)
      IF(SINOMP.LT.0.) PHIP=2.*PIVALU-PHIP
      RETURN
      END
