2 SUBROUTINE ZUNK2
(ZR
, ZI
, FNU
, KODE
, MR
, N
, YR
, YI
, NZ
, TOL
, ELIM
,
4 C***BEGIN PROLOGUE ZUNK2
6 C***PURPOSE Subsidiary to ZBESK
8 C***TYPE ALL (CUNK2-A, ZUNK2-A)
9 C***AUTHOR Amos, D. E., (SNL)
12 C ZUNK2 COMPUTES K(FNU,Z) AND ITS ANALYTIC CONTINUATION FROM THE
13 C RIGHT HALF PLANE TO THE LEFT HALF PLANE BY MEANS OF THE
14 C UNIFORM ASYMPTOTIC EXPANSIONS FOR H(KIND,FNU,ZN) AND J(FNU,ZN)
15 C WHERE ZN IS IN THE RIGHT HALF PLANE, KIND=(3-MR)/2, MR=+1 OR
16 C -1. HERE ZN=ZR*I OR -ZR*I WHERE ZR=Z IF Z IS IN THE RIGHT
17 C HALF PLANE OR ZR=-Z IF Z IS IN THE LEFT HALF PLANE. MR INDIC-
18 C ATES THE DIRECTION OF ROTATION FOR ANALYTIC CONTINUATION.
19 C NZ=-1 MEANS AN OVERFLOW WILL OCCUR
22 C***ROUTINES CALLED D1MACH, ZABS, ZAIRY, ZS1S2, ZUCHK, ZUNHJ
23 C***REVISION HISTORY (YYMMDD)
25 C 910415 Prologue converted to Version 4.0 format. (BAB)
26 C***END PROLOGUE ZUNK2
27 C COMPLEX AI,ARG,ARGD,ASUM,ASUMD,BSUM,BSUMD,CFN,CI,CIP,CK,CONE,CRSC,
28 C *CR1,CR2,CS,CSCL,CSGN,CSPN,CSR,CSS,CY,CZERO,C1,C2,DAI,PHI,PHID,RZ,
29 C *S1,S2,Y,Z,ZB,ZETA1,ZETA1D,ZETA2,ZETA2D,ZN,ZR
30 DOUBLE PRECISION AARG
, AIC
, AII
, AIR
, ALIM
, ANG
, APHI
, ARGDI
,
31 * ARGDR
, ARGI
, ARGR
, ASC
, ASCLE
, ASUMDI
, ASUMDR
, ASUMI
, ASUMR
,
32 * BRY
, BSUMDI
, BSUMDR
, BSUMI
, BSUMR
, CAR
, CIPI
, CIPR
, CKI
, CKR
,
33 * CONER
, CRSC
, CR1I
, CR1R
, CR2I
, CR2R
, CSCL
, CSGNI
, CSI
,
34 * CSPNI
, CSPNR
, CSR
, CSRR
, CSSR
, CYI
, CYR
, C1I
, C1R
, C2I
, C2M
,
35 * C2R
, DAII
, DAIR
, ELIM
, FMR
, FN
, FNF
, FNU
, HPI
, PHIDI
, PHIDR
,
36 * PHII
, PHIR
, PI
, PTI
, PTR
, RAST
, RAZR
, RS1
, RZI
, RZR
, SAR
, SGN
,
37 * STI
, STR
, S1I
, S1R
, S2I
, S2R
, TOL
, YI
, YR
, YY
, ZBI
, ZBR
, ZEROI
,
38 * ZEROR
, ZETA1I
, ZETA1R
, ZETA2I
, ZETA2R
, ZET1DI
, ZET1DR
, ZET2DI
,
39 * ZET2DR
, ZI
, ZNI
, ZNR
, ZR
, ZRI
, ZRR
, D1MACH
, ZABS
40 INTEGER I
, IB
, IFLAG
, IFN
, IL
, IN
, INU
, IUF
, K
, KDFLG
, KFLAG
, KK
,
41 * KODE
, MR
, N
, NAI
, NDAI
, NW
, NZ
, IDUM
, J
, IPARD
, IC
42 DIMENSION BRY
(3), YR
(N
), YI
(N
), ASUMR
(2), ASUMI
(2), BSUMR
(2),
43 * BSUMI
(2), PHIR
(2), PHII
(2), ARGR
(2), ARGI
(2), ZETA1R
(2),
44 * ZETA1I
(2), ZETA2R
(2), ZETA2I
(2), CYR
(2), CYI
(2), CIPR
(4),
45 * CIPI
(4), CSSR
(3), CSRR
(3)
47 DATA ZEROR
,ZEROI
,CONER
,CR1R
,CR1I
,CR2R
,CR2I
/
48 1 0.0D0
, 0.0D0
, 1.0D0
,
49 1 1.0D0
,1.73205080756887729D0
, -0.5D0
,-8.66025403784438647D
-01 /
51 1 1.57079632679489662D
+00, 3.14159265358979324D
+00,
52 1 1.26551212348464539D
+00/
53 DATA CIPR
(1),CIPI
(1),CIPR
(2),CIPI
(2),CIPR
(3),CIPI
(3),CIPR
(4),
55 1 1.0D0
,0.0D0
, 0.0D0
,-1.0D0
, -1.0D0
,0.0D0
, 0.0D0
,1.0D0
/
56 C***FIRST EXECUTABLE STATEMENT ZUNK2
59 C-----------------------------------------------------------------------
60 C EXP(-ALIM)=EXP(-ELIM)/TOL=APPROX. ONE PRECISION GREATER THAN
62 C-----------------------------------------------------------------------
71 BRY
(1) = 1.0D
+3*D1MACH
(1)/TOL
76 IF (ZR
.GE
.0.0D0
) GO TO 10
93 STR
= C2R*CIPR
(KK
) - C2I*CIPI
(KK
)
94 STI
= C2R*CIPI
(KK
) + C2I*CIPR
(KK
)
95 CSR
= CR1R*STR
- CR1I*STI
96 CSI
= CR1R*STI
+ CR1I*STR
97 IF (YY
.GT
.0.0D0
) GO TO 20
101 C-----------------------------------------------------------------------
102 C K(FNU,Z) IS COMPUTED FROM H(2,FNU,-I*Z) WHERE Z IS IN THE FIRST
103 C QUADRANT. FOURTH QUADRANT VALUES (YY.LE.0.0E0) ARE COMPUTED BY
104 C CONJUGATION SINCE THE K FUNCTION IS REAL ON THE POSITIVE REAL AXIS
105 C-----------------------------------------------------------------------
108 C-----------------------------------------------------------------------
109 C J FLIP FLOPS BETWEEN 1 AND 2 IN J = 3 - J
110 C-----------------------------------------------------------------------
113 CALL ZUNHJ
(ZNR
, ZNI
, FN
, 0, TOL
, PHIR
(J
), PHII
(J
), ARGR
(J
),
114 * ARGI
(J
), ZETA1R
(J
), ZETA1I
(J
), ZETA2R
(J
), ZETA2I
(J
), ASUMR
(J
),
115 * ASUMI
(J
), BSUMR
(J
), BSUMI
(J
))
116 IF (KODE
.EQ
.1) GO TO 30
117 STR
= ZBR
+ ZETA2R
(J
)
118 STI
= ZBI
+ ZETA2I
(J
)
119 RAST
= FN
/ZABS
(STR
,STI
)
122 S1R
= ZETA1R
(J
) - STR
123 S1I
= ZETA1I
(J
) - STI
126 S1R
= ZETA1R
(J
) - ZETA2R
(J
)
127 S1I
= ZETA1I
(J
) - ZETA2I
(J
)
129 C-----------------------------------------------------------------------
130 C TEST FOR UNDERFLOW AND OVERFLOW
131 C-----------------------------------------------------------------------
133 IF (ABS
(RS1
).GT
.ELIM
) GO TO 70
134 IF (KDFLG
.EQ
.1) KFLAG
= 2
135 IF (ABS
(RS1
).LT
.ALIM
) GO TO 50
136 C-----------------------------------------------------------------------
137 C REFINE TEST AND SCALE
138 C-----------------------------------------------------------------------
139 APHI
= ZABS
(PHIR
(J
),PHII
(J
))
140 AARG
= ZABS
(ARGR
(J
),ARGI
(J
))
141 RS1
= RS1
+ LOG
(APHI
) - 0.25D0*LOG
(AARG
) - AIC
142 IF (ABS
(RS1
).GT
.ELIM
) GO TO 70
143 IF (KDFLG
.EQ
.1) KFLAG
= 1
144 IF (RS1
.LT
.0.0D0
) GO TO 50
145 IF (KDFLG
.EQ
.1) KFLAG
= 3
147 C-----------------------------------------------------------------------
148 C SCALE S1 TO KEEP INTERMEDIATE ARITHMETIC ON SCALE NEAR
150 C-----------------------------------------------------------------------
151 C2R
= ARGR
(J
)*CR2R
- ARGI
(J
)*CR2I
152 C2I
= ARGR
(J
)*CR2I
+ ARGI
(J
)*CR2R
153 CALL ZAIRY
(C2R
, C2I
, 0, 2, AIR
, AII
, NAI
, IDUM
)
154 CALL ZAIRY
(C2R
, C2I
, 1, 2, DAIR
, DAII
, NDAI
, IDUM
)
155 STR
= DAIR*BSUMR
(J
) - DAII*BSUMI
(J
)
156 STI
= DAIR*BSUMI
(J
) + DAII*BSUMR
(J
)
157 PTR
= STR*CR2R
- STI*CR2I
158 PTI
= STR*CR2I
+ STI*CR2R
159 STR
= PTR
+ (AIR*ASUMR
(J
)-AII*ASUMI
(J
))
160 STI
= PTI
+ (AIR*ASUMI
(J
)+AII*ASUMR
(J
))
161 PTR
= STR*PHIR
(J
) - STI*PHII
(J
)
162 PTI
= STR*PHII
(J
) + STI*PHIR
(J
)
163 S2R
= PTR*CSR
- PTI*CSI
164 S2I
= PTR*CSI
+ PTI*CSR
165 STR
= EXP
(S1R
)*CSSR
(KFLAG
)
168 STR
= S2R*S1R
- S2I*S1I
169 S2I
= S1R*S2I
+ S2R*S1I
171 IF (KFLAG
.NE
.1) GO TO 60
172 CALL ZUCHK
(S2R
, S2I
, NW
, BRY
(1), TOL
)
173 IF (NW
.NE
.0) GO TO 70
175 IF (YY
.LE
.0.0D0
) S2I
= -S2I
178 YR
(I
) = S2R*CSRR
(KFLAG
)
179 YI
(I
) = S2I*CSRR
(KFLAG
)
183 IF (KDFLG
.EQ
.2) GO TO 85
187 IF (RS1
.GT
.0.0D0
) GO TO 320
188 C-----------------------------------------------------------------------
189 C FOR ZR.LT.0.0, THE I FUNCTION TO BE ADDED WILL OVERFLOW
190 C-----------------------------------------------------------------------
191 IF (ZR
.LT
.0.0D0
) GO TO 320
200 IF ((YR
(I
-1).EQ
.ZEROR
).AND
.(YI
(I
-1).EQ
.ZEROI
)) GO TO 80
207 RAZR
= 1.0D0
/ZABS
(ZRR
,ZRI
)
215 IF (N
.LT
.IB
) GO TO 180
216 C-----------------------------------------------------------------------
217 C TEST LAST MEMBER FOR UNDERFLOW AND OVERFLOW. SET SEQUENCE TO ZERO
219 C-----------------------------------------------------------------------
222 IF (MR
.NE
.0) IPARD
= 0
223 CALL ZUNHJ
(ZNR
, ZNI
, FN
, IPARD
, TOL
, PHIDR
, PHIDI
, ARGDR
, ARGDI
,
224 * ZET1DR
, ZET1DI
, ZET2DR
, ZET2DI
, ASUMDR
, ASUMDI
, BSUMDR
, BSUMDI
)
225 IF (KODE
.EQ
.1) GO TO 90
228 RAST
= FN
/ZABS
(STR
,STI
)
235 S1R
= ZET1DR
- ZET2DR
236 S1I
= ZET1DI
- ZET2DI
239 IF (ABS
(RS1
).GT
.ELIM
) GO TO 105
240 IF (ABS
(RS1
).LT
.ALIM
) GO TO 120
241 C-----------------------------------------------------------------------
242 C REFINE ESTIMATE AND TEST
243 C-----------------------------------------------------------------------
244 APHI
= ZABS
(PHIDR
,PHIDI
)
246 IF (ABS
(RS1
).LT
.ELIM
) GO TO 120
248 IF (RS1
.GT
.0.0D0
) GO TO 320
249 C-----------------------------------------------------------------------
250 C FOR ZR.LT.0.0, THE I FUNCTION TO BE ADDED WILL OVERFLOW
251 C-----------------------------------------------------------------------
252 IF (ZR
.LT
.0.0D0
) GO TO 320
269 S2R
= CKR*C2R
- CKI*C2I
+ S1R
270 S2I
= CKR*C2I
+ CKI*C2R
+ S1I
279 IF (KFLAG
.GE
.3) GO TO 130
283 IF (C2M
.LE
.ASCLE
) GO TO 130
290 S1R
= S1R*CSSR
(KFLAG
)
291 S1I
= S1I*CSSR
(KFLAG
)
292 S2R
= S2R*CSSR
(KFLAG
)
293 S2I
= S2I*CSSR
(KFLAG
)
298 C-----------------------------------------------------------------------
299 C ANALYTIC CONTINUATION FOR RE(Z).LT.0.0D0
300 C-----------------------------------------------------------------------
304 C-----------------------------------------------------------------------
305 C CSPN AND CSGN ARE COEFF OF K AND I FUNCTIONS RESP.
306 C-----------------------------------------------------------------------
308 IF (YY
.LE
.0.0D0
) CSGNI
= -CSGNI
313 IF (MOD
(IFN
,2).EQ
.0) GO TO 190
317 C-----------------------------------------------------------------------
318 C CS=COEFF OF THE J FUNCTION TO GET THE I FUNCTION. I(FNU,Z) IS
319 C COMPUTED FROM EXP(I*FNU*HPI)*J(FNU,-I*Z) WHERE Z IS IN THE FIRST
320 C QUADRANT. FOURTH QUADRANT VALUES (YY.LE.0.0E0) ARE COMPUTED BY
321 C CONJUGATION SINCE THE I FUNCTION IS REAL ON THE POSITIVE REAL AXIS
322 C-----------------------------------------------------------------------
328 STR
= CSR*C2R
+ CSI*C2I
329 CSI
= -CSR*C2I
+ CSI*C2R
339 C-----------------------------------------------------------------------
340 C LOGIC TO SORT OUT CASES WHOSE PARAMETERS WERE SET FOR THE K
342 C-----------------------------------------------------------------------
343 IF (N
.GT
.2) GO TO 175
360 IF ((KK
.EQ
.N
).AND
.(IB
.LT
.N
)) GO TO 210
361 IF ((KK
.EQ
.IB
).OR
.(KK
.EQ
.IC
)) GO TO 172
362 CALL ZUNHJ
(ZNR
, ZNI
, FN
, 0, TOL
, PHIDR
, PHIDI
, ARGDR
,
363 * ARGDI
, ZET1DR
, ZET1DI
, ZET2DR
, ZET2DI
, ASUMDR
,
364 * ASUMDI
, BSUMDR
, BSUMDI
)
366 IF (KODE
.EQ
.1) GO TO 220
369 RAST
= FN
/ZABS
(STR
,STI
)
376 S1R
= -ZET1DR
+ ZET2DR
377 S1I
= -ZET1DI
+ ZET2DI
379 C-----------------------------------------------------------------------
380 C TEST FOR UNDERFLOW AND OVERFLOW
381 C-----------------------------------------------------------------------
383 IF (ABS
(RS1
).GT
.ELIM
) GO TO 280
384 IF (KDFLG
.EQ
.1) IFLAG
= 2
385 IF (ABS
(RS1
).LT
.ALIM
) GO TO 240
386 C-----------------------------------------------------------------------
387 C REFINE TEST AND SCALE
388 C-----------------------------------------------------------------------
389 APHI
= ZABS
(PHIDR
,PHIDI
)
390 AARG
= ZABS
(ARGDR
,ARGDI
)
391 RS1
= RS1
+ LOG
(APHI
) - 0.25D0*LOG
(AARG
) - AIC
392 IF (ABS
(RS1
).GT
.ELIM
) GO TO 280
393 IF (KDFLG
.EQ
.1) IFLAG
= 1
394 IF (RS1
.LT
.0.0D0
) GO TO 240
395 IF (KDFLG
.EQ
.1) IFLAG
= 3
397 CALL ZAIRY
(ARGDR
, ARGDI
, 0, 2, AIR
, AII
, NAI
, IDUM
)
398 CALL ZAIRY
(ARGDR
, ARGDI
, 1, 2, DAIR
, DAII
, NDAI
, IDUM
)
399 STR
= DAIR*BSUMDR
- DAII*BSUMDI
400 STI
= DAIR*BSUMDI
+ DAII*BSUMDR
401 STR
= STR
+ (AIR*ASUMDR
-AII*ASUMDI
)
402 STI
= STI
+ (AIR*ASUMDI
+AII*ASUMDR
)
403 PTR
= STR*PHIDR
- STI*PHIDI
404 PTI
= STR*PHIDI
+ STI*PHIDR
405 S2R
= PTR*CSR
- PTI*CSI
406 S2I
= PTR*CSI
+ PTI*CSR
407 STR
= EXP
(S1R
)*CSSR
(IFLAG
)
410 STR
= S2R*S1R
- S2I*S1I
411 S2I
= S2R*S1I
+ S2I*S1R
413 IF (IFLAG
.NE
.1) GO TO 250
414 CALL ZUCHK
(S2R
, S2I
, NW
, BRY
(1), TOL
)
415 IF (NW
.EQ
.0) GO TO 250
419 IF (YY
.LE
.0.0D0
) S2I
= -S2I
424 S2R
= S2R*CSRR
(IFLAG
)
425 S2I
= S2I*CSRR
(IFLAG
)
426 C-----------------------------------------------------------------------
427 C ADD I AND K FUNCTIONS, K SEQUENCE IN Y(I), I=1,N
428 C-----------------------------------------------------------------------
431 IF (KODE
.EQ
.1) GO TO 270
432 CALL ZS1S2
(ZRR
, ZRI
, S1R
, S1I
, S2R
, S2I
, NW
, ASC
, ALIM
, IUF
)
435 YR
(KK
) = S1R*CSPNR
- S1I*CSPNI
+ S2R
436 YI
(KK
) = S1R*CSPNI
+ S1I*CSPNR
+ S2I
443 IF (C2R
.NE
.0.0D0
.OR
. C2I
.NE
.0.0D0
) GO TO 255
447 IF (KDFLG
.EQ
.2) GO TO 295
451 IF (RS1
.GT
.0.0D0
) GO TO 320
460 C-----------------------------------------------------------------------
461 C RECUR BACKWARD FOR REMAINDER OF I SEQUENCE AND ADD IN THE
462 C K FUNCTIONS, SCALING THE I SEQUENCE DURING RECURRENCE TO KEEP
463 C INTERMEDIATE ARITHMETIC ON SCALE NEAR EXPONENT EXTREMES.
464 C-----------------------------------------------------------------------
475 S2R
= S1R
+ (FN
+FNF
)*(RZR*C2R
-RZI*C2I
)
476 S2I
= S1I
+ (FN
+FNF
)*(RZR*C2I
+RZI*C2R
)
486 IF (KODE
.EQ
.1) GO TO 300
487 CALL ZS1S2
(ZRR
, ZRI
, C1R
, C1I
, C2R
, C2I
, NW
, ASC
, ALIM
, IUF
)
490 YR
(KK
) = C1R*CSPNR
- C1I*CSPNI
+ C2R
491 YI
(KK
) = C1R*CSPNI
+ C1I*CSPNR
+ C2I
495 IF (IFLAG
.GE
.3) GO TO 310
499 IF (C2M
.LE
.ASCLE
) GO TO 310
506 S1R
= S1R*CSSR
(IFLAG
)
507 S1I
= S1I*CSSR
(IFLAG
)
508 S2R
= S2R*CSSR
(IFLAG
)
509 S2I
= S2I*CSSR
(IFLAG
)