! copyright (c) 2008 Swedish Defence Research Agency (FOI) 
! may not be copied or distributed without written permission from FOI



C	Sven Ivansson 1991



	COMPLEX*32 FUNCTION AZIMILN (Z)
C	to compute    - ln(z) / (1-z*z)   accurately, even for z close to 1
	IMPLICIT NONE
	COMPLEX*32 Z

	INTEGER N, I
	REAL*16 EPS
	COMPLEX*32 ZZ, ZD, CREL(40)

	DATA EPS /1.0Q-30/  ! desired relative accuracy (approximately), 
C	strict analysis possible with MacLaurin remainder term

	ZZ = Z
	IF ( ABS(1-ZZ) .GE. 0.1Q0 ) THEN
	  AZIMILN = -LOG(ZZ) / (1-ZZ**2)
	ELSE
C	  azimiln := 1 + z/2 + (z**2)/3 + (z**3)/4 + ...
	  ZD = 1-ZZ
	  N = 1
	  CREL(1) = ZD/2
	  DO WHILE ( ABS(CREL(N)) .GT. EPS )
	    N = N + 1
	    IF (N.GT.40) STOP '%%% azimiln, dim'
	    CREL(N) = CREL(N-1) * (N*ZD)/(N+1)     !  zd**n / (n+1)
	  END DO
	  AZIMILN = (0.0Q0,0.0Q0)
	  DO I = N, 1, -1
	    AZIMILN = AZIMILN + CREL(I)
	  END DO
	  AZIMILN = ( (1.0Q0,0.0Q0) + AZIMILN ) / (2-ZD)
	END IF

	RETURN
	END
