Télécharger dtrevc3.eso

Retour à la liste

Numérotation des lignes :

dtrevc3
  1. C DTREVC3 SOURCE FANDEUR 22/05/02 21:15:17 11359
  2. *> \brief \b DTREVC3
  3. *
  4. * =========== DOCUMENTATION ===========
  5. *
  6. * Online html documentation available at
  7. * http://www.netlib.org/lapack/explore-html/
  8. *
  9. *> \htmlonly
  10. *> Download DTREVC3 + dependencies
  11. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dtrevc3.f">
  12. *> [TGZ]</a>
  13. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dtrevc3.f">
  14. *> [ZIP]</a>
  15. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dtrevc3.f">
  16. *> [TXT]</a>
  17. *> \endhtmlonly
  18. *
  19. * Definition:
  20. * ===========
  21. *
  22. * SUBROUTINE DTREVC3( SIDE, HOWMNY, SELECT, N, T, LDT, VL, LDVL,
  23. * VR, LDVR, MM, M, WORK, LWORK, INFO )
  24. *
  25. * .. Scalar Arguments ..
  26. * CHARACTER HOWMNY, SIDE
  27. * INTEGER INFO, LDT, LDVL, LDVR, LWORK, M, MM, N
  28. * ..
  29. * .. Array Arguments ..
  30. * LOGICAL SELECT( * )
  31. * REAL*8 T( LDT, * ), VL( LDVL, * ), VR( LDVR, * ),
  32. * $ WORK( * )
  33. * ..
  34. *
  35. *
  36. *> \par Purpose:
  37. * =============
  38. *>
  39. *> \verbatim
  40. *>
  41. *> DTREVC3 computes some or all of the right and/or left eigenvectors of
  42. *> a real upper quasi-triangular matrix T.
  43. *> Matrices of this type are produced by the Schur factorization of
  44. *> a real general matrix: A = Q*T*Q**T, as computed by DHSEQR.
  45. *>
  46. *> The right eigenvector x and the left eigenvector y of T corresponding
  47. *> to an eigenvalue w are defined by:
  48. *>
  49. *> T*x = w*x, (y**H)*T = w*(y**H)
  50. *>
  51. *> where y**H denotes the conjugate transpose of y.
  52. *> The eigenvalues are not input to this routine, but are read directly
  53. *> from the diagonal blocks of T.
  54. *>
  55. *> This routine returns the matrices X and/or Y of right and left
  56. *> eigenvectors of T, or the products Q*X and/or Q*Y, where Q is an
  57. *> input matrix. If Q is the orthogonal factor that reduces a matrix
  58. *> A to Schur form T, then Q*X and Q*Y are the matrices of right and
  59. *> left eigenvectors of A.
  60. *>
  61. *> This uses a Level 3 BLAS version of the back transformation.
  62. *> \endverbatim
  63. *
  64. * Arguments:
  65. * ==========
  66. *
  67. *> \param[in] SIDE
  68. *> \verbatim
  69. *> SIDE is CHARACTER*1
  70. *> = 'R': compute right eigenvectors only;
  71. *> = 'L': compute left eigenvectors only;
  72. *> = 'B': compute both right and left eigenvectors.
  73. *> \endverbatim
  74. *>
  75. *> \param[in] HOWMNY
  76. *> \verbatim
  77. *> HOWMNY is CHARACTER*1
  78. *> = 'A': compute all right and/or left eigenvectors;
  79. *> = 'B': compute all right and/or left eigenvectors,
  80. *> backtransformed by the matrices in VR and/or VL;
  81. *> = 'S': compute selected right and/or left eigenvectors,
  82. *> as indicated by the logical array SELECT.
  83. *> \endverbatim
  84. *>
  85. *> \param[in,out] SELECT
  86. *> \verbatim
  87. *> SELECT is LOGICAL array, dimension (N)
  88. *> If HOWMNY = 'S', SELECT specifies the eigenvectors to be
  89. *> computed.
  90. *> If w(j) is a real eigenvalue, the corresponding real
  91. *> eigenvector is computed if SELECT(j) is .TRUE..
  92. *> If w(j) and w(j+1) are the real and imaginary parts of a
  93. *> complex eigenvalue, the corresponding complex eigenvector is
  94. *> computed if either SELECT(j) or SELECT(j+1) is .TRUE., and
  95. *> on exit SELECT(j) is set to .TRUE. and SELECT(j+1) is set to
  96. *> .FALSE..
  97. *> Not referenced if HOWMNY = 'A' or 'B'.
  98. *> \endverbatim
  99. *>
  100. *> \param[in] N
  101. *> \verbatim
  102. *> N is INTEGER
  103. *> The order of the matrix T. N >= 0.
  104. *> \endverbatim
  105. *>
  106. *> \param[in] T
  107. *> \verbatim
  108. *> T is REAL*8 array, dimension (LDT,N)
  109. *> The upper quasi-triangular matrix T in Schur canonical form.
  110. *> \endverbatim
  111. *>
  112. *> \param[in] LDT
  113. *> \verbatim
  114. *> LDT is INTEGER
  115. *> The leading dimension of the array T. LDT >= max(1,N).
  116. *> \endverbatim
  117. *>
  118. *> \param[in,out] VL
  119. *> \verbatim
  120. *> VL is REAL*8 array, dimension (LDVL,MM)
  121. *> On entry, if SIDE = 'L' or 'B' and HOWMNY = 'B', VL must
  122. *> contain an N-by-N matrix Q (usually the orthogonal matrix Q
  123. *> of Schur vectors returned by DHSEQR).
  124. *> On exit, if SIDE = 'L' or 'B', VL contains:
  125. *> if HOWMNY = 'A', the matrix Y of left eigenvectors of T;
  126. *> if HOWMNY = 'B', the matrix Q*Y;
  127. *> if HOWMNY = 'S', the left eigenvectors of T specified by
  128. *> SELECT, stored consecutively in the columns
  129. *> of VL, in the same order as their
  130. *> eigenvalues.
  131. *> A complex eigenvector corresponding to a complex eigenvalue
  132. *> is stored in two consecutive columns, the first holding the
  133. *> real part, and the second the imaginary part.
  134. *> Not referenced if SIDE = 'R'.
  135. *> \endverbatim
  136. *>
  137. *> \param[in] LDVL
  138. *> \verbatim
  139. *> LDVL is INTEGER
  140. *> The leading dimension of the array VL.
  141. *> LDVL >= 1, and if SIDE = 'L' or 'B', LDVL >= N.
  142. *> \endverbatim
  143. *>
  144. *> \param[in,out] VR
  145. *> \verbatim
  146. *> VR is REAL*8 array, dimension (LDVR,MM)
  147. *> On entry, if SIDE = 'R' or 'B' and HOWMNY = 'B', VR must
  148. *> contain an N-by-N matrix Q (usually the orthogonal matrix Q
  149. *> of Schur vectors returned by DHSEQR).
  150. *> On exit, if SIDE = 'R' or 'B', VR contains:
  151. *> if HOWMNY = 'A', the matrix X of right eigenvectors of T;
  152. *> if HOWMNY = 'B', the matrix Q*X;
  153. *> if HOWMNY = 'S', the right eigenvectors of T specified by
  154. *> SELECT, stored consecutively in the columns
  155. *> of VR, in the same order as their
  156. *> eigenvalues.
  157. *> A complex eigenvector corresponding to a complex eigenvalue
  158. *> is stored in two consecutive columns, the first holding the
  159. *> real part and the second the imaginary part.
  160. *> Not referenced if SIDE = 'L'.
  161. *> \endverbatim
  162. *>
  163. *> \param[in] LDVR
  164. *> \verbatim
  165. *> LDVR is INTEGER
  166. *> The leading dimension of the array VR.
  167. *> LDVR >= 1, and if SIDE = 'R' or 'B', LDVR >= N.
  168. *> \endverbatim
  169. *>
  170. *> \param[in] MM
  171. *> \verbatim
  172. *> MM is INTEGER
  173. *> The number of columns in the arrays VL and/or VR. MM >= M.
  174. *> \endverbatim
  175. *>
  176. *> \param[out] M
  177. *> \verbatim
  178. *> M is INTEGER
  179. *> The number of columns in the arrays VL and/or VR actually
  180. *> used to store the eigenvectors.
  181. *> If HOWMNY = 'A' or 'B', M is set to N.
  182. *> Each selected real eigenvector occupies one column and each
  183. *> selected complex eigenvector occupies two columns.
  184. *> \endverbatim
  185. *>
  186. *> \param[out] WORK
  187. *> \verbatim
  188. *> WORK is REAL*8 array, dimension (MAX(1,LWORK))
  189. *> \endverbatim
  190. *>
  191. *> \param[in] LWORK
  192. *> \verbatim
  193. *> LWORK is INTEGER
  194. *> The dimension of array WORK. LWORK >= max(1,3*N).
  195. *> For optimum performance, LWORK >= N + 2*N*NB, where NB is
  196. *> the optimal blocksize.
  197. *>
  198. *> If LWORK = -1, then a workspace query is assumed; the routine
  199. *> only calculates the optimal size of the WORK array, returns
  200. *> this value as the first entry of the WORK array, and no error
  201. *> message related to LWORK is issued by XERBLA.
  202. *> \endverbatim
  203. *>
  204. *> \param[out] INFO
  205. *> \verbatim
  206. *> INFO is INTEGER
  207. *> = 0: successful exit
  208. *> < 0: if INFO = -i, the i-th argument had an illegal value
  209. *> \endverbatim
  210. *
  211. * Authors:
  212. * ========
  213. *
  214. *> \author Univ. of Tennessee
  215. *> \author Univ. of California Berkeley
  216. *> \author Univ. of Colorado Denver
  217. *> \author NAG Ltd.
  218. *
  219. *> \date November 2017
  220. *
  221. * @precisions fortran d -> s
  222. *
  223. *> \ingroup doubleOTHERcomputational
  224. *
  225. *> \par Further Details:
  226. * =====================
  227. *>
  228. *> \verbatim
  229. *>
  230. *> The algorithm used in this program is basically backward (forward)
  231. *> substitution, with scaling to make the the code robust against
  232. *> possible overflow.
  233. *>
  234. *> Each eigenvector is normalized so that the element of largest
  235. *> magnitude has magnitude 1; here the magnitude of a complex number
  236. *> (x,y) is taken to be |x| + |y|.
  237. *> \endverbatim
  238. *>
  239. * =====================================================================
  240. SUBROUTINE DTREVC3( SIDE, HOWMNY, SELECT, N, T, LDT, VL, LDVL,
  241. $ VR, LDVR, MM, M, WORK, LWORK, INFO )
  242. *
  243. * -- LAPACK computational routine (version 3.8.0) --
  244. * -- LAPACK is a software package provided by Univ. of Tennessee, --
  245. * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
  246. * November 2017
  247.  
  248. * IMPLICIT NONE
  249. IMPLICIT INTEGER(I-N)
  250. IMPLICIT REAL*8(A-H,O-Z)
  251. *
  252. * .. Scalar Arguments ..
  253. CHARACTER HOWMNY, SIDE
  254. INTEGER INFO, LDT, LDVL, LDVR, LWORK, M, MM, N
  255. * ..
  256. * .. Array Arguments ..
  257. LOGICAL SELECT( * )
  258. REAL*8 T( LDT, * ), VL( LDVL, * ), VR( LDVR, * ),
  259. $ WORK( * )
  260. * ..
  261. *
  262. * =====================================================================
  263. *
  264. * .. Parameters ..
  265. REAL*8 ZERO, ONE
  266. PARAMETER ( ZERO = 0.0D+0, ONE = 1.0D+0 )
  267. INTEGER NBMIN, NBMAX
  268. PARAMETER ( NBMIN = 8, NBMAX = 128 )
  269. * ..
  270. * .. Local Scalars ..
  271. LOGICAL ALLV, BOTHV, LEFTV, LQUERY, OVER, PAIR,
  272. $ RIGHTV, SOMEV
  273. INTEGER I, IERR, II, IP, IS, J, J1, J2, JNXT, K, KI,
  274. $ IV, MAXWRK, NB, KI2
  275. REAL*8 BETA, BIGNUM, EMAX, OVFL, REC, REMAX, SCALE,
  276. $ SMIN, SMLNUM, ULP, UNFL, VCRIT, VMAX, WI, WR,
  277. $ XNORM
  278. * ..
  279. * .. External Functions ..
  280. LOGICAL LSAME
  281. INTEGER IDAMAX, ILAENV
  282. REAL*8 DDOT, DLAMCH
  283. EXTERNAL LSAME, IDAMAX, ILAENV,
  284. * ..
  285. * .. External Subroutines ..
  286. EXTERNAL DAXPY, DCOPY, DGEMV, DLALN2,
  287. * ..
  288. * .. Intrinsic Functions ..
  289. * INTRINSIC ABS, MAX, SQRT
  290. * ..
  291. * .. Local Arrays ..
  292. REAL*8 X( 2, 2 )
  293. INTEGER ISCOMPLEX( NBMAX )
  294. * ..
  295. * .. Executable Statements ..
  296. *
  297. * Decode and test the input parameters
  298. *
  299. BOTHV = LSAME( SIDE, 'B' )
  300. RIGHTV = LSAME( SIDE, 'R' ) .OR. BOTHV
  301. LEFTV = LSAME( SIDE, 'L' ) .OR. BOTHV
  302. *
  303. ALLV = LSAME( HOWMNY, 'A' )
  304. OVER = LSAME( HOWMNY, 'B' )
  305. SOMEV = LSAME( HOWMNY, 'S' )
  306. *
  307. INFO = 0
  308. NB = ILAENV( 1, 'DTREVC', SIDE // HOWMNY, N, -1, -1, -1 )
  309. MAXWRK = N + 2*N*NB
  310. WORK(1) = MAXWRK
  311. LQUERY = ( LWORK.EQ.-1 )
  312. IF( .NOT.RIGHTV .AND. .NOT.LEFTV ) THEN
  313. INFO = -1
  314. ELSE IF( .NOT.ALLV .AND. .NOT.OVER .AND. .NOT.SOMEV ) THEN
  315. INFO = -2
  316. ELSE IF( N.LT.0 ) THEN
  317. INFO = -4
  318. ELSE IF( LDT.LT.MAX( 1, N ) ) THEN
  319. INFO = -6
  320. ELSE IF( LDVL.LT.1 .OR. ( LEFTV .AND. LDVL.LT.N ) ) THEN
  321. INFO = -8
  322. ELSE IF( LDVR.LT.1 .OR. ( RIGHTV .AND. LDVR.LT.N ) ) THEN
  323. INFO = -10
  324. ELSE IF( LWORK.LT.MAX( 1, 3*N ) .AND. .NOT.LQUERY ) THEN
  325. INFO = -14
  326. ELSE
  327. *
  328. * Set M to the number of columns required to store the selected
  329. * eigenvectors, standardize the array SELECT if necessary, and
  330. * test MM.
  331. *
  332. IF( SOMEV ) THEN
  333. M = 0
  334. PAIR = .FALSE.
  335. DO 10 J = 1, N
  336. IF( PAIR ) THEN
  337. PAIR = .FALSE.
  338. SELECT( J ) = .FALSE.
  339. ELSE
  340. IF( J.LT.N ) THEN
  341. IF( T( J+1, J ).EQ.ZERO ) THEN
  342. IF( SELECT( J ) )
  343. $ M = M + 1
  344. ELSE
  345. PAIR = .TRUE.
  346. IF( SELECT( J ) .OR. SELECT( J+1 ) ) THEN
  347. SELECT( J ) = .TRUE.
  348. M = M + 2
  349. END IF
  350. END IF
  351. ELSE
  352. IF( SELECT( N ) )
  353. $ M = M + 1
  354. END IF
  355. END IF
  356. 10 CONTINUE
  357. ELSE
  358. M = N
  359. END IF
  360. *
  361. IF( MM.LT.M ) THEN
  362. INFO = -11
  363. END IF
  364. END IF
  365. IF( INFO.NE.0 ) THEN
  366. CALL XERBLA( 'DTREVC3', -INFO )
  367. RETURN
  368. ELSE IF( LQUERY ) THEN
  369. RETURN
  370. END IF
  371. *
  372. * Quick return if possible.
  373. *
  374. IF( N.EQ.0 )
  375. $ RETURN
  376. *
  377. * Use blocked version of back-transformation if sufficient workspace.
  378. * Zero-out the workspace to avoid potential NaN propagation.
  379. *
  380. IF( OVER .AND. LWORK .GE. N + 2*N*NBMIN ) THEN
  381. NB = (LWORK - N) / (2*N)
  382. NB = MIN( NB, NBMAX )
  383. CALL DLASET( 'F', N, 1+2*NB, ZERO, ZERO, WORK, N )
  384. ELSE
  385. NB = 1
  386. END IF
  387. *
  388. * Set the constants to control overflow.
  389. *
  390. UNFL = DLAMCH( 'Safe minimum' )
  391. OVFL = ONE / UNFL
  392. CALL DLABAD( UNFL, OVFL )
  393. ULP = DLAMCH( 'Precision' )
  394. SMLNUM = UNFL*( N / ULP )
  395. BIGNUM = ( ONE-ULP ) / SMLNUM
  396. *
  397. * Compute 1-norm of each column of strictly upper triangular
  398. * part of T to control overflow in triangular solver.
  399. *
  400. WORK( 1 ) = ZERO
  401. DO 30 J = 2, N
  402. WORK( J ) = ZERO
  403. DO 20 I = 1, J - 1
  404. WORK( J ) = WORK( J ) + ABS( T( I, J ) )
  405. 20 CONTINUE
  406. 30 CONTINUE
  407. *
  408. * Index IP is used to specify the real or complex eigenvalue:
  409. * IP = 0, real eigenvalue,
  410. * 1, first of conjugate complex pair: (wr,wi)
  411. * -1, second of conjugate complex pair: (wr,wi)
  412. * ISCOMPLEX array stores IP for each column in current block.
  413. *
  414. IF( RIGHTV ) THEN
  415. *
  416. * ============================================================
  417. * Compute right eigenvectors.
  418. *
  419. * IV is index of column in current block.
  420. * For complex right vector, uses IV-1 for real part and IV for complex part.
  421. * Non-blocked version always uses IV=2;
  422. * blocked version starts with IV=NB, goes down to 1 or 2.
  423. * (Note the "0-th" column is used for 1-norms computed above.)
  424. IV = 2
  425. IF( NB.GT.2 ) THEN
  426. IV = NB
  427. END IF
  428.  
  429. IP = 0
  430. IS = M
  431. DO 140 KI = N, 1, -1
  432. IF( IP.EQ.-1 ) THEN
  433. * previous iteration (ki+1) was second of conjugate pair,
  434. * so this ki is first of conjugate pair; skip to end of loop
  435. IP = 1
  436. GO TO 140
  437. ELSE IF( KI.EQ.1 ) THEN
  438. * last column, so this ki must be real eigenvalue
  439. IP = 0
  440. ELSE IF( T( KI, KI-1 ).EQ.ZERO ) THEN
  441. * zero on sub-diagonal, so this ki is real eigenvalue
  442. IP = 0
  443. ELSE
  444. * non-zero on sub-diagonal, so this ki is second of conjugate pair
  445. IP = -1
  446. END IF
  447.  
  448. IF( SOMEV ) THEN
  449. IF( IP.EQ.0 ) THEN
  450. IF( .NOT.SELECT( KI ) )
  451. $ GO TO 140
  452. ELSE
  453. IF( .NOT.SELECT( KI-1 ) )
  454. $ GO TO 140
  455. END IF
  456. END IF
  457. *
  458. * Compute the KI-th eigenvalue (WR,WI).
  459. *
  460. WR = T( KI, KI )
  461. WI = ZERO
  462. IF( IP.NE.0 )
  463. $ WI = SQRT( ABS( T( KI, KI-1 ) ) )*
  464. $ SQRT( ABS( T( KI-1, KI ) ) )
  465. SMIN = MAX( ULP*( ABS( WR )+ABS( WI ) ), SMLNUM )
  466. *
  467. IF( IP.EQ.0 ) THEN
  468. *
  469. * --------------------------------------------------------
  470. * Real right eigenvector
  471. *
  472. WORK( KI + IV*N ) = ONE
  473. *
  474. * Form right-hand side.
  475. *
  476. DO 50 K = 1, KI - 1
  477. WORK( K + IV*N ) = -T( K, KI )
  478. 50 CONTINUE
  479. *
  480. * Solve upper quasi-triangular system:
  481. * [ T(1:KI-1,1:KI-1) - WR ]*X = SCALE*WORK.
  482. *
  483. JNXT = KI - 1
  484. DO 60 J = KI - 1, 1, -1
  485. IF( J.GT.JNXT )
  486. $ GO TO 60
  487. J1 = J
  488. J2 = J
  489. JNXT = J - 1
  490. IF( J.GT.1 ) THEN
  491. IF( T( J, J-1 ).NE.ZERO ) THEN
  492. J1 = J - 1
  493. JNXT = J - 2
  494. END IF
  495. END IF
  496. *
  497. IF( J1.EQ.J2 ) THEN
  498. *
  499. * 1-by-1 diagonal block
  500. *
  501. CALL DLALN2( .FALSE., 1, 1, SMIN, ONE, T( J, J ),
  502. $ LDT, ONE, ONE, WORK( J+IV*N ), N, WR,
  503. $ ZERO, X, 2, SCALE, XNORM, IERR )
  504. *
  505. * Scale X(1,1) to avoid overflow when updating
  506. * the right-hand side.
  507. *
  508. IF( XNORM.GT.ONE ) THEN
  509. IF( WORK( J ).GT.BIGNUM / XNORM ) THEN
  510. X( 1, 1 ) = X( 1, 1 ) / XNORM
  511. SCALE = SCALE / XNORM
  512. END IF
  513. END IF
  514. *
  515. * Scale if necessary
  516. *
  517. IF( SCALE.NE.ONE )
  518. $ CALL DSCAL( KI, SCALE, WORK( 1+IV*N ), 1 )
  519. WORK( J+IV*N ) = X( 1, 1 )
  520. *
  521. * Update right-hand side
  522. *
  523. CALL DAXPY( J-1, -X( 1, 1 ), T( 1, J ), 1,
  524. $ WORK( 1+IV*N ), 1 )
  525. *
  526. ELSE
  527. *
  528. * 2-by-2 diagonal block
  529. *
  530. CALL DLALN2( .FALSE., 2, 1, SMIN, ONE,
  531. $ T( J-1, J-1 ), LDT, ONE, ONE,
  532. $ WORK( J-1+IV*N ), N, WR, ZERO, X, 2,
  533. $ SCALE, XNORM, IERR )
  534. *
  535. * Scale X(1,1) and X(2,1) to avoid overflow when
  536. * updating the right-hand side.
  537. *
  538. IF( XNORM.GT.ONE ) THEN
  539. BETA = MAX( WORK( J-1 ), WORK( J ) )
  540. IF( BETA.GT.BIGNUM / XNORM ) THEN
  541. X( 1, 1 ) = X( 1, 1 ) / XNORM
  542. X( 2, 1 ) = X( 2, 1 ) / XNORM
  543. SCALE = SCALE / XNORM
  544. END IF
  545. END IF
  546. *
  547. * Scale if necessary
  548. *
  549. IF( SCALE.NE.ONE )
  550. $ CALL DSCAL( KI, SCALE, WORK( 1+IV*N ), 1 )
  551. WORK( J-1+IV*N ) = X( 1, 1 )
  552. WORK( J +IV*N ) = X( 2, 1 )
  553. *
  554. * Update right-hand side
  555. *
  556. CALL DAXPY( J-2, -X( 1, 1 ), T( 1, J-1 ), 1,
  557. $ WORK( 1+IV*N ), 1 )
  558. CALL DAXPY( J-2, -X( 2, 1 ), T( 1, J ), 1,
  559. $ WORK( 1+IV*N ), 1 )
  560. END IF
  561. 60 CONTINUE
  562. *
  563. * Copy the vector x or Q*x to VR and normalize.
  564. *
  565. IF( .NOT.OVER ) THEN
  566. * ------------------------------
  567. * no back-transform: copy x to VR and normalize.
  568. CALL DCOPY( KI, WORK( 1 + IV*N ), 1, VR( 1, IS ), 1 )
  569. *
  570. II = IDAMAX( KI, VR( 1, IS ), 1 )
  571. REMAX = ONE / ABS( VR( II, IS ) )
  572. CALL DSCAL( KI, REMAX, VR( 1, IS ), 1 )
  573. *
  574. DO 70 K = KI + 1, N
  575. VR( K, IS ) = ZERO
  576. 70 CONTINUE
  577. *
  578. ELSE IF( NB.EQ.1 ) THEN
  579. * ------------------------------
  580. * version 1: back-transform each vector with GEMV, Q*x.
  581. IF( KI.GT.1 )
  582. $ CALL DGEMV( 'N', N, KI-1, ONE, VR, LDVR,
  583. $ WORK( 1 + IV*N ), 1, WORK( KI + IV*N ),
  584. $ VR( 1, KI ), 1 )
  585. *
  586. II = IDAMAX( N, VR( 1, KI ), 1 )
  587. REMAX = ONE / ABS( VR( II, KI ) )
  588. CALL DSCAL( N, REMAX, VR( 1, KI ), 1 )
  589. *
  590. ELSE
  591. * ------------------------------
  592. * version 2: back-transform block of vectors with GEMM
  593. * zero out below vector
  594. DO K = KI + 1, N
  595. WORK( K + IV*N ) = ZERO
  596. END DO
  597. ISCOMPLEX( IV ) = IP
  598. * back-transform and normalization is done below
  599. END IF
  600. ELSE
  601. *
  602. * --------------------------------------------------------
  603. * Complex right eigenvector.
  604. *
  605. * Initial solve
  606. * [ ( T(KI-1,KI-1) T(KI-1,KI) ) - (WR + I*WI) ]*X = 0.
  607. * [ ( T(KI, KI-1) T(KI, KI) ) ]
  608. *
  609. IF( ABS( T( KI-1, KI ) ).GE.ABS( T( KI, KI-1 ) ) ) THEN
  610. WORK( KI-1 + (IV-1)*N ) = ONE
  611. WORK( KI + (IV )*N ) = WI / T( KI-1, KI )
  612. ELSE
  613. WORK( KI-1 + (IV-1)*N ) = -WI / T( KI, KI-1 )
  614. WORK( KI + (IV )*N ) = ONE
  615. END IF
  616. WORK( KI + (IV-1)*N ) = ZERO
  617. WORK( KI-1 + (IV )*N ) = ZERO
  618. *
  619. * Form right-hand side.
  620. *
  621. DO 80 K = 1, KI - 2
  622. WORK( K+(IV-1)*N ) = -WORK( KI-1+(IV-1)*N )*T(K,KI-1)
  623. WORK( K+(IV )*N ) = -WORK( KI +(IV )*N )*T(K,KI )
  624. 80 CONTINUE
  625. *
  626. * Solve upper quasi-triangular system:
  627. * [ T(1:KI-2,1:KI-2) - (WR+i*WI) ]*X = SCALE*(WORK+i*WORK2)
  628. *
  629. JNXT = KI - 2
  630. DO 90 J = KI - 2, 1, -1
  631. IF( J.GT.JNXT )
  632. $ GO TO 90
  633. J1 = J
  634. J2 = J
  635. JNXT = J - 1
  636. IF( J.GT.1 ) THEN
  637. IF( T( J, J-1 ).NE.ZERO ) THEN
  638. J1 = J - 1
  639. JNXT = J - 2
  640. END IF
  641. END IF
  642. *
  643. IF( J1.EQ.J2 ) THEN
  644. *
  645. * 1-by-1 diagonal block
  646. *
  647. CALL DLALN2( .FALSE., 1, 2, SMIN, ONE, T( J, J ),
  648. $ LDT, ONE, ONE, WORK( J+(IV-1)*N ), N,
  649. $ WR, WI, X, 2, SCALE, XNORM, IERR )
  650. *
  651. * Scale X(1,1) and X(1,2) to avoid overflow when
  652. * updating the right-hand side.
  653. *
  654. IF( XNORM.GT.ONE ) THEN
  655. IF( WORK( J ).GT.BIGNUM / XNORM ) THEN
  656. X( 1, 1 ) = X( 1, 1 ) / XNORM
  657. X( 1, 2 ) = X( 1, 2 ) / XNORM
  658. SCALE = SCALE / XNORM
  659. END IF
  660. END IF
  661. *
  662. * Scale if necessary
  663. *
  664. IF( SCALE.NE.ONE ) THEN
  665. CALL DSCAL( KI, SCALE, WORK( 1+(IV-1)*N ), 1 )
  666. CALL DSCAL( KI, SCALE, WORK( 1+(IV )*N ), 1 )
  667. END IF
  668. WORK( J+(IV-1)*N ) = X( 1, 1 )
  669. WORK( J+(IV )*N ) = X( 1, 2 )
  670. *
  671. * Update the right-hand side
  672. *
  673. CALL DAXPY( J-1, -X( 1, 1 ), T( 1, J ), 1,
  674. $ WORK( 1+(IV-1)*N ), 1 )
  675. CALL DAXPY( J-1, -X( 1, 2 ), T( 1, J ), 1,
  676. $ WORK( 1+(IV )*N ), 1 )
  677. *
  678. ELSE
  679. *
  680. * 2-by-2 diagonal block
  681. *
  682. CALL DLALN2( .FALSE., 2, 2, SMIN, ONE,
  683. $ T( J-1, J-1 ), LDT, ONE, ONE,
  684. $ WORK( J-1+(IV-1)*N ), N, WR, WI, X, 2,
  685. $ SCALE, XNORM, IERR )
  686. *
  687. * Scale X to avoid overflow when updating
  688. * the right-hand side.
  689. *
  690. IF( XNORM.GT.ONE ) THEN
  691. BETA = MAX( WORK( J-1 ), WORK( J ) )
  692. IF( BETA.GT.BIGNUM / XNORM ) THEN
  693. REC = ONE / XNORM
  694. X( 1, 1 ) = X( 1, 1 )*REC
  695. X( 1, 2 ) = X( 1, 2 )*REC
  696. X( 2, 1 ) = X( 2, 1 )*REC
  697. X( 2, 2 ) = X( 2, 2 )*REC
  698. SCALE = SCALE*REC
  699. END IF
  700. END IF
  701. *
  702. * Scale if necessary
  703. *
  704. IF( SCALE.NE.ONE ) THEN
  705. CALL DSCAL( KI, SCALE, WORK( 1+(IV-1)*N ), 1 )
  706. CALL DSCAL( KI, SCALE, WORK( 1+(IV )*N ), 1 )
  707. END IF
  708. WORK( J-1+(IV-1)*N ) = X( 1, 1 )
  709. WORK( J +(IV-1)*N ) = X( 2, 1 )
  710. WORK( J-1+(IV )*N ) = X( 1, 2 )
  711. WORK( J +(IV )*N ) = X( 2, 2 )
  712. *
  713. * Update the right-hand side
  714. *
  715. CALL DAXPY( J-2, -X( 1, 1 ), T( 1, J-1 ), 1,
  716. $ WORK( 1+(IV-1)*N ), 1 )
  717. CALL DAXPY( J-2, -X( 2, 1 ), T( 1, J ), 1,
  718. $ WORK( 1+(IV-1)*N ), 1 )
  719. CALL DAXPY( J-2, -X( 1, 2 ), T( 1, J-1 ), 1,
  720. $ WORK( 1+(IV )*N ), 1 )
  721. CALL DAXPY( J-2, -X( 2, 2 ), T( 1, J ), 1,
  722. $ WORK( 1+(IV )*N ), 1 )
  723. END IF
  724. 90 CONTINUE
  725. *
  726. * Copy the vector x or Q*x to VR and normalize.
  727. *
  728. IF( .NOT.OVER ) THEN
  729. * ------------------------------
  730. * no back-transform: copy x to VR and normalize.
  731. CALL DCOPY( KI, WORK( 1+(IV-1)*N ), 1, VR(1,IS-1), 1 )
  732. CALL DCOPY( KI, WORK( 1+(IV )*N ), 1, VR(1,IS ), 1 )
  733. *
  734. EMAX = ZERO
  735. DO 100 K = 1, KI
  736. EMAX = MAX( EMAX, ABS( VR( K, IS-1 ) )+
  737. $ ABS( VR( K, IS ) ) )
  738. 100 CONTINUE
  739. REMAX = ONE / EMAX
  740. CALL DSCAL( KI, REMAX, VR( 1, IS-1 ), 1 )
  741. CALL DSCAL( KI, REMAX, VR( 1, IS ), 1 )
  742. *
  743. DO 110 K = KI + 1, N
  744. VR( K, IS-1 ) = ZERO
  745. VR( K, IS ) = ZERO
  746. 110 CONTINUE
  747. *
  748. ELSE IF( NB.EQ.1 ) THEN
  749. * ------------------------------
  750. * version 1: back-transform each vector with GEMV, Q*x.
  751. IF( KI.GT.2 ) THEN
  752. CALL DGEMV( 'N', N, KI-2, ONE, VR, LDVR,
  753. $ WORK( 1 + (IV-1)*N ), 1,
  754. $ WORK( KI-1 + (IV-1)*N ), VR(1,KI-1), 1)
  755. CALL DGEMV( 'N', N, KI-2, ONE, VR, LDVR,
  756. $ WORK( 1 + (IV)*N ), 1,
  757. $ WORK( KI + (IV)*N ), VR( 1, KI ), 1 )
  758. ELSE
  759. CALL DSCAL( N, WORK(KI-1+(IV-1)*N), VR(1,KI-1), 1)
  760. CALL DSCAL( N, WORK(KI +(IV )*N), VR(1,KI ), 1)
  761. END IF
  762. *
  763. EMAX = ZERO
  764. DO 120 K = 1, N
  765. EMAX = MAX( EMAX, ABS( VR( K, KI-1 ) )+
  766. $ ABS( VR( K, KI ) ) )
  767. 120 CONTINUE
  768. REMAX = ONE / EMAX
  769. CALL DSCAL( N, REMAX, VR( 1, KI-1 ), 1 )
  770. CALL DSCAL( N, REMAX, VR( 1, KI ), 1 )
  771. *
  772. ELSE
  773. * ------------------------------
  774. * version 2: back-transform block of vectors with GEMM
  775. * zero out below vector
  776. DO K = KI + 1, N
  777. WORK( K + (IV-1)*N ) = ZERO
  778. WORK( K + (IV )*N ) = ZERO
  779. END DO
  780. ISCOMPLEX( IV-1 ) = -IP
  781. ISCOMPLEX( IV ) = IP
  782. IV = IV - 1
  783. * back-transform and normalization is done below
  784. END IF
  785. END IF
  786.  
  787. IF( NB.GT.1 ) THEN
  788. * --------------------------------------------------------
  789. * Blocked version of back-transform
  790. * For complex case, KI2 includes both vectors (KI-1 and KI)
  791. IF( IP.EQ.0 ) THEN
  792. KI2 = KI
  793. ELSE
  794. KI2 = KI - 1
  795. END IF
  796.  
  797. * Columns IV:NB of work are valid vectors.
  798. * When the number of vectors stored reaches NB-1 or NB,
  799. * or if this was last vector, do the GEMM
  800. IF( (IV.LE.2) .OR. (KI2.EQ.1) ) THEN
  801. CALL DGEMM( 'N', 'N', N, NB-IV+1, KI2+NB-IV, ONE,
  802. $ VR, LDVR,
  803. $ WORK( 1 + (IV)*N ), N,
  804. $ ZERO,
  805. $ WORK( 1 + (NB+IV)*N ), N )
  806. * normalize vectors
  807. DO K = IV, NB
  808. IF( ISCOMPLEX(K).EQ.0 ) THEN
  809. * real eigenvector
  810. II = IDAMAX( N, WORK( 1 + (NB+K)*N ), 1 )
  811. REMAX = ONE / ABS( WORK( II + (NB+K)*N ) )
  812. ELSE IF( ISCOMPLEX(K).EQ.1 ) THEN
  813. * first eigenvector of conjugate pair
  814. EMAX = ZERO
  815. DO II = 1, N
  816. EMAX = MAX( EMAX,
  817. $ ABS( WORK( II + (NB+K )*N ) )+
  818. $ ABS( WORK( II + (NB+K+1)*N ) ) )
  819. END DO
  820. REMAX = ONE / EMAX
  821. * else if ISCOMPLEX(K).EQ.-1
  822. * second eigenvector of conjugate pair
  823. * reuse same REMAX as previous K
  824. END IF
  825. CALL DSCAL( N, REMAX, WORK( 1 + (NB+K)*N ), 1 )
  826. END DO
  827. CALL DLACPY( 'F', N, NB-IV+1,
  828. $ WORK( 1 + (NB+IV)*N ), N,
  829. $ VR( 1, KI2 ), LDVR )
  830. IV = NB
  831. ELSE
  832. IV = IV - 1
  833. END IF
  834. END IF
  835. *! blocked back-transform
  836. *
  837. IS = IS - 1
  838. IF( IP.NE.0 )
  839. $ IS = IS - 1
  840. 140 CONTINUE
  841. END IF
  842.  
  843. IF( LEFTV ) THEN
  844. *
  845. * ============================================================
  846. * Compute left eigenvectors.
  847. *
  848. * IV is index of column in current block.
  849. * For complex left vector, uses IV for real part and IV+1 for complex part.
  850. * Non-blocked version always uses IV=1;
  851. * blocked version starts with IV=1, goes up to NB-1 or NB.
  852. * (Note the "0-th" column is used for 1-norms computed above.)
  853. IV = 1
  854. IP = 0
  855. IS = 1
  856. DO 260 KI = 1, N
  857. IF( IP.EQ.1 ) THEN
  858. * previous iteration (ki-1) was first of conjugate pair,
  859. * so this ki is second of conjugate pair; skip to end of loop
  860. IP = -1
  861. GO TO 260
  862. ELSE IF( KI.EQ.N ) THEN
  863. * last column, so this ki must be real eigenvalue
  864. IP = 0
  865. ELSE IF( T( KI+1, KI ).EQ.ZERO ) THEN
  866. * zero on sub-diagonal, so this ki is real eigenvalue
  867. IP = 0
  868. ELSE
  869. * non-zero on sub-diagonal, so this ki is first of conjugate pair
  870. IP = 1
  871. END IF
  872. *
  873. IF( SOMEV ) THEN
  874. IF( .NOT.SELECT( KI ) )
  875. $ GO TO 260
  876. END IF
  877. *
  878. * Compute the KI-th eigenvalue (WR,WI).
  879. *
  880. WR = T( KI, KI )
  881. WI = ZERO
  882. IF( IP.NE.0 )
  883. $ WI = SQRT( ABS( T( KI, KI+1 ) ) )*
  884. $ SQRT( ABS( T( KI+1, KI ) ) )
  885. SMIN = MAX( ULP*( ABS( WR )+ABS( WI ) ), SMLNUM )
  886. *
  887. IF( IP.EQ.0 ) THEN
  888. *
  889. * --------------------------------------------------------
  890. * Real left eigenvector
  891. *
  892. WORK( KI + IV*N ) = ONE
  893. *
  894. * Form right-hand side.
  895. *
  896. DO 160 K = KI + 1, N
  897. WORK( K + IV*N ) = -T( KI, K )
  898. 160 CONTINUE
  899. *
  900. * Solve transposed quasi-triangular system:
  901. * [ T(KI+1:N,KI+1:N) - WR ]**T * X = SCALE*WORK
  902. *
  903. VMAX = ONE
  904. VCRIT = BIGNUM
  905. *
  906. JNXT = KI + 1
  907. DO 170 J = KI + 1, N
  908. IF( J.LT.JNXT )
  909. $ GO TO 170
  910. J1 = J
  911. J2 = J
  912. JNXT = J + 1
  913. IF( J.LT.N ) THEN
  914. IF( T( J+1, J ).NE.ZERO ) THEN
  915. J2 = J + 1
  916. JNXT = J + 2
  917. END IF
  918. END IF
  919. *
  920. IF( J1.EQ.J2 ) THEN
  921. *
  922. * 1-by-1 diagonal block
  923. *
  924. * Scale if necessary to avoid overflow when forming
  925. * the right-hand side.
  926. *
  927. IF( WORK( J ).GT.VCRIT ) THEN
  928. REC = ONE / VMAX
  929. CALL DSCAL( N-KI+1, REC, WORK( KI+IV*N ), 1 )
  930. VMAX = ONE
  931. VCRIT = BIGNUM
  932. END IF
  933. *
  934. WORK( J+IV*N ) = WORK( J+IV*N ) -
  935. $ DDOT( J-KI-1, T( KI+1, J ), 1,
  936. $ WORK( KI+1+IV*N ), 1 )
  937. *
  938. * Solve [ T(J,J) - WR ]**T * X = WORK
  939. *
  940. CALL DLALN2( .FALSE., 1, 1, SMIN, ONE, T( J, J ),
  941. $ LDT, ONE, ONE, WORK( J+IV*N ), N, WR,
  942. $ ZERO, X, 2, SCALE, XNORM, IERR )
  943. *
  944. * Scale if necessary
  945. *
  946. IF( SCALE.NE.ONE )
  947. $ CALL DSCAL( N-KI+1, SCALE, WORK( KI+IV*N ), 1 )
  948. WORK( J+IV*N ) = X( 1, 1 )
  949. VMAX = MAX( ABS( WORK( J+IV*N ) ), VMAX )
  950. VCRIT = BIGNUM / VMAX
  951. *
  952. ELSE
  953. *
  954. * 2-by-2 diagonal block
  955. *
  956. * Scale if necessary to avoid overflow when forming
  957. * the right-hand side.
  958. *
  959. BETA = MAX( WORK( J ), WORK( J+1 ) )
  960. IF( BETA.GT.VCRIT ) THEN
  961. REC = ONE / VMAX
  962. CALL DSCAL( N-KI+1, REC, WORK( KI+IV*N ), 1 )
  963. VMAX = ONE
  964. VCRIT = BIGNUM
  965. END IF
  966. *
  967. WORK( J+IV*N ) = WORK( J+IV*N ) -
  968. $ DDOT( J-KI-1, T( KI+1, J ), 1,
  969. $ WORK( KI+1+IV*N ), 1 )
  970. *
  971. WORK( J+1+IV*N ) = WORK( J+1+IV*N ) -
  972. $ DDOT( J-KI-1, T( KI+1, J+1 ), 1,
  973. $ WORK( KI+1+IV*N ), 1 )
  974. *
  975. * Solve
  976. * [ T(J,J)-WR T(J,J+1) ]**T * X = SCALE*( WORK1 )
  977. * [ T(J+1,J) T(J+1,J+1)-WR ] ( WORK2 )
  978. *
  979. CALL DLALN2( .TRUE., 2, 1, SMIN, ONE, T( J, J ),
  980. $ LDT, ONE, ONE, WORK( J+IV*N ), N, WR,
  981. $ ZERO, X, 2, SCALE, XNORM, IERR )
  982. *
  983. * Scale if necessary
  984. *
  985. IF( SCALE.NE.ONE )
  986. $ CALL DSCAL( N-KI+1, SCALE, WORK( KI+IV*N ), 1 )
  987. WORK( J +IV*N ) = X( 1, 1 )
  988. WORK( J+1+IV*N ) = X( 2, 1 )
  989. *
  990. VMAX = MAX( ABS( WORK( J +IV*N ) ),
  991. $ ABS( WORK( J+1+IV*N ) ), VMAX )
  992. VCRIT = BIGNUM / VMAX
  993. *
  994. END IF
  995. 170 CONTINUE
  996. *
  997. * Copy the vector x or Q*x to VL and normalize.
  998. *
  999. IF( .NOT.OVER ) THEN
  1000. * ------------------------------
  1001. * no back-transform: copy x to VL and normalize.
  1002. CALL DCOPY( N-KI+1, WORK( KI + IV*N ), 1,
  1003. $ VL( KI, IS ), 1 )
  1004. *
  1005. II = IDAMAX( N-KI+1, VL( KI, IS ), 1 ) + KI - 1
  1006. REMAX = ONE / ABS( VL( II, IS ) )
  1007. CALL DSCAL( N-KI+1, REMAX, VL( KI, IS ), 1 )
  1008. *
  1009. DO 180 K = 1, KI - 1
  1010. VL( K, IS ) = ZERO
  1011. 180 CONTINUE
  1012. *
  1013. ELSE IF( NB.EQ.1 ) THEN
  1014. * ------------------------------
  1015. * version 1: back-transform each vector with GEMV, Q*x.
  1016. IF( KI.LT.N )
  1017. $ CALL DGEMV( 'N', N, N-KI, ONE,
  1018. $ VL( 1, KI+1 ), LDVL,
  1019. $ WORK( KI+1 + IV*N ), 1,
  1020. $ WORK( KI + IV*N ), VL( 1, KI ), 1 )
  1021. *
  1022. II = IDAMAX( N, VL( 1, KI ), 1 )
  1023. REMAX = ONE / ABS( VL( II, KI ) )
  1024. CALL DSCAL( N, REMAX, VL( 1, KI ), 1 )
  1025. *
  1026. ELSE
  1027. * ------------------------------
  1028. * version 2: back-transform block of vectors with GEMM
  1029. * zero out above vector
  1030. * could go from KI-NV+1 to KI-1
  1031. DO K = 1, KI - 1
  1032. WORK( K + IV*N ) = ZERO
  1033. END DO
  1034. ISCOMPLEX( IV ) = IP
  1035. * back-transform and normalization is done below
  1036. END IF
  1037. ELSE
  1038. *
  1039. * --------------------------------------------------------
  1040. * Complex left eigenvector.
  1041. *
  1042. * Initial solve:
  1043. * [ ( T(KI,KI) T(KI,KI+1) )**T - (WR - I* WI) ]*X = 0.
  1044. * [ ( T(KI+1,KI) T(KI+1,KI+1) ) ]
  1045. *
  1046. IF( ABS( T( KI, KI+1 ) ).GE.ABS( T( KI+1, KI ) ) ) THEN
  1047. WORK( KI + (IV )*N ) = WI / T( KI, KI+1 )
  1048. WORK( KI+1 + (IV+1)*N ) = ONE
  1049. ELSE
  1050. WORK( KI + (IV )*N ) = ONE
  1051. WORK( KI+1 + (IV+1)*N ) = -WI / T( KI+1, KI )
  1052. END IF
  1053. WORK( KI+1 + (IV )*N ) = ZERO
  1054. WORK( KI + (IV+1)*N ) = ZERO
  1055. *
  1056. * Form right-hand side.
  1057. *
  1058. DO 190 K = KI + 2, N
  1059. WORK( K+(IV )*N ) = -WORK( KI +(IV )*N )*T(KI, K)
  1060. WORK( K+(IV+1)*N ) = -WORK( KI+1+(IV+1)*N )*T(KI+1,K)
  1061. 190 CONTINUE
  1062. *
  1063. * Solve transposed quasi-triangular system:
  1064. * [ T(KI+2:N,KI+2:N)**T - (WR-i*WI) ]*X = WORK1+i*WORK2
  1065. *
  1066. VMAX = ONE
  1067. VCRIT = BIGNUM
  1068. *
  1069. JNXT = KI + 2
  1070. DO 200 J = KI + 2, N
  1071. IF( J.LT.JNXT )
  1072. $ GO TO 200
  1073. J1 = J
  1074. J2 = J
  1075. JNXT = J + 1
  1076. IF( J.LT.N ) THEN
  1077. IF( T( J+1, J ).NE.ZERO ) THEN
  1078. J2 = J + 1
  1079. JNXT = J + 2
  1080. END IF
  1081. END IF
  1082. *
  1083. IF( J1.EQ.J2 ) THEN
  1084. *
  1085. * 1-by-1 diagonal block
  1086. *
  1087. * Scale if necessary to avoid overflow when
  1088. * forming the right-hand side elements.
  1089. *
  1090. IF( WORK( J ).GT.VCRIT ) THEN
  1091. REC = ONE / VMAX
  1092. CALL DSCAL( N-KI+1, REC, WORK(KI+(IV )*N), 1 )
  1093. CALL DSCAL( N-KI+1, REC, WORK(KI+(IV+1)*N), 1 )
  1094. VMAX = ONE
  1095. VCRIT = BIGNUM
  1096. END IF
  1097. *
  1098. WORK( J+(IV )*N ) = WORK( J+(IV)*N ) -
  1099. $ DDOT( J-KI-2, T( KI+2, J ), 1,
  1100. $ WORK( KI+2+(IV)*N ), 1 )
  1101. WORK( J+(IV+1)*N ) = WORK( J+(IV+1)*N ) -
  1102. $ DDOT( J-KI-2, T( KI+2, J ), 1,
  1103. $ WORK( KI+2+(IV+1)*N ), 1 )
  1104. *
  1105. * Solve [ T(J,J)-(WR-i*WI) ]*(X11+i*X12)= WK+I*WK2
  1106. *
  1107. CALL DLALN2( .FALSE., 1, 2, SMIN, ONE, T( J, J ),
  1108. $ LDT, ONE, ONE, WORK( J+IV*N ), N, WR,
  1109. $ -WI, X, 2, SCALE, XNORM, IERR )
  1110. *
  1111. * Scale if necessary
  1112. *
  1113. IF( SCALE.NE.ONE ) THEN
  1114. CALL DSCAL( N-KI+1, SCALE, WORK(KI+(IV )*N), 1)
  1115. CALL DSCAL( N-KI+1, SCALE, WORK(KI+(IV+1)*N), 1)
  1116. END IF
  1117. WORK( J+(IV )*N ) = X( 1, 1 )
  1118. WORK( J+(IV+1)*N ) = X( 1, 2 )
  1119. VMAX = MAX( ABS( WORK( J+(IV )*N ) ),
  1120. $ ABS( WORK( J+(IV+1)*N ) ), VMAX )
  1121. VCRIT = BIGNUM / VMAX
  1122. *
  1123. ELSE
  1124. *
  1125. * 2-by-2 diagonal block
  1126. *
  1127. * Scale if necessary to avoid overflow when forming
  1128. * the right-hand side elements.
  1129. *
  1130. BETA = MAX( WORK( J ), WORK( J+1 ) )
  1131. IF( BETA.GT.VCRIT ) THEN
  1132. REC = ONE / VMAX
  1133. CALL DSCAL( N-KI+1, REC, WORK(KI+(IV )*N), 1 )
  1134. CALL DSCAL( N-KI+1, REC, WORK(KI+(IV+1)*N), 1 )
  1135. VMAX = ONE
  1136. VCRIT = BIGNUM
  1137. END IF
  1138. *
  1139. WORK( J +(IV )*N ) = WORK( J+(IV)*N ) -
  1140. $ DDOT( J-KI-2, T( KI+2, J ), 1,
  1141. $ WORK( KI+2+(IV)*N ), 1 )
  1142. *
  1143. WORK( J +(IV+1)*N ) = WORK( J+(IV+1)*N ) -
  1144. $ DDOT( J-KI-2, T( KI+2, J ), 1,
  1145. $ WORK( KI+2+(IV+1)*N ), 1 )
  1146. *
  1147. WORK( J+1+(IV )*N ) = WORK( J+1+(IV)*N ) -
  1148. $ DDOT( J-KI-2, T( KI+2, J+1 ), 1,
  1149. $ WORK( KI+2+(IV)*N ), 1 )
  1150. *
  1151. WORK( J+1+(IV+1)*N ) = WORK( J+1+(IV+1)*N ) -
  1152. $ DDOT( J-KI-2, T( KI+2, J+1 ), 1,
  1153. $ WORK( KI+2+(IV+1)*N ), 1 )
  1154. *
  1155. * Solve 2-by-2 complex linear equation
  1156. * [ (T(j,j) T(j,j+1) )**T - (wr-i*wi)*I ]*X = SCALE*B
  1157. * [ (T(j+1,j) T(j+1,j+1)) ]
  1158. *
  1159. CALL DLALN2( .TRUE., 2, 2, SMIN, ONE, T( J, J ),
  1160. $ LDT, ONE, ONE, WORK( J+IV*N ), N, WR,
  1161. $ -WI, X, 2, SCALE, XNORM, IERR )
  1162. *
  1163. * Scale if necessary
  1164. *
  1165. IF( SCALE.NE.ONE ) THEN
  1166. CALL DSCAL( N-KI+1, SCALE, WORK(KI+(IV )*N), 1)
  1167. CALL DSCAL( N-KI+1, SCALE, WORK(KI+(IV+1)*N), 1)
  1168. END IF
  1169. WORK( J +(IV )*N ) = X( 1, 1 )
  1170. WORK( J +(IV+1)*N ) = X( 1, 2 )
  1171. WORK( J+1+(IV )*N ) = X( 2, 1 )
  1172. WORK( J+1+(IV+1)*N ) = X( 2, 2 )
  1173. VMAX = MAX( ABS( X( 1, 1 ) ), ABS( X( 1, 2 ) ),
  1174. $ ABS( X( 2, 1 ) ), ABS( X( 2, 2 ) ),
  1175. $ VMAX )
  1176. VCRIT = BIGNUM / VMAX
  1177. *
  1178. END IF
  1179. 200 CONTINUE
  1180. *
  1181. * Copy the vector x or Q*x to VL and normalize.
  1182. *
  1183. IF( .NOT.OVER ) THEN
  1184. * ------------------------------
  1185. * no back-transform: copy x to VL and normalize.
  1186. CALL DCOPY( N-KI+1, WORK( KI + (IV )*N ), 1,
  1187. $ VL( KI, IS ), 1 )
  1188. CALL DCOPY( N-KI+1, WORK( KI + (IV+1)*N ), 1,
  1189. $ VL( KI, IS+1 ), 1 )
  1190. *
  1191. EMAX = ZERO
  1192. DO 220 K = KI, N
  1193. EMAX = MAX( EMAX, ABS( VL( K, IS ) )+
  1194. $ ABS( VL( K, IS+1 ) ) )
  1195. 220 CONTINUE
  1196. REMAX = ONE / EMAX
  1197. CALL DSCAL( N-KI+1, REMAX, VL( KI, IS ), 1 )
  1198. CALL DSCAL( N-KI+1, REMAX, VL( KI, IS+1 ), 1 )
  1199. *
  1200. DO 230 K = 1, KI - 1
  1201. VL( K, IS ) = ZERO
  1202. VL( K, IS+1 ) = ZERO
  1203. 230 CONTINUE
  1204. *
  1205. ELSE IF( NB.EQ.1 ) THEN
  1206. * ------------------------------
  1207. * version 1: back-transform each vector with GEMV, Q*x.
  1208. IF( KI.LT.N-1 ) THEN
  1209. CALL DGEMV( 'N', N, N-KI-1, ONE,
  1210. $ VL( 1, KI+2 ), LDVL,
  1211. $ WORK( KI+2 + (IV)*N ), 1,
  1212. $ WORK( KI + (IV)*N ),
  1213. $ VL( 1, KI ), 1 )
  1214. CALL DGEMV( 'N', N, N-KI-1, ONE,
  1215. $ VL( 1, KI+2 ), LDVL,
  1216. $ WORK( KI+2 + (IV+1)*N ), 1,
  1217. $ WORK( KI+1 + (IV+1)*N ),
  1218. $ VL( 1, KI+1 ), 1 )
  1219. ELSE
  1220. CALL DSCAL( N, WORK(KI+ (IV )*N), VL(1, KI ), 1)
  1221. CALL DSCAL( N, WORK(KI+1+(IV+1)*N), VL(1, KI+1), 1)
  1222. END IF
  1223. *
  1224. EMAX = ZERO
  1225. DO 240 K = 1, N
  1226. EMAX = MAX( EMAX, ABS( VL( K, KI ) )+
  1227. $ ABS( VL( K, KI+1 ) ) )
  1228. 240 CONTINUE
  1229. REMAX = ONE / EMAX
  1230. CALL DSCAL( N, REMAX, VL( 1, KI ), 1 )
  1231. CALL DSCAL( N, REMAX, VL( 1, KI+1 ), 1 )
  1232. *
  1233. ELSE
  1234. * ------------------------------
  1235. * version 2: back-transform block of vectors with GEMM
  1236. * zero out above vector
  1237. * could go from KI-NV+1 to KI-1
  1238. DO K = 1, KI - 1
  1239. WORK( K + (IV )*N ) = ZERO
  1240. WORK( K + (IV+1)*N ) = ZERO
  1241. END DO
  1242. ISCOMPLEX( IV ) = IP
  1243. ISCOMPLEX( IV+1 ) = -IP
  1244. IV = IV + 1
  1245. * back-transform and normalization is done below
  1246. END IF
  1247. END IF
  1248.  
  1249. IF( NB.GT.1 ) THEN
  1250. * --------------------------------------------------------
  1251. * Blocked version of back-transform
  1252. * For complex case, KI2 includes both vectors (KI and KI+1)
  1253. IF( IP.EQ.0 ) THEN
  1254. KI2 = KI
  1255. ELSE
  1256. KI2 = KI + 1
  1257. END IF
  1258.  
  1259. * Columns 1:IV of work are valid vectors.
  1260. * When the number of vectors stored reaches NB-1 or NB,
  1261. * or if this was last vector, do the GEMM
  1262. IF( (IV.GE.NB-1) .OR. (KI2.EQ.N) ) THEN
  1263. CALL DGEMM( 'N', 'N', N, IV, N-KI2+IV, ONE,
  1264. $ VL( 1, KI2-IV+1 ), LDVL,
  1265. $ WORK( KI2-IV+1 + (1)*N ), N,
  1266. $ ZERO,
  1267. $ WORK( 1 + (NB+1)*N ), N )
  1268. * normalize vectors
  1269. DO K = 1, IV
  1270. IF( ISCOMPLEX(K).EQ.0) THEN
  1271. * real eigenvector
  1272. II = IDAMAX( N, WORK( 1 + (NB+K)*N ), 1 )
  1273. REMAX = ONE / ABS( WORK( II + (NB+K)*N ) )
  1274. ELSE IF( ISCOMPLEX(K).EQ.1) THEN
  1275. * first eigenvector of conjugate pair
  1276. EMAX = ZERO
  1277. DO II = 1, N
  1278. EMAX = MAX( EMAX,
  1279. $ ABS( WORK( II + (NB+K )*N ) )+
  1280. $ ABS( WORK( II + (NB+K+1)*N ) ) )
  1281. END DO
  1282. REMAX = ONE / EMAX
  1283. * else if ISCOMPLEX(K).EQ.-1
  1284. * second eigenvector of conjugate pair
  1285. * reuse same REMAX as previous K
  1286. END IF
  1287. CALL DSCAL( N, REMAX, WORK( 1 + (NB+K)*N ), 1 )
  1288. END DO
  1289. CALL DLACPY( 'F', N, IV,
  1290. $ WORK( 1 + (NB+1)*N ), N,
  1291. $ VL( 1, KI2-IV+1 ), LDVL )
  1292. IV = 1
  1293. ELSE
  1294. IV = IV + 1
  1295. END IF
  1296. END IF
  1297. *! blocked back-transform
  1298. *
  1299. IS = IS + 1
  1300. IF( IP.NE.0 )
  1301. $ IS = IS + 1
  1302. 260 CONTINUE
  1303. END IF
  1304. *
  1305. RETURN
  1306. *
  1307. * End of DTREVC3
  1308. *
  1309. END
  1310.  
  1311.  
  1312.  

© Cast3M 2003 - Tous droits réservés.
Mentions légales