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.

dhgeqz.f 46 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372
  1. *> \brief \b DHGEQZ
  2. *
  3. * =========== DOCUMENTATION ===========
  4. *
  5. * Online html documentation available at
  6. * http://www.netlib.org/lapack/explore-html/
  7. *
  8. *> \htmlonly
  9. *> Download DHGEQZ + dependencies
  10. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dhgeqz.f">
  11. *> [TGZ]</a>
  12. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dhgeqz.f">
  13. *> [ZIP]</a>
  14. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dhgeqz.f">
  15. *> [TXT]</a>
  16. *> \endhtmlonly
  17. *
  18. * Definition:
  19. * ===========
  20. *
  21. * SUBROUTINE DHGEQZ( JOB, COMPQ, COMPZ, N, ILO, IHI, H, LDH, T, LDT,
  22. * ALPHAR, ALPHAI, BETA, Q, LDQ, Z, LDZ, WORK,
  23. * LWORK, INFO )
  24. *
  25. * .. Scalar Arguments ..
  26. * CHARACTER COMPQ, COMPZ, JOB
  27. * INTEGER IHI, ILO, INFO, LDH, LDQ, LDT, LDZ, LWORK, N
  28. * ..
  29. * .. Array Arguments ..
  30. * DOUBLE PRECISION ALPHAI( * ), ALPHAR( * ), BETA( * ),
  31. * $ H( LDH, * ), Q( LDQ, * ), T( LDT, * ),
  32. * $ WORK( * ), Z( LDZ, * )
  33. * ..
  34. *
  35. *
  36. *> \par Purpose:
  37. * =============
  38. *>
  39. *> \verbatim
  40. *>
  41. *> DHGEQZ computes the eigenvalues of a real matrix pair (H,T),
  42. *> where H is an upper Hessenberg matrix and T is upper triangular,
  43. *> using the double-shift QZ method.
  44. *> Matrix pairs of this type are produced by the reduction to
  45. *> generalized upper Hessenberg form of a real matrix pair (A,B):
  46. *>
  47. *> A = Q1*H*Z1**T, B = Q1*T*Z1**T,
  48. *>
  49. *> as computed by DGGHRD.
  50. *>
  51. *> If JOB='S', then the Hessenberg-triangular pair (H,T) is
  52. *> also reduced to generalized Schur form,
  53. *>
  54. *> H = Q*S*Z**T, T = Q*P*Z**T,
  55. *>
  56. *> where Q and Z are orthogonal matrices, P is an upper triangular
  57. *> matrix, and S is a quasi-triangular matrix with 1-by-1 and 2-by-2
  58. *> diagonal blocks.
  59. *>
  60. *> The 1-by-1 blocks correspond to real eigenvalues of the matrix pair
  61. *> (H,T) and the 2-by-2 blocks correspond to complex conjugate pairs of
  62. *> eigenvalues.
  63. *>
  64. *> Additionally, the 2-by-2 upper triangular diagonal blocks of P
  65. *> corresponding to 2-by-2 blocks of S are reduced to positive diagonal
  66. *> form, i.e., if S(j+1,j) is non-zero, then P(j+1,j) = P(j,j+1) = 0,
  67. *> P(j,j) > 0, and P(j+1,j+1) > 0.
  68. *>
  69. *> Optionally, the orthogonal matrix Q from the generalized Schur
  70. *> factorization may be postmultiplied into an input matrix Q1, and the
  71. *> orthogonal matrix Z may be postmultiplied into an input matrix Z1.
  72. *> If Q1 and Z1 are the orthogonal matrices from DGGHRD that reduced
  73. *> the matrix pair (A,B) to generalized upper Hessenberg form, then the
  74. *> output matrices Q1*Q and Z1*Z are the orthogonal factors from the
  75. *> generalized Schur factorization of (A,B):
  76. *>
  77. *> A = (Q1*Q)*S*(Z1*Z)**T, B = (Q1*Q)*P*(Z1*Z)**T.
  78. *>
  79. *> To avoid overflow, eigenvalues of the matrix pair (H,T) (equivalently,
  80. *> of (A,B)) are computed as a pair of values (alpha,beta), where alpha is
  81. *> complex and beta real.
  82. *> If beta is nonzero, lambda = alpha / beta is an eigenvalue of the
  83. *> generalized nonsymmetric eigenvalue problem (GNEP)
  84. *> A*x = lambda*B*x
  85. *> and if alpha is nonzero, mu = beta / alpha is an eigenvalue of the
  86. *> alternate form of the GNEP
  87. *> mu*A*y = B*y.
  88. *> Real eigenvalues can be read directly from the generalized Schur
  89. *> form:
  90. *> alpha = S(i,i), beta = P(i,i).
  91. *>
  92. *> Ref: C.B. Moler & G.W. Stewart, "An Algorithm for Generalized Matrix
  93. *> Eigenvalue Problems", SIAM J. Numer. Anal., 10(1973),
  94. *> pp. 241--256.
  95. *> \endverbatim
  96. *
  97. * Arguments:
  98. * ==========
  99. *
  100. *> \param[in] JOB
  101. *> \verbatim
  102. *> JOB is CHARACTER*1
  103. *> = 'E': Compute eigenvalues only;
  104. *> = 'S': Compute eigenvalues and the Schur form.
  105. *> \endverbatim
  106. *>
  107. *> \param[in] COMPQ
  108. *> \verbatim
  109. *> COMPQ is CHARACTER*1
  110. *> = 'N': Left Schur vectors (Q) are not computed;
  111. *> = 'I': Q is initialized to the unit matrix and the matrix Q
  112. *> of left Schur vectors of (H,T) is returned;
  113. *> = 'V': Q must contain an orthogonal matrix Q1 on entry and
  114. *> the product Q1*Q is returned.
  115. *> \endverbatim
  116. *>
  117. *> \param[in] COMPZ
  118. *> \verbatim
  119. *> COMPZ is CHARACTER*1
  120. *> = 'N': Right Schur vectors (Z) are not computed;
  121. *> = 'I': Z is initialized to the unit matrix and the matrix Z
  122. *> of right Schur vectors of (H,T) is returned;
  123. *> = 'V': Z must contain an orthogonal matrix Z1 on entry and
  124. *> the product Z1*Z is returned.
  125. *> \endverbatim
  126. *>
  127. *> \param[in] N
  128. *> \verbatim
  129. *> N is INTEGER
  130. *> The order of the matrices H, T, Q, and Z. N >= 0.
  131. *> \endverbatim
  132. *>
  133. *> \param[in] ILO
  134. *> \verbatim
  135. *> ILO is INTEGER
  136. *> \endverbatim
  137. *>
  138. *> \param[in] IHI
  139. *> \verbatim
  140. *> IHI is INTEGER
  141. *> ILO and IHI mark the rows and columns of H which are in
  142. *> Hessenberg form. It is assumed that A is already upper
  143. *> triangular in rows and columns 1:ILO-1 and IHI+1:N.
  144. *> If N > 0, 1 <= ILO <= IHI <= N; if N = 0, ILO=1 and IHI=0.
  145. *> \endverbatim
  146. *>
  147. *> \param[in,out] H
  148. *> \verbatim
  149. *> H is DOUBLE PRECISION array, dimension (LDH, N)
  150. *> On entry, the N-by-N upper Hessenberg matrix H.
  151. *> On exit, if JOB = 'S', H contains the upper quasi-triangular
  152. *> matrix S from the generalized Schur factorization.
  153. *> If JOB = 'E', the diagonal blocks of H match those of S, but
  154. *> the rest of H is unspecified.
  155. *> \endverbatim
  156. *>
  157. *> \param[in] LDH
  158. *> \verbatim
  159. *> LDH is INTEGER
  160. *> The leading dimension of the array H. LDH >= max( 1, N ).
  161. *> \endverbatim
  162. *>
  163. *> \param[in,out] T
  164. *> \verbatim
  165. *> T is DOUBLE PRECISION array, dimension (LDT, N)
  166. *> On entry, the N-by-N upper triangular matrix T.
  167. *> On exit, if JOB = 'S', T contains the upper triangular
  168. *> matrix P from the generalized Schur factorization;
  169. *> 2-by-2 diagonal blocks of P corresponding to 2-by-2 blocks of S
  170. *> are reduced to positive diagonal form, i.e., if H(j+1,j) is
  171. *> non-zero, then T(j+1,j) = T(j,j+1) = 0, T(j,j) > 0, and
  172. *> T(j+1,j+1) > 0.
  173. *> If JOB = 'E', the diagonal blocks of T match those of P, but
  174. *> the rest of T is unspecified.
  175. *> \endverbatim
  176. *>
  177. *> \param[in] LDT
  178. *> \verbatim
  179. *> LDT is INTEGER
  180. *> The leading dimension of the array T. LDT >= max( 1, N ).
  181. *> \endverbatim
  182. *>
  183. *> \param[out] ALPHAR
  184. *> \verbatim
  185. *> ALPHAR is DOUBLE PRECISION array, dimension (N)
  186. *> The real parts of each scalar alpha defining an eigenvalue
  187. *> of GNEP.
  188. *> \endverbatim
  189. *>
  190. *> \param[out] ALPHAI
  191. *> \verbatim
  192. *> ALPHAI is DOUBLE PRECISION array, dimension (N)
  193. *> The imaginary parts of each scalar alpha defining an
  194. *> eigenvalue of GNEP.
  195. *> If ALPHAI(j) is zero, then the j-th eigenvalue is real; if
  196. *> positive, then the j-th and (j+1)-st eigenvalues are a
  197. *> complex conjugate pair, with ALPHAI(j+1) = -ALPHAI(j).
  198. *> \endverbatim
  199. *>
  200. *> \param[out] BETA
  201. *> \verbatim
  202. *> BETA is DOUBLE PRECISION array, dimension (N)
  203. *> The scalars beta that define the eigenvalues of GNEP.
  204. *> Together, the quantities alpha = (ALPHAR(j),ALPHAI(j)) and
  205. *> beta = BETA(j) represent the j-th eigenvalue of the matrix
  206. *> pair (A,B), in one of the forms lambda = alpha/beta or
  207. *> mu = beta/alpha. Since either lambda or mu may overflow,
  208. *> they should not, in general, be computed.
  209. *> \endverbatim
  210. *>
  211. *> \param[in,out] Q
  212. *> \verbatim
  213. *> Q is DOUBLE PRECISION array, dimension (LDQ, N)
  214. *> On entry, if COMPQ = 'V', the orthogonal matrix Q1 used in
  215. *> the reduction of (A,B) to generalized Hessenberg form.
  216. *> On exit, if COMPQ = 'I', the orthogonal matrix of left Schur
  217. *> vectors of (H,T), and if COMPQ = 'V', the orthogonal matrix
  218. *> of left Schur vectors of (A,B).
  219. *> Not referenced if COMPQ = 'N'.
  220. *> \endverbatim
  221. *>
  222. *> \param[in] LDQ
  223. *> \verbatim
  224. *> LDQ is INTEGER
  225. *> The leading dimension of the array Q. LDQ >= 1.
  226. *> If COMPQ='V' or 'I', then LDQ >= N.
  227. *> \endverbatim
  228. *>
  229. *> \param[in,out] Z
  230. *> \verbatim
  231. *> Z is DOUBLE PRECISION array, dimension (LDZ, N)
  232. *> On entry, if COMPZ = 'V', the orthogonal matrix Z1 used in
  233. *> the reduction of (A,B) to generalized Hessenberg form.
  234. *> On exit, if COMPZ = 'I', the orthogonal matrix of
  235. *> right Schur vectors of (H,T), and if COMPZ = 'V', the
  236. *> orthogonal matrix of right Schur vectors of (A,B).
  237. *> Not referenced if COMPZ = 'N'.
  238. *> \endverbatim
  239. *>
  240. *> \param[in] LDZ
  241. *> \verbatim
  242. *> LDZ is INTEGER
  243. *> The leading dimension of the array Z. LDZ >= 1.
  244. *> If COMPZ='V' or 'I', then LDZ >= N.
  245. *> \endverbatim
  246. *>
  247. *> \param[out] WORK
  248. *> \verbatim
  249. *> WORK is DOUBLE PRECISION array, dimension (MAX(1,LWORK))
  250. *> On exit, if INFO >= 0, WORK(1) returns the optimal LWORK.
  251. *> \endverbatim
  252. *>
  253. *> \param[in] LWORK
  254. *> \verbatim
  255. *> LWORK is INTEGER
  256. *> The dimension of the array WORK. LWORK >= max(1,N).
  257. *>
  258. *> If LWORK = -1, then a workspace query is assumed; the routine
  259. *> only calculates the optimal size of the WORK array, returns
  260. *> this value as the first entry of the WORK array, and no error
  261. *> message related to LWORK is issued by XERBLA.
  262. *> \endverbatim
  263. *>
  264. *> \param[out] INFO
  265. *> \verbatim
  266. *> INFO is INTEGER
  267. *> = 0: successful exit
  268. *> < 0: if INFO = -i, the i-th argument had an illegal value
  269. *> = 1,...,N: the QZ iteration did not converge. (H,T) is not
  270. *> in Schur form, but ALPHAR(i), ALPHAI(i), and
  271. *> BETA(i), i=INFO+1,...,N should be correct.
  272. *> = N+1,...,2*N: the shift calculation failed. (H,T) is not
  273. *> in Schur form, but ALPHAR(i), ALPHAI(i), and
  274. *> BETA(i), i=INFO-N+1,...,N should be correct.
  275. *> \endverbatim
  276. *
  277. * Authors:
  278. * ========
  279. *
  280. *> \author Univ. of Tennessee
  281. *> \author Univ. of California Berkeley
  282. *> \author Univ. of Colorado Denver
  283. *> \author NAG Ltd.
  284. *
  285. *> \ingroup doubleGEcomputational
  286. *
  287. *> \par Further Details:
  288. * =====================
  289. *>
  290. *> \verbatim
  291. *>
  292. *> Iteration counters:
  293. *>
  294. *> JITER -- counts iterations.
  295. *> IITER -- counts iterations run since ILAST was last
  296. *> changed. This is therefore reset only when a 1-by-1 or
  297. *> 2-by-2 block deflates off the bottom.
  298. *> \endverbatim
  299. *>
  300. * =====================================================================
  301. SUBROUTINE DHGEQZ( JOB, COMPQ, COMPZ, N, ILO, IHI, H, LDH, T, LDT,
  302. $ ALPHAR, ALPHAI, BETA, Q, LDQ, Z, LDZ, WORK,
  303. $ LWORK, INFO )
  304. *
  305. * -- LAPACK computational routine --
  306. * -- LAPACK is a software package provided by Univ. of Tennessee, --
  307. * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
  308. *
  309. * .. Scalar Arguments ..
  310. CHARACTER COMPQ, COMPZ, JOB
  311. INTEGER IHI, ILO, INFO, LDH, LDQ, LDT, LDZ, LWORK, N
  312. * ..
  313. * .. Array Arguments ..
  314. DOUBLE PRECISION ALPHAI( * ), ALPHAR( * ), BETA( * ),
  315. $ H( LDH, * ), Q( LDQ, * ), T( LDT, * ),
  316. $ WORK( * ), Z( LDZ, * )
  317. * ..
  318. *
  319. * =====================================================================
  320. *
  321. * .. Parameters ..
  322. * $ SAFETY = 1.0E+0 )
  323. DOUBLE PRECISION HALF, ZERO, ONE, SAFETY
  324. PARAMETER ( HALF = 0.5D+0, ZERO = 0.0D+0, ONE = 1.0D+0,
  325. $ SAFETY = 1.0D+2 )
  326. * ..
  327. * .. Local Scalars ..
  328. LOGICAL ILAZR2, ILAZRO, ILPIVT, ILQ, ILSCHR, ILZ,
  329. $ LQUERY
  330. INTEGER ICOMPQ, ICOMPZ, IFIRST, IFRSTM, IITER, ILAST,
  331. $ ILASTM, IN, ISCHUR, ISTART, J, JC, JCH, JITER,
  332. $ JR, MAXIT
  333. DOUBLE PRECISION A11, A12, A1I, A1R, A21, A22, A2I, A2R, AD11,
  334. $ AD11L, AD12, AD12L, AD21, AD21L, AD22, AD22L,
  335. $ AD32L, AN, ANORM, ASCALE, ATOL, B11, B1A, B1I,
  336. $ B1R, B22, B2A, B2I, B2R, BN, BNORM, BSCALE,
  337. $ BTOL, C, C11I, C11R, C12, C21, C22I, C22R, CL,
  338. $ CQ, CR, CZ, ESHIFT, S, S1, S1INV, S2, SAFMAX,
  339. $ SAFMIN, SCALE, SL, SQI, SQR, SR, SZI, SZR, T1,
  340. $ T2, T3, TAU, TEMP, TEMP2, TEMPI, TEMPR, U1,
  341. $ U12, U12L, U2, ULP, VS, W11, W12, W21, W22,
  342. $ WABS, WI, WR, WR2
  343. * ..
  344. * .. Local Arrays ..
  345. DOUBLE PRECISION V( 3 )
  346. * ..
  347. * .. External Functions ..
  348. LOGICAL LSAME
  349. DOUBLE PRECISION DLAMCH, DLANHS, DLAPY2, DLAPY3
  350. EXTERNAL LSAME, DLAMCH, DLANHS, DLAPY2, DLAPY3
  351. * ..
  352. * .. External Subroutines ..
  353. EXTERNAL DLAG2, DLARFG, DLARTG, DLASET, DLASV2, DROT,
  354. $ XERBLA
  355. * ..
  356. * .. Intrinsic Functions ..
  357. INTRINSIC ABS, DBLE, MAX, MIN, SQRT
  358. * ..
  359. * .. Executable Statements ..
  360. *
  361. * Decode JOB, COMPQ, COMPZ
  362. *
  363. IF( LSAME( JOB, 'E' ) ) THEN
  364. ILSCHR = .FALSE.
  365. ISCHUR = 1
  366. ELSE IF( LSAME( JOB, 'S' ) ) THEN
  367. ILSCHR = .TRUE.
  368. ISCHUR = 2
  369. ELSE
  370. ISCHUR = 0
  371. END IF
  372. *
  373. IF( LSAME( COMPQ, 'N' ) ) THEN
  374. ILQ = .FALSE.
  375. ICOMPQ = 1
  376. ELSE IF( LSAME( COMPQ, 'V' ) ) THEN
  377. ILQ = .TRUE.
  378. ICOMPQ = 2
  379. ELSE IF( LSAME( COMPQ, 'I' ) ) THEN
  380. ILQ = .TRUE.
  381. ICOMPQ = 3
  382. ELSE
  383. ICOMPQ = 0
  384. END IF
  385. *
  386. IF( LSAME( COMPZ, 'N' ) ) THEN
  387. ILZ = .FALSE.
  388. ICOMPZ = 1
  389. ELSE IF( LSAME( COMPZ, 'V' ) ) THEN
  390. ILZ = .TRUE.
  391. ICOMPZ = 2
  392. ELSE IF( LSAME( COMPZ, 'I' ) ) THEN
  393. ILZ = .TRUE.
  394. ICOMPZ = 3
  395. ELSE
  396. ICOMPZ = 0
  397. END IF
  398. *
  399. * Check Argument Values
  400. *
  401. INFO = 0
  402. WORK( 1 ) = MAX( 1, N )
  403. LQUERY = ( LWORK.EQ.-1 )
  404. IF( ISCHUR.EQ.0 ) THEN
  405. INFO = -1
  406. ELSE IF( ICOMPQ.EQ.0 ) THEN
  407. INFO = -2
  408. ELSE IF( ICOMPZ.EQ.0 ) THEN
  409. INFO = -3
  410. ELSE IF( N.LT.0 ) THEN
  411. INFO = -4
  412. ELSE IF( ILO.LT.1 ) THEN
  413. INFO = -5
  414. ELSE IF( IHI.GT.N .OR. IHI.LT.ILO-1 ) THEN
  415. INFO = -6
  416. ELSE IF( LDH.LT.N ) THEN
  417. INFO = -8
  418. ELSE IF( LDT.LT.N ) THEN
  419. INFO = -10
  420. ELSE IF( LDQ.LT.1 .OR. ( ILQ .AND. LDQ.LT.N ) ) THEN
  421. INFO = -15
  422. ELSE IF( LDZ.LT.1 .OR. ( ILZ .AND. LDZ.LT.N ) ) THEN
  423. INFO = -17
  424. ELSE IF( LWORK.LT.MAX( 1, N ) .AND. .NOT.LQUERY ) THEN
  425. INFO = -19
  426. END IF
  427. IF( INFO.NE.0 ) THEN
  428. CALL XERBLA( 'DHGEQZ', -INFO )
  429. RETURN
  430. ELSE IF( LQUERY ) THEN
  431. RETURN
  432. END IF
  433. *
  434. * Quick return if possible
  435. *
  436. IF( N.LE.0 ) THEN
  437. WORK( 1 ) = DBLE( 1 )
  438. RETURN
  439. END IF
  440. *
  441. * Initialize Q and Z
  442. *
  443. IF( ICOMPQ.EQ.3 )
  444. $ CALL DLASET( 'Full', N, N, ZERO, ONE, Q, LDQ )
  445. IF( ICOMPZ.EQ.3 )
  446. $ CALL DLASET( 'Full', N, N, ZERO, ONE, Z, LDZ )
  447. *
  448. * Machine Constants
  449. *
  450. IN = IHI + 1 - ILO
  451. SAFMIN = DLAMCH( 'S' )
  452. SAFMAX = ONE / SAFMIN
  453. ULP = DLAMCH( 'E' )*DLAMCH( 'B' )
  454. ANORM = DLANHS( 'F', IN, H( ILO, ILO ), LDH, WORK )
  455. BNORM = DLANHS( 'F', IN, T( ILO, ILO ), LDT, WORK )
  456. ATOL = MAX( SAFMIN, ULP*ANORM )
  457. BTOL = MAX( SAFMIN, ULP*BNORM )
  458. ASCALE = ONE / MAX( SAFMIN, ANORM )
  459. BSCALE = ONE / MAX( SAFMIN, BNORM )
  460. *
  461. * Set Eigenvalues IHI+1:N
  462. *
  463. DO 30 J = IHI + 1, N
  464. IF( T( J, J ).LT.ZERO ) THEN
  465. IF( ILSCHR ) THEN
  466. DO 10 JR = 1, J
  467. H( JR, J ) = -H( JR, J )
  468. T( JR, J ) = -T( JR, J )
  469. 10 CONTINUE
  470. ELSE
  471. H( J, J ) = -H( J, J )
  472. T( J, J ) = -T( J, J )
  473. END IF
  474. IF( ILZ ) THEN
  475. DO 20 JR = 1, N
  476. Z( JR, J ) = -Z( JR, J )
  477. 20 CONTINUE
  478. END IF
  479. END IF
  480. ALPHAR( J ) = H( J, J )
  481. ALPHAI( J ) = ZERO
  482. BETA( J ) = T( J, J )
  483. 30 CONTINUE
  484. *
  485. * If IHI < ILO, skip QZ steps
  486. *
  487. IF( IHI.LT.ILO )
  488. $ GO TO 380
  489. *
  490. * MAIN QZ ITERATION LOOP
  491. *
  492. * Initialize dynamic indices
  493. *
  494. * Eigenvalues ILAST+1:N have been found.
  495. * Column operations modify rows IFRSTM:whatever.
  496. * Row operations modify columns whatever:ILASTM.
  497. *
  498. * If only eigenvalues are being computed, then
  499. * IFRSTM is the row of the last splitting row above row ILAST;
  500. * this is always at least ILO.
  501. * IITER counts iterations since the last eigenvalue was found,
  502. * to tell when to use an extraordinary shift.
  503. * MAXIT is the maximum number of QZ sweeps allowed.
  504. *
  505. ILAST = IHI
  506. IF( ILSCHR ) THEN
  507. IFRSTM = 1
  508. ILASTM = N
  509. ELSE
  510. IFRSTM = ILO
  511. ILASTM = IHI
  512. END IF
  513. IITER = 0
  514. ESHIFT = ZERO
  515. MAXIT = 30*( IHI-ILO+1 )
  516. *
  517. DO 360 JITER = 1, MAXIT
  518. *
  519. * Split the matrix if possible.
  520. *
  521. * Two tests:
  522. * 1: H(j,j-1)=0 or j=ILO
  523. * 2: T(j,j)=0
  524. *
  525. IF( ILAST.EQ.ILO ) THEN
  526. *
  527. * Special case: j=ILAST
  528. *
  529. GO TO 80
  530. ELSE
  531. IF( ABS( H( ILAST, ILAST-1 ) ).LE.MAX( SAFMIN, ULP*(
  532. $ ABS( H( ILAST, ILAST ) ) + ABS( H( ILAST-1, ILAST-1 ) )
  533. $ ) ) ) THEN
  534. H( ILAST, ILAST-1 ) = ZERO
  535. GO TO 80
  536. END IF
  537. END IF
  538. *
  539. IF( ABS( T( ILAST, ILAST ) ).LE.BTOL ) THEN
  540. T( ILAST, ILAST ) = ZERO
  541. GO TO 70
  542. END IF
  543. *
  544. * General case: j<ILAST
  545. *
  546. DO 60 J = ILAST - 1, ILO, -1
  547. *
  548. * Test 1: for H(j,j-1)=0 or j=ILO
  549. *
  550. IF( J.EQ.ILO ) THEN
  551. ILAZRO = .TRUE.
  552. ELSE
  553. IF( ABS( H( J, J-1 ) ).LE.MAX( SAFMIN, ULP*(
  554. $ ABS( H( J, J ) ) + ABS( H( J-1, J-1 ) )
  555. $ ) ) ) THEN
  556. H( J, J-1 ) = ZERO
  557. ILAZRO = .TRUE.
  558. ELSE
  559. ILAZRO = .FALSE.
  560. END IF
  561. END IF
  562. *
  563. * Test 2: for T(j,j)=0
  564. *
  565. IF( ABS( T( J, J ) ).LT.BTOL ) THEN
  566. T( J, J ) = ZERO
  567. *
  568. * Test 1a: Check for 2 consecutive small subdiagonals in A
  569. *
  570. ILAZR2 = .FALSE.
  571. IF( .NOT.ILAZRO ) THEN
  572. TEMP = ABS( H( J, J-1 ) )
  573. TEMP2 = ABS( H( J, J ) )
  574. TEMPR = MAX( TEMP, TEMP2 )
  575. IF( TEMPR.LT.ONE .AND. TEMPR.NE.ZERO ) THEN
  576. TEMP = TEMP / TEMPR
  577. TEMP2 = TEMP2 / TEMPR
  578. END IF
  579. IF( TEMP*( ASCALE*ABS( H( J+1, J ) ) ).LE.TEMP2*
  580. $ ( ASCALE*ATOL ) )ILAZR2 = .TRUE.
  581. END IF
  582. *
  583. * If both tests pass (1 & 2), i.e., the leading diagonal
  584. * element of B in the block is zero, split a 1x1 block off
  585. * at the top. (I.e., at the J-th row/column) The leading
  586. * diagonal element of the remainder can also be zero, so
  587. * this may have to be done repeatedly.
  588. *
  589. IF( ILAZRO .OR. ILAZR2 ) THEN
  590. DO 40 JCH = J, ILAST - 1
  591. TEMP = H( JCH, JCH )
  592. CALL DLARTG( TEMP, H( JCH+1, JCH ), C, S,
  593. $ H( JCH, JCH ) )
  594. H( JCH+1, JCH ) = ZERO
  595. CALL DROT( ILASTM-JCH, H( JCH, JCH+1 ), LDH,
  596. $ H( JCH+1, JCH+1 ), LDH, C, S )
  597. CALL DROT( ILASTM-JCH, T( JCH, JCH+1 ), LDT,
  598. $ T( JCH+1, JCH+1 ), LDT, C, S )
  599. IF( ILQ )
  600. $ CALL DROT( N, Q( 1, JCH ), 1, Q( 1, JCH+1 ), 1,
  601. $ C, S )
  602. IF( ILAZR2 )
  603. $ H( JCH, JCH-1 ) = H( JCH, JCH-1 )*C
  604. ILAZR2 = .FALSE.
  605. IF( ABS( T( JCH+1, JCH+1 ) ).GE.BTOL ) THEN
  606. IF( JCH+1.GE.ILAST ) THEN
  607. GO TO 80
  608. ELSE
  609. IFIRST = JCH + 1
  610. GO TO 110
  611. END IF
  612. END IF
  613. T( JCH+1, JCH+1 ) = ZERO
  614. 40 CONTINUE
  615. GO TO 70
  616. ELSE
  617. *
  618. * Only test 2 passed -- chase the zero to T(ILAST,ILAST)
  619. * Then process as in the case T(ILAST,ILAST)=0
  620. *
  621. DO 50 JCH = J, ILAST - 1
  622. TEMP = T( JCH, JCH+1 )
  623. CALL DLARTG( TEMP, T( JCH+1, JCH+1 ), C, S,
  624. $ T( JCH, JCH+1 ) )
  625. T( JCH+1, JCH+1 ) = ZERO
  626. IF( JCH.LT.ILASTM-1 )
  627. $ CALL DROT( ILASTM-JCH-1, T( JCH, JCH+2 ), LDT,
  628. $ T( JCH+1, JCH+2 ), LDT, C, S )
  629. CALL DROT( ILASTM-JCH+2, H( JCH, JCH-1 ), LDH,
  630. $ H( JCH+1, JCH-1 ), LDH, C, S )
  631. IF( ILQ )
  632. $ CALL DROT( N, Q( 1, JCH ), 1, Q( 1, JCH+1 ), 1,
  633. $ C, S )
  634. TEMP = H( JCH+1, JCH )
  635. CALL DLARTG( TEMP, H( JCH+1, JCH-1 ), C, S,
  636. $ H( JCH+1, JCH ) )
  637. H( JCH+1, JCH-1 ) = ZERO
  638. CALL DROT( JCH+1-IFRSTM, H( IFRSTM, JCH ), 1,
  639. $ H( IFRSTM, JCH-1 ), 1, C, S )
  640. CALL DROT( JCH-IFRSTM, T( IFRSTM, JCH ), 1,
  641. $ T( IFRSTM, JCH-1 ), 1, C, S )
  642. IF( ILZ )
  643. $ CALL DROT( N, Z( 1, JCH ), 1, Z( 1, JCH-1 ), 1,
  644. $ C, S )
  645. 50 CONTINUE
  646. GO TO 70
  647. END IF
  648. ELSE IF( ILAZRO ) THEN
  649. *
  650. * Only test 1 passed -- work on J:ILAST
  651. *
  652. IFIRST = J
  653. GO TO 110
  654. END IF
  655. *
  656. * Neither test passed -- try next J
  657. *
  658. 60 CONTINUE
  659. *
  660. * (Drop-through is "impossible")
  661. *
  662. INFO = N + 1
  663. GO TO 420
  664. *
  665. * T(ILAST,ILAST)=0 -- clear H(ILAST,ILAST-1) to split off a
  666. * 1x1 block.
  667. *
  668. 70 CONTINUE
  669. TEMP = H( ILAST, ILAST )
  670. CALL DLARTG( TEMP, H( ILAST, ILAST-1 ), C, S,
  671. $ H( ILAST, ILAST ) )
  672. H( ILAST, ILAST-1 ) = ZERO
  673. CALL DROT( ILAST-IFRSTM, H( IFRSTM, ILAST ), 1,
  674. $ H( IFRSTM, ILAST-1 ), 1, C, S )
  675. CALL DROT( ILAST-IFRSTM, T( IFRSTM, ILAST ), 1,
  676. $ T( IFRSTM, ILAST-1 ), 1, C, S )
  677. IF( ILZ )
  678. $ CALL DROT( N, Z( 1, ILAST ), 1, Z( 1, ILAST-1 ), 1, C, S )
  679. *
  680. * H(ILAST,ILAST-1)=0 -- Standardize B, set ALPHAR, ALPHAI,
  681. * and BETA
  682. *
  683. 80 CONTINUE
  684. IF( T( ILAST, ILAST ).LT.ZERO ) THEN
  685. IF( ILSCHR ) THEN
  686. DO 90 J = IFRSTM, ILAST
  687. H( J, ILAST ) = -H( J, ILAST )
  688. T( J, ILAST ) = -T( J, ILAST )
  689. 90 CONTINUE
  690. ELSE
  691. H( ILAST, ILAST ) = -H( ILAST, ILAST )
  692. T( ILAST, ILAST ) = -T( ILAST, ILAST )
  693. END IF
  694. IF( ILZ ) THEN
  695. DO 100 J = 1, N
  696. Z( J, ILAST ) = -Z( J, ILAST )
  697. 100 CONTINUE
  698. END IF
  699. END IF
  700. ALPHAR( ILAST ) = H( ILAST, ILAST )
  701. ALPHAI( ILAST ) = ZERO
  702. BETA( ILAST ) = T( ILAST, ILAST )
  703. *
  704. * Go to next block -- exit if finished.
  705. *
  706. ILAST = ILAST - 1
  707. IF( ILAST.LT.ILO )
  708. $ GO TO 380
  709. *
  710. * Reset counters
  711. *
  712. IITER = 0
  713. ESHIFT = ZERO
  714. IF( .NOT.ILSCHR ) THEN
  715. ILASTM = ILAST
  716. IF( IFRSTM.GT.ILAST )
  717. $ IFRSTM = ILO
  718. END IF
  719. GO TO 350
  720. *
  721. * QZ step
  722. *
  723. * This iteration only involves rows/columns IFIRST:ILAST. We
  724. * assume IFIRST < ILAST, and that the diagonal of B is non-zero.
  725. *
  726. 110 CONTINUE
  727. IITER = IITER + 1
  728. IF( .NOT.ILSCHR ) THEN
  729. IFRSTM = IFIRST
  730. END IF
  731. *
  732. * Compute single shifts.
  733. *
  734. * At this point, IFIRST < ILAST, and the diagonal elements of
  735. * T(IFIRST:ILAST,IFIRST,ILAST) are larger than BTOL (in
  736. * magnitude)
  737. *
  738. IF( ( IITER / 10 )*10.EQ.IITER ) THEN
  739. *
  740. * Exceptional shift. Chosen for no particularly good reason.
  741. * (Single shift only.)
  742. *
  743. IF( ( DBLE( MAXIT )*SAFMIN )*ABS( H( ILAST, ILAST-1 ) ).LT.
  744. $ ABS( T( ILAST-1, ILAST-1 ) ) ) THEN
  745. ESHIFT = H( ILAST, ILAST-1 ) /
  746. $ T( ILAST-1, ILAST-1 )
  747. ELSE
  748. ESHIFT = ESHIFT + ONE / ( SAFMIN*DBLE( MAXIT ) )
  749. END IF
  750. S1 = ONE
  751. WR = ESHIFT
  752. *
  753. ELSE
  754. *
  755. * Shifts based on the generalized eigenvalues of the
  756. * bottom-right 2x2 block of A and B. The first eigenvalue
  757. * returned by DLAG2 is the Wilkinson shift (AEP p.512),
  758. *
  759. CALL DLAG2( H( ILAST-1, ILAST-1 ), LDH,
  760. $ T( ILAST-1, ILAST-1 ), LDT, SAFMIN*SAFETY, S1,
  761. $ S2, WR, WR2, WI )
  762. *
  763. IF ( ABS( (WR/S1)*T( ILAST, ILAST ) - H( ILAST, ILAST ) )
  764. $ .GT. ABS( (WR2/S2)*T( ILAST, ILAST )
  765. $ - H( ILAST, ILAST ) ) ) THEN
  766. TEMP = WR
  767. WR = WR2
  768. WR2 = TEMP
  769. TEMP = S1
  770. S1 = S2
  771. S2 = TEMP
  772. END IF
  773. TEMP = MAX( S1, SAFMIN*MAX( ONE, ABS( WR ), ABS( WI ) ) )
  774. IF( WI.NE.ZERO )
  775. $ GO TO 200
  776. END IF
  777. *
  778. * Fiddle with shift to avoid overflow
  779. *
  780. TEMP = MIN( ASCALE, ONE )*( HALF*SAFMAX )
  781. IF( S1.GT.TEMP ) THEN
  782. SCALE = TEMP / S1
  783. ELSE
  784. SCALE = ONE
  785. END IF
  786. *
  787. TEMP = MIN( BSCALE, ONE )*( HALF*SAFMAX )
  788. IF( ABS( WR ).GT.TEMP )
  789. $ SCALE = MIN( SCALE, TEMP / ABS( WR ) )
  790. S1 = SCALE*S1
  791. WR = SCALE*WR
  792. *
  793. * Now check for two consecutive small subdiagonals.
  794. *
  795. DO 120 J = ILAST - 1, IFIRST + 1, -1
  796. ISTART = J
  797. TEMP = ABS( S1*H( J, J-1 ) )
  798. TEMP2 = ABS( S1*H( J, J )-WR*T( J, J ) )
  799. TEMPR = MAX( TEMP, TEMP2 )
  800. IF( TEMPR.LT.ONE .AND. TEMPR.NE.ZERO ) THEN
  801. TEMP = TEMP / TEMPR
  802. TEMP2 = TEMP2 / TEMPR
  803. END IF
  804. IF( ABS( ( ASCALE*H( J+1, J ) )*TEMP ).LE.( ASCALE*ATOL )*
  805. $ TEMP2 )GO TO 130
  806. 120 CONTINUE
  807. *
  808. ISTART = IFIRST
  809. 130 CONTINUE
  810. *
  811. * Do an implicit single-shift QZ sweep.
  812. *
  813. * Initial Q
  814. *
  815. TEMP = S1*H( ISTART, ISTART ) - WR*T( ISTART, ISTART )
  816. TEMP2 = S1*H( ISTART+1, ISTART )
  817. CALL DLARTG( TEMP, TEMP2, C, S, TEMPR )
  818. *
  819. * Sweep
  820. *
  821. DO 190 J = ISTART, ILAST - 1
  822. IF( J.GT.ISTART ) THEN
  823. TEMP = H( J, J-1 )
  824. CALL DLARTG( TEMP, H( J+1, J-1 ), C, S, H( J, J-1 ) )
  825. H( J+1, J-1 ) = ZERO
  826. END IF
  827. *
  828. DO 140 JC = J, ILASTM
  829. TEMP = C*H( J, JC ) + S*H( J+1, JC )
  830. H( J+1, JC ) = -S*H( J, JC ) + C*H( J+1, JC )
  831. H( J, JC ) = TEMP
  832. TEMP2 = C*T( J, JC ) + S*T( J+1, JC )
  833. T( J+1, JC ) = -S*T( J, JC ) + C*T( J+1, JC )
  834. T( J, JC ) = TEMP2
  835. 140 CONTINUE
  836. IF( ILQ ) THEN
  837. DO 150 JR = 1, N
  838. TEMP = C*Q( JR, J ) + S*Q( JR, J+1 )
  839. Q( JR, J+1 ) = -S*Q( JR, J ) + C*Q( JR, J+1 )
  840. Q( JR, J ) = TEMP
  841. 150 CONTINUE
  842. END IF
  843. *
  844. TEMP = T( J+1, J+1 )
  845. CALL DLARTG( TEMP, T( J+1, J ), C, S, T( J+1, J+1 ) )
  846. T( J+1, J ) = ZERO
  847. *
  848. DO 160 JR = IFRSTM, MIN( J+2, ILAST )
  849. TEMP = C*H( JR, J+1 ) + S*H( JR, J )
  850. H( JR, J ) = -S*H( JR, J+1 ) + C*H( JR, J )
  851. H( JR, J+1 ) = TEMP
  852. 160 CONTINUE
  853. DO 170 JR = IFRSTM, J
  854. TEMP = C*T( JR, J+1 ) + S*T( JR, J )
  855. T( JR, J ) = -S*T( JR, J+1 ) + C*T( JR, J )
  856. T( JR, J+1 ) = TEMP
  857. 170 CONTINUE
  858. IF( ILZ ) THEN
  859. DO 180 JR = 1, N
  860. TEMP = C*Z( JR, J+1 ) + S*Z( JR, J )
  861. Z( JR, J ) = -S*Z( JR, J+1 ) + C*Z( JR, J )
  862. Z( JR, J+1 ) = TEMP
  863. 180 CONTINUE
  864. END IF
  865. 190 CONTINUE
  866. *
  867. GO TO 350
  868. *
  869. * Use Francis double-shift
  870. *
  871. * Note: the Francis double-shift should work with real shifts,
  872. * but only if the block is at least 3x3.
  873. * This code may break if this point is reached with
  874. * a 2x2 block with real eigenvalues.
  875. *
  876. 200 CONTINUE
  877. IF( IFIRST+1.EQ.ILAST ) THEN
  878. *
  879. * Special case -- 2x2 block with complex eigenvectors
  880. *
  881. * Step 1: Standardize, that is, rotate so that
  882. *
  883. * ( B11 0 )
  884. * B = ( ) with B11 non-negative.
  885. * ( 0 B22 )
  886. *
  887. CALL DLASV2( T( ILAST-1, ILAST-1 ), T( ILAST-1, ILAST ),
  888. $ T( ILAST, ILAST ), B22, B11, SR, CR, SL, CL )
  889. *
  890. IF( B11.LT.ZERO ) THEN
  891. CR = -CR
  892. SR = -SR
  893. B11 = -B11
  894. B22 = -B22
  895. END IF
  896. *
  897. CALL DROT( ILASTM+1-IFIRST, H( ILAST-1, ILAST-1 ), LDH,
  898. $ H( ILAST, ILAST-1 ), LDH, CL, SL )
  899. CALL DROT( ILAST+1-IFRSTM, H( IFRSTM, ILAST-1 ), 1,
  900. $ H( IFRSTM, ILAST ), 1, CR, SR )
  901. *
  902. IF( ILAST.LT.ILASTM )
  903. $ CALL DROT( ILASTM-ILAST, T( ILAST-1, ILAST+1 ), LDT,
  904. $ T( ILAST, ILAST+1 ), LDT, CL, SL )
  905. IF( IFRSTM.LT.ILAST-1 )
  906. $ CALL DROT( IFIRST-IFRSTM, T( IFRSTM, ILAST-1 ), 1,
  907. $ T( IFRSTM, ILAST ), 1, CR, SR )
  908. *
  909. IF( ILQ )
  910. $ CALL DROT( N, Q( 1, ILAST-1 ), 1, Q( 1, ILAST ), 1, CL,
  911. $ SL )
  912. IF( ILZ )
  913. $ CALL DROT( N, Z( 1, ILAST-1 ), 1, Z( 1, ILAST ), 1, CR,
  914. $ SR )
  915. *
  916. T( ILAST-1, ILAST-1 ) = B11
  917. T( ILAST-1, ILAST ) = ZERO
  918. T( ILAST, ILAST-1 ) = ZERO
  919. T( ILAST, ILAST ) = B22
  920. *
  921. * If B22 is negative, negate column ILAST
  922. *
  923. IF( B22.LT.ZERO ) THEN
  924. DO 210 J = IFRSTM, ILAST
  925. H( J, ILAST ) = -H( J, ILAST )
  926. T( J, ILAST ) = -T( J, ILAST )
  927. 210 CONTINUE
  928. *
  929. IF( ILZ ) THEN
  930. DO 220 J = 1, N
  931. Z( J, ILAST ) = -Z( J, ILAST )
  932. 220 CONTINUE
  933. END IF
  934. B22 = -B22
  935. END IF
  936. *
  937. * Step 2: Compute ALPHAR, ALPHAI, and BETA (see refs.)
  938. *
  939. * Recompute shift
  940. *
  941. CALL DLAG2( H( ILAST-1, ILAST-1 ), LDH,
  942. $ T( ILAST-1, ILAST-1 ), LDT, SAFMIN*SAFETY, S1,
  943. $ TEMP, WR, TEMP2, WI )
  944. *
  945. * If standardization has perturbed the shift onto real line,
  946. * do another (real single-shift) QR step.
  947. *
  948. IF( WI.EQ.ZERO )
  949. $ GO TO 350
  950. S1INV = ONE / S1
  951. *
  952. * Do EISPACK (QZVAL) computation of alpha and beta
  953. *
  954. A11 = H( ILAST-1, ILAST-1 )
  955. A21 = H( ILAST, ILAST-1 )
  956. A12 = H( ILAST-1, ILAST )
  957. A22 = H( ILAST, ILAST )
  958. *
  959. * Compute complex Givens rotation on right
  960. * (Assume some element of C = (sA - wB) > unfl )
  961. * __
  962. * (sA - wB) ( CZ -SZ )
  963. * ( SZ CZ )
  964. *
  965. C11R = S1*A11 - WR*B11
  966. C11I = -WI*B11
  967. C12 = S1*A12
  968. C21 = S1*A21
  969. C22R = S1*A22 - WR*B22
  970. C22I = -WI*B22
  971. *
  972. IF( ABS( C11R )+ABS( C11I )+ABS( C12 ).GT.ABS( C21 )+
  973. $ ABS( C22R )+ABS( C22I ) ) THEN
  974. T1 = DLAPY3( C12, C11R, C11I )
  975. CZ = C12 / T1
  976. SZR = -C11R / T1
  977. SZI = -C11I / T1
  978. ELSE
  979. CZ = DLAPY2( C22R, C22I )
  980. IF( CZ.LE.SAFMIN ) THEN
  981. CZ = ZERO
  982. SZR = ONE
  983. SZI = ZERO
  984. ELSE
  985. TEMPR = C22R / CZ
  986. TEMPI = C22I / CZ
  987. T1 = DLAPY2( CZ, C21 )
  988. CZ = CZ / T1
  989. SZR = -C21*TEMPR / T1
  990. SZI = C21*TEMPI / T1
  991. END IF
  992. END IF
  993. *
  994. * Compute Givens rotation on left
  995. *
  996. * ( CQ SQ )
  997. * ( __ ) A or B
  998. * ( -SQ CQ )
  999. *
  1000. AN = ABS( A11 ) + ABS( A12 ) + ABS( A21 ) + ABS( A22 )
  1001. BN = ABS( B11 ) + ABS( B22 )
  1002. WABS = ABS( WR ) + ABS( WI )
  1003. IF( S1*AN.GT.WABS*BN ) THEN
  1004. CQ = CZ*B11
  1005. SQR = SZR*B22
  1006. SQI = -SZI*B22
  1007. ELSE
  1008. A1R = CZ*A11 + SZR*A12
  1009. A1I = SZI*A12
  1010. A2R = CZ*A21 + SZR*A22
  1011. A2I = SZI*A22
  1012. CQ = DLAPY2( A1R, A1I )
  1013. IF( CQ.LE.SAFMIN ) THEN
  1014. CQ = ZERO
  1015. SQR = ONE
  1016. SQI = ZERO
  1017. ELSE
  1018. TEMPR = A1R / CQ
  1019. TEMPI = A1I / CQ
  1020. SQR = TEMPR*A2R + TEMPI*A2I
  1021. SQI = TEMPI*A2R - TEMPR*A2I
  1022. END IF
  1023. END IF
  1024. T1 = DLAPY3( CQ, SQR, SQI )
  1025. CQ = CQ / T1
  1026. SQR = SQR / T1
  1027. SQI = SQI / T1
  1028. *
  1029. * Compute diagonal elements of QBZ
  1030. *
  1031. TEMPR = SQR*SZR - SQI*SZI
  1032. TEMPI = SQR*SZI + SQI*SZR
  1033. B1R = CQ*CZ*B11 + TEMPR*B22
  1034. B1I = TEMPI*B22
  1035. B1A = DLAPY2( B1R, B1I )
  1036. B2R = CQ*CZ*B22 + TEMPR*B11
  1037. B2I = -TEMPI*B11
  1038. B2A = DLAPY2( B2R, B2I )
  1039. *
  1040. * Normalize so beta > 0, and Im( alpha1 ) > 0
  1041. *
  1042. BETA( ILAST-1 ) = B1A
  1043. BETA( ILAST ) = B2A
  1044. ALPHAR( ILAST-1 ) = ( WR*B1A )*S1INV
  1045. ALPHAI( ILAST-1 ) = ( WI*B1A )*S1INV
  1046. ALPHAR( ILAST ) = ( WR*B2A )*S1INV
  1047. ALPHAI( ILAST ) = -( WI*B2A )*S1INV
  1048. *
  1049. * Step 3: Go to next block -- exit if finished.
  1050. *
  1051. ILAST = IFIRST - 1
  1052. IF( ILAST.LT.ILO )
  1053. $ GO TO 380
  1054. *
  1055. * Reset counters
  1056. *
  1057. IITER = 0
  1058. ESHIFT = ZERO
  1059. IF( .NOT.ILSCHR ) THEN
  1060. ILASTM = ILAST
  1061. IF( IFRSTM.GT.ILAST )
  1062. $ IFRSTM = ILO
  1063. END IF
  1064. GO TO 350
  1065. ELSE
  1066. *
  1067. * Usual case: 3x3 or larger block, using Francis implicit
  1068. * double-shift
  1069. *
  1070. * 2
  1071. * Eigenvalue equation is w - c w + d = 0,
  1072. *
  1073. * -1 2 -1
  1074. * so compute 1st column of (A B ) - c A B + d
  1075. * using the formula in QZIT (from EISPACK)
  1076. *
  1077. * We assume that the block is at least 3x3
  1078. *
  1079. AD11 = ( ASCALE*H( ILAST-1, ILAST-1 ) ) /
  1080. $ ( BSCALE*T( ILAST-1, ILAST-1 ) )
  1081. AD21 = ( ASCALE*H( ILAST, ILAST-1 ) ) /
  1082. $ ( BSCALE*T( ILAST-1, ILAST-1 ) )
  1083. AD12 = ( ASCALE*H( ILAST-1, ILAST ) ) /
  1084. $ ( BSCALE*T( ILAST, ILAST ) )
  1085. AD22 = ( ASCALE*H( ILAST, ILAST ) ) /
  1086. $ ( BSCALE*T( ILAST, ILAST ) )
  1087. U12 = T( ILAST-1, ILAST ) / T( ILAST, ILAST )
  1088. AD11L = ( ASCALE*H( IFIRST, IFIRST ) ) /
  1089. $ ( BSCALE*T( IFIRST, IFIRST ) )
  1090. AD21L = ( ASCALE*H( IFIRST+1, IFIRST ) ) /
  1091. $ ( BSCALE*T( IFIRST, IFIRST ) )
  1092. AD12L = ( ASCALE*H( IFIRST, IFIRST+1 ) ) /
  1093. $ ( BSCALE*T( IFIRST+1, IFIRST+1 ) )
  1094. AD22L = ( ASCALE*H( IFIRST+1, IFIRST+1 ) ) /
  1095. $ ( BSCALE*T( IFIRST+1, IFIRST+1 ) )
  1096. AD32L = ( ASCALE*H( IFIRST+2, IFIRST+1 ) ) /
  1097. $ ( BSCALE*T( IFIRST+1, IFIRST+1 ) )
  1098. U12L = T( IFIRST, IFIRST+1 ) / T( IFIRST+1, IFIRST+1 )
  1099. *
  1100. V( 1 ) = ( AD11-AD11L )*( AD22-AD11L ) - AD12*AD21 +
  1101. $ AD21*U12*AD11L + ( AD12L-AD11L*U12L )*AD21L
  1102. V( 2 ) = ( ( AD22L-AD11L )-AD21L*U12L-( AD11-AD11L )-
  1103. $ ( AD22-AD11L )+AD21*U12 )*AD21L
  1104. V( 3 ) = AD32L*AD21L
  1105. *
  1106. ISTART = IFIRST
  1107. *
  1108. CALL DLARFG( 3, V( 1 ), V( 2 ), 1, TAU )
  1109. V( 1 ) = ONE
  1110. *
  1111. * Sweep
  1112. *
  1113. DO 290 J = ISTART, ILAST - 2
  1114. *
  1115. * All but last elements: use 3x3 Householder transforms.
  1116. *
  1117. * Zero (j-1)st column of A
  1118. *
  1119. IF( J.GT.ISTART ) THEN
  1120. V( 1 ) = H( J, J-1 )
  1121. V( 2 ) = H( J+1, J-1 )
  1122. V( 3 ) = H( J+2, J-1 )
  1123. *
  1124. CALL DLARFG( 3, H( J, J-1 ), V( 2 ), 1, TAU )
  1125. V( 1 ) = ONE
  1126. H( J+1, J-1 ) = ZERO
  1127. H( J+2, J-1 ) = ZERO
  1128. END IF
  1129. *
  1130. T2 = TAU*V( 2 )
  1131. T3 = TAU*V( 3 )
  1132. DO 230 JC = J, ILASTM
  1133. TEMP = H( J, JC )+V( 2 )*H( J+1, JC )+V( 3 )*
  1134. $ H( J+2, JC )
  1135. H( J, JC ) = H( J, JC ) - TEMP*TAU
  1136. H( J+1, JC ) = H( J+1, JC ) - TEMP*T2
  1137. H( J+2, JC ) = H( J+2, JC ) - TEMP*T3
  1138. TEMP2 = T( J, JC )+V( 2 )*T( J+1, JC )+V( 3 )*
  1139. $ T( J+2, JC )
  1140. T( J, JC ) = T( J, JC ) - TEMP2*TAU
  1141. T( J+1, JC ) = T( J+1, JC ) - TEMP2*T2
  1142. T( J+2, JC ) = T( J+2, JC ) - TEMP2*T3
  1143. 230 CONTINUE
  1144. IF( ILQ ) THEN
  1145. DO 240 JR = 1, N
  1146. TEMP = Q( JR, J )+V( 2 )*Q( JR, J+1 )+V( 3 )*
  1147. $ Q( JR, J+2 )
  1148. Q( JR, J ) = Q( JR, J ) - TEMP*TAU
  1149. Q( JR, J+1 ) = Q( JR, J+1 ) - TEMP*T2
  1150. Q( JR, J+2 ) = Q( JR, J+2 ) - TEMP*T3
  1151. 240 CONTINUE
  1152. END IF
  1153. *
  1154. * Zero j-th column of B (see DLAGBC for details)
  1155. *
  1156. * Swap rows to pivot
  1157. *
  1158. ILPIVT = .FALSE.
  1159. TEMP = MAX( ABS( T( J+1, J+1 ) ), ABS( T( J+1, J+2 ) ) )
  1160. TEMP2 = MAX( ABS( T( J+2, J+1 ) ), ABS( T( J+2, J+2 ) ) )
  1161. IF( MAX( TEMP, TEMP2 ).LT.SAFMIN ) THEN
  1162. SCALE = ZERO
  1163. U1 = ONE
  1164. U2 = ZERO
  1165. GO TO 250
  1166. ELSE IF( TEMP.GE.TEMP2 ) THEN
  1167. W11 = T( J+1, J+1 )
  1168. W21 = T( J+2, J+1 )
  1169. W12 = T( J+1, J+2 )
  1170. W22 = T( J+2, J+2 )
  1171. U1 = T( J+1, J )
  1172. U2 = T( J+2, J )
  1173. ELSE
  1174. W21 = T( J+1, J+1 )
  1175. W11 = T( J+2, J+1 )
  1176. W22 = T( J+1, J+2 )
  1177. W12 = T( J+2, J+2 )
  1178. U2 = T( J+1, J )
  1179. U1 = T( J+2, J )
  1180. END IF
  1181. *
  1182. * Swap columns if nec.
  1183. *
  1184. IF( ABS( W12 ).GT.ABS( W11 ) ) THEN
  1185. ILPIVT = .TRUE.
  1186. TEMP = W12
  1187. TEMP2 = W22
  1188. W12 = W11
  1189. W22 = W21
  1190. W11 = TEMP
  1191. W21 = TEMP2
  1192. END IF
  1193. *
  1194. * LU-factor
  1195. *
  1196. TEMP = W21 / W11
  1197. U2 = U2 - TEMP*U1
  1198. W22 = W22 - TEMP*W12
  1199. W21 = ZERO
  1200. *
  1201. * Compute SCALE
  1202. *
  1203. SCALE = ONE
  1204. IF( ABS( W22 ).LT.SAFMIN ) THEN
  1205. SCALE = ZERO
  1206. U2 = ONE
  1207. U1 = -W12 / W11
  1208. GO TO 250
  1209. END IF
  1210. IF( ABS( W22 ).LT.ABS( U2 ) )
  1211. $ SCALE = ABS( W22 / U2 )
  1212. IF( ABS( W11 ).LT.ABS( U1 ) )
  1213. $ SCALE = MIN( SCALE, ABS( W11 / U1 ) )
  1214. *
  1215. * Solve
  1216. *
  1217. U2 = ( SCALE*U2 ) / W22
  1218. U1 = ( SCALE*U1-W12*U2 ) / W11
  1219. *
  1220. 250 CONTINUE
  1221. IF( ILPIVT ) THEN
  1222. TEMP = U2
  1223. U2 = U1
  1224. U1 = TEMP
  1225. END IF
  1226. *
  1227. * Compute Householder Vector
  1228. *
  1229. T1 = SQRT( SCALE**2+U1**2+U2**2 )
  1230. TAU = ONE + SCALE / T1
  1231. VS = -ONE / ( SCALE+T1 )
  1232. V( 1 ) = ONE
  1233. V( 2 ) = VS*U1
  1234. V( 3 ) = VS*U2
  1235. *
  1236. * Apply transformations from the right.
  1237. *
  1238. T2 = TAU*V(2)
  1239. T3 = TAU*V(3)
  1240. DO 260 JR = IFRSTM, MIN( J+3, ILAST )
  1241. TEMP = H( JR, J )+V( 2 )*H( JR, J+1 )+V( 3 )*
  1242. $ H( JR, J+2 )
  1243. H( JR, J ) = H( JR, J ) - TEMP*TAU
  1244. H( JR, J+1 ) = H( JR, J+1 ) - TEMP*T2
  1245. H( JR, J+2 ) = H( JR, J+2 ) - TEMP*T3
  1246. 260 CONTINUE
  1247. DO 270 JR = IFRSTM, J + 2
  1248. TEMP = T( JR, J )+V( 2 )*T( JR, J+1 )+V( 3 )*
  1249. $ T( JR, J+2 )
  1250. T( JR, J ) = T( JR, J ) - TEMP*TAU
  1251. T( JR, J+1 ) = T( JR, J+1 ) - TEMP*T2
  1252. T( JR, J+2 ) = T( JR, J+2 ) - TEMP*T3
  1253. 270 CONTINUE
  1254. IF( ILZ ) THEN
  1255. DO 280 JR = 1, N
  1256. TEMP = Z( JR, J )+V( 2 )*Z( JR, J+1 )+V( 3 )*
  1257. $ Z( JR, J+2 )
  1258. Z( JR, J ) = Z( JR, J ) - TEMP*TAU
  1259. Z( JR, J+1 ) = Z( JR, J+1 ) - TEMP*T2
  1260. Z( JR, J+2 ) = Z( JR, J+2 ) - TEMP*T3
  1261. 280 CONTINUE
  1262. END IF
  1263. T( J+1, J ) = ZERO
  1264. T( J+2, J ) = ZERO
  1265. 290 CONTINUE
  1266. *
  1267. * Last elements: Use Givens rotations
  1268. *
  1269. * Rotations from the left
  1270. *
  1271. J = ILAST - 1
  1272. TEMP = H( J, J-1 )
  1273. CALL DLARTG( TEMP, H( J+1, J-1 ), C, S, H( J, J-1 ) )
  1274. H( J+1, J-1 ) = ZERO
  1275. *
  1276. DO 300 JC = J, ILASTM
  1277. TEMP = C*H( J, JC ) + S*H( J+1, JC )
  1278. H( J+1, JC ) = -S*H( J, JC ) + C*H( J+1, JC )
  1279. H( J, JC ) = TEMP
  1280. TEMP2 = C*T( J, JC ) + S*T( J+1, JC )
  1281. T( J+1, JC ) = -S*T( J, JC ) + C*T( J+1, JC )
  1282. T( J, JC ) = TEMP2
  1283. 300 CONTINUE
  1284. IF( ILQ ) THEN
  1285. DO 310 JR = 1, N
  1286. TEMP = C*Q( JR, J ) + S*Q( JR, J+1 )
  1287. Q( JR, J+1 ) = -S*Q( JR, J ) + C*Q( JR, J+1 )
  1288. Q( JR, J ) = TEMP
  1289. 310 CONTINUE
  1290. END IF
  1291. *
  1292. * Rotations from the right.
  1293. *
  1294. TEMP = T( J+1, J+1 )
  1295. CALL DLARTG( TEMP, T( J+1, J ), C, S, T( J+1, J+1 ) )
  1296. T( J+1, J ) = ZERO
  1297. *
  1298. DO 320 JR = IFRSTM, ILAST
  1299. TEMP = C*H( JR, J+1 ) + S*H( JR, J )
  1300. H( JR, J ) = -S*H( JR, J+1 ) + C*H( JR, J )
  1301. H( JR, J+1 ) = TEMP
  1302. 320 CONTINUE
  1303. DO 330 JR = IFRSTM, ILAST - 1
  1304. TEMP = C*T( JR, J+1 ) + S*T( JR, J )
  1305. T( JR, J ) = -S*T( JR, J+1 ) + C*T( JR, J )
  1306. T( JR, J+1 ) = TEMP
  1307. 330 CONTINUE
  1308. IF( ILZ ) THEN
  1309. DO 340 JR = 1, N
  1310. TEMP = C*Z( JR, J+1 ) + S*Z( JR, J )
  1311. Z( JR, J ) = -S*Z( JR, J+1 ) + C*Z( JR, J )
  1312. Z( JR, J+1 ) = TEMP
  1313. 340 CONTINUE
  1314. END IF
  1315. *
  1316. * End of Double-Shift code
  1317. *
  1318. END IF
  1319. *
  1320. GO TO 350
  1321. *
  1322. * End of iteration loop
  1323. *
  1324. 350 CONTINUE
  1325. 360 CONTINUE
  1326. *
  1327. * Drop-through = non-convergence
  1328. *
  1329. INFO = ILAST
  1330. GO TO 420
  1331. *
  1332. * Successful completion of all QZ steps
  1333. *
  1334. 380 CONTINUE
  1335. *
  1336. * Set Eigenvalues 1:ILO-1
  1337. *
  1338. DO 410 J = 1, ILO - 1
  1339. IF( T( J, J ).LT.ZERO ) THEN
  1340. IF( ILSCHR ) THEN
  1341. DO 390 JR = 1, J
  1342. H( JR, J ) = -H( JR, J )
  1343. T( JR, J ) = -T( JR, J )
  1344. 390 CONTINUE
  1345. ELSE
  1346. H( J, J ) = -H( J, J )
  1347. T( J, J ) = -T( J, J )
  1348. END IF
  1349. IF( ILZ ) THEN
  1350. DO 400 JR = 1, N
  1351. Z( JR, J ) = -Z( JR, J )
  1352. 400 CONTINUE
  1353. END IF
  1354. END IF
  1355. ALPHAR( J ) = H( J, J )
  1356. ALPHAI( J ) = ZERO
  1357. BETA( J ) = T( J, J )
  1358. 410 CONTINUE
  1359. *
  1360. * Normal Termination
  1361. *
  1362. INFO = 0
  1363. *
  1364. * Exit (other than argument error) -- return optimal workspace size
  1365. *
  1366. 420 CONTINUE
  1367. WORK( 1 ) = DBLE( N )
  1368. RETURN
  1369. *
  1370. * End of DHGEQZ
  1371. *
  1372. END