001:       SUBROUTINE SSTEMR( 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:       REAL               VL, VU
015: *     ..
016: *     .. Array Arguments ..
017:       INTEGER            ISUPPZ( * ), IWORK( * )
018:       REAL               D( * ), E( * ), W( * ), WORK( * )
019:       REAL               Z( LDZ, * )
020: *     ..
021: *
022: *  Purpose
023: *  =======
024: *
025: *  SSTEMR 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.SSTEMR 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) REAL 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) REAL 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) REAL
103: *  VU      (input) REAL
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) REAL array, dimension (N)
120: *          The first M elements contain the selected eigenvalues in
121: *          ascending order.
122: *
123: *  Z       (output) REAL 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) REAL 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 SLARRE,
198: *                if INFO = 2X, internal error in SLARRV.
199: *                Here, the digit X = ABS( IINFO ) < 10, where IINFO is
200: *                the nonzero error code returned by SLARRE or
201: *                SLARRV, 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:       REAL               ZERO, ONE, FOUR, MINRGP
218:       PARAMETER          ( ZERO = 0.0E0, ONE = 1.0E0,
219:      $                     FOUR = 4.0E0,
220:      $                     MINRGP = 3.0E-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:       REAL               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:       REAL               SLAMCH, SLANST
237:       EXTERNAL           LSAME, SLAMCH, SLANST
238: *     ..
239: *     .. External Subroutines ..
240:       EXTERNAL           SCOPY, SLAE2, SLAEV2, SLARRC, SLARRE, SLARRJ,
241:      $                   SLARRR, SLARRV, SLASRT, SSCAL, SSWAP, XERBLA
242: *     ..
243: *     .. Intrinsic Functions ..
244:       INTRINSIC          MAX, MIN, SQRT
245: *     ..
246: *     .. Executable Statements ..
247: *
248: *     Test the input parameters.
249: *
250:       WANTZ = LSAME( JOBZ, 'V' )
251:       ALLEIG = LSAME( RANGE, 'A' )
252:       VALEIG = LSAME( RANGE, 'V' )
253:       INDEIG = LSAME( RANGE, 'I' )
254: *
255:       LQUERY = ( ( LWORK.EQ.-1 ).OR.( LIWORK.EQ.-1 ) )
256:       ZQUERY = ( NZC.EQ.-1 )
257: 
258: *     SSTEMR needs WORK of size 6*N, IWORK of size 3*N.
259: *     In addition, SLARRE needs WORK of size 6*N, IWORK of size 5*N.
260: *     Furthermore, SLARRV needs WORK of size 12*N, IWORK of size 7*N.
261:       IF( WANTZ ) THEN
262:          LWMIN = 18*N
263:          LIWMIN = 10*N
264:       ELSE
265: *        need less workspace if only the eigenvalues are wanted
266:          LWMIN = 12*N
267:          LIWMIN = 8*N
268:       ENDIF
269: 
270:       WL = ZERO
271:       WU = ZERO
272:       IIL = 0
273:       IIU = 0
274: 
275:       IF( VALEIG ) THEN
276: *        We do not reference VL, VU in the cases RANGE = 'I','A'
277: *        The interval (WL, WU] contains all the wanted eigenvalues.
278: *        It is either given by the user or computed in SLARRE.
279:          WL = VL
280:          WU = VU
281:       ELSEIF( INDEIG ) THEN
282: *        We do not reference IL, IU in the cases RANGE = 'V','A'
283:          IIL = IL
284:          IIU = IU
285:       ENDIF
286: *
287:       INFO = 0
288:       IF( .NOT.( WANTZ .OR. LSAME( JOBZ, 'N' ) ) ) THEN
289:          INFO = -1
290:       ELSE IF( .NOT.( ALLEIG .OR. VALEIG .OR. INDEIG ) ) THEN
291:          INFO = -2
292:       ELSE IF( N.LT.0 ) THEN
293:          INFO = -3
294:       ELSE IF( VALEIG .AND. N.GT.0 .AND. WU.LE.WL ) THEN
295:          INFO = -7
296:       ELSE IF( INDEIG .AND. ( IIL.LT.1 .OR. IIL.GT.N ) ) THEN
297:          INFO = -8
298:       ELSE IF( INDEIG .AND. ( IIU.LT.IIL .OR. IIU.GT.N ) ) THEN
299:          INFO = -9
300:       ELSE IF( LDZ.LT.1 .OR. ( WANTZ .AND. LDZ.LT.N ) ) THEN
301:          INFO = -13
302:       ELSE IF( LWORK.LT.LWMIN .AND. .NOT.LQUERY ) THEN
303:          INFO = -17
304:       ELSE IF( LIWORK.LT.LIWMIN .AND. .NOT.LQUERY ) THEN
305:          INFO = -19
306:       END IF
307: *
308: *     Get machine constants.
309: *
310:       SAFMIN = SLAMCH( 'Safe minimum' )
311:       EPS = SLAMCH( 'Precision' )
312:       SMLNUM = SAFMIN / EPS
313:       BIGNUM = ONE / SMLNUM
314:       RMIN = SQRT( SMLNUM )
315:       RMAX = MIN( SQRT( BIGNUM ), ONE / SQRT( SQRT( SAFMIN ) ) )
316: *
317:       IF( INFO.EQ.0 ) THEN
318:          WORK( 1 ) = LWMIN
319:          IWORK( 1 ) = LIWMIN
320: *
321:          IF( WANTZ .AND. ALLEIG ) THEN
322:             NZCMIN = N
323:          ELSE IF( WANTZ .AND. VALEIG ) THEN
324:             CALL SLARRC( 'T', N, VL, VU, D, E, SAFMIN,
325:      $                            NZCMIN, ITMP, ITMP2, INFO )
326:          ELSE IF( WANTZ .AND. INDEIG ) THEN
327:             NZCMIN = IIU-IIL+1
328:          ELSE
329: *           WANTZ .EQ. FALSE.
330:             NZCMIN = 0
331:          ENDIF
332:          IF( ZQUERY .AND. INFO.EQ.0 ) THEN
333:             Z( 1,1 ) = NZCMIN
334:          ELSE IF( NZC.LT.NZCMIN .AND. .NOT.ZQUERY ) THEN
335:             INFO = -14
336:          END IF
337:       END IF
338: 
339:       IF( INFO.NE.0 ) THEN
340: *
341:          CALL XERBLA( 'SSTEMR', -INFO )
342: *
343:          RETURN
344:       ELSE IF( LQUERY .OR. ZQUERY ) THEN
345:          RETURN
346:       END IF
347: *
348: *     Handle N = 0, 1, and 2 cases immediately
349: *
350:       M = 0
351:       IF( N.EQ.0 )
352:      $   RETURN
353: *
354:       IF( N.EQ.1 ) THEN
355:          IF( ALLEIG .OR. INDEIG ) THEN
356:             M = 1
357:             W( 1 ) = D( 1 )
358:          ELSE
359:             IF( WL.LT.D( 1 ) .AND. WU.GE.D( 1 ) ) THEN
360:                M = 1
361:                W( 1 ) = D( 1 )
362:             END IF
363:          END IF
364:          IF( WANTZ.AND.(.NOT.ZQUERY) ) THEN
365:             Z( 1, 1 ) = ONE
366:             ISUPPZ(1) = 1
367:             ISUPPZ(2) = 1
368:          END IF
369:          RETURN
370:       END IF
371: *
372:       IF( N.EQ.2 ) THEN
373:          IF( .NOT.WANTZ ) THEN
374:             CALL SLAE2( D(1), E(1), D(2), R1, R2 )
375:          ELSE IF( WANTZ.AND.(.NOT.ZQUERY) ) THEN
376:             CALL SLAEV2( D(1), E(1), D(2), R1, R2, CS, SN )
377:          END IF
378:          IF( ALLEIG.OR.
379:      $      (VALEIG.AND.(R2.GT.WL).AND.
380:      $                  (R2.LE.WU)).OR.
381:      $      (INDEIG.AND.(IIL.EQ.1)) ) THEN
382:             M = M+1
383:             W( M ) = R2
384:             IF( WANTZ.AND.(.NOT.ZQUERY) ) THEN
385:                Z( 1, M ) = -SN
386:                Z( 2, M ) = CS
387: *              Note: At most one of SN and CS can be zero.
388:                IF (SN.NE.ZERO) THEN
389:                   IF (CS.NE.ZERO) THEN
390:                      ISUPPZ(2*M-1) = 1
391:                      ISUPPZ(2*M-1) = 2
392:                   ELSE
393:                      ISUPPZ(2*M-1) = 1
394:                      ISUPPZ(2*M-1) = 1
395:                   END IF
396:                ELSE
397:                   ISUPPZ(2*M-1) = 2
398:                   ISUPPZ(2*M) = 2
399:                END IF
400:             ENDIF
401:          ENDIF
402:          IF( ALLEIG.OR.
403:      $      (VALEIG.AND.(R1.GT.WL).AND.
404:      $                  (R1.LE.WU)).OR.
405:      $      (INDEIG.AND.(IIU.EQ.2)) ) THEN
406:             M = M+1
407:             W( M ) = R1
408:             IF( WANTZ.AND.(.NOT.ZQUERY) ) THEN
409:                Z( 1, M ) = CS
410:                Z( 2, M ) = SN
411: *              Note: At most one of SN and CS can be zero.
412:                IF (SN.NE.ZERO) THEN
413:                   IF (CS.NE.ZERO) THEN
414:                      ISUPPZ(2*M-1) = 1
415:                      ISUPPZ(2*M-1) = 2
416:                   ELSE
417:                      ISUPPZ(2*M-1) = 1
418:                      ISUPPZ(2*M-1) = 1
419:                   END IF
420:                ELSE
421:                   ISUPPZ(2*M-1) = 2
422:                   ISUPPZ(2*M) = 2
423:                END IF
424:             ENDIF
425:          ENDIF
426:          RETURN
427:       END IF
428: 
429: *     Continue with general N
430: 
431:       INDGRS = 1
432:       INDERR = 2*N + 1
433:       INDGP = 3*N + 1
434:       INDD = 4*N + 1
435:       INDE2 = 5*N + 1
436:       INDWRK = 6*N + 1
437: *
438:       IINSPL = 1
439:       IINDBL = N + 1
440:       IINDW = 2*N + 1
441:       IINDWK = 3*N + 1
442: *
443: *     Scale matrix to allowable range, if necessary.
444: *     The allowable range is related to the PIVMIN parameter; see the
445: *     comments in SLARRD.  The preference for scaling small values
446: *     up is heuristic; we expect users' matrices not to be close to the
447: *     RMAX threshold.
448: *
449:       SCALE = ONE
450:       TNRM = SLANST( 'M', N, D, E )
451:       IF( TNRM.GT.ZERO .AND. TNRM.LT.RMIN ) THEN
452:          SCALE = RMIN / TNRM
453:       ELSE IF( TNRM.GT.RMAX ) THEN
454:          SCALE = RMAX / TNRM
455:       END IF
456:       IF( SCALE.NE.ONE ) THEN
457:          CALL SSCAL( N, SCALE, D, 1 )
458:          CALL SSCAL( N-1, SCALE, E, 1 )
459:          TNRM = TNRM*SCALE
460:          IF( VALEIG ) THEN
461: *           If eigenvalues in interval have to be found,
462: *           scale (WL, WU] accordingly
463:             WL = WL*SCALE
464:             WU = WU*SCALE
465:          ENDIF
466:       END IF
467: *
468: *     Compute the desired eigenvalues of the tridiagonal after splitting
469: *     into smaller subblocks if the corresponding off-diagonal elements
470: *     are small
471: *     THRESH is the splitting parameter for SLARRE
472: *     A negative THRESH forces the old splitting criterion based on the
473: *     size of the off-diagonal. A positive THRESH switches to splitting
474: *     which preserves relative accuracy.
475: *
476:       IF( TRYRAC ) THEN
477: *        Test whether the matrix warrants the more expensive relative approach.
478:          CALL SLARRR( N, D, E, IINFO )
479:       ELSE
480: *        The user does not care about relative accurately eigenvalues
481:          IINFO = -1
482:       ENDIF
483: *     Set the splitting criterion
484:       IF (IINFO.EQ.0) THEN
485:          THRESH = EPS
486:       ELSE
487:          THRESH = -EPS
488: *        relative accuracy is desired but T does not guarantee it
489:          TRYRAC = .FALSE.
490:       ENDIF
491: *
492:       IF( TRYRAC ) THEN
493: *        Copy original diagonal, needed to guarantee relative accuracy
494:          CALL SCOPY(N,D,1,WORK(INDD),1)
495:       ENDIF
496: *     Store the squares of the offdiagonal values of T
497:       DO 5 J = 1, N-1
498:          WORK( INDE2+J-1 ) = E(J)**2
499:  5    CONTINUE
500: 
501: *     Set the tolerance parameters for bisection
502:       IF( .NOT.WANTZ ) THEN
503: *        SLARRE computes the eigenvalues to full precision.
504:          RTOL1 = FOUR * EPS
505:          RTOL2 = FOUR * EPS
506:       ELSE
507: *        SLARRE computes the eigenvalues to less than full precision.
508: *        SLARRV will refine the eigenvalue approximations, and we can
509: *        need less accurate initial bisection in SLARRE.
510: *        Note: these settings do only affect the subset case and SLARRE
511:          RTOL1 = MAX( SQRT(EPS)*5.0E-2, FOUR * EPS )
512:          RTOL2 = MAX( SQRT(EPS)*5.0E-3, FOUR * EPS )
513:       ENDIF
514:       CALL SLARRE( RANGE, N, WL, WU, IIL, IIU, D, E,
515:      $             WORK(INDE2), RTOL1, RTOL2, THRESH, NSPLIT,
516:      $             IWORK( IINSPL ), M, W, WORK( INDERR ),
517:      $             WORK( INDGP ), IWORK( IINDBL ),
518:      $             IWORK( IINDW ), WORK( INDGRS ), PIVMIN,
519:      $             WORK( INDWRK ), IWORK( IINDWK ), IINFO )
520:       IF( IINFO.NE.0 ) THEN
521:          INFO = 10 + ABS( IINFO )
522:          RETURN
523:       END IF
524: *     Note that if RANGE .NE. 'V', SLARRE computes bounds on the desired
525: *     part of the spectrum. All desired eigenvalues are contained in
526: *     (WL,WU]
527: 
528: 
529:       IF( WANTZ ) THEN
530: *
531: *        Compute the desired eigenvectors corresponding to the computed
532: *        eigenvalues
533: *
534:          CALL SLARRV( N, WL, WU, D, E,
535:      $                PIVMIN, IWORK( IINSPL ), M,
536:      $                1, M, MINRGP, RTOL1, RTOL2,
537:      $                W, WORK( INDERR ), WORK( INDGP ), IWORK( IINDBL ),
538:      $                IWORK( IINDW ), WORK( INDGRS ), Z, LDZ,
539:      $                ISUPPZ, WORK( INDWRK ), IWORK( IINDWK ), IINFO )
540:          IF( IINFO.NE.0 ) THEN
541:             INFO = 20 + ABS( IINFO )
542:             RETURN
543:          END IF
544:       ELSE
545: *        SLARRE computes eigenvalues of the (shifted) root representation
546: *        SLARRV returns the eigenvalues of the unshifted matrix.
547: *        However, if the eigenvectors are not desired by the user, we need
548: *        to apply the corresponding shifts from SLARRE to obtain the
549: *        eigenvalues of the original matrix.
550:          DO 20 J = 1, M
551:             ITMP = IWORK( IINDBL+J-1 )
552:             W( J ) = W( J ) + E( IWORK( IINSPL+ITMP-1 ) )
553:  20      CONTINUE
554:       END IF
555: *
556: 
557:       IF ( TRYRAC ) THEN
558: *        Refine computed eigenvalues so that they are relatively accurate
559: *        with respect to the original matrix T.
560:          IBEGIN = 1
561:          WBEGIN = 1
562:          DO 39  JBLK = 1, IWORK( IINDBL+M-1 )
563:             IEND = IWORK( IINSPL+JBLK-1 )
564:             IN = IEND - IBEGIN + 1
565:             WEND = WBEGIN - 1
566: *           check if any eigenvalues have to be refined in this block
567:  36         CONTINUE
568:             IF( WEND.LT.M ) THEN
569:                IF( IWORK( IINDBL+WEND ).EQ.JBLK ) THEN
570:                   WEND = WEND + 1
571:                   GO TO 36
572:                END IF
573:             END IF
574:             IF( WEND.LT.WBEGIN ) THEN
575:                IBEGIN = IEND + 1
576:                GO TO 39
577:             END IF
578: 
579:             OFFSET = IWORK(IINDW+WBEGIN-1)-1
580:             IFIRST = IWORK(IINDW+WBEGIN-1)
581:             ILAST = IWORK(IINDW+WEND-1)
582:             RTOL2 = FOUR * EPS
583:             CALL SLARRJ( IN,
584:      $                   WORK(INDD+IBEGIN-1), WORK(INDE2+IBEGIN-1),
585:      $                   IFIRST, ILAST, RTOL2, OFFSET, W(WBEGIN),
586:      $                   WORK( INDERR+WBEGIN-1 ),
587:      $                   WORK( INDWRK ), IWORK( IINDWK ), PIVMIN,
588:      $                   TNRM, IINFO )
589:             IBEGIN = IEND + 1
590:             WBEGIN = WEND + 1
591:  39      CONTINUE
592:       ENDIF
593: *
594: *     If matrix was scaled, then rescale eigenvalues appropriately.
595: *
596:       IF( SCALE.NE.ONE ) THEN
597:          CALL SSCAL( M, ONE / SCALE, W, 1 )
598:       END IF
599: *
600: *     If eigenvalues are not in increasing order, then sort them,
601: *     possibly along with eigenvectors.
602: *
603:       IF( NSPLIT.GT.1 ) THEN
604:          IF( .NOT. WANTZ ) THEN
605:             CALL SLASRT( 'I', M, W, IINFO )
606:             IF( IINFO.NE.0 ) THEN
607:                INFO = 3
608:                RETURN
609:             END IF
610:          ELSE
611:             DO 60 J = 1, M - 1
612:                I = 0
613:                TMP = W( J )
614:                DO 50 JJ = J + 1, M
615:                   IF( W( JJ ).LT.TMP ) THEN
616:                      I = JJ
617:                      TMP = W( JJ )
618:                   END IF
619:  50            CONTINUE
620:                IF( I.NE.0 ) THEN
621:                   W( I ) = W( J )
622:                   W( J ) = TMP
623:                   IF( WANTZ ) THEN
624:                      CALL SSWAP( N, Z( 1, I ), 1, Z( 1, J ), 1 )
625:                      ITMP = ISUPPZ( 2*I-1 )
626:                      ISUPPZ( 2*I-1 ) = ISUPPZ( 2*J-1 )
627:                      ISUPPZ( 2*J-1 ) = ITMP
628:                      ITMP = ISUPPZ( 2*I )
629:                      ISUPPZ( 2*I ) = ISUPPZ( 2*J )
630:                      ISUPPZ( 2*J ) = ITMP
631:                   END IF
632:                END IF
633:  60         CONTINUE
634:          END IF
635:       ENDIF
636: *
637: *
638:       WORK( 1 ) = LWMIN
639:       IWORK( 1 ) = LIWMIN
640:       RETURN
641: *
642: *     End of SSTEMR
643: *
644:       END
645: