001:       SUBROUTINE SSYEVR( JOBZ, RANGE, UPLO, N, A, LDA, VL, VU, IL, IU,
002:      $                   ABSTOL, M, W, Z, LDZ, ISUPPZ, WORK, LWORK,
003:      $                   IWORK, LIWORK, INFO )
004: *
005: *  -- LAPACK driver routine (version 3.2) --
006: *     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
007: *     November 2006
008: *
009: *     .. Scalar Arguments ..
010:       CHARACTER          JOBZ, RANGE, UPLO
011:       INTEGER            IL, INFO, IU, LDA, LDZ, LIWORK, LWORK, M, N
012:       REAL               ABSTOL, VL, VU
013: *     ..
014: *     .. Array Arguments ..
015:       INTEGER            ISUPPZ( * ), IWORK( * )
016:       REAL               A( LDA, * ), W( * ), WORK( * ), Z( LDZ, * )
017: *     ..
018: *
019: *  Purpose
020: *  =======
021: *
022: *  SSYEVR computes selected eigenvalues and, optionally, eigenvectors
023: *  of a real symmetric matrix A.  Eigenvalues and eigenvectors can be
024: *  selected by specifying either a range of values or a range of
025: *  indices for the desired eigenvalues.
026: *
027: *  SSYEVR first reduces the matrix A to tridiagonal form T with a call
028: *  to SSYTRD.  Then, whenever possible, SSYEVR calls SSTEMR to compute
029: *  the eigenspectrum using Relatively Robust Representations.  SSTEMR
030: *  computes eigenvalues by the dqds algorithm, while orthogonal
031: *  eigenvectors are computed from various "good" L D L^T representations
032: *  (also known as Relatively Robust Representations). Gram-Schmidt
033: *  orthogonalization is avoided as far as possible. More specifically,
034: *  the various steps of the algorithm are as follows.
035: *
036: *  For each unreduced block (submatrix) of T,
037: *     (a) Compute T - sigma I  = L D L^T, so that L and D
038: *         define all the wanted eigenvalues to high relative accuracy.
039: *         This means that small relative changes in the entries of D and L
040: *         cause only small relative changes in the eigenvalues and
041: *         eigenvectors. The standard (unfactored) representation of the
042: *         tridiagonal matrix T does not have this property in general.
043: *     (b) Compute the eigenvalues to suitable accuracy.
044: *         If the eigenvectors are desired, the algorithm attains full
045: *         accuracy of the computed eigenvalues only right before
046: *         the corresponding vectors have to be computed, see steps c) and d).
047: *     (c) For each cluster of close eigenvalues, select a new
048: *         shift close to the cluster, find a new factorization, and refine
049: *         the shifted eigenvalues to suitable accuracy.
050: *     (d) For each eigenvalue with a large enough relative separation compute
051: *         the corresponding eigenvector by forming a rank revealing twisted
052: *         factorization. Go back to (c) for any clusters that remain.
053: *
054: *  The desired accuracy of the output can be specified by the input
055: *  parameter ABSTOL.
056: *
057: *  For more details, see SSTEMR's documentation and:
058: *  - Inderjit S. Dhillon and Beresford N. Parlett: "Multiple representations
059: *    to compute orthogonal eigenvectors of symmetric tridiagonal matrices,"
060: *    Linear Algebra and its Applications, 387(1), pp. 1-28, August 2004.
061: *  - Inderjit Dhillon and Beresford Parlett: "Orthogonal Eigenvectors and
062: *    Relative Gaps," SIAM Journal on Matrix Analysis and Applications, Vol. 25,
063: *    2004.  Also LAPACK Working Note 154.
064: *  - Inderjit Dhillon: "A new O(n^2) algorithm for the symmetric
065: *    tridiagonal eigenvalue/eigenvector problem",
066: *    Computer Science Division Technical Report No. UCB/CSD-97-971,
067: *    UC Berkeley, May 1997.
068: *
069: *
070: *  Note 1 : SSYEVR calls SSTEMR when the full spectrum is requested
071: *  on machines which conform to the ieee-754 floating point standard.
072: *  SSYEVR calls SSTEBZ and SSTEIN on non-ieee machines and
073: *  when partial spectrum requests are made.
074: *
075: *  Normal execution of SSTEMR may create NaNs and infinities and
076: *  hence may abort due to a floating point exception in environments
077: *  which do not handle NaNs and infinities in the ieee standard default
078: *  manner.
079: *
080: *  Arguments
081: *  =========
082: *
083: *  JOBZ    (input) CHARACTER*1
084: *          = 'N':  Compute eigenvalues only;
085: *          = 'V':  Compute eigenvalues and eigenvectors.
086: *
087: *  RANGE   (input) CHARACTER*1
088: *          = 'A': all eigenvalues will be found.
089: *          = 'V': all eigenvalues in the half-open interval (VL,VU]
090: *                 will be found.
091: *          = 'I': the IL-th through IU-th eigenvalues will be found.
092: ********** For RANGE = 'V' or 'I' and IU - IL < N - 1, SSTEBZ and
093: ********** SSTEIN are called
094: *
095: *  UPLO    (input) CHARACTER*1
096: *          = 'U':  Upper triangle of A is stored;
097: *          = 'L':  Lower triangle of A is stored.
098: *
099: *  N       (input) INTEGER
100: *          The order of the matrix A.  N >= 0.
101: *
102: *  A       (input/output) REAL array, dimension (LDA, N)
103: *          On entry, the symmetric matrix A.  If UPLO = 'U', the
104: *          leading N-by-N upper triangular part of A contains the
105: *          upper triangular part of the matrix A.  If UPLO = 'L',
106: *          the leading N-by-N lower triangular part of A contains
107: *          the lower triangular part of the matrix A.
108: *          On exit, the lower triangle (if UPLO='L') or the upper
109: *          triangle (if UPLO='U') of A, including the diagonal, is
110: *          destroyed.
111: *
112: *  LDA     (input) INTEGER
113: *          The leading dimension of the array A.  LDA >= max(1,N).
114: *
115: *  VL      (input) REAL
116: *  VU      (input) REAL
117: *          If RANGE='V', the lower and upper bounds of the interval to
118: *          be searched for eigenvalues. VL < VU.
119: *          Not referenced if RANGE = 'A' or 'I'.
120: *
121: *  IL      (input) INTEGER
122: *  IU      (input) INTEGER
123: *          If RANGE='I', the indices (in ascending order) of the
124: *          smallest and largest eigenvalues to be returned.
125: *          1 <= IL <= IU <= N, if N > 0; IL = 1 and IU = 0 if N = 0.
126: *          Not referenced if RANGE = 'A' or 'V'.
127: *
128: *  ABSTOL  (input) REAL
129: *          The absolute error tolerance for the eigenvalues.
130: *          An approximate eigenvalue is accepted as converged
131: *          when it is determined to lie in an interval [a,b]
132: *          of width less than or equal to
133: *
134: *                  ABSTOL + EPS *   max( |a|,|b| ) ,
135: *
136: *          where EPS is the machine precision.  If ABSTOL is less than
137: *          or equal to zero, then  EPS*|T|  will be used in its place,
138: *          where |T| is the 1-norm of the tridiagonal matrix obtained
139: *          by reducing A to tridiagonal form.
140: *
141: *          See "Computing Small Singular Values of Bidiagonal Matrices
142: *          with Guaranteed High Relative Accuracy," by Demmel and
143: *          Kahan, LAPACK Working Note #3.
144: *
145: *          If high relative accuracy is important, set ABSTOL to
146: *          SLAMCH( 'Safe minimum' ).  Doing so will guarantee that
147: *          eigenvalues are computed to high relative accuracy when
148: *          possible in future releases.  The current code does not
149: *          make any guarantees about high relative accuracy, but
150: *          future releases will. See J. Barlow and J. Demmel,
151: *          "Computing Accurate Eigensystems of Scaled Diagonally
152: *          Dominant Matrices", LAPACK Working Note #7, for a discussion
153: *          of which matrices define their eigenvalues to high relative
154: *          accuracy.
155: *
156: *  M       (output) INTEGER
157: *          The total number of eigenvalues found.  0 <= M <= N.
158: *          If RANGE = 'A', M = N, and if RANGE = 'I', M = IU-IL+1.
159: *
160: *  W       (output) REAL array, dimension (N)
161: *          The first M elements contain the selected eigenvalues in
162: *          ascending order.
163: *
164: *  Z       (output) REAL array, dimension (LDZ, max(1,M))
165: *          If JOBZ = 'V', then if INFO = 0, the first M columns of Z
166: *          contain the orthonormal eigenvectors of the matrix A
167: *          corresponding to the selected eigenvalues, with the i-th
168: *          column of Z holding the eigenvector associated with W(i).
169: *          If JOBZ = 'N', then Z is not referenced.
170: *          Note: the user must ensure that at least max(1,M) columns are
171: *          supplied in the array Z; if RANGE = 'V', the exact value of M
172: *          is not known in advance and an upper bound must be used.
173: *          Supplying N columns is always safe.
174: *
175: *  LDZ     (input) INTEGER
176: *          The leading dimension of the array Z.  LDZ >= 1, and if
177: *          JOBZ = 'V', LDZ >= max(1,N).
178: *
179: *  ISUPPZ  (output) INTEGER array, dimension ( 2*max(1,M) )
180: *          The support of the eigenvectors in Z, i.e., the indices
181: *          indicating the nonzero elements in Z. The i-th eigenvector
182: *          is nonzero only in elements ISUPPZ( 2*i-1 ) through
183: *          ISUPPZ( 2*i ).
184: ********** Implemented only for RANGE = 'A' or 'I' and IU - IL = N - 1
185: *
186: *  WORK    (workspace/output) REAL array, dimension (MAX(1,LWORK))
187: *          On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
188: *
189: *  LWORK   (input) INTEGER
190: *          The dimension of the array WORK.  LWORK >= max(1,26*N).
191: *          For optimal efficiency, LWORK >= (NB+6)*N,
192: *          where NB is the max of the blocksize for SSYTRD and SORMTR
193: *          returned by ILAENV.
194: *
195: *          If LWORK = -1, then a workspace query is assumed; the routine
196: *          only calculates the optimal sizes of the WORK and IWORK
197: *          arrays, returns these values as the first entries of the WORK
198: *          and IWORK arrays, and no error message related to LWORK or
199: *          LIWORK is issued by XERBLA.
200: *
201: *  IWORK   (workspace/output) INTEGER array, dimension (MAX(1,LIWORK))
202: *          On exit, if INFO = 0, IWORK(1) returns the optimal LWORK.
203: *
204: *  LIWORK  (input) INTEGER
205: *          The dimension of the array IWORK.  LIWORK >= max(1,10*N).
206: *
207: *          If LIWORK = -1, then a workspace query is assumed; the
208: *          routine only calculates the optimal sizes of the WORK and
209: *          IWORK arrays, returns these values as the first entries of
210: *          the WORK and IWORK arrays, and no error message related to
211: *          LWORK or LIWORK is issued by XERBLA.
212: *
213: *  INFO    (output) INTEGER
214: *          = 0:  successful exit
215: *          < 0:  if INFO = -i, the i-th argument had an illegal value
216: *          > 0:  Internal error
217: *
218: *  Further Details
219: *  ===============
220: *
221: *  Based on contributions by
222: *     Inderjit Dhillon, IBM Almaden, USA
223: *     Osni Marques, LBNL/NERSC, USA
224: *     Ken Stanley, Computer Science Division, University of
225: *       California at Berkeley, USA
226: *     Jason Riedy, Computer Science Division, University of
227: *       California at Berkeley, USA
228: *
229: * =====================================================================
230: *
231: *     .. Parameters ..
232:       REAL               ZERO, ONE, TWO
233:       PARAMETER          ( ZERO = 0.0E+0, ONE = 1.0E+0, TWO = 2.0E+0 )
234: *     ..
235: *     .. Local Scalars ..
236:       LOGICAL            ALLEIG, INDEIG, LOWER, LQUERY, TEST, VALEIG,
237:      $                   WANTZ, TRYRAC
238:       CHARACTER          ORDER
239:       INTEGER            I, IEEEOK, IINFO, IMAX, INDD, INDDD, INDE,
240:      $                   INDEE, INDIBL, INDIFL, INDISP, INDIWO, INDTAU,
241:      $                   INDWK, INDWKN, ISCALE, J, JJ, LIWMIN,
242:      $                   LLWORK, LLWRKN, LWKOPT, LWMIN, NB, NSPLIT
243:       REAL               ABSTLL, ANRM, BIGNUM, EPS, RMAX, RMIN, SAFMIN,
244:      $                   SIGMA, SMLNUM, TMP1, VLL, VUU
245: *     ..
246: *     .. External Functions ..
247:       LOGICAL            LSAME
248:       INTEGER            ILAENV
249:       REAL               SLAMCH, SLANSY
250:       EXTERNAL           LSAME, ILAENV, SLAMCH, SLANSY
251: *     ..
252: *     .. External Subroutines ..
253:       EXTERNAL           SCOPY, SORMTR, SSCAL, SSTEBZ, SSTEMR, SSTEIN,
254:      $                   SSTERF, SSWAP, SSYTRD, XERBLA
255: *     ..
256: *     .. Intrinsic Functions ..
257:       INTRINSIC          MAX, MIN, SQRT
258: *     ..
259: *     .. Executable Statements ..
260: *
261: *     Test the input parameters.
262: *
263:       IEEEOK = ILAENV( 10, 'SSYEVR', 'N', 1, 2, 3, 4 )
264: *
265:       LOWER = LSAME( UPLO, 'L' )
266:       WANTZ = LSAME( JOBZ, 'V' )
267:       ALLEIG = LSAME( RANGE, 'A' )
268:       VALEIG = LSAME( RANGE, 'V' )
269:       INDEIG = LSAME( RANGE, 'I' )
270: *
271:       LQUERY = ( ( LWORK.EQ.-1 ) .OR. ( LIWORK.EQ.-1 ) )
272: *
273:       LWMIN = MAX( 1, 26*N )
274:       LIWMIN = MAX( 1, 10*N )
275: *
276:       INFO = 0
277:       IF( .NOT.( WANTZ .OR. LSAME( JOBZ, 'N' ) ) ) THEN
278:          INFO = -1
279:       ELSE IF( .NOT.( ALLEIG .OR. VALEIG .OR. INDEIG ) ) THEN
280:          INFO = -2
281:       ELSE IF( .NOT.( LOWER .OR. LSAME( UPLO, 'U' ) ) ) THEN
282:          INFO = -3
283:       ELSE IF( N.LT.0 ) THEN
284:          INFO = -4
285:       ELSE IF( LDA.LT.MAX( 1, N ) ) THEN
286:          INFO = -6
287:       ELSE
288:          IF( VALEIG ) THEN
289:             IF( N.GT.0 .AND. VU.LE.VL )
290:      $         INFO = -8
291:          ELSE IF( INDEIG ) THEN
292:             IF( IL.LT.1 .OR. IL.GT.MAX( 1, N ) ) THEN
293:                INFO = -9
294:             ELSE IF( IU.LT.MIN( N, IL ) .OR. IU.GT.N ) THEN
295:                INFO = -10
296:             END IF
297:          END IF
298:       END IF
299:       IF( INFO.EQ.0 ) THEN
300:          IF( LDZ.LT.1 .OR. ( WANTZ .AND. LDZ.LT.N ) ) THEN
301:             INFO = -15
302:          END IF
303:       END IF
304: *
305:       IF( INFO.EQ.0 ) THEN
306:          NB = ILAENV( 1, 'SSYTRD', UPLO, N, -1, -1, -1 )
307:          NB = MAX( NB, ILAENV( 1, 'SORMTR', UPLO, N, -1, -1, -1 ) )
308:          LWKOPT = MAX( ( NB+1 )*N, LWMIN )
309:          WORK( 1 ) = LWKOPT
310:          IWORK( 1 ) = LIWMIN
311: *
312:          IF( LWORK.LT.LWMIN .AND. .NOT.LQUERY ) THEN
313:             INFO = -18
314:          ELSE IF( LIWORK.LT.LIWMIN .AND. .NOT.LQUERY ) THEN
315:             INFO = -20
316:          END IF
317:       END IF
318: *
319:       IF( INFO.NE.0 ) THEN
320:          CALL XERBLA( 'SSYEVR', -INFO )
321:          RETURN
322:       ELSE IF( LQUERY ) THEN
323:          RETURN
324:       END IF
325: *
326: *     Quick return if possible
327: *
328:       M = 0
329:       IF( N.EQ.0 ) THEN
330:          WORK( 1 ) = 1
331:          RETURN
332:       END IF
333: *
334:       IF( N.EQ.1 ) THEN
335:          WORK( 1 ) = 26
336:          IF( ALLEIG .OR. INDEIG ) THEN
337:             M = 1
338:             W( 1 ) = A( 1, 1 )
339:          ELSE
340:             IF( VL.LT.A( 1, 1 ) .AND. VU.GE.A( 1, 1 ) ) THEN
341:                M = 1
342:                W( 1 ) = A( 1, 1 )
343:             END IF
344:          END IF
345:          IF( WANTZ )
346:      $      Z( 1, 1 ) = ONE
347:          RETURN
348:       END IF
349: *
350: *     Get machine constants.
351: *
352:       SAFMIN = SLAMCH( 'Safe minimum' )
353:       EPS = SLAMCH( 'Precision' )
354:       SMLNUM = SAFMIN / EPS
355:       BIGNUM = ONE / SMLNUM
356:       RMIN = SQRT( SMLNUM )
357:       RMAX = MIN( SQRT( BIGNUM ), ONE / SQRT( SQRT( SAFMIN ) ) )
358: *
359: *     Scale matrix to allowable range, if necessary.
360: *
361:       ISCALE = 0
362:       ABSTLL = ABSTOL
363:       IF (VALEIG) THEN
364:          VLL = VL
365:          VUU = VU
366:       END IF
367:       ANRM = SLANSY( 'M', UPLO, N, A, LDA, WORK )
368:       IF( ANRM.GT.ZERO .AND. ANRM.LT.RMIN ) THEN
369:          ISCALE = 1
370:          SIGMA = RMIN / ANRM
371:       ELSE IF( ANRM.GT.RMAX ) THEN
372:          ISCALE = 1
373:          SIGMA = RMAX / ANRM
374:       END IF
375:       IF( ISCALE.EQ.1 ) THEN
376:          IF( LOWER ) THEN
377:             DO 10 J = 1, N
378:                CALL SSCAL( N-J+1, SIGMA, A( J, J ), 1 )
379:    10       CONTINUE
380:          ELSE
381:             DO 20 J = 1, N
382:                CALL SSCAL( J, SIGMA, A( 1, J ), 1 )
383:    20       CONTINUE
384:          END IF
385:          IF( ABSTOL.GT.0 )
386:      $      ABSTLL = ABSTOL*SIGMA
387:          IF( VALEIG ) THEN
388:             VLL = VL*SIGMA
389:             VUU = VU*SIGMA
390:          END IF
391:       END IF
392: 
393: *     Initialize indices into workspaces.  Note: The IWORK indices are
394: *     used only if SSTERF or SSTEMR fail.
395: 
396: *     WORK(INDTAU:INDTAU+N-1) stores the scalar factors of the
397: *     elementary reflectors used in SSYTRD.
398:       INDTAU = 1
399: *     WORK(INDD:INDD+N-1) stores the tridiagonal's diagonal entries.
400:       INDD = INDTAU + N
401: *     WORK(INDE:INDE+N-1) stores the off-diagonal entries of the
402: *     tridiagonal matrix from SSYTRD.
403:       INDE = INDD + N
404: *     WORK(INDDD:INDDD+N-1) is a copy of the diagonal entries over
405: *     -written by SSTEMR (the SSTERF path copies the diagonal to W).
406:       INDDD = INDE + N
407: *     WORK(INDEE:INDEE+N-1) is a copy of the off-diagonal entries over
408: *     -written while computing the eigenvalues in SSTERF and SSTEMR.
409:       INDEE = INDDD + N
410: *     INDWK is the starting offset of the left-over workspace, and
411: *     LLWORK is the remaining workspace size.
412:       INDWK = INDEE + N
413:       LLWORK = LWORK - INDWK + 1
414: 
415: *     IWORK(INDIBL:INDIBL+M-1) corresponds to IBLOCK in SSTEBZ and
416: *     stores the block indices of each of the M<=N eigenvalues.
417:       INDIBL = 1
418: *     IWORK(INDISP:INDISP+NSPLIT-1) corresponds to ISPLIT in SSTEBZ and
419: *     stores the starting and finishing indices of each block.
420:       INDISP = INDIBL + N
421: *     IWORK(INDIFL:INDIFL+N-1) stores the indices of eigenvectors
422: *     that corresponding to eigenvectors that fail to converge in
423: *     SSTEIN.  This information is discarded; if any fail, the driver
424: *     returns INFO > 0.
425:       INDIFL = INDISP + N
426: *     INDIWO is the offset of the remaining integer workspace.
427:       INDIWO = INDISP + N
428: 
429: *
430: *     Call SSYTRD to reduce symmetric matrix to tridiagonal form.
431: *
432:       CALL SSYTRD( UPLO, N, A, LDA, WORK( INDD ), WORK( INDE ),
433:      $             WORK( INDTAU ), WORK( INDWK ), LLWORK, IINFO )
434: *
435: *     If all eigenvalues are desired
436: *     then call SSTERF or SSTEMR and SORMTR.
437: *
438:       TEST = .FALSE.
439:       IF( INDEIG ) THEN
440:          IF( IL.EQ.1 .AND. IU.EQ.N ) THEN
441:             TEST = .TRUE.
442:          END IF
443:       END IF
444:       IF( ( ALLEIG.OR.TEST ) .AND. ( IEEEOK.EQ.1 ) ) THEN
445:          IF( .NOT.WANTZ ) THEN
446:             CALL SCOPY( N, WORK( INDD ), 1, W, 1 )
447:             CALL SCOPY( N-1, WORK( INDE ), 1, WORK( INDEE ), 1 )
448:             CALL SSTERF( N, W, WORK( INDEE ), INFO )
449:          ELSE
450:             CALL SCOPY( N-1, WORK( INDE ), 1, WORK( INDEE ), 1 )
451:             CALL SCOPY( N, WORK( INDD ), 1, WORK( INDDD ), 1 )
452: *
453:             IF (ABSTOL .LE. TWO*N*EPS) THEN
454:                TRYRAC = .TRUE.
455:             ELSE
456:                TRYRAC = .FALSE.
457:             END IF
458:             CALL SSTEMR( JOBZ, 'A', N, WORK( INDDD ), WORK( INDEE ),
459:      $                   VL, VU, IL, IU, M, W, Z, LDZ, N, ISUPPZ,
460:      $                   TRYRAC, WORK( INDWK ), LWORK, IWORK, LIWORK,
461:      $                   INFO )
462: *
463: *
464: *
465: *        Apply orthogonal matrix used in reduction to tridiagonal
466: *        form to eigenvectors returned by SSTEIN.
467: *
468:             IF( WANTZ .AND. INFO.EQ.0 ) THEN
469:                INDWKN = INDE
470:                LLWRKN = LWORK - INDWKN + 1
471:                CALL SORMTR( 'L', UPLO, 'N', N, M, A, LDA,
472:      $                      WORK( INDTAU ), Z, LDZ, WORK( INDWKN ),
473:      $                      LLWRKN, IINFO )
474:             END IF
475:          END IF
476: *
477: *
478:          IF( INFO.EQ.0 ) THEN
479: *           Everything worked.  Skip SSTEBZ/SSTEIN.  IWORK(:) are
480: *           undefined.
481:             M = N
482:             GO TO 30
483:          END IF
484:          INFO = 0
485:       END IF
486: *
487: *     Otherwise, call SSTEBZ and, if eigenvectors are desired, SSTEIN.
488: *     Also call SSTEBZ and SSTEIN if SSTEMR fails.
489: *
490:       IF( WANTZ ) THEN
491:          ORDER = 'B'
492:       ELSE
493:          ORDER = 'E'
494:       END IF
495: 
496:       CALL SSTEBZ( RANGE, ORDER, N, VLL, VUU, IL, IU, ABSTLL,
497:      $             WORK( INDD ), WORK( INDE ), M, NSPLIT, W,
498:      $             IWORK( INDIBL ), IWORK( INDISP ), WORK( INDWK ),
499:      $             IWORK( INDIWO ), INFO )
500: *
501:       IF( WANTZ ) THEN
502:          CALL SSTEIN( N, WORK( INDD ), WORK( INDE ), M, W,
503:      $                IWORK( INDIBL ), IWORK( INDISP ), Z, LDZ,
504:      $                WORK( INDWK ), IWORK( INDIWO ), IWORK( INDIFL ),
505:      $                INFO )
506: *
507: *        Apply orthogonal matrix used in reduction to tridiagonal
508: *        form to eigenvectors returned by SSTEIN.
509: *
510:          INDWKN = INDE
511:          LLWRKN = LWORK - INDWKN + 1
512:          CALL SORMTR( 'L', UPLO, 'N', N, M, A, LDA, WORK( INDTAU ), Z,
513:      $                LDZ, WORK( INDWKN ), LLWRKN, IINFO )
514:       END IF
515: *
516: *     If matrix was scaled, then rescale eigenvalues appropriately.
517: *
518: *  Jump here if SSTEMR/SSTEIN succeeded.
519:    30 CONTINUE
520:       IF( ISCALE.EQ.1 ) THEN
521:          IF( INFO.EQ.0 ) THEN
522:             IMAX = M
523:          ELSE
524:             IMAX = INFO - 1
525:          END IF
526:          CALL SSCAL( IMAX, ONE / SIGMA, W, 1 )
527:       END IF
528: *
529: *     If eigenvalues are not in order, then sort them, along with
530: *     eigenvectors.  Note: We do not sort the IFAIL portion of IWORK.
531: *     It may not be initialized (if SSTEMR/SSTEIN succeeded), and we do
532: *     not return this detailed information to the user.
533: *
534:       IF( WANTZ ) THEN
535:          DO 50 J = 1, M - 1
536:             I = 0
537:             TMP1 = W( J )
538:             DO 40 JJ = J + 1, M
539:                IF( W( JJ ).LT.TMP1 ) THEN
540:                   I = JJ
541:                   TMP1 = W( JJ )
542:                END IF
543:    40       CONTINUE
544: *
545:             IF( I.NE.0 ) THEN
546:                W( I ) = W( J )
547:                W( J ) = TMP1
548:                CALL SSWAP( N, Z( 1, I ), 1, Z( 1, J ), 1 )
549:             END IF
550:    50    CONTINUE
551:       END IF
552: *
553: *     Set WORK(1) to optimal workspace size.
554: *
555:       WORK( 1 ) = LWKOPT
556:       IWORK( 1 ) = LIWMIN
557: *
558:       RETURN
559: *
560: *     End of SSYEVR
561: *
562:       END
563: