zrati.cpp 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. /* zrati.f -- translated by f2c (version 20100827).
  2. This file no longer depends on f2c.
  3. */
  4. #include "slatec-internal.hpp"
  5. int zrati_(double *zr, double *zi, double const *fnu,
  6. integer const *n, double *cyr, double *cyi, double *tol)
  7. {
  8. /* Initialized data */
  9. static double const czeror = 0.;
  10. static double const czeroi = 0.;
  11. static double const coner = 1.;
  12. static double const conei = 0.;
  13. static double const rt2 = 1.41421356237309505;
  14. /* System generated locals */
  15. integer i__1;
  16. double d__1;
  17. /* Local variables */
  18. integer i__, k;
  19. double ak;
  20. integer id, kk;
  21. double az, ap1, ap2, p1i, p2i, t1i, p1r, p2r, t1r, arg, rak, rho;
  22. integer inu;
  23. double pti, tti, rzi, ptr, ttr, rzr, rap1, flam, dfnu, fdnu;
  24. integer magz;
  25. integer idnu;
  26. double fnup;
  27. double test, test1, amagz;
  28. integer itime;
  29. double cdfnui, cdfnur;
  30. /* ***BEGIN PROLOGUE ZRATI */
  31. /* ***SUBSIDIARY */
  32. /* ***PURPOSE Subsidiary to ZBESH, ZBESI and ZBESK */
  33. /* ***LIBRARY SLATEC */
  34. /* ***TYPE ALL (CRATI-A, ZRATI-A) */
  35. /* ***AUTHOR Amos, D. E., (SNL) */
  36. /* ***DESCRIPTION */
  37. /* ZRATI COMPUTES RATIOS OF I BESSEL FUNCTIONS BY BACKWARD */
  38. /* RECURRENCE. THE STARTING INDEX IS DETERMINED BY FORWARD */
  39. /* RECURRENCE AS DESCRIBED IN J. RES. OF NAT. BUR. OF STANDARDS-B, */
  40. /* MATHEMATICAL SCIENCES, VOL 77B, P111-114, SEPTEMBER, 1973, */
  41. /* BESSEL FUNCTIONS I AND J OF COMPLEX ARGUMENT AND INTEGER ORDER, */
  42. /* BY D. J. SOOKNE. */
  43. /* ***SEE ALSO ZBESH, ZBESI, ZBESK */
  44. /* ***ROUTINES CALLED ZABS, ZDIV */
  45. /* ***REVISION HISTORY (YYMMDD) */
  46. /* 830501 DATE WRITTEN */
  47. /* 910415 Prologue converted to Version 4.0 format. (BAB) */
  48. /* ***END PROLOGUE ZRATI */
  49. /* Parameter adjustments */
  50. --cyi;
  51. --cyr;
  52. /* Function Body */
  53. /* ***FIRST EXECUTABLE STATEMENT ZRATI */
  54. az = zabs_(zr, zi);
  55. inu = (integer) (*fnu);
  56. idnu = inu + *n - 1;
  57. magz = (integer) az;
  58. amagz = (double) (magz + 1);
  59. fdnu = (double) idnu;
  60. fnup = max(amagz,fdnu);
  61. id = idnu - magz - 1;
  62. itime = 1;
  63. k = 1;
  64. ptr = 1. / az;
  65. rzr = ptr * (*zr + *zr) * ptr;
  66. rzi = -ptr * (*zi + *zi) * ptr;
  67. t1r = rzr * fnup;
  68. t1i = rzi * fnup;
  69. p2r = -t1r;
  70. p2i = -t1i;
  71. p1r = coner;
  72. p1i = conei;
  73. t1r += rzr;
  74. t1i += rzi;
  75. if (id > 0) {
  76. id = 0;
  77. }
  78. ap2 = zabs_(&p2r, &p2i);
  79. ap1 = zabs_(&p1r, &p1i);
  80. /* ----------------------------------------------------------------------- */
  81. /* THE OVERFLOW TEST ON K(FNU+I-1,Z) BEFORE THE CALL TO CBKNU */
  82. /* GUARANTEES THAT P2 IS ON SCALE. SCALE TEST1 AND ALL SUBSEQUENT */
  83. /* P2 VALUES BY AP1 TO ENSURE THAT AN OVERFLOW DOES NOT OCCUR */
  84. /* PREMATURELY. */
  85. /* ----------------------------------------------------------------------- */
  86. arg = (ap2 + ap2) / (ap1 * *tol);
  87. test1 = sqrt(arg);
  88. test = test1;
  89. rap1 = 1. / ap1;
  90. p1r *= rap1;
  91. p1i *= rap1;
  92. p2r *= rap1;
  93. p2i *= rap1;
  94. ap2 *= rap1;
  95. L10:
  96. ++k;
  97. ap1 = ap2;
  98. ptr = p2r;
  99. pti = p2i;
  100. p2r = p1r - (t1r * ptr - t1i * pti);
  101. p2i = p1i - (t1r * pti + t1i * ptr);
  102. p1r = ptr;
  103. p1i = pti;
  104. t1r += rzr;
  105. t1i += rzi;
  106. ap2 = zabs_(&p2r, &p2i);
  107. if (ap1 <= test) {
  108. goto L10;
  109. }
  110. if (itime == 2) {
  111. goto L20;
  112. }
  113. ak = zabs_(&t1r, &t1i) * .5;
  114. flam = ak + sqrt(ak * ak - 1.);
  115. /* Computing MIN */
  116. d__1 = ap2 / ap1;
  117. rho = min(d__1,flam);
  118. test = test1 * sqrt(rho / (rho * rho - 1.));
  119. itime = 2;
  120. goto L10;
  121. L20:
  122. kk = k + 1 - id;
  123. ak = (double) kk;
  124. t1r = ak;
  125. t1i = czeroi;
  126. dfnu = *fnu + (*n - 1);
  127. p1r = 1. / ap2;
  128. p1i = czeroi;
  129. p2r = czeror;
  130. p2i = czeroi;
  131. i__1 = kk;
  132. for (i__ = 1; i__ <= i__1; ++i__) {
  133. ptr = p1r;
  134. pti = p1i;
  135. rap1 = dfnu + t1r;
  136. ttr = rzr * rap1;
  137. tti = rzi * rap1;
  138. p1r = ptr * ttr - pti * tti + p2r;
  139. p1i = ptr * tti + pti * ttr + p2i;
  140. p2r = ptr;
  141. p2i = pti;
  142. t1r -= coner;
  143. /* L30: */
  144. }
  145. if (p1r != czeror || p1i != czeroi) {
  146. goto L40;
  147. }
  148. p1r = *tol;
  149. p1i = *tol;
  150. L40:
  151. zdiv_(&p2r, &p2i, &p1r, &p1i, &cyr[*n], &cyi[*n]);
  152. if (*n == 1) {
  153. return 0;
  154. }
  155. k = *n - 1;
  156. ak = (double) k;
  157. t1r = ak;
  158. t1i = czeroi;
  159. cdfnur = *fnu * rzr;
  160. cdfnui = *fnu * rzi;
  161. i__1 = *n;
  162. for (i__ = 2; i__ <= i__1; ++i__) {
  163. ptr = cdfnur + (t1r * rzr - t1i * rzi) + cyr[k + 1];
  164. pti = cdfnui + (t1r * rzi + t1i * rzr) + cyi[k + 1];
  165. ak = zabs_(&ptr, &pti);
  166. if (ak != czeror) {
  167. goto L50;
  168. }
  169. ptr = *tol;
  170. pti = *tol;
  171. ak = *tol * rt2;
  172. L50:
  173. rak = coner / ak;
  174. cyr[k] = rak * ptr * rak;
  175. cyi[k] = -rak * pti * rak;
  176. t1r -= coner;
  177. --k;
  178. /* L60: */
  179. }
  180. return 0;
  181. } /* zrati_ */