001:       SUBROUTINE ZHEEVR( JOBZ, RANGE, UPLO, N, A, LDA, VL, VU, IL, IU,
002:      $                   ABSTOL, M, W, Z, LDZ, ISUPPZ, WORK, LWORK,
003:      $                   RWORK, LRWORK, IWORK, LIWORK, INFO )
004: *
005: *  -- LAPACK driver routine (version 3.2) --
006: *     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
007: *     November 2006
008: *
009: *     .. Scalar Arguments ..
010:       CHARACTER          JOBZ, RANGE, UPLO
011:       INTEGER            IL, INFO, IU, LDA, LDZ, LIWORK, LRWORK, LWORK,
012:      $                   M, N
013:       DOUBLE PRECISION   ABSTOL, VL, VU
014: *     ..
015: *     .. Array Arguments ..
016:       INTEGER            ISUPPZ( * ), IWORK( * )
017:       DOUBLE PRECISION   RWORK( * ), W( * )
018:       COMPLEX*16         A( LDA, * ), WORK( * ), Z( LDZ, * )
019: *     ..
020: *
021: *  Purpose
022: *  =======
023: *
024: *  ZHEEVR computes selected eigenvalues and, optionally, eigenvectors
025: *  of a complex Hermitian matrix A.  Eigenvalues and eigenvectors can
026: *  be selected by specifying either a range of values or a range of
027: *  indices for the desired eigenvalues.
028: *
029: *  ZHEEVR first reduces the matrix A to tridiagonal form T with a call
030: *  to ZHETRD.  Then, whenever possible, ZHEEVR calls ZSTEMR to compute
031: *  eigenspectrum using Relatively Robust Representations.  ZSTEMR
032: *  computes eigenvalues by the dqds algorithm, while orthogonal
033: *  eigenvectors are computed from various "good" L D L^T representations
034: *  (also known as Relatively Robust Representations). Gram-Schmidt
035: *  orthogonalization is avoided as far as possible. More specifically,
036: *  the various steps of the algorithm are as follows.
037: *
038: *  For each unreduced block (submatrix) of T,
039: *     (a) Compute T - sigma I  = L D L^T, so that L and D
040: *         define all the wanted eigenvalues to high relative accuracy.
041: *         This means that small relative changes in the entries of D and L
042: *         cause only small relative changes in the eigenvalues and
043: *         eigenvectors. The standard (unfactored) representation of the
044: *         tridiagonal matrix T does not have this property in general.
045: *     (b) Compute the eigenvalues to suitable accuracy.
046: *         If the eigenvectors are desired, the algorithm attains full
047: *         accuracy of the computed eigenvalues only right before
048: *         the corresponding vectors have to be computed, see steps c) and d).
049: *     (c) For each cluster of close eigenvalues, select a new
050: *         shift close to the cluster, find a new factorization, and refine
051: *         the shifted eigenvalues to suitable accuracy.
052: *     (d) For each eigenvalue with a large enough relative separation compute
053: *         the corresponding eigenvector by forming a rank revealing twisted
054: *         factorization. Go back to (c) for any clusters that remain.
055: *
056: *  The desired accuracy of the output can be specified by the input
057: *  parameter ABSTOL.
058: *
059: *  For more details, see DSTEMR's documentation and:
060: *  - Inderjit S. Dhillon and Beresford N. Parlett: "Multiple representations
061: *    to compute orthogonal eigenvectors of symmetric tridiagonal matrices,"
062: *    Linear Algebra and its Applications, 387(1), pp. 1-28, August 2004.
063: *  - Inderjit Dhillon and Beresford Parlett: "Orthogonal Eigenvectors and
064: *    Relative Gaps," SIAM Journal on Matrix Analysis and Applications, Vol. 25,
065: *    2004.  Also LAPACK Working Note 154.
066: *  - Inderjit Dhillon: "A new O(n^2) algorithm for the symmetric
067: *    tridiagonal eigenvalue/eigenvector problem",
068: *    Computer Science Division Technical Report No. UCB/CSD-97-971,
069: *    UC Berkeley, May 1997.
070: *
071: *
072: *  Note 1 : ZHEEVR calls ZSTEMR when the full spectrum is requested
073: *  on machines which conform to the ieee-754 floating point standard.
074: *  ZHEEVR calls DSTEBZ and ZSTEIN on non-ieee machines and
075: *  when partial spectrum requests are made.
076: *
077: *  Normal execution of ZSTEMR may create NaNs and infinities and
078: *  hence may abort due to a floating point exception in environments
079: *  which do not handle NaNs and infinities in the ieee standard default
080: *  manner.
081: *
082: *  Arguments
083: *  =========
084: *
085: *  JOBZ    (input) CHARACTER*1
086: *          = 'N':  Compute eigenvalues only;
087: *          = 'V':  Compute eigenvalues and eigenvectors.
088: *
089: *  RANGE   (input) CHARACTER*1
090: *          = 'A': all eigenvalues will be found.
091: *          = 'V': all eigenvalues in the half-open interval (VL,VU]
092: *                 will be found.
093: *          = 'I': the IL-th through IU-th eigenvalues will be found.
094: ********** For RANGE = 'V' or 'I' and IU - IL < N - 1, DSTEBZ and
095: ********** ZSTEIN are called
096: *
097: *  UPLO    (input) CHARACTER*1
098: *          = 'U':  Upper triangle of A is stored;
099: *          = 'L':  Lower triangle of A is stored.
100: *
101: *  N       (input) INTEGER
102: *          The order of the matrix A.  N >= 0.
103: *
104: *  A       (input/output) COMPLEX*16 array, dimension (LDA, N)
105: *          On entry, the Hermitian matrix A.  If UPLO = 'U', the
106: *          leading N-by-N upper triangular part of A contains the
107: *          upper triangular part of the matrix A.  If UPLO = 'L',
108: *          the leading N-by-N lower triangular part of A contains
109: *          the lower triangular part of the matrix A.
110: *          On exit, the lower triangle (if UPLO='L') or the upper
111: *          triangle (if UPLO='U') of A, including the diagonal, is
112: *          destroyed.
113: *
114: *  LDA     (input) INTEGER
115: *          The leading dimension of the array A.  LDA >= max(1,N).
116: *
117: *  VL      (input) DOUBLE PRECISION
118: *  VU      (input) DOUBLE PRECISION
119: *          If RANGE='V', the lower and upper bounds of the interval to
120: *          be searched for eigenvalues. VL < VU.
121: *          Not referenced if RANGE = 'A' or 'I'.
122: *
123: *  IL      (input) INTEGER
124: *  IU      (input) INTEGER
125: *          If RANGE='I', the indices (in ascending order) of the
126: *          smallest and largest eigenvalues to be returned.
127: *          1 <= IL <= IU <= N, if N > 0; IL = 1 and IU = 0 if N = 0.
128: *          Not referenced if RANGE = 'A' or 'V'.
129: *
130: *  ABSTOL  (input) DOUBLE PRECISION
131: *          The absolute error tolerance for the eigenvalues.
132: *          An approximate eigenvalue is accepted as converged
133: *          when it is determined to lie in an interval [a,b]
134: *          of width less than or equal to
135: *
136: *                  ABSTOL + EPS *   max( |a|,|b| ) ,
137: *
138: *          where EPS is the machine precision.  If ABSTOL is less than
139: *          or equal to zero, then  EPS*|T|  will be used in its place,
140: *          where |T| is the 1-norm of the tridiagonal matrix obtained
141: *          by reducing A to tridiagonal form.
142: *
143: *          See "Computing Small Singular Values of Bidiagonal Matrices
144: *          with Guaranteed High Relative Accuracy," by Demmel and
145: *          Kahan, LAPACK Working Note #3.
146: *
147: *          If high relative accuracy is important, set ABSTOL to
148: *          DLAMCH( 'Safe minimum' ).  Doing so will guarantee that
149: *          eigenvalues are computed to high relative accuracy when
150: *          possible in future releases.  The current code does not
151: *          make any guarantees about high relative accuracy, but
152: *          furutre releases will. See J. Barlow and J. Demmel,
153: *          "Computing Accurate Eigensystems of Scaled Diagonally
154: *          Dominant Matrices", LAPACK Working Note #7, for a discussion
155: *          of which matrices define their eigenvalues to high relative
156: *          accuracy.
157: *
158: *  M       (output) INTEGER
159: *          The total number of eigenvalues found.  0 <= M <= N.
160: *          If RANGE = 'A', M = N, and if RANGE = 'I', M = IU-IL+1.
161: *
162: *  W       (output) DOUBLE PRECISION array, dimension (N)
163: *          The first M elements contain the selected eigenvalues in
164: *          ascending order.
165: *
166: *  Z       (output) COMPLEX*16 array, dimension (LDZ, max(1,M))
167: *          If JOBZ = 'V', then if INFO = 0, the first M columns of Z
168: *          contain the orthonormal eigenvectors of the matrix A
169: *          corresponding to the selected eigenvalues, with the i-th
170: *          column of Z holding the eigenvector associated with W(i).
171: *          If JOBZ = 'N', then Z is not referenced.
172: *          Note: the user must ensure that at least max(1,M) columns are
173: *          supplied in the array Z; if RANGE = 'V', the exact value of M
174: *          is not known in advance and an upper bound must be used.
175: *
176: *  LDZ     (input) INTEGER
177: *          The leading dimension of the array Z.  LDZ >= 1, and if
178: *          JOBZ = 'V', LDZ >= max(1,N).
179: *
180: *  ISUPPZ  (output) INTEGER array, dimension ( 2*max(1,M) )
181: *          The support of the eigenvectors in Z, i.e., the indices
182: *          indicating the nonzero elements in Z. The i-th eigenvector
183: *          is nonzero only in elements ISUPPZ( 2*i-1 ) through
184: *          ISUPPZ( 2*i ).
185: ********** Implemented only for RANGE = 'A' or 'I' and IU - IL = N - 1
186: *
187: *  WORK    (workspace/output) COMPLEX*16 array, dimension (MAX(1,LWORK))
188: *          On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
189: *
190: *  LWORK   (input) INTEGER
191: *          The length of the array WORK.  LWORK >= max(1,2*N).
192: *          For optimal efficiency, LWORK >= (NB+1)*N,
193: *          where NB is the max of the blocksize for ZHETRD and for
194: *          ZUNMTR as returned by ILAENV.
195: *
196: *          If LWORK = -1, then a workspace query is assumed; the routine
197: *          only calculates the optimal sizes of the WORK, RWORK and
198: *          IWORK arrays, returns these values as the first entries of
199: *          the WORK, RWORK and IWORK arrays, and no error message
200: *          related to LWORK or LRWORK or LIWORK is issued by XERBLA.
201: *
202: *  RWORK   (workspace/output) DOUBLE PRECISION array, dimension (MAX(1,LRWORK))
203: *          On exit, if INFO = 0, RWORK(1) returns the optimal
204: *          (and minimal) LRWORK.
205: *
206: * LRWORK   (input) INTEGER
207: *          The length of the array RWORK.  LRWORK >= max(1,24*N).
208: *
209: *          If LRWORK = -1, then a workspace query is assumed; the
210: *          routine only calculates the optimal sizes of the WORK, RWORK
211: *          and IWORK arrays, returns these values as the first entries
212: *          of the WORK, RWORK and IWORK arrays, and no error message
213: *          related to LWORK or LRWORK or LIWORK is issued by XERBLA.
214: *
215: *  IWORK   (workspace/output) INTEGER array, dimension (MAX(1,LIWORK))
216: *          On exit, if INFO = 0, IWORK(1) returns the optimal
217: *          (and minimal) LIWORK.
218: *
219: * LIWORK   (input) INTEGER
220: *          The dimension of the array IWORK.  LIWORK >= max(1,10*N).
221: *
222: *          If LIWORK = -1, then a workspace query is assumed; the
223: *          routine only calculates the optimal sizes of the WORK, RWORK
224: *          and IWORK arrays, returns these values as the first entries
225: *          of the WORK, RWORK and IWORK arrays, and no error message
226: *          related to LWORK or LRWORK or LIWORK is issued by XERBLA.
227: *
228: *  INFO    (output) INTEGER
229: *          = 0:  successful exit
230: *          < 0:  if INFO = -i, the i-th argument had an illegal value
231: *          > 0:  Internal error
232: *
233: *  Further Details
234: *  ===============
235: *
236: *  Based on contributions by
237: *     Inderjit Dhillon, IBM Almaden, USA
238: *     Osni Marques, LBNL/NERSC, USA
239: *     Ken Stanley, Computer Science Division, University of
240: *       California at Berkeley, USA
241: *     Jason Riedy, Computer Science Division, University of
242: *       California at Berkeley, USA
243: *
244: * =====================================================================
245: *
246: *     .. Parameters ..
247:       DOUBLE PRECISION   ZERO, ONE, TWO
248:       PARAMETER          ( ZERO = 0.0D+0, ONE = 1.0D+0, TWO = 2.0D+0 )
249: *     ..
250: *     .. Local Scalars ..
251:       LOGICAL            ALLEIG, INDEIG, LOWER, LQUERY, TEST, VALEIG,
252:      $                   WANTZ, TRYRAC
253:       CHARACTER          ORDER
254:       INTEGER            I, IEEEOK, IINFO, IMAX, INDIBL, INDIFL, INDISP,
255:      $                   INDIWO, INDRD, INDRDD, INDRE, INDREE, INDRWK,
256:      $                   INDTAU, INDWK, INDWKN, ISCALE, ITMP1, J, JJ,
257:      $                   LIWMIN, LLWORK, LLRWORK, LLWRKN, LRWMIN,
258:      $                   LWKOPT, LWMIN, NB, NSPLIT
259:       DOUBLE PRECISION   ABSTLL, ANRM, BIGNUM, EPS, RMAX, RMIN, SAFMIN,
260:      $                   SIGMA, SMLNUM, TMP1, VLL, VUU
261: *     ..
262: *     .. External Functions ..
263:       LOGICAL            LSAME
264:       INTEGER            ILAENV
265:       DOUBLE PRECISION   DLAMCH, ZLANSY
266:       EXTERNAL           LSAME, ILAENV, DLAMCH, ZLANSY
267: *     ..
268: *     .. External Subroutines ..
269:       EXTERNAL           DCOPY, DSCAL, DSTEBZ, DSTERF, XERBLA, ZDSCAL,
270:      $                   ZHETRD, ZSTEMR, ZSTEIN, ZSWAP, ZUNMTR
271: *     ..
272: *     .. Intrinsic Functions ..
273:       INTRINSIC          DBLE, MAX, MIN, SQRT
274: *     ..
275: *     .. Executable Statements ..
276: *
277: *     Test the input parameters.
278: *
279:       IEEEOK = ILAENV( 10, 'ZHEEVR', 'N', 1, 2, 3, 4 )
280: *
281:       LOWER = LSAME( UPLO, 'L' )
282:       WANTZ = LSAME( JOBZ, 'V' )
283:       ALLEIG = LSAME( RANGE, 'A' )
284:       VALEIG = LSAME( RANGE, 'V' )
285:       INDEIG = LSAME( RANGE, 'I' )
286: *
287:       LQUERY = ( ( LWORK.EQ.-1 ) .OR. ( LRWORK.EQ.-1 ) .OR.
288:      $         ( LIWORK.EQ.-1 ) )
289: *
290:       LRWMIN = MAX( 1, 24*N )
291:       LIWMIN = MAX( 1, 10*N )
292:       LWMIN = MAX( 1, 2*N )
293: *
294:       INFO = 0
295:       IF( .NOT.( WANTZ .OR. LSAME( JOBZ, 'N' ) ) ) THEN
296:          INFO = -1
297:       ELSE IF( .NOT.( ALLEIG .OR. VALEIG .OR. INDEIG ) ) THEN
298:          INFO = -2
299:       ELSE IF( .NOT.( LOWER .OR. LSAME( UPLO, 'U' ) ) ) THEN
300:          INFO = -3
301:       ELSE IF( N.LT.0 ) THEN
302:          INFO = -4
303:       ELSE IF( LDA.LT.MAX( 1, N ) ) THEN
304:          INFO = -6
305:       ELSE
306:          IF( VALEIG ) THEN
307:             IF( N.GT.0 .AND. VU.LE.VL )
308:      $         INFO = -8
309:          ELSE IF( INDEIG ) THEN
310:             IF( IL.LT.1 .OR. IL.GT.MAX( 1, N ) ) THEN
311:                INFO = -9
312:             ELSE IF( IU.LT.MIN( N, IL ) .OR. IU.GT.N ) THEN
313:                INFO = -10
314:             END IF
315:          END IF
316:       END IF
317:       IF( INFO.EQ.0 ) THEN
318:          IF( LDZ.LT.1 .OR. ( WANTZ .AND. LDZ.LT.N ) ) THEN
319:             INFO = -15
320:          END IF
321:       END IF
322: *
323:       IF( INFO.EQ.0 ) THEN
324:          NB = ILAENV( 1, 'ZHETRD', UPLO, N, -1, -1, -1 )
325:          NB = MAX( NB, ILAENV( 1, 'ZUNMTR', UPLO, N, -1, -1, -1 ) )
326:          LWKOPT = MAX( ( NB+1 )*N, LWMIN )
327:          WORK( 1 ) = LWKOPT
328:          RWORK( 1 ) = LRWMIN
329:          IWORK( 1 ) = LIWMIN
330: *
331:          IF( LWORK.LT.LWMIN .AND. .NOT.LQUERY ) THEN
332:             INFO = -18
333:          ELSE IF( LRWORK.LT.LRWMIN .AND. .NOT.LQUERY ) THEN
334:             INFO = -20
335:          ELSE IF( LIWORK.LT.LIWMIN .AND. .NOT.LQUERY ) THEN
336:             INFO = -22
337:          END IF
338:       END IF
339: *
340:       IF( INFO.NE.0 ) THEN
341:          CALL XERBLA( 'ZHEEVR', -INFO )
342:          RETURN
343:       ELSE IF( LQUERY ) THEN
344:          RETURN
345:       END IF
346: *
347: *     Quick return if possible
348: *
349:       M = 0
350:       IF( N.EQ.0 ) THEN
351:          WORK( 1 ) = 1
352:          RETURN
353:       END IF
354: *
355:       IF( N.EQ.1 ) THEN
356:          WORK( 1 ) = 2
357:          IF( ALLEIG .OR. INDEIG ) THEN
358:             M = 1
359:             W( 1 ) = DBLE( A( 1, 1 ) )
360:          ELSE
361:             IF( VL.LT.DBLE( A( 1, 1 ) ) .AND. VU.GE.DBLE( A( 1, 1 ) ) )
362:      $           THEN
363:                M = 1
364:                W( 1 ) = DBLE( A( 1, 1 ) )
365:             END IF
366:          END IF
367:          IF( WANTZ )
368:      $      Z( 1, 1 ) = ONE
369:          RETURN
370:       END IF
371: *
372: *     Get machine constants.
373: *
374:       SAFMIN = DLAMCH( 'Safe minimum' )
375:       EPS = DLAMCH( 'Precision' )
376:       SMLNUM = SAFMIN / EPS
377:       BIGNUM = ONE / SMLNUM
378:       RMIN = SQRT( SMLNUM )
379:       RMAX = MIN( SQRT( BIGNUM ), ONE / SQRT( SQRT( SAFMIN ) ) )
380: *
381: *     Scale matrix to allowable range, if necessary.
382: *
383:       ISCALE = 0
384:       ABSTLL = ABSTOL
385:       IF (VALEIG) THEN
386:          VLL = VL
387:          VUU = VU
388:       END IF
389:       ANRM = ZLANSY( 'M', UPLO, N, A, LDA, RWORK )
390:       IF( ANRM.GT.ZERO .AND. ANRM.LT.RMIN ) THEN
391:          ISCALE = 1
392:          SIGMA = RMIN / ANRM
393:       ELSE IF( ANRM.GT.RMAX ) THEN
394:          ISCALE = 1
395:          SIGMA = RMAX / ANRM
396:       END IF
397:       IF( ISCALE.EQ.1 ) THEN
398:          IF( LOWER ) THEN
399:             DO 10 J = 1, N
400:                CALL ZDSCAL( N-J+1, SIGMA, A( J, J ), 1 )
401:    10       CONTINUE
402:          ELSE
403:             DO 20 J = 1, N
404:                CALL ZDSCAL( J, SIGMA, A( 1, J ), 1 )
405:    20       CONTINUE
406:          END IF
407:          IF( ABSTOL.GT.0 )
408:      $      ABSTLL = ABSTOL*SIGMA
409:          IF( VALEIG ) THEN
410:             VLL = VL*SIGMA
411:             VUU = VU*SIGMA
412:          END IF
413:       END IF
414: 
415: *     Initialize indices into workspaces.  Note: The IWORK indices are
416: *     used only if DSTERF or ZSTEMR fail.
417: 
418: *     WORK(INDTAU:INDTAU+N-1) stores the complex scalar factors of the
419: *     elementary reflectors used in ZHETRD.
420:       INDTAU = 1
421: *     INDWK is the starting offset of the remaining complex workspace,
422: *     and LLWORK is the remaining complex workspace size.
423:       INDWK = INDTAU + N
424:       LLWORK = LWORK - INDWK + 1
425: 
426: *     RWORK(INDRD:INDRD+N-1) stores the real tridiagonal's diagonal
427: *     entries.
428:       INDRD = 1
429: *     RWORK(INDRE:INDRE+N-1) stores the off-diagonal entries of the
430: *     tridiagonal matrix from ZHETRD.
431:       INDRE = INDRD + N
432: *     RWORK(INDRDD:INDRDD+N-1) is a copy of the diagonal entries over
433: *     -written by ZSTEMR (the DSTERF path copies the diagonal to W).
434:       INDRDD = INDRE + N
435: *     RWORK(INDREE:INDREE+N-1) is a copy of the off-diagonal entries over
436: *     -written while computing the eigenvalues in DSTERF and ZSTEMR.
437:       INDREE = INDRDD + N
438: *     INDRWK is the starting offset of the left-over real workspace, and
439: *     LLRWORK is the remaining workspace size.
440:       INDRWK = INDREE + N
441:       LLRWORK = LRWORK - INDRWK + 1
442: 
443: *     IWORK(INDIBL:INDIBL+M-1) corresponds to IBLOCK in DSTEBZ and
444: *     stores the block indices of each of the M<=N eigenvalues.
445:       INDIBL = 1
446: *     IWORK(INDISP:INDISP+NSPLIT-1) corresponds to ISPLIT in DSTEBZ and
447: *     stores the starting and finishing indices of each block.
448:       INDISP = INDIBL + N
449: *     IWORK(INDIFL:INDIFL+N-1) stores the indices of eigenvectors
450: *     that corresponding to eigenvectors that fail to converge in
451: *     DSTEIN.  This information is discarded; if any fail, the driver
452: *     returns INFO > 0.
453:       INDIFL = INDISP + N
454: *     INDIWO is the offset of the remaining integer workspace.
455:       INDIWO = INDISP + N
456: 
457: *
458: *     Call ZHETRD to reduce Hermitian matrix to tridiagonal form.
459: *
460:       CALL ZHETRD( UPLO, N, A, LDA, RWORK( INDRD ), RWORK( INDRE ),
461:      $             WORK( INDTAU ), WORK( INDWK ), LLWORK, IINFO )
462: *
463: *     If all eigenvalues are desired
464: *     then call DSTERF or ZSTEMR and ZUNMTR.
465: *
466:       TEST = .FALSE.
467:       IF( INDEIG ) THEN
468:          IF( IL.EQ.1 .AND. IU.EQ.N ) THEN
469:             TEST = .TRUE.
470:          END IF
471:       END IF
472:       IF( ( ALLEIG.OR.TEST ) .AND. ( IEEEOK.EQ.1 ) ) THEN
473:          IF( .NOT.WANTZ ) THEN
474:             CALL DCOPY( N, RWORK( INDRD ), 1, W, 1 )
475:             CALL DCOPY( N-1, RWORK( INDRE ), 1, RWORK( INDREE ), 1 )
476:             CALL DSTERF( N, W, RWORK( INDREE ), INFO )
477:          ELSE
478:             CALL DCOPY( N-1, RWORK( INDRE ), 1, RWORK( INDREE ), 1 )
479:             CALL DCOPY( N, RWORK( INDRD ), 1, RWORK( INDRDD ), 1 )
480: *
481:             IF (ABSTOL .LE. TWO*N*EPS) THEN
482:                TRYRAC = .TRUE.
483:             ELSE
484:                TRYRAC = .FALSE.
485:             END IF
486:             CALL ZSTEMR( JOBZ, 'A', N, RWORK( INDRDD ),
487:      $                   RWORK( INDREE ), VL, VU, IL, IU, M, W,
488:      $                   Z, LDZ, N, ISUPPZ, TRYRAC,
489:      $                   RWORK( INDRWK ), LLRWORK,
490:      $                   IWORK, LIWORK, INFO )
491: *
492: *           Apply unitary matrix used in reduction to tridiagonal
493: *           form to eigenvectors returned by ZSTEIN.
494: *
495:             IF( WANTZ .AND. INFO.EQ.0 ) THEN
496:                INDWKN = INDWK
497:                LLWRKN = LWORK - INDWKN + 1
498:                CALL ZUNMTR( 'L', UPLO, 'N', N, M, A, LDA,
499:      $                      WORK( INDTAU ), Z, LDZ, WORK( INDWKN ),
500:      $                      LLWRKN, IINFO )
501:             END IF
502:          END IF
503: *
504: *
505:          IF( INFO.EQ.0 ) THEN
506:             M = N
507:             GO TO 30
508:          END IF
509:          INFO = 0
510:       END IF
511: *
512: *     Otherwise, call DSTEBZ and, if eigenvectors are desired, ZSTEIN.
513: *     Also call DSTEBZ and ZSTEIN if ZSTEMR fails.
514: *
515:       IF( WANTZ ) THEN
516:          ORDER = 'B'
517:       ELSE
518:          ORDER = 'E'
519:       END IF
520: 
521:       CALL DSTEBZ( RANGE, ORDER, N, VLL, VUU, IL, IU, ABSTLL,
522:      $             RWORK( INDRD ), RWORK( INDRE ), M, NSPLIT, W,
523:      $             IWORK( INDIBL ), IWORK( INDISP ), RWORK( INDRWK ),
524:      $             IWORK( INDIWO ), INFO )
525: *
526:       IF( WANTZ ) THEN
527:          CALL ZSTEIN( N, RWORK( INDRD ), RWORK( INDRE ), M, W,
528:      $                IWORK( INDIBL ), IWORK( INDISP ), Z, LDZ,
529:      $                RWORK( INDRWK ), IWORK( INDIWO ), IWORK( INDIFL ),
530:      $                INFO )
531: *
532: *        Apply unitary matrix used in reduction to tridiagonal
533: *        form to eigenvectors returned by ZSTEIN.
534: *
535:          INDWKN = INDWK
536:          LLWRKN = LWORK - INDWKN + 1
537:          CALL ZUNMTR( 'L', UPLO, 'N', N, M, A, LDA, WORK( INDTAU ), Z,
538:      $                LDZ, WORK( INDWKN ), LLWRKN, IINFO )
539:       END IF
540: *
541: *     If matrix was scaled, then rescale eigenvalues appropriately.
542: *
543:    30 CONTINUE
544:       IF( ISCALE.EQ.1 ) THEN
545:          IF( INFO.EQ.0 ) THEN
546:             IMAX = M
547:          ELSE
548:             IMAX = INFO - 1
549:          END IF
550:          CALL DSCAL( IMAX, ONE / SIGMA, W, 1 )
551:       END IF
552: *
553: *     If eigenvalues are not in order, then sort them, along with
554: *     eigenvectors.
555: *
556:       IF( WANTZ ) THEN
557:          DO 50 J = 1, M - 1
558:             I = 0
559:             TMP1 = W( J )
560:             DO 40 JJ = J + 1, M
561:                IF( W( JJ ).LT.TMP1 ) THEN
562:                   I = JJ
563:                   TMP1 = W( JJ )
564:                END IF
565:    40       CONTINUE
566: *
567:             IF( I.NE.0 ) THEN
568:                ITMP1 = IWORK( INDIBL+I-1 )
569:                W( I ) = W( J )
570:                IWORK( INDIBL+I-1 ) = IWORK( INDIBL+J-1 )
571:                W( J ) = TMP1
572:                IWORK( INDIBL+J-1 ) = ITMP1
573:                CALL ZSWAP( N, Z( 1, I ), 1, Z( 1, J ), 1 )
574:             END IF
575:    50    CONTINUE
576:       END IF
577: *
578: *     Set WORK(1) to optimal workspace size.
579: *
580:       WORK( 1 ) = LWKOPT
581:       RWORK( 1 ) = LRWMIN
582:       IWORK( 1 ) = LIWMIN
583: *
584:       RETURN
585: *
586: *     End of ZHEEVR
587: *
588:       END
589: