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