You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

stgsja.f 20 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653
  1. *> \brief \b STGSJA
  2. *
  3. * =========== DOCUMENTATION ===========
  4. *
  5. * Online html documentation available at
  6. * http://www.netlib.org/lapack/explore-html/
  7. *
  8. *> \htmlonly
  9. *> Download STGSJA + dependencies
  10. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/stgsja.f">
  11. *> [TGZ]</a>
  12. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/stgsja.f">
  13. *> [ZIP]</a>
  14. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/stgsja.f">
  15. *> [TXT]</a>
  16. *> \endhtmlonly
  17. *
  18. * Definition:
  19. * ===========
  20. *
  21. * SUBROUTINE STGSJA( JOBU, JOBV, JOBQ, M, P, N, K, L, A, LDA, B,
  22. * LDB, TOLA, TOLB, ALPHA, BETA, U, LDU, V, LDV,
  23. * Q, LDQ, WORK, NCYCLE, INFO )
  24. *
  25. * .. Scalar Arguments ..
  26. * CHARACTER JOBQ, JOBU, JOBV
  27. * INTEGER INFO, K, L, LDA, LDB, LDQ, LDU, LDV, M, N,
  28. * $ NCYCLE, P
  29. * REAL TOLA, TOLB
  30. * ..
  31. * .. Array Arguments ..
  32. * REAL A( LDA, * ), ALPHA( * ), B( LDB, * ),
  33. * $ BETA( * ), Q( LDQ, * ), U( LDU, * ),
  34. * $ V( LDV, * ), WORK( * )
  35. * ..
  36. *
  37. *
  38. *> \par Purpose:
  39. * =============
  40. *>
  41. *> \verbatim
  42. *>
  43. *> STGSJA computes the generalized singular value decomposition (GSVD)
  44. *> of two real upper triangular (or trapezoidal) matrices A and B.
  45. *>
  46. *> On entry, it is assumed that matrices A and B have the following
  47. *> forms, which may be obtained by the preprocessing subroutine SGGSVP
  48. *> from a general M-by-N matrix A and P-by-N matrix B:
  49. *>
  50. *> N-K-L K L
  51. *> A = K ( 0 A12 A13 ) if M-K-L >= 0;
  52. *> L ( 0 0 A23 )
  53. *> M-K-L ( 0 0 0 )
  54. *>
  55. *> N-K-L K L
  56. *> A = K ( 0 A12 A13 ) if M-K-L < 0;
  57. *> M-K ( 0 0 A23 )
  58. *>
  59. *> N-K-L K L
  60. *> B = L ( 0 0 B13 )
  61. *> P-L ( 0 0 0 )
  62. *>
  63. *> where the K-by-K matrix A12 and L-by-L matrix B13 are nonsingular
  64. *> upper triangular; A23 is L-by-L upper triangular if M-K-L >= 0,
  65. *> otherwise A23 is (M-K)-by-L upper trapezoidal.
  66. *>
  67. *> On exit,
  68. *>
  69. *> U**T *A*Q = D1*( 0 R ), V**T *B*Q = D2*( 0 R ),
  70. *>
  71. *> where U, V and Q are orthogonal matrices.
  72. *> R is a nonsingular upper triangular matrix, and D1 and D2 are
  73. *> ``diagonal'' matrices, which are of the following structures:
  74. *>
  75. *> If M-K-L >= 0,
  76. *>
  77. *> K L
  78. *> D1 = K ( I 0 )
  79. *> L ( 0 C )
  80. *> M-K-L ( 0 0 )
  81. *>
  82. *> K L
  83. *> D2 = L ( 0 S )
  84. *> P-L ( 0 0 )
  85. *>
  86. *> N-K-L K L
  87. *> ( 0 R ) = K ( 0 R11 R12 ) K
  88. *> L ( 0 0 R22 ) L
  89. *>
  90. *> where
  91. *>
  92. *> C = diag( ALPHA(K+1), ... , ALPHA(K+L) ),
  93. *> S = diag( BETA(K+1), ... , BETA(K+L) ),
  94. *> C**2 + S**2 = I.
  95. *>
  96. *> R is stored in A(1:K+L,N-K-L+1:N) on exit.
  97. *>
  98. *> If M-K-L < 0,
  99. *>
  100. *> K M-K K+L-M
  101. *> D1 = K ( I 0 0 )
  102. *> M-K ( 0 C 0 )
  103. *>
  104. *> K M-K K+L-M
  105. *> D2 = M-K ( 0 S 0 )
  106. *> K+L-M ( 0 0 I )
  107. *> P-L ( 0 0 0 )
  108. *>
  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. *>
  114. *> where
  115. *> C = diag( ALPHA(K+1), ... , ALPHA(M) ),
  116. *> S = diag( BETA(K+1), ... , BETA(M) ),
  117. *> C**2 + S**2 = I.
  118. *>
  119. *> R = ( R11 R12 R13 ) is stored in A(1:M, N-K-L+1:N) and R33 is stored
  120. *> ( 0 R22 R23 )
  121. *> in B(M-K+1:L,N+M-K-L+1:N) on exit.
  122. *>
  123. *> The computation of the orthogonal transformation matrices U, V or Q
  124. *> is optional. These matrices may either be formed explicitly, or they
  125. *> may be postmultiplied into input matrices U1, V1, or Q1.
  126. *> \endverbatim
  127. *
  128. * Arguments:
  129. * ==========
  130. *
  131. *> \param[in] JOBU
  132. *> \verbatim
  133. *> JOBU is CHARACTER*1
  134. *> = 'U': U must contain an orthogonal matrix U1 on entry, and
  135. *> the product U1*U is returned;
  136. *> = 'I': U is initialized to the unit matrix, and the
  137. *> orthogonal matrix U is returned;
  138. *> = 'N': U is not computed.
  139. *> \endverbatim
  140. *>
  141. *> \param[in] JOBV
  142. *> \verbatim
  143. *> JOBV is CHARACTER*1
  144. *> = 'V': V must contain an orthogonal matrix V1 on entry, and
  145. *> the product V1*V is returned;
  146. *> = 'I': V is initialized to the unit matrix, and the
  147. *> orthogonal matrix V is returned;
  148. *> = 'N': V is not computed.
  149. *> \endverbatim
  150. *>
  151. *> \param[in] JOBQ
  152. *> \verbatim
  153. *> JOBQ is CHARACTER*1
  154. *> = 'Q': Q must contain an orthogonal matrix Q1 on entry, and
  155. *> the product Q1*Q is returned;
  156. *> = 'I': Q is initialized to the unit matrix, and the
  157. *> orthogonal matrix Q is returned;
  158. *> = 'N': Q is not computed.
  159. *> \endverbatim
  160. *>
  161. *> \param[in] M
  162. *> \verbatim
  163. *> M is INTEGER
  164. *> The number of rows of the matrix A. M >= 0.
  165. *> \endverbatim
  166. *>
  167. *> \param[in] P
  168. *> \verbatim
  169. *> P is INTEGER
  170. *> The number of rows of the matrix B. P >= 0.
  171. *> \endverbatim
  172. *>
  173. *> \param[in] N
  174. *> \verbatim
  175. *> N is INTEGER
  176. *> The number of columns of the matrices A and B. N >= 0.
  177. *> \endverbatim
  178. *>
  179. *> \param[in] K
  180. *> \verbatim
  181. *> K is INTEGER
  182. *> \endverbatim
  183. *>
  184. *> \param[in] L
  185. *> \verbatim
  186. *> L is INTEGER
  187. *>
  188. *> K and L specify the subblocks in the input matrices A and B:
  189. *> A23 = A(K+1:MIN(K+L,M),N-L+1:N) and B13 = B(1:L,N-L+1:N)
  190. *> of A and B, whose GSVD is going to be computed by STGSJA.
  191. *> See Further Details.
  192. *> \endverbatim
  193. *>
  194. *> \param[in,out] A
  195. *> \verbatim
  196. *> A is REAL array, dimension (LDA,N)
  197. *> On entry, the M-by-N matrix A.
  198. *> On exit, A(N-K+1:N,1:MIN(K+L,M) ) contains the triangular
  199. *> matrix R or part of R. See Purpose for details.
  200. *> \endverbatim
  201. *>
  202. *> \param[in] LDA
  203. *> \verbatim
  204. *> LDA is INTEGER
  205. *> The leading dimension of the array A. LDA >= max(1,M).
  206. *> \endverbatim
  207. *>
  208. *> \param[in,out] B
  209. *> \verbatim
  210. *> B is REAL array, dimension (LDB,N)
  211. *> On entry, the P-by-N matrix B.
  212. *> On exit, if necessary, B(M-K+1:L,N+M-K-L+1:N) contains
  213. *> a part of R. See Purpose for details.
  214. *> \endverbatim
  215. *>
  216. *> \param[in] LDB
  217. *> \verbatim
  218. *> LDB is INTEGER
  219. *> The leading dimension of the array B. LDB >= max(1,P).
  220. *> \endverbatim
  221. *>
  222. *> \param[in] TOLA
  223. *> \verbatim
  224. *> TOLA is REAL
  225. *> \endverbatim
  226. *>
  227. *> \param[in] TOLB
  228. *> \verbatim
  229. *> TOLB is REAL
  230. *>
  231. *> TOLA and TOLB are the convergence criteria for the Jacobi-
  232. *> Kogbetliantz iteration procedure. Generally, they are the
  233. *> same as used in the preprocessing step, say
  234. *> TOLA = max(M,N)*norm(A)*MACHEPS,
  235. *> TOLB = max(P,N)*norm(B)*MACHEPS.
  236. *> \endverbatim
  237. *>
  238. *> \param[out] ALPHA
  239. *> \verbatim
  240. *> ALPHA is REAL array, dimension (N)
  241. *> \endverbatim
  242. *>
  243. *> \param[out] BETA
  244. *> \verbatim
  245. *> BETA is REAL array, dimension (N)
  246. *>
  247. *> On exit, ALPHA and BETA contain the generalized singular
  248. *> value pairs of A and B;
  249. *> ALPHA(1:K) = 1,
  250. *> BETA(1:K) = 0,
  251. *> and if M-K-L >= 0,
  252. *> ALPHA(K+1:K+L) = diag(C),
  253. *> BETA(K+1:K+L) = diag(S),
  254. *> or if M-K-L < 0,
  255. *> ALPHA(K+1:M)= C, ALPHA(M+1:K+L)= 0
  256. *> BETA(K+1:M) = S, BETA(M+1:K+L) = 1.
  257. *> Furthermore, if K+L < N,
  258. *> ALPHA(K+L+1:N) = 0 and
  259. *> BETA(K+L+1:N) = 0.
  260. *> \endverbatim
  261. *>
  262. *> \param[in,out] U
  263. *> \verbatim
  264. *> U is REAL array, dimension (LDU,M)
  265. *> On entry, if JOBU = 'U', U must contain a matrix U1 (usually
  266. *> the orthogonal matrix returned by SGGSVP).
  267. *> On exit,
  268. *> if JOBU = 'I', U contains the orthogonal matrix U;
  269. *> if JOBU = 'U', U contains the product U1*U.
  270. *> If JOBU = 'N', U is not referenced.
  271. *> \endverbatim
  272. *>
  273. *> \param[in] LDU
  274. *> \verbatim
  275. *> LDU is INTEGER
  276. *> The leading dimension of the array U. LDU >= max(1,M) if
  277. *> JOBU = 'U'; LDU >= 1 otherwise.
  278. *> \endverbatim
  279. *>
  280. *> \param[in,out] V
  281. *> \verbatim
  282. *> V is REAL array, dimension (LDV,P)
  283. *> On entry, if JOBV = 'V', V must contain a matrix V1 (usually
  284. *> the orthogonal matrix returned by SGGSVP).
  285. *> On exit,
  286. *> if JOBV = 'I', V contains the orthogonal matrix V;
  287. *> if JOBV = 'V', V contains the product V1*V.
  288. *> If JOBV = 'N', V is not referenced.
  289. *> \endverbatim
  290. *>
  291. *> \param[in] LDV
  292. *> \verbatim
  293. *> LDV is INTEGER
  294. *> The leading dimension of the array V. LDV >= max(1,P) if
  295. *> JOBV = 'V'; LDV >= 1 otherwise.
  296. *> \endverbatim
  297. *>
  298. *> \param[in,out] Q
  299. *> \verbatim
  300. *> Q is REAL array, dimension (LDQ,N)
  301. *> On entry, if JOBQ = 'Q', Q must contain a matrix Q1 (usually
  302. *> the orthogonal matrix returned by SGGSVP).
  303. *> On exit,
  304. *> if JOBQ = 'I', Q contains the orthogonal matrix Q;
  305. *> if JOBQ = 'Q', Q contains the product Q1*Q.
  306. *> If JOBQ = 'N', Q is not referenced.
  307. *> \endverbatim
  308. *>
  309. *> \param[in] LDQ
  310. *> \verbatim
  311. *> LDQ is INTEGER
  312. *> The leading dimension of the array Q. LDQ >= max(1,N) if
  313. *> JOBQ = 'Q'; LDQ >= 1 otherwise.
  314. *> \endverbatim
  315. *>
  316. *> \param[out] WORK
  317. *> \verbatim
  318. *> WORK is REAL array, dimension (2*N)
  319. *> \endverbatim
  320. *>
  321. *> \param[out] NCYCLE
  322. *> \verbatim
  323. *> NCYCLE is INTEGER
  324. *> The number of cycles required for convergence.
  325. *> \endverbatim
  326. *>
  327. *> \param[out] INFO
  328. *> \verbatim
  329. *> INFO is INTEGER
  330. *> = 0: successful exit
  331. *> < 0: if INFO = -i, the i-th argument had an illegal value.
  332. *> = 1: the procedure does not converge after MAXIT cycles.
  333. *> \endverbatim
  334. *>
  335. *> \verbatim
  336. *> Internal Parameters
  337. *> ===================
  338. *>
  339. *> MAXIT INTEGER
  340. *> MAXIT specifies the total loops that the iterative procedure
  341. *> may take. If after MAXIT cycles, the routine fails to
  342. *> converge, we return INFO = 1.
  343. *> \endverbatim
  344. *
  345. * Authors:
  346. * ========
  347. *
  348. *> \author Univ. of Tennessee
  349. *> \author Univ. of California Berkeley
  350. *> \author Univ. of Colorado Denver
  351. *> \author NAG Ltd.
  352. *
  353. *> \ingroup realOTHERcomputational
  354. *
  355. *> \par Further Details:
  356. * =====================
  357. *>
  358. *> \verbatim
  359. *>
  360. *> STGSJA essentially uses a variant of Kogbetliantz algorithm to reduce
  361. *> min(L,M-K)-by-L triangular (or trapezoidal) matrix A23 and L-by-L
  362. *> matrix B13 to the form:
  363. *>
  364. *> U1**T *A13*Q1 = C1*R1; V1**T *B13*Q1 = S1*R1,
  365. *>
  366. *> where U1, V1 and Q1 are orthogonal matrix, and Z**T is the transpose
  367. *> of Z. C1 and S1 are diagonal matrices satisfying
  368. *>
  369. *> C1**2 + S1**2 = I,
  370. *>
  371. *> and R1 is an L-by-L nonsingular upper triangular matrix.
  372. *> \endverbatim
  373. *>
  374. * =====================================================================
  375. SUBROUTINE STGSJA( JOBU, JOBV, JOBQ, M, P, N, K, L, A, LDA, B,
  376. $ LDB, TOLA, TOLB, ALPHA, BETA, U, LDU, V, LDV,
  377. $ Q, LDQ, WORK, NCYCLE, INFO )
  378. *
  379. * -- LAPACK computational routine --
  380. * -- LAPACK is a software package provided by Univ. of Tennessee, --
  381. * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
  382. *
  383. * .. Scalar Arguments ..
  384. CHARACTER JOBQ, JOBU, JOBV
  385. INTEGER INFO, K, L, LDA, LDB, LDQ, LDU, LDV, M, N,
  386. $ NCYCLE, P
  387. REAL TOLA, TOLB
  388. * ..
  389. * .. Array Arguments ..
  390. REAL A( LDA, * ), ALPHA( * ), B( LDB, * ),
  391. $ BETA( * ), Q( LDQ, * ), U( LDU, * ),
  392. $ V( LDV, * ), WORK( * )
  393. * ..
  394. *
  395. * =====================================================================
  396. *
  397. * .. Parameters ..
  398. INTEGER MAXIT
  399. PARAMETER ( MAXIT = 40 )
  400. REAL ZERO, ONE, HUGENUM
  401. PARAMETER ( ZERO = 0.0E+0, ONE = 1.0E+0 )
  402. * ..
  403. * .. Local Scalars ..
  404. *
  405. LOGICAL INITQ, INITU, INITV, UPPER, WANTQ, WANTU, WANTV
  406. INTEGER I, J, KCYCLE
  407. REAL A1, A2, A3, B1, B2, B3, CSQ, CSU, CSV, ERROR,
  408. $ GAMMA, RWK, SNQ, SNU, SNV, SSMIN
  409. * ..
  410. * .. External Functions ..
  411. LOGICAL LSAME
  412. EXTERNAL LSAME
  413. * ..
  414. * .. External Subroutines ..
  415. EXTERNAL SCOPY, SLAGS2, SLAPLL, SLARTG, SLASET, SROT,
  416. $ SSCAL, XERBLA
  417. * ..
  418. * .. Intrinsic Functions ..
  419. INTRINSIC ABS, MAX, MIN, HUGE
  420. PARAMETER ( HUGENUM = HUGE(ZERO) )
  421. * ..
  422. * .. Executable Statements ..
  423. *
  424. * Decode and test the input parameters
  425. *
  426. INITU = LSAME( JOBU, 'I' )
  427. WANTU = INITU .OR. LSAME( JOBU, 'U' )
  428. *
  429. INITV = LSAME( JOBV, 'I' )
  430. WANTV = INITV .OR. LSAME( JOBV, 'V' )
  431. *
  432. INITQ = LSAME( JOBQ, 'I' )
  433. WANTQ = INITQ .OR. LSAME( JOBQ, 'Q' )
  434. *
  435. INFO = 0
  436. IF( .NOT.( INITU .OR. WANTU .OR. LSAME( JOBU, 'N' ) ) ) THEN
  437. INFO = -1
  438. ELSE IF( .NOT.( INITV .OR. WANTV .OR. LSAME( JOBV, 'N' ) ) ) THEN
  439. INFO = -2
  440. ELSE IF( .NOT.( INITQ .OR. WANTQ .OR. LSAME( JOBQ, 'N' ) ) ) THEN
  441. INFO = -3
  442. ELSE IF( M.LT.0 ) THEN
  443. INFO = -4
  444. ELSE IF( P.LT.0 ) THEN
  445. INFO = -5
  446. ELSE IF( N.LT.0 ) THEN
  447. INFO = -6
  448. ELSE IF( LDA.LT.MAX( 1, M ) ) THEN
  449. INFO = -10
  450. ELSE IF( LDB.LT.MAX( 1, P ) ) THEN
  451. INFO = -12
  452. ELSE IF( LDU.LT.1 .OR. ( WANTU .AND. LDU.LT.M ) ) THEN
  453. INFO = -18
  454. ELSE IF( LDV.LT.1 .OR. ( WANTV .AND. LDV.LT.P ) ) THEN
  455. INFO = -20
  456. ELSE IF( LDQ.LT.1 .OR. ( WANTQ .AND. LDQ.LT.N ) ) THEN
  457. INFO = -22
  458. END IF
  459. IF( INFO.NE.0 ) THEN
  460. CALL XERBLA( 'STGSJA', -INFO )
  461. RETURN
  462. END IF
  463. *
  464. * Initialize U, V and Q, if necessary
  465. *
  466. IF( INITU )
  467. $ CALL SLASET( 'Full', M, M, ZERO, ONE, U, LDU )
  468. IF( INITV )
  469. $ CALL SLASET( 'Full', P, P, ZERO, ONE, V, LDV )
  470. IF( INITQ )
  471. $ CALL SLASET( 'Full', N, N, ZERO, ONE, Q, LDQ )
  472. *
  473. * Loop until convergence
  474. *
  475. UPPER = .FALSE.
  476. DO 40 KCYCLE = 1, MAXIT
  477. *
  478. UPPER = .NOT.UPPER
  479. *
  480. DO 20 I = 1, L - 1
  481. DO 10 J = I + 1, L
  482. *
  483. A1 = ZERO
  484. A2 = ZERO
  485. A3 = ZERO
  486. IF( K+I.LE.M )
  487. $ A1 = A( K+I, N-L+I )
  488. IF( K+J.LE.M )
  489. $ A3 = A( K+J, N-L+J )
  490. *
  491. B1 = B( I, N-L+I )
  492. B3 = B( J, N-L+J )
  493. *
  494. IF( UPPER ) THEN
  495. IF( K+I.LE.M )
  496. $ A2 = A( K+I, N-L+J )
  497. B2 = B( I, N-L+J )
  498. ELSE
  499. IF( K+J.LE.M )
  500. $ A2 = A( K+J, N-L+I )
  501. B2 = B( J, N-L+I )
  502. END IF
  503. *
  504. CALL SLAGS2( UPPER, A1, A2, A3, B1, B2, B3, CSU, SNU,
  505. $ CSV, SNV, CSQ, SNQ )
  506. *
  507. * Update (K+I)-th and (K+J)-th rows of matrix A: U**T *A
  508. *
  509. IF( K+J.LE.M )
  510. $ CALL SROT( L, A( K+J, N-L+1 ), LDA, A( K+I, N-L+1 ),
  511. $ LDA, CSU, SNU )
  512. *
  513. * Update I-th and J-th rows of matrix B: V**T *B
  514. *
  515. CALL SROT( L, B( J, N-L+1 ), LDB, B( I, N-L+1 ), LDB,
  516. $ CSV, SNV )
  517. *
  518. * Update (N-L+I)-th and (N-L+J)-th columns of matrices
  519. * A and B: A*Q and B*Q
  520. *
  521. CALL SROT( MIN( K+L, M ), A( 1, N-L+J ), 1,
  522. $ A( 1, N-L+I ), 1, CSQ, SNQ )
  523. *
  524. CALL SROT( L, B( 1, N-L+J ), 1, B( 1, N-L+I ), 1, CSQ,
  525. $ SNQ )
  526. *
  527. IF( UPPER ) THEN
  528. IF( K+I.LE.M )
  529. $ A( K+I, N-L+J ) = ZERO
  530. B( I, N-L+J ) = ZERO
  531. ELSE
  532. IF( K+J.LE.M )
  533. $ A( K+J, N-L+I ) = ZERO
  534. B( J, N-L+I ) = ZERO
  535. END IF
  536. *
  537. * Update orthogonal matrices U, V, Q, if desired.
  538. *
  539. IF( WANTU .AND. K+J.LE.M )
  540. $ CALL SROT( M, U( 1, K+J ), 1, U( 1, K+I ), 1, CSU,
  541. $ SNU )
  542. *
  543. IF( WANTV )
  544. $ CALL SROT( P, V( 1, J ), 1, V( 1, I ), 1, CSV, SNV )
  545. *
  546. IF( WANTQ )
  547. $ CALL SROT( N, Q( 1, N-L+J ), 1, Q( 1, N-L+I ), 1, CSQ,
  548. $ SNQ )
  549. *
  550. 10 CONTINUE
  551. 20 CONTINUE
  552. *
  553. IF( .NOT.UPPER ) THEN
  554. *
  555. * The matrices A13 and B13 were lower triangular at the start
  556. * of the cycle, and are now upper triangular.
  557. *
  558. * Convergence test: test the parallelism of the corresponding
  559. * rows of A and B.
  560. *
  561. ERROR = ZERO
  562. DO 30 I = 1, MIN( L, M-K )
  563. CALL SCOPY( L-I+1, A( K+I, N-L+I ), LDA, WORK, 1 )
  564. CALL SCOPY( L-I+1, B( I, N-L+I ), LDB, WORK( L+1 ), 1 )
  565. CALL SLAPLL( L-I+1, WORK, 1, WORK( L+1 ), 1, SSMIN )
  566. ERROR = MAX( ERROR, SSMIN )
  567. 30 CONTINUE
  568. *
  569. IF( ABS( ERROR ).LE.MIN( TOLA, TOLB ) )
  570. $ GO TO 50
  571. END IF
  572. *
  573. * End of cycle loop
  574. *
  575. 40 CONTINUE
  576. *
  577. * The algorithm has not converged after MAXIT cycles.
  578. *
  579. INFO = 1
  580. GO TO 100
  581. *
  582. 50 CONTINUE
  583. *
  584. * If ERROR <= MIN(TOLA,TOLB), then the algorithm has converged.
  585. * Compute the generalized singular value pairs (ALPHA, BETA), and
  586. * set the triangular matrix R to array A.
  587. *
  588. DO 60 I = 1, K
  589. ALPHA( I ) = ONE
  590. BETA( I ) = ZERO
  591. 60 CONTINUE
  592. *
  593. DO 70 I = 1, MIN( L, M-K )
  594. *
  595. A1 = A( K+I, N-L+I )
  596. B1 = B( I, N-L+I )
  597. GAMMA = B1 / A1
  598. *
  599. IF( (GAMMA.LE.HUGENUM).AND.(GAMMA.GE.-HUGENUM) ) THEN
  600. *
  601. * change sign if necessary
  602. *
  603. IF( GAMMA.LT.ZERO ) THEN
  604. CALL SSCAL( L-I+1, -ONE, B( I, N-L+I ), LDB )
  605. IF( WANTV )
  606. $ CALL SSCAL( P, -ONE, V( 1, I ), 1 )
  607. END IF
  608. *
  609. CALL SLARTG( ABS( GAMMA ), ONE, BETA( K+I ), ALPHA( K+I ),
  610. $ RWK )
  611. *
  612. IF( ALPHA( K+I ).GE.BETA( K+I ) ) THEN
  613. CALL SSCAL( L-I+1, ONE / ALPHA( K+I ), A( K+I, N-L+I ),
  614. $ LDA )
  615. ELSE
  616. CALL SSCAL( L-I+1, ONE / BETA( K+I ), B( I, N-L+I ),
  617. $ LDB )
  618. CALL SCOPY( L-I+1, B( I, N-L+I ), LDB, A( K+I, N-L+I ),
  619. $ LDA )
  620. END IF
  621. *
  622. ELSE
  623. *
  624. ALPHA( K+I ) = ZERO
  625. BETA( K+I ) = ONE
  626. CALL SCOPY( L-I+1, B( I, N-L+I ), LDB, A( K+I, N-L+I ),
  627. $ LDA )
  628. *
  629. END IF
  630. *
  631. 70 CONTINUE
  632. *
  633. * Post-assignment
  634. *
  635. DO 80 I = M + 1, K + L
  636. ALPHA( I ) = ZERO
  637. BETA( I ) = ONE
  638. 80 CONTINUE
  639. *
  640. IF( K+L.LT.N ) THEN
  641. DO 90 I = K + L + 1, N
  642. ALPHA( I ) = ZERO
  643. BETA( I ) = ZERO
  644. 90 CONTINUE
  645. END IF
  646. *
  647. 100 CONTINUE
  648. NCYCLE = KCYCLE
  649. RETURN
  650. *
  651. * End of STGSJA
  652. *
  653. END