001:       SUBROUTINE CHBGVD( JOBZ, UPLO, N, KA, KB, AB, LDAB, BB, LDBB, W,
002:      $                   Z, LDZ, WORK, LWORK, RWORK, LRWORK, IWORK,
003:      $                   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, UPLO
011:       INTEGER            INFO, KA, KB, LDAB, LDBB, LDZ, LIWORK, LRWORK,
012:      $                   LWORK, N
013: *     ..
014: *     .. Array Arguments ..
015:       INTEGER            IWORK( * )
016:       REAL               RWORK( * ), W( * )
017:       COMPLEX            AB( LDAB, * ), BB( LDBB, * ), WORK( * ),
018:      $                   Z( LDZ, * )
019: *     ..
020: *
021: *  Purpose
022: *  =======
023: *
024: *  CHBGVD computes all the eigenvalues, and optionally, the eigenvectors
025: *  of a complex generalized Hermitian-definite banded eigenproblem, of
026: *  the form A*x=(lambda)*B*x. Here A and B are assumed to be Hermitian
027: *  and banded, and B is also positive definite.  If eigenvectors are
028: *  desired, it uses a divide and conquer algorithm.
029: *
030: *  The divide and conquer algorithm makes very mild assumptions about
031: *  floating point arithmetic. It will work on machines with a guard
032: *  digit in add/subtract, or on those binary machines without guard
033: *  digits which subtract like the Cray X-MP, Cray Y-MP, Cray C-90, or
034: *  Cray-2. It could conceivably fail on hexadecimal or decimal machines
035: *  without guard digits, but we know of none.
036: *
037: *  Arguments
038: *  =========
039: *
040: *  JOBZ    (input) CHARACTER*1
041: *          = 'N':  Compute eigenvalues only;
042: *          = 'V':  Compute eigenvalues and eigenvectors.
043: *
044: *  UPLO    (input) CHARACTER*1
045: *          = 'U':  Upper triangles of A and B are stored;
046: *          = 'L':  Lower triangles of A and B are stored.
047: *
048: *  N       (input) INTEGER
049: *          The order of the matrices A and B.  N >= 0.
050: *
051: *  KA      (input) INTEGER
052: *          The number of superdiagonals of the matrix A if UPLO = 'U',
053: *          or the number of subdiagonals if UPLO = 'L'. KA >= 0.
054: *
055: *  KB      (input) INTEGER
056: *          The number of superdiagonals of the matrix B if UPLO = 'U',
057: *          or the number of subdiagonals if UPLO = 'L'. KB >= 0.
058: *
059: *  AB      (input/output) COMPLEX array, dimension (LDAB, N)
060: *          On entry, the upper or lower triangle of the Hermitian band
061: *          matrix A, stored in the first ka+1 rows of the array.  The
062: *          j-th column of A is stored in the j-th column of the array AB
063: *          as follows:
064: *          if UPLO = 'U', AB(ka+1+i-j,j) = A(i,j) for max(1,j-ka)<=i<=j;
065: *          if UPLO = 'L', AB(1+i-j,j)    = A(i,j) for j<=i<=min(n,j+ka).
066: *
067: *          On exit, the contents of AB are destroyed.
068: *
069: *  LDAB    (input) INTEGER
070: *          The leading dimension of the array AB.  LDAB >= KA+1.
071: *
072: *  BB      (input/output) COMPLEX array, dimension (LDBB, N)
073: *          On entry, the upper or lower triangle of the Hermitian band
074: *          matrix B, stored in the first kb+1 rows of the array.  The
075: *          j-th column of B is stored in the j-th column of the array BB
076: *          as follows:
077: *          if UPLO = 'U', BB(kb+1+i-j,j) = B(i,j) for max(1,j-kb)<=i<=j;
078: *          if UPLO = 'L', BB(1+i-j,j)    = B(i,j) for j<=i<=min(n,j+kb).
079: *
080: *          On exit, the factor S from the split Cholesky factorization
081: *          B = S**H*S, as returned by CPBSTF.
082: *
083: *  LDBB    (input) INTEGER
084: *          The leading dimension of the array BB.  LDBB >= KB+1.
085: *
086: *  W       (output) REAL array, dimension (N)
087: *          If INFO = 0, the eigenvalues in ascending order.
088: *
089: *  Z       (output) COMPLEX array, dimension (LDZ, N)
090: *          If JOBZ = 'V', then if INFO = 0, Z contains the matrix Z of
091: *          eigenvectors, with the i-th column of Z holding the
092: *          eigenvector associated with W(i). The eigenvectors are
093: *          normalized so that Z**H*B*Z = I.
094: *          If JOBZ = 'N', then Z is not referenced.
095: *
096: *  LDZ     (input) INTEGER
097: *          The leading dimension of the array Z.  LDZ >= 1, and if
098: *          JOBZ = 'V', LDZ >= N.
099: *
100: *  WORK    (workspace/output) COMPLEX array, dimension (MAX(1,LWORK))
101: *          On exit, if INFO=0, WORK(1) returns the optimal LWORK.
102: *
103: *  LWORK   (input) INTEGER
104: *          The dimension of the array WORK.
105: *          If N <= 1,               LWORK >= 1.
106: *          If JOBZ = 'N' and N > 1, LWORK >= N.
107: *          If JOBZ = 'V' and N > 1, LWORK >= 2*N**2.
108: *
109: *          If LWORK = -1, then a workspace query is assumed; the routine
110: *          only calculates the optimal sizes of the WORK, RWORK and
111: *          IWORK arrays, returns these values as the first entries of
112: *          the WORK, RWORK and IWORK arrays, and no error message
113: *          related to LWORK or LRWORK or LIWORK is issued by XERBLA.
114: *
115: *  RWORK   (workspace/output) REAL array, dimension (MAX(1,LRWORK))
116: *          On exit, if INFO=0, RWORK(1) returns the optimal LRWORK.
117: *
118: *  LRWORK  (input) INTEGER
119: *          The dimension of array RWORK.
120: *          If N <= 1,               LRWORK >= 1.
121: *          If JOBZ = 'N' and N > 1, LRWORK >= N.
122: *          If JOBZ = 'V' and N > 1, LRWORK >= 1 + 5*N + 2*N**2.
123: *
124: *          If LRWORK = -1, then a workspace query is assumed; the
125: *          routine only calculates the optimal sizes of the WORK, RWORK
126: *          and IWORK arrays, returns these values as the first entries
127: *          of the WORK, RWORK and IWORK arrays, and no error message
128: *          related to LWORK or LRWORK or LIWORK is issued by XERBLA.
129: *
130: *  IWORK   (workspace/output) INTEGER array, dimension (MAX(1,LIWORK))
131: *          On exit, if INFO=0, IWORK(1) returns the optimal LIWORK.
132: *
133: *  LIWORK  (input) INTEGER
134: *          The dimension of array IWORK.
135: *          If JOBZ = 'N' or N <= 1, LIWORK >= 1.
136: *          If JOBZ = 'V' and N > 1, LIWORK >= 3 + 5*N.
137: *
138: *          If LIWORK = -1, then a workspace query is assumed; the
139: *          routine only calculates the optimal sizes of the WORK, RWORK
140: *          and IWORK arrays, returns these values as the first entries
141: *          of the WORK, RWORK and IWORK arrays, and no error message
142: *          related to LWORK or LRWORK or LIWORK is issued by XERBLA.
143: *
144: *  INFO    (output) INTEGER
145: *          = 0:  successful exit
146: *          < 0:  if INFO = -i, the i-th argument had an illegal value
147: *          > 0:  if INFO = i, and i is:
148: *             <= N:  the algorithm failed to converge:
149: *                    i off-diagonal elements of an intermediate
150: *                    tridiagonal form did not converge to zero;
151: *             > N:   if INFO = N + i, for 1 <= i <= N, then CPBSTF
152: *                    returned INFO = i: B is not positive definite.
153: *                    The factorization of B could not be completed and
154: *                    no eigenvalues or eigenvectors were computed.
155: *
156: *  Further Details
157: *  ===============
158: *
159: *  Based on contributions by
160: *     Mark Fahey, Department of Mathematics, Univ. of Kentucky, USA
161: *
162: *  =====================================================================
163: *
164: *     .. Parameters ..
165:       COMPLEX            CONE, CZERO
166:       PARAMETER          ( CONE = ( 1.0E+0, 0.0E+0 ),
167:      $                   CZERO = ( 0.0E+0, 0.0E+0 ) )
168: *     ..
169: *     .. Local Scalars ..
170:       LOGICAL            LQUERY, UPPER, WANTZ
171:       CHARACTER          VECT
172:       INTEGER            IINFO, INDE, INDWK2, INDWRK, LIWMIN, LLRWK,
173:      $                   LLWK2, LRWMIN, LWMIN
174: *     ..
175: *     .. External Functions ..
176:       LOGICAL            LSAME
177:       EXTERNAL           LSAME
178: *     ..
179: *     .. External Subroutines ..
180:       EXTERNAL           CGEMM, CHBGST, CHBTRD, CLACPY, CPBSTF, CSTEDC,
181:      $                   SSTERF, XERBLA
182: *     ..
183: *     .. Executable Statements ..
184: *
185: *     Test the input parameters.
186: *
187:       WANTZ = LSAME( JOBZ, 'V' )
188:       UPPER = LSAME( UPLO, 'U' )
189:       LQUERY = ( LWORK.EQ.-1 .OR. LRWORK.EQ.-1 .OR. LIWORK.EQ.-1 )
190: *
191:       INFO = 0
192:       IF( N.LE.1 ) THEN
193:          LWMIN = 1
194:          LRWMIN = 1
195:          LIWMIN = 1
196:       ELSE IF( WANTZ ) THEN
197:          LWMIN = 2*N**2
198:          LRWMIN = 1 + 5*N + 2*N**2
199:          LIWMIN = 3 + 5*N
200:       ELSE
201:          LWMIN = N
202:          LRWMIN = N
203:          LIWMIN = 1
204:       END IF
205:       IF( .NOT.( WANTZ .OR. LSAME( JOBZ, 'N' ) ) ) THEN
206:          INFO = -1
207:       ELSE IF( .NOT.( UPPER .OR. LSAME( UPLO, 'L' ) ) ) THEN
208:          INFO = -2
209:       ELSE IF( N.LT.0 ) THEN
210:          INFO = -3
211:       ELSE IF( KA.LT.0 ) THEN
212:          INFO = -4
213:       ELSE IF( KB.LT.0 .OR. KB.GT.KA ) THEN
214:          INFO = -5
215:       ELSE IF( LDAB.LT.KA+1 ) THEN
216:          INFO = -7
217:       ELSE IF( LDBB.LT.KB+1 ) THEN
218:          INFO = -9
219:       ELSE IF( LDZ.LT.1 .OR. ( WANTZ .AND. LDZ.LT.N ) ) THEN
220:          INFO = -12
221:       END IF
222: *
223:       IF( INFO.EQ.0 ) THEN
224:          WORK( 1 ) = LWMIN
225:          RWORK( 1 ) = LRWMIN
226:          IWORK( 1 ) = LIWMIN
227: *
228:          IF( LWORK.LT.LWMIN .AND. .NOT.LQUERY ) THEN
229:             INFO = -14
230:          ELSE IF( LRWORK.LT.LRWMIN .AND. .NOT.LQUERY ) THEN
231:             INFO = -16
232:          ELSE IF( LIWORK.LT.LIWMIN .AND. .NOT.LQUERY ) THEN
233:             INFO = -18
234:          END IF
235:       END IF
236: *
237:       IF( INFO.NE.0 ) THEN
238:          CALL XERBLA( 'CHBGVD', -INFO )
239:          RETURN
240:       ELSE IF( LQUERY ) THEN
241:          RETURN
242:       END IF
243: *
244: *     Quick return if possible
245: *
246:       IF( N.EQ.0 )
247:      $   RETURN
248: *
249: *     Form a split Cholesky factorization of B.
250: *
251:       CALL CPBSTF( UPLO, N, KB, BB, LDBB, INFO )
252:       IF( INFO.NE.0 ) THEN
253:          INFO = N + INFO
254:          RETURN
255:       END IF
256: *
257: *     Transform problem to standard eigenvalue problem.
258: *
259:       INDE = 1
260:       INDWRK = INDE + N
261:       INDWK2 = 1 + N*N
262:       LLWK2 = LWORK - INDWK2 + 2
263:       LLRWK = LRWORK - INDWRK + 2
264:       CALL CHBGST( JOBZ, UPLO, N, KA, KB, AB, LDAB, BB, LDBB, Z, LDZ,
265:      $             WORK, RWORK( INDWRK ), IINFO )
266: *
267: *     Reduce Hermitian band matrix to tridiagonal form.
268: *
269:       IF( WANTZ ) THEN
270:          VECT = 'U'
271:       ELSE
272:          VECT = 'N'
273:       END IF
274:       CALL CHBTRD( VECT, UPLO, N, KA, AB, LDAB, W, RWORK( INDE ), Z,
275:      $             LDZ, WORK, IINFO )
276: *
277: *     For eigenvalues only, call SSTERF.  For eigenvectors, call CSTEDC.
278: *
279:       IF( .NOT.WANTZ ) THEN
280:          CALL SSTERF( N, W, RWORK( INDE ), INFO )
281:       ELSE
282:          CALL CSTEDC( 'I', N, W, RWORK( INDE ), WORK, N, WORK( INDWK2 ),
283:      $                LLWK2, RWORK( INDWRK ), LLRWK, IWORK, LIWORK,
284:      $                INFO )
285:          CALL CGEMM( 'N', 'N', N, N, N, CONE, Z, LDZ, WORK, N, CZERO,
286:      $               WORK( INDWK2 ), N )
287:          CALL CLACPY( 'A', N, N, WORK( INDWK2 ), N, Z, LDZ )
288:       END IF
289: *
290:       WORK( 1 ) = LWMIN
291:       RWORK( 1 ) = LRWMIN
292:       IWORK( 1 ) = LIWMIN
293:       RETURN
294: *
295: *     End of CHBGVD
296: *
297:       END
298: