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