zunk1.cpp 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593
  1. /* zunk1.f -- translated by f2c (version 20100827).
  2. This file no longer depends on f2c.
  3. */
  4. #include "slatec-internal.hpp"
  5. /* Table of constant values */
  6. static integer const c__1 = 1;
  7. static integer const c__2 = 2;
  8. static integer const c__0 = 0;
  9. int zunk1_(double *zr, double *zi, double const *fnu,
  10. integer const *kode, integer *mr, integer const *n, double *yr, double *
  11. yi, integer *nz, double *tol, double *elim, double *alim)
  12. {
  13. /* Initialized data */
  14. static double const zeror = 0.;
  15. static double const zeroi = 0.;
  16. static double const coner = 1.;
  17. static double const pi = 3.14159265358979324;
  18. /* System generated locals */
  19. integer i__1;
  20. /* Local variables */
  21. integer i__, j, k, m, ib, ic;
  22. double fn;
  23. integer il, kk, nw;
  24. double c1i, c2i, c2m, c1r, c2r, s1i, s2i, rs1, s1r, s2r, ang, asc,
  25. cki, fnf;
  26. integer ifn;
  27. double ckr;
  28. integer iuf;
  29. double cyi[2], fmr, csr, sgn;
  30. integer inu;
  31. double bry[3], cyr[2], sti, rzi, zri, str, rzr, zrr, aphi, cscl, phii[
  32. 2], crsc;
  33. double phir[2];
  34. integer init[2];
  35. double csrr[3], cssr[3], rast, sumi[2], razr;
  36. double sumr[2];
  37. integer iflag = 0, kflag = 0;
  38. double ascle;
  39. integer kdflg;
  40. double phidi;
  41. integer ipard;
  42. double csgni, phidr;
  43. integer initd;
  44. double cspni, cwrki[48] /* was [16][3] */, sumdi;
  45. double cspnr, cwrkr[48] /* was [16][3] */, sumdr;
  46. double zeta1i[2], zeta2i[2], zet1di, zet2di, zeta1r[2], zeta2r[2],
  47. zet1dr, zet2dr;
  48. /* ***BEGIN PROLOGUE ZUNK1 */
  49. /* ***SUBSIDIARY */
  50. /* ***PURPOSE Subsidiary to ZBESK */
  51. /* ***LIBRARY SLATEC */
  52. /* ***TYPE ALL (CUNK1-A, ZUNK1-A) */
  53. /* ***AUTHOR Amos, D. E., (SNL) */
  54. /* ***DESCRIPTION */
  55. /* ZUNK1 COMPUTES K(FNU,Z) AND ITS ANALYTIC CONTINUATION FROM THE */
  56. /* RIGHT HALF PLANE TO THE LEFT HALF PLANE BY MEANS OF THE */
  57. /* UNIFORM ASYMPTOTIC EXPANSION. */
  58. /* MR INDICATES THE DIRECTION OF ROTATION FOR ANALYTIC CONTINUATION. */
  59. /* NZ=-1 MEANS AN OVERFLOW WILL OCCUR */
  60. /* ***SEE ALSO ZBESK */
  61. /* ***ROUTINES CALLED D1MACH, ZABS, ZS1S2, ZUCHK, ZUNIK */
  62. /* ***REVISION HISTORY (YYMMDD) */
  63. /* 830501 DATE WRITTEN */
  64. /* 910415 Prologue converted to Version 4.0 format. (BAB) */
  65. /* ***END PROLOGUE ZUNK1 */
  66. /* COMPLEX CFN,CK,CONE,CRSC,CS,CSCL,CSGN,CSPN,CSR,CSS,CWRK,CY,CZERO, */
  67. /* *C1,C2,PHI,PHID,RZ,SUM,SUMD,S1,S2,Y,Z,ZETA1,ZETA1D,ZETA2,ZETA2D,ZR */
  68. /* Parameter adjustments */
  69. --yi;
  70. --yr;
  71. /* Function Body */
  72. /* ***FIRST EXECUTABLE STATEMENT ZUNK1 */
  73. kdflg = 1;
  74. *nz = 0;
  75. /* ----------------------------------------------------------------------- */
  76. /* EXP(-ALIM)=EXP(-ELIM)/TOL=APPROX. ONE PRECISION GREATER THAN */
  77. /* THE UNDERFLOW LIMIT */
  78. /* ----------------------------------------------------------------------- */
  79. cscl = 1. / *tol;
  80. crsc = *tol;
  81. cssr[0] = cscl;
  82. cssr[1] = coner;
  83. cssr[2] = crsc;
  84. csrr[0] = crsc;
  85. csrr[1] = coner;
  86. csrr[2] = cscl;
  87. bry[0] = d1mach_(1) * 1e3 / *tol;
  88. bry[1] = 1. / bry[0];
  89. bry[2] = d1mach_(2);
  90. zrr = *zr;
  91. zri = *zi;
  92. if (*zr >= 0.) {
  93. goto L10;
  94. }
  95. zrr = -(*zr);
  96. zri = -(*zi);
  97. L10:
  98. j = 2;
  99. i__1 = *n;
  100. for (i__ = 1; i__ <= i__1; ++i__) {
  101. /* ----------------------------------------------------------------------- */
  102. /* J FLIP FLOPS BETWEEN 1 AND 2 IN J = 3 - J */
  103. /* ----------------------------------------------------------------------- */
  104. j = 3 - j;
  105. fn = *fnu + (i__ - 1);
  106. init[j - 1] = 0;
  107. zunik_(&zrr, &zri, &fn, &c__2, &c__0, tol, &init[j - 1], &phir[j - 1],
  108. &phii[j - 1], &zeta1r[j - 1], &zeta1i[j - 1], &zeta2r[j - 1],
  109. &zeta2i[j - 1], &sumr[j - 1], &sumi[j - 1], &cwrkr[(j << 4)
  110. - 16], &cwrki[(j << 4) - 16]);
  111. if (*kode == 1) {
  112. goto L20;
  113. }
  114. str = zrr + zeta2r[j - 1];
  115. sti = zri + zeta2i[j - 1];
  116. rast = fn / zabs_(&str, &sti);
  117. str = str * rast * rast;
  118. sti = -sti * rast * rast;
  119. s1r = zeta1r[j - 1] - str;
  120. s1i = zeta1i[j - 1] - sti;
  121. goto L30;
  122. L20:
  123. s1r = zeta1r[j - 1] - zeta2r[j - 1];
  124. s1i = zeta1i[j - 1] - zeta2i[j - 1];
  125. L30:
  126. rs1 = s1r;
  127. /* ----------------------------------------------------------------------- */
  128. /* TEST FOR UNDERFLOW AND OVERFLOW */
  129. /* ----------------------------------------------------------------------- */
  130. if (abs(rs1) > *elim) {
  131. goto L60;
  132. }
  133. if (kdflg == 1) {
  134. kflag = 2;
  135. }
  136. if (abs(rs1) < *alim) {
  137. goto L40;
  138. }
  139. /* ----------------------------------------------------------------------- */
  140. /* REFINE TEST AND SCALE */
  141. /* ----------------------------------------------------------------------- */
  142. aphi = zabs_(&phir[j - 1], &phii[j - 1]);
  143. rs1 += log(aphi);
  144. if (abs(rs1) > *elim) {
  145. goto L60;
  146. }
  147. if (kdflg == 1) {
  148. kflag = 1;
  149. }
  150. if (rs1 < 0.) {
  151. goto L40;
  152. }
  153. if (kdflg == 1) {
  154. kflag = 3;
  155. }
  156. L40:
  157. /* ----------------------------------------------------------------------- */
  158. /* SCALE S1 TO KEEP INTERMEDIATE ARITHMETIC ON SCALE NEAR */
  159. /* EXPONENT EXTREMES */
  160. /* ----------------------------------------------------------------------- */
  161. s2r = phir[j - 1] * sumr[j - 1] - phii[j - 1] * sumi[j - 1];
  162. s2i = phir[j - 1] * sumi[j - 1] + phii[j - 1] * sumr[j - 1];
  163. str = exp(s1r) * cssr[kflag - 1];
  164. s1r = str * cos(s1i);
  165. s1i = str * sin(s1i);
  166. str = s2r * s1r - s2i * s1i;
  167. s2i = s1r * s2i + s2r * s1i;
  168. s2r = str;
  169. if (kflag != 1) {
  170. goto L50;
  171. }
  172. zuchk_(&s2r, &s2i, &nw, bry, tol);
  173. if (nw != 0) {
  174. goto L60;
  175. }
  176. L50:
  177. cyr[kdflg - 1] = s2r;
  178. cyi[kdflg - 1] = s2i;
  179. yr[i__] = s2r * csrr[kflag - 1];
  180. yi[i__] = s2i * csrr[kflag - 1];
  181. if (kdflg == 2) {
  182. goto L75;
  183. }
  184. kdflg = 2;
  185. goto L70;
  186. L60:
  187. if (rs1 > 0.) {
  188. goto L300;
  189. }
  190. /* ----------------------------------------------------------------------- */
  191. /* FOR ZR.LT.0.0, THE I FUNCTION TO BE ADDED WILL OVERFLOW */
  192. /* ----------------------------------------------------------------------- */
  193. if (*zr < 0.) {
  194. goto L300;
  195. }
  196. kdflg = 1;
  197. yr[i__] = zeror;
  198. yi[i__] = zeroi;
  199. ++(*nz);
  200. if (i__ == 1) {
  201. goto L70;
  202. }
  203. if (yr[i__ - 1] == zeror && yi[i__ - 1] == zeroi) {
  204. goto L70;
  205. }
  206. yr[i__ - 1] = zeror;
  207. yi[i__ - 1] = zeroi;
  208. ++(*nz);
  209. L70:
  210. ;
  211. }
  212. i__ = *n;
  213. L75:
  214. razr = 1. / zabs_(&zrr, &zri);
  215. str = zrr * razr;
  216. sti = -zri * razr;
  217. rzr = (str + str) * razr;
  218. rzi = (sti + sti) * razr;
  219. ckr = fn * rzr;
  220. cki = fn * rzi;
  221. ib = i__ + 1;
  222. if (*n < ib) {
  223. goto L160;
  224. }
  225. /* ----------------------------------------------------------------------- */
  226. /* TEST LAST MEMBER FOR UNDERFLOW AND OVERFLOW. SET SEQUENCE TO ZERO */
  227. /* ON UNDERFLOW. */
  228. /* ----------------------------------------------------------------------- */
  229. fn = *fnu + (*n - 1);
  230. ipard = 1;
  231. if (*mr != 0) {
  232. ipard = 0;
  233. }
  234. initd = 0;
  235. zunik_(&zrr, &zri, &fn, &c__2, &ipard, tol, &initd, &phidr, &phidi, &
  236. zet1dr, &zet1di, &zet2dr, &zet2di, &sumdr, &sumdi, &cwrkr[32], &
  237. cwrki[32]);
  238. if (*kode == 1) {
  239. goto L80;
  240. }
  241. str = zrr + zet2dr;
  242. sti = zri + zet2di;
  243. rast = fn / zabs_(&str, &sti);
  244. str = str * rast * rast;
  245. sti = -sti * rast * rast;
  246. s1r = zet1dr - str;
  247. s1i = zet1di - sti;
  248. goto L90;
  249. L80:
  250. s1r = zet1dr - zet2dr;
  251. s1i = zet1di - zet2di;
  252. L90:
  253. rs1 = s1r;
  254. if (abs(rs1) > *elim) {
  255. goto L95;
  256. }
  257. if (abs(rs1) < *alim) {
  258. goto L100;
  259. }
  260. /* ----------------------------------------------------------------------- */
  261. /* REFINE ESTIMATE AND TEST */
  262. /* ----------------------------------------------------------------------- */
  263. aphi = zabs_(&phidr, &phidi);
  264. rs1 += log(aphi);
  265. if (abs(rs1) < *elim) {
  266. goto L100;
  267. }
  268. L95:
  269. if (abs(rs1) > 0.) {
  270. goto L300;
  271. }
  272. /* ----------------------------------------------------------------------- */
  273. /* FOR ZR.LT.0.0, THE I FUNCTION TO BE ADDED WILL OVERFLOW */
  274. /* ----------------------------------------------------------------------- */
  275. if (*zr < 0.) {
  276. goto L300;
  277. }
  278. *nz = *n;
  279. i__1 = *n;
  280. for (i__ = 1; i__ <= i__1; ++i__) {
  281. yr[i__] = zeror;
  282. yi[i__] = zeroi;
  283. /* L96: */
  284. }
  285. return 0;
  286. /* ----------------------------------------------------------------------- */
  287. /* FORWARD RECUR FOR REMAINDER OF THE SEQUENCE */
  288. /* ----------------------------------------------------------------------- */
  289. L100:
  290. s1r = cyr[0];
  291. s1i = cyi[0];
  292. s2r = cyr[1];
  293. s2i = cyi[1];
  294. c1r = csrr[kflag - 1];
  295. ascle = bry[kflag - 1];
  296. i__1 = *n;
  297. for (i__ = ib; i__ <= i__1; ++i__) {
  298. c2r = s2r;
  299. c2i = s2i;
  300. s2r = ckr * c2r - cki * c2i + s1r;
  301. s2i = ckr * c2i + cki * c2r + s1i;
  302. s1r = c2r;
  303. s1i = c2i;
  304. ckr += rzr;
  305. cki += rzi;
  306. c2r = s2r * c1r;
  307. c2i = s2i * c1r;
  308. yr[i__] = c2r;
  309. yi[i__] = c2i;
  310. if (kflag >= 3) {
  311. goto L120;
  312. }
  313. str = abs(c2r);
  314. sti = abs(c2i);
  315. c2m = max(str,sti);
  316. if (c2m <= ascle) {
  317. goto L120;
  318. }
  319. ++kflag;
  320. ascle = bry[kflag - 1];
  321. s1r *= c1r;
  322. s1i *= c1r;
  323. s2r = c2r;
  324. s2i = c2i;
  325. s1r *= cssr[kflag - 1];
  326. s1i *= cssr[kflag - 1];
  327. s2r *= cssr[kflag - 1];
  328. s2i *= cssr[kflag - 1];
  329. c1r = csrr[kflag - 1];
  330. L120:
  331. ;
  332. }
  333. L160:
  334. if (*mr == 0) {
  335. return 0;
  336. }
  337. /* ----------------------------------------------------------------------- */
  338. /* ANALYTIC CONTINUATION FOR RE(Z).LT.0.0D0 */
  339. /* ----------------------------------------------------------------------- */
  340. *nz = 0;
  341. fmr = (double) (*mr);
  342. sgn = -f2c::d_sign(&pi, &fmr);
  343. /* ----------------------------------------------------------------------- */
  344. /* CSPN AND CSGN ARE COEFF OF K AND I FUNCTIONS RESP. */
  345. /* ----------------------------------------------------------------------- */
  346. csgni = sgn;
  347. inu = (integer) (*fnu);
  348. fnf = *fnu - inu;
  349. ifn = inu + *n - 1;
  350. ang = fnf * sgn;
  351. cspnr = cos(ang);
  352. cspni = sin(ang);
  353. if (ifn % 2 == 0) {
  354. goto L170;
  355. }
  356. cspnr = -cspnr;
  357. cspni = -cspni;
  358. L170:
  359. asc = bry[0];
  360. iuf = 0;
  361. kk = *n;
  362. kdflg = 1;
  363. --ib;
  364. ic = ib - 1;
  365. i__1 = *n;
  366. for (k = 1; k <= i__1; ++k) {
  367. fn = *fnu + (kk - 1);
  368. /* ----------------------------------------------------------------------- */
  369. /* LOGIC TO SORT OUT CASES WHOSE PARAMETERS WERE SET FOR THE K */
  370. /* FUNCTION ABOVE */
  371. /* ----------------------------------------------------------------------- */
  372. m = 3;
  373. if (*n > 2) {
  374. goto L175;
  375. }
  376. L172:
  377. initd = init[j - 1];
  378. phidr = phir[j - 1];
  379. phidi = phii[j - 1];
  380. zet1dr = zeta1r[j - 1];
  381. zet1di = zeta1i[j - 1];
  382. zet2dr = zeta2r[j - 1];
  383. zet2di = zeta2i[j - 1];
  384. sumdr = sumr[j - 1];
  385. sumdi = sumi[j - 1];
  386. m = j;
  387. j = 3 - j;
  388. goto L180;
  389. L175:
  390. if (kk == *n && ib < *n) {
  391. goto L180;
  392. }
  393. if (kk == ib || kk == ic) {
  394. goto L172;
  395. }
  396. initd = 0;
  397. L180:
  398. zunik_(&zrr, &zri, &fn, &c__1, &c__0, tol, &initd, &phidr, &phidi, &
  399. zet1dr, &zet1di, &zet2dr, &zet2di, &sumdr, &sumdi, &cwrkr[(m
  400. << 4) - 16], &cwrki[(m << 4) - 16]);
  401. if (*kode == 1) {
  402. goto L200;
  403. }
  404. str = zrr + zet2dr;
  405. sti = zri + zet2di;
  406. rast = fn / zabs_(&str, &sti);
  407. str = str * rast * rast;
  408. sti = -sti * rast * rast;
  409. s1r = -zet1dr + str;
  410. s1i = -zet1di + sti;
  411. goto L210;
  412. L200:
  413. s1r = -zet1dr + zet2dr;
  414. s1i = -zet1di + zet2di;
  415. L210:
  416. /* ----------------------------------------------------------------------- */
  417. /* TEST FOR UNDERFLOW AND OVERFLOW */
  418. /* ----------------------------------------------------------------------- */
  419. rs1 = s1r;
  420. if (abs(rs1) > *elim) {
  421. goto L260;
  422. }
  423. if (kdflg == 1) {
  424. iflag = 2;
  425. }
  426. if (abs(rs1) < *alim) {
  427. goto L220;
  428. }
  429. /* ----------------------------------------------------------------------- */
  430. /* REFINE TEST AND SCALE */
  431. /* ----------------------------------------------------------------------- */
  432. aphi = zabs_(&phidr, &phidi);
  433. rs1 += log(aphi);
  434. if (abs(rs1) > *elim) {
  435. goto L260;
  436. }
  437. if (kdflg == 1) {
  438. iflag = 1;
  439. }
  440. if (rs1 < 0.) {
  441. goto L220;
  442. }
  443. if (kdflg == 1) {
  444. iflag = 3;
  445. }
  446. L220:
  447. str = phidr * sumdr - phidi * sumdi;
  448. sti = phidr * sumdi + phidi * sumdr;
  449. s2r = -csgni * sti;
  450. s2i = csgni * str;
  451. str = exp(s1r) * cssr[iflag - 1];
  452. s1r = str * cos(s1i);
  453. s1i = str * sin(s1i);
  454. str = s2r * s1r - s2i * s1i;
  455. s2i = s2r * s1i + s2i * s1r;
  456. s2r = str;
  457. if (iflag != 1) {
  458. goto L230;
  459. }
  460. zuchk_(&s2r, &s2i, &nw, bry, tol);
  461. if (nw == 0) {
  462. goto L230;
  463. }
  464. s2r = zeror;
  465. s2i = zeroi;
  466. L230:
  467. cyr[kdflg - 1] = s2r;
  468. cyi[kdflg - 1] = s2i;
  469. c2r = s2r;
  470. c2i = s2i;
  471. s2r *= csrr[iflag - 1];
  472. s2i *= csrr[iflag - 1];
  473. /* ----------------------------------------------------------------------- */
  474. /* ADD I AND K FUNCTIONS, K SEQUENCE IN Y(I), I=1,N */
  475. /* ----------------------------------------------------------------------- */
  476. s1r = yr[kk];
  477. s1i = yi[kk];
  478. if (*kode == 1) {
  479. goto L250;
  480. }
  481. zs1s2_(&zrr, &zri, &s1r, &s1i, &s2r, &s2i, &nw, &asc, alim, &iuf);
  482. *nz += nw;
  483. L250:
  484. yr[kk] = s1r * cspnr - s1i * cspni + s2r;
  485. yi[kk] = cspnr * s1i + cspni * s1r + s2i;
  486. --kk;
  487. cspnr = -cspnr;
  488. cspni = -cspni;
  489. if (c2r != 0. || c2i != 0.) {
  490. goto L255;
  491. }
  492. kdflg = 1;
  493. goto L270;
  494. L255:
  495. if (kdflg == 2) {
  496. goto L275;
  497. }
  498. kdflg = 2;
  499. goto L270;
  500. L260:
  501. if (rs1 > 0.) {
  502. goto L300;
  503. }
  504. s2r = zeror;
  505. s2i = zeroi;
  506. goto L230;
  507. L270:
  508. ;
  509. }
  510. k = *n;
  511. L275:
  512. il = *n - k;
  513. if (il == 0) {
  514. return 0;
  515. }
  516. /* ----------------------------------------------------------------------- */
  517. /* RECUR BACKWARD FOR REMAINDER OF I SEQUENCE AND ADD IN THE */
  518. /* K FUNCTIONS, SCALING THE I SEQUENCE DURING RECURRENCE TO KEEP */
  519. /* INTERMEDIATE ARITHMETIC ON SCALE NEAR EXPONENT EXTREMES. */
  520. /* ----------------------------------------------------------------------- */
  521. s1r = cyr[0];
  522. s1i = cyi[0];
  523. s2r = cyr[1];
  524. s2i = cyi[1];
  525. csr = csrr[iflag - 1];
  526. ascle = bry[iflag - 1];
  527. fn = (double) (inu + il);
  528. i__1 = il;
  529. for (i__ = 1; i__ <= i__1; ++i__) {
  530. c2r = s2r;
  531. c2i = s2i;
  532. s2r = s1r + (fn + fnf) * (rzr * c2r - rzi * c2i);
  533. s2i = s1i + (fn + fnf) * (rzr * c2i + rzi * c2r);
  534. s1r = c2r;
  535. s1i = c2i;
  536. fn += -1.;
  537. c2r = s2r * csr;
  538. c2i = s2i * csr;
  539. ckr = c2r;
  540. cki = c2i;
  541. c1r = yr[kk];
  542. c1i = yi[kk];
  543. if (*kode == 1) {
  544. goto L280;
  545. }
  546. zs1s2_(&zrr, &zri, &c1r, &c1i, &c2r, &c2i, &nw, &asc, alim, &iuf);
  547. *nz += nw;
  548. L280:
  549. yr[kk] = c1r * cspnr - c1i * cspni + c2r;
  550. yi[kk] = c1r * cspni + c1i * cspnr + c2i;
  551. --kk;
  552. cspnr = -cspnr;
  553. cspni = -cspni;
  554. if (iflag >= 3) {
  555. goto L290;
  556. }
  557. c2r = abs(ckr);
  558. c2i = abs(cki);
  559. c2m = max(c2r,c2i);
  560. if (c2m <= ascle) {
  561. goto L290;
  562. }
  563. ++iflag;
  564. ascle = bry[iflag - 1];
  565. s1r *= csr;
  566. s1i *= csr;
  567. s2r = ckr;
  568. s2i = cki;
  569. s1r *= cssr[iflag - 1];
  570. s1i *= cssr[iflag - 1];
  571. s2r *= cssr[iflag - 1];
  572. s2i *= cssr[iflag - 1];
  573. csr = csrr[iflag - 1];
  574. L290:
  575. ;
  576. }
  577. return 0;
  578. L300:
  579. *nz = -1;
  580. return 0;
  581. } /* zunk1_ */