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.

slaqr3.f 21 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690
  1. *> \brief \b SLAQR3 performs the orthogonal similarity transformation of a Hessenberg matrix to detect and deflate fully converged eigenvalues from a trailing principal submatrix (aggressive early deflation).
  2. *
  3. * =========== DOCUMENTATION ===========
  4. *
  5. * Online html documentation available at
  6. * http://www.netlib.org/lapack/explore-html/
  7. *
  8. *> \htmlonly
  9. *> Download SLAQR3 + dependencies
  10. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/slaqr3.f">
  11. *> [TGZ]</a>
  12. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/slaqr3.f">
  13. *> [ZIP]</a>
  14. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/slaqr3.f">
  15. *> [TXT]</a>
  16. *> \endhtmlonly
  17. *
  18. * Definition:
  19. * ===========
  20. *
  21. * SUBROUTINE SLAQR3( WANTT, WANTZ, N, KTOP, KBOT, NW, H, LDH, ILOZ,
  22. * IHIZ, Z, LDZ, NS, ND, SR, SI, V, LDV, NH, T,
  23. * LDT, NV, WV, LDWV, WORK, LWORK )
  24. *
  25. * .. Scalar Arguments ..
  26. * INTEGER IHIZ, ILOZ, KBOT, KTOP, LDH, LDT, LDV, LDWV,
  27. * $ LDZ, LWORK, N, ND, NH, NS, NV, NW
  28. * LOGICAL WANTT, WANTZ
  29. * ..
  30. * .. Array Arguments ..
  31. * REAL H( LDH, * ), SI( * ), SR( * ), T( LDT, * ),
  32. * $ V( LDV, * ), WORK( * ), WV( LDWV, * ),
  33. * $ Z( LDZ, * )
  34. * ..
  35. *
  36. *
  37. *> \par Purpose:
  38. * =============
  39. *>
  40. *> \verbatim
  41. *>
  42. *> Aggressive early deflation:
  43. *>
  44. *> SLAQR3 accepts as input an upper Hessenberg matrix
  45. *> H and performs an orthogonal similarity transformation
  46. *> designed to detect and deflate fully converged eigenvalues from
  47. *> a trailing principal submatrix. On output H has been over-
  48. *> written by a new Hessenberg matrix that is a perturbation of
  49. *> an orthogonal similarity transformation of H. It is to be
  50. *> hoped that the final version of H has many zero subdiagonal
  51. *> entries.
  52. *> \endverbatim
  53. *
  54. * Arguments:
  55. * ==========
  56. *
  57. *> \param[in] WANTT
  58. *> \verbatim
  59. *> WANTT is LOGICAL
  60. *> If .TRUE., then the Hessenberg matrix H is fully updated
  61. *> so that the quasi-triangular Schur factor may be
  62. *> computed (in cooperation with the calling subroutine).
  63. *> If .FALSE., then only enough of H is updated to preserve
  64. *> the eigenvalues.
  65. *> \endverbatim
  66. *>
  67. *> \param[in] WANTZ
  68. *> \verbatim
  69. *> WANTZ is LOGICAL
  70. *> If .TRUE., then the orthogonal matrix Z is updated so
  71. *> so that the orthogonal Schur factor may be computed
  72. *> (in cooperation with the calling subroutine).
  73. *> If .FALSE., then Z is not referenced.
  74. *> \endverbatim
  75. *>
  76. *> \param[in] N
  77. *> \verbatim
  78. *> N is INTEGER
  79. *> The order of the matrix H and (if WANTZ is .TRUE.) the
  80. *> order of the orthogonal matrix Z.
  81. *> \endverbatim
  82. *>
  83. *> \param[in] KTOP
  84. *> \verbatim
  85. *> KTOP is INTEGER
  86. *> It is assumed that either KTOP = 1 or H(KTOP,KTOP-1)=0.
  87. *> KBOT and KTOP together determine an isolated block
  88. *> along the diagonal of the Hessenberg matrix.
  89. *> \endverbatim
  90. *>
  91. *> \param[in] KBOT
  92. *> \verbatim
  93. *> KBOT is INTEGER
  94. *> It is assumed without a check that either
  95. *> KBOT = N or H(KBOT+1,KBOT)=0. KBOT and KTOP together
  96. *> determine an isolated block along the diagonal of the
  97. *> Hessenberg matrix.
  98. *> \endverbatim
  99. *>
  100. *> \param[in] NW
  101. *> \verbatim
  102. *> NW is INTEGER
  103. *> Deflation window size. 1 <= NW <= (KBOT-KTOP+1).
  104. *> \endverbatim
  105. *>
  106. *> \param[in,out] H
  107. *> \verbatim
  108. *> H is REAL array, dimension (LDH,N)
  109. *> On input the initial N-by-N section of H stores the
  110. *> Hessenberg matrix undergoing aggressive early deflation.
  111. *> On output H has been transformed by an orthogonal
  112. *> similarity transformation, perturbed, and the returned
  113. *> to Hessenberg form that (it is to be hoped) has some
  114. *> zero subdiagonal entries.
  115. *> \endverbatim
  116. *>
  117. *> \param[in] LDH
  118. *> \verbatim
  119. *> LDH is INTEGER
  120. *> Leading dimension of H just as declared in the calling
  121. *> subroutine. N <= LDH
  122. *> \endverbatim
  123. *>
  124. *> \param[in] ILOZ
  125. *> \verbatim
  126. *> ILOZ is INTEGER
  127. *> \endverbatim
  128. *>
  129. *> \param[in] IHIZ
  130. *> \verbatim
  131. *> IHIZ is INTEGER
  132. *> Specify the rows of Z to which transformations must be
  133. *> applied if WANTZ is .TRUE.. 1 <= ILOZ <= IHIZ <= N.
  134. *> \endverbatim
  135. *>
  136. *> \param[in,out] Z
  137. *> \verbatim
  138. *> Z is REAL array, dimension (LDZ,N)
  139. *> IF WANTZ is .TRUE., then on output, the orthogonal
  140. *> similarity transformation mentioned above has been
  141. *> accumulated into Z(ILOZ:IHIZ,ILOZ:IHIZ) from the right.
  142. *> If WANTZ is .FALSE., then Z is unreferenced.
  143. *> \endverbatim
  144. *>
  145. *> \param[in] LDZ
  146. *> \verbatim
  147. *> LDZ is INTEGER
  148. *> The leading dimension of Z just as declared in the
  149. *> calling subroutine. 1 <= LDZ.
  150. *> \endverbatim
  151. *>
  152. *> \param[out] NS
  153. *> \verbatim
  154. *> NS is INTEGER
  155. *> The number of unconverged (ie approximate) eigenvalues
  156. *> returned in SR and SI that may be used as shifts by the
  157. *> calling subroutine.
  158. *> \endverbatim
  159. *>
  160. *> \param[out] ND
  161. *> \verbatim
  162. *> ND is INTEGER
  163. *> The number of converged eigenvalues uncovered by this
  164. *> subroutine.
  165. *> \endverbatim
  166. *>
  167. *> \param[out] SR
  168. *> \verbatim
  169. *> SR is REAL array, dimension (KBOT)
  170. *> \endverbatim
  171. *>
  172. *> \param[out] SI
  173. *> \verbatim
  174. *> SI is REAL array, dimension (KBOT)
  175. *> On output, the real and imaginary parts of approximate
  176. *> eigenvalues that may be used for shifts are stored in
  177. *> SR(KBOT-ND-NS+1) through SR(KBOT-ND) and
  178. *> SI(KBOT-ND-NS+1) through SI(KBOT-ND), respectively.
  179. *> The real and imaginary parts of converged eigenvalues
  180. *> are stored in SR(KBOT-ND+1) through SR(KBOT) and
  181. *> SI(KBOT-ND+1) through SI(KBOT), respectively.
  182. *> \endverbatim
  183. *>
  184. *> \param[out] V
  185. *> \verbatim
  186. *> V is REAL array, dimension (LDV,NW)
  187. *> An NW-by-NW work array.
  188. *> \endverbatim
  189. *>
  190. *> \param[in] LDV
  191. *> \verbatim
  192. *> LDV is INTEGER
  193. *> The leading dimension of V just as declared in the
  194. *> calling subroutine. NW <= LDV
  195. *> \endverbatim
  196. *>
  197. *> \param[in] NH
  198. *> \verbatim
  199. *> NH is INTEGER
  200. *> The number of columns of T. NH >= NW.
  201. *> \endverbatim
  202. *>
  203. *> \param[out] T
  204. *> \verbatim
  205. *> T is REAL array, dimension (LDT,NW)
  206. *> \endverbatim
  207. *>
  208. *> \param[in] LDT
  209. *> \verbatim
  210. *> LDT is INTEGER
  211. *> The leading dimension of T just as declared in the
  212. *> calling subroutine. NW <= LDT
  213. *> \endverbatim
  214. *>
  215. *> \param[in] NV
  216. *> \verbatim
  217. *> NV is INTEGER
  218. *> The number of rows of work array WV available for
  219. *> workspace. NV >= NW.
  220. *> \endverbatim
  221. *>
  222. *> \param[out] WV
  223. *> \verbatim
  224. *> WV is REAL array, dimension (LDWV,NW)
  225. *> \endverbatim
  226. *>
  227. *> \param[in] LDWV
  228. *> \verbatim
  229. *> LDWV is INTEGER
  230. *> The leading dimension of W just as declared in the
  231. *> calling subroutine. NW <= LDV
  232. *> \endverbatim
  233. *>
  234. *> \param[out] WORK
  235. *> \verbatim
  236. *> WORK is REAL array, dimension (LWORK)
  237. *> On exit, WORK(1) is set to an estimate of the optimal value
  238. *> of LWORK for the given values of N, NW, KTOP and KBOT.
  239. *> \endverbatim
  240. *>
  241. *> \param[in] LWORK
  242. *> \verbatim
  243. *> LWORK is INTEGER
  244. *> The dimension of the work array WORK. LWORK = 2*NW
  245. *> suffices, but greater efficiency may result from larger
  246. *> values of LWORK.
  247. *>
  248. *> If LWORK = -1, then a workspace query is assumed; SLAQR3
  249. *> only estimates the optimal workspace size for the given
  250. *> values of N, NW, KTOP and KBOT. The estimate is returned
  251. *> in WORK(1). No error message related to LWORK is issued
  252. *> by XERBLA. Neither H nor Z are accessed.
  253. *> \endverbatim
  254. *
  255. * Authors:
  256. * ========
  257. *
  258. *> \author Univ. of Tennessee
  259. *> \author Univ. of California Berkeley
  260. *> \author Univ. of Colorado Denver
  261. *> \author NAG Ltd.
  262. *
  263. *> \ingroup laqr3
  264. *
  265. *> \par Contributors:
  266. * ==================
  267. *>
  268. *> Karen Braman and Ralph Byers, Department of Mathematics,
  269. *> University of Kansas, USA
  270. *>
  271. * =====================================================================
  272. SUBROUTINE SLAQR3( WANTT, WANTZ, N, KTOP, KBOT, NW, H, LDH, ILOZ,
  273. $ IHIZ, Z, LDZ, NS, ND, SR, SI, V, LDV, NH, T,
  274. $ LDT, NV, WV, LDWV, WORK, LWORK )
  275. *
  276. * -- LAPACK auxiliary routine --
  277. * -- LAPACK is a software package provided by Univ. of Tennessee, --
  278. * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
  279. *
  280. * .. Scalar Arguments ..
  281. INTEGER IHIZ, ILOZ, KBOT, KTOP, LDH, LDT, LDV, LDWV,
  282. $ LDZ, LWORK, N, ND, NH, NS, NV, NW
  283. LOGICAL WANTT, WANTZ
  284. * ..
  285. * .. Array Arguments ..
  286. REAL H( LDH, * ), SI( * ), SR( * ), T( LDT, * ),
  287. $ V( LDV, * ), WORK( * ), WV( LDWV, * ),
  288. $ Z( LDZ, * )
  289. * ..
  290. *
  291. * ================================================================
  292. * .. Parameters ..
  293. REAL ZERO, ONE
  294. PARAMETER ( ZERO = 0.0e0, ONE = 1.0e0 )
  295. * ..
  296. * .. Local Scalars ..
  297. REAL AA, BB, BETA, CC, CS, DD, EVI, EVK, FOO, S,
  298. $ SAFMAX, SAFMIN, SMLNUM, SN, TAU, ULP
  299. INTEGER I, IFST, ILST, INFO, INFQR, J, JW, K, KCOL,
  300. $ KEND, KLN, KROW, KWTOP, LTOP, LWK1, LWK2, LWK3,
  301. $ LWKOPT, NMIN
  302. LOGICAL BULGE, SORTED
  303. * ..
  304. * .. External Functions ..
  305. REAL SLAMCH, SROUNDUP_LWORK
  306. INTEGER ILAENV
  307. EXTERNAL SLAMCH, SROUNDUP_LWORK, ILAENV
  308. * ..
  309. * .. External Subroutines ..
  310. EXTERNAL SCOPY, SGEHRD, SGEMM, SLACPY, SLAHQR, SLANV2,
  311. $ SLAQR4, SLARF, SLARFG, SLASET, SORMHR, STREXC
  312. * ..
  313. * .. Intrinsic Functions ..
  314. INTRINSIC ABS, INT, MAX, MIN, REAL, SQRT
  315. * ..
  316. * .. Executable Statements ..
  317. *
  318. * ==== Estimate optimal workspace. ====
  319. *
  320. JW = MIN( NW, KBOT-KTOP+1 )
  321. IF( JW.LE.2 ) THEN
  322. LWKOPT = 1
  323. ELSE
  324. *
  325. * ==== Workspace query call to SGEHRD ====
  326. *
  327. CALL SGEHRD( JW, 1, JW-1, T, LDT, WORK, WORK, -1, INFO )
  328. LWK1 = INT( WORK( 1 ) )
  329. *
  330. * ==== Workspace query call to SORMHR ====
  331. *
  332. CALL SORMHR( 'R', 'N', JW, JW, 1, JW-1, T, LDT, WORK, V, LDV,
  333. $ WORK, -1, INFO )
  334. LWK2 = INT( WORK( 1 ) )
  335. *
  336. * ==== Workspace query call to SLAQR4 ====
  337. *
  338. CALL SLAQR4( .true., .true., JW, 1, JW, T, LDT, SR, SI, 1, JW,
  339. $ V, LDV, WORK, -1, INFQR )
  340. LWK3 = INT( WORK( 1 ) )
  341. *
  342. * ==== Optimal workspace ====
  343. *
  344. LWKOPT = MAX( JW+MAX( LWK1, LWK2 ), LWK3 )
  345. END IF
  346. *
  347. * ==== Quick return in case of workspace query. ====
  348. *
  349. IF( LWORK.EQ.-1 ) THEN
  350. WORK( 1 ) = SROUNDUP_LWORK( LWKOPT )
  351. RETURN
  352. END IF
  353. *
  354. * ==== Nothing to do ...
  355. * ... for an empty active block ... ====
  356. NS = 0
  357. ND = 0
  358. WORK( 1 ) = ONE
  359. IF( KTOP.GT.KBOT )
  360. $ RETURN
  361. * ... nor for an empty deflation window. ====
  362. IF( NW.LT.1 )
  363. $ RETURN
  364. *
  365. * ==== Machine constants ====
  366. *
  367. SAFMIN = SLAMCH( 'SAFE MINIMUM' )
  368. SAFMAX = ONE / SAFMIN
  369. ULP = SLAMCH( 'PRECISION' )
  370. SMLNUM = SAFMIN*( REAL( N ) / ULP )
  371. *
  372. * ==== Setup deflation window ====
  373. *
  374. JW = MIN( NW, KBOT-KTOP+1 )
  375. KWTOP = KBOT - JW + 1
  376. IF( KWTOP.EQ.KTOP ) THEN
  377. S = ZERO
  378. ELSE
  379. S = H( KWTOP, KWTOP-1 )
  380. END IF
  381. *
  382. IF( KBOT.EQ.KWTOP ) THEN
  383. *
  384. * ==== 1-by-1 deflation window: not much to do ====
  385. *
  386. SR( KWTOP ) = H( KWTOP, KWTOP )
  387. SI( KWTOP ) = ZERO
  388. NS = 1
  389. ND = 0
  390. IF( ABS( S ).LE.MAX( SMLNUM, ULP*ABS( H( KWTOP, KWTOP ) ) ) )
  391. $ THEN
  392. NS = 0
  393. ND = 1
  394. IF( KWTOP.GT.KTOP )
  395. $ H( KWTOP, KWTOP-1 ) = ZERO
  396. END IF
  397. WORK( 1 ) = ONE
  398. RETURN
  399. END IF
  400. *
  401. * ==== Convert to spike-triangular form. (In case of a
  402. * . rare QR failure, this routine continues to do
  403. * . aggressive early deflation using that part of
  404. * . the deflation window that converged using INFQR
  405. * . here and there to keep track.) ====
  406. *
  407. CALL SLACPY( 'U', JW, JW, H( KWTOP, KWTOP ), LDH, T, LDT )
  408. CALL SCOPY( JW-1, H( KWTOP+1, KWTOP ), LDH+1, T( 2, 1 ), LDT+1 )
  409. *
  410. CALL SLASET( 'A', JW, JW, ZERO, ONE, V, LDV )
  411. NMIN = ILAENV( 12, 'SLAQR3', 'SV', JW, 1, JW, LWORK )
  412. IF( JW.GT.NMIN ) THEN
  413. CALL SLAQR4( .true., .true., JW, 1, JW, T, LDT, SR( KWTOP ),
  414. $ SI( KWTOP ), 1, JW, V, LDV, WORK, LWORK, INFQR )
  415. ELSE
  416. CALL SLAHQR( .true., .true., JW, 1, JW, T, LDT, SR( KWTOP ),
  417. $ SI( KWTOP ), 1, JW, V, LDV, INFQR )
  418. END IF
  419. *
  420. * ==== STREXC needs a clean margin near the diagonal ====
  421. *
  422. DO 10 J = 1, JW - 3
  423. T( J+2, J ) = ZERO
  424. T( J+3, J ) = ZERO
  425. 10 CONTINUE
  426. IF( JW.GT.2 )
  427. $ T( JW, JW-2 ) = ZERO
  428. *
  429. * ==== Deflation detection loop ====
  430. *
  431. NS = JW
  432. ILST = INFQR + 1
  433. 20 CONTINUE
  434. IF( ILST.LE.NS ) THEN
  435. IF( NS.EQ.1 ) THEN
  436. BULGE = .FALSE.
  437. ELSE
  438. BULGE = T( NS, NS-1 ).NE.ZERO
  439. END IF
  440. *
  441. * ==== Small spike tip test for deflation ====
  442. *
  443. IF( .NOT. BULGE ) THEN
  444. *
  445. * ==== Real eigenvalue ====
  446. *
  447. FOO = ABS( T( NS, NS ) )
  448. IF( FOO.EQ.ZERO )
  449. $ FOO = ABS( S )
  450. IF( ABS( S*V( 1, NS ) ).LE.MAX( SMLNUM, ULP*FOO ) ) THEN
  451. *
  452. * ==== Deflatable ====
  453. *
  454. NS = NS - 1
  455. ELSE
  456. *
  457. * ==== Undeflatable. Move it up out of the way.
  458. * . (STREXC can not fail in this case.) ====
  459. *
  460. IFST = NS
  461. CALL STREXC( 'V', JW, T, LDT, V, LDV, IFST, ILST, WORK,
  462. $ INFO )
  463. ILST = ILST + 1
  464. END IF
  465. ELSE
  466. *
  467. * ==== Complex conjugate pair ====
  468. *
  469. FOO = ABS( T( NS, NS ) ) + SQRT( ABS( T( NS, NS-1 ) ) )*
  470. $ SQRT( ABS( T( NS-1, NS ) ) )
  471. IF( FOO.EQ.ZERO )
  472. $ FOO = ABS( S )
  473. IF( MAX( ABS( S*V( 1, NS ) ), ABS( S*V( 1, NS-1 ) ) ).LE.
  474. $ MAX( SMLNUM, ULP*FOO ) ) THEN
  475. *
  476. * ==== Deflatable ====
  477. *
  478. NS = NS - 2
  479. ELSE
  480. *
  481. * ==== Undeflatable. Move them up out of the way.
  482. * . Fortunately, STREXC does the right thing with
  483. * . ILST in case of a rare exchange failure. ====
  484. *
  485. IFST = NS
  486. CALL STREXC( 'V', JW, T, LDT, V, LDV, IFST, ILST, WORK,
  487. $ INFO )
  488. ILST = ILST + 2
  489. END IF
  490. END IF
  491. *
  492. * ==== End deflation detection loop ====
  493. *
  494. GO TO 20
  495. END IF
  496. *
  497. * ==== Return to Hessenberg form ====
  498. *
  499. IF( NS.EQ.0 )
  500. $ S = ZERO
  501. *
  502. IF( NS.LT.JW ) THEN
  503. *
  504. * ==== sorting diagonal blocks of T improves accuracy for
  505. * . graded matrices. Bubble sort deals well with
  506. * . exchange failures. ====
  507. *
  508. SORTED = .false.
  509. I = NS + 1
  510. 30 CONTINUE
  511. IF( SORTED )
  512. $ GO TO 50
  513. SORTED = .true.
  514. *
  515. KEND = I - 1
  516. I = INFQR + 1
  517. IF( I.EQ.NS ) THEN
  518. K = I + 1
  519. ELSE IF( T( I+1, I ).EQ.ZERO ) THEN
  520. K = I + 1
  521. ELSE
  522. K = I + 2
  523. END IF
  524. 40 CONTINUE
  525. IF( K.LE.KEND ) THEN
  526. IF( K.EQ.I+1 ) THEN
  527. EVI = ABS( T( I, I ) )
  528. ELSE
  529. EVI = ABS( T( I, I ) ) + SQRT( ABS( T( I+1, I ) ) )*
  530. $ SQRT( ABS( T( I, I+1 ) ) )
  531. END IF
  532. *
  533. IF( K.EQ.KEND ) THEN
  534. EVK = ABS( T( K, K ) )
  535. ELSE IF( T( K+1, K ).EQ.ZERO ) THEN
  536. EVK = ABS( T( K, K ) )
  537. ELSE
  538. EVK = ABS( T( K, K ) ) + SQRT( ABS( T( K+1, K ) ) )*
  539. $ SQRT( ABS( T( K, K+1 ) ) )
  540. END IF
  541. *
  542. IF( EVI.GE.EVK ) THEN
  543. I = K
  544. ELSE
  545. SORTED = .false.
  546. IFST = I
  547. ILST = K
  548. CALL STREXC( 'V', JW, T, LDT, V, LDV, IFST, ILST, WORK,
  549. $ INFO )
  550. IF( INFO.EQ.0 ) THEN
  551. I = ILST
  552. ELSE
  553. I = K
  554. END IF
  555. END IF
  556. IF( I.EQ.KEND ) THEN
  557. K = I + 1
  558. ELSE IF( T( I+1, I ).EQ.ZERO ) THEN
  559. K = I + 1
  560. ELSE
  561. K = I + 2
  562. END IF
  563. GO TO 40
  564. END IF
  565. GO TO 30
  566. 50 CONTINUE
  567. END IF
  568. *
  569. * ==== Restore shift/eigenvalue array from T ====
  570. *
  571. I = JW
  572. 60 CONTINUE
  573. IF( I.GE.INFQR+1 ) THEN
  574. IF( I.EQ.INFQR+1 ) THEN
  575. SR( KWTOP+I-1 ) = T( I, I )
  576. SI( KWTOP+I-1 ) = ZERO
  577. I = I - 1
  578. ELSE IF( T( I, I-1 ).EQ.ZERO ) THEN
  579. SR( KWTOP+I-1 ) = T( I, I )
  580. SI( KWTOP+I-1 ) = ZERO
  581. I = I - 1
  582. ELSE
  583. AA = T( I-1, I-1 )
  584. CC = T( I, I-1 )
  585. BB = T( I-1, I )
  586. DD = T( I, I )
  587. CALL SLANV2( AA, BB, CC, DD, SR( KWTOP+I-2 ),
  588. $ SI( KWTOP+I-2 ), SR( KWTOP+I-1 ),
  589. $ SI( KWTOP+I-1 ), CS, SN )
  590. I = I - 2
  591. END IF
  592. GO TO 60
  593. END IF
  594. *
  595. IF( NS.LT.JW .OR. S.EQ.ZERO ) THEN
  596. IF( NS.GT.1 .AND. S.NE.ZERO ) THEN
  597. *
  598. * ==== Reflect spike back into lower triangle ====
  599. *
  600. CALL SCOPY( NS, V, LDV, WORK, 1 )
  601. BETA = WORK( 1 )
  602. CALL SLARFG( NS, BETA, WORK( 2 ), 1, TAU )
  603. WORK( 1 ) = ONE
  604. *
  605. CALL SLASET( 'L', JW-2, JW-2, ZERO, ZERO, T( 3, 1 ), LDT )
  606. *
  607. CALL SLARF( 'L', NS, JW, WORK, 1, TAU, T, LDT,
  608. $ WORK( JW+1 ) )
  609. CALL SLARF( 'R', NS, NS, WORK, 1, TAU, T, LDT,
  610. $ WORK( JW+1 ) )
  611. CALL SLARF( 'R', JW, NS, WORK, 1, TAU, V, LDV,
  612. $ WORK( JW+1 ) )
  613. *
  614. CALL SGEHRD( JW, 1, NS, T, LDT, WORK, WORK( JW+1 ),
  615. $ LWORK-JW, INFO )
  616. END IF
  617. *
  618. * ==== Copy updated reduced window into place ====
  619. *
  620. IF( KWTOP.GT.1 )
  621. $ H( KWTOP, KWTOP-1 ) = S*V( 1, 1 )
  622. CALL SLACPY( 'U', JW, JW, T, LDT, H( KWTOP, KWTOP ), LDH )
  623. CALL SCOPY( JW-1, T( 2, 1 ), LDT+1, H( KWTOP+1, KWTOP ),
  624. $ LDH+1 )
  625. *
  626. * ==== Accumulate orthogonal matrix in order update
  627. * . H and Z, if requested. ====
  628. *
  629. IF( NS.GT.1 .AND. S.NE.ZERO )
  630. $ CALL SORMHR( 'R', 'N', JW, NS, 1, NS, T, LDT, WORK, V, LDV,
  631. $ WORK( JW+1 ), LWORK-JW, INFO )
  632. *
  633. * ==== Update vertical slab in H ====
  634. *
  635. IF( WANTT ) THEN
  636. LTOP = 1
  637. ELSE
  638. LTOP = KTOP
  639. END IF
  640. DO 70 KROW = LTOP, KWTOP - 1, NV
  641. KLN = MIN( NV, KWTOP-KROW )
  642. CALL SGEMM( 'N', 'N', KLN, JW, JW, ONE, H( KROW, KWTOP ),
  643. $ LDH, V, LDV, ZERO, WV, LDWV )
  644. CALL SLACPY( 'A', KLN, JW, WV, LDWV, H( KROW, KWTOP ), LDH )
  645. 70 CONTINUE
  646. *
  647. * ==== Update horizontal slab in H ====
  648. *
  649. IF( WANTT ) THEN
  650. DO 80 KCOL = KBOT + 1, N, NH
  651. KLN = MIN( NH, N-KCOL+1 )
  652. CALL SGEMM( 'C', 'N', JW, KLN, JW, ONE, V, LDV,
  653. $ H( KWTOP, KCOL ), LDH, ZERO, T, LDT )
  654. CALL SLACPY( 'A', JW, KLN, T, LDT, H( KWTOP, KCOL ),
  655. $ LDH )
  656. 80 CONTINUE
  657. END IF
  658. *
  659. * ==== Update vertical slab in Z ====
  660. *
  661. IF( WANTZ ) THEN
  662. DO 90 KROW = ILOZ, IHIZ, NV
  663. KLN = MIN( NV, IHIZ-KROW+1 )
  664. CALL SGEMM( 'N', 'N', KLN, JW, JW, ONE, Z( KROW, KWTOP ),
  665. $ LDZ, V, LDV, ZERO, WV, LDWV )
  666. CALL SLACPY( 'A', KLN, JW, WV, LDWV, Z( KROW, KWTOP ),
  667. $ LDZ )
  668. 90 CONTINUE
  669. END IF
  670. END IF
  671. *
  672. * ==== Return the number of deflations ... ====
  673. *
  674. ND = JW - NS
  675. *
  676. * ==== ... and the number of shifts. (Subtracting
  677. * . INFQR from the spike length takes care
  678. * . of the case of a rare QR failure while
  679. * . calculating eigenvalues of the deflation
  680. * . window.) ====
  681. *
  682. NS = NS - INFQR
  683. *
  684. * ==== Return optimal workspace. ====
  685. *
  686. WORK( 1 ) = SROUNDUP_LWORK( LWKOPT )
  687. *
  688. * ==== End of SLAQR3 ====
  689. *
  690. END