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.

cgsvj1.f 26 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705
  1. *> \brief \b CGSVJ1 pre-processor for the routine cgesvj, applies Jacobi rotations targeting only particular pivots.
  2. *
  3. * =========== DOCUMENTATION ===========
  4. *
  5. * Online html documentation available at
  6. * http://www.netlib.org/lapack/explore-html/
  7. *
  8. *> \htmlonly
  9. *> Download CGSVJ1 + dependencies
  10. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/cgsvj1.f">
  11. *> [TGZ]</a>
  12. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/cgsvj1.f">
  13. *> [ZIP]</a>
  14. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/cgsvj1.f">
  15. *> [TXT]</a>
  16. *> \endhtmlonly
  17. *
  18. * Definition:
  19. * ===========
  20. *
  21. * SUBROUTINE CGSVJ1( JOBV, M, N, N1, A, LDA, D, SVA, MV, V, LDV,
  22. * EPS, SFMIN, TOL, NSWEEP, WORK, LWORK, INFO )
  23. *
  24. * .. Scalar Arguments ..
  25. * REAL EPS, SFMIN, TOL
  26. * INTEGER INFO, LDA, LDV, LWORK, M, MV, N, N1, NSWEEP
  27. * CHARACTER*1 JOBV
  28. * ..
  29. * .. Array Arguments ..
  30. * COMPLEX A( LDA, * ), D( N ), V( LDV, * ), WORK( LWORK )
  31. * REAL SVA( N )
  32. * ..
  33. *
  34. *
  35. *> \par Purpose:
  36. * =============
  37. *>
  38. *> \verbatim
  39. *>
  40. *> CGSVJ1 is called from CGESVJ as a pre-processor and that is its main
  41. *> purpose. It applies Jacobi rotations in the same way as CGESVJ does, but
  42. *> it targets only particular pivots and it does not check convergence
  43. *> (stopping criterion). Few tunning parameters (marked by [TP]) are
  44. *> available for the implementer.
  45. *>
  46. *> Further Details
  47. *> ~~~~~~~~~~~~~~~
  48. *> CGSVJ1 applies few sweeps of Jacobi rotations in the column space of
  49. *> the input M-by-N matrix A. The pivot pairs are taken from the (1,2)
  50. *> off-diagonal block in the corresponding N-by-N Gram matrix A^T * A. The
  51. *> block-entries (tiles) of the (1,2) off-diagonal block are marked by the
  52. *> [x]'s in the following scheme:
  53. *>
  54. *> | * * * [x] [x] [x]|
  55. *> | * * * [x] [x] [x]| Row-cycling in the nblr-by-nblc [x] blocks.
  56. *> | * * * [x] [x] [x]| Row-cyclic pivoting inside each [x] block.
  57. *> |[x] [x] [x] * * * |
  58. *> |[x] [x] [x] * * * |
  59. *> |[x] [x] [x] * * * |
  60. *>
  61. *> In terms of the columns of A, the first N1 columns are rotated 'against'
  62. *> the remaining N-N1 columns, trying to increase the angle between the
  63. *> corresponding subspaces. The off-diagonal block is N1-by(N-N1) and it is
  64. *> tiled using quadratic tiles of side KBL. Here, KBL is a tunning parameter.
  65. *> The number of sweeps is given in NSWEEP and the orthogonality threshold
  66. *> is given in TOL.
  67. *> \endverbatim
  68. *
  69. * Arguments:
  70. * ==========
  71. *
  72. *> \param[in] JOBV
  73. *> \verbatim
  74. *> JOBV is CHARACTER*1
  75. *> Specifies whether the output from this procedure is used
  76. *> to compute the matrix V:
  77. *> = 'V': the product of the Jacobi rotations is accumulated
  78. *> by postmulyiplying the N-by-N array V.
  79. *> (See the description of V.)
  80. *> = 'A': the product of the Jacobi rotations is accumulated
  81. *> by postmulyiplying the MV-by-N array V.
  82. *> (See the descriptions of MV and V.)
  83. *> = 'N': the Jacobi rotations are not accumulated.
  84. *> \endverbatim
  85. *>
  86. *> \param[in] M
  87. *> \verbatim
  88. *> M is INTEGER
  89. *> The number of rows of the input matrix A. M >= 0.
  90. *> \endverbatim
  91. *>
  92. *> \param[in] N
  93. *> \verbatim
  94. *> N is INTEGER
  95. *> The number of columns of the input matrix A.
  96. *> M >= N >= 0.
  97. *> \endverbatim
  98. *>
  99. *> \param[in] N1
  100. *> \verbatim
  101. *> N1 is INTEGER
  102. *> N1 specifies the 2 x 2 block partition, the first N1 columns are
  103. *> rotated 'against' the remaining N-N1 columns of A.
  104. *> \endverbatim
  105. *>
  106. *> \param[in,out] A
  107. *> \verbatim
  108. *> A is COMPLEX array, dimension (LDA,N)
  109. *> On entry, M-by-N matrix A, such that A*diag(D) represents
  110. *> the input matrix.
  111. *> On exit,
  112. *> A_onexit * D_onexit represents the input matrix A*diag(D)
  113. *> post-multiplied by a sequence of Jacobi rotations, where the
  114. *> rotation threshold and the total number of sweeps are given in
  115. *> TOL and NSWEEP, respectively.
  116. *> (See the descriptions of N1, D, TOL and NSWEEP.)
  117. *> \endverbatim
  118. *>
  119. *> \param[in] LDA
  120. *> \verbatim
  121. *> LDA is INTEGER
  122. *> The leading dimension of the array A. LDA >= max(1,M).
  123. *> \endverbatim
  124. *>
  125. *> \param[in,out] D
  126. *> \verbatim
  127. *> D is COMPLEX array, dimension (N)
  128. *> The array D accumulates the scaling factors from the fast scaled
  129. *> Jacobi rotations.
  130. *> On entry, A*diag(D) represents the input matrix.
  131. *> On exit, A_onexit*diag(D_onexit) represents the input matrix
  132. *> post-multiplied by a sequence of Jacobi rotations, where the
  133. *> rotation threshold and the total number of sweeps are given in
  134. *> TOL and NSWEEP, respectively.
  135. *> (See the descriptions of N1, A, TOL and NSWEEP.)
  136. *> \endverbatim
  137. *>
  138. *> \param[in,out] SVA
  139. *> \verbatim
  140. *> SVA is REAL array, dimension (N)
  141. *> On entry, SVA contains the Euclidean norms of the columns of
  142. *> the matrix A*diag(D).
  143. *> On exit, SVA contains the Euclidean norms of the columns of
  144. *> the matrix onexit*diag(D_onexit).
  145. *> \endverbatim
  146. *>
  147. *> \param[in] MV
  148. *> \verbatim
  149. *> MV is INTEGER
  150. *> If JOBV = 'A', then MV rows of V are post-multipled by a
  151. *> sequence of Jacobi rotations.
  152. *> If JOBV = 'N', then MV is not referenced.
  153. *> \endverbatim
  154. *>
  155. *> \param[in,out] V
  156. *> \verbatim
  157. *> V is COMPLEX array, dimension (LDV,N)
  158. *> If JOBV = 'V' then N rows of V are post-multipled by a
  159. *> sequence of Jacobi rotations.
  160. *> If JOBV = 'A' then MV rows of V are post-multipled by a
  161. *> sequence of Jacobi rotations.
  162. *> If JOBV = 'N', then V is not referenced.
  163. *> \endverbatim
  164. *>
  165. *> \param[in] LDV
  166. *> \verbatim
  167. *> LDV is INTEGER
  168. *> The leading dimension of the array V, LDV >= 1.
  169. *> If JOBV = 'V', LDV >= N.
  170. *> If JOBV = 'A', LDV >= MV.
  171. *> \endverbatim
  172. *>
  173. *> \param[in] EPS
  174. *> \verbatim
  175. *> EPS is REAL
  176. *> EPS = SLAMCH('Epsilon')
  177. *> \endverbatim
  178. *>
  179. *> \param[in] SFMIN
  180. *> \verbatim
  181. *> SFMIN is REAL
  182. *> SFMIN = SLAMCH('Safe Minimum')
  183. *> \endverbatim
  184. *>
  185. *> \param[in] TOL
  186. *> \verbatim
  187. *> TOL is REAL
  188. *> TOL is the threshold for Jacobi rotations. For a pair
  189. *> A(:,p), A(:,q) of pivot columns, the Jacobi rotation is
  190. *> applied only if ABS(COS(angle(A(:,p),A(:,q)))) > TOL.
  191. *> \endverbatim
  192. *>
  193. *> \param[in] NSWEEP
  194. *> \verbatim
  195. *> NSWEEP is INTEGER
  196. *> NSWEEP is the number of sweeps of Jacobi rotations to be
  197. *> performed.
  198. *> \endverbatim
  199. *>
  200. *> \param[out] WORK
  201. *> \verbatim
  202. *> WORK is COMPLEX array, dimension (LWORK)
  203. *> \endverbatim
  204. *>
  205. *> \param[in] LWORK
  206. *> \verbatim
  207. *> LWORK is INTEGER
  208. *> LWORK is the dimension of WORK. LWORK >= M.
  209. *> \endverbatim
  210. *>
  211. *> \param[out] INFO
  212. *> \verbatim
  213. *> INFO is INTEGER
  214. *> = 0: successful exit.
  215. *> < 0: if INFO = -i, then the i-th argument had an illegal value
  216. *> \endverbatim
  217. *
  218. * Authors:
  219. * ========
  220. *
  221. *> \author Univ. of Tennessee
  222. *> \author Univ. of California Berkeley
  223. *> \author Univ. of Colorado Denver
  224. *> \author NAG Ltd.
  225. *
  226. *> \date June 2016
  227. *
  228. *> \ingroup complexOTHERcomputational
  229. *
  230. *> \par Contributor:
  231. * ==================
  232. *>
  233. *> Zlatko Drmac (Zagreb, Croatia)
  234. *
  235. * =====================================================================
  236. SUBROUTINE CGSVJ1( JOBV, M, N, N1, A, LDA, D, SVA, MV, V, LDV,
  237. $ EPS, SFMIN, TOL, NSWEEP, WORK, LWORK, INFO )
  238. *
  239. * -- LAPACK computational routine (version 3.8.0) --
  240. * -- LAPACK is a software package provided by Univ. of Tennessee, --
  241. * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
  242. * June 2016
  243. *
  244. * .. Scalar Arguments ..
  245. REAL EPS, SFMIN, TOL
  246. INTEGER INFO, LDA, LDV, LWORK, M, MV, N, N1, NSWEEP
  247. CHARACTER*1 JOBV
  248. * ..
  249. * .. Array Arguments ..
  250. COMPLEX A( LDA, * ), D( N ), V( LDV, * ), WORK( LWORK )
  251. REAL SVA( N )
  252. * ..
  253. *
  254. * =====================================================================
  255. *
  256. * .. Local Parameters ..
  257. REAL ZERO, HALF, ONE
  258. PARAMETER ( ZERO = 0.0E0, HALF = 0.5E0, ONE = 1.0E0)
  259. * ..
  260. * .. Local Scalars ..
  261. COMPLEX AAPQ, OMPQ
  262. REAL AAPP, AAPP0, AAPQ1, AAQQ, APOAQ, AQOAP, BIG,
  263. $ BIGTHETA, CS, MXAAPQ, MXSINJ, ROOTBIG,
  264. $ ROOTEPS, ROOTSFMIN, ROOTTOL, SMALL, SN, T,
  265. $ TEMP1, THETA, THSIGN
  266. INTEGER BLSKIP, EMPTSW, i, ibr, igl, IERR, IJBLSK,
  267. $ ISWROT, jbc, jgl, KBL, MVL, NOTROT, nblc, nblr,
  268. $ p, PSKIPPED, q, ROWSKIP, SWBAND
  269. LOGICAL APPLV, ROTOK, RSVEC
  270. * ..
  271. * ..
  272. * .. Intrinsic Functions ..
  273. INTRINSIC ABS, MAX, CONJG, REAL, MIN, SIGN, SQRT
  274. * ..
  275. * .. External Functions ..
  276. REAL SCNRM2
  277. COMPLEX CDOTC
  278. INTEGER ISAMAX
  279. LOGICAL LSAME
  280. EXTERNAL ISAMAX, LSAME, CDOTC, SCNRM2
  281. * ..
  282. * .. External Subroutines ..
  283. * .. from BLAS
  284. EXTERNAL CCOPY, CROT, CSWAP, CAXPY
  285. * .. from LAPACK
  286. EXTERNAL CLASCL, CLASSQ, XERBLA
  287. * ..
  288. * .. Executable Statements ..
  289. *
  290. * Test the input parameters.
  291. *
  292. APPLV = LSAME( JOBV, 'A' )
  293. RSVEC = LSAME( JOBV, 'V' )
  294. IF( .NOT.( RSVEC .OR. APPLV .OR. LSAME( JOBV, 'N' ) ) ) THEN
  295. INFO = -1
  296. ELSE IF( M.LT.0 ) THEN
  297. INFO = -2
  298. ELSE IF( ( N.LT.0 ) .OR. ( N.GT.M ) ) THEN
  299. INFO = -3
  300. ELSE IF( N1.LT.0 ) THEN
  301. INFO = -4
  302. ELSE IF( LDA.LT.M ) THEN
  303. INFO = -6
  304. ELSE IF( ( RSVEC.OR.APPLV ) .AND. ( MV.LT.0 ) ) THEN
  305. INFO = -9
  306. ELSE IF( ( RSVEC.AND.( LDV.LT.N ) ).OR.
  307. $ ( APPLV.AND.( LDV.LT.MV ) ) ) THEN
  308. INFO = -11
  309. ELSE IF( TOL.LE.EPS ) THEN
  310. INFO = -14
  311. ELSE IF( NSWEEP.LT.0 ) THEN
  312. INFO = -15
  313. ELSE IF( LWORK.LT.M ) THEN
  314. INFO = -17
  315. ELSE
  316. INFO = 0
  317. END IF
  318. *
  319. * #:(
  320. IF( INFO.NE.0 ) THEN
  321. CALL XERBLA( 'CGSVJ1', -INFO )
  322. RETURN
  323. END IF
  324. *
  325. IF( RSVEC ) THEN
  326. MVL = N
  327. ELSE IF( APPLV ) THEN
  328. MVL = MV
  329. END IF
  330. RSVEC = RSVEC .OR. APPLV
  331. ROOTEPS = SQRT( EPS )
  332. ROOTSFMIN = SQRT( SFMIN )
  333. SMALL = SFMIN / EPS
  334. BIG = ONE / SFMIN
  335. ROOTBIG = ONE / ROOTSFMIN
  336. * LARGE = BIG / SQRT( REAL( M*N ) )
  337. BIGTHETA = ONE / ROOTEPS
  338. ROOTTOL = SQRT( TOL )
  339. *
  340. * .. Initialize the right singular vector matrix ..
  341. *
  342. * RSVEC = LSAME( JOBV, 'Y' )
  343. *
  344. EMPTSW = N1*( N-N1 )
  345. NOTROT = 0
  346. *
  347. * .. Row-cyclic pivot strategy with de Rijk's pivoting ..
  348. *
  349. KBL = MIN( 8, N )
  350. NBLR = N1 / KBL
  351. IF( ( NBLR*KBL ).NE.N1 )NBLR = NBLR + 1
  352. * .. the tiling is nblr-by-nblc [tiles]
  353. NBLC = ( N-N1 ) / KBL
  354. IF( ( NBLC*KBL ).NE.( N-N1 ) )NBLC = NBLC + 1
  355. BLSKIP = ( KBL**2 ) + 1
  356. *[TP] BLKSKIP is a tuning parameter that depends on SWBAND and KBL.
  357. ROWSKIP = MIN( 5, KBL )
  358. *[TP] ROWSKIP is a tuning parameter.
  359. SWBAND = 0
  360. *[TP] SWBAND is a tuning parameter. It is meaningful and effective
  361. * if CGESVJ is used as a computational routine in the preconditioned
  362. * Jacobi SVD algorithm CGEJSV.
  363. *
  364. *
  365. * | * * * [x] [x] [x]|
  366. * | * * * [x] [x] [x]| Row-cycling in the nblr-by-nblc [x] blocks.
  367. * | * * * [x] [x] [x]| Row-cyclic pivoting inside each [x] block.
  368. * |[x] [x] [x] * * * |
  369. * |[x] [x] [x] * * * |
  370. * |[x] [x] [x] * * * |
  371. *
  372. *
  373. DO 1993 i = 1, NSWEEP
  374. *
  375. * .. go go go ...
  376. *
  377. MXAAPQ = ZERO
  378. MXSINJ = ZERO
  379. ISWROT = 0
  380. *
  381. NOTROT = 0
  382. PSKIPPED = 0
  383. *
  384. * Each sweep is unrolled using KBL-by-KBL tiles over the pivot pairs
  385. * 1 <= p < q <= N. This is the first step toward a blocked implementation
  386. * of the rotations. New implementation, based on block transformations,
  387. * is under development.
  388. *
  389. DO 2000 ibr = 1, NBLR
  390. *
  391. igl = ( ibr-1 )*KBL + 1
  392. *
  393. *
  394. * ... go to the off diagonal blocks
  395. *
  396. igl = ( ibr-1 )*KBL + 1
  397. *
  398. * DO 2010 jbc = ibr + 1, NBL
  399. DO 2010 jbc = 1, NBLC
  400. *
  401. jgl = ( jbc-1 )*KBL + N1 + 1
  402. *
  403. * doing the block at ( ibr, jbc )
  404. *
  405. IJBLSK = 0
  406. DO 2100 p = igl, MIN( igl+KBL-1, N1 )
  407. *
  408. AAPP = SVA( p )
  409. IF( AAPP.GT.ZERO ) THEN
  410. *
  411. PSKIPPED = 0
  412. *
  413. DO 2200 q = jgl, MIN( jgl+KBL-1, N )
  414. *
  415. AAQQ = SVA( q )
  416. IF( AAQQ.GT.ZERO ) THEN
  417. AAPP0 = AAPP
  418. *
  419. * .. M x 2 Jacobi SVD ..
  420. *
  421. * Safe Gram matrix computation
  422. *
  423. IF( AAQQ.GE.ONE ) THEN
  424. IF( AAPP.GE.AAQQ ) THEN
  425. ROTOK = ( SMALL*AAPP ).LE.AAQQ
  426. ELSE
  427. ROTOK = ( SMALL*AAQQ ).LE.AAPP
  428. END IF
  429. IF( AAPP.LT.( BIG / AAQQ ) ) THEN
  430. AAPQ = ( CDOTC( M, A( 1, p ), 1,
  431. $ A( 1, q ), 1 ) / AAQQ ) / AAPP
  432. ELSE
  433. CALL CCOPY( M, A( 1, p ), 1,
  434. $ WORK, 1 )
  435. CALL CLASCL( 'G', 0, 0, AAPP,
  436. $ ONE, M, 1,
  437. $ WORK, LDA, IERR )
  438. AAPQ = CDOTC( M, WORK, 1,
  439. $ A( 1, q ), 1 ) / AAQQ
  440. END IF
  441. ELSE
  442. IF( AAPP.GE.AAQQ ) THEN
  443. ROTOK = AAPP.LE.( AAQQ / SMALL )
  444. ELSE
  445. ROTOK = AAQQ.LE.( AAPP / SMALL )
  446. END IF
  447. IF( AAPP.GT.( SMALL / AAQQ ) ) THEN
  448. AAPQ = ( CDOTC( M, A( 1, p ), 1,
  449. $ A( 1, q ), 1 ) / MAX(AAQQ,AAPP) )
  450. $ / MIN(AAQQ,AAPP)
  451. ELSE
  452. CALL CCOPY( M, A( 1, q ), 1,
  453. $ WORK, 1 )
  454. CALL CLASCL( 'G', 0, 0, AAQQ,
  455. $ ONE, M, 1,
  456. $ WORK, LDA, IERR )
  457. AAPQ = CDOTC( M, A( 1, p ), 1,
  458. $ WORK, 1 ) / AAPP
  459. END IF
  460. END IF
  461. *
  462. * AAPQ = AAPQ * CONJG(CWORK(p))*CWORK(q)
  463. AAPQ1 = -ABS(AAPQ)
  464. MXAAPQ = MAX( MXAAPQ, -AAPQ1 )
  465. *
  466. * TO rotate or NOT to rotate, THAT is the question ...
  467. *
  468. IF( ABS( AAPQ1 ).GT.TOL ) THEN
  469. OMPQ = AAPQ / ABS(AAPQ)
  470. NOTROT = 0
  471. *[RTD] ROTATED = ROTATED + 1
  472. PSKIPPED = 0
  473. ISWROT = ISWROT + 1
  474. *
  475. IF( ROTOK ) THEN
  476. *
  477. AQOAP = AAQQ / AAPP
  478. APOAQ = AAPP / AAQQ
  479. THETA = -HALF*ABS( AQOAP-APOAQ )/ AAPQ1
  480. IF( AAQQ.GT.AAPP0 )THETA = -THETA
  481. *
  482. IF( ABS( THETA ).GT.BIGTHETA ) THEN
  483. T = HALF / THETA
  484. CS = ONE
  485. CALL CROT( M, A(1,p), 1, A(1,q), 1,
  486. $ CS, CONJG(OMPQ)*T )
  487. IF( RSVEC ) THEN
  488. CALL CROT( MVL, V(1,p), 1,
  489. $ V(1,q), 1, CS, CONJG(OMPQ)*T )
  490. END IF
  491. SVA( q ) = AAQQ*SQRT( MAX( ZERO,
  492. $ ONE+T*APOAQ*AAPQ1 ) )
  493. AAPP = AAPP*SQRT( MAX( ZERO,
  494. $ ONE-T*AQOAP*AAPQ1 ) )
  495. MXSINJ = MAX( MXSINJ, ABS( T ) )
  496. ELSE
  497. *
  498. * .. choose correct signum for THETA and rotate
  499. *
  500. THSIGN = -SIGN( ONE, AAPQ1 )
  501. IF( AAQQ.GT.AAPP0 )THSIGN = -THSIGN
  502. T = ONE / ( THETA+THSIGN*
  503. $ SQRT( ONE+THETA*THETA ) )
  504. CS = SQRT( ONE / ( ONE+T*T ) )
  505. SN = T*CS
  506. MXSINJ = MAX( MXSINJ, ABS( SN ) )
  507. SVA( q ) = AAQQ*SQRT( MAX( ZERO,
  508. $ ONE+T*APOAQ*AAPQ1 ) )
  509. AAPP = AAPP*SQRT( MAX( ZERO,
  510. $ ONE-T*AQOAP*AAPQ1 ) )
  511. *
  512. CALL CROT( M, A(1,p), 1, A(1,q), 1,
  513. $ CS, CONJG(OMPQ)*SN )
  514. IF( RSVEC ) THEN
  515. CALL CROT( MVL, V(1,p), 1,
  516. $ V(1,q), 1, CS, CONJG(OMPQ)*SN )
  517. END IF
  518. END IF
  519. D(p) = -D(q) * OMPQ
  520. *
  521. ELSE
  522. * .. have to use modified Gram-Schmidt like transformation
  523. IF( AAPP.GT.AAQQ ) THEN
  524. CALL CCOPY( M, A( 1, p ), 1,
  525. $ WORK, 1 )
  526. CALL CLASCL( 'G', 0, 0, AAPP, ONE,
  527. $ M, 1, WORK,LDA,
  528. $ IERR )
  529. CALL CLASCL( 'G', 0, 0, AAQQ, ONE,
  530. $ M, 1, A( 1, q ), LDA,
  531. $ IERR )
  532. CALL CAXPY( M, -AAPQ, WORK,
  533. $ 1, A( 1, q ), 1 )
  534. CALL CLASCL( 'G', 0, 0, ONE, AAQQ,
  535. $ M, 1, A( 1, q ), LDA,
  536. $ IERR )
  537. SVA( q ) = AAQQ*SQRT( MAX( ZERO,
  538. $ ONE-AAPQ1*AAPQ1 ) )
  539. MXSINJ = MAX( MXSINJ, SFMIN )
  540. ELSE
  541. CALL CCOPY( M, A( 1, q ), 1,
  542. $ WORK, 1 )
  543. CALL CLASCL( 'G', 0, 0, AAQQ, ONE,
  544. $ M, 1, WORK,LDA,
  545. $ IERR )
  546. CALL CLASCL( 'G', 0, 0, AAPP, ONE,
  547. $ M, 1, A( 1, p ), LDA,
  548. $ IERR )
  549. CALL CAXPY( M, -CONJG(AAPQ),
  550. $ WORK, 1, A( 1, p ), 1 )
  551. CALL CLASCL( 'G', 0, 0, ONE, AAPP,
  552. $ M, 1, A( 1, p ), LDA,
  553. $ IERR )
  554. SVA( p ) = AAPP*SQRT( MAX( ZERO,
  555. $ ONE-AAPQ1*AAPQ1 ) )
  556. MXSINJ = MAX( MXSINJ, SFMIN )
  557. END IF
  558. END IF
  559. * END IF ROTOK THEN ... ELSE
  560. *
  561. * In the case of cancellation in updating SVA(q), SVA(p)
  562. * .. recompute SVA(q), SVA(p)
  563. IF( ( SVA( q ) / AAQQ )**2.LE.ROOTEPS )
  564. $ THEN
  565. IF( ( AAQQ.LT.ROOTBIG ) .AND.
  566. $ ( AAQQ.GT.ROOTSFMIN ) ) THEN
  567. SVA( q ) = SCNRM2( M, A( 1, q ), 1)
  568. ELSE
  569. T = ZERO
  570. AAQQ = ONE
  571. CALL CLASSQ( M, A( 1, q ), 1, T,
  572. $ AAQQ )
  573. SVA( q ) = T*SQRT( AAQQ )
  574. END IF
  575. END IF
  576. IF( ( AAPP / AAPP0 )**2.LE.ROOTEPS ) THEN
  577. IF( ( AAPP.LT.ROOTBIG ) .AND.
  578. $ ( AAPP.GT.ROOTSFMIN ) ) THEN
  579. AAPP = SCNRM2( M, A( 1, p ), 1 )
  580. ELSE
  581. T = ZERO
  582. AAPP = ONE
  583. CALL CLASSQ( M, A( 1, p ), 1, T,
  584. $ AAPP )
  585. AAPP = T*SQRT( AAPP )
  586. END IF
  587. SVA( p ) = AAPP
  588. END IF
  589. * end of OK rotation
  590. ELSE
  591. NOTROT = NOTROT + 1
  592. *[RTD] SKIPPED = SKIPPED + 1
  593. PSKIPPED = PSKIPPED + 1
  594. IJBLSK = IJBLSK + 1
  595. END IF
  596. ELSE
  597. NOTROT = NOTROT + 1
  598. PSKIPPED = PSKIPPED + 1
  599. IJBLSK = IJBLSK + 1
  600. END IF
  601. *
  602. IF( ( i.LE.SWBAND ) .AND. ( IJBLSK.GE.BLSKIP ) )
  603. $ THEN
  604. SVA( p ) = AAPP
  605. NOTROT = 0
  606. GO TO 2011
  607. END IF
  608. IF( ( i.LE.SWBAND ) .AND.
  609. $ ( PSKIPPED.GT.ROWSKIP ) ) THEN
  610. AAPP = -AAPP
  611. NOTROT = 0
  612. GO TO 2203
  613. END IF
  614. *
  615. 2200 CONTINUE
  616. * end of the q-loop
  617. 2203 CONTINUE
  618. *
  619. SVA( p ) = AAPP
  620. *
  621. ELSE
  622. *
  623. IF( AAPP.EQ.ZERO )NOTROT = NOTROT +
  624. $ MIN( jgl+KBL-1, N ) - jgl + 1
  625. IF( AAPP.LT.ZERO )NOTROT = 0
  626. *
  627. END IF
  628. *
  629. 2100 CONTINUE
  630. * end of the p-loop
  631. 2010 CONTINUE
  632. * end of the jbc-loop
  633. 2011 CONTINUE
  634. *2011 bailed out of the jbc-loop
  635. DO 2012 p = igl, MIN( igl+KBL-1, N )
  636. SVA( p ) = ABS( SVA( p ) )
  637. 2012 CONTINUE
  638. ***
  639. 2000 CONTINUE
  640. *2000 :: end of the ibr-loop
  641. *
  642. * .. update SVA(N)
  643. IF( ( SVA( N ).LT.ROOTBIG ) .AND. ( SVA( N ).GT.ROOTSFMIN ) )
  644. $ THEN
  645. SVA( N ) = SCNRM2( M, A( 1, N ), 1 )
  646. ELSE
  647. T = ZERO
  648. AAPP = ONE
  649. CALL CLASSQ( M, A( 1, N ), 1, T, AAPP )
  650. SVA( N ) = T*SQRT( AAPP )
  651. END IF
  652. *
  653. * Additional steering devices
  654. *
  655. IF( ( i.LT.SWBAND ) .AND. ( ( MXAAPQ.LE.ROOTTOL ) .OR.
  656. $ ( ISWROT.LE.N ) ) )SWBAND = i
  657. *
  658. IF( ( i.GT.SWBAND+1 ) .AND. ( MXAAPQ.LT.SQRT( REAL( N ) )*
  659. $ TOL ) .AND. ( REAL( N )*MXAAPQ*MXSINJ.LT.TOL ) ) THEN
  660. GO TO 1994
  661. END IF
  662. *
  663. IF( NOTROT.GE.EMPTSW )GO TO 1994
  664. *
  665. 1993 CONTINUE
  666. * end i=1:NSWEEP loop
  667. *
  668. * #:( Reaching this point means that the procedure has not converged.
  669. INFO = NSWEEP - 1
  670. GO TO 1995
  671. *
  672. 1994 CONTINUE
  673. * #:) Reaching this point means numerical convergence after the i-th
  674. * sweep.
  675. *
  676. INFO = 0
  677. * #:) INFO = 0 confirms successful iterations.
  678. 1995 CONTINUE
  679. *
  680. * Sort the vector SVA() of column norms.
  681. DO 5991 p = 1, N - 1
  682. q = ISAMAX( N-p+1, SVA( p ), 1 ) + p - 1
  683. IF( p.NE.q ) THEN
  684. TEMP1 = SVA( p )
  685. SVA( p ) = SVA( q )
  686. SVA( q ) = TEMP1
  687. AAPQ = D( p )
  688. D( p ) = D( q )
  689. D( q ) = AAPQ
  690. CALL CSWAP( M, A( 1, p ), 1, A( 1, q ), 1 )
  691. IF( RSVEC )CALL CSWAP( MVL, V( 1, p ), 1, V( 1, q ), 1 )
  692. END IF
  693. 5991 CONTINUE
  694. *
  695. *
  696. RETURN
  697. * ..
  698. * .. END OF CGSVJ1
  699. * ..
  700. END