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.

shgeqz.f 46 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373
  1. *> \brief \b SHGEQZ
  2. *
  3. * =========== DOCUMENTATION ===========
  4. *
  5. * Online html documentation available at
  6. * http://www.netlib.org/lapack/explore-html/
  7. *
  8. *> \htmlonly
  9. *> Download SHGEQZ + dependencies
  10. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/shgeqz.f">
  11. *> [TGZ]</a>
  12. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/shgeqz.f">
  13. *> [ZIP]</a>
  14. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/shgeqz.f">
  15. *> [TXT]</a>
  16. *> \endhtmlonly
  17. *
  18. * Definition:
  19. * ===========
  20. *
  21. * SUBROUTINE SHGEQZ( 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. * REAL 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. *> SHGEQZ 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 SGGHRD.
  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 SGGHRD 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 REAL 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 REAL 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 REAL 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 REAL 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 REAL 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 REAL 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 REAL 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 REAL 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 hgeqz
  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 SHGEQZ( 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. REAL 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. REAL HALF, ZERO, ONE, SAFETY
  324. PARAMETER ( HALF = 0.5E+0, ZERO = 0.0E+0, ONE = 1.0E+0,
  325. $ SAFETY = 1.0E+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. REAL 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. REAL V( 3 )
  346. * ..
  347. * .. External Functions ..
  348. LOGICAL LSAME
  349. REAL SLAMCH, SLANHS, SLAPY2, SLAPY3, SROUNDUP_LWORK
  350. EXTERNAL LSAME, SLAMCH, SLANHS, SLAPY2, SLAPY3,
  351. $ SROUNDUP_LWORK
  352. * ..
  353. * .. External Subroutines ..
  354. EXTERNAL SLAG2, SLARFG, SLARTG, SLASET, SLASV2, SROT,
  355. $ XERBLA
  356. * ..
  357. * .. Intrinsic Functions ..
  358. INTRINSIC ABS, MAX, MIN, REAL, SQRT
  359. * ..
  360. * .. Executable Statements ..
  361. *
  362. * Decode JOB, COMPQ, COMPZ
  363. *
  364. IF( LSAME( JOB, 'E' ) ) THEN
  365. ILSCHR = .FALSE.
  366. ISCHUR = 1
  367. ELSE IF( LSAME( JOB, 'S' ) ) THEN
  368. ILSCHR = .TRUE.
  369. ISCHUR = 2
  370. ELSE
  371. ISCHUR = 0
  372. END IF
  373. *
  374. IF( LSAME( COMPQ, 'N' ) ) THEN
  375. ILQ = .FALSE.
  376. ICOMPQ = 1
  377. ELSE IF( LSAME( COMPQ, 'V' ) ) THEN
  378. ILQ = .TRUE.
  379. ICOMPQ = 2
  380. ELSE IF( LSAME( COMPQ, 'I' ) ) THEN
  381. ILQ = .TRUE.
  382. ICOMPQ = 3
  383. ELSE
  384. ICOMPQ = 0
  385. END IF
  386. *
  387. IF( LSAME( COMPZ, 'N' ) ) THEN
  388. ILZ = .FALSE.
  389. ICOMPZ = 1
  390. ELSE IF( LSAME( COMPZ, 'V' ) ) THEN
  391. ILZ = .TRUE.
  392. ICOMPZ = 2
  393. ELSE IF( LSAME( COMPZ, 'I' ) ) THEN
  394. ILZ = .TRUE.
  395. ICOMPZ = 3
  396. ELSE
  397. ICOMPZ = 0
  398. END IF
  399. *
  400. * Check Argument Values
  401. *
  402. INFO = 0
  403. WORK( 1 ) = MAX( 1, N )
  404. LQUERY = ( LWORK.EQ.-1 )
  405. IF( ISCHUR.EQ.0 ) THEN
  406. INFO = -1
  407. ELSE IF( ICOMPQ.EQ.0 ) THEN
  408. INFO = -2
  409. ELSE IF( ICOMPZ.EQ.0 ) THEN
  410. INFO = -3
  411. ELSE IF( N.LT.0 ) THEN
  412. INFO = -4
  413. ELSE IF( ILO.LT.1 ) THEN
  414. INFO = -5
  415. ELSE IF( IHI.GT.N .OR. IHI.LT.ILO-1 ) THEN
  416. INFO = -6
  417. ELSE IF( LDH.LT.N ) THEN
  418. INFO = -8
  419. ELSE IF( LDT.LT.N ) THEN
  420. INFO = -10
  421. ELSE IF( LDQ.LT.1 .OR. ( ILQ .AND. LDQ.LT.N ) ) THEN
  422. INFO = -15
  423. ELSE IF( LDZ.LT.1 .OR. ( ILZ .AND. LDZ.LT.N ) ) THEN
  424. INFO = -17
  425. ELSE IF( LWORK.LT.MAX( 1, N ) .AND. .NOT.LQUERY ) THEN
  426. INFO = -19
  427. END IF
  428. IF( INFO.NE.0 ) THEN
  429. CALL XERBLA( 'SHGEQZ', -INFO )
  430. RETURN
  431. ELSE IF( LQUERY ) THEN
  432. RETURN
  433. END IF
  434. *
  435. * Quick return if possible
  436. *
  437. IF( N.LE.0 ) THEN
  438. WORK( 1 ) = REAL( 1 )
  439. RETURN
  440. END IF
  441. *
  442. * Initialize Q and Z
  443. *
  444. IF( ICOMPQ.EQ.3 )
  445. $ CALL SLASET( 'Full', N, N, ZERO, ONE, Q, LDQ )
  446. IF( ICOMPZ.EQ.3 )
  447. $ CALL SLASET( 'Full', N, N, ZERO, ONE, Z, LDZ )
  448. *
  449. * Machine Constants
  450. *
  451. IN = IHI + 1 - ILO
  452. SAFMIN = SLAMCH( 'S' )
  453. SAFMAX = ONE / SAFMIN
  454. ULP = SLAMCH( 'E' )*SLAMCH( 'B' )
  455. ANORM = SLANHS( 'F', IN, H( ILO, ILO ), LDH, WORK )
  456. BNORM = SLANHS( 'F', IN, T( ILO, ILO ), LDT, WORK )
  457. ATOL = MAX( SAFMIN, ULP*ANORM )
  458. BTOL = MAX( SAFMIN, ULP*BNORM )
  459. ASCALE = ONE / MAX( SAFMIN, ANORM )
  460. BSCALE = ONE / MAX( SAFMIN, BNORM )
  461. *
  462. * Set Eigenvalues IHI+1:N
  463. *
  464. DO 30 J = IHI + 1, N
  465. IF( T( J, J ).LT.ZERO ) THEN
  466. IF( ILSCHR ) THEN
  467. DO 10 JR = 1, J
  468. H( JR, J ) = -H( JR, J )
  469. T( JR, J ) = -T( JR, J )
  470. 10 CONTINUE
  471. ELSE
  472. H( J, J ) = -H( J, J )
  473. T( J, J ) = -T( J, J )
  474. END IF
  475. IF( ILZ ) THEN
  476. DO 20 JR = 1, N
  477. Z( JR, J ) = -Z( JR, J )
  478. 20 CONTINUE
  479. END IF
  480. END IF
  481. ALPHAR( J ) = H( J, J )
  482. ALPHAI( J ) = ZERO
  483. BETA( J ) = T( J, J )
  484. 30 CONTINUE
  485. *
  486. * If IHI < ILO, skip QZ steps
  487. *
  488. IF( IHI.LT.ILO )
  489. $ GO TO 380
  490. *
  491. * MAIN QZ ITERATION LOOP
  492. *
  493. * Initialize dynamic indices
  494. *
  495. * Eigenvalues ILAST+1:N have been found.
  496. * Column operations modify rows IFRSTM:whatever.
  497. * Row operations modify columns whatever:ILASTM.
  498. *
  499. * If only eigenvalues are being computed, then
  500. * IFRSTM is the row of the last splitting row above row ILAST;
  501. * this is always at least ILO.
  502. * IITER counts iterations since the last eigenvalue was found,
  503. * to tell when to use an extraordinary shift.
  504. * MAXIT is the maximum number of QZ sweeps allowed.
  505. *
  506. ILAST = IHI
  507. IF( ILSCHR ) THEN
  508. IFRSTM = 1
  509. ILASTM = N
  510. ELSE
  511. IFRSTM = ILO
  512. ILASTM = IHI
  513. END IF
  514. IITER = 0
  515. ESHIFT = ZERO
  516. MAXIT = 30*( IHI-ILO+1 )
  517. *
  518. DO 360 JITER = 1, MAXIT
  519. *
  520. * Split the matrix if possible.
  521. *
  522. * Two tests:
  523. * 1: H(j,j-1)=0 or j=ILO
  524. * 2: T(j,j)=0
  525. *
  526. IF( ILAST.EQ.ILO ) THEN
  527. *
  528. * Special case: j=ILAST
  529. *
  530. GO TO 80
  531. ELSE
  532. IF( ABS( H( ILAST, ILAST-1 ) ).LE.MAX( SAFMIN, ULP*(
  533. $ ABS( H( ILAST, ILAST ) ) + ABS( H( ILAST-1, ILAST-1 ) )
  534. $ ) ) ) THEN
  535. H( ILAST, ILAST-1 ) = ZERO
  536. GO TO 80
  537. END IF
  538. END IF
  539. *
  540. IF( ABS( T( ILAST, ILAST ) ).LE.BTOL ) THEN
  541. T( ILAST, ILAST ) = ZERO
  542. GO TO 70
  543. END IF
  544. *
  545. * General case: j<ILAST
  546. *
  547. DO 60 J = ILAST - 1, ILO, -1
  548. *
  549. * Test 1: for H(j,j-1)=0 or j=ILO
  550. *
  551. IF( J.EQ.ILO ) THEN
  552. ILAZRO = .TRUE.
  553. ELSE
  554. IF( ABS( H( J, J-1 ) ).LE.MAX( SAFMIN, ULP*(
  555. $ ABS( H( J, J ) ) + ABS( H( J-1, J-1 ) )
  556. $ ) ) ) THEN
  557. H( J, J-1 ) = ZERO
  558. ILAZRO = .TRUE.
  559. ELSE
  560. ILAZRO = .FALSE.
  561. END IF
  562. END IF
  563. *
  564. * Test 2: for T(j,j)=0
  565. *
  566. IF( ABS( T( J, J ) ).LT.BTOL ) THEN
  567. T( J, J ) = ZERO
  568. *
  569. * Test 1a: Check for 2 consecutive small subdiagonals in A
  570. *
  571. ILAZR2 = .FALSE.
  572. IF( .NOT.ILAZRO ) THEN
  573. TEMP = ABS( H( J, J-1 ) )
  574. TEMP2 = ABS( H( J, J ) )
  575. TEMPR = MAX( TEMP, TEMP2 )
  576. IF( TEMPR.LT.ONE .AND. TEMPR.NE.ZERO ) THEN
  577. TEMP = TEMP / TEMPR
  578. TEMP2 = TEMP2 / TEMPR
  579. END IF
  580. IF( TEMP*( ASCALE*ABS( H( J+1, J ) ) ).LE.TEMP2*
  581. $ ( ASCALE*ATOL ) )ILAZR2 = .TRUE.
  582. END IF
  583. *
  584. * If both tests pass (1 & 2), i.e., the leading diagonal
  585. * element of B in the block is zero, split a 1x1 block off
  586. * at the top. (I.e., at the J-th row/column) The leading
  587. * diagonal element of the remainder can also be zero, so
  588. * this may have to be done repeatedly.
  589. *
  590. IF( ILAZRO .OR. ILAZR2 ) THEN
  591. DO 40 JCH = J, ILAST - 1
  592. TEMP = H( JCH, JCH )
  593. CALL SLARTG( TEMP, H( JCH+1, JCH ), C, S,
  594. $ H( JCH, JCH ) )
  595. H( JCH+1, JCH ) = ZERO
  596. CALL SROT( ILASTM-JCH, H( JCH, JCH+1 ), LDH,
  597. $ H( JCH+1, JCH+1 ), LDH, C, S )
  598. CALL SROT( ILASTM-JCH, T( JCH, JCH+1 ), LDT,
  599. $ T( JCH+1, JCH+1 ), LDT, C, S )
  600. IF( ILQ )
  601. $ CALL SROT( N, Q( 1, JCH ), 1, Q( 1, JCH+1 ), 1,
  602. $ C, S )
  603. IF( ILAZR2 )
  604. $ H( JCH, JCH-1 ) = H( JCH, JCH-1 )*C
  605. ILAZR2 = .FALSE.
  606. IF( ABS( T( JCH+1, JCH+1 ) ).GE.BTOL ) THEN
  607. IF( JCH+1.GE.ILAST ) THEN
  608. GO TO 80
  609. ELSE
  610. IFIRST = JCH + 1
  611. GO TO 110
  612. END IF
  613. END IF
  614. T( JCH+1, JCH+1 ) = ZERO
  615. 40 CONTINUE
  616. GO TO 70
  617. ELSE
  618. *
  619. * Only test 2 passed -- chase the zero to T(ILAST,ILAST)
  620. * Then process as in the case T(ILAST,ILAST)=0
  621. *
  622. DO 50 JCH = J, ILAST - 1
  623. TEMP = T( JCH, JCH+1 )
  624. CALL SLARTG( TEMP, T( JCH+1, JCH+1 ), C, S,
  625. $ T( JCH, JCH+1 ) )
  626. T( JCH+1, JCH+1 ) = ZERO
  627. IF( JCH.LT.ILASTM-1 )
  628. $ CALL SROT( ILASTM-JCH-1, T( JCH, JCH+2 ), LDT,
  629. $ T( JCH+1, JCH+2 ), LDT, C, S )
  630. CALL SROT( ILASTM-JCH+2, H( JCH, JCH-1 ), LDH,
  631. $ H( JCH+1, JCH-1 ), LDH, C, S )
  632. IF( ILQ )
  633. $ CALL SROT( N, Q( 1, JCH ), 1, Q( 1, JCH+1 ), 1,
  634. $ C, S )
  635. TEMP = H( JCH+1, JCH )
  636. CALL SLARTG( TEMP, H( JCH+1, JCH-1 ), C, S,
  637. $ H( JCH+1, JCH ) )
  638. H( JCH+1, JCH-1 ) = ZERO
  639. CALL SROT( JCH+1-IFRSTM, H( IFRSTM, JCH ), 1,
  640. $ H( IFRSTM, JCH-1 ), 1, C, S )
  641. CALL SROT( JCH-IFRSTM, T( IFRSTM, JCH ), 1,
  642. $ T( IFRSTM, JCH-1 ), 1, C, S )
  643. IF( ILZ )
  644. $ CALL SROT( N, Z( 1, JCH ), 1, Z( 1, JCH-1 ), 1,
  645. $ C, S )
  646. 50 CONTINUE
  647. GO TO 70
  648. END IF
  649. ELSE IF( ILAZRO ) THEN
  650. *
  651. * Only test 1 passed -- work on J:ILAST
  652. *
  653. IFIRST = J
  654. GO TO 110
  655. END IF
  656. *
  657. * Neither test passed -- try next J
  658. *
  659. 60 CONTINUE
  660. *
  661. * (Drop-through is "impossible")
  662. *
  663. INFO = N + 1
  664. GO TO 420
  665. *
  666. * T(ILAST,ILAST)=0 -- clear H(ILAST,ILAST-1) to split off a
  667. * 1x1 block.
  668. *
  669. 70 CONTINUE
  670. TEMP = H( ILAST, ILAST )
  671. CALL SLARTG( TEMP, H( ILAST, ILAST-1 ), C, S,
  672. $ H( ILAST, ILAST ) )
  673. H( ILAST, ILAST-1 ) = ZERO
  674. CALL SROT( ILAST-IFRSTM, H( IFRSTM, ILAST ), 1,
  675. $ H( IFRSTM, ILAST-1 ), 1, C, S )
  676. CALL SROT( ILAST-IFRSTM, T( IFRSTM, ILAST ), 1,
  677. $ T( IFRSTM, ILAST-1 ), 1, C, S )
  678. IF( ILZ )
  679. $ CALL SROT( N, Z( 1, ILAST ), 1, Z( 1, ILAST-1 ), 1, C, S )
  680. *
  681. * H(ILAST,ILAST-1)=0 -- Standardize B, set ALPHAR, ALPHAI,
  682. * and BETA
  683. *
  684. 80 CONTINUE
  685. IF( T( ILAST, ILAST ).LT.ZERO ) THEN
  686. IF( ILSCHR ) THEN
  687. DO 90 J = IFRSTM, ILAST
  688. H( J, ILAST ) = -H( J, ILAST )
  689. T( J, ILAST ) = -T( J, ILAST )
  690. 90 CONTINUE
  691. ELSE
  692. H( ILAST, ILAST ) = -H( ILAST, ILAST )
  693. T( ILAST, ILAST ) = -T( ILAST, ILAST )
  694. END IF
  695. IF( ILZ ) THEN
  696. DO 100 J = 1, N
  697. Z( J, ILAST ) = -Z( J, ILAST )
  698. 100 CONTINUE
  699. END IF
  700. END IF
  701. ALPHAR( ILAST ) = H( ILAST, ILAST )
  702. ALPHAI( ILAST ) = ZERO
  703. BETA( ILAST ) = T( ILAST, ILAST )
  704. *
  705. * Go to next block -- exit if finished.
  706. *
  707. ILAST = ILAST - 1
  708. IF( ILAST.LT.ILO )
  709. $ GO TO 380
  710. *
  711. * Reset counters
  712. *
  713. IITER = 0
  714. ESHIFT = ZERO
  715. IF( .NOT.ILSCHR ) THEN
  716. ILASTM = ILAST
  717. IF( IFRSTM.GT.ILAST )
  718. $ IFRSTM = ILO
  719. END IF
  720. GO TO 350
  721. *
  722. * QZ step
  723. *
  724. * This iteration only involves rows/columns IFIRST:ILAST. We
  725. * assume IFIRST < ILAST, and that the diagonal of B is non-zero.
  726. *
  727. 110 CONTINUE
  728. IITER = IITER + 1
  729. IF( .NOT.ILSCHR ) THEN
  730. IFRSTM = IFIRST
  731. END IF
  732. *
  733. * Compute single shifts.
  734. *
  735. * At this point, IFIRST < ILAST, and the diagonal elements of
  736. * T(IFIRST:ILAST,IFIRST,ILAST) are larger than BTOL (in
  737. * magnitude)
  738. *
  739. IF( ( IITER / 10 )*10.EQ.IITER ) THEN
  740. *
  741. * Exceptional shift. Chosen for no particularly good reason.
  742. * (Single shift only.)
  743. *
  744. IF( ( REAL( MAXIT )*SAFMIN )*ABS( H( ILAST, ILAST-1 ) ).LT.
  745. $ ABS( T( ILAST-1, ILAST-1 ) ) ) THEN
  746. ESHIFT = H( ILAST, ILAST-1 ) /
  747. $ T( ILAST-1, ILAST-1 )
  748. ELSE
  749. ESHIFT = ESHIFT + ONE / ( SAFMIN*REAL( MAXIT ) )
  750. END IF
  751. S1 = ONE
  752. WR = ESHIFT
  753. *
  754. ELSE
  755. *
  756. * Shifts based on the generalized eigenvalues of the
  757. * bottom-right 2x2 block of A and B. The first eigenvalue
  758. * returned by SLAG2 is the Wilkinson shift (AEP p.512),
  759. *
  760. CALL SLAG2( H( ILAST-1, ILAST-1 ), LDH,
  761. $ T( ILAST-1, ILAST-1 ), LDT, SAFMIN*SAFETY, S1,
  762. $ S2, WR, WR2, WI )
  763. *
  764. IF ( ABS( (WR/S1)*T( ILAST, ILAST ) - H( ILAST, ILAST ) )
  765. $ .GT. ABS( (WR2/S2)*T( ILAST, ILAST )
  766. $ - H( ILAST, ILAST ) ) ) THEN
  767. TEMP = WR
  768. WR = WR2
  769. WR2 = TEMP
  770. TEMP = S1
  771. S1 = S2
  772. S2 = TEMP
  773. END IF
  774. TEMP = MAX( S1, SAFMIN*MAX( ONE, ABS( WR ), ABS( WI ) ) )
  775. IF( WI.NE.ZERO )
  776. $ GO TO 200
  777. END IF
  778. *
  779. * Fiddle with shift to avoid overflow
  780. *
  781. TEMP = MIN( ASCALE, ONE )*( HALF*SAFMAX )
  782. IF( S1.GT.TEMP ) THEN
  783. SCALE = TEMP / S1
  784. ELSE
  785. SCALE = ONE
  786. END IF
  787. *
  788. TEMP = MIN( BSCALE, ONE )*( HALF*SAFMAX )
  789. IF( ABS( WR ).GT.TEMP )
  790. $ SCALE = MIN( SCALE, TEMP / ABS( WR ) )
  791. S1 = SCALE*S1
  792. WR = SCALE*WR
  793. *
  794. * Now check for two consecutive small subdiagonals.
  795. *
  796. DO 120 J = ILAST - 1, IFIRST + 1, -1
  797. ISTART = J
  798. TEMP = ABS( S1*H( J, J-1 ) )
  799. TEMP2 = ABS( S1*H( J, J )-WR*T( J, J ) )
  800. TEMPR = MAX( TEMP, TEMP2 )
  801. IF( TEMPR.LT.ONE .AND. TEMPR.NE.ZERO ) THEN
  802. TEMP = TEMP / TEMPR
  803. TEMP2 = TEMP2 / TEMPR
  804. END IF
  805. IF( ABS( ( ASCALE*H( J+1, J ) )*TEMP ).LE.( ASCALE*ATOL )*
  806. $ TEMP2 )GO TO 130
  807. 120 CONTINUE
  808. *
  809. ISTART = IFIRST
  810. 130 CONTINUE
  811. *
  812. * Do an implicit single-shift QZ sweep.
  813. *
  814. * Initial Q
  815. *
  816. TEMP = S1*H( ISTART, ISTART ) - WR*T( ISTART, ISTART )
  817. TEMP2 = S1*H( ISTART+1, ISTART )
  818. CALL SLARTG( TEMP, TEMP2, C, S, TEMPR )
  819. *
  820. * Sweep
  821. *
  822. DO 190 J = ISTART, ILAST - 1
  823. IF( J.GT.ISTART ) THEN
  824. TEMP = H( J, J-1 )
  825. CALL SLARTG( TEMP, H( J+1, J-1 ), C, S, H( J, J-1 ) )
  826. H( J+1, J-1 ) = ZERO
  827. END IF
  828. *
  829. DO 140 JC = J, ILASTM
  830. TEMP = C*H( J, JC ) + S*H( J+1, JC )
  831. H( J+1, JC ) = -S*H( J, JC ) + C*H( J+1, JC )
  832. H( J, JC ) = TEMP
  833. TEMP2 = C*T( J, JC ) + S*T( J+1, JC )
  834. T( J+1, JC ) = -S*T( J, JC ) + C*T( J+1, JC )
  835. T( J, JC ) = TEMP2
  836. 140 CONTINUE
  837. IF( ILQ ) THEN
  838. DO 150 JR = 1, N
  839. TEMP = C*Q( JR, J ) + S*Q( JR, J+1 )
  840. Q( JR, J+1 ) = -S*Q( JR, J ) + C*Q( JR, J+1 )
  841. Q( JR, J ) = TEMP
  842. 150 CONTINUE
  843. END IF
  844. *
  845. TEMP = T( J+1, J+1 )
  846. CALL SLARTG( TEMP, T( J+1, J ), C, S, T( J+1, J+1 ) )
  847. T( J+1, J ) = ZERO
  848. *
  849. DO 160 JR = IFRSTM, MIN( J+2, ILAST )
  850. TEMP = C*H( JR, J+1 ) + S*H( JR, J )
  851. H( JR, J ) = -S*H( JR, J+1 ) + C*H( JR, J )
  852. H( JR, J+1 ) = TEMP
  853. 160 CONTINUE
  854. DO 170 JR = IFRSTM, J
  855. TEMP = C*T( JR, J+1 ) + S*T( JR, J )
  856. T( JR, J ) = -S*T( JR, J+1 ) + C*T( JR, J )
  857. T( JR, J+1 ) = TEMP
  858. 170 CONTINUE
  859. IF( ILZ ) THEN
  860. DO 180 JR = 1, N
  861. TEMP = C*Z( JR, J+1 ) + S*Z( JR, J )
  862. Z( JR, J ) = -S*Z( JR, J+1 ) + C*Z( JR, J )
  863. Z( JR, J+1 ) = TEMP
  864. 180 CONTINUE
  865. END IF
  866. 190 CONTINUE
  867. *
  868. GO TO 350
  869. *
  870. * Use Francis double-shift
  871. *
  872. * Note: the Francis double-shift should work with real shifts,
  873. * but only if the block is at least 3x3.
  874. * This code may break if this point is reached with
  875. * a 2x2 block with real eigenvalues.
  876. *
  877. 200 CONTINUE
  878. IF( IFIRST+1.EQ.ILAST ) THEN
  879. *
  880. * Special case -- 2x2 block with complex eigenvectors
  881. *
  882. * Step 1: Standardize, that is, rotate so that
  883. *
  884. * ( B11 0 )
  885. * B = ( ) with B11 non-negative.
  886. * ( 0 B22 )
  887. *
  888. CALL SLASV2( T( ILAST-1, ILAST-1 ), T( ILAST-1, ILAST ),
  889. $ T( ILAST, ILAST ), B22, B11, SR, CR, SL, CL )
  890. *
  891. IF( B11.LT.ZERO ) THEN
  892. CR = -CR
  893. SR = -SR
  894. B11 = -B11
  895. B22 = -B22
  896. END IF
  897. *
  898. CALL SROT( ILASTM+1-IFIRST, H( ILAST-1, ILAST-1 ), LDH,
  899. $ H( ILAST, ILAST-1 ), LDH, CL, SL )
  900. CALL SROT( ILAST+1-IFRSTM, H( IFRSTM, ILAST-1 ), 1,
  901. $ H( IFRSTM, ILAST ), 1, CR, SR )
  902. *
  903. IF( ILAST.LT.ILASTM )
  904. $ CALL SROT( ILASTM-ILAST, T( ILAST-1, ILAST+1 ), LDT,
  905. $ T( ILAST, ILAST+1 ), LDT, CL, SL )
  906. IF( IFRSTM.LT.ILAST-1 )
  907. $ CALL SROT( IFIRST-IFRSTM, T( IFRSTM, ILAST-1 ), 1,
  908. $ T( IFRSTM, ILAST ), 1, CR, SR )
  909. *
  910. IF( ILQ )
  911. $ CALL SROT( N, Q( 1, ILAST-1 ), 1, Q( 1, ILAST ), 1, CL,
  912. $ SL )
  913. IF( ILZ )
  914. $ CALL SROT( N, Z( 1, ILAST-1 ), 1, Z( 1, ILAST ), 1, CR,
  915. $ SR )
  916. *
  917. T( ILAST-1, ILAST-1 ) = B11
  918. T( ILAST-1, ILAST ) = ZERO
  919. T( ILAST, ILAST-1 ) = ZERO
  920. T( ILAST, ILAST ) = B22
  921. *
  922. * If B22 is negative, negate column ILAST
  923. *
  924. IF( B22.LT.ZERO ) THEN
  925. DO 210 J = IFRSTM, ILAST
  926. H( J, ILAST ) = -H( J, ILAST )
  927. T( J, ILAST ) = -T( J, ILAST )
  928. 210 CONTINUE
  929. *
  930. IF( ILZ ) THEN
  931. DO 220 J = 1, N
  932. Z( J, ILAST ) = -Z( J, ILAST )
  933. 220 CONTINUE
  934. END IF
  935. B22 = -B22
  936. END IF
  937. *
  938. * Step 2: Compute ALPHAR, ALPHAI, and BETA (see refs.)
  939. *
  940. * Recompute shift
  941. *
  942. CALL SLAG2( H( ILAST-1, ILAST-1 ), LDH,
  943. $ T( ILAST-1, ILAST-1 ), LDT, SAFMIN*SAFETY, S1,
  944. $ TEMP, WR, TEMP2, WI )
  945. *
  946. * If standardization has perturbed the shift onto real line,
  947. * do another (real single-shift) QR step.
  948. *
  949. IF( WI.EQ.ZERO )
  950. $ GO TO 350
  951. S1INV = ONE / S1
  952. *
  953. * Do EISPACK (QZVAL) computation of alpha and beta
  954. *
  955. A11 = H( ILAST-1, ILAST-1 )
  956. A21 = H( ILAST, ILAST-1 )
  957. A12 = H( ILAST-1, ILAST )
  958. A22 = H( ILAST, ILAST )
  959. *
  960. * Compute complex Givens rotation on right
  961. * (Assume some element of C = (sA - wB) > unfl )
  962. * __
  963. * (sA - wB) ( CZ -SZ )
  964. * ( SZ CZ )
  965. *
  966. C11R = S1*A11 - WR*B11
  967. C11I = -WI*B11
  968. C12 = S1*A12
  969. C21 = S1*A21
  970. C22R = S1*A22 - WR*B22
  971. C22I = -WI*B22
  972. *
  973. IF( ABS( C11R )+ABS( C11I )+ABS( C12 ).GT.ABS( C21 )+
  974. $ ABS( C22R )+ABS( C22I ) ) THEN
  975. T1 = SLAPY3( C12, C11R, C11I )
  976. CZ = C12 / T1
  977. SZR = -C11R / T1
  978. SZI = -C11I / T1
  979. ELSE
  980. CZ = SLAPY2( C22R, C22I )
  981. IF( CZ.LE.SAFMIN ) THEN
  982. CZ = ZERO
  983. SZR = ONE
  984. SZI = ZERO
  985. ELSE
  986. TEMPR = C22R / CZ
  987. TEMPI = C22I / CZ
  988. T1 = SLAPY2( CZ, C21 )
  989. CZ = CZ / T1
  990. SZR = -C21*TEMPR / T1
  991. SZI = C21*TEMPI / T1
  992. END IF
  993. END IF
  994. *
  995. * Compute Givens rotation on left
  996. *
  997. * ( CQ SQ )
  998. * ( __ ) A or B
  999. * ( -SQ CQ )
  1000. *
  1001. AN = ABS( A11 ) + ABS( A12 ) + ABS( A21 ) + ABS( A22 )
  1002. BN = ABS( B11 ) + ABS( B22 )
  1003. WABS = ABS( WR ) + ABS( WI )
  1004. IF( S1*AN.GT.WABS*BN ) THEN
  1005. CQ = CZ*B11
  1006. SQR = SZR*B22
  1007. SQI = -SZI*B22
  1008. ELSE
  1009. A1R = CZ*A11 + SZR*A12
  1010. A1I = SZI*A12
  1011. A2R = CZ*A21 + SZR*A22
  1012. A2I = SZI*A22
  1013. CQ = SLAPY2( A1R, A1I )
  1014. IF( CQ.LE.SAFMIN ) THEN
  1015. CQ = ZERO
  1016. SQR = ONE
  1017. SQI = ZERO
  1018. ELSE
  1019. TEMPR = A1R / CQ
  1020. TEMPI = A1I / CQ
  1021. SQR = TEMPR*A2R + TEMPI*A2I
  1022. SQI = TEMPI*A2R - TEMPR*A2I
  1023. END IF
  1024. END IF
  1025. T1 = SLAPY3( CQ, SQR, SQI )
  1026. CQ = CQ / T1
  1027. SQR = SQR / T1
  1028. SQI = SQI / T1
  1029. *
  1030. * Compute diagonal elements of QBZ
  1031. *
  1032. TEMPR = SQR*SZR - SQI*SZI
  1033. TEMPI = SQR*SZI + SQI*SZR
  1034. B1R = CQ*CZ*B11 + TEMPR*B22
  1035. B1I = TEMPI*B22
  1036. B1A = SLAPY2( B1R, B1I )
  1037. B2R = CQ*CZ*B22 + TEMPR*B11
  1038. B2I = -TEMPI*B11
  1039. B2A = SLAPY2( B2R, B2I )
  1040. *
  1041. * Normalize so beta > 0, and Im( alpha1 ) > 0
  1042. *
  1043. BETA( ILAST-1 ) = B1A
  1044. BETA( ILAST ) = B2A
  1045. ALPHAR( ILAST-1 ) = ( WR*B1A )*S1INV
  1046. ALPHAI( ILAST-1 ) = ( WI*B1A )*S1INV
  1047. ALPHAR( ILAST ) = ( WR*B2A )*S1INV
  1048. ALPHAI( ILAST ) = -( WI*B2A )*S1INV
  1049. *
  1050. * Step 3: Go to next block -- exit if finished.
  1051. *
  1052. ILAST = IFIRST - 1
  1053. IF( ILAST.LT.ILO )
  1054. $ GO TO 380
  1055. *
  1056. * Reset counters
  1057. *
  1058. IITER = 0
  1059. ESHIFT = ZERO
  1060. IF( .NOT.ILSCHR ) THEN
  1061. ILASTM = ILAST
  1062. IF( IFRSTM.GT.ILAST )
  1063. $ IFRSTM = ILO
  1064. END IF
  1065. GO TO 350
  1066. ELSE
  1067. *
  1068. * Usual case: 3x3 or larger block, using Francis implicit
  1069. * double-shift
  1070. *
  1071. * 2
  1072. * Eigenvalue equation is w - c w + d = 0,
  1073. *
  1074. * -1 2 -1
  1075. * so compute 1st column of (A B ) - c A B + d
  1076. * using the formula in QZIT (from EISPACK)
  1077. *
  1078. * We assume that the block is at least 3x3
  1079. *
  1080. AD11 = ( ASCALE*H( ILAST-1, ILAST-1 ) ) /
  1081. $ ( BSCALE*T( ILAST-1, ILAST-1 ) )
  1082. AD21 = ( ASCALE*H( ILAST, ILAST-1 ) ) /
  1083. $ ( BSCALE*T( ILAST-1, ILAST-1 ) )
  1084. AD12 = ( ASCALE*H( ILAST-1, ILAST ) ) /
  1085. $ ( BSCALE*T( ILAST, ILAST ) )
  1086. AD22 = ( ASCALE*H( ILAST, ILAST ) ) /
  1087. $ ( BSCALE*T( ILAST, ILAST ) )
  1088. U12 = T( ILAST-1, ILAST ) / T( ILAST, ILAST )
  1089. AD11L = ( ASCALE*H( IFIRST, IFIRST ) ) /
  1090. $ ( BSCALE*T( IFIRST, IFIRST ) )
  1091. AD21L = ( ASCALE*H( IFIRST+1, IFIRST ) ) /
  1092. $ ( BSCALE*T( IFIRST, IFIRST ) )
  1093. AD12L = ( ASCALE*H( IFIRST, IFIRST+1 ) ) /
  1094. $ ( BSCALE*T( IFIRST+1, IFIRST+1 ) )
  1095. AD22L = ( ASCALE*H( IFIRST+1, IFIRST+1 ) ) /
  1096. $ ( BSCALE*T( IFIRST+1, IFIRST+1 ) )
  1097. AD32L = ( ASCALE*H( IFIRST+2, IFIRST+1 ) ) /
  1098. $ ( BSCALE*T( IFIRST+1, IFIRST+1 ) )
  1099. U12L = T( IFIRST, IFIRST+1 ) / T( IFIRST+1, IFIRST+1 )
  1100. *
  1101. V( 1 ) = ( AD11-AD11L )*( AD22-AD11L ) - AD12*AD21 +
  1102. $ AD21*U12*AD11L + ( AD12L-AD11L*U12L )*AD21L
  1103. V( 2 ) = ( ( AD22L-AD11L )-AD21L*U12L-( AD11-AD11L )-
  1104. $ ( AD22-AD11L )+AD21*U12 )*AD21L
  1105. V( 3 ) = AD32L*AD21L
  1106. *
  1107. ISTART = IFIRST
  1108. *
  1109. CALL SLARFG( 3, V( 1 ), V( 2 ), 1, TAU )
  1110. V( 1 ) = ONE
  1111. *
  1112. * Sweep
  1113. *
  1114. DO 290 J = ISTART, ILAST - 2
  1115. *
  1116. * All but last elements: use 3x3 Householder transforms.
  1117. *
  1118. * Zero (j-1)st column of A
  1119. *
  1120. IF( J.GT.ISTART ) THEN
  1121. V( 1 ) = H( J, J-1 )
  1122. V( 2 ) = H( J+1, J-1 )
  1123. V( 3 ) = H( J+2, J-1 )
  1124. *
  1125. CALL SLARFG( 3, H( J, J-1 ), V( 2 ), 1, TAU )
  1126. V( 1 ) = ONE
  1127. H( J+1, J-1 ) = ZERO
  1128. H( J+2, J-1 ) = ZERO
  1129. END IF
  1130. *
  1131. T2 = TAU * V( 2 )
  1132. T3 = TAU * V( 3 )
  1133. DO 230 JC = J, ILASTM
  1134. TEMP = H( J, JC )+V( 2 )*H( J+1, JC )+V( 3 )*
  1135. $ H( J+2, JC )
  1136. H( J, JC ) = H( J, JC ) - TEMP*TAU
  1137. H( J+1, JC ) = H( J+1, JC ) - TEMP*T2
  1138. H( J+2, JC ) = H( J+2, JC ) - TEMP*T3
  1139. TEMP2 = T( J, JC )+V( 2 )*T( J+1, JC )+V( 3 )*
  1140. $ T( J+2, JC )
  1141. T( J, JC ) = T( J, JC ) - TEMP2*TAU
  1142. T( J+1, JC ) = T( J+1, JC ) - TEMP2*T2
  1143. T( J+2, JC ) = T( J+2, JC ) - TEMP2*T3
  1144. 230 CONTINUE
  1145. IF( ILQ ) THEN
  1146. DO 240 JR = 1, N
  1147. TEMP = Q( JR, J )+V( 2 )*Q( JR, J+1 )+V( 3 )*
  1148. $ Q( JR, J+2 )
  1149. Q( JR, J ) = Q( JR, J ) - TEMP*TAU
  1150. Q( JR, J+1 ) = Q( JR, J+1 ) - TEMP*T2
  1151. Q( JR, J+2 ) = Q( JR, J+2 ) - TEMP*T3
  1152. 240 CONTINUE
  1153. END IF
  1154. *
  1155. * Zero j-th column of B (see SLAGBC for details)
  1156. *
  1157. * Swap rows to pivot
  1158. *
  1159. ILPIVT = .FALSE.
  1160. TEMP = MAX( ABS( T( J+1, J+1 ) ), ABS( T( J+1, J+2 ) ) )
  1161. TEMP2 = MAX( ABS( T( J+2, J+1 ) ), ABS( T( J+2, J+2 ) ) )
  1162. IF( MAX( TEMP, TEMP2 ).LT.SAFMIN ) THEN
  1163. SCALE = ZERO
  1164. U1 = ONE
  1165. U2 = ZERO
  1166. GO TO 250
  1167. ELSE IF( TEMP.GE.TEMP2 ) THEN
  1168. W11 = T( J+1, J+1 )
  1169. W21 = T( J+2, J+1 )
  1170. W12 = T( J+1, J+2 )
  1171. W22 = T( J+2, J+2 )
  1172. U1 = T( J+1, J )
  1173. U2 = T( J+2, J )
  1174. ELSE
  1175. W21 = T( J+1, J+1 )
  1176. W11 = T( J+2, J+1 )
  1177. W22 = T( J+1, J+2 )
  1178. W12 = T( J+2, J+2 )
  1179. U2 = T( J+1, J )
  1180. U1 = T( J+2, J )
  1181. END IF
  1182. *
  1183. * Swap columns if nec.
  1184. *
  1185. IF( ABS( W12 ).GT.ABS( W11 ) ) THEN
  1186. ILPIVT = .TRUE.
  1187. TEMP = W12
  1188. TEMP2 = W22
  1189. W12 = W11
  1190. W22 = W21
  1191. W11 = TEMP
  1192. W21 = TEMP2
  1193. END IF
  1194. *
  1195. * LU-factor
  1196. *
  1197. TEMP = W21 / W11
  1198. U2 = U2 - TEMP*U1
  1199. W22 = W22 - TEMP*W12
  1200. W21 = ZERO
  1201. *
  1202. * Compute SCALE
  1203. *
  1204. SCALE = ONE
  1205. IF( ABS( W22 ).LT.SAFMIN ) THEN
  1206. SCALE = ZERO
  1207. U2 = ONE
  1208. U1 = -W12 / W11
  1209. GO TO 250
  1210. END IF
  1211. IF( ABS( W22 ).LT.ABS( U2 ) )
  1212. $ SCALE = ABS( W22 / U2 )
  1213. IF( ABS( W11 ).LT.ABS( U1 ) )
  1214. $ SCALE = MIN( SCALE, ABS( W11 / U1 ) )
  1215. *
  1216. * Solve
  1217. *
  1218. U2 = ( SCALE*U2 ) / W22
  1219. U1 = ( SCALE*U1-W12*U2 ) / W11
  1220. *
  1221. 250 CONTINUE
  1222. IF( ILPIVT ) THEN
  1223. TEMP = U2
  1224. U2 = U1
  1225. U1 = TEMP
  1226. END IF
  1227. *
  1228. * Compute Householder Vector
  1229. *
  1230. T1 = SQRT( SCALE**2+U1**2+U2**2 )
  1231. TAU = ONE + SCALE / T1
  1232. VS = -ONE / ( SCALE+T1 )
  1233. V( 1 ) = ONE
  1234. V( 2 ) = VS*U1
  1235. V( 3 ) = VS*U2
  1236. *
  1237. * Apply transformations from the right.
  1238. *
  1239. T2 = TAU*V( 2 )
  1240. T3 = TAU*V( 3 )
  1241. DO 260 JR = IFRSTM, MIN( J+3, ILAST )
  1242. TEMP = H( JR, J )+V( 2 )*H( JR, J+1 )+V( 3 )*
  1243. $ H( JR, J+2 )
  1244. H( JR, J ) = H( JR, J ) - TEMP*TAU
  1245. H( JR, J+1 ) = H( JR, J+1 ) - TEMP*T2
  1246. H( JR, J+2 ) = H( JR, J+2 ) - TEMP*T3
  1247. 260 CONTINUE
  1248. DO 270 JR = IFRSTM, J + 2
  1249. TEMP = T( JR, J )+V( 2 )*T( JR, J+1 )+V( 3 )*
  1250. $ T( JR, J+2 )
  1251. T( JR, J ) = T( JR, J ) - TEMP*TAU
  1252. T( JR, J+1 ) = T( JR, J+1 ) - TEMP*T2
  1253. T( JR, J+2 ) = T( JR, J+2 ) - TEMP*T3
  1254. 270 CONTINUE
  1255. IF( ILZ ) THEN
  1256. DO 280 JR = 1, N
  1257. TEMP = Z( JR, J )+V( 2 )*Z( JR, J+1 )+V( 3 )*
  1258. $ Z( JR, J+2 )
  1259. Z( JR, J ) = Z( JR, J ) - TEMP*TAU
  1260. Z( JR, J+1 ) = Z( JR, J+1 ) - TEMP*T2
  1261. Z( JR, J+2 ) = Z( JR, J+2 ) - TEMP*T3
  1262. 280 CONTINUE
  1263. END IF
  1264. T( J+1, J ) = ZERO
  1265. T( J+2, J ) = ZERO
  1266. 290 CONTINUE
  1267. *
  1268. * Last elements: Use Givens rotations
  1269. *
  1270. * Rotations from the left
  1271. *
  1272. J = ILAST - 1
  1273. TEMP = H( J, J-1 )
  1274. CALL SLARTG( TEMP, H( J+1, J-1 ), C, S, H( J, J-1 ) )
  1275. H( J+1, J-1 ) = ZERO
  1276. *
  1277. DO 300 JC = J, ILASTM
  1278. TEMP = C*H( J, JC ) + S*H( J+1, JC )
  1279. H( J+1, JC ) = -S*H( J, JC ) + C*H( J+1, JC )
  1280. H( J, JC ) = TEMP
  1281. TEMP2 = C*T( J, JC ) + S*T( J+1, JC )
  1282. T( J+1, JC ) = -S*T( J, JC ) + C*T( J+1, JC )
  1283. T( J, JC ) = TEMP2
  1284. 300 CONTINUE
  1285. IF( ILQ ) THEN
  1286. DO 310 JR = 1, N
  1287. TEMP = C*Q( JR, J ) + S*Q( JR, J+1 )
  1288. Q( JR, J+1 ) = -S*Q( JR, J ) + C*Q( JR, J+1 )
  1289. Q( JR, J ) = TEMP
  1290. 310 CONTINUE
  1291. END IF
  1292. *
  1293. * Rotations from the right.
  1294. *
  1295. TEMP = T( J+1, J+1 )
  1296. CALL SLARTG( TEMP, T( J+1, J ), C, S, T( J+1, J+1 ) )
  1297. T( J+1, J ) = ZERO
  1298. *
  1299. DO 320 JR = IFRSTM, ILAST
  1300. TEMP = C*H( JR, J+1 ) + S*H( JR, J )
  1301. H( JR, J ) = -S*H( JR, J+1 ) + C*H( JR, J )
  1302. H( JR, J+1 ) = TEMP
  1303. 320 CONTINUE
  1304. DO 330 JR = IFRSTM, ILAST - 1
  1305. TEMP = C*T( JR, J+1 ) + S*T( JR, J )
  1306. T( JR, J ) = -S*T( JR, J+1 ) + C*T( JR, J )
  1307. T( JR, J+1 ) = TEMP
  1308. 330 CONTINUE
  1309. IF( ILZ ) THEN
  1310. DO 340 JR = 1, N
  1311. TEMP = C*Z( JR, J+1 ) + S*Z( JR, J )
  1312. Z( JR, J ) = -S*Z( JR, J+1 ) + C*Z( JR, J )
  1313. Z( JR, J+1 ) = TEMP
  1314. 340 CONTINUE
  1315. END IF
  1316. *
  1317. * End of Double-Shift code
  1318. *
  1319. END IF
  1320. *
  1321. GO TO 350
  1322. *
  1323. * End of iteration loop
  1324. *
  1325. 350 CONTINUE
  1326. 360 CONTINUE
  1327. *
  1328. * Drop-through = non-convergence
  1329. *
  1330. INFO = ILAST
  1331. GO TO 420
  1332. *
  1333. * Successful completion of all QZ steps
  1334. *
  1335. 380 CONTINUE
  1336. *
  1337. * Set Eigenvalues 1:ILO-1
  1338. *
  1339. DO 410 J = 1, ILO - 1
  1340. IF( T( J, J ).LT.ZERO ) THEN
  1341. IF( ILSCHR ) THEN
  1342. DO 390 JR = 1, J
  1343. H( JR, J ) = -H( JR, J )
  1344. T( JR, J ) = -T( JR, J )
  1345. 390 CONTINUE
  1346. ELSE
  1347. H( J, J ) = -H( J, J )
  1348. T( J, J ) = -T( J, J )
  1349. END IF
  1350. IF( ILZ ) THEN
  1351. DO 400 JR = 1, N
  1352. Z( JR, J ) = -Z( JR, J )
  1353. 400 CONTINUE
  1354. END IF
  1355. END IF
  1356. ALPHAR( J ) = H( J, J )
  1357. ALPHAI( J ) = ZERO
  1358. BETA( J ) = T( J, J )
  1359. 410 CONTINUE
  1360. *
  1361. * Normal Termination
  1362. *
  1363. INFO = 0
  1364. *
  1365. * Exit (other than argument error) -- return optimal workspace size
  1366. *
  1367. 420 CONTINUE
  1368. WORK( 1 ) = SROUNDUP_LWORK( N )
  1369. RETURN
  1370. *
  1371. * End of SHGEQZ
  1372. *
  1373. END