001:       SUBROUTINE DSTEMR( 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:       DOUBLE PRECISION   Z( LDZ, * )
020: *     ..
021: *
022: *  Purpose
023: *  =======
024: *
025: *  DSTEMR 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.DSTEMR 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: *  Arguments
077: *  =========
078: *
079: *  JOBZ    (input) CHARACTER*1
080: *          = 'N':  Compute eigenvalues only;
081: *          = 'V':  Compute eigenvalues and eigenvectors.
082: *
083: *  RANGE   (input) CHARACTER*1
084: *          = 'A': all eigenvalues will be found.
085: *          = 'V': all eigenvalues in the half-open interval (VL,VU]
086: *                 will be found.
087: *          = 'I': the IL-th through IU-th eigenvalues will be found.
088: *
089: *  N       (input) INTEGER
090: *          The order of the matrix.  N >= 0.
091: *
092: *  D       (input/output) DOUBLE PRECISION array, dimension (N)
093: *          On entry, the N diagonal elements of the tridiagonal matrix
094: *          T. On exit, D is overwritten.
095: *
096: *  E       (input/output) DOUBLE PRECISION array, dimension (N)
097: *          On entry, the (N-1) subdiagonal elements of the tridiagonal
098: *          matrix T in elements 1 to N-1 of E. E(N) need not be set on
099: *          input, but is used internally as workspace.
100: *          On exit, E is overwritten.
101: *
102: *  VL      (input) DOUBLE PRECISION
103: *  VU      (input) DOUBLE PRECISION
104: *          If RANGE='V', the lower and upper bounds of the interval to
105: *          be searched for eigenvalues. VL < VU.
106: *          Not referenced if RANGE = 'A' or 'I'.
107: *
108: *  IL      (input) INTEGER
109: *  IU      (input) INTEGER
110: *          If RANGE='I', the indices (in ascending order) of the
111: *          smallest and largest eigenvalues to be returned.
112: *          1 <= IL <= IU <= N, if N > 0.
113: *          Not referenced if RANGE = 'A' or 'V'.
114: *
115: *  M       (output) INTEGER
116: *          The total number of eigenvalues found.  0 <= M <= N.
117: *          If RANGE = 'A', M = N, and if RANGE = 'I', M = IU-IL+1.
118: *
119: *  W       (output) DOUBLE PRECISION array, dimension (N)
120: *          The first M elements contain the selected eigenvalues in
121: *          ascending order.
122: *
123: *  Z       (output) DOUBLE PRECISION array, dimension (LDZ, max(1,M) )
124: *          If JOBZ = 'V', and if INFO = 0, then the first M columns of Z
125: *          contain the orthonormal eigenvectors of the matrix T
126: *          corresponding to the selected eigenvalues, with the i-th
127: *          column of Z holding the eigenvector associated with W(i).
128: *          If JOBZ = 'N', then Z is not referenced.
129: *          Note: the user must ensure that at least max(1,M) columns are
130: *          supplied in the array Z; if RANGE = 'V', the exact value of M
131: *          is not known in advance and can be computed with a workspace
132: *          query by setting NZC = -1, see below.
133: *
134: *  LDZ     (input) INTEGER
135: *          The leading dimension of the array Z.  LDZ >= 1, and if
136: *          JOBZ = 'V', then LDZ >= max(1,N).
137: *
138: *  NZC     (input) INTEGER
139: *          The number of eigenvectors to be held in the array Z.
140: *          If RANGE = 'A', then NZC >= max(1,N).
141: *          If RANGE = 'V', then NZC >= the number of eigenvalues in (VL,VU].
142: *          If RANGE = 'I', then NZC >= IU-IL+1.
143: *          If NZC = -1, then a workspace query is assumed; the
144: *          routine calculates the number of columns of the array Z that
145: *          are needed to hold the eigenvectors.
146: *          This value is returned as the first entry of the Z array, and
147: *          no error message related to NZC is issued by XERBLA.
148: *
149: *  ISUPPZ  (output) INTEGER ARRAY, dimension ( 2*max(1,M) )
150: *          The support of the eigenvectors in Z, i.e., the indices
151: *          indicating the nonzero elements in Z. The i-th computed eigenvector
152: *          is nonzero only in elements ISUPPZ( 2*i-1 ) through
153: *          ISUPPZ( 2*i ). This is relevant in the case when the matrix
154: *          is split. ISUPPZ is only accessed when JOBZ is 'V' and N > 0.
155: *
156: *  TRYRAC  (input/output) LOGICAL
157: *          If TRYRAC.EQ..TRUE., indicates that the code should check whether
158: *          the tridiagonal matrix defines its eigenvalues to high relative
159: *          accuracy.  If so, the code uses relative-accuracy preserving
160: *          algorithms that might be (a bit) slower depending on the matrix.
161: *          If the matrix does not define its eigenvalues to high relative
162: *          accuracy, the code can uses possibly faster algorithms.
163: *          If TRYRAC.EQ..FALSE., the code is not required to guarantee
164: *          relatively accurate eigenvalues and can use the fastest possible
165: *          techniques.
166: *          On exit, a .TRUE. TRYRAC will be set to .FALSE. if the matrix
167: *          does not define its eigenvalues to high relative accuracy.
168: *
169: *  WORK    (workspace/output) DOUBLE PRECISION array, dimension (LWORK)
170: *          On exit, if INFO = 0, WORK(1) returns the optimal
171: *          (and minimal) LWORK.
172: *
173: *  LWORK   (input) INTEGER
174: *          The dimension of the array WORK. LWORK >= max(1,18*N)
175: *          if JOBZ = 'V', and LWORK >= max(1,12*N) if JOBZ = 'N'.
176: *          If LWORK = -1, then a workspace query is assumed; the routine
177: *          only calculates the optimal size of the WORK array, returns
178: *          this value as the first entry of the WORK array, and no error
179: *          message related to LWORK is issued by XERBLA.
180: *
181: *  IWORK   (workspace/output) INTEGER array, dimension (LIWORK)
182: *          On exit, if INFO = 0, IWORK(1) returns the optimal LIWORK.
183: *
184: *  LIWORK  (input) INTEGER
185: *          The dimension of the array IWORK.  LIWORK >= max(1,10*N)
186: *          if the eigenvectors are desired, and LIWORK >= max(1,8*N)
187: *          if only the eigenvalues are to be computed.
188: *          If LIWORK = -1, then a workspace query is assumed; the
189: *          routine only calculates the optimal size of the IWORK array,
190: *          returns this value as the first entry of the IWORK array, and
191: *          no error message related to LIWORK is issued by XERBLA.
192: *
193: *  INFO    (output) INTEGER
194: *          On exit, INFO
195: *          = 0:  successful exit
196: *          < 0:  if INFO = -i, the i-th argument had an illegal value
197: *          > 0:  if INFO = 1X, internal error in DLARRE,
198: *                if INFO = 2X, internal error in DLARRV.
199: *                Here, the digit X = ABS( IINFO ) < 10, where IINFO is
200: *                the nonzero error code returned by DLARRE or
201: *                DLARRV, respectively.
202: *
203: *
204: *  Further Details
205: *  ===============
206: *
207: *  Based on contributions by
208: *     Beresford Parlett, University of California, Berkeley, USA
209: *     Jim Demmel, University of California, Berkeley, USA
210: *     Inderjit Dhillon, University of Texas, Austin, USA
211: *     Osni Marques, LBNL/NERSC, USA
212: *     Christof Voemel, University of California, Berkeley, USA
213: *
214: *  =====================================================================
215: *
216: *     .. Parameters ..
217:       DOUBLE PRECISION   ZERO, ONE, FOUR, MINRGP
218:       PARAMETER          ( ZERO = 0.0D0, ONE = 1.0D0,
219:      $                     FOUR = 4.0D0,
220:      $                     MINRGP = 1.0D-3 )
221: *     ..
222: *     .. Local Scalars ..
223:       LOGICAL            ALLEIG, INDEIG, LQUERY, VALEIG, WANTZ, ZQUERY
224:       INTEGER            I, IBEGIN, IEND, IFIRST, IIL, IINDBL, IINDW,
225:      $                   IINDWK, IINFO, IINSPL, IIU, ILAST, IN, INDD,
226:      $                   INDE2, INDERR, INDGP, INDGRS, INDWRK, ITMP,
227:      $                   ITMP2, J, JBLK, JJ, LIWMIN, LWMIN, NSPLIT,
228:      $                   NZCMIN, OFFSET, WBEGIN, WEND
229:       DOUBLE PRECISION   BIGNUM, CS, EPS, PIVMIN, R1, R2, RMAX, RMIN,
230:      $                   RTOL1, RTOL2, SAFMIN, SCALE, SMLNUM, SN,
231:      $                   THRESH, TMP, TNRM, WL, WU
232: *     ..
233: *     ..
234: *     .. External Functions ..
235:       LOGICAL            LSAME
236:       DOUBLE PRECISION   DLAMCH, DLANST
237:       EXTERNAL           LSAME, DLAMCH, DLANST
238: *     ..
239: *     .. External Subroutines ..
240:       EXTERNAL           DCOPY, DLAE2, DLAEV2, DLARRC, DLARRE, DLARRJ,
241:      $                   DLARRR, DLARRV, DLASRT, DSCAL, DSWAP, XERBLA
242: *     ..
243: *     .. Intrinsic Functions ..
244:       INTRINSIC          MAX, MIN, SQRT
245: 
246: 
247: *     ..
248: *     .. Executable Statements ..
249: *
250: *     Test the input parameters.
251: *
252:       WANTZ = LSAME( JOBZ, 'V' )
253:       ALLEIG = LSAME( RANGE, 'A' )
254:       VALEIG = LSAME( RANGE, 'V' )
255:       INDEIG = LSAME( RANGE, 'I' )
256: *
257:       LQUERY = ( ( LWORK.EQ.-1 ).OR.( LIWORK.EQ.-1 ) )
258:       ZQUERY = ( NZC.EQ.-1 )
259: 
260: *     DSTEMR needs WORK of size 6*N, IWORK of size 3*N.
261: *     In addition, DLARRE needs WORK of size 6*N, IWORK of size 5*N.
262: *     Furthermore, DLARRV needs WORK of size 12*N, IWORK of size 7*N.
263:       IF( WANTZ ) THEN
264:          LWMIN = 18*N
265:          LIWMIN = 10*N
266:       ELSE
267: *        need less workspace if only the eigenvalues are wanted
268:          LWMIN = 12*N
269:          LIWMIN = 8*N
270:       ENDIF
271: 
272:       WL = ZERO
273:       WU = ZERO
274:       IIL = 0
275:       IIU = 0
276: 
277:       IF( VALEIG ) THEN
278: *        We do not reference VL, VU in the cases RANGE = 'I','A'
279: *        The interval (WL, WU] contains all the wanted eigenvalues.
280: *        It is either given by the user or computed in DLARRE.
281:          WL = VL
282:          WU = VU
283:       ELSEIF( INDEIG ) THEN
284: *        We do not reference IL, IU in the cases RANGE = 'V','A'
285:          IIL = IL
286:          IIU = IU
287:       ENDIF
288: *
289:       INFO = 0
290:       IF( .NOT.( WANTZ .OR. LSAME( JOBZ, 'N' ) ) ) THEN
291:          INFO = -1
292:       ELSE IF( .NOT.( ALLEIG .OR. VALEIG .OR. INDEIG ) ) THEN
293:          INFO = -2
294:       ELSE IF( N.LT.0 ) THEN
295:          INFO = -3
296:       ELSE IF( VALEIG .AND. N.GT.0 .AND. WU.LE.WL ) THEN
297:          INFO = -7
298:       ELSE IF( INDEIG .AND. ( IIL.LT.1 .OR. IIL.GT.N ) ) THEN
299:          INFO = -8
300:       ELSE IF( INDEIG .AND. ( IIU.LT.IIL .OR. IIU.GT.N ) ) THEN
301:          INFO = -9
302:       ELSE IF( LDZ.LT.1 .OR. ( WANTZ .AND. LDZ.LT.N ) ) THEN
303:          INFO = -13
304:       ELSE IF( LWORK.LT.LWMIN .AND. .NOT.LQUERY ) THEN
305:          INFO = -17
306:       ELSE IF( LIWORK.LT.LIWMIN .AND. .NOT.LQUERY ) THEN
307:          INFO = -19
308:       END IF
309: *
310: *     Get machine constants.
311: *
312:       SAFMIN = DLAMCH( 'Safe minimum' )
313:       EPS = DLAMCH( 'Precision' )
314:       SMLNUM = SAFMIN / EPS
315:       BIGNUM = ONE / SMLNUM
316:       RMIN = SQRT( SMLNUM )
317:       RMAX = MIN( SQRT( BIGNUM ), ONE / SQRT( SQRT( SAFMIN ) ) )
318: *
319:       IF( INFO.EQ.0 ) THEN
320:          WORK( 1 ) = LWMIN
321:          IWORK( 1 ) = LIWMIN
322: *
323:          IF( WANTZ .AND. ALLEIG ) THEN
324:             NZCMIN = N
325:          ELSE IF( WANTZ .AND. VALEIG ) THEN
326:             CALL DLARRC( 'T', N, VL, VU, D, E, SAFMIN,
327:      $                            NZCMIN, ITMP, ITMP2, INFO )
328:          ELSE IF( WANTZ .AND. INDEIG ) THEN
329:             NZCMIN = IIU-IIL+1
330:          ELSE
331: *           WANTZ .EQ. FALSE.
332:             NZCMIN = 0
333:          ENDIF
334:          IF( ZQUERY .AND. INFO.EQ.0 ) THEN
335:             Z( 1,1 ) = NZCMIN
336:          ELSE IF( NZC.LT.NZCMIN .AND. .NOT.ZQUERY ) THEN
337:             INFO = -14
338:          END IF
339:       END IF
340: 
341:       IF( INFO.NE.0 ) THEN
342: *
343:          CALL XERBLA( 'DSTEMR', -INFO )
344: *
345:          RETURN
346:       ELSE IF( LQUERY .OR. ZQUERY ) THEN
347:          RETURN
348:       END IF
349: *
350: *     Handle N = 0, 1, and 2 cases immediately
351: *
352:       M = 0
353:       IF( N.EQ.0 )
354:      $   RETURN
355: *
356:       IF( N.EQ.1 ) THEN
357:          IF( ALLEIG .OR. INDEIG ) THEN
358:             M = 1
359:             W( 1 ) = D( 1 )
360:          ELSE
361:             IF( WL.LT.D( 1 ) .AND. WU.GE.D( 1 ) ) THEN
362:                M = 1
363:                W( 1 ) = D( 1 )
364:             END IF
365:          END IF
366:          IF( WANTZ.AND.(.NOT.ZQUERY) ) THEN
367:             Z( 1, 1 ) = ONE
368:             ISUPPZ(1) = 1
369:             ISUPPZ(2) = 1
370:          END IF
371:          RETURN
372:       END IF
373: *
374:       IF( N.EQ.2 ) THEN
375:          IF( .NOT.WANTZ ) THEN
376:             CALL DLAE2( D(1), E(1), D(2), R1, R2 )
377:          ELSE IF( WANTZ.AND.(.NOT.ZQUERY) ) THEN
378:             CALL DLAEV2( D(1), E(1), D(2), R1, R2, CS, SN )
379:          END IF
380:          IF( ALLEIG.OR.
381:      $      (VALEIG.AND.(R2.GT.WL).AND.
382:      $                  (R2.LE.WU)).OR.
383:      $      (INDEIG.AND.(IIL.EQ.1)) ) THEN
384:             M = M+1
385:             W( M ) = R2
386:             IF( WANTZ.AND.(.NOT.ZQUERY) ) THEN
387:                Z( 1, M ) = -SN
388:                Z( 2, M ) = CS
389: *              Note: At most one of SN and CS can be zero.
390:                IF (SN.NE.ZERO) THEN
391:                   IF (CS.NE.ZERO) THEN
392:                      ISUPPZ(2*M-1) = 1
393:                      ISUPPZ(2*M-1) = 2
394:                   ELSE
395:                      ISUPPZ(2*M-1) = 1
396:                      ISUPPZ(2*M-1) = 1
397:                   END IF
398:                ELSE
399:                   ISUPPZ(2*M-1) = 2
400:                   ISUPPZ(2*M) = 2
401:                END IF
402:             ENDIF
403:          ENDIF
404:          IF( ALLEIG.OR.
405:      $      (VALEIG.AND.(R1.GT.WL).AND.
406:      $                  (R1.LE.WU)).OR.
407:      $      (INDEIG.AND.(IIU.EQ.2)) ) THEN
408:             M = M+1
409:             W( M ) = R1
410:             IF( WANTZ.AND.(.NOT.ZQUERY) ) THEN
411:                Z( 1, M ) = CS
412:                Z( 2, M ) = SN
413: *              Note: At most one of SN and CS can be zero.
414:                IF (SN.NE.ZERO) THEN
415:                   IF (CS.NE.ZERO) THEN
416:                      ISUPPZ(2*M-1) = 1
417:                      ISUPPZ(2*M-1) = 2
418:                   ELSE
419:                      ISUPPZ(2*M-1) = 1
420:                      ISUPPZ(2*M-1) = 1
421:                   END IF
422:                ELSE
423:                   ISUPPZ(2*M-1) = 2
424:                   ISUPPZ(2*M) = 2
425:                END IF
426:             ENDIF
427:          ENDIF
428:          RETURN
429:       END IF
430: 
431: *     Continue with general N
432: 
433:       INDGRS = 1
434:       INDERR = 2*N + 1
435:       INDGP = 3*N + 1
436:       INDD = 4*N + 1
437:       INDE2 = 5*N + 1
438:       INDWRK = 6*N + 1
439: *
440:       IINSPL = 1
441:       IINDBL = N + 1
442:       IINDW = 2*N + 1
443:       IINDWK = 3*N + 1
444: *
445: *     Scale matrix to allowable range, if necessary.
446: *     The allowable range is related to the PIVMIN parameter; see the
447: *     comments in DLARRD.  The preference for scaling small values
448: *     up is heuristic; we expect users' matrices not to be close to the
449: *     RMAX threshold.
450: *
451:       SCALE = ONE
452:       TNRM = DLANST( 'M', N, D, E )
453:       IF( TNRM.GT.ZERO .AND. TNRM.LT.RMIN ) THEN
454:          SCALE = RMIN / TNRM
455:       ELSE IF( TNRM.GT.RMAX ) THEN
456:          SCALE = RMAX / TNRM
457:       END IF
458:       IF( SCALE.NE.ONE ) THEN
459:          CALL DSCAL( N, SCALE, D, 1 )
460:          CALL DSCAL( N-1, SCALE, E, 1 )
461:          TNRM = TNRM*SCALE
462:          IF( VALEIG ) THEN
463: *           If eigenvalues in interval have to be found,
464: *           scale (WL, WU] accordingly
465:             WL = WL*SCALE
466:             WU = WU*SCALE
467:          ENDIF
468:       END IF
469: *
470: *     Compute the desired eigenvalues of the tridiagonal after splitting
471: *     into smaller subblocks if the corresponding off-diagonal elements
472: *     are small
473: *     THRESH is the splitting parameter for DLARRE
474: *     A negative THRESH forces the old splitting criterion based on the
475: *     size of the off-diagonal. A positive THRESH switches to splitting
476: *     which preserves relative accuracy.
477: *
478:       IF( TRYRAC ) THEN
479: *        Test whether the matrix warrants the more expensive relative approach.
480:          CALL DLARRR( N, D, E, IINFO )
481:       ELSE
482: *        The user does not care about relative accurately eigenvalues
483:          IINFO = -1
484:       ENDIF
485: *     Set the splitting criterion
486:       IF (IINFO.EQ.0) THEN
487:          THRESH = EPS
488:       ELSE
489:          THRESH = -EPS
490: *        relative accuracy is desired but T does not guarantee it
491:          TRYRAC = .FALSE.
492:       ENDIF
493: *
494:       IF( TRYRAC ) THEN
495: *        Copy original diagonal, needed to guarantee relative accuracy
496:          CALL DCOPY(N,D,1,WORK(INDD),1)
497:       ENDIF
498: *     Store the squares of the offdiagonal values of T
499:       DO 5 J = 1, N-1
500:          WORK( INDE2+J-1 ) = E(J)**2
501:  5    CONTINUE
502: 
503: *     Set the tolerance parameters for bisection
504:       IF( .NOT.WANTZ ) THEN
505: *        DLARRE computes the eigenvalues to full precision.
506:          RTOL1 = FOUR * EPS
507:          RTOL2 = FOUR * EPS
508:       ELSE
509: *        DLARRE computes the eigenvalues to less than full precision.
510: *        DLARRV will refine the eigenvalue approximations, and we can
511: *        need less accurate initial bisection in DLARRE.
512: *        Note: these settings do only affect the subset case and DLARRE
513:          RTOL1 = SQRT(EPS)
514:          RTOL2 = MAX( SQRT(EPS)*5.0D-3, FOUR * EPS )
515:       ENDIF
516:       CALL DLARRE( RANGE, N, WL, WU, IIL, IIU, D, E,
517:      $             WORK(INDE2), RTOL1, RTOL2, THRESH, NSPLIT,
518:      $             IWORK( IINSPL ), M, W, WORK( INDERR ),
519:      $             WORK( INDGP ), IWORK( IINDBL ),
520:      $             IWORK( IINDW ), WORK( INDGRS ), PIVMIN,
521:      $             WORK( INDWRK ), IWORK( IINDWK ), IINFO )
522:       IF( IINFO.NE.0 ) THEN
523:          INFO = 10 + ABS( IINFO )
524:          RETURN
525:       END IF
526: *     Note that if RANGE .NE. 'V', DLARRE computes bounds on the desired
527: *     part of the spectrum. All desired eigenvalues are contained in
528: *     (WL,WU]
529: 
530: 
531:       IF( WANTZ ) THEN
532: *
533: *        Compute the desired eigenvectors corresponding to the computed
534: *        eigenvalues
535: *
536:          CALL DLARRV( N, WL, WU, D, E,
537:      $                PIVMIN, IWORK( IINSPL ), M,
538:      $                1, M, MINRGP, RTOL1, RTOL2,
539:      $                W, WORK( INDERR ), WORK( INDGP ), IWORK( IINDBL ),
540:      $                IWORK( IINDW ), WORK( INDGRS ), Z, LDZ,
541:      $                ISUPPZ, WORK( INDWRK ), IWORK( IINDWK ), IINFO )
542:          IF( IINFO.NE.0 ) THEN
543:             INFO = 20 + ABS( IINFO )
544:             RETURN
545:          END IF
546:       ELSE
547: *        DLARRE computes eigenvalues of the (shifted) root representation
548: *        DLARRV returns the eigenvalues of the unshifted matrix.
549: *        However, if the eigenvectors are not desired by the user, we need
550: *        to apply the corresponding shifts from DLARRE to obtain the
551: *        eigenvalues of the original matrix.
552:          DO 20 J = 1, M
553:             ITMP = IWORK( IINDBL+J-1 )
554:             W( J ) = W( J ) + E( IWORK( IINSPL+ITMP-1 ) )
555:  20      CONTINUE
556:       END IF
557: *
558: 
559:       IF ( TRYRAC ) THEN
560: *        Refine computed eigenvalues so that they are relatively accurate
561: *        with respect to the original matrix T.
562:          IBEGIN = 1
563:          WBEGIN = 1
564:          DO 39  JBLK = 1, IWORK( IINDBL+M-1 )
565:             IEND = IWORK( IINSPL+JBLK-1 )
566:             IN = IEND - IBEGIN + 1
567:             WEND = WBEGIN - 1
568: *           check if any eigenvalues have to be refined in this block
569:  36         CONTINUE
570:             IF( WEND.LT.M ) THEN
571:                IF( IWORK( IINDBL+WEND ).EQ.JBLK ) THEN
572:                   WEND = WEND + 1
573:                   GO TO 36
574:                END IF
575:             END IF
576:             IF( WEND.LT.WBEGIN ) THEN
577:                IBEGIN = IEND + 1
578:                GO TO 39
579:             END IF
580: 
581:             OFFSET = IWORK(IINDW+WBEGIN-1)-1
582:             IFIRST = IWORK(IINDW+WBEGIN-1)
583:             ILAST = IWORK(IINDW+WEND-1)
584:             RTOL2 = FOUR * EPS
585:             CALL DLARRJ( IN,
586:      $                   WORK(INDD+IBEGIN-1), WORK(INDE2+IBEGIN-1),
587:      $                   IFIRST, ILAST, RTOL2, OFFSET, W(WBEGIN),
588:      $                   WORK( INDERR+WBEGIN-1 ),
589:      $                   WORK( INDWRK ), IWORK( IINDWK ), PIVMIN,
590:      $                   TNRM, IINFO )
591:             IBEGIN = IEND + 1
592:             WBEGIN = WEND + 1
593:  39      CONTINUE
594:       ENDIF
595: *
596: *     If matrix was scaled, then rescale eigenvalues appropriately.
597: *
598:       IF( SCALE.NE.ONE ) THEN
599:          CALL DSCAL( M, ONE / SCALE, W, 1 )
600:       END IF
601: *
602: *     If eigenvalues are not in increasing order, then sort them,
603: *     possibly along with eigenvectors.
604: *
605:       IF( NSPLIT.GT.1 ) THEN
606:          IF( .NOT. WANTZ ) THEN
607:             CALL DLASRT( 'I', M, W, IINFO )
608:             IF( IINFO.NE.0 ) THEN
609:                INFO = 3
610:                RETURN
611:             END IF
612:          ELSE
613:             DO 60 J = 1, M - 1
614:                I = 0
615:                TMP = W( J )
616:                DO 50 JJ = J + 1, M
617:                   IF( W( JJ ).LT.TMP ) THEN
618:                      I = JJ
619:                      TMP = W( JJ )
620:                   END IF
621:  50            CONTINUE
622:                IF( I.NE.0 ) THEN
623:                   W( I ) = W( J )
624:                   W( J ) = TMP
625:                   IF( WANTZ ) THEN
626:                      CALL DSWAP( N, Z( 1, I ), 1, Z( 1, J ), 1 )
627:                      ITMP = ISUPPZ( 2*I-1 )
628:                      ISUPPZ( 2*I-1 ) = ISUPPZ( 2*J-1 )
629:                      ISUPPZ( 2*J-1 ) = ITMP
630:                      ITMP = ISUPPZ( 2*I )
631:                      ISUPPZ( 2*I ) = ISUPPZ( 2*J )
632:                      ISUPPZ( 2*J ) = ITMP
633:                   END IF
634:                END IF
635:  60         CONTINUE
636:          END IF
637:       ENDIF
638: *
639: *
640:       WORK( 1 ) = LWMIN
641:       IWORK( 1 ) = LIWMIN
642:       RETURN
643: *
644: *     End of DSTEMR
645: *
646:       END
647: