3 * =========== DOCUMENTATION ===========
5 * Online html documentation available at
6 * http://www.netlib.org/lapack/explore-html/
9 *> Download SHGEQZ + dependencies
10 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/shgeqz.f">
12 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/shgeqz.f">
14 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/shgeqz.f">
21 * SUBROUTINE SHGEQZ( JOB, COMPQ, COMPZ, N, ILO, IHI, H, LDH, T, LDT,
22 * ALPHAR, ALPHAI, BETA, Q, LDQ, Z, LDZ, WORK,
25 * .. Scalar Arguments ..
26 * CHARACTER COMPQ, COMPZ, JOB
27 * INTEGER IHI, ILO, INFO, LDH, LDQ, LDT, LDZ, LWORK, N
29 * .. Array Arguments ..
30 * REAL ALPHAI( * ), ALPHAR( * ), BETA( * ),
31 * $ H( LDH, * ), Q( LDQ, * ), T( LDT, * ),
32 * $ WORK( * ), Z( LDZ, * )
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):
47 *> A = Q1*H*Z1**T, B = Q1*T*Z1**T,
49 *> as computed by SGGHRD.
51 *> If JOB='S', then the Hessenberg-triangular pair (H,T) is
52 *> also reduced to generalized Schur form,
54 *> H = Q*S*Z**T, T = Q*P*Z**T,
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
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
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.
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):
77 *> A = (Q1*Q)*S*(Z1*Z)**T, B = (Q1*Q)*P*(Z1*Z)**T.
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)
85 *> and if alpha is nonzero, mu = beta / alpha is an eigenvalue of the
86 *> alternate form of the GNEP
88 *> Real eigenvalues can be read directly from the generalized Schur
90 *> alpha = S(i,i), beta = P(i,i).
92 *> Ref: C.B. Moler & G.W. Stewart, "An Algorithm for Generalized Matrix
93 *> Eigenvalue Problems", SIAM J. Numer. Anal., 10(1973),
102 *> JOB is CHARACTER*1
103 *> = 'E': Compute eigenvalues only;
104 *> = 'S': Compute eigenvalues and the Schur form.
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.
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.
130 *> The order of the matrices H, T, Q, and Z. N >= 0.
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.
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.
160 *> The leading dimension of the array H. LDH >= max( 1, N ).
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
173 *> If JOB = 'E', the diagonal blocks of T match those of P, but
174 *> the rest of T is unspecified.
180 *> The leading dimension of the array T. LDT >= max( 1, N ).
183 *> \param[out] ALPHAR
185 *> ALPHAR is REAL array, dimension (N)
186 *> The real parts of each scalar alpha defining an eigenvalue
190 *> \param[out] ALPHAI
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).
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.
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'.
225 *> The leading dimension of the array Q. LDQ >= 1.
226 *> If COMPQ='V' or 'I', then LDQ >= N.
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'.
243 *> The leading dimension of the array Z. LDZ >= 1.
244 *> If COMPZ='V' or 'I', then LDZ >= N.
249 *> WORK is REAL array, dimension (MAX(1,LWORK))
250 *> On exit, if INFO >= 0, WORK(1) returns the optimal LWORK.
256 *> The dimension of the array WORK. LWORK >= max(1,N).
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.
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.
280 *> \author Univ. of Tennessee
281 *> \author Univ. of California Berkeley
282 *> \author Univ. of Colorado Denver
287 *> \ingroup realGEcomputational
289 *> \par Further Details:
290 * =====================
294 *> Iteration counters:
296 *> JITER -- counts iterations.
297 *> IITER -- counts iterations run since ILAST was last
298 *> changed. This is therefore reset only when a 1-by-1 or
299 *> 2-by-2 block deflates off the bottom.
302 * =====================================================================
303 SUBROUTINE SHGEQZ( JOB, COMPQ, COMPZ, N, ILO, IHI, H, LDH, T, LDT,
304 $ ALPHAR, ALPHAI, BETA, Q, LDQ, Z, LDZ, WORK,
307 * -- LAPACK computational routine (version 3.6.1) --
308 * -- LAPACK is a software package provided by Univ. of Tennessee, --
309 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
312 * .. Scalar Arguments ..
313 CHARACTER COMPQ, COMPZ, JOB
314 INTEGER IHI, ILO, INFO, LDH, LDQ, LDT, LDZ, LWORK, N
316 * .. Array Arguments ..
317 REAL ALPHAI( * ), ALPHAR( * ), BETA( * ),
318 $ H( LDH, * ), Q( LDQ, * ), T( LDT, * ),
319 $ WORK( * ), Z( LDZ, * )
322 * =====================================================================
325 * $ SAFETY = 1.0E+0 )
326 REAL HALF, ZERO, ONE, SAFETY
327 PARAMETER ( HALF = 0.5E+0, ZERO = 0.0E+0, ONE = 1.0E+0,
330 * .. Local Scalars ..
331 LOGICAL ILAZR2, ILAZRO, ILPIVT, ILQ, ILSCHR, ILZ,
333 INTEGER ICOMPQ, ICOMPZ, IFIRST, IFRSTM, IITER, ILAST,
334 $ ILASTM, IN, ISCHUR, ISTART, J, JC, JCH, JITER,
336 REAL A11, A12, A1I, A1R, A21, A22, A2I, A2R, AD11,
337 $ AD11L, AD12, AD12L, AD21, AD21L, AD22, AD22L,
338 $ AD32L, AN, ANORM, ASCALE, ATOL, B11, B1A, B1I,
339 $ B1R, B22, B2A, B2I, B2R, BN, BNORM, BSCALE,
340 $ BTOL, C, C11I, C11R, C12, C21, C22I, C22R, CL,
341 $ CQ, CR, CZ, ESHIFT, S, S1, S1INV, S2, SAFMAX,
342 $ SAFMIN, SCALE, SL, SQI, SQR, SR, SZI, SZR, T1,
343 $ TAU, TEMP, TEMP2, TEMPI, TEMPR, U1, U12, U12L,
344 $ U2, ULP, VS, W11, W12, W21, W22, WABS, WI, WR,
350 * .. External Functions ..
352 REAL SLAMCH, SLANHS, SLAPY2, SLAPY3
353 EXTERNAL LSAME, SLAMCH, SLANHS, SLAPY2, SLAPY3
355 * .. External Subroutines ..
356 EXTERNAL SLAG2, SLARFG, SLARTG, SLASET, SLASV2, SROT,
359 * .. Intrinsic Functions ..
360 INTRINSIC ABS, MAX, MIN, REAL, SQRT
362 * .. Executable Statements ..
364 * Decode JOB, COMPQ, COMPZ
366 IF( LSAME( JOB, 'E' ) ) THEN
369 ELSE IF( LSAME( JOB, 'S' ) ) THEN
376 IF( LSAME( COMPQ, 'N' ) ) THEN
379 ELSE IF( LSAME( COMPQ, 'V' ) ) THEN
382 ELSE IF( LSAME( COMPQ, 'I' ) ) THEN
389 IF( LSAME( COMPZ, 'N' ) ) THEN
392 ELSE IF( LSAME( COMPZ, 'V' ) ) THEN
395 ELSE IF( LSAME( COMPZ, 'I' ) ) THEN
402 * Check Argument Values
405 WORK( 1 ) = MAX( 1, N )
406 LQUERY = ( LWORK.EQ.-1 )
407 IF( ISCHUR.EQ.0 ) THEN
409 ELSE IF( ICOMPQ.EQ.0 ) THEN
411 ELSE IF( ICOMPZ.EQ.0 ) THEN
413 ELSE IF( N.LT.0 ) THEN
415 ELSE IF( ILO.LT.1 ) THEN
417 ELSE IF( IHI.GT.N .OR. IHI.LT.ILO-1 ) THEN
419 ELSE IF( LDH.LT.N ) THEN
421 ELSE IF( LDT.LT.N ) THEN
423 ELSE IF( LDQ.LT.1 .OR. ( ILQ .AND. LDQ.LT.N ) ) THEN
425 ELSE IF( LDZ.LT.1 .OR. ( ILZ .AND. LDZ.LT.N ) ) THEN
427 ELSE IF( LWORK.LT.MAX( 1, N ) .AND. .NOT.LQUERY ) THEN
431 CALL XERBLA( 'SHGEQZ', -INFO )
433 ELSE IF( LQUERY ) THEN
437 * Quick return if possible
440 WORK( 1 ) = REAL( 1 )
447 $ CALL SLASET( 'Full', N, N, ZERO, ONE, Q, LDQ )
449 $ CALL SLASET( 'Full', N, N, ZERO, ONE, Z, LDZ )
454 SAFMIN = SLAMCH( 'S' )
455 SAFMAX = ONE / SAFMIN
456 ULP = SLAMCH( 'E' )*SLAMCH( 'B' )
457 ANORM = SLANHS( 'F', IN, H( ILO, ILO ), LDH, WORK )
458 BNORM = SLANHS( 'F', IN, T( ILO, ILO ), LDT, WORK )
459 ATOL = MAX( SAFMIN, ULP*ANORM )
460 BTOL = MAX( SAFMIN, ULP*BNORM )
461 ASCALE = ONE / MAX( SAFMIN, ANORM )
462 BSCALE = ONE / MAX( SAFMIN, BNORM )
464 * Set Eigenvalues IHI+1:N
467 IF( T( J, J ).LT.ZERO ) THEN
470 H( JR, J ) = -H( JR, J )
471 T( JR, J ) = -T( JR, J )
474 H( J, J ) = -H( J, J )
475 T( J, J ) = -T( J, J )
479 Z( JR, J ) = -Z( JR, J )
483 ALPHAR( J ) = H( J, J )
485 BETA( J ) = T( J, J )
488 * If IHI < ILO, skip QZ steps
493 * MAIN QZ ITERATION LOOP
495 * Initialize dynamic indices
497 * Eigenvalues ILAST+1:N have been found.
498 * Column operations modify rows IFRSTM:whatever.
499 * Row operations modify columns whatever:ILASTM.
501 * If only eigenvalues are being computed, then
502 * IFRSTM is the row of the last splitting row above row ILAST;
503 * this is always at least ILO.
504 * IITER counts iterations since the last eigenvalue was found,
505 * to tell when to use an extraordinary shift.
506 * MAXIT is the maximum number of QZ sweeps allowed.
518 MAXIT = 30*( IHI-ILO+1 )
520 DO 360 JITER = 1, MAXIT
522 * Split the matrix if possible.
525 * 1: H(j,j-1)=0 or j=ILO
528 IF( ILAST.EQ.ILO ) THEN
530 * Special case: j=ILAST
534 IF( ABS( H( ILAST, ILAST-1 ) ).LE.ATOL ) THEN
535 H( ILAST, ILAST-1 ) = ZERO
540 IF( ABS( T( ILAST, ILAST ) ).LE.BTOL ) THEN
541 T( ILAST, ILAST ) = ZERO
545 * General case: j<ILAST
547 DO 60 J = ILAST - 1, ILO, -1
549 * Test 1: for H(j,j-1)=0 or j=ILO
554 IF( ABS( H( J, J-1 ) ).LE.ATOL ) THEN
562 * Test 2: for T(j,j)=0
564 IF( ABS( T( J, J ) ).LT.BTOL ) THEN
567 * Test 1a: Check for 2 consecutive small subdiagonals in A
570 IF( .NOT.ILAZRO ) THEN
571 TEMP = ABS( H( J, J-1 ) )
572 TEMP2 = ABS( H( J, J ) )
573 TEMPR = MAX( TEMP, TEMP2 )
574 IF( TEMPR.LT.ONE .AND. TEMPR.NE.ZERO ) THEN
576 TEMP2 = TEMP2 / TEMPR
578 IF( TEMP*( ASCALE*ABS( H( J+1, J ) ) ).LE.TEMP2*
579 $ ( ASCALE*ATOL ) )ILAZR2 = .TRUE.
582 * If both tests pass (1 & 2), i.e., the leading diagonal
583 * element of B in the block is zero, split a 1x1 block off
584 * at the top. (I.e., at the J-th row/column) The leading
585 * diagonal element of the remainder can also be zero, so
586 * this may have to be done repeatedly.
588 IF( ILAZRO .OR. ILAZR2 ) THEN
589 DO 40 JCH = J, ILAST - 1
591 CALL SLARTG( TEMP, H( JCH+1, JCH ), C, S,
593 H( JCH+1, JCH ) = ZERO
594 CALL SROT( ILASTM-JCH, H( JCH, JCH+1 ), LDH,
595 $ H( JCH+1, JCH+1 ), LDH, C, S )
596 CALL SROT( ILASTM-JCH, T( JCH, JCH+1 ), LDT,
597 $ T( JCH+1, JCH+1 ), LDT, C, S )
599 $ CALL SROT( N, Q( 1, JCH ), 1, Q( 1, JCH+1 ), 1,
602 $ H( JCH, JCH-1 ) = H( JCH, JCH-1 )*C
604 IF( ABS( T( JCH+1, JCH+1 ) ).GE.BTOL ) THEN
605 IF( JCH+1.GE.ILAST ) THEN
612 T( JCH+1, JCH+1 ) = ZERO
617 * Only test 2 passed -- chase the zero to T(ILAST,ILAST)
618 * Then process as in the case T(ILAST,ILAST)=0
620 DO 50 JCH = J, ILAST - 1
621 TEMP = T( JCH, JCH+1 )
622 CALL SLARTG( TEMP, T( JCH+1, JCH+1 ), C, S,
624 T( JCH+1, JCH+1 ) = ZERO
625 IF( JCH.LT.ILASTM-1 )
626 $ CALL SROT( ILASTM-JCH-1, T( JCH, JCH+2 ), LDT,
627 $ T( JCH+1, JCH+2 ), LDT, C, S )
628 CALL SROT( ILASTM-JCH+2, H( JCH, JCH-1 ), LDH,
629 $ H( JCH+1, JCH-1 ), LDH, C, S )
631 $ CALL SROT( N, Q( 1, JCH ), 1, Q( 1, JCH+1 ), 1,
633 TEMP = H( JCH+1, JCH )
634 CALL SLARTG( TEMP, H( JCH+1, JCH-1 ), C, S,
636 H( JCH+1, JCH-1 ) = ZERO
637 CALL SROT( JCH+1-IFRSTM, H( IFRSTM, JCH ), 1,
638 $ H( IFRSTM, JCH-1 ), 1, C, S )
639 CALL SROT( JCH-IFRSTM, T( IFRSTM, JCH ), 1,
640 $ T( IFRSTM, JCH-1 ), 1, C, S )
642 $ CALL SROT( N, Z( 1, JCH ), 1, Z( 1, JCH-1 ), 1,
647 ELSE IF( ILAZRO ) THEN
649 * Only test 1 passed -- work on J:ILAST
655 * Neither test passed -- try next J
659 * (Drop-through is "impossible")
664 * T(ILAST,ILAST)=0 -- clear H(ILAST,ILAST-1) to split off a
668 TEMP = H( ILAST, ILAST )
669 CALL SLARTG( TEMP, H( ILAST, ILAST-1 ), C, S,
670 $ H( ILAST, ILAST ) )
671 H( ILAST, ILAST-1 ) = ZERO
672 CALL SROT( ILAST-IFRSTM, H( IFRSTM, ILAST ), 1,
673 $ H( IFRSTM, ILAST-1 ), 1, C, S )
674 CALL SROT( ILAST-IFRSTM, T( IFRSTM, ILAST ), 1,
675 $ T( IFRSTM, ILAST-1 ), 1, C, S )
677 $ CALL SROT( N, Z( 1, ILAST ), 1, Z( 1, ILAST-1 ), 1, C, S )
679 * H(ILAST,ILAST-1)=0 -- Standardize B, set ALPHAR, ALPHAI,
683 IF( T( ILAST, ILAST ).LT.ZERO ) THEN
685 DO 90 J = IFRSTM, ILAST
686 H( J, ILAST ) = -H( J, ILAST )
687 T( J, ILAST ) = -T( J, ILAST )
690 H( ILAST, ILAST ) = -H( ILAST, ILAST )
691 T( ILAST, ILAST ) = -T( ILAST, ILAST )
695 Z( J, ILAST ) = -Z( J, ILAST )
699 ALPHAR( ILAST ) = H( ILAST, ILAST )
700 ALPHAI( ILAST ) = ZERO
701 BETA( ILAST ) = T( ILAST, ILAST )
703 * Go to next block -- exit if finished.
713 IF( .NOT.ILSCHR ) THEN
715 IF( IFRSTM.GT.ILAST )
722 * This iteration only involves rows/columns IFIRST:ILAST. We
723 * assume IFIRST < ILAST, and that the diagonal of B is non-zero.
727 IF( .NOT.ILSCHR ) THEN
731 * Compute single shifts.
733 * At this point, IFIRST < ILAST, and the diagonal elements of
734 * T(IFIRST:ILAST,IFIRST,ILAST) are larger than BTOL (in
737 IF( ( IITER / 10 )*10.EQ.IITER ) THEN
739 * Exceptional shift. Chosen for no particularly good reason.
740 * (Single shift only.)
742 IF( ( REAL( MAXIT )*SAFMIN )*ABS( H( ILAST, ILAST-1 ) ).LT.
743 $ ABS( T( ILAST-1, ILAST-1 ) ) ) THEN
744 ESHIFT = H( ILAST, ILAST-1 ) /
745 $ T( ILAST-1, ILAST-1 )
747 ESHIFT = ESHIFT + ONE / ( SAFMIN*REAL( MAXIT ) )
754 * Shifts based on the generalized eigenvalues of the
755 * bottom-right 2x2 block of A and B. The first eigenvalue
756 * returned by SLAG2 is the Wilkinson shift (AEP p.512),
758 CALL SLAG2( H( ILAST-1, ILAST-1 ), LDH,
759 $ T( ILAST-1, ILAST-1 ), LDT, SAFMIN*SAFETY, S1,
762 IF ( ABS( (WR/S1)*T( ILAST, ILAST ) - H( ILAST, ILAST ) )
763 $ .GT. ABS( (WR2/S2)*T( ILAST, ILAST )
764 $ - H( ILAST, ILAST ) ) ) THEN
772 TEMP = MAX( S1, SAFMIN*MAX( ONE, ABS( WR ), ABS( WI ) ) )
777 * Fiddle with shift to avoid overflow
779 TEMP = MIN( ASCALE, ONE )*( HALF*SAFMAX )
780 IF( S1.GT.TEMP ) THEN
786 TEMP = MIN( BSCALE, ONE )*( HALF*SAFMAX )
787 IF( ABS( WR ).GT.TEMP )
788 $ SCALE = MIN( SCALE, TEMP / ABS( WR ) )
792 * Now check for two consecutive small subdiagonals.
794 DO 120 J = ILAST - 1, IFIRST + 1, -1
796 TEMP = ABS( S1*H( J, J-1 ) )
797 TEMP2 = ABS( S1*H( J, J )-WR*T( J, J ) )
798 TEMPR = MAX( TEMP, TEMP2 )
799 IF( TEMPR.LT.ONE .AND. TEMPR.NE.ZERO ) THEN
801 TEMP2 = TEMP2 / TEMPR
803 IF( ABS( ( ASCALE*H( J+1, J ) )*TEMP ).LE.( ASCALE*ATOL )*
810 * Do an implicit single-shift QZ sweep.
814 TEMP = S1*H( ISTART, ISTART ) - WR*T( ISTART, ISTART )
815 TEMP2 = S1*H( ISTART+1, ISTART )
816 CALL SLARTG( TEMP, TEMP2, C, S, TEMPR )
820 DO 190 J = ISTART, ILAST - 1
821 IF( J.GT.ISTART ) THEN
823 CALL SLARTG( TEMP, H( J+1, J-1 ), C, S, H( J, J-1 ) )
827 DO 140 JC = J, ILASTM
828 TEMP = C*H( J, JC ) + S*H( J+1, JC )
829 H( J+1, JC ) = -S*H( J, JC ) + C*H( J+1, JC )
831 TEMP2 = C*T( J, JC ) + S*T( J+1, JC )
832 T( J+1, JC ) = -S*T( J, JC ) + C*T( J+1, JC )
837 TEMP = C*Q( JR, J ) + S*Q( JR, J+1 )
838 Q( JR, J+1 ) = -S*Q( JR, J ) + C*Q( JR, J+1 )
844 CALL SLARTG( TEMP, T( J+1, J ), C, S, T( J+1, J+1 ) )
847 DO 160 JR = IFRSTM, MIN( J+2, ILAST )
848 TEMP = C*H( JR, J+1 ) + S*H( JR, J )
849 H( JR, J ) = -S*H( JR, J+1 ) + C*H( JR, J )
852 DO 170 JR = IFRSTM, J
853 TEMP = C*T( JR, J+1 ) + S*T( JR, J )
854 T( JR, J ) = -S*T( JR, J+1 ) + C*T( JR, J )
859 TEMP = C*Z( JR, J+1 ) + S*Z( JR, J )
860 Z( JR, J ) = -S*Z( JR, J+1 ) + C*Z( JR, J )
868 * Use Francis double-shift
870 * Note: the Francis double-shift should work with real shifts,
871 * but only if the block is at least 3x3.
872 * This code may break if this point is reached with
873 * a 2x2 block with real eigenvalues.
876 IF( IFIRST+1.EQ.ILAST ) THEN
878 * Special case -- 2x2 block with complex eigenvectors
880 * Step 1: Standardize, that is, rotate so that
883 * B = ( ) with B11 non-negative.
886 CALL SLASV2( T( ILAST-1, ILAST-1 ), T( ILAST-1, ILAST ),
887 $ T( ILAST, ILAST ), B22, B11, SR, CR, SL, CL )
889 IF( B11.LT.ZERO ) THEN
896 CALL SROT( ILASTM+1-IFIRST, H( ILAST-1, ILAST-1 ), LDH,
897 $ H( ILAST, ILAST-1 ), LDH, CL, SL )
898 CALL SROT( ILAST+1-IFRSTM, H( IFRSTM, ILAST-1 ), 1,
899 $ H( IFRSTM, ILAST ), 1, CR, SR )
901 IF( ILAST.LT.ILASTM )
902 $ CALL SROT( ILASTM-ILAST, T( ILAST-1, ILAST+1 ), LDT,
903 $ T( ILAST, ILAST+1 ), LDT, CL, SL )
904 IF( IFRSTM.LT.ILAST-1 )
905 $ CALL SROT( IFIRST-IFRSTM, T( IFRSTM, ILAST-1 ), 1,
906 $ T( IFRSTM, ILAST ), 1, CR, SR )
909 $ CALL SROT( N, Q( 1, ILAST-1 ), 1, Q( 1, ILAST ), 1, CL,
912 $ CALL SROT( N, Z( 1, ILAST-1 ), 1, Z( 1, ILAST ), 1, CR,
915 T( ILAST-1, ILAST-1 ) = B11
916 T( ILAST-1, ILAST ) = ZERO
917 T( ILAST, ILAST-1 ) = ZERO
918 T( ILAST, ILAST ) = B22
920 * If B22 is negative, negate column ILAST
922 IF( B22.LT.ZERO ) THEN
923 DO 210 J = IFRSTM, ILAST
924 H( J, ILAST ) = -H( J, ILAST )
925 T( J, ILAST ) = -T( J, ILAST )
930 Z( J, ILAST ) = -Z( J, ILAST )
936 * Step 2: Compute ALPHAR, ALPHAI, and BETA (see refs.)
940 CALL SLAG2( H( ILAST-1, ILAST-1 ), LDH,
941 $ T( ILAST-1, ILAST-1 ), LDT, SAFMIN*SAFETY, S1,
942 $ TEMP, WR, TEMP2, WI )
944 * If standardization has perturbed the shift onto real line,
945 * do another (real single-shift) QR step.
951 * Do EISPACK (QZVAL) computation of alpha and beta
953 A11 = H( ILAST-1, ILAST-1 )
954 A21 = H( ILAST, ILAST-1 )
955 A12 = H( ILAST-1, ILAST )
956 A22 = H( ILAST, ILAST )
958 * Compute complex Givens rotation on right
959 * (Assume some element of C = (sA - wB) > unfl )
961 * (sA - wB) ( CZ -SZ )
964 C11R = S1*A11 - WR*B11
968 C22R = S1*A22 - WR*B22
971 IF( ABS( C11R )+ABS( C11I )+ABS( C12 ).GT.ABS( C21 )+
972 $ ABS( C22R )+ABS( C22I ) ) THEN
973 T1 = SLAPY3( C12, C11R, C11I )
978 CZ = SLAPY2( C22R, C22I )
979 IF( CZ.LE.SAFMIN ) THEN
986 T1 = SLAPY2( CZ, C21 )
988 SZR = -C21*TEMPR / T1
993 * Compute Givens rotation on left
999 AN = ABS( A11 ) + ABS( A12 ) + ABS( A21 ) + ABS( A22 )
1000 BN = ABS( B11 ) + ABS( B22 )
1001 WABS = ABS( WR ) + ABS( WI )
1002 IF( S1*AN.GT.WABS*BN ) THEN
1007 A1R = CZ*A11 + SZR*A12
1009 A2R = CZ*A21 + SZR*A22
1011 CQ = SLAPY2( A1R, A1I )
1012 IF( CQ.LE.SAFMIN ) THEN
1019 SQR = TEMPR*A2R + TEMPI*A2I
1020 SQI = TEMPI*A2R - TEMPR*A2I
1023 T1 = SLAPY3( CQ, SQR, SQI )
1028 * Compute diagonal elements of QBZ
1030 TEMPR = SQR*SZR - SQI*SZI
1031 TEMPI = SQR*SZI + SQI*SZR
1032 B1R = CQ*CZ*B11 + TEMPR*B22
1034 B1A = SLAPY2( B1R, B1I )
1035 B2R = CQ*CZ*B22 + TEMPR*B11
1037 B2A = SLAPY2( B2R, B2I )
1039 * Normalize so beta > 0, and Im( alpha1 ) > 0
1041 BETA( ILAST-1 ) = B1A
1043 ALPHAR( ILAST-1 ) = ( WR*B1A )*S1INV
1044 ALPHAI( ILAST-1 ) = ( WI*B1A )*S1INV
1045 ALPHAR( ILAST ) = ( WR*B2A )*S1INV
1046 ALPHAI( ILAST ) = -( WI*B2A )*S1INV
1048 * Step 3: Go to next block -- exit if finished.
1058 IF( .NOT.ILSCHR ) THEN
1060 IF( IFRSTM.GT.ILAST )
1066 * Usual case: 3x3 or larger block, using Francis implicit
1070 * Eigenvalue equation is w - c w + d = 0,
1073 * so compute 1st column of (A B ) - c A B + d
1074 * using the formula in QZIT (from EISPACK)
1076 * We assume that the block is at least 3x3
1078 AD11 = ( ASCALE*H( ILAST-1, ILAST-1 ) ) /
1079 $ ( BSCALE*T( ILAST-1, ILAST-1 ) )
1080 AD21 = ( ASCALE*H( ILAST, ILAST-1 ) ) /
1081 $ ( BSCALE*T( ILAST-1, ILAST-1 ) )
1082 AD12 = ( ASCALE*H( ILAST-1, ILAST ) ) /
1083 $ ( BSCALE*T( ILAST, ILAST ) )
1084 AD22 = ( ASCALE*H( ILAST, ILAST ) ) /
1085 $ ( BSCALE*T( ILAST, ILAST ) )
1086 U12 = T( ILAST-1, ILAST ) / T( ILAST, ILAST )
1087 AD11L = ( ASCALE*H( IFIRST, IFIRST ) ) /
1088 $ ( BSCALE*T( IFIRST, IFIRST ) )
1089 AD21L = ( ASCALE*H( IFIRST+1, IFIRST ) ) /
1090 $ ( BSCALE*T( IFIRST, IFIRST ) )
1091 AD12L = ( ASCALE*H( IFIRST, IFIRST+1 ) ) /
1092 $ ( BSCALE*T( IFIRST+1, IFIRST+1 ) )
1093 AD22L = ( ASCALE*H( IFIRST+1, IFIRST+1 ) ) /
1094 $ ( BSCALE*T( IFIRST+1, IFIRST+1 ) )
1095 AD32L = ( ASCALE*H( IFIRST+2, IFIRST+1 ) ) /
1096 $ ( BSCALE*T( IFIRST+1, IFIRST+1 ) )
1097 U12L = T( IFIRST, IFIRST+1 ) / T( IFIRST+1, IFIRST+1 )
1099 V( 1 ) = ( AD11-AD11L )*( AD22-AD11L ) - AD12*AD21 +
1100 $ AD21*U12*AD11L + ( AD12L-AD11L*U12L )*AD21L
1101 V( 2 ) = ( ( AD22L-AD11L )-AD21L*U12L-( AD11-AD11L )-
1102 $ ( AD22-AD11L )+AD21*U12 )*AD21L
1103 V( 3 ) = AD32L*AD21L
1107 CALL SLARFG( 3, V( 1 ), V( 2 ), 1, TAU )
1112 DO 290 J = ISTART, ILAST - 2
1114 * All but last elements: use 3x3 Householder transforms.
1116 * Zero (j-1)st column of A
1118 IF( J.GT.ISTART ) THEN
1119 V( 1 ) = H( J, J-1 )
1120 V( 2 ) = H( J+1, J-1 )
1121 V( 3 ) = H( J+2, J-1 )
1123 CALL SLARFG( 3, H( J, J-1 ), V( 2 ), 1, TAU )
1125 H( J+1, J-1 ) = ZERO
1126 H( J+2, J-1 ) = ZERO
1129 DO 230 JC = J, ILASTM
1130 TEMP = TAU*( H( J, JC )+V( 2 )*H( J+1, JC )+V( 3 )*
1132 H( J, JC ) = H( J, JC ) - TEMP
1133 H( J+1, JC ) = H( J+1, JC ) - TEMP*V( 2 )
1134 H( J+2, JC ) = H( J+2, JC ) - TEMP*V( 3 )
1135 TEMP2 = TAU*( T( J, JC )+V( 2 )*T( J+1, JC )+V( 3 )*
1137 T( J, JC ) = T( J, JC ) - TEMP2
1138 T( J+1, JC ) = T( J+1, JC ) - TEMP2*V( 2 )
1139 T( J+2, JC ) = T( J+2, JC ) - TEMP2*V( 3 )
1143 TEMP = TAU*( Q( JR, J )+V( 2 )*Q( JR, J+1 )+V( 3 )*
1145 Q( JR, J ) = Q( JR, J ) - TEMP
1146 Q( JR, J+1 ) = Q( JR, J+1 ) - TEMP*V( 2 )
1147 Q( JR, J+2 ) = Q( JR, J+2 ) - TEMP*V( 3 )
1151 * Zero j-th column of B (see SLAGBC for details)
1153 * Swap rows to pivot
1156 TEMP = MAX( ABS( T( J+1, J+1 ) ), ABS( T( J+1, J+2 ) ) )
1157 TEMP2 = MAX( ABS( T( J+2, J+1 ) ), ABS( T( J+2, J+2 ) ) )
1158 IF( MAX( TEMP, TEMP2 ).LT.SAFMIN ) THEN
1163 ELSE IF( TEMP.GE.TEMP2 ) THEN
1179 * Swap columns if nec.
1181 IF( ABS( W12 ).GT.ABS( W11 ) ) THEN
1195 W22 = W22 - TEMP*W12
1201 IF( ABS( W22 ).LT.SAFMIN ) THEN
1207 IF( ABS( W22 ).LT.ABS( U2 ) )
1208 $ SCALE = ABS( W22 / U2 )
1209 IF( ABS( W11 ).LT.ABS( U1 ) )
1210 $ SCALE = MIN( SCALE, ABS( W11 / U1 ) )
1214 U2 = ( SCALE*U2 ) / W22
1215 U1 = ( SCALE*U1-W12*U2 ) / W11
1224 * Compute Householder Vector
1226 T1 = SQRT( SCALE**2+U1**2+U2**2 )
1227 TAU = ONE + SCALE / T1
1228 VS = -ONE / ( SCALE+T1 )
1233 * Apply transformations from the right.
1235 DO 260 JR = IFRSTM, MIN( J+3, ILAST )
1236 TEMP = TAU*( H( JR, J )+V( 2 )*H( JR, J+1 )+V( 3 )*
1238 H( JR, J ) = H( JR, J ) - TEMP
1239 H( JR, J+1 ) = H( JR, J+1 ) - TEMP*V( 2 )
1240 H( JR, J+2 ) = H( JR, J+2 ) - TEMP*V( 3 )
1242 DO 270 JR = IFRSTM, J + 2
1243 TEMP = TAU*( T( JR, J )+V( 2 )*T( JR, J+1 )+V( 3 )*
1245 T( JR, J ) = T( JR, J ) - TEMP
1246 T( JR, J+1 ) = T( JR, J+1 ) - TEMP*V( 2 )
1247 T( JR, J+2 ) = T( JR, J+2 ) - TEMP*V( 3 )
1251 TEMP = TAU*( Z( JR, J )+V( 2 )*Z( JR, J+1 )+V( 3 )*
1253 Z( JR, J ) = Z( JR, J ) - TEMP
1254 Z( JR, J+1 ) = Z( JR, J+1 ) - TEMP*V( 2 )
1255 Z( JR, J+2 ) = Z( JR, J+2 ) - TEMP*V( 3 )
1262 * Last elements: Use Givens rotations
1264 * Rotations from the left
1268 CALL SLARTG( TEMP, H( J+1, J-1 ), C, S, H( J, J-1 ) )
1269 H( J+1, J-1 ) = ZERO
1271 DO 300 JC = J, ILASTM
1272 TEMP = C*H( J, JC ) + S*H( J+1, JC )
1273 H( J+1, JC ) = -S*H( J, JC ) + C*H( J+1, JC )
1275 TEMP2 = C*T( J, JC ) + S*T( J+1, JC )
1276 T( J+1, JC ) = -S*T( J, JC ) + C*T( J+1, JC )
1281 TEMP = C*Q( JR, J ) + S*Q( JR, J+1 )
1282 Q( JR, J+1 ) = -S*Q( JR, J ) + C*Q( JR, J+1 )
1287 * Rotations from the right.
1289 TEMP = T( J+1, J+1 )
1290 CALL SLARTG( TEMP, T( J+1, J ), C, S, T( J+1, J+1 ) )
1293 DO 320 JR = IFRSTM, ILAST
1294 TEMP = C*H( JR, J+1 ) + S*H( JR, J )
1295 H( JR, J ) = -S*H( JR, J+1 ) + C*H( JR, J )
1298 DO 330 JR = IFRSTM, ILAST - 1
1299 TEMP = C*T( JR, J+1 ) + S*T( JR, J )
1300 T( JR, J ) = -S*T( JR, J+1 ) + C*T( JR, J )
1305 TEMP = C*Z( JR, J+1 ) + S*Z( JR, J )
1306 Z( JR, J ) = -S*Z( JR, J+1 ) + C*Z( JR, J )
1311 * End of Double-Shift code
1317 * End of iteration loop
1322 * Drop-through = non-convergence
1327 * Successful completion of all QZ steps
1331 * Set Eigenvalues 1:ILO-1
1333 DO 410 J = 1, ILO - 1
1334 IF( T( J, J ).LT.ZERO ) THEN
1337 H( JR, J ) = -H( JR, J )
1338 T( JR, J ) = -T( JR, J )
1341 H( J, J ) = -H( J, J )
1342 T( J, J ) = -T( J, J )
1346 Z( JR, J ) = -Z( JR, J )
1350 ALPHAR( J ) = H( J, J )
1352 BETA( J ) = T( J, J )
1355 * Normal Termination
1359 * Exit (other than argument error) -- return optimal workspace size
1362 WORK( 1 ) = REAL( N )