zuni2.cpp 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  1. /* zuni2.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__0 = 0;
  8. static integer const c__2 = 2;
  9. int zuni2_(double *zr, double *zi, double const *fnu,
  10. integer const *kode, integer const *n, double *yr, double *yi, integer *
  11. nz, integer *nlast, double *fnul, double *tol, double *
  12. elim, double *alim)
  13. {
  14. /* Initialized data */
  15. static double const zeror = 0.;
  16. static double const zeroi = 0.;
  17. static double const coner = 1.;
  18. static double const cipr[4] = { 1.,0.,-1.,0. };
  19. static double const cipi[4] = { 0.,1.,0.,-1. };
  20. static double const hpi = 1.57079632679489662;
  21. static double const aic = 1.265512123484645396;
  22. /* System generated locals */
  23. integer i__1;
  24. /* Local variables */
  25. integer i__, j, k, nd;
  26. double fn;
  27. integer in, nn, nw;
  28. double c2i, c2m, c1r, c2r, s1i, s2i, rs1, s1r, s2r, aii, ang, car;
  29. integer nai;
  30. double air, zbi, cyi[2], sar;
  31. integer nuf, inu;
  32. double bry[3], raz, sti, zbr, zni, cyr[2], rzi, str, znr, rzr, daii,
  33. cidi, aarg;
  34. integer ndai;
  35. double dair, aphi, argi, cscl, phii, crsc, argr;
  36. integer idum;
  37. double phir, csrr[3], cssr[3], rast;
  38. integer iflag = 0;
  39. double ascle, asumi, bsumi;
  40. double asumr, bsumr;
  41. double zeta1i, zeta2i, zeta1r, zeta2r;
  42. /* ***BEGIN PROLOGUE ZUNI2 */
  43. /* ***SUBSIDIARY */
  44. /* ***PURPOSE Subsidiary to ZBESI and ZBESK */
  45. /* ***LIBRARY SLATEC */
  46. /* ***TYPE ALL (CUNI2-A, ZUNI2-A) */
  47. /* ***AUTHOR Amos, D. E., (SNL) */
  48. /* ***DESCRIPTION */
  49. /* ZUNI2 COMPUTES I(FNU,Z) IN THE RIGHT HALF PLANE BY MEANS OF */
  50. /* UNIFORM ASYMPTOTIC EXPANSION FOR J(FNU,ZN) WHERE ZN IS Z*I */
  51. /* OR -Z*I AND ZN IS IN THE RIGHT HALF PLANE ALSO. */
  52. /* FNUL IS THE SMALLEST ORDER PERMITTED FOR THE ASYMPTOTIC */
  53. /* EXPANSION. NLAST=0 MEANS ALL OF THE Y VALUES WERE SET. */
  54. /* NLAST.NE.0 IS THE NUMBER LEFT TO BE COMPUTED BY ANOTHER */
  55. /* FORMULA FOR ORDERS FNU TO FNU+NLAST-1 BECAUSE FNU+NLAST-1.LT.FNUL. */
  56. /* Y(I)=CZERO FOR I=NLAST+1,N */
  57. /* ***SEE ALSO ZBESI, ZBESK */
  58. /* ***ROUTINES CALLED D1MACH, ZABS, ZAIRY, ZUCHK, ZUNHJ, ZUOIK */
  59. /* ***REVISION HISTORY (YYMMDD) */
  60. /* 830501 DATE WRITTEN */
  61. /* 910415 Prologue converted to Version 4.0 format. (BAB) */
  62. /* ***END PROLOGUE ZUNI2 */
  63. /* COMPLEX AI,ARG,ASUM,BSUM,CFN,CI,CID,CIP,CONE,CRSC,CSCL,CSR,CSS, */
  64. /* *CZERO,C1,C2,DAI,PHI,RZ,S1,S2,Y,Z,ZB,ZETA1,ZETA2,ZN */
  65. /* Parameter adjustments */
  66. --yi;
  67. --yr;
  68. /* Function Body */
  69. /* ***FIRST EXECUTABLE STATEMENT ZUNI2 */
  70. *nz = 0;
  71. nd = *n;
  72. *nlast = 0;
  73. /* ----------------------------------------------------------------------- */
  74. /* COMPUTED VALUES WITH EXPONENTS BETWEEN ALIM AND ELIM IN MAG- */
  75. /* NITUDE ARE SCALED TO KEEP INTERMEDIATE ARITHMETIC ON SCALE, */
  76. /* EXP(ALIM)=EXP(ELIM)*TOL */
  77. /* ----------------------------------------------------------------------- */
  78. cscl = 1. / *tol;
  79. crsc = *tol;
  80. cssr[0] = cscl;
  81. cssr[1] = coner;
  82. cssr[2] = crsc;
  83. csrr[0] = crsc;
  84. csrr[1] = coner;
  85. csrr[2] = cscl;
  86. bry[0] = d1mach_(1) * 1e3 / *tol;
  87. /* ----------------------------------------------------------------------- */
  88. /* ZN IS IN THE RIGHT HALF PLANE AFTER ROTATION BY CI OR -CI */
  89. /* ----------------------------------------------------------------------- */
  90. znr = *zi;
  91. zni = -(*zr);
  92. zbr = *zr;
  93. zbi = *zi;
  94. cidi = -coner;
  95. inu = (integer) (*fnu);
  96. ang = hpi * (*fnu - inu);
  97. c2r = cos(ang);
  98. c2i = sin(ang);
  99. car = c2r;
  100. sar = c2i;
  101. in = inu + *n - 1;
  102. in = in % 4 + 1;
  103. str = c2r * cipr[in - 1] - c2i * cipi[in - 1];
  104. c2i = c2r * cipi[in - 1] + c2i * cipr[in - 1];
  105. c2r = str;
  106. if (*zi > 0.) {
  107. goto L10;
  108. }
  109. znr = -znr;
  110. zbi = -zbi;
  111. cidi = -cidi;
  112. c2i = -c2i;
  113. L10:
  114. /* ----------------------------------------------------------------------- */
  115. /* CHECK FOR UNDERFLOW AND OVERFLOW ON FIRST MEMBER */
  116. /* ----------------------------------------------------------------------- */
  117. fn = max(*fnu,1.);
  118. zunhj_(&znr, &zni, &fn, &c__1, tol, &phir, &phii, &argr, &argi, &zeta1r, &
  119. zeta1i, &zeta2r, &zeta2i, &asumr, &asumi, &bsumr, &bsumi);
  120. if (*kode == 1) {
  121. goto L20;
  122. }
  123. str = zbr + zeta2r;
  124. sti = zbi + zeta2i;
  125. rast = fn / zabs_(&str, &sti);
  126. str = str * rast * rast;
  127. sti = -sti * rast * rast;
  128. s1r = -zeta1r + str;
  129. s1i = -zeta1i + sti;
  130. goto L30;
  131. L20:
  132. s1r = -zeta1r + zeta2r;
  133. s1i = -zeta1i + zeta2i;
  134. L30:
  135. rs1 = s1r;
  136. if (abs(rs1) > *elim) {
  137. goto L150;
  138. }
  139. L40:
  140. nn = min(2,nd);
  141. i__1 = nn;
  142. for (i__ = 1; i__ <= i__1; ++i__) {
  143. fn = *fnu + (nd - i__);
  144. zunhj_(&znr, &zni, &fn, &c__0, tol, &phir, &phii, &argr, &argi, &
  145. zeta1r, &zeta1i, &zeta2r, &zeta2i, &asumr, &asumi, &bsumr, &
  146. bsumi);
  147. if (*kode == 1) {
  148. goto L50;
  149. }
  150. str = zbr + zeta2r;
  151. sti = zbi + zeta2i;
  152. rast = fn / zabs_(&str, &sti);
  153. str = str * rast * rast;
  154. sti = -sti * rast * rast;
  155. s1r = -zeta1r + str;
  156. s1i = -zeta1i + sti + abs(*zi);
  157. goto L60;
  158. L50:
  159. s1r = -zeta1r + zeta2r;
  160. s1i = -zeta1i + zeta2i;
  161. L60:
  162. /* ----------------------------------------------------------------------- */
  163. /* TEST FOR UNDERFLOW AND OVERFLOW */
  164. /* ----------------------------------------------------------------------- */
  165. rs1 = s1r;
  166. if (abs(rs1) > *elim) {
  167. goto L120;
  168. }
  169. if (i__ == 1) {
  170. iflag = 2;
  171. }
  172. if (abs(rs1) < *alim) {
  173. goto L70;
  174. }
  175. /* ----------------------------------------------------------------------- */
  176. /* REFINE TEST AND SCALE */
  177. /* ----------------------------------------------------------------------- */
  178. /* ----------------------------------------------------------------------- */
  179. aphi = zabs_(&phir, &phii);
  180. aarg = zabs_(&argr, &argi);
  181. rs1 = rs1 + log(aphi) - log(aarg) * .25 - aic;
  182. if (abs(rs1) > *elim) {
  183. goto L120;
  184. }
  185. if (i__ == 1) {
  186. iflag = 1;
  187. }
  188. if (rs1 < 0.) {
  189. goto L70;
  190. }
  191. if (i__ == 1) {
  192. iflag = 3;
  193. }
  194. L70:
  195. /* ----------------------------------------------------------------------- */
  196. /* SCALE S1 TO KEEP INTERMEDIATE ARITHMETIC ON SCALE NEAR */
  197. /* EXPONENT EXTREMES */
  198. /* ----------------------------------------------------------------------- */
  199. zairy_(&argr, &argi, &c__0, &c__2, &air, &aii, &nai, &idum);
  200. zairy_(&argr, &argi, &c__1, &c__2, &dair, &daii, &ndai, &idum);
  201. str = dair * bsumr - daii * bsumi;
  202. sti = dair * bsumi + daii * bsumr;
  203. str += air * asumr - aii * asumi;
  204. sti += air * asumi + aii * asumr;
  205. s2r = phir * str - phii * sti;
  206. s2i = phir * sti + phii * str;
  207. str = exp(s1r) * cssr[iflag - 1];
  208. s1r = str * cos(s1i);
  209. s1i = str * sin(s1i);
  210. str = s2r * s1r - s2i * s1i;
  211. s2i = s2r * s1i + s2i * s1r;
  212. s2r = str;
  213. if (iflag != 1) {
  214. goto L80;
  215. }
  216. zuchk_(&s2r, &s2i, &nw, bry, tol);
  217. if (nw != 0) {
  218. goto L120;
  219. }
  220. L80:
  221. if (*zi <= 0.) {
  222. s2i = -s2i;
  223. }
  224. str = s2r * c2r - s2i * c2i;
  225. s2i = s2r * c2i + s2i * c2r;
  226. s2r = str;
  227. cyr[i__ - 1] = s2r;
  228. cyi[i__ - 1] = s2i;
  229. j = nd - i__ + 1;
  230. yr[j] = s2r * csrr[iflag - 1];
  231. yi[j] = s2i * csrr[iflag - 1];
  232. str = -c2i * cidi;
  233. c2i = c2r * cidi;
  234. c2r = str;
  235. /* L90: */
  236. }
  237. if (nd <= 2) {
  238. goto L110;
  239. }
  240. raz = 1. / zabs_(zr, zi);
  241. str = *zr * raz;
  242. sti = -(*zi) * raz;
  243. rzr = (str + str) * raz;
  244. rzi = (sti + sti) * raz;
  245. bry[1] = 1. / bry[0];
  246. bry[2] = d1mach_(2);
  247. s1r = cyr[0];
  248. s1i = cyi[0];
  249. s2r = cyr[1];
  250. s2i = cyi[1];
  251. c1r = csrr[iflag - 1];
  252. ascle = bry[iflag - 1];
  253. k = nd - 2;
  254. fn = (double) k;
  255. i__1 = nd;
  256. for (i__ = 3; i__ <= i__1; ++i__) {
  257. c2r = s2r;
  258. c2i = s2i;
  259. s2r = s1r + (*fnu + fn) * (rzr * c2r - rzi * c2i);
  260. s2i = s1i + (*fnu + fn) * (rzr * c2i + rzi * c2r);
  261. s1r = c2r;
  262. s1i = c2i;
  263. c2r = s2r * c1r;
  264. c2i = s2i * c1r;
  265. yr[k] = c2r;
  266. yi[k] = c2i;
  267. --k;
  268. fn += -1.;
  269. if (iflag >= 3) {
  270. goto L100;
  271. }
  272. str = abs(c2r);
  273. sti = abs(c2i);
  274. c2m = max(str,sti);
  275. if (c2m <= ascle) {
  276. goto L100;
  277. }
  278. ++iflag;
  279. ascle = bry[iflag - 1];
  280. s1r *= c1r;
  281. s1i *= c1r;
  282. s2r = c2r;
  283. s2i = c2i;
  284. s1r *= cssr[iflag - 1];
  285. s1i *= cssr[iflag - 1];
  286. s2r *= cssr[iflag - 1];
  287. s2i *= cssr[iflag - 1];
  288. c1r = csrr[iflag - 1];
  289. L100:
  290. ;
  291. }
  292. L110:
  293. return 0;
  294. L120:
  295. if (rs1 > 0.) {
  296. goto L140;
  297. }
  298. /* ----------------------------------------------------------------------- */
  299. /* SET UNDERFLOW AND UPDATE PARAMETERS */
  300. /* ----------------------------------------------------------------------- */
  301. yr[nd] = zeror;
  302. yi[nd] = zeroi;
  303. ++(*nz);
  304. --nd;
  305. if (nd == 0) {
  306. goto L110;
  307. }
  308. zuoik_(zr, zi, fnu, kode, &c__1, &nd, &yr[1], &yi[1], &nuf, tol, elim,
  309. alim);
  310. if (nuf < 0) {
  311. goto L140;
  312. }
  313. nd -= nuf;
  314. *nz += nuf;
  315. if (nd == 0) {
  316. goto L110;
  317. }
  318. fn = *fnu + (nd - 1);
  319. if (fn < *fnul) {
  320. goto L130;
  321. }
  322. /* FN = CIDI */
  323. /* J = NUF + 1 */
  324. /* K = MOD(J,4) + 1 */
  325. /* S1R = CIPR(K) */
  326. /* S1I = CIPI(K) */
  327. /* IF (FN.LT.0.0D0) S1I = -S1I */
  328. /* STR = C2R*S1R - C2I*S1I */
  329. /* C2I = C2R*S1I + C2I*S1R */
  330. /* C2R = STR */
  331. in = inu + nd - 1;
  332. in = in % 4 + 1;
  333. c2r = car * cipr[in - 1] - sar * cipi[in - 1];
  334. c2i = car * cipi[in - 1] + sar * cipr[in - 1];
  335. if (*zi <= 0.) {
  336. c2i = -c2i;
  337. }
  338. goto L40;
  339. L130:
  340. *nlast = nd;
  341. return 0;
  342. L140:
  343. *nz = -1;
  344. return 0;
  345. L150:
  346. if (rs1 > 0.) {
  347. goto L140;
  348. }
  349. *nz = *n;
  350. i__1 = *n;
  351. for (i__ = 1; i__ <= i__1; ++i__) {
  352. yr[i__] = zeror;
  353. yi[i__] = zeroi;
  354. /* L160: */
  355. }
  356. return 0;
  357. } /* zuni2_ */