dlascl.c 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  1. /* dlascl.f -- translated by f2c (version 20061008).
  2. You must link the resulting object file with libf2c:
  3. on Microsoft Windows system, link with libf2c.lib;
  4. on Linux or Unix systems, link with .../path/to/libf2c.a -lm
  5. or, if you install libf2c.a in a standard place, with -lf2c -lm
  6. -- in that order, at the end of the command line, as in
  7. cc *.o -lf2c -lm
  8. Source for libf2c is in /netlib/f2c/libf2c.zip, e.g.,
  9. http://www.netlib.org/f2c/libf2c.zip
  10. */
  11. #include "f2c.h"
  12. #include "blaswrap.h"
  13. /* Subroutine */ int dlascl_(char *type__, integer *kl, integer *ku,
  14. doublereal *cfrom, doublereal *cto, integer *m, integer *n,
  15. doublereal *a, integer *lda, integer *info)
  16. {
  17. /* System generated locals */
  18. integer a_dim1, a_offset, i__1, i__2, i__3, i__4, i__5;
  19. /* Local variables */
  20. integer i__, j, k1, k2, k3, k4;
  21. doublereal mul, cto1;
  22. logical done;
  23. doublereal ctoc;
  24. extern logical lsame_(char *, char *);
  25. integer itype;
  26. doublereal cfrom1;
  27. extern doublereal dlamch_(char *);
  28. doublereal cfromc;
  29. extern logical disnan_(doublereal *);
  30. extern /* Subroutine */ int xerbla_(char *, integer *);
  31. doublereal bignum, smlnum;
  32. /* -- LAPACK auxiliary routine (version 3.2) -- */
  33. /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
  34. /* November 2006 */
  35. /* .. Scalar Arguments .. */
  36. /* .. */
  37. /* .. Array Arguments .. */
  38. /* .. */
  39. /* Purpose */
  40. /* ======= */
  41. /* DLASCL multiplies the M by N real matrix A by the real scalar */
  42. /* CTO/CFROM. This is done without over/underflow as long as the final */
  43. /* result CTO*A(I,J)/CFROM does not over/underflow. TYPE specifies that */
  44. /* A may be full, upper triangular, lower triangular, upper Hessenberg, */
  45. /* or banded. */
  46. /* Arguments */
  47. /* ========= */
  48. /* TYPE (input) CHARACTER*1 */
  49. /* TYPE indices the storage type of the input matrix. */
  50. /* = 'G': A is a full matrix. */
  51. /* = 'L': A is a lower triangular matrix. */
  52. /* = 'U': A is an upper triangular matrix. */
  53. /* = 'H': A is an upper Hessenberg matrix. */
  54. /* = 'B': A is a symmetric band matrix with lower bandwidth KL */
  55. /* and upper bandwidth KU and with the only the lower */
  56. /* half stored. */
  57. /* = 'Q': A is a symmetric band matrix with lower bandwidth KL */
  58. /* and upper bandwidth KU and with the only the upper */
  59. /* half stored. */
  60. /* = 'Z': A is a band matrix with lower bandwidth KL and upper */
  61. /* bandwidth KU. */
  62. /* KL (input) INTEGER */
  63. /* The lower bandwidth of A. Referenced only if TYPE = 'B', */
  64. /* 'Q' or 'Z'. */
  65. /* KU (input) INTEGER */
  66. /* The upper bandwidth of A. Referenced only if TYPE = 'B', */
  67. /* 'Q' or 'Z'. */
  68. /* CFROM (input) DOUBLE PRECISION */
  69. /* CTO (input) DOUBLE PRECISION */
  70. /* The matrix A is multiplied by CTO/CFROM. A(I,J) is computed */
  71. /* without over/underflow if the final result CTO*A(I,J)/CFROM */
  72. /* can be represented without over/underflow. CFROM must be */
  73. /* nonzero. */
  74. /* M (input) INTEGER */
  75. /* The number of rows of the matrix A. M >= 0. */
  76. /* N (input) INTEGER */
  77. /* The number of columns of the matrix A. N >= 0. */
  78. /* A (input/output) DOUBLE PRECISION array, dimension (LDA,N) */
  79. /* The matrix to be multiplied by CTO/CFROM. See TYPE for the */
  80. /* storage type. */
  81. /* LDA (input) INTEGER */
  82. /* The leading dimension of the array A. LDA >= max(1,M). */
  83. /* INFO (output) INTEGER */
  84. /* 0 - successful exit */
  85. /* <0 - if INFO = -i, the i-th argument had an illegal value. */
  86. /* ===================================================================== */
  87. /* .. Parameters .. */
  88. /* .. */
  89. /* .. Local Scalars .. */
  90. /* .. */
  91. /* .. External Functions .. */
  92. /* .. */
  93. /* .. Intrinsic Functions .. */
  94. /* .. */
  95. /* .. External Subroutines .. */
  96. /* .. */
  97. /* .. Executable Statements .. */
  98. /* Test the input arguments */
  99. /* Parameter adjustments */
  100. a_dim1 = *lda;
  101. a_offset = 1 + a_dim1;
  102. a -= a_offset;
  103. /* Function Body */
  104. *info = 0;
  105. if (lsame_(type__, "G")) {
  106. itype = 0;
  107. } else if (lsame_(type__, "L")) {
  108. itype = 1;
  109. } else if (lsame_(type__, "U")) {
  110. itype = 2;
  111. } else if (lsame_(type__, "H")) {
  112. itype = 3;
  113. } else if (lsame_(type__, "B")) {
  114. itype = 4;
  115. } else if (lsame_(type__, "Q")) {
  116. itype = 5;
  117. } else if (lsame_(type__, "Z")) {
  118. itype = 6;
  119. } else {
  120. itype = -1;
  121. }
  122. if (itype == -1) {
  123. *info = -1;
  124. } else if (*cfrom == 0. || disnan_(cfrom)) {
  125. *info = -4;
  126. } else if (disnan_(cto)) {
  127. *info = -5;
  128. } else if (*m < 0) {
  129. *info = -6;
  130. } else if (*n < 0 || itype == 4 && *n != *m || itype == 5 && *n != *m) {
  131. *info = -7;
  132. } else if (itype <= 3 && *lda < max(1,*m)) {
  133. *info = -9;
  134. } else if (itype >= 4) {
  135. /* Computing MAX */
  136. i__1 = *m - 1;
  137. if (*kl < 0 || *kl > max(i__1,0)) {
  138. *info = -2;
  139. } else /* if(complicated condition) */ {
  140. /* Computing MAX */
  141. i__1 = *n - 1;
  142. if (*ku < 0 || *ku > max(i__1,0) || (itype == 4 || itype == 5) &&
  143. *kl != *ku) {
  144. *info = -3;
  145. } else if (itype == 4 && *lda < *kl + 1 || itype == 5 && *lda < *
  146. ku + 1 || itype == 6 && *lda < (*kl << 1) + *ku + 1) {
  147. *info = -9;
  148. }
  149. }
  150. }
  151. if (*info != 0) {
  152. i__1 = -(*info);
  153. xerbla_("DLASCL", &i__1);
  154. return 0;
  155. }
  156. /* Quick return if possible */
  157. if (*n == 0 || *m == 0) {
  158. return 0;
  159. }
  160. /* Get machine parameters */
  161. smlnum = dlamch_("S");
  162. bignum = 1. / smlnum;
  163. cfromc = *cfrom;
  164. ctoc = *cto;
  165. L10:
  166. cfrom1 = cfromc * smlnum;
  167. if (cfrom1 == cfromc) {
  168. /* CFROMC is an inf. Multiply by a correctly signed zero for */
  169. /* finite CTOC, or a NaN if CTOC is infinite. */
  170. mul = ctoc / cfromc;
  171. done = TRUE_;
  172. cto1 = ctoc;
  173. } else {
  174. cto1 = ctoc / bignum;
  175. if (cto1 == ctoc) {
  176. /* CTOC is either 0 or an inf. In both cases, CTOC itself */
  177. /* serves as the correct multiplication factor. */
  178. mul = ctoc;
  179. done = TRUE_;
  180. cfromc = 1.;
  181. } else if (abs(cfrom1) > abs(ctoc) && ctoc != 0.) {
  182. mul = smlnum;
  183. done = FALSE_;
  184. cfromc = cfrom1;
  185. } else if (abs(cto1) > abs(cfromc)) {
  186. mul = bignum;
  187. done = FALSE_;
  188. ctoc = cto1;
  189. } else {
  190. mul = ctoc / cfromc;
  191. done = TRUE_;
  192. }
  193. }
  194. if (itype == 0) {
  195. /* Full matrix */
  196. i__1 = *n;
  197. for (j = 1; j <= i__1; ++j) {
  198. i__2 = *m;
  199. for (i__ = 1; i__ <= i__2; ++i__) {
  200. a[i__ + j * a_dim1] *= mul;
  201. /* L20: */
  202. }
  203. /* L30: */
  204. }
  205. } else if (itype == 1) {
  206. /* Lower triangular matrix */
  207. i__1 = *n;
  208. for (j = 1; j <= i__1; ++j) {
  209. i__2 = *m;
  210. for (i__ = j; i__ <= i__2; ++i__) {
  211. a[i__ + j * a_dim1] *= mul;
  212. /* L40: */
  213. }
  214. /* L50: */
  215. }
  216. } else if (itype == 2) {
  217. /* Upper triangular matrix */
  218. i__1 = *n;
  219. for (j = 1; j <= i__1; ++j) {
  220. i__2 = min(j,*m);
  221. for (i__ = 1; i__ <= i__2; ++i__) {
  222. a[i__ + j * a_dim1] *= mul;
  223. /* L60: */
  224. }
  225. /* L70: */
  226. }
  227. } else if (itype == 3) {
  228. /* Upper Hessenberg matrix */
  229. i__1 = *n;
  230. for (j = 1; j <= i__1; ++j) {
  231. /* Computing MIN */
  232. i__3 = j + 1;
  233. i__2 = min(i__3,*m);
  234. for (i__ = 1; i__ <= i__2; ++i__) {
  235. a[i__ + j * a_dim1] *= mul;
  236. /* L80: */
  237. }
  238. /* L90: */
  239. }
  240. } else if (itype == 4) {
  241. /* Lower half of a symmetric band matrix */
  242. k3 = *kl + 1;
  243. k4 = *n + 1;
  244. i__1 = *n;
  245. for (j = 1; j <= i__1; ++j) {
  246. /* Computing MIN */
  247. i__3 = k3, i__4 = k4 - j;
  248. i__2 = min(i__3,i__4);
  249. for (i__ = 1; i__ <= i__2; ++i__) {
  250. a[i__ + j * a_dim1] *= mul;
  251. /* L100: */
  252. }
  253. /* L110: */
  254. }
  255. } else if (itype == 5) {
  256. /* Upper half of a symmetric band matrix */
  257. k1 = *ku + 2;
  258. k3 = *ku + 1;
  259. i__1 = *n;
  260. for (j = 1; j <= i__1; ++j) {
  261. /* Computing MAX */
  262. i__2 = k1 - j;
  263. i__3 = k3;
  264. for (i__ = max(i__2,1); i__ <= i__3; ++i__) {
  265. a[i__ + j * a_dim1] *= mul;
  266. /* L120: */
  267. }
  268. /* L130: */
  269. }
  270. } else if (itype == 6) {
  271. /* Band matrix */
  272. k1 = *kl + *ku + 2;
  273. k2 = *kl + 1;
  274. k3 = (*kl << 1) + *ku + 1;
  275. k4 = *kl + *ku + 1 + *m;
  276. i__1 = *n;
  277. for (j = 1; j <= i__1; ++j) {
  278. /* Computing MAX */
  279. i__3 = k1 - j;
  280. /* Computing MIN */
  281. i__4 = k3, i__5 = k4 - j;
  282. i__2 = min(i__4,i__5);
  283. for (i__ = max(i__3,k2); i__ <= i__2; ++i__) {
  284. a[i__ + j * a_dim1] *= mul;
  285. /* L140: */
  286. }
  287. /* L150: */
  288. }
  289. }
  290. if (! done) {
  291. goto L10;
  292. }
  293. return 0;
  294. /* End of DLASCL */
  295. } /* dlascl_ */