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.

dtgevc.f 41 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207
  1. *> \brief \b DTGEVC
  2. *
  3. * =========== DOCUMENTATION ===========
  4. *
  5. * Online html documentation available at
  6. * http://www.netlib.org/lapack/explore-html/
  7. *
  8. *> \htmlonly
  9. *> Download DTGEVC + dependencies
  10. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dtgevc.f">
  11. *> [TGZ]</a>
  12. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dtgevc.f">
  13. *> [ZIP]</a>
  14. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dtgevc.f">
  15. *> [TXT]</a>
  16. *> \endhtmlonly
  17. *
  18. * Definition:
  19. * ===========
  20. *
  21. * SUBROUTINE DTGEVC( SIDE, HOWMNY, SELECT, N, S, LDS, P, LDP, VL,
  22. * LDVL, VR, LDVR, MM, M, WORK, INFO )
  23. *
  24. * .. Scalar Arguments ..
  25. * CHARACTER HOWMNY, SIDE
  26. * INTEGER INFO, LDP, LDS, LDVL, LDVR, M, MM, N
  27. * ..
  28. * .. Array Arguments ..
  29. * LOGICAL SELECT( * )
  30. * DOUBLE PRECISION P( LDP, * ), S( LDS, * ), VL( LDVL, * ),
  31. * $ VR( LDVR, * ), WORK( * )
  32. * ..
  33. *
  34. *
  35. *
  36. *> \par Purpose:
  37. * =============
  38. *>
  39. *> \verbatim
  40. *>
  41. *> DTGEVC computes some or all of the right and/or left eigenvectors of
  42. *> a pair of real matrices (S,P), where S is a quasi-triangular matrix
  43. *> and P is upper triangular. Matrix pairs of this type are produced by
  44. *> the generalized Schur factorization of a matrix pair (A,B):
  45. *>
  46. *> A = Q*S*Z**T, B = Q*P*Z**T
  47. *>
  48. *> as computed by DGGHRD + DHGEQZ.
  49. *>
  50. *> The right eigenvector x and the left eigenvector y of (S,P)
  51. *> corresponding to an eigenvalue w are defined by:
  52. *>
  53. *> S*x = w*P*x, (y**H)*S = w*(y**H)*P,
  54. *>
  55. *> where y**H denotes the conjugate transpose of y.
  56. *> The eigenvalues are not input to this routine, but are computed
  57. *> directly from the diagonal blocks of S and P.
  58. *>
  59. *> This routine returns the matrices X and/or Y of right and left
  60. *> eigenvectors of (S,P), or the products Z*X and/or Q*Y,
  61. *> where Z and Q are input matrices.
  62. *> If Q and Z are the orthogonal factors from the generalized Schur
  63. *> factorization of a matrix pair (A,B), then Z*X and Q*Y
  64. *> are the matrices of right and left eigenvectors of (A,B).
  65. *>
  66. *> \endverbatim
  67. *
  68. * Arguments:
  69. * ==========
  70. *
  71. *> \param[in] SIDE
  72. *> \verbatim
  73. *> SIDE is CHARACTER*1
  74. *> = 'R': compute right eigenvectors only;
  75. *> = 'L': compute left eigenvectors only;
  76. *> = 'B': compute both right and left eigenvectors.
  77. *> \endverbatim
  78. *>
  79. *> \param[in] HOWMNY
  80. *> \verbatim
  81. *> HOWMNY is CHARACTER*1
  82. *> = 'A': compute all right and/or left eigenvectors;
  83. *> = 'B': compute all right and/or left eigenvectors,
  84. *> backtransformed by the matrices in VR and/or VL;
  85. *> = 'S': compute selected right and/or left eigenvectors,
  86. *> specified by the logical array SELECT.
  87. *> \endverbatim
  88. *>
  89. *> \param[in] SELECT
  90. *> \verbatim
  91. *> SELECT is LOGICAL array, dimension (N)
  92. *> If HOWMNY='S', SELECT specifies the eigenvectors to be
  93. *> computed. If w(j) is a real eigenvalue, the corresponding
  94. *> real eigenvector is computed if SELECT(j) is .TRUE..
  95. *> If w(j) and w(j+1) are the real and imaginary parts of a
  96. *> complex eigenvalue, the corresponding complex eigenvector
  97. *> is computed if either SELECT(j) or SELECT(j+1) is .TRUE.,
  98. *> and on exit SELECT(j) is set to .TRUE. and SELECT(j+1) is
  99. *> set to .FALSE..
  100. *> Not referenced if HOWMNY = 'A' or 'B'.
  101. *> \endverbatim
  102. *>
  103. *> \param[in] N
  104. *> \verbatim
  105. *> N is INTEGER
  106. *> The order of the matrices S and P. N >= 0.
  107. *> \endverbatim
  108. *>
  109. *> \param[in] S
  110. *> \verbatim
  111. *> S is DOUBLE PRECISION array, dimension (LDS,N)
  112. *> The upper quasi-triangular matrix S from a generalized Schur
  113. *> factorization, as computed by DHGEQZ.
  114. *> \endverbatim
  115. *>
  116. *> \param[in] LDS
  117. *> \verbatim
  118. *> LDS is INTEGER
  119. *> The leading dimension of array S. LDS >= max(1,N).
  120. *> \endverbatim
  121. *>
  122. *> \param[in] P
  123. *> \verbatim
  124. *> P is DOUBLE PRECISION array, dimension (LDP,N)
  125. *> The upper triangular matrix P from a generalized Schur
  126. *> factorization, as computed by DHGEQZ.
  127. *> 2-by-2 diagonal blocks of P corresponding to 2-by-2 blocks
  128. *> of S must be in positive diagonal form.
  129. *> \endverbatim
  130. *>
  131. *> \param[in] LDP
  132. *> \verbatim
  133. *> LDP is INTEGER
  134. *> The leading dimension of array P. LDP >= max(1,N).
  135. *> \endverbatim
  136. *>
  137. *> \param[in,out] VL
  138. *> \verbatim
  139. *> VL is DOUBLE PRECISION array, dimension (LDVL,MM)
  140. *> On entry, if SIDE = 'L' or 'B' and HOWMNY = 'B', VL must
  141. *> contain an N-by-N matrix Q (usually the orthogonal matrix Q
  142. *> of left Schur vectors returned by DHGEQZ).
  143. *> On exit, if SIDE = 'L' or 'B', VL contains:
  144. *> if HOWMNY = 'A', the matrix Y of left eigenvectors of (S,P);
  145. *> if HOWMNY = 'B', the matrix Q*Y;
  146. *> if HOWMNY = 'S', the left eigenvectors of (S,P) specified by
  147. *> SELECT, stored consecutively in the columns of
  148. *> VL, in the same order as their eigenvalues.
  149. *>
  150. *> A complex eigenvector corresponding to a complex eigenvalue
  151. *> is stored in two consecutive columns, the first holding the
  152. *> real part, and the second the imaginary part.
  153. *>
  154. *> Not referenced if SIDE = 'R'.
  155. *> \endverbatim
  156. *>
  157. *> \param[in] LDVL
  158. *> \verbatim
  159. *> LDVL is INTEGER
  160. *> The leading dimension of array VL. LDVL >= 1, and if
  161. *> SIDE = 'L' or 'B', LDVL >= N.
  162. *> \endverbatim
  163. *>
  164. *> \param[in,out] VR
  165. *> \verbatim
  166. *> VR is DOUBLE PRECISION array, dimension (LDVR,MM)
  167. *> On entry, if SIDE = 'R' or 'B' and HOWMNY = 'B', VR must
  168. *> contain an N-by-N matrix Z (usually the orthogonal matrix Z
  169. *> of right Schur vectors returned by DHGEQZ).
  170. *>
  171. *> On exit, if SIDE = 'R' or 'B', VR contains:
  172. *> if HOWMNY = 'A', the matrix X of right eigenvectors of (S,P);
  173. *> if HOWMNY = 'B' or 'b', the matrix Z*X;
  174. *> if HOWMNY = 'S' or 's', the right eigenvectors of (S,P)
  175. *> specified by SELECT, stored consecutively in the
  176. *> columns of VR, in the same order as their
  177. *> eigenvalues.
  178. *>
  179. *> A complex eigenvector corresponding to a complex eigenvalue
  180. *> is stored in two consecutive columns, the first holding the
  181. *> real part and the second the imaginary part.
  182. *>
  183. *> Not referenced if SIDE = 'L'.
  184. *> \endverbatim
  185. *>
  186. *> \param[in] LDVR
  187. *> \verbatim
  188. *> LDVR is INTEGER
  189. *> The leading dimension of the array VR. LDVR >= 1, and if
  190. *> SIDE = 'R' or 'B', LDVR >= N.
  191. *> \endverbatim
  192. *>
  193. *> \param[in] MM
  194. *> \verbatim
  195. *> MM is INTEGER
  196. *> The number of columns in the arrays VL and/or VR. MM >= M.
  197. *> \endverbatim
  198. *>
  199. *> \param[out] M
  200. *> \verbatim
  201. *> M is INTEGER
  202. *> The number of columns in the arrays VL and/or VR actually
  203. *> used to store the eigenvectors. If HOWMNY = 'A' or 'B', M
  204. *> is set to N. Each selected real eigenvector occupies one
  205. *> column and each selected complex eigenvector occupies two
  206. *> columns.
  207. *> \endverbatim
  208. *>
  209. *> \param[out] WORK
  210. *> \verbatim
  211. *> WORK is DOUBLE PRECISION array, dimension (6*N)
  212. *> \endverbatim
  213. *>
  214. *> \param[out] INFO
  215. *> \verbatim
  216. *> INFO is INTEGER
  217. *> = 0: successful exit.
  218. *> < 0: if INFO = -i, the i-th argument had an illegal value.
  219. *> > 0: the 2-by-2 block (INFO:INFO+1) does not have a complex
  220. *> eigenvalue.
  221. *> \endverbatim
  222. *
  223. * Authors:
  224. * ========
  225. *
  226. *> \author Univ. of Tennessee
  227. *> \author Univ. of California Berkeley
  228. *> \author Univ. of Colorado Denver
  229. *> \author NAG Ltd.
  230. *
  231. *> \ingroup doubleGEcomputational
  232. *
  233. *> \par Further Details:
  234. * =====================
  235. *>
  236. *> \verbatim
  237. *>
  238. *> Allocation of workspace:
  239. *> ---------- -- ---------
  240. *>
  241. *> WORK( j ) = 1-norm of j-th column of A, above the diagonal
  242. *> WORK( N+j ) = 1-norm of j-th column of B, above the diagonal
  243. *> WORK( 2*N+1:3*N ) = real part of eigenvector
  244. *> WORK( 3*N+1:4*N ) = imaginary part of eigenvector
  245. *> WORK( 4*N+1:5*N ) = real part of back-transformed eigenvector
  246. *> WORK( 5*N+1:6*N ) = imaginary part of back-transformed eigenvector
  247. *>
  248. *> Rowwise vs. columnwise solution methods:
  249. *> ------- -- ---------- -------- -------
  250. *>
  251. *> Finding a generalized eigenvector consists basically of solving the
  252. *> singular triangular system
  253. *>
  254. *> (A - w B) x = 0 (for right) or: (A - w B)**H y = 0 (for left)
  255. *>
  256. *> Consider finding the i-th right eigenvector (assume all eigenvalues
  257. *> are real). The equation to be solved is:
  258. *> n i
  259. *> 0 = sum C(j,k) v(k) = sum C(j,k) v(k) for j = i,. . .,1
  260. *> k=j k=j
  261. *>
  262. *> where C = (A - w B) (The components v(i+1:n) are 0.)
  263. *>
  264. *> The "rowwise" method is:
  265. *>
  266. *> (1) v(i) := 1
  267. *> for j = i-1,. . .,1:
  268. *> i
  269. *> (2) compute s = - sum C(j,k) v(k) and
  270. *> k=j+1
  271. *>
  272. *> (3) v(j) := s / C(j,j)
  273. *>
  274. *> Step 2 is sometimes called the "dot product" step, since it is an
  275. *> inner product between the j-th row and the portion of the eigenvector
  276. *> that has been computed so far.
  277. *>
  278. *> The "columnwise" method consists basically in doing the sums
  279. *> for all the rows in parallel. As each v(j) is computed, the
  280. *> contribution of v(j) times the j-th column of C is added to the
  281. *> partial sums. Since FORTRAN arrays are stored columnwise, this has
  282. *> the advantage that at each step, the elements of C that are accessed
  283. *> are adjacent to one another, whereas with the rowwise method, the
  284. *> elements accessed at a step are spaced LDS (and LDP) words apart.
  285. *>
  286. *> When finding left eigenvectors, the matrix in question is the
  287. *> transpose of the one in storage, so the rowwise method then
  288. *> actually accesses columns of A and B at each step, and so is the
  289. *> preferred method.
  290. *> \endverbatim
  291. *>
  292. * =====================================================================
  293. SUBROUTINE DTGEVC( SIDE, HOWMNY, SELECT, N, S, LDS, P, LDP, VL,
  294. $ LDVL, VR, LDVR, MM, M, WORK, INFO )
  295. *
  296. * -- LAPACK computational routine --
  297. * -- LAPACK is a software package provided by Univ. of Tennessee, --
  298. * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
  299. *
  300. * .. Scalar Arguments ..
  301. CHARACTER HOWMNY, SIDE
  302. INTEGER INFO, LDP, LDS, LDVL, LDVR, M, MM, N
  303. * ..
  304. * .. Array Arguments ..
  305. LOGICAL SELECT( * )
  306. DOUBLE PRECISION P( LDP, * ), S( LDS, * ), VL( LDVL, * ),
  307. $ VR( LDVR, * ), WORK( * )
  308. * ..
  309. *
  310. *
  311. * =====================================================================
  312. *
  313. * .. Parameters ..
  314. DOUBLE PRECISION ZERO, ONE, SAFETY
  315. PARAMETER ( ZERO = 0.0D+0, ONE = 1.0D+0,
  316. $ SAFETY = 1.0D+2 )
  317. * ..
  318. * .. Local Scalars ..
  319. LOGICAL COMPL, COMPR, IL2BY2, ILABAD, ILALL, ILBACK,
  320. $ ILBBAD, ILCOMP, ILCPLX, LSA, LSB
  321. INTEGER I, IBEG, IEIG, IEND, IHWMNY, IINFO, IM, ISIDE,
  322. $ J, JA, JC, JE, JR, JW, NA, NW
  323. DOUBLE PRECISION ACOEF, ACOEFA, ANORM, ASCALE, BCOEFA, BCOEFI,
  324. $ BCOEFR, BIG, BIGNUM, BNORM, BSCALE, CIM2A,
  325. $ CIM2B, CIMAGA, CIMAGB, CRE2A, CRE2B, CREALA,
  326. $ CREALB, DMIN, SAFMIN, SALFAR, SBETA, SCALE,
  327. $ SMALL, TEMP, TEMP2, TEMP2I, TEMP2R, ULP, XMAX,
  328. $ XSCALE
  329. * ..
  330. * .. Local Arrays ..
  331. DOUBLE PRECISION BDIAG( 2 ), SUM( 2, 2 ), SUMS( 2, 2 ),
  332. $ SUMP( 2, 2 )
  333. * ..
  334. * .. External Functions ..
  335. LOGICAL LSAME
  336. DOUBLE PRECISION DLAMCH
  337. EXTERNAL LSAME, DLAMCH
  338. * ..
  339. * .. External Subroutines ..
  340. EXTERNAL DGEMV, DLACPY, DLAG2, DLALN2, XERBLA
  341. * ..
  342. * .. Intrinsic Functions ..
  343. INTRINSIC ABS, MAX, MIN
  344. * ..
  345. * .. Executable Statements ..
  346. *
  347. * Decode and Test the input parameters
  348. *
  349. IF( LSAME( HOWMNY, 'A' ) ) THEN
  350. IHWMNY = 1
  351. ILALL = .TRUE.
  352. ILBACK = .FALSE.
  353. ELSE IF( LSAME( HOWMNY, 'S' ) ) THEN
  354. IHWMNY = 2
  355. ILALL = .FALSE.
  356. ILBACK = .FALSE.
  357. ELSE IF( LSAME( HOWMNY, 'B' ) ) THEN
  358. IHWMNY = 3
  359. ILALL = .TRUE.
  360. ILBACK = .TRUE.
  361. ELSE
  362. IHWMNY = -1
  363. ILALL = .TRUE.
  364. END IF
  365. *
  366. IF( LSAME( SIDE, 'R' ) ) THEN
  367. ISIDE = 1
  368. COMPL = .FALSE.
  369. COMPR = .TRUE.
  370. ELSE IF( LSAME( SIDE, 'L' ) ) THEN
  371. ISIDE = 2
  372. COMPL = .TRUE.
  373. COMPR = .FALSE.
  374. ELSE IF( LSAME( SIDE, 'B' ) ) THEN
  375. ISIDE = 3
  376. COMPL = .TRUE.
  377. COMPR = .TRUE.
  378. ELSE
  379. ISIDE = -1
  380. END IF
  381. *
  382. INFO = 0
  383. IF( ISIDE.LT.0 ) THEN
  384. INFO = -1
  385. ELSE IF( IHWMNY.LT.0 ) THEN
  386. INFO = -2
  387. ELSE IF( N.LT.0 ) THEN
  388. INFO = -4
  389. ELSE IF( LDS.LT.MAX( 1, N ) ) THEN
  390. INFO = -6
  391. ELSE IF( LDP.LT.MAX( 1, N ) ) THEN
  392. INFO = -8
  393. END IF
  394. IF( INFO.NE.0 ) THEN
  395. CALL XERBLA( 'DTGEVC', -INFO )
  396. RETURN
  397. END IF
  398. *
  399. * Count the number of eigenvectors to be computed
  400. *
  401. IF( .NOT.ILALL ) THEN
  402. IM = 0
  403. ILCPLX = .FALSE.
  404. DO 10 J = 1, N
  405. IF( ILCPLX ) THEN
  406. ILCPLX = .FALSE.
  407. GO TO 10
  408. END IF
  409. IF( J.LT.N ) THEN
  410. IF( S( J+1, J ).NE.ZERO )
  411. $ ILCPLX = .TRUE.
  412. END IF
  413. IF( ILCPLX ) THEN
  414. IF( SELECT( J ) .OR. SELECT( J+1 ) )
  415. $ IM = IM + 2
  416. ELSE
  417. IF( SELECT( J ) )
  418. $ IM = IM + 1
  419. END IF
  420. 10 CONTINUE
  421. ELSE
  422. IM = N
  423. END IF
  424. *
  425. * Check 2-by-2 diagonal blocks of A, B
  426. *
  427. ILABAD = .FALSE.
  428. ILBBAD = .FALSE.
  429. DO 20 J = 1, N - 1
  430. IF( S( J+1, J ).NE.ZERO ) THEN
  431. IF( P( J, J ).EQ.ZERO .OR. P( J+1, J+1 ).EQ.ZERO .OR.
  432. $ P( J, J+1 ).NE.ZERO )ILBBAD = .TRUE.
  433. IF( J.LT.N-1 ) THEN
  434. IF( S( J+2, J+1 ).NE.ZERO )
  435. $ ILABAD = .TRUE.
  436. END IF
  437. END IF
  438. 20 CONTINUE
  439. *
  440. IF( ILABAD ) THEN
  441. INFO = -5
  442. ELSE IF( ILBBAD ) THEN
  443. INFO = -7
  444. ELSE IF( COMPL .AND. LDVL.LT.N .OR. LDVL.LT.1 ) THEN
  445. INFO = -10
  446. ELSE IF( COMPR .AND. LDVR.LT.N .OR. LDVR.LT.1 ) THEN
  447. INFO = -12
  448. ELSE IF( MM.LT.IM ) THEN
  449. INFO = -13
  450. END IF
  451. IF( INFO.NE.0 ) THEN
  452. CALL XERBLA( 'DTGEVC', -INFO )
  453. RETURN
  454. END IF
  455. *
  456. * Quick return if possible
  457. *
  458. M = IM
  459. IF( N.EQ.0 )
  460. $ RETURN
  461. *
  462. * Machine Constants
  463. *
  464. SAFMIN = DLAMCH( 'Safe minimum' )
  465. BIG = ONE / SAFMIN
  466. ULP = DLAMCH( 'Epsilon' )*DLAMCH( 'Base' )
  467. SMALL = SAFMIN*N / ULP
  468. BIG = ONE / SMALL
  469. BIGNUM = ONE / ( SAFMIN*N )
  470. *
  471. * Compute the 1-norm of each column of the strictly upper triangular
  472. * part (i.e., excluding all elements belonging to the diagonal
  473. * blocks) of A and B to check for possible overflow in the
  474. * triangular solver.
  475. *
  476. ANORM = ABS( S( 1, 1 ) )
  477. IF( N.GT.1 )
  478. $ ANORM = ANORM + ABS( S( 2, 1 ) )
  479. BNORM = ABS( P( 1, 1 ) )
  480. WORK( 1 ) = ZERO
  481. WORK( N+1 ) = ZERO
  482. *
  483. DO 50 J = 2, N
  484. TEMP = ZERO
  485. TEMP2 = ZERO
  486. IF( S( J, J-1 ).EQ.ZERO ) THEN
  487. IEND = J - 1
  488. ELSE
  489. IEND = J - 2
  490. END IF
  491. DO 30 I = 1, IEND
  492. TEMP = TEMP + ABS( S( I, J ) )
  493. TEMP2 = TEMP2 + ABS( P( I, J ) )
  494. 30 CONTINUE
  495. WORK( J ) = TEMP
  496. WORK( N+J ) = TEMP2
  497. DO 40 I = IEND + 1, MIN( J+1, N )
  498. TEMP = TEMP + ABS( S( I, J ) )
  499. TEMP2 = TEMP2 + ABS( P( I, J ) )
  500. 40 CONTINUE
  501. ANORM = MAX( ANORM, TEMP )
  502. BNORM = MAX( BNORM, TEMP2 )
  503. 50 CONTINUE
  504. *
  505. ASCALE = ONE / MAX( ANORM, SAFMIN )
  506. BSCALE = ONE / MAX( BNORM, SAFMIN )
  507. *
  508. * Left eigenvectors
  509. *
  510. IF( COMPL ) THEN
  511. IEIG = 0
  512. *
  513. * Main loop over eigenvalues
  514. *
  515. ILCPLX = .FALSE.
  516. DO 220 JE = 1, N
  517. *
  518. * Skip this iteration if (a) HOWMNY='S' and SELECT=.FALSE., or
  519. * (b) this would be the second of a complex pair.
  520. * Check for complex eigenvalue, so as to be sure of which
  521. * entry(-ies) of SELECT to look at.
  522. *
  523. IF( ILCPLX ) THEN
  524. ILCPLX = .FALSE.
  525. GO TO 220
  526. END IF
  527. NW = 1
  528. IF( JE.LT.N ) THEN
  529. IF( S( JE+1, JE ).NE.ZERO ) THEN
  530. ILCPLX = .TRUE.
  531. NW = 2
  532. END IF
  533. END IF
  534. IF( ILALL ) THEN
  535. ILCOMP = .TRUE.
  536. ELSE IF( ILCPLX ) THEN
  537. ILCOMP = SELECT( JE ) .OR. SELECT( JE+1 )
  538. ELSE
  539. ILCOMP = SELECT( JE )
  540. END IF
  541. IF( .NOT.ILCOMP )
  542. $ GO TO 220
  543. *
  544. * Decide if (a) singular pencil, (b) real eigenvalue, or
  545. * (c) complex eigenvalue.
  546. *
  547. IF( .NOT.ILCPLX ) THEN
  548. IF( ABS( S( JE, JE ) ).LE.SAFMIN .AND.
  549. $ ABS( P( JE, JE ) ).LE.SAFMIN ) THEN
  550. *
  551. * Singular matrix pencil -- return unit eigenvector
  552. *
  553. IEIG = IEIG + 1
  554. DO 60 JR = 1, N
  555. VL( JR, IEIG ) = ZERO
  556. 60 CONTINUE
  557. VL( IEIG, IEIG ) = ONE
  558. GO TO 220
  559. END IF
  560. END IF
  561. *
  562. * Clear vector
  563. *
  564. DO 70 JR = 1, NW*N
  565. WORK( 2*N+JR ) = ZERO
  566. 70 CONTINUE
  567. * T
  568. * Compute coefficients in ( a A - b B ) y = 0
  569. * a is ACOEF
  570. * b is BCOEFR + i*BCOEFI
  571. *
  572. IF( .NOT.ILCPLX ) THEN
  573. *
  574. * Real eigenvalue
  575. *
  576. TEMP = ONE / MAX( ABS( S( JE, JE ) )*ASCALE,
  577. $ ABS( P( JE, JE ) )*BSCALE, SAFMIN )
  578. SALFAR = ( TEMP*S( JE, JE ) )*ASCALE
  579. SBETA = ( TEMP*P( JE, JE ) )*BSCALE
  580. ACOEF = SBETA*ASCALE
  581. BCOEFR = SALFAR*BSCALE
  582. BCOEFI = ZERO
  583. *
  584. * Scale to avoid underflow
  585. *
  586. SCALE = ONE
  587. LSA = ABS( SBETA ).GE.SAFMIN .AND. ABS( ACOEF ).LT.SMALL
  588. LSB = ABS( SALFAR ).GE.SAFMIN .AND. ABS( BCOEFR ).LT.
  589. $ SMALL
  590. IF( LSA )
  591. $ SCALE = ( SMALL / ABS( SBETA ) )*MIN( ANORM, BIG )
  592. IF( LSB )
  593. $ SCALE = MAX( SCALE, ( SMALL / ABS( SALFAR ) )*
  594. $ MIN( BNORM, BIG ) )
  595. IF( LSA .OR. LSB ) THEN
  596. SCALE = MIN( SCALE, ONE /
  597. $ ( SAFMIN*MAX( ONE, ABS( ACOEF ),
  598. $ ABS( BCOEFR ) ) ) )
  599. IF( LSA ) THEN
  600. ACOEF = ASCALE*( SCALE*SBETA )
  601. ELSE
  602. ACOEF = SCALE*ACOEF
  603. END IF
  604. IF( LSB ) THEN
  605. BCOEFR = BSCALE*( SCALE*SALFAR )
  606. ELSE
  607. BCOEFR = SCALE*BCOEFR
  608. END IF
  609. END IF
  610. ACOEFA = ABS( ACOEF )
  611. BCOEFA = ABS( BCOEFR )
  612. *
  613. * First component is 1
  614. *
  615. WORK( 2*N+JE ) = ONE
  616. XMAX = ONE
  617. ELSE
  618. *
  619. * Complex eigenvalue
  620. *
  621. CALL DLAG2( S( JE, JE ), LDS, P( JE, JE ), LDP,
  622. $ SAFMIN*SAFETY, ACOEF, TEMP, BCOEFR, TEMP2,
  623. $ BCOEFI )
  624. BCOEFI = -BCOEFI
  625. IF( BCOEFI.EQ.ZERO ) THEN
  626. INFO = JE
  627. RETURN
  628. END IF
  629. *
  630. * Scale to avoid over/underflow
  631. *
  632. ACOEFA = ABS( ACOEF )
  633. BCOEFA = ABS( BCOEFR ) + ABS( BCOEFI )
  634. SCALE = ONE
  635. IF( ACOEFA*ULP.LT.SAFMIN .AND. ACOEFA.GE.SAFMIN )
  636. $ SCALE = ( SAFMIN / ULP ) / ACOEFA
  637. IF( BCOEFA*ULP.LT.SAFMIN .AND. BCOEFA.GE.SAFMIN )
  638. $ SCALE = MAX( SCALE, ( SAFMIN / ULP ) / BCOEFA )
  639. IF( SAFMIN*ACOEFA.GT.ASCALE )
  640. $ SCALE = ASCALE / ( SAFMIN*ACOEFA )
  641. IF( SAFMIN*BCOEFA.GT.BSCALE )
  642. $ SCALE = MIN( SCALE, BSCALE / ( SAFMIN*BCOEFA ) )
  643. IF( SCALE.NE.ONE ) THEN
  644. ACOEF = SCALE*ACOEF
  645. ACOEFA = ABS( ACOEF )
  646. BCOEFR = SCALE*BCOEFR
  647. BCOEFI = SCALE*BCOEFI
  648. BCOEFA = ABS( BCOEFR ) + ABS( BCOEFI )
  649. END IF
  650. *
  651. * Compute first two components of eigenvector
  652. *
  653. TEMP = ACOEF*S( JE+1, JE )
  654. TEMP2R = ACOEF*S( JE, JE ) - BCOEFR*P( JE, JE )
  655. TEMP2I = -BCOEFI*P( JE, JE )
  656. IF( ABS( TEMP ).GT.ABS( TEMP2R )+ABS( TEMP2I ) ) THEN
  657. WORK( 2*N+JE ) = ONE
  658. WORK( 3*N+JE ) = ZERO
  659. WORK( 2*N+JE+1 ) = -TEMP2R / TEMP
  660. WORK( 3*N+JE+1 ) = -TEMP2I / TEMP
  661. ELSE
  662. WORK( 2*N+JE+1 ) = ONE
  663. WORK( 3*N+JE+1 ) = ZERO
  664. TEMP = ACOEF*S( JE, JE+1 )
  665. WORK( 2*N+JE ) = ( BCOEFR*P( JE+1, JE+1 )-ACOEF*
  666. $ S( JE+1, JE+1 ) ) / TEMP
  667. WORK( 3*N+JE ) = BCOEFI*P( JE+1, JE+1 ) / TEMP
  668. END IF
  669. XMAX = MAX( ABS( WORK( 2*N+JE ) )+ABS( WORK( 3*N+JE ) ),
  670. $ ABS( WORK( 2*N+JE+1 ) )+ABS( WORK( 3*N+JE+1 ) ) )
  671. END IF
  672. *
  673. DMIN = MAX( ULP*ACOEFA*ANORM, ULP*BCOEFA*BNORM, SAFMIN )
  674. *
  675. * T
  676. * Triangular solve of (a A - b B) y = 0
  677. *
  678. * T
  679. * (rowwise in (a A - b B) , or columnwise in (a A - b B) )
  680. *
  681. IL2BY2 = .FALSE.
  682. *
  683. DO 160 J = JE + NW, N
  684. IF( IL2BY2 ) THEN
  685. IL2BY2 = .FALSE.
  686. GO TO 160
  687. END IF
  688. *
  689. NA = 1
  690. BDIAG( 1 ) = P( J, J )
  691. IF( J.LT.N ) THEN
  692. IF( S( J+1, J ).NE.ZERO ) THEN
  693. IL2BY2 = .TRUE.
  694. BDIAG( 2 ) = P( J+1, J+1 )
  695. NA = 2
  696. END IF
  697. END IF
  698. *
  699. * Check whether scaling is necessary for dot products
  700. *
  701. XSCALE = ONE / MAX( ONE, XMAX )
  702. TEMP = MAX( WORK( J ), WORK( N+J ),
  703. $ ACOEFA*WORK( J )+BCOEFA*WORK( N+J ) )
  704. IF( IL2BY2 )
  705. $ TEMP = MAX( TEMP, WORK( J+1 ), WORK( N+J+1 ),
  706. $ ACOEFA*WORK( J+1 )+BCOEFA*WORK( N+J+1 ) )
  707. IF( TEMP.GT.BIGNUM*XSCALE ) THEN
  708. DO 90 JW = 0, NW - 1
  709. DO 80 JR = JE, J - 1
  710. WORK( ( JW+2 )*N+JR ) = XSCALE*
  711. $ WORK( ( JW+2 )*N+JR )
  712. 80 CONTINUE
  713. 90 CONTINUE
  714. XMAX = XMAX*XSCALE
  715. END IF
  716. *
  717. * Compute dot products
  718. *
  719. * j-1
  720. * SUM = sum conjg( a*S(k,j) - b*P(k,j) )*x(k)
  721. * k=je
  722. *
  723. * To reduce the op count, this is done as
  724. *
  725. * _ j-1 _ j-1
  726. * a*conjg( sum S(k,j)*x(k) ) - b*conjg( sum P(k,j)*x(k) )
  727. * k=je k=je
  728. *
  729. * which may cause underflow problems if A or B are close
  730. * to underflow. (E.g., less than SMALL.)
  731. *
  732. *
  733. DO 120 JW = 1, NW
  734. DO 110 JA = 1, NA
  735. SUMS( JA, JW ) = ZERO
  736. SUMP( JA, JW ) = ZERO
  737. *
  738. DO 100 JR = JE, J - 1
  739. SUMS( JA, JW ) = SUMS( JA, JW ) +
  740. $ S( JR, J+JA-1 )*
  741. $ WORK( ( JW+1 )*N+JR )
  742. SUMP( JA, JW ) = SUMP( JA, JW ) +
  743. $ P( JR, J+JA-1 )*
  744. $ WORK( ( JW+1 )*N+JR )
  745. 100 CONTINUE
  746. 110 CONTINUE
  747. 120 CONTINUE
  748. *
  749. DO 130 JA = 1, NA
  750. IF( ILCPLX ) THEN
  751. SUM( JA, 1 ) = -ACOEF*SUMS( JA, 1 ) +
  752. $ BCOEFR*SUMP( JA, 1 ) -
  753. $ BCOEFI*SUMP( JA, 2 )
  754. SUM( JA, 2 ) = -ACOEF*SUMS( JA, 2 ) +
  755. $ BCOEFR*SUMP( JA, 2 ) +
  756. $ BCOEFI*SUMP( JA, 1 )
  757. ELSE
  758. SUM( JA, 1 ) = -ACOEF*SUMS( JA, 1 ) +
  759. $ BCOEFR*SUMP( JA, 1 )
  760. END IF
  761. 130 CONTINUE
  762. *
  763. * T
  764. * Solve ( a A - b B ) y = SUM(,)
  765. * with scaling and perturbation of the denominator
  766. *
  767. CALL DLALN2( .TRUE., NA, NW, DMIN, ACOEF, S( J, J ), LDS,
  768. $ BDIAG( 1 ), BDIAG( 2 ), SUM, 2, BCOEFR,
  769. $ BCOEFI, WORK( 2*N+J ), N, SCALE, TEMP,
  770. $ IINFO )
  771. IF( SCALE.LT.ONE ) THEN
  772. DO 150 JW = 0, NW - 1
  773. DO 140 JR = JE, J - 1
  774. WORK( ( JW+2 )*N+JR ) = SCALE*
  775. $ WORK( ( JW+2 )*N+JR )
  776. 140 CONTINUE
  777. 150 CONTINUE
  778. XMAX = SCALE*XMAX
  779. END IF
  780. XMAX = MAX( XMAX, TEMP )
  781. 160 CONTINUE
  782. *
  783. * Copy eigenvector to VL, back transforming if
  784. * HOWMNY='B'.
  785. *
  786. IEIG = IEIG + 1
  787. IF( ILBACK ) THEN
  788. DO 170 JW = 0, NW - 1
  789. CALL DGEMV( 'N', N, N+1-JE, ONE, VL( 1, JE ), LDVL,
  790. $ WORK( ( JW+2 )*N+JE ), 1, ZERO,
  791. $ WORK( ( JW+4 )*N+1 ), 1 )
  792. 170 CONTINUE
  793. CALL DLACPY( ' ', N, NW, WORK( 4*N+1 ), N, VL( 1, JE ),
  794. $ LDVL )
  795. IBEG = 1
  796. ELSE
  797. CALL DLACPY( ' ', N, NW, WORK( 2*N+1 ), N, VL( 1, IEIG ),
  798. $ LDVL )
  799. IBEG = JE
  800. END IF
  801. *
  802. * Scale eigenvector
  803. *
  804. XMAX = ZERO
  805. IF( ILCPLX ) THEN
  806. DO 180 J = IBEG, N
  807. XMAX = MAX( XMAX, ABS( VL( J, IEIG ) )+
  808. $ ABS( VL( J, IEIG+1 ) ) )
  809. 180 CONTINUE
  810. ELSE
  811. DO 190 J = IBEG, N
  812. XMAX = MAX( XMAX, ABS( VL( J, IEIG ) ) )
  813. 190 CONTINUE
  814. END IF
  815. *
  816. IF( XMAX.GT.SAFMIN ) THEN
  817. XSCALE = ONE / XMAX
  818. *
  819. DO 210 JW = 0, NW - 1
  820. DO 200 JR = IBEG, N
  821. VL( JR, IEIG+JW ) = XSCALE*VL( JR, IEIG+JW )
  822. 200 CONTINUE
  823. 210 CONTINUE
  824. END IF
  825. IEIG = IEIG + NW - 1
  826. *
  827. 220 CONTINUE
  828. END IF
  829. *
  830. * Right eigenvectors
  831. *
  832. IF( COMPR ) THEN
  833. IEIG = IM + 1
  834. *
  835. * Main loop over eigenvalues
  836. *
  837. ILCPLX = .FALSE.
  838. DO 500 JE = N, 1, -1
  839. *
  840. * Skip this iteration if (a) HOWMNY='S' and SELECT=.FALSE., or
  841. * (b) this would be the second of a complex pair.
  842. * Check for complex eigenvalue, so as to be sure of which
  843. * entry(-ies) of SELECT to look at -- if complex, SELECT(JE)
  844. * or SELECT(JE-1).
  845. * If this is a complex pair, the 2-by-2 diagonal block
  846. * corresponding to the eigenvalue is in rows/columns JE-1:JE
  847. *
  848. IF( ILCPLX ) THEN
  849. ILCPLX = .FALSE.
  850. GO TO 500
  851. END IF
  852. NW = 1
  853. IF( JE.GT.1 ) THEN
  854. IF( S( JE, JE-1 ).NE.ZERO ) THEN
  855. ILCPLX = .TRUE.
  856. NW = 2
  857. END IF
  858. END IF
  859. IF( ILALL ) THEN
  860. ILCOMP = .TRUE.
  861. ELSE IF( ILCPLX ) THEN
  862. ILCOMP = SELECT( JE ) .OR. SELECT( JE-1 )
  863. ELSE
  864. ILCOMP = SELECT( JE )
  865. END IF
  866. IF( .NOT.ILCOMP )
  867. $ GO TO 500
  868. *
  869. * Decide if (a) singular pencil, (b) real eigenvalue, or
  870. * (c) complex eigenvalue.
  871. *
  872. IF( .NOT.ILCPLX ) THEN
  873. IF( ABS( S( JE, JE ) ).LE.SAFMIN .AND.
  874. $ ABS( P( JE, JE ) ).LE.SAFMIN ) THEN
  875. *
  876. * Singular matrix pencil -- unit eigenvector
  877. *
  878. IEIG = IEIG - 1
  879. DO 230 JR = 1, N
  880. VR( JR, IEIG ) = ZERO
  881. 230 CONTINUE
  882. VR( IEIG, IEIG ) = ONE
  883. GO TO 500
  884. END IF
  885. END IF
  886. *
  887. * Clear vector
  888. *
  889. DO 250 JW = 0, NW - 1
  890. DO 240 JR = 1, N
  891. WORK( ( JW+2 )*N+JR ) = ZERO
  892. 240 CONTINUE
  893. 250 CONTINUE
  894. *
  895. * Compute coefficients in ( a A - b B ) x = 0
  896. * a is ACOEF
  897. * b is BCOEFR + i*BCOEFI
  898. *
  899. IF( .NOT.ILCPLX ) THEN
  900. *
  901. * Real eigenvalue
  902. *
  903. TEMP = ONE / MAX( ABS( S( JE, JE ) )*ASCALE,
  904. $ ABS( P( JE, JE ) )*BSCALE, SAFMIN )
  905. SALFAR = ( TEMP*S( JE, JE ) )*ASCALE
  906. SBETA = ( TEMP*P( JE, JE ) )*BSCALE
  907. ACOEF = SBETA*ASCALE
  908. BCOEFR = SALFAR*BSCALE
  909. BCOEFI = ZERO
  910. *
  911. * Scale to avoid underflow
  912. *
  913. SCALE = ONE
  914. LSA = ABS( SBETA ).GE.SAFMIN .AND. ABS( ACOEF ).LT.SMALL
  915. LSB = ABS( SALFAR ).GE.SAFMIN .AND. ABS( BCOEFR ).LT.
  916. $ SMALL
  917. IF( LSA )
  918. $ SCALE = ( SMALL / ABS( SBETA ) )*MIN( ANORM, BIG )
  919. IF( LSB )
  920. $ SCALE = MAX( SCALE, ( SMALL / ABS( SALFAR ) )*
  921. $ MIN( BNORM, BIG ) )
  922. IF( LSA .OR. LSB ) THEN
  923. SCALE = MIN( SCALE, ONE /
  924. $ ( SAFMIN*MAX( ONE, ABS( ACOEF ),
  925. $ ABS( BCOEFR ) ) ) )
  926. IF( LSA ) THEN
  927. ACOEF = ASCALE*( SCALE*SBETA )
  928. ELSE
  929. ACOEF = SCALE*ACOEF
  930. END IF
  931. IF( LSB ) THEN
  932. BCOEFR = BSCALE*( SCALE*SALFAR )
  933. ELSE
  934. BCOEFR = SCALE*BCOEFR
  935. END IF
  936. END IF
  937. ACOEFA = ABS( ACOEF )
  938. BCOEFA = ABS( BCOEFR )
  939. *
  940. * First component is 1
  941. *
  942. WORK( 2*N+JE ) = ONE
  943. XMAX = ONE
  944. *
  945. * Compute contribution from column JE of A and B to sum
  946. * (See "Further Details", above.)
  947. *
  948. DO 260 JR = 1, JE - 1
  949. WORK( 2*N+JR ) = BCOEFR*P( JR, JE ) -
  950. $ ACOEF*S( JR, JE )
  951. 260 CONTINUE
  952. ELSE
  953. *
  954. * Complex eigenvalue
  955. *
  956. CALL DLAG2( S( JE-1, JE-1 ), LDS, P( JE-1, JE-1 ), LDP,
  957. $ SAFMIN*SAFETY, ACOEF, TEMP, BCOEFR, TEMP2,
  958. $ BCOEFI )
  959. IF( BCOEFI.EQ.ZERO ) THEN
  960. INFO = JE - 1
  961. RETURN
  962. END IF
  963. *
  964. * Scale to avoid over/underflow
  965. *
  966. ACOEFA = ABS( ACOEF )
  967. BCOEFA = ABS( BCOEFR ) + ABS( BCOEFI )
  968. SCALE = ONE
  969. IF( ACOEFA*ULP.LT.SAFMIN .AND. ACOEFA.GE.SAFMIN )
  970. $ SCALE = ( SAFMIN / ULP ) / ACOEFA
  971. IF( BCOEFA*ULP.LT.SAFMIN .AND. BCOEFA.GE.SAFMIN )
  972. $ SCALE = MAX( SCALE, ( SAFMIN / ULP ) / BCOEFA )
  973. IF( SAFMIN*ACOEFA.GT.ASCALE )
  974. $ SCALE = ASCALE / ( SAFMIN*ACOEFA )
  975. IF( SAFMIN*BCOEFA.GT.BSCALE )
  976. $ SCALE = MIN( SCALE, BSCALE / ( SAFMIN*BCOEFA ) )
  977. IF( SCALE.NE.ONE ) THEN
  978. ACOEF = SCALE*ACOEF
  979. ACOEFA = ABS( ACOEF )
  980. BCOEFR = SCALE*BCOEFR
  981. BCOEFI = SCALE*BCOEFI
  982. BCOEFA = ABS( BCOEFR ) + ABS( BCOEFI )
  983. END IF
  984. *
  985. * Compute first two components of eigenvector
  986. * and contribution to sums
  987. *
  988. TEMP = ACOEF*S( JE, JE-1 )
  989. TEMP2R = ACOEF*S( JE, JE ) - BCOEFR*P( JE, JE )
  990. TEMP2I = -BCOEFI*P( JE, JE )
  991. IF( ABS( TEMP ).GE.ABS( TEMP2R )+ABS( TEMP2I ) ) THEN
  992. WORK( 2*N+JE ) = ONE
  993. WORK( 3*N+JE ) = ZERO
  994. WORK( 2*N+JE-1 ) = -TEMP2R / TEMP
  995. WORK( 3*N+JE-1 ) = -TEMP2I / TEMP
  996. ELSE
  997. WORK( 2*N+JE-1 ) = ONE
  998. WORK( 3*N+JE-1 ) = ZERO
  999. TEMP = ACOEF*S( JE-1, JE )
  1000. WORK( 2*N+JE ) = ( BCOEFR*P( JE-1, JE-1 )-ACOEF*
  1001. $ S( JE-1, JE-1 ) ) / TEMP
  1002. WORK( 3*N+JE ) = BCOEFI*P( JE-1, JE-1 ) / TEMP
  1003. END IF
  1004. *
  1005. XMAX = MAX( ABS( WORK( 2*N+JE ) )+ABS( WORK( 3*N+JE ) ),
  1006. $ ABS( WORK( 2*N+JE-1 ) )+ABS( WORK( 3*N+JE-1 ) ) )
  1007. *
  1008. * Compute contribution from columns JE and JE-1
  1009. * of A and B to the sums.
  1010. *
  1011. CREALA = ACOEF*WORK( 2*N+JE-1 )
  1012. CIMAGA = ACOEF*WORK( 3*N+JE-1 )
  1013. CREALB = BCOEFR*WORK( 2*N+JE-1 ) -
  1014. $ BCOEFI*WORK( 3*N+JE-1 )
  1015. CIMAGB = BCOEFI*WORK( 2*N+JE-1 ) +
  1016. $ BCOEFR*WORK( 3*N+JE-1 )
  1017. CRE2A = ACOEF*WORK( 2*N+JE )
  1018. CIM2A = ACOEF*WORK( 3*N+JE )
  1019. CRE2B = BCOEFR*WORK( 2*N+JE ) - BCOEFI*WORK( 3*N+JE )
  1020. CIM2B = BCOEFI*WORK( 2*N+JE ) + BCOEFR*WORK( 3*N+JE )
  1021. DO 270 JR = 1, JE - 2
  1022. WORK( 2*N+JR ) = -CREALA*S( JR, JE-1 ) +
  1023. $ CREALB*P( JR, JE-1 ) -
  1024. $ CRE2A*S( JR, JE ) + CRE2B*P( JR, JE )
  1025. WORK( 3*N+JR ) = -CIMAGA*S( JR, JE-1 ) +
  1026. $ CIMAGB*P( JR, JE-1 ) -
  1027. $ CIM2A*S( JR, JE ) + CIM2B*P( JR, JE )
  1028. 270 CONTINUE
  1029. END IF
  1030. *
  1031. DMIN = MAX( ULP*ACOEFA*ANORM, ULP*BCOEFA*BNORM, SAFMIN )
  1032. *
  1033. * Columnwise triangular solve of (a A - b B) x = 0
  1034. *
  1035. IL2BY2 = .FALSE.
  1036. DO 370 J = JE - NW, 1, -1
  1037. *
  1038. * If a 2-by-2 block, is in position j-1:j, wait until
  1039. * next iteration to process it (when it will be j:j+1)
  1040. *
  1041. IF( .NOT.IL2BY2 .AND. J.GT.1 ) THEN
  1042. IF( S( J, J-1 ).NE.ZERO ) THEN
  1043. IL2BY2 = .TRUE.
  1044. GO TO 370
  1045. END IF
  1046. END IF
  1047. BDIAG( 1 ) = P( J, J )
  1048. IF( IL2BY2 ) THEN
  1049. NA = 2
  1050. BDIAG( 2 ) = P( J+1, J+1 )
  1051. ELSE
  1052. NA = 1
  1053. END IF
  1054. *
  1055. * Compute x(j) (and x(j+1), if 2-by-2 block)
  1056. *
  1057. CALL DLALN2( .FALSE., NA, NW, DMIN, ACOEF, S( J, J ),
  1058. $ LDS, BDIAG( 1 ), BDIAG( 2 ), WORK( 2*N+J ),
  1059. $ N, BCOEFR, BCOEFI, SUM, 2, SCALE, TEMP,
  1060. $ IINFO )
  1061. IF( SCALE.LT.ONE ) THEN
  1062. *
  1063. DO 290 JW = 0, NW - 1
  1064. DO 280 JR = 1, JE
  1065. WORK( ( JW+2 )*N+JR ) = SCALE*
  1066. $ WORK( ( JW+2 )*N+JR )
  1067. 280 CONTINUE
  1068. 290 CONTINUE
  1069. END IF
  1070. XMAX = MAX( SCALE*XMAX, TEMP )
  1071. *
  1072. DO 310 JW = 1, NW
  1073. DO 300 JA = 1, NA
  1074. WORK( ( JW+1 )*N+J+JA-1 ) = SUM( JA, JW )
  1075. 300 CONTINUE
  1076. 310 CONTINUE
  1077. *
  1078. * w = w + x(j)*(a S(*,j) - b P(*,j) ) with scaling
  1079. *
  1080. IF( J.GT.1 ) THEN
  1081. *
  1082. * Check whether scaling is necessary for sum.
  1083. *
  1084. XSCALE = ONE / MAX( ONE, XMAX )
  1085. TEMP = ACOEFA*WORK( J ) + BCOEFA*WORK( N+J )
  1086. IF( IL2BY2 )
  1087. $ TEMP = MAX( TEMP, ACOEFA*WORK( J+1 )+BCOEFA*
  1088. $ WORK( N+J+1 ) )
  1089. TEMP = MAX( TEMP, ACOEFA, BCOEFA )
  1090. IF( TEMP.GT.BIGNUM*XSCALE ) THEN
  1091. *
  1092. DO 330 JW = 0, NW - 1
  1093. DO 320 JR = 1, JE
  1094. WORK( ( JW+2 )*N+JR ) = XSCALE*
  1095. $ WORK( ( JW+2 )*N+JR )
  1096. 320 CONTINUE
  1097. 330 CONTINUE
  1098. XMAX = XMAX*XSCALE
  1099. END IF
  1100. *
  1101. * Compute the contributions of the off-diagonals of
  1102. * column j (and j+1, if 2-by-2 block) of A and B to the
  1103. * sums.
  1104. *
  1105. *
  1106. DO 360 JA = 1, NA
  1107. IF( ILCPLX ) THEN
  1108. CREALA = ACOEF*WORK( 2*N+J+JA-1 )
  1109. CIMAGA = ACOEF*WORK( 3*N+J+JA-1 )
  1110. CREALB = BCOEFR*WORK( 2*N+J+JA-1 ) -
  1111. $ BCOEFI*WORK( 3*N+J+JA-1 )
  1112. CIMAGB = BCOEFI*WORK( 2*N+J+JA-1 ) +
  1113. $ BCOEFR*WORK( 3*N+J+JA-1 )
  1114. DO 340 JR = 1, J - 1
  1115. WORK( 2*N+JR ) = WORK( 2*N+JR ) -
  1116. $ CREALA*S( JR, J+JA-1 ) +
  1117. $ CREALB*P( JR, J+JA-1 )
  1118. WORK( 3*N+JR ) = WORK( 3*N+JR ) -
  1119. $ CIMAGA*S( JR, J+JA-1 ) +
  1120. $ CIMAGB*P( JR, J+JA-1 )
  1121. 340 CONTINUE
  1122. ELSE
  1123. CREALA = ACOEF*WORK( 2*N+J+JA-1 )
  1124. CREALB = BCOEFR*WORK( 2*N+J+JA-1 )
  1125. DO 350 JR = 1, J - 1
  1126. WORK( 2*N+JR ) = WORK( 2*N+JR ) -
  1127. $ CREALA*S( JR, J+JA-1 ) +
  1128. $ CREALB*P( JR, J+JA-1 )
  1129. 350 CONTINUE
  1130. END IF
  1131. 360 CONTINUE
  1132. END IF
  1133. *
  1134. IL2BY2 = .FALSE.
  1135. 370 CONTINUE
  1136. *
  1137. * Copy eigenvector to VR, back transforming if
  1138. * HOWMNY='B'.
  1139. *
  1140. IEIG = IEIG - NW
  1141. IF( ILBACK ) THEN
  1142. *
  1143. DO 410 JW = 0, NW - 1
  1144. DO 380 JR = 1, N
  1145. WORK( ( JW+4 )*N+JR ) = WORK( ( JW+2 )*N+1 )*
  1146. $ VR( JR, 1 )
  1147. 380 CONTINUE
  1148. *
  1149. * A series of compiler directives to defeat
  1150. * vectorization for the next loop
  1151. *
  1152. *
  1153. DO 400 JC = 2, JE
  1154. DO 390 JR = 1, N
  1155. WORK( ( JW+4 )*N+JR ) = WORK( ( JW+4 )*N+JR ) +
  1156. $ WORK( ( JW+2 )*N+JC )*VR( JR, JC )
  1157. 390 CONTINUE
  1158. 400 CONTINUE
  1159. 410 CONTINUE
  1160. *
  1161. DO 430 JW = 0, NW - 1
  1162. DO 420 JR = 1, N
  1163. VR( JR, IEIG+JW ) = WORK( ( JW+4 )*N+JR )
  1164. 420 CONTINUE
  1165. 430 CONTINUE
  1166. *
  1167. IEND = N
  1168. ELSE
  1169. DO 450 JW = 0, NW - 1
  1170. DO 440 JR = 1, N
  1171. VR( JR, IEIG+JW ) = WORK( ( JW+2 )*N+JR )
  1172. 440 CONTINUE
  1173. 450 CONTINUE
  1174. *
  1175. IEND = JE
  1176. END IF
  1177. *
  1178. * Scale eigenvector
  1179. *
  1180. XMAX = ZERO
  1181. IF( ILCPLX ) THEN
  1182. DO 460 J = 1, IEND
  1183. XMAX = MAX( XMAX, ABS( VR( J, IEIG ) )+
  1184. $ ABS( VR( J, IEIG+1 ) ) )
  1185. 460 CONTINUE
  1186. ELSE
  1187. DO 470 J = 1, IEND
  1188. XMAX = MAX( XMAX, ABS( VR( J, IEIG ) ) )
  1189. 470 CONTINUE
  1190. END IF
  1191. *
  1192. IF( XMAX.GT.SAFMIN ) THEN
  1193. XSCALE = ONE / XMAX
  1194. DO 490 JW = 0, NW - 1
  1195. DO 480 JR = 1, IEND
  1196. VR( JR, IEIG+JW ) = XSCALE*VR( JR, IEIG+JW )
  1197. 480 CONTINUE
  1198. 490 CONTINUE
  1199. END IF
  1200. 500 CONTINUE
  1201. END IF
  1202. *
  1203. RETURN
  1204. *
  1205. * End of DTGEVC
  1206. *
  1207. END