      SUBROUTINE WATAN (XR, XI, YR, YI)
      IMPLICIT NONE
C
C     Y = ATAN(X) = (I/2)*LOG ((I+X)/(I-X))
C
      DOUBLE PRECISION XR, XI, YR, YI
C
      DOUBLE PRECISION TR, TI
C
C
      IF (XI.NE.0.0D0) GO TO 10
      YR = DATAN2 (XR, 1.0D0)
      YI = 0.0D0
      RETURN
C
10    CONTINUE
      IF (XR.NE.0.0D0 .OR. DABS (XI).NE.1.0D0) GO TO 20
      CALL ERROR (32)
      RETURN
C
20    CONTINUE
      CALL WDIV (XR, 1.0D0+XI, -XR, 1.0D0-XI, TR, TI)
      CALL WLOG (TR, TI, TR, TI)
      YR = -TI/2.0D0
      YI = TR/2.0D0
C
      RETURN
      END
