Constant factors in general (off-plane) Ewald 2D-in-3D sum
[qpms.git] / amos / zs1s2.f
blob194be444db012d99ee59236934f194fa851e6773
1 SUBROUTINE ZS1S2(ZRR, ZRI, S1R, S1I, S2R, S2I, NZ, ASCLE, ALIM,
2 * IUF)
3 C***BEGIN PROLOGUE ZS1S2
4 C***REFER TO ZBESK,ZAIRY
6 C ZS1S2 TESTS FOR A POSSIBLE UNDERFLOW RESULTING FROM THE
7 C ADDITION OF THE I AND K FUNCTIONS IN THE ANALYTIC CON-
8 C TINUATION FORMULA WHERE S1=K FUNCTION AND S2=I FUNCTION.
9 C ON KODE=1 THE I AND K FUNCTIONS ARE DIFFERENT ORDERS OF
10 C MAGNITUDE, BUT FOR KODE=2 THEY CAN BE OF THE SAME ORDER
11 C OF MAGNITUDE AND THE MAXIMUM MUST BE AT LEAST ONE
12 C PRECISION ABOVE THE UNDERFLOW LIMIT.
14 C***ROUTINES CALLED AZABS,AZEXP,AZLOG
15 C***END PROLOGUE ZS1S2
16 C COMPLEX CZERO,C1,S1,S1D,S2,ZR
17 DOUBLE PRECISION AA, ALIM, ALN, ASCLE, AS1, AS2, C1I, C1R, S1DI,
18 * S1DR, S1I, S1R, S2I, S2R, ZEROI, ZEROR, ZRI, ZRR, AZABS
19 INTEGER IUF, IDUM, NZ
20 DATA ZEROR,ZEROI / 0.0D0 , 0.0D0 /
21 NZ = 0
22 AS1 = AZABS(S1R,S1I)
23 AS2 = AZABS(S2R,S2I)
24 IF (S1R.EQ.0.0D0 .AND. S1I.EQ.0.0D0) GO TO 10
25 IF (AS1.EQ.0.0D0) GO TO 10
26 ALN = -ZRR - ZRR + DLOG(AS1)
27 S1DR = S1R
28 S1DI = S1I
29 S1R = ZEROR
30 S1I = ZEROI
31 AS1 = ZEROR
32 IF (ALN.LT.(-ALIM)) GO TO 10
33 CALL AZLOG(S1DR, S1DI, C1R, C1I, IDUM)
34 C1R = C1R - ZRR - ZRR
35 C1I = C1I - ZRI - ZRI
36 CALL AZEXP(C1R, C1I, S1R, S1I)
37 AS1 = AZABS(S1R,S1I)
38 IUF = IUF + 1
39 10 CONTINUE
40 AA = DMAX1(AS1,AS2)
41 IF (AA.GT.ASCLE) RETURN
42 S1R = ZEROR
43 S1I = ZEROI
44 S2R = ZEROR
45 S2I = ZEROI
46 NZ = 1
47 IUF = 0
48 RETURN
49 END