PLaSK library
Loading...
Searching...
No Matches
camos.c
Go to the documentation of this file.
1#include <math.h>
2
3static inline double pow_dd(double *ap, double *bp)
4{
5 return (pow(*ap, *bp));
6}
7
8double d_sign(double *a, double *b)
9{
10 double x;
11 x = (*a >= 0 ? *a : -*a);
12 return (*b >= 0 ? x : -x);
13}
14
15#define min(a,b) ((a) <= (b) ? (a) : (b))
16#define max(a,b) ((a) >= (b) ? (a) : (b))
17#define abs(x) ((x) >= 0 ? (x) : -(x))
18
19/* Table of constant values */
20static long c__4 = 4;
21static long c__14 = 14;
22static long c__5 = 5;
23static long c__1 = 1;
24static long c__2 = 2;
25static long c__15 = 15;
26static long c__16 = 16;
27static long c__9 = 9;
28static double c_b219 = .5;
29static double c_b220 = 0.;
30static long c__0 = 0;
31
32double dgamln(double *z__, long *ierr)
33{
34 /* Initialized data */
35
36 double gln[100] = { 0., 0., .693147180559945309,
37 1.791759469228055, 3.17805383034794562, 4.78749174278204599,
38 6.579251212010101, 8.5251613610654143, 10.6046029027452502,
39 12.8018274800814696, 15.1044125730755153, 17.5023078458738858,
40 19.9872144956618861, 22.5521638531234229, 25.1912211827386815,
41 27.8992713838408916, 30.6718601060806728, 33.5050734501368889,
42 36.3954452080330536, 39.339884187199494, 42.335616460753485,
43 45.380138898476908, 48.4711813518352239, 51.6066755677643736,
44 54.7847293981123192, 58.0036052229805199, 61.261701761002002,
45 64.5575386270063311, 67.889743137181535, 71.257038967168009,
46 74.6582363488301644, 78.0922235533153106, 81.5579594561150372,
47 85.0544670175815174, 88.5808275421976788, 92.1361756036870925,
48 95.7196945421432025, 99.3306124547874269, 102.968198614513813,
49 106.631760260643459, 110.320639714757395, 114.034211781461703,
50 117.771881399745072, 121.533081515438634, 125.317271149356895,
51 129.123933639127215, 132.95257503561631, 136.802722637326368,
52 140.673923648234259, 144.565743946344886, 148.477766951773032,
53 152.409592584497358, 156.360836303078785, 160.331128216630907,
54 164.320112263195181, 168.327445448427652, 172.352797139162802,
55 176.395848406997352, 180.456291417543771, 184.533828861449491,
56 188.628173423671591, 192.739047287844902, 196.866181672889994,
57 201.009316399281527, 205.168199482641199, 209.342586752536836,
58 213.532241494563261, 217.736934113954227, 221.956441819130334,
59 226.190548323727593, 230.439043565776952, 234.701723442818268,
60 238.978389561834323, 243.268849002982714, 247.572914096186884,
61 251.890402209723194, 256.221135550009525, 260.564940971863209,
62 264.921649798552801, 269.291097651019823, 273.673124285693704,
63 278.067573440366143, 282.474292687630396, 286.893133295426994,
64 291.323950094270308, 295.766601350760624, 300.220948647014132,
65 304.686856765668715, 309.164193580146922, 313.652829949879062,
66 318.152639620209327, 322.663499126726177, 327.185287703775217,
67 331.717887196928473, 336.261181979198477, 340.815058870799018,
68 345.379407062266854, 349.954118040770237, 354.539085519440809,
69 359.134205369575399
70 };
71 double cf[22] = { .0833333333333333333, -.00277777777777777778,
72 7.93650793650793651e-4, -5.95238095238095238e-4,
73 8.41750841750841751e-4, -.00191752691752691753,
74 .00641025641025641026, -.0295506535947712418, .179644372368830573,
75 -1.39243221690590112, 13.402864044168392, -156.848284626002017,
76 2193.10333333333333, -36108.7712537249894, 691472.268851313067,
77 -15238221.5394074162, 382900751.391414141, -10882266035.7843911,
78 347320283765.002252, -12369602142269.2745, 488788064793079.335,
79 -21320333960919373.9
80 };
81 double con = 1.83787706640934548;
82
83 /* System generated locals */
84 long i__1;
85 double ret_val;
86
87 /* Builtin functions */
88 double log(double);
89
90 /* Local variables */
91 long i__, k;
92 double s, t1, fz, zm;
93 long mz, nz;
94 double zp;
95 long i1m;
96 double fln, tlg, rln, trm, tst, zsq, zinc, zmin, zdmy, wdtol;
97 extern double d1mach(long *);
98 extern long i1mach(long *);
99
100/* ***BEGIN PROLOGUE DGAMLN */
101/* ***DATE WRITTEN 830501 (YYMMDD) */
102/* ***REVISION DATE 830501 (YYMMDD) */
103/* ***CATEGORY NO. B5F */
104/* ***KEYWORDS GAMMA FUNCTION,LOGARITHM OF GAMMA FUNCTION */
105/* ***AUTHOR AMOS, DONALD E., SANDIA NATIONAL LABORATORIES */
106/* ***PURPOSE TO COMPUTE THE LOGARITHM OF THE GAMMA FUNCTION */
107/* ***DESCRIPTION */
108
109/* **** A DOUBLE PRECISION ROUTINE **** */
110/* DGAMLN COMPUTES THE NATURAL LOG OF THE GAMMA FUNCTION FOR */
111/* Z.GT.0. THE ASYMPTOTIC EXPANSION IS USED TO GENERATE VALUES */
112/* GREATER THAN ZMIN WHICH ARE ADJUSTED BY THE RECURSION */
113/* G(Z+1)=Z*G(Z) FOR Z.LE.ZMIN. THE FUNCTION WAS MADE AS */
114/* PORTABLE AS POSSIBLE BY COMPUTIMG ZMIN FROM THE NUMBER OF BASE */
115/* 10 DIGITS IN A WORD, RLN=AMAX1(-ALOG10(R1MACH(4)),0.5E-18) */
116/* LIMITED TO 18 DIGITS OF (RELATIVE) ACCURACY. */
117
118/* SINCE INTEGER ARGUMENTS ARE COMMON, A TABLE LOOK UP ON 100 */
119/* VALUES IS USED FOR SPEED OF EXECUTION. */
120
121/* DESCRIPTION OF ARGUMENTS */
122
123/* INPUT Z IS D0UBLE PRECISION */
124/* Z - ARGUMENT, Z.GT.0.0D0 */
125
126/* OUTPUT DGAMLN IS DOUBLE PRECISION */
127/* DGAMLN - NATURAL LOG OF THE GAMMA FUNCTION AT Z.NE.0.0D0 */
128/* IERR - ERROR FLAG */
129/* IERR=0, NORMAL RETURN, COMPUTATION COMPLETED */
130/* IERR=1, Z.LE.0.0D0, NO COMPUTATION */
131
132
133/* ***REFERENCES COMPUTATION OF BESSEL FUNCTIONS OF COMPLEX ARGUMENT */
134/* BY D. E. AMOS, SAND83-0083, MAY, 1983. */
135/* ***ROUTINES CALLED I1MACH,D1MACH */
136/* ***END PROLOGUE DGAMLN */
137/* LNGAMMA(N), N=1,100 */
138/* COEFFICIENTS OF ASYMPTOTIC EXPANSION */
139
140/* LN(2*PI) */
141
142/* ***FIRST EXECUTABLE STATEMENT DGAMLN */
143 *ierr = 0;
144 if (*z__ <= 0.) {
145 goto L70;
146 }
147 if (*z__ > 101.) {
148 goto L10;
149 }
150 nz = (long) ((float) (*z__));
151 fz = *z__ - (float) nz;
152 if (fz > 0.) {
153 goto L10;
154 }
155 if (nz > 100) {
156 goto L10;
157 }
158 ret_val = gln[nz - 1];
159 return ret_val;
160 L10:
161 wdtol = d1mach(&c__4);
162 wdtol = max(wdtol, 5e-19);
163 i1m = i1mach(&c__14);
164 rln = d1mach(&c__5) * (float) i1m;
165 fln = min(rln, 20.);
166 fln = max(fln, 3.);
167 fln += -3.;
168 zm = fln * .3875 + 1.8;
169 mz = (long) ((float) zm) + 1;
170 zmin = (float) mz;
171 zdmy = *z__;
172 zinc = 0.;
173 if (*z__ >= zmin) {
174 goto L20;
175 }
176 zinc = zmin - (float) nz;
177 zdmy = *z__ + zinc;
178 L20:
179 zp = 1. / zdmy;
180 t1 = cf[0] * zp;
181 s = t1;
182 if (zp < wdtol) {
183 goto L40;
184 }
185 zsq = zp * zp;
186 tst = t1 * wdtol;
187 for (k = 2; k <= 22; ++k) {
188 zp *= zsq;
189 trm = cf[k - 1] * zp;
190 if (abs(trm) < tst) {
191 goto L40;
192 }
193 s += trm;
194/* L30: */
195 }
196 L40:
197 if (zinc != 0.) {
198 goto L50;
199 }
200 tlg = log(*z__);
201 ret_val = *z__ * (tlg - 1.) + (con - tlg) * .5 + s;
202 return ret_val;
203 L50:
204 zp = 1.;
205 nz = (long) ((float) zinc);
206 i__1 = nz;
207 for (i__ = 1; i__ <= i__1; ++i__) {
208 zp *= *z__ + (float) (i__ - 1);
209/* L60: */
210 }
211 tlg = log(zdmy);
212 ret_val = zdmy * (tlg - 1.) - log(zp) + (con - tlg) * .5 + s;
213 return ret_val;
214
215
216 L70:
217 *ierr = 1;
218 return ret_val;
219} /* dgamln_ */
220
221/* Subroutine */ int dsclmr(void)
222{
223/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
224/* * ISSUED BY SANDIA LABORATORIES, */
225/* * A PRIME CONTRACTOR TO THE */
226/* * UNITED STATES DEPARTMENT OF ENERGY */
227/* * * * * * * * * * * * * * * NOTICE * * * * * * * * * * * * * * * */
228/* * THIS REPORT WAS PREPARED AS AN ACCOUNT OF WORK SPONSORED BY THE */
229/* * UNITED STATES GOVERNMENT. NEITHER THE UNITED STATES NOR THE */
230/* * UNITED STATES DEPARTMENT OF ENERGY, NOR ANY OF THEIR */
231/* * EMPLOYEES, NOR ANY OF THEIR CONTRACTORS, SUBCONTRACTORS, OR THEIR */
232/* * EMPLOYEES, MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR ASSUMES ANY */
233/* * LEGAL LIABILITY OR RESPONSIBILITY FOR THE ACCURACY, COMPLETENESS */
234/* * OR USEFULNESS OF ANY INFORMATION, APPARATUS, PRODUCT OR PROCESS */
235/* * DISCLOSED, OR REPRESENTS THAT ITS USE WOULD NOT INFRINGE */
236/* * PRIVATELY OWNED RIGHTS. */
237/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
238/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
239/* * THIS CODE HAS BEEN APPROVED FOR UNLIMITED RELEASE. */
240/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
241 return 0;
242} /* dsclmr_ */
243
244/* Subroutine */ int fdump(void)
245{
246/* ***BEGIN PROLOGUE FDUMP */
247/* ***DATE WRITTEN 790801 (YYMMDD) */
248/* ***REVISION DATE 861211 (YYMMDD) */
249/* ***CATEGORY NO. R3 */
250/* ***KEYWORDS LIBRARY=SLATEC(XERROR),TYPE=ALL(FDUMP-A),ERROR */
251/* ***AUTHOR JONES, R. E., (SNLA) */
252/* ***PURPOSE Symbolic dump (should be locally written). */
253/* ***DESCRIPTION */
254
255/* ***Note*** Machine Dependent Routine */
256/* FDUMP is intended to be replaced by a locally written */
257/* version which produces a symbolic dump. Failing this, */
258/* it should be replaced by a version which prints the */
259/* subprogram nesting list. Note that this dump must be */
260/* printed on each of up to five files, as indicated by the */
261/* XGETUA routine. See XSETUA and XGETUA for details. */
262
263/* Written by Ron Jones, with SLATEC Common Math Library Subcommittee */
264/* ***REFERENCES (NONE) */
265/* ***ROUTINES CALLED (NONE) */
266/* ***END PROLOGUE FDUMP */
267/* ***FIRST EXECUTABLE STATEMENT FDUMP */
268 return 0;
269} /* fdump_ */
270
271double azabs(double *zr, double *zi)
272{
273 /* System generated locals */
274 double ret_val;
275
276 /* Builtin functions */
277 double sqrt(double);
278
279 /* Local variables */
280 double q, s, u, v;
281
282/* ***BEGIN PROLOGUE AZABS */
283/* ***REFER TO ZBESH,ZBESI,ZBESJ,ZBESK,ZBESY,ZAIRY,ZBIRY */
284
285/* AZABS COMPUTES THE ABSOLUTE VALUE OR MAGNITUDE OF A DOUBLE */
286/* PRECISION COMPLEX VARIABLE CMPLX(ZR,ZI) */
287
288/* ***ROUTINES CALLED (NONE) */
289/* ***END PROLOGUE AZABS */
290 u = abs(*zr);
291 v = abs(*zi);
292 s = u + v;
293/* ----------------------------------------------------------------------- */
294/* S*1.0D0 MAKES AN UNNORMALIZED UNDERFLOW ON CDC MACHINES INTO A */
295/* TRUE FLOATING ZERO */
296/* ----------------------------------------------------------------------- */
297 s *= 1.;
298 if (s == 0.) {
299 goto L20;
300 }
301 if (u > v) {
302 goto L10;
303 }
304 q = u / v;
305 ret_val = v * sqrt(q * q + 1.);
306 return ret_val;
307 L10:
308 q = v / u;
309 ret_val = u * sqrt(q * q + 1.);
310 return ret_val;
311 L20:
312 ret_val = 0.;
313 return ret_val;
314} /* azabs_ */
315
316/* Subroutine */ int zacai(double *zr, double *zi, double *fnu,
317 long *kode, long *mr, long *n, double *yr,
318 double *yi, long *nz, double *rl, double *tol,
319 double *elim, double *alim)
320{
321 /* Initialized data */
322
323 double pi = 3.14159265358979324;
324
325 /* Builtin functions */
326 double d_sign(double *, double *), sin(double), cos(double);
327
328 /* Local variables */
329 double az;
330 long nn, nw;
331 double yy, c1i, c2i, c1r, c2r, arg;
332 long iuf;
333 double cyi[2], fmr, sgn;
334 long inu;
335 double cyr[2], zni, znr, dfnu;
336 extern /* Subroutine */ int zs1s2(double *, double *, double
337 *, double *, double *, double *,
338 long *, double *, double *, long *);
339 double ascle;
340 extern double azabs(double *, double *);
341 double csgni, csgnr, cspni, cspnr;
342 extern /* Subroutine */ int zbknu(double *, double *, double
343 *, long *, long *, double *,
344 double *, long *, double *, double *,
345 double *), zseri(double *, double *,
346 double *, long *,
347 long *, double *,
348 double *, long *,
349 double *, double *,
350 double *);
351 extern double d1mach(long *);
352 extern /* Subroutine */ int zmlri(double *, double *, double
353 *, long *, long *, double *,
354 double *, long *, double *),
355 zasyi(double *, double *, double *, long *, long *, double *,
356 double *, long *, double *, double *, double *, double *);
357
358/* ***BEGIN PROLOGUE ZACAI */
359/* ***REFER TO ZAIRY */
360
361/* ZACAI APPLIES THE ANALYTIC CONTINUATION FORMULA */
362
363/* K(FNU,ZN*EXP(MP))=K(FNU,ZN)*EXP(-MP*FNU) - MP*I(FNU,ZN) */
364/* MP=PI*MR*CMPLX(0.0,1.0) */
365
366/* TO CONTINUE THE K FUNCTION FROM THE RIGHT HALF TO THE LEFT */
367/* HALF Z PLANE FOR USE WITH ZAIRY WHERE FNU=1/3 OR 2/3 AND N=1. */
368/* ZACAI IS THE SAME AS ZACON WITH THE PARTS FOR LARGER ORDERS AND */
369/* RECURRENCE REMOVED. A RECURSIVE CALL TO ZACON CAN RESULT IF ZACON */
370/* IS CALLED FROM ZAIRY. */
371
372/* ***ROUTINES CALLED ZASYI,ZBKNU,ZMLRI,ZSERI,ZS1S2,D1MACH,AZABS */
373/* ***END PROLOGUE ZACAI */
374/* COMPLEX CSGN,CSPN,C1,C2,Y,Z,ZN,CY */
375 /* Parameter adjustments */
376 --yi;
377 --yr;
378
379 /* Function Body */
380 *nz = 0;
381 znr = -(*zr);
382 zni = -(*zi);
383 az = azabs(zr, zi);
384 nn = *n;
385 dfnu = *fnu + (double) ((float) (*n - 1));
386 if (az <= 2.) {
387 goto L10;
388 }
389 if (az * az * .25 > dfnu + 1.) {
390 goto L20;
391 }
392 L10:
393/* ----------------------------------------------------------------------- */
394/* POWER SERIES FOR THE I FUNCTION */
395/* ----------------------------------------------------------------------- */
396 zseri(&znr, &zni, fnu, kode, &nn, &yr[1], &yi[1], &nw, tol, elim,
397 alim);
398 goto L40;
399 L20:
400 if (az < *rl) {
401 goto L30;
402 }
403/* ----------------------------------------------------------------------- */
404/* ASYMPTOTIC EXPANSION FOR LARGE Z FOR THE I FUNCTION */
405/* ----------------------------------------------------------------------- */
406 zasyi(&znr, &zni, fnu, kode, &nn, &yr[1], &yi[1], &nw, rl, tol, elim,
407 alim);
408 if (nw < 0) {
409 goto L80;
410 }
411 goto L40;
412 L30:
413/* ----------------------------------------------------------------------- */
414/* MILLER ALGORITHM NORMALIZED BY THE SERIES FOR THE I FUNCTION */
415/* ----------------------------------------------------------------------- */
416 zmlri(&znr, &zni, fnu, kode, &nn, &yr[1], &yi[1], &nw, tol);
417 if (nw < 0) {
418 goto L80;
419 }
420 L40:
421/* ----------------------------------------------------------------------- */
422/* ANALYTIC CONTINUATION TO THE LEFT HALF PLANE FOR THE K FUNCTION */
423/* ----------------------------------------------------------------------- */
424 zbknu(&znr, &zni, fnu, kode, &c__1, cyr, cyi, &nw, tol, elim, alim);
425 if (nw != 0) {
426 goto L80;
427 }
428 fmr = (double) ((float) (*mr));
429 sgn = -d_sign(&pi, &fmr);
430 csgnr = 0.;
431 csgni = sgn;
432 if (*kode == 1) {
433 goto L50;
434 }
435 yy = -zni;
436 csgnr = -csgni * sin(yy);
437 csgni *= cos(yy);
438 L50:
439/* ----------------------------------------------------------------------- */
440/* CALCULATE CSPN=EXP(FNU*PI*I) TO MINIMIZE LOSSES OF SIGNIFICANCE */
441/* WHEN FNU IS LARGE */
442/* ----------------------------------------------------------------------- */
443 inu = (long) ((float) (*fnu));
444 arg = (*fnu - (double) ((float) inu)) * sgn;
445 cspnr = cos(arg);
446 cspni = sin(arg);
447 if (inu % 2 == 0) {
448 goto L60;
449 }
450 cspnr = -cspnr;
451 cspni = -cspni;
452 L60:
453 c1r = cyr[0];
454 c1i = cyi[0];
455 c2r = yr[1];
456 c2i = yi[1];
457 if (*kode == 1) {
458 goto L70;
459 }
460 iuf = 0;
461 ascle = d1mach(&c__1) * 1e3 / *tol;
462 zs1s2(&znr, &zni, &c1r, &c1i, &c2r, &c2i, &nw, &ascle, alim, &iuf);
463 *nz += nw;
464 L70:
465 yr[1] = cspnr * c1r - cspni * c1i + csgnr * c2r - csgni * c2i;
466 yi[1] = cspnr * c1i + cspni * c1r + csgnr * c2i + csgni * c2r;
467 return 0;
468 L80:
469 *nz = -1;
470 if (nw == -2) {
471 *nz = -2;
472 }
473 return 0;
474} /* zacai_ */
475
476/* Subroutine */ int zacon(double *zr, double *zi, double *fnu,
477 long *kode, long *mr, long *n, double *yr,
478 double *yi, long *nz, double *rl, double *fnul,
479 double *tol, double *elim, double *alim)
480{
481 /* Initialized data */
482
483 double pi = 3.14159265358979324;
484 double zeror = 0.;
485 double coner = 1.;
486
487 /* System generated locals */
488 long i__1;
489
490 /* Builtin functions */
491 double d_sign(double *, double *), cos(double), sin(double);
492
493 /* Local variables */
494 long i__;
495 double fn;
496 long nn, nw;
497 double yy, c1i, c2i, c1m, as2, c1r, c2r, s1i, s2i, s1r, s2r,
498 cki, arg, ckr, cpn;
499 long iuf;
500 double cyi[2], fmr, csr, azn, sgn;
501 long inu;
502 double bry[3], cyr[2], pti, spn, sti, zni, rzi, ptr, str, znr,
503 rzr, sc1i, sc2i, sc1r, sc2r, cscl, cscr, csrr[3], cssr[3], razn;
504 extern /* Subroutine */ int zs1s2(double *, double *, double
505 *, double *, double *, double *,
506 long *, double *, double *, long *),
507 zmlt(double *, double *, double *, double *, double *, double *);
508 long kflag;
509 double ascle, bscle;
510 extern double azabs(double *, double *);
511 double csgni, csgnr, cspni, cspnr;
512 extern /* Subroutine */ int zbinu(double *, double *, double
513 *, long *, long *, double *,
514 double *, long *, double *, double *,
515 double *, double *, double *),
516 zbknu(double *, double *, double *, long *, long *, double *,
517 double *, long *, double *, double *, double *);
518 extern double d1mach(long *);
519
520/* ***BEGIN PROLOGUE ZACON */
521/* ***REFER TO ZBESK,ZBESH */
522
523/* ZACON APPLIES THE ANALYTIC CONTINUATION FORMULA */
524
525/* K(FNU,ZN*EXP(MP))=K(FNU,ZN)*EXP(-MP*FNU) - MP*I(FNU,ZN) */
526/* MP=PI*MR*CMPLX(0.0,1.0) */
527
528/* TO CONTINUE THE K FUNCTION FROM THE RIGHT HALF TO THE LEFT */
529/* HALF Z PLANE */
530
531/* ***ROUTINES CALLED ZBINU,ZBKNU,ZS1S2,D1MACH,AZABS,ZMLT */
532/* ***END PROLOGUE ZACON */
533/* COMPLEX CK,CONE,CSCL,CSCR,CSGN,CSPN,CY,CZERO,C1,C2,RZ,SC1,SC2,ST, */
534/* *S1,S2,Y,Z,ZN */
535 /* Parameter adjustments */
536 --yi;
537 --yr;
538
539 /* Function Body */
540 *nz = 0;
541 znr = -(*zr);
542 zni = -(*zi);
543 nn = *n;
544 zbinu(&znr, &zni, fnu, kode, &nn, &yr[1], &yi[1], &nw, rl, fnul, tol,
545 elim, alim);
546 if (nw < 0) {
547 goto L90;
548 }
549/* ----------------------------------------------------------------------- */
550/* ANALYTIC CONTINUATION TO THE LEFT HALF PLANE FOR THE K FUNCTION */
551/* ----------------------------------------------------------------------- */
552 nn = min(2, *n);
553 zbknu(&znr, &zni, fnu, kode, &nn, cyr, cyi, &nw, tol, elim, alim);
554 if (nw != 0) {
555 goto L90;
556 }
557 s1r = cyr[0];
558 s1i = cyi[0];
559 fmr = (double) ((float) (*mr));
560 sgn = -d_sign(&pi, &fmr);
561 csgnr = zeror;
562 csgni = sgn;
563 if (*kode == 1) {
564 goto L10;
565 }
566 yy = -zni;
567 cpn = cos(yy);
568 spn = sin(yy);
569 zmlt(&csgnr, &csgni, &cpn, &spn, &csgnr, &csgni);
570 L10:
571/* ----------------------------------------------------------------------- */
572/* CALCULATE CSPN=EXP(FNU*PI*I) TO MINIMIZE LOSSES OF SIGNIFICANCE */
573/* WHEN FNU IS LARGE */
574/* ----------------------------------------------------------------------- */
575 inu = (long) ((float) (*fnu));
576 arg = (*fnu - (double) ((float) inu)) * sgn;
577 cpn = cos(arg);
578 spn = sin(arg);
579 cspnr = cpn;
580 cspni = spn;
581 if (inu % 2 == 0) {
582 goto L20;
583 }
584 cspnr = -cspnr;
585 cspni = -cspni;
586 L20:
587 iuf = 0;
588 c1r = s1r;
589 c1i = s1i;
590 c2r = yr[1];
591 c2i = yi[1];
592 ascle = d1mach(&c__1) * 1e3 / *tol;
593 if (*kode == 1) {
594 goto L30;
595 }
596 zs1s2(&znr, &zni, &c1r, &c1i, &c2r, &c2i, &nw, &ascle, alim, &iuf);
597 *nz += nw;
598 sc1r = c1r;
599 sc1i = c1i;
600 L30:
601 zmlt(&cspnr, &cspni, &c1r, &c1i, &str, &sti);
602 zmlt(&csgnr, &csgni, &c2r, &c2i, &ptr, &pti);
603 yr[1] = str + ptr;
604 yi[1] = sti + pti;
605 if (*n == 1) {
606 return 0;
607 }
608 cspnr = -cspnr;
609 cspni = -cspni;
610 s2r = cyr[1];
611 s2i = cyi[1];
612 c1r = s2r;
613 c1i = s2i;
614 c2r = yr[2];
615 c2i = yi[2];
616 if (*kode == 1) {
617 goto L40;
618 }
619 zs1s2(&znr, &zni, &c1r, &c1i, &c2r, &c2i, &nw, &ascle, alim, &iuf);
620 *nz += nw;
621 sc2r = c1r;
622 sc2i = c1i;
623 L40:
624 zmlt(&cspnr, &cspni, &c1r, &c1i, &str, &sti);
625 zmlt(&csgnr, &csgni, &c2r, &c2i, &ptr, &pti);
626 yr[2] = str + ptr;
627 yi[2] = sti + pti;
628 if (*n == 2) {
629 return 0;
630 }
631 cspnr = -cspnr;
632 cspni = -cspni;
633 azn = azabs(&znr, &zni);
634 razn = 1. / azn;
635 str = znr * razn;
636 sti = -zni * razn;
637 rzr = (str + str) * razn;
638 rzi = (sti + sti) * razn;
639 fn = *fnu + 1.;
640 ckr = fn * rzr;
641 cki = fn * rzi;
642/* ----------------------------------------------------------------------- */
643/* SCALE NEAR EXPONENT EXTREMES DURING RECURRENCE ON K FUNCTIONS */
644/* ----------------------------------------------------------------------- */
645 cscl = 1. / *tol;
646 cscr = *tol;
647 cssr[0] = cscl;
648 cssr[1] = coner;
649 cssr[2] = cscr;
650 csrr[0] = cscr;
651 csrr[1] = coner;
652 csrr[2] = cscl;
653 bry[0] = ascle;
654 bry[1] = 1. / ascle;
655 bry[2] = d1mach(&c__2);
656 as2 = azabs(&s2r, &s2i);
657 kflag = 2;
658 if (as2 > bry[0]) {
659 goto L50;
660 }
661 kflag = 1;
662 goto L60;
663 L50:
664 if (as2 < bry[1]) {
665 goto L60;
666 }
667 kflag = 3;
668 L60:
669 bscle = bry[kflag - 1];
670 s1r *= cssr[kflag - 1];
671 s1i *= cssr[kflag - 1];
672 s2r *= cssr[kflag - 1];
673 s2i *= cssr[kflag - 1];
674 csr = csrr[kflag - 1];
675 i__1 = *n;
676 for (i__ = 3; i__ <= i__1; ++i__) {
677 str = s2r;
678 sti = s2i;
679 s2r = ckr * str - cki * sti + s1r;
680 s2i = ckr * sti + cki * str + s1i;
681 s1r = str;
682 s1i = sti;
683 c1r = s2r * csr;
684 c1i = s2i * csr;
685 str = c1r;
686 sti = c1i;
687 c2r = yr[i__];
688 c2i = yi[i__];
689 if (*kode == 1) {
690 goto L70;
691 }
692 if (iuf < 0) {
693 goto L70;
694 }
695 zs1s2(&znr, &zni, &c1r, &c1i, &c2r, &c2i, &nw, &ascle, alim, &iuf);
696 *nz += nw;
697 sc1r = sc2r;
698 sc1i = sc2i;
699 sc2r = c1r;
700 sc2i = c1i;
701 if (iuf != 3) {
702 goto L70;
703 }
704 iuf = -4;
705 s1r = sc1r * cssr[kflag - 1];
706 s1i = sc1i * cssr[kflag - 1];
707 s2r = sc2r * cssr[kflag - 1];
708 s2i = sc2i * cssr[kflag - 1];
709 str = sc2r;
710 sti = sc2i;
711 L70:
712 ptr = cspnr * c1r - cspni * c1i;
713 pti = cspnr * c1i + cspni * c1r;
714 yr[i__] = ptr + csgnr * c2r - csgni * c2i;
715 yi[i__] = pti + csgnr * c2i + csgni * c2r;
716 ckr += rzr;
717 cki += rzi;
718 cspnr = -cspnr;
719 cspni = -cspni;
720 if (kflag >= 3) {
721 goto L80;
722 }
723 ptr = abs(c1r);
724 pti = abs(c1i);
725 c1m = max(ptr, pti);
726 if (c1m <= bscle) {
727 goto L80;
728 }
729 ++kflag;
730 bscle = bry[kflag - 1];
731 s1r *= csr;
732 s1i *= csr;
733 s2r = str;
734 s2i = sti;
735 s1r *= cssr[kflag - 1];
736 s1i *= cssr[kflag - 1];
737 s2r *= cssr[kflag - 1];
738 s2i *= cssr[kflag - 1];
739 csr = csrr[kflag - 1];
740 L80:
741 ;
742 }
743 return 0;
744 L90:
745 *nz = -1;
746 if (nw == -2) {
747 *nz = -2;
748 }
749 return 0;
750} /* zacon_ */
751
752/* Subroutine */ int zairy(double *zr, double *zi, long *id,
753 long *kode, double *air, double *aii, long *nz, long
754 *ierr)
755{
756 /* Initialized data */
757
758 double tth = .666666666666666667;
759 double c1 = .35502805388781724;
760 double c2 = .258819403792806799;
761 double coef = .183776298473930683;
762 double zeror = 0.;
763 double zeroi = 0.;
764 double coner = 1.;
765 double conei = 0.;
766
767 /* System generated locals */
768 long i__1, i__2;
769 double d__1;
770
771 /* Builtin functions */
772 double log(double), pow_dd(double *, double *), sqrt(double);
773
774 /* Local variables */
775 long k;
776 double d1, d2;
777 long k1, k2;
778 double aa, bb, ad, cc, ak, bk, ck, dk, az;
779 long nn;
780 double rl;
781 long mr;
782 double s1i, az3, s2i, s1r, s2r, z3i, z3r, dig, fid, cyi[1],
783 r1m5, fnu, cyr[1], tol, sti, ptr, str, sfac, alim, elim, alaz,
784 csqi, atrm, ztai, csqr, ztar, trm1i, trm2i, trm1r, trm2r;
785 long iflag;
786 extern /* Subroutine */ int zacai(double *, double *, double
787 *, long *, long *, long *, double *,
788 double *, long *, double *, double *,
789 double *, double *);
790 extern double azabs(double *, double *);
791 extern /* Subroutine */ int azexp(double *, double *, double
792 *, double *), zbknu(double *,
793 double *,
794 double *, long *,
795 long *, double *,
796 double *, long *,
797 double *,
798 double *,
799 double *);
800 extern double d1mach(long *);
801 extern long i1mach(long *);
802 extern /* Subroutine */ int azsqrt(double *, double *,
803 double *, double *);
804
805/* ***BEGIN PROLOGUE ZAIRY */
806/* ***DATE WRITTEN 830501 (YYMMDD) */
807/* ***REVISION DATE 890801 (YYMMDD) */
808/* ***CATEGORY NO. B5K */
809/* ***KEYWORDS AIRY FUNCTION,BESSEL FUNCTIONS OF ORDER ONE THIRD */
810/* ***AUTHOR AMOS, DONALD E., SANDIA NATIONAL LABORATORIES */
811/* ***PURPOSE TO COMPUTE AIRY FUNCTIONS AI(Z) AND DAI(Z) FOR COMPLEX Z */
812/* ***DESCRIPTION */
813
814/* ***A DOUBLE PRECISION ROUTINE*** */
815/* ON KODE=1, ZAIRY COMPUTES THE COMPLEX AIRY FUNCTION AI(Z) OR */
816/* ITS DERIVATIVE DAI(Z)/DZ ON ID=0 OR ID=1 RESPECTIVELY. ON */
817/* KODE=2, A SCALING OPTION CEXP(ZTA)*AI(Z) OR CEXP(ZTA)* */
818/* DAI(Z)/DZ IS PROVIDED TO REMOVE THE EXPONENTIAL DECAY IN */
819/* -PI/3.LT.ARG(Z).LT.PI/3 AND THE EXPONENTIAL GROWTH IN */
820/* PI/3.LT.ABS(ARG(Z)).LT.PI WHERE ZTA=(2/3)*Z*CSQRT(Z). */
821
822/* WHILE THE AIRY FUNCTIONS AI(Z) AND DAI(Z)/DZ ARE ANALYTIC IN */
823/* THE WHOLE Z PLANE, THE CORRESPONDING SCALED FUNCTIONS DEFINED */
824/* FOR KODE=2 HAVE A CUT ALONG THE NEGATIVE REAL AXIS. */
825/* DEFINTIONS AND NOTATION ARE FOUND IN THE NBS HANDBOOK OF */
826/* MATHEMATICAL FUNCTIONS (REF. 1). */
827
828/* INPUT ZR,ZI ARE DOUBLE PRECISION */
829/* ZR,ZI - Z=CMPLX(ZR,ZI) */
830/* ID - ORDER OF DERIVATIVE, ID=0 OR ID=1 */
831/* KODE - A PARAMETER TO INDICATE THE SCALING OPTION */
832/* KODE= 1 RETURNS */
833/* AI=AI(Z) ON ID=0 OR */
834/* AI=DAI(Z)/DZ ON ID=1 */
835/* = 2 RETURNS */
836/* AI=CEXP(ZTA)*AI(Z) ON ID=0 OR */
837/* AI=CEXP(ZTA)*DAI(Z)/DZ ON ID=1 WHERE */
838/* ZTA=(2/3)*Z*CSQRT(Z) */
839
840/* OUTPUT AIR,AII ARE DOUBLE PRECISION */
841/* AIR,AII- COMPLEX ANSWER DEPENDING ON THE CHOICES FOR ID AND */
842/* KODE */
843/* NZ - UNDERFLOW INDICATOR */
844/* NZ= 0 , NORMAL RETURN */
845/* NZ= 1 , AI=CMPLX(0.0D0,0.0D0) DUE TO UNDERFLOW IN */
846/* -PI/3.LT.ARG(Z).LT.PI/3 ON KODE=1 */
847/* IERR - ERROR FLAG */
848/* IERR=0, NORMAL RETURN - COMPUTATION COMPLETED */
849/* IERR=1, INPUT ERROR - NO COMPUTATION */
850/* IERR=2, OVERFLOW - NO COMPUTATION, REAL(ZTA) */
851/* TOO LARGE ON KODE=1 */
852/* IERR=3, CABS(Z) LARGE - COMPUTATION COMPLETED */
853/* LOSSES OF SIGNIFCANCE BY ARGUMENT REDUCTION */
854/* PRODUCE LESS THAN HALF OF MACHINE ACCURACY */
855/* IERR=4, CABS(Z) TOO LARGE - NO COMPUTATION */
856/* COMPLETE LOSS OF ACCURACY BY ARGUMENT */
857/* REDUCTION */
858/* IERR=5, ERROR - NO COMPUTATION, */
859/* ALGORITHM TERMINATION CONDITION NOT MET */
860
861/* ***LONG DESCRIPTION */
862
863/* AI AND DAI ARE COMPUTED FOR CABS(Z).GT.1.0 FROM THE K BESSEL */
864/* FUNCTIONS BY */
865
866/* AI(Z)=C*SQRT(Z)*K(1/3,ZTA) , DAI(Z)=-C*Z*K(2/3,ZTA) */
867/* C=1.0/(PI*SQRT(3.0)) */
868/* ZTA=(2/3)*Z**(3/2) */
869
870/* WITH THE POWER SERIES FOR CABS(Z).LE.1.0. */
871
872/* IN MOST COMPLEX VARIABLE COMPUTATION, ONE MUST EVALUATE ELE- */
873/* MENTARY FUNCTIONS. WHEN THE MAGNITUDE OF Z IS LARGE, LOSSES */
874/* OF SIGNIFICANCE BY ARGUMENT REDUCTION OCCUR. CONSEQUENTLY, IF */
875/* THE MAGNITUDE OF ZETA=(2/3)*Z**1.5 EXCEEDS U1=SQRT(0.5/UR), */
876/* THEN LOSSES EXCEEDING HALF PRECISION ARE LIKELY AND AN ERROR */
877/* FLAG IERR=3 IS TRIGGERED WHERE UR=DMAX1(D1MACH(4),1.0D-18) IS */
878/* DOUBLE PRECISION UNIT ROUNDOFF LIMITED TO 18 DIGITS PRECISION. */
879/* ALSO, IF THE MAGNITUDE OF ZETA IS LARGER THAN U2=0.5/UR, THEN */
880/* ALL SIGNIFICANCE IS LOST AND IERR=4. IN ORDER TO USE THE INT */
881/* FUNCTION, ZETA MUST BE FURTHER RESTRICTED NOT TO EXCEED THE */
882/* LARGEST INTEGER, U3=I1MACH(9). THUS, THE MAGNITUDE OF ZETA */
883/* MUST BE RESTRICTED BY MIN(U2,U3). ON 32 BIT MACHINES, U1,U2, */
884/* AND U3 ARE APPROXIMATELY 2.0E+3, 4.2E+6, 2.1E+9 IN SINGLE */
885/* PRECISION ARITHMETIC AND 1.3E+8, 1.8E+16, 2.1E+9 IN DOUBLE */
886/* PRECISION ARITHMETIC RESPECTIVELY. THIS MAKES U2 AND U3 LIMIT- */
887/* ING IN THEIR RESPECTIVE ARITHMETICS. THIS MEANS THAT THE MAG- */
888/* NITUDE OF Z CANNOT EXCEED 3.1E+4 IN SINGLE AND 2.1E+6 IN */
889/* DOUBLE PRECISION ARITHMETIC. THIS ALSO MEANS THAT ONE CAN */
890/* EXPECT TO RETAIN, IN THE WORST CASES ON 32 BIT MACHINES, */
891/* NO DIGITS IN SINGLE PRECISION AND ONLY 7 DIGITS IN DOUBLE */
892/* PRECISION ARITHMETIC. SIMILAR CONSIDERATIONS HOLD FOR OTHER */
893/* MACHINES. */
894
895/* THE APPROXIMATE RELATIVE ERROR IN THE MAGNITUDE OF A COMPLEX */
896/* BESSEL FUNCTION CAN BE EXPRESSED BY P*10**S WHERE P=MAX(UNIT */
897/* ROUNDOFF,1.0E-18) IS THE NOMINAL PRECISION AND 10**S REPRE- */
898/* SENTS THE INCREASE IN ERROR DUE TO ARGUMENT REDUCTION IN THE */
899/* ELEMENTARY FUNCTIONS. HERE, S=MAX(1,ABS(LOG10(CABS(Z))), */
900/* ABS(LOG10(FNU))) APPROXIMATELY (I.E. S=MAX(1,ABS(EXPONENT OF */
901/* CABS(Z),ABS(EXPONENT OF FNU)) ). HOWEVER, THE PHASE ANGLE MAY */
902/* HAVE ONLY ABSOLUTE ACCURACY. THIS IS MOST LIKELY TO OCCUR WHEN */
903/* ONE COMPONENT (IN ABSOLUTE VALUE) IS LARGER THAN THE OTHER BY */
904/* SEVERAL ORDERS OF MAGNITUDE. IF ONE COMPONENT IS 10**K LARGER */
905/* THAN THE OTHER, THEN ONE CAN EXPECT ONLY MAX(ABS(LOG10(P))-K, */
906/* 0) SIGNIFICANT DIGITS; OR, STATED ANOTHER WAY, WHEN K EXCEEDS */
907/* THE EXPONENT OF P, NO SIGNIFICANT DIGITS REMAIN IN THE SMALLER */
908/* COMPONENT. HOWEVER, THE PHASE ANGLE RETAINS ABSOLUTE ACCURACY */
909/* BECAUSE, IN COMPLEX ARITHMETIC WITH PRECISION P, THE SMALLER */
910/* COMPONENT WILL NOT (AS A RULE) DECREASE BELOW P TIMES THE */
911/* MAGNITUDE OF THE LARGER COMPONENT. IN THESE EXTREME CASES, */
912/* THE PRINCIPAL PHASE ANGLE IS ON THE ORDER OF +P, -P, PI/2-P, */
913/* OR -PI/2+P. */
914
915/* ***REFERENCES HANDBOOK OF MATHEMATICAL FUNCTIONS BY M. ABRAMOWITZ */
916/* AND I. A. STEGUN, NBS AMS SERIES 55, U.S. DEPT. OF */
917/* COMMERCE, 1955. */
918
919/* COMPUTATION OF BESSEL FUNCTIONS OF COMPLEX ARGUMENT */
920/* AND LARGE ORDER BY D. E. AMOS, SAND83-0643, MAY, 1983 */
921
922/* A SUBROUTINE PACKAGE FOR BESSEL FUNCTIONS OF A COMPLEX */
923/* ARGUMENT AND NONNEGATIVE ORDER BY D. E. AMOS, SAND85- */
924/* 1018, MAY, 1985 */
925
926/* A PORTABLE PACKAGE FOR BESSEL FUNCTIONS OF A COMPLEX */
927/* ARGUMENT AND NONNEGATIVE ORDER BY D. E. AMOS, TRANS. */
928/* MATH. SOFTWARE, 1986 */
929
930/* ***ROUTINES CALLED ZACAI,ZBKNU,AZEXP,AZSQRT,I1MACH,D1MACH */
931/* ***END PROLOGUE ZAIRY */
932/* COMPLEX AI,CONE,CSQ,CY,S1,S2,TRM1,TRM2,Z,ZTA,Z3 */
933/* ***FIRST EXECUTABLE STATEMENT ZAIRY */
934 *ierr = 0;
935 *nz = 0;
936 if (*id < 0 || *id > 1) {
937 *ierr = 1;
938 }
939 if (*kode < 1 || *kode > 2) {
940 *ierr = 1;
941 }
942 if (*ierr != 0) {
943 return 0;
944 }
945 az = azabs(zr, zi);
946/* Computing MAX */
947 d__1 = d1mach(&c__4);
948 tol = max(d__1, 1e-18);
949 fid = (double) ((float) (*id));
950 if (az > 1.) {
951 goto L70;
952 }
953/* ----------------------------------------------------------------------- */
954/* POWER SERIES FOR CABS(Z).LE.1. */
955/* ----------------------------------------------------------------------- */
956 s1r = coner;
957 s1i = conei;
958 s2r = coner;
959 s2i = conei;
960 if (az < tol) {
961 goto L170;
962 }
963 aa = az * az;
964 if (aa < tol / az) {
965 goto L40;
966 }
967 trm1r = coner;
968 trm1i = conei;
969 trm2r = coner;
970 trm2i = conei;
971 atrm = 1.;
972 str = *zr * *zr - *zi * *zi;
973 sti = *zr * *zi + *zi * *zr;
974 z3r = str * *zr - sti * *zi;
975 z3i = str * *zi + sti * *zr;
976 az3 = az * aa;
977 ak = fid + 2.;
978 bk = 3. - fid - fid;
979 ck = 4. - fid;
980 dk = fid + 3. + fid;
981 d1 = ak * dk;
982 d2 = bk * ck;
983 ad = min(d1, d2);
984 ak = fid * 9. + 24.;
985 bk = 30. - fid * 9.;
986 for (k = 1; k <= 25; ++k) {
987 str = (trm1r * z3r - trm1i * z3i) / d1;
988 trm1i = (trm1r * z3i + trm1i * z3r) / d1;
989 trm1r = str;
990 s1r += trm1r;
991 s1i += trm1i;
992 str = (trm2r * z3r - trm2i * z3i) / d2;
993 trm2i = (trm2r * z3i + trm2i * z3r) / d2;
994 trm2r = str;
995 s2r += trm2r;
996 s2i += trm2i;
997 atrm = atrm * az3 / ad;
998 d1 += ak;
999 d2 += bk;
1000 ad = min(d1, d2);
1001 if (atrm < tol * ad) {
1002 goto L40;
1003 }
1004 ak += 18.;
1005 bk += 18.;
1006/* L30: */
1007 }
1008 L40:
1009 if (*id == 1) {
1010 goto L50;
1011 }
1012 *air = s1r * c1 - c2 * (*zr * s2r - *zi * s2i);
1013 *aii = s1i * c1 - c2 * (*zr * s2i + *zi * s2r);
1014 if (*kode == 1) {
1015 return 0;
1016 }
1017 azsqrt(zr, zi, &str, &sti);
1018 ztar = tth * (*zr * str - *zi * sti);
1019 ztai = tth * (*zr * sti + *zi * str);
1020 azexp(&ztar, &ztai, &str, &sti);
1021 ptr = *air * str - *aii * sti;
1022 *aii = *air * sti + *aii * str;
1023 *air = ptr;
1024 return 0;
1025 L50:
1026 *air = -s2r * c2;
1027 *aii = -s2i * c2;
1028 if (az <= tol) {
1029 goto L60;
1030 }
1031 str = *zr * s1r - *zi * s1i;
1032 sti = *zr * s1i + *zi * s1r;
1033 cc = c1 / (fid + 1.);
1034 *air += cc * (str * *zr - sti * *zi);
1035 *aii += cc * (str * *zi + sti * *zr);
1036 L60:
1037 if (*kode == 1) {
1038 return 0;
1039 }
1040 azsqrt(zr, zi, &str, &sti);
1041 ztar = tth * (*zr * str - *zi * sti);
1042 ztai = tth * (*zr * sti + *zi * str);
1043 azexp(&ztar, &ztai, &str, &sti);
1044 ptr = str * *air - sti * *aii;
1045 *aii = str * *aii + sti * *air;
1046 *air = ptr;
1047 return 0;
1048/* ----------------------------------------------------------------------- */
1049/* CASE FOR CABS(Z).GT.1.0 */
1050/* ----------------------------------------------------------------------- */
1051 L70:
1052 fnu = (fid + 1.) / 3.;
1053/* ----------------------------------------------------------------------- */
1054/* SET PARAMETERS RELATED TO MACHINE CONSTANTS. */
1055/* TOL IS THE APPROXIMATE UNIT ROUNDOFF LIMITED TO 1.0D-18. */
1056/* ELIM IS THE APPROXIMATE EXPONENTIAL OVER- AND UNDERFLOW LIMIT. */
1057/* EXP(-ELIM).LT.EXP(-ALIM)=EXP(-ELIM)/TOL AND */
1058/* EXP(ELIM).GT.EXP(ALIM)=EXP(ELIM)*TOL ARE INTERVALS NEAR */
1059/* UNDERFLOW AND OVERFLOW LIMITS WHERE SCALED ARITHMETIC IS DONE. */
1060/* RL IS THE LOWER BOUNDARY OF THE ASYMPTOTIC EXPANSION FOR LARGE Z. */
1061/* DIG = NUMBER OF BASE 10 DIGITS IN TOL = 10**(-DIG). */
1062/* ----------------------------------------------------------------------- */
1063 k1 = i1mach(&c__15);
1064 k2 = i1mach(&c__16);
1065 r1m5 = d1mach(&c__5);
1066/* Computing MIN */
1067 i__1 = abs(k1), i__2 = abs(k2);
1068 k = min(i__1, i__2);
1069 elim = ((double) ((float) k) * r1m5 - 3.) * 2.303;
1070 k1 = i1mach(&c__14) - 1;
1071 aa = r1m5 * (double) ((float) k1);
1072 dig = min(aa, 18.);
1073 aa *= 2.303;
1074/* Computing MAX */
1075 d__1 = -aa;
1076 alim = elim + max(d__1, -41.45);
1077 rl = dig * 1.2 + 3.;
1078 alaz = log(az);
1079/* -------------------------------------------------------------------------- */
1080/* TEST FOR PROPER RANGE */
1081/* ----------------------------------------------------------------------- */
1082 aa = .5 / tol;
1083 bb = (double) ((float) i1mach(&c__9)) * .5;
1084 aa = min(aa, bb);
1085 aa = pow_dd(&aa, &tth);
1086 if (az > aa) {
1087 goto L260;
1088 }
1089 aa = sqrt(aa);
1090 if (az > aa) {
1091 *ierr = 3;
1092 }
1093 azsqrt(zr, zi, &csqr, &csqi);
1094 ztar = tth * (*zr * csqr - *zi * csqi);
1095 ztai = tth * (*zr * csqi + *zi * csqr);
1096/* ----------------------------------------------------------------------- */
1097/* RE(ZTA).LE.0 WHEN RE(Z).LT.0, ESPECIALLY WHEN IM(Z) IS SMALL */
1098/* ----------------------------------------------------------------------- */
1099 iflag = 0;
1100 sfac = 1.;
1101 ak = ztai;
1102 if (*zr >= 0.) {
1103 goto L80;
1104 }
1105 bk = ztar;
1106 ck = -abs(bk);
1107 ztar = ck;
1108 ztai = ak;
1109 L80:
1110 if (*zi != 0.) {
1111 goto L90;
1112 }
1113 if (*zr > 0.) {
1114 goto L90;
1115 }
1116 ztar = 0.;
1117 ztai = ak;
1118 L90:
1119 aa = ztar;
1120 if (aa >= 0. && *zr > 0.) {
1121 goto L110;
1122 }
1123 if (*kode == 2) {
1124 goto L100;
1125 }
1126/* ----------------------------------------------------------------------- */
1127/* OVERFLOW TEST */
1128/* ----------------------------------------------------------------------- */
1129 if (aa > -alim) {
1130 goto L100;
1131 }
1132 aa = -aa + alaz * .25;
1133 iflag = 1;
1134 sfac = tol;
1135 if (aa > elim) {
1136 goto L270;
1137 }
1138 L100:
1139/* ----------------------------------------------------------------------- */
1140/* CBKNU AND CACON RETURN EXP(ZTA)*K(FNU,ZTA) ON KODE=2 */
1141/* ----------------------------------------------------------------------- */
1142 mr = 1;
1143 if (*zi < 0.) {
1144 mr = -1;
1145 }
1146 zacai(&ztar, &ztai, &fnu, kode, &mr, &c__1, cyr, cyi, &nn, &rl, &tol,
1147 &elim, &alim);
1148 if (nn < 0) {
1149 goto L280;
1150 }
1151 *nz += nn;
1152 goto L130;
1153 L110:
1154 if (*kode == 2) {
1155 goto L120;
1156 }
1157/* ----------------------------------------------------------------------- */
1158/* UNDERFLOW TEST */
1159/* ----------------------------------------------------------------------- */
1160 if (aa < alim) {
1161 goto L120;
1162 }
1163 aa = -aa - alaz * .25;
1164 iflag = 2;
1165 sfac = 1. / tol;
1166 if (aa < -elim) {
1167 goto L210;
1168 }
1169 L120:
1170 zbknu(&ztar, &ztai, &fnu, kode, &c__1, cyr, cyi, nz, &tol, &elim,
1171 &alim);
1172 L130:
1173 s1r = cyr[0] * coef;
1174 s1i = cyi[0] * coef;
1175 if (iflag != 0) {
1176 goto L150;
1177 }
1178 if (*id == 1) {
1179 goto L140;
1180 }
1181 *air = csqr * s1r - csqi * s1i;
1182 *aii = csqr * s1i + csqi * s1r;
1183 return 0;
1184 L140:
1185 *air = -(*zr * s1r - *zi * s1i);
1186 *aii = -(*zr * s1i + *zi * s1r);
1187 return 0;
1188 L150:
1189 s1r *= sfac;
1190 s1i *= sfac;
1191 if (*id == 1) {
1192 goto L160;
1193 }
1194 str = s1r * csqr - s1i * csqi;
1195 s1i = s1r * csqi + s1i * csqr;
1196 s1r = str;
1197 *air = s1r / sfac;
1198 *aii = s1i / sfac;
1199 return 0;
1200 L160:
1201 str = -(s1r * *zr - s1i * *zi);
1202 s1i = -(s1r * *zi + s1i * *zr);
1203 s1r = str;
1204 *air = s1r / sfac;
1205 *aii = s1i / sfac;
1206 return 0;
1207 L170:
1208 aa = d1mach(&c__1) * 1e3;
1209 s1r = zeror;
1210 s1i = zeroi;
1211 if (*id == 1) {
1212 goto L190;
1213 }
1214 if (az <= aa) {
1215 goto L180;
1216 }
1217 s1r = c2 * *zr;
1218 s1i = c2 * *zi;
1219 L180:
1220 *air = c1 - s1r;
1221 *aii = -s1i;
1222 return 0;
1223 L190:
1224 *air = -c2;
1225 *aii = 0.;
1226 aa = sqrt(aa);
1227 if (az <= aa) {
1228 goto L200;
1229 }
1230 s1r = (*zr * *zr - *zi * *zi) * .5;
1231 s1i = *zr * *zi;
1232 L200:
1233 *air += c1 * s1r;
1234 *aii += c1 * s1i;
1235 return 0;
1236 L210:
1237 *nz = 1;
1238 *air = zeror;
1239 *aii = zeroi;
1240 return 0;
1241 L270:
1242 *nz = 0;
1243 *ierr = 2;
1244 return 0;
1245 L280:
1246 if (nn == -1) {
1247 goto L270;
1248 }
1249 *nz = 0;
1250 *ierr = 5;
1251 return 0;
1252 L260:
1253 *ierr = 4;
1254 *nz = 0;
1255 return 0;
1256} /* zairy_ */
1257
1258/* Subroutine */ int zasyi(double *zr, double *zi, double *fnu,
1259 long *kode, long *n, double *yr, double *yi,
1260 long *nz, double *rl, double *tol, double *elim,
1261 double *alim)
1262{
1263 /* Initialized data */
1264
1265 double pi = 3.14159265358979324;
1266 double rtpi = .159154943091895336;
1267 double zeror = 0.;
1268 double zeroi = 0.;
1269 double coner = 1.;
1270 double conei = 0.;
1271
1272 /* System generated locals */
1273 long i__1, i__2;
1274 double d__1, d__2;
1275
1276 /* Builtin functions */
1277 double sqrt(double), sin(double), cos(double);
1278
1279 /* Local variables */
1280 long i__, j, k, m;
1281 double s, aa, bb;
1282 long ib;
1283 double ak, bk;
1284 long il, jl;
1285 double az;
1286 long nn;
1287 double p1i, s2i, p1r, s2r, cki, dki, fdn, arg, aez, arm, ckr,
1288 dkr, czi, ezi, sgn;
1289 long inu;
1290 double raz, czr, ezr, sqk, sti, rzi, tzi, str, rzr, tzr, ak1i,
1291 ak1r, cs1i, cs2i, cs1r, cs2r, dnu2, rtr1, dfnu, atol;
1292 extern /* Subroutine */ int zdiv(double *, double *, double *
1293 , double *, double *, double *),
1294 zmlt(double *, double *, double *, double *, double *, double *);
1295 long koded;
1296 extern double azabs(double *, double *);
1297 extern /* Subroutine */ int azexp(double *, double *, double
1298 *, double *);
1299 extern double d1mach(long *);
1300 extern /* Subroutine */ int azsqrt(double *, double *,
1301 double *, double *);
1302
1303/* ***BEGIN PROLOGUE ZASYI */
1304/* ***REFER TO ZBESI,ZBESK */
1305
1306/* ZASYI COMPUTES THE I BESSEL FUNCTION FOR REAL(Z).GE.0.0 BY */
1307/* MEANS OF THE ASYMPTOTIC EXPANSION FOR LARGE CABS(Z) IN THE */
1308/* REGION CABS(Z).GT.MAX(RL,FNU*FNU/2). NZ=0 IS A NORMAL RETURN. */
1309/* NZ.LT.0 INDICATES AN OVERFLOW ON KODE=1. */
1310
1311/* ***ROUTINES CALLED D1MACH,AZABS,ZDIV,AZEXP,ZMLT,AZSQRT */
1312/* ***END PROLOGUE ZASYI */
1313/* COMPLEX AK1,CK,CONE,CS1,CS2,CZ,CZERO,DK,EZ,P1,RZ,S2,Y,Z */
1314 /* Parameter adjustments */
1315 --yi;
1316 --yr;
1317
1318 /* Function Body */
1319
1320 *nz = 0;
1321 az = azabs(zr, zi);
1322 arm = d1mach(&c__1) * 1e3;
1323 rtr1 = sqrt(arm);
1324 il = min(2, *n);
1325 dfnu = *fnu + (double) ((float) (*n - il));
1326/* ----------------------------------------------------------------------- */
1327/* OVERFLOW TEST */
1328/* ----------------------------------------------------------------------- */
1329 raz = 1. / az;
1330 str = *zr * raz;
1331 sti = -(*zi) * raz;
1332 ak1r = rtpi * str * raz;
1333 ak1i = rtpi * sti * raz;
1334 azsqrt(&ak1r, &ak1i, &ak1r, &ak1i);
1335 czr = *zr;
1336 czi = *zi;
1337 if (*kode != 2) {
1338 goto L10;
1339 }
1340 czr = zeror;
1341 czi = *zi;
1342 L10:
1343 if (abs(czr) > *elim) {
1344 goto L100;
1345 }
1346 dnu2 = dfnu + dfnu;
1347 koded = 1;
1348 if (abs(czr) > *alim && *n > 2) {
1349 goto L20;
1350 }
1351 koded = 0;
1352 azexp(&czr, &czi, &str, &sti);
1353 zmlt(&ak1r, &ak1i, &str, &sti, &ak1r, &ak1i);
1354 L20:
1355 fdn = 0.;
1356 if (dnu2 > rtr1) {
1357 fdn = dnu2 * dnu2;
1358 }
1359 ezr = *zr * 8.;
1360 ezi = *zi * 8.;
1361/* ----------------------------------------------------------------------- */
1362/* WHEN Z IS IMAGINARY, THE ERROR TEST MUST BE MADE RELATIVE TO THE */
1363/* FIRST RECIPROCAL POWER SINCE THIS IS THE LEADING TERM OF THE */
1364/* EXPANSION FOR THE IMAGINARY PART. */
1365/* ----------------------------------------------------------------------- */
1366 aez = az * 8.;
1367 s = *tol / aez;
1368 jl = (long) ((float) (*rl + *rl)) + 2;
1369 p1r = zeror;
1370 p1i = zeroi;
1371 if (*zi == 0.) {
1372 goto L30;
1373 }
1374/* ----------------------------------------------------------------------- */
1375/* CALCULATE EXP(PI*(0.5+FNU+N-IL)*I) TO MINIMIZE LOSSES OF */
1376/* SIGNIFICANCE WHEN FNU OR N IS LARGE */
1377/* ----------------------------------------------------------------------- */
1378 inu = (long) ((float) (*fnu));
1379 arg = (*fnu - (double) ((float) inu)) * pi;
1380 inu = inu + *n - il;
1381 ak = -sin(arg);
1382 bk = cos(arg);
1383 if (*zi < 0.) {
1384 bk = -bk;
1385 }
1386 p1r = ak;
1387 p1i = bk;
1388 if (inu % 2 == 0) {
1389 goto L30;
1390 }
1391 p1r = -p1r;
1392 p1i = -p1i;
1393 L30:
1394 i__1 = il;
1395 for (k = 1; k <= i__1; ++k) {
1396 sqk = fdn - 1.;
1397 atol = s * abs(sqk);
1398 sgn = 1.;
1399 cs1r = coner;
1400 cs1i = conei;
1401 cs2r = coner;
1402 cs2i = conei;
1403 ckr = coner;
1404 cki = conei;
1405 ak = 0.;
1406 aa = 1.;
1407 bb = aez;
1408 dkr = ezr;
1409 dki = ezi;
1410 i__2 = jl;
1411 for (j = 1; j <= i__2; ++j) {
1412 zdiv(&ckr, &cki, &dkr, &dki, &str, &sti);
1413 ckr = str * sqk;
1414 cki = sti * sqk;
1415 cs2r += ckr;
1416 cs2i += cki;
1417 sgn = -sgn;
1418 cs1r += ckr * sgn;
1419 cs1i += cki * sgn;
1420 dkr += ezr;
1421 dki += ezi;
1422 aa = aa * abs(sqk) / bb;
1423 bb += aez;
1424 ak += 8.;
1425 sqk -= ak;
1426 if (aa <= atol) {
1427 goto L50;
1428 }
1429/* L40: */
1430 }
1431 goto L110;
1432 L50:
1433 s2r = cs1r;
1434 s2i = cs1i;
1435 if (*zr + *zr >= *elim) {
1436 goto L60;
1437 }
1438 tzr = *zr + *zr;
1439 tzi = *zi + *zi;
1440 d__1 = -tzr;
1441 d__2 = -tzi;
1442 azexp(&d__1, &d__2, &str, &sti);
1443 zmlt(&str, &sti, &p1r, &p1i, &str, &sti);
1444 zmlt(&str, &sti, &cs2r, &cs2i, &str, &sti);
1445 s2r += str;
1446 s2i += sti;
1447 L60:
1448 fdn = fdn + dfnu * 8. + 4.;
1449 p1r = -p1r;
1450 p1i = -p1i;
1451 m = *n - il + k;
1452 yr[m] = s2r * ak1r - s2i * ak1i;
1453 yi[m] = s2r * ak1i + s2i * ak1r;
1454/* L70: */
1455 }
1456 if (*n <= 2) {
1457 return 0;
1458 }
1459 nn = *n;
1460 k = nn - 2;
1461 ak = (double) ((float) k);
1462 str = *zr * raz;
1463 sti = -(*zi) * raz;
1464 rzr = (str + str) * raz;
1465 rzi = (sti + sti) * raz;
1466 ib = 3;
1467 i__1 = nn;
1468 for (i__ = ib; i__ <= i__1; ++i__) {
1469 yr[k] =
1470 (ak + *fnu) * (rzr * yr[k + 1] - rzi * yi[k + 1]) + yr[k + 2];
1471 yi[k] =
1472 (ak + *fnu) * (rzr * yi[k + 1] + rzi * yr[k + 1]) + yi[k + 2];
1473 ak += -1.;
1474 --k;
1475/* L80: */
1476 }
1477 if (koded == 0) {
1478 return 0;
1479 }
1480 azexp(&czr, &czi, &ckr, &cki);
1481 i__1 = nn;
1482 for (i__ = 1; i__ <= i__1; ++i__) {
1483 str = yr[i__] * ckr - yi[i__] * cki;
1484 yi[i__] = yr[i__] * cki + yi[i__] * ckr;
1485 yr[i__] = str;
1486/* L90: */
1487 }
1488 return 0;
1489 L100:
1490 *nz = -1;
1491 return 0;
1492 L110:
1493 *nz = -2;
1494 return 0;
1495} /* zasyi_ */
1496
1497/* Subroutine */ int zbesh(double *zr, double *zi, double *fnu,
1498 long *kode, long *m, long *n, double *cyr,
1499 double *cyi, long *nz, long *ierr)
1500{
1501 /* Initialized data */
1502
1503 double hpi = 1.57079632679489662;
1504
1505 /* System generated locals */
1506 long i__1, i__2;
1507 double d__1, d__2;
1508
1509 /* Builtin functions */
1510 double sqrt(double), log(double), d_sign(double *, double
1511 *), cos(double), sin(double);
1512
1513 /* Local variables */
1514 long i__, k, k1, k2;
1515 double aa, bb, fn;
1516 long mm;
1517 double az;
1518 long ir, nn;
1519 double rl;
1520 long mr, nw;
1521 double dig, arg, aln, fmm, r1m5, ufl, sgn;
1522 long nuf, inu;
1523 double tol, sti, zni, zti, str, znr, alim, elim, atol, rhpi;
1524 long inuh;
1525 double fnul, rtol, ascle;
1526 extern double azabs(double *, double *);
1527 double csgni;
1528 extern /* Subroutine */ int zacon(double *, double *, double
1529 *, long *, long *, long *, double *,
1530 double *, long *, double *, double *,
1531 double *, double *, double *);
1532 double csgnr;
1533 extern /* Subroutine */ int zbknu(double *, double *, double
1534 *, long *, long *, double *,
1535 double *, long *, double *, double *,
1536 double *), zbunk(double *, double *,
1537 double *, long *,
1538 long *, long *,
1539 double *, double *,
1540 long *, double *,
1541 double *, double *);
1542 extern double d1mach(long *);
1543 extern /* Subroutine */ int zuoik(double *, double *, double
1544 *, long *, long *, long *, double *,
1545 double *, long *, double *, double *,
1546 double *);
1547 extern long i1mach(long *);
1548
1549/* ***BEGIN PROLOGUE ZBESH */
1550/* ***DATE WRITTEN 830501 (YYMMDD) */
1551/* ***REVISION DATE 890801 (YYMMDD) */
1552/* ***CATEGORY NO. B5K */
1553/* ***KEYWORDS H-BESSEL FUNCTIONS,BESSEL FUNCTIONS OF COMPLEX ARGUMENT, */
1554/* BESSEL FUNCTIONS OF THIRD KIND,HANKEL FUNCTIONS */
1555/* ***AUTHOR AMOS, DONALD E., SANDIA NATIONAL LABORATORIES */
1556/* ***PURPOSE TO COMPUTE THE H-BESSEL FUNCTIONS OF A COMPLEX ARGUMENT */
1557/* ***DESCRIPTION */
1558
1559/* ***A DOUBLE PRECISION ROUTINE*** */
1560/* ON KODE=1, ZBESH COMPUTES AN N MEMBER SEQUENCE OF COMPLEX */
1561/* HANKEL (BESSEL) FUNCTIONS CY(J)=H(M,FNU+J-1,Z) FOR KINDS M=1 */
1562/* OR 2, REAL, NONNEGATIVE ORDERS FNU+J-1, J=1,...,N, AND COMPLEX */
1563/* Z.NE.CMPLX(0.0,0.0) IN THE CUT PLANE -PI.LT.ARG(Z).LE.PI. */
1564/* ON KODE=2, ZBESH RETURNS THE SCALED HANKEL FUNCTIONS */
1565
1566/* CY(I)=EXP(-MM*Z*I)*H(M,FNU+J-1,Z) MM=3-2*M, I**2=-1. */
1567
1568/* WHICH REMOVES THE EXPONENTIAL BEHAVIOR IN BOTH THE UPPER AND */
1569/* LOWER HALF PLANES. DEFINITIONS AND NOTATION ARE FOUND IN THE */
1570/* NBS HANDBOOK OF MATHEMATICAL FUNCTIONS (REF. 1). */
1571
1572/* INPUT ZR,ZI,FNU ARE DOUBLE PRECISION */
1573/* ZR,ZI - Z=CMPLX(ZR,ZI), Z.NE.CMPLX(0.0D0,0.0D0), */
1574/* -PI.LT.ARG(Z).LE.PI */
1575/* FNU - ORDER OF INITIAL H FUNCTION, FNU.GE.0.0D0 */
1576/* KODE - A PARAMETER TO INDICATE THE SCALING OPTION */
1577/* KODE= 1 RETURNS */
1578/* CY(J)=H(M,FNU+J-1,Z), J=1,...,N */
1579/* = 2 RETURNS */
1580/* CY(J)=H(M,FNU+J-1,Z)*EXP(-I*Z*(3-2M)) */
1581/* J=1,...,N , I**2=-1 */
1582/* M - KIND OF HANKEL FUNCTION, M=1 OR 2 */
1583/* N - NUMBER OF MEMBERS IN THE SEQUENCE, N.GE.1 */
1584
1585/* OUTPUT CYR,CYI ARE DOUBLE PRECISION */
1586/* CYR,CYI- DOUBLE PRECISION VECTORS WHOSE FIRST N COMPONENTS */
1587/* CONTAIN REAL AND IMAGINARY PARTS FOR THE SEQUENCE */
1588/* CY(J)=H(M,FNU+J-1,Z) OR */
1589/* CY(J)=H(M,FNU+J-1,Z)*EXP(-I*Z*(3-2M)) J=1,...,N */
1590/* DEPENDING ON KODE, I**2=-1. */
1591/* NZ - NUMBER OF COMPONENTS SET TO ZERO DUE TO UNDERFLOW, */
1592/* NZ= 0 , NORMAL RETURN */
1593/* NZ.GT.0 , FIRST NZ COMPONENTS OF CY SET TO ZERO DUE */
1594/* TO UNDERFLOW, CY(J)=CMPLX(0.0D0,0.0D0) */
1595/* J=1,...,NZ WHEN Y.GT.0.0 AND M=1 OR */
1596/* Y.LT.0.0 AND M=2. FOR THE COMPLMENTARY */
1597/* HALF PLANES, NZ STATES ONLY THE NUMBER */
1598/* OF UNDERFLOWS. */
1599/* IERR - ERROR FLAG */
1600/* IERR=0, NORMAL RETURN - COMPUTATION COMPLETED */
1601/* IERR=1, INPUT ERROR - NO COMPUTATION */
1602/* IERR=2, OVERFLOW - NO COMPUTATION, FNU TOO */
1603/* LARGE OR CABS(Z) TOO SMALL OR BOTH */
1604/* IERR=3, CABS(Z) OR FNU+N-1 LARGE - COMPUTATION DONE */
1605/* BUT LOSSES OF SIGNIFCANCE BY ARGUMENT */
1606/* REDUCTION PRODUCE LESS THAN HALF OF MACHINE */
1607/* ACCURACY */
1608/* IERR=4, CABS(Z) OR FNU+N-1 TOO LARGE - NO COMPUTA- */
1609/* TION BECAUSE OF COMPLETE LOSSES OF SIGNIFI- */
1610/* CANCE BY ARGUMENT REDUCTION */
1611/* IERR=5, ERROR - NO COMPUTATION, */
1612/* ALGORITHM TERMINATION CONDITION NOT MET */
1613
1614/* ***LONG DESCRIPTION */
1615
1616/* THE COMPUTATION IS CARRIED OUT BY THE RELATION */
1617
1618/* H(M,FNU,Z)=(1/MP)*EXP(-MP*FNU)*K(FNU,Z*EXP(-MP)) */
1619/* MP=MM*HPI*I, MM=3-2*M, HPI=PI/2, I**2=-1 */
1620
1621/* FOR M=1 OR 2 WHERE THE K BESSEL FUNCTION IS COMPUTED FOR THE */
1622/* RIGHT HALF PLANE RE(Z).GE.0.0. THE K FUNCTION IS CONTINUED */
1623/* TO THE LEFT HALF PLANE BY THE RELATION */
1624
1625/* K(FNU,Z*EXP(MP)) = EXP(-MP*FNU)*K(FNU,Z)-MP*I(FNU,Z) */
1626/* MP=MR*PI*I, MR=+1 OR -1, RE(Z).GT.0, I**2=-1 */
1627
1628/* WHERE I(FNU,Z) IS THE I BESSEL FUNCTION. */
1629
1630/* EXPONENTIAL DECAY OF H(M,FNU,Z) OCCURS IN THE UPPER HALF Z */
1631/* PLANE FOR M=1 AND THE LOWER HALF Z PLANE FOR M=2. EXPONENTIAL */
1632/* GROWTH OCCURS IN THE COMPLEMENTARY HALF PLANES. SCALING */
1633/* BY EXP(-MM*Z*I) REMOVES THE EXPONENTIAL BEHAVIOR IN THE */
1634/* WHOLE Z PLANE FOR Z TO INFINITY. */
1635
1636/* FOR NEGATIVE ORDERS,THE FORMULAE */
1637
1638/* H(1,-FNU,Z) = H(1,FNU,Z)*CEXP( PI*FNU*I) */
1639/* H(2,-FNU,Z) = H(2,FNU,Z)*CEXP(-PI*FNU*I) */
1640/* I**2=-1 */
1641
1642/* CAN BE USED. */
1643
1644/* IN MOST COMPLEX VARIABLE COMPUTATION, ONE MUST EVALUATE ELE- */
1645/* MENTARY FUNCTIONS. WHEN THE MAGNITUDE OF Z OR FNU+N-1 IS */
1646/* LARGE, LOSSES OF SIGNIFICANCE BY ARGUMENT REDUCTION OCCUR. */
1647/* CONSEQUENTLY, IF EITHER ONE EXCEEDS U1=SQRT(0.5/UR), THEN */
1648/* LOSSES EXCEEDING HALF PRECISION ARE LIKELY AND AN ERROR FLAG */
1649/* IERR=3 IS TRIGGERED WHERE UR=DMAX1(D1MACH(4),1.0D-18) IS */
1650/* DOUBLE PRECISION UNIT ROUNDOFF LIMITED TO 18 DIGITS PRECISION. */
1651/* IF EITHER IS LARGER THAN U2=0.5/UR, THEN ALL SIGNIFICANCE IS */
1652/* LOST AND IERR=4. IN ORDER TO USE THE INT FUNCTION, ARGUMENTS */
1653/* MUST BE FURTHER RESTRICTED NOT TO EXCEED THE LARGEST MACHINE */
1654/* INTEGER, U3=I1MACH(9). THUS, THE MAGNITUDE OF Z AND FNU+N-1 IS */
1655/* RESTRICTED BY MIN(U2,U3). ON 32 BIT MACHINES, U1,U2, AND U3 */
1656/* ARE APPROXIMATELY 2.0E+3, 4.2E+6, 2.1E+9 IN SINGLE PRECISION */
1657/* ARITHMETIC AND 1.3E+8, 1.8E+16, 2.1E+9 IN DOUBLE PRECISION */
1658/* ARITHMETIC RESPECTIVELY. THIS MAKES U2 AND U3 LIMITING IN */
1659/* THEIR RESPECTIVE ARITHMETICS. THIS MEANS THAT ONE CAN EXPECT */
1660/* TO RETAIN, IN THE WORST CASES ON 32 BIT MACHINES, NO DIGITS */
1661/* IN SINGLE AND ONLY 7 DIGITS IN DOUBLE PRECISION ARITHMETIC. */
1662/* SIMILAR CONSIDERATIONS HOLD FOR OTHER MACHINES. */
1663
1664/* THE APPROXIMATE RELATIVE ERROR IN THE MAGNITUDE OF A COMPLEX */
1665/* BESSEL FUNCTION CAN BE EXPRESSED BY P*10**S WHERE P=MAX(UNIT */
1666/* ROUNDOFF,1.0D-18) IS THE NOMINAL PRECISION AND 10**S REPRE- */
1667/* SENTS THE INCREASE IN ERROR DUE TO ARGUMENT REDUCTION IN THE */
1668/* ELEMENTARY FUNCTIONS. HERE, S=MAX(1,ABS(LOG10(CABS(Z))), */
1669/* ABS(LOG10(FNU))) APPROXIMATELY (I.E. S=MAX(1,ABS(EXPONENT OF */
1670/* CABS(Z),ABS(EXPONENT OF FNU)) ). HOWEVER, THE PHASE ANGLE MAY */
1671/* HAVE ONLY ABSOLUTE ACCURACY. THIS IS MOST LIKELY TO OCCUR WHEN */
1672/* ONE COMPONENT (IN ABSOLUTE VALUE) IS LARGER THAN THE OTHER BY */
1673/* SEVERAL ORDERS OF MAGNITUDE. IF ONE COMPONENT IS 10**K LARGER */
1674/* THAN THE OTHER, THEN ONE CAN EXPECT ONLY MAX(ABS(LOG10(P))-K, */
1675/* 0) SIGNIFICANT DIGITS; OR, STATED ANOTHER WAY, WHEN K EXCEEDS */
1676/* THE EXPONENT OF P, NO SIGNIFICANT DIGITS REMAIN IN THE SMALLER */
1677/* COMPONENT. HOWEVER, THE PHASE ANGLE RETAINS ABSOLUTE ACCURACY */
1678/* BECAUSE, IN COMPLEX ARITHMETIC WITH PRECISION P, THE SMALLER */
1679/* COMPONENT WILL NOT (AS A RULE) DECREASE BELOW P TIMES THE */
1680/* MAGNITUDE OF THE LARGER COMPONENT. IN THESE EXTREME CASES, */
1681/* THE PRINCIPAL PHASE ANGLE IS ON THE ORDER OF +P, -P, PI/2-P, */
1682/* OR -PI/2+P. */
1683
1684/* ***REFERENCES HANDBOOK OF MATHEMATICAL FUNCTIONS BY M. ABRAMOWITZ */
1685/* AND I. A. STEGUN, NBS AMS SERIES 55, U.S. DEPT. OF */
1686/* COMMERCE, 1955. */
1687
1688/* COMPUTATION OF BESSEL FUNCTIONS OF COMPLEX ARGUMENT */
1689/* BY D. E. AMOS, SAND83-0083, MAY, 1983. */
1690
1691/* COMPUTATION OF BESSEL FUNCTIONS OF COMPLEX ARGUMENT */
1692/* AND LARGE ORDER BY D. E. AMOS, SAND83-0643, MAY, 1983 */
1693
1694/* A SUBROUTINE PACKAGE FOR BESSEL FUNCTIONS OF A COMPLEX */
1695/* ARGUMENT AND NONNEGATIVE ORDER BY D. E. AMOS, SAND85- */
1696/* 1018, MAY, 1985 */
1697
1698/* A PORTABLE PACKAGE FOR BESSEL FUNCTIONS OF A COMPLEX */
1699/* ARGUMENT AND NONNEGATIVE ORDER BY D. E. AMOS, TRANS. */
1700/* MATH. SOFTWARE, 1986 */
1701
1702/* ***ROUTINES CALLED ZACON,ZBKNU,ZBUNK,ZUOIK,AZABS,I1MACH,D1MACH */
1703/* ***END PROLOGUE ZBESH */
1704
1705/* COMPLEX CY,Z,ZN,ZT,CSGN */
1706
1707 /* Parameter adjustments */
1708 --cyi;
1709 --cyr;
1710
1711 /* Function Body */
1712
1713/* ***FIRST EXECUTABLE STATEMENT ZBESH */
1714 *ierr = 0;
1715 *nz = 0;
1716 if (*zr == 0. && *zi == 0.) {
1717 *ierr = 1;
1718 }
1719 if (*fnu < 0.) {
1720 *ierr = 1;
1721 }
1722 if (*m < 1 || *m > 2) {
1723 *ierr = 1;
1724 }
1725 if (*kode < 1 || *kode > 2) {
1726 *ierr = 1;
1727 }
1728 if (*n < 1) {
1729 *ierr = 1;
1730 }
1731 if (*ierr != 0) {
1732 return 0;
1733 }
1734 nn = *n;
1735/* ----------------------------------------------------------------------- */
1736/* SET PARAMETERS RELATED TO MACHINE CONSTANTS. */
1737/* TOL IS THE APPROXIMATE UNIT ROUNDOFF LIMITED TO 1.0E-18. */
1738/* ELIM IS THE APPROXIMATE EXPONENTIAL OVER- AND UNDERFLOW LIMIT. */
1739/* EXP(-ELIM).LT.EXP(-ALIM)=EXP(-ELIM)/TOL AND */
1740/* EXP(ELIM).GT.EXP(ALIM)=EXP(ELIM)*TOL ARE INTERVALS NEAR */
1741/* UNDERFLOW AND OVERFLOW LIMITS WHERE SCALED ARITHMETIC IS DONE. */
1742/* RL IS THE LOWER BOUNDARY OF THE ASYMPTOTIC EXPANSION FOR LARGE Z. */
1743/* DIG = NUMBER OF BASE 10 DIGITS IN TOL = 10**(-DIG). */
1744/* FNUL IS THE LOWER BOUNDARY OF THE ASYMPTOTIC SERIES FOR LARGE FNU */
1745/* ----------------------------------------------------------------------- */
1746/* Computing MAX */
1747 d__1 = d1mach(&c__4);
1748 tol = max(d__1, 1e-18);
1749 k1 = i1mach(&c__15);
1750 k2 = i1mach(&c__16);
1751 r1m5 = d1mach(&c__5);
1752/* Computing MIN */
1753 i__1 = abs(k1), i__2 = abs(k2);
1754 k = min(i__1, i__2);
1755 elim = ((double) ((float) k) * r1m5 - 3.) * 2.303;
1756 k1 = i1mach(&c__14) - 1;
1757 aa = r1m5 * (double) ((float) k1);
1758 dig = min(aa, 18.);
1759 aa *= 2.303;
1760/* Computing MAX */
1761 d__1 = -aa;
1762 alim = elim + max(d__1, -41.45);
1763 fnul = (dig - 3.) * 6. + 10.;
1764 rl = dig * 1.2 + 3.;
1765 fn = *fnu + (double) ((float) (nn - 1));
1766 mm = 3 - *m - *m;
1767 fmm = (double) ((float) mm);
1768 znr = fmm * *zi;
1769 zni = -fmm * *zr;
1770/* ----------------------------------------------------------------------- */
1771/* TEST FOR PROPER RANGE */
1772/* ----------------------------------------------------------------------- */
1773 az = azabs(zr, zi);
1774 aa = .5 / tol;
1775 bb = (double) ((float) i1mach(&c__9)) * .5;
1776 aa = min(aa, bb);
1777 if (az > aa) {
1778 goto L260;
1779 }
1780 if (fn > aa) {
1781 goto L260;
1782 }
1783 aa = sqrt(aa);
1784 if (az > aa) {
1785 *ierr = 3;
1786 }
1787 if (fn > aa) {
1788 *ierr = 3;
1789 }
1790/* ----------------------------------------------------------------------- */
1791/* OVERFLOW TEST ON THE LAST MEMBER OF THE SEQUENCE */
1792/* ----------------------------------------------------------------------- */
1793 ufl = d1mach(&c__1) * 1e3;
1794 if (az < ufl) {
1795 goto L230;
1796 }
1797 if (*fnu > fnul) {
1798 goto L90;
1799 }
1800 if (fn <= 1.) {
1801 goto L70;
1802 }
1803 if (fn > 2.) {
1804 goto L60;
1805 }
1806 if (az > tol) {
1807 goto L70;
1808 }
1809 arg = az * .5;
1810 aln = -fn * log(arg);
1811 if (aln > elim) {
1812 goto L230;
1813 }
1814 goto L70;
1815 L60:
1816 zuoik(&znr, &zni, fnu, kode, &c__2, &nn, &cyr[1], &cyi[1], &nuf, &tol,
1817 &elim, &alim);
1818 if (nuf < 0) {
1819 goto L230;
1820 }
1821 *nz += nuf;
1822 nn -= nuf;
1823/* ----------------------------------------------------------------------- */
1824/* HERE NN=N OR NN=0 SINCE NUF=0,NN, OR -1 ON RETURN FROM CUOIK */
1825/* IF NUF=NN, THEN CY(I)=CZERO FOR ALL I */
1826/* ----------------------------------------------------------------------- */
1827 if (nn == 0) {
1828 goto L140;
1829 }
1830 L70:
1831 if (znr < 0. || (znr == 0. && zni < 0. && *m == 2)) {
1832 goto L80;
1833 }
1834/* ----------------------------------------------------------------------- */
1835/* RIGHT HALF PLANE COMPUTATION, XN.GE.0. .AND. (XN.NE.0. .OR. */
1836/* YN.GE.0. .OR. M=1) */
1837/* ----------------------------------------------------------------------- */
1838 zbknu(&znr, &zni, fnu, kode, &nn, &cyr[1], &cyi[1], nz, &tol, &elim,
1839 &alim);
1840 goto L110;
1841/* ----------------------------------------------------------------------- */
1842/* LEFT HALF PLANE COMPUTATION */
1843/* ----------------------------------------------------------------------- */
1844 L80:
1845 mr = -mm;
1846 zacon(&znr, &zni, fnu, kode, &mr, &nn, &cyr[1], &cyi[1], &nw, &rl,
1847 &fnul, &tol, &elim, &alim);
1848 if (nw < 0) {
1849 goto L240;
1850 }
1851 *nz = nw;
1852 goto L110;
1853 L90:
1854/* ----------------------------------------------------------------------- */
1855/* UNIFORM ASYMPTOTIC EXPANSIONS FOR FNU.GT.FNUL */
1856/* ----------------------------------------------------------------------- */
1857 mr = 0;
1858 if (znr >= 0. && (znr != 0. || zni >= 0. || *m != 2)) {
1859 goto L100;
1860 }
1861 mr = -mm;
1862 if (znr != 0. || zni >= 0.) {
1863 goto L100;
1864 }
1865 znr = -znr;
1866 zni = -zni;
1867 L100:
1868 zbunk(&znr, &zni, fnu, kode, &mr, &nn, &cyr[1], &cyi[1], &nw, &tol,
1869 &elim, &alim);
1870 if (nw < 0) {
1871 goto L240;
1872 }
1873 *nz += nw;
1874 L110:
1875/* ----------------------------------------------------------------------- */
1876/* H(M,FNU,Z) = -FMM*(I/HPI)*(ZT**FNU)*K(FNU,-Z*ZT) */
1877
1878/* ZT=EXP(-FMM*HPI*I) = CMPLX(0.0,-FMM), FMM=3-2*M, M=1,2 */
1879/* ----------------------------------------------------------------------- */
1880 d__1 = -fmm;
1881 sgn = d_sign(&hpi, &d__1);
1882/* ----------------------------------------------------------------------- */
1883/* CALCULATE EXP(FNU*HPI*I) TO MINIMIZE LOSSES OF SIGNIFICANCE */
1884/* WHEN FNU IS LARGE */
1885/* ----------------------------------------------------------------------- */
1886 inu = (long) ((float) (*fnu));
1887 inuh = inu / 2;
1888 ir = inu - (inuh << 1);
1889 arg = (*fnu - (double) ((float) (inu - ir))) * sgn;
1890 rhpi = 1. / sgn;
1891/* ZNI = RHPI*DCOS(ARG) */
1892/* ZNR = -RHPI*DSIN(ARG) */
1893 csgni = rhpi * cos(arg);
1894 csgnr = -rhpi * sin(arg);
1895 if (inuh % 2 == 0) {
1896 goto L120;
1897 }
1898/* ZNR = -ZNR */
1899/* ZNI = -ZNI */
1900 csgnr = -csgnr;
1901 csgni = -csgni;
1902 L120:
1903 zti = -fmm;
1904 rtol = 1. / tol;
1905 ascle = ufl * rtol;
1906 i__1 = nn;
1907 for (i__ = 1; i__ <= i__1; ++i__) {
1908/* STR = CYR(I)*ZNR - CYI(I)*ZNI */
1909/* CYI(I) = CYR(I)*ZNI + CYI(I)*ZNR */
1910/* CYR(I) = STR */
1911/* STR = -ZNI*ZTI */
1912/* ZNI = ZNR*ZTI */
1913/* ZNR = STR */
1914 aa = cyr[i__];
1915 bb = cyi[i__];
1916 atol = 1.;
1917/* Computing MAX */
1918 d__1 = abs(aa), d__2 = abs(bb);
1919 if (max(d__1, d__2) > ascle) {
1920 goto L135;
1921 }
1922 aa *= rtol;
1923 bb *= rtol;
1924 atol = tol;
1925 L135:
1926 str = aa * csgnr - bb * csgni;
1927 sti = aa * csgni + bb * csgnr;
1928 cyr[i__] = str * atol;
1929 cyi[i__] = sti * atol;
1930 str = -csgni * zti;
1931 csgni = csgnr * zti;
1932 csgnr = str;
1933/* L130: */
1934 }
1935 return 0;
1936 L140:
1937 if (znr < 0.) {
1938 goto L230;
1939 }
1940 return 0;
1941 L230:
1942 *nz = 0;
1943 *ierr = 2;
1944 return 0;
1945 L240:
1946 if (nw == -1) {
1947 goto L230;
1948 }
1949 *nz = 0;
1950 *ierr = 5;
1951 return 0;
1952 L260:
1953 *nz = 0;
1954 *ierr = 4;
1955 return 0;
1956} /* zbesh_ */
1957
1958/* Subroutine */ int zbesi(double *zr, double *zi, double *fnu,
1959 long *kode, long *n, double *cyr, double *cyi,
1960 long *nz, long *ierr)
1961{
1962 /* Initialized data */
1963
1964 double pi = 3.14159265358979324;
1965 double coner = 1.;
1966 double conei = 0.;
1967
1968 /* System generated locals */
1969 long i__1, i__2;
1970 double d__1, d__2;
1971
1972 /* Builtin functions */
1973 double sqrt(double), cos(double), sin(double);
1974
1975 /* Local variables */
1976 long i__, k, k1, k2;
1977 double aa, bb, fn, az;
1978 long nn;
1979 double rl, dig, arg, r1m5;
1980 long inu;
1981 double tol, sti, zni, str, znr, alim, elim, atol, fnul, rtol,
1982 ascle;
1983 extern double azabs(double *, double *);
1984 double csgni, csgnr;
1985 extern /* Subroutine */ int zbinu(double *, double *, double
1986 *, long *, long *, double *,
1987 double *, long *, double *, double *,
1988 double *, double *, double *);
1989 extern double d1mach(long *);
1990 extern long i1mach(long *);
1991
1992/* ***BEGIN PROLOGUE ZBESI */
1993/* ***DATE WRITTEN 830501 (YYMMDD) */
1994/* ***REVISION DATE 890801 (YYMMDD) */
1995/* ***CATEGORY NO. B5K */
1996/* ***KEYWORDS I-BESSEL FUNCTION,COMPLEX BESSEL FUNCTION, */
1997/* MODIFIED BESSEL FUNCTION OF THE FIRST KIND */
1998/* ***AUTHOR AMOS, DONALD E., SANDIA NATIONAL LABORATORIES */
1999/* ***PURPOSE TO COMPUTE I-BESSEL FUNCTIONS OF COMPLEX ARGUMENT */
2000/* ***DESCRIPTION */
2001
2002/* ***A DOUBLE PRECISION ROUTINE*** */
2003/* ON KODE=1, ZBESI COMPUTES AN N MEMBER SEQUENCE OF COMPLEX */
2004/* BESSEL FUNCTIONS CY(J)=I(FNU+J-1,Z) FOR REAL, NONNEGATIVE */
2005/* ORDERS FNU+J-1, J=1,...,N AND COMPLEX Z IN THE CUT PLANE */
2006/* -PI.LT.ARG(Z).LE.PI. ON KODE=2, ZBESI RETURNS THE SCALED */
2007/* FUNCTIONS */
2008
2009/* CY(J)=EXP(-ABS(X))*I(FNU+J-1,Z) J = 1,...,N , X=REAL(Z) */
2010
2011/* WITH THE EXPONENTIAL GROWTH REMOVED IN BOTH THE LEFT AND */
2012/* RIGHT HALF PLANES FOR Z TO INFINITY. DEFINITIONS AND NOTATION */
2013/* ARE FOUND IN THE NBS HANDBOOK OF MATHEMATICAL FUNCTIONS */
2014/* (REF. 1). */
2015
2016/* INPUT ZR,ZI,FNU ARE DOUBLE PRECISION */
2017/* ZR,ZI - Z=CMPLX(ZR,ZI), -PI.LT.ARG(Z).LE.PI */
2018/* FNU - ORDER OF INITIAL I FUNCTION, FNU.GE.0.0D0 */
2019/* KODE - A PARAMETER TO INDICATE THE SCALING OPTION */
2020/* KODE= 1 RETURNS */
2021/* CY(J)=I(FNU+J-1,Z), J=1,...,N */
2022/* = 2 RETURNS */
2023/* CY(J)=I(FNU+J-1,Z)*EXP(-ABS(X)), J=1,...,N */
2024/* N - NUMBER OF MEMBERS OF THE SEQUENCE, N.GE.1 */
2025
2026/* OUTPUT CYR,CYI ARE DOUBLE PRECISION */
2027/* CYR,CYI- DOUBLE PRECISION VECTORS WHOSE FIRST N COMPONENTS */
2028/* CONTAIN REAL AND IMAGINARY PARTS FOR THE SEQUENCE */
2029/* CY(J)=I(FNU+J-1,Z) OR */
2030/* CY(J)=I(FNU+J-1,Z)*EXP(-ABS(X)) J=1,...,N */
2031/* DEPENDING ON KODE, X=REAL(Z) */
2032/* NZ - NUMBER OF COMPONENTS SET TO ZERO DUE TO UNDERFLOW, */
2033/* NZ= 0 , NORMAL RETURN */
2034/* NZ.GT.0 , LAST NZ COMPONENTS OF CY SET TO ZERO */
2035/* TO UNDERFLOW, CY(J)=CMPLX(0.0D0,0.0D0) */
2036/* J = N-NZ+1,...,N */
2037/* IERR - ERROR FLAG */
2038/* IERR=0, NORMAL RETURN - COMPUTATION COMPLETED */
2039/* IERR=1, INPUT ERROR - NO COMPUTATION */
2040/* IERR=2, OVERFLOW - NO COMPUTATION, REAL(Z) TOO */
2041/* LARGE ON KODE=1 */
2042/* IERR=3, CABS(Z) OR FNU+N-1 LARGE - COMPUTATION DONE */
2043/* BUT LOSSES OF SIGNIFCANCE BY ARGUMENT */
2044/* REDUCTION PRODUCE LESS THAN HALF OF MACHINE */
2045/* ACCURACY */
2046/* IERR=4, CABS(Z) OR FNU+N-1 TOO LARGE - NO COMPUTA- */
2047/* TION BECAUSE OF COMPLETE LOSSES OF SIGNIFI- */
2048/* CANCE BY ARGUMENT REDUCTION */
2049/* IERR=5, ERROR - NO COMPUTATION, */
2050/* ALGORITHM TERMINATION CONDITION NOT MET */
2051
2052/* ***LONG DESCRIPTION */
2053
2054/* THE COMPUTATION IS CARRIED OUT BY THE POWER SERIES FOR */
2055/* SMALL CABS(Z), THE ASYMPTOTIC EXPANSION FOR LARGE CABS(Z), */
2056/* THE MILLER ALGORITHM NORMALIZED BY THE WRONSKIAN AND A */
2057/* NEUMANN SERIES FOR IMTERMEDIATE MAGNITUDES, AND THE */
2058/* UNIFORM ASYMPTOTIC EXPANSIONS FOR I(FNU,Z) AND J(FNU,Z) */
2059/* FOR LARGE ORDERS. BACKWARD RECURRENCE IS USED TO GENERATE */
2060/* SEQUENCES OR REDUCE ORDERS WHEN NECESSARY. */
2061
2062/* THE CALCULATIONS ABOVE ARE DONE IN THE RIGHT HALF PLANE AND */
2063/* CONTINUED INTO THE LEFT HALF PLANE BY THE FORMULA */
2064
2065/* I(FNU,Z*EXP(M*PI)) = EXP(M*PI*FNU)*I(FNU,Z) REAL(Z).GT.0.0 */
2066/* M = +I OR -I, I**2=-1 */
2067
2068/* FOR NEGATIVE ORDERS,THE FORMULA */
2069
2070/* I(-FNU,Z) = I(FNU,Z) + (2/PI)*SIN(PI*FNU)*K(FNU,Z) */
2071
2072/* CAN BE USED. HOWEVER,FOR LARGE ORDERS CLOSE TO INTEGERS, THE */
2073/* THE FUNCTION CHANGES RADICALLY. WHEN FNU IS A LARGE POSITIVE */
2074/* INTEGER,THE MAGNITUDE OF I(-FNU,Z)=I(FNU,Z) IS A LARGE */
2075/* NEGATIVE POWER OF TEN. BUT WHEN FNU IS NOT AN INTEGER, */
2076/* K(FNU,Z) DOMINATES IN MAGNITUDE WITH A LARGE POSITIVE POWER OF */
2077/* TEN AND THE MOST THAT THE SECOND TERM CAN BE REDUCED IS BY */
2078/* UNIT ROUNDOFF FROM THE COEFFICIENT. THUS, WIDE CHANGES CAN */
2079/* OCCUR WITHIN UNIT ROUNDOFF OF A LARGE INTEGER FOR FNU. HERE, */
2080/* LARGE MEANS FNU.GT.CABS(Z). */
2081
2082/* IN MOST COMPLEX VARIABLE COMPUTATION, ONE MUST EVALUATE ELE- */
2083/* MENTARY FUNCTIONS. WHEN THE MAGNITUDE OF Z OR FNU+N-1 IS */
2084/* LARGE, LOSSES OF SIGNIFICANCE BY ARGUMENT REDUCTION OCCUR. */
2085/* CONSEQUENTLY, IF EITHER ONE EXCEEDS U1=SQRT(0.5/UR), THEN */
2086/* LOSSES EXCEEDING HALF PRECISION ARE LIKELY AND AN ERROR FLAG */
2087/* IERR=3 IS TRIGGERED WHERE UR=DMAX1(D1MACH(4),1.0D-18) IS */
2088/* DOUBLE PRECISION UNIT ROUNDOFF LIMITED TO 18 DIGITS PRECISION. */
2089/* IF EITHER IS LARGER THAN U2=0.5/UR, THEN ALL SIGNIFICANCE IS */
2090/* LOST AND IERR=4. IN ORDER TO USE THE INT FUNCTION, ARGUMENTS */
2091/* MUST BE FURTHER RESTRICTED NOT TO EXCEED THE LARGEST MACHINE */
2092/* INTEGER, U3=I1MACH(9). THUS, THE MAGNITUDE OF Z AND FNU+N-1 IS */
2093/* RESTRICTED BY MIN(U2,U3). ON 32 BIT MACHINES, U1,U2, AND U3 */
2094/* ARE APPROXIMATELY 2.0E+3, 4.2E+6, 2.1E+9 IN SINGLE PRECISION */
2095/* ARITHMETIC AND 1.3E+8, 1.8E+16, 2.1E+9 IN DOUBLE PRECISION */
2096/* ARITHMETIC RESPECTIVELY. THIS MAKES U2 AND U3 LIMITING IN */
2097/* THEIR RESPECTIVE ARITHMETICS. THIS MEANS THAT ONE CAN EXPECT */
2098/* TO RETAIN, IN THE WORST CASES ON 32 BIT MACHINES, NO DIGITS */
2099/* IN SINGLE AND ONLY 7 DIGITS IN DOUBLE PRECISION ARITHMETIC. */
2100/* SIMILAR CONSIDERATIONS HOLD FOR OTHER MACHINES. */
2101
2102/* THE APPROXIMATE RELATIVE ERROR IN THE MAGNITUDE OF A COMPLEX */
2103/* BESSEL FUNCTION CAN BE EXPRESSED BY P*10**S WHERE P=MAX(UNIT */
2104/* ROUNDOFF,1.0E-18) IS THE NOMINAL PRECISION AND 10**S REPRE- */
2105/* SENTS THE INCREASE IN ERROR DUE TO ARGUMENT REDUCTION IN THE */
2106/* ELEMENTARY FUNCTIONS. HERE, S=MAX(1,ABS(LOG10(CABS(Z))), */
2107/* ABS(LOG10(FNU))) APPROXIMATELY (I.E. S=MAX(1,ABS(EXPONENT OF */
2108/* CABS(Z),ABS(EXPONENT OF FNU)) ). HOWEVER, THE PHASE ANGLE MAY */
2109/* HAVE ONLY ABSOLUTE ACCURACY. THIS IS MOST LIKELY TO OCCUR WHEN */
2110/* ONE COMPONENT (IN ABSOLUTE VALUE) IS LARGER THAN THE OTHER BY */
2111/* SEVERAL ORDERS OF MAGNITUDE. IF ONE COMPONENT IS 10**K LARGER */
2112/* THAN THE OTHER, THEN ONE CAN EXPECT ONLY MAX(ABS(LOG10(P))-K, */
2113/* 0) SIGNIFICANT DIGITS; OR, STATED ANOTHER WAY, WHEN K EXCEEDS */
2114/* THE EXPONENT OF P, NO SIGNIFICANT DIGITS REMAIN IN THE SMALLER */
2115/* COMPONENT. HOWEVER, THE PHASE ANGLE RETAINS ABSOLUTE ACCURACY */
2116/* BECAUSE, IN COMPLEX ARITHMETIC WITH PRECISION P, THE SMALLER */
2117/* COMPONENT WILL NOT (AS A RULE) DECREASE BELOW P TIMES THE */
2118/* MAGNITUDE OF THE LARGER COMPONENT. IN THESE EXTREME CASES, */
2119/* THE PRINCIPAL PHASE ANGLE IS ON THE ORDER OF +P, -P, PI/2-P, */
2120/* OR -PI/2+P. */
2121
2122/* ***REFERENCES HANDBOOK OF MATHEMATICAL FUNCTIONS BY M. ABRAMOWITZ */
2123/* AND I. A. STEGUN, NBS AMS SERIES 55, U.S. DEPT. OF */
2124/* COMMERCE, 1955. */
2125
2126/* COMPUTATION OF BESSEL FUNCTIONS OF COMPLEX ARGUMENT */
2127/* BY D. E. AMOS, SAND83-0083, MAY, 1983. */
2128
2129/* COMPUTATION OF BESSEL FUNCTIONS OF COMPLEX ARGUMENT */
2130/* AND LARGE ORDER BY D. E. AMOS, SAND83-0643, MAY, 1983 */
2131
2132/* A SUBROUTINE PACKAGE FOR BESSEL FUNCTIONS OF A COMPLEX */
2133/* ARGUMENT AND NONNEGATIVE ORDER BY D. E. AMOS, SAND85- */
2134/* 1018, MAY, 1985 */
2135
2136/* A PORTABLE PACKAGE FOR BESSEL FUNCTIONS OF A COMPLEX */
2137/* ARGUMENT AND NONNEGATIVE ORDER BY D. E. AMOS, TRANS. */
2138/* MATH. SOFTWARE, 1986 */
2139
2140/* ***ROUTINES CALLED ZBINU,I1MACH,D1MACH */
2141/* ***END PROLOGUE ZBESI */
2142/* COMPLEX CONE,CSGN,CW,CY,CZERO,Z,ZN */
2143 /* Parameter adjustments */
2144 --cyi;
2145 --cyr;
2146
2147 /* Function Body */
2148
2149/* ***FIRST EXECUTABLE STATEMENT ZBESI */
2150 *ierr = 0;
2151 *nz = 0;
2152 if (*fnu < 0.) {
2153 *ierr = 1;
2154 }
2155 if (*kode < 1 || *kode > 2) {
2156 *ierr = 1;
2157 }
2158 if (*n < 1) {
2159 *ierr = 1;
2160 }
2161 if (*ierr != 0) {
2162 return 0;
2163 }
2164/* ----------------------------------------------------------------------- */
2165/* SET PARAMETERS RELATED TO MACHINE CONSTANTS. */
2166/* TOL IS THE APPROXIMATE UNIT ROUNDOFF LIMITED TO 1.0E-18. */
2167/* ELIM IS THE APPROXIMATE EXPONENTIAL OVER- AND UNDERFLOW LIMIT. */
2168/* EXP(-ELIM).LT.EXP(-ALIM)=EXP(-ELIM)/TOL AND */
2169/* EXP(ELIM).GT.EXP(ALIM)=EXP(ELIM)*TOL ARE INTERVALS NEAR */
2170/* UNDERFLOW AND OVERFLOW LIMITS WHERE SCALED ARITHMETIC IS DONE. */
2171/* RL IS THE LOWER BOUNDARY OF THE ASYMPTOTIC EXPANSION FOR LARGE Z. */
2172/* DIG = NUMBER OF BASE 10 DIGITS IN TOL = 10**(-DIG). */
2173/* FNUL IS THE LOWER BOUNDARY OF THE ASYMPTOTIC SERIES FOR LARGE FNU. */
2174/* ----------------------------------------------------------------------- */
2175/* Computing MAX */
2176 d__1 = d1mach(&c__4);
2177 tol = max(d__1, 1e-18);
2178 k1 = i1mach(&c__15);
2179 k2 = i1mach(&c__16);
2180 r1m5 = d1mach(&c__5);
2181/* Computing MIN */
2182 i__1 = abs(k1), i__2 = abs(k2);
2183 k = min(i__1, i__2);
2184 elim = ((double) ((float) k) * r1m5 - 3.) * 2.303;
2185 k1 = i1mach(&c__14) - 1;
2186 aa = r1m5 * (double) ((float) k1);
2187 dig = min(aa, 18.);
2188 aa *= 2.303;
2189/* Computing MAX */
2190 d__1 = -aa;
2191 alim = elim + max(d__1, -41.45);
2192 rl = dig * 1.2 + 3.;
2193 fnul = (dig - 3.) * 6. + 10.;
2194/* ----------------------------------------------------------------------------- */
2195/* TEST FOR PROPER RANGE */
2196/* ----------------------------------------------------------------------- */
2197 az = azabs(zr, zi);
2198 fn = *fnu + (double) ((float) (*n - 1));
2199 aa = .5 / tol;
2200 bb = (double) ((float) i1mach(&c__9)) * .5;
2201 aa = min(aa, bb);
2202 if (az > aa) {
2203 goto L260;
2204 }
2205 if (fn > aa) {
2206 goto L260;
2207 }
2208 aa = sqrt(aa);
2209 if (az > aa) {
2210 *ierr = 3;
2211 }
2212 if (fn > aa) {
2213 *ierr = 3;
2214 }
2215 znr = *zr;
2216 zni = *zi;
2217 csgnr = coner;
2218 csgni = conei;
2219 if (*zr >= 0.) {
2220 goto L40;
2221 }
2222 znr = -(*zr);
2223 zni = -(*zi);
2224/* ----------------------------------------------------------------------- */
2225/* CALCULATE CSGN=EXP(FNU*PI*I) TO MINIMIZE LOSSES OF SIGNIFICANCE */
2226/* WHEN FNU IS LARGE */
2227/* ----------------------------------------------------------------------- */
2228 inu = (long) ((float) (*fnu));
2229 arg = (*fnu - (double) ((float) inu)) * pi;
2230 if (*zi < 0.) {
2231 arg = -arg;
2232 }
2233 csgnr = cos(arg);
2234 csgni = sin(arg);
2235 if (inu % 2 == 0) {
2236 goto L40;
2237 }
2238 csgnr = -csgnr;
2239 csgni = -csgni;
2240 L40:
2241 zbinu(&znr, &zni, fnu, kode, n, &cyr[1], &cyi[1], nz, &rl, &fnul, &tol,
2242 &elim, &alim);
2243 if (*nz < 0) {
2244 goto L120;
2245 }
2246 if (*zr >= 0.) {
2247 return 0;
2248 }
2249/* ----------------------------------------------------------------------- */
2250/* ANALYTIC CONTINUATION TO THE LEFT HALF PLANE */
2251/* ----------------------------------------------------------------------- */
2252 nn = *n - *nz;
2253 if (nn == 0) {
2254 return 0;
2255 }
2256 rtol = 1. / tol;
2257 ascle = d1mach(&c__1) * rtol * 1e3;
2258 i__1 = nn;
2259 for (i__ = 1; i__ <= i__1; ++i__) {
2260/* STR = CYR(I)*CSGNR - CYI(I)*CSGNI */
2261/* CYI(I) = CYR(I)*CSGNI + CYI(I)*CSGNR */
2262/* CYR(I) = STR */
2263 aa = cyr[i__];
2264 bb = cyi[i__];
2265 atol = 1.;
2266/* Computing MAX */
2267 d__1 = abs(aa), d__2 = abs(bb);
2268 if (max(d__1, d__2) > ascle) {
2269 goto L55;
2270 }
2271 aa *= rtol;
2272 bb *= rtol;
2273 atol = tol;
2274 L55:
2275 str = aa * csgnr - bb * csgni;
2276 sti = aa * csgni + bb * csgnr;
2277 cyr[i__] = str * atol;
2278 cyi[i__] = sti * atol;
2279 csgnr = -csgnr;
2280 csgni = -csgni;
2281/* L50: */
2282 }
2283 return 0;
2284 L120:
2285 if (*nz == -2) {
2286 goto L130;
2287 }
2288 *nz = 0;
2289 *ierr = 2;
2290 return 0;
2291 L130:
2292 *nz = 0;
2293 *ierr = 5;
2294 return 0;
2295 L260:
2296 *nz = 0;
2297 *ierr = 4;
2298 return 0;
2299} /* zbesi_ */
2300
2301/* Subroutine */ int zbesj(double *zr, double *zi, double *fnu,
2302 long *kode, long *n, double *cyr, double *cyi,
2303 long *nz, long *ierr)
2304{
2305 /* Initialized data */
2306
2307 double hpi = 1.57079632679489662;
2308
2309 /* System generated locals */
2310 long i__1, i__2;
2311 double d__1, d__2;
2312
2313 /* Builtin functions */
2314 double sqrt(double), cos(double), sin(double);
2315
2316 /* Local variables */
2317 long i__, k, k1, k2;
2318 double aa, bb, fn;
2319 long nl;
2320 double az;
2321 long ir;
2322 double rl, dig, cii, arg, r1m5;
2323 long inu;
2324 double tol, sti, zni, str, znr, alim, elim, atol;
2325 long inuh;
2326 double fnul, rtol, ascle;
2327 extern double azabs(double *, double *);
2328 double csgni, csgnr;
2329 extern /* Subroutine */ int zbinu(double *, double *, double
2330 *, long *, long *, double *,
2331 double *, long *, double *, double *,
2332 double *, double *, double *);
2333 extern double d1mach(long *);
2334 extern long i1mach(long *);
2335
2336/* ***BEGIN PROLOGUE ZBESJ */
2337/* ***DATE WRITTEN 830501 (YYMMDD) */
2338/* ***REVISION DATE 890801 (YYMMDD) */
2339/* ***CATEGORY NO. B5K */
2340/* ***KEYWORDS J-BESSEL FUNCTION,BESSEL FUNCTION OF COMPLEX ARGUMENT, */
2341/* BESSEL FUNCTION OF FIRST KIND */
2342/* ***AUTHOR AMOS, DONALD E., SANDIA NATIONAL LABORATORIES */
2343/* ***PURPOSE TO COMPUTE THE J-BESSEL FUNCTION OF A COMPLEX ARGUMENT */
2344/* ***DESCRIPTION */
2345
2346/* ***A DOUBLE PRECISION ROUTINE*** */
2347/* ON KODE=1, CBESJ COMPUTES AN N MEMBER SEQUENCE OF COMPLEX */
2348/* BESSEL FUNCTIONS CY(I)=J(FNU+I-1,Z) FOR REAL, NONNEGATIVE */
2349/* ORDERS FNU+I-1, I=1,...,N AND COMPLEX Z IN THE CUT PLANE */
2350/* -PI.LT.ARG(Z).LE.PI. ON KODE=2, CBESJ RETURNS THE SCALED */
2351/* FUNCTIONS */
2352
2353/* CY(I)=EXP(-ABS(Y))*J(FNU+I-1,Z) I = 1,...,N , Y=AIMAG(Z) */
2354
2355/* WHICH REMOVE THE EXPONENTIAL GROWTH IN BOTH THE UPPER AND */
2356/* LOWER HALF PLANES FOR Z TO INFINITY. DEFINITIONS AND NOTATION */
2357/* ARE FOUND IN THE NBS HANDBOOK OF MATHEMATICAL FUNCTIONS */
2358/* (REF. 1). */
2359
2360/* INPUT ZR,ZI,FNU ARE DOUBLE PRECISION */
2361/* ZR,ZI - Z=CMPLX(ZR,ZI), -PI.LT.ARG(Z).LE.PI */
2362/* FNU - ORDER OF INITIAL J FUNCTION, FNU.GE.0.0D0 */
2363/* KODE - A PARAMETER TO INDICATE THE SCALING OPTION */
2364/* KODE= 1 RETURNS */
2365/* CY(I)=J(FNU+I-1,Z), I=1,...,N */
2366/* = 2 RETURNS */
2367/* CY(I)=J(FNU+I-1,Z)EXP(-ABS(Y)), I=1,...,N */
2368/* N - NUMBER OF MEMBERS OF THE SEQUENCE, N.GE.1 */
2369
2370/* OUTPUT CYR,CYI ARE DOUBLE PRECISION */
2371/* CYR,CYI- DOUBLE PRECISION VECTORS WHOSE FIRST N COMPONENTS */
2372/* CONTAIN REAL AND IMAGINARY PARTS FOR THE SEQUENCE */
2373/* CY(I)=J(FNU+I-1,Z) OR */
2374/* CY(I)=J(FNU+I-1,Z)EXP(-ABS(Y)) I=1,...,N */
2375/* DEPENDING ON KODE, Y=AIMAG(Z). */
2376/* NZ - NUMBER OF COMPONENTS SET TO ZERO DUE TO UNDERFLOW, */
2377/* NZ= 0 , NORMAL RETURN */
2378/* NZ.GT.0 , LAST NZ COMPONENTS OF CY SET ZERO DUE */
2379/* TO UNDERFLOW, CY(I)=CMPLX(0.0D0,0.0D0), */
2380/* I = N-NZ+1,...,N */
2381/* IERR - ERROR FLAG */
2382/* IERR=0, NORMAL RETURN - COMPUTATION COMPLETED */
2383/* IERR=1, INPUT ERROR - NO COMPUTATION */
2384/* IERR=2, OVERFLOW - NO COMPUTATION, AIMAG(Z) */
2385/* TOO LARGE ON KODE=1 */
2386/* IERR=3, CABS(Z) OR FNU+N-1 LARGE - COMPUTATION DONE */
2387/* BUT LOSSES OF SIGNIFCANCE BY ARGUMENT */
2388/* REDUCTION PRODUCE LESS THAN HALF OF MACHINE */
2389/* ACCURACY */
2390/* IERR=4, CABS(Z) OR FNU+N-1 TOO LARGE - NO COMPUTA- */
2391/* TION BECAUSE OF COMPLETE LOSSES OF SIGNIFI- */
2392/* CANCE BY ARGUMENT REDUCTION */
2393/* IERR=5, ERROR - NO COMPUTATION, */
2394/* ALGORITHM TERMINATION CONDITION NOT MET */
2395
2396/* ***LONG DESCRIPTION */
2397
2398/* THE COMPUTATION IS CARRIED OUT BY THE FORMULA */
2399
2400/* J(FNU,Z)=EXP( FNU*PI*I/2)*I(FNU,-I*Z) AIMAG(Z).GE.0.0 */
2401
2402/* J(FNU,Z)=EXP(-FNU*PI*I/2)*I(FNU, I*Z) AIMAG(Z).LT.0.0 */
2403
2404/* WHERE I**2 = -1 AND I(FNU,Z) IS THE I BESSEL FUNCTION. */
2405
2406/* FOR NEGATIVE ORDERS,THE FORMULA */
2407
2408/* J(-FNU,Z) = J(FNU,Z)*COS(PI*FNU) - Y(FNU,Z)*SIN(PI*FNU) */
2409
2410/* CAN BE USED. HOWEVER,FOR LARGE ORDERS CLOSE TO INTEGERS, THE */
2411/* THE FUNCTION CHANGES RADICALLY. WHEN FNU IS A LARGE POSITIVE */
2412/* INTEGER,THE MAGNITUDE OF J(-FNU,Z)=J(FNU,Z)*COS(PI*FNU) IS A */
2413/* LARGE NEGATIVE POWER OF TEN. BUT WHEN FNU IS NOT AN INTEGER, */
2414/* Y(FNU,Z) DOMINATES IN MAGNITUDE WITH A LARGE POSITIVE POWER OF */
2415/* TEN AND THE MOST THAT THE SECOND TERM CAN BE REDUCED IS BY */
2416/* UNIT ROUNDOFF FROM THE COEFFICIENT. THUS, WIDE CHANGES CAN */
2417/* OCCUR WITHIN UNIT ROUNDOFF OF A LARGE INTEGER FOR FNU. HERE, */
2418/* LARGE MEANS FNU.GT.CABS(Z). */
2419
2420/* IN MOST COMPLEX VARIABLE COMPUTATION, ONE MUST EVALUATE ELE- */
2421/* MENTARY FUNCTIONS. WHEN THE MAGNITUDE OF Z OR FNU+N-1 IS */
2422/* LARGE, LOSSES OF SIGNIFICANCE BY ARGUMENT REDUCTION OCCUR. */
2423/* CONSEQUENTLY, IF EITHER ONE EXCEEDS U1=SQRT(0.5/UR), THEN */
2424/* LOSSES EXCEEDING HALF PRECISION ARE LIKELY AND AN ERROR FLAG */
2425/* IERR=3 IS TRIGGERED WHERE UR=DMAX1(D1MACH(4),1.0D-18) IS */
2426/* DOUBLE PRECISION UNIT ROUNDOFF LIMITED TO 18 DIGITS PRECISION. */
2427/* IF EITHER IS LARGER THAN U2=0.5/UR, THEN ALL SIGNIFICANCE IS */
2428/* LOST AND IERR=4. IN ORDER TO USE THE INT FUNCTION, ARGUMENTS */
2429/* MUST BE FURTHER RESTRICTED NOT TO EXCEED THE LARGEST MACHINE */
2430/* INTEGER, U3=I1MACH(9). THUS, THE MAGNITUDE OF Z AND FNU+N-1 IS */
2431/* RESTRICTED BY MIN(U2,U3). ON 32 BIT MACHINES, U1,U2, AND U3 */
2432/* ARE APPROXIMATELY 2.0E+3, 4.2E+6, 2.1E+9 IN SINGLE PRECISION */
2433/* ARITHMETIC AND 1.3E+8, 1.8E+16, 2.1E+9 IN DOUBLE PRECISION */
2434/* ARITHMETIC RESPECTIVELY. THIS MAKES U2 AND U3 LIMITING IN */
2435/* THEIR RESPECTIVE ARITHMETICS. THIS MEANS THAT ONE CAN EXPECT */
2436/* TO RETAIN, IN THE WORST CASES ON 32 BIT MACHINES, NO DIGITS */
2437/* IN SINGLE AND ONLY 7 DIGITS IN DOUBLE PRECISION ARITHMETIC. */
2438/* SIMILAR CONSIDERATIONS HOLD FOR OTHER MACHINES. */
2439
2440/* THE APPROXIMATE RELATIVE ERROR IN THE MAGNITUDE OF A COMPLEX */
2441/* BESSEL FUNCTION CAN BE EXPRESSED BY P*10**S WHERE P=MAX(UNIT */
2442/* ROUNDOFF,1.0E-18) IS THE NOMINAL PRECISION AND 10**S REPRE- */
2443/* SENTS THE INCREASE IN ERROR DUE TO ARGUMENT REDUCTION IN THE */
2444/* ELEMENTARY FUNCTIONS. HERE, S=MAX(1,ABS(LOG10(CABS(Z))), */
2445/* ABS(LOG10(FNU))) APPROXIMATELY (I.E. S=MAX(1,ABS(EXPONENT OF */
2446/* CABS(Z),ABS(EXPONENT OF FNU)) ). HOWEVER, THE PHASE ANGLE MAY */
2447/* HAVE ONLY ABSOLUTE ACCURACY. THIS IS MOST LIKELY TO OCCUR WHEN */
2448/* ONE COMPONENT (IN ABSOLUTE VALUE) IS LARGER THAN THE OTHER BY */
2449/* SEVERAL ORDERS OF MAGNITUDE. IF ONE COMPONENT IS 10**K LARGER */
2450/* THAN THE OTHER, THEN ONE CAN EXPECT ONLY MAX(ABS(LOG10(P))-K, */
2451/* 0) SIGNIFICANT DIGITS; OR, STATED ANOTHER WAY, WHEN K EXCEEDS */
2452/* THE EXPONENT OF P, NO SIGNIFICANT DIGITS REMAIN IN THE SMALLER */
2453/* COMPONENT. HOWEVER, THE PHASE ANGLE RETAINS ABSOLUTE ACCURACY */
2454/* BECAUSE, IN COMPLEX ARITHMETIC WITH PRECISION P, THE SMALLER */
2455/* COMPONENT WILL NOT (AS A RULE) DECREASE BELOW P TIMES THE */
2456/* MAGNITUDE OF THE LARGER COMPONENT. IN THESE EXTREME CASES, */
2457/* THE PRINCIPAL PHASE ANGLE IS ON THE ORDER OF +P, -P, PI/2-P, */
2458/* OR -PI/2+P. */
2459
2460/* ***REFERENCES HANDBOOK OF MATHEMATICAL FUNCTIONS BY M. ABRAMOWITZ */
2461/* AND I. A. STEGUN, NBS AMS SERIES 55, U.S. DEPT. OF */
2462/* COMMERCE, 1955. */
2463
2464/* COMPUTATION OF BESSEL FUNCTIONS OF COMPLEX ARGUMENT */
2465/* BY D. E. AMOS, SAND83-0083, MAY, 1983. */
2466
2467/* COMPUTATION OF BESSEL FUNCTIONS OF COMPLEX ARGUMENT */
2468/* AND LARGE ORDER BY D. E. AMOS, SAND83-0643, MAY, 1983 */
2469
2470/* A SUBROUTINE PACKAGE FOR BESSEL FUNCTIONS OF A COMPLEX */
2471/* ARGUMENT AND NONNEGATIVE ORDER BY D. E. AMOS, SAND85- */
2472/* 1018, MAY, 1985 */
2473
2474/* A PORTABLE PACKAGE FOR BESSEL FUNCTIONS OF A COMPLEX */
2475/* ARGUMENT AND NONNEGATIVE ORDER BY D. E. AMOS, TRANS. */
2476/* MATH. SOFTWARE, 1986 */
2477
2478/* ***ROUTINES CALLED ZBINU,I1MACH,D1MACH */
2479/* ***END PROLOGUE ZBESJ */
2480
2481/* COMPLEX CI,CSGN,CY,Z,ZN */
2482 /* Parameter adjustments */
2483 --cyi;
2484 --cyr;
2485
2486 /* Function Body */
2487
2488/* ***FIRST EXECUTABLE STATEMENT ZBESJ */
2489 *ierr = 0;
2490 *nz = 0;
2491 if (*fnu < 0.) {
2492 *ierr = 1;
2493 }
2494 if (*kode < 1 || *kode > 2) {
2495 *ierr = 1;
2496 }
2497 if (*n < 1) {
2498 *ierr = 1;
2499 }
2500 if (*ierr != 0) {
2501 return 0;
2502 }
2503/* ----------------------------------------------------------------------- */
2504/* SET PARAMETERS RELATED TO MACHINE CONSTANTS. */
2505/* TOL IS THE APPROXIMATE UNIT ROUNDOFF LIMITED TO 1.0E-18. */
2506/* ELIM IS THE APPROXIMATE EXPONENTIAL OVER- AND UNDERFLOW LIMIT. */
2507/* EXP(-ELIM).LT.EXP(-ALIM)=EXP(-ELIM)/TOL AND */
2508/* EXP(ELIM).GT.EXP(ALIM)=EXP(ELIM)*TOL ARE INTERVALS NEAR */
2509/* UNDERFLOW AND OVERFLOW LIMITS WHERE SCALED ARITHMETIC IS DONE. */
2510/* RL IS THE LOWER BOUNDARY OF THE ASYMPTOTIC EXPANSION FOR LARGE Z. */
2511/* DIG = NUMBER OF BASE 10 DIGITS IN TOL = 10**(-DIG). */
2512/* FNUL IS THE LOWER BOUNDARY OF THE ASYMPTOTIC SERIES FOR LARGE FNU. */
2513/* ----------------------------------------------------------------------- */
2514/* Computing MAX */
2515 d__1 = d1mach(&c__4);
2516 tol = max(d__1, 1e-18);
2517 k1 = i1mach(&c__15);
2518 k2 = i1mach(&c__16);
2519 r1m5 = d1mach(&c__5);
2520/* Computing MIN */
2521 i__1 = abs(k1), i__2 = abs(k2);
2522 k = min(i__1, i__2);
2523 elim = ((double) ((float) k) * r1m5 - 3.) * 2.303;
2524 k1 = i1mach(&c__14) - 1;
2525 aa = r1m5 * (double) ((float) k1);
2526 dig = min(aa, 18.);
2527 aa *= 2.303;
2528/* Computing MAX */
2529 d__1 = -aa;
2530 alim = elim + max(d__1, -41.45);
2531 rl = dig * 1.2 + 3.;
2532 fnul = (dig - 3.) * 6. + 10.;
2533/* ----------------------------------------------------------------------- */
2534/* TEST FOR PROPER RANGE */
2535/* ----------------------------------------------------------------------- */
2536 az = azabs(zr, zi);
2537 fn = *fnu + (double) ((float) (*n - 1));
2538 aa = .5 / tol;
2539 bb = (double) ((float) i1mach(&c__9)) * .5;
2540 aa = min(aa, bb);
2541 if (az > aa) {
2542 goto L260;
2543 }
2544 if (fn > aa) {
2545 goto L260;
2546 }
2547 aa = sqrt(aa);
2548 if (az > aa) {
2549 *ierr = 3;
2550 }
2551 if (fn > aa) {
2552 *ierr = 3;
2553 }
2554/* ----------------------------------------------------------------------- */
2555/* CALCULATE CSGN=EXP(FNU*HPI*I) TO MINIMIZE LOSSES OF SIGNIFICANCE */
2556/* WHEN FNU IS LARGE */
2557/* ----------------------------------------------------------------------- */
2558 cii = 1.;
2559 inu = (long) ((float) (*fnu));
2560 inuh = inu / 2;
2561 ir = inu - (inuh << 1);
2562 arg = (*fnu - (double) ((float) (inu - ir))) * hpi;
2563 csgnr = cos(arg);
2564 csgni = sin(arg);
2565 if (inuh % 2 == 0) {
2566 goto L40;
2567 }
2568 csgnr = -csgnr;
2569 csgni = -csgni;
2570 L40:
2571/* ----------------------------------------------------------------------- */
2572/* ZN IS IN THE RIGHT HALF PLANE */
2573/* ----------------------------------------------------------------------- */
2574 znr = *zi;
2575 zni = -(*zr);
2576 if (*zi >= 0.) {
2577 goto L50;
2578 }
2579 znr = -znr;
2580 zni = -zni;
2581 csgni = -csgni;
2582 cii = -cii;
2583 L50:
2584 zbinu(&znr, &zni, fnu, kode, n, &cyr[1], &cyi[1], nz, &rl, &fnul, &tol,
2585 &elim, &alim);
2586 if (*nz < 0) {
2587 goto L130;
2588 }
2589 nl = *n - *nz;
2590 if (nl == 0) {
2591 return 0;
2592 }
2593 rtol = 1. / tol;
2594 ascle = d1mach(&c__1) * rtol * 1e3;
2595 i__1 = nl;
2596 for (i__ = 1; i__ <= i__1; ++i__) {
2597/* STR = CYR(I)*CSGNR - CYI(I)*CSGNI */
2598/* CYI(I) = CYR(I)*CSGNI + CYI(I)*CSGNR */
2599/* CYR(I) = STR */
2600 aa = cyr[i__];
2601 bb = cyi[i__];
2602 atol = 1.;
2603/* Computing MAX */
2604 d__1 = abs(aa), d__2 = abs(bb);
2605 if (max(d__1, d__2) > ascle) {
2606 goto L55;
2607 }
2608 aa *= rtol;
2609 bb *= rtol;
2610 atol = tol;
2611 L55:
2612 str = aa * csgnr - bb * csgni;
2613 sti = aa * csgni + bb * csgnr;
2614 cyr[i__] = str * atol;
2615 cyi[i__] = sti * atol;
2616 str = -csgni * cii;
2617 csgni = csgnr * cii;
2618 csgnr = str;
2619/* L60: */
2620 }
2621 return 0;
2622 L130:
2623 if (*nz == -2) {
2624 goto L140;
2625 }
2626 *nz = 0;
2627 *ierr = 2;
2628 return 0;
2629 L140:
2630 *nz = 0;
2631 *ierr = 5;
2632 return 0;
2633 L260:
2634 *nz = 0;
2635 *ierr = 4;
2636 return 0;
2637} /* zbesj_ */
2638
2639/* Subroutine */ int zbesk(double *zr, double *zi, double *fnu,
2640 long *kode, long *n, double *cyr, double *cyi,
2641 long *nz, long *ierr)
2642{
2643 /* System generated locals */
2644 long i__1, i__2;
2645 double d__1;
2646
2647 /* Builtin functions */
2648 double sqrt(double), log(double);
2649
2650 /* Local variables */
2651 long k, k1, k2;
2652 double aa, bb, fn, az;
2653 long nn;
2654 double rl;
2655 long mr, nw;
2656 double dig, arg, aln, r1m5, ufl;
2657 long nuf;
2658 double tol, alim, elim, fnul;
2659 extern double azabs(double *, double *);
2660 extern /* Subroutine */ int zacon(double *, double *, double
2661 *, long *, long *, long *, double *,
2662 double *, long *, double *, double *,
2663 double *, double *, double *),
2664 zbknu(double *, double *, double *, long *, long *, double *,
2665 double *, long *, double *, double *, double *),
2666 zbunk(double *, double *, double *, long *, long *, long *,
2667 double *, double *, long *, double *, double *, double *);
2668 extern double d1mach(long *);
2669 extern /* Subroutine */ int zuoik(double *, double *, double
2670 *, long *, long *, long *, double *,
2671 double *, long *, double *, double *,
2672 double *);
2673 extern long i1mach(long *);
2674
2675/* ***BEGIN PROLOGUE ZBESK */
2676/* ***DATE WRITTEN 830501 (YYMMDD) */
2677/* ***REVISION DATE 890801 (YYMMDD) */
2678/* ***CATEGORY NO. B5K */
2679/* ***KEYWORDS K-BESSEL FUNCTION,COMPLEX BESSEL FUNCTION, */
2680/* MODIFIED BESSEL FUNCTION OF THE SECOND KIND, */
2681/* BESSEL FUNCTION OF THE THIRD KIND */
2682/* ***AUTHOR AMOS, DONALD E., SANDIA NATIONAL LABORATORIES */
2683/* ***PURPOSE TO COMPUTE K-BESSEL FUNCTIONS OF COMPLEX ARGUMENT */
2684/* ***DESCRIPTION */
2685
2686/* ***A DOUBLE PRECISION ROUTINE*** */
2687
2688/* ON KODE=1, CBESK COMPUTES AN N MEMBER SEQUENCE OF COMPLEX */
2689/* BESSEL FUNCTIONS CY(J)=K(FNU+J-1,Z) FOR REAL, NONNEGATIVE */
2690/* ORDERS FNU+J-1, J=1,...,N AND COMPLEX Z.NE.CMPLX(0.0,0.0) */
2691/* IN THE CUT PLANE -PI.LT.ARG(Z).LE.PI. ON KODE=2, CBESK */
2692/* RETURNS THE SCALED K FUNCTIONS, */
2693
2694/* CY(J)=EXP(Z)*K(FNU+J-1,Z) , J=1,...,N, */
2695
2696/* WHICH REMOVE THE EXPONENTIAL BEHAVIOR IN BOTH THE LEFT AND */
2697/* RIGHT HALF PLANES FOR Z TO INFINITY. DEFINITIONS AND */
2698/* NOTATION ARE FOUND IN THE NBS HANDBOOK OF MATHEMATICAL */
2699/* FUNCTIONS (REF. 1). */
2700
2701/* INPUT ZR,ZI,FNU ARE DOUBLE PRECISION */
2702/* ZR,ZI - Z=CMPLX(ZR,ZI), Z.NE.CMPLX(0.0D0,0.0D0), */
2703/* -PI.LT.ARG(Z).LE.PI */
2704/* FNU - ORDER OF INITIAL K FUNCTION, FNU.GE.0.0D0 */
2705/* N - NUMBER OF MEMBERS OF THE SEQUENCE, N.GE.1 */
2706/* KODE - A PARAMETER TO INDICATE THE SCALING OPTION */
2707/* KODE= 1 RETURNS */
2708/* CY(I)=K(FNU+I-1,Z), I=1,...,N */
2709/* = 2 RETURNS */
2710/* CY(I)=K(FNU+I-1,Z)*EXP(Z), I=1,...,N */
2711
2712/* OUTPUT CYR,CYI ARE DOUBLE PRECISION */
2713/* CYR,CYI- DOUBLE PRECISION VECTORS WHOSE FIRST N COMPONENTS */
2714/* CONTAIN REAL AND IMAGINARY PARTS FOR THE SEQUENCE */
2715/* CY(I)=K(FNU+I-1,Z), I=1,...,N OR */
2716/* CY(I)=K(FNU+I-1,Z)*EXP(Z), I=1,...,N */
2717/* DEPENDING ON KODE */
2718/* NZ - NUMBER OF COMPONENTS SET TO ZERO DUE TO UNDERFLOW. */
2719/* NZ= 0 , NORMAL RETURN */
2720/* NZ.GT.0 , FIRST NZ COMPONENTS OF CY SET TO ZERO DUE */
2721/* TO UNDERFLOW, CY(I)=CMPLX(0.0D0,0.0D0), */
2722/* I=1,...,N WHEN X.GE.0.0. WHEN X.LT.0.0 */
2723/* NZ STATES ONLY THE NUMBER OF UNDERFLOWS */
2724/* IN THE SEQUENCE. */
2725
2726/* IERR - ERROR FLAG */
2727/* IERR=0, NORMAL RETURN - COMPUTATION COMPLETED */
2728/* IERR=1, INPUT ERROR - NO COMPUTATION */
2729/* IERR=2, OVERFLOW - NO COMPUTATION, FNU IS */
2730/* TOO LARGE OR CABS(Z) IS TOO SMALL OR BOTH */
2731/* IERR=3, CABS(Z) OR FNU+N-1 LARGE - COMPUTATION DONE */
2732/* BUT LOSSES OF SIGNIFCANCE BY ARGUMENT */
2733/* REDUCTION PRODUCE LESS THAN HALF OF MACHINE */
2734/* ACCURACY */
2735/* IERR=4, CABS(Z) OR FNU+N-1 TOO LARGE - NO COMPUTA- */
2736/* TION BECAUSE OF COMPLETE LOSSES OF SIGNIFI- */
2737/* CANCE BY ARGUMENT REDUCTION */
2738/* IERR=5, ERROR - NO COMPUTATION, */
2739/* ALGORITHM TERMINATION CONDITION NOT MET */
2740
2741/* ***LONG DESCRIPTION */
2742
2743/* EQUATIONS OF THE REFERENCE ARE IMPLEMENTED FOR SMALL ORDERS */
2744/* DNU AND DNU+1.0 IN THE RIGHT HALF PLANE X.GE.0.0. FORWARD */
2745/* RECURRENCE GENERATES HIGHER ORDERS. K IS CONTINUED TO THE LEFT */
2746/* HALF PLANE BY THE RELATION */
2747
2748/* K(FNU,Z*EXP(MP)) = EXP(-MP*FNU)*K(FNU,Z)-MP*I(FNU,Z) */
2749/* MP=MR*PI*I, MR=+1 OR -1, RE(Z).GT.0, I**2=-1 */
2750
2751/* WHERE I(FNU,Z) IS THE I BESSEL FUNCTION. */
2752
2753/* FOR LARGE ORDERS, FNU.GT.FNUL, THE K FUNCTION IS COMPUTED */
2754/* BY MEANS OF ITS UNIFORM ASYMPTOTIC EXPANSIONS. */
2755
2756/* FOR NEGATIVE ORDERS, THE FORMULA */
2757
2758/* K(-FNU,Z) = K(FNU,Z) */
2759
2760/* CAN BE USED. */
2761
2762/* CBESK ASSUMES THAT A SIGNIFICANT DIGIT SINH(X) FUNCTION IS */
2763/* AVAILABLE. */
2764
2765/* IN MOST COMPLEX VARIABLE COMPUTATION, ONE MUST EVALUATE ELE- */
2766/* MENTARY FUNCTIONS. WHEN THE MAGNITUDE OF Z OR FNU+N-1 IS */
2767/* LARGE, LOSSES OF SIGNIFICANCE BY ARGUMENT REDUCTION OCCUR. */
2768/* CONSEQUENTLY, IF EITHER ONE EXCEEDS U1=SQRT(0.5/UR), THEN */
2769/* LOSSES EXCEEDING HALF PRECISION ARE LIKELY AND AN ERROR FLAG */
2770/* IERR=3 IS TRIGGERED WHERE UR=DMAX1(D1MACH(4),1.0D-18) IS */
2771/* DOUBLE PRECISION UNIT ROUNDOFF LIMITED TO 18 DIGITS PRECISION. */
2772/* IF EITHER IS LARGER THAN U2=0.5/UR, THEN ALL SIGNIFICANCE IS */
2773/* LOST AND IERR=4. IN ORDER TO USE THE INT FUNCTION, ARGUMENTS */
2774/* MUST BE FURTHER RESTRICTED NOT TO EXCEED THE LARGEST MACHINE */
2775/* INTEGER, U3=I1MACH(9). THUS, THE MAGNITUDE OF Z AND FNU+N-1 IS */
2776/* RESTRICTED BY MIN(U2,U3). ON 32 BIT MACHINES, U1,U2, AND U3 */
2777/* ARE APPROXIMATELY 2.0E+3, 4.2E+6, 2.1E+9 IN SINGLE PRECISION */
2778/* ARITHMETIC AND 1.3E+8, 1.8E+16, 2.1E+9 IN DOUBLE PRECISION */
2779/* ARITHMETIC RESPECTIVELY. THIS MAKES U2 AND U3 LIMITING IN */
2780/* THEIR RESPECTIVE ARITHMETICS. THIS MEANS THAT ONE CAN EXPECT */
2781/* TO RETAIN, IN THE WORST CASES ON 32 BIT MACHINES, NO DIGITS */
2782/* IN SINGLE AND ONLY 7 DIGITS IN DOUBLE PRECISION ARITHMETIC. */
2783/* SIMILAR CONSIDERATIONS HOLD FOR OTHER MACHINES. */
2784
2785/* THE APPROXIMATE RELATIVE ERROR IN THE MAGNITUDE OF A COMPLEX */
2786/* BESSEL FUNCTION CAN BE EXPRESSED BY P*10**S WHERE P=MAX(UNIT */
2787/* ROUNDOFF,1.0E-18) IS THE NOMINAL PRECISION AND 10**S REPRE- */
2788/* SENTS THE INCREASE IN ERROR DUE TO ARGUMENT REDUCTION IN THE */
2789/* ELEMENTARY FUNCTIONS. HERE, S=MAX(1,ABS(LOG10(CABS(Z))), */
2790/* ABS(LOG10(FNU))) APPROXIMATELY (I.E. S=MAX(1,ABS(EXPONENT OF */
2791/* CABS(Z),ABS(EXPONENT OF FNU)) ). HOWEVER, THE PHASE ANGLE MAY */
2792/* HAVE ONLY ABSOLUTE ACCURACY. THIS IS MOST LIKELY TO OCCUR WHEN */
2793/* ONE COMPONENT (IN ABSOLUTE VALUE) IS LARGER THAN THE OTHER BY */
2794/* SEVERAL ORDERS OF MAGNITUDE. IF ONE COMPONENT IS 10**K LARGER */
2795/* THAN THE OTHER, THEN ONE CAN EXPECT ONLY MAX(ABS(LOG10(P))-K, */
2796/* 0) SIGNIFICANT DIGITS; OR, STATED ANOTHER WAY, WHEN K EXCEEDS */
2797/* THE EXPONENT OF P, NO SIGNIFICANT DIGITS REMAIN IN THE SMALLER */
2798/* COMPONENT. HOWEVER, THE PHASE ANGLE RETAINS ABSOLUTE ACCURACY */
2799/* BECAUSE, IN COMPLEX ARITHMETIC WITH PRECISION P, THE SMALLER */
2800/* COMPONENT WILL NOT (AS A RULE) DECREASE BELOW P TIMES THE */
2801/* MAGNITUDE OF THE LARGER COMPONENT. IN THESE EXTREME CASES, */
2802/* THE PRINCIPAL PHASE ANGLE IS ON THE ORDER OF +P, -P, PI/2-P, */
2803/* OR -PI/2+P. */
2804
2805/* ***REFERENCES HANDBOOK OF MATHEMATICAL FUNCTIONS BY M. ABRAMOWITZ */
2806/* AND I. A. STEGUN, NBS AMS SERIES 55, U.S. DEPT. OF */
2807/* COMMERCE, 1955. */
2808
2809/* COMPUTATION OF BESSEL FUNCTIONS OF COMPLEX ARGUMENT */
2810/* BY D. E. AMOS, SAND83-0083, MAY, 1983. */
2811
2812/* COMPUTATION OF BESSEL FUNCTIONS OF COMPLEX ARGUMENT */
2813/* AND LARGE ORDER BY D. E. AMOS, SAND83-0643, MAY, 1983. */
2814
2815/* A SUBROUTINE PACKAGE FOR BESSEL FUNCTIONS OF A COMPLEX */
2816/* ARGUMENT AND NONNEGATIVE ORDER BY D. E. AMOS, SAND85- */
2817/* 1018, MAY, 1985 */
2818
2819/* A PORTABLE PACKAGE FOR BESSEL FUNCTIONS OF A COMPLEX */
2820/* ARGUMENT AND NONNEGATIVE ORDER BY D. E. AMOS, TRANS. */
2821/* MATH. SOFTWARE, 1986 */
2822
2823/* ***ROUTINES CALLED ZACON,ZBKNU,ZBUNK,ZUOIK,AZABS,I1MACH,D1MACH */
2824/* ***END PROLOGUE ZBESK */
2825
2826/* COMPLEX CY,Z */
2827/* ***FIRST EXECUTABLE STATEMENT ZBESK */
2828 /* Parameter adjustments */
2829 --cyi;
2830 --cyr;
2831
2832 /* Function Body */
2833 *ierr = 0;
2834 *nz = 0;
2835 if (*zi == 0.f && *zr == 0.f) {
2836 *ierr = 1;
2837 }
2838 if (*fnu < 0.) {
2839 *ierr = 1;
2840 }
2841 if (*kode < 1 || *kode > 2) {
2842 *ierr = 1;
2843 }
2844 if (*n < 1) {
2845 *ierr = 1;
2846 }
2847 if (*ierr != 0) {
2848 return 0;
2849 }
2850 nn = *n;
2851/* ----------------------------------------------------------------------- */
2852/* SET PARAMETERS RELATED TO MACHINE CONSTANTS. */
2853/* TOL IS THE APPROXIMATE UNIT ROUNDOFF LIMITED TO 1.0E-18. */
2854/* ELIM IS THE APPROXIMATE EXPONENTIAL OVER- AND UNDERFLOW LIMIT. */
2855/* EXP(-ELIM).LT.EXP(-ALIM)=EXP(-ELIM)/TOL AND */
2856/* EXP(ELIM).GT.EXP(ALIM)=EXP(ELIM)*TOL ARE INTERVALS NEAR */
2857/* UNDERFLOW AND OVERFLOW LIMITS WHERE SCALED ARITHMETIC IS DONE. */
2858/* RL IS THE LOWER BOUNDARY OF THE ASYMPTOTIC EXPANSION FOR LARGE Z. */
2859/* DIG = NUMBER OF BASE 10 DIGITS IN TOL = 10**(-DIG). */
2860/* FNUL IS THE LOWER BOUNDARY OF THE ASYMPTOTIC SERIES FOR LARGE FNU */
2861/* ----------------------------------------------------------------------- */
2862/* Computing MAX */
2863 d__1 = d1mach(&c__4);
2864 tol = max(d__1, 1e-18);
2865 k1 = i1mach(&c__15);
2866 k2 = i1mach(&c__16);
2867 r1m5 = d1mach(&c__5);
2868/* Computing MIN */
2869 i__1 = abs(k1), i__2 = abs(k2);
2870 k = min(i__1, i__2);
2871 elim = ((double) ((float) k) * r1m5 - 3.) * 2.303;
2872 k1 = i1mach(&c__14) - 1;
2873 aa = r1m5 * (double) ((float) k1);
2874 dig = min(aa, 18.);
2875 aa *= 2.303;
2876/* Computing MAX */
2877 d__1 = -aa;
2878 alim = elim + max(d__1, -41.45);
2879 fnul = (dig - 3.) * 6. + 10.;
2880 rl = dig * 1.2 + 3.;
2881/* ----------------------------------------------------------------------------- */
2882/* TEST FOR PROPER RANGE */
2883/* ----------------------------------------------------------------------- */
2884 az = azabs(zr, zi);
2885 fn = *fnu + (double) ((float) (nn - 1));
2886 aa = .5 / tol;
2887 bb = (double) ((float) i1mach(&c__9)) * .5;
2888 aa = min(aa, bb);
2889 if (az > aa) {
2890 goto L260;
2891 }
2892 if (fn > aa) {
2893 goto L260;
2894 }
2895 aa = sqrt(aa);
2896 if (az > aa) {
2897 *ierr = 3;
2898 }
2899 if (fn > aa) {
2900 *ierr = 3;
2901 }
2902/* ----------------------------------------------------------------------- */
2903/* OVERFLOW TEST ON THE LAST MEMBER OF THE SEQUENCE */
2904/* ----------------------------------------------------------------------- */
2905/* UFL = DEXP(-ELIM) */
2906 ufl = d1mach(&c__1) * 1e3;
2907 if (az < ufl) {
2908 goto L180;
2909 }
2910 if (*fnu > fnul) {
2911 goto L80;
2912 }
2913 if (fn <= 1.) {
2914 goto L60;
2915 }
2916 if (fn > 2.) {
2917 goto L50;
2918 }
2919 if (az > tol) {
2920 goto L60;
2921 }
2922 arg = az * .5;
2923 aln = -fn * log(arg);
2924 if (aln > elim) {
2925 goto L180;
2926 }
2927 goto L60;
2928 L50:
2929 zuoik(zr, zi, fnu, kode, &c__2, &nn, &cyr[1], &cyi[1], &nuf, &tol,
2930 &elim, &alim);
2931 if (nuf < 0) {
2932 goto L180;
2933 }
2934 *nz += nuf;
2935 nn -= nuf;
2936/* ----------------------------------------------------------------------- */
2937/* HERE NN=N OR NN=0 SINCE NUF=0,NN, OR -1 ON RETURN FROM CUOIK */
2938/* IF NUF=NN, THEN CY(I)=CZERO FOR ALL I */
2939/* ----------------------------------------------------------------------- */
2940 if (nn == 0) {
2941 goto L100;
2942 }
2943 L60:
2944 if (*zr < 0.) {
2945 goto L70;
2946 }
2947/* ----------------------------------------------------------------------- */
2948/* RIGHT HALF PLANE COMPUTATION, REAL(Z).GE.0. */
2949/* ----------------------------------------------------------------------- */
2950 zbknu(zr, zi, fnu, kode, &nn, &cyr[1], &cyi[1], &nw, &tol, &elim,
2951 &alim);
2952 if (nw < 0) {
2953 goto L200;
2954 }
2955 *nz = nw;
2956 return 0;
2957/* ----------------------------------------------------------------------- */
2958/* LEFT HALF PLANE COMPUTATION */
2959/* PI/2.LT.ARG(Z).LE.PI AND -PI.LT.ARG(Z).LT.-PI/2. */
2960/* ----------------------------------------------------------------------- */
2961 L70:
2962 if (*nz != 0) {
2963 goto L180;
2964 }
2965 mr = 1;
2966 if (*zi < 0.) {
2967 mr = -1;
2968 }
2969 zacon(zr, zi, fnu, kode, &mr, &nn, &cyr[1], &cyi[1], &nw, &rl, &fnul,
2970 &tol, &elim, &alim);
2971 if (nw < 0) {
2972 goto L200;
2973 }
2974 *nz = nw;
2975 return 0;
2976/* ----------------------------------------------------------------------- */
2977/* UNIFORM ASYMPTOTIC EXPANSIONS FOR FNU.GT.FNUL */
2978/* ----------------------------------------------------------------------- */
2979 L80:
2980 mr = 0;
2981 if (*zr >= 0.) {
2982 goto L90;
2983 }
2984 mr = 1;
2985 if (*zi < 0.) {
2986 mr = -1;
2987 }
2988 L90:
2989 zbunk(zr, zi, fnu, kode, &mr, &nn, &cyr[1], &cyi[1], &nw, &tol, &elim,
2990 &alim);
2991 if (nw < 0) {
2992 goto L200;
2993 }
2994 *nz += nw;
2995 return 0;
2996 L100:
2997 if (*zr < 0.) {
2998 goto L180;
2999 }
3000 return 0;
3001 L180:
3002 *nz = 0;
3003 *ierr = 2;
3004 return 0;
3005 L200:
3006 if (nw == -1) {
3007 goto L180;
3008 }
3009 *nz = 0;
3010 *ierr = 5;
3011 return 0;
3012 L260:
3013 *nz = 0;
3014 *ierr = 4;
3015 return 0;
3016} /* zbesk_ */
3017
3018/* Subroutine */ int zbesy(double *zr, double *zi, double *fnu,
3019 long *kode, long *n, double *cyr, double *cyi,
3020 long *nz, double *cwrkr, double *cwrki,
3021 long *ierr)
3022{
3023 /* System generated locals */
3024 long i__1, i__2;
3025 double d__1, d__2;
3026
3027 /* Builtin functions */
3028 double cos(double), sin(double), exp(double);
3029
3030 /* Local variables */
3031 long i__, k, k1, k2;
3032 double aa, bb, ey, c1i, c2i, c1r, c2r;
3033 long nz1, nz2;
3034 double exi;
3035 float r1m5;
3036 double exr, sti, tay, tol, str, hcii, elim, atol, rtol, ascle;
3037 extern /* Subroutine */ int zbesh(double *, double *, double
3038 *, long *, long *, long *, double *,
3039 double *, long *, long *);
3040 extern double d1mach(long *);
3041 extern long i1mach(long *);
3042
3043/* ***BEGIN PROLOGUE ZBESY */
3044/* ***DATE WRITTEN 830501 (YYMMDD) */
3045/* ***REVISION DATE 890801 (YYMMDD) */
3046/* ***CATEGORY NO. B5K */
3047/* ***KEYWORDS Y-BESSEL FUNCTION,BESSEL FUNCTION OF COMPLEX ARGUMENT, */
3048/* BESSEL FUNCTION OF SECOND KIND */
3049/* ***AUTHOR AMOS, DONALD E., SANDIA NATIONAL LABORATORIES */
3050/* ***PURPOSE TO COMPUTE THE Y-BESSEL FUNCTION OF A COMPLEX ARGUMENT */
3051/* ***DESCRIPTION */
3052
3053/* ***A DOUBLE PRECISION ROUTINE*** */
3054
3055/* ON KODE=1, CBESY COMPUTES AN N MEMBER SEQUENCE OF COMPLEX */
3056/* BESSEL FUNCTIONS CY(I)=Y(FNU+I-1,Z) FOR REAL, NONNEGATIVE */
3057/* ORDERS FNU+I-1, I=1,...,N AND COMPLEX Z IN THE CUT PLANE */
3058/* -PI.LT.ARG(Z).LE.PI. ON KODE=2, CBESY RETURNS THE SCALED */
3059/* FUNCTIONS */
3060
3061/* CY(I)=EXP(-ABS(Y))*Y(FNU+I-1,Z) I = 1,...,N , Y=AIMAG(Z) */
3062
3063/* WHICH REMOVE THE EXPONENTIAL GROWTH IN BOTH THE UPPER AND */
3064/* LOWER HALF PLANES FOR Z TO INFINITY. DEFINITIONS AND NOTATION */
3065/* ARE FOUND IN THE NBS HANDBOOK OF MATHEMATICAL FUNCTIONS */
3066/* (REF. 1). */
3067
3068/* INPUT ZR,ZI,FNU ARE DOUBLE PRECISION */
3069/* ZR,ZI - Z=CMPLX(ZR,ZI), Z.NE.CMPLX(0.0D0,0.0D0), */
3070/* -PI.LT.ARG(Z).LE.PI */
3071/* FNU - ORDER OF INITIAL Y FUNCTION, FNU.GE.0.0D0 */
3072/* KODE - A PARAMETER TO INDICATE THE SCALING OPTION */
3073/* KODE= 1 RETURNS */
3074/* CY(I)=Y(FNU+I-1,Z), I=1,...,N */
3075/* = 2 RETURNS */
3076/* CY(I)=Y(FNU+I-1,Z)*EXP(-ABS(Y)), I=1,...,N */
3077/* WHERE Y=AIMAG(Z) */
3078/* N - NUMBER OF MEMBERS OF THE SEQUENCE, N.GE.1 */
3079/* CWRKR, - DOUBLE PRECISION WORK VECTORS OF DIMENSION AT */
3080/* CWRKI AT LEAST N */
3081
3082/* OUTPUT CYR,CYI ARE DOUBLE PRECISION */
3083/* CYR,CYI- DOUBLE PRECISION VECTORS WHOSE FIRST N COMPONENTS */
3084/* CONTAIN REAL AND IMAGINARY PARTS FOR THE SEQUENCE */
3085/* CY(I)=Y(FNU+I-1,Z) OR */
3086/* CY(I)=Y(FNU+I-1,Z)*EXP(-ABS(Y)) I=1,...,N */
3087/* DEPENDING ON KODE. */
3088/* NZ - NZ=0 , A NORMAL RETURN */
3089/* NZ.GT.0 , NZ COMPONENTS OF CY SET TO ZERO DUE TO */
3090/* UNDERFLOW (GENERALLY ON KODE=2) */
3091/* IERR - ERROR FLAG */
3092/* IERR=0, NORMAL RETURN - COMPUTATION COMPLETED */
3093/* IERR=1, INPUT ERROR - NO COMPUTATION */
3094/* IERR=2, OVERFLOW - NO COMPUTATION, FNU IS */
3095/* TOO LARGE OR CABS(Z) IS TOO SMALL OR BOTH */
3096/* IERR=3, CABS(Z) OR FNU+N-1 LARGE - COMPUTATION DONE */
3097/* BUT LOSSES OF SIGNIFCANCE BY ARGUMENT */
3098/* REDUCTION PRODUCE LESS THAN HALF OF MACHINE */
3099/* ACCURACY */
3100/* IERR=4, CABS(Z) OR FNU+N-1 TOO LARGE - NO COMPUTA- */
3101/* TION BECAUSE OF COMPLETE LOSSES OF SIGNIFI- */
3102/* CANCE BY ARGUMENT REDUCTION */
3103/* IERR=5, ERROR - NO COMPUTATION, */
3104/* ALGORITHM TERMINATION CONDITION NOT MET */
3105
3106/* ***LONG DESCRIPTION */
3107
3108/* THE COMPUTATION IS CARRIED OUT BY THE FORMULA */
3109
3110/* Y(FNU,Z)=0.5*(H(1,FNU,Z)-H(2,FNU,Z))/I */
3111
3112/* WHERE I**2 = -1 AND THE HANKEL BESSEL FUNCTIONS H(1,FNU,Z) */
3113/* AND H(2,FNU,Z) ARE CALCULATED IN CBESH. */
3114
3115/* FOR NEGATIVE ORDERS,THE FORMULA */
3116
3117/* Y(-FNU,Z) = Y(FNU,Z)*COS(PI*FNU) + J(FNU,Z)*SIN(PI*FNU) */
3118
3119/* CAN BE USED. HOWEVER,FOR LARGE ORDERS CLOSE TO HALF ODD */
3120/* INTEGERS THE FUNCTION CHANGES RADICALLY. WHEN FNU IS A LARGE */
3121/* POSITIVE HALF ODD INTEGER,THE MAGNITUDE OF Y(-FNU,Z)=J(FNU,Z)* */
3122/* SIN(PI*FNU) IS A LARGE NEGATIVE POWER OF TEN. BUT WHEN FNU IS */
3123/* NOT A HALF ODD INTEGER, Y(FNU,Z) DOMINATES IN MAGNITUDE WITH A */
3124/* LARGE POSITIVE POWER OF TEN AND THE MOST THAT THE SECOND TERM */
3125/* CAN BE REDUCED IS BY UNIT ROUNDOFF FROM THE COEFFICIENT. THUS, */
3126/* WIDE CHANGES CAN OCCUR WITHIN UNIT ROUNDOFF OF A LARGE HALF */
3127/* ODD INTEGER. HERE, LARGE MEANS FNU.GT.CABS(Z). */
3128
3129/* IN MOST COMPLEX VARIABLE COMPUTATION, ONE MUST EVALUATE ELE- */
3130/* MENTARY FUNCTIONS. WHEN THE MAGNITUDE OF Z OR FNU+N-1 IS */
3131/* LARGE, LOSSES OF SIGNIFICANCE BY ARGUMENT REDUCTION OCCUR. */
3132/* CONSEQUENTLY, IF EITHER ONE EXCEEDS U1=SQRT(0.5/UR), THEN */
3133/* LOSSES EXCEEDING HALF PRECISION ARE LIKELY AND AN ERROR FLAG */
3134/* IERR=3 IS TRIGGERED WHERE UR=DMAX1(D1MACH(4),1.0D-18) IS */
3135/* DOUBLE PRECISION UNIT ROUNDOFF LIMITED TO 18 DIGITS PRECISION. */
3136/* IF EITHER IS LARGER THAN U2=0.5/UR, THEN ALL SIGNIFICANCE IS */
3137/* LOST AND IERR=4. IN ORDER TO USE THE INT FUNCTION, ARGUMENTS */
3138/* MUST BE FURTHER RESTRICTED NOT TO EXCEED THE LARGEST MACHINE */
3139/* INTEGER, U3=I1MACH(9). THUS, THE MAGNITUDE OF Z AND FNU+N-1 IS */
3140/* RESTRICTED BY MIN(U2,U3). ON 32 BIT MACHINES, U1,U2, AND U3 */
3141/* ARE APPROXIMATELY 2.0E+3, 4.2E+6, 2.1E+9 IN SINGLE PRECISION */
3142/* ARITHMETIC AND 1.3E+8, 1.8E+16, 2.1E+9 IN DOUBLE PRECISION */
3143/* ARITHMETIC RESPECTIVELY. THIS MAKES U2 AND U3 LIMITING IN */
3144/* THEIR RESPECTIVE ARITHMETICS. THIS MEANS THAT ONE CAN EXPECT */
3145/* TO RETAIN, IN THE WORST CASES ON 32 BIT MACHINES, NO DIGITS */
3146/* IN SINGLE AND ONLY 7 DIGITS IN DOUBLE PRECISION ARITHMETIC. */
3147/* SIMILAR CONSIDERATIONS HOLD FOR OTHER MACHINES. */
3148
3149/* THE APPROXIMATE RELATIVE ERROR IN THE MAGNITUDE OF A COMPLEX */
3150/* BESSEL FUNCTION CAN BE EXPRESSED BY P*10**S WHERE P=MAX(UNIT */
3151/* ROUNDOFF,1.0E-18) IS THE NOMINAL PRECISION AND 10**S REPRE- */
3152/* SENTS THE INCREASE IN ERROR DUE TO ARGUMENT REDUCTION IN THE */
3153/* ELEMENTARY FUNCTIONS. HERE, S=MAX(1,ABS(LOG10(CABS(Z))), */
3154/* ABS(LOG10(FNU))) APPROXIMATELY (I.E. S=MAX(1,ABS(EXPONENT OF */
3155/* CABS(Z),ABS(EXPONENT OF FNU)) ). HOWEVER, THE PHASE ANGLE MAY */
3156/* HAVE ONLY ABSOLUTE ACCURACY. THIS IS MOST LIKELY TO OCCUR WHEN */
3157/* ONE COMPONENT (IN ABSOLUTE VALUE) IS LARGER THAN THE OTHER BY */
3158/* SEVERAL ORDERS OF MAGNITUDE. IF ONE COMPONENT IS 10**K LARGER */
3159/* THAN THE OTHER, THEN ONE CAN EXPECT ONLY MAX(ABS(LOG10(P))-K, */
3160/* 0) SIGNIFICANT DIGITS; OR, STATED ANOTHER WAY, WHEN K EXCEEDS */
3161/* THE EXPONENT OF P, NO SIGNIFICANT DIGITS REMAIN IN THE SMALLER */
3162/* COMPONENT. HOWEVER, THE PHASE ANGLE RETAINS ABSOLUTE ACCURACY */
3163/* BECAUSE, IN COMPLEX ARITHMETIC WITH PRECISION P, THE SMALLER */
3164/* COMPONENT WILL NOT (AS A RULE) DECREASE BELOW P TIMES THE */
3165/* MAGNITUDE OF THE LARGER COMPONENT. IN THESE EXTREME CASES, */
3166/* THE PRINCIPAL PHASE ANGLE IS ON THE ORDER OF +P, -P, PI/2-P, */
3167/* OR -PI/2+P. */
3168
3169/* ***REFERENCES HANDBOOK OF MATHEMATICAL FUNCTIONS BY M. ABRAMOWITZ */
3170/* AND I. A. STEGUN, NBS AMS SERIES 55, U.S. DEPT. OF */
3171/* COMMERCE, 1955. */
3172
3173/* COMPUTATION OF BESSEL FUNCTIONS OF COMPLEX ARGUMENT */
3174/* BY D. E. AMOS, SAND83-0083, MAY, 1983. */
3175
3176/* COMPUTATION OF BESSEL FUNCTIONS OF COMPLEX ARGUMENT */
3177/* AND LARGE ORDER BY D. E. AMOS, SAND83-0643, MAY, 1983 */
3178
3179/* A SUBROUTINE PACKAGE FOR BESSEL FUNCTIONS OF A COMPLEX */
3180/* ARGUMENT AND NONNEGATIVE ORDER BY D. E. AMOS, SAND85- */
3181/* 1018, MAY, 1985 */
3182
3183/* A PORTABLE PACKAGE FOR BESSEL FUNCTIONS OF A COMPLEX */
3184/* ARGUMENT AND NONNEGATIVE ORDER BY D. E. AMOS, TRANS. */
3185/* MATH. SOFTWARE, 1986 */
3186
3187/* ***ROUTINES CALLED ZBESH,I1MACH,D1MACH */
3188/* ***END PROLOGUE ZBESY */
3189
3190/* COMPLEX CWRK,CY,C1,C2,EX,HCI,Z,ZU,ZV */
3191/* ***FIRST EXECUTABLE STATEMENT ZBESY */
3192 /* Parameter adjustments */
3193 --cwrki;
3194 --cwrkr;
3195 --cyi;
3196 --cyr;
3197
3198 /* Function Body */
3199 *ierr = 0;
3200 *nz = 0;
3201 if (*zr == 0. && *zi == 0.) {
3202 *ierr = 1;
3203 }
3204 if (*fnu < 0.) {
3205 *ierr = 1;
3206 }
3207 if (*kode < 1 || *kode > 2) {
3208 *ierr = 1;
3209 }
3210 if (*n < 1) {
3211 *ierr = 1;
3212 }
3213 if (*ierr != 0) {
3214 return 0;
3215 }
3216 hcii = .5;
3217 zbesh(zr, zi, fnu, kode, &c__1, n, &cyr[1], &cyi[1], &nz1, ierr);
3218 if (*ierr != 0 && *ierr != 3) {
3219 goto L170;
3220 }
3221 zbesh(zr, zi, fnu, kode, &c__2, n, &cwrkr[1], &cwrki[1], &nz2, ierr);
3222 if (*ierr != 0 && *ierr != 3) {
3223 goto L170;
3224 }
3225 *nz = min(nz1, nz2);
3226 if (*kode == 2) {
3227 goto L60;
3228 }
3229 i__1 = *n;
3230 for (i__ = 1; i__ <= i__1; ++i__) {
3231 str = cwrkr[i__] - cyr[i__];
3232 sti = cwrki[i__] - cyi[i__];
3233 cyr[i__] = -sti * hcii;
3234 cyi[i__] = str * hcii;
3235/* L50: */
3236 }
3237 return 0;
3238 L60:
3239/* Computing MAX */
3240 d__1 = d1mach(&c__4);
3241 tol = max(d__1, 1e-18);
3242 k1 = i1mach(&c__15);
3243 k2 = i1mach(&c__16);
3244/* Computing MIN */
3245 i__1 = abs(k1), i__2 = abs(k2);
3246 k = min(i__1, i__2);
3247 r1m5 = d1mach(&c__5);
3248/* ----------------------------------------------------------------------- */
3249/* ELIM IS THE APPROXIMATE EXPONENTIAL UNDER- AND OVERFLOW LIMIT */
3250/* ----------------------------------------------------------------------- */
3251 elim = ((double) ((float) k) * r1m5 - 3.) * 2.303;
3252 exr = cos(*zr);
3253 exi = sin(*zr);
3254 ey = 0.;
3255 tay = (d__1 = *zi + *zi, abs(d__1));
3256 if (tay < elim) {
3257 ey = exp(-tay);
3258 }
3259 if (*zi < 0.) {
3260 goto L90;
3261 }
3262 c1r = exr * ey;
3263 c1i = exi * ey;
3264 c2r = exr;
3265 c2i = -exi;
3266 L70:
3267 *nz = 0;
3268 rtol = 1. / tol;
3269 ascle = d1mach(&c__1) * rtol * 1e3;
3270 i__1 = *n;
3271 for (i__ = 1; i__ <= i__1; ++i__) {
3272/* STR = C1R*CYR(I) - C1I*CYI(I) */
3273/* STI = C1R*CYI(I) + C1I*CYR(I) */
3274/* STR = -STR + C2R*CWRKR(I) - C2I*CWRKI(I) */
3275/* STI = -STI + C2R*CWRKI(I) + C2I*CWRKR(I) */
3276/* CYR(I) = -STI*HCII */
3277/* CYI(I) = STR*HCII */
3278 aa = cwrkr[i__];
3279 bb = cwrki[i__];
3280 atol = 1.;
3281/* Computing MAX */
3282 d__1 = abs(aa), d__2 = abs(bb);
3283 if (max(d__1, d__2) > ascle) {
3284 goto L75;
3285 }
3286 aa *= rtol;
3287 bb *= rtol;
3288 atol = tol;
3289 L75:
3290 str = (aa * c2r - bb * c2i) * atol;
3291 sti = (aa * c2i + bb * c2r) * atol;
3292 aa = cyr[i__];
3293 bb = cyi[i__];
3294 atol = 1.;
3295/* Computing MAX */
3296 d__1 = abs(aa), d__2 = abs(bb);
3297 if (max(d__1, d__2) > ascle) {
3298 goto L85;
3299 }
3300 aa *= rtol;
3301 bb *= rtol;
3302 atol = tol;
3303 L85:
3304 str -= (aa * c1r - bb * c1i) * atol;
3305 sti -= (aa * c1i + bb * c1r) * atol;
3306 cyr[i__] = -sti * hcii;
3307 cyi[i__] = str * hcii;
3308 if (str == 0. && sti == 0. && ey == 0.) {
3309 ++(*nz);
3310 }
3311/* L80: */
3312 }
3313 return 0;
3314 L90:
3315 c1r = exr;
3316 c1i = exi;
3317 c2r = exr * ey;
3318 c2i = -exi * ey;
3319 goto L70;
3320 L170:
3321 *nz = 0;
3322 return 0;
3323} /* zbesy_ */
3324
3325/* Subroutine */ int zbinu(double *zr, double *zi, double *fnu,
3326 long *kode, long *n, double *cyr, double *cyi,
3327 long *nz, double *rl, double *fnul, double *tol,
3328 double *elim, double *alim)
3329{
3330 /* Initialized data */
3331
3332 double zeror = 0.;
3333 double zeroi = 0.;
3334
3335 /* System generated locals */
3336 long i__1;
3337
3338 /* Local variables */
3339 long i__;
3340 double az;
3341 long nn, nw;
3342 double cwi[2], cwr[2];
3343 long nui, inw;
3344 double dfnu;
3345 extern double azabs(double *, double *);
3346 long nlast;
3347 extern /* Subroutine */ int zbuni(double *, double *, double
3348 *, long *, long *, double *,
3349 double *, long *, long *, long *,
3350 double *, double *, double *,
3351 double *), zseri(double *, double *,
3352 double *, long *,
3353 long *, double *,
3354 double *, long *,
3355 double *, double *,
3356 double *),
3357 zmlri(double *, double *, double *, long *, long *, double *,
3358 double *, long *, double *), zasyi(double *, double *,
3359 double *, long *, long *,
3360 double *, double *,
3361 long *, double *,
3362 double *, double *,
3363 double *), zuoik(double *,
3364 double *,
3365 double *,
3366 long *,
3367 long *,
3368 long *,
3369 double *,
3370 double *,
3371 long *,
3372 double *,
3373 double *,
3374 double
3375 *),
3376 zwrsk(double *, double *, double *, long *, long *, double *,
3377 double *, long *, double *, double *, double *, double *,
3378 double *);
3379
3380/* ***BEGIN PROLOGUE ZBINU */
3381/* ***REFER TO ZBESH,ZBESI,ZBESJ,ZBESK,ZAIRY,ZBIRY */
3382
3383/* ZBINU COMPUTES THE I FUNCTION IN THE RIGHT HALF Z PLANE */
3384
3385/* ***ROUTINES CALLED AZABS,ZASYI,ZBUNI,ZMLRI,ZSERI,ZUOIK,ZWRSK */
3386/* ***END PROLOGUE ZBINU */
3387 /* Parameter adjustments */
3388 --cyi;
3389 --cyr;
3390
3391 /* Function Body */
3392
3393 *nz = 0;
3394 az = azabs(zr, zi);
3395 nn = *n;
3396 dfnu = *fnu + (double) ((float) (*n - 1));
3397 if (az <= 2.) {
3398 goto L10;
3399 }
3400 if (az * az * .25 > dfnu + 1.) {
3401 goto L20;
3402 }
3403 L10:
3404/* ----------------------------------------------------------------------- */
3405/* POWER SERIES */
3406/* ----------------------------------------------------------------------- */
3407 zseri(zr, zi, fnu, kode, &nn, &cyr[1], &cyi[1], &nw, tol, elim, alim);
3408 inw = abs(nw);
3409 *nz += inw;
3410 nn -= inw;
3411 if (nn == 0) {
3412 return 0;
3413 }
3414 if (nw >= 0) {
3415 goto L120;
3416 }
3417 dfnu = *fnu + (double) ((float) (nn - 1));
3418 L20:
3419 if (az < *rl) {
3420 goto L40;
3421 }
3422 if (dfnu <= 1.) {
3423 goto L30;
3424 }
3425 if (az + az < dfnu * dfnu) {
3426 goto L50;
3427 }
3428/* ----------------------------------------------------------------------- */
3429/* ASYMPTOTIC EXPANSION FOR LARGE Z */
3430/* ----------------------------------------------------------------------- */
3431 L30:
3432 zasyi(zr, zi, fnu, kode, &nn, &cyr[1], &cyi[1], &nw, rl, tol, elim,
3433 alim);
3434 if (nw < 0) {
3435 goto L130;
3436 }
3437 goto L120;
3438 L40:
3439 if (dfnu <= 1.) {
3440 goto L70;
3441 }
3442 L50:
3443/* ----------------------------------------------------------------------- */
3444/* OVERFLOW AND UNDERFLOW TEST ON I SEQUENCE FOR MILLER ALGORITHM */
3445/* ----------------------------------------------------------------------- */
3446 zuoik(zr, zi, fnu, kode, &c__1, &nn, &cyr[1], &cyi[1], &nw, tol, elim,
3447 alim);
3448 if (nw < 0) {
3449 goto L130;
3450 }
3451 *nz += nw;
3452 nn -= nw;
3453 if (nn == 0) {
3454 return 0;
3455 }
3456 dfnu = *fnu + (double) ((float) (nn - 1));
3457 if (dfnu > *fnul) {
3458 goto L110;
3459 }
3460 if (az > *fnul) {
3461 goto L110;
3462 }
3463 L60:
3464 if (az > *rl) {
3465 goto L80;
3466 }
3467 L70:
3468/* ----------------------------------------------------------------------- */
3469/* MILLER ALGORITHM NORMALIZED BY THE SERIES */
3470/* ----------------------------------------------------------------------- */
3471 zmlri(zr, zi, fnu, kode, &nn, &cyr[1], &cyi[1], &nw, tol);
3472 if (nw < 0) {
3473 goto L130;
3474 }
3475 goto L120;
3476 L80:
3477/* ----------------------------------------------------------------------- */
3478/* MILLER ALGORITHM NORMALIZED BY THE WRONSKIAN */
3479/* ----------------------------------------------------------------------- */
3480/* ----------------------------------------------------------------------- */
3481/* OVERFLOW TEST ON K FUNCTIONS USED IN WRONSKIAN */
3482/* ----------------------------------------------------------------------- */
3483 zuoik(zr, zi, fnu, kode, &c__2, &c__2, cwr, cwi, &nw, tol, elim, alim);
3484 if (nw >= 0) {
3485 goto L100;
3486 }
3487 *nz = nn;
3488 i__1 = nn;
3489 for (i__ = 1; i__ <= i__1; ++i__) {
3490 cyr[i__] = zeror;
3491 cyi[i__] = zeroi;
3492/* L90: */
3493 }
3494 return 0;
3495 L100:
3496 if (nw > 0) {
3497 goto L130;
3498 }
3499 zwrsk(zr, zi, fnu, kode, &nn, &cyr[1], &cyi[1], &nw, cwr, cwi, tol,
3500 elim, alim);
3501 if (nw < 0) {
3502 goto L130;
3503 }
3504 goto L120;
3505 L110:
3506/* ----------------------------------------------------------------------- */
3507/* INCREMENT FNU+NN-1 UP TO FNUL, COMPUTE AND RECUR BACKWARD */
3508/* ----------------------------------------------------------------------- */
3509 nui = (long) ((float) (*fnul - dfnu)) + 1;
3510 nui = max(nui, 0);
3511 zbuni(zr, zi, fnu, kode, &nn, &cyr[1], &cyi[1], &nw, &nui, &nlast,
3512 fnul, tol, elim, alim);
3513 if (nw < 0) {
3514 goto L130;
3515 }
3516 *nz += nw;
3517 if (nlast == 0) {
3518 goto L120;
3519 }
3520 nn = nlast;
3521 goto L60;
3522 L120:
3523 return 0;
3524 L130:
3525 *nz = -1;
3526 if (nw == -2) {
3527 *nz = -2;
3528 }
3529 return 0;
3530} /* zbinu_ */
3531
3532/* Subroutine */ int zbiry(double *zr, double *zi, long *id,
3533 long *kode, double *bir, double *bii,
3534 long *ierr)
3535{
3536 /* Initialized data */
3537
3538 double tth = .666666666666666667;
3539 double c1 = .614926627446000736;
3540 double c2 = .448288357353826359;
3541 double coef = .577350269189625765;
3542 double pi = 3.14159265358979324;
3543 double coner = 1.;
3544 double conei = 0.;
3545
3546 /* System generated locals */
3547 long i__1, i__2;
3548 double d__1;
3549
3550 /* Builtin functions */
3551 double exp(double), pow_dd(double *, double *), sqrt(double),
3552 log(double), cos(double), sin(double);
3553
3554 /* Local variables */
3555 long k;
3556 double d1, d2;
3557 long k1, k2;
3558 double aa, bb, ad, cc, ak, bk, ck, dk, az, rl;
3559 long nz;
3560 double s1i, az3, s2i, s1r, s2r, z3i, z3r, eaa, fid, dig, cyi[2]
3561 , fmr, r1m5, fnu, cyr[2], tol, sti, str, sfac, alim, elim, csqi,
3562 atrm, fnul, ztai, csqr;
3563 extern /* Subroutine */ int zdiv(double *, double *, double *
3564 , double *, double *, double *);
3565 double ztar, trm1i, trm2i, trm1r, trm2r;
3566 extern double azabs(double *, double *);
3567 extern /* Subroutine */ int zbinu(double *, double *, double
3568 *, long *, long *, double *,
3569 double *, long *, double *, double *,
3570 double *, double *, double *);
3571 extern double d1mach(long *);
3572 extern long i1mach(long *);
3573 extern /* Subroutine */ int azsqrt(double *, double *,
3574 double *, double *);
3575
3576/* ***BEGIN PROLOGUE ZBIRY */
3577/* ***DATE WRITTEN 830501 (YYMMDD) */
3578/* ***REVISION DATE 890801 (YYMMDD) */
3579/* ***CATEGORY NO. B5K */
3580/* ***KEYWORDS AIRY FUNCTION,BESSEL FUNCTIONS OF ORDER ONE THIRD */
3581/* ***AUTHOR AMOS, DONALD E., SANDIA NATIONAL LABORATORIES */
3582/* ***PURPOSE TO COMPUTE AIRY FUNCTIONS BI(Z) AND DBI(Z) FOR COMPLEX Z */
3583/* ***DESCRIPTION */
3584
3585/* ***A DOUBLE PRECISION ROUTINE*** */
3586/* ON KODE=1, CBIRY COMPUTES THE COMPLEX AIRY FUNCTION BI(Z) OR */
3587/* ITS DERIVATIVE DBI(Z)/DZ ON ID=0 OR ID=1 RESPECTIVELY. ON */
3588/* KODE=2, A SCALING OPTION CEXP(-AXZTA)*BI(Z) OR CEXP(-AXZTA)* */
3589/* DBI(Z)/DZ IS PROVIDED TO REMOVE THE EXPONENTIAL BEHAVIOR IN */
3590/* BOTH THE LEFT AND RIGHT HALF PLANES WHERE */
3591/* ZTA=(2/3)*Z*CSQRT(Z)=CMPLX(XZTA,YZTA) AND AXZTA=ABS(XZTA). */
3592/* DEFINTIONS AND NOTATION ARE FOUND IN THE NBS HANDBOOK OF */
3593/* MATHEMATICAL FUNCTIONS (REF. 1). */
3594
3595/* INPUT ZR,ZI ARE DOUBLE PRECISION */
3596/* ZR,ZI - Z=CMPLX(ZR,ZI) */
3597/* ID - ORDER OF DERIVATIVE, ID=0 OR ID=1 */
3598/* KODE - A PARAMETER TO INDICATE THE SCALING OPTION */
3599/* KODE= 1 RETURNS */
3600/* BI=BI(Z) ON ID=0 OR */
3601/* BI=DBI(Z)/DZ ON ID=1 */
3602/* = 2 RETURNS */
3603/* BI=CEXP(-AXZTA)*BI(Z) ON ID=0 OR */
3604/* BI=CEXP(-AXZTA)*DBI(Z)/DZ ON ID=1 WHERE */
3605/* ZTA=(2/3)*Z*CSQRT(Z)=CMPLX(XZTA,YZTA) */
3606/* AND AXZTA=ABS(XZTA) */
3607
3608/* OUTPUT BIR,BII ARE DOUBLE PRECISION */
3609/* BIR,BII- COMPLEX ANSWER DEPENDING ON THE CHOICES FOR ID AND */
3610/* KODE */
3611/* IERR - ERROR FLAG */
3612/* IERR=0, NORMAL RETURN - COMPUTATION COMPLETED */
3613/* IERR=1, INPUT ERROR - NO COMPUTATION */
3614/* IERR=2, OVERFLOW - NO COMPUTATION, REAL(Z) */
3615/* TOO LARGE ON KODE=1 */
3616/* IERR=3, CABS(Z) LARGE - COMPUTATION COMPLETED */
3617/* LOSSES OF SIGNIFCANCE BY ARGUMENT REDUCTION */
3618/* PRODUCE LESS THAN HALF OF MACHINE ACCURACY */
3619/* IERR=4, CABS(Z) TOO LARGE - NO COMPUTATION */
3620/* COMPLETE LOSS OF ACCURACY BY ARGUMENT */
3621/* REDUCTION */
3622/* IERR=5, ERROR - NO COMPUTATION, */
3623/* ALGORITHM TERMINATION CONDITION NOT MET */
3624
3625/* ***LONG DESCRIPTION */
3626
3627/* BI AND DBI ARE COMPUTED FOR CABS(Z).GT.1.0 FROM THE I BESSEL */
3628/* FUNCTIONS BY */
3629
3630/* BI(Z)=C*SQRT(Z)*( I(-1/3,ZTA) + I(1/3,ZTA) ) */
3631/* DBI(Z)=C * Z * ( I(-2/3,ZTA) + I(2/3,ZTA) ) */
3632/* C=1.0/SQRT(3.0) */
3633/* ZTA=(2/3)*Z**(3/2) */
3634
3635/* WITH THE POWER SERIES FOR CABS(Z).LE.1.0. */
3636
3637/* IN MOST COMPLEX VARIABLE COMPUTATION, ONE MUST EVALUATE ELE- */
3638/* MENTARY FUNCTIONS. WHEN THE MAGNITUDE OF Z IS LARGE, LOSSES */
3639/* OF SIGNIFICANCE BY ARGUMENT REDUCTION OCCUR. CONSEQUENTLY, IF */
3640/* THE MAGNITUDE OF ZETA=(2/3)*Z**1.5 EXCEEDS U1=SQRT(0.5/UR), */
3641/* THEN LOSSES EXCEEDING HALF PRECISION ARE LIKELY AND AN ERROR */
3642/* FLAG IERR=3 IS TRIGGERED WHERE UR=DMAX1(D1MACH(4),1.0D-18) IS */
3643/* DOUBLE PRECISION UNIT ROUNDOFF LIMITED TO 18 DIGITS PRECISION. */
3644/* ALSO, IF THE MAGNITUDE OF ZETA IS LARGER THAN U2=0.5/UR, THEN */
3645/* ALL SIGNIFICANCE IS LOST AND IERR=4. IN ORDER TO USE THE INT */
3646/* FUNCTION, ZETA MUST BE FURTHER RESTRICTED NOT TO EXCEED THE */
3647/* LARGEST INTEGER, U3=I1MACH(9). THUS, THE MAGNITUDE OF ZETA */
3648/* MUST BE RESTRICTED BY MIN(U2,U3). ON 32 BIT MACHINES, U1,U2, */
3649/* AND U3 ARE APPROXIMATELY 2.0E+3, 4.2E+6, 2.1E+9 IN SINGLE */
3650/* PRECISION ARITHMETIC AND 1.3E+8, 1.8E+16, 2.1E+9 IN DOUBLE */
3651/* PRECISION ARITHMETIC RESPECTIVELY. THIS MAKES U2 AND U3 LIMIT- */
3652/* ING IN THEIR RESPECTIVE ARITHMETICS. THIS MEANS THAT THE MAG- */
3653/* NITUDE OF Z CANNOT EXCEED 3.1E+4 IN SINGLE AND 2.1E+6 IN */
3654/* DOUBLE PRECISION ARITHMETIC. THIS ALSO MEANS THAT ONE CAN */
3655/* EXPECT TO RETAIN, IN THE WORST CASES ON 32 BIT MACHINES, */
3656/* NO DIGITS IN SINGLE PRECISION AND ONLY 7 DIGITS IN DOUBLE */
3657/* PRECISION ARITHMETIC. SIMILAR CONSIDERATIONS HOLD FOR OTHER */
3658/* MACHINES. */
3659
3660/* THE APPROXIMATE RELATIVE ERROR IN THE MAGNITUDE OF A COMPLEX */
3661/* BESSEL FUNCTION CAN BE EXPRESSED BY P*10**S WHERE P=MAX(UNIT */
3662/* ROUNDOFF,1.0E-18) IS THE NOMINAL PRECISION AND 10**S REPRE- */
3663/* SENTS THE INCREASE IN ERROR DUE TO ARGUMENT REDUCTION IN THE */
3664/* ELEMENTARY FUNCTIONS. HERE, S=MAX(1,ABS(LOG10(CABS(Z))), */
3665/* ABS(LOG10(FNU))) APPROXIMATELY (I.E. S=MAX(1,ABS(EXPONENT OF */
3666/* CABS(Z),ABS(EXPONENT OF FNU)) ). HOWEVER, THE PHASE ANGLE MAY */
3667/* HAVE ONLY ABSOLUTE ACCURACY. THIS IS MOST LIKELY TO OCCUR WHEN */
3668/* ONE COMPONENT (IN ABSOLUTE VALUE) IS LARGER THAN THE OTHER BY */
3669/* SEVERAL ORDERS OF MAGNITUDE. IF ONE COMPONENT IS 10**K LARGER */
3670/* THAN THE OTHER, THEN ONE CAN EXPECT ONLY MAX(ABS(LOG10(P))-K, */
3671/* 0) SIGNIFICANT DIGITS; OR, STATED ANOTHER WAY, WHEN K EXCEEDS */
3672/* THE EXPONENT OF P, NO SIGNIFICANT DIGITS REMAIN IN THE SMALLER */
3673/* COMPONENT. HOWEVER, THE PHASE ANGLE RETAINS ABSOLUTE ACCURACY */
3674/* BECAUSE, IN COMPLEX ARITHMETIC WITH PRECISION P, THE SMALLER */
3675/* COMPONENT WILL NOT (AS A RULE) DECREASE BELOW P TIMES THE */
3676/* MAGNITUDE OF THE LARGER COMPONENT. IN THESE EXTREME CASES, */
3677/* THE PRINCIPAL PHASE ANGLE IS ON THE ORDER OF +P, -P, PI/2-P, */
3678/* OR -PI/2+P. */
3679
3680/* ***REFERENCES HANDBOOK OF MATHEMATICAL FUNCTIONS BY M. ABRAMOWITZ */
3681/* AND I. A. STEGUN, NBS AMS SERIES 55, U.S. DEPT. OF */
3682/* COMMERCE, 1955. */
3683
3684/* COMPUTATION OF BESSEL FUNCTIONS OF COMPLEX ARGUMENT */
3685/* AND LARGE ORDER BY D. E. AMOS, SAND83-0643, MAY, 1983 */
3686
3687/* A SUBROUTINE PACKAGE FOR BESSEL FUNCTIONS OF A COMPLEX */
3688/* ARGUMENT AND NONNEGATIVE ORDER BY D. E. AMOS, SAND85- */
3689/* 1018, MAY, 1985 */
3690
3691/* A PORTABLE PACKAGE FOR BESSEL FUNCTIONS OF A COMPLEX */
3692/* ARGUMENT AND NONNEGATIVE ORDER BY D. E. AMOS, TRANS. */
3693/* MATH. SOFTWARE, 1986 */
3694
3695/* ***ROUTINES CALLED ZBINU,AZABS,ZDIV,AZSQRT,D1MACH,I1MACH */
3696/* ***END PROLOGUE ZBIRY */
3697/* COMPLEX BI,CONE,CSQ,CY,S1,S2,TRM1,TRM2,Z,ZTA,Z3 */
3698/* ***FIRST EXECUTABLE STATEMENT ZBIRY */
3699 *ierr = 0;
3700 nz = 0;
3701 if (*id < 0 || *id > 1) {
3702 *ierr = 1;
3703 }
3704 if (*kode < 1 || *kode > 2) {
3705 *ierr = 1;
3706 }
3707 if (*ierr != 0) {
3708 return 0;
3709 }
3710 az = azabs(zr, zi);
3711/* Computing MAX */
3712 d__1 = d1mach(&c__4);
3713 tol = max(d__1, 1e-18);
3714 fid = (double) ((float) (*id));
3715 if (az > 1.f) {
3716 goto L70;
3717 }
3718/* ----------------------------------------------------------------------- */
3719/* POWER SERIES FOR CABS(Z).LE.1. */
3720/* ----------------------------------------------------------------------- */
3721 s1r = coner;
3722 s1i = conei;
3723 s2r = coner;
3724 s2i = conei;
3725 if (az < tol) {
3726 goto L130;
3727 }
3728 aa = az * az;
3729 if (aa < tol / az) {
3730 goto L40;
3731 }
3732 trm1r = coner;
3733 trm1i = conei;
3734 trm2r = coner;
3735 trm2i = conei;
3736 atrm = 1.;
3737 str = *zr * *zr - *zi * *zi;
3738 sti = *zr * *zi + *zi * *zr;
3739 z3r = str * *zr - sti * *zi;
3740 z3i = str * *zi + sti * *zr;
3741 az3 = az * aa;
3742 ak = fid + 2.;
3743 bk = 3. - fid - fid;
3744 ck = 4. - fid;
3745 dk = fid + 3. + fid;
3746 d1 = ak * dk;
3747 d2 = bk * ck;
3748 ad = min(d1, d2);
3749 ak = fid * 9. + 24.;
3750 bk = 30. - fid * 9.;
3751 for (k = 1; k <= 25; ++k) {
3752 str = (trm1r * z3r - trm1i * z3i) / d1;
3753 trm1i = (trm1r * z3i + trm1i * z3r) / d1;
3754 trm1r = str;
3755 s1r += trm1r;
3756 s1i += trm1i;
3757 str = (trm2r * z3r - trm2i * z3i) / d2;
3758 trm2i = (trm2r * z3i + trm2i * z3r) / d2;
3759 trm2r = str;
3760 s2r += trm2r;
3761 s2i += trm2i;
3762 atrm = atrm * az3 / ad;
3763 d1 += ak;
3764 d2 += bk;
3765 ad = min(d1, d2);
3766 if (atrm < tol * ad) {
3767 goto L40;
3768 }
3769 ak += 18.;
3770 bk += 18.;
3771/* L30: */
3772 }
3773 L40:
3774 if (*id == 1) {
3775 goto L50;
3776 }
3777 *bir = c1 * s1r + c2 * (*zr * s2r - *zi * s2i);
3778 *bii = c1 * s1i + c2 * (*zr * s2i + *zi * s2r);
3779 if (*kode == 1) {
3780 return 0;
3781 }
3782 azsqrt(zr, zi, &str, &sti);
3783 ztar = tth * (*zr * str - *zi * sti);
3784 ztai = tth * (*zr * sti + *zi * str);
3785 aa = ztar;
3786 aa = -abs(aa);
3787 eaa = exp(aa);
3788 *bir *= eaa;
3789 *bii *= eaa;
3790 return 0;
3791 L50:
3792 *bir = s2r * c2;
3793 *bii = s2i * c2;
3794 if (az <= tol) {
3795 goto L60;
3796 }
3797 cc = c1 / (fid + 1.);
3798 str = s1r * *zr - s1i * *zi;
3799 sti = s1r * *zi + s1i * *zr;
3800 *bir += cc * (str * *zr - sti * *zi);
3801 *bii += cc * (str * *zi + sti * *zr);
3802 L60:
3803 if (*kode == 1) {
3804 return 0;
3805 }
3806 azsqrt(zr, zi, &str, &sti);
3807 ztar = tth * (*zr * str - *zi * sti);
3808 ztai = tth * (*zr * sti + *zi * str);
3809 aa = ztar;
3810 aa = -abs(aa);
3811 eaa = exp(aa);
3812 *bir *= eaa;
3813 *bii *= eaa;
3814 return 0;
3815/* ----------------------------------------------------------------------- */
3816/* CASE FOR CABS(Z).GT.1.0 */
3817/* ----------------------------------------------------------------------- */
3818 L70:
3819 fnu = (fid + 1.) / 3.;
3820/* ----------------------------------------------------------------------- */
3821/* SET PARAMETERS RELATED TO MACHINE CONSTANTS. */
3822/* TOL IS THE APPROXIMATE UNIT ROUNDOFF LIMITED TO 1.0E-18. */
3823/* ELIM IS THE APPROXIMATE EXPONENTIAL OVER- AND UNDERFLOW LIMIT. */
3824/* EXP(-ELIM).LT.EXP(-ALIM)=EXP(-ELIM)/TOL AND */
3825/* EXP(ELIM).GT.EXP(ALIM)=EXP(ELIM)*TOL ARE INTERVALS NEAR */
3826/* UNDERFLOW AND OVERFLOW LIMITS WHERE SCALED ARITHMETIC IS DONE. */
3827/* RL IS THE LOWER BOUNDARY OF THE ASYMPTOTIC EXPANSION FOR LARGE Z. */
3828/* DIG = NUMBER OF BASE 10 DIGITS IN TOL = 10**(-DIG). */
3829/* FNUL IS THE LOWER BOUNDARY OF THE ASYMPTOTIC SERIES FOR LARGE FNU. */
3830/* ----------------------------------------------------------------------- */
3831 k1 = i1mach(&c__15);
3832 k2 = i1mach(&c__16);
3833 r1m5 = d1mach(&c__5);
3834/* Computing MIN */
3835 i__1 = abs(k1), i__2 = abs(k2);
3836 k = min(i__1, i__2);
3837 elim = ((double) ((float) k) * r1m5 - 3.) * 2.303;
3838 k1 = i1mach(&c__14) - 1;
3839 aa = r1m5 * (double) ((float) k1);
3840 dig = min(aa, 18.);
3841 aa *= 2.303;
3842/* Computing MAX */
3843 d__1 = -aa;
3844 alim = elim + max(d__1, -41.45);
3845 rl = dig * 1.2 + 3.;
3846 fnul = (dig - 3.) * 6. + 10.;
3847/* ----------------------------------------------------------------------- */
3848/* TEST FOR RANGE */
3849/* ----------------------------------------------------------------------- */
3850 aa = .5 / tol;
3851 bb = (double) ((float) i1mach(&c__9)) * .5;
3852 aa = min(aa, bb);
3853 aa = pow_dd(&aa, &tth);
3854 if (az > aa) {
3855 goto L260;
3856 }
3857 aa = sqrt(aa);
3858 if (az > aa) {
3859 *ierr = 3;
3860 }
3861 azsqrt(zr, zi, &csqr, &csqi);
3862 ztar = tth * (*zr * csqr - *zi * csqi);
3863 ztai = tth * (*zr * csqi + *zi * csqr);
3864/* ----------------------------------------------------------------------- */
3865/* RE(ZTA).LE.0 WHEN RE(Z).LT.0, ESPECIALLY WHEN IM(Z) IS SMALL */
3866/* ----------------------------------------------------------------------- */
3867 sfac = 1.;
3868 ak = ztai;
3869 if (*zr >= 0.) {
3870 goto L80;
3871 }
3872 bk = ztar;
3873 ck = -abs(bk);
3874 ztar = ck;
3875 ztai = ak;
3876 L80:
3877 if (*zi != 0. || *zr > 0.) {
3878 goto L90;
3879 }
3880 ztar = 0.;
3881 ztai = ak;
3882 L90:
3883 aa = ztar;
3884 if (*kode == 2) {
3885 goto L100;
3886 }
3887/* ----------------------------------------------------------------------- */
3888/* OVERFLOW TEST */
3889/* ----------------------------------------------------------------------- */
3890 bb = abs(aa);
3891 if (bb < alim) {
3892 goto L100;
3893 }
3894 bb += log(az) * .25;
3895 sfac = tol;
3896 if (bb > elim) {
3897 goto L190;
3898 }
3899 L100:
3900 fmr = 0.;
3901 if (aa >= 0. && *zr > 0.) {
3902 goto L110;
3903 }
3904 fmr = pi;
3905 if (*zi < 0.) {
3906 fmr = -pi;
3907 }
3908 ztar = -ztar;
3909 ztai = -ztai;
3910 L110:
3911/* ----------------------------------------------------------------------- */
3912/* AA=FACTOR FOR ANALYTIC CONTINUATION OF I(FNU,ZTA) */
3913/* KODE=2 RETURNS EXP(-ABS(XZTA))*I(FNU,ZTA) FROM CBESI */
3914/* ----------------------------------------------------------------------- */
3915 zbinu(&ztar, &ztai, &fnu, kode, &c__1, cyr, cyi, &nz, &rl, &fnul, &tol,
3916 &elim, &alim);
3917 if (nz < 0) {
3918 goto L200;
3919 }
3920 aa = fmr * fnu;
3921 z3r = sfac;
3922 str = cos(aa);
3923 sti = sin(aa);
3924 s1r = (str * cyr[0] - sti * cyi[0]) * z3r;
3925 s1i = (str * cyi[0] + sti * cyr[0]) * z3r;
3926 fnu = (2. - fid) / 3.;
3927 zbinu(&ztar, &ztai, &fnu, kode, &c__2, cyr, cyi, &nz, &rl, &fnul, &tol,
3928 &elim, &alim);
3929 cyr[0] *= z3r;
3930 cyi[0] *= z3r;
3931 cyr[1] *= z3r;
3932 cyi[1] *= z3r;
3933/* ----------------------------------------------------------------------- */
3934/* BACKWARD RECUR ONE STEP FOR ORDERS -1/3 OR -2/3 */
3935/* ----------------------------------------------------------------------- */
3936 zdiv(cyr, cyi, &ztar, &ztai, &str, &sti);
3937 s2r = (fnu + fnu) * str + cyr[1];
3938 s2i = (fnu + fnu) * sti + cyi[1];
3939 aa = fmr * (fnu - 1.);
3940 str = cos(aa);
3941 sti = sin(aa);
3942 s1r = coef * (s1r + s2r * str - s2i * sti);
3943 s1i = coef * (s1i + s2r * sti + s2i * str);
3944 if (*id == 1) {
3945 goto L120;
3946 }
3947 str = csqr * s1r - csqi * s1i;
3948 s1i = csqr * s1i + csqi * s1r;
3949 s1r = str;
3950 *bir = s1r / sfac;
3951 *bii = s1i / sfac;
3952 return 0;
3953 L120:
3954 str = *zr * s1r - *zi * s1i;
3955 s1i = *zr * s1i + *zi * s1r;
3956 s1r = str;
3957 *bir = s1r / sfac;
3958 *bii = s1i / sfac;
3959 return 0;
3960 L130:
3961 aa = c1 * (1. - fid) + fid * c2;
3962 *bir = aa;
3963 *bii = 0.;
3964 return 0;
3965 L190:
3966 *ierr = 2;
3967 nz = 0;
3968 return 0;
3969 L200:
3970 if (nz == -1) {
3971 goto L190;
3972 }
3973 nz = 0;
3974 *ierr = 5;
3975 return 0;
3976 L260:
3977 *ierr = 4;
3978 nz = 0;
3979 return 0;
3980} /* zbiry_ */
3981
3982/* Subroutine */ int zbknu(double *zr, double *zi, double *fnu,
3983 long *kode, long *n, double *yr, double *yi,
3984 long *nz, double *tol, double *elim,
3985 double *alim)
3986{
3987 /* Initialized data */
3988
3989 long kmax = 30;
3990 double czeror = 0.;
3991 double czeroi = 0.;
3992 double coner = 1.;
3993 double conei = 0.;
3994 double ctwor = 2.;
3995 double r1 = 2.;
3996 double dpi = 3.14159265358979324;
3997 double rthpi = 1.25331413731550025;
3998 double spi = 1.90985931710274403;
3999 double hpi = 1.57079632679489662;
4000 double fpi = 1.89769999331517738;
4001 double tth = .666666666666666666;
4002 double cc[8] = { .577215664901532861, -.0420026350340952355,
4003 -.0421977345555443367, .00721894324666309954,
4004 -2.15241674114950973e-4, -2.01348547807882387e-5,
4005 1.13302723198169588e-6, 6.11609510448141582e-9
4006 };
4007
4008 /* System generated locals */
4009 long i__1;
4010 double d__1;
4011
4012 /* Builtin functions */
4013 double sin(double), exp(double), cos(double), atan(double)
4014 , sqrt(double), log(double);
4015
4016 /* Local variables */
4017 long i__, j, k;
4018 double s, a1, a2, g1, g2, t1, t2, aa, bb, fc, ak, bk;
4019 long ic;
4020 double fi, fk, as;
4021 long kk;
4022 double fr, pi, qi, tm, pr, qr;
4023 long nw;
4024 double p1i, p2i, s1i, s2i, p2m, p1r, p2r, s1r, s2r, cbi, cbr,
4025 cki, caz, csi, ckr, fhs, fks, rak, czi, dnu, csr, elm, zdi, bry[3]
4026 , pti, czr, sti, zdr, cyr[2], rzi, ptr, cyi[2];
4027 long inu;
4028 double str, rzr, dnu2, cchi, cchr, alas, cshi;
4029 long inub, idum;
4030 double cshr, fmui, rcaz, csrr[3], cssr[3], fmur;
4031 extern /* Subroutine */ int zdiv(double *, double *, double *
4032 , double *, double *, double *);
4033 double smui, smur;
4034 extern /* Subroutine */ int zmlt(double *, double *, double *
4035 , double *, double *, double *);
4036 long iflag, kflag;
4037 double coefi;
4038 long koded;
4039 double ascle, coefr, helim;
4040 extern double azabs(double *, double *);
4041 double celmr, csclr, crscr;
4042 extern /* Subroutine */ int azlog(double *, double *, double
4043 *, double *, long *), zshch(double *,
4044 double *,
4045 double *,
4046 double *,
4047 double *,
4048 double
4049 *);
4050 double etest;
4051 extern /* Subroutine */ int zuchk(double *, double *, long *,
4052 double *, double *), azexp(double *,
4053 double *,
4054 double *,
4055 double *),
4056 zkscl(double *, double *, double *, long *, double *, double *,
4057 long *, double *, double *, double *, double *, double *);
4058 extern double d1mach(long *);
4059 extern long i1mach(long *);
4060 extern double dgamln(double *, long *);
4061 extern /* Subroutine */ int azsqrt(double *, double *,
4062 double *, double *);
4063
4064/* ***BEGIN PROLOGUE ZBKNU */
4065/* ***REFER TO ZBESI,ZBESK,ZAIRY,ZBESH */
4066
4067/* ZBKNU COMPUTES THE K BESSEL FUNCTION IN THE RIGHT HALF Z PLANE. */
4068
4069/* ***ROUTINES CALLED DGAMLN,I1MACH,D1MACH,ZKSCL,ZSHCH,ZUCHK,AZABS,ZDIV, */
4070/* AZEXP,AZLOG,ZMLT,AZSQRT */
4071/* ***END PROLOGUE ZBKNU */
4072
4073/* COMPLEX Z,Y,A,B,RZ,SMU,FU,FMU,F,FLRZ,CZ,S1,S2,CSH,CCH */
4074/* COMPLEX CK,P,Q,COEF,P1,P2,CBK,PT,CZERO,CONE,CTWO,ST,EZ,CS,DK */
4075
4076 /* Parameter adjustments */
4077 --yi;
4078 --yr;
4079
4080 /* Function Body */
4081
4082 caz = azabs(zr, zi);
4083 csclr = 1. / *tol;
4084 crscr = *tol;
4085 cssr[0] = csclr;
4086 cssr[1] = 1.;
4087 cssr[2] = crscr;
4088 csrr[0] = crscr;
4089 csrr[1] = 1.;
4090 csrr[2] = csclr;
4091 bry[0] = d1mach(&c__1) * 1e3 / *tol;
4092 bry[1] = 1. / bry[0];
4093 bry[2] = d1mach(&c__2);
4094 *nz = 0;
4095 iflag = 0;
4096 koded = *kode;
4097 rcaz = 1. / caz;
4098 str = *zr * rcaz;
4099 sti = -(*zi) * rcaz;
4100 rzr = (str + str) * rcaz;
4101 rzi = (sti + sti) * rcaz;
4102 inu = (long) ((float) (*fnu + .5));
4103 dnu = *fnu - (double) ((float) inu);
4104 if (abs(dnu) == .5) {
4105 goto L110;
4106 }
4107 dnu2 = 0.;
4108 if (abs(dnu) > *tol) {
4109 dnu2 = dnu * dnu;
4110 }
4111 if (caz > r1) {
4112 goto L110;
4113 }
4114/* ----------------------------------------------------------------------- */
4115/* SERIES FOR CABS(Z).LE.R1 */
4116/* ----------------------------------------------------------------------- */
4117 fc = 1.;
4118 azlog(&rzr, &rzi, &smur, &smui, &idum);
4119 fmur = smur * dnu;
4120 fmui = smui * dnu;
4121 zshch(&fmur, &fmui, &cshr, &cshi, &cchr, &cchi);
4122 if (dnu == 0.) {
4123 goto L10;
4124 }
4125 fc = dnu * dpi;
4126 fc /= sin(fc);
4127 smur = cshr / dnu;
4128 smui = cshi / dnu;
4129 L10:
4130 a2 = dnu + 1.;
4131/* ----------------------------------------------------------------------- */
4132/* GAM(1-Z)*GAM(1+Z)=PI*Z/SIN(PI*Z), T1=1/GAM(1-DNU), T2=1/GAM(1+DNU) */
4133/* ----------------------------------------------------------------------- */
4134 t2 = exp(-dgamln(&a2, &idum));
4135 t1 = 1. / (t2 * fc);
4136 if (abs(dnu) > .1) {
4137 goto L40;
4138 }
4139/* ----------------------------------------------------------------------- */
4140/* SERIES FOR F0 TO RESOLVE INDETERMINACY FOR SMALL ABS(DNU) */
4141/* ----------------------------------------------------------------------- */
4142 ak = 1.;
4143 s = cc[0];
4144 for (k = 2; k <= 8; ++k) {
4145 ak *= dnu2;
4146 tm = cc[k - 1] * ak;
4147 s += tm;
4148 if (abs(tm) < *tol) {
4149 goto L30;
4150 }
4151/* L20: */
4152 }
4153 L30:
4154 g1 = -s;
4155 goto L50;
4156 L40:
4157 g1 = (t1 - t2) / (dnu + dnu);
4158 L50:
4159 g2 = (t1 + t2) * .5;
4160 fr = fc * (cchr * g1 + smur * g2);
4161 fi = fc * (cchi * g1 + smui * g2);
4162 azexp(&fmur, &fmui, &str, &sti);
4163 pr = str * .5 / t2;
4164 pi = sti * .5 / t2;
4165 zdiv(&c_b219, &c_b220, &str, &sti, &ptr, &pti);
4166 qr = ptr / t1;
4167 qi = pti / t1;
4168 s1r = fr;
4169 s1i = fi;
4170 s2r = pr;
4171 s2i = pi;
4172 ak = 1.;
4173 a1 = 1.;
4174 ckr = coner;
4175 cki = conei;
4176 bk = 1. - dnu2;
4177 if (inu > 0 || *n > 1) {
4178 goto L80;
4179 }
4180/* ----------------------------------------------------------------------- */
4181/* GENERATE K(FNU,Z), 0.0D0 .LE. FNU .LT. 0.5D0 AND N=1 */
4182/* ----------------------------------------------------------------------- */
4183 if (caz < *tol) {
4184 goto L70;
4185 }
4186 zmlt(zr, zi, zr, zi, &czr, &czi);
4187 czr *= .25;
4188 czi *= .25;
4189 t1 = caz * .25 * caz;
4190 L60:
4191 fr = (fr * ak + pr + qr) / bk;
4192 fi = (fi * ak + pi + qi) / bk;
4193 str = 1. / (ak - dnu);
4194 pr *= str;
4195 pi *= str;
4196 str = 1. / (ak + dnu);
4197 qr *= str;
4198 qi *= str;
4199 str = ckr * czr - cki * czi;
4200 rak = 1. / ak;
4201 cki = (ckr * czi + cki * czr) * rak;
4202 ckr = str * rak;
4203 s1r = ckr * fr - cki * fi + s1r;
4204 s1i = ckr * fi + cki * fr + s1i;
4205 a1 = a1 * t1 * rak;
4206 bk = bk + ak + ak + 1.;
4207 ak += 1.;
4208 if (a1 > *tol) {
4209 goto L60;
4210 }
4211 L70:
4212 yr[1] = s1r;
4213 yi[1] = s1i;
4214 if (koded == 1) {
4215 return 0;
4216 }
4217 azexp(zr, zi, &str, &sti);
4218 zmlt(&s1r, &s1i, &str, &sti, &yr[1], &yi[1]);
4219 return 0;
4220/* ----------------------------------------------------------------------- */
4221/* GENERATE K(DNU,Z) AND K(DNU+1,Z) FOR FORWARD RECURRENCE */
4222/* ----------------------------------------------------------------------- */
4223 L80:
4224 if (caz < *tol) {
4225 goto L100;
4226 }
4227 zmlt(zr, zi, zr, zi, &czr, &czi);
4228 czr *= .25;
4229 czi *= .25;
4230 t1 = caz * .25 * caz;
4231 L90:
4232 fr = (fr * ak + pr + qr) / bk;
4233 fi = (fi * ak + pi + qi) / bk;
4234 str = 1. / (ak - dnu);
4235 pr *= str;
4236 pi *= str;
4237 str = 1. / (ak + dnu);
4238 qr *= str;
4239 qi *= str;
4240 str = ckr * czr - cki * czi;
4241 rak = 1. / ak;
4242 cki = (ckr * czi + cki * czr) * rak;
4243 ckr = str * rak;
4244 s1r = ckr * fr - cki * fi + s1r;
4245 s1i = ckr * fi + cki * fr + s1i;
4246 str = pr - fr * ak;
4247 sti = pi - fi * ak;
4248 s2r = ckr * str - cki * sti + s2r;
4249 s2i = ckr * sti + cki * str + s2i;
4250 a1 = a1 * t1 * rak;
4251 bk = bk + ak + ak + 1.;
4252 ak += 1.;
4253 if (a1 > *tol) {
4254 goto L90;
4255 }
4256 L100:
4257 kflag = 2;
4258 a1 = *fnu + 1.;
4259 ak = a1 * abs(smur);
4260 if (ak > *alim) {
4261 kflag = 3;
4262 }
4263 str = cssr[kflag - 1];
4264 p2r = s2r * str;
4265 p2i = s2i * str;
4266 zmlt(&p2r, &p2i, &rzr, &rzi, &s2r, &s2i);
4267 s1r *= str;
4268 s1i *= str;
4269 if (koded == 1) {
4270 goto L210;
4271 }
4272 azexp(zr, zi, &fr, &fi);
4273 zmlt(&s1r, &s1i, &fr, &fi, &s1r, &s1i);
4274 zmlt(&s2r, &s2i, &fr, &fi, &s2r, &s2i);
4275 goto L210;
4276/* ----------------------------------------------------------------------- */
4277/* IFLAG=0 MEANS NO UNDERFLOW OCCURRED */
4278/* IFLAG=1 MEANS AN UNDERFLOW OCCURRED- COMPUTATION PROCEEDS WITH */
4279/* KODED=2 AND A TEST FOR ON SCALE VALUES IS MADE DURING FORWARD */
4280/* RECURSION */
4281/* ----------------------------------------------------------------------- */
4282 L110:
4283 azsqrt(zr, zi, &str, &sti);
4284 zdiv(&rthpi, &czeroi, &str, &sti, &coefr, &coefi);
4285 kflag = 2;
4286 if (koded == 2) {
4287 goto L120;
4288 }
4289 if (*zr > *alim) {
4290 goto L290;
4291 }
4292/* BLANK LINE */
4293 str = exp(-(*zr)) * cssr[kflag - 1];
4294 sti = -str * sin(*zi);
4295 str *= cos(*zi);
4296 zmlt(&coefr, &coefi, &str, &sti, &coefr, &coefi);
4297 L120:
4298 if (abs(dnu) == .5) {
4299 goto L300;
4300 }
4301/* ----------------------------------------------------------------------- */
4302/* MILLER ALGORITHM FOR CABS(Z).GT.R1 */
4303/* ----------------------------------------------------------------------- */
4304 ak = cos(dpi * dnu);
4305 ak = abs(ak);
4306 if (ak == czeror) {
4307 goto L300;
4308 }
4309 fhs = (d__1 = .25 - dnu2, abs(d__1));
4310 if (fhs == czeror) {
4311 goto L300;
4312 }
4313/* ----------------------------------------------------------------------- */
4314/* COMPUTE R2=F(E). IF CABS(Z).GE.R2, USE FORWARD RECURRENCE TO */
4315/* DETERMINE THE BACKWARD INDEX K. R2=F(E) IS A STRAIGHT LINE ON */
4316/* 12.LE.E.LE.60. E IS COMPUTED FROM 2**(-E)=B**(1-I1MACH(14))= */
4317/* TOL WHERE B IS THE BASE OF THE ARITHMETIC. */
4318/* ----------------------------------------------------------------------- */
4319 t1 = (double) ((float) (i1mach(&c__14) - 1));
4320 t1 = t1 * d1mach(&c__5) * 3.321928094;
4321 t1 = max(t1, 12.);
4322 t1 = min(t1, 60.);
4323 t2 = tth * t1 - 6.;
4324 if (*zr != 0.) {
4325 goto L130;
4326 }
4327 t1 = hpi;
4328 goto L140;
4329 L130:
4330 t1 = atan(*zi / *zr);
4331 t1 = abs(t1);
4332 L140:
4333 if (t2 > caz) {
4334 goto L170;
4335 }
4336/* ----------------------------------------------------------------------- */
4337/* FORWARD RECURRENCE LOOP WHEN CABS(Z).GE.R2 */
4338/* ----------------------------------------------------------------------- */
4339 etest = ak / (dpi * caz * *tol);
4340 fk = coner;
4341 if (etest < coner) {
4342 goto L180;
4343 }
4344 fks = ctwor;
4345 ckr = caz + caz + ctwor;
4346 p1r = czeror;
4347 p2r = coner;
4348 i__1 = kmax;
4349 for (i__ = 1; i__ <= i__1; ++i__) {
4350 ak = fhs / fks;
4351 cbr = ckr / (fk + coner);
4352 ptr = p2r;
4353 p2r = cbr * p2r - p1r * ak;
4354 p1r = ptr;
4355 ckr += ctwor;
4356 fks = fks + fk + fk + ctwor;
4357 fhs = fhs + fk + fk;
4358 fk += coner;
4359 str = abs(p2r) * fk;
4360 if (etest < str) {
4361 goto L160;
4362 }
4363/* L150: */
4364 }
4365 goto L310;
4366 L160:
4367 fk += spi * t1 * sqrt(t2 / caz);
4368 fhs = (d__1 = .25 - dnu2, abs(d__1));
4369 goto L180;
4370 L170:
4371/* ----------------------------------------------------------------------- */
4372/* COMPUTE BACKWARD INDEX K FOR CABS(Z).LT.R2 */
4373/* ----------------------------------------------------------------------- */
4374 a2 = sqrt(caz);
4375 ak = fpi * ak / (*tol * sqrt(a2));
4376 aa = t1 * 3. / (caz + 1.);
4377 bb = t1 * 14.7 / (caz + 28.);
4378 ak = (log(ak) + caz * cos(aa) / (caz * .008 + 1.)) / cos(bb);
4379 fk = ak * .12125 * ak / caz + 1.5;
4380 L180:
4381/* ----------------------------------------------------------------------- */
4382/* BACKWARD RECURRENCE LOOP FOR MILLER ALGORITHM */
4383/* ----------------------------------------------------------------------- */
4384 k = (long) ((float) fk);
4385 fk = (double) ((float) k);
4386 fks = fk * fk;
4387 p1r = czeror;
4388 p1i = czeroi;
4389 p2r = *tol;
4390 p2i = czeroi;
4391 csr = p2r;
4392 csi = p2i;
4393 i__1 = k;
4394 for (i__ = 1; i__ <= i__1; ++i__) {
4395 a1 = fks - fk;
4396 ak = (fks + fk) / (a1 + fhs);
4397 rak = 2. / (fk + coner);
4398 cbr = (fk + *zr) * rak;
4399 cbi = *zi * rak;
4400 ptr = p2r;
4401 pti = p2i;
4402 p2r = (ptr * cbr - pti * cbi - p1r) * ak;
4403 p2i = (pti * cbr + ptr * cbi - p1i) * ak;
4404 p1r = ptr;
4405 p1i = pti;
4406 csr += p2r;
4407 csi += p2i;
4408 fks = a1 - fk + coner;
4409 fk -= coner;
4410/* L190: */
4411 }
4412/* ----------------------------------------------------------------------- */
4413/* COMPUTE (P2/CS)=(P2/CABS(CS))*(CONJG(CS)/CABS(CS)) FOR BETTER */
4414/* SCALING */
4415/* ----------------------------------------------------------------------- */
4416 tm = azabs(&csr, &csi);
4417 ptr = 1. / tm;
4418 s1r = p2r * ptr;
4419 s1i = p2i * ptr;
4420 csr *= ptr;
4421 csi = -csi * ptr;
4422 zmlt(&coefr, &coefi, &s1r, &s1i, &str, &sti);
4423 zmlt(&str, &sti, &csr, &csi, &s1r, &s1i);
4424 if (inu > 0 || *n > 1) {
4425 goto L200;
4426 }
4427 zdr = *zr;
4428 zdi = *zi;
4429 if (iflag == 1) {
4430 goto L270;
4431 }
4432 goto L240;
4433 L200:
4434/* ----------------------------------------------------------------------- */
4435/* COMPUTE P1/P2=(P1/CABS(P2)*CONJG(P2)/CABS(P2) FOR SCALING */
4436/* ----------------------------------------------------------------------- */
4437 tm = azabs(&p2r, &p2i);
4438 ptr = 1. / tm;
4439 p1r *= ptr;
4440 p1i *= ptr;
4441 p2r *= ptr;
4442 p2i = -p2i * ptr;
4443 zmlt(&p1r, &p1i, &p2r, &p2i, &ptr, &pti);
4444 str = dnu + .5 - ptr;
4445 sti = -pti;
4446 zdiv(&str, &sti, zr, zi, &str, &sti);
4447 str += 1.;
4448 zmlt(&str, &sti, &s1r, &s1i, &s2r, &s2i);
4449/* ----------------------------------------------------------------------- */
4450/* FORWARD RECURSION ON THE THREE TERM RECURSION WITH RELATION WITH */
4451/* SCALING NEAR EXPONENT EXTREMES ON KFLAG=1 OR KFLAG=3 */
4452/* ----------------------------------------------------------------------- */
4453 L210:
4454 str = dnu + 1.;
4455 ckr = str * rzr;
4456 cki = str * rzi;
4457 if (*n == 1) {
4458 --inu;
4459 }
4460 if (inu > 0) {
4461 goto L220;
4462 }
4463 if (*n > 1) {
4464 goto L215;
4465 }
4466 s1r = s2r;
4467 s1i = s2i;
4468 L215:
4469 zdr = *zr;
4470 zdi = *zi;
4471 if (iflag == 1) {
4472 goto L270;
4473 }
4474 goto L240;
4475 L220:
4476 inub = 1;
4477 if (iflag == 1) {
4478 goto L261;
4479 }
4480 L225:
4481 p1r = csrr[kflag - 1];
4482 ascle = bry[kflag - 1];
4483 i__1 = inu;
4484 for (i__ = inub; i__ <= i__1; ++i__) {
4485 str = s2r;
4486 sti = s2i;
4487 s2r = ckr * str - cki * sti + s1r;
4488 s2i = ckr * sti + cki * str + s1i;
4489 s1r = str;
4490 s1i = sti;
4491 ckr += rzr;
4492 cki += rzi;
4493 if (kflag >= 3) {
4494 goto L230;
4495 }
4496 p2r = s2r * p1r;
4497 p2i = s2i * p1r;
4498 str = abs(p2r);
4499 sti = abs(p2i);
4500 p2m = max(str, sti);
4501 if (p2m <= ascle) {
4502 goto L230;
4503 }
4504 ++kflag;
4505 ascle = bry[kflag - 1];
4506 s1r *= p1r;
4507 s1i *= p1r;
4508 s2r = p2r;
4509 s2i = p2i;
4510 str = cssr[kflag - 1];
4511 s1r *= str;
4512 s1i *= str;
4513 s2r *= str;
4514 s2i *= str;
4515 p1r = csrr[kflag - 1];
4516 L230:
4517 ;
4518 }
4519 if (*n != 1) {
4520 goto L240;
4521 }
4522 s1r = s2r;
4523 s1i = s2i;
4524 L240:
4525 str = csrr[kflag - 1];
4526 yr[1] = s1r * str;
4527 yi[1] = s1i * str;
4528 if (*n == 1) {
4529 return 0;
4530 }
4531 yr[2] = s2r * str;
4532 yi[2] = s2i * str;
4533 if (*n == 2) {
4534 return 0;
4535 }
4536 kk = 2;
4537 L250:
4538 ++kk;
4539 if (kk > *n) {
4540 return 0;
4541 }
4542 p1r = csrr[kflag - 1];
4543 ascle = bry[kflag - 1];
4544 i__1 = *n;
4545 for (i__ = kk; i__ <= i__1; ++i__) {
4546 p2r = s2r;
4547 p2i = s2i;
4548 s2r = ckr * p2r - cki * p2i + s1r;
4549 s2i = cki * p2r + ckr * p2i + s1i;
4550 s1r = p2r;
4551 s1i = p2i;
4552 ckr += rzr;
4553 cki += rzi;
4554 p2r = s2r * p1r;
4555 p2i = s2i * p1r;
4556 yr[i__] = p2r;
4557 yi[i__] = p2i;
4558 if (kflag >= 3) {
4559 goto L260;
4560 }
4561 str = abs(p2r);
4562 sti = abs(p2i);
4563 p2m = max(str, sti);
4564 if (p2m <= ascle) {
4565 goto L260;
4566 }
4567 ++kflag;
4568 ascle = bry[kflag - 1];
4569 s1r *= p1r;
4570 s1i *= p1r;
4571 s2r = p2r;
4572 s2i = p2i;
4573 str = cssr[kflag - 1];
4574 s1r *= str;
4575 s1i *= str;
4576 s2r *= str;
4577 s2i *= str;
4578 p1r = csrr[kflag - 1];
4579 L260:
4580 ;
4581 }
4582 return 0;
4583/* ----------------------------------------------------------------------- */
4584/* IFLAG=1 CASES, FORWARD RECURRENCE ON SCALED VALUES ON UNDERFLOW */
4585/* ----------------------------------------------------------------------- */
4586 L261:
4587 helim = *elim * .5;
4588 elm = exp(-(*elim));
4589 celmr = elm;
4590 ascle = bry[0];
4591 zdr = *zr;
4592 zdi = *zi;
4593 ic = -1;
4594 j = 2;
4595 i__1 = inu;
4596 for (i__ = 1; i__ <= i__1; ++i__) {
4597 str = s2r;
4598 sti = s2i;
4599 s2r = str * ckr - sti * cki + s1r;
4600 s2i = sti * ckr + str * cki + s1i;
4601 s1r = str;
4602 s1i = sti;
4603 ckr += rzr;
4604 cki += rzi;
4605 as = azabs(&s2r, &s2i);
4606 alas = log(as);
4607 p2r = -zdr + alas;
4608 if (p2r < -(*elim)) {
4609 goto L263;
4610 }
4611 azlog(&s2r, &s2i, &str, &sti, &idum);
4612 p2r = -zdr + str;
4613 p2i = -zdi + sti;
4614 p2m = exp(p2r) / *tol;
4615 p1r = p2m * cos(p2i);
4616 p1i = p2m * sin(p2i);
4617 zuchk(&p1r, &p1i, &nw, &ascle, tol);
4618 if (nw != 0) {
4619 goto L263;
4620 }
4621 j = 3 - j;
4622 cyr[j - 1] = p1r;
4623 cyi[j - 1] = p1i;
4624 if (ic == i__ - 1) {
4625 goto L264;
4626 }
4627 ic = i__;
4628 goto L262;
4629 L263:
4630 if (alas < helim) {
4631 goto L262;
4632 }
4633 zdr -= *elim;
4634 s1r *= celmr;
4635 s1i *= celmr;
4636 s2r *= celmr;
4637 s2i *= celmr;
4638 L262:
4639 ;
4640 }
4641 if (*n != 1) {
4642 goto L270;
4643 }
4644 s1r = s2r;
4645 s1i = s2i;
4646 goto L270;
4647 L264:
4648 kflag = 1;
4649 inub = i__ + 1;
4650 s2r = cyr[j - 1];
4651 s2i = cyi[j - 1];
4652 j = 3 - j;
4653 s1r = cyr[j - 1];
4654 s1i = cyi[j - 1];
4655 if (inub <= inu) {
4656 goto L225;
4657 }
4658 if (*n != 1) {
4659 goto L240;
4660 }
4661 s1r = s2r;
4662 s1i = s2i;
4663 goto L240;
4664 L270:
4665 yr[1] = s1r;
4666 yi[1] = s1i;
4667 if (*n == 1) {
4668 goto L280;
4669 }
4670 yr[2] = s2r;
4671 yi[2] = s2i;
4672 L280:
4673 ascle = bry[0];
4674 zkscl(&zdr, &zdi, fnu, n, &yr[1], &yi[1], nz, &rzr, &rzi, &ascle, tol,
4675 elim);
4676 inu = *n - *nz;
4677 if (inu <= 0) {
4678 return 0;
4679 }
4680 kk = *nz + 1;
4681 s1r = yr[kk];
4682 s1i = yi[kk];
4683 yr[kk] = s1r * csrr[0];
4684 yi[kk] = s1i * csrr[0];
4685 if (inu == 1) {
4686 return 0;
4687 }
4688 kk = *nz + 2;
4689 s2r = yr[kk];
4690 s2i = yi[kk];
4691 yr[kk] = s2r * csrr[0];
4692 yi[kk] = s2i * csrr[0];
4693 if (inu == 2) {
4694 return 0;
4695 }
4696 t2 = *fnu + (double) ((float) (kk - 1));
4697 ckr = t2 * rzr;
4698 cki = t2 * rzi;
4699 kflag = 1;
4700 goto L250;
4701 L290:
4702/* ----------------------------------------------------------------------- */
4703/* SCALE BY DEXP(Z), IFLAG = 1 CASES */
4704/* ----------------------------------------------------------------------- */
4705 koded = 2;
4706 iflag = 1;
4707 kflag = 2;
4708 goto L120;
4709/* ----------------------------------------------------------------------- */
4710/* FNU=HALF ODD INTEGER CASE, DNU=-0.5 */
4711/* ----------------------------------------------------------------------- */
4712 L300:
4713 s1r = coefr;
4714 s1i = coefi;
4715 s2r = coefr;
4716 s2i = coefi;
4717 goto L210;
4718
4719
4720 L310:
4721 *nz = -2;
4722 return 0;
4723} /* zbknu_ */
4724
4725/* Subroutine */ int zbuni(double *zr, double *zi, double *fnu,
4726 long *kode, long *n, double *yr, double *yi,
4727 long *nz, long *nui, long *nlast, double *fnul,
4728 double *tol, double *elim, double *alim)
4729{
4730 /* System generated locals */
4731 long i__1;
4732
4733 /* Local variables */
4734 long i__, k;
4735 double ax, ay;
4736 long nl, nw;
4737 double c1i, c1m, c1r, s1i, s2i, s1r, s2r, cyi[2], gnu, raz,
4738 cyr[2], sti, bry[3], rzi, str, rzr, dfnu, fnui;
4739 extern /* Subroutine */ int zuni1(double *, double *, double
4740 *, long *, long *, double *,
4741 double *, long *, long *, double *,
4742 double *, double *, double *)
4743 , zuni2(double *, double *, double *, long *, long *, double *,
4744 double *, long *, long *, double *, double *, double *,
4745 double *);
4746 long iflag;
4747 double ascle;
4748 extern double azabs(double *, double *);
4749 double csclr, cscrr;
4750 long iform;
4751 extern double d1mach(long *);
4752
4753/* ***BEGIN PROLOGUE ZBUNI */
4754/* ***REFER TO ZBESI,ZBESK */
4755
4756/* ZBUNI COMPUTES THE I BESSEL FUNCTION FOR LARGE CABS(Z).GT. */
4757/* FNUL AND FNU+N-1.LT.FNUL. THE ORDER IS INCREASED FROM */
4758/* FNU+N-1 GREATER THAN FNUL BY ADDING NUI AND COMPUTING */
4759/* ACCORDING TO THE UNIFORM ASYMPTOTIC EXPANSION FOR I(FNU,Z) */
4760/* ON IFORM=1 AND THE EXPANSION FOR J(FNU,Z) ON IFORM=2 */
4761
4762/* ***ROUTINES CALLED ZUNI1,ZUNI2,AZABS,D1MACH */
4763/* ***END PROLOGUE ZBUNI */
4764/* COMPLEX CSCL,CSCR,CY,RZ,ST,S1,S2,Y,Z */
4765 /* Parameter adjustments */
4766 --yi;
4767 --yr;
4768
4769 /* Function Body */
4770 *nz = 0;
4771 ax = abs(*zr) * 1.7321;
4772 ay = abs(*zi);
4773 iform = 1;
4774 if (ay > ax) {
4775 iform = 2;
4776 }
4777 if (*nui == 0) {
4778 goto L60;
4779 }
4780 fnui = (double) ((float) (*nui));
4781 dfnu = *fnu + (double) ((float) (*n - 1));
4782 gnu = dfnu + fnui;
4783 if (iform == 2) {
4784 goto L10;
4785 }
4786/* ----------------------------------------------------------------------- */
4787/* ASYMPTOTIC EXPANSION FOR I(FNU,Z) FOR LARGE FNU APPLIED IN */
4788/* -PI/3.LE.ARG(Z).LE.PI/3 */
4789/* ----------------------------------------------------------------------- */
4790 zuni1(zr, zi, &gnu, kode, &c__2, cyr, cyi, &nw, nlast, fnul, tol, elim,
4791 alim);
4792 goto L20;
4793 L10:
4794/* ----------------------------------------------------------------------- */
4795/* ASYMPTOTIC EXPANSION FOR J(FNU,Z*EXP(M*HPI)) FOR LARGE FNU */
4796/* APPLIED IN PI/3.LT.ABS(ARG(Z)).LE.PI/2 WHERE M=+I OR -I */
4797/* AND HPI=PI/2 */
4798/* ----------------------------------------------------------------------- */
4799 zuni2(zr, zi, &gnu, kode, &c__2, cyr, cyi, &nw, nlast, fnul, tol, elim,
4800 alim);
4801 L20:
4802 if (nw < 0) {
4803 goto L50;
4804 }
4805 if (nw != 0) {
4806 goto L90;
4807 }
4808 str = azabs(cyr, cyi);
4809/* ---------------------------------------------------------------------- */
4810/* SCALE BACKWARD RECURRENCE, BRY(3) IS DEFINED BUT NEVER USED */
4811/* ---------------------------------------------------------------------- */
4812 bry[0] = d1mach(&c__1) * 1e3 / *tol;
4813 bry[1] = 1. / bry[0];
4814 bry[2] = bry[1];
4815 iflag = 2;
4816 ascle = bry[1];
4817 csclr = 1.;
4818 if (str > bry[0]) {
4819 goto L21;
4820 }
4821 iflag = 1;
4822 ascle = bry[0];
4823 csclr = 1. / *tol;
4824 goto L25;
4825 L21:
4826 if (str < bry[1]) {
4827 goto L25;
4828 }
4829 iflag = 3;
4830 ascle = bry[2];
4831 csclr = *tol;
4832 L25:
4833 cscrr = 1. / csclr;
4834 s1r = cyr[1] * csclr;
4835 s1i = cyi[1] * csclr;
4836 s2r = cyr[0] * csclr;
4837 s2i = cyi[0] * csclr;
4838 raz = 1. / azabs(zr, zi);
4839 str = *zr * raz;
4840 sti = -(*zi) * raz;
4841 rzr = (str + str) * raz;
4842 rzi = (sti + sti) * raz;
4843 i__1 = *nui;
4844 for (i__ = 1; i__ <= i__1; ++i__) {
4845 str = s2r;
4846 sti = s2i;
4847 s2r = (dfnu + fnui) * (rzr * str - rzi * sti) + s1r;
4848 s2i = (dfnu + fnui) * (rzr * sti + rzi * str) + s1i;
4849 s1r = str;
4850 s1i = sti;
4851 fnui += -1.;
4852 if (iflag >= 3) {
4853 goto L30;
4854 }
4855 str = s2r * cscrr;
4856 sti = s2i * cscrr;
4857 c1r = abs(str);
4858 c1i = abs(sti);
4859 c1m = max(c1r, c1i);
4860 if (c1m <= ascle) {
4861 goto L30;
4862 }
4863 ++iflag;
4864 ascle = bry[iflag - 1];
4865 s1r *= cscrr;
4866 s1i *= cscrr;
4867 s2r = str;
4868 s2i = sti;
4869 csclr *= *tol;
4870 cscrr = 1. / csclr;
4871 s1r *= csclr;
4872 s1i *= csclr;
4873 s2r *= csclr;
4874 s2i *= csclr;
4875 L30:
4876 ;
4877 }
4878 yr[*n] = s2r * cscrr;
4879 yi[*n] = s2i * cscrr;
4880 if (*n == 1) {
4881 return 0;
4882 }
4883 nl = *n - 1;
4884 fnui = (double) ((float) nl);
4885 k = nl;
4886 i__1 = nl;
4887 for (i__ = 1; i__ <= i__1; ++i__) {
4888 str = s2r;
4889 sti = s2i;
4890 s2r = (*fnu + fnui) * (rzr * str - rzi * sti) + s1r;
4891 s2i = (*fnu + fnui) * (rzr * sti + rzi * str) + s1i;
4892 s1r = str;
4893 s1i = sti;
4894 str = s2r * cscrr;
4895 sti = s2i * cscrr;
4896 yr[k] = str;
4897 yi[k] = sti;
4898 fnui += -1.;
4899 --k;
4900 if (iflag >= 3) {
4901 goto L40;
4902 }
4903 c1r = abs(str);
4904 c1i = abs(sti);
4905 c1m = max(c1r, c1i);
4906 if (c1m <= ascle) {
4907 goto L40;
4908 }
4909 ++iflag;
4910 ascle = bry[iflag - 1];
4911 s1r *= cscrr;
4912 s1i *= cscrr;
4913 s2r = str;
4914 s2i = sti;
4915 csclr *= *tol;
4916 cscrr = 1. / csclr;
4917 s1r *= csclr;
4918 s1i *= csclr;
4919 s2r *= csclr;
4920 s2i *= csclr;
4921 L40:
4922 ;
4923 }
4924 return 0;
4925 L50:
4926 *nz = -1;
4927 if (nw == -2) {
4928 *nz = -2;
4929 }
4930 return 0;
4931 L60:
4932 if (iform == 2) {
4933 goto L70;
4934 }
4935/* ----------------------------------------------------------------------- */
4936/* ASYMPTOTIC EXPANSION FOR I(FNU,Z) FOR LARGE FNU APPLIED IN */
4937/* -PI/3.LE.ARG(Z).LE.PI/3 */
4938/* ----------------------------------------------------------------------- */
4939 zuni1(zr, zi, fnu, kode, n, &yr[1], &yi[1], &nw, nlast, fnul, tol,
4940 elim, alim);
4941 goto L80;
4942 L70:
4943/* ----------------------------------------------------------------------- */
4944/* ASYMPTOTIC EXPANSION FOR J(FNU,Z*EXP(M*HPI)) FOR LARGE FNU */
4945/* APPLIED IN PI/3.LT.ABS(ARG(Z)).LE.PI/2 WHERE M=+I OR -I */
4946/* AND HPI=PI/2 */
4947/* ----------------------------------------------------------------------- */
4948 zuni2(zr, zi, fnu, kode, n, &yr[1], &yi[1], &nw, nlast, fnul, tol,
4949 elim, alim);
4950 L80:
4951 if (nw < 0) {
4952 goto L50;
4953 }
4954 *nz = nw;
4955 return 0;
4956 L90:
4957 *nlast = *n;
4958 return 0;
4959} /* zbuni_ */
4960
4961/* Subroutine */ int zbunk(double *zr, double *zi, double *fnu,
4962 long *kode, long *mr, long *n, double *yr,
4963 double *yi, long *nz, double *tol, double *elim,
4964 double *alim)
4965{
4966 double ax, ay;
4967 extern /* Subroutine */ int zunk1(double *, double *, double
4968 *, long *, long *, long *, double *,
4969 double *, long *, double *, double *,
4970 double *), zunk2(double *, double *,
4971 double *, long *,
4972 long *, long *,
4973 double *, double *,
4974 long *, double *,
4975 double *, double *);
4976
4977/* ***BEGIN PROLOGUE ZBUNK */
4978/* ***REFER TO ZBESK,ZBESH */
4979
4980/* ZBUNK COMPUTES THE K BESSEL FUNCTION FOR FNU.GT.FNUL. */
4981/* ACCORDING TO THE UNIFORM ASYMPTOTIC EXPANSION FOR K(FNU,Z) */
4982/* IN ZUNK1 AND THE EXPANSION FOR H(2,FNU,Z) IN ZUNK2 */
4983
4984/* ***ROUTINES CALLED ZUNK1,ZUNK2 */
4985/* ***END PROLOGUE ZBUNK */
4986/* COMPLEX Y,Z */
4987 /* Parameter adjustments */
4988 --yi;
4989 --yr;
4990
4991 /* Function Body */
4992 *nz = 0;
4993 ax = abs(*zr) * 1.7321;
4994 ay = abs(*zi);
4995 if (ay > ax) {
4996 goto L10;
4997 }
4998/* ----------------------------------------------------------------------- */
4999/* ASYMPTOTIC EXPANSION FOR K(FNU,Z) FOR LARGE FNU APPLIED IN */
5000/* -PI/3.LE.ARG(Z).LE.PI/3 */
5001/* ----------------------------------------------------------------------- */
5002 zunk1(zr, zi, fnu, kode, mr, n, &yr[1], &yi[1], nz, tol, elim, alim);
5003 goto L20;
5004 L10:
5005/* ----------------------------------------------------------------------- */
5006/* ASYMPTOTIC EXPANSION FOR H(2,FNU,Z*EXP(M*HPI)) FOR LARGE FNU */
5007/* APPLIED IN PI/3.LT.ABS(ARG(Z)).LE.PI/2 WHERE M=+I OR -I */
5008/* AND HPI=PI/2 */
5009/* ----------------------------------------------------------------------- */
5010 zunk2(zr, zi, fnu, kode, mr, n, &yr[1], &yi[1], nz, tol, elim, alim);
5011 L20:
5012 return 0;
5013} /* zbunk_ */
5014
5015/* Subroutine */ int zdiv(double *ar, double *ai, double *br,
5016 double *bi, double *cr, double *ci)
5017{
5018 double ca, cb, cc, cd, bm;
5019 extern double azabs(double *, double *);
5020
5021/* ***BEGIN PROLOGUE ZDIV */
5022/* ***REFER TO ZBESH,ZBESI,ZBESJ,ZBESK,ZBESY,ZAIRY,ZBIRY */
5023
5024/* DOUBLE PRECISION COMPLEX DIVIDE C=A/B. */
5025
5026/* ***ROUTINES CALLED AZABS */
5027/* ***END PROLOGUE ZDIV */
5028 bm = 1. / azabs(br, bi);
5029 cc = *br * bm;
5030 cd = *bi * bm;
5031 ca = (*ar * cc + *ai * cd) * bm;
5032 cb = (*ai * cc - *ar * cd) * bm;
5033 *cr = ca;
5034 *ci = cb;
5035 return 0;
5036} /* zdiv_ */
5037
5038/* Subroutine */ int azexp(double *ar, double *ai, double *br,
5039 double *bi)
5040{
5041 /* Builtin functions */
5042 double exp(double), cos(double), sin(double);
5043
5044 /* Local variables */
5045 double ca, cb, zm;
5046
5047/* ***BEGIN PROLOGUE AZEXP */
5048/* ***REFER TO ZBESH,ZBESI,ZBESJ,ZBESK,ZBESY,ZAIRY,ZBIRY */
5049
5050/* DOUBLE PRECISION COMPLEX EXPONENTIAL FUNCTION B=EXP(A) */
5051
5052/* ***ROUTINES CALLED (NONE) */
5053/* ***END PROLOGUE AZEXP */
5054 zm = exp(*ar);
5055 ca = zm * cos(*ai);
5056 cb = zm * sin(*ai);
5057 *br = ca;
5058 *bi = cb;
5059 return 0;
5060} /* azexp_ */
5061
5062/* Subroutine */ int zkscl(double *zrr, double *zri, double *fnu,
5063 long *n, double *yr, double *yi, long *nz,
5064 double *rzr, double *rzi, double *ascle,
5065 double *tol, double *elim)
5066{
5067 /* Initialized data */
5068
5069 double zeror = 0.;
5070 double zeroi = 0.;
5071
5072 /* System generated locals */
5073 long i__1;
5074
5075 /* Builtin functions */
5076 double log(double), exp(double), cos(double), sin(double);
5077
5078 /* Local variables */
5079 long i__, ic;
5080 double as, fn;
5081 long kk, nn, nw;
5082 double s1i, s2i, s1r, s2r, acs, cki, elm, csi, ckr, cyi[2],
5083 zdi, csr, cyr[2], zdr, str, alas;
5084 long idum;
5085 double helim;
5086 extern double azabs(double *, double *);
5087 double celmr;
5088 extern /* Subroutine */ int azlog(double *, double *, double
5089 *, double *, long *), zuchk(double *,
5090 double *,
5091 long *,
5092 double *,
5093 double
5094 *);
5095
5096/* ***BEGIN PROLOGUE ZKSCL */
5097/* ***REFER TO ZBESK */
5098
5099/* SET K FUNCTIONS TO ZERO ON UNDERFLOW, CONTINUE RECURRENCE */
5100/* ON SCALED FUNCTIONS UNTIL TWO MEMBERS COME ON SCALE, THEN */
5101/* RETURN WITH MIN(NZ+2,N) VALUES SCALED BY 1/TOL. */
5102
5103/* ***ROUTINES CALLED ZUCHK,AZABS,AZLOG */
5104/* ***END PROLOGUE ZKSCL */
5105/* COMPLEX CK,CS,CY,CZERO,RZ,S1,S2,Y,ZR,ZD,CELM */
5106 /* Parameter adjustments */
5107 --yi;
5108 --yr;
5109
5110 /* Function Body */
5111
5112 *nz = 0;
5113 ic = 0;
5114 nn = min(2, *n);
5115 i__1 = nn;
5116 for (i__ = 1; i__ <= i__1; ++i__) {
5117 s1r = yr[i__];
5118 s1i = yi[i__];
5119 cyr[i__ - 1] = s1r;
5120 cyi[i__ - 1] = s1i;
5121 as = azabs(&s1r, &s1i);
5122 acs = -(*zrr) + log(as);
5123 ++(*nz);
5124 yr[i__] = zeror;
5125 yi[i__] = zeroi;
5126 if (acs < -(*elim)) {
5127 goto L10;
5128 }
5129 azlog(&s1r, &s1i, &csr, &csi, &idum);
5130 csr -= *zrr;
5131 csi -= *zri;
5132 str = exp(csr) / *tol;
5133 csr = str * cos(csi);
5134 csi = str * sin(csi);
5135 zuchk(&csr, &csi, &nw, ascle, tol);
5136 if (nw != 0) {
5137 goto L10;
5138 }
5139 yr[i__] = csr;
5140 yi[i__] = csi;
5141 ic = i__;
5142 --(*nz);
5143 L10:
5144 ;
5145 }
5146 if (*n == 1) {
5147 return 0;
5148 }
5149 if (ic > 1) {
5150 goto L20;
5151 }
5152 yr[1] = zeror;
5153 yi[1] = zeroi;
5154 *nz = 2;
5155 L20:
5156 if (*n == 2) {
5157 return 0;
5158 }
5159 if (*nz == 0) {
5160 return 0;
5161 }
5162 fn = *fnu + 1.;
5163 ckr = fn * *rzr;
5164 cki = fn * *rzi;
5165 s1r = cyr[0];
5166 s1i = cyi[0];
5167 s2r = cyr[1];
5168 s2i = cyi[1];
5169 helim = *elim * .5;
5170 elm = exp(-(*elim));
5171 celmr = elm;
5172 zdr = *zrr;
5173 zdi = *zri;
5174
5175/* FIND TWO CONSECUTIVE Y VALUES ON SCALE. SCALE RECURRENCE IF */
5176/* S2 GETS LARGER THAN EXP(ELIM/2) */
5177
5178 i__1 = *n;
5179 for (i__ = 3; i__ <= i__1; ++i__) {
5180 kk = i__;
5181 csr = s2r;
5182 csi = s2i;
5183 s2r = ckr * csr - cki * csi + s1r;
5184 s2i = cki * csr + ckr * csi + s1i;
5185 s1r = csr;
5186 s1i = csi;
5187 ckr += *rzr;
5188 cki += *rzi;
5189 as = azabs(&s2r, &s2i);
5190 alas = log(as);
5191 acs = -zdr + alas;
5192 ++(*nz);
5193 yr[i__] = zeror;
5194 yi[i__] = zeroi;
5195 if (acs < -(*elim)) {
5196 goto L25;
5197 }
5198 azlog(&s2r, &s2i, &csr, &csi, &idum);
5199 csr -= zdr;
5200 csi -= zdi;
5201 str = exp(csr) / *tol;
5202 csr = str * cos(csi);
5203 csi = str * sin(csi);
5204 zuchk(&csr, &csi, &nw, ascle, tol);
5205 if (nw != 0) {
5206 goto L25;
5207 }
5208 yr[i__] = csr;
5209 yi[i__] = csi;
5210 --(*nz);
5211 if (ic == kk - 1) {
5212 goto L40;
5213 }
5214 ic = kk;
5215 goto L30;
5216 L25:
5217 if (alas < helim) {
5218 goto L30;
5219 }
5220 zdr -= *elim;
5221 s1r *= celmr;
5222 s1i *= celmr;
5223 s2r *= celmr;
5224 s2i *= celmr;
5225 L30:
5226 ;
5227 }
5228 *nz = *n;
5229 if (ic == *n) {
5230 *nz = *n - 1;
5231 }
5232 goto L45;
5233 L40:
5234 *nz = kk - 2;
5235 L45:
5236 i__1 = *nz;
5237 for (i__ = 1; i__ <= i__1; ++i__) {
5238 yr[i__] = zeror;
5239 yi[i__] = zeroi;
5240/* L50: */
5241 }
5242 return 0;
5243} /* zkscl_ */
5244
5245/* Subroutine */ int azlog(double *ar, double *ai, double *br,
5246 double *bi, long *ierr)
5247{
5248 /* Initialized data */
5249
5250 double dpi = 3.141592653589793238462643383;
5251 double dhpi = 1.570796326794896619231321696;
5252
5253 /* Builtin functions */
5254 double atan(double), log(double);
5255
5256 /* Local variables */
5257 double zm;
5258 extern double azabs(double *, double *);
5259 double dtheta;
5260
5261/* ***BEGIN PROLOGUE AZLOG */
5262/* ***REFER TO ZBESH,ZBESI,ZBESJ,ZBESK,ZBESY,ZAIRY,ZBIRY */
5263
5264/* DOUBLE PRECISION COMPLEX LOGARITHM B=CLOG(A) */
5265/* IERR=0,NORMAL RETURN IERR=1, Z=CMPLX(0.0,0.0) */
5266/* ***ROUTINES CALLED AZABS */
5267/* ***END PROLOGUE AZLOG */
5268
5269 *ierr = 0;
5270 if (*ar == 0.) {
5271 goto L10;
5272 }
5273 if (*ai == 0.) {
5274 goto L20;
5275 }
5276 dtheta = atan(*ai / *ar);
5277 if (dtheta <= 0.) {
5278 goto L40;
5279 }
5280 if (*ar < 0.) {
5281 dtheta -= dpi;
5282 }
5283 goto L50;
5284 L10:
5285 if (*ai == 0.) {
5286 goto L60;
5287 }
5288 *bi = dhpi;
5289 *br = log((abs(*ai)));
5290 if (*ai < 0.) {
5291 *bi = -(*bi);
5292 }
5293 return 0;
5294 L20:
5295 if (*ar > 0.) {
5296 goto L30;
5297 }
5298 *br = log((abs(*ar)));
5299 *bi = dpi;
5300 return 0;
5301 L30:
5302 *br = log(*ar);
5303 *bi = 0.;
5304 return 0;
5305 L40:
5306 if (*ar < 0.) {
5307 dtheta += dpi;
5308 }
5309 L50:
5310 zm = azabs(ar, ai);
5311 *br = log(zm);
5312 *bi = dtheta;
5313 return 0;
5314 L60:
5315 *ierr = 1;
5316 return 0;
5317} /* azlog_ */
5318
5319/* Subroutine */ int zmlri(double *zr, double *zi, double *fnu,
5320 long *kode, long *n, double *yr, double *yi,
5321 long *nz, double *tol)
5322{
5323 /* Initialized data */
5324
5325 double zeror = 0.;
5326 double zeroi = 0.;
5327 double coner = 1.;
5328 double conei = 0.;
5329
5330 /* System generated locals */
5331 long i__1, i__2;
5332 double d__1, d__2, d__3;
5333
5334 /* Builtin functions */
5335 double sqrt(double), exp(double);
5336
5337 /* Local variables */
5338 long i__, k, m;
5339 double ak, bk, ap, at;
5340 long kk, km;
5341 double az, p1i, p2i, p1r, p2r, ack, cki, fnf, fkk, ckr;
5342 long iaz;
5343 double rho;
5344 long inu;
5345 double pti, raz, sti, rzi, ptr, str, tst, rzr, rho2, flam,
5346 fkap, scle, tfnf;
5347 long idum, ifnu;
5348 double sumi, sumr;
5349 extern /* Subroutine */ int zmlt(double *, double *, double *
5350 , double *, double *, double *);
5351 extern double azabs(double *, double *);
5352 long itime;
5353 extern /* Subroutine */ int azlog(double *, double *, double
5354 *, double *, long *), azexp(double *,
5355 double *,
5356 double *,
5357 double
5358 *);
5359 extern double d1mach(long *), dgamln(double *, long *);
5360 double cnormi, cnormr;
5361
5362/* ***BEGIN PROLOGUE ZMLRI */
5363/* ***REFER TO ZBESI,ZBESK */
5364
5365/* ZMLRI COMPUTES THE I BESSEL FUNCTION FOR RE(Z).GE.0.0 BY THE */
5366/* MILLER ALGORITHM NORMALIZED BY A NEUMANN SERIES. */
5367
5368/* ***ROUTINES CALLED DGAMLN,D1MACH,AZABS,AZEXP,AZLOG,ZMLT */
5369/* ***END PROLOGUE ZMLRI */
5370/* COMPLEX CK,CNORM,CONE,CTWO,CZERO,PT,P1,P2,RZ,SUM,Y,Z */
5371 /* Parameter adjustments */
5372 --yi;
5373 --yr;
5374
5375 /* Function Body */
5376 scle = d1mach(&c__1) / *tol;
5377 *nz = 0;
5378 az = azabs(zr, zi);
5379 iaz = (long) ((float) az);
5380 ifnu = (long) ((float) (*fnu));
5381 inu = ifnu + *n - 1;
5382 at = (double) ((float) iaz) + 1.;
5383 raz = 1. / az;
5384 str = *zr * raz;
5385 sti = -(*zi) * raz;
5386 ckr = str * at * raz;
5387 cki = sti * at * raz;
5388 rzr = (str + str) * raz;
5389 rzi = (sti + sti) * raz;
5390 p1r = zeror;
5391 p1i = zeroi;
5392 p2r = coner;
5393 p2i = conei;
5394 ack = (at + 1.) * raz;
5395 rho = ack + sqrt(ack * ack - 1.);
5396 rho2 = rho * rho;
5397 tst = (rho2 + rho2) / ((rho2 - 1.) * (rho - 1.));
5398 tst /= *tol;
5399/* ----------------------------------------------------------------------- */
5400/* COMPUTE RELATIVE TRUNCATION ERROR INDEX FOR SERIES */
5401/* ----------------------------------------------------------------------- */
5402 ak = at;
5403 for (i__ = 1; i__ <= 80; ++i__) {
5404 ptr = p2r;
5405 pti = p2i;
5406 p2r = p1r - (ckr * ptr - cki * pti);
5407 p2i = p1i - (cki * ptr + ckr * pti);
5408 p1r = ptr;
5409 p1i = pti;
5410 ckr += rzr;
5411 cki += rzi;
5412 ap = azabs(&p2r, &p2i);
5413 if (ap > tst * ak * ak) {
5414 goto L20;
5415 }
5416 ak += 1.;
5417/* L10: */
5418 }
5419 goto L110;
5420 L20:
5421 ++i__;
5422 k = 0;
5423 if (inu < iaz) {
5424 goto L40;
5425 }
5426/* ----------------------------------------------------------------------- */
5427/* COMPUTE RELATIVE TRUNCATION ERROR FOR RATIOS */
5428/* ----------------------------------------------------------------------- */
5429 p1r = zeror;
5430 p1i = zeroi;
5431 p2r = coner;
5432 p2i = conei;
5433 at = (double) ((float) inu) + 1.;
5434 str = *zr * raz;
5435 sti = -(*zi) * raz;
5436 ckr = str * at * raz;
5437 cki = sti * at * raz;
5438 ack = at * raz;
5439 tst = sqrt(ack / *tol);
5440 itime = 1;
5441 for (k = 1; k <= 80; ++k) {
5442 ptr = p2r;
5443 pti = p2i;
5444 p2r = p1r - (ckr * ptr - cki * pti);
5445 p2i = p1i - (ckr * pti + cki * ptr);
5446 p1r = ptr;
5447 p1i = pti;
5448 ckr += rzr;
5449 cki += rzi;
5450 ap = azabs(&p2r, &p2i);
5451 if (ap < tst) {
5452 goto L30;
5453 }
5454 if (itime == 2) {
5455 goto L40;
5456 }
5457 ack = azabs(&ckr, &cki);
5458 flam = ack + sqrt(ack * ack - 1.);
5459 fkap = ap / azabs(&p1r, &p1i);
5460 rho = min(flam, fkap);
5461 tst *= sqrt(rho / (rho * rho - 1.));
5462 itime = 2;
5463 L30:
5464 ;
5465 }
5466 goto L110;
5467 L40:
5468/* ----------------------------------------------------------------------- */
5469/* BACKWARD RECURRENCE AND SUM NORMALIZING RELATION */
5470/* ----------------------------------------------------------------------- */
5471 ++k;
5472/* Computing MAX */
5473 i__1 = i__ + iaz, i__2 = k + inu;
5474 kk = max(i__1, i__2);
5475 fkk = (double) ((float) kk);
5476 p1r = zeror;
5477 p1i = zeroi;
5478/* ----------------------------------------------------------------------- */
5479/* SCALE P2 AND SUM BY SCLE */
5480/* ----------------------------------------------------------------------- */
5481 p2r = scle;
5482 p2i = zeroi;
5483 fnf = *fnu - (double) ((float) ifnu);
5484 tfnf = fnf + fnf;
5485 d__1 = fkk + tfnf + 1.;
5486 d__2 = fkk + 1.;
5487 d__3 = tfnf + 1.;
5488 bk = dgamln(&d__1, &idum) - dgamln(&d__2, &idum) - dgamln(&d__3,
5489 &idum);
5490 bk = exp(bk);
5491 sumr = zeror;
5492 sumi = zeroi;
5493 km = kk - inu;
5494 i__1 = km;
5495 for (i__ = 1; i__ <= i__1; ++i__) {
5496 ptr = p2r;
5497 pti = p2i;
5498 p2r = p1r + (fkk + fnf) * (rzr * ptr - rzi * pti);
5499 p2i = p1i + (fkk + fnf) * (rzi * ptr + rzr * pti);
5500 p1r = ptr;
5501 p1i = pti;
5502 ak = 1. - tfnf / (fkk + tfnf);
5503 ack = bk * ak;
5504 sumr += (ack + bk) * p1r;
5505 sumi += (ack + bk) * p1i;
5506 bk = ack;
5507 fkk += -1.;
5508/* L50: */
5509 }
5510 yr[*n] = p2r;
5511 yi[*n] = p2i;
5512 if (*n == 1) {
5513 goto L70;
5514 }
5515 i__1 = *n;
5516 for (i__ = 2; i__ <= i__1; ++i__) {
5517 ptr = p2r;
5518 pti = p2i;
5519 p2r = p1r + (fkk + fnf) * (rzr * ptr - rzi * pti);
5520 p2i = p1i + (fkk + fnf) * (rzi * ptr + rzr * pti);
5521 p1r = ptr;
5522 p1i = pti;
5523 ak = 1. - tfnf / (fkk + tfnf);
5524 ack = bk * ak;
5525 sumr += (ack + bk) * p1r;
5526 sumi += (ack + bk) * p1i;
5527 bk = ack;
5528 fkk += -1.;
5529 m = *n - i__ + 1;
5530 yr[m] = p2r;
5531 yi[m] = p2i;
5532/* L60: */
5533 }
5534 L70:
5535 if (ifnu <= 0) {
5536 goto L90;
5537 }
5538 i__1 = ifnu;
5539 for (i__ = 1; i__ <= i__1; ++i__) {
5540 ptr = p2r;
5541 pti = p2i;
5542 p2r = p1r + (fkk + fnf) * (rzr * ptr - rzi * pti);
5543 p2i = p1i + (fkk + fnf) * (rzr * pti + rzi * ptr);
5544 p1r = ptr;
5545 p1i = pti;
5546 ak = 1. - tfnf / (fkk + tfnf);
5547 ack = bk * ak;
5548 sumr += (ack + bk) * p1r;
5549 sumi += (ack + bk) * p1i;
5550 bk = ack;
5551 fkk += -1.;
5552/* L80: */
5553 }
5554 L90:
5555 ptr = *zr;
5556 pti = *zi;
5557 if (*kode == 2) {
5558 ptr = zeror;
5559 }
5560 azlog(&rzr, &rzi, &str, &sti, &idum);
5561 p1r = -fnf * str + ptr;
5562 p1i = -fnf * sti + pti;
5563 d__1 = fnf + 1.;
5564 ap = dgamln(&d__1, &idum);
5565 ptr = p1r - ap;
5566 pti = p1i;
5567/* ----------------------------------------------------------------------- */
5568/* THE DIVISION CEXP(PT)/(SUM+P2) IS ALTERED TO AVOID OVERFLOW */
5569/* IN THE DENOMINATOR BY SQUARING LARGE QUANTITIES */
5570/* ----------------------------------------------------------------------- */
5571 p2r += sumr;
5572 p2i += sumi;
5573 ap = azabs(&p2r, &p2i);
5574 p1r = 1. / ap;
5575 azexp(&ptr, &pti, &str, &sti);
5576 ckr = str * p1r;
5577 cki = sti * p1r;
5578 ptr = p2r * p1r;
5579 pti = -p2i * p1r;
5580 zmlt(&ckr, &cki, &ptr, &pti, &cnormr, &cnormi);
5581 i__1 = *n;
5582 for (i__ = 1; i__ <= i__1; ++i__) {
5583 str = yr[i__] * cnormr - yi[i__] * cnormi;
5584 yi[i__] = yr[i__] * cnormi + yi[i__] * cnormr;
5585 yr[i__] = str;
5586/* L100: */
5587 }
5588 return 0;
5589 L110:
5590 *nz = -2;
5591 return 0;
5592} /* zmlri_ */
5593
5594/* Subroutine */ int zmlt(double *ar, double *ai, double *br,
5595 double *bi, double *cr, double *ci)
5596{
5597 double ca, cb;
5598
5599/* ***BEGIN PROLOGUE ZMLT */
5600/* ***REFER TO ZBESH,ZBESI,ZBESJ,ZBESK,ZBESY,ZAIRY,ZBIRY */
5601
5602/* DOUBLE PRECISION COMPLEX MULTIPLY, C=A*B. */
5603
5604/* ***ROUTINES CALLED (NONE) */
5605/* ***END PROLOGUE ZMLT */
5606 ca = *ar * *br - *ai * *bi;
5607 cb = *ar * *bi + *ai * *br;
5608 *cr = ca;
5609 *ci = cb;
5610 return 0;
5611} /* zmlt_ */
5612
5613/* Subroutine */ int zrati(double *zr, double *zi, double *fnu,
5614 long *n, double *cyr, double *cyi, double *tol)
5615{
5616 /* Initialized data */
5617
5618 double czeror = 0.;
5619 double czeroi = 0.;
5620 double coner = 1.;
5621 double conei = 0.;
5622 double rt2 = 1.41421356237309505;
5623
5624 /* System generated locals */
5625 long i__1;
5626 double d__1;
5627
5628 /* Builtin functions */
5629 double sqrt(double);
5630
5631 /* Local variables */
5632 long i__, k;
5633 double ak;
5634 long id, kk;
5635 double az, ap1, ap2, p1i, p2i, t1i, p1r, p2r, t1r, arg, rak,
5636 rho;
5637 long inu;
5638 double pti, tti, rzi, ptr, ttr, rzr, rap1, flam, dfnu, fdnu;
5639 long magz, idnu;
5640 double fnup;
5641 extern /* Subroutine */ int zdiv(double *, double *, double *
5642 , double *, double *, double *);
5643 double test, test1, amagz;
5644 extern double azabs(double *, double *);
5645 long itime;
5646 double cdfnui, cdfnur;
5647
5648/* ***BEGIN PROLOGUE ZRATI */
5649/* ***REFER TO ZBESI,ZBESK,ZBESH */
5650
5651/* ZRATI COMPUTES RATIOS OF I BESSEL FUNCTIONS BY BACKWARD */
5652/* RECURRENCE. THE STARTING INDEX IS DETERMINED BY FORWARD */
5653/* RECURRENCE AS DESCRIBED IN J. RES. OF NAT. BUR. OF STANDARDS-B, */
5654/* MATHEMATICAL SCIENCES, VOL 77B, P111-114, SEPTEMBER, 1973, */
5655/* BESSEL FUNCTIONS I AND J OF COMPLEX ARGUMENT AND INTEGER ORDER, */
5656/* BY D. J. SOOKNE. */
5657
5658/* ***ROUTINES CALLED AZABS,ZDIV */
5659/* ***END PROLOGUE ZRATI */
5660/* COMPLEX Z,CY(1),CONE,CZERO,P1,P2,T1,RZ,PT,CDFNU */
5661 /* Parameter adjustments */
5662 --cyi;
5663 --cyr;
5664
5665 /* Function Body */
5666 az = azabs(zr, zi);
5667 inu = (long) ((float) (*fnu));
5668 idnu = inu + *n - 1;
5669 magz = (long) ((float) az);
5670 amagz = (double) ((float) (magz + 1));
5671 fdnu = (double) ((float) idnu);
5672 fnup = max(amagz, fdnu);
5673 id = idnu - magz - 1;
5674 itime = 1;
5675 k = 1;
5676 ptr = 1. / az;
5677 rzr = ptr * (*zr + *zr) * ptr;
5678 rzi = -ptr * (*zi + *zi) * ptr;
5679 t1r = rzr * fnup;
5680 t1i = rzi * fnup;
5681 p2r = -t1r;
5682 p2i = -t1i;
5683 p1r = coner;
5684 p1i = conei;
5685 t1r += rzr;
5686 t1i += rzi;
5687 if (id > 0) {
5688 id = 0;
5689 }
5690 ap2 = azabs(&p2r, &p2i);
5691 ap1 = azabs(&p1r, &p1i);
5692/* ----------------------------------------------------------------------- */
5693/* THE OVERFLOW TEST ON K(FNU+I-1,Z) BEFORE THE CALL TO CBKNU */
5694/* GUARANTEES THAT P2 IS ON SCALE. SCALE TEST1 AND ALL SUBSEQUENT */
5695/* P2 VALUES BY AP1 TO ENSURE THAT AN OVERFLOW DOES NOT OCCUR */
5696/* PREMATURELY. */
5697/* ----------------------------------------------------------------------- */
5698 arg = (ap2 + ap2) / (ap1 * *tol);
5699 test1 = sqrt(arg);
5700 test = test1;
5701 rap1 = 1. / ap1;
5702 p1r *= rap1;
5703 p1i *= rap1;
5704 p2r *= rap1;
5705 p2i *= rap1;
5706 ap2 *= rap1;
5707 L10:
5708 ++k;
5709 ap1 = ap2;
5710 ptr = p2r;
5711 pti = p2i;
5712 p2r = p1r - (t1r * ptr - t1i * pti);
5713 p2i = p1i - (t1r * pti + t1i * ptr);
5714 p1r = ptr;
5715 p1i = pti;
5716 t1r += rzr;
5717 t1i += rzi;
5718 ap2 = azabs(&p2r, &p2i);
5719 if (ap1 <= test) {
5720 goto L10;
5721 }
5722 if (itime == 2) {
5723 goto L20;
5724 }
5725 ak = azabs(&t1r, &t1i) * .5;
5726 flam = ak + sqrt(ak * ak - 1.);
5727/* Computing MIN */
5728 d__1 = ap2 / ap1;
5729 rho = min(d__1, flam);
5730 test = test1 * sqrt(rho / (rho * rho - 1.));
5731 itime = 2;
5732 goto L10;
5733 L20:
5734 kk = k + 1 - id;
5735 ak = (double) ((float) kk);
5736 t1r = ak;
5737 t1i = czeroi;
5738 dfnu = *fnu + (double) ((float) (*n - 1));
5739 p1r = 1. / ap2;
5740 p1i = czeroi;
5741 p2r = czeror;
5742 p2i = czeroi;
5743 i__1 = kk;
5744 for (i__ = 1; i__ <= i__1; ++i__) {
5745 ptr = p1r;
5746 pti = p1i;
5747 rap1 = dfnu + t1r;
5748 ttr = rzr * rap1;
5749 tti = rzi * rap1;
5750 p1r = ptr * ttr - pti * tti + p2r;
5751 p1i = ptr * tti + pti * ttr + p2i;
5752 p2r = ptr;
5753 p2i = pti;
5754 t1r -= coner;
5755/* L30: */
5756 }
5757 if (p1r != czeror || p1i != czeroi) {
5758 goto L40;
5759 }
5760 p1r = *tol;
5761 p1i = *tol;
5762 L40:
5763 zdiv(&p2r, &p2i, &p1r, &p1i, &cyr[*n], &cyi[*n]);
5764 if (*n == 1) {
5765 return 0;
5766 }
5767 k = *n - 1;
5768 ak = (double) ((float) k);
5769 t1r = ak;
5770 t1i = czeroi;
5771 cdfnur = *fnu * rzr;
5772 cdfnui = *fnu * rzi;
5773 i__1 = *n;
5774 for (i__ = 2; i__ <= i__1; ++i__) {
5775 ptr = cdfnur + (t1r * rzr - t1i * rzi) + cyr[k + 1];
5776 pti = cdfnui + (t1r * rzi + t1i * rzr) + cyi[k + 1];
5777 ak = azabs(&ptr, &pti);
5778 if (ak != czeror) {
5779 goto L50;
5780 }
5781 ptr = *tol;
5782 pti = *tol;
5783 ak = *tol * rt2;
5784 L50:
5785 rak = coner / ak;
5786 cyr[k] = rak * ptr * rak;
5787 cyi[k] = -rak * pti * rak;
5788 t1r -= coner;
5789 --k;
5790/* L60: */
5791 }
5792 return 0;
5793} /* zrati_ */
5794
5795/* Subroutine */ int zs1s2(double *zrr, double *zri, double *s1r,
5796 double *s1i, double *s2r, double *s2i, long *nz,
5797 double *ascle, double *alim, long *iuf)
5798{
5799 /* Initialized data */
5800
5801 double zeror = 0.;
5802 double zeroi = 0.;
5803
5804 /* Builtin functions */
5805 double log(double);
5806
5807 /* Local variables */
5808 double aa, c1i, as1, as2, c1r, aln, s1di, s1dr;
5809 long idum;
5810 extern double azabs(double *, double *);
5811 extern /* Subroutine */ int azlog(double *, double *, double
5812 *, double *, long *), azexp(double *,
5813 double *,
5814 double *,
5815 double
5816 *);
5817
5818/* ***BEGIN PROLOGUE ZS1S2 */
5819/* ***REFER TO ZBESK,ZAIRY */
5820
5821/* ZS1S2 TESTS FOR A POSSIBLE UNDERFLOW RESULTING FROM THE */
5822/* ADDITION OF THE I AND K FUNCTIONS IN THE ANALYTIC CON- */
5823/* TINUATION FORMULA WHERE S1=K FUNCTION AND S2=I FUNCTION. */
5824/* ON KODE=1 THE I AND K FUNCTIONS ARE DIFFERENT ORDERS OF */
5825/* MAGNITUDE, BUT FOR KODE=2 THEY CAN BE OF THE SAME ORDER */
5826/* OF MAGNITUDE AND THE MAXIMUM MUST BE AT LEAST ONE */
5827/* PRECISION ABOVE THE UNDERFLOW LIMIT. */
5828
5829/* ***ROUTINES CALLED AZABS,AZEXP,AZLOG */
5830/* ***END PROLOGUE ZS1S2 */
5831/* COMPLEX CZERO,C1,S1,S1D,S2,ZR */
5832 *nz = 0;
5833 as1 = azabs(s1r, s1i);
5834 as2 = azabs(s2r, s2i);
5835 if (*s1r == 0. && *s1i == 0.) {
5836 goto L10;
5837 }
5838 if (as1 == 0.) {
5839 goto L10;
5840 }
5841 aln = -(*zrr) - *zrr + log(as1);
5842 s1dr = *s1r;
5843 s1di = *s1i;
5844 *s1r = zeror;
5845 *s1i = zeroi;
5846 as1 = zeror;
5847 if (aln < -(*alim)) {
5848 goto L10;
5849 }
5850 azlog(&s1dr, &s1di, &c1r, &c1i, &idum);
5851 c1r = c1r - *zrr - *zrr;
5852 c1i = c1i - *zri - *zri;
5853 azexp(&c1r, &c1i, s1r, s1i);
5854 as1 = azabs(s1r, s1i);
5855 ++(*iuf);
5856 L10:
5857 aa = max(as1, as2);
5858 if (aa > *ascle) {
5859 return 0;
5860 }
5861 *s1r = zeror;
5862 *s1i = zeroi;
5863 *s2r = zeror;
5864 *s2i = zeroi;
5865 *nz = 1;
5866 *iuf = 0;
5867 return 0;
5868} /* zs1s2_ */
5869
5870/* Subroutine */ int zseri(double *zr, double *zi, double *fnu,
5871 long *kode, long *n, double *yr, double *yi,
5872 long *nz, double *tol, double *elim,
5873 double *alim)
5874{
5875 /* Initialized data */
5876
5877 double zeror = 0.;
5878 double zeroi = 0.;
5879 double coner = 1.;
5880 double conei = 0.;
5881
5882 /* System generated locals */
5883 long i__1;
5884
5885 /* Builtin functions */
5886 double sqrt(double), exp(double), cos(double), sin(double);
5887
5888 /* Local variables */
5889 long i__, k, l, m;
5890 double s, aa;
5891 long ib;
5892 double ak;
5893 long il;
5894 double az;
5895 long nn;
5896 double wi[2], rs, ss;
5897 long nw;
5898 double wr[2], s1i, s2i, s1r, s2r, cki, acz, arm, ckr, czi, hzi,
5899 raz, czr, sti, hzr, rzi, str, rzr, ak1i, ak1r, rtr1, dfnu;
5900 long idum;
5901 double atol, fnup;
5902 extern /* Subroutine */ int zdiv(double *, double *, double *
5903 , double *, double *, double *),
5904 zmlt(double *, double *, double *, double *, double *, double *);
5905 long iflag;
5906 double coefi, ascle, coefr;
5907 extern double azabs(double *, double *);
5908 double crscr;
5909 extern /* Subroutine */ int azlog(double *, double *, double
5910 *, double *, long *), zuchk(double *,
5911 double *,
5912 long *,
5913 double *,
5914 double
5915 *);
5916 extern double d1mach(long *), dgamln(double *, long *);
5917
5918/* ***BEGIN PROLOGUE ZSERI */
5919/* ***REFER TO ZBESI,ZBESK */
5920
5921/* ZSERI COMPUTES THE I BESSEL FUNCTION FOR REAL(Z).GE.0.0 BY */
5922/* MEANS OF THE POWER SERIES FOR LARGE CABS(Z) IN THE */
5923/* REGION CABS(Z).LE.2*SQRT(FNU+1). NZ=0 IS A NORMAL RETURN. */
5924/* NZ.GT.0 MEANS THAT THE LAST NZ COMPONENTS WERE SET TO ZERO */
5925/* DUE TO UNDERFLOW. NZ.LT.0 MEANS UNDERFLOW OCCURRED, BUT THE */
5926/* CONDITION CABS(Z).LE.2*SQRT(FNU+1) WAS VIOLATED AND THE */
5927/* COMPUTATION MUST BE COMPLETED IN ANOTHER ROUTINE WITH N=N-ABS(NZ). */
5928
5929/* ***ROUTINES CALLED DGAMLN,D1MACH,ZUCHK,AZABS,ZDIV,AZLOG,ZMLT */
5930/* ***END PROLOGUE ZSERI */
5931/* COMPLEX AK1,CK,COEF,CONE,CRSC,CSCL,CZ,CZERO,HZ,RZ,S1,S2,Y,Z */
5932 /* Parameter adjustments */
5933 --yi;
5934 --yr;
5935
5936 /* Function Body */
5937
5938 *nz = 0;
5939 az = azabs(zr, zi);
5940 if (az == 0.) {
5941 goto L160;
5942 }
5943 arm = d1mach(&c__1) * 1e3;
5944 rtr1 = sqrt(arm);
5945 crscr = 1.;
5946 iflag = 0;
5947 if (az < arm) {
5948 goto L150;
5949 }
5950 hzr = *zr * .5;
5951 hzi = *zi * .5;
5952 czr = zeror;
5953 czi = zeroi;
5954 if (az <= rtr1) {
5955 goto L10;
5956 }
5957 zmlt(&hzr, &hzi, &hzr, &hzi, &czr, &czi);
5958 L10:
5959 acz = azabs(&czr, &czi);
5960 nn = *n;
5961 azlog(&hzr, &hzi, &ckr, &cki, &idum);
5962 L20:
5963 dfnu = *fnu + (double) ((float) (nn - 1));
5964 fnup = dfnu + 1.;
5965/* ----------------------------------------------------------------------- */
5966/* UNDERFLOW TEST */
5967/* ----------------------------------------------------------------------- */
5968 ak1r = ckr * dfnu;
5969 ak1i = cki * dfnu;
5970 ak = dgamln(&fnup, &idum);
5971 ak1r -= ak;
5972 if (*kode == 2) {
5973 ak1r -= *zr;
5974 }
5975 if (ak1r > -(*elim)) {
5976 goto L40;
5977 }
5978 L30:
5979 ++(*nz);
5980 yr[nn] = zeror;
5981 yi[nn] = zeroi;
5982 if (acz > dfnu) {
5983 goto L190;
5984 }
5985 --nn;
5986 if (nn == 0) {
5987 return 0;
5988 }
5989 goto L20;
5990 L40:
5991 if (ak1r > -(*alim)) {
5992 goto L50;
5993 }
5994 iflag = 1;
5995 ss = 1. / *tol;
5996 crscr = *tol;
5997 ascle = arm * ss;
5998 L50:
5999 aa = exp(ak1r);
6000 if (iflag == 1) {
6001 aa *= ss;
6002 }
6003 coefr = aa * cos(ak1i);
6004 coefi = aa * sin(ak1i);
6005 atol = *tol * acz / fnup;
6006 il = min(2, nn);
6007 i__1 = il;
6008 for (i__ = 1; i__ <= i__1; ++i__) {
6009 dfnu = *fnu + (double) ((float) (nn - i__));
6010 fnup = dfnu + 1.;
6011 s1r = coner;
6012 s1i = conei;
6013 if (acz < *tol * fnup) {
6014 goto L70;
6015 }
6016 ak1r = coner;
6017 ak1i = conei;
6018 ak = fnup + 2.;
6019 s = fnup;
6020 aa = 2.;
6021 L60:
6022 rs = 1. / s;
6023 str = ak1r * czr - ak1i * czi;
6024 sti = ak1r * czi + ak1i * czr;
6025 ak1r = str * rs;
6026 ak1i = sti * rs;
6027 s1r += ak1r;
6028 s1i += ak1i;
6029 s += ak;
6030 ak += 2.;
6031 aa = aa * acz * rs;
6032 if (aa > atol) {
6033 goto L60;
6034 }
6035 L70:
6036 s2r = s1r * coefr - s1i * coefi;
6037 s2i = s1r * coefi + s1i * coefr;
6038 wr[i__ - 1] = s2r;
6039 wi[i__ - 1] = s2i;
6040 if (iflag == 0) {
6041 goto L80;
6042 }
6043 zuchk(&s2r, &s2i, &nw, &ascle, tol);
6044 if (nw != 0) {
6045 goto L30;
6046 }
6047 L80:
6048 m = nn - i__ + 1;
6049 yr[m] = s2r * crscr;
6050 yi[m] = s2i * crscr;
6051 if (i__ == il) {
6052 goto L90;
6053 }
6054 zdiv(&coefr, &coefi, &hzr, &hzi, &str, &sti);
6055 coefr = str * dfnu;
6056 coefi = sti * dfnu;
6057 L90:
6058 ;
6059 }
6060 if (nn <= 2) {
6061 return 0;
6062 }
6063 k = nn - 2;
6064 ak = (double) ((float) k);
6065 raz = 1. / az;
6066 str = *zr * raz;
6067 sti = -(*zi) * raz;
6068 rzr = (str + str) * raz;
6069 rzi = (sti + sti) * raz;
6070 if (iflag == 1) {
6071 goto L120;
6072 }
6073 ib = 3;
6074 L100:
6075 i__1 = nn;
6076 for (i__ = ib; i__ <= i__1; ++i__) {
6077 yr[k] =
6078 (ak + *fnu) * (rzr * yr[k + 1] - rzi * yi[k + 1]) + yr[k + 2];
6079 yi[k] =
6080 (ak + *fnu) * (rzr * yi[k + 1] + rzi * yr[k + 1]) + yi[k + 2];
6081 ak += -1.;
6082 --k;
6083/* L110: */
6084 }
6085 return 0;
6086/* ----------------------------------------------------------------------- */
6087/* RECUR BACKWARD WITH SCALED VALUES */
6088/* ----------------------------------------------------------------------- */
6089 L120:
6090/* ----------------------------------------------------------------------- */
6091/* EXP(-ALIM)=EXP(-ELIM)/TOL=APPROX. ONE PRECISION ABOVE THE */
6092/* UNDERFLOW LIMIT = ASCLE = D1MACH(1)*SS*1.0D+3 */
6093/* ----------------------------------------------------------------------- */
6094 s1r = wr[0];
6095 s1i = wi[0];
6096 s2r = wr[1];
6097 s2i = wi[1];
6098 i__1 = nn;
6099 for (l = 3; l <= i__1; ++l) {
6100 ckr = s2r;
6101 cki = s2i;
6102 s2r = s1r + (ak + *fnu) * (rzr * ckr - rzi * cki);
6103 s2i = s1i + (ak + *fnu) * (rzr * cki + rzi * ckr);
6104 s1r = ckr;
6105 s1i = cki;
6106 ckr = s2r * crscr;
6107 cki = s2i * crscr;
6108 yr[k] = ckr;
6109 yi[k] = cki;
6110 ak += -1.;
6111 --k;
6112 if (azabs(&ckr, &cki) > ascle) {
6113 goto L140;
6114 }
6115/* L130: */
6116 }
6117 return 0;
6118 L140:
6119 ib = l + 1;
6120 if (ib > nn) {
6121 return 0;
6122 }
6123 goto L100;
6124 L150:
6125 *nz = *n;
6126 if (*fnu == 0.) {
6127 --(*nz);
6128 }
6129 L160:
6130 yr[1] = zeror;
6131 yi[1] = zeroi;
6132 if (*fnu != 0.) {
6133 goto L170;
6134 }
6135 yr[1] = coner;
6136 yi[1] = conei;
6137 L170:
6138 if (*n == 1) {
6139 return 0;
6140 }
6141 i__1 = *n;
6142 for (i__ = 2; i__ <= i__1; ++i__) {
6143 yr[i__] = zeror;
6144 yi[i__] = zeroi;
6145/* L180: */
6146 }
6147 return 0;
6148/* ----------------------------------------------------------------------- */
6149/* RETURN WITH NZ.LT.0 IF CABS(Z*Z/4).GT.FNU+N-NZ-1 COMPLETE */
6150/* THE CALCULATION IN CBINU WITH N=N-IABS(NZ) */
6151/* ----------------------------------------------------------------------- */
6152 L190:
6153 *nz = -(*nz);
6154 return 0;
6155} /* zseri_ */
6156
6157/* Subroutine */ int zshch(double *zr, double *zi, double *cshr,
6158 double *cshi, double *cchr, double *cchi)
6159{
6160 /* Builtin functions */
6161 double sinh(double), cosh(double), sin(double), cos(double);
6162
6163 /* Local variables */
6164 double ch, cn, sh, sn;
6165
6166/* ***BEGIN PROLOGUE ZSHCH */
6167/* ***REFER TO ZBESK,ZBESH */
6168
6169/* ZSHCH COMPUTES THE COMPLEX HYPERBOLIC FUNCTIONS CSH=SINH(X+I*Y) */
6170/* AND CCH=COSH(X+I*Y), WHERE I**2=-1. */
6171
6172/* ***ROUTINES CALLED (NONE) */
6173/* ***END PROLOGUE ZSHCH */
6174
6175 sh = sinh(*zr);
6176 ch = cosh(*zr);
6177 sn = sin(*zi);
6178 cn = cos(*zi);
6179 *cshr = sh * cn;
6180 *cshi = ch * sn;
6181 *cchr = ch * cn;
6182 *cchi = sh * sn;
6183 return 0;
6184} /* zshch_ */
6185
6186/* Subroutine */ int azsqrt(double *ar, double *ai, double *br,
6187 double *bi)
6188{
6189 /* Initialized data */
6190
6191 double drt = .7071067811865475244008443621;
6192 double dpi = 3.141592653589793238462643383;
6193
6194 /* Builtin functions */
6195 double sqrt(double), atan(double), cos(double), sin(double);
6196
6197 /* Local variables */
6198 double zm;
6199 extern double azabs(double *, double *);
6200 double dtheta;
6201
6202/* ***BEGIN PROLOGUE AZSQRT */
6203/* ***REFER TO ZBESH,ZBESI,ZBESJ,ZBESK,ZBESY,ZAIRY,ZBIRY */
6204
6205/* DOUBLE PRECISION COMPLEX SQUARE ROOT, B=CSQRT(A) */
6206
6207/* ***ROUTINES CALLED AZABS */
6208/* ***END PROLOGUE AZSQRT */
6209 zm = azabs(ar, ai);
6210 zm = sqrt(zm);
6211 if (*ar == 0.) {
6212 goto L10;
6213 }
6214 if (*ai == 0.) {
6215 goto L20;
6216 }
6217 dtheta = atan(*ai / *ar);
6218 if (dtheta <= 0.) {
6219 goto L40;
6220 }
6221 if (*ar < 0.) {
6222 dtheta -= dpi;
6223 }
6224 goto L50;
6225 L10:
6226 if (*ai > 0.) {
6227 goto L60;
6228 }
6229 if (*ai < 0.) {
6230 goto L70;
6231 }
6232 *br = 0.;
6233 *bi = 0.;
6234 return 0;
6235 L20:
6236 if (*ar > 0.) {
6237 goto L30;
6238 }
6239 *br = 0.;
6240 *bi = sqrt((abs(*ar)));
6241 return 0;
6242 L30:
6243 *br = sqrt(*ar);
6244 *bi = 0.;
6245 return 0;
6246 L40:
6247 if (*ar < 0.) {
6248 dtheta += dpi;
6249 }
6250 L50:
6251 dtheta *= .5;
6252 *br = zm * cos(dtheta);
6253 *bi = zm * sin(dtheta);
6254 return 0;
6255 L60:
6256 *br = zm * drt;
6257 *bi = zm * drt;
6258 return 0;
6259 L70:
6260 *br = zm * drt;
6261 *bi = -zm * drt;
6262 return 0;
6263} /* azsqrt_ */
6264
6265/* Subroutine */ int zuchk(double *yr, double *yi, long *nz,
6266 double *ascle, double *tol)
6267{
6268 double wi, ss, st, wr;
6269
6270/* ***BEGIN PROLOGUE ZUCHK */
6271/* ***REFER TO ZSERI,ZUOIK,ZUNK1,ZUNK2,ZUNI1,ZUNI2,ZKSCL */
6272
6273/* Y ENTERS AS A SCALED QUANTITY WHOSE MAGNITUDE IS GREATER THAN */
6274/* EXP(-ALIM)=ASCLE=1.0E+3*D1MACH(1)/TOL. THE TEST IS MADE TO SEE */
6275/* IF THE MAGNITUDE OF THE REAL OR IMAGINARY PART WOULD UNDERFLOW */
6276/* WHEN Y IS SCALED (BY TOL) TO ITS PROPER VALUE. Y IS ACCEPTED */
6277/* IF THE UNDERFLOW IS AT LEAST ONE PRECISION BELOW THE MAGNITUDE */
6278/* OF THE LARGEST COMPONENT; OTHERWISE THE PHASE ANGLE DOES NOT HAVE */
6279/* ABSOLUTE ACCURACY AND AN UNDERFLOW IS ASSUMED. */
6280
6281/* ***ROUTINES CALLED (NONE) */
6282/* ***END PROLOGUE ZUCHK */
6283
6284/* COMPLEX Y */
6285 *nz = 0;
6286 wr = abs(*yr);
6287 wi = abs(*yi);
6288 st = min(wr, wi);
6289 if (st > *ascle) {
6290 return 0;
6291 }
6292 ss = max(wr, wi);
6293 st /= *tol;
6294 if (ss < st) {
6295 *nz = 1;
6296 }
6297 return 0;
6298} /* zuchk_ */
6299
6300/* Subroutine */ int zunhj(double *zr, double *zi, double *fnu,
6301 long *ipmtr, double *tol, double *phir,
6302 double *phii, double *argr, double *argi,
6303 double *zeta1r, double *zeta1i, double *zeta2r,
6304 double *zeta2i, double *asumr, double *asumi,
6305 double *bsumr, double *bsumi)
6306{
6307 /* Initialized data */
6308
6309 double ar[14] = { 1., .104166666666666667, .0835503472222222222,
6310 .12822657455632716, .291849026464140464, .881627267443757652,
6311 3.32140828186276754, 14.9957629868625547, 78.9230130115865181,
6312 474.451538868264323, 3207.49009089066193, 24086.5496408740049,
6313 198923.119169509794, 1791902.00777534383
6314 };
6315 double br[14] = { 1., -.145833333333333333,
6316 -.0987413194444444444, -.143312053915895062, -.317227202678413548,
6317 -.942429147957120249, -3.51120304082635426, -15.7272636203680451,
6318 -82.2814390971859444, -492.355370523670524, -3316.21856854797251,
6319 -24827.6742452085896, -204526.587315129788, -1838444.9170682099
6320 };
6321 double c__[105] = { 1., -.208333333333333333, .125,
6322 .334201388888888889, -.401041666666666667, .0703125,
6323 -1.02581259645061728, 1.84646267361111111, -.8912109375,
6324 .0732421875,
6325 4.66958442342624743, -11.2070026162229938, 8.78912353515625,
6326 -2.3640869140625, .112152099609375, -28.2120725582002449,
6327 84.6362176746007346, -91.8182415432400174, 42.5349987453884549,
6328 -7.3687943594796317, .227108001708984375, 212.570130039217123,
6329 -765.252468141181642, 1059.99045252799988, -699.579627376132541,
6330 218.19051174421159, -26.4914304869515555, .572501420974731445,
6331 -1919.457662318407, 8061.72218173730938, -13586.5500064341374,
6332 11655.3933368645332, -5305.64697861340311, 1200.90291321635246,
6333 -108.090919788394656, 1.7277275025844574, 20204.2913309661486,
6334 -96980.5983886375135, 192547.001232531532, -203400.177280415534,
6335 122200.46498301746, -41192.6549688975513, 7109.51430248936372,
6336 -493.915304773088012, 6.07404200127348304, -242919.187900551333,
6337 1311763.6146629772, -2998015.91853810675, 3763271.297656404,
6338 -2813563.22658653411, 1268365.27332162478, -331645.172484563578,
6339 45218.7689813627263, -2499.83048181120962, 24.3805296995560639,
6340 3284469.85307203782, -19706819.1184322269, 50952602.4926646422,
6341 -74105148.2115326577, 66344512.2747290267, -37567176.6607633513,
6342 13288767.1664218183, -2785618.12808645469, 308186.404612662398,
6343 -13886.0897537170405, 110.017140269246738, -49329253.664509962,
6344 325573074.185765749, -939462359.681578403, 1553596899.57058006,
6345 -1621080552.10833708, 1106842816.82301447, -495889784.275030309,
6346 142062907.797533095, -24474062.7257387285, 2243768.17792244943,
6347 -84005.4336030240853, 551.335896122020586, 814789096.118312115,
6348 -5866481492.05184723, 18688207509.2958249, -34632043388.1587779,
6349 41280185579.753974, -33026599749.8007231, 17954213731.1556001,
6350 -6563293792.61928433, 1559279864.87925751, -225105661.889415278,
6351 17395107.5539781645, -549842.327572288687, 3038.09051092238427,
6352 -14679261247.6956167, 114498237732.02581, -399096175224.466498,
6353 819218669548.577329, -1098375156081.22331, 1008158106865.38209,
6354 -645364869245.376503, 287900649906.150589, -87867072178.0232657,
6355 17634730606.8349694, -2167164983.22379509, 143157876.718888981,
6356 -3871833.44257261262, 18257.7554742931747
6357 };
6358 double alfa[180] = { -.00444444444444444444,
6359 -9.22077922077922078e-4, -8.84892884892884893e-5,
6360 1.65927687832449737e-4, 2.4669137274179291e-4,
6361 2.6599558934625478e-4, 2.61824297061500945e-4,
6362 2.48730437344655609e-4, 2.32721040083232098e-4,
6363 2.16362485712365082e-4, 2.00738858762752355e-4,
6364 1.86267636637545172e-4, 1.73060775917876493e-4,
6365 1.61091705929015752e-4, 1.50274774160908134e-4,
6366 1.40503497391269794e-4, 1.31668816545922806e-4,
6367 1.23667445598253261e-4, 1.16405271474737902e-4,
6368 1.09798298372713369e-4, 1.03772410422992823e-4,
6369 9.82626078369363448e-5, 9.32120517249503256e-5,
6370 8.85710852478711718e-5, 8.42963105715700223e-5,
6371 8.03497548407791151e-5, 7.66981345359207388e-5,
6372 7.33122157481777809e-5, 7.01662625163141333e-5,
6373 6.72375633790160292e-5, 6.93735541354588974e-4,
6374 2.32241745182921654e-4, -1.41986273556691197e-5,
6375 -1.1644493167204864e-4, -1.50803558053048762e-4,
6376 -1.55121924918096223e-4, -1.46809756646465549e-4,
6377 -1.33815503867491367e-4, -1.19744975684254051e-4,
6378 -1.0618431920797402e-4, -9.37699549891194492e-5,
6379 -8.26923045588193274e-5, -7.29374348155221211e-5,
6380 -6.44042357721016283e-5, -5.69611566009369048e-5,
6381 -5.04731044303561628e-5, -4.48134868008882786e-5,
6382 -3.98688727717598864e-5, -3.55400532972042498e-5,
6383 -3.1741425660902248e-5, -2.83996793904174811e-5,
6384 -2.54522720634870566e-5, -2.28459297164724555e-5,
6385 -2.05352753106480604e-5, -1.84816217627666085e-5,
6386 -1.66519330021393806e-5, -1.50179412980119482e-5,
6387 -1.35554031379040526e-5, -1.22434746473858131e-5,
6388 -1.10641884811308169e-5, -3.54211971457743841e-4,
6389 -1.56161263945159416e-4, 3.0446550359493641e-5,
6390 1.30198655773242693e-4, 1.67471106699712269e-4,
6391 1.70222587683592569e-4, 1.56501427608594704e-4,
6392 1.3633917097744512e-4, 1.14886692029825128e-4,
6393 9.45869093034688111e-5, 7.64498419250898258e-5,
6394 6.07570334965197354e-5, 4.74394299290508799e-5,
6395 3.62757512005344297e-5, 2.69939714979224901e-5,
6396 1.93210938247939253e-5, 1.30056674793963203e-5,
6397 7.82620866744496661e-6, 3.59257485819351583e-6,
6398 1.44040049814251817e-7, -2.65396769697939116e-6,
6399 -4.9134686709848591e-6, -6.72739296091248287e-6,
6400 -8.17269379678657923e-6, -9.31304715093561232e-6,
6401 -1.02011418798016441e-5, -1.0880596251059288e-5,
6402 -1.13875481509603555e-5, -1.17519675674556414e-5,
6403 -1.19987364870944141e-5, 3.78194199201772914e-4,
6404 2.02471952761816167e-4, -6.37938506318862408e-5,
6405 -2.38598230603005903e-4, -3.10916256027361568e-4,
6406 -3.13680115247576316e-4, -2.78950273791323387e-4,
6407 -2.28564082619141374e-4, -1.75245280340846749e-4,
6408 -1.25544063060690348e-4, -8.22982872820208365e-5,
6409 -4.62860730588116458e-5, -1.72334302366962267e-5,
6410 5.60690482304602267e-6, 2.313954431482868e-5,
6411 3.62642745856793957e-5, 4.58006124490188752e-5,
6412 5.2459529495911405e-5, 5.68396208545815266e-5,
6413 5.94349820393104052e-5, 6.06478527578421742e-5,
6414 6.08023907788436497e-5, 6.01577894539460388e-5,
6415 5.891996573446985e-5, 5.72515823777593053e-5,
6416 5.52804375585852577e-5, 5.3106377380288017e-5,
6417 5.08069302012325706e-5, 4.84418647620094842e-5,
6418 4.6056858160747537e-5, -6.91141397288294174e-4,
6419 -4.29976633058871912e-4, 1.83067735980039018e-4,
6420 6.60088147542014144e-4, 8.75964969951185931e-4,
6421 8.77335235958235514e-4, 7.49369585378990637e-4,
6422 5.63832329756980918e-4, 3.68059319971443156e-4,
6423 1.88464535514455599e-4, 3.70663057664904149e-5,
6424 -8.28520220232137023e-5, -1.72751952869172998e-4,
6425 -2.36314873605872983e-4, -2.77966150694906658e-4,
6426 -3.02079514155456919e-4, -3.12594712643820127e-4,
6427 -3.12872558758067163e-4, -3.05678038466324377e-4,
6428 -2.93226470614557331e-4, -2.77255655582934777e-4,
6429 -2.59103928467031709e-4, -2.39784014396480342e-4,
6430 -2.20048260045422848e-4, -2.00443911094971498e-4,
6431 -1.81358692210970687e-4, -1.63057674478657464e-4,
6432 -1.45712672175205844e-4, -1.29425421983924587e-4,
6433 -1.14245691942445952e-4, .00192821964248775885,
6434 .00135592576302022234, -7.17858090421302995e-4,
6435 -.00258084802575270346, -.00349271130826168475,
6436 -.00346986299340960628, -.00282285233351310182,
6437 -.00188103076404891354, -8.895317183839476e-4,
6438 3.87912102631035228e-6, 7.28688540119691412e-4,
6439 .00126566373053457758, .00162518158372674427,
6440 .00183203153216373172,
6441 .00191588388990527909, .00190588846755546138,
6442 .00182798982421825727,
6443 .0017038950642112153, .00155097127171097686, .00138261421852276159,
6444 .00120881424230064774, .00103676532638344962,
6445 8.71437918068619115e-4, 7.16080155297701002e-4,
6446 5.72637002558129372e-4, 4.42089819465802277e-4,
6447 3.24724948503090564e-4, 2.20342042730246599e-4,
6448 1.28412898401353882e-4, 4.82005924552095464e-5
6449 };
6450 double beta[210] = { .0179988721413553309,
6451 .00559964911064388073, .00288501402231132779,
6452 .00180096606761053941,
6453 .00124753110589199202, 9.22878876572938311e-4,
6454 7.14430421727287357e-4, 5.71787281789704872e-4,
6455 4.69431007606481533e-4, 3.93232835462916638e-4,
6456 3.34818889318297664e-4, 2.88952148495751517e-4,
6457 2.52211615549573284e-4, 2.22280580798883327e-4,
6458 1.97541838033062524e-4, 1.76836855019718004e-4,
6459 1.59316899661821081e-4, 1.44347930197333986e-4,
6460 1.31448068119965379e-4, 1.20245444949302884e-4,
6461 1.10449144504599392e-4, 1.01828770740567258e-4,
6462 9.41998224204237509e-5, 8.74130545753834437e-5,
6463 8.13466262162801467e-5, 7.59002269646219339e-5,
6464 7.09906300634153481e-5, 6.65482874842468183e-5,
6465 6.25146958969275078e-5, 5.88403394426251749e-5,
6466 -.00149282953213429172, -8.78204709546389328e-4,
6467 -5.02916549572034614e-4, -2.94822138512746025e-4,
6468 -1.75463996970782828e-4, -1.04008550460816434e-4,
6469 -5.96141953046457895e-5, -3.1203892907609834e-5,
6470 -1.26089735980230047e-5, -2.42892608575730389e-7,
6471 8.05996165414273571e-6, 1.36507009262147391e-5,
6472 1.73964125472926261e-5, 1.9867297884213378e-5,
6473 2.14463263790822639e-5, 2.23954659232456514e-5,
6474 2.28967783814712629e-5, 2.30785389811177817e-5,
6475 2.30321976080909144e-5, 2.28236073720348722e-5,
6476 2.25005881105292418e-5, 2.20981015361991429e-5,
6477 2.16418427448103905e-5, 2.11507649256220843e-5,
6478 2.06388749782170737e-5, 2.01165241997081666e-5,
6479 1.95913450141179244e-5, 1.9068936791043674e-5,
6480 1.85533719641636667e-5, 1.80475722259674218e-5,
6481 5.5221307672129279e-4, 4.47932581552384646e-4,
6482 2.79520653992020589e-4, 1.52468156198446602e-4,
6483 6.93271105657043598e-5, 1.76258683069991397e-5,
6484 -1.35744996343269136e-5, -3.17972413350427135e-5,
6485 -4.18861861696693365e-5, -4.69004889379141029e-5,
6486 -4.87665447413787352e-5, -4.87010031186735069e-5,
6487 -4.74755620890086638e-5, -4.55813058138628452e-5,
6488 -4.33309644511266036e-5, -4.09230193157750364e-5,
6489 -3.84822638603221274e-5, -3.60857167535410501e-5,
6490 -3.37793306123367417e-5, -3.15888560772109621e-5,
6491 -2.95269561750807315e-5, -2.75978914828335759e-5,
6492 -2.58006174666883713e-5, -2.413083567612802e-5,
6493 -2.25823509518346033e-5, -2.11479656768912971e-5,
6494 -1.98200638885294927e-5, -1.85909870801065077e-5,
6495 -1.74532699844210224e-5, -1.63997823854497997e-5,
6496 -4.74617796559959808e-4, -4.77864567147321487e-4,
6497 -3.20390228067037603e-4, -1.61105016119962282e-4,
6498 -4.25778101285435204e-5, 3.44571294294967503e-5,
6499 7.97092684075674924e-5, 1.031382367082722e-4,
6500 1.12466775262204158e-4, 1.13103642108481389e-4,
6501 1.08651634848774268e-4, 1.01437951597661973e-4,
6502 9.29298396593363896e-5, 8.40293133016089978e-5,
6503 7.52727991349134062e-5, 6.69632521975730872e-5,
6504 5.92564547323194704e-5, 5.22169308826975567e-5,
6505 4.58539485165360646e-5, 4.01445513891486808e-5,
6506 3.50481730031328081e-5, 3.05157995034346659e-5,
6507 2.64956119950516039e-5, 2.29363633690998152e-5,
6508 1.97893056664021636e-5, 1.70091984636412623e-5,
6509 1.45547428261524004e-5, 1.23886640995878413e-5,
6510 1.04775876076583236e-5, 8.79179954978479373e-6,
6511 7.36465810572578444e-4, 8.72790805146193976e-4,
6512 6.22614862573135066e-4, 2.85998154194304147e-4,
6513 3.84737672879366102e-6, -1.87906003636971558e-4,
6514 -2.97603646594554535e-4, -3.45998126832656348e-4,
6515 -3.53382470916037712e-4, -3.35715635775048757e-4,
6516 -3.04321124789039809e-4, -2.66722723047612821e-4,
6517 -2.27654214122819527e-4, -1.89922611854562356e-4,
6518 -1.5505891859909387e-4, -1.2377824076187363e-4,
6519 -9.62926147717644187e-5, -7.25178327714425337e-5,
6520 -5.22070028895633801e-5, -3.50347750511900522e-5,
6521 -2.06489761035551757e-5, -8.70106096849767054e-6,
6522 1.1369868667510029e-6, 9.16426474122778849e-6,
6523 1.5647778542887262e-5, 2.08223629482466847e-5,
6524 2.48923381004595156e-5, 2.80340509574146325e-5,
6525 3.03987774629861915e-5, 3.21156731406700616e-5,
6526 -.00180182191963885708, -.00243402962938042533,
6527 -.00183422663549856802, -7.62204596354009765e-4,
6528 2.39079475256927218e-4, 9.49266117176881141e-4,
6529 .00134467449701540359, .00148457495259449178,
6530 .00144732339830617591,
6531 .00130268261285657186, .00110351597375642682,
6532 8.86047440419791759e-4, 6.73073208165665473e-4,
6533 4.77603872856582378e-4, 3.05991926358789362e-4,
6534 1.6031569459472163e-4, 4.00749555270613286e-5,
6535 -5.66607461635251611e-5, -1.32506186772982638e-4,
6536 -1.90296187989614057e-4, -2.32811450376937408e-4,
6537 -2.62628811464668841e-4, -2.82050469867598672e-4,
6538 -2.93081563192861167e-4, -2.97435962176316616e-4,
6539 -2.96557334239348078e-4, -2.91647363312090861e-4,
6540 -2.83696203837734166e-4, -2.73512317095673346e-4,
6541 -2.6175015580676858e-4, .00638585891212050914,
6542 .00962374215806377941, .00761878061207001043,
6543 .00283219055545628054,
6544 -.0020984135201272009, -.00573826764216626498,
6545 -.0077080424449541462, -.00821011692264844401,
6546 -.00765824520346905413, -.00647209729391045177,
6547 -.00499132412004966473, -.0034561228971313328,
6548 -.00201785580014170775, -7.59430686781961401e-4,
6549 2.84173631523859138e-4, .00110891667586337403,
6550 .00172901493872728771, .00216812590802684701,
6551 .00245357710494539735,
6552 .00261281821058334862, .00267141039656276912, .0026520307339598043,
6553 .00257411652877287315, .00245389126236094427,
6554 .00230460058071795494,
6555 .00213684837686712662, .00195896528478870911,
6556 .00177737008679454412,
6557 .00159690280765839059, .00142111975664438546
6558 };
6559 double gama[30] = { .629960524947436582, .251984209978974633,
6560 .154790300415655846, .110713062416159013, .0857309395527394825,
6561 .0697161316958684292, .0586085671893713576, .0504698873536310685,
6562 .0442600580689154809, .0393720661543509966, .0354283195924455368,
6563 .0321818857502098231, .0294646240791157679, .0271581677112934479,
6564 .0251768272973861779, .0234570755306078891, .0219508390134907203,
6565 .020621082823564624, .0194388240897880846, .0183810633800683158,
6566 .0174293213231963172, .0165685837786612353, .0157865285987918445,
6567 .0150729501494095594, .0144193250839954639, .0138184805735341786,
6568 .0132643378994276568, .0127517121970498651, .0122761545318762767,
6569 .0118338262398482403
6570 };
6571 double ex1 = .333333333333333333;
6572 double ex2 = .666666666666666667;
6573 double hpi = 1.57079632679489662;
6574 double gpi = 3.14159265358979324;
6575 double thpi = 4.71238898038468986;
6576 double zeror = 0.;
6577 double zeroi = 0.;
6578 double coner = 1.;
6579 double conei = 0.;
6580
6581 /* System generated locals */
6582 long i__1, i__2;
6583 double d__1;
6584
6585 /* Builtin functions */
6586 double log(double), pow_dd(double *, double *), atan(double),
6587 cos(double), sin(double), sqrt(double);
6588
6589 /* Local variables */
6590 long j, k, l, m, l1, l2;
6591 double ac, ap[30], pi[30];
6592 long is, jr, ks, ju;
6593 double pp, wi, pr[30];
6594 long lr;
6595 double wr, aw2;
6596 long kp1;
6597 double t2i, w2i, t2r, w2r, ang, fn13, fn23;
6598 long ias;
6599 double cri[14], dri[14];
6600 long ibs;
6601 double zai, zbi, zci, crr[14], drr[14], raw, zar, upi[14], sti,
6602 zbr, zcr, upr[14], str, raw2;
6603 long lrp1;
6604 double rfn13;
6605 long idum;
6606 double atol, btol, tfni;
6607 long kmax;
6608 double azth, tzai, tfnr, rfnu;
6609 extern /* Subroutine */ int zdiv(double *, double *, double *
6610 , double *, double *, double *);
6611 double zthi, test, tzar, zthr, rfnu2;
6612 extern double azabs(double *, double *);
6613 double zetai;
6614 extern /* Subroutine */ int azlog(double *, double *, double
6615 *, double *, long *);
6616 double ptfni, sumai, sumbi, zetar, ptfnr, razth, sumar, sumbr,
6617 rzthi;
6618 extern double d1mach(long *);
6619 double rzthr, rtzti, rtztr, przthi;
6620 extern /* Subroutine */ int azsqrt(double *, double *,
6621 double *, double *);
6622 double przthr;
6623
6624/* ***BEGIN PROLOGUE ZUNHJ */
6625/* ***REFER TO ZBESI,ZBESK */
6626
6627/* REFERENCES */
6628/* HANDBOOK OF MATHEMATICAL FUNCTIONS BY M. ABRAMOWITZ AND I.A. */
6629/* STEGUN, AMS55, NATIONAL BUREAU OF STANDARDS, 1965, CHAPTER 9. */
6630
6631/* ASYMPTOTICS AND SPECIAL FUNCTIONS BY F.W.J. OLVER, ACADEMIC */
6632/* PRESS, N.Y., 1974, PAGE 420 */
6633
6634/* ABSTRACT */
6635/* ZUNHJ COMPUTES PARAMETERS FOR BESSEL FUNCTIONS C(FNU,Z) = */
6636/* J(FNU,Z), Y(FNU,Z) OR H(I,FNU,Z) I=1,2 FOR LARGE ORDERS FNU */
6637/* BY MEANS OF THE UNIFORM ASYMPTOTIC EXPANSION */
6638
6639/* C(FNU,Z)=C1*PHI*( ASUM*AIRY(ARG) + C2*BSUM*DAIRY(ARG) ) */
6640
6641/* FOR PROPER CHOICES OF C1, C2, AIRY AND DAIRY WHERE AIRY IS */
6642/* AN AIRY FUNCTION AND DAIRY IS ITS DERIVATIVE. */
6643
6644/* (2/3)*FNU*ZETA**1.5 = ZETA1-ZETA2, */
6645
6646/* ZETA1=0.5*FNU*CLOG((1+W)/(1-W)), ZETA2=FNU*W FOR SCALING */
6647/* PURPOSES IN AIRY FUNCTIONS FROM CAIRY OR CBIRY. */
6648
6649/* MCONJ=SIGN OF AIMAG(Z), BUT IS AMBIGUOUS WHEN Z IS REAL AND */
6650/* MUST BE SPECIFIED. IPMTR=0 RETURNS ALL PARAMETERS. IPMTR= */
6651/* 1 COMPUTES ALL EXCEPT ASUM AND BSUM. */
6652
6653/* ***ROUTINES CALLED AZABS,ZDIV,AZLOG,AZSQRT,D1MACH */
6654/* ***END PROLOGUE ZUNHJ */
6655/* COMPLEX ARG,ASUM,BSUM,CFNU,CONE,CR,CZERO,DR,P,PHI,PRZTH,PTFN, */
6656/* *RFN13,RTZTA,RZTH,SUMA,SUMB,TFN,T2,UP,W,W2,Z,ZA,ZB,ZC,ZETA,ZETA1, */
6657/* *ZETA2,ZTH */
6658
6659 rfnu = 1. / *fnu;
6660/* ----------------------------------------------------------------------- */
6661/* OVERFLOW TEST (Z/FNU TOO SMALL) */
6662/* ----------------------------------------------------------------------- */
6663 test = d1mach(&c__1) * 1e3;
6664 ac = *fnu * test;
6665 if (abs(*zr) > ac || abs(*zi) > ac) {
6666 goto L15;
6667 }
6668 *zeta1r = (d__1 = log(test), abs(d__1)) * 2. + *fnu;
6669 *zeta1i = 0.;
6670 *zeta2r = *fnu;
6671 *zeta2i = 0.;
6672 *phir = 1.;
6673 *phii = 0.;
6674 *argr = 1.;
6675 *argi = 0.;
6676 return 0;
6677 L15:
6678 zbr = *zr * rfnu;
6679 zbi = *zi * rfnu;
6680 rfnu2 = rfnu * rfnu;
6681/* ----------------------------------------------------------------------- */
6682/* COMPUTE IN THE FOURTH QUADRANT */
6683/* ----------------------------------------------------------------------- */
6684 fn13 = pow_dd(fnu, &ex1);
6685 fn23 = fn13 * fn13;
6686 rfn13 = 1. / fn13;
6687 w2r = coner - zbr * zbr + zbi * zbi;
6688 w2i = conei - zbr * zbi - zbr * zbi;
6689 aw2 = azabs(&w2r, &w2i);
6690 if (aw2 > .25) {
6691 goto L130;
6692 }
6693/* ----------------------------------------------------------------------- */
6694/* POWER SERIES FOR CABS(W2).LE.0.25D0 */
6695/* ----------------------------------------------------------------------- */
6696 k = 1;
6697 pr[0] = coner;
6698 pi[0] = conei;
6699 sumar = gama[0];
6700 sumai = zeroi;
6701 ap[0] = 1.;
6702 if (aw2 < *tol) {
6703 goto L20;
6704 }
6705 for (k = 2; k <= 30; ++k) {
6706 pr[k - 1] = pr[k - 2] * w2r - pi[k - 2] * w2i;
6707 pi[k - 1] = pr[k - 2] * w2i + pi[k - 2] * w2r;
6708 sumar += pr[k - 1] * gama[k - 1];
6709 sumai += pi[k - 1] * gama[k - 1];
6710 ap[k - 1] = ap[k - 2] * aw2;
6711 if (ap[k - 1] < *tol) {
6712 goto L20;
6713 }
6714/* L10: */
6715 }
6716 k = 30;
6717 L20:
6718 kmax = k;
6719 zetar = w2r * sumar - w2i * sumai;
6720 zetai = w2r * sumai + w2i * sumar;
6721 *argr = zetar * fn23;
6722 *argi = zetai * fn23;
6723 azsqrt(&sumar, &sumai, &zar, &zai);
6724 azsqrt(&w2r, &w2i, &str, &sti);
6725 *zeta2r = str * *fnu;
6726 *zeta2i = sti * *fnu;
6727 str = coner + ex2 * (zetar * zar - zetai * zai);
6728 sti = conei + ex2 * (zetar * zai + zetai * zar);
6729 *zeta1r = str * *zeta2r - sti * *zeta2i;
6730 *zeta1i = str * *zeta2i + sti * *zeta2r;
6731 zar += zar;
6732 zai += zai;
6733 azsqrt(&zar, &zai, &str, &sti);
6734 *phir = str * rfn13;
6735 *phii = sti * rfn13;
6736 if (*ipmtr == 1) {
6737 goto L120;
6738 }
6739/* ----------------------------------------------------------------------- */
6740/* SUM SERIES FOR ASUM AND BSUM */
6741/* ----------------------------------------------------------------------- */
6742 sumbr = zeror;
6743 sumbi = zeroi;
6744 i__1 = kmax;
6745 for (k = 1; k <= i__1; ++k) {
6746 sumbr += pr[k - 1] * beta[k - 1];
6747 sumbi += pi[k - 1] * beta[k - 1];
6748/* L30: */
6749 }
6750 *asumr = zeror;
6751 *asumi = zeroi;
6752 *bsumr = sumbr;
6753 *bsumi = sumbi;
6754 l1 = 0;
6755 l2 = 30;
6756 btol = *tol * (abs(*bsumr) + abs(*bsumi));
6757 atol = *tol;
6758 pp = 1.;
6759 ias = 0;
6760 ibs = 0;
6761 if (rfnu2 < *tol) {
6762 goto L110;
6763 }
6764 for (is = 2; is <= 7; ++is) {
6765 atol /= rfnu2;
6766 pp *= rfnu2;
6767 if (ias == 1) {
6768 goto L60;
6769 }
6770 sumar = zeror;
6771 sumai = zeroi;
6772 i__1 = kmax;
6773 for (k = 1; k <= i__1; ++k) {
6774 m = l1 + k;
6775 sumar += pr[k - 1] * alfa[m - 1];
6776 sumai += pi[k - 1] * alfa[m - 1];
6777 if (ap[k - 1] < atol) {
6778 goto L50;
6779 }
6780/* L40: */
6781 }
6782 L50:
6783 *asumr += sumar * pp;
6784 *asumi += sumai * pp;
6785 if (pp < *tol) {
6786 ias = 1;
6787 }
6788 L60:
6789 if (ibs == 1) {
6790 goto L90;
6791 }
6792 sumbr = zeror;
6793 sumbi = zeroi;
6794 i__1 = kmax;
6795 for (k = 1; k <= i__1; ++k) {
6796 m = l2 + k;
6797 sumbr += pr[k - 1] * beta[m - 1];
6798 sumbi += pi[k - 1] * beta[m - 1];
6799 if (ap[k - 1] < atol) {
6800 goto L80;
6801 }
6802/* L70: */
6803 }
6804 L80:
6805 *bsumr += sumbr * pp;
6806 *bsumi += sumbi * pp;
6807 if (pp < btol) {
6808 ibs = 1;
6809 }
6810 L90:
6811 if (ias == 1 && ibs == 1) {
6812 goto L110;
6813 }
6814 l1 += 30;
6815 l2 += 30;
6816/* L100: */
6817 }
6818 L110:
6819 *asumr += coner;
6820 pp = rfnu * rfn13;
6821 *bsumr *= pp;
6822 *bsumi *= pp;
6823 L120:
6824 return 0;
6825/* ----------------------------------------------------------------------- */
6826/* CABS(W2).GT.0.25D0 */
6827/* ----------------------------------------------------------------------- */
6828 L130:
6829 azsqrt(&w2r, &w2i, &wr, &wi);
6830 if (wr < 0.) {
6831 wr = 0.;
6832 }
6833 if (wi < 0.) {
6834 wi = 0.;
6835 }
6836 str = coner + wr;
6837 sti = wi;
6838 zdiv(&str, &sti, &zbr, &zbi, &zar, &zai);
6839 azlog(&zar, &zai, &zcr, &zci, &idum);
6840 if (zci < 0.) {
6841 zci = 0.;
6842 }
6843 if (zci > hpi) {
6844 zci = hpi;
6845 }
6846 if (zcr < 0.) {
6847 zcr = 0.;
6848 }
6849 zthr = (zcr - wr) * 1.5;
6850 zthi = (zci - wi) * 1.5;
6851 *zeta1r = zcr * *fnu;
6852 *zeta1i = zci * *fnu;
6853 *zeta2r = wr * *fnu;
6854 *zeta2i = wi * *fnu;
6855 azth = azabs(&zthr, &zthi);
6856 ang = thpi;
6857 if (zthr >= 0. && zthi < 0.) {
6858 goto L140;
6859 }
6860 ang = hpi;
6861 if (zthr == 0.) {
6862 goto L140;
6863 }
6864 ang = atan(zthi / zthr);
6865 if (zthr < 0.) {
6866 ang += gpi;
6867 }
6868 L140:
6869 pp = pow_dd(&azth, &ex2);
6870 ang *= ex2;
6871 zetar = pp * cos(ang);
6872 zetai = pp * sin(ang);
6873 if (zetai < 0.) {
6874 zetai = 0.;
6875 }
6876 *argr = zetar * fn23;
6877 *argi = zetai * fn23;
6878 zdiv(&zthr, &zthi, &zetar, &zetai, &rtztr, &rtzti);
6879 zdiv(&rtztr, &rtzti, &wr, &wi, &zar, &zai);
6880 tzar = zar + zar;
6881 tzai = zai + zai;
6882 azsqrt(&tzar, &tzai, &str, &sti);
6883 *phir = str * rfn13;
6884 *phii = sti * rfn13;
6885 if (*ipmtr == 1) {
6886 goto L120;
6887 }
6888 raw = 1. / sqrt(aw2);
6889 str = wr * raw;
6890 sti = -wi * raw;
6891 tfnr = str * rfnu * raw;
6892 tfni = sti * rfnu * raw;
6893 razth = 1. / azth;
6894 str = zthr * razth;
6895 sti = -zthi * razth;
6896 rzthr = str * razth * rfnu;
6897 rzthi = sti * razth * rfnu;
6898 zcr = rzthr * ar[1];
6899 zci = rzthi * ar[1];
6900 raw2 = 1. / aw2;
6901 str = w2r * raw2;
6902 sti = -w2i * raw2;
6903 t2r = str * raw2;
6904 t2i = sti * raw2;
6905 str = t2r * c__[1] + c__[2];
6906 sti = t2i * c__[1];
6907 upr[1] = str * tfnr - sti * tfni;
6908 upi[1] = str * tfni + sti * tfnr;
6909 *bsumr = upr[1] + zcr;
6910 *bsumi = upi[1] + zci;
6911 *asumr = zeror;
6912 *asumi = zeroi;
6913 if (rfnu < *tol) {
6914 goto L220;
6915 }
6916 przthr = rzthr;
6917 przthi = rzthi;
6918 ptfnr = tfnr;
6919 ptfni = tfni;
6920 upr[0] = coner;
6921 upi[0] = conei;
6922 pp = 1.;
6923 btol = *tol * (abs(*bsumr) + abs(*bsumi));
6924 ks = 0;
6925 kp1 = 2;
6926 l = 3;
6927 ias = 0;
6928 ibs = 0;
6929 for (lr = 2; lr <= 12; lr += 2) {
6930 lrp1 = lr + 1;
6931/* ----------------------------------------------------------------------- */
6932/* COMPUTE TWO ADDITIONAL CR, DR, AND UP FOR TWO MORE TERMS IN */
6933/* NEXT SUMA AND SUMB */
6934/* ----------------------------------------------------------------------- */
6935 i__1 = lrp1;
6936 for (k = lr; k <= i__1; ++k) {
6937 ++ks;
6938 ++kp1;
6939 ++l;
6940 zar = c__[l - 1];
6941 zai = zeroi;
6942 i__2 = kp1;
6943 for (j = 2; j <= i__2; ++j) {
6944 ++l;
6945 str = zar * t2r - t2i * zai + c__[l - 1];
6946 zai = zar * t2i + zai * t2r;
6947 zar = str;
6948/* L150: */
6949 }
6950 str = ptfnr * tfnr - ptfni * tfni;
6951 ptfni = ptfnr * tfni + ptfni * tfnr;
6952 ptfnr = str;
6953 upr[kp1 - 1] = ptfnr * zar - ptfni * zai;
6954 upi[kp1 - 1] = ptfni * zar + ptfnr * zai;
6955 crr[ks - 1] = przthr * br[ks];
6956 cri[ks - 1] = przthi * br[ks];
6957 str = przthr * rzthr - przthi * rzthi;
6958 przthi = przthr * rzthi + przthi * rzthr;
6959 przthr = str;
6960 drr[ks - 1] = przthr * ar[ks + 1];
6961 dri[ks - 1] = przthi * ar[ks + 1];
6962/* L160: */
6963 }
6964 pp *= rfnu2;
6965 if (ias == 1) {
6966 goto L180;
6967 }
6968 sumar = upr[lrp1 - 1];
6969 sumai = upi[lrp1 - 1];
6970 ju = lrp1;
6971 i__1 = lr;
6972 for (jr = 1; jr <= i__1; ++jr) {
6973 --ju;
6974 sumar =
6975 sumar + crr[jr - 1] * upr[ju - 1] - cri[jr - 1] * upi[ju -
6976 1];
6977 sumai =
6978 sumai + crr[jr - 1] * upi[ju - 1] + cri[jr - 1] * upr[ju -
6979 1];
6980/* L170: */
6981 }
6982 *asumr += sumar;
6983 *asumi += sumai;
6984 test = abs(sumar) + abs(sumai);
6985 if (pp < *tol && test < *tol) {
6986 ias = 1;
6987 }
6988 L180:
6989 if (ibs == 1) {
6990 goto L200;
6991 }
6992 sumbr = upr[lr + 1] + upr[lrp1 - 1] * zcr - upi[lrp1 - 1] * zci;
6993 sumbi = upi[lr + 1] + upr[lrp1 - 1] * zci + upi[lrp1 - 1] * zcr;
6994 ju = lrp1;
6995 i__1 = lr;
6996 for (jr = 1; jr <= i__1; ++jr) {
6997 --ju;
6998 sumbr =
6999 sumbr + drr[jr - 1] * upr[ju - 1] - dri[jr - 1] * upi[ju -
7000 1];
7001 sumbi =
7002 sumbi + drr[jr - 1] * upi[ju - 1] + dri[jr - 1] * upr[ju -
7003 1];
7004/* L190: */
7005 }
7006 *bsumr += sumbr;
7007 *bsumi += sumbi;
7008 test = abs(sumbr) + abs(sumbi);
7009 if (pp < btol && test < btol) {
7010 ibs = 1;
7011 }
7012 L200:
7013 if (ias == 1 && ibs == 1) {
7014 goto L220;
7015 }
7016/* L210: */
7017 }
7018 L220:
7019 *asumr += coner;
7020 str = -(*bsumr) * rfn13;
7021 sti = -(*bsumi) * rfn13;
7022 zdiv(&str, &sti, &rtztr, &rtzti, bsumr, bsumi);
7023 goto L120;
7024} /* zunhj_ */
7025
7026/* Subroutine */ int zuni1(double *zr, double *zi, double *fnu,
7027 long *kode, long *n, double *yr, double *yi,
7028 long *nz, long *nlast, double *fnul,
7029 double *tol, double *elim, double *alim)
7030{
7031 /* Initialized data */
7032
7033 double zeror = 0.;
7034 double zeroi = 0.;
7035 double coner = 1.;
7036
7037 /* System generated locals */
7038 long i__1;
7039
7040 /* Builtin functions */
7041 double log(double), exp(double), cos(double), sin(double);
7042
7043 /* Local variables */
7044 long i__, k, m, nd;
7045 double fn;
7046 long nn, nw;
7047 double c2i, c2m, c1r, c2r, s1i, s2i, rs1, s1r, s2r, cyi[2];
7048 long nuf;
7049 double bry[3], cyr[2], sti, rzi, str, rzr, aphi, cscl, phii,
7050 crsc, phir;
7051 long init;
7052 double csrr[3], cssr[3], rast, sumi, sumr;
7053 long iflag;
7054 double ascle;
7055 extern double azabs(double *, double *);
7056 double cwrki[16];
7057 extern /* Subroutine */ int zuchk(double *, double *, long *,
7058 double *, double *);
7059 double cwrkr[16];
7060 extern double d1mach(long *);
7061 extern /* Subroutine */ int zunik(double *, double *, double
7062 *, long *, long *, double *, long *,
7063 double *, double *, double *,
7064 double *, double *, double *,
7065 double *, double *, double *,
7066 double *), zuoik(double *, double *,
7067 double *, long *,
7068 long *, long *,
7069 double *, double *,
7070 long *, double *,
7071 double *, double *);
7072 double zeta1i, zeta2i, zeta1r, zeta2r;
7073
7074/* ***BEGIN PROLOGUE ZUNI1 */
7075/* ***REFER TO ZBESI,ZBESK */
7076
7077/* ZUNI1 COMPUTES I(FNU,Z) BY MEANS OF THE UNIFORM ASYMPTOTIC */
7078/* EXPANSION FOR I(FNU,Z) IN -PI/3.LE.ARG Z.LE.PI/3. */
7079
7080/* FNUL IS THE SMALLEST ORDER PERMITTED FOR THE ASYMPTOTIC */
7081/* EXPANSION. NLAST=0 MEANS ALL OF THE Y VALUES WERE SET. */
7082/* NLAST.NE.0 IS THE NUMBER LEFT TO BE COMPUTED BY ANOTHER */
7083/* FORMULA FOR ORDERS FNU TO FNU+NLAST-1 BECAUSE FNU+NLAST-1.LT.FNUL. */
7084/* Y(I)=CZERO FOR I=NLAST+1,N */
7085
7086/* ***ROUTINES CALLED ZUCHK,ZUNIK,ZUOIK,D1MACH,AZABS */
7087/* ***END PROLOGUE ZUNI1 */
7088/* COMPLEX CFN,CONE,CRSC,CSCL,CSR,CSS,CWRK,CZERO,C1,C2,PHI,RZ,SUM,S1, */
7089/* *S2,Y,Z,ZETA1,ZETA2 */
7090 /* Parameter adjustments */
7091 --yi;
7092 --yr;
7093
7094 /* Function Body */
7095
7096 *nz = 0;
7097 nd = *n;
7098 *nlast = 0;
7099/* ----------------------------------------------------------------------- */
7100/* COMPUTED VALUES WITH EXPONENTS BETWEEN ALIM AND ELIM IN MAG- */
7101/* NITUDE ARE SCALED TO KEEP INTERMEDIATE ARITHMETIC ON SCALE, */
7102/* EXP(ALIM)=EXP(ELIM)*TOL */
7103/* ----------------------------------------------------------------------- */
7104 cscl = 1. / *tol;
7105 crsc = *tol;
7106 cssr[0] = cscl;
7107 cssr[1] = coner;
7108 cssr[2] = crsc;
7109 csrr[0] = crsc;
7110 csrr[1] = coner;
7111 csrr[2] = cscl;
7112 bry[0] = d1mach(&c__1) * 1e3 / *tol;
7113/* ----------------------------------------------------------------------- */
7114/* CHECK FOR UNDERFLOW AND OVERFLOW ON FIRST MEMBER */
7115/* ----------------------------------------------------------------------- */
7116 fn = max(*fnu, 1.);
7117 init = 0;
7118 zunik(zr, zi, &fn, &c__1, &c__1, tol, &init, &phir, &phii, &zeta1r,
7119 &zeta1i, &zeta2r, &zeta2i, &sumr, &sumi, cwrkr, cwrki);
7120 if (*kode == 1) {
7121 goto L10;
7122 }
7123 str = *zr + zeta2r;
7124 sti = *zi + zeta2i;
7125 rast = fn / azabs(&str, &sti);
7126 str = str * rast * rast;
7127 sti = -sti * rast * rast;
7128 s1r = -zeta1r + str;
7129 s1i = -zeta1i + sti;
7130 goto L20;
7131 L10:
7132 s1r = -zeta1r + zeta2r;
7133 s1i = -zeta1i + zeta2i;
7134 L20:
7135 rs1 = s1r;
7136 if (abs(rs1) > *elim) {
7137 goto L130;
7138 }
7139 L30:
7140 nn = min(2, nd);
7141 i__1 = nn;
7142 for (i__ = 1; i__ <= i__1; ++i__) {
7143 fn = *fnu + (double) ((float) (nd - i__));
7144 init = 0;
7145 zunik(zr, zi, &fn, &c__1, &c__0, tol, &init, &phir, &phii, &zeta1r,
7146 &zeta1i, &zeta2r, &zeta2i, &sumr, &sumi, cwrkr, cwrki);
7147 if (*kode == 1) {
7148 goto L40;
7149 }
7150 str = *zr + zeta2r;
7151 sti = *zi + zeta2i;
7152 rast = fn / azabs(&str, &sti);
7153 str = str * rast * rast;
7154 sti = -sti * rast * rast;
7155 s1r = -zeta1r + str;
7156 s1i = -zeta1i + sti + *zi;
7157 goto L50;
7158 L40:
7159 s1r = -zeta1r + zeta2r;
7160 s1i = -zeta1i + zeta2i;
7161 L50:
7162/* ----------------------------------------------------------------------- */
7163/* TEST FOR UNDERFLOW AND OVERFLOW */
7164/* ----------------------------------------------------------------------- */
7165 rs1 = s1r;
7166 if (abs(rs1) > *elim) {
7167 goto L110;
7168 }
7169 if (i__ == 1) {
7170 iflag = 2;
7171 }
7172 if (abs(rs1) < *alim) {
7173 goto L60;
7174 }
7175/* ----------------------------------------------------------------------- */
7176/* REFINE TEST AND SCALE */
7177/* ----------------------------------------------------------------------- */
7178 aphi = azabs(&phir, &phii);
7179 rs1 += log(aphi);
7180 if (abs(rs1) > *elim) {
7181 goto L110;
7182 }
7183 if (i__ == 1) {
7184 iflag = 1;
7185 }
7186 if (rs1 < 0.) {
7187 goto L60;
7188 }
7189 if (i__ == 1) {
7190 iflag = 3;
7191 }
7192 L60:
7193/* ----------------------------------------------------------------------- */
7194/* SCALE S1 IF CABS(S1).LT.ASCLE */
7195/* ----------------------------------------------------------------------- */
7196 s2r = phir * sumr - phii * sumi;
7197 s2i = phir * sumi + phii * sumr;
7198 str = exp(s1r) * cssr[iflag - 1];
7199 s1r = str * cos(s1i);
7200 s1i = str * sin(s1i);
7201 str = s2r * s1r - s2i * s1i;
7202 s2i = s2r * s1i + s2i * s1r;
7203 s2r = str;
7204 if (iflag != 1) {
7205 goto L70;
7206 }
7207 zuchk(&s2r, &s2i, &nw, bry, tol);
7208 if (nw != 0) {
7209 goto L110;
7210 }
7211 L70:
7212 cyr[i__ - 1] = s2r;
7213 cyi[i__ - 1] = s2i;
7214 m = nd - i__ + 1;
7215 yr[m] = s2r * csrr[iflag - 1];
7216 yi[m] = s2i * csrr[iflag - 1];
7217/* L80: */
7218 }
7219 if (nd <= 2) {
7220 goto L100;
7221 }
7222 rast = 1. / azabs(zr, zi);
7223 str = *zr * rast;
7224 sti = -(*zi) * rast;
7225 rzr = (str + str) * rast;
7226 rzi = (sti + sti) * rast;
7227 bry[1] = 1. / bry[0];
7228 bry[2] = d1mach(&c__2);
7229 s1r = cyr[0];
7230 s1i = cyi[0];
7231 s2r = cyr[1];
7232 s2i = cyi[1];
7233 c1r = csrr[iflag - 1];
7234 ascle = bry[iflag - 1];
7235 k = nd - 2;
7236 fn = (double) ((float) k);
7237 i__1 = nd;
7238 for (i__ = 3; i__ <= i__1; ++i__) {
7239 c2r = s2r;
7240 c2i = s2i;
7241 s2r = s1r + (*fnu + fn) * (rzr * c2r - rzi * c2i);
7242 s2i = s1i + (*fnu + fn) * (rzr * c2i + rzi * c2r);
7243 s1r = c2r;
7244 s1i = c2i;
7245 c2r = s2r * c1r;
7246 c2i = s2i * c1r;
7247 yr[k] = c2r;
7248 yi[k] = c2i;
7249 --k;
7250 fn += -1.;
7251 if (iflag >= 3) {
7252 goto L90;
7253 }
7254 str = abs(c2r);
7255 sti = abs(c2i);
7256 c2m = max(str, sti);
7257 if (c2m <= ascle) {
7258 goto L90;
7259 }
7260 ++iflag;
7261 ascle = bry[iflag - 1];
7262 s1r *= c1r;
7263 s1i *= c1r;
7264 s2r = c2r;
7265 s2i = c2i;
7266 s1r *= cssr[iflag - 1];
7267 s1i *= cssr[iflag - 1];
7268 s2r *= cssr[iflag - 1];
7269 s2i *= cssr[iflag - 1];
7270 c1r = csrr[iflag - 1];
7271 L90:
7272 ;
7273 }
7274 L100:
7275 return 0;
7276/* ----------------------------------------------------------------------- */
7277/* SET UNDERFLOW AND UPDATE PARAMETERS */
7278/* ----------------------------------------------------------------------- */
7279 L110:
7280 if (rs1 > 0.) {
7281 goto L120;
7282 }
7283 yr[nd] = zeror;
7284 yi[nd] = zeroi;
7285 ++(*nz);
7286 --nd;
7287 if (nd == 0) {
7288 goto L100;
7289 }
7290 zuoik(zr, zi, fnu, kode, &c__1, &nd, &yr[1], &yi[1], &nuf, tol, elim,
7291 alim);
7292 if (nuf < 0) {
7293 goto L120;
7294 }
7295 nd -= nuf;
7296 *nz += nuf;
7297 if (nd == 0) {
7298 goto L100;
7299 }
7300 fn = *fnu + (double) ((float) (nd - 1));
7301 if (fn >= *fnul) {
7302 goto L30;
7303 }
7304 *nlast = nd;
7305 return 0;
7306 L120:
7307 *nz = -1;
7308 return 0;
7309 L130:
7310 if (rs1 > 0.) {
7311 goto L120;
7312 }
7313 *nz = *n;
7314 i__1 = *n;
7315 for (i__ = 1; i__ <= i__1; ++i__) {
7316 yr[i__] = zeror;
7317 yi[i__] = zeroi;
7318/* L140: */
7319 }
7320 return 0;
7321} /* zuni1_ */
7322
7323/* Subroutine */ int zuni2(double *zr, double *zi, double *fnu,
7324 long *kode, long *n, double *yr, double *yi,
7325 long *nz, long *nlast, double *fnul,
7326 double *tol, double *elim, double *alim)
7327{
7328 /* Initialized data */
7329
7330 double zeror = 0.;
7331 double zeroi = 0.;
7332 double coner = 1.;
7333 double cipr[4] = { 1., 0., -1., 0. };
7334 double cipi[4] = { 0., 1., 0., -1. };
7335 double hpi = 1.57079632679489662;
7336 double aic = 1.265512123484645396;
7337
7338 /* System generated locals */
7339 long i__1;
7340
7341 /* Builtin functions */
7342 double cos(double), sin(double), log(double), exp(double);
7343
7344 /* Local variables */
7345 long i__, j, k, nd;
7346 double fn;
7347 long in, nn, nw;
7348 double c2i, c2m, c1r, c2r, s1i, s2i, rs1, s1r, s2r, aii, ang,
7349 car;
7350 long nai;
7351 double air, zbi, cyi[2], sar;
7352 long nuf, inu;
7353 double bry[3], raz, sti, zbr, zni, cyr[2], rzi, str, znr, rzr,
7354 daii, cidi, aarg;
7355 long ndai;
7356 double dair, aphi, argi, cscl, phii, crsc, argr;
7357 long idum;
7358 double phir, csrr[3], cssr[3], rast;
7359 long iflag;
7360 double ascle;
7361 extern double azabs(double *, double *);
7362 double asumi, bsumi;
7363 extern /* Subroutine */ int zuchk(double *, double *, long *,
7364 double *, double *);
7365 double asumr, bsumr;
7366 extern double d1mach(long *);
7367 extern /* Subroutine */ int zunhj(double *, double *, double
7368 *, long *, double *, double *,
7369 double *, double *, double *,
7370 double *, double *, double *,
7371 double *, double *, double *,
7372 double *, double *), zairy(double *,
7373 double *,
7374 long *,
7375 long *,
7376 double *,
7377 double *,
7378 long *,
7379 long *),
7380 zuoik(double *, double *, double *, long *, long *, long *,
7381 double *, double *, long *, double *, double *, double *);
7382 double zeta1i, zeta2i, zeta1r, zeta2r;
7383
7384/* ***BEGIN PROLOGUE ZUNI2 */
7385/* ***REFER TO ZBESI,ZBESK */
7386
7387/* ZUNI2 COMPUTES I(FNU,Z) IN THE RIGHT HALF PLANE BY MEANS OF */
7388/* UNIFORM ASYMPTOTIC EXPANSION FOR J(FNU,ZN) WHERE ZN IS Z*I */
7389/* OR -Z*I AND ZN IS IN THE RIGHT HALF PLANE ALSO. */
7390
7391/* FNUL IS THE SMALLEST ORDER PERMITTED FOR THE ASYMPTOTIC */
7392/* EXPANSION. NLAST=0 MEANS ALL OF THE Y VALUES WERE SET. */
7393/* NLAST.NE.0 IS THE NUMBER LEFT TO BE COMPUTED BY ANOTHER */
7394/* FORMULA FOR ORDERS FNU TO FNU+NLAST-1 BECAUSE FNU+NLAST-1.LT.FNUL. */
7395/* Y(I)=CZERO FOR I=NLAST+1,N */
7396
7397/* ***ROUTINES CALLED ZAIRY,ZUCHK,ZUNHJ,ZUOIK,D1MACH,AZABS */
7398/* ***END PROLOGUE ZUNI2 */
7399/* COMPLEX AI,ARG,ASUM,BSUM,CFN,CI,CID,CIP,CONE,CRSC,CSCL,CSR,CSS, */
7400/* *CZERO,C1,C2,DAI,PHI,RZ,S1,S2,Y,Z,ZB,ZETA1,ZETA2,ZN */
7401 /* Parameter adjustments */
7402 --yi;
7403 --yr;
7404
7405 /* Function Body */
7406
7407 *nz = 0;
7408 nd = *n;
7409 *nlast = 0;
7410/* ----------------------------------------------------------------------- */
7411/* COMPUTED VALUES WITH EXPONENTS BETWEEN ALIM AND ELIM IN MAG- */
7412/* NITUDE ARE SCALED TO KEEP INTERMEDIATE ARITHMETIC ON SCALE, */
7413/* EXP(ALIM)=EXP(ELIM)*TOL */
7414/* ----------------------------------------------------------------------- */
7415 cscl = 1. / *tol;
7416 crsc = *tol;
7417 cssr[0] = cscl;
7418 cssr[1] = coner;
7419 cssr[2] = crsc;
7420 csrr[0] = crsc;
7421 csrr[1] = coner;
7422 csrr[2] = cscl;
7423 bry[0] = d1mach(&c__1) * 1e3 / *tol;
7424/* ----------------------------------------------------------------------- */
7425/* ZN IS IN THE RIGHT HALF PLANE AFTER ROTATION BY CI OR -CI */
7426/* ----------------------------------------------------------------------- */
7427 znr = *zi;
7428 zni = -(*zr);
7429 zbr = *zr;
7430 zbi = *zi;
7431 cidi = -coner;
7432 inu = (long) ((float) (*fnu));
7433 ang = hpi * (*fnu - (double) ((float) inu));
7434 c2r = cos(ang);
7435 c2i = sin(ang);
7436 car = c2r;
7437 sar = c2i;
7438 in = inu + *n - 1;
7439 in = in % 4 + 1;
7440 str = c2r * cipr[in - 1] - c2i * cipi[in - 1];
7441 c2i = c2r * cipi[in - 1] + c2i * cipr[in - 1];
7442 c2r = str;
7443 if (*zi > 0.) {
7444 goto L10;
7445 }
7446 znr = -znr;
7447 zbi = -zbi;
7448 cidi = -cidi;
7449 c2i = -c2i;
7450 L10:
7451/* ----------------------------------------------------------------------- */
7452/* CHECK FOR UNDERFLOW AND OVERFLOW ON FIRST MEMBER */
7453/* ----------------------------------------------------------------------- */
7454 fn = max(*fnu, 1.);
7455 zunhj(&znr, &zni, &fn, &c__1, tol, &phir, &phii, &argr, &argi, &zeta1r,
7456 &zeta1i, &zeta2r, &zeta2i, &asumr, &asumi, &bsumr, &bsumi);
7457 if (*kode == 1) {
7458 goto L20;
7459 }
7460 str = zbr + zeta2r;
7461 sti = zbi + zeta2i;
7462 rast = fn / azabs(&str, &sti);
7463 str = str * rast * rast;
7464 sti = -sti * rast * rast;
7465 s1r = -zeta1r + str;
7466 s1i = -zeta1i + sti;
7467 goto L30;
7468 L20:
7469 s1r = -zeta1r + zeta2r;
7470 s1i = -zeta1i + zeta2i;
7471 L30:
7472 rs1 = s1r;
7473 if (abs(rs1) > *elim) {
7474 goto L150;
7475 }
7476 L40:
7477 nn = min(2, nd);
7478 i__1 = nn;
7479 for (i__ = 1; i__ <= i__1; ++i__) {
7480 fn = *fnu + (double) ((float) (nd - i__));
7481 zunhj(&znr, &zni, &fn, &c__0, tol, &phir, &phii, &argr, &argi,
7482 &zeta1r, &zeta1i, &zeta2r, &zeta2i, &asumr, &asumi, &bsumr,
7483 &bsumi);
7484 if (*kode == 1) {
7485 goto L50;
7486 }
7487 str = zbr + zeta2r;
7488 sti = zbi + zeta2i;
7489 rast = fn / azabs(&str, &sti);
7490 str = str * rast * rast;
7491 sti = -sti * rast * rast;
7492 s1r = -zeta1r + str;
7493 s1i = -zeta1i + sti + abs(*zi);
7494 goto L60;
7495 L50:
7496 s1r = -zeta1r + zeta2r;
7497 s1i = -zeta1i + zeta2i;
7498 L60:
7499/* ----------------------------------------------------------------------- */
7500/* TEST FOR UNDERFLOW AND OVERFLOW */
7501/* ----------------------------------------------------------------------- */
7502 rs1 = s1r;
7503 if (abs(rs1) > *elim) {
7504 goto L120;
7505 }
7506 if (i__ == 1) {
7507 iflag = 2;
7508 }
7509 if (abs(rs1) < *alim) {
7510 goto L70;
7511 }
7512/* ----------------------------------------------------------------------- */
7513/* REFINE TEST AND SCALE */
7514/* ----------------------------------------------------------------------- */
7515/* ----------------------------------------------------------------------- */
7516 aphi = azabs(&phir, &phii);
7517 aarg = azabs(&argr, &argi);
7518 rs1 = rs1 + log(aphi) - log(aarg) * .25 - aic;
7519 if (abs(rs1) > *elim) {
7520 goto L120;
7521 }
7522 if (i__ == 1) {
7523 iflag = 1;
7524 }
7525 if (rs1 < 0.) {
7526 goto L70;
7527 }
7528 if (i__ == 1) {
7529 iflag = 3;
7530 }
7531 L70:
7532/* ----------------------------------------------------------------------- */
7533/* SCALE S1 TO KEEP INTERMEDIATE ARITHMETIC ON SCALE NEAR */
7534/* EXPONENT EXTREMES */
7535/* ----------------------------------------------------------------------- */
7536 zairy(&argr, &argi, &c__0, &c__2, &air, &aii, &nai, &idum);
7537 zairy(&argr, &argi, &c__1, &c__2, &dair, &daii, &ndai, &idum);
7538 str = dair * bsumr - daii * bsumi;
7539 sti = dair * bsumi + daii * bsumr;
7540 str += air * asumr - aii * asumi;
7541 sti += air * asumi + aii * asumr;
7542 s2r = phir * str - phii * sti;
7543 s2i = phir * sti + phii * str;
7544 str = exp(s1r) * cssr[iflag - 1];
7545 s1r = str * cos(s1i);
7546 s1i = str * sin(s1i);
7547 str = s2r * s1r - s2i * s1i;
7548 s2i = s2r * s1i + s2i * s1r;
7549 s2r = str;
7550 if (iflag != 1) {
7551 goto L80;
7552 }
7553 zuchk(&s2r, &s2i, &nw, bry, tol);
7554 if (nw != 0) {
7555 goto L120;
7556 }
7557 L80:
7558 if (*zi <= 0.) {
7559 s2i = -s2i;
7560 }
7561 str = s2r * c2r - s2i * c2i;
7562 s2i = s2r * c2i + s2i * c2r;
7563 s2r = str;
7564 cyr[i__ - 1] = s2r;
7565 cyi[i__ - 1] = s2i;
7566 j = nd - i__ + 1;
7567 yr[j] = s2r * csrr[iflag - 1];
7568 yi[j] = s2i * csrr[iflag - 1];
7569 str = -c2i * cidi;
7570 c2i = c2r * cidi;
7571 c2r = str;
7572/* L90: */
7573 }
7574 if (nd <= 2) {
7575 goto L110;
7576 }
7577 raz = 1. / azabs(zr, zi);
7578 str = *zr * raz;
7579 sti = -(*zi) * raz;
7580 rzr = (str + str) * raz;
7581 rzi = (sti + sti) * raz;
7582 bry[1] = 1. / bry[0];
7583 bry[2] = d1mach(&c__2);
7584 s1r = cyr[0];
7585 s1i = cyi[0];
7586 s2r = cyr[1];
7587 s2i = cyi[1];
7588 c1r = csrr[iflag - 1];
7589 ascle = bry[iflag - 1];
7590 k = nd - 2;
7591 fn = (double) ((float) k);
7592 i__1 = nd;
7593 for (i__ = 3; i__ <= i__1; ++i__) {
7594 c2r = s2r;
7595 c2i = s2i;
7596 s2r = s1r + (*fnu + fn) * (rzr * c2r - rzi * c2i);
7597 s2i = s1i + (*fnu + fn) * (rzr * c2i + rzi * c2r);
7598 s1r = c2r;
7599 s1i = c2i;
7600 c2r = s2r * c1r;
7601 c2i = s2i * c1r;
7602 yr[k] = c2r;
7603 yi[k] = c2i;
7604 --k;
7605 fn += -1.;
7606 if (iflag >= 3) {
7607 goto L100;
7608 }
7609 str = abs(c2r);
7610 sti = abs(c2i);
7611 c2m = max(str, sti);
7612 if (c2m <= ascle) {
7613 goto L100;
7614 }
7615 ++iflag;
7616 ascle = bry[iflag - 1];
7617 s1r *= c1r;
7618 s1i *= c1r;
7619 s2r = c2r;
7620 s2i = c2i;
7621 s1r *= cssr[iflag - 1];
7622 s1i *= cssr[iflag - 1];
7623 s2r *= cssr[iflag - 1];
7624 s2i *= cssr[iflag - 1];
7625 c1r = csrr[iflag - 1];
7626 L100:
7627 ;
7628 }
7629 L110:
7630 return 0;
7631 L120:
7632 if (rs1 > 0.) {
7633 goto L140;
7634 }
7635/* ----------------------------------------------------------------------- */
7636/* SET UNDERFLOW AND UPDATE PARAMETERS */
7637/* ----------------------------------------------------------------------- */
7638 yr[nd] = zeror;
7639 yi[nd] = zeroi;
7640 ++(*nz);
7641 --nd;
7642 if (nd == 0) {
7643 goto L110;
7644 }
7645 zuoik(zr, zi, fnu, kode, &c__1, &nd, &yr[1], &yi[1], &nuf, tol, elim,
7646 alim);
7647 if (nuf < 0) {
7648 goto L140;
7649 }
7650 nd -= nuf;
7651 *nz += nuf;
7652 if (nd == 0) {
7653 goto L110;
7654 }
7655 fn = *fnu + (double) ((float) (nd - 1));
7656 if (fn < *fnul) {
7657 goto L130;
7658 }
7659/* FN = CIDI */
7660/* J = NUF + 1 */
7661/* K = MOD(J,4) + 1 */
7662/* S1R = CIPR(K) */
7663/* S1I = CIPI(K) */
7664/* IF (FN.LT.0.0D0) S1I = -S1I */
7665/* STR = C2R*S1R - C2I*S1I */
7666/* C2I = C2R*S1I + C2I*S1R */
7667/* C2R = STR */
7668 in = inu + nd - 1;
7669 in = in % 4 + 1;
7670 c2r = car * cipr[in - 1] - sar * cipi[in - 1];
7671 c2i = car * cipi[in - 1] + sar * cipr[in - 1];
7672 if (*zi <= 0.) {
7673 c2i = -c2i;
7674 }
7675 goto L40;
7676 L130:
7677 *nlast = nd;
7678 return 0;
7679 L140:
7680 *nz = -1;
7681 return 0;
7682 L150:
7683 if (rs1 > 0.) {
7684 goto L140;
7685 }
7686 *nz = *n;
7687 i__1 = *n;
7688 for (i__ = 1; i__ <= i__1; ++i__) {
7689 yr[i__] = zeror;
7690 yi[i__] = zeroi;
7691/* L160: */
7692 }
7693 return 0;
7694} /* zuni2_ */
7695
7696/* Subroutine */ int zunik(double *zrr, double *zri, double *fnu,
7697 long *ikflg, long *ipmtr, double *tol,
7698 long *init, double *phir, double *phii,
7699 double *zeta1r, double *zeta1i, double *zeta2r,
7700 double *zeta2i, double *sumr, double *sumi,
7701 double *cwrkr, double *cwrki)
7702{
7703 /* Initialized data */
7704
7705 double zeror = 0.;
7706 double zeroi = 0.;
7707 double coner = 1.;
7708 double conei = 0.;
7709 double con[2] = { .398942280401432678, 1.25331413731550025 };
7710 double c__[120] = { 1., -.208333333333333333, .125,
7711 .334201388888888889, -.401041666666666667, .0703125,
7712 -1.02581259645061728, 1.84646267361111111, -.8912109375,
7713 .0732421875,
7714 4.66958442342624743, -11.2070026162229938, 8.78912353515625,
7715 -2.3640869140625, .112152099609375, -28.2120725582002449,
7716 84.6362176746007346, -91.8182415432400174, 42.5349987453884549,
7717 -7.3687943594796317, .227108001708984375, 212.570130039217123,
7718 -765.252468141181642, 1059.99045252799988, -699.579627376132541,
7719 218.19051174421159, -26.4914304869515555, .572501420974731445,
7720 -1919.457662318407, 8061.72218173730938, -13586.5500064341374,
7721 11655.3933368645332, -5305.64697861340311, 1200.90291321635246,
7722 -108.090919788394656, 1.7277275025844574, 20204.2913309661486,
7723 -96980.5983886375135, 192547.001232531532, -203400.177280415534,
7724 122200.46498301746, -41192.6549688975513, 7109.51430248936372,
7725 -493.915304773088012, 6.07404200127348304, -242919.187900551333,
7726 1311763.6146629772, -2998015.91853810675, 3763271.297656404,
7727 -2813563.22658653411, 1268365.27332162478, -331645.172484563578,
7728 45218.7689813627263, -2499.83048181120962, 24.3805296995560639,
7729 3284469.85307203782, -19706819.1184322269, 50952602.4926646422,
7730 -74105148.2115326577, 66344512.2747290267, -37567176.6607633513,
7731 13288767.1664218183, -2785618.12808645469, 308186.404612662398,
7732 -13886.0897537170405, 110.017140269246738, -49329253.664509962,
7733 325573074.185765749, -939462359.681578403, 1553596899.57058006,
7734 -1621080552.10833708, 1106842816.82301447, -495889784.275030309,
7735 142062907.797533095, -24474062.7257387285, 2243768.17792244943,
7736 -84005.4336030240853, 551.335896122020586, 814789096.118312115,
7737 -5866481492.05184723, 18688207509.2958249, -34632043388.1587779,
7738 41280185579.753974, -33026599749.8007231, 17954213731.1556001,
7739 -6563293792.61928433, 1559279864.87925751, -225105661.889415278,
7740 17395107.5539781645, -549842.327572288687, 3038.09051092238427,
7741 -14679261247.6956167, 114498237732.02581, -399096175224.466498,
7742 819218669548.577329, -1098375156081.22331, 1008158106865.38209,
7743 -645364869245.376503, 287900649906.150589, -87867072178.0232657,
7744 17634730606.8349694, -2167164983.22379509, 143157876.718888981,
7745 -3871833.44257261262, 18257.7554742931747, 286464035717.679043,
7746 -2406297900028.50396, 9109341185239.89896, -20516899410934.4374,
7747 30565125519935.3206, -31667088584785.1584, 23348364044581.8409,
7748 -12320491305598.2872, 4612725780849.13197, -1196552880196.1816,
7749 205914503232.410016, -21822927757.5292237, 1247009293.51271032,
7750 -29188388.1222208134, 118838.426256783253
7751 };
7752
7753 /* System generated locals */
7754 long i__1;
7755 double d__1, d__2;
7756
7757 /* Builtin functions */
7758 double log(double);
7759
7760 /* Local variables */
7761 long i__, j, k, l;
7762 double ac, si, ti, sr, tr, t2i, t2r, rfn, sri, sti, zni, srr,
7763 str, znr;
7764 long idum;
7765 extern /* Subroutine */ int zdiv(double *, double *, double *
7766 , double *, double *, double *);
7767 double test, crfni, crfnr;
7768 extern /* Subroutine */ int azlog(double *, double *, double
7769 *, double *, long *);
7770 extern double d1mach(long *);
7771 extern /* Subroutine */ int azsqrt(double *, double *,
7772 double *, double *);
7773
7774/* ***BEGIN PROLOGUE ZUNIK */
7775/* ***REFER TO ZBESI,ZBESK */
7776
7777/* ZUNIK COMPUTES PARAMETERS FOR THE UNIFORM ASYMPTOTIC */
7778/* EXPANSIONS OF THE I AND K FUNCTIONS ON IKFLG= 1 OR 2 */
7779/* RESPECTIVELY BY */
7780
7781/* W(FNU,ZR) = PHI*EXP(ZETA)*SUM */
7782
7783/* WHERE ZETA=-ZETA1 + ZETA2 OR */
7784/* ZETA1 - ZETA2 */
7785
7786/* THE FIRST CALL MUST HAVE INIT=0. SUBSEQUENT CALLS WITH THE */
7787/* SAME ZR AND FNU WILL RETURN THE I OR K FUNCTION ON IKFLG= */
7788/* 1 OR 2 WITH NO CHANGE IN INIT. CWRK IS A COMPLEX WORK */
7789/* ARRAY. IPMTR=0 COMPUTES ALL PARAMETERS. IPMTR=1 COMPUTES PHI, */
7790/* ZETA1,ZETA2. */
7791
7792/* ***ROUTINES CALLED ZDIV,AZLOG,AZSQRT,D1MACH */
7793/* ***END PROLOGUE ZUNIK */
7794/* COMPLEX CFN,CON,CONE,CRFN,CWRK,CZERO,PHI,S,SR,SUM,T,T2,ZETA1, */
7795/* *ZETA2,ZN,ZR */
7796 /* Parameter adjustments */
7797 --cwrki;
7798 --cwrkr;
7799
7800 /* Function Body */
7801
7802 if (*init != 0) {
7803 goto L40;
7804 }
7805/* ----------------------------------------------------------------------- */
7806/* INITIALIZE ALL VARIABLES */
7807/* ----------------------------------------------------------------------- */
7808 rfn = 1. / *fnu;
7809/* ----------------------------------------------------------------------- */
7810/* OVERFLOW TEST (ZR/FNU TOO SMALL) */
7811/* ----------------------------------------------------------------------- */
7812 test = d1mach(&c__1) * 1e3;
7813 ac = *fnu * test;
7814 if (abs(*zrr) > ac || abs(*zri) > ac) {
7815 goto L15;
7816 }
7817 *zeta1r = (d__1 = log(test), abs(d__1)) * 2. + *fnu;
7818 *zeta1i = 0.;
7819 *zeta2r = *fnu;
7820 *zeta2i = 0.;
7821 *phir = 1.;
7822 *phii = 0.;
7823 return 0;
7824 L15:
7825 tr = *zrr * rfn;
7826 ti = *zri * rfn;
7827 sr = coner + (tr * tr - ti * ti);
7828 si = conei + (tr * ti + ti * tr);
7829 azsqrt(&sr, &si, &srr, &sri);
7830 str = coner + srr;
7831 sti = conei + sri;
7832 zdiv(&str, &sti, &tr, &ti, &znr, &zni);
7833 azlog(&znr, &zni, &str, &sti, &idum);
7834 *zeta1r = *fnu * str;
7835 *zeta1i = *fnu * sti;
7836 *zeta2r = *fnu * srr;
7837 *zeta2i = *fnu * sri;
7838 zdiv(&coner, &conei, &srr, &sri, &tr, &ti);
7839 srr = tr * rfn;
7840 sri = ti * rfn;
7841 azsqrt(&srr, &sri, &cwrkr[16], &cwrki[16]);
7842 *phir = cwrkr[16] * con[*ikflg - 1];
7843 *phii = cwrki[16] * con[*ikflg - 1];
7844 if (*ipmtr != 0) {
7845 return 0;
7846 }
7847 zdiv(&coner, &conei, &sr, &si, &t2r, &t2i);
7848 cwrkr[1] = coner;
7849 cwrki[1] = conei;
7850 crfnr = coner;
7851 crfni = conei;
7852 ac = 1.;
7853 l = 1;
7854 for (k = 2; k <= 15; ++k) {
7855 sr = zeror;
7856 si = zeroi;
7857 i__1 = k;
7858 for (j = 1; j <= i__1; ++j) {
7859 ++l;
7860 str = sr * t2r - si * t2i + c__[l - 1];
7861 si = sr * t2i + si * t2r;
7862 sr = str;
7863/* L10: */
7864 }
7865 str = crfnr * srr - crfni * sri;
7866 crfni = crfnr * sri + crfni * srr;
7867 crfnr = str;
7868 cwrkr[k] = crfnr * sr - crfni * si;
7869 cwrki[k] = crfnr * si + crfni * sr;
7870 ac *= rfn;
7871 test = (d__1 = cwrkr[k], abs(d__1)) + (d__2 = cwrki[k], abs(d__2));
7872 if (ac < *tol && test < *tol) {
7873 goto L30;
7874 }
7875/* L20: */
7876 }
7877 k = 15;
7878 L30:
7879 *init = k;
7880 L40:
7881 if (*ikflg == 2) {
7882 goto L60;
7883 }
7884/* ----------------------------------------------------------------------- */
7885/* COMPUTE SUM FOR THE I FUNCTION */
7886/* ----------------------------------------------------------------------- */
7887 sr = zeror;
7888 si = zeroi;
7889 i__1 = *init;
7890 for (i__ = 1; i__ <= i__1; ++i__) {
7891 sr += cwrkr[i__];
7892 si += cwrki[i__];
7893/* L50: */
7894 }
7895 *sumr = sr;
7896 *sumi = si;
7897 *phir = cwrkr[16] * con[0];
7898 *phii = cwrki[16] * con[0];
7899 return 0;
7900 L60:
7901/* ----------------------------------------------------------------------- */
7902/* COMPUTE SUM FOR THE K FUNCTION */
7903/* ----------------------------------------------------------------------- */
7904 sr = zeror;
7905 si = zeroi;
7906 tr = coner;
7907 i__1 = *init;
7908 for (i__ = 1; i__ <= i__1; ++i__) {
7909 sr += tr * cwrkr[i__];
7910 si += tr * cwrki[i__];
7911 tr = -tr;
7912/* L70: */
7913 }
7914 *sumr = sr;
7915 *sumi = si;
7916 *phir = cwrkr[16] * con[1];
7917 *phii = cwrki[16] * con[1];
7918 return 0;
7919} /* zunik_ */
7920
7921/* Subroutine */ int zunk1(double *zr, double *zi, double *fnu,
7922 long *kode, long *mr, long *n, double *yr,
7923 double *yi, long *nz, double *tol, double *elim,
7924 double *alim)
7925{
7926 /* Initialized data */
7927
7928 double zeror = 0.;
7929 double zeroi = 0.;
7930 double coner = 1.;
7931 double pi = 3.14159265358979324;
7932
7933 /* System generated locals */
7934 long i__1;
7935
7936 /* Builtin functions */
7937 double log(double), exp(double), cos(double), sin(double),
7938 d_sign(double *, double *);
7939
7940 /* Local variables */
7941 long i__, j, k, m, ib, ic;
7942 double fn;
7943 long il, kk, nw;
7944 double c1i, c2i, c2m, c1r, c2r, s1i, s2i, rs1, s1r, s2r, ang,
7945 asc, cki, fnf;
7946 long ifn;
7947 double ckr;
7948 long iuf;
7949 double cyi[2], fmr, csr, sgn;
7950 long inu;
7951 double bry[3], cyr[2], sti, rzi, zri, str, rzr, zrr, aphi,
7952 cscl, phii[2], crsc, phir[2];
7953 long init[2];
7954 double csrr[3], cssr[3], rast, sumi[2], razr;
7955 extern /* Subroutine */ int zs1s2(double *, double *, double
7956 *, double *, double *, double *,
7957 long *, double *, double *, long *);
7958 double sumr[2];
7959 long iflag, kflag;
7960 double ascle;
7961 long kdflg;
7962 double phidi;
7963 long ipard;
7964 extern double azabs(double *, double *);
7965 double csgni, phidr;
7966 long initd;
7967 double cspni, cwrki[48] /* was [16][3] */ , sumdi;
7968 extern /* Subroutine */ int zuchk(double *, double *, long *,
7969 double *, double *);
7970 double cspnr, cwrkr[48] /* was [16][3] */ , sumdr;
7971 extern double d1mach(long *);
7972 extern /* Subroutine */ int zunik(double *, double *, double
7973 *, long *, long *, double *, long *,
7974 double *, double *, double *,
7975 double *, double *, double *,
7976 double *, double *, double *,
7977 double *);
7978 double zeta1i[2], zeta2i[2], zet1di, zet2di, zeta1r[2],
7979 zeta2r[2], zet1dr, zet2dr;
7980
7981/* ***BEGIN PROLOGUE ZUNK1 */
7982/* ***REFER TO ZBESK */
7983
7984/* ZUNK1 COMPUTES K(FNU,Z) AND ITS ANALYTIC CONTINUATION FROM THE */
7985/* RIGHT HALF PLANE TO THE LEFT HALF PLANE BY MEANS OF THE */
7986/* UNIFORM ASYMPTOTIC EXPANSION. */
7987/* MR INDICATES THE DIRECTION OF ROTATION FOR ANALYTIC CONTINUATION. */
7988/* NZ=-1 MEANS AN OVERFLOW WILL OCCUR */
7989
7990/* ***ROUTINES CALLED ZKSCL,ZS1S2,ZUCHK,ZUNIK,D1MACH,AZABS */
7991/* ***END PROLOGUE ZUNK1 */
7992/* COMPLEX CFN,CK,CONE,CRSC,CS,CSCL,CSGN,CSPN,CSR,CSS,CWRK,CY,CZERO, */
7993/* *C1,C2,PHI,PHID,RZ,SUM,SUMD,S1,S2,Y,Z,ZETA1,ZETA1D,ZETA2,ZETA2D,ZR */
7994 /* Parameter adjustments */
7995 --yi;
7996 --yr;
7997
7998 /* Function Body */
7999
8000 kdflg = 1;
8001 *nz = 0;
8002/* ----------------------------------------------------------------------- */
8003/* EXP(-ALIM)=EXP(-ELIM)/TOL=APPROX. ONE PRECISION GREATER THAN */
8004/* THE UNDERFLOW LIMIT */
8005/* ----------------------------------------------------------------------- */
8006 cscl = 1. / *tol;
8007 crsc = *tol;
8008 cssr[0] = cscl;
8009 cssr[1] = coner;
8010 cssr[2] = crsc;
8011 csrr[0] = crsc;
8012 csrr[1] = coner;
8013 csrr[2] = cscl;
8014 bry[0] = d1mach(&c__1) * 1e3 / *tol;
8015 bry[1] = 1. / bry[0];
8016 bry[2] = d1mach(&c__2);
8017 zrr = *zr;
8018 zri = *zi;
8019 if (*zr >= 0.) {
8020 goto L10;
8021 }
8022 zrr = -(*zr);
8023 zri = -(*zi);
8024 L10:
8025 j = 2;
8026 i__1 = *n;
8027 for (i__ = 1; i__ <= i__1; ++i__) {
8028/* ----------------------------------------------------------------------- */
8029/* J FLIP FLOPS BETWEEN 1 AND 2 IN J = 3 - J */
8030/* ----------------------------------------------------------------------- */
8031 j = 3 - j;
8032 fn = *fnu + (double) ((float) (i__ - 1));
8033 init[j - 1] = 0;
8034 zunik(&zrr, &zri, &fn, &c__2, &c__0, tol, &init[j - 1],
8035 &phir[j - 1], &phii[j - 1], &zeta1r[j - 1], &zeta1i[j - 1],
8036 &zeta2r[j - 1], &zeta2i[j - 1], &sumr[j - 1], &sumi[j - 1],
8037 &cwrkr[(j << 4)
8038 - 16], &cwrki[(j << 4) - 16]);
8039 if (*kode == 1) {
8040 goto L20;
8041 }
8042 str = zrr + zeta2r[j - 1];
8043 sti = zri + zeta2i[j - 1];
8044 rast = fn / azabs(&str, &sti);
8045 str = str * rast * rast;
8046 sti = -sti * rast * rast;
8047 s1r = zeta1r[j - 1] - str;
8048 s1i = zeta1i[j - 1] - sti;
8049 goto L30;
8050 L20:
8051 s1r = zeta1r[j - 1] - zeta2r[j - 1];
8052 s1i = zeta1i[j - 1] - zeta2i[j - 1];
8053 L30:
8054 rs1 = s1r;
8055/* ----------------------------------------------------------------------- */
8056/* TEST FOR UNDERFLOW AND OVERFLOW */
8057/* ----------------------------------------------------------------------- */
8058 if (abs(rs1) > *elim) {
8059 goto L60;
8060 }
8061 if (kdflg == 1) {
8062 kflag = 2;
8063 }
8064 if (abs(rs1) < *alim) {
8065 goto L40;
8066 }
8067/* ----------------------------------------------------------------------- */
8068/* REFINE TEST AND SCALE */
8069/* ----------------------------------------------------------------------- */
8070 aphi = azabs(&phir[j - 1], &phii[j - 1]);
8071 rs1 += log(aphi);
8072 if (abs(rs1) > *elim) {
8073 goto L60;
8074 }
8075 if (kdflg == 1) {
8076 kflag = 1;
8077 }
8078 if (rs1 < 0.) {
8079 goto L40;
8080 }
8081 if (kdflg == 1) {
8082 kflag = 3;
8083 }
8084 L40:
8085/* ----------------------------------------------------------------------- */
8086/* SCALE S1 TO KEEP INTERMEDIATE ARITHMETIC ON SCALE NEAR */
8087/* EXPONENT EXTREMES */
8088/* ----------------------------------------------------------------------- */
8089 s2r = phir[j - 1] * sumr[j - 1] - phii[j - 1] * sumi[j - 1];
8090 s2i = phir[j - 1] * sumi[j - 1] + phii[j - 1] * sumr[j - 1];
8091 str = exp(s1r) * cssr[kflag - 1];
8092 s1r = str * cos(s1i);
8093 s1i = str * sin(s1i);
8094 str = s2r * s1r - s2i * s1i;
8095 s2i = s1r * s2i + s2r * s1i;
8096 s2r = str;
8097 if (kflag != 1) {
8098 goto L50;
8099 }
8100 zuchk(&s2r, &s2i, &nw, bry, tol);
8101 if (nw != 0) {
8102 goto L60;
8103 }
8104 L50:
8105 cyr[kdflg - 1] = s2r;
8106 cyi[kdflg - 1] = s2i;
8107 yr[i__] = s2r * csrr[kflag - 1];
8108 yi[i__] = s2i * csrr[kflag - 1];
8109 if (kdflg == 2) {
8110 goto L75;
8111 }
8112 kdflg = 2;
8113 goto L70;
8114 L60:
8115 if (rs1 > 0.) {
8116 goto L300;
8117 }
8118/* ----------------------------------------------------------------------- */
8119/* FOR ZR.LT.0.0, THE I FUNCTION TO BE ADDED WILL OVERFLOW */
8120/* ----------------------------------------------------------------------- */
8121 if (*zr < 0.) {
8122 goto L300;
8123 }
8124 kdflg = 1;
8125 yr[i__] = zeror;
8126 yi[i__] = zeroi;
8127 ++(*nz);
8128 if (i__ == 1) {
8129 goto L70;
8130 }
8131 if (yr[i__ - 1] == zeror && yi[i__ - 1] == zeroi) {
8132 goto L70;
8133 }
8134 yr[i__ - 1] = zeror;
8135 yi[i__ - 1] = zeroi;
8136 ++(*nz);
8137 L70:
8138 ;
8139 }
8140 i__ = *n;
8141 L75:
8142 razr = 1. / azabs(&zrr, &zri);
8143 str = zrr * razr;
8144 sti = -zri * razr;
8145 rzr = (str + str) * razr;
8146 rzi = (sti + sti) * razr;
8147 ckr = fn * rzr;
8148 cki = fn * rzi;
8149 ib = i__ + 1;
8150 if (*n < ib) {
8151 goto L160;
8152 }
8153/* ----------------------------------------------------------------------- */
8154/* TEST LAST MEMBER FOR UNDERFLOW AND OVERFLOW. SET SEQUENCE TO ZERO */
8155/* ON UNDERFLOW. */
8156/* ----------------------------------------------------------------------- */
8157 fn = *fnu + (double) ((float) (*n - 1));
8158 ipard = 1;
8159 if (*mr != 0) {
8160 ipard = 0;
8161 }
8162 initd = 0;
8163 zunik(&zrr, &zri, &fn, &c__2, &ipard, tol, &initd, &phidr, &phidi,
8164 &zet1dr, &zet1di, &zet2dr, &zet2di, &sumdr, &sumdi, &cwrkr[32],
8165 &cwrki[32]);
8166 if (*kode == 1) {
8167 goto L80;
8168 }
8169 str = zrr + zet2dr;
8170 sti = zri + zet2di;
8171 rast = fn / azabs(&str, &sti);
8172 str = str * rast * rast;
8173 sti = -sti * rast * rast;
8174 s1r = zet1dr - str;
8175 s1i = zet1di - sti;
8176 goto L90;
8177 L80:
8178 s1r = zet1dr - zet2dr;
8179 s1i = zet1di - zet2di;
8180 L90:
8181 rs1 = s1r;
8182 if (abs(rs1) > *elim) {
8183 goto L95;
8184 }
8185 if (abs(rs1) < *alim) {
8186 goto L100;
8187 }
8188/* ---------------------------------------------------------------------------- */
8189/* REFINE ESTIMATE AND TEST */
8190/* ------------------------------------------------------------------------- */
8191 aphi = azabs(&phidr, &phidi);
8192 rs1 += log(aphi);
8193 if (abs(rs1) < *elim) {
8194 goto L100;
8195 }
8196 L95:
8197 if (abs(rs1) > 0.) {
8198 goto L300;
8199 }
8200/* ----------------------------------------------------------------------- */
8201/* FOR ZR.LT.0.0, THE I FUNCTION TO BE ADDED WILL OVERFLOW */
8202/* ----------------------------------------------------------------------- */
8203 if (*zr < 0.) {
8204 goto L300;
8205 }
8206 *nz = *n;
8207 i__1 = *n;
8208 for (i__ = 1; i__ <= i__1; ++i__) {
8209 yr[i__] = zeror;
8210 yi[i__] = zeroi;
8211/* L96: */
8212 }
8213 return 0;
8214/* --------------------------------------------------------------------------- */
8215/* FORWARD RECUR FOR REMAINDER OF THE SEQUENCE */
8216/* ---------------------------------------------------------------------------- */
8217 L100:
8218 s1r = cyr[0];
8219 s1i = cyi[0];
8220 s2r = cyr[1];
8221 s2i = cyi[1];
8222 c1r = csrr[kflag - 1];
8223 ascle = bry[kflag - 1];
8224 i__1 = *n;
8225 for (i__ = ib; i__ <= i__1; ++i__) {
8226 c2r = s2r;
8227 c2i = s2i;
8228 s2r = ckr * c2r - cki * c2i + s1r;
8229 s2i = ckr * c2i + cki * c2r + s1i;
8230 s1r = c2r;
8231 s1i = c2i;
8232 ckr += rzr;
8233 cki += rzi;
8234 c2r = s2r * c1r;
8235 c2i = s2i * c1r;
8236 yr[i__] = c2r;
8237 yi[i__] = c2i;
8238 if (kflag >= 3) {
8239 goto L120;
8240 }
8241 str = abs(c2r);
8242 sti = abs(c2i);
8243 c2m = max(str, sti);
8244 if (c2m <= ascle) {
8245 goto L120;
8246 }
8247 ++kflag;
8248 ascle = bry[kflag - 1];
8249 s1r *= c1r;
8250 s1i *= c1r;
8251 s2r = c2r;
8252 s2i = c2i;
8253 s1r *= cssr[kflag - 1];
8254 s1i *= cssr[kflag - 1];
8255 s2r *= cssr[kflag - 1];
8256 s2i *= cssr[kflag - 1];
8257 c1r = csrr[kflag - 1];
8258 L120:
8259 ;
8260 }
8261 L160:
8262 if (*mr == 0) {
8263 return 0;
8264 }
8265/* ----------------------------------------------------------------------- */
8266/* ANALYTIC CONTINUATION FOR RE(Z).LT.0.0D0 */
8267/* ----------------------------------------------------------------------- */
8268 *nz = 0;
8269 fmr = (double) ((float) (*mr));
8270 sgn = -d_sign(&pi, &fmr);
8271/* ----------------------------------------------------------------------- */
8272/* CSPN AND CSGN ARE COEFF OF K AND I FUNCTIONS RESP. */
8273/* ----------------------------------------------------------------------- */
8274 csgni = sgn;
8275 inu = (long) ((float) (*fnu));
8276 fnf = *fnu - (double) ((float) inu);
8277 ifn = inu + *n - 1;
8278 ang = fnf * sgn;
8279 cspnr = cos(ang);
8280 cspni = sin(ang);
8281 if (ifn % 2 == 0) {
8282 goto L170;
8283 }
8284 cspnr = -cspnr;
8285 cspni = -cspni;
8286 L170:
8287 asc = bry[0];
8288 iuf = 0;
8289 kk = *n;
8290 kdflg = 1;
8291 --ib;
8292 ic = ib - 1;
8293 i__1 = *n;
8294 for (k = 1; k <= i__1; ++k) {
8295 fn = *fnu + (double) ((float) (kk - 1));
8296/* ----------------------------------------------------------------------- */
8297/* LOGIC TO SORT OUT CASES WHOSE PARAMETERS WERE SET FOR THE K */
8298/* FUNCTION ABOVE */
8299/* ----------------------------------------------------------------------- */
8300 m = 3;
8301 if (*n > 2) {
8302 goto L175;
8303 }
8304 L172:
8305 initd = init[j - 1];
8306 phidr = phir[j - 1];
8307 phidi = phii[j - 1];
8308 zet1dr = zeta1r[j - 1];
8309 zet1di = zeta1i[j - 1];
8310 zet2dr = zeta2r[j - 1];
8311 zet2di = zeta2i[j - 1];
8312 sumdr = sumr[j - 1];
8313 sumdi = sumi[j - 1];
8314 m = j;
8315 j = 3 - j;
8316 goto L180;
8317 L175:
8318 if (kk == *n && ib < *n) {
8319 goto L180;
8320 }
8321 if (kk == ib || kk == ic) {
8322 goto L172;
8323 }
8324 initd = 0;
8325 L180:
8326 zunik(&zrr, &zri, &fn, &c__1, &c__0, tol, &initd, &phidr, &phidi,
8327 &zet1dr, &zet1di, &zet2dr, &zet2di, &sumdr, &sumdi,
8328 &cwrkr[(m << 4) - 16], &cwrki[(m << 4) - 16]);
8329 if (*kode == 1) {
8330 goto L200;
8331 }
8332 str = zrr + zet2dr;
8333 sti = zri + zet2di;
8334 rast = fn / azabs(&str, &sti);
8335 str = str * rast * rast;
8336 sti = -sti * rast * rast;
8337 s1r = -zet1dr + str;
8338 s1i = -zet1di + sti;
8339 goto L210;
8340 L200:
8341 s1r = -zet1dr + zet2dr;
8342 s1i = -zet1di + zet2di;
8343 L210:
8344/* ----------------------------------------------------------------------- */
8345/* TEST FOR UNDERFLOW AND OVERFLOW */
8346/* ----------------------------------------------------------------------- */
8347 rs1 = s1r;
8348 if (abs(rs1) > *elim) {
8349 goto L260;
8350 }
8351 if (kdflg == 1) {
8352 iflag = 2;
8353 }
8354 if (abs(rs1) < *alim) {
8355 goto L220;
8356 }
8357/* ----------------------------------------------------------------------- */
8358/* REFINE TEST AND SCALE */
8359/* ----------------------------------------------------------------------- */
8360 aphi = azabs(&phidr, &phidi);
8361 rs1 += log(aphi);
8362 if (abs(rs1) > *elim) {
8363 goto L260;
8364 }
8365 if (kdflg == 1) {
8366 iflag = 1;
8367 }
8368 if (rs1 < 0.) {
8369 goto L220;
8370 }
8371 if (kdflg == 1) {
8372 iflag = 3;
8373 }
8374 L220:
8375 str = phidr * sumdr - phidi * sumdi;
8376 sti = phidr * sumdi + phidi * sumdr;
8377 s2r = -csgni * sti;
8378 s2i = csgni * str;
8379 str = exp(s1r) * cssr[iflag - 1];
8380 s1r = str * cos(s1i);
8381 s1i = str * sin(s1i);
8382 str = s2r * s1r - s2i * s1i;
8383 s2i = s2r * s1i + s2i * s1r;
8384 s2r = str;
8385 if (iflag != 1) {
8386 goto L230;
8387 }
8388 zuchk(&s2r, &s2i, &nw, bry, tol);
8389 if (nw == 0) {
8390 goto L230;
8391 }
8392 s2r = zeror;
8393 s2i = zeroi;
8394 L230:
8395 cyr[kdflg - 1] = s2r;
8396 cyi[kdflg - 1] = s2i;
8397 c2r = s2r;
8398 c2i = s2i;
8399 s2r *= csrr[iflag - 1];
8400 s2i *= csrr[iflag - 1];
8401/* ----------------------------------------------------------------------- */
8402/* ADD I AND K FUNCTIONS, K SEQUENCE IN Y(I), I=1,N */
8403/* ----------------------------------------------------------------------- */
8404 s1r = yr[kk];
8405 s1i = yi[kk];
8406 if (*kode == 1) {
8407 goto L250;
8408 }
8409 zs1s2(&zrr, &zri, &s1r, &s1i, &s2r, &s2i, &nw, &asc, alim, &iuf);
8410 *nz += nw;
8411 L250:
8412 yr[kk] = s1r * cspnr - s1i * cspni + s2r;
8413 yi[kk] = cspnr * s1i + cspni * s1r + s2i;
8414 --kk;
8415 cspnr = -cspnr;
8416 cspni = -cspni;
8417 if (c2r != 0. || c2i != 0.) {
8418 goto L255;
8419 }
8420 kdflg = 1;
8421 goto L270;
8422 L255:
8423 if (kdflg == 2) {
8424 goto L275;
8425 }
8426 kdflg = 2;
8427 goto L270;
8428 L260:
8429 if (rs1 > 0.) {
8430 goto L300;
8431 }
8432 s2r = zeror;
8433 s2i = zeroi;
8434 goto L230;
8435 L270:
8436 ;
8437 }
8438 k = *n;
8439 L275:
8440 il = *n - k;
8441 if (il == 0) {
8442 return 0;
8443 }
8444/* ----------------------------------------------------------------------- */
8445/* RECUR BACKWARD FOR REMAINDER OF I SEQUENCE AND ADD IN THE */
8446/* K FUNCTIONS, SCALING THE I SEQUENCE DURING RECURRENCE TO KEEP */
8447/* INTERMEDIATE ARITHMETIC ON SCALE NEAR EXPONENT EXTREMES. */
8448/* ----------------------------------------------------------------------- */
8449 s1r = cyr[0];
8450 s1i = cyi[0];
8451 s2r = cyr[1];
8452 s2i = cyi[1];
8453 csr = csrr[iflag - 1];
8454 ascle = bry[iflag - 1];
8455 fn = (double) ((float) (inu + il));
8456 i__1 = il;
8457 for (i__ = 1; i__ <= i__1; ++i__) {
8458 c2r = s2r;
8459 c2i = s2i;
8460 s2r = s1r + (fn + fnf) * (rzr * c2r - rzi * c2i);
8461 s2i = s1i + (fn + fnf) * (rzr * c2i + rzi * c2r);
8462 s1r = c2r;
8463 s1i = c2i;
8464 fn += -1.;
8465 c2r = s2r * csr;
8466 c2i = s2i * csr;
8467 ckr = c2r;
8468 cki = c2i;
8469 c1r = yr[kk];
8470 c1i = yi[kk];
8471 if (*kode == 1) {
8472 goto L280;
8473 }
8474 zs1s2(&zrr, &zri, &c1r, &c1i, &c2r, &c2i, &nw, &asc, alim, &iuf);
8475 *nz += nw;
8476 L280:
8477 yr[kk] = c1r * cspnr - c1i * cspni + c2r;
8478 yi[kk] = c1r * cspni + c1i * cspnr + c2i;
8479 --kk;
8480 cspnr = -cspnr;
8481 cspni = -cspni;
8482 if (iflag >= 3) {
8483 goto L290;
8484 }
8485 c2r = abs(ckr);
8486 c2i = abs(cki);
8487 c2m = max(c2r, c2i);
8488 if (c2m <= ascle) {
8489 goto L290;
8490 }
8491 ++iflag;
8492 ascle = bry[iflag - 1];
8493 s1r *= csr;
8494 s1i *= csr;
8495 s2r = ckr;
8496 s2i = cki;
8497 s1r *= cssr[iflag - 1];
8498 s1i *= cssr[iflag - 1];
8499 s2r *= cssr[iflag - 1];
8500 s2i *= cssr[iflag - 1];
8501 csr = csrr[iflag - 1];
8502 L290:
8503 ;
8504 }
8505 return 0;
8506 L300:
8507 *nz = -1;
8508 return 0;
8509} /* zunk1_ */
8510
8511/* Subroutine */ int zunk2(double *zr, double *zi, double *fnu,
8512 long *kode, long *mr, long *n, double *yr,
8513 double *yi, long *nz, double *tol, double *elim,
8514 double *alim)
8515{
8516 /* Initialized data */
8517
8518 double zeror = 0.;
8519 double zeroi = 0.;
8520 double coner = 1.;
8521 double cr1r = 1.;
8522 double cr1i = 1.73205080756887729;
8523 double cr2r = -.5;
8524 double cr2i = -.866025403784438647;
8525 double hpi = 1.57079632679489662;
8526 double pi = 3.14159265358979324;
8527 double aic = 1.26551212348464539;
8528 double cipr[4] = { 1., 0., -1., 0. };
8529 double cipi[4] = { 0., -1., 0., 1. };
8530
8531 /* System generated locals */
8532 long i__1;
8533
8534 /* Builtin functions */
8535 double cos(double), sin(double), log(double), exp(double),
8536 d_sign(double *, double *);
8537
8538 /* Local variables */
8539 long i__, j, k, ib, ic;
8540 double fn;
8541 long il, kk, in, nw;
8542 double yy, c1i, c2i, c2m, c1r, c2r, s1i, s2i, rs1, s1r, s2r,
8543 aii, ang, asc, car, cki, fnf;
8544 long nai;
8545 double air;
8546 long ifn;
8547 double csi, ckr;
8548 long iuf;
8549 double cyi[2], fmr, sar, csr, sgn, zbi;
8550 long inu;
8551 double bry[3], cyr[2], pti, sti, zbr, zni, rzi, ptr, zri, str,
8552 znr, rzr, zrr, daii, aarg;
8553 long ndai;
8554 double dair, aphi, argi[2], cscl, phii[2], crsc, argr[2];
8555 long idum;
8556 double phir[2], csrr[3], cssr[3], rast, razr;
8557 extern /* Subroutine */ int zs1s2(double *, double *, double
8558 *, double *, double *, double *,
8559 long *, double *, double *, long *);
8560 long iflag, kflag;
8561 double argdi, ascle;
8562 long kdflg;
8563 double phidi, argdr;
8564 extern double azabs(double *, double *);
8565 long ipard;
8566 double csgni, phidr, cspni, asumi[2], bsumi[2];
8567 extern /* Subroutine */ int zuchk(double *, double *, long *,
8568 double *, double *);
8569 double cspnr, asumr[2], bsumr[2];
8570 extern double d1mach(long *);
8571 extern /* Subroutine */ int zunhj(double *, double *, double
8572 *, long *, double *, double *,
8573 double *, double *, double *,
8574 double *, double *, double *,
8575 double *, double *, double *,
8576 double *, double *), zairy(double *,
8577 double *,
8578 long *,
8579 long *,
8580 double *,
8581 double *,
8582 long *,
8583 long *);
8584 double zeta1i[2], zeta2i[2], zet1di, zet2di, zeta1r[2],
8585 zeta2r[2], zet1dr, zet2dr, asumdi, bsumdi, asumdr, bsumdr;
8586
8587/* ***BEGIN PROLOGUE ZUNK2 */
8588/* ***REFER TO ZBESK */
8589
8590/* ZUNK2 COMPUTES K(FNU,Z) AND ITS ANALYTIC CONTINUATION FROM THE */
8591/* RIGHT HALF PLANE TO THE LEFT HALF PLANE BY MEANS OF THE */
8592/* UNIFORM ASYMPTOTIC EXPANSIONS FOR H(KIND,FNU,ZN) AND J(FNU,ZN) */
8593/* WHERE ZN IS IN THE RIGHT HALF PLANE, KIND=(3-MR)/2, MR=+1 OR */
8594/* -1. HERE ZN=ZR*I OR -ZR*I WHERE ZR=Z IF Z IS IN THE RIGHT */
8595/* HALF PLANE OR ZR=-Z IF Z IS IN THE LEFT HALF PLANE. MR INDIC- */
8596/* ATES THE DIRECTION OF ROTATION FOR ANALYTIC CONTINUATION. */
8597/* NZ=-1 MEANS AN OVERFLOW WILL OCCUR */
8598
8599/* ***ROUTINES CALLED ZAIRY,ZKSCL,ZS1S2,ZUCHK,ZUNHJ,D1MACH,AZABS */
8600/* ***END PROLOGUE ZUNK2 */
8601/* COMPLEX AI,ARG,ARGD,ASUM,ASUMD,BSUM,BSUMD,CFN,CI,CIP,CK,CONE,CRSC, */
8602/* *CR1,CR2,CS,CSCL,CSGN,CSPN,CSR,CSS,CY,CZERO,C1,C2,DAI,PHI,PHID,RZ, */
8603/* *S1,S2,Y,Z,ZB,ZETA1,ZETA1D,ZETA2,ZETA2D,ZN,ZR */
8604 /* Parameter adjustments */
8605 --yi;
8606 --yr;
8607
8608 /* Function Body */
8609
8610 kdflg = 1;
8611 *nz = 0;
8612/* ----------------------------------------------------------------------- */
8613/* EXP(-ALIM)=EXP(-ELIM)/TOL=APPROX. ONE PRECISION GREATER THAN */
8614/* THE UNDERFLOW LIMIT */
8615/* ----------------------------------------------------------------------- */
8616 cscl = 1. / *tol;
8617 crsc = *tol;
8618 cssr[0] = cscl;
8619 cssr[1] = coner;
8620 cssr[2] = crsc;
8621 csrr[0] = crsc;
8622 csrr[1] = coner;
8623 csrr[2] = cscl;
8624 bry[0] = d1mach(&c__1) * 1e3 / *tol;
8625 bry[1] = 1. / bry[0];
8626 bry[2] = d1mach(&c__2);
8627 zrr = *zr;
8628 zri = *zi;
8629 if (*zr >= 0.) {
8630 goto L10;
8631 }
8632 zrr = -(*zr);
8633 zri = -(*zi);
8634 L10:
8635 yy = zri;
8636 znr = zri;
8637 zni = -zrr;
8638 zbr = zrr;
8639 zbi = zri;
8640 inu = (long) ((float) (*fnu));
8641 fnf = *fnu - (double) ((float) inu);
8642 ang = -hpi * fnf;
8643 car = cos(ang);
8644 sar = sin(ang);
8645 c2r = hpi * sar;
8646 c2i = -hpi * car;
8647 kk = inu % 4 + 1;
8648 str = c2r * cipr[kk - 1] - c2i * cipi[kk - 1];
8649 sti = c2r * cipi[kk - 1] + c2i * cipr[kk - 1];
8650 csr = cr1r * str - cr1i * sti;
8651 csi = cr1r * sti + cr1i * str;
8652 if (yy > 0.) {
8653 goto L20;
8654 }
8655 znr = -znr;
8656 zbi = -zbi;
8657 L20:
8658/* ----------------------------------------------------------------------- */
8659/* K(FNU,Z) IS COMPUTED FROM H(2,FNU,-I*Z) WHERE Z IS IN THE FIRST */
8660/* QUADRANT. FOURTH QUADRANT VALUES (YY.LE.0.0E0) ARE COMPUTED BY */
8661/* CONJUGATION SINCE THE K FUNCTION IS REAL ON THE POSITIVE REAL AXIS */
8662/* ----------------------------------------------------------------------- */
8663 j = 2;
8664 i__1 = *n;
8665 for (i__ = 1; i__ <= i__1; ++i__) {
8666/* ----------------------------------------------------------------------- */
8667/* J FLIP FLOPS BETWEEN 1 AND 2 IN J = 3 - J */
8668/* ----------------------------------------------------------------------- */
8669 j = 3 - j;
8670 fn = *fnu + (double) ((float) (i__ - 1));
8671 zunhj(&znr, &zni, &fn, &c__0, tol, &phir[j - 1], &phii[j - 1],
8672 &argr[j - 1], &argi[j - 1], &zeta1r[j - 1], &zeta1i[j - 1],
8673 &zeta2r[j - 1], &zeta2i[j - 1], &asumr[j - 1], &asumi[j - 1],
8674 &bsumr[j - 1], &bsumi[j - 1]);
8675 if (*kode == 1) {
8676 goto L30;
8677 }
8678 str = zbr + zeta2r[j - 1];
8679 sti = zbi + zeta2i[j - 1];
8680 rast = fn / azabs(&str, &sti);
8681 str = str * rast * rast;
8682 sti = -sti * rast * rast;
8683 s1r = zeta1r[j - 1] - str;
8684 s1i = zeta1i[j - 1] - sti;
8685 goto L40;
8686 L30:
8687 s1r = zeta1r[j - 1] - zeta2r[j - 1];
8688 s1i = zeta1i[j - 1] - zeta2i[j - 1];
8689 L40:
8690/* ----------------------------------------------------------------------- */
8691/* TEST FOR UNDERFLOW AND OVERFLOW */
8692/* ----------------------------------------------------------------------- */
8693 rs1 = s1r;
8694 if (abs(rs1) > *elim) {
8695 goto L70;
8696 }
8697 if (kdflg == 1) {
8698 kflag = 2;
8699 }
8700 if (abs(rs1) < *alim) {
8701 goto L50;
8702 }
8703/* ----------------------------------------------------------------------- */
8704/* REFINE TEST AND SCALE */
8705/* ----------------------------------------------------------------------- */
8706 aphi = azabs(&phir[j - 1], &phii[j - 1]);
8707 aarg = azabs(&argr[j - 1], &argi[j - 1]);
8708 rs1 = rs1 + log(aphi) - log(aarg) * .25 - aic;
8709 if (abs(rs1) > *elim) {
8710 goto L70;
8711 }
8712 if (kdflg == 1) {
8713 kflag = 1;
8714 }
8715 if (rs1 < 0.) {
8716 goto L50;
8717 }
8718 if (kdflg == 1) {
8719 kflag = 3;
8720 }
8721 L50:
8722/* ----------------------------------------------------------------------- */
8723/* SCALE S1 TO KEEP INTERMEDIATE ARITHMETIC ON SCALE NEAR */
8724/* EXPONENT EXTREMES */
8725/* ----------------------------------------------------------------------- */
8726 c2r = argr[j - 1] * cr2r - argi[j - 1] * cr2i;
8727 c2i = argr[j - 1] * cr2i + argi[j - 1] * cr2r;
8728 zairy(&c2r, &c2i, &c__0, &c__2, &air, &aii, &nai, &idum);
8729 zairy(&c2r, &c2i, &c__1, &c__2, &dair, &daii, &ndai, &idum);
8730 str = dair * bsumr[j - 1] - daii * bsumi[j - 1];
8731 sti = dair * bsumi[j - 1] + daii * bsumr[j - 1];
8732 ptr = str * cr2r - sti * cr2i;
8733 pti = str * cr2i + sti * cr2r;
8734 str = ptr + (air * asumr[j - 1] - aii * asumi[j - 1]);
8735 sti = pti + (air * asumi[j - 1] + aii * asumr[j - 1]);
8736 ptr = str * phir[j - 1] - sti * phii[j - 1];
8737 pti = str * phii[j - 1] + sti * phir[j - 1];
8738 s2r = ptr * csr - pti * csi;
8739 s2i = ptr * csi + pti * csr;
8740 str = exp(s1r) * cssr[kflag - 1];
8741 s1r = str * cos(s1i);
8742 s1i = str * sin(s1i);
8743 str = s2r * s1r - s2i * s1i;
8744 s2i = s1r * s2i + s2r * s1i;
8745 s2r = str;
8746 if (kflag != 1) {
8747 goto L60;
8748 }
8749 zuchk(&s2r, &s2i, &nw, bry, tol);
8750 if (nw != 0) {
8751 goto L70;
8752 }
8753 L60:
8754 if (yy <= 0.) {
8755 s2i = -s2i;
8756 }
8757 cyr[kdflg - 1] = s2r;
8758 cyi[kdflg - 1] = s2i;
8759 yr[i__] = s2r * csrr[kflag - 1];
8760 yi[i__] = s2i * csrr[kflag - 1];
8761 str = csi;
8762 csi = -csr;
8763 csr = str;
8764 if (kdflg == 2) {
8765 goto L85;
8766 }
8767 kdflg = 2;
8768 goto L80;
8769 L70:
8770 if (rs1 > 0.) {
8771 goto L320;
8772 }
8773/* ----------------------------------------------------------------------- */
8774/* FOR ZR.LT.0.0, THE I FUNCTION TO BE ADDED WILL OVERFLOW */
8775/* ----------------------------------------------------------------------- */
8776 if (*zr < 0.) {
8777 goto L320;
8778 }
8779 kdflg = 1;
8780 yr[i__] = zeror;
8781 yi[i__] = zeroi;
8782 ++(*nz);
8783 str = csi;
8784 csi = -csr;
8785 csr = str;
8786 if (i__ == 1) {
8787 goto L80;
8788 }
8789 if (yr[i__ - 1] == zeror && yi[i__ - 1] == zeroi) {
8790 goto L80;
8791 }
8792 yr[i__ - 1] = zeror;
8793 yi[i__ - 1] = zeroi;
8794 ++(*nz);
8795 L80:
8796 ;
8797 }
8798 i__ = *n;
8799 L85:
8800 razr = 1. / azabs(&zrr, &zri);
8801 str = zrr * razr;
8802 sti = -zri * razr;
8803 rzr = (str + str) * razr;
8804 rzi = (sti + sti) * razr;
8805 ckr = fn * rzr;
8806 cki = fn * rzi;
8807 ib = i__ + 1;
8808 if (*n < ib) {
8809 goto L180;
8810 }
8811/* ----------------------------------------------------------------------- */
8812/* TEST LAST MEMBER FOR UNDERFLOW AND OVERFLOW. SET SEQUENCE TO ZERO */
8813/* ON UNDERFLOW. */
8814/* ----------------------------------------------------------------------- */
8815 fn = *fnu + (double) ((float) (*n - 1));
8816 ipard = 1;
8817 if (*mr != 0) {
8818 ipard = 0;
8819 }
8820 zunhj(&znr, &zni, &fn, &ipard, tol, &phidr, &phidi, &argdr, &argdi,
8821 &zet1dr, &zet1di, &zet2dr, &zet2di, &asumdr, &asumdi, &bsumdr,
8822 &bsumdi);
8823 if (*kode == 1) {
8824 goto L90;
8825 }
8826 str = zbr + zet2dr;
8827 sti = zbi + zet2di;
8828 rast = fn / azabs(&str, &sti);
8829 str = str * rast * rast;
8830 sti = -sti * rast * rast;
8831 s1r = zet1dr - str;
8832 s1i = zet1di - sti;
8833 goto L100;
8834 L90:
8835 s1r = zet1dr - zet2dr;
8836 s1i = zet1di - zet2di;
8837 L100:
8838 rs1 = s1r;
8839 if (abs(rs1) > *elim) {
8840 goto L105;
8841 }
8842 if (abs(rs1) < *alim) {
8843 goto L120;
8844 }
8845/* ---------------------------------------------------------------------------- */
8846/* REFINE ESTIMATE AND TEST */
8847/* ------------------------------------------------------------------------- */
8848 aphi = azabs(&phidr, &phidi);
8849 rs1 += log(aphi);
8850 if (abs(rs1) < *elim) {
8851 goto L120;
8852 }
8853 L105:
8854 if (rs1 > 0.) {
8855 goto L320;
8856 }
8857/* ----------------------------------------------------------------------- */
8858/* FOR ZR.LT.0.0, THE I FUNCTION TO BE ADDED WILL OVERFLOW */
8859/* ----------------------------------------------------------------------- */
8860 if (*zr < 0.) {
8861 goto L320;
8862 }
8863 *nz = *n;
8864 i__1 = *n;
8865 for (i__ = 1; i__ <= i__1; ++i__) {
8866 yr[i__] = zeror;
8867 yi[i__] = zeroi;
8868/* L106: */
8869 }
8870 return 0;
8871 L120:
8872 s1r = cyr[0];
8873 s1i = cyi[0];
8874 s2r = cyr[1];
8875 s2i = cyi[1];
8876 c1r = csrr[kflag - 1];
8877 ascle = bry[kflag - 1];
8878 i__1 = *n;
8879 for (i__ = ib; i__ <= i__1; ++i__) {
8880 c2r = s2r;
8881 c2i = s2i;
8882 s2r = ckr * c2r - cki * c2i + s1r;
8883 s2i = ckr * c2i + cki * c2r + s1i;
8884 s1r = c2r;
8885 s1i = c2i;
8886 ckr += rzr;
8887 cki += rzi;
8888 c2r = s2r * c1r;
8889 c2i = s2i * c1r;
8890 yr[i__] = c2r;
8891 yi[i__] = c2i;
8892 if (kflag >= 3) {
8893 goto L130;
8894 }
8895 str = abs(c2r);
8896 sti = abs(c2i);
8897 c2m = max(str, sti);
8898 if (c2m <= ascle) {
8899 goto L130;
8900 }
8901 ++kflag;
8902 ascle = bry[kflag - 1];
8903 s1r *= c1r;
8904 s1i *= c1r;
8905 s2r = c2r;
8906 s2i = c2i;
8907 s1r *= cssr[kflag - 1];
8908 s1i *= cssr[kflag - 1];
8909 s2r *= cssr[kflag - 1];
8910 s2i *= cssr[kflag - 1];
8911 c1r = csrr[kflag - 1];
8912 L130:
8913 ;
8914 }
8915 L180:
8916 if (*mr == 0) {
8917 return 0;
8918 }
8919/* ----------------------------------------------------------------------- */
8920/* ANALYTIC CONTINUATION FOR RE(Z).LT.0.0D0 */
8921/* ----------------------------------------------------------------------- */
8922 *nz = 0;
8923 fmr = (double) ((float) (*mr));
8924 sgn = -d_sign(&pi, &fmr);
8925/* ----------------------------------------------------------------------- */
8926/* CSPN AND CSGN ARE COEFF OF K AND I FUNCIONS RESP. */
8927/* ----------------------------------------------------------------------- */
8928 csgni = sgn;
8929 if (yy <= 0.) {
8930 csgni = -csgni;
8931 }
8932 ifn = inu + *n - 1;
8933 ang = fnf * sgn;
8934 cspnr = cos(ang);
8935 cspni = sin(ang);
8936 if (ifn % 2 == 0) {
8937 goto L190;
8938 }
8939 cspnr = -cspnr;
8940 cspni = -cspni;
8941 L190:
8942/* ----------------------------------------------------------------------- */
8943/* CS=COEFF OF THE J FUNCTION TO GET THE I FUNCTION. I(FNU,Z) IS */
8944/* COMPUTED FROM EXP(I*FNU*HPI)*J(FNU,-I*Z) WHERE Z IS IN THE FIRST */
8945/* QUADRANT. FOURTH QUADRANT VALUES (YY.LE.0.0E0) ARE COMPUTED BY */
8946/* CONJUGATION SINCE THE I FUNCTION IS REAL ON THE POSITIVE REAL AXIS */
8947/* ----------------------------------------------------------------------- */
8948 csr = sar * csgni;
8949 csi = car * csgni;
8950 in = ifn % 4 + 1;
8951 c2r = cipr[in - 1];
8952 c2i = cipi[in - 1];
8953 str = csr * c2r + csi * c2i;
8954 csi = -csr * c2i + csi * c2r;
8955 csr = str;
8956 asc = bry[0];
8957 iuf = 0;
8958 kk = *n;
8959 kdflg = 1;
8960 --ib;
8961 ic = ib - 1;
8962 i__1 = *n;
8963 for (k = 1; k <= i__1; ++k) {
8964 fn = *fnu + (double) ((float) (kk - 1));
8965/* ----------------------------------------------------------------------- */
8966/* LOGIC TO SORT OUT CASES WHOSE PARAMETERS WERE SET FOR THE K */
8967/* FUNCTION ABOVE */
8968/* ----------------------------------------------------------------------- */
8969 if (*n > 2) {
8970 goto L175;
8971 }
8972 L172:
8973 phidr = phir[j - 1];
8974 phidi = phii[j - 1];
8975 argdr = argr[j - 1];
8976 argdi = argi[j - 1];
8977 zet1dr = zeta1r[j - 1];
8978 zet1di = zeta1i[j - 1];
8979 zet2dr = zeta2r[j - 1];
8980 zet2di = zeta2i[j - 1];
8981 asumdr = asumr[j - 1];
8982 asumdi = asumi[j - 1];
8983 bsumdr = bsumr[j - 1];
8984 bsumdi = bsumi[j - 1];
8985 j = 3 - j;
8986 goto L210;
8987 L175:
8988 if (kk == *n && ib < *n) {
8989 goto L210;
8990 }
8991 if (kk == ib || kk == ic) {
8992 goto L172;
8993 }
8994 zunhj(&znr, &zni, &fn, &c__0, tol, &phidr, &phidi, &argdr, &argdi,
8995 &zet1dr, &zet1di, &zet2dr, &zet2di, &asumdr, &asumdi,
8996 &bsumdr, &bsumdi);
8997 L210:
8998 if (*kode == 1) {
8999 goto L220;
9000 }
9001 str = zbr + zet2dr;
9002 sti = zbi + zet2di;
9003 rast = fn / azabs(&str, &sti);
9004 str = str * rast * rast;
9005 sti = -sti * rast * rast;
9006 s1r = -zet1dr + str;
9007 s1i = -zet1di + sti;
9008 goto L230;
9009 L220:
9010 s1r = -zet1dr + zet2dr;
9011 s1i = -zet1di + zet2di;
9012 L230:
9013/* ----------------------------------------------------------------------- */
9014/* TEST FOR UNDERFLOW AND OVERFLOW */
9015/* ----------------------------------------------------------------------- */
9016 rs1 = s1r;
9017 if (abs(rs1) > *elim) {
9018 goto L280;
9019 }
9020 if (kdflg == 1) {
9021 iflag = 2;
9022 }
9023 if (abs(rs1) < *alim) {
9024 goto L240;
9025 }
9026/* ----------------------------------------------------------------------- */
9027/* REFINE TEST AND SCALE */
9028/* ----------------------------------------------------------------------- */
9029 aphi = azabs(&phidr, &phidi);
9030 aarg = azabs(&argdr, &argdi);
9031 rs1 = rs1 + log(aphi) - log(aarg) * .25 - aic;
9032 if (abs(rs1) > *elim) {
9033 goto L280;
9034 }
9035 if (kdflg == 1) {
9036 iflag = 1;
9037 }
9038 if (rs1 < 0.) {
9039 goto L240;
9040 }
9041 if (kdflg == 1) {
9042 iflag = 3;
9043 }
9044 L240:
9045 zairy(&argdr, &argdi, &c__0, &c__2, &air, &aii, &nai, &idum);
9046 zairy(&argdr, &argdi, &c__1, &c__2, &dair, &daii, &ndai, &idum);
9047 str = dair * bsumdr - daii * bsumdi;
9048 sti = dair * bsumdi + daii * bsumdr;
9049 str += air * asumdr - aii * asumdi;
9050 sti += air * asumdi + aii * asumdr;
9051 ptr = str * phidr - sti * phidi;
9052 pti = str * phidi + sti * phidr;
9053 s2r = ptr * csr - pti * csi;
9054 s2i = ptr * csi + pti * csr;
9055 str = exp(s1r) * cssr[iflag - 1];
9056 s1r = str * cos(s1i);
9057 s1i = str * sin(s1i);
9058 str = s2r * s1r - s2i * s1i;
9059 s2i = s2r * s1i + s2i * s1r;
9060 s2r = str;
9061 if (iflag != 1) {
9062 goto L250;
9063 }
9064 zuchk(&s2r, &s2i, &nw, bry, tol);
9065 if (nw == 0) {
9066 goto L250;
9067 }
9068 s2r = zeror;
9069 s2i = zeroi;
9070 L250:
9071 if (yy <= 0.) {
9072 s2i = -s2i;
9073 }
9074 cyr[kdflg - 1] = s2r;
9075 cyi[kdflg - 1] = s2i;
9076 c2r = s2r;
9077 c2i = s2i;
9078 s2r *= csrr[iflag - 1];
9079 s2i *= csrr[iflag - 1];
9080/* ----------------------------------------------------------------------- */
9081/* ADD I AND K FUNCTIONS, K SEQUENCE IN Y(I), I=1,N */
9082/* ----------------------------------------------------------------------- */
9083 s1r = yr[kk];
9084 s1i = yi[kk];
9085 if (*kode == 1) {
9086 goto L270;
9087 }
9088 zs1s2(&zrr, &zri, &s1r, &s1i, &s2r, &s2i, &nw, &asc, alim, &iuf);
9089 *nz += nw;
9090 L270:
9091 yr[kk] = s1r * cspnr - s1i * cspni + s2r;
9092 yi[kk] = s1r * cspni + s1i * cspnr + s2i;
9093 --kk;
9094 cspnr = -cspnr;
9095 cspni = -cspni;
9096 str = csi;
9097 csi = -csr;
9098 csr = str;
9099 if (c2r != 0. || c2i != 0.) {
9100 goto L255;
9101 }
9102 kdflg = 1;
9103 goto L290;
9104 L255:
9105 if (kdflg == 2) {
9106 goto L295;
9107 }
9108 kdflg = 2;
9109 goto L290;
9110 L280:
9111 if (rs1 > 0.) {
9112 goto L320;
9113 }
9114 s2r = zeror;
9115 s2i = zeroi;
9116 goto L250;
9117 L290:
9118 ;
9119 }
9120 k = *n;
9121 L295:
9122 il = *n - k;
9123 if (il == 0) {
9124 return 0;
9125 }
9126/* ----------------------------------------------------------------------- */
9127/* RECUR BACKWARD FOR REMAINDER OF I SEQUENCE AND ADD IN THE */
9128/* K FUNCTIONS, SCALING THE I SEQUENCE DURING RECURRENCE TO KEEP */
9129/* INTERMEDIATE ARITHMETIC ON SCALE NEAR EXPONENT EXTREMES. */
9130/* ----------------------------------------------------------------------- */
9131 s1r = cyr[0];
9132 s1i = cyi[0];
9133 s2r = cyr[1];
9134 s2i = cyi[1];
9135 csr = csrr[iflag - 1];
9136 ascle = bry[iflag - 1];
9137 fn = (double) ((float) (inu + il));
9138 i__1 = il;
9139 for (i__ = 1; i__ <= i__1; ++i__) {
9140 c2r = s2r;
9141 c2i = s2i;
9142 s2r = s1r + (fn + fnf) * (rzr * c2r - rzi * c2i);
9143 s2i = s1i + (fn + fnf) * (rzr * c2i + rzi * c2r);
9144 s1r = c2r;
9145 s1i = c2i;
9146 fn += -1.;
9147 c2r = s2r * csr;
9148 c2i = s2i * csr;
9149 ckr = c2r;
9150 cki = c2i;
9151 c1r = yr[kk];
9152 c1i = yi[kk];
9153 if (*kode == 1) {
9154 goto L300;
9155 }
9156 zs1s2(&zrr, &zri, &c1r, &c1i, &c2r, &c2i, &nw, &asc, alim, &iuf);
9157 *nz += nw;
9158 L300:
9159 yr[kk] = c1r * cspnr - c1i * cspni + c2r;
9160 yi[kk] = c1r * cspni + c1i * cspnr + c2i;
9161 --kk;
9162 cspnr = -cspnr;
9163 cspni = -cspni;
9164 if (iflag >= 3) {
9165 goto L310;
9166 }
9167 c2r = abs(ckr);
9168 c2i = abs(cki);
9169 c2m = max(c2r, c2i);
9170 if (c2m <= ascle) {
9171 goto L310;
9172 }
9173 ++iflag;
9174 ascle = bry[iflag - 1];
9175 s1r *= csr;
9176 s1i *= csr;
9177 s2r = ckr;
9178 s2i = cki;
9179 s1r *= cssr[iflag - 1];
9180 s1i *= cssr[iflag - 1];
9181 s2r *= cssr[iflag - 1];
9182 s2i *= cssr[iflag - 1];
9183 csr = csrr[iflag - 1];
9184 L310:
9185 ;
9186 }
9187 return 0;
9188 L320:
9189 *nz = -1;
9190 return 0;
9191} /* zunk2_ */
9192
9193/* Subroutine */ int zuoik(double *zr, double *zi, double *fnu,
9194 long *kode, long *ikflg, long *n, double *yr, double
9195 *yi, long *nuf, double *tol, double *elim,
9196 double *alim)
9197{
9198 /* Initialized data */
9199
9200 double zeror = 0.;
9201 double zeroi = 0.;
9202 double aic = 1.265512123484645396;
9203
9204 /* System generated locals */
9205 long i__1;
9206
9207 /* Builtin functions */
9208 double log(double), exp(double), cos(double), sin(double);
9209
9210 /* Local variables */
9211 long i__;
9212 double ax, ay;
9213 long nn, nw;
9214 double fnn, gnn, zbi, czi, gnu, zbr, czr, rcz, sti, zni, zri,
9215 str, znr, zrr, aarg, aphi, argi, phii, argr;
9216 long idum;
9217 double phir;
9218 long init;
9219 double sumi, sumr, ascle;
9220 extern double azabs(double *, double *);
9221 long iform;
9222 extern /* Subroutine */ int azlog(double *, double *, double
9223 *, double *, long *);
9224 double asumi, bsumi, cwrki[16];
9225 extern /* Subroutine */ int zuchk(double *, double *, long *,
9226 double *, double *);
9227 double asumr, bsumr, cwrkr[16];
9228 extern double d1mach(long *);
9229 extern /* Subroutine */ int zunhj(double *, double *, double
9230 *, long *, double *, double *,
9231 double *, double *, double *,
9232 double *, double *, double *,
9233 double *, double *, double *,
9234 double *, double *), zunik(double *,
9235 double *,
9236 double *,
9237 long *,
9238 long *,
9239 double *,
9240 long *,
9241 double *,
9242 double *,
9243 double *,
9244 double *,
9245 double *,
9246 double *,
9247 double *,
9248 double *,
9249 double *,
9250 double *);
9251 double zeta1i, zeta2i, zeta1r, zeta2r;
9252
9253/* ***BEGIN PROLOGUE ZUOIK */
9254/* ***REFER TO ZBESI,ZBESK,ZBESH */
9255
9256/* ZUOIK COMPUTES THE LEADING TERMS OF THE UNIFORM ASYMPTOTIC */
9257/* EXPANSIONS FOR THE I AND K FUNCTIONS AND COMPARES THEM */
9258/* (IN LOGARITHMIC FORM) TO ALIM AND ELIM FOR OVER AND UNDERFLOW */
9259/* WHERE ALIM.LT.ELIM. IF THE MAGNITUDE, BASED ON THE LEADING */
9260/* EXPONENTIAL, IS LESS THAN ALIM OR GREATER THAN -ALIM, THEN */
9261/* THE RESULT IS ON SCALE. IF NOT, THEN A REFINED TEST USING OTHER */
9262/* MULTIPLIERS (IN LOGARITHMIC FORM) IS MADE BASED ON ELIM. HERE */
9263/* EXP(-ELIM)=SMALLEST MACHINE NUMBER*1.0E+3 AND EXP(-ALIM)= */
9264/* EXP(-ELIM)/TOL */
9265
9266/* IKFLG=1 MEANS THE I SEQUENCE IS TESTED */
9267/* =2 MEANS THE K SEQUENCE IS TESTED */
9268/* NUF = 0 MEANS THE LAST MEMBER OF THE SEQUENCE IS ON SCALE */
9269/* =-1 MEANS AN OVERFLOW WOULD OCCUR */
9270/* IKFLG=1 AND NUF.GT.0 MEANS THE LAST NUF Y VALUES WERE SET TO ZERO */
9271/* THE FIRST N-NUF VALUES MUST BE SET BY ANOTHER ROUTINE */
9272/* IKFLG=2 AND NUF.EQ.N MEANS ALL Y VALUES WERE SET TO ZERO */
9273/* IKFLG=2 AND 0.LT.NUF.LT.N NOT CONSIDERED. Y MUST BE SET BY */
9274/* ANOTHER ROUTINE */
9275
9276/* ***ROUTINES CALLED ZUCHK,ZUNHJ,ZUNIK,D1MACH,AZABS,AZLOG */
9277/* ***END PROLOGUE ZUOIK */
9278/* COMPLEX ARG,ASUM,BSUM,CWRK,CZ,CZERO,PHI,SUM,Y,Z,ZB,ZETA1,ZETA2,ZN, */
9279/* *ZR */
9280 /* Parameter adjustments */
9281 --yi;
9282 --yr;
9283
9284 /* Function Body */
9285 *nuf = 0;
9286 nn = *n;
9287 zrr = *zr;
9288 zri = *zi;
9289 if (*zr >= 0.) {
9290 goto L10;
9291 }
9292 zrr = -(*zr);
9293 zri = -(*zi);
9294 L10:
9295 zbr = zrr;
9296 zbi = zri;
9297 ax = abs(*zr) * 1.7321;
9298 ay = abs(*zi);
9299 iform = 1;
9300 if (ay > ax) {
9301 iform = 2;
9302 }
9303 gnu = max(*fnu, 1.);
9304 if (*ikflg == 1) {
9305 goto L20;
9306 }
9307 fnn = (double) ((float) nn);
9308 gnn = *fnu + fnn - 1.;
9309 gnu = max(gnn, fnn);
9310 L20:
9311/* ----------------------------------------------------------------------- */
9312/* ONLY THE MAGNITUDE OF ARG AND PHI ARE NEEDED ALONG WITH THE */
9313/* REAL PARTS OF ZETA1, ZETA2 AND ZB. NO ATTEMPT IS MADE TO GET */
9314/* THE SIGN OF THE IMAGINARY PART CORRECT. */
9315/* ----------------------------------------------------------------------- */
9316 if (iform == 2) {
9317 goto L30;
9318 }
9319 init = 0;
9320 zunik(&zrr, &zri, &gnu, ikflg, &c__1, tol, &init, &phir, &phii,
9321 &zeta1r, &zeta1i, &zeta2r, &zeta2i, &sumr, &sumi, cwrkr, cwrki);
9322 czr = -zeta1r + zeta2r;
9323 czi = -zeta1i + zeta2i;
9324 goto L50;
9325 L30:
9326 znr = zri;
9327 zni = -zrr;
9328 if (*zi > 0.) {
9329 goto L40;
9330 }
9331 znr = -znr;
9332 L40:
9333 zunhj(&znr, &zni, &gnu, &c__1, tol, &phir, &phii, &argr, &argi,
9334 &zeta1r, &zeta1i, &zeta2r, &zeta2i, &asumr, &asumi, &bsumr,
9335 &bsumi);
9336 czr = -zeta1r + zeta2r;
9337 czi = -zeta1i + zeta2i;
9338 aarg = azabs(&argr, &argi);
9339 L50:
9340 if (*kode == 1) {
9341 goto L60;
9342 }
9343 czr -= zbr;
9344 czi -= zbi;
9345 L60:
9346 if (*ikflg == 1) {
9347 goto L70;
9348 }
9349 czr = -czr;
9350 czi = -czi;
9351 L70:
9352 aphi = azabs(&phir, &phii);
9353 rcz = czr;
9354/* ----------------------------------------------------------------------- */
9355/* OVERFLOW TEST */
9356/* ----------------------------------------------------------------------- */
9357 if (rcz > *elim) {
9358 goto L210;
9359 }
9360 if (rcz < *alim) {
9361 goto L80;
9362 }
9363 rcz += log(aphi);
9364 if (iform == 2) {
9365 rcz = rcz - log(aarg) * .25 - aic;
9366 }
9367 if (rcz > *elim) {
9368 goto L210;
9369 }
9370 goto L130;
9371 L80:
9372/* ----------------------------------------------------------------------- */
9373/* UNDERFLOW TEST */
9374/* ----------------------------------------------------------------------- */
9375 if (rcz < -(*elim)) {
9376 goto L90;
9377 }
9378 if (rcz > -(*alim)) {
9379 goto L130;
9380 }
9381 rcz += log(aphi);
9382 if (iform == 2) {
9383 rcz = rcz - log(aarg) * .25 - aic;
9384 }
9385 if (rcz > -(*elim)) {
9386 goto L110;
9387 }
9388 L90:
9389 i__1 = nn;
9390 for (i__ = 1; i__ <= i__1; ++i__) {
9391 yr[i__] = zeror;
9392 yi[i__] = zeroi;
9393/* L100: */
9394 }
9395 *nuf = nn;
9396 return 0;
9397 L110:
9398 ascle = d1mach(&c__1) * 1e3 / *tol;
9399 azlog(&phir, &phii, &str, &sti, &idum);
9400 czr += str;
9401 czi += sti;
9402 if (iform == 1) {
9403 goto L120;
9404 }
9405 azlog(&argr, &argi, &str, &sti, &idum);
9406 czr = czr - str * .25 - aic;
9407 czi -= sti * .25;
9408 L120:
9409 ax = exp(rcz) / *tol;
9410 ay = czi;
9411 czr = ax * cos(ay);
9412 czi = ax * sin(ay);
9413 zuchk(&czr, &czi, &nw, &ascle, tol);
9414 if (nw != 0) {
9415 goto L90;
9416 }
9417 L130:
9418 if (*ikflg == 2) {
9419 return 0;
9420 }
9421 if (*n == 1) {
9422 return 0;
9423 }
9424/* ----------------------------------------------------------------------- */
9425/* SET UNDERFLOWS ON I SEQUENCE */
9426/* ----------------------------------------------------------------------- */
9427 L140:
9428 gnu = *fnu + (double) ((float) (nn - 1));
9429 if (iform == 2) {
9430 goto L150;
9431 }
9432 init = 0;
9433 zunik(&zrr, &zri, &gnu, ikflg, &c__1, tol, &init, &phir, &phii,
9434 &zeta1r, &zeta1i, &zeta2r, &zeta2i, &sumr, &sumi, cwrkr, cwrki);
9435 czr = -zeta1r + zeta2r;
9436 czi = -zeta1i + zeta2i;
9437 goto L160;
9438 L150:
9439 zunhj(&znr, &zni, &gnu, &c__1, tol, &phir, &phii, &argr, &argi,
9440 &zeta1r, &zeta1i, &zeta2r, &zeta2i, &asumr, &asumi, &bsumr,
9441 &bsumi);
9442 czr = -zeta1r + zeta2r;
9443 czi = -zeta1i + zeta2i;
9444 aarg = azabs(&argr, &argi);
9445 L160:
9446 if (*kode == 1) {
9447 goto L170;
9448 }
9449 czr -= zbr;
9450 czi -= zbi;
9451 L170:
9452 aphi = azabs(&phir, &phii);
9453 rcz = czr;
9454 if (rcz < -(*elim)) {
9455 goto L180;
9456 }
9457 if (rcz > -(*alim)) {
9458 return 0;
9459 }
9460 rcz += log(aphi);
9461 if (iform == 2) {
9462 rcz = rcz - log(aarg) * .25 - aic;
9463 }
9464 if (rcz > -(*elim)) {
9465 goto L190;
9466 }
9467 L180:
9468 yr[nn] = zeror;
9469 yi[nn] = zeroi;
9470 --nn;
9471 ++(*nuf);
9472 if (nn == 0) {
9473 return 0;
9474 }
9475 goto L140;
9476 L190:
9477 ascle = d1mach(&c__1) * 1e3 / *tol;
9478 azlog(&phir, &phii, &str, &sti, &idum);
9479 czr += str;
9480 czi += sti;
9481 if (iform == 1) {
9482 goto L200;
9483 }
9484 azlog(&argr, &argi, &str, &sti, &idum);
9485 czr = czr - str * .25 - aic;
9486 czi -= sti * .25;
9487 L200:
9488 ax = exp(rcz) / *tol;
9489 ay = czi;
9490 czr = ax * cos(ay);
9491 czi = ax * sin(ay);
9492 zuchk(&czr, &czi, &nw, &ascle, tol);
9493 if (nw != 0) {
9494 goto L180;
9495 }
9496 return 0;
9497 L210:
9498 *nuf = -1;
9499 return 0;
9500} /* zuoik_ */
9501
9502/* Subroutine */ int zwrsk(double *zrr, double *zri, double *fnu,
9503 long *kode, long *n, double *yr, double *yi,
9504 long *nz, double *cwr, double *cwi, double *tol,
9505 double *elim, double *alim)
9506{
9507 /* System generated locals */
9508 long i__1;
9509
9510 /* Builtin functions */
9511 double cos(double), sin(double);
9512
9513 /* Local variables */
9514 long i__, nw;
9515 double c1i, c2i, c1r, c2r, act, acw, cti, ctr, pti, sti, ptr,
9516 str, ract, ascle;
9517 extern double azabs(double *, double *);
9518 double csclr, cinui, cinur;
9519 extern /* Subroutine */ int zbknu(double *, double *, double
9520 *, long *, long *, double *,
9521 double *, long *, double *, double *,
9522 double *), zrati(double *, double *,
9523 double *, long *,
9524 double *, double *,
9525 double *);
9526 extern double d1mach(long *);
9527
9528/* ***BEGIN PROLOGUE ZWRSK */
9529/* ***REFER TO ZBESI,ZBESK */
9530
9531/* ZWRSK COMPUTES THE I BESSEL FUNCTION FOR RE(Z).GE.0.0 BY */
9532/* NORMALIZING THE I FUNCTION RATIOS FROM ZRATI BY THE WRONSKIAN */
9533
9534/* ***ROUTINES CALLED D1MACH,ZBKNU,ZRATI,AZABS */
9535/* ***END PROLOGUE ZWRSK */
9536/* COMPLEX CINU,CSCL,CT,CW,C1,C2,RCT,ST,Y,ZR */
9537/* ----------------------------------------------------------------------- */
9538/* I(FNU+I-1,Z) BY BACKWARD RECURRENCE FOR RATIOS */
9539/* Y(I)=I(FNU+I,Z)/I(FNU+I-1,Z) FROM CRATI NORMALIZED BY THE */
9540/* WRONSKIAN WITH K(FNU,Z) AND K(FNU+1,Z) FROM CBKNU. */
9541/* ----------------------------------------------------------------------- */
9542 /* Parameter adjustments */
9543 --yi;
9544 --yr;
9545 --cwr;
9546 --cwi;
9547
9548 /* Function Body */
9549 *nz = 0;
9550 zbknu(zrr, zri, fnu, kode, &c__2, &cwr[1], &cwi[1], &nw, tol, elim,
9551 alim);
9552 if (nw != 0) {
9553 goto L50;
9554 }
9555 zrati(zrr, zri, fnu, n, &yr[1], &yi[1], tol);
9556/* ----------------------------------------------------------------------- */
9557/* RECUR FORWARD ON I(FNU+1,Z) = R(FNU,Z)*I(FNU,Z), */
9558/* R(FNU+J-1,Z)=Y(J), J=1,...,N */
9559/* ----------------------------------------------------------------------- */
9560 cinur = 1.;
9561 cinui = 0.;
9562 if (*kode == 1) {
9563 goto L10;
9564 }
9565 cinur = cos(*zri);
9566 cinui = sin(*zri);
9567 L10:
9568/* ----------------------------------------------------------------------- */
9569/* ON LOW EXPONENT MACHINES THE K FUNCTIONS CAN BE CLOSE TO BOTH */
9570/* THE UNDER AND OVERFLOW LIMITS AND THE NORMALIZATION MUST BE */
9571/* SCALED TO PREVENT OVER OR UNDERFLOW. CUOIK HAS DETERMINED THAT */
9572/* THE RESULT IS ON SCALE. */
9573/* ----------------------------------------------------------------------- */
9574 acw = azabs(&cwr[2], &cwi[2]);
9575 ascle = d1mach(&c__1) * 1e3 / *tol;
9576 csclr = 1.;
9577 if (acw > ascle) {
9578 goto L20;
9579 }
9580 csclr = 1. / *tol;
9581 goto L30;
9582 L20:
9583 ascle = 1. / ascle;
9584 if (acw < ascle) {
9585 goto L30;
9586 }
9587 csclr = *tol;
9588 L30:
9589 c1r = cwr[1] * csclr;
9590 c1i = cwi[1] * csclr;
9591 c2r = cwr[2] * csclr;
9592 c2i = cwi[2] * csclr;
9593 str = yr[1];
9594 sti = yi[1];
9595/* ----------------------------------------------------------------------- */
9596/* CINU=CINU*(CONJG(CT)/CABS(CT))*(1.0D0/CABS(CT) PREVENTS */
9597/* UNDER- OR OVERFLOW PREMATURELY BY SQUARING CABS(CT) */
9598/* ----------------------------------------------------------------------- */
9599 ptr = str * c1r - sti * c1i;
9600 pti = str * c1i + sti * c1r;
9601 ptr += c2r;
9602 pti += c2i;
9603 ctr = *zrr * ptr - *zri * pti;
9604 cti = *zrr * pti + *zri * ptr;
9605 act = azabs(&ctr, &cti);
9606 ract = 1. / act;
9607 ctr *= ract;
9608 cti = -cti * ract;
9609 ptr = cinur * ract;
9610 pti = cinui * ract;
9611 cinur = ptr * ctr - pti * cti;
9612 cinui = ptr * cti + pti * ctr;
9613 yr[1] = cinur * csclr;
9614 yi[1] = cinui * csclr;
9615 if (*n == 1) {
9616 return 0;
9617 }
9618 i__1 = *n;
9619 for (i__ = 2; i__ <= i__1; ++i__) {
9620 ptr = str * cinur - sti * cinui;
9621 cinui = str * cinui + sti * cinur;
9622 cinur = ptr;
9623 str = yr[i__];
9624 sti = yi[i__];
9625 yr[i__] = cinur * csclr;
9626 yi[i__] = cinui * csclr;
9627/* L40: */
9628 }
9629 return 0;
9630 L50:
9631 *nz = -1;
9632 if (nw == -2) {
9633 *nz = -2;
9634 }
9635 return 0;
9636} /* zwrsk_ */