2 SUBROUTINE ZUNK1
(ZR
, ZI
, FNU
, KODE
, MR
, N
, YR
, YI
, NZ
, TOL
, ELIM
,
4 C***BEGIN PROLOGUE ZUNK1
6 C***PURPOSE Subsidiary to ZBESK
8 C***TYPE ALL (CUNK1-A, ZUNK1-A)
9 C***AUTHOR Amos, D. E., (SNL)
12 C ZUNK1 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 EXPANSION.
15 C MR INDICATES THE DIRECTION OF ROTATION FOR ANALYTIC CONTINUATION.
16 C NZ=-1 MEANS AN OVERFLOW WILL OCCUR
19 C***ROUTINES CALLED D1MACH, ZABS, ZS1S2, ZUCHK, ZUNIK
20 C***REVISION HISTORY (YYMMDD)
22 C 910415 Prologue converted to Version 4.0 format. (BAB)
23 C***END PROLOGUE ZUNK1
24 C COMPLEX CFN,CK,CONE,CRSC,CS,CSCL,CSGN,CSPN,CSR,CSS,CWRK,CY,CZERO,
25 C *C1,C2,PHI,PHID,RZ,SUM,SUMD,S1,S2,Y,Z,ZETA1,ZETA1D,ZETA2,ZETA2D,ZR
26 DOUBLE PRECISION ALIM
, ANG
, APHI
, ASC
, ASCLE
, BRY
, CKI
, CKR
,
27 * CONER
, CRSC
, CSCL
, CSGNI
, CSPNI
, CSPNR
, CSR
, CSRR
, CSSR
,
28 * CWRKI
, CWRKR
, CYI
, CYR
, C1I
, C1R
, C2I
, C2M
, C2R
, ELIM
, FMR
, FN
,
29 * FNF
, FNU
, PHIDI
, PHIDR
, PHII
, PHIR
, PI
, RAST
, RAZR
, RS1
, RZI
,
30 * RZR
, SGN
, STI
, STR
, SUMDI
, SUMDR
, SUMI
, SUMR
, S1I
, S1R
, S2I
,
31 * S2R
, TOL
, YI
, YR
, ZEROI
, ZEROR
, ZETA1I
, ZETA1R
, ZETA2I
, ZETA2R
,
32 * ZET1DI
, ZET1DR
, ZET2DI
, ZET2DR
, ZI
, ZR
, ZRI
, ZRR
, D1MACH
, ZABS
33 INTEGER I
, IB
, IFLAG
, IFN
, IL
, INIT
, INU
, IUF
, K
, KDFLG
, KFLAG
,
34 * KK
, KODE
, MR
, N
, NW
, NZ
, INITD
, IC
, IPARD
, J
, M
35 DIMENSION BRY
(3), INIT
(2), YR
(N
), YI
(N
), SUMR
(2), SUMI
(2),
36 * ZETA1R
(2), ZETA1I
(2), ZETA2R
(2), ZETA2I
(2), CYR
(2), CYI
(2),
37 * CWRKR
(16,3), CWRKI
(16,3), CSSR
(3), CSRR
(3), PHIR
(2), PHII
(2)
39 DATA ZEROR
,ZEROI
,CONER
/ 0.0D0
, 0.0D0
, 1.0D0
/
40 DATA PI
/ 3.14159265358979324D0
/
41 C***FIRST EXECUTABLE STATEMENT ZUNK1
44 C-----------------------------------------------------------------------
45 C EXP(-ALIM)=EXP(-ELIM)/TOL=APPROX. ONE PRECISION GREATER THAN
47 C-----------------------------------------------------------------------
56 BRY
(1) = 1.0D
+3*D1MACH
(1)/TOL
61 IF (ZR
.GE
.0.0D0
) GO TO 10
67 C-----------------------------------------------------------------------
68 C J FLIP FLOPS BETWEEN 1 AND 2 IN J = 3 - J
69 C-----------------------------------------------------------------------
73 CALL ZUNIK
(ZRR
, ZRI
, FN
, 2, 0, TOL
, INIT
(J
), PHIR
(J
), PHII
(J
),
74 * ZETA1R
(J
), ZETA1I
(J
), ZETA2R
(J
), ZETA2I
(J
), SUMR
(J
), SUMI
(J
),
75 * CWRKR
(1,J
), CWRKI
(1,J
))
76 IF (KODE
.EQ
.1) GO TO 20
79 RAST
= FN
/ZABS
(STR
,STI
)
86 S1R
= ZETA1R
(J
) - ZETA2R
(J
)
87 S1I
= ZETA1I
(J
) - ZETA2I
(J
)
90 C-----------------------------------------------------------------------
91 C TEST FOR UNDERFLOW AND OVERFLOW
92 C-----------------------------------------------------------------------
93 IF (ABS
(RS1
).GT
.ELIM
) GO TO 60
94 IF (KDFLG
.EQ
.1) KFLAG
= 2
95 IF (ABS
(RS1
).LT
.ALIM
) GO TO 40
96 C-----------------------------------------------------------------------
97 C REFINE TEST AND SCALE
98 C-----------------------------------------------------------------------
99 APHI
= ZABS
(PHIR
(J
),PHII
(J
))
100 RS1
= RS1
+ LOG
(APHI
)
101 IF (ABS
(RS1
).GT
.ELIM
) GO TO 60
102 IF (KDFLG
.EQ
.1) KFLAG
= 1
103 IF (RS1
.LT
.0.0D0
) GO TO 40
104 IF (KDFLG
.EQ
.1) KFLAG
= 3
106 C-----------------------------------------------------------------------
107 C SCALE S1 TO KEEP INTERMEDIATE ARITHMETIC ON SCALE NEAR
109 C-----------------------------------------------------------------------
110 S2R
= PHIR
(J
)*SUMR
(J
) - PHII
(J
)*SUMI
(J
)
111 S2I
= PHIR
(J
)*SUMI
(J
) + PHII
(J
)*SUMR
(J
)
112 STR
= EXP
(S1R
)*CSSR
(KFLAG
)
115 STR
= S2R*S1R
- S2I*S1I
116 S2I
= S1R*S2I
+ S2R*S1I
118 IF (KFLAG
.NE
.1) GO TO 50
119 CALL ZUCHK
(S2R
, S2I
, NW
, BRY
(1), TOL
)
120 IF (NW
.NE
.0) GO TO 60
124 YR
(I
) = S2R*CSRR
(KFLAG
)
125 YI
(I
) = S2I*CSRR
(KFLAG
)
126 IF (KDFLG
.EQ
.2) GO TO 75
130 IF (RS1
.GT
.0.0D0
) GO TO 300
131 C-----------------------------------------------------------------------
132 C FOR ZR.LT.0.0, THE I FUNCTION TO BE ADDED WILL OVERFLOW
133 C-----------------------------------------------------------------------
134 IF (ZR
.LT
.0.0D0
) GO TO 300
140 IF ((YR
(I
-1).EQ
.ZEROR
).AND
.(YI
(I
-1).EQ
.ZEROI
)) GO TO 70
147 RAZR
= 1.0D0
/ZABS
(ZRR
,ZRI
)
155 IF (N
.LT
.IB
) GO TO 160
156 C-----------------------------------------------------------------------
157 C TEST LAST MEMBER FOR UNDERFLOW AND OVERFLOW. SET SEQUENCE TO ZERO
159 C-----------------------------------------------------------------------
162 IF (MR
.NE
.0) IPARD
= 0
164 CALL ZUNIK
(ZRR
, ZRI
, FN
, 2, IPARD
, TOL
, INITD
, PHIDR
, PHIDI
,
165 * ZET1DR
, ZET1DI
, ZET2DR
, ZET2DI
, SUMDR
, SUMDI
, CWRKR
(1,3),
167 IF (KODE
.EQ
.1) GO TO 80
170 RAST
= FN
/ZABS
(STR
,STI
)
177 S1R
= ZET1DR
- ZET2DR
178 S1I
= ZET1DI
- ZET2DI
181 IF (ABS
(RS1
).GT
.ELIM
) GO TO 95
182 IF (ABS
(RS1
).LT
.ALIM
) GO TO 100
183 C-----------------------------------------------------------------------
184 C REFINE ESTIMATE AND TEST
185 C-----------------------------------------------------------------------
186 APHI
= ZABS
(PHIDR
,PHIDI
)
188 IF (ABS
(RS1
).LT
.ELIM
) GO TO 100
190 IF (ABS
(RS1
).GT
.0.0D0
) GO TO 300
191 C-----------------------------------------------------------------------
192 C FOR ZR.LT.0.0, THE I FUNCTION TO BE ADDED WILL OVERFLOW
193 C-----------------------------------------------------------------------
194 IF (ZR
.LT
.0.0D0
) GO TO 300
201 C-----------------------------------------------------------------------
202 C FORWARD RECUR FOR REMAINDER OF THE SEQUENCE
203 C-----------------------------------------------------------------------
214 S2R
= CKR*C2R
- CKI*C2I
+ S1R
215 S2I
= CKR*C2I
+ CKI*C2R
+ S1I
224 IF (KFLAG
.GE
.3) GO TO 120
228 IF (C2M
.LE
.ASCLE
) GO TO 120
235 S1R
= S1R*CSSR
(KFLAG
)
236 S1I
= S1I*CSSR
(KFLAG
)
237 S2R
= S2R*CSSR
(KFLAG
)
238 S2I
= S2I*CSSR
(KFLAG
)
243 C-----------------------------------------------------------------------
244 C ANALYTIC CONTINUATION FOR RE(Z).LT.0.0D0
245 C-----------------------------------------------------------------------
249 C-----------------------------------------------------------------------
250 C CSPN AND CSGN ARE COEFF OF K AND I FUNCTIONS RESP.
251 C-----------------------------------------------------------------------
259 IF (MOD
(IFN
,2).EQ
.0) GO TO 170
271 C-----------------------------------------------------------------------
272 C LOGIC TO SORT OUT CASES WHOSE PARAMETERS WERE SET FOR THE K
274 C-----------------------------------------------------------------------
276 IF (N
.GT
.2) GO TO 175
291 IF ((KK
.EQ
.N
).AND
.(IB
.LT
.N
)) GO TO 180
292 IF ((KK
.EQ
.IB
).OR
.(KK
.EQ
.IC
)) GO TO 172
295 CALL ZUNIK
(ZRR
, ZRI
, FN
, 1, 0, TOL
, INITD
, PHIDR
, PHIDI
,
296 * ZET1DR
, ZET1DI
, ZET2DR
, ZET2DI
, SUMDR
, SUMDI
,
297 * CWRKR
(1,M
), CWRKI
(1,M
))
298 IF (KODE
.EQ
.1) GO TO 200
301 RAST
= FN
/ZABS
(STR
,STI
)
308 S1R
= -ZET1DR
+ ZET2DR
309 S1I
= -ZET1DI
+ ZET2DI
311 C-----------------------------------------------------------------------
312 C TEST FOR UNDERFLOW AND OVERFLOW
313 C-----------------------------------------------------------------------
315 IF (ABS
(RS1
).GT
.ELIM
) GO TO 260
316 IF (KDFLG
.EQ
.1) IFLAG
= 2
317 IF (ABS
(RS1
).LT
.ALIM
) GO TO 220
318 C-----------------------------------------------------------------------
319 C REFINE TEST AND SCALE
320 C-----------------------------------------------------------------------
321 APHI
= ZABS
(PHIDR
,PHIDI
)
322 RS1
= RS1
+ LOG
(APHI
)
323 IF (ABS
(RS1
).GT
.ELIM
) GO TO 260
324 IF (KDFLG
.EQ
.1) IFLAG
= 1
325 IF (RS1
.LT
.0.0D0
) GO TO 220
326 IF (KDFLG
.EQ
.1) IFLAG
= 3
328 STR
= PHIDR*SUMDR
- PHIDI*SUMDI
329 STI
= PHIDR*SUMDI
+ PHIDI*SUMDR
332 STR
= EXP
(S1R
)*CSSR
(IFLAG
)
335 STR
= S2R*S1R
- S2I*S1I
336 S2I
= S2R*S1I
+ S2I*S1R
338 IF (IFLAG
.NE
.1) GO TO 230
339 CALL ZUCHK
(S2R
, S2I
, NW
, BRY
(1), TOL
)
340 IF (NW
.EQ
.0) GO TO 230
348 S2R
= S2R*CSRR
(IFLAG
)
349 S2I
= S2I*CSRR
(IFLAG
)
350 C-----------------------------------------------------------------------
351 C ADD I AND K FUNCTIONS, K SEQUENCE IN Y(I), I=1,N
352 C-----------------------------------------------------------------------
355 IF (KODE
.EQ
.1) GO TO 250
356 CALL ZS1S2
(ZRR
, ZRI
, S1R
, S1I
, S2R
, S2I
, NW
, ASC
, ALIM
, IUF
)
359 YR
(KK
) = S1R*CSPNR
- S1I*CSPNI
+ S2R
360 YI
(KK
) = CSPNR*S1I
+ CSPNI*S1R
+ S2I
364 IF (C2R
.NE
.0.0D0
.OR
. C2I
.NE
.0.0D0
) GO TO 255
368 IF (KDFLG
.EQ
.2) GO TO 275
372 IF (RS1
.GT
.0.0D0
) GO TO 300
381 C-----------------------------------------------------------------------
382 C RECUR BACKWARD FOR REMAINDER OF I SEQUENCE AND ADD IN THE
383 C K FUNCTIONS, SCALING THE I SEQUENCE DURING RECURRENCE TO KEEP
384 C INTERMEDIATE ARITHMETIC ON SCALE NEAR EXPONENT EXTREMES.
385 C-----------------------------------------------------------------------
396 S2R
= S1R
+ (FN
+FNF
)*(RZR*C2R
-RZI*C2I
)
397 S2I
= S1I
+ (FN
+FNF
)*(RZR*C2I
+RZI*C2R
)
407 IF (KODE
.EQ
.1) GO TO 280
408 CALL ZS1S2
(ZRR
, ZRI
, C1R
, C1I
, C2R
, C2I
, NW
, ASC
, ALIM
, IUF
)
411 YR
(KK
) = C1R*CSPNR
- C1I*CSPNI
+ C2R
412 YI
(KK
) = C1R*CSPNI
+ C1I*CSPNR
+ C2I
416 IF (IFLAG
.GE
.3) GO TO 290
420 IF (C2M
.LE
.ASCLE
) GO TO 290
427 S1R
= S1R*CSSR
(IFLAG
)
428 S1I
= S1I*CSSR
(IFLAG
)
429 S2R
= S2R*CSSR
(IFLAG
)
430 S2I
= S2I*CSSR
(IFLAG
)