1 SUBROUTINE ZUNK2
(ZR
, ZI
, FNU
, KODE
, MR
, N
, YR
, YI
, NZ
, TOL
, ELIM
,
3 C***BEGIN PROLOGUE ZUNK2
6 C ZUNK2 COMPUTES K(FNU,Z) AND ITS ANALYTIC CONTINUATION FROM THE
7 C RIGHT HALF PLANE TO THE LEFT HALF PLANE BY MEANS OF THE
8 C UNIFORM ASYMPTOTIC EXPANSIONS FOR H(KIND,FNU,ZN) AND J(FNU,ZN)
9 C WHERE ZN IS IN THE RIGHT HALF PLANE, KIND=(3-MR)/2, MR=+1 OR
10 C -1. HERE ZN=ZR*I OR -ZR*I WHERE ZR=Z IF Z IS IN THE RIGHT
11 C HALF PLANE OR ZR=-Z IF Z IS IN THE LEFT HALF PLANE. MR INDIC-
12 C ATES THE DIRECTION OF ROTATION FOR ANALYTIC CONTINUATION.
13 C NZ=-1 MEANS AN OVERFLOW WILL OCCUR
15 C***ROUTINES CALLED ZAIRY,ZKSCL,ZS1S2,ZUCHK,ZUNHJ,D1MACH,AZABS
16 C***END PROLOGUE ZUNK2
17 C COMPLEX AI,ARG,ARGD,ASUM,ASUMD,BSUM,BSUMD,CFN,CI,CIP,CK,CONE,CRSC,
18 C *CR1,CR2,CS,CSCL,CSGN,CSPN,CSR,CSS,CY,CZERO,C1,C2,DAI,PHI,PHID,RZ,
19 C *S1,S2,Y,Z,ZB,ZETA1,ZETA1D,ZETA2,ZETA2D,ZN,ZR
20 DOUBLE PRECISION AARG
, AIC
, AII
, AIR
, ALIM
, ANG
, APHI
, ARGDI
,
21 * ARGDR
, ARGI
, ARGR
, ASC
, ASCLE
, ASUMDI
, ASUMDR
, ASUMI
, ASUMR
,
22 * BRY
, BSUMDI
, BSUMDR
, BSUMI
, BSUMR
, CAR
, CIPI
, CIPR
, CKI
, CKR
,
23 * CONER
, CRSC
, CR1I
, CR1R
, CR2I
, CR2R
, CSCL
, CSGNI
, CSI
,
24 * CSPNI
, CSPNR
, CSR
, CSRR
, CSSR
, CYI
, CYR
, C1I
, C1R
, C2I
, C2M
,
25 * C2R
, DAII
, DAIR
, ELIM
, FMR
, FN
, FNF
, FNU
, HPI
, PHIDI
, PHIDR
,
26 * PHII
, PHIR
, PI
, PTI
, PTR
, RAST
, RAZR
, RS1
, RZI
, RZR
, SAR
, SGN
,
27 * STI
, STR
, S1I
, S1R
, S2I
, S2R
, TOL
, YI
, YR
, YY
, ZBI
, ZBR
, ZEROI
,
28 * ZEROR
, ZETA1I
, ZETA1R
, ZETA2I
, ZETA2R
, ZET1DI
, ZET1DR
, ZET2DI
,
29 * ZET2DR
, ZI
, ZNI
, ZNR
, ZR
, ZRI
, ZRR
, D1MACH
, AZABS
30 INTEGER I
, IB
, IFLAG
, IFN
, IL
, IN
, INU
, IUF
, K
, KDFLG
, KFLAG
, KK
,
31 * KODE
, MR
, N
, NAI
, NDAI
, NW
, NZ
, IDUM
, J
, IPARD
, IC
32 DIMENSION BRY
(3), YR
(N
), YI
(N
), ASUMR
(2), ASUMI
(2), BSUMR
(2),
33 * BSUMI
(2), PHIR
(2), PHII
(2), ARGR
(2), ARGI
(2), ZETA1R
(2),
34 * ZETA1I
(2), ZETA2R
(2), ZETA2I
(2), CYR
(2), CYI
(2), CIPR
(4),
35 * CIPI
(4), CSSR
(3), CSRR
(3)
36 DATA ZEROR
,ZEROI
,CONER
,CR1R
,CR1I
,CR2R
,CR2I
/
37 1 0.0D0
, 0.0D0
, 1.0D0
,
38 1 1.0D0
,1.73205080756887729D0
, -0.5D0
,-8.66025403784438647D
-01 /
40 1 1.57079632679489662D
+00, 3.14159265358979324D
+00,
41 1 1.26551212348464539D
+00/
42 DATA CIPR
(1),CIPI
(1),CIPR
(2),CIPI
(2),CIPR
(3),CIPI
(3),CIPR
(4),
44 1 1.0D0
,0.0D0
, 0.0D0
,-1.0D0
, -1.0D0
,0.0D0
, 0.0D0
,1.0D0
/
48 C-----------------------------------------------------------------------
49 C EXP(-ALIM)=EXP(-ELIM)/TOL=APPROX. ONE PRECISION GREATER THAN
51 C-----------------------------------------------------------------------
60 BRY
(1) = 1.0D
+3*D1MACH
(1)/TOL
65 IF (ZR
.GE
.0.0D0
) GO TO 10
75 FNF
= FNU
- DBLE
(FLOAT
(INU
))
82 STR
= C2R*CIPR
(KK
) - C2I*CIPI
(KK
)
83 STI
= C2R*CIPI
(KK
) + C2I*CIPR
(KK
)
84 CSR
= CR1R*STR
- CR1I*STI
85 CSI
= CR1R*STI
+ CR1I*STR
86 IF (YY
.GT
.0.0D0
) GO TO 20
90 C-----------------------------------------------------------------------
91 C K(FNU,Z) IS COMPUTED FROM H(2,FNU,-I*Z) WHERE Z IS IN THE FIRST
92 C QUADRANT. FOURTH QUADRANT VALUES (YY.LE.0.0E0) ARE COMPUTED BY
93 C CONJUGATION SINCE THE K FUNCTION IS REAL ON THE POSITIVE REAL AXIS
94 C-----------------------------------------------------------------------
97 C-----------------------------------------------------------------------
98 C J FLIP FLOPS BETWEEN 1 AND 2 IN J = 3 - J
99 C-----------------------------------------------------------------------
101 FN
= FNU
+ DBLE
(FLOAT
(I
-1))
102 CALL ZUNHJ
(ZNR
, ZNI
, FN
, 0, TOL
, PHIR
(J
), PHII
(J
), ARGR
(J
),
103 * ARGI
(J
), ZETA1R
(J
), ZETA1I
(J
), ZETA2R
(J
), ZETA2I
(J
), ASUMR
(J
),
104 * ASUMI
(J
), BSUMR
(J
), BSUMI
(J
))
105 IF (KODE
.EQ
.1) GO TO 30
106 STR
= ZBR
+ ZETA2R
(J
)
107 STI
= ZBI
+ ZETA2I
(J
)
108 RAST
= FN
/AZABS
(STR
,STI
)
111 S1R
= ZETA1R
(J
) - STR
112 S1I
= ZETA1I
(J
) - STI
115 S1R
= ZETA1R
(J
) - ZETA2R
(J
)
116 S1I
= ZETA1I
(J
) - ZETA2I
(J
)
118 C-----------------------------------------------------------------------
119 C TEST FOR UNDERFLOW AND OVERFLOW
120 C-----------------------------------------------------------------------
122 IF (DABS
(RS1
).GT
.ELIM
) GO TO 70
123 IF (KDFLG
.EQ
.1) KFLAG
= 2
124 IF (DABS
(RS1
).LT
.ALIM
) GO TO 50
125 C-----------------------------------------------------------------------
126 C REFINE TEST AND SCALE
127 C-----------------------------------------------------------------------
128 APHI
= AZABS
(PHIR
(J
),PHII
(J
))
129 AARG
= AZABS
(ARGR
(J
),ARGI
(J
))
130 RS1
= RS1
+ DLOG
(APHI
) - 0.25D0*DLOG
(AARG
) - AIC
131 IF (DABS
(RS1
).GT
.ELIM
) GO TO 70
132 IF (KDFLG
.EQ
.1) KFLAG
= 1
133 IF (RS1
.LT
.0.0D0
) GO TO 50
134 IF (KDFLG
.EQ
.1) KFLAG
= 3
136 C-----------------------------------------------------------------------
137 C SCALE S1 TO KEEP INTERMEDIATE ARITHMETIC ON SCALE NEAR
139 C-----------------------------------------------------------------------
140 C2R
= ARGR
(J
)*CR2R
- ARGI
(J
)*CR2I
141 C2I
= ARGR
(J
)*CR2I
+ ARGI
(J
)*CR2R
142 CALL ZAIRY
(C2R
, C2I
, 0, 2, AIR
, AII
, NAI
, IDUM
)
143 CALL ZAIRY
(C2R
, C2I
, 1, 2, DAIR
, DAII
, NDAI
, IDUM
)
144 STR
= DAIR*BSUMR
(J
) - DAII*BSUMI
(J
)
145 STI
= DAIR*BSUMI
(J
) + DAII*BSUMR
(J
)
146 PTR
= STR*CR2R
- STI*CR2I
147 PTI
= STR*CR2I
+ STI*CR2R
148 STR
= PTR
+ (AIR*ASUMR
(J
)-AII*ASUMI
(J
))
149 STI
= PTI
+ (AIR*ASUMI
(J
)+AII*ASUMR
(J
))
150 PTR
= STR*PHIR
(J
) - STI*PHII
(J
)
151 PTI
= STR*PHII
(J
) + STI*PHIR
(J
)
152 S2R
= PTR*CSR
- PTI*CSI
153 S2I
= PTR*CSI
+ PTI*CSR
154 STR
= DEXP
(S1R
)*CSSR
(KFLAG
)
157 STR
= S2R*S1R
- S2I*S1I
158 S2I
= S1R*S2I
+ S2R*S1I
160 IF (KFLAG
.NE
.1) GO TO 60
161 CALL ZUCHK
(S2R
, S2I
, NW
, BRY
(1), TOL
)
162 IF (NW
.NE
.0) GO TO 70
164 IF (YY
.LE
.0.0D0
) S2I
= -S2I
167 YR
(I
) = S2R*CSRR
(KFLAG
)
168 YI
(I
) = S2I*CSRR
(KFLAG
)
172 IF (KDFLG
.EQ
.2) GO TO 85
176 IF (RS1
.GT
.0.0D0
) GO TO 320
177 C-----------------------------------------------------------------------
178 C FOR ZR.LT.0.0, THE I FUNCTION TO BE ADDED WILL OVERFLOW
179 C-----------------------------------------------------------------------
180 IF (ZR
.LT
.0.0D0
) GO TO 320
189 IF ((YR
(I
-1).EQ
.ZEROR
).AND
.(YI
(I
-1).EQ
.ZEROI
)) GO TO 80
196 RAZR
= 1.0D0
/AZABS
(ZRR
,ZRI
)
204 IF (N
.LT
.IB
) GO TO 180
205 C-----------------------------------------------------------------------
206 C TEST LAST MEMBER FOR UNDERFLOW AND OVERFLOW. SET SEQUENCE TO ZERO
208 C-----------------------------------------------------------------------
209 FN
= FNU
+ DBLE
(FLOAT
(N
-1))
211 IF (MR
.NE
.0) IPARD
= 0
212 CALL ZUNHJ
(ZNR
, ZNI
, FN
, IPARD
, TOL
, PHIDR
, PHIDI
, ARGDR
, ARGDI
,
213 * ZET1DR
, ZET1DI
, ZET2DR
, ZET2DI
, ASUMDR
, ASUMDI
, BSUMDR
, BSUMDI
)
214 IF (KODE
.EQ
.1) GO TO 90
217 RAST
= FN
/AZABS
(STR
,STI
)
224 S1R
= ZET1DR
- ZET2DR
225 S1I
= ZET1DI
- ZET2DI
228 IF (DABS
(RS1
).GT
.ELIM
) GO TO 105
229 IF (DABS
(RS1
).LT
.ALIM
) GO TO 120
230 C----------------------------------------------------------------------------
231 C REFINE ESTIMATE AND TEST
232 C-------------------------------------------------------------------------
233 APHI
= AZABS
(PHIDR
,PHIDI
)
235 IF (DABS
(RS1
).LT
.ELIM
) GO TO 120
237 IF (RS1
.GT
.0.0D0
) GO TO 320
238 C-----------------------------------------------------------------------
239 C FOR ZR.LT.0.0, THE I FUNCTION TO BE ADDED WILL OVERFLOW
240 C-----------------------------------------------------------------------
241 IF (ZR
.LT
.0.0D0
) GO TO 320
258 S2R
= CKR*C2R
- CKI*C2I
+ S1R
259 S2I
= CKR*C2I
+ CKI*C2R
+ S1I
268 IF (KFLAG
.GE
.3) GO TO 130
272 IF (C2M
.LE
.ASCLE
) GO TO 130
279 S1R
= S1R*CSSR
(KFLAG
)
280 S1I
= S1I*CSSR
(KFLAG
)
281 S2R
= S2R*CSSR
(KFLAG
)
282 S2I
= S2I*CSSR
(KFLAG
)
287 C-----------------------------------------------------------------------
288 C ANALYTIC CONTINUATION FOR RE(Z).LT.0.0D0
289 C-----------------------------------------------------------------------
291 FMR
= DBLE
(FLOAT
(MR
))
293 C-----------------------------------------------------------------------
294 C CSPN AND CSGN ARE COEFF OF K AND I FUNCTIONS RESP.
295 C-----------------------------------------------------------------------
297 IF (YY
.LE
.0.0D0
) CSGNI
= -CSGNI
302 IF (MOD
(IFN
,2).EQ
.0) GO TO 190
306 C-----------------------------------------------------------------------
307 C CS=COEFF OF THE J FUNCTION TO GET THE I FUNCTION. I(FNU,Z) IS
308 C COMPUTED FROM EXP(I*FNU*HPI)*J(FNU,-I*Z) WHERE Z IS IN THE FIRST
309 C QUADRANT. FOURTH QUADRANT VALUES (YY.LE.0.0E0) ARE COMPUTED BY
310 C CONJUGATION SINCE THE I FUNCTION IS REAL ON THE POSITIVE REAL AXIS
311 C-----------------------------------------------------------------------
317 STR
= CSR*C2R
+ CSI*C2I
318 CSI
= -CSR*C2I
+ CSI*C2R
327 FN
= FNU
+ DBLE
(FLOAT
(KK
-1))
328 C-----------------------------------------------------------------------
329 C LOGIC TO SORT OUT CASES WHOSE PARAMETERS WERE SET FOR THE K
331 C-----------------------------------------------------------------------
332 IF (N
.GT
.2) GO TO 175
349 IF ((KK
.EQ
.N
).AND
.(IB
.LT
.N
)) GO TO 210
350 IF ((KK
.EQ
.IB
).OR
.(KK
.EQ
.IC
)) GO TO 172
351 CALL ZUNHJ
(ZNR
, ZNI
, FN
, 0, TOL
, PHIDR
, PHIDI
, ARGDR
,
352 * ARGDI
, ZET1DR
, ZET1DI
, ZET2DR
, ZET2DI
, ASUMDR
,
353 * ASUMDI
, BSUMDR
, BSUMDI
)
355 IF (KODE
.EQ
.1) GO TO 220
358 RAST
= FN
/AZABS
(STR
,STI
)
365 S1R
= -ZET1DR
+ ZET2DR
366 S1I
= -ZET1DI
+ ZET2DI
368 C-----------------------------------------------------------------------
369 C TEST FOR UNDERFLOW AND OVERFLOW
370 C-----------------------------------------------------------------------
372 IF (DABS
(RS1
).GT
.ELIM
) GO TO 280
373 IF (KDFLG
.EQ
.1) IFLAG
= 2
374 IF (DABS
(RS1
).LT
.ALIM
) GO TO 240
375 C-----------------------------------------------------------------------
376 C REFINE TEST AND SCALE
377 C-----------------------------------------------------------------------
378 APHI
= AZABS
(PHIDR
,PHIDI
)
379 AARG
= AZABS
(ARGDR
,ARGDI
)
380 RS1
= RS1
+ DLOG
(APHI
) - 0.25D0*DLOG
(AARG
) - AIC
381 IF (DABS
(RS1
).GT
.ELIM
) GO TO 280
382 IF (KDFLG
.EQ
.1) IFLAG
= 1
383 IF (RS1
.LT
.0.0D0
) GO TO 240
384 IF (KDFLG
.EQ
.1) IFLAG
= 3
386 CALL ZAIRY
(ARGDR
, ARGDI
, 0, 2, AIR
, AII
, NAI
, IDUM
)
387 CALL ZAIRY
(ARGDR
, ARGDI
, 1, 2, DAIR
, DAII
, NDAI
, IDUM
)
388 STR
= DAIR*BSUMDR
- DAII*BSUMDI
389 STI
= DAIR*BSUMDI
+ DAII*BSUMDR
390 STR
= STR
+ (AIR*ASUMDR
-AII*ASUMDI
)
391 STI
= STI
+ (AIR*ASUMDI
+AII*ASUMDR
)
392 PTR
= STR*PHIDR
- STI*PHIDI
393 PTI
= STR*PHIDI
+ STI*PHIDR
394 S2R
= PTR*CSR
- PTI*CSI
395 S2I
= PTR*CSI
+ PTI*CSR
396 STR
= DEXP
(S1R
)*CSSR
(IFLAG
)
399 STR
= S2R*S1R
- S2I*S1I
400 S2I
= S2R*S1I
+ S2I*S1R
402 IF (IFLAG
.NE
.1) GO TO 250
403 CALL ZUCHK
(S2R
, S2I
, NW
, BRY
(1), TOL
)
404 IF (NW
.EQ
.0) GO TO 250
408 IF (YY
.LE
.0.0D0
) S2I
= -S2I
413 S2R
= S2R*CSRR
(IFLAG
)
414 S2I
= S2I*CSRR
(IFLAG
)
415 C-----------------------------------------------------------------------
416 C ADD I AND K FUNCTIONS, K SEQUENCE IN Y(I), I=1,N
417 C-----------------------------------------------------------------------
420 IF (KODE
.EQ
.1) GO TO 270
421 CALL ZS1S2
(ZRR
, ZRI
, S1R
, S1I
, S2R
, S2I
, NW
, ASC
, ALIM
, IUF
)
424 YR
(KK
) = S1R*CSPNR
- S1I*CSPNI
+ S2R
425 YI
(KK
) = S1R*CSPNI
+ S1I*CSPNR
+ S2I
432 IF (C2R
.NE
.0.0D0
.OR
. C2I
.NE
.0.0D0
) GO TO 255
436 IF (KDFLG
.EQ
.2) GO TO 295
440 IF (RS1
.GT
.0.0D0
) GO TO 320
449 C-----------------------------------------------------------------------
450 C RECUR BACKWARD FOR REMAINDER OF I SEQUENCE AND ADD IN THE
451 C K FUNCTIONS, SCALING THE I SEQUENCE DURING RECURRENCE TO KEEP
452 C INTERMEDIATE ARITHMETIC ON SCALE NEAR EXPONENT EXTREMES.
453 C-----------------------------------------------------------------------
460 FN
= DBLE
(FLOAT
(INU
+IL
))
464 S2R
= S1R
+ (FN
+FNF
)*(RZR*C2R
-RZI*C2I
)
465 S2I
= S1I
+ (FN
+FNF
)*(RZR*C2I
+RZI*C2R
)
475 IF (KODE
.EQ
.1) GO TO 300
476 CALL ZS1S2
(ZRR
, ZRI
, C1R
, C1I
, C2R
, C2I
, NW
, ASC
, ALIM
, IUF
)
479 YR
(KK
) = C1R*CSPNR
- C1I*CSPNI
+ C2R
480 YI
(KK
) = C1R*CSPNI
+ C1I*CSPNR
+ C2I
484 IF (IFLAG
.GE
.3) GO TO 310
488 IF (C2M
.LE
.ASCLE
) GO TO 310
495 S1R
= S1R*CSSR
(IFLAG
)
496 S1I
= S1I*CSSR
(IFLAG
)
497 S2R
= S2R*CSSR
(IFLAG
)
498 S2I
= S2I*CSSR
(IFLAG
)