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.

sgesvj.f 68 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614
  1. *> \brief \b SGESVJ
  2. *
  3. * =========== DOCUMENTATION ===========
  4. *
  5. * Online html documentation available at
  6. * http://www.netlib.org/lapack/explore-html/
  7. *
  8. *> \htmlonly
  9. *> Download SGESVJ + dependencies
  10. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/sgesvj.f">
  11. *> [TGZ]</a>
  12. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/sgesvj.f">
  13. *> [ZIP]</a>
  14. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/sgesvj.f">
  15. *> [TXT]</a>
  16. *> \endhtmlonly
  17. *
  18. * Definition:
  19. * ===========
  20. *
  21. * SUBROUTINE SGESVJ( JOBA, JOBU, JOBV, M, N, A, LDA, SVA, MV, V,
  22. * LDV, WORK, LWORK, INFO )
  23. *
  24. * .. Scalar Arguments ..
  25. * INTEGER INFO, LDA, LDV, LWORK, M, MV, N
  26. * CHARACTER*1 JOBA, JOBU, JOBV
  27. * ..
  28. * .. Array Arguments ..
  29. * REAL A( LDA, * ), SVA( N ), V( LDV, * ),
  30. * $ WORK( LWORK )
  31. * ..
  32. *
  33. *
  34. *> \par Purpose:
  35. * =============
  36. *>
  37. *> \verbatim
  38. *>
  39. *> SGESVJ computes the singular value decomposition (SVD) of a real
  40. *> M-by-N matrix A, where M >= N. The SVD of A is written as
  41. *> [++] [xx] [x0] [xx]
  42. *> A = U * SIGMA * V^t, [++] = [xx] * [ox] * [xx]
  43. *> [++] [xx]
  44. *> where SIGMA is an N-by-N diagonal matrix, U is an M-by-N orthonormal
  45. *> matrix, and V is an N-by-N orthogonal matrix. The diagonal elements
  46. *> of SIGMA are the singular values of A. The columns of U and V are the
  47. *> left and the right singular vectors of A, respectively.
  48. *> SGESVJ can sometimes compute tiny singular values and their singular vectors much
  49. *> more accurately than other SVD routines, see below under Further Details.
  50. *> \endverbatim
  51. *
  52. * Arguments:
  53. * ==========
  54. *
  55. *> \param[in] JOBA
  56. *> \verbatim
  57. *> JOBA is CHARACTER*1
  58. *> Specifies the structure of A.
  59. *> = 'L': The input matrix A is lower triangular;
  60. *> = 'U': The input matrix A is upper triangular;
  61. *> = 'G': The input matrix A is general M-by-N matrix, M >= N.
  62. *> \endverbatim
  63. *>
  64. *> \param[in] JOBU
  65. *> \verbatim
  66. *> JOBU is CHARACTER*1
  67. *> Specifies whether to compute the left singular vectors
  68. *> (columns of U):
  69. *> = 'U': The left singular vectors corresponding to the nonzero
  70. *> singular values are computed and returned in the leading
  71. *> columns of A. See more details in the description of A.
  72. *> The default numerical orthogonality threshold is set to
  73. *> approximately TOL=CTOL*EPS, CTOL=SQRT(M), EPS=SLAMCH('E').
  74. *> = 'C': Analogous to JOBU='U', except that user can control the
  75. *> level of numerical orthogonality of the computed left
  76. *> singular vectors. TOL can be set to TOL = CTOL*EPS, where
  77. *> CTOL is given on input in the array WORK.
  78. *> No CTOL smaller than ONE is allowed. CTOL greater
  79. *> than 1 / EPS is meaningless. The option 'C'
  80. *> can be used if M*EPS is satisfactory orthogonality
  81. *> of the computed left singular vectors, so CTOL=M could
  82. *> save few sweeps of Jacobi rotations.
  83. *> See the descriptions of A and WORK(1).
  84. *> = 'N': The matrix U is not computed. However, see the
  85. *> description of A.
  86. *> \endverbatim
  87. *>
  88. *> \param[in] JOBV
  89. *> \verbatim
  90. *> JOBV is CHARACTER*1
  91. *> Specifies whether to compute the right singular vectors, that
  92. *> is, the matrix V:
  93. *> = 'V': the matrix V is computed and returned in the array V
  94. *> = 'A': the Jacobi rotations are applied to the MV-by-N
  95. *> array V. In other words, the right singular vector
  96. *> matrix V is not computed explicitly; instead it is
  97. *> applied to an MV-by-N matrix initially stored in the
  98. *> first MV rows of V.
  99. *> = 'N': the matrix V is not computed and the array V is not
  100. *> referenced
  101. *> \endverbatim
  102. *>
  103. *> \param[in] M
  104. *> \verbatim
  105. *> M is INTEGER
  106. *> The number of rows of the input matrix A. 1/SLAMCH('E') > M >= 0.
  107. *> \endverbatim
  108. *>
  109. *> \param[in] N
  110. *> \verbatim
  111. *> N is INTEGER
  112. *> The number of columns of the input matrix A.
  113. *> M >= N >= 0.
  114. *> \endverbatim
  115. *>
  116. *> \param[in,out] A
  117. *> \verbatim
  118. *> A is REAL array, dimension (LDA,N)
  119. *> On entry, the M-by-N matrix A.
  120. *> On exit,
  121. *> If JOBU = 'U' .OR. JOBU = 'C':
  122. *> If INFO = 0:
  123. *> RANKA orthonormal columns of U are returned in the
  124. *> leading RANKA columns of the array A. Here RANKA <= N
  125. *> is the number of computed singular values of A that are
  126. *> above the underflow threshold SLAMCH('S'). The singular
  127. *> vectors corresponding to underflowed or zero singular
  128. *> values are not computed. The value of RANKA is returned
  129. *> in the array WORK as RANKA=NINT(WORK(2)). Also see the
  130. *> descriptions of SVA and WORK. The computed columns of U
  131. *> are mutually numerically orthogonal up to approximately
  132. *> TOL=SQRT(M)*EPS (default); or TOL=CTOL*EPS (JOBU = 'C'),
  133. *> see the description of JOBU.
  134. *> If INFO > 0,
  135. *> the procedure SGESVJ did not converge in the given number
  136. *> of iterations (sweeps). In that case, the computed
  137. *> columns of U may not be orthogonal up to TOL. The output
  138. *> U (stored in A), SIGMA (given by the computed singular
  139. *> values in SVA(1:N)) and V is still a decomposition of the
  140. *> input matrix A in the sense that the residual
  141. *> ||A-SCALE*U*SIGMA*V^T||_2 / ||A||_2 is small.
  142. *> If JOBU = 'N':
  143. *> If INFO = 0:
  144. *> Note that the left singular vectors are 'for free' in the
  145. *> one-sided Jacobi SVD algorithm. However, if only the
  146. *> singular values are needed, the level of numerical
  147. *> orthogonality of U is not an issue and iterations are
  148. *> stopped when the columns of the iterated matrix are
  149. *> numerically orthogonal up to approximately M*EPS. Thus,
  150. *> on exit, A contains the columns of U scaled with the
  151. *> corresponding singular values.
  152. *> If INFO > 0:
  153. *> the procedure SGESVJ did not converge in the given number
  154. *> of iterations (sweeps).
  155. *> \endverbatim
  156. *>
  157. *> \param[in] LDA
  158. *> \verbatim
  159. *> LDA is INTEGER
  160. *> The leading dimension of the array A. LDA >= max(1,M).
  161. *> \endverbatim
  162. *>
  163. *> \param[out] SVA
  164. *> \verbatim
  165. *> SVA is REAL array, dimension (N)
  166. *> On exit,
  167. *> If INFO = 0 :
  168. *> depending on the value SCALE = WORK(1), we have:
  169. *> If SCALE = ONE:
  170. *> SVA(1:N) contains the computed singular values of A.
  171. *> During the computation SVA contains the Euclidean column
  172. *> norms of the iterated matrices in the array A.
  173. *> If SCALE .NE. ONE:
  174. *> The singular values of A are SCALE*SVA(1:N), and this
  175. *> factored representation is due to the fact that some of the
  176. *> singular values of A might underflow or overflow.
  177. *>
  178. *> If INFO > 0 :
  179. *> the procedure SGESVJ did not converge in the given number of
  180. *> iterations (sweeps) and SCALE*SVA(1:N) may not be accurate.
  181. *> \endverbatim
  182. *>
  183. *> \param[in] MV
  184. *> \verbatim
  185. *> MV is INTEGER
  186. *> If JOBV = 'A', then the product of Jacobi rotations in SGESVJ
  187. *> is applied to the first MV rows of V. See the description of JOBV.
  188. *> \endverbatim
  189. *>
  190. *> \param[in,out] V
  191. *> \verbatim
  192. *> V is REAL array, dimension (LDV,N)
  193. *> If JOBV = 'V', then V contains on exit the N-by-N matrix of
  194. *> the right singular vectors;
  195. *> If JOBV = 'A', then V contains the product of the computed right
  196. *> singular vector matrix and the initial matrix in
  197. *> the array V.
  198. *> If JOBV = 'N', then V is not referenced.
  199. *> \endverbatim
  200. *>
  201. *> \param[in] LDV
  202. *> \verbatim
  203. *> LDV is INTEGER
  204. *> The leading dimension of the array V, LDV >= 1.
  205. *> If JOBV = 'V', then LDV >= max(1,N).
  206. *> If JOBV = 'A', then LDV >= max(1,MV) .
  207. *> \endverbatim
  208. *>
  209. *> \param[in,out] WORK
  210. *> \verbatim
  211. *> WORK is REAL array, dimension (MAX(1,LWORK))
  212. *> On entry,
  213. *> If JOBU = 'C' :
  214. *> WORK(1) = CTOL, where CTOL defines the threshold for convergence.
  215. *> The process stops if all columns of A are mutually
  216. *> orthogonal up to CTOL*EPS, EPS=SLAMCH('E').
  217. *> It is required that CTOL >= ONE, i.e. it is not
  218. *> allowed to force the routine to obtain orthogonality
  219. *> below EPSILON.
  220. *> On exit,
  221. *> WORK(1) = SCALE is the scaling factor such that SCALE*SVA(1:N)
  222. *> are the computed singular vcalues of A.
  223. *> (See description of SVA().)
  224. *> WORK(2) = NINT(WORK(2)) is the number of the computed nonzero
  225. *> singular values.
  226. *> WORK(3) = NINT(WORK(3)) is the number of the computed singular
  227. *> values that are larger than the underflow threshold.
  228. *> WORK(4) = NINT(WORK(4)) is the number of sweeps of Jacobi
  229. *> rotations needed for numerical convergence.
  230. *> WORK(5) = max_{i.NE.j} |COS(A(:,i),A(:,j))| in the last sweep.
  231. *> This is useful information in cases when SGESVJ did
  232. *> not converge, as it can be used to estimate whether
  233. *> the output is still useful and for post festum analysis.
  234. *> WORK(6) = the largest absolute value over all sines of the
  235. *> Jacobi rotation angles in the last sweep. It can be
  236. *> useful for a post festum analysis.
  237. *> \endverbatim
  238. *>
  239. *> \param[in] LWORK
  240. *> \verbatim
  241. *> LWORK is INTEGER
  242. *> Length of WORK.
  243. *> LWORK >= 1, if MIN(M,N) = 0, and LWORK >= MAX(6,M+N), otherwise.
  244. *>
  245. *> If on entry LWORK = -1, then a workspace query is assumed and
  246. *> no computation is done; WORK(1) is set to the minial (and optimal)
  247. *> length of WORK.
  248. *> \endverbatim
  249. *>
  250. *> \param[out] INFO
  251. *> \verbatim
  252. *> INFO is INTEGER
  253. *> = 0: successful exit.
  254. *> < 0: if INFO = -i, then the i-th argument had an illegal value
  255. *> > 0: SGESVJ did not converge in the maximal allowed number (30)
  256. *> of sweeps. The output may still be useful. See the
  257. *> description of WORK.
  258. *> \endverbatim
  259. *
  260. * Authors:
  261. * ========
  262. *
  263. *> \author Univ. of Tennessee
  264. *> \author Univ. of California Berkeley
  265. *> \author Univ. of Colorado Denver
  266. *> \author NAG Ltd.
  267. *
  268. *> \ingroup gesvj
  269. *
  270. *> \par Further Details:
  271. * =====================
  272. *>
  273. *> The orthogonal N-by-N matrix V is obtained as a product of Jacobi plane
  274. *> rotations. The rotations are implemented as fast scaled rotations of
  275. *> Anda and Park [1]. In the case of underflow of the Jacobi angle, a
  276. *> modified Jacobi transformation of Drmac [4] is used. Pivot strategy uses
  277. *> column interchanges of de Rijk [2]. The relative accuracy of the computed
  278. *> singular values and the accuracy of the computed singular vectors (in
  279. *> angle metric) is as guaranteed by the theory of Demmel and Veselic [3].
  280. *> The condition number that determines the accuracy in the full rank case
  281. *> is essentially min_{D=diag} kappa(A*D), where kappa(.) is the
  282. *> spectral condition number. The best performance of this Jacobi SVD
  283. *> procedure is achieved if used in an accelerated version of Drmac and
  284. *> Veselic [5,6], and it is the kernel routine in the SIGMA library [7].
  285. *> Some tuning parameters (marked with [TP]) are available for the
  286. *> implementer. \n
  287. *> The computational range for the nonzero singular values is the machine
  288. *> number interval ( UNDERFLOW , OVERFLOW ). In extreme cases, even
  289. *> denormalized singular values can be computed with the corresponding
  290. *> gradual loss of accurate digits.
  291. *>
  292. *> \par Contributors:
  293. * ==================
  294. *>
  295. *> Zlatko Drmac (Zagreb, Croatia) and Kresimir Veselic (Hagen, Germany)
  296. *>
  297. *> \par References:
  298. * ================
  299. *>
  300. *> [1] A. A. Anda and H. Park: Fast plane rotations with dynamic scaling. \n
  301. *> SIAM J. matrix Anal. Appl., Vol. 15 (1994), pp. 162-174. \n\n
  302. *> [2] P. P. M. De Rijk: A one-sided Jacobi algorithm for computing the
  303. *> singular value decomposition on a vector computer. \n
  304. *> SIAM J. Sci. Stat. Comp., Vol. 10 (1998), pp. 359-371. \n\n
  305. *> [3] J. Demmel and K. Veselic: Jacobi method is more accurate than QR. \n
  306. *> [4] Z. Drmac: Implementation of Jacobi rotations for accurate singular
  307. *> value computation in floating point arithmetic. \n
  308. *> SIAM J. Sci. Comp., Vol. 18 (1997), pp. 1200-1222. \n\n
  309. *> [5] Z. Drmac and K. Veselic: New fast and accurate Jacobi SVD algorithm I. \n
  310. *> SIAM J. Matrix Anal. Appl. Vol. 35, No. 2 (2008), pp. 1322-1342. \n
  311. *> LAPACK Working note 169. \n\n
  312. *> [6] Z. Drmac and K. Veselic: New fast and accurate Jacobi SVD algorithm II. \n
  313. *> SIAM J. Matrix Anal. Appl. Vol. 35, No. 2 (2008), pp. 1343-1362. \n
  314. *> LAPACK Working note 170. \n\n
  315. *> [7] Z. Drmac: SIGMA - mathematical software library for accurate SVD, PSV,
  316. *> QSVD, (H,K)-SVD computations.\n
  317. *> Department of Mathematics, University of Zagreb, 2008.
  318. *>
  319. *> \par Bugs, Examples and Comments:
  320. * =================================
  321. *>
  322. *> Please report all bugs and send interesting test examples and comments to
  323. *> drmac@math.hr. Thank you.
  324. *
  325. * =====================================================================
  326. SUBROUTINE SGESVJ( JOBA, JOBU, JOBV, M, N, A, LDA, SVA, MV, V,
  327. $ LDV, WORK, LWORK, INFO )
  328. *
  329. * -- LAPACK computational routine --
  330. * -- LAPACK is a software package provided by Univ. of Tennessee, --
  331. * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
  332. *
  333. * .. Scalar Arguments ..
  334. INTEGER INFO, LDA, LDV, LWORK, M, MV, N
  335. CHARACTER*1 JOBA, JOBU, JOBV
  336. * ..
  337. * .. Array Arguments ..
  338. REAL A( LDA, * ), SVA( N ), V( LDV, * ),
  339. $ WORK( LWORK )
  340. * ..
  341. *
  342. * =====================================================================
  343. *
  344. * .. Local Parameters ..
  345. REAL ZERO, HALF, ONE
  346. PARAMETER ( ZERO = 0.0E0, HALF = 0.5E0, ONE = 1.0E0)
  347. INTEGER NSWEEP
  348. PARAMETER ( NSWEEP = 30 )
  349. * ..
  350. * .. Local Scalars ..
  351. REAL AAPP, AAPP0, AAPQ, AAQQ, APOAQ, AQOAP, BIG,
  352. $ BIGTHETA, CS, CTOL, EPSLN, LARGE, MXAAPQ,
  353. $ MXSINJ, ROOTBIG, ROOTEPS, ROOTSFMIN, ROOTTOL,
  354. $ SKL, SFMIN, SMALL, SN, T, TEMP1, THETA,
  355. $ THSIGN, TOL
  356. INTEGER BLSKIP, EMPTSW, i, ibr, IERR, igl, IJBLSK, ir1,
  357. $ ISWROT, jbc, jgl, KBL, LKAHEAD, MVL, N2, N34,
  358. $ N4, NBL, NOTROT, p, PSKIPPED, q, ROWSKIP,
  359. $ SWBAND, MINMN, LWMIN
  360. LOGICAL APPLV, GOSCALE, LOWER, LQUERY, LSVEC, NOSCALE,
  361. $ ROTOK, RSVEC, UCTOL, UPPER
  362. * ..
  363. * .. Local Arrays ..
  364. REAL FASTR( 5 )
  365. * ..
  366. * .. Intrinsic Functions ..
  367. INTRINSIC ABS, MAX, MIN, FLOAT, SIGN, SQRT
  368. * ..
  369. * .. External Functions ..
  370. * ..
  371. * from BLAS
  372. REAL SDOT, SNRM2
  373. EXTERNAL SDOT, SNRM2
  374. INTEGER ISAMAX
  375. EXTERNAL ISAMAX
  376. * from LAPACK
  377. REAL SLAMCH, SROUNDUP_LWORK
  378. EXTERNAL SLAMCH, SROUNDUP_LWORK
  379. LOGICAL LSAME
  380. EXTERNAL LSAME
  381. * ..
  382. * .. External Subroutines ..
  383. * ..
  384. * from BLAS
  385. EXTERNAL SAXPY, SCOPY, SROTM, SSCAL, SSWAP
  386. * from LAPACK
  387. EXTERNAL SLASCL, SLASET, SLASSQ, XERBLA
  388. *
  389. EXTERNAL SGSVJ0, SGSVJ1
  390. * ..
  391. * .. Executable Statements ..
  392. *
  393. * Test the input arguments
  394. *
  395. LSVEC = LSAME( JOBU, 'U' )
  396. UCTOL = LSAME( JOBU, 'C' )
  397. RSVEC = LSAME( JOBV, 'V' )
  398. APPLV = LSAME( JOBV, 'A' )
  399. UPPER = LSAME( JOBA, 'U' )
  400. LOWER = LSAME( JOBA, 'L' )
  401. *
  402. MINMN = MIN( M, N )
  403. IF( MINMN.EQ.0 ) THEN
  404. LWMIN = 1
  405. ELSE
  406. LWMIN = MAX( 6, M+N )
  407. END IF
  408. *
  409. LQUERY = ( LWORK.EQ.-1 )
  410. IF( .NOT.( UPPER .OR. LOWER .OR. LSAME( JOBA, 'G' ) ) ) THEN
  411. INFO = -1
  412. ELSE IF( .NOT.( LSVEC .OR. UCTOL .OR. LSAME( JOBU, 'N' ) ) ) THEN
  413. INFO = -2
  414. ELSE IF( .NOT.( RSVEC .OR. APPLV .OR. LSAME( JOBV, 'N' ) ) ) THEN
  415. INFO = -3
  416. ELSE IF( M.LT.0 ) THEN
  417. INFO = -4
  418. ELSE IF( ( N.LT.0 ) .OR. ( N.GT.M ) ) THEN
  419. INFO = -5
  420. ELSE IF( LDA.LT.M ) THEN
  421. INFO = -7
  422. ELSE IF( MV.LT.0 ) THEN
  423. INFO = -9
  424. ELSE IF( ( RSVEC .AND. ( LDV.LT.N ) ) .OR.
  425. $ ( APPLV .AND. ( LDV.LT.MV ) ) ) THEN
  426. INFO = -11
  427. ELSE IF( UCTOL .AND. ( WORK( 1 ).LE.ONE ) ) THEN
  428. INFO = -12
  429. ELSE IF( LWORK.LT.LWMIN .AND. ( .NOT.LQUERY ) ) THEN
  430. INFO = -13
  431. ELSE
  432. INFO = 0
  433. END IF
  434. *
  435. * #:(
  436. IF( INFO.NE.0 ) THEN
  437. CALL XERBLA( 'SGESVJ', -INFO )
  438. RETURN
  439. ELSE IF( LQUERY ) THEN
  440. WORK( 1 ) = SROUNDUP_LWORK( LWMIN )
  441. RETURN
  442. END IF
  443. *
  444. * #:) Quick return for void matrix
  445. *
  446. IF( MINMN.EQ.0 ) RETURN
  447. *
  448. * Set numerical parameters
  449. * The stopping criterion for Jacobi rotations is
  450. *
  451. * max_{i<>j}|A(:,i)^T * A(:,j)|/(||A(:,i)||*||A(:,j)||) < CTOL*EPS
  452. *
  453. * where EPS is the round-off and CTOL is defined as follows:
  454. *
  455. IF( UCTOL ) THEN
  456. * ... user controlled
  457. CTOL = WORK( 1 )
  458. ELSE
  459. * ... default
  460. IF( LSVEC .OR. RSVEC .OR. APPLV ) THEN
  461. CTOL = SQRT( FLOAT( M ) )
  462. ELSE
  463. CTOL = FLOAT( M )
  464. END IF
  465. END IF
  466. * ... and the machine dependent parameters are
  467. *[!] (Make sure that SLAMCH() works properly on the target machine.)
  468. *
  469. EPSLN = SLAMCH( 'Epsilon' )
  470. ROOTEPS = SQRT( EPSLN )
  471. SFMIN = SLAMCH( 'SafeMinimum' )
  472. ROOTSFMIN = SQRT( SFMIN )
  473. SMALL = SFMIN / EPSLN
  474. BIG = SLAMCH( 'Overflow' )
  475. * BIG = ONE / SFMIN
  476. ROOTBIG = ONE / ROOTSFMIN
  477. LARGE = BIG / SQRT( FLOAT( M*N ) )
  478. BIGTHETA = ONE / ROOTEPS
  479. *
  480. TOL = CTOL*EPSLN
  481. ROOTTOL = SQRT( TOL )
  482. *
  483. IF( FLOAT( M )*EPSLN.GE.ONE ) THEN
  484. INFO = -4
  485. CALL XERBLA( 'SGESVJ', -INFO )
  486. RETURN
  487. END IF
  488. *
  489. * Initialize the right singular vector matrix.
  490. *
  491. IF( RSVEC ) THEN
  492. MVL = N
  493. CALL SLASET( 'A', MVL, N, ZERO, ONE, V, LDV )
  494. ELSE IF( APPLV ) THEN
  495. MVL = MV
  496. END IF
  497. RSVEC = RSVEC .OR. APPLV
  498. *
  499. * Initialize SVA( 1:N ) = ( ||A e_i||_2, i = 1:N )
  500. *(!) If necessary, scale A to protect the largest singular value
  501. * from overflow. It is possible that saving the largest singular
  502. * value destroys the information about the small ones.
  503. * This initial scaling is almost minimal in the sense that the
  504. * goal is to make sure that no column norm overflows, and that
  505. * SQRT(N)*max_i SVA(i) does not overflow. If INFinite entries
  506. * in A are detected, the procedure returns with INFO=-6.
  507. *
  508. SKL = ONE / SQRT( FLOAT( M )*FLOAT( N ) )
  509. NOSCALE = .TRUE.
  510. GOSCALE = .TRUE.
  511. *
  512. IF( LOWER ) THEN
  513. * the input matrix is M-by-N lower triangular (trapezoidal)
  514. DO 1874 p = 1, N
  515. AAPP = ZERO
  516. AAQQ = ONE
  517. CALL SLASSQ( M-p+1, A( p, p ), 1, AAPP, AAQQ )
  518. IF( AAPP.GT.BIG ) THEN
  519. INFO = -6
  520. CALL XERBLA( 'SGESVJ', -INFO )
  521. RETURN
  522. END IF
  523. AAQQ = SQRT( AAQQ )
  524. IF( ( AAPP.LT.( BIG / AAQQ ) ) .AND. NOSCALE ) THEN
  525. SVA( p ) = AAPP*AAQQ
  526. ELSE
  527. NOSCALE = .FALSE.
  528. SVA( p ) = AAPP*( AAQQ*SKL )
  529. IF( GOSCALE ) THEN
  530. GOSCALE = .FALSE.
  531. DO 1873 q = 1, p - 1
  532. SVA( q ) = SVA( q )*SKL
  533. 1873 CONTINUE
  534. END IF
  535. END IF
  536. 1874 CONTINUE
  537. ELSE IF( UPPER ) THEN
  538. * the input matrix is M-by-N upper triangular (trapezoidal)
  539. DO 2874 p = 1, N
  540. AAPP = ZERO
  541. AAQQ = ONE
  542. CALL SLASSQ( p, A( 1, p ), 1, AAPP, AAQQ )
  543. IF( AAPP.GT.BIG ) THEN
  544. INFO = -6
  545. CALL XERBLA( 'SGESVJ', -INFO )
  546. RETURN
  547. END IF
  548. AAQQ = SQRT( AAQQ )
  549. IF( ( AAPP.LT.( BIG / AAQQ ) ) .AND. NOSCALE ) THEN
  550. SVA( p ) = AAPP*AAQQ
  551. ELSE
  552. NOSCALE = .FALSE.
  553. SVA( p ) = AAPP*( AAQQ*SKL )
  554. IF( GOSCALE ) THEN
  555. GOSCALE = .FALSE.
  556. DO 2873 q = 1, p - 1
  557. SVA( q ) = SVA( q )*SKL
  558. 2873 CONTINUE
  559. END IF
  560. END IF
  561. 2874 CONTINUE
  562. ELSE
  563. * the input matrix is M-by-N general dense
  564. DO 3874 p = 1, N
  565. AAPP = ZERO
  566. AAQQ = ONE
  567. CALL SLASSQ( M, A( 1, p ), 1, AAPP, AAQQ )
  568. IF( AAPP.GT.BIG ) THEN
  569. INFO = -6
  570. CALL XERBLA( 'SGESVJ', -INFO )
  571. RETURN
  572. END IF
  573. AAQQ = SQRT( AAQQ )
  574. IF( ( AAPP.LT.( BIG / AAQQ ) ) .AND. NOSCALE ) THEN
  575. SVA( p ) = AAPP*AAQQ
  576. ELSE
  577. NOSCALE = .FALSE.
  578. SVA( p ) = AAPP*( AAQQ*SKL )
  579. IF( GOSCALE ) THEN
  580. GOSCALE = .FALSE.
  581. DO 3873 q = 1, p - 1
  582. SVA( q ) = SVA( q )*SKL
  583. 3873 CONTINUE
  584. END IF
  585. END IF
  586. 3874 CONTINUE
  587. END IF
  588. *
  589. IF( NOSCALE )SKL = ONE
  590. *
  591. * Move the smaller part of the spectrum from the underflow threshold
  592. *(!) Start by determining the position of the nonzero entries of the
  593. * array SVA() relative to ( SFMIN, BIG ).
  594. *
  595. AAPP = ZERO
  596. AAQQ = BIG
  597. DO 4781 p = 1, N
  598. IF( SVA( p ).NE.ZERO )AAQQ = MIN( AAQQ, SVA( p ) )
  599. AAPP = MAX( AAPP, SVA( p ) )
  600. 4781 CONTINUE
  601. *
  602. * #:) Quick return for zero matrix
  603. *
  604. IF( AAPP.EQ.ZERO ) THEN
  605. IF( LSVEC )CALL SLASET( 'G', M, N, ZERO, ONE, A, LDA )
  606. WORK( 1 ) = ONE
  607. WORK( 2 ) = ZERO
  608. WORK( 3 ) = ZERO
  609. WORK( 4 ) = ZERO
  610. WORK( 5 ) = ZERO
  611. WORK( 6 ) = ZERO
  612. RETURN
  613. END IF
  614. *
  615. * #:) Quick return for one-column matrix
  616. *
  617. IF( N.EQ.1 ) THEN
  618. IF( LSVEC )CALL SLASCL( 'G', 0, 0, SVA( 1 ), SKL, M, 1,
  619. $ A( 1, 1 ), LDA, IERR )
  620. WORK( 1 ) = ONE / SKL
  621. IF( SVA( 1 ).GE.SFMIN ) THEN
  622. WORK( 2 ) = ONE
  623. ELSE
  624. WORK( 2 ) = ZERO
  625. END IF
  626. WORK( 3 ) = ZERO
  627. WORK( 4 ) = ZERO
  628. WORK( 5 ) = ZERO
  629. WORK( 6 ) = ZERO
  630. RETURN
  631. END IF
  632. *
  633. * Protect small singular values from underflow, and try to
  634. * avoid underflows/overflows in computing Jacobi rotations.
  635. *
  636. SN = SQRT( SFMIN / EPSLN )
  637. TEMP1 = SQRT( BIG / FLOAT( N ) )
  638. IF( ( AAPP.LE.SN ) .OR. ( AAQQ.GE.TEMP1 ) .OR.
  639. $ ( ( SN.LE.AAQQ ) .AND. ( AAPP.LE.TEMP1 ) ) ) THEN
  640. TEMP1 = MIN( BIG, TEMP1 / AAPP )
  641. * AAQQ = AAQQ*TEMP1
  642. * AAPP = AAPP*TEMP1
  643. ELSE IF( ( AAQQ.LE.SN ) .AND. ( AAPP.LE.TEMP1 ) ) THEN
  644. TEMP1 = MIN( SN / AAQQ, BIG / ( AAPP*SQRT( FLOAT( N ) ) ) )
  645. * AAQQ = AAQQ*TEMP1
  646. * AAPP = AAPP*TEMP1
  647. ELSE IF( ( AAQQ.GE.SN ) .AND. ( AAPP.GE.TEMP1 ) ) THEN
  648. TEMP1 = MAX( SN / AAQQ, TEMP1 / AAPP )
  649. * AAQQ = AAQQ*TEMP1
  650. * AAPP = AAPP*TEMP1
  651. ELSE IF( ( AAQQ.LE.SN ) .AND. ( AAPP.GE.TEMP1 ) ) THEN
  652. TEMP1 = MIN( SN / AAQQ, BIG / ( SQRT( FLOAT( N ) )*AAPP ) )
  653. * AAQQ = AAQQ*TEMP1
  654. * AAPP = AAPP*TEMP1
  655. ELSE
  656. TEMP1 = ONE
  657. END IF
  658. *
  659. * Scale, if necessary
  660. *
  661. IF( TEMP1.NE.ONE ) THEN
  662. CALL SLASCL( 'G', 0, 0, ONE, TEMP1, N, 1, SVA, N, IERR )
  663. END IF
  664. SKL = TEMP1*SKL
  665. IF( SKL.NE.ONE ) THEN
  666. CALL SLASCL( JOBA, 0, 0, ONE, SKL, M, N, A, LDA, IERR )
  667. SKL = ONE / SKL
  668. END IF
  669. *
  670. * Row-cyclic Jacobi SVD algorithm with column pivoting
  671. *
  672. EMPTSW = ( N*( N-1 ) ) / 2
  673. NOTROT = 0
  674. FASTR( 1 ) = ZERO
  675. *
  676. * A is represented in factored form A = A * diag(WORK), where diag(WORK)
  677. * is initialized to identity. WORK is updated during fast scaled
  678. * rotations.
  679. *
  680. DO 1868 q = 1, N
  681. WORK( q ) = ONE
  682. 1868 CONTINUE
  683. *
  684. *
  685. SWBAND = 3
  686. *[TP] SWBAND is a tuning parameter [TP]. It is meaningful and effective
  687. * if SGESVJ is used as a computational routine in the preconditioned
  688. * Jacobi SVD algorithm SGESVJ. For sweeps i=1:SWBAND the procedure
  689. * works on pivots inside a band-like region around the diagonal.
  690. * The boundaries are determined dynamically, based on the number of
  691. * pivots above a threshold.
  692. *
  693. KBL = MIN( 8, N )
  694. *[TP] KBL is a tuning parameter that defines the tile size in the
  695. * tiling of the p-q loops of pivot pairs. In general, an optimal
  696. * value of KBL depends on the matrix dimensions and on the
  697. * parameters of the computer's memory.
  698. *
  699. NBL = N / KBL
  700. IF( ( NBL*KBL ).NE.N )NBL = NBL + 1
  701. *
  702. BLSKIP = KBL**2
  703. *[TP] BLKSKIP is a tuning parameter that depends on SWBAND and KBL.
  704. *
  705. ROWSKIP = MIN( 5, KBL )
  706. *[TP] ROWSKIP is a tuning parameter.
  707. *
  708. LKAHEAD = 1
  709. *[TP] LKAHEAD is a tuning parameter.
  710. *
  711. * Quasi block transformations, using the lower (upper) triangular
  712. * structure of the input matrix. The quasi-block-cycling usually
  713. * invokes cubic convergence. Big part of this cycle is done inside
  714. * canonical subspaces of dimensions less than M.
  715. *
  716. IF( ( LOWER .OR. UPPER ) .AND. ( N.GT.MAX( 64, 4*KBL ) ) ) THEN
  717. *[TP] The number of partition levels and the actual partition are
  718. * tuning parameters.
  719. N4 = N / 4
  720. N2 = N / 2
  721. N34 = 3*N4
  722. IF( APPLV ) THEN
  723. q = 0
  724. ELSE
  725. q = 1
  726. END IF
  727. *
  728. IF( LOWER ) THEN
  729. *
  730. * This works very well on lower triangular matrices, in particular
  731. * in the framework of the preconditioned Jacobi SVD (xGEJSV).
  732. * The idea is simple:
  733. * [+ 0 0 0] Note that Jacobi transformations of [0 0]
  734. * [+ + 0 0] [0 0]
  735. * [+ + x 0] actually work on [x 0] [x 0]
  736. * [+ + x x] [x x]. [x x]
  737. *
  738. CALL SGSVJ0( JOBV, M-N34, N-N34, A( N34+1, N34+1 ), LDA,
  739. $ WORK( N34+1 ), SVA( N34+1 ), MVL,
  740. $ V( N34*q+1, N34+1 ), LDV, EPSLN, SFMIN, TOL,
  741. $ 2, WORK( N+1 ), LWORK-N, IERR )
  742. *
  743. CALL SGSVJ0( JOBV, M-N2, N34-N2, A( N2+1, N2+1 ), LDA,
  744. $ WORK( N2+1 ), SVA( N2+1 ), MVL,
  745. $ V( N2*q+1, N2+1 ), LDV, EPSLN, SFMIN, TOL, 2,
  746. $ WORK( N+1 ), LWORK-N, IERR )
  747. *
  748. CALL SGSVJ1( JOBV, M-N2, N-N2, N4, A( N2+1, N2+1 ), LDA,
  749. $ WORK( N2+1 ), SVA( N2+1 ), MVL,
  750. $ V( N2*q+1, N2+1 ), LDV, EPSLN, SFMIN, TOL, 1,
  751. $ WORK( N+1 ), LWORK-N, IERR )
  752. *
  753. CALL SGSVJ0( JOBV, M-N4, N2-N4, A( N4+1, N4+1 ), LDA,
  754. $ WORK( N4+1 ), SVA( N4+1 ), MVL,
  755. $ V( N4*q+1, N4+1 ), LDV, EPSLN, SFMIN, TOL, 1,
  756. $ WORK( N+1 ), LWORK-N, IERR )
  757. *
  758. CALL SGSVJ0( JOBV, M, N4, A, LDA, WORK, SVA, MVL, V, LDV,
  759. $ EPSLN, SFMIN, TOL, 1, WORK( N+1 ), LWORK-N,
  760. $ IERR )
  761. *
  762. CALL SGSVJ1( JOBV, M, N2, N4, A, LDA, WORK, SVA, MVL, V,
  763. $ LDV, EPSLN, SFMIN, TOL, 1, WORK( N+1 ),
  764. $ LWORK-N, IERR )
  765. *
  766. *
  767. ELSE IF( UPPER ) THEN
  768. *
  769. *
  770. CALL SGSVJ0( JOBV, N4, N4, A, LDA, WORK, SVA, MVL, V, LDV,
  771. $ EPSLN, SFMIN, TOL, 2, WORK( N+1 ), LWORK-N,
  772. $ IERR )
  773. *
  774. CALL SGSVJ0( JOBV, N2, N4, A( 1, N4+1 ), LDA, WORK( N4+1 ),
  775. $ SVA( N4+1 ), MVL, V( N4*q+1, N4+1 ), LDV,
  776. $ EPSLN, SFMIN, TOL, 1, WORK( N+1 ), LWORK-N,
  777. $ IERR )
  778. *
  779. CALL SGSVJ1( JOBV, N2, N2, N4, A, LDA, WORK, SVA, MVL, V,
  780. $ LDV, EPSLN, SFMIN, TOL, 1, WORK( N+1 ),
  781. $ LWORK-N, IERR )
  782. *
  783. CALL SGSVJ0( JOBV, N2+N4, N4, A( 1, N2+1 ), LDA,
  784. $ WORK( N2+1 ), SVA( N2+1 ), MVL,
  785. $ V( N2*q+1, N2+1 ), LDV, EPSLN, SFMIN, TOL, 1,
  786. $ WORK( N+1 ), LWORK-N, IERR )
  787. END IF
  788. *
  789. END IF
  790. *
  791. * .. Row-cyclic pivot strategy with de Rijk's pivoting ..
  792. *
  793. DO 1993 i = 1, NSWEEP
  794. *
  795. * .. go go go ...
  796. *
  797. MXAAPQ = ZERO
  798. MXSINJ = ZERO
  799. ISWROT = 0
  800. *
  801. NOTROT = 0
  802. PSKIPPED = 0
  803. *
  804. * Each sweep is unrolled using KBL-by-KBL tiles over the pivot pairs
  805. * 1 <= p < q <= N. This is the first step toward a blocked implementation
  806. * of the rotations. New implementation, based on block transformations,
  807. * is under development.
  808. *
  809. DO 2000 ibr = 1, NBL
  810. *
  811. igl = ( ibr-1 )*KBL + 1
  812. *
  813. DO 1002 ir1 = 0, MIN( LKAHEAD, NBL-ibr )
  814. *
  815. igl = igl + ir1*KBL
  816. *
  817. DO 2001 p = igl, MIN( igl+KBL-1, N-1 )
  818. *
  819. * .. de Rijk's pivoting
  820. *
  821. q = ISAMAX( N-p+1, SVA( p ), 1 ) + p - 1
  822. IF( p.NE.q ) THEN
  823. CALL SSWAP( M, A( 1, p ), 1, A( 1, q ), 1 )
  824. IF( RSVEC )CALL SSWAP( MVL, V( 1, p ), 1,
  825. $ V( 1, q ), 1 )
  826. TEMP1 = SVA( p )
  827. SVA( p ) = SVA( q )
  828. SVA( q ) = TEMP1
  829. TEMP1 = WORK( p )
  830. WORK( p ) = WORK( q )
  831. WORK( q ) = TEMP1
  832. END IF
  833. *
  834. IF( ir1.EQ.0 ) THEN
  835. *
  836. * Column norms are periodically updated by explicit
  837. * norm computation.
  838. * Caveat:
  839. * Unfortunately, some BLAS implementations compute SNRM2(M,A(1,p),1)
  840. * as SQRT(SDOT(M,A(1,p),1,A(1,p),1)), which may cause the result to
  841. * overflow for ||A(:,p)||_2 > SQRT(overflow_threshold), and to
  842. * underflow for ||A(:,p)||_2 < SQRT(underflow_threshold).
  843. * Hence, SNRM2 cannot be trusted, not even in the case when
  844. * the true norm is far from the under(over)flow boundaries.
  845. * If properly implemented SNRM2 is available, the IF-THEN-ELSE
  846. * below should read "AAPP = SNRM2( M, A(1,p), 1 ) * WORK(p)".
  847. *
  848. IF( ( SVA( p ).LT.ROOTBIG ) .AND.
  849. $ ( SVA( p ).GT.ROOTSFMIN ) ) THEN
  850. SVA( p ) = SNRM2( M, A( 1, p ), 1 )*WORK( p )
  851. ELSE
  852. TEMP1 = ZERO
  853. AAPP = ONE
  854. CALL SLASSQ( M, A( 1, p ), 1, TEMP1, AAPP )
  855. SVA( p ) = TEMP1*SQRT( AAPP )*WORK( p )
  856. END IF
  857. AAPP = SVA( p )
  858. ELSE
  859. AAPP = SVA( p )
  860. END IF
  861. *
  862. IF( AAPP.GT.ZERO ) THEN
  863. *
  864. PSKIPPED = 0
  865. *
  866. DO 2002 q = p + 1, MIN( igl+KBL-1, N )
  867. *
  868. AAQQ = SVA( q )
  869. *
  870. IF( AAQQ.GT.ZERO ) THEN
  871. *
  872. AAPP0 = AAPP
  873. IF( AAQQ.GE.ONE ) THEN
  874. ROTOK = ( SMALL*AAPP ).LE.AAQQ
  875. IF( AAPP.LT.( BIG / AAQQ ) ) THEN
  876. AAPQ = ( SDOT( M, A( 1, p ), 1, A( 1,
  877. $ q ), 1 )*WORK( p )*WORK( q ) /
  878. $ AAQQ ) / AAPP
  879. ELSE
  880. CALL SCOPY( M, A( 1, p ), 1,
  881. $ WORK( N+1 ), 1 )
  882. CALL SLASCL( 'G', 0, 0, AAPP,
  883. $ WORK( p ), M, 1,
  884. $ WORK( N+1 ), LDA, IERR )
  885. AAPQ = SDOT( M, WORK( N+1 ), 1,
  886. $ A( 1, q ), 1 )*WORK( q ) / AAQQ
  887. END IF
  888. ELSE
  889. ROTOK = AAPP.LE.( AAQQ / SMALL )
  890. IF( AAPP.GT.( SMALL / AAQQ ) ) THEN
  891. AAPQ = ( SDOT( M, A( 1, p ), 1, A( 1,
  892. $ q ), 1 )*WORK( p )*WORK( q ) /
  893. $ AAQQ ) / AAPP
  894. ELSE
  895. CALL SCOPY( M, A( 1, q ), 1,
  896. $ WORK( N+1 ), 1 )
  897. CALL SLASCL( 'G', 0, 0, AAQQ,
  898. $ WORK( q ), M, 1,
  899. $ WORK( N+1 ), LDA, IERR )
  900. AAPQ = SDOT( M, WORK( N+1 ), 1,
  901. $ A( 1, p ), 1 )*WORK( p ) / AAPP
  902. END IF
  903. END IF
  904. *
  905. MXAAPQ = MAX( MXAAPQ, ABS( AAPQ ) )
  906. *
  907. * TO rotate or NOT to rotate, THAT is the question ...
  908. *
  909. IF( ABS( AAPQ ).GT.TOL ) THEN
  910. *
  911. * .. rotate
  912. *[RTD] ROTATED = ROTATED + ONE
  913. *
  914. IF( ir1.EQ.0 ) THEN
  915. NOTROT = 0
  916. PSKIPPED = 0
  917. ISWROT = ISWROT + 1
  918. END IF
  919. *
  920. IF( ROTOK ) THEN
  921. *
  922. AQOAP = AAQQ / AAPP
  923. APOAQ = AAPP / AAQQ
  924. THETA = -HALF*ABS( AQOAP-APOAQ ) / AAPQ
  925. *
  926. IF( ABS( THETA ).GT.BIGTHETA ) THEN
  927. *
  928. T = HALF / THETA
  929. FASTR( 3 ) = T*WORK( p ) / WORK( q )
  930. FASTR( 4 ) = -T*WORK( q ) /
  931. $ WORK( p )
  932. CALL SROTM( M, A( 1, p ), 1,
  933. $ A( 1, q ), 1, FASTR )
  934. IF( RSVEC )CALL SROTM( MVL,
  935. $ V( 1, p ), 1,
  936. $ V( 1, q ), 1,
  937. $ FASTR )
  938. SVA( q ) = AAQQ*SQRT( MAX( ZERO,
  939. $ ONE+T*APOAQ*AAPQ ) )
  940. AAPP = AAPP*SQRT( MAX( ZERO,
  941. $ ONE-T*AQOAP*AAPQ ) )
  942. MXSINJ = MAX( MXSINJ, ABS( T ) )
  943. *
  944. ELSE
  945. *
  946. * .. choose correct signum for THETA and rotate
  947. *
  948. THSIGN = -SIGN( ONE, AAPQ )
  949. T = ONE / ( THETA+THSIGN*
  950. $ SQRT( ONE+THETA*THETA ) )
  951. CS = SQRT( ONE / ( ONE+T*T ) )
  952. SN = T*CS
  953. *
  954. MXSINJ = MAX( MXSINJ, ABS( SN ) )
  955. SVA( q ) = AAQQ*SQRT( MAX( ZERO,
  956. $ ONE+T*APOAQ*AAPQ ) )
  957. AAPP = AAPP*SQRT( MAX( ZERO,
  958. $ ONE-T*AQOAP*AAPQ ) )
  959. *
  960. APOAQ = WORK( p ) / WORK( q )
  961. AQOAP = WORK( q ) / WORK( p )
  962. IF( WORK( p ).GE.ONE ) THEN
  963. IF( WORK( q ).GE.ONE ) THEN
  964. FASTR( 3 ) = T*APOAQ
  965. FASTR( 4 ) = -T*AQOAP
  966. WORK( p ) = WORK( p )*CS
  967. WORK( q ) = WORK( q )*CS
  968. CALL SROTM( M, A( 1, p ), 1,
  969. $ A( 1, q ), 1,
  970. $ FASTR )
  971. IF( RSVEC )CALL SROTM( MVL,
  972. $ V( 1, p ), 1, V( 1, q ),
  973. $ 1, FASTR )
  974. ELSE
  975. CALL SAXPY( M, -T*AQOAP,
  976. $ A( 1, q ), 1,
  977. $ A( 1, p ), 1 )
  978. CALL SAXPY( M, CS*SN*APOAQ,
  979. $ A( 1, p ), 1,
  980. $ A( 1, q ), 1 )
  981. WORK( p ) = WORK( p )*CS
  982. WORK( q ) = WORK( q ) / CS
  983. IF( RSVEC ) THEN
  984. CALL SAXPY( MVL, -T*AQOAP,
  985. $ V( 1, q ), 1,
  986. $ V( 1, p ), 1 )
  987. CALL SAXPY( MVL,
  988. $ CS*SN*APOAQ,
  989. $ V( 1, p ), 1,
  990. $ V( 1, q ), 1 )
  991. END IF
  992. END IF
  993. ELSE
  994. IF( WORK( q ).GE.ONE ) THEN
  995. CALL SAXPY( M, T*APOAQ,
  996. $ A( 1, p ), 1,
  997. $ A( 1, q ), 1 )
  998. CALL SAXPY( M, -CS*SN*AQOAP,
  999. $ A( 1, q ), 1,
  1000. $ A( 1, p ), 1 )
  1001. WORK( p ) = WORK( p ) / CS
  1002. WORK( q ) = WORK( q )*CS
  1003. IF( RSVEC ) THEN
  1004. CALL SAXPY( MVL, T*APOAQ,
  1005. $ V( 1, p ), 1,
  1006. $ V( 1, q ), 1 )
  1007. CALL SAXPY( MVL,
  1008. $ -CS*SN*AQOAP,
  1009. $ V( 1, q ), 1,
  1010. $ V( 1, p ), 1 )
  1011. END IF
  1012. ELSE
  1013. IF( WORK( p ).GE.WORK( q ) )
  1014. $ THEN
  1015. CALL SAXPY( M, -T*AQOAP,
  1016. $ A( 1, q ), 1,
  1017. $ A( 1, p ), 1 )
  1018. CALL SAXPY( M, CS*SN*APOAQ,
  1019. $ A( 1, p ), 1,
  1020. $ A( 1, q ), 1 )
  1021. WORK( p ) = WORK( p )*CS
  1022. WORK( q ) = WORK( q ) / CS
  1023. IF( RSVEC ) THEN
  1024. CALL SAXPY( MVL,
  1025. $ -T*AQOAP,
  1026. $ V( 1, q ), 1,
  1027. $ V( 1, p ), 1 )
  1028. CALL SAXPY( MVL,
  1029. $ CS*SN*APOAQ,
  1030. $ V( 1, p ), 1,
  1031. $ V( 1, q ), 1 )
  1032. END IF
  1033. ELSE
  1034. CALL SAXPY( M, T*APOAQ,
  1035. $ A( 1, p ), 1,
  1036. $ A( 1, q ), 1 )
  1037. CALL SAXPY( M,
  1038. $ -CS*SN*AQOAP,
  1039. $ A( 1, q ), 1,
  1040. $ A( 1, p ), 1 )
  1041. WORK( p ) = WORK( p ) / CS
  1042. WORK( q ) = WORK( q )*CS
  1043. IF( RSVEC ) THEN
  1044. CALL SAXPY( MVL,
  1045. $ T*APOAQ, V( 1, p ),
  1046. $ 1, V( 1, q ), 1 )
  1047. CALL SAXPY( MVL,
  1048. $ -CS*SN*AQOAP,
  1049. $ V( 1, q ), 1,
  1050. $ V( 1, p ), 1 )
  1051. END IF
  1052. END IF
  1053. END IF
  1054. END IF
  1055. END IF
  1056. *
  1057. ELSE
  1058. * .. have to use modified Gram-Schmidt like transformation
  1059. CALL SCOPY( M, A( 1, p ), 1,
  1060. $ WORK( N+1 ), 1 )
  1061. CALL SLASCL( 'G', 0, 0, AAPP, ONE, M,
  1062. $ 1, WORK( N+1 ), LDA,
  1063. $ IERR )
  1064. CALL SLASCL( 'G', 0, 0, AAQQ, ONE, M,
  1065. $ 1, A( 1, q ), LDA, IERR )
  1066. TEMP1 = -AAPQ*WORK( p ) / WORK( q )
  1067. CALL SAXPY( M, TEMP1, WORK( N+1 ), 1,
  1068. $ A( 1, q ), 1 )
  1069. CALL SLASCL( 'G', 0, 0, ONE, AAQQ, M,
  1070. $ 1, A( 1, q ), LDA, IERR )
  1071. SVA( q ) = AAQQ*SQRT( MAX( ZERO,
  1072. $ ONE-AAPQ*AAPQ ) )
  1073. MXSINJ = MAX( MXSINJ, SFMIN )
  1074. END IF
  1075. * END IF ROTOK THEN ... ELSE
  1076. *
  1077. * In the case of cancellation in updating SVA(q), SVA(p)
  1078. * recompute SVA(q), SVA(p).
  1079. *
  1080. IF( ( SVA( q ) / AAQQ )**2.LE.ROOTEPS )
  1081. $ THEN
  1082. IF( ( AAQQ.LT.ROOTBIG ) .AND.
  1083. $ ( AAQQ.GT.ROOTSFMIN ) ) THEN
  1084. SVA( q ) = SNRM2( M, A( 1, q ), 1 )*
  1085. $ WORK( q )
  1086. ELSE
  1087. T = ZERO
  1088. AAQQ = ONE
  1089. CALL SLASSQ( M, A( 1, q ), 1, T,
  1090. $ AAQQ )
  1091. SVA( q ) = T*SQRT( AAQQ )*WORK( q )
  1092. END IF
  1093. END IF
  1094. IF( ( AAPP / AAPP0 ).LE.ROOTEPS ) THEN
  1095. IF( ( AAPP.LT.ROOTBIG ) .AND.
  1096. $ ( AAPP.GT.ROOTSFMIN ) ) THEN
  1097. AAPP = SNRM2( M, A( 1, p ), 1 )*
  1098. $ WORK( p )
  1099. ELSE
  1100. T = ZERO
  1101. AAPP = ONE
  1102. CALL SLASSQ( M, A( 1, p ), 1, T,
  1103. $ AAPP )
  1104. AAPP = T*SQRT( AAPP )*WORK( p )
  1105. END IF
  1106. SVA( p ) = AAPP
  1107. END IF
  1108. *
  1109. ELSE
  1110. * A(:,p) and A(:,q) already numerically orthogonal
  1111. IF( ir1.EQ.0 )NOTROT = NOTROT + 1
  1112. *[RTD] SKIPPED = SKIPPED + 1
  1113. PSKIPPED = PSKIPPED + 1
  1114. END IF
  1115. ELSE
  1116. * A(:,q) is zero column
  1117. IF( ir1.EQ.0 )NOTROT = NOTROT + 1
  1118. PSKIPPED = PSKIPPED + 1
  1119. END IF
  1120. *
  1121. IF( ( i.LE.SWBAND ) .AND.
  1122. $ ( PSKIPPED.GT.ROWSKIP ) ) THEN
  1123. IF( ir1.EQ.0 )AAPP = -AAPP
  1124. NOTROT = 0
  1125. GO TO 2103
  1126. END IF
  1127. *
  1128. 2002 CONTINUE
  1129. * END q-LOOP
  1130. *
  1131. 2103 CONTINUE
  1132. * bailed out of q-loop
  1133. *
  1134. SVA( p ) = AAPP
  1135. *
  1136. ELSE
  1137. SVA( p ) = AAPP
  1138. IF( ( ir1.EQ.0 ) .AND. ( AAPP.EQ.ZERO ) )
  1139. $ NOTROT = NOTROT + MIN( igl+KBL-1, N ) - p
  1140. END IF
  1141. *
  1142. 2001 CONTINUE
  1143. * end of the p-loop
  1144. * end of doing the block ( ibr, ibr )
  1145. 1002 CONTINUE
  1146. * end of ir1-loop
  1147. *
  1148. * ... go to the off diagonal blocks
  1149. *
  1150. igl = ( ibr-1 )*KBL + 1
  1151. *
  1152. DO 2010 jbc = ibr + 1, NBL
  1153. *
  1154. jgl = ( jbc-1 )*KBL + 1
  1155. *
  1156. * doing the block at ( ibr, jbc )
  1157. *
  1158. IJBLSK = 0
  1159. DO 2100 p = igl, MIN( igl+KBL-1, N )
  1160. *
  1161. AAPP = SVA( p )
  1162. IF( AAPP.GT.ZERO ) THEN
  1163. *
  1164. PSKIPPED = 0
  1165. *
  1166. DO 2200 q = jgl, MIN( jgl+KBL-1, N )
  1167. *
  1168. AAQQ = SVA( q )
  1169. IF( AAQQ.GT.ZERO ) THEN
  1170. AAPP0 = AAPP
  1171. *
  1172. * .. M x 2 Jacobi SVD ..
  1173. *
  1174. * Safe Gram matrix computation
  1175. *
  1176. IF( AAQQ.GE.ONE ) THEN
  1177. IF( AAPP.GE.AAQQ ) THEN
  1178. ROTOK = ( SMALL*AAPP ).LE.AAQQ
  1179. ELSE
  1180. ROTOK = ( SMALL*AAQQ ).LE.AAPP
  1181. END IF
  1182. IF( AAPP.LT.( BIG / AAQQ ) ) THEN
  1183. AAPQ = ( SDOT( M, A( 1, p ), 1, A( 1,
  1184. $ q ), 1 )*WORK( p )*WORK( q ) /
  1185. $ AAQQ ) / AAPP
  1186. ELSE
  1187. CALL SCOPY( M, A( 1, p ), 1,
  1188. $ WORK( N+1 ), 1 )
  1189. CALL SLASCL( 'G', 0, 0, AAPP,
  1190. $ WORK( p ), M, 1,
  1191. $ WORK( N+1 ), LDA, IERR )
  1192. AAPQ = SDOT( M, WORK( N+1 ), 1,
  1193. $ A( 1, q ), 1 )*WORK( q ) / AAQQ
  1194. END IF
  1195. ELSE
  1196. IF( AAPP.GE.AAQQ ) THEN
  1197. ROTOK = AAPP.LE.( AAQQ / SMALL )
  1198. ELSE
  1199. ROTOK = AAQQ.LE.( AAPP / SMALL )
  1200. END IF
  1201. IF( AAPP.GT.( SMALL / AAQQ ) ) THEN
  1202. AAPQ = ( SDOT( M, A( 1, p ), 1, A( 1,
  1203. $ q ), 1 )*WORK( p )*WORK( q ) /
  1204. $ AAQQ ) / AAPP
  1205. ELSE
  1206. CALL SCOPY( M, A( 1, q ), 1,
  1207. $ WORK( N+1 ), 1 )
  1208. CALL SLASCL( 'G', 0, 0, AAQQ,
  1209. $ WORK( q ), M, 1,
  1210. $ WORK( N+1 ), LDA, IERR )
  1211. AAPQ = SDOT( M, WORK( N+1 ), 1,
  1212. $ A( 1, p ), 1 )*WORK( p ) / AAPP
  1213. END IF
  1214. END IF
  1215. *
  1216. MXAAPQ = MAX( MXAAPQ, ABS( AAPQ ) )
  1217. *
  1218. * TO rotate or NOT to rotate, THAT is the question ...
  1219. *
  1220. IF( ABS( AAPQ ).GT.TOL ) THEN
  1221. NOTROT = 0
  1222. *[RTD] ROTATED = ROTATED + 1
  1223. PSKIPPED = 0
  1224. ISWROT = ISWROT + 1
  1225. *
  1226. IF( ROTOK ) THEN
  1227. *
  1228. AQOAP = AAQQ / AAPP
  1229. APOAQ = AAPP / AAQQ
  1230. THETA = -HALF*ABS( AQOAP-APOAQ ) / AAPQ
  1231. IF( AAQQ.GT.AAPP0 )THETA = -THETA
  1232. *
  1233. IF( ABS( THETA ).GT.BIGTHETA ) THEN
  1234. T = HALF / THETA
  1235. FASTR( 3 ) = T*WORK( p ) / WORK( q )
  1236. FASTR( 4 ) = -T*WORK( q ) /
  1237. $ WORK( p )
  1238. CALL SROTM( M, A( 1, p ), 1,
  1239. $ A( 1, q ), 1, FASTR )
  1240. IF( RSVEC )CALL SROTM( MVL,
  1241. $ V( 1, p ), 1,
  1242. $ V( 1, q ), 1,
  1243. $ FASTR )
  1244. SVA( q ) = AAQQ*SQRT( MAX( ZERO,
  1245. $ ONE+T*APOAQ*AAPQ ) )
  1246. AAPP = AAPP*SQRT( MAX( ZERO,
  1247. $ ONE-T*AQOAP*AAPQ ) )
  1248. MXSINJ = MAX( MXSINJ, ABS( T ) )
  1249. ELSE
  1250. *
  1251. * .. choose correct signum for THETA and rotate
  1252. *
  1253. THSIGN = -SIGN( ONE, AAPQ )
  1254. IF( AAQQ.GT.AAPP0 )THSIGN = -THSIGN
  1255. T = ONE / ( THETA+THSIGN*
  1256. $ SQRT( ONE+THETA*THETA ) )
  1257. CS = SQRT( ONE / ( ONE+T*T ) )
  1258. SN = T*CS
  1259. MXSINJ = MAX( MXSINJ, ABS( SN ) )
  1260. SVA( q ) = AAQQ*SQRT( MAX( ZERO,
  1261. $ ONE+T*APOAQ*AAPQ ) )
  1262. AAPP = AAPP*SQRT( MAX( ZERO,
  1263. $ ONE-T*AQOAP*AAPQ ) )
  1264. *
  1265. APOAQ = WORK( p ) / WORK( q )
  1266. AQOAP = WORK( q ) / WORK( p )
  1267. IF( WORK( p ).GE.ONE ) THEN
  1268. *
  1269. IF( WORK( q ).GE.ONE ) THEN
  1270. FASTR( 3 ) = T*APOAQ
  1271. FASTR( 4 ) = -T*AQOAP
  1272. WORK( p ) = WORK( p )*CS
  1273. WORK( q ) = WORK( q )*CS
  1274. CALL SROTM( M, A( 1, p ), 1,
  1275. $ A( 1, q ), 1,
  1276. $ FASTR )
  1277. IF( RSVEC )CALL SROTM( MVL,
  1278. $ V( 1, p ), 1, V( 1, q ),
  1279. $ 1, FASTR )
  1280. ELSE
  1281. CALL SAXPY( M, -T*AQOAP,
  1282. $ A( 1, q ), 1,
  1283. $ A( 1, p ), 1 )
  1284. CALL SAXPY( M, CS*SN*APOAQ,
  1285. $ A( 1, p ), 1,
  1286. $ A( 1, q ), 1 )
  1287. IF( RSVEC ) THEN
  1288. CALL SAXPY( MVL, -T*AQOAP,
  1289. $ V( 1, q ), 1,
  1290. $ V( 1, p ), 1 )
  1291. CALL SAXPY( MVL,
  1292. $ CS*SN*APOAQ,
  1293. $ V( 1, p ), 1,
  1294. $ V( 1, q ), 1 )
  1295. END IF
  1296. WORK( p ) = WORK( p )*CS
  1297. WORK( q ) = WORK( q ) / CS
  1298. END IF
  1299. ELSE
  1300. IF( WORK( q ).GE.ONE ) THEN
  1301. CALL SAXPY( M, T*APOAQ,
  1302. $ A( 1, p ), 1,
  1303. $ A( 1, q ), 1 )
  1304. CALL SAXPY( M, -CS*SN*AQOAP,
  1305. $ A( 1, q ), 1,
  1306. $ A( 1, p ), 1 )
  1307. IF( RSVEC ) THEN
  1308. CALL SAXPY( MVL, T*APOAQ,
  1309. $ V( 1, p ), 1,
  1310. $ V( 1, q ), 1 )
  1311. CALL SAXPY( MVL,
  1312. $ -CS*SN*AQOAP,
  1313. $ V( 1, q ), 1,
  1314. $ V( 1, p ), 1 )
  1315. END IF
  1316. WORK( p ) = WORK( p ) / CS
  1317. WORK( q ) = WORK( q )*CS
  1318. ELSE
  1319. IF( WORK( p ).GE.WORK( q ) )
  1320. $ THEN
  1321. CALL SAXPY( M, -T*AQOAP,
  1322. $ A( 1, q ), 1,
  1323. $ A( 1, p ), 1 )
  1324. CALL SAXPY( M, CS*SN*APOAQ,
  1325. $ A( 1, p ), 1,
  1326. $ A( 1, q ), 1 )
  1327. WORK( p ) = WORK( p )*CS
  1328. WORK( q ) = WORK( q ) / CS
  1329. IF( RSVEC ) THEN
  1330. CALL SAXPY( MVL,
  1331. $ -T*AQOAP,
  1332. $ V( 1, q ), 1,
  1333. $ V( 1, p ), 1 )
  1334. CALL SAXPY( MVL,
  1335. $ CS*SN*APOAQ,
  1336. $ V( 1, p ), 1,
  1337. $ V( 1, q ), 1 )
  1338. END IF
  1339. ELSE
  1340. CALL SAXPY( M, T*APOAQ,
  1341. $ A( 1, p ), 1,
  1342. $ A( 1, q ), 1 )
  1343. CALL SAXPY( M,
  1344. $ -CS*SN*AQOAP,
  1345. $ A( 1, q ), 1,
  1346. $ A( 1, p ), 1 )
  1347. WORK( p ) = WORK( p ) / CS
  1348. WORK( q ) = WORK( q )*CS
  1349. IF( RSVEC ) THEN
  1350. CALL SAXPY( MVL,
  1351. $ T*APOAQ, V( 1, p ),
  1352. $ 1, V( 1, q ), 1 )
  1353. CALL SAXPY( MVL,
  1354. $ -CS*SN*AQOAP,
  1355. $ V( 1, q ), 1,
  1356. $ V( 1, p ), 1 )
  1357. END IF
  1358. END IF
  1359. END IF
  1360. END IF
  1361. END IF
  1362. *
  1363. ELSE
  1364. IF( AAPP.GT.AAQQ ) THEN
  1365. CALL SCOPY( M, A( 1, p ), 1,
  1366. $ WORK( N+1 ), 1 )
  1367. CALL SLASCL( 'G', 0, 0, AAPP, ONE,
  1368. $ M, 1, WORK( N+1 ), LDA,
  1369. $ IERR )
  1370. CALL SLASCL( 'G', 0, 0, AAQQ, ONE,
  1371. $ M, 1, A( 1, q ), LDA,
  1372. $ IERR )
  1373. TEMP1 = -AAPQ*WORK( p ) / WORK( q )
  1374. CALL SAXPY( M, TEMP1, WORK( N+1 ),
  1375. $ 1, A( 1, q ), 1 )
  1376. CALL SLASCL( 'G', 0, 0, ONE, AAQQ,
  1377. $ M, 1, A( 1, q ), LDA,
  1378. $ IERR )
  1379. SVA( q ) = AAQQ*SQRT( MAX( ZERO,
  1380. $ ONE-AAPQ*AAPQ ) )
  1381. MXSINJ = MAX( MXSINJ, SFMIN )
  1382. ELSE
  1383. CALL SCOPY( M, A( 1, q ), 1,
  1384. $ WORK( N+1 ), 1 )
  1385. CALL SLASCL( 'G', 0, 0, AAQQ, ONE,
  1386. $ M, 1, WORK( N+1 ), LDA,
  1387. $ IERR )
  1388. CALL SLASCL( 'G', 0, 0, AAPP, ONE,
  1389. $ M, 1, A( 1, p ), LDA,
  1390. $ IERR )
  1391. TEMP1 = -AAPQ*WORK( q ) / WORK( p )
  1392. CALL SAXPY( M, TEMP1, WORK( N+1 ),
  1393. $ 1, A( 1, p ), 1 )
  1394. CALL SLASCL( 'G', 0, 0, ONE, AAPP,
  1395. $ M, 1, A( 1, p ), LDA,
  1396. $ IERR )
  1397. SVA( p ) = AAPP*SQRT( MAX( ZERO,
  1398. $ ONE-AAPQ*AAPQ ) )
  1399. MXSINJ = MAX( MXSINJ, SFMIN )
  1400. END IF
  1401. END IF
  1402. * END IF ROTOK THEN ... ELSE
  1403. *
  1404. * In the case of cancellation in updating SVA(q)
  1405. * .. recompute SVA(q)
  1406. IF( ( SVA( q ) / AAQQ )**2.LE.ROOTEPS )
  1407. $ THEN
  1408. IF( ( AAQQ.LT.ROOTBIG ) .AND.
  1409. $ ( AAQQ.GT.ROOTSFMIN ) ) THEN
  1410. SVA( q ) = SNRM2( M, A( 1, q ), 1 )*
  1411. $ WORK( q )
  1412. ELSE
  1413. T = ZERO
  1414. AAQQ = ONE
  1415. CALL SLASSQ( M, A( 1, q ), 1, T,
  1416. $ AAQQ )
  1417. SVA( q ) = T*SQRT( AAQQ )*WORK( q )
  1418. END IF
  1419. END IF
  1420. IF( ( AAPP / AAPP0 )**2.LE.ROOTEPS ) THEN
  1421. IF( ( AAPP.LT.ROOTBIG ) .AND.
  1422. $ ( AAPP.GT.ROOTSFMIN ) ) THEN
  1423. AAPP = SNRM2( M, A( 1, p ), 1 )*
  1424. $ WORK( p )
  1425. ELSE
  1426. T = ZERO
  1427. AAPP = ONE
  1428. CALL SLASSQ( M, A( 1, p ), 1, T,
  1429. $ AAPP )
  1430. AAPP = T*SQRT( AAPP )*WORK( p )
  1431. END IF
  1432. SVA( p ) = AAPP
  1433. END IF
  1434. * end of OK rotation
  1435. ELSE
  1436. NOTROT = NOTROT + 1
  1437. *[RTD] SKIPPED = SKIPPED + 1
  1438. PSKIPPED = PSKIPPED + 1
  1439. IJBLSK = IJBLSK + 1
  1440. END IF
  1441. ELSE
  1442. NOTROT = NOTROT + 1
  1443. PSKIPPED = PSKIPPED + 1
  1444. IJBLSK = IJBLSK + 1
  1445. END IF
  1446. *
  1447. IF( ( i.LE.SWBAND ) .AND. ( IJBLSK.GE.BLSKIP ) )
  1448. $ THEN
  1449. SVA( p ) = AAPP
  1450. NOTROT = 0
  1451. GO TO 2011
  1452. END IF
  1453. IF( ( i.LE.SWBAND ) .AND.
  1454. $ ( PSKIPPED.GT.ROWSKIP ) ) THEN
  1455. AAPP = -AAPP
  1456. NOTROT = 0
  1457. GO TO 2203
  1458. END IF
  1459. *
  1460. 2200 CONTINUE
  1461. * end of the q-loop
  1462. 2203 CONTINUE
  1463. *
  1464. SVA( p ) = AAPP
  1465. *
  1466. ELSE
  1467. *
  1468. IF( AAPP.EQ.ZERO )NOTROT = NOTROT +
  1469. $ MIN( jgl+KBL-1, N ) - jgl + 1
  1470. IF( AAPP.LT.ZERO )NOTROT = 0
  1471. *
  1472. END IF
  1473. *
  1474. 2100 CONTINUE
  1475. * end of the p-loop
  1476. 2010 CONTINUE
  1477. * end of the jbc-loop
  1478. 2011 CONTINUE
  1479. *2011 bailed out of the jbc-loop
  1480. DO 2012 p = igl, MIN( igl+KBL-1, N )
  1481. SVA( p ) = ABS( SVA( p ) )
  1482. 2012 CONTINUE
  1483. ***
  1484. 2000 CONTINUE
  1485. *2000 :: end of the ibr-loop
  1486. *
  1487. * .. update SVA(N)
  1488. IF( ( SVA( N ).LT.ROOTBIG ) .AND. ( SVA( N ).GT.ROOTSFMIN ) )
  1489. $ THEN
  1490. SVA( N ) = SNRM2( M, A( 1, N ), 1 )*WORK( N )
  1491. ELSE
  1492. T = ZERO
  1493. AAPP = ONE
  1494. CALL SLASSQ( M, A( 1, N ), 1, T, AAPP )
  1495. SVA( N ) = T*SQRT( AAPP )*WORK( N )
  1496. END IF
  1497. *
  1498. * Additional steering devices
  1499. *
  1500. IF( ( i.LT.SWBAND ) .AND. ( ( MXAAPQ.LE.ROOTTOL ) .OR.
  1501. $ ( ISWROT.LE.N ) ) )SWBAND = i
  1502. *
  1503. IF( ( i.GT.SWBAND+1 ) .AND. ( MXAAPQ.LT.SQRT( FLOAT( N ) )*
  1504. $ TOL ) .AND. ( FLOAT( N )*MXAAPQ*MXSINJ.LT.TOL ) ) THEN
  1505. GO TO 1994
  1506. END IF
  1507. *
  1508. IF( NOTROT.GE.EMPTSW )GO TO 1994
  1509. *
  1510. 1993 CONTINUE
  1511. * end i=1:NSWEEP loop
  1512. *
  1513. * #:( Reaching this point means that the procedure has not converged.
  1514. INFO = NSWEEP - 1
  1515. GO TO 1995
  1516. *
  1517. 1994 CONTINUE
  1518. * #:) Reaching this point means numerical convergence after the i-th
  1519. * sweep.
  1520. *
  1521. INFO = 0
  1522. * #:) INFO = 0 confirms successful iterations.
  1523. 1995 CONTINUE
  1524. *
  1525. * Sort the singular values and find how many are above
  1526. * the underflow threshold.
  1527. *
  1528. N2 = 0
  1529. N4 = 0
  1530. DO 5991 p = 1, N - 1
  1531. q = ISAMAX( N-p+1, SVA( p ), 1 ) + p - 1
  1532. IF( p.NE.q ) THEN
  1533. TEMP1 = SVA( p )
  1534. SVA( p ) = SVA( q )
  1535. SVA( q ) = TEMP1
  1536. TEMP1 = WORK( p )
  1537. WORK( p ) = WORK( q )
  1538. WORK( q ) = TEMP1
  1539. CALL SSWAP( M, A( 1, p ), 1, A( 1, q ), 1 )
  1540. IF( RSVEC )CALL SSWAP( MVL, V( 1, p ), 1, V( 1, q ), 1 )
  1541. END IF
  1542. IF( SVA( p ).NE.ZERO ) THEN
  1543. N4 = N4 + 1
  1544. IF( SVA( p )*SKL.GT.SFMIN )N2 = N2 + 1
  1545. END IF
  1546. 5991 CONTINUE
  1547. IF( SVA( N ).NE.ZERO ) THEN
  1548. N4 = N4 + 1
  1549. IF( SVA( N )*SKL.GT.SFMIN )N2 = N2 + 1
  1550. END IF
  1551. *
  1552. * Normalize the left singular vectors.
  1553. *
  1554. IF( LSVEC .OR. UCTOL ) THEN
  1555. DO 1998 p = 1, N2
  1556. CALL SSCAL( M, WORK( p ) / SVA( p ), A( 1, p ), 1 )
  1557. 1998 CONTINUE
  1558. END IF
  1559. *
  1560. * Scale the product of Jacobi rotations (assemble the fast rotations).
  1561. *
  1562. IF( RSVEC ) THEN
  1563. IF( APPLV ) THEN
  1564. DO 2398 p = 1, N
  1565. CALL SSCAL( MVL, WORK( p ), V( 1, p ), 1 )
  1566. 2398 CONTINUE
  1567. ELSE
  1568. DO 2399 p = 1, N
  1569. TEMP1 = ONE / SNRM2( MVL, V( 1, p ), 1 )
  1570. CALL SSCAL( MVL, TEMP1, V( 1, p ), 1 )
  1571. 2399 CONTINUE
  1572. END IF
  1573. END IF
  1574. *
  1575. * Undo scaling, if necessary (and possible).
  1576. IF( ( ( SKL.GT.ONE ) .AND. ( SVA( 1 ).LT.( BIG / SKL ) ) )
  1577. $ .OR. ( ( SKL.LT.ONE ) .AND. ( SVA( MAX( N2, 1 ) ) .GT.
  1578. $ ( SFMIN / SKL ) ) ) ) THEN
  1579. DO 2400 p = 1, N
  1580. SVA( P ) = SKL*SVA( P )
  1581. 2400 CONTINUE
  1582. SKL = ONE
  1583. END IF
  1584. *
  1585. WORK( 1 ) = SKL
  1586. * The singular values of A are SKL*SVA(1:N). If SKL.NE.ONE
  1587. * then some of the singular values may overflow or underflow and
  1588. * the spectrum is given in this factored representation.
  1589. *
  1590. WORK( 2 ) = FLOAT( N4 )
  1591. * N4 is the number of computed nonzero singular values of A.
  1592. *
  1593. WORK( 3 ) = FLOAT( N2 )
  1594. * N2 is the number of singular values of A greater than SFMIN.
  1595. * If N2<N, SVA(N2:N) contains ZEROS and/or denormalized numbers
  1596. * that may carry some information.
  1597. *
  1598. WORK( 4 ) = FLOAT( i )
  1599. * i is the index of the last sweep before declaring convergence.
  1600. *
  1601. WORK( 5 ) = MXAAPQ
  1602. * MXAAPQ is the largest absolute value of scaled pivots in the
  1603. * last sweep
  1604. *
  1605. WORK( 6 ) = MXSINJ
  1606. * MXSINJ is the largest absolute value of the sines of Jacobi angles
  1607. * in the last sweep
  1608. *
  1609. RETURN
  1610. * ..
  1611. * .. END OF SGESVJ
  1612. * ..
  1613. END