LAPACK  3.4.1
LAPACK: Linear Algebra PACKage
claqr0.f
Go to the documentation of this file.
00001 *> \brief \b CLAQR0
00002 *
00003 *  =========== DOCUMENTATION ===========
00004 *
00005 * Online html documentation available at 
00006 *            http://www.netlib.org/lapack/explore-html/ 
00007 *
00008 *> \htmlonly
00009 *> Download CLAQR0 + dependencies 
00010 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/claqr0.f"> 
00011 *> [TGZ]</a> 
00012 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/claqr0.f"> 
00013 *> [ZIP]</a> 
00014 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/claqr0.f"> 
00015 *> [TXT]</a>
00016 *> \endhtmlonly 
00017 *
00018 *  Definition:
00019 *  ===========
00020 *
00021 *       SUBROUTINE CLAQR0( WANTT, WANTZ, N, ILO, IHI, H, LDH, W, ILOZ,
00022 *                          IHIZ, Z, LDZ, WORK, LWORK, INFO )
00023 * 
00024 *       .. Scalar Arguments ..
00025 *       INTEGER            IHI, IHIZ, ILO, ILOZ, INFO, LDH, LDZ, LWORK, N
00026 *       LOGICAL            WANTT, WANTZ
00027 *       ..
00028 *       .. Array Arguments ..
00029 *       COMPLEX            H( LDH, * ), W( * ), WORK( * ), Z( LDZ, * )
00030 *       ..
00031 *  
00032 *
00033 *> \par Purpose:
00034 *  =============
00035 *>
00036 *> \verbatim
00037 *>
00038 *>    CLAQR0 computes the eigenvalues of a Hessenberg matrix H
00039 *>    and, optionally, the matrices T and Z from the Schur decomposition
00040 *>    H = Z T Z**H, where T is an upper triangular matrix (the
00041 *>    Schur form), and Z is the unitary matrix of Schur vectors.
00042 *>
00043 *>    Optionally Z may be postmultiplied into an input unitary
00044 *>    matrix Q so that this routine can give the Schur factorization
00045 *>    of a matrix A which has been reduced to the Hessenberg form H
00046 *>    by the unitary matrix Q:  A = Q*H*Q**H = (QZ)*H*(QZ)**H.
00047 *> \endverbatim
00048 *
00049 *  Arguments:
00050 *  ==========
00051 *
00052 *> \param[in] WANTT
00053 *> \verbatim
00054 *>          WANTT is LOGICAL
00055 *>          = .TRUE. : the full Schur form T is required;
00056 *>          = .FALSE.: only eigenvalues are required.
00057 *> \endverbatim
00058 *>
00059 *> \param[in] WANTZ
00060 *> \verbatim
00061 *>          WANTZ is LOGICAL
00062 *>          = .TRUE. : the matrix of Schur vectors Z is required;
00063 *>          = .FALSE.: Schur vectors are not required.
00064 *> \endverbatim
00065 *>
00066 *> \param[in] N
00067 *> \verbatim
00068 *>          N is INTEGER
00069 *>           The order of the matrix H.  N .GE. 0.
00070 *> \endverbatim
00071 *>
00072 *> \param[in] ILO
00073 *> \verbatim
00074 *>          ILO is INTEGER
00075 *> \endverbatim
00076 *>
00077 *> \param[in] IHI
00078 *> \verbatim
00079 *>          IHI is INTEGER
00080 *>           It is assumed that H is already upper triangular in rows
00081 *>           and columns 1:ILO-1 and IHI+1:N and, if ILO.GT.1,
00082 *>           H(ILO,ILO-1) is zero. ILO and IHI are normally set by a
00083 *>           previous call to CGEBAL, and then passed to CGEHRD when the
00084 *>           matrix output by CGEBAL is reduced to Hessenberg form.
00085 *>           Otherwise, ILO and IHI should be set to 1 and N,
00086 *>           respectively.  If N.GT.0, then 1.LE.ILO.LE.IHI.LE.N.
00087 *>           If N = 0, then ILO = 1 and IHI = 0.
00088 *> \endverbatim
00089 *>
00090 *> \param[in,out] H
00091 *> \verbatim
00092 *>          H is COMPLEX array, dimension (LDH,N)
00093 *>           On entry, the upper Hessenberg matrix H.
00094 *>           On exit, if INFO = 0 and WANTT is .TRUE., then H
00095 *>           contains the upper triangular matrix T from the Schur
00096 *>           decomposition (the Schur form). If INFO = 0 and WANT is
00097 *>           .FALSE., then the contents of H are unspecified on exit.
00098 *>           (The output value of H when INFO.GT.0 is given under the
00099 *>           description of INFO below.)
00100 *>
00101 *>           This subroutine may explicitly set H(i,j) = 0 for i.GT.j and
00102 *>           j = 1, 2, ... ILO-1 or j = IHI+1, IHI+2, ... N.
00103 *> \endverbatim
00104 *>
00105 *> \param[in] LDH
00106 *> \verbatim
00107 *>          LDH is INTEGER
00108 *>           The leading dimension of the array H. LDH .GE. max(1,N).
00109 *> \endverbatim
00110 *>
00111 *> \param[out] W
00112 *> \verbatim
00113 *>          W is COMPLEX array, dimension (N)
00114 *>           The computed eigenvalues of H(ILO:IHI,ILO:IHI) are stored
00115 *>           in W(ILO:IHI). If WANTT is .TRUE., then the eigenvalues are
00116 *>           stored in the same order as on the diagonal of the Schur
00117 *>           form returned in H, with W(i) = H(i,i).
00118 *> \endverbatim
00119 *>
00120 *> \param[in] ILOZ
00121 *> \verbatim
00122 *>          ILOZ is INTEGER
00123 *> \endverbatim
00124 *>
00125 *> \param[in] IHIZ
00126 *> \verbatim
00127 *>          IHIZ is INTEGER
00128 *>           Specify the rows of Z to which transformations must be
00129 *>           applied if WANTZ is .TRUE..
00130 *>           1 .LE. ILOZ .LE. ILO; IHI .LE. IHIZ .LE. N.
00131 *> \endverbatim
00132 *>
00133 *> \param[in,out] Z
00134 *> \verbatim
00135 *>          Z is COMPLEX array, dimension (LDZ,IHI)
00136 *>           If WANTZ is .FALSE., then Z is not referenced.
00137 *>           If WANTZ is .TRUE., then Z(ILO:IHI,ILOZ:IHIZ) is
00138 *>           replaced by Z(ILO:IHI,ILOZ:IHIZ)*U where U is the
00139 *>           orthogonal Schur factor of H(ILO:IHI,ILO:IHI).
00140 *>           (The output value of Z when INFO.GT.0 is given under
00141 *>           the description of INFO below.)
00142 *> \endverbatim
00143 *>
00144 *> \param[in] LDZ
00145 *> \verbatim
00146 *>          LDZ is INTEGER
00147 *>           The leading dimension of the array Z.  if WANTZ is .TRUE.
00148 *>           then LDZ.GE.MAX(1,IHIZ).  Otherwize, LDZ.GE.1.
00149 *> \endverbatim
00150 *>
00151 *> \param[out] WORK
00152 *> \verbatim
00153 *>          WORK is COMPLEX array, dimension LWORK
00154 *>           On exit, if LWORK = -1, WORK(1) returns an estimate of
00155 *>           the optimal value for LWORK.
00156 *> \endverbatim
00157 *>
00158 *> \param[in] LWORK
00159 *> \verbatim
00160 *>          LWORK is INTEGER
00161 *>           The dimension of the array WORK.  LWORK .GE. max(1,N)
00162 *>           is sufficient, but LWORK typically as large as 6*N may
00163 *>           be required for optimal performance.  A workspace query
00164 *>           to determine the optimal workspace size is recommended.
00165 *>
00166 *>           If LWORK = -1, then CLAQR0 does a workspace query.
00167 *>           In this case, CLAQR0 checks the input parameters and
00168 *>           estimates the optimal workspace size for the given
00169 *>           values of N, ILO and IHI.  The estimate is returned
00170 *>           in WORK(1).  No error message related to LWORK is
00171 *>           issued by XERBLA.  Neither H nor Z are accessed.
00172 *> \endverbatim
00173 *>
00174 *> \param[out] INFO
00175 *> \verbatim
00176 *>          INFO is INTEGER
00177 *>             =  0:  successful exit
00178 *>           .GT. 0:  if INFO = i, CLAQR0 failed to compute all of
00179 *>                the eigenvalues.  Elements 1:ilo-1 and i+1:n of WR
00180 *>                and WI contain those eigenvalues which have been
00181 *>                successfully computed.  (Failures are rare.)
00182 *>
00183 *>                If INFO .GT. 0 and WANT is .FALSE., then on exit,
00184 *>                the remaining unconverged eigenvalues are the eigen-
00185 *>                values of the upper Hessenberg matrix rows and
00186 *>                columns ILO through INFO of the final, output
00187 *>                value of H.
00188 *>
00189 *>                If INFO .GT. 0 and WANTT is .TRUE., then on exit
00190 *>
00191 *>           (*)  (initial value of H)*U  = U*(final value of H)
00192 *>
00193 *>                where U is a unitary matrix.  The final
00194 *>                value of  H is upper Hessenberg and triangular in
00195 *>                rows and columns INFO+1 through IHI.
00196 *>
00197 *>                If INFO .GT. 0 and WANTZ is .TRUE., then on exit
00198 *>
00199 *>                  (final value of Z(ILO:IHI,ILOZ:IHIZ)
00200 *>                   =  (initial value of Z(ILO:IHI,ILOZ:IHIZ)*U
00201 *>
00202 *>                where U is the unitary matrix in (*) (regard-
00203 *>                less of the value of WANTT.)
00204 *>
00205 *>                If INFO .GT. 0 and WANTZ is .FALSE., then Z is not
00206 *>                accessed.
00207 *> \endverbatim
00208 *
00209 *  Authors:
00210 *  ========
00211 *
00212 *> \author Univ. of Tennessee 
00213 *> \author Univ. of California Berkeley 
00214 *> \author Univ. of Colorado Denver 
00215 *> \author NAG Ltd. 
00216 *
00217 *> \date November 2011
00218 *
00219 *> \ingroup complexOTHERauxiliary
00220 *
00221 *> \par Contributors:
00222 *  ==================
00223 *>
00224 *>       Karen Braman and Ralph Byers, Department of Mathematics,
00225 *>       University of Kansas, USA
00226 *
00227 *> \par References:
00228 *  ================
00229 *>
00230 *>       K. Braman, R. Byers and R. Mathias, The Multi-Shift QR
00231 *>       Algorithm Part I: Maintaining Well Focused Shifts, and Level 3
00232 *>       Performance, SIAM Journal of Matrix Analysis, volume 23, pages
00233 *>       929--947, 2002.
00234 *> \n
00235 *>       K. Braman, R. Byers and R. Mathias, The Multi-Shift QR
00236 *>       Algorithm Part II: Aggressive Early Deflation, SIAM Journal
00237 *>       of Matrix Analysis, volume 23, pages 948--973, 2002.
00238 *>
00239 *  =====================================================================
00240       SUBROUTINE CLAQR0( WANTT, WANTZ, N, ILO, IHI, H, LDH, W, ILOZ,
00241      $                   IHIZ, Z, LDZ, WORK, LWORK, INFO )
00242 *
00243 *  -- LAPACK auxiliary routine (version 3.4.0) --
00244 *  -- LAPACK is a software package provided by Univ. of Tennessee,    --
00245 *  -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
00246 *     November 2011
00247 *
00248 *     .. Scalar Arguments ..
00249       INTEGER            IHI, IHIZ, ILO, ILOZ, INFO, LDH, LDZ, LWORK, N
00250       LOGICAL            WANTT, WANTZ
00251 *     ..
00252 *     .. Array Arguments ..
00253       COMPLEX            H( LDH, * ), W( * ), WORK( * ), Z( LDZ, * )
00254 *     ..
00255 *
00256 *  ================================================================
00257 *     .. Parameters ..
00258 *
00259 *     ==== Matrices of order NTINY or smaller must be processed by
00260 *     .    CLAHQR because of insufficient subdiagonal scratch space.
00261 *     .    (This is a hard limit.) ====
00262       INTEGER            NTINY
00263       PARAMETER          ( NTINY = 11 )
00264 *
00265 *     ==== Exceptional deflation windows:  try to cure rare
00266 *     .    slow convergence by varying the size of the
00267 *     .    deflation window after KEXNW iterations. ====
00268       INTEGER            KEXNW
00269       PARAMETER          ( KEXNW = 5 )
00270 *
00271 *     ==== Exceptional shifts: try to cure rare slow convergence
00272 *     .    with ad-hoc exceptional shifts every KEXSH iterations.
00273 *     .    ====
00274       INTEGER            KEXSH
00275       PARAMETER          ( KEXSH = 6 )
00276 *
00277 *     ==== The constant WILK1 is used to form the exceptional
00278 *     .    shifts. ====
00279       REAL               WILK1
00280       PARAMETER          ( WILK1 = 0.75e0 )
00281       COMPLEX            ZERO, ONE
00282       PARAMETER          ( ZERO = ( 0.0e0, 0.0e0 ),
00283      $                   ONE = ( 1.0e0, 0.0e0 ) )
00284       REAL               TWO
00285       PARAMETER          ( TWO = 2.0e0 )
00286 *     ..
00287 *     .. Local Scalars ..
00288       COMPLEX            AA, BB, CC, CDUM, DD, DET, RTDISC, SWAP, TR2
00289       REAL               S
00290       INTEGER            I, INF, IT, ITMAX, K, KACC22, KBOT, KDU, KS,
00291      $                   KT, KTOP, KU, KV, KWH, KWTOP, KWV, LD, LS,
00292      $                   LWKOPT, NDEC, NDFL, NH, NHO, NIBBLE, NMIN, NS,
00293      $                   NSMAX, NSR, NVE, NW, NWMAX, NWR, NWUPBD
00294       LOGICAL            SORTED
00295       CHARACTER          JBCMPZ*2
00296 *     ..
00297 *     .. External Functions ..
00298       INTEGER            ILAENV
00299       EXTERNAL           ILAENV
00300 *     ..
00301 *     .. Local Arrays ..
00302       COMPLEX            ZDUM( 1, 1 )
00303 *     ..
00304 *     .. External Subroutines ..
00305       EXTERNAL           CLACPY, CLAHQR, CLAQR3, CLAQR4, CLAQR5
00306 *     ..
00307 *     .. Intrinsic Functions ..
00308       INTRINSIC          ABS, AIMAG, CMPLX, INT, MAX, MIN, MOD, REAL,
00309      $                   SQRT
00310 *     ..
00311 *     .. Statement Functions ..
00312       REAL               CABS1
00313 *     ..
00314 *     .. Statement Function definitions ..
00315       CABS1( CDUM ) = ABS( REAL( CDUM ) ) + ABS( AIMAG( CDUM ) )
00316 *     ..
00317 *     .. Executable Statements ..
00318       INFO = 0
00319 *
00320 *     ==== Quick return for N = 0: nothing to do. ====
00321 *
00322       IF( N.EQ.0 ) THEN
00323          WORK( 1 ) = ONE
00324          RETURN
00325       END IF
00326 *
00327       IF( N.LE.NTINY ) THEN
00328 *
00329 *        ==== Tiny matrices must use CLAHQR. ====
00330 *
00331          LWKOPT = 1
00332          IF( LWORK.NE.-1 )
00333      $      CALL CLAHQR( WANTT, WANTZ, N, ILO, IHI, H, LDH, W, ILOZ,
00334      $                   IHIZ, Z, LDZ, INFO )
00335       ELSE
00336 *
00337 *        ==== Use small bulge multi-shift QR with aggressive early
00338 *        .    deflation on larger-than-tiny matrices. ====
00339 *
00340 *        ==== Hope for the best. ====
00341 *
00342          INFO = 0
00343 *
00344 *        ==== Set up job flags for ILAENV. ====
00345 *
00346          IF( WANTT ) THEN
00347             JBCMPZ( 1: 1 ) = 'S'
00348          ELSE
00349             JBCMPZ( 1: 1 ) = 'E'
00350          END IF
00351          IF( WANTZ ) THEN
00352             JBCMPZ( 2: 2 ) = 'V'
00353          ELSE
00354             JBCMPZ( 2: 2 ) = 'N'
00355          END IF
00356 *
00357 *        ==== NWR = recommended deflation window size.  At this
00358 *        .    point,  N .GT. NTINY = 11, so there is enough
00359 *        .    subdiagonal workspace for NWR.GE.2 as required.
00360 *        .    (In fact, there is enough subdiagonal space for
00361 *        .    NWR.GE.3.) ====
00362 *
00363          NWR = ILAENV( 13, 'CLAQR0', JBCMPZ, N, ILO, IHI, LWORK )
00364          NWR = MAX( 2, NWR )
00365          NWR = MIN( IHI-ILO+1, ( N-1 ) / 3, NWR )
00366 *
00367 *        ==== NSR = recommended number of simultaneous shifts.
00368 *        .    At this point N .GT. NTINY = 11, so there is at
00369 *        .    enough subdiagonal workspace for NSR to be even
00370 *        .    and greater than or equal to two as required. ====
00371 *
00372          NSR = ILAENV( 15, 'CLAQR0', JBCMPZ, N, ILO, IHI, LWORK )
00373          NSR = MIN( NSR, ( N+6 ) / 9, IHI-ILO )
00374          NSR = MAX( 2, NSR-MOD( NSR, 2 ) )
00375 *
00376 *        ==== Estimate optimal workspace ====
00377 *
00378 *        ==== Workspace query call to CLAQR3 ====
00379 *
00380          CALL CLAQR3( WANTT, WANTZ, N, ILO, IHI, NWR+1, H, LDH, ILOZ,
00381      $                IHIZ, Z, LDZ, LS, LD, W, H, LDH, N, H, LDH, N, H,
00382      $                LDH, WORK, -1 )
00383 *
00384 *        ==== Optimal workspace = MAX(CLAQR5, CLAQR3) ====
00385 *
00386          LWKOPT = MAX( 3*NSR / 2, INT( WORK( 1 ) ) )
00387 *
00388 *        ==== Quick return in case of workspace query. ====
00389 *
00390          IF( LWORK.EQ.-1 ) THEN
00391             WORK( 1 ) = CMPLX( LWKOPT, 0 )
00392             RETURN
00393          END IF
00394 *
00395 *        ==== CLAHQR/CLAQR0 crossover point ====
00396 *
00397          NMIN = ILAENV( 12, 'CLAQR0', JBCMPZ, N, ILO, IHI, LWORK )
00398          NMIN = MAX( NTINY, NMIN )
00399 *
00400 *        ==== Nibble crossover point ====
00401 *
00402          NIBBLE = ILAENV( 14, 'CLAQR0', JBCMPZ, N, ILO, IHI, LWORK )
00403          NIBBLE = MAX( 0, NIBBLE )
00404 *
00405 *        ==== Accumulate reflections during ttswp?  Use block
00406 *        .    2-by-2 structure during matrix-matrix multiply? ====
00407 *
00408          KACC22 = ILAENV( 16, 'CLAQR0', JBCMPZ, N, ILO, IHI, LWORK )
00409          KACC22 = MAX( 0, KACC22 )
00410          KACC22 = MIN( 2, KACC22 )
00411 *
00412 *        ==== NWMAX = the largest possible deflation window for
00413 *        .    which there is sufficient workspace. ====
00414 *
00415          NWMAX = MIN( ( N-1 ) / 3, LWORK / 2 )
00416          NW = NWMAX
00417 *
00418 *        ==== NSMAX = the Largest number of simultaneous shifts
00419 *        .    for which there is sufficient workspace. ====
00420 *
00421          NSMAX = MIN( ( N+6 ) / 9, 2*LWORK / 3 )
00422          NSMAX = NSMAX - MOD( NSMAX, 2 )
00423 *
00424 *        ==== NDFL: an iteration count restarted at deflation. ====
00425 *
00426          NDFL = 1
00427 *
00428 *        ==== ITMAX = iteration limit ====
00429 *
00430          ITMAX = MAX( 30, 2*KEXSH )*MAX( 10, ( IHI-ILO+1 ) )
00431 *
00432 *        ==== Last row and column in the active block ====
00433 *
00434          KBOT = IHI
00435 *
00436 *        ==== Main Loop ====
00437 *
00438          DO 70 IT = 1, ITMAX
00439 *
00440 *           ==== Done when KBOT falls below ILO ====
00441 *
00442             IF( KBOT.LT.ILO )
00443      $         GO TO 80
00444 *
00445 *           ==== Locate active block ====
00446 *
00447             DO 10 K = KBOT, ILO + 1, -1
00448                IF( H( K, K-1 ).EQ.ZERO )
00449      $            GO TO 20
00450    10       CONTINUE
00451             K = ILO
00452    20       CONTINUE
00453             KTOP = K
00454 *
00455 *           ==== Select deflation window size:
00456 *           .    Typical Case:
00457 *           .      If possible and advisable, nibble the entire
00458 *           .      active block.  If not, use size MIN(NWR,NWMAX)
00459 *           .      or MIN(NWR+1,NWMAX) depending upon which has
00460 *           .      the smaller corresponding subdiagonal entry
00461 *           .      (a heuristic).
00462 *           .
00463 *           .    Exceptional Case:
00464 *           .      If there have been no deflations in KEXNW or
00465 *           .      more iterations, then vary the deflation window
00466 *           .      size.   At first, because, larger windows are,
00467 *           .      in general, more powerful than smaller ones,
00468 *           .      rapidly increase the window to the maximum possible.
00469 *           .      Then, gradually reduce the window size. ====
00470 *
00471             NH = KBOT - KTOP + 1
00472             NWUPBD = MIN( NH, NWMAX )
00473             IF( NDFL.LT.KEXNW ) THEN
00474                NW = MIN( NWUPBD, NWR )
00475             ELSE
00476                NW = MIN( NWUPBD, 2*NW )
00477             END IF
00478             IF( NW.LT.NWMAX ) THEN
00479                IF( NW.GE.NH-1 ) THEN
00480                   NW = NH
00481                ELSE
00482                   KWTOP = KBOT - NW + 1
00483                   IF( CABS1( H( KWTOP, KWTOP-1 ) ).GT.
00484      $                CABS1( H( KWTOP-1, KWTOP-2 ) ) )NW = NW + 1
00485                END IF
00486             END IF
00487             IF( NDFL.LT.KEXNW ) THEN
00488                NDEC = -1
00489             ELSE IF( NDEC.GE.0 .OR. NW.GE.NWUPBD ) THEN
00490                NDEC = NDEC + 1
00491                IF( NW-NDEC.LT.2 )
00492      $            NDEC = 0
00493                NW = NW - NDEC
00494             END IF
00495 *
00496 *           ==== Aggressive early deflation:
00497 *           .    split workspace under the subdiagonal into
00498 *           .      - an nw-by-nw work array V in the lower
00499 *           .        left-hand-corner,
00500 *           .      - an NW-by-at-least-NW-but-more-is-better
00501 *           .        (NW-by-NHO) horizontal work array along
00502 *           .        the bottom edge,
00503 *           .      - an at-least-NW-but-more-is-better (NHV-by-NW)
00504 *           .        vertical work array along the left-hand-edge.
00505 *           .        ====
00506 *
00507             KV = N - NW + 1
00508             KT = NW + 1
00509             NHO = ( N-NW-1 ) - KT + 1
00510             KWV = NW + 2
00511             NVE = ( N-NW ) - KWV + 1
00512 *
00513 *           ==== Aggressive early deflation ====
00514 *
00515             CALL CLAQR3( WANTT, WANTZ, N, KTOP, KBOT, NW, H, LDH, ILOZ,
00516      $                   IHIZ, Z, LDZ, LS, LD, W, H( KV, 1 ), LDH, NHO,
00517      $                   H( KV, KT ), LDH, NVE, H( KWV, 1 ), LDH, WORK,
00518      $                   LWORK )
00519 *
00520 *           ==== Adjust KBOT accounting for new deflations. ====
00521 *
00522             KBOT = KBOT - LD
00523 *
00524 *           ==== KS points to the shifts. ====
00525 *
00526             KS = KBOT - LS + 1
00527 *
00528 *           ==== Skip an expensive QR sweep if there is a (partly
00529 *           .    heuristic) reason to expect that many eigenvalues
00530 *           .    will deflate without it.  Here, the QR sweep is
00531 *           .    skipped if many eigenvalues have just been deflated
00532 *           .    or if the remaining active block is small.
00533 *
00534             IF( ( LD.EQ.0 ) .OR. ( ( 100*LD.LE.NW*NIBBLE ) .AND. ( KBOT-
00535      $          KTOP+1.GT.MIN( NMIN, NWMAX ) ) ) ) THEN
00536 *
00537 *              ==== NS = nominal number of simultaneous shifts.
00538 *              .    This may be lowered (slightly) if CLAQR3
00539 *              .    did not provide that many shifts. ====
00540 *
00541                NS = MIN( NSMAX, NSR, MAX( 2, KBOT-KTOP ) )
00542                NS = NS - MOD( NS, 2 )
00543 *
00544 *              ==== If there have been no deflations
00545 *              .    in a multiple of KEXSH iterations,
00546 *              .    then try exceptional shifts.
00547 *              .    Otherwise use shifts provided by
00548 *              .    CLAQR3 above or from the eigenvalues
00549 *              .    of a trailing principal submatrix. ====
00550 *
00551                IF( MOD( NDFL, KEXSH ).EQ.0 ) THEN
00552                   KS = KBOT - NS + 1
00553                   DO 30 I = KBOT, KS + 1, -2
00554                      W( I ) = H( I, I ) + WILK1*CABS1( H( I, I-1 ) )
00555                      W( I-1 ) = W( I )
00556    30             CONTINUE
00557                ELSE
00558 *
00559 *                 ==== Got NS/2 or fewer shifts? Use CLAQR4 or
00560 *                 .    CLAHQR on a trailing principal submatrix to
00561 *                 .    get more. (Since NS.LE.NSMAX.LE.(N+6)/9,
00562 *                 .    there is enough space below the subdiagonal
00563 *                 .    to fit an NS-by-NS scratch array.) ====
00564 *
00565                   IF( KBOT-KS+1.LE.NS / 2 ) THEN
00566                      KS = KBOT - NS + 1
00567                      KT = N - NS + 1
00568                      CALL CLACPY( 'A', NS, NS, H( KS, KS ), LDH,
00569      $                            H( KT, 1 ), LDH )
00570                      IF( NS.GT.NMIN ) THEN
00571                         CALL CLAQR4( .false., .false., NS, 1, NS,
00572      $                               H( KT, 1 ), LDH, W( KS ), 1, 1,
00573      $                               ZDUM, 1, WORK, LWORK, INF )
00574                      ELSE
00575                         CALL CLAHQR( .false., .false., NS, 1, NS,
00576      $                               H( KT, 1 ), LDH, W( KS ), 1, 1,
00577      $                               ZDUM, 1, INF )
00578                      END IF
00579                      KS = KS + INF
00580 *
00581 *                    ==== In case of a rare QR failure use
00582 *                    .    eigenvalues of the trailing 2-by-2
00583 *                    .    principal submatrix.  Scale to avoid
00584 *                    .    overflows, underflows and subnormals.
00585 *                    .    (The scale factor S can not be zero,
00586 *                    .    because H(KBOT,KBOT-1) is nonzero.) ====
00587 *
00588                      IF( KS.GE.KBOT ) THEN
00589                         S = CABS1( H( KBOT-1, KBOT-1 ) ) +
00590      $                      CABS1( H( KBOT, KBOT-1 ) ) +
00591      $                      CABS1( H( KBOT-1, KBOT ) ) +
00592      $                      CABS1( H( KBOT, KBOT ) )
00593                         AA = H( KBOT-1, KBOT-1 ) / S
00594                         CC = H( KBOT, KBOT-1 ) / S
00595                         BB = H( KBOT-1, KBOT ) / S
00596                         DD = H( KBOT, KBOT ) / S
00597                         TR2 = ( AA+DD ) / TWO
00598                         DET = ( AA-TR2 )*( DD-TR2 ) - BB*CC
00599                         RTDISC = SQRT( -DET )
00600                         W( KBOT-1 ) = ( TR2+RTDISC )*S
00601                         W( KBOT ) = ( TR2-RTDISC )*S
00602 *
00603                         KS = KBOT - 1
00604                      END IF
00605                   END IF
00606 *
00607                   IF( KBOT-KS+1.GT.NS ) THEN
00608 *
00609 *                    ==== Sort the shifts (Helps a little) ====
00610 *
00611                      SORTED = .false.
00612                      DO 50 K = KBOT, KS + 1, -1
00613                         IF( SORTED )
00614      $                     GO TO 60
00615                         SORTED = .true.
00616                         DO 40 I = KS, K - 1
00617                            IF( CABS1( W( I ) ).LT.CABS1( W( I+1 ) ) )
00618      $                          THEN
00619                               SORTED = .false.
00620                               SWAP = W( I )
00621                               W( I ) = W( I+1 )
00622                               W( I+1 ) = SWAP
00623                            END IF
00624    40                   CONTINUE
00625    50                CONTINUE
00626    60                CONTINUE
00627                   END IF
00628                END IF
00629 *
00630 *              ==== If there are only two shifts, then use
00631 *              .    only one.  ====
00632 *
00633                IF( KBOT-KS+1.EQ.2 ) THEN
00634                   IF( CABS1( W( KBOT )-H( KBOT, KBOT ) ).LT.
00635      $                CABS1( W( KBOT-1 )-H( KBOT, KBOT ) ) ) THEN
00636                      W( KBOT-1 ) = W( KBOT )
00637                   ELSE
00638                      W( KBOT ) = W( KBOT-1 )
00639                   END IF
00640                END IF
00641 *
00642 *              ==== Use up to NS of the the smallest magnatiude
00643 *              .    shifts.  If there aren't NS shifts available,
00644 *              .    then use them all, possibly dropping one to
00645 *              .    make the number of shifts even. ====
00646 *
00647                NS = MIN( NS, KBOT-KS+1 )
00648                NS = NS - MOD( NS, 2 )
00649                KS = KBOT - NS + 1
00650 *
00651 *              ==== Small-bulge multi-shift QR sweep:
00652 *              .    split workspace under the subdiagonal into
00653 *              .    - a KDU-by-KDU work array U in the lower
00654 *              .      left-hand-corner,
00655 *              .    - a KDU-by-at-least-KDU-but-more-is-better
00656 *              .      (KDU-by-NHo) horizontal work array WH along
00657 *              .      the bottom edge,
00658 *              .    - and an at-least-KDU-but-more-is-better-by-KDU
00659 *              .      (NVE-by-KDU) vertical work WV arrow along
00660 *              .      the left-hand-edge. ====
00661 *
00662                KDU = 3*NS - 3
00663                KU = N - KDU + 1
00664                KWH = KDU + 1
00665                NHO = ( N-KDU+1-4 ) - ( KDU+1 ) + 1
00666                KWV = KDU + 4
00667                NVE = N - KDU - KWV + 1
00668 *
00669 *              ==== Small-bulge multi-shift QR sweep ====
00670 *
00671                CALL CLAQR5( WANTT, WANTZ, KACC22, N, KTOP, KBOT, NS,
00672      $                      W( KS ), H, LDH, ILOZ, IHIZ, Z, LDZ, WORK,
00673      $                      3, H( KU, 1 ), LDH, NVE, H( KWV, 1 ), LDH,
00674      $                      NHO, H( KU, KWH ), LDH )
00675             END IF
00676 *
00677 *           ==== Note progress (or the lack of it). ====
00678 *
00679             IF( LD.GT.0 ) THEN
00680                NDFL = 1
00681             ELSE
00682                NDFL = NDFL + 1
00683             END IF
00684 *
00685 *           ==== End of main loop ====
00686    70    CONTINUE
00687 *
00688 *        ==== Iteration limit exceeded.  Set INFO to show where
00689 *        .    the problem occurred and exit. ====
00690 *
00691          INFO = KBOT
00692    80    CONTINUE
00693       END IF
00694 *
00695 *     ==== Return the optimal value of LWORK. ====
00696 *
00697       WORK( 1 ) = CMPLX( LWKOPT, 0 )
00698 *
00699 *     ==== End of CLAQR0 ====
00700 *
00701       END
 All Files Functions