001:       SUBROUTINE ZLAQR4( WANTT, WANTZ, N, ILO, IHI, H, LDH, W, ILOZ,
002:      $                   IHIZ, Z, LDZ, WORK, LWORK, INFO )
003: *
004: *  -- LAPACK auxiliary routine (version 3.2) --
005: *     Univ. of Tennessee, Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..
006: *     November 2006
007: *
008: *     .. Scalar Arguments ..
009:       INTEGER            IHI, IHIZ, ILO, ILOZ, INFO, LDH, LDZ, LWORK, N
010:       LOGICAL            WANTT, WANTZ
011: *     ..
012: *     .. Array Arguments ..
013:       COMPLEX*16         H( LDH, * ), W( * ), WORK( * ), Z( LDZ, * )
014: *     ..
015: *
016: *     This subroutine implements one level of recursion for ZLAQR0.
017: *     It is a complete implementation of the small bulge multi-shift
018: *     QR algorithm.  It may be called by ZLAQR0 and, for large enough
019: *     deflation window size, it may be called by ZLAQR3.  This
020: *     subroutine is identical to ZLAQR0 except that it calls ZLAQR2
021: *     instead of ZLAQR3.
022: *
023: *     Purpose
024: *     =======
025: *
026: *     ZLAQR4 computes the eigenvalues of a Hessenberg matrix H
027: *     and, optionally, the matrices T and Z from the Schur decomposition
028: *     H = Z T Z**H, where T is an upper triangular matrix (the
029: *     Schur form), and Z is the unitary matrix of Schur vectors.
030: *
031: *     Optionally Z may be postmultiplied into an input unitary
032: *     matrix Q so that this routine can give the Schur factorization
033: *     of a matrix A which has been reduced to the Hessenberg form H
034: *     by the unitary matrix Q:  A = Q*H*Q**H = (QZ)*H*(QZ)**H.
035: *
036: *     Arguments
037: *     =========
038: *
039: *     WANTT   (input) LOGICAL
040: *          = .TRUE. : the full Schur form T is required;
041: *          = .FALSE.: only eigenvalues are required.
042: *
043: *     WANTZ   (input) LOGICAL
044: *          = .TRUE. : the matrix of Schur vectors Z is required;
045: *          = .FALSE.: Schur vectors are not required.
046: *
047: *     N     (input) INTEGER
048: *           The order of the matrix H.  N .GE. 0.
049: *
050: *     ILO   (input) INTEGER
051: *     IHI   (input) INTEGER
052: *           It is assumed that H is already upper triangular in rows
053: *           and columns 1:ILO-1 and IHI+1:N and, if ILO.GT.1,
054: *           H(ILO,ILO-1) is zero. ILO and IHI are normally set by a
055: *           previous call to ZGEBAL, and then passed to ZGEHRD when the
056: *           matrix output by ZGEBAL is reduced to Hessenberg form.
057: *           Otherwise, ILO and IHI should be set to 1 and N,
058: *           respectively.  If N.GT.0, then 1.LE.ILO.LE.IHI.LE.N.
059: *           If N = 0, then ILO = 1 and IHI = 0.
060: *
061: *     H     (input/output) COMPLEX*16 array, dimension (LDH,N)
062: *           On entry, the upper Hessenberg matrix H.
063: *           On exit, if INFO = 0 and WANTT is .TRUE., then H
064: *           contains the upper triangular matrix T from the Schur
065: *           decomposition (the Schur form). If INFO = 0 and WANT is
066: *           .FALSE., then the contents of H are unspecified on exit.
067: *           (The output value of H when INFO.GT.0 is given under the
068: *           description of INFO below.)
069: *
070: *           This subroutine may explicitly set H(i,j) = 0 for i.GT.j and
071: *           j = 1, 2, ... ILO-1 or j = IHI+1, IHI+2, ... N.
072: *
073: *     LDH   (input) INTEGER
074: *           The leading dimension of the array H. LDH .GE. max(1,N).
075: *
076: *     W        (output) COMPLEX*16 array, dimension (N)
077: *           The computed eigenvalues of H(ILO:IHI,ILO:IHI) are stored
078: *           in W(ILO:IHI). If WANTT is .TRUE., then the eigenvalues are
079: *           stored in the same order as on the diagonal of the Schur
080: *           form returned in H, with W(i) = H(i,i).
081: *
082: *     Z     (input/output) COMPLEX*16 array, dimension (LDZ,IHI)
083: *           If WANTZ is .FALSE., then Z is not referenced.
084: *           If WANTZ is .TRUE., then Z(ILO:IHI,ILOZ:IHIZ) is
085: *           replaced by Z(ILO:IHI,ILOZ:IHIZ)*U where U is the
086: *           orthogonal Schur factor of H(ILO:IHI,ILO:IHI).
087: *           (The output value of Z when INFO.GT.0 is given under
088: *           the description of INFO below.)
089: *
090: *     LDZ   (input) INTEGER
091: *           The leading dimension of the array Z.  if WANTZ is .TRUE.
092: *           then LDZ.GE.MAX(1,IHIZ).  Otherwize, LDZ.GE.1.
093: *
094: *     WORK  (workspace/output) COMPLEX*16 array, dimension LWORK
095: *           On exit, if LWORK = -1, WORK(1) returns an estimate of
096: *           the optimal value for LWORK.
097: *
098: *     LWORK (input) INTEGER
099: *           The dimension of the array WORK.  LWORK .GE. max(1,N)
100: *           is sufficient, but LWORK typically as large as 6*N may
101: *           be required for optimal performance.  A workspace query
102: *           to determine the optimal workspace size is recommended.
103: *
104: *           If LWORK = -1, then ZLAQR4 does a workspace query.
105: *           In this case, ZLAQR4 checks the input parameters and
106: *           estimates the optimal workspace size for the given
107: *           values of N, ILO and IHI.  The estimate is returned
108: *           in WORK(1).  No error message related to LWORK is
109: *           issued by XERBLA.  Neither H nor Z are accessed.
110: *
111: *
112: *     INFO  (output) INTEGER
113: *             =  0:  successful exit
114: *           .GT. 0:  if INFO = i, ZLAQR4 failed to compute all of
115: *                the eigenvalues.  Elements 1:ilo-1 and i+1:n of WR
116: *                and WI contain those eigenvalues which have been
117: *                successfully computed.  (Failures are rare.)
118: *
119: *                If INFO .GT. 0 and WANT is .FALSE., then on exit,
120: *                the remaining unconverged eigenvalues are the eigen-
121: *                values of the upper Hessenberg matrix rows and
122: *                columns ILO through INFO of the final, output
123: *                value of H.
124: *
125: *                If INFO .GT. 0 and WANTT is .TRUE., then on exit
126: *
127: *           (*)  (initial value of H)*U  = U*(final value of H)
128: *
129: *                where U is a unitary matrix.  The final
130: *                value of  H is upper Hessenberg and triangular in
131: *                rows and columns INFO+1 through IHI.
132: *
133: *                If INFO .GT. 0 and WANTZ is .TRUE., then on exit
134: *
135: *                  (final value of Z(ILO:IHI,ILOZ:IHIZ)
136: *                   =  (initial value of Z(ILO:IHI,ILOZ:IHIZ)*U
137: *
138: *                where U is the unitary matrix in (*) (regard-
139: *                less of the value of WANTT.)
140: *
141: *                If INFO .GT. 0 and WANTZ is .FALSE., then Z is not
142: *                accessed.
143: *
144: *     ================================================================
145: *     Based on contributions by
146: *        Karen Braman and Ralph Byers, Department of Mathematics,
147: *        University of Kansas, USA
148: *
149: *     ================================================================
150: *     References:
151: *       K. Braman, R. Byers and R. Mathias, The Multi-Shift QR
152: *       Algorithm Part I: Maintaining Well Focused Shifts, and Level 3
153: *       Performance, SIAM Journal of Matrix Analysis, volume 23, pages
154: *       929--947, 2002.
155: *
156: *       K. Braman, R. Byers and R. Mathias, The Multi-Shift QR
157: *       Algorithm Part II: Aggressive Early Deflation, SIAM Journal
158: *       of Matrix Analysis, volume 23, pages 948--973, 2002.
159: *
160: *     ================================================================
161: *     .. Parameters ..
162: *
163: *     ==== Matrices of order NTINY or smaller must be processed by
164: *     .    ZLAHQR because of insufficient subdiagonal scratch space.
165: *     .    (This is a hard limit.) ====
166:       INTEGER            NTINY
167:       PARAMETER          ( NTINY = 11 )
168: *
169: *     ==== Exceptional deflation windows:  try to cure rare
170: *     .    slow convergence by varying the size of the
171: *     .    deflation window after KEXNW iterations. ====
172:       INTEGER            KEXNW
173:       PARAMETER          ( KEXNW = 5 )
174: *
175: *     ==== Exceptional shifts: try to cure rare slow convergence
176: *     .    with ad-hoc exceptional shifts every KEXSH iterations.
177: *     .    ====
178:       INTEGER            KEXSH
179:       PARAMETER          ( KEXSH = 6 )
180: *
181: *     ==== The constant WILK1 is used to form the exceptional
182: *     .    shifts. ====
183:       DOUBLE PRECISION   WILK1
184:       PARAMETER          ( WILK1 = 0.75d0 )
185:       COMPLEX*16         ZERO, ONE
186:       PARAMETER          ( ZERO = ( 0.0d0, 0.0d0 ),
187:      $                   ONE = ( 1.0d0, 0.0d0 ) )
188:       DOUBLE PRECISION   TWO
189:       PARAMETER          ( TWO = 2.0d0 )
190: *     ..
191: *     .. Local Scalars ..
192:       COMPLEX*16         AA, BB, CC, CDUM, DD, DET, RTDISC, SWAP, TR2
193:       DOUBLE PRECISION   S
194:       INTEGER            I, INF, IT, ITMAX, K, KACC22, KBOT, KDU, KS,
195:      $                   KT, KTOP, KU, KV, KWH, KWTOP, KWV, LD, LS,
196:      $                   LWKOPT, NDEC, NDFL, NH, NHO, NIBBLE, NMIN, NS,
197:      $                   NSMAX, NSR, NVE, NW, NWMAX, NWR, NWUPBD
198:       LOGICAL            SORTED
199:       CHARACTER          JBCMPZ*2
200: *     ..
201: *     .. External Functions ..
202:       INTEGER            ILAENV
203:       EXTERNAL           ILAENV
204: *     ..
205: *     .. Local Arrays ..
206:       COMPLEX*16         ZDUM( 1, 1 )
207: *     ..
208: *     .. External Subroutines ..
209:       EXTERNAL           ZLACPY, ZLAHQR, ZLAQR2, ZLAQR5
210: *     ..
211: *     .. Intrinsic Functions ..
212:       INTRINSIC          ABS, DBLE, DCMPLX, DIMAG, INT, MAX, MIN, MOD,
213:      $                   SQRT
214: *     ..
215: *     .. Statement Functions ..
216:       DOUBLE PRECISION   CABS1
217: *     ..
218: *     .. Statement Function definitions ..
219:       CABS1( CDUM ) = ABS( DBLE( CDUM ) ) + ABS( DIMAG( CDUM ) )
220: *     ..
221: *     .. Executable Statements ..
222:       INFO = 0
223: *
224: *     ==== Quick return for N = 0: nothing to do. ====
225: *
226:       IF( N.EQ.0 ) THEN
227:          WORK( 1 ) = ONE
228:          RETURN
229:       END IF
230: *
231:       IF( N.LE.NTINY ) THEN
232: *
233: *        ==== Tiny matrices must use ZLAHQR. ====
234: *
235:          LWKOPT = 1
236:          IF( LWORK.NE.-1 )
237:      $      CALL ZLAHQR( WANTT, WANTZ, N, ILO, IHI, H, LDH, W, ILOZ,
238:      $                   IHIZ, Z, LDZ, INFO )
239:       ELSE
240: *
241: *        ==== Use small bulge multi-shift QR with aggressive early
242: *        .    deflation on larger-than-tiny matrices. ====
243: *
244: *        ==== Hope for the best. ====
245: *
246:          INFO = 0
247: *
248: *        ==== Set up job flags for ILAENV. ====
249: *
250:          IF( WANTT ) THEN
251:             JBCMPZ( 1: 1 ) = 'S'
252:          ELSE
253:             JBCMPZ( 1: 1 ) = 'E'
254:          END IF
255:          IF( WANTZ ) THEN
256:             JBCMPZ( 2: 2 ) = 'V'
257:          ELSE
258:             JBCMPZ( 2: 2 ) = 'N'
259:          END IF
260: *
261: *        ==== NWR = recommended deflation window size.  At this
262: *        .    point,  N .GT. NTINY = 11, so there is enough
263: *        .    subdiagonal workspace for NWR.GE.2 as required.
264: *        .    (In fact, there is enough subdiagonal space for
265: *        .    NWR.GE.3.) ====
266: *
267:          NWR = ILAENV( 13, 'ZLAQR4', JBCMPZ, N, ILO, IHI, LWORK )
268:          NWR = MAX( 2, NWR )
269:          NWR = MIN( IHI-ILO+1, ( N-1 ) / 3, NWR )
270: *
271: *        ==== NSR = recommended number of simultaneous shifts.
272: *        .    At this point N .GT. NTINY = 11, so there is at
273: *        .    enough subdiagonal workspace for NSR to be even
274: *        .    and greater than or equal to two as required. ====
275: *
276:          NSR = ILAENV( 15, 'ZLAQR4', JBCMPZ, N, ILO, IHI, LWORK )
277:          NSR = MIN( NSR, ( N+6 ) / 9, IHI-ILO )
278:          NSR = MAX( 2, NSR-MOD( NSR, 2 ) )
279: *
280: *        ==== Estimate optimal workspace ====
281: *
282: *        ==== Workspace query call to ZLAQR2 ====
283: *
284:          CALL ZLAQR2( WANTT, WANTZ, N, ILO, IHI, NWR+1, H, LDH, ILOZ,
285:      $                IHIZ, Z, LDZ, LS, LD, W, H, LDH, N, H, LDH, N, H,
286:      $                LDH, WORK, -1 )
287: *
288: *        ==== Optimal workspace = MAX(ZLAQR5, ZLAQR2) ====
289: *
290:          LWKOPT = MAX( 3*NSR / 2, INT( WORK( 1 ) ) )
291: *
292: *        ==== Quick return in case of workspace query. ====
293: *
294:          IF( LWORK.EQ.-1 ) THEN
295:             WORK( 1 ) = DCMPLX( LWKOPT, 0 )
296:             RETURN
297:          END IF
298: *
299: *        ==== ZLAHQR/ZLAQR0 crossover point ====
300: *
301:          NMIN = ILAENV( 12, 'ZLAQR4', JBCMPZ, N, ILO, IHI, LWORK )
302:          NMIN = MAX( NTINY, NMIN )
303: *
304: *        ==== Nibble crossover point ====
305: *
306:          NIBBLE = ILAENV( 14, 'ZLAQR4', JBCMPZ, N, ILO, IHI, LWORK )
307:          NIBBLE = MAX( 0, NIBBLE )
308: *
309: *        ==== Accumulate reflections during ttswp?  Use block
310: *        .    2-by-2 structure during matrix-matrix multiply? ====
311: *
312:          KACC22 = ILAENV( 16, 'ZLAQR4', JBCMPZ, N, ILO, IHI, LWORK )
313:          KACC22 = MAX( 0, KACC22 )
314:          KACC22 = MIN( 2, KACC22 )
315: *
316: *        ==== NWMAX = the largest possible deflation window for
317: *        .    which there is sufficient workspace. ====
318: *
319:          NWMAX = MIN( ( N-1 ) / 3, LWORK / 2 )
320:          NW = NWMAX
321: *
322: *        ==== NSMAX = the Largest number of simultaneous shifts
323: *        .    for which there is sufficient workspace. ====
324: *
325:          NSMAX = MIN( ( N+6 ) / 9, 2*LWORK / 3 )
326:          NSMAX = NSMAX - MOD( NSMAX, 2 )
327: *
328: *        ==== NDFL: an iteration count restarted at deflation. ====
329: *
330:          NDFL = 1
331: *
332: *        ==== ITMAX = iteration limit ====
333: *
334:          ITMAX = MAX( 30, 2*KEXSH )*MAX( 10, ( IHI-ILO+1 ) )
335: *
336: *        ==== Last row and column in the active block ====
337: *
338:          KBOT = IHI
339: *
340: *        ==== Main Loop ====
341: *
342:          DO 70 IT = 1, ITMAX
343: *
344: *           ==== Done when KBOT falls below ILO ====
345: *
346:             IF( KBOT.LT.ILO )
347:      $         GO TO 80
348: *
349: *           ==== Locate active block ====
350: *
351:             DO 10 K = KBOT, ILO + 1, -1
352:                IF( H( K, K-1 ).EQ.ZERO )
353:      $            GO TO 20
354:    10       CONTINUE
355:             K = ILO
356:    20       CONTINUE
357:             KTOP = K
358: *
359: *           ==== Select deflation window size:
360: *           .    Typical Case:
361: *           .      If possible and advisable, nibble the entire
362: *           .      active block.  If not, use size MIN(NWR,NWMAX)
363: *           .      or MIN(NWR+1,NWMAX) depending upon which has
364: *           .      the smaller corresponding subdiagonal entry
365: *           .      (a heuristic).
366: *           .
367: *           .    Exceptional Case:
368: *           .      If there have been no deflations in KEXNW or
369: *           .      more iterations, then vary the deflation window
370: *           .      size.   At first, because, larger windows are,
371: *           .      in general, more powerful than smaller ones,
372: *           .      rapidly increase the window to the maximum possible.
373: *           .      Then, gradually reduce the window size. ====
374: *
375:             NH = KBOT - KTOP + 1
376:             NWUPBD = MIN( NH, NWMAX )
377:             IF( NDFL.LT.KEXNW ) THEN
378:                NW = MIN( NWUPBD, NWR )
379:             ELSE
380:                NW = MIN( NWUPBD, 2*NW )
381:             END IF
382:             IF( NW.LT.NWMAX ) THEN
383:                IF( NW.GE.NH-1 ) THEN
384:                   NW = NH
385:                ELSE
386:                   KWTOP = KBOT - NW + 1
387:                   IF( CABS1( H( KWTOP, KWTOP-1 ) ).GT.
388:      $                CABS1( H( KWTOP-1, KWTOP-2 ) ) )NW = NW + 1
389:                END IF
390:             END IF
391:             IF( NDFL.LT.KEXNW ) THEN
392:                NDEC = -1
393:             ELSE IF( NDEC.GE.0 .OR. NW.GE.NWUPBD ) THEN
394:                NDEC = NDEC + 1
395:                IF( NW-NDEC.LT.2 )
396:      $            NDEC = 0
397:                NW = NW - NDEC
398:             END IF
399: *
400: *           ==== Aggressive early deflation:
401: *           .    split workspace under the subdiagonal into
402: *           .      - an nw-by-nw work array V in the lower
403: *           .        left-hand-corner,
404: *           .      - an NW-by-at-least-NW-but-more-is-better
405: *           .        (NW-by-NHO) horizontal work array along
406: *           .        the bottom edge,
407: *           .      - an at-least-NW-but-more-is-better (NHV-by-NW)
408: *           .        vertical work array along the left-hand-edge.
409: *           .        ====
410: *
411:             KV = N - NW + 1
412:             KT = NW + 1
413:             NHO = ( N-NW-1 ) - KT + 1
414:             KWV = NW + 2
415:             NVE = ( N-NW ) - KWV + 1
416: *
417: *           ==== Aggressive early deflation ====
418: *
419:             CALL ZLAQR2( WANTT, WANTZ, N, KTOP, KBOT, NW, H, LDH, ILOZ,
420:      $                   IHIZ, Z, LDZ, LS, LD, W, H( KV, 1 ), LDH, NHO,
421:      $                   H( KV, KT ), LDH, NVE, H( KWV, 1 ), LDH, WORK,
422:      $                   LWORK )
423: *
424: *           ==== Adjust KBOT accounting for new deflations. ====
425: *
426:             KBOT = KBOT - LD
427: *
428: *           ==== KS points to the shifts. ====
429: *
430:             KS = KBOT - LS + 1
431: *
432: *           ==== Skip an expensive QR sweep if there is a (partly
433: *           .    heuristic) reason to expect that many eigenvalues
434: *           .    will deflate without it.  Here, the QR sweep is
435: *           .    skipped if many eigenvalues have just been deflated
436: *           .    or if the remaining active block is small.
437: *
438:             IF( ( LD.EQ.0 ) .OR. ( ( 100*LD.LE.NW*NIBBLE ) .AND. ( KBOT-
439:      $          KTOP+1.GT.MIN( NMIN, NWMAX ) ) ) ) THEN
440: *
441: *              ==== NS = nominal number of simultaneous shifts.
442: *              .    This may be lowered (slightly) if ZLAQR2
443: *              .    did not provide that many shifts. ====
444: *
445:                NS = MIN( NSMAX, NSR, MAX( 2, KBOT-KTOP ) )
446:                NS = NS - MOD( NS, 2 )
447: *
448: *              ==== If there have been no deflations
449: *              .    in a multiple of KEXSH iterations,
450: *              .    then try exceptional shifts.
451: *              .    Otherwise use shifts provided by
452: *              .    ZLAQR2 above or from the eigenvalues
453: *              .    of a trailing principal submatrix. ====
454: *
455:                IF( MOD( NDFL, KEXSH ).EQ.0 ) THEN
456:                   KS = KBOT - NS + 1
457:                   DO 30 I = KBOT, KS + 1, -2
458:                      W( I ) = H( I, I ) + WILK1*CABS1( H( I, I-1 ) )
459:                      W( I-1 ) = W( I )
460:    30             CONTINUE
461:                ELSE
462: *
463: *                 ==== Got NS/2 or fewer shifts? Use ZLAHQR
464: *                 .    on a trailing principal submatrix to
465: *                 .    get more. (Since NS.LE.NSMAX.LE.(N+6)/9,
466: *                 .    there is enough space below the subdiagonal
467: *                 .    to fit an NS-by-NS scratch array.) ====
468: *
469:                   IF( KBOT-KS+1.LE.NS / 2 ) THEN
470:                      KS = KBOT - NS + 1
471:                      KT = N - NS + 1
472:                      CALL ZLACPY( 'A', NS, NS, H( KS, KS ), LDH,
473:      $                            H( KT, 1 ), LDH )
474:                      CALL ZLAHQR( .false., .false., NS, 1, NS,
475:      $                            H( KT, 1 ), LDH, W( KS ), 1, 1, ZDUM,
476:      $                            1, INF )
477:                      KS = KS + INF
478: *
479: *                    ==== In case of a rare QR failure use
480: *                    .    eigenvalues of the trailing 2-by-2
481: *                    .    principal submatrix.  Scale to avoid
482: *                    .    overflows, underflows and subnormals.
483: *                    .    (The scale factor S can not be zero,
484: *                    .    because H(KBOT,KBOT-1) is nonzero.) ====
485: *
486:                      IF( KS.GE.KBOT ) THEN
487:                         S = CABS1( H( KBOT-1, KBOT-1 ) ) +
488:      $                      CABS1( H( KBOT, KBOT-1 ) ) +
489:      $                      CABS1( H( KBOT-1, KBOT ) ) +
490:      $                      CABS1( H( KBOT, KBOT ) )
491:                         AA = H( KBOT-1, KBOT-1 ) / S
492:                         CC = H( KBOT, KBOT-1 ) / S
493:                         BB = H( KBOT-1, KBOT ) / S
494:                         DD = H( KBOT, KBOT ) / S
495:                         TR2 = ( AA+DD ) / TWO
496:                         DET = ( AA-TR2 )*( DD-TR2 ) - BB*CC
497:                         RTDISC = SQRT( -DET )
498:                         W( KBOT-1 ) = ( TR2+RTDISC )*S
499:                         W( KBOT ) = ( TR2-RTDISC )*S
500: *
501:                         KS = KBOT - 1
502:                      END IF
503:                   END IF
504: *
505:                   IF( KBOT-KS+1.GT.NS ) THEN
506: *
507: *                    ==== Sort the shifts (Helps a little) ====
508: *
509:                      SORTED = .false.
510:                      DO 50 K = KBOT, KS + 1, -1
511:                         IF( SORTED )
512:      $                     GO TO 60
513:                         SORTED = .true.
514:                         DO 40 I = KS, K - 1
515:                            IF( CABS1( W( I ) ).LT.CABS1( W( I+1 ) ) )
516:      $                          THEN
517:                               SORTED = .false.
518:                               SWAP = W( I )
519:                               W( I ) = W( I+1 )
520:                               W( I+1 ) = SWAP
521:                            END IF
522:    40                   CONTINUE
523:    50                CONTINUE
524:    60                CONTINUE
525:                   END IF
526:                END IF
527: *
528: *              ==== If there are only two shifts, then use
529: *              .    only one.  ====
530: *
531:                IF( KBOT-KS+1.EQ.2 ) THEN
532:                   IF( CABS1( W( KBOT )-H( KBOT, KBOT ) ).LT.
533:      $                CABS1( W( KBOT-1 )-H( KBOT, KBOT ) ) ) THEN
534:                      W( KBOT-1 ) = W( KBOT )
535:                   ELSE
536:                      W( KBOT ) = W( KBOT-1 )
537:                   END IF
538:                END IF
539: *
540: *              ==== Use up to NS of the the smallest magnatiude
541: *              .    shifts.  If there aren't NS shifts available,
542: *              .    then use them all, possibly dropping one to
543: *              .    make the number of shifts even. ====
544: *
545:                NS = MIN( NS, KBOT-KS+1 )
546:                NS = NS - MOD( NS, 2 )
547:                KS = KBOT - NS + 1
548: *
549: *              ==== Small-bulge multi-shift QR sweep:
550: *              .    split workspace under the subdiagonal into
551: *              .    - a KDU-by-KDU work array U in the lower
552: *              .      left-hand-corner,
553: *              .    - a KDU-by-at-least-KDU-but-more-is-better
554: *              .      (KDU-by-NHo) horizontal work array WH along
555: *              .      the bottom edge,
556: *              .    - and an at-least-KDU-but-more-is-better-by-KDU
557: *              .      (NVE-by-KDU) vertical work WV arrow along
558: *              .      the left-hand-edge. ====
559: *
560:                KDU = 3*NS - 3
561:                KU = N - KDU + 1
562:                KWH = KDU + 1
563:                NHO = ( N-KDU+1-4 ) - ( KDU+1 ) + 1
564:                KWV = KDU + 4
565:                NVE = N - KDU - KWV + 1
566: *
567: *              ==== Small-bulge multi-shift QR sweep ====
568: *
569:                CALL ZLAQR5( WANTT, WANTZ, KACC22, N, KTOP, KBOT, NS,
570:      $                      W( KS ), H, LDH, ILOZ, IHIZ, Z, LDZ, WORK,
571:      $                      3, H( KU, 1 ), LDH, NVE, H( KWV, 1 ), LDH,
572:      $                      NHO, H( KU, KWH ), LDH )
573:             END IF
574: *
575: *           ==== Note progress (or the lack of it). ====
576: *
577:             IF( LD.GT.0 ) THEN
578:                NDFL = 1
579:             ELSE
580:                NDFL = NDFL + 1
581:             END IF
582: *
583: *           ==== End of main loop ====
584:    70    CONTINUE
585: *
586: *        ==== Iteration limit exceeded.  Set INFO to show where
587: *        .    the problem occurred and exit. ====
588: *
589:          INFO = KBOT
590:    80    CONTINUE
591:       END IF
592: *
593: *     ==== Return the optimal value of LWORK. ====
594: *
595:       WORK( 1 ) = DCMPLX( LWKOPT, 0 )
596: *
597: *     ==== End of ZLAQR4 ====
598: *
599:       END
600: