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