001:       SUBROUTINE CHBEV( JOBZ, UPLO, N, KD, AB, LDAB, W, Z, LDZ, WORK,
002:      $                  RWORK, 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               RWORK( * ), W( * )
014:       COMPLEX            AB( LDAB, * ), WORK( * ), Z( LDZ, * )
015: *     ..
016: *
017: *  Purpose
018: *  =======
019: *
020: *  CHBEV computes all the eigenvalues and, optionally, eigenvectors of
021: *  a complex Hermitian 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) COMPLEX array, dimension (LDAB, N)
042: *          On entry, the upper or lower triangle of the Hermitian 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) COMPLEX 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) COMPLEX array, dimension (N)
073: *
074: *  RWORK   (workspace) REAL array, dimension (max(1,3*N-2))
075: *
076: *  INFO    (output) INTEGER
077: *          = 0:  successful exit.
078: *          < 0:  if INFO = -i, the i-th argument had an illegal value.
079: *          > 0:  if INFO = i, the algorithm failed to converge; i
080: *                off-diagonal elements of an intermediate tridiagonal
081: *                form did not converge to zero.
082: *
083: *  =====================================================================
084: *
085: *     .. Parameters ..
086:       REAL               ZERO, ONE
087:       PARAMETER          ( ZERO = 0.0E0, ONE = 1.0E0 )
088: *     ..
089: *     .. Local Scalars ..
090:       LOGICAL            LOWER, WANTZ
091:       INTEGER            IINFO, IMAX, INDE, INDRWK, ISCALE
092:       REAL               ANRM, BIGNUM, EPS, RMAX, RMIN, SAFMIN, SIGMA,
093:      $                   SMLNUM
094: *     ..
095: *     .. External Functions ..
096:       LOGICAL            LSAME
097:       REAL               CLANHB, SLAMCH
098:       EXTERNAL           LSAME, CLANHB, SLAMCH
099: *     ..
100: *     .. External Subroutines ..
101:       EXTERNAL           CHBTRD, CLASCL, CSTEQR, SSCAL, SSTERF, XERBLA
102: *     ..
103: *     .. Intrinsic Functions ..
104:       INTRINSIC          SQRT
105: *     ..
106: *     .. Executable Statements ..
107: *
108: *     Test the input parameters.
109: *
110:       WANTZ = LSAME( JOBZ, 'V' )
111:       LOWER = LSAME( UPLO, 'L' )
112: *
113:       INFO = 0
114:       IF( .NOT.( WANTZ .OR. LSAME( JOBZ, 'N' ) ) ) THEN
115:          INFO = -1
116:       ELSE IF( .NOT.( LOWER .OR. LSAME( UPLO, 'U' ) ) ) THEN
117:          INFO = -2
118:       ELSE IF( N.LT.0 ) THEN
119:          INFO = -3
120:       ELSE IF( KD.LT.0 ) THEN
121:          INFO = -4
122:       ELSE IF( LDAB.LT.KD+1 ) THEN
123:          INFO = -6
124:       ELSE IF( LDZ.LT.1 .OR. ( WANTZ .AND. LDZ.LT.N ) ) THEN
125:          INFO = -9
126:       END IF
127: *
128:       IF( INFO.NE.0 ) THEN
129:          CALL XERBLA( 'CHBEV ', -INFO )
130:          RETURN
131:       END IF
132: *
133: *     Quick return if possible
134: *
135:       IF( N.EQ.0 )
136:      $   RETURN
137: *
138:       IF( N.EQ.1 ) THEN
139:          IF( LOWER ) THEN
140:             W( 1 ) = AB( 1, 1 )
141:          ELSE
142:             W( 1 ) = AB( KD+1, 1 )
143:          END IF
144:          IF( WANTZ )
145:      $      Z( 1, 1 ) = ONE
146:          RETURN
147:       END IF
148: *
149: *     Get machine constants.
150: *
151:       SAFMIN = SLAMCH( 'Safe minimum' )
152:       EPS = SLAMCH( 'Precision' )
153:       SMLNUM = SAFMIN / EPS
154:       BIGNUM = ONE / SMLNUM
155:       RMIN = SQRT( SMLNUM )
156:       RMAX = SQRT( BIGNUM )
157: *
158: *     Scale matrix to allowable range, if necessary.
159: *
160:       ANRM = CLANHB( 'M', UPLO, N, KD, AB, LDAB, RWORK )
161:       ISCALE = 0
162:       IF( ANRM.GT.ZERO .AND. ANRM.LT.RMIN ) THEN
163:          ISCALE = 1
164:          SIGMA = RMIN / ANRM
165:       ELSE IF( ANRM.GT.RMAX ) THEN
166:          ISCALE = 1
167:          SIGMA = RMAX / ANRM
168:       END IF
169:       IF( ISCALE.EQ.1 ) THEN
170:          IF( LOWER ) THEN
171:             CALL CLASCL( 'B', KD, KD, ONE, SIGMA, N, N, AB, LDAB, INFO )
172:          ELSE
173:             CALL CLASCL( 'Q', KD, KD, ONE, SIGMA, N, N, AB, LDAB, INFO )
174:          END IF
175:       END IF
176: *
177: *     Call CHBTRD to reduce Hermitian band matrix to tridiagonal form.
178: *
179:       INDE = 1
180:       CALL CHBTRD( JOBZ, UPLO, N, KD, AB, LDAB, W, RWORK( INDE ), Z,
181:      $             LDZ, WORK, IINFO )
182: *
183: *     For eigenvalues only, call SSTERF.  For eigenvectors, call CSTEQR.
184: *
185:       IF( .NOT.WANTZ ) THEN
186:          CALL SSTERF( N, W, RWORK( INDE ), INFO )
187:       ELSE
188:          INDRWK = INDE + N
189:          CALL CSTEQR( JOBZ, N, W, RWORK( INDE ), Z, LDZ,
190:      $                RWORK( INDRWK ), INFO )
191:       END IF
192: *
193: *     If matrix was scaled, then rescale eigenvalues appropriately.
194: *
195:       IF( ISCALE.EQ.1 ) THEN
196:          IF( INFO.EQ.0 ) THEN
197:             IMAX = N
198:          ELSE
199:             IMAX = INFO - 1
200:          END IF
201:          CALL SSCAL( IMAX, ONE / SIGMA, W, 1 )
202:       END IF
203: *
204:       RETURN
205: *
206: *     End of CHBEV
207: *
208:       END
209: