zwrsk.cpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /* zwrsk.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__2 = 2;
  7. static integer const c__1 = 1;
  8. int zwrsk_(double *zrr, double *zri, double const *fnu,
  9. integer const *kode, integer const *n, double *yr, double *yi, integer * nz,
  10. double *cwr, double *cwi, double *tol, double *
  11. elim, double *alim)
  12. {
  13. /* System generated locals */
  14. integer i__1;
  15. /* Local variables */
  16. integer i__, nw;
  17. double c1i, c2i, c1r, c2r, act, acw, cti, ctr, pti, sti, ptr, str, ract;
  18. double ascle, csclr, cinui, cinur;
  19. /* ***BEGIN PROLOGUE ZWRSK */
  20. /* ***SUBSIDIARY */
  21. /* ***PURPOSE Subsidiary to ZBESI and ZBESK */
  22. /* ***LIBRARY SLATEC */
  23. /* ***TYPE ALL (CWRSK-A, ZWRSK-A) */
  24. /* ***AUTHOR Amos, D. E., (SNL) */
  25. /* ***DESCRIPTION */
  26. /* ZWRSK COMPUTES THE I BESSEL FUNCTION FOR RE(Z).GE.0.0 BY */
  27. /* NORMALIZING THE I FUNCTION RATIOS FROM ZRATI BY THE WRONSKIAN */
  28. /* ***SEE ALSO ZBESI, ZBESK */
  29. /* ***ROUTINES CALLED D1MACH, ZABS, ZBKNU, ZRATI */
  30. /* ***REVISION HISTORY (YYMMDD) */
  31. /* 830501 DATE WRITTEN */
  32. /* 910415 Prologue converted to Version 4.0 format. (BAB) */
  33. /* ***END PROLOGUE ZWRSK */
  34. /* COMPLEX CINU,CSCL,CT,CW,C1,C2,RCT,ST,Y,ZR */
  35. /* ***FIRST EXECUTABLE STATEMENT ZWRSK */
  36. /* ----------------------------------------------------------------------- */
  37. /* I(FNU+I-1,Z) BY BACKWARD RECURRENCE FOR RATIOS */
  38. /* Y(I)=I(FNU+I,Z)/I(FNU+I-1,Z) FROM CRATI NORMALIZED BY THE */
  39. /* WRONSKIAN WITH K(FNU,Z) AND K(FNU+1,Z) FROM CBKNU. */
  40. /* ----------------------------------------------------------------------- */
  41. /* Parameter adjustments */
  42. --yi;
  43. --yr;
  44. --cwr;
  45. --cwi;
  46. /* Function Body */
  47. *nz = 0;
  48. zbknu_(zrr, zri, fnu, kode, &c__2, &cwr[1], &cwi[1], &nw, tol, elim, alim)
  49. ;
  50. if (nw != 0) {
  51. goto L50;
  52. }
  53. zrati_(zrr, zri, fnu, n, &yr[1], &yi[1], tol);
  54. /* ----------------------------------------------------------------------- */
  55. /* RECUR FORWARD ON I(FNU+1,Z) = R(FNU,Z)*I(FNU,Z), */
  56. /* R(FNU+J-1,Z)=Y(J), J=1,...,N */
  57. /* ----------------------------------------------------------------------- */
  58. cinur = 1.;
  59. cinui = 0.;
  60. if (*kode == 1) {
  61. goto L10;
  62. }
  63. cinur = cos(*zri);
  64. cinui = sin(*zri);
  65. L10:
  66. /* ----------------------------------------------------------------------- */
  67. /* ON LOW EXPONENT MACHINES THE K FUNCTIONS CAN BE CLOSE TO BOTH */
  68. /* THE UNDER AND OVERFLOW LIMITS AND THE NORMALIZATION MUST BE */
  69. /* SCALED TO PREVENT OVER OR UNDERFLOW. CUOIK HAS DETERMINED THAT */
  70. /* THE RESULT IS ON SCALE. */
  71. /* ----------------------------------------------------------------------- */
  72. acw = zabs_(&cwr[2], &cwi[2]);
  73. ascle = d1mach_(1) * 1e3 / *tol;
  74. csclr = 1.;
  75. if (acw > ascle) {
  76. goto L20;
  77. }
  78. csclr = 1. / *tol;
  79. goto L30;
  80. L20:
  81. ascle = 1. / ascle;
  82. if (acw < ascle) {
  83. goto L30;
  84. }
  85. csclr = *tol;
  86. L30:
  87. c1r = cwr[1] * csclr;
  88. c1i = cwi[1] * csclr;
  89. c2r = cwr[2] * csclr;
  90. c2i = cwi[2] * csclr;
  91. str = yr[1];
  92. sti = yi[1];
  93. /* ----------------------------------------------------------------------- */
  94. /* CINU=CINU*(CONJG(CT)/ABS(CT))*(1.0D0/ABS(CT) PREVENTS */
  95. /* UNDER- OR OVERFLOW PREMATURELY BY SQUARING ABS(CT) */
  96. /* ----------------------------------------------------------------------- */
  97. ptr = str * c1r - sti * c1i;
  98. pti = str * c1i + sti * c1r;
  99. ptr += c2r;
  100. pti += c2i;
  101. ctr = *zrr * ptr - *zri * pti;
  102. cti = *zrr * pti + *zri * ptr;
  103. act = zabs_(&ctr, &cti);
  104. ract = 1. / act;
  105. ctr *= ract;
  106. cti = -cti * ract;
  107. ptr = cinur * ract;
  108. pti = cinui * ract;
  109. cinur = ptr * ctr - pti * cti;
  110. cinui = ptr * cti + pti * ctr;
  111. yr[1] = cinur * csclr;
  112. yi[1] = cinui * csclr;
  113. if (*n == 1) {
  114. return 0;
  115. }
  116. i__1 = *n;
  117. for (i__ = 2; i__ <= i__1; ++i__) {
  118. ptr = str * cinur - sti * cinui;
  119. cinui = str * cinui + sti * cinur;
  120. cinur = ptr;
  121. str = yr[i__];
  122. sti = yi[i__];
  123. yr[i__] = cinur * csclr;
  124. yi[i__] = cinui * csclr;
  125. /* L40: */
  126. }
  127. return 0;
  128. L50:
  129. *nz = -1;
  130. if (nw == -2) {
  131. *nz = -2;
  132. }
  133. return 0;
  134. } /* zwrsk_ */