zkscl.cpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. /* zkscl.f -- translated by f2c (version 20100827).
  2. This file no longer depends on f2c.
  3. */
  4. #include "slatec-internal.hpp"
  5. int zkscl_(double *zrr, double *zri, double const *fnu,
  6. integer const *n, double *yr, double *yi, integer *nz, double *
  7. rzr, double *rzi, double *ascle, double *tol, double *
  8. elim)
  9. {
  10. /* Initialized data */
  11. static double const zeror = 0.;
  12. static double const zeroi = 0.;
  13. /* System generated locals */
  14. integer i__1;
  15. /* Local variables */
  16. integer i__, ic;
  17. double as, fn;
  18. integer kk, nn, nw;
  19. double s1i, s2i, s1r, s2r, acs, cki, elm, csi, ckr, cyi[2], zdi, csr,
  20. cyr[2], zdr, str, alas;
  21. integer idum;
  22. double helim, celmr;
  23. /* ***BEGIN PROLOGUE ZKSCL */
  24. /* ***SUBSIDIARY */
  25. /* ***PURPOSE Subsidiary to ZBESK */
  26. /* ***LIBRARY SLATEC */
  27. /* ***TYPE ALL (CKSCL-A, ZKSCL-A) */
  28. /* ***AUTHOR Amos, D. E., (SNL) */
  29. /* ***DESCRIPTION */
  30. /* SET K FUNCTIONS TO ZERO ON UNDERFLOW, CONTINUE RECURRENCE */
  31. /* ON SCALED FUNCTIONS UNTIL TWO MEMBERS COME ON SCALE, THEN */
  32. /* RETURN WITH MIN(NZ+2,N) VALUES SCALED BY 1/TOL. */
  33. /* ***SEE ALSO ZBESK */
  34. /* ***ROUTINES CALLED ZABS, ZLOG, ZUCHK */
  35. /* ***REVISION HISTORY (YYMMDD) */
  36. /* 830501 DATE WRITTEN */
  37. /* 910415 Prologue converted to Version 4.0 format. (BAB) */
  38. /* 930122 Added ZLOG to EXTERNAL statement. (RWC) */
  39. /* ***END PROLOGUE ZKSCL */
  40. /* COMPLEX CK,CS,CY,CZERO,RZ,S1,S2,Y,ZR,ZD,CELM */
  41. /* Parameter adjustments */
  42. --yi;
  43. --yr;
  44. /* Function Body */
  45. /* ***FIRST EXECUTABLE STATEMENT ZKSCL */
  46. *nz = 0;
  47. ic = 0;
  48. nn = min(2,*n);
  49. i__1 = nn;
  50. for (i__ = 1; i__ <= i__1; ++i__) {
  51. s1r = yr[i__];
  52. s1i = yi[i__];
  53. cyr[i__ - 1] = s1r;
  54. cyi[i__ - 1] = s1i;
  55. as = zabs_(&s1r, &s1i);
  56. acs = -(*zrr) + log(as);
  57. ++(*nz);
  58. yr[i__] = zeror;
  59. yi[i__] = zeroi;
  60. if (acs < -(*elim)) {
  61. goto L10;
  62. }
  63. zlog_(&s1r, &s1i, &csr, &csi, &idum);
  64. csr -= *zrr;
  65. csi -= *zri;
  66. str = exp(csr) / *tol;
  67. csr = str * cos(csi);
  68. csi = str * sin(csi);
  69. zuchk_(&csr, &csi, &nw, ascle, tol);
  70. if (nw != 0) {
  71. goto L10;
  72. }
  73. yr[i__] = csr;
  74. yi[i__] = csi;
  75. ic = i__;
  76. --(*nz);
  77. L10:
  78. ;
  79. }
  80. if (*n == 1) {
  81. return 0;
  82. }
  83. if (ic > 1) {
  84. goto L20;
  85. }
  86. yr[1] = zeror;
  87. yi[1] = zeroi;
  88. *nz = 2;
  89. L20:
  90. if (*n == 2) {
  91. return 0;
  92. }
  93. if (*nz == 0) {
  94. return 0;
  95. }
  96. fn = *fnu + 1.;
  97. ckr = fn * *rzr;
  98. cki = fn * *rzi;
  99. s1r = cyr[0];
  100. s1i = cyi[0];
  101. s2r = cyr[1];
  102. s2i = cyi[1];
  103. helim = *elim * .5;
  104. elm = exp(-(*elim));
  105. celmr = elm;
  106. zdr = *zrr;
  107. zdi = *zri;
  108. /* FIND TWO CONSECUTIVE Y VALUES ON SCALE. SCALE RECURRENCE IF */
  109. /* S2 GETS LARGER THAN EXP(ELIM/2) */
  110. i__1 = *n;
  111. for (i__ = 3; i__ <= i__1; ++i__) {
  112. kk = i__;
  113. csr = s2r;
  114. csi = s2i;
  115. s2r = ckr * csr - cki * csi + s1r;
  116. s2i = cki * csr + ckr * csi + s1i;
  117. s1r = csr;
  118. s1i = csi;
  119. ckr += *rzr;
  120. cki += *rzi;
  121. as = zabs_(&s2r, &s2i);
  122. alas = log(as);
  123. acs = -zdr + alas;
  124. ++(*nz);
  125. yr[i__] = zeror;
  126. yi[i__] = zeroi;
  127. if (acs < -(*elim)) {
  128. goto L25;
  129. }
  130. zlog_(&s2r, &s2i, &csr, &csi, &idum);
  131. csr -= zdr;
  132. csi -= zdi;
  133. str = exp(csr) / *tol;
  134. csr = str * cos(csi);
  135. csi = str * sin(csi);
  136. zuchk_(&csr, &csi, &nw, ascle, tol);
  137. if (nw != 0) {
  138. goto L25;
  139. }
  140. yr[i__] = csr;
  141. yi[i__] = csi;
  142. --(*nz);
  143. if (ic == kk - 1) {
  144. goto L40;
  145. }
  146. ic = kk;
  147. goto L30;
  148. L25:
  149. if (alas < helim) {
  150. goto L30;
  151. }
  152. zdr -= *elim;
  153. s1r *= celmr;
  154. s1i *= celmr;
  155. s2r *= celmr;
  156. s2i *= celmr;
  157. L30:
  158. ;
  159. }
  160. *nz = *n;
  161. if (ic == *n) {
  162. *nz = *n - 1;
  163. }
  164. goto L45;
  165. L40:
  166. *nz = kk - 2;
  167. L45:
  168. i__1 = *nz;
  169. for (i__ = 1; i__ <= i__1; ++i__) {
  170. yr[i__] = zeror;
  171. yi[i__] = zeroi;
  172. /* L50: */
  173. }
  174. return 0;
  175. } /* zkscl_ */