dtgsja.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626
  1. /* dtgsja.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. /* Table of constant values */
  14. static doublereal c_b13 = 0.;
  15. static doublereal c_b14 = 1.;
  16. static integer c__1 = 1;
  17. static doublereal c_b43 = -1.;
  18. /* Subroutine */ int dtgsja_(char *jobu, char *jobv, char *jobq, integer *m,
  19. integer *p, integer *n, integer *k, integer *l, doublereal *a,
  20. integer *lda, doublereal *b, integer *ldb, doublereal *tola,
  21. doublereal *tolb, doublereal *alpha, doublereal *beta, doublereal *u,
  22. integer *ldu, doublereal *v, integer *ldv, doublereal *q, integer *
  23. ldq, doublereal *work, integer *ncycle, integer *info)
  24. {
  25. /* System generated locals */
  26. integer a_dim1, a_offset, b_dim1, b_offset, q_dim1, q_offset, u_dim1,
  27. u_offset, v_dim1, v_offset, i__1, i__2, i__3, i__4;
  28. doublereal d__1;
  29. /* Local variables */
  30. integer i__, j;
  31. doublereal a1, a2, a3, b1, b2, b3, csq, csu, csv, snq, rwk, snu, snv;
  32. extern /* Subroutine */ int drot_(integer *, doublereal *, integer *,
  33. doublereal *, integer *, doublereal *, doublereal *);
  34. doublereal gamma;
  35. extern /* Subroutine */ int dscal_(integer *, doublereal *, doublereal *,
  36. integer *);
  37. extern logical lsame_(char *, char *);
  38. extern /* Subroutine */ int dcopy_(integer *, doublereal *, integer *,
  39. doublereal *, integer *);
  40. logical initq, initu, initv, wantq, upper;
  41. doublereal error, ssmin;
  42. logical wantu, wantv;
  43. extern /* Subroutine */ int dlags2_(logical *, doublereal *, doublereal *,
  44. doublereal *, doublereal *, doublereal *, doublereal *,
  45. doublereal *, doublereal *, doublereal *, doublereal *,
  46. doublereal *, doublereal *), dlapll_(integer *, doublereal *,
  47. integer *, doublereal *, integer *, doublereal *);
  48. integer kcycle;
  49. extern /* Subroutine */ int dlartg_(doublereal *, doublereal *,
  50. doublereal *, doublereal *, doublereal *), dlaset_(char *,
  51. integer *, integer *, doublereal *, doublereal *, doublereal *,
  52. integer *), xerbla_(char *, integer *);
  53. /* -- LAPACK routine (version 3.2) -- */
  54. /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
  55. /* November 2006 */
  56. /* .. Scalar Arguments .. */
  57. /* .. */
  58. /* .. Array Arguments .. */
  59. /* .. */
  60. /* Purpose */
  61. /* ======= */
  62. /* DTGSJA computes the generalized singular value decomposition (GSVD) */
  63. /* of two real upper triangular (or trapezoidal) matrices A and B. */
  64. /* On entry, it is assumed that matrices A and B have the following */
  65. /* forms, which may be obtained by the preprocessing subroutine DGGSVP */
  66. /* from a general M-by-N matrix A and P-by-N matrix B: */
  67. /* N-K-L K L */
  68. /* A = K ( 0 A12 A13 ) if M-K-L >= 0; */
  69. /* L ( 0 0 A23 ) */
  70. /* M-K-L ( 0 0 0 ) */
  71. /* N-K-L K L */
  72. /* A = K ( 0 A12 A13 ) if M-K-L < 0; */
  73. /* M-K ( 0 0 A23 ) */
  74. /* N-K-L K L */
  75. /* B = L ( 0 0 B13 ) */
  76. /* P-L ( 0 0 0 ) */
  77. /* where the K-by-K matrix A12 and L-by-L matrix B13 are nonsingular */
  78. /* upper triangular; A23 is L-by-L upper triangular if M-K-L >= 0, */
  79. /* otherwise A23 is (M-K)-by-L upper trapezoidal. */
  80. /* On exit, */
  81. /* U'*A*Q = D1*( 0 R ), V'*B*Q = D2*( 0 R ), */
  82. /* where U, V and Q are orthogonal matrices, Z' denotes the transpose */
  83. /* of Z, R is a nonsingular upper triangular matrix, and D1 and D2 are */
  84. /* ``diagonal'' matrices, which are of the following structures: */
  85. /* If M-K-L >= 0, */
  86. /* K L */
  87. /* D1 = K ( I 0 ) */
  88. /* L ( 0 C ) */
  89. /* M-K-L ( 0 0 ) */
  90. /* K L */
  91. /* D2 = L ( 0 S ) */
  92. /* P-L ( 0 0 ) */
  93. /* N-K-L K L */
  94. /* ( 0 R ) = K ( 0 R11 R12 ) K */
  95. /* L ( 0 0 R22 ) L */
  96. /* where */
  97. /* C = diag( ALPHA(K+1), ... , ALPHA(K+L) ), */
  98. /* S = diag( BETA(K+1), ... , BETA(K+L) ), */
  99. /* C**2 + S**2 = I. */
  100. /* R is stored in A(1:K+L,N-K-L+1:N) on exit. */
  101. /* If M-K-L < 0, */
  102. /* K M-K K+L-M */
  103. /* D1 = K ( I 0 0 ) */
  104. /* M-K ( 0 C 0 ) */
  105. /* K M-K K+L-M */
  106. /* D2 = M-K ( 0 S 0 ) */
  107. /* K+L-M ( 0 0 I ) */
  108. /* P-L ( 0 0 0 ) */
  109. /* N-K-L K M-K K+L-M */
  110. /* ( 0 R ) = K ( 0 R11 R12 R13 ) */
  111. /* M-K ( 0 0 R22 R23 ) */
  112. /* K+L-M ( 0 0 0 R33 ) */
  113. /* where */
  114. /* C = diag( ALPHA(K+1), ... , ALPHA(M) ), */
  115. /* S = diag( BETA(K+1), ... , BETA(M) ), */
  116. /* C**2 + S**2 = I. */
  117. /* R = ( R11 R12 R13 ) is stored in A(1:M, N-K-L+1:N) and R33 is stored */
  118. /* ( 0 R22 R23 ) */
  119. /* in B(M-K+1:L,N+M-K-L+1:N) on exit. */
  120. /* The computation of the orthogonal transformation matrices U, V or Q */
  121. /* is optional. These matrices may either be formed explicitly, or they */
  122. /* may be postmultiplied into input matrices U1, V1, or Q1. */
  123. /* Arguments */
  124. /* ========= */
  125. /* JOBU (input) CHARACTER*1 */
  126. /* = 'U': U must contain an orthogonal matrix U1 on entry, and */
  127. /* the product U1*U is returned; */
  128. /* = 'I': U is initialized to the unit matrix, and the */
  129. /* orthogonal matrix U is returned; */
  130. /* = 'N': U is not computed. */
  131. /* JOBV (input) CHARACTER*1 */
  132. /* = 'V': V must contain an orthogonal matrix V1 on entry, and */
  133. /* the product V1*V is returned; */
  134. /* = 'I': V is initialized to the unit matrix, and the */
  135. /* orthogonal matrix V is returned; */
  136. /* = 'N': V is not computed. */
  137. /* JOBQ (input) CHARACTER*1 */
  138. /* = 'Q': Q must contain an orthogonal matrix Q1 on entry, and */
  139. /* the product Q1*Q is returned; */
  140. /* = 'I': Q is initialized to the unit matrix, and the */
  141. /* orthogonal matrix Q is returned; */
  142. /* = 'N': Q is not computed. */
  143. /* M (input) INTEGER */
  144. /* The number of rows of the matrix A. M >= 0. */
  145. /* P (input) INTEGER */
  146. /* The number of rows of the matrix B. P >= 0. */
  147. /* N (input) INTEGER */
  148. /* The number of columns of the matrices A and B. N >= 0. */
  149. /* K (input) INTEGER */
  150. /* L (input) INTEGER */
  151. /* K and L specify the subblocks in the input matrices A and B: */
  152. /* A23 = A(K+1:MIN(K+L,M),N-L+1:N) and B13 = B(1:L,N-L+1:N) */
  153. /* of A and B, whose GSVD is going to be computed by DTGSJA. */
  154. /* See Further details. */
  155. /* A (input/output) DOUBLE PRECISION array, dimension (LDA,N) */
  156. /* On entry, the M-by-N matrix A. */
  157. /* On exit, A(N-K+1:N,1:MIN(K+L,M) ) contains the triangular */
  158. /* matrix R or part of R. See Purpose for details. */
  159. /* LDA (input) INTEGER */
  160. /* The leading dimension of the array A. LDA >= max(1,M). */
  161. /* B (input/output) DOUBLE PRECISION array, dimension (LDB,N) */
  162. /* On entry, the P-by-N matrix B. */
  163. /* On exit, if necessary, B(M-K+1:L,N+M-K-L+1:N) contains */
  164. /* a part of R. See Purpose for details. */
  165. /* LDB (input) INTEGER */
  166. /* The leading dimension of the array B. LDB >= max(1,P). */
  167. /* TOLA (input) DOUBLE PRECISION */
  168. /* TOLB (input) DOUBLE PRECISION */
  169. /* TOLA and TOLB are the convergence criteria for the Jacobi- */
  170. /* Kogbetliantz iteration procedure. Generally, they are the */
  171. /* same as used in the preprocessing step, say */
  172. /* TOLA = max(M,N)*norm(A)*MAZHEPS, */
  173. /* TOLB = max(P,N)*norm(B)*MAZHEPS. */
  174. /* ALPHA (output) DOUBLE PRECISION array, dimension (N) */
  175. /* BETA (output) DOUBLE PRECISION array, dimension (N) */
  176. /* On exit, ALPHA and BETA contain the generalized singular */
  177. /* value pairs of A and B; */
  178. /* ALPHA(1:K) = 1, */
  179. /* BETA(1:K) = 0, */
  180. /* and if M-K-L >= 0, */
  181. /* ALPHA(K+1:K+L) = diag(C), */
  182. /* BETA(K+1:K+L) = diag(S), */
  183. /* or if M-K-L < 0, */
  184. /* ALPHA(K+1:M)= C, ALPHA(M+1:K+L)= 0 */
  185. /* BETA(K+1:M) = S, BETA(M+1:K+L) = 1. */
  186. /* Furthermore, if K+L < N, */
  187. /* ALPHA(K+L+1:N) = 0 and */
  188. /* BETA(K+L+1:N) = 0. */
  189. /* U (input/output) DOUBLE PRECISION array, dimension (LDU,M) */
  190. /* On entry, if JOBU = 'U', U must contain a matrix U1 (usually */
  191. /* the orthogonal matrix returned by DGGSVP). */
  192. /* On exit, */
  193. /* if JOBU = 'I', U contains the orthogonal matrix U; */
  194. /* if JOBU = 'U', U contains the product U1*U. */
  195. /* If JOBU = 'N', U is not referenced. */
  196. /* LDU (input) INTEGER */
  197. /* The leading dimension of the array U. LDU >= max(1,M) if */
  198. /* JOBU = 'U'; LDU >= 1 otherwise. */
  199. /* V (input/output) DOUBLE PRECISION array, dimension (LDV,P) */
  200. /* On entry, if JOBV = 'V', V must contain a matrix V1 (usually */
  201. /* the orthogonal matrix returned by DGGSVP). */
  202. /* On exit, */
  203. /* if JOBV = 'I', V contains the orthogonal matrix V; */
  204. /* if JOBV = 'V', V contains the product V1*V. */
  205. /* If JOBV = 'N', V is not referenced. */
  206. /* LDV (input) INTEGER */
  207. /* The leading dimension of the array V. LDV >= max(1,P) if */
  208. /* JOBV = 'V'; LDV >= 1 otherwise. */
  209. /* Q (input/output) DOUBLE PRECISION array, dimension (LDQ,N) */
  210. /* On entry, if JOBQ = 'Q', Q must contain a matrix Q1 (usually */
  211. /* the orthogonal matrix returned by DGGSVP). */
  212. /* On exit, */
  213. /* if JOBQ = 'I', Q contains the orthogonal matrix Q; */
  214. /* if JOBQ = 'Q', Q contains the product Q1*Q. */
  215. /* If JOBQ = 'N', Q is not referenced. */
  216. /* LDQ (input) INTEGER */
  217. /* The leading dimension of the array Q. LDQ >= max(1,N) if */
  218. /* JOBQ = 'Q'; LDQ >= 1 otherwise. */
  219. /* WORK (workspace) DOUBLE PRECISION array, dimension (2*N) */
  220. /* NCYCLE (output) INTEGER */
  221. /* The number of cycles required for convergence. */
  222. /* INFO (output) INTEGER */
  223. /* = 0: successful exit */
  224. /* < 0: if INFO = -i, the i-th argument had an illegal value. */
  225. /* = 1: the procedure does not converge after MAXIT cycles. */
  226. /* Internal Parameters */
  227. /* =================== */
  228. /* MAXIT INTEGER */
  229. /* MAXIT specifies the total loops that the iterative procedure */
  230. /* may take. If after MAXIT cycles, the routine fails to */
  231. /* converge, we return INFO = 1. */
  232. /* Further Details */
  233. /* =============== */
  234. /* DTGSJA essentially uses a variant of Kogbetliantz algorithm to reduce */
  235. /* min(L,M-K)-by-L triangular (or trapezoidal) matrix A23 and L-by-L */
  236. /* matrix B13 to the form: */
  237. /* U1'*A13*Q1 = C1*R1; V1'*B13*Q1 = S1*R1, */
  238. /* where U1, V1 and Q1 are orthogonal matrix, and Z' is the transpose */
  239. /* of Z. C1 and S1 are diagonal matrices satisfying */
  240. /* C1**2 + S1**2 = I, */
  241. /* and R1 is an L-by-L nonsingular upper triangular matrix. */
  242. /* ===================================================================== */
  243. /* .. Parameters .. */
  244. /* .. */
  245. /* .. Local Scalars .. */
  246. /* .. */
  247. /* .. External Functions .. */
  248. /* .. */
  249. /* .. External Subroutines .. */
  250. /* .. */
  251. /* .. Intrinsic Functions .. */
  252. /* .. */
  253. /* .. Executable Statements .. */
  254. /* Decode and test the input parameters */
  255. /* Parameter adjustments */
  256. a_dim1 = *lda;
  257. a_offset = 1 + a_dim1;
  258. a -= a_offset;
  259. b_dim1 = *ldb;
  260. b_offset = 1 + b_dim1;
  261. b -= b_offset;
  262. --alpha;
  263. --beta;
  264. u_dim1 = *ldu;
  265. u_offset = 1 + u_dim1;
  266. u -= u_offset;
  267. v_dim1 = *ldv;
  268. v_offset = 1 + v_dim1;
  269. v -= v_offset;
  270. q_dim1 = *ldq;
  271. q_offset = 1 + q_dim1;
  272. q -= q_offset;
  273. --work;
  274. /* Function Body */
  275. initu = lsame_(jobu, "I");
  276. wantu = initu || lsame_(jobu, "U");
  277. initv = lsame_(jobv, "I");
  278. wantv = initv || lsame_(jobv, "V");
  279. initq = lsame_(jobq, "I");
  280. wantq = initq || lsame_(jobq, "Q");
  281. *info = 0;
  282. if (! (initu || wantu || lsame_(jobu, "N"))) {
  283. *info = -1;
  284. } else if (! (initv || wantv || lsame_(jobv, "N")))
  285. {
  286. *info = -2;
  287. } else if (! (initq || wantq || lsame_(jobq, "N")))
  288. {
  289. *info = -3;
  290. } else if (*m < 0) {
  291. *info = -4;
  292. } else if (*p < 0) {
  293. *info = -5;
  294. } else if (*n < 0) {
  295. *info = -6;
  296. } else if (*lda < max(1,*m)) {
  297. *info = -10;
  298. } else if (*ldb < max(1,*p)) {
  299. *info = -12;
  300. } else if (*ldu < 1 || wantu && *ldu < *m) {
  301. *info = -18;
  302. } else if (*ldv < 1 || wantv && *ldv < *p) {
  303. *info = -20;
  304. } else if (*ldq < 1 || wantq && *ldq < *n) {
  305. *info = -22;
  306. }
  307. if (*info != 0) {
  308. i__1 = -(*info);
  309. xerbla_("DTGSJA", &i__1);
  310. return 0;
  311. }
  312. /* Initialize U, V and Q, if necessary */
  313. if (initu) {
  314. dlaset_("Full", m, m, &c_b13, &c_b14, &u[u_offset], ldu);
  315. }
  316. if (initv) {
  317. dlaset_("Full", p, p, &c_b13, &c_b14, &v[v_offset], ldv);
  318. }
  319. if (initq) {
  320. dlaset_("Full", n, n, &c_b13, &c_b14, &q[q_offset], ldq);
  321. }
  322. /* Loop until convergence */
  323. upper = FALSE_;
  324. for (kcycle = 1; kcycle <= 40; ++kcycle) {
  325. upper = ! upper;
  326. i__1 = *l - 1;
  327. for (i__ = 1; i__ <= i__1; ++i__) {
  328. i__2 = *l;
  329. for (j = i__ + 1; j <= i__2; ++j) {
  330. a1 = 0.;
  331. a2 = 0.;
  332. a3 = 0.;
  333. if (*k + i__ <= *m) {
  334. a1 = a[*k + i__ + (*n - *l + i__) * a_dim1];
  335. }
  336. if (*k + j <= *m) {
  337. a3 = a[*k + j + (*n - *l + j) * a_dim1];
  338. }
  339. b1 = b[i__ + (*n - *l + i__) * b_dim1];
  340. b3 = b[j + (*n - *l + j) * b_dim1];
  341. if (upper) {
  342. if (*k + i__ <= *m) {
  343. a2 = a[*k + i__ + (*n - *l + j) * a_dim1];
  344. }
  345. b2 = b[i__ + (*n - *l + j) * b_dim1];
  346. } else {
  347. if (*k + j <= *m) {
  348. a2 = a[*k + j + (*n - *l + i__) * a_dim1];
  349. }
  350. b2 = b[j + (*n - *l + i__) * b_dim1];
  351. }
  352. dlags2_(&upper, &a1, &a2, &a3, &b1, &b2, &b3, &csu, &snu, &
  353. csv, &snv, &csq, &snq);
  354. /* Update (K+I)-th and (K+J)-th rows of matrix A: U'*A */
  355. if (*k + j <= *m) {
  356. drot_(l, &a[*k + j + (*n - *l + 1) * a_dim1], lda, &a[*k
  357. + i__ + (*n - *l + 1) * a_dim1], lda, &csu, &snu);
  358. }
  359. /* Update I-th and J-th rows of matrix B: V'*B */
  360. drot_(l, &b[j + (*n - *l + 1) * b_dim1], ldb, &b[i__ + (*n - *
  361. l + 1) * b_dim1], ldb, &csv, &snv);
  362. /* Update (N-L+I)-th and (N-L+J)-th columns of matrices */
  363. /* A and B: A*Q and B*Q */
  364. /* Computing MIN */
  365. i__4 = *k + *l;
  366. i__3 = min(i__4,*m);
  367. drot_(&i__3, &a[(*n - *l + j) * a_dim1 + 1], &c__1, &a[(*n - *
  368. l + i__) * a_dim1 + 1], &c__1, &csq, &snq);
  369. drot_(l, &b[(*n - *l + j) * b_dim1 + 1], &c__1, &b[(*n - *l +
  370. i__) * b_dim1 + 1], &c__1, &csq, &snq);
  371. if (upper) {
  372. if (*k + i__ <= *m) {
  373. a[*k + i__ + (*n - *l + j) * a_dim1] = 0.;
  374. }
  375. b[i__ + (*n - *l + j) * b_dim1] = 0.;
  376. } else {
  377. if (*k + j <= *m) {
  378. a[*k + j + (*n - *l + i__) * a_dim1] = 0.;
  379. }
  380. b[j + (*n - *l + i__) * b_dim1] = 0.;
  381. }
  382. /* Update orthogonal matrices U, V, Q, if desired. */
  383. if (wantu && *k + j <= *m) {
  384. drot_(m, &u[(*k + j) * u_dim1 + 1], &c__1, &u[(*k + i__) *
  385. u_dim1 + 1], &c__1, &csu, &snu);
  386. }
  387. if (wantv) {
  388. drot_(p, &v[j * v_dim1 + 1], &c__1, &v[i__ * v_dim1 + 1],
  389. &c__1, &csv, &snv);
  390. }
  391. if (wantq) {
  392. drot_(n, &q[(*n - *l + j) * q_dim1 + 1], &c__1, &q[(*n - *
  393. l + i__) * q_dim1 + 1], &c__1, &csq, &snq);
  394. }
  395. /* L10: */
  396. }
  397. /* L20: */
  398. }
  399. if (! upper) {
  400. /* The matrices A13 and B13 were lower triangular at the start */
  401. /* of the cycle, and are now upper triangular. */
  402. /* Convergence test: test the parallelism of the corresponding */
  403. /* rows of A and B. */
  404. error = 0.;
  405. /* Computing MIN */
  406. i__2 = *l, i__3 = *m - *k;
  407. i__1 = min(i__2,i__3);
  408. for (i__ = 1; i__ <= i__1; ++i__) {
  409. i__2 = *l - i__ + 1;
  410. dcopy_(&i__2, &a[*k + i__ + (*n - *l + i__) * a_dim1], lda, &
  411. work[1], &c__1);
  412. i__2 = *l - i__ + 1;
  413. dcopy_(&i__2, &b[i__ + (*n - *l + i__) * b_dim1], ldb, &work[*
  414. l + 1], &c__1);
  415. i__2 = *l - i__ + 1;
  416. dlapll_(&i__2, &work[1], &c__1, &work[*l + 1], &c__1, &ssmin);
  417. error = max(error,ssmin);
  418. /* L30: */
  419. }
  420. if (abs(error) <= min(*tola,*tolb)) {
  421. goto L50;
  422. }
  423. }
  424. /* End of cycle loop */
  425. /* L40: */
  426. }
  427. /* The algorithm has not converged after MAXIT cycles. */
  428. *info = 1;
  429. goto L100;
  430. L50:
  431. /* If ERROR <= MIN(TOLA,TOLB), then the algorithm has converged. */
  432. /* Compute the generalized singular value pairs (ALPHA, BETA), and */
  433. /* set the triangular matrix R to array A. */
  434. i__1 = *k;
  435. for (i__ = 1; i__ <= i__1; ++i__) {
  436. alpha[i__] = 1.;
  437. beta[i__] = 0.;
  438. /* L60: */
  439. }
  440. /* Computing MIN */
  441. i__2 = *l, i__3 = *m - *k;
  442. i__1 = min(i__2,i__3);
  443. for (i__ = 1; i__ <= i__1; ++i__) {
  444. a1 = a[*k + i__ + (*n - *l + i__) * a_dim1];
  445. b1 = b[i__ + (*n - *l + i__) * b_dim1];
  446. if (a1 != 0.) {
  447. gamma = b1 / a1;
  448. /* change sign if necessary */
  449. if (gamma < 0.) {
  450. i__2 = *l - i__ + 1;
  451. dscal_(&i__2, &c_b43, &b[i__ + (*n - *l + i__) * b_dim1], ldb)
  452. ;
  453. if (wantv) {
  454. dscal_(p, &c_b43, &v[i__ * v_dim1 + 1], &c__1);
  455. }
  456. }
  457. d__1 = abs(gamma);
  458. dlartg_(&d__1, &c_b14, &beta[*k + i__], &alpha[*k + i__], &rwk);
  459. if (alpha[*k + i__] >= beta[*k + i__]) {
  460. i__2 = *l - i__ + 1;
  461. d__1 = 1. / alpha[*k + i__];
  462. dscal_(&i__2, &d__1, &a[*k + i__ + (*n - *l + i__) * a_dim1],
  463. lda);
  464. } else {
  465. i__2 = *l - i__ + 1;
  466. d__1 = 1. / beta[*k + i__];
  467. dscal_(&i__2, &d__1, &b[i__ + (*n - *l + i__) * b_dim1], ldb);
  468. i__2 = *l - i__ + 1;
  469. dcopy_(&i__2, &b[i__ + (*n - *l + i__) * b_dim1], ldb, &a[*k
  470. + i__ + (*n - *l + i__) * a_dim1], lda);
  471. }
  472. } else {
  473. alpha[*k + i__] = 0.;
  474. beta[*k + i__] = 1.;
  475. i__2 = *l - i__ + 1;
  476. dcopy_(&i__2, &b[i__ + (*n - *l + i__) * b_dim1], ldb, &a[*k +
  477. i__ + (*n - *l + i__) * a_dim1], lda);
  478. }
  479. /* L70: */
  480. }
  481. /* Post-assignment */
  482. i__1 = *k + *l;
  483. for (i__ = *m + 1; i__ <= i__1; ++i__) {
  484. alpha[i__] = 0.;
  485. beta[i__] = 1.;
  486. /* L80: */
  487. }
  488. if (*k + *l < *n) {
  489. i__1 = *n;
  490. for (i__ = *k + *l + 1; i__ <= i__1; ++i__) {
  491. alpha[i__] = 0.;
  492. beta[i__] = 0.;
  493. /* L90: */
  494. }
  495. }
  496. L100:
  497. *ncycle = kcycle;
  498. return 0;
  499. /* End of DTGSJA */
  500. } /* dtgsja_ */