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