1 SUBROUTINE ZUNK1
(ZR
, ZI
, FNU
, KODE
, MR
, N
, YR
, YI
, NZ
, TOL
, ELIM
,
3 C***BEGIN PROLOGUE ZUNK1
6 C ZUNK1 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 EXPANSION.
9 C MR INDICATES THE DIRECTION OF ROTATION FOR ANALYTIC CONTINUATION.
10 C NZ=-1 MEANS AN OVERFLOW WILL OCCUR
12 C***ROUTINES CALLED ZKSCL,ZS1S2,ZUCHK,ZUNIK,D1MACH,AZABS
13 C***END PROLOGUE ZUNK1
14 C COMPLEX CFN,CK,CONE,CRSC,CS,CSCL,CSGN,CSPN,CSR,CSS,CWRK,CY,CZERO,
15 C *C1,C2,PHI,PHID,RZ,SUM,SUMD,S1,S2,Y,Z,ZETA1,ZETA1D,ZETA2,ZETA2D,ZR
16 DOUBLE PRECISION ALIM
, ANG
, APHI
, ASC
, ASCLE
, BRY
, CKI
, CKR
,
17 * CONER
, CRSC
, CSCL
, CSGNI
, CSPNI
, CSPNR
, CSR
, CSRR
, CSSR
,
18 * CWRKI
, CWRKR
, CYI
, CYR
, C1I
, C1R
, C2I
, C2M
, C2R
, ELIM
, FMR
, FN
,
19 * FNF
, FNU
, PHIDI
, PHIDR
, PHII
, PHIR
, PI
, RAST
, RAZR
, RS1
, RZI
,
20 * RZR
, SGN
, STI
, STR
, SUMDI
, SUMDR
, SUMI
, SUMR
, S1I
, S1R
, S2I
,
21 * S2R
, TOL
, YI
, YR
, ZEROI
, ZEROR
, ZETA1I
, ZETA1R
, ZETA2I
, ZETA2R
,
22 * ZET1DI
, ZET1DR
, ZET2DI
, ZET2DR
, ZI
, ZR
, ZRI
, ZRR
, D1MACH
, AZABS
23 INTEGER I
, IB
, IFLAG
, IFN
, IL
, INIT
, INU
, IUF
, K
, KDFLG
, KFLAG
,
24 * KK
, KODE
, MR
, N
, NW
, NZ
, INITD
, IC
, IPARD
, J
25 DIMENSION BRY
(3), INIT
(2), YR
(N
), YI
(N
), SUMR
(2), SUMI
(2),
26 * ZETA1R
(2), ZETA1I
(2), ZETA2R
(2), ZETA2I
(2), CYR
(2), CYI
(2),
27 * CWRKR
(16,3), CWRKI
(16,3), CSSR
(3), CSRR
(3), PHIR
(2), PHII
(2)
28 DATA ZEROR
,ZEROI
,CONER
/ 0.0D0
, 0.0D0
, 1.0D0
/
29 DATA PI
/ 3.14159265358979324D0
/
33 C-----------------------------------------------------------------------
34 C EXP(-ALIM)=EXP(-ELIM)/TOL=APPROX. ONE PRECISION GREATER THAN
36 C-----------------------------------------------------------------------
45 BRY
(1) = 1.0D
+3*D1MACH
(1)/TOL
50 IF (ZR
.GE
.0.0D0
) GO TO 10
56 C-----------------------------------------------------------------------
57 C J FLIP FLOPS BETWEEN 1 AND 2 IN J = 3 - J
58 C-----------------------------------------------------------------------
60 FN
= FNU
+ DBLE
(FLOAT
(I
-1))
62 CALL ZUNIK
(ZRR
, ZRI
, FN
, 2, 0, TOL
, INIT
(J
), PHIR
(J
), PHII
(J
),
63 * ZETA1R
(J
), ZETA1I
(J
), ZETA2R
(J
), ZETA2I
(J
), SUMR
(J
), SUMI
(J
),
64 * CWRKR
(1,J
), CWRKI
(1,J
))
65 IF (KODE
.EQ
.1) GO TO 20
68 RAST
= FN
/AZABS
(STR
,STI
)
75 S1R
= ZETA1R
(J
) - ZETA2R
(J
)
76 S1I
= ZETA1I
(J
) - ZETA2I
(J
)
79 C-----------------------------------------------------------------------
80 C TEST FOR UNDERFLOW AND OVERFLOW
81 C-----------------------------------------------------------------------
82 IF (DABS
(RS1
).GT
.ELIM
) GO TO 60
83 IF (KDFLG
.EQ
.1) KFLAG
= 2
84 IF (DABS
(RS1
).LT
.ALIM
) GO TO 40
85 C-----------------------------------------------------------------------
86 C REFINE TEST AND SCALE
87 C-----------------------------------------------------------------------
88 APHI
= AZABS
(PHIR
(J
),PHII
(J
))
89 RS1
= RS1
+ DLOG
(APHI
)
90 IF (DABS
(RS1
).GT
.ELIM
) GO TO 60
91 IF (KDFLG
.EQ
.1) KFLAG
= 1
92 IF (RS1
.LT
.0.0D0
) GO TO 40
93 IF (KDFLG
.EQ
.1) KFLAG
= 3
95 C-----------------------------------------------------------------------
96 C SCALE S1 TO KEEP INTERMEDIATE ARITHMETIC ON SCALE NEAR
98 C-----------------------------------------------------------------------
99 S2R
= PHIR
(J
)*SUMR
(J
) - PHII
(J
)*SUMI
(J
)
100 S2I
= PHIR
(J
)*SUMI
(J
) + PHII
(J
)*SUMR
(J
)
101 STR
= DEXP
(S1R
)*CSSR
(KFLAG
)
104 STR
= S2R*S1R
- S2I*S1I
105 S2I
= S1R*S2I
+ S2R*S1I
107 IF (KFLAG
.NE
.1) GO TO 50
108 CALL ZUCHK
(S2R
, S2I
, NW
, BRY
(1), TOL
)
109 IF (NW
.NE
.0) GO TO 60
113 YR
(I
) = S2R*CSRR
(KFLAG
)
114 YI
(I
) = S2I*CSRR
(KFLAG
)
115 IF (KDFLG
.EQ
.2) GO TO 75
119 IF (RS1
.GT
.0.0D0
) GO TO 300
120 C-----------------------------------------------------------------------
121 C FOR ZR.LT.0.0, THE I FUNCTION TO BE ADDED WILL OVERFLOW
122 C-----------------------------------------------------------------------
123 IF (ZR
.LT
.0.0D0
) GO TO 300
129 IF ((YR
(I
-1).EQ
.ZEROR
).AND
.(YI
(I
-1).EQ
.ZEROI
)) GO TO 70
136 RAZR
= 1.0D0
/AZABS
(ZRR
,ZRI
)
144 IF (N
.LT
.IB
) GO TO 160
145 C-----------------------------------------------------------------------
146 C TEST LAST MEMBER FOR UNDERFLOW AND OVERFLOW. SET SEQUENCE TO ZERO
148 C-----------------------------------------------------------------------
149 FN
= FNU
+ DBLE
(FLOAT
(N
-1))
151 IF (MR
.NE
.0) IPARD
= 0
153 CALL ZUNIK
(ZRR
, ZRI
, FN
, 2, IPARD
, TOL
, INITD
, PHIDR
, PHIDI
,
154 * ZET1DR
, ZET1DI
, ZET2DR
, ZET2DI
, SUMDR
, SUMDI
, CWRKR
(1,3),
156 IF (KODE
.EQ
.1) GO TO 80
159 RAST
= FN
/AZABS
(STR
,STI
)
166 S1R
= ZET1DR
- ZET2DR
167 S1I
= ZET1DI
- ZET2DI
170 IF (DABS
(RS1
).GT
.ELIM
) GO TO 95
171 IF (DABS
(RS1
).LT
.ALIM
) GO TO 100
172 C----------------------------------------------------------------------------
173 C REFINE ESTIMATE AND TEST
174 C-------------------------------------------------------------------------
175 APHI
= AZABS
(PHIDR
,PHIDI
)
177 IF (DABS
(RS1
).LT
.ELIM
) GO TO 100
179 IF (DABS
(RS1
).GT
.0.0D0
) GO TO 300
180 C-----------------------------------------------------------------------
181 C FOR ZR.LT.0.0, THE I FUNCTION TO BE ADDED WILL OVERFLOW
182 C-----------------------------------------------------------------------
183 IF (ZR
.LT
.0.0D0
) GO TO 300
190 C---------------------------------------------------------------------------
191 C FORWARD RECUR FOR REMAINDER OF THE SEQUENCE
192 C----------------------------------------------------------------------------
203 S2R
= CKR*C2R
- CKI*C2I
+ S1R
204 S2I
= CKR*C2I
+ CKI*C2R
+ S1I
213 IF (KFLAG
.GE
.3) GO TO 120
217 IF (C2M
.LE
.ASCLE
) GO TO 120
224 S1R
= S1R*CSSR
(KFLAG
)
225 S1I
= S1I*CSSR
(KFLAG
)
226 S2R
= S2R*CSSR
(KFLAG
)
227 S2I
= S2I*CSSR
(KFLAG
)
232 C-----------------------------------------------------------------------
233 C ANALYTIC CONTINUATION FOR RE(Z).LT.0.0D0
234 C-----------------------------------------------------------------------
236 FMR
= DBLE
(FLOAT
(MR
))
238 C-----------------------------------------------------------------------
239 C CSPN AND CSGN ARE COEFF OF K AND I FUNCTIONS RESP.
240 C-----------------------------------------------------------------------
243 FNF
= FNU
- DBLE
(FLOAT
(INU
))
248 IF (MOD
(IFN
,2).EQ
.0) GO TO 170
259 FN
= FNU
+ DBLE
(FLOAT
(KK
-1))
260 C-----------------------------------------------------------------------
261 C LOGIC TO SORT OUT CASES WHOSE PARAMETERS WERE SET FOR THE K
263 C-----------------------------------------------------------------------
265 IF (N
.GT
.2) GO TO 175
280 IF ((KK
.EQ
.N
).AND
.(IB
.LT
.N
)) GO TO 180
281 IF ((KK
.EQ
.IB
).OR
.(KK
.EQ
.IC
)) GO TO 172
284 CALL ZUNIK
(ZRR
, ZRI
, FN
, 1, 0, TOL
, INITD
, PHIDR
, PHIDI
,
285 * ZET1DR
, ZET1DI
, ZET2DR
, ZET2DI
, SUMDR
, SUMDI
,
286 * CWRKR
(1,M
), CWRKI
(1,M
))
287 IF (KODE
.EQ
.1) GO TO 200
290 RAST
= FN
/AZABS
(STR
,STI
)
297 S1R
= -ZET1DR
+ ZET2DR
298 S1I
= -ZET1DI
+ ZET2DI
300 C-----------------------------------------------------------------------
301 C TEST FOR UNDERFLOW AND OVERFLOW
302 C-----------------------------------------------------------------------
304 IF (DABS
(RS1
).GT
.ELIM
) GO TO 260
305 IF (KDFLG
.EQ
.1) IFLAG
= 2
306 IF (DABS
(RS1
).LT
.ALIM
) GO TO 220
307 C-----------------------------------------------------------------------
308 C REFINE TEST AND SCALE
309 C-----------------------------------------------------------------------
310 APHI
= AZABS
(PHIDR
,PHIDI
)
311 RS1
= RS1
+ DLOG
(APHI
)
312 IF (DABS
(RS1
).GT
.ELIM
) GO TO 260
313 IF (KDFLG
.EQ
.1) IFLAG
= 1
314 IF (RS1
.LT
.0.0D0
) GO TO 220
315 IF (KDFLG
.EQ
.1) IFLAG
= 3
317 STR
= PHIDR*SUMDR
- PHIDI*SUMDI
318 STI
= PHIDR*SUMDI
+ PHIDI*SUMDR
321 STR
= DEXP
(S1R
)*CSSR
(IFLAG
)
324 STR
= S2R*S1R
- S2I*S1I
325 S2I
= S2R*S1I
+ S2I*S1R
327 IF (IFLAG
.NE
.1) GO TO 230
328 CALL ZUCHK
(S2R
, S2I
, NW
, BRY
(1), TOL
)
329 IF (NW
.EQ
.0) GO TO 230
337 S2R
= S2R*CSRR
(IFLAG
)
338 S2I
= S2I*CSRR
(IFLAG
)
339 C-----------------------------------------------------------------------
340 C ADD I AND K FUNCTIONS, K SEQUENCE IN Y(I), I=1,N
341 C-----------------------------------------------------------------------
344 IF (KODE
.EQ
.1) GO TO 250
345 CALL ZS1S2
(ZRR
, ZRI
, S1R
, S1I
, S2R
, S2I
, NW
, ASC
, ALIM
, IUF
)
348 YR
(KK
) = S1R*CSPNR
- S1I*CSPNI
+ S2R
349 YI
(KK
) = CSPNR*S1I
+ CSPNI*S1R
+ S2I
353 IF (C2R
.NE
.0.0D0
.OR
. C2I
.NE
.0.0D0
) GO TO 255
357 IF (KDFLG
.EQ
.2) GO TO 275
361 IF (RS1
.GT
.0.0D0
) GO TO 300
370 C-----------------------------------------------------------------------
371 C RECUR BACKWARD FOR REMAINDER OF I SEQUENCE AND ADD IN THE
372 C K FUNCTIONS, SCALING THE I SEQUENCE DURING RECURRENCE TO KEEP
373 C INTERMEDIATE ARITHMETIC ON SCALE NEAR EXPONENT EXTREMES.
374 C-----------------------------------------------------------------------
381 FN
= DBLE
(FLOAT
(INU
+IL
))
385 S2R
= S1R
+ (FN
+FNF
)*(RZR*C2R
-RZI*C2I
)
386 S2I
= S1I
+ (FN
+FNF
)*(RZR*C2I
+RZI*C2R
)
396 IF (KODE
.EQ
.1) GO TO 280
397 CALL ZS1S2
(ZRR
, ZRI
, C1R
, C1I
, C2R
, C2I
, NW
, ASC
, ALIM
, IUF
)
400 YR
(KK
) = C1R*CSPNR
- C1I*CSPNI
+ C2R
401 YI
(KK
) = C1R*CSPNI
+ C1I*CSPNR
+ C2I
405 IF (IFLAG
.GE
.3) GO TO 290
409 IF (C2M
.LE
.ASCLE
) GO TO 290
416 S1R
= S1R*CSSR
(IFLAG
)
417 S1I
= S1I*CSSR
(IFLAG
)
418 S2R
= S2R*CSSR
(IFLAG
)
419 S2I
= S2I*CSSR
(IFLAG
)