001:       SUBROUTINE SSBEV( JOBZ, UPLO, N, KD, AB, LDAB, W, Z, LDZ, WORK,
002:      $                  INFO )
003: *
004: *  -- LAPACK driver routine (version 3.2) --
005: *  -- LAPACK is a software package provided by Univ. of Tennessee,    --
006: *  -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
007: *     November 2006
008: *
009: *     .. Scalar Arguments ..
010:       CHARACTER          JOBZ, UPLO
011:       INTEGER            INFO, KD, LDAB, LDZ, N
012: *     ..
013: *     .. Array Arguments ..
014:       REAL               AB( LDAB, * ), W( * ), WORK( * ), Z( LDZ, * )
015: *     ..
016: *
017: *  Purpose
018: *  =======
019: *
020: *  SSBEV computes all the eigenvalues and, optionally, eigenvectors of
021: *  a real symmetric band matrix A.
022: *
023: *  Arguments
024: *  =========
025: *
026: *  JOBZ    (input) CHARACTER*1
027: *          = 'N':  Compute eigenvalues only;
028: *          = 'V':  Compute eigenvalues and eigenvectors.
029: *
030: *  UPLO    (input) CHARACTER*1
031: *          = 'U':  Upper triangle of A is stored;
032: *          = 'L':  Lower triangle of A is stored.
033: *
034: *  N       (input) INTEGER
035: *          The order of the matrix A.  N >= 0.
036: *
037: *  KD      (input) INTEGER
038: *          The number of superdiagonals of the matrix A if UPLO = 'U',
039: *          or the number of subdiagonals if UPLO = 'L'.  KD >= 0.
040: *
041: *  AB      (input/output) REAL array, dimension (LDAB, N)
042: *          On entry, the upper or lower triangle of the symmetric band
043: *          matrix A, stored in the first KD+1 rows of the array.  The
044: *          j-th column of A is stored in the j-th column of the array AB
045: *          as follows:
046: *          if UPLO = 'U', AB(kd+1+i-j,j) = A(i,j) for max(1,j-kd)<=i<=j;
047: *          if UPLO = 'L', AB(1+i-j,j)    = A(i,j) for j<=i<=min(n,j+kd).
048: *
049: *          On exit, AB is overwritten by values generated during the
050: *          reduction to tridiagonal form.  If UPLO = 'U', the first
051: *          superdiagonal and the diagonal of the tridiagonal matrix T
052: *          are returned in rows KD and KD+1 of AB, and if UPLO = 'L',
053: *          the diagonal and first subdiagonal of T are returned in the
054: *          first two rows of AB.
055: *
056: *  LDAB    (input) INTEGER
057: *          The leading dimension of the array AB.  LDAB >= KD + 1.
058: *
059: *  W       (output) REAL array, dimension (N)
060: *          If INFO = 0, the eigenvalues in ascending order.
061: *
062: *  Z       (output) REAL array, dimension (LDZ, N)
063: *          If JOBZ = 'V', then if INFO = 0, Z contains the orthonormal
064: *          eigenvectors of the matrix A, with the i-th column of Z
065: *          holding the eigenvector associated with W(i).
066: *          If JOBZ = 'N', then Z is not referenced.
067: *
068: *  LDZ     (input) INTEGER
069: *          The leading dimension of the array Z.  LDZ >= 1, and if
070: *          JOBZ = 'V', LDZ >= max(1,N).
071: *
072: *  WORK    (workspace) REAL array, dimension (max(1,3*N-2))
073: *
074: *  INFO    (output) INTEGER
075: *          = 0:  successful exit
076: *          < 0:  if INFO = -i, the i-th argument had an illegal value
077: *          > 0:  if INFO = i, the algorithm failed to converge; i
078: *                off-diagonal elements of an intermediate tridiagonal
079: *                form did not converge to zero.
080: *
081: *  =====================================================================
082: *
083: *     .. Parameters ..
084:       REAL               ZERO, ONE
085:       PARAMETER          ( ZERO = 0.0E0, ONE = 1.0E0 )
086: *     ..
087: *     .. Local Scalars ..
088:       LOGICAL            LOWER, WANTZ
089:       INTEGER            IINFO, IMAX, INDE, INDWRK, ISCALE
090:       REAL               ANRM, BIGNUM, EPS, RMAX, RMIN, SAFMIN, SIGMA,
091:      $                   SMLNUM
092: *     ..
093: *     .. External Functions ..
094:       LOGICAL            LSAME
095:       REAL               SLAMCH, SLANSB
096:       EXTERNAL           LSAME, SLAMCH, SLANSB
097: *     ..
098: *     .. External Subroutines ..
099:       EXTERNAL           SLASCL, SSBTRD, SSCAL, SSTEQR, SSTERF, XERBLA
100: *     ..
101: *     .. Intrinsic Functions ..
102:       INTRINSIC          SQRT
103: *     ..
104: *     .. Executable Statements ..
105: *
106: *     Test the input parameters.
107: *
108:       WANTZ = LSAME( JOBZ, 'V' )
109:       LOWER = LSAME( UPLO, 'L' )
110: *
111:       INFO = 0
112:       IF( .NOT.( WANTZ .OR. LSAME( JOBZ, 'N' ) ) ) THEN
113:          INFO = -1
114:       ELSE IF( .NOT.( LOWER .OR. LSAME( UPLO, 'U' ) ) ) THEN
115:          INFO = -2
116:       ELSE IF( N.LT.0 ) THEN
117:          INFO = -3
118:       ELSE IF( KD.LT.0 ) THEN
119:          INFO = -4
120:       ELSE IF( LDAB.LT.KD+1 ) THEN
121:          INFO = -6
122:       ELSE IF( LDZ.LT.1 .OR. ( WANTZ .AND. LDZ.LT.N ) ) THEN
123:          INFO = -9
124:       END IF
125: *
126:       IF( INFO.NE.0 ) THEN
127:          CALL XERBLA( 'SSBEV ', -INFO )
128:          RETURN
129:       END IF
130: *
131: *     Quick return if possible
132: *
133:       IF( N.EQ.0 )
134:      $   RETURN
135: *
136:       IF( N.EQ.1 ) THEN
137:          IF( LOWER ) THEN
138:             W( 1 ) = AB( 1, 1 )
139:          ELSE
140:             W( 1 ) = AB( KD+1, 1 )
141:          END IF
142:          IF( WANTZ )
143:      $      Z( 1, 1 ) = ONE
144:          RETURN
145:       END IF
146: *
147: *     Get machine constants.
148: *
149:       SAFMIN = SLAMCH( 'Safe minimum' )
150:       EPS = SLAMCH( 'Precision' )
151:       SMLNUM = SAFMIN / EPS
152:       BIGNUM = ONE / SMLNUM
153:       RMIN = SQRT( SMLNUM )
154:       RMAX = SQRT( BIGNUM )
155: *
156: *     Scale matrix to allowable range, if necessary.
157: *
158:       ANRM = SLANSB( 'M', UPLO, N, KD, AB, LDAB, WORK )
159:       ISCALE = 0
160:       IF( ANRM.GT.ZERO .AND. ANRM.LT.RMIN ) THEN
161:          ISCALE = 1
162:          SIGMA = RMIN / ANRM
163:       ELSE IF( ANRM.GT.RMAX ) THEN
164:          ISCALE = 1
165:          SIGMA = RMAX / ANRM
166:       END IF
167:       IF( ISCALE.EQ.1 ) THEN
168:          IF( LOWER ) THEN
169:             CALL SLASCL( 'B', KD, KD, ONE, SIGMA, N, N, AB, LDAB, INFO )
170:          ELSE
171:             CALL SLASCL( 'Q', KD, KD, ONE, SIGMA, N, N, AB, LDAB, INFO )
172:          END IF
173:       END IF
174: *
175: *     Call SSBTRD to reduce symmetric band matrix to tridiagonal form.
176: *
177:       INDE = 1
178:       INDWRK = INDE + N
179:       CALL SSBTRD( JOBZ, UPLO, N, KD, AB, LDAB, W, WORK( INDE ), Z, LDZ,
180:      $             WORK( INDWRK ), IINFO )
181: *
182: *     For eigenvalues only, call SSTERF.  For eigenvectors, call SSTEQR.
183: *
184:       IF( .NOT.WANTZ ) THEN
185:          CALL SSTERF( N, W, WORK( INDE ), INFO )
186:       ELSE
187:          CALL SSTEQR( JOBZ, N, W, WORK( INDE ), Z, LDZ, WORK( INDWRK ),
188:      $                INFO )
189:       END IF
190: *
191: *     If matrix was scaled, then rescale eigenvalues appropriately.
192: *
193:       IF( ISCALE.EQ.1 ) THEN
194:          IF( INFO.EQ.0 ) THEN
195:             IMAX = N
196:          ELSE
197:             IMAX = INFO - 1
198:          END IF
199:          CALL SSCAL( IMAX, ONE / SIGMA, W, 1 )
200:       END IF
201: *
202:       RETURN
203: *
204: *     End of SSBEV
205: *
206:       END
207: