001:       SUBROUTINE CHBGVX( JOBZ, RANGE, UPLO, N, KA, KB, AB, LDAB, BB,
002:      $                   LDBB, Q, LDQ, VL, VU, IL, IU, ABSTOL, M, W, Z,
003:      $                   LDZ, WORK, RWORK, IWORK, IFAIL, 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, RANGE, UPLO
011:       INTEGER            IL, INFO, IU, KA, KB, LDAB, LDBB, LDQ, LDZ, M,
012:      $                   N
013:       REAL               ABSTOL, VL, VU
014: *     ..
015: *     .. Array Arguments ..
016:       INTEGER            IFAIL( * ), IWORK( * )
017:       REAL               RWORK( * ), W( * )
018:       COMPLEX            AB( LDAB, * ), BB( LDBB, * ), Q( LDQ, * ),
019:      $                   WORK( * ), Z( LDZ, * )
020: *     ..
021: *
022: *  Purpose
023: *  =======
024: *
025: *  CHBGVX computes all the eigenvalues, and optionally, the eigenvectors
026: *  of a complex generalized Hermitian-definite banded eigenproblem, of
027: *  the form A*x=(lambda)*B*x. Here A and B are assumed to be Hermitian
028: *  and banded, and B is also positive definite.  Eigenvalues and
029: *  eigenvectors can be selected by specifying either all eigenvalues,
030: *  a range of values or a range of indices for the desired eigenvalues.
031: *
032: *  Arguments
033: *  =========
034: *
035: *  JOBZ    (input) CHARACTER*1
036: *          = 'N':  Compute eigenvalues only;
037: *          = 'V':  Compute eigenvalues and eigenvectors.
038: *
039: *  RANGE   (input) CHARACTER*1
040: *          = 'A': all eigenvalues will be found;
041: *          = 'V': all eigenvalues in the half-open interval (VL,VU]
042: *                 will be found;
043: *          = 'I': the IL-th through IU-th eigenvalues will be found.
044: *
045: *  UPLO    (input) CHARACTER*1
046: *          = 'U':  Upper triangles of A and B are stored;
047: *          = 'L':  Lower triangles of A and B are stored.
048: *
049: *  N       (input) INTEGER
050: *          The order of the matrices A and B.  N >= 0.
051: *
052: *  KA      (input) INTEGER
053: *          The number of superdiagonals of the matrix A if UPLO = 'U',
054: *          or the number of subdiagonals if UPLO = 'L'. KA >= 0.
055: *
056: *  KB      (input) INTEGER
057: *          The number of superdiagonals of the matrix B if UPLO = 'U',
058: *          or the number of subdiagonals if UPLO = 'L'. KB >= 0.
059: *
060: *  AB      (input/output) COMPLEX array, dimension (LDAB, N)
061: *          On entry, the upper or lower triangle of the Hermitian band
062: *          matrix A, stored in the first ka+1 rows of the array.  The
063: *          j-th column of A is stored in the j-th column of the array AB
064: *          as follows:
065: *          if UPLO = 'U', AB(ka+1+i-j,j) = A(i,j) for max(1,j-ka)<=i<=j;
066: *          if UPLO = 'L', AB(1+i-j,j)    = A(i,j) for j<=i<=min(n,j+ka).
067: *
068: *          On exit, the contents of AB are destroyed.
069: *
070: *  LDAB    (input) INTEGER
071: *          The leading dimension of the array AB.  LDAB >= KA+1.
072: *
073: *  BB      (input/output) COMPLEX array, dimension (LDBB, N)
074: *          On entry, the upper or lower triangle of the Hermitian band
075: *          matrix B, stored in the first kb+1 rows of the array.  The
076: *          j-th column of B is stored in the j-th column of the array BB
077: *          as follows:
078: *          if UPLO = 'U', BB(kb+1+i-j,j) = B(i,j) for max(1,j-kb)<=i<=j;
079: *          if UPLO = 'L', BB(1+i-j,j)    = B(i,j) for j<=i<=min(n,j+kb).
080: *
081: *          On exit, the factor S from the split Cholesky factorization
082: *          B = S**H*S, as returned by CPBSTF.
083: *
084: *  LDBB    (input) INTEGER
085: *          The leading dimension of the array BB.  LDBB >= KB+1.
086: *
087: *  Q       (output) COMPLEX array, dimension (LDQ, N)
088: *          If JOBZ = 'V', the n-by-n matrix used in the reduction of
089: *          A*x = (lambda)*B*x to standard form, i.e. C*x = (lambda)*x,
090: *          and consequently C to tridiagonal form.
091: *          If JOBZ = 'N', the array Q is not referenced.
092: *
093: *  LDQ     (input) INTEGER
094: *          The leading dimension of the array Q.  If JOBZ = 'N',
095: *          LDQ >= 1. If JOBZ = 'V', LDQ >= max(1,N).
096: *
097: *  VL      (input) REAL
098: *  VU      (input) REAL
099: *          If RANGE='V', the lower and upper bounds of the interval to
100: *          be searched for eigenvalues. VL < VU.
101: *          Not referenced if RANGE = 'A' or 'I'.
102: *
103: *  IL      (input) INTEGER
104: *  IU      (input) INTEGER
105: *          If RANGE='I', the indices (in ascending order) of the
106: *          smallest and largest eigenvalues to be returned.
107: *          1 <= IL <= IU <= N, if N > 0; IL = 1 and IU = 0 if N = 0.
108: *          Not referenced if RANGE = 'A' or 'V'.
109: *
110: *  ABSTOL  (input) REAL
111: *          The absolute error tolerance for the eigenvalues.
112: *          An approximate eigenvalue is accepted as converged
113: *          when it is determined to lie in an interval [a,b]
114: *          of width less than or equal to
115: *
116: *                  ABSTOL + EPS *   max( |a|,|b| ) ,
117: *
118: *          where EPS is the machine precision.  If ABSTOL is less than
119: *          or equal to zero, then  EPS*|T|  will be used in its place,
120: *          where |T| is the 1-norm of the tridiagonal matrix obtained
121: *          by reducing AP to tridiagonal form.
122: *
123: *          Eigenvalues will be computed most accurately when ABSTOL is
124: *          set to twice the underflow threshold 2*SLAMCH('S'), not zero.
125: *          If this routine returns with INFO>0, indicating that some
126: *          eigenvectors did not converge, try setting ABSTOL to
127: *          2*SLAMCH('S').
128: *
129: *  M       (output) INTEGER
130: *          The total number of eigenvalues found.  0 <= M <= N.
131: *          If RANGE = 'A', M = N, and if RANGE = 'I', M = IU-IL+1.
132: *
133: *  W       (output) REAL array, dimension (N)
134: *          If INFO = 0, the eigenvalues in ascending order.
135: *
136: *  Z       (output) COMPLEX array, dimension (LDZ, N)
137: *          If JOBZ = 'V', then if INFO = 0, Z contains the matrix Z of
138: *          eigenvectors, with the i-th column of Z holding the
139: *          eigenvector associated with W(i). The eigenvectors are
140: *          normalized so that Z**H*B*Z = I.
141: *          If JOBZ = 'N', then Z is not referenced.
142: *
143: *  LDZ     (input) INTEGER
144: *          The leading dimension of the array Z.  LDZ >= 1, and if
145: *          JOBZ = 'V', LDZ >= N.
146: *
147: *  WORK    (workspace) COMPLEX array, dimension (N)
148: *
149: *  RWORK   (workspace) REAL array, dimension (7*N)
150: *
151: *  IWORK   (workspace) INTEGER array, dimension (5*N)
152: *
153: *  IFAIL   (output) INTEGER array, dimension (N)
154: *          If JOBZ = 'V', then if INFO = 0, the first M elements of
155: *          IFAIL are zero.  If INFO > 0, then IFAIL contains the
156: *          indices of the eigenvectors that failed to converge.
157: *          If JOBZ = 'N', then IFAIL is not referenced.
158: *
159: *  INFO    (output) INTEGER
160: *          = 0:  successful exit
161: *          < 0:  if INFO = -i, the i-th argument had an illegal value
162: *          > 0:  if INFO = i, and i is:
163: *             <= N:  then i eigenvectors failed to converge.  Their
164: *                    indices are stored in array IFAIL.
165: *             > N:   if INFO = N + i, for 1 <= i <= N, then CPBSTF
166: *                    returned INFO = i: B is not positive definite.
167: *                    The factorization of B could not be completed and
168: *                    no eigenvalues or eigenvectors were computed.
169: *
170: *  Further Details
171: *  ===============
172: *
173: *  Based on contributions by
174: *     Mark Fahey, Department of Mathematics, Univ. of Kentucky, USA
175: *
176: *  =====================================================================
177: *
178: *     .. Parameters ..
179:       REAL               ZERO
180:       PARAMETER          ( ZERO = 0.0E+0 )
181:       COMPLEX            CZERO, CONE
182:       PARAMETER          ( CZERO = ( 0.0E+0, 0.0E+0 ),
183:      $                   CONE = ( 1.0E+0, 0.0E+0 ) )
184: *     ..
185: *     .. Local Scalars ..
186:       LOGICAL            ALLEIG, INDEIG, TEST, UPPER, VALEIG, WANTZ
187:       CHARACTER          ORDER, VECT
188:       INTEGER            I, IINFO, INDD, INDE, INDEE, INDIBL, INDISP,
189:      $                   INDIWK, INDRWK, INDWRK, ITMP1, J, JJ, NSPLIT
190:       REAL               TMP1
191: *     ..
192: *     .. External Functions ..
193:       LOGICAL            LSAME
194:       EXTERNAL           LSAME
195: *     ..
196: *     .. External Subroutines ..
197:       EXTERNAL           CCOPY, CGEMV, CHBGST, CHBTRD, CLACPY, CPBSTF,
198:      $                   CSTEIN, CSTEQR, CSWAP, SCOPY, SSTEBZ, SSTERF,
199:      $                   XERBLA
200: *     ..
201: *     .. Intrinsic Functions ..
202:       INTRINSIC          MIN
203: *     ..
204: *     .. Executable Statements ..
205: *
206: *     Test the input parameters.
207: *
208:       WANTZ = LSAME( JOBZ, 'V' )
209:       UPPER = LSAME( UPLO, 'U' )
210:       ALLEIG = LSAME( RANGE, 'A' )
211:       VALEIG = LSAME( RANGE, 'V' )
212:       INDEIG = LSAME( RANGE, 'I' )
213: *
214:       INFO = 0
215:       IF( .NOT.( WANTZ .OR. LSAME( JOBZ, 'N' ) ) ) THEN
216:          INFO = -1
217:       ELSE IF( .NOT.( ALLEIG .OR. VALEIG .OR. INDEIG ) ) THEN
218:          INFO = -2
219:       ELSE IF( .NOT.( UPPER .OR. LSAME( UPLO, 'L' ) ) ) THEN
220:          INFO = -3
221:       ELSE IF( N.LT.0 ) THEN
222:          INFO = -4
223:       ELSE IF( KA.LT.0 ) THEN
224:          INFO = -5
225:       ELSE IF( KB.LT.0 .OR. KB.GT.KA ) THEN
226:          INFO = -6
227:       ELSE IF( LDAB.LT.KA+1 ) THEN
228:          INFO = -8
229:       ELSE IF( LDBB.LT.KB+1 ) THEN
230:          INFO = -10
231:       ELSE IF( LDQ.LT.1 .OR. ( WANTZ .AND. LDQ.LT.N ) ) THEN
232:          INFO = -12
233:       ELSE
234:          IF( VALEIG ) THEN
235:             IF( N.GT.0 .AND. VU.LE.VL )
236:      $         INFO = -14
237:          ELSE IF( INDEIG ) THEN
238:             IF( IL.LT.1 .OR. IL.GT.MAX( 1, N ) ) THEN
239:                INFO = -15
240:             ELSE IF ( IU.LT.MIN( N, IL ) .OR. IU.GT.N ) THEN
241:                INFO = -16
242:             END IF
243:          END IF
244:       END IF
245:       IF( INFO.EQ.0) THEN
246:          IF( LDZ.LT.1 .OR. ( WANTZ .AND. LDZ.LT.N ) ) THEN
247:             INFO = -21
248:          END IF
249:       END IF
250: *
251:       IF( INFO.NE.0 ) THEN
252:          CALL XERBLA( 'CHBGVX', -INFO )
253:          RETURN
254:       END IF
255: *
256: *     Quick return if possible
257: *
258:       M = 0
259:       IF( N.EQ.0 )
260:      $   RETURN
261: *
262: *     Form a split Cholesky factorization of B.
263: *
264:       CALL CPBSTF( UPLO, N, KB, BB, LDBB, INFO )
265:       IF( INFO.NE.0 ) THEN
266:          INFO = N + INFO
267:          RETURN
268:       END IF
269: *
270: *     Transform problem to standard eigenvalue problem.
271: *
272:       CALL CHBGST( JOBZ, UPLO, N, KA, KB, AB, LDAB, BB, LDBB, Q, LDQ,
273:      $             WORK, RWORK, IINFO )
274: *
275: *     Solve the standard eigenvalue problem.
276: *     Reduce Hermitian band matrix to tridiagonal form.
277: *
278:       INDD = 1
279:       INDE = INDD + N
280:       INDRWK = INDE + N
281:       INDWRK = 1
282:       IF( WANTZ ) THEN
283:          VECT = 'U'
284:       ELSE
285:          VECT = 'N'
286:       END IF
287:       CALL CHBTRD( VECT, UPLO, N, KA, AB, LDAB, RWORK( INDD ),
288:      $             RWORK( INDE ), Q, LDQ, WORK( INDWRK ), IINFO )
289: *
290: *     If all eigenvalues are desired and ABSTOL is less than or equal
291: *     to zero, then call SSTERF or CSTEQR.  If this fails for some
292: *     eigenvalue, then try SSTEBZ.
293: *
294:       TEST = .FALSE.
295:       IF( INDEIG ) THEN
296:          IF( IL.EQ.1 .AND. IU.EQ.N ) THEN
297:             TEST = .TRUE.
298:          END IF
299:       END IF
300:       IF( ( ALLEIG .OR. TEST ) .AND. ( ABSTOL.LE.ZERO ) ) THEN
301:          CALL SCOPY( N, RWORK( INDD ), 1, W, 1 )
302:          INDEE = INDRWK + 2*N
303:          CALL SCOPY( N-1, RWORK( INDE ), 1, RWORK( INDEE ), 1 )
304:          IF( .NOT.WANTZ ) THEN
305:             CALL SSTERF( N, W, RWORK( INDEE ), INFO )
306:          ELSE
307:             CALL CLACPY( 'A', N, N, Q, LDQ, Z, LDZ )
308:             CALL CSTEQR( JOBZ, N, W, RWORK( INDEE ), Z, LDZ,
309:      $                   RWORK( INDRWK ), INFO )
310:             IF( INFO.EQ.0 ) THEN
311:                DO 10 I = 1, N
312:                   IFAIL( I ) = 0
313:    10          CONTINUE
314:             END IF
315:          END IF
316:          IF( INFO.EQ.0 ) THEN
317:             M = N
318:             GO TO 30
319:          END IF
320:          INFO = 0
321:       END IF
322: *
323: *     Otherwise, call SSTEBZ and, if eigenvectors are desired,
324: *     call CSTEIN.
325: *
326:       IF( WANTZ ) THEN
327:          ORDER = 'B'
328:       ELSE
329:          ORDER = 'E'
330:       END IF
331:       INDIBL = 1
332:       INDISP = INDIBL + N
333:       INDIWK = INDISP + N
334:       CALL SSTEBZ( RANGE, ORDER, N, VL, VU, IL, IU, ABSTOL,
335:      $             RWORK( INDD ), RWORK( INDE ), M, NSPLIT, W,
336:      $             IWORK( INDIBL ), IWORK( INDISP ), RWORK( INDRWK ),
337:      $             IWORK( INDIWK ), INFO )
338: *
339:       IF( WANTZ ) THEN
340:          CALL CSTEIN( N, RWORK( INDD ), RWORK( INDE ), M, W,
341:      $                IWORK( INDIBL ), IWORK( INDISP ), Z, LDZ,
342:      $                RWORK( INDRWK ), IWORK( INDIWK ), IFAIL, INFO )
343: *
344: *        Apply unitary matrix used in reduction to tridiagonal
345: *        form to eigenvectors returned by CSTEIN.
346: *
347:          DO 20 J = 1, M
348:             CALL CCOPY( N, Z( 1, J ), 1, WORK( 1 ), 1 )
349:             CALL CGEMV( 'N', N, N, CONE, Q, LDQ, WORK, 1, CZERO,
350:      $                  Z( 1, J ), 1 )
351:    20    CONTINUE
352:       END IF
353: *
354:    30 CONTINUE
355: *
356: *     If eigenvalues are not in order, then sort them, along with
357: *     eigenvectors.
358: *
359:       IF( WANTZ ) THEN
360:          DO 50 J = 1, M - 1
361:             I = 0
362:             TMP1 = W( J )
363:             DO 40 JJ = J + 1, M
364:                IF( W( JJ ).LT.TMP1 ) THEN
365:                   I = JJ
366:                   TMP1 = W( JJ )
367:                END IF
368:    40       CONTINUE
369: *
370:             IF( I.NE.0 ) THEN
371:                ITMP1 = IWORK( INDIBL+I-1 )
372:                W( I ) = W( J )
373:                IWORK( INDIBL+I-1 ) = IWORK( INDIBL+J-1 )
374:                W( J ) = TMP1
375:                IWORK( INDIBL+J-1 ) = ITMP1
376:                CALL CSWAP( N, Z( 1, I ), 1, Z( 1, J ), 1 )
377:                IF( INFO.NE.0 ) THEN
378:                   ITMP1 = IFAIL( I )
379:                   IFAIL( I ) = IFAIL( J )
380:                   IFAIL( J ) = ITMP1
381:                END IF
382:             END IF
383:    50    CONTINUE
384:       END IF
385: *
386:       RETURN
387: *
388: *     End of CHBGVX
389: *
390:       END
391: