001:       SUBROUTINE ZSTEMR( JOBZ, RANGE, N, D, E, VL, VU, IL, IU,
002:      $                   M, W, Z, LDZ, NZC, ISUPPZ, TRYRAC, WORK, LWORK,
003:      $                   IWORK, LIWORK, INFO )
004:       IMPLICIT NONE
005: *
006: *  -- LAPACK computational routine (version 3.2) --
007: *     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
008: *     November 2006
009: *
010: *     .. Scalar Arguments ..
011:       CHARACTER          JOBZ, RANGE
012:       LOGICAL            TRYRAC
013:       INTEGER            IL, INFO, IU, LDZ, NZC, LIWORK, LWORK, M, N
014:       DOUBLE PRECISION VL, VU
015: *     ..
016: *     .. Array Arguments ..
017:       INTEGER            ISUPPZ( * ), IWORK( * )
018:       DOUBLE PRECISION   D( * ), E( * ), W( * ), WORK( * )
019:       COMPLEX*16         Z( LDZ, * )
020: *     ..
021: *
022: *  Purpose
023: *  =======
024: *
025: *  ZSTEMR computes selected eigenvalues and, optionally, eigenvectors
026: *  of a real symmetric tridiagonal matrix T. Any such unreduced matrix has
027: *  a well defined set of pairwise different real eigenvalues, the corresponding
028: *  real eigenvectors are pairwise orthogonal.
029: *
030: *  The spectrum may be computed either completely or partially by specifying
031: *  either an interval (VL,VU] or a range of indices IL:IU for the desired
032: *  eigenvalues.
033: *
034: *  Depending on the number of desired eigenvalues, these are computed either
035: *  by bisection or the dqds algorithm. Numerically orthogonal eigenvectors are
036: *  computed by the use of various suitable L D L^T factorizations near clusters
037: *  of close eigenvalues (referred to as RRRs, Relatively Robust
038: *  Representations). An informal sketch of the algorithm follows.
039: *
040: *  For each unreduced block (submatrix) of T,
041: *     (a) Compute T - sigma I  = L D L^T, so that L and D
042: *         define all the wanted eigenvalues to high relative accuracy.
043: *         This means that small relative changes in the entries of D and L
044: *         cause only small relative changes in the eigenvalues and
045: *         eigenvectors. The standard (unfactored) representation of the
046: *         tridiagonal matrix T does not have this property in general.
047: *     (b) Compute the eigenvalues to suitable accuracy.
048: *         If the eigenvectors are desired, the algorithm attains full
049: *         accuracy of the computed eigenvalues only right before
050: *         the corresponding vectors have to be computed, see steps c) and d).
051: *     (c) For each cluster of close eigenvalues, select a new
052: *         shift close to the cluster, find a new factorization, and refine
053: *         the shifted eigenvalues to suitable accuracy.
054: *     (d) For each eigenvalue with a large enough relative separation compute
055: *         the corresponding eigenvector by forming a rank revealing twisted
056: *         factorization. Go back to (c) for any clusters that remain.
057: *
058: *  For more details, see:
059: *  - Inderjit S. Dhillon and Beresford N. Parlett: "Multiple representations
060: *    to compute orthogonal eigenvectors of symmetric tridiagonal matrices,"
061: *    Linear Algebra and its Applications, 387(1), pp. 1-28, August 2004.
062: *  - Inderjit Dhillon and Beresford Parlett: "Orthogonal Eigenvectors and
063: *    Relative Gaps," SIAM Journal on Matrix Analysis and Applications, Vol. 25,
064: *    2004.  Also LAPACK Working Note 154.
065: *  - Inderjit Dhillon: "A new O(n^2) algorithm for the symmetric
066: *    tridiagonal eigenvalue/eigenvector problem",
067: *    Computer Science Division Technical Report No. UCB/CSD-97-971,
068: *    UC Berkeley, May 1997.
069: *
070: *  Notes:
071: *  1.ZSTEMR works only on machines which follow IEEE-754
072: *  floating-point standard in their handling of infinities and NaNs.
073: *  This permits the use of efficient inner loops avoiding a check for
074: *  zero divisors.
075: *
076: *  2. LAPACK routines can be used to reduce a complex Hermitean matrix to
077: *  real symmetric tridiagonal form.
078: *
079: *  (Any complex Hermitean tridiagonal matrix has real values on its diagonal
080: *  and potentially complex numbers on its off-diagonals. By applying a
081: *  similarity transform with an appropriate diagonal matrix
082: *  diag(1,e^{i \phy_1}, ... , e^{i \phy_{n-1}}), the complex Hermitean
083: *  matrix can be transformed into a real symmetric matrix and complex
084: *  arithmetic can be entirely avoided.)
085: *
086: *  While the eigenvectors of the real symmetric tridiagonal matrix are real,
087: *  the eigenvectors of original complex Hermitean matrix have complex entries
088: *  in general.
089: *  Since LAPACK drivers overwrite the matrix data with the eigenvectors,
090: *  ZSTEMR accepts complex workspace to facilitate interoperability
091: *  with ZUNMTR or ZUPMTR.
092: *
093: *  Arguments
094: *  =========
095: *
096: *  JOBZ    (input) CHARACTER*1
097: *          = 'N':  Compute eigenvalues only;
098: *          = 'V':  Compute eigenvalues and eigenvectors.
099: *
100: *  RANGE   (input) CHARACTER*1
101: *          = 'A': all eigenvalues will be found.
102: *          = 'V': all eigenvalues in the half-open interval (VL,VU]
103: *                 will be found.
104: *          = 'I': the IL-th through IU-th eigenvalues will be found.
105: *
106: *  N       (input) INTEGER
107: *          The order of the matrix.  N >= 0.
108: *
109: *  D       (input/output) DOUBLE PRECISION array, dimension (N)
110: *          On entry, the N diagonal elements of the tridiagonal matrix
111: *          T. On exit, D is overwritten.
112: *
113: *  E       (input/output) DOUBLE PRECISION array, dimension (N)
114: *          On entry, the (N-1) subdiagonal elements of the tridiagonal
115: *          matrix T in elements 1 to N-1 of E. E(N) need not be set on
116: *          input, but is used internally as workspace.
117: *          On exit, E is overwritten.
118: *
119: *  VL      (input) DOUBLE PRECISION
120: *  VU      (input) DOUBLE PRECISION
121: *          If RANGE='V', the lower and upper bounds of the interval to
122: *          be searched for eigenvalues. VL < VU.
123: *          Not referenced if RANGE = 'A' or 'I'.
124: *
125: *  IL      (input) INTEGER
126: *  IU      (input) INTEGER
127: *          If RANGE='I', the indices (in ascending order) of the
128: *          smallest and largest eigenvalues to be returned.
129: *          1 <= IL <= IU <= N, if N > 0.
130: *          Not referenced if RANGE = 'A' or 'V'.
131: *
132: *  M       (output) INTEGER
133: *          The total number of eigenvalues found.  0 <= M <= N.
134: *          If RANGE = 'A', M = N, and if RANGE = 'I', M = IU-IL+1.
135: *
136: *  W       (output) DOUBLE PRECISION array, dimension (N)
137: *          The first M elements contain the selected eigenvalues in
138: *          ascending order.
139: *
140: *  Z       (output) COMPLEX*16 array, dimension (LDZ, max(1,M) )
141: *          If JOBZ = 'V', and if INFO = 0, then the first M columns of Z
142: *          contain the orthonormal eigenvectors of the matrix T
143: *          corresponding to the selected eigenvalues, with the i-th
144: *          column of Z holding the eigenvector associated with W(i).
145: *          If JOBZ = 'N', then Z is not referenced.
146: *          Note: the user must ensure that at least max(1,M) columns are
147: *          supplied in the array Z; if RANGE = 'V', the exact value of M
148: *          is not known in advance and can be computed with a workspace
149: *          query by setting NZC = -1, see below.
150: *
151: *  LDZ     (input) INTEGER
152: *          The leading dimension of the array Z.  LDZ >= 1, and if
153: *          JOBZ = 'V', then LDZ >= max(1,N).
154: *
155: *  NZC     (input) INTEGER
156: *          The number of eigenvectors to be held in the array Z.
157: *          If RANGE = 'A', then NZC >= max(1,N).
158: *          If RANGE = 'V', then NZC >= the number of eigenvalues in (VL,VU].
159: *          If RANGE = 'I', then NZC >= IU-IL+1.
160: *          If NZC = -1, then a workspace query is assumed; the
161: *          routine calculates the number of columns of the array Z that
162: *          are needed to hold the eigenvectors.
163: *          This value is returned as the first entry of the Z array, and
164: *          no error message related to NZC is issued by XERBLA.
165: *
166: *  ISUPPZ  (output) INTEGER ARRAY, dimension ( 2*max(1,M) )
167: *          The support of the eigenvectors in Z, i.e., the indices
168: *          indicating the nonzero elements in Z. The i-th computed eigenvector
169: *          is nonzero only in elements ISUPPZ( 2*i-1 ) through
170: *          ISUPPZ( 2*i ). This is relevant in the case when the matrix
171: *          is split. ISUPPZ is only accessed when JOBZ is 'V' and N > 0.
172: *
173: *  TRYRAC  (input/output) LOGICAL
174: *          If TRYRAC.EQ..TRUE., indicates that the code should check whether
175: *          the tridiagonal matrix defines its eigenvalues to high relative
176: *          accuracy.  If so, the code uses relative-accuracy preserving
177: *          algorithms that might be (a bit) slower depending on the matrix.
178: *          If the matrix does not define its eigenvalues to high relative
179: *          accuracy, the code can uses possibly faster algorithms.
180: *          If TRYRAC.EQ..FALSE., the code is not required to guarantee
181: *          relatively accurate eigenvalues and can use the fastest possible
182: *          techniques.
183: *          On exit, a .TRUE. TRYRAC will be set to .FALSE. if the matrix
184: *          does not define its eigenvalues to high relative accuracy.
185: *
186: *  WORK    (workspace/output) DOUBLE PRECISION array, dimension (LWORK)
187: *          On exit, if INFO = 0, WORK(1) returns the optimal
188: *          (and minimal) LWORK.
189: *
190: *  LWORK   (input) INTEGER
191: *          The dimension of the array WORK. LWORK >= max(1,18*N)
192: *          if JOBZ = 'V', and LWORK >= max(1,12*N) if JOBZ = 'N'.
193: *          If LWORK = -1, then a workspace query is assumed; the routine
194: *          only calculates the optimal size of the WORK array, returns
195: *          this value as the first entry of the WORK array, and no error
196: *          message related to LWORK is issued by XERBLA.
197: *
198: *  IWORK   (workspace/output) INTEGER array, dimension (LIWORK)
199: *          On exit, if INFO = 0, IWORK(1) returns the optimal LIWORK.
200: *
201: *  LIWORK  (input) INTEGER
202: *          The dimension of the array IWORK.  LIWORK >= max(1,10*N)
203: *          if the eigenvectors are desired, and LIWORK >= max(1,8*N)
204: *          if only the eigenvalues are to be computed.
205: *          If LIWORK = -1, then a workspace query is assumed; the
206: *          routine only calculates the optimal size of the IWORK array,
207: *          returns this value as the first entry of the IWORK array, and
208: *          no error message related to LIWORK is issued by XERBLA.
209: *
210: *  INFO    (output) INTEGER
211: *          On exit, INFO
212: *          = 0:  successful exit
213: *          < 0:  if INFO = -i, the i-th argument had an illegal value
214: *          > 0:  if INFO = 1X, internal error in DLARRE,
215: *                if INFO = 2X, internal error in ZLARRV.
216: *                Here, the digit X = ABS( IINFO ) < 10, where IINFO is
217: *                the nonzero error code returned by DLARRE or
218: *                ZLARRV, respectively.
219: *
220: *
221: *  Further Details
222: *  ===============
223: *
224: *  Based on contributions by
225: *     Beresford Parlett, University of California, Berkeley, USA
226: *     Jim Demmel, University of California, Berkeley, USA
227: *     Inderjit Dhillon, University of Texas, Austin, USA
228: *     Osni Marques, LBNL/NERSC, USA
229: *     Christof Voemel, University of California, Berkeley, USA
230: *
231: *  =====================================================================
232: *
233: *     .. Parameters ..
234:       DOUBLE PRECISION   ZERO, ONE, FOUR, MINRGP
235:       PARAMETER          ( ZERO = 0.0D0, ONE = 1.0D0,
236:      $                     FOUR = 4.0D0,
237:      $                     MINRGP = 1.0D-3 )
238: *     ..
239: *     .. Local Scalars ..
240:       LOGICAL            ALLEIG, INDEIG, LQUERY, VALEIG, WANTZ, ZQUERY
241:       INTEGER            I, IBEGIN, IEND, IFIRST, IIL, IINDBL, IINDW,
242:      $                   IINDWK, IINFO, IINSPL, IIU, ILAST, IN, INDD,
243:      $                   INDE2, INDERR, INDGP, INDGRS, INDWRK, ITMP,
244:      $                   ITMP2, J, JBLK, JJ, LIWMIN, LWMIN, NSPLIT,
245:      $                   NZCMIN, OFFSET, WBEGIN, WEND
246:       DOUBLE PRECISION   BIGNUM, CS, EPS, PIVMIN, R1, R2, RMAX, RMIN,
247:      $                   RTOL1, RTOL2, SAFMIN, SCALE, SMLNUM, SN,
248:      $                   THRESH, TMP, TNRM, WL, WU
249: *     ..
250: *     ..
251: *     .. External Functions ..
252:       LOGICAL            LSAME
253:       DOUBLE PRECISION   DLAMCH, DLANST
254:       EXTERNAL           LSAME, DLAMCH, DLANST
255: *     ..
256: *     .. External Subroutines ..
257:       EXTERNAL           DCOPY, DLAE2, DLAEV2, DLARRC, DLARRE, DLARRJ,
258:      $                   DLARRR, DLASRT, DSCAL, XERBLA, ZLARRV, ZSWAP
259: *     ..
260: *     .. Intrinsic Functions ..
261:       INTRINSIC          MAX, MIN, SQRT
262: 
263: 
264: *     ..
265: *     .. Executable Statements ..
266: *
267: *     Test the input parameters.
268: *
269:       WANTZ = LSAME( JOBZ, 'V' )
270:       ALLEIG = LSAME( RANGE, 'A' )
271:       VALEIG = LSAME( RANGE, 'V' )
272:       INDEIG = LSAME( RANGE, 'I' )
273: *
274:       LQUERY = ( ( LWORK.EQ.-1 ).OR.( LIWORK.EQ.-1 ) )
275:       ZQUERY = ( NZC.EQ.-1 )
276: 
277: *     DSTEMR needs WORK of size 6*N, IWORK of size 3*N.
278: *     In addition, DLARRE needs WORK of size 6*N, IWORK of size 5*N.
279: *     Furthermore, ZLARRV needs WORK of size 12*N, IWORK of size 7*N.
280:       IF( WANTZ ) THEN
281:          LWMIN = 18*N
282:          LIWMIN = 10*N
283:       ELSE
284: *        need less workspace if only the eigenvalues are wanted
285:          LWMIN = 12*N
286:          LIWMIN = 8*N
287:       ENDIF
288: 
289:       WL = ZERO
290:       WU = ZERO
291:       IIL = 0
292:       IIU = 0
293: 
294:       IF( VALEIG ) THEN
295: *        We do not reference VL, VU in the cases RANGE = 'I','A'
296: *        The interval (WL, WU] contains all the wanted eigenvalues.
297: *        It is either given by the user or computed in DLARRE.
298:          WL = VL
299:          WU = VU
300:       ELSEIF( INDEIG ) THEN
301: *        We do not reference IL, IU in the cases RANGE = 'V','A'
302:          IIL = IL
303:          IIU = IU
304:       ENDIF
305: *
306:       INFO = 0
307:       IF( .NOT.( WANTZ .OR. LSAME( JOBZ, 'N' ) ) ) THEN
308:          INFO = -1
309:       ELSE IF( .NOT.( ALLEIG .OR. VALEIG .OR. INDEIG ) ) THEN
310:          INFO = -2
311:       ELSE IF( N.LT.0 ) THEN
312:          INFO = -3
313:       ELSE IF( VALEIG .AND. N.GT.0 .AND. WU.LE.WL ) THEN
314:          INFO = -7
315:       ELSE IF( INDEIG .AND. ( IIL.LT.1 .OR. IIL.GT.N ) ) THEN
316:          INFO = -8
317:       ELSE IF( INDEIG .AND. ( IIU.LT.IIL .OR. IIU.GT.N ) ) THEN
318:          INFO = -9
319:       ELSE IF( LDZ.LT.1 .OR. ( WANTZ .AND. LDZ.LT.N ) ) THEN
320:          INFO = -13
321:       ELSE IF( LWORK.LT.LWMIN .AND. .NOT.LQUERY ) THEN
322:          INFO = -17
323:       ELSE IF( LIWORK.LT.LIWMIN .AND. .NOT.LQUERY ) THEN
324:          INFO = -19
325:       END IF
326: *
327: *     Get machine constants.
328: *
329:       SAFMIN = DLAMCH( 'Safe minimum' )
330:       EPS = DLAMCH( 'Precision' )
331:       SMLNUM = SAFMIN / EPS
332:       BIGNUM = ONE / SMLNUM
333:       RMIN = SQRT( SMLNUM )
334:       RMAX = MIN( SQRT( BIGNUM ), ONE / SQRT( SQRT( SAFMIN ) ) )
335: *
336:       IF( INFO.EQ.0 ) THEN
337:          WORK( 1 ) = LWMIN
338:          IWORK( 1 ) = LIWMIN
339: *
340:          IF( WANTZ .AND. ALLEIG ) THEN
341:             NZCMIN = N
342:          ELSE IF( WANTZ .AND. VALEIG ) THEN
343:             CALL DLARRC( 'T', N, VL, VU, D, E, SAFMIN,
344:      $                            NZCMIN, ITMP, ITMP2, INFO )
345:          ELSE IF( WANTZ .AND. INDEIG ) THEN
346:             NZCMIN = IIU-IIL+1
347:          ELSE
348: *           WANTZ .EQ. FALSE.
349:             NZCMIN = 0
350:          ENDIF
351:          IF( ZQUERY .AND. INFO.EQ.0 ) THEN
352:             Z( 1,1 ) = NZCMIN
353:          ELSE IF( NZC.LT.NZCMIN .AND. .NOT.ZQUERY ) THEN
354:             INFO = -14
355:          END IF
356:       END IF
357: 
358:       IF( INFO.NE.0 ) THEN
359: *
360:          CALL XERBLA( 'ZSTEMR', -INFO )
361: *
362:          RETURN
363:       ELSE IF( LQUERY .OR. ZQUERY ) THEN
364:          RETURN
365:       END IF
366: *
367: *     Handle N = 0, 1, and 2 cases immediately
368: *
369:       M = 0
370:       IF( N.EQ.0 )
371:      $   RETURN
372: *
373:       IF( N.EQ.1 ) THEN
374:          IF( ALLEIG .OR. INDEIG ) THEN
375:             M = 1
376:             W( 1 ) = D( 1 )
377:          ELSE
378:             IF( WL.LT.D( 1 ) .AND. WU.GE.D( 1 ) ) THEN
379:                M = 1
380:                W( 1 ) = D( 1 )
381:             END IF
382:          END IF
383:          IF( WANTZ.AND.(.NOT.ZQUERY) ) THEN
384:             Z( 1, 1 ) = ONE
385:             ISUPPZ(1) = 1
386:             ISUPPZ(2) = 1
387:          END IF
388:          RETURN
389:       END IF
390: *
391:       IF( N.EQ.2 ) THEN
392:          IF( .NOT.WANTZ ) THEN
393:             CALL DLAE2( D(1), E(1), D(2), R1, R2 )
394:          ELSE IF( WANTZ.AND.(.NOT.ZQUERY) ) THEN
395:             CALL DLAEV2( D(1), E(1), D(2), R1, R2, CS, SN )
396:          END IF
397:          IF( ALLEIG.OR.
398:      $      (VALEIG.AND.(R2.GT.WL).AND.
399:      $                  (R2.LE.WU)).OR.
400:      $      (INDEIG.AND.(IIL.EQ.1)) ) THEN
401:             M = M+1
402:             W( M ) = R2
403:             IF( WANTZ.AND.(.NOT.ZQUERY) ) THEN
404:                Z( 1, M ) = -SN
405:                Z( 2, M ) = CS
406: *              Note: At most one of SN and CS can be zero.
407:                IF (SN.NE.ZERO) THEN
408:                   IF (CS.NE.ZERO) THEN
409:                      ISUPPZ(2*M-1) = 1
410:                      ISUPPZ(2*M-1) = 2
411:                   ELSE
412:                      ISUPPZ(2*M-1) = 1
413:                      ISUPPZ(2*M-1) = 1
414:                   END IF
415:                ELSE
416:                   ISUPPZ(2*M-1) = 2
417:                   ISUPPZ(2*M) = 2
418:                END IF
419:             ENDIF
420:          ENDIF
421:          IF( ALLEIG.OR.
422:      $      (VALEIG.AND.(R1.GT.WL).AND.
423:      $                  (R1.LE.WU)).OR.
424:      $      (INDEIG.AND.(IIU.EQ.2)) ) THEN
425:             M = M+1
426:             W( M ) = R1
427:             IF( WANTZ.AND.(.NOT.ZQUERY) ) THEN
428:                Z( 1, M ) = CS
429:                Z( 2, M ) = SN
430: *              Note: At most one of SN and CS can be zero.
431:                IF (SN.NE.ZERO) THEN
432:                   IF (CS.NE.ZERO) THEN
433:                      ISUPPZ(2*M-1) = 1
434:                      ISUPPZ(2*M-1) = 2
435:                   ELSE
436:                      ISUPPZ(2*M-1) = 1
437:                      ISUPPZ(2*M-1) = 1
438:                   END IF
439:                ELSE
440:                   ISUPPZ(2*M-1) = 2
441:                   ISUPPZ(2*M) = 2
442:                END IF
443:             ENDIF
444:          ENDIF
445:          RETURN
446:       END IF
447: 
448: *     Continue with general N
449: 
450:       INDGRS = 1
451:       INDERR = 2*N + 1
452:       INDGP = 3*N + 1
453:       INDD = 4*N + 1
454:       INDE2 = 5*N + 1
455:       INDWRK = 6*N + 1
456: *
457:       IINSPL = 1
458:       IINDBL = N + 1
459:       IINDW = 2*N + 1
460:       IINDWK = 3*N + 1
461: *
462: *     Scale matrix to allowable range, if necessary.
463: *     The allowable range is related to the PIVMIN parameter; see the
464: *     comments in DLARRD.  The preference for scaling small values
465: *     up is heuristic; we expect users' matrices not to be close to the
466: *     RMAX threshold.
467: *
468:       SCALE = ONE
469:       TNRM = DLANST( 'M', N, D, E )
470:       IF( TNRM.GT.ZERO .AND. TNRM.LT.RMIN ) THEN
471:          SCALE = RMIN / TNRM
472:       ELSE IF( TNRM.GT.RMAX ) THEN
473:          SCALE = RMAX / TNRM
474:       END IF
475:       IF( SCALE.NE.ONE ) THEN
476:          CALL DSCAL( N, SCALE, D, 1 )
477:          CALL DSCAL( N-1, SCALE, E, 1 )
478:          TNRM = TNRM*SCALE
479:          IF( VALEIG ) THEN
480: *           If eigenvalues in interval have to be found,
481: *           scale (WL, WU] accordingly
482:             WL = WL*SCALE
483:             WU = WU*SCALE
484:          ENDIF
485:       END IF
486: *
487: *     Compute the desired eigenvalues of the tridiagonal after splitting
488: *     into smaller subblocks if the corresponding off-diagonal elements
489: *     are small
490: *     THRESH is the splitting parameter for DLARRE
491: *     A negative THRESH forces the old splitting criterion based on the
492: *     size of the off-diagonal. A positive THRESH switches to splitting
493: *     which preserves relative accuracy.
494: *
495:       IF( TRYRAC ) THEN
496: *        Test whether the matrix warrants the more expensive relative approach.
497:          CALL DLARRR( N, D, E, IINFO )
498:       ELSE
499: *        The user does not care about relative accurately eigenvalues
500:          IINFO = -1
501:       ENDIF
502: *     Set the splitting criterion
503:       IF (IINFO.EQ.0) THEN
504:          THRESH = EPS
505:       ELSE
506:          THRESH = -EPS
507: *        relative accuracy is desired but T does not guarantee it
508:          TRYRAC = .FALSE.
509:       ENDIF
510: *
511:       IF( TRYRAC ) THEN
512: *        Copy original diagonal, needed to guarantee relative accuracy
513:          CALL DCOPY(N,D,1,WORK(INDD),1)
514:       ENDIF
515: *     Store the squares of the offdiagonal values of T
516:       DO 5 J = 1, N-1
517:          WORK( INDE2+J-1 ) = E(J)**2
518:  5    CONTINUE
519: 
520: *     Set the tolerance parameters for bisection
521:       IF( .NOT.WANTZ ) THEN
522: *        DLARRE computes the eigenvalues to full precision.
523:          RTOL1 = FOUR * EPS
524:          RTOL2 = FOUR * EPS
525:       ELSE
526: *        DLARRE computes the eigenvalues to less than full precision.
527: *        ZLARRV will refine the eigenvalue approximations, and we only
528: *        need less accurate initial bisection in DLARRE.
529: *        Note: these settings do only affect the subset case and DLARRE
530:          RTOL1 = SQRT(EPS)
531:          RTOL2 = MAX( SQRT(EPS)*5.0D-3, FOUR * EPS )
532:       ENDIF
533:       CALL DLARRE( RANGE, N, WL, WU, IIL, IIU, D, E,
534:      $             WORK(INDE2), RTOL1, RTOL2, THRESH, NSPLIT,
535:      $             IWORK( IINSPL ), M, W, WORK( INDERR ),
536:      $             WORK( INDGP ), IWORK( IINDBL ),
537:      $             IWORK( IINDW ), WORK( INDGRS ), PIVMIN,
538:      $             WORK( INDWRK ), IWORK( IINDWK ), IINFO )
539:       IF( IINFO.NE.0 ) THEN
540:          INFO = 10 + ABS( IINFO )
541:          RETURN
542:       END IF
543: *     Note that if RANGE .NE. 'V', DLARRE computes bounds on the desired
544: *     part of the spectrum. All desired eigenvalues are contained in
545: *     (WL,WU]
546: 
547: 
548:       IF( WANTZ ) THEN
549: *
550: *        Compute the desired eigenvectors corresponding to the computed
551: *        eigenvalues
552: *
553:          CALL ZLARRV( N, WL, WU, D, E,
554:      $                PIVMIN, IWORK( IINSPL ), M,
555:      $                1, M, MINRGP, RTOL1, RTOL2,
556:      $                W, WORK( INDERR ), WORK( INDGP ), IWORK( IINDBL ),
557:      $                IWORK( IINDW ), WORK( INDGRS ), Z, LDZ,
558:      $                ISUPPZ, WORK( INDWRK ), IWORK( IINDWK ), IINFO )
559:          IF( IINFO.NE.0 ) THEN
560:             INFO = 20 + ABS( IINFO )
561:             RETURN
562:          END IF
563:       ELSE
564: *        DLARRE computes eigenvalues of the (shifted) root representation
565: *        ZLARRV returns the eigenvalues of the unshifted matrix.
566: *        However, if the eigenvectors are not desired by the user, we need
567: *        to apply the corresponding shifts from DLARRE to obtain the
568: *        eigenvalues of the original matrix.
569:          DO 20 J = 1, M
570:             ITMP = IWORK( IINDBL+J-1 )
571:             W( J ) = W( J ) + E( IWORK( IINSPL+ITMP-1 ) )
572:  20      CONTINUE
573:       END IF
574: *
575: 
576:       IF ( TRYRAC ) THEN
577: *        Refine computed eigenvalues so that they are relatively accurate
578: *        with respect to the original matrix T.
579:          IBEGIN = 1
580:          WBEGIN = 1
581:          DO 39  JBLK = 1, IWORK( IINDBL+M-1 )
582:             IEND = IWORK( IINSPL+JBLK-1 )
583:             IN = IEND - IBEGIN + 1
584:             WEND = WBEGIN - 1
585: *           check if any eigenvalues have to be refined in this block
586:  36         CONTINUE
587:             IF( WEND.LT.M ) THEN
588:                IF( IWORK( IINDBL+WEND ).EQ.JBLK ) THEN
589:                   WEND = WEND + 1
590:                   GO TO 36
591:                END IF
592:             END IF
593:             IF( WEND.LT.WBEGIN ) THEN
594:                IBEGIN = IEND + 1
595:                GO TO 39
596:             END IF
597: 
598:             OFFSET = IWORK(IINDW+WBEGIN-1)-1
599:             IFIRST = IWORK(IINDW+WBEGIN-1)
600:             ILAST = IWORK(IINDW+WEND-1)
601:             RTOL2 = FOUR * EPS
602:             CALL DLARRJ( IN,
603:      $                   WORK(INDD+IBEGIN-1), WORK(INDE2+IBEGIN-1),
604:      $                   IFIRST, ILAST, RTOL2, OFFSET, W(WBEGIN),
605:      $                   WORK( INDERR+WBEGIN-1 ),
606:      $                   WORK( INDWRK ), IWORK( IINDWK ), PIVMIN,
607:      $                   TNRM, IINFO )
608:             IBEGIN = IEND + 1
609:             WBEGIN = WEND + 1
610:  39      CONTINUE
611:       ENDIF
612: *
613: *     If matrix was scaled, then rescale eigenvalues appropriately.
614: *
615:       IF( SCALE.NE.ONE ) THEN
616:          CALL DSCAL( M, ONE / SCALE, W, 1 )
617:       END IF
618: *
619: *     If eigenvalues are not in increasing order, then sort them,
620: *     possibly along with eigenvectors.
621: *
622:       IF( NSPLIT.GT.1 ) THEN
623:          IF( .NOT. WANTZ ) THEN
624:             CALL DLASRT( 'I', M, W, IINFO )
625:             IF( IINFO.NE.0 ) THEN
626:                INFO = 3
627:                RETURN
628:             END IF
629:          ELSE
630:             DO 60 J = 1, M - 1
631:                I = 0
632:                TMP = W( J )
633:                DO 50 JJ = J + 1, M
634:                   IF( W( JJ ).LT.TMP ) THEN
635:                      I = JJ
636:                      TMP = W( JJ )
637:                   END IF
638:  50            CONTINUE
639:                IF( I.NE.0 ) THEN
640:                   W( I ) = W( J )
641:                   W( J ) = TMP
642:                   IF( WANTZ ) THEN
643:                      CALL ZSWAP( N, Z( 1, I ), 1, Z( 1, J ), 1 )
644:                      ITMP = ISUPPZ( 2*I-1 )
645:                      ISUPPZ( 2*I-1 ) = ISUPPZ( 2*J-1 )
646:                      ISUPPZ( 2*J-1 ) = ITMP
647:                      ITMP = ISUPPZ( 2*I )
648:                      ISUPPZ( 2*I ) = ISUPPZ( 2*J )
649:                      ISUPPZ( 2*J ) = ITMP
650:                   END IF
651:                END IF
652:  60         CONTINUE
653:          END IF
654:       ENDIF
655: *
656: *
657:       WORK( 1 ) = LWMIN
658:       IWORK( 1 ) = LIWMIN
659:       RETURN
660: *
661: *     End of ZSTEMR
662: *
663:       END
664: