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