001:       SUBROUTINE ZHBEVX( JOBZ, RANGE, UPLO, N, KD, AB, LDAB, Q, LDQ, VL,
002:      $                   VU, IL, IU, ABSTOL, M, W, Z, LDZ, WORK, RWORK,
003:      $                   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, KD, LDAB, LDQ, LDZ, M, N
012:       DOUBLE PRECISION   ABSTOL, VL, VU
013: *     ..
014: *     .. Array Arguments ..
015:       INTEGER            IFAIL( * ), IWORK( * )
016:       DOUBLE PRECISION   RWORK( * ), W( * )
017:       COMPLEX*16         AB( LDAB, * ), Q( LDQ, * ), WORK( * ),
018:      $                   Z( LDZ, * )
019: *     ..
020: *
021: *  Purpose
022: *  =======
023: *
024: *  ZHBEVX computes selected eigenvalues and, optionally, eigenvectors
025: *  of a complex Hermitian band matrix A.  Eigenvalues and eigenvectors
026: *  can be selected by specifying either a range of values or a range of
027: *  indices for the desired eigenvalues.
028: *
029: *  Arguments
030: *  =========
031: *
032: *  JOBZ    (input) CHARACTER*1
033: *          = 'N':  Compute eigenvalues only;
034: *          = 'V':  Compute eigenvalues and eigenvectors.
035: *
036: *  RANGE   (input) CHARACTER*1
037: *          = 'A': all eigenvalues will be found;
038: *          = 'V': all eigenvalues in the half-open interval (VL,VU]
039: *                 will be found;
040: *          = 'I': the IL-th through IU-th eigenvalues will be found.
041: *
042: *  UPLO    (input) CHARACTER*1
043: *          = 'U':  Upper triangle of A is stored;
044: *          = 'L':  Lower triangle of A is stored.
045: *
046: *  N       (input) INTEGER
047: *          The order of the matrix A.  N >= 0.
048: *
049: *  KD      (input) INTEGER
050: *          The number of superdiagonals of the matrix A if UPLO = 'U',
051: *          or the number of subdiagonals if UPLO = 'L'.  KD >= 0.
052: *
053: *  AB      (input/output) COMPLEX*16 array, dimension (LDAB, N)
054: *          On entry, the upper or lower triangle of the Hermitian band
055: *          matrix A, stored in the first KD+1 rows of the array.  The
056: *          j-th column of A is stored in the j-th column of the array AB
057: *          as follows:
058: *          if UPLO = 'U', AB(kd+1+i-j,j) = A(i,j) for max(1,j-kd)<=i<=j;
059: *          if UPLO = 'L', AB(1+i-j,j)    = A(i,j) for j<=i<=min(n,j+kd).
060: *
061: *          On exit, AB is overwritten by values generated during the
062: *          reduction to tridiagonal form.
063: *
064: *  LDAB    (input) INTEGER
065: *          The leading dimension of the array AB.  LDAB >= KD + 1.
066: *
067: *  Q       (output) COMPLEX*16 array, dimension (LDQ, N)
068: *          If JOBZ = 'V', the N-by-N unitary matrix used in the
069: *                          reduction to tridiagonal form.
070: *          If JOBZ = 'N', the array Q is not referenced.
071: *
072: *  LDQ     (input) INTEGER
073: *          The leading dimension of the array Q.  If JOBZ = 'V', then
074: *          LDQ >= max(1,N).
075: *
076: *  VL      (input) DOUBLE PRECISION
077: *  VU      (input) DOUBLE PRECISION
078: *          If RANGE='V', the lower and upper bounds of the interval to
079: *          be searched for eigenvalues. VL < VU.
080: *          Not referenced if RANGE = 'A' or 'I'.
081: *
082: *  IL      (input) INTEGER
083: *  IU      (input) INTEGER
084: *          If RANGE='I', the indices (in ascending order) of the
085: *          smallest and largest eigenvalues to be returned.
086: *          1 <= IL <= IU <= N, if N > 0; IL = 1 and IU = 0 if N = 0.
087: *          Not referenced if RANGE = 'A' or 'V'.
088: *
089: *  ABSTOL  (input) DOUBLE PRECISION
090: *          The absolute error tolerance for the eigenvalues.
091: *          An approximate eigenvalue is accepted as converged
092: *          when it is determined to lie in an interval [a,b]
093: *          of width less than or equal to
094: *
095: *                  ABSTOL + EPS *   max( |a|,|b| ) ,
096: *
097: *          where EPS is the machine precision.  If ABSTOL is less than
098: *          or equal to zero, then  EPS*|T|  will be used in its place,
099: *          where |T| is the 1-norm of the tridiagonal matrix obtained
100: *          by reducing AB to tridiagonal form.
101: *
102: *          Eigenvalues will be computed most accurately when ABSTOL is
103: *          set to twice the underflow threshold 2*DLAMCH('S'), not zero.
104: *          If this routine returns with INFO>0, indicating that some
105: *          eigenvectors did not converge, try setting ABSTOL to
106: *          2*DLAMCH('S').
107: *
108: *          See "Computing Small Singular Values of Bidiagonal Matrices
109: *          with Guaranteed High Relative Accuracy," by Demmel and
110: *          Kahan, LAPACK Working Note #3.
111: *
112: *  M       (output) INTEGER
113: *          The total number of eigenvalues found.  0 <= M <= N.
114: *          If RANGE = 'A', M = N, and if RANGE = 'I', M = IU-IL+1.
115: *
116: *  W       (output) DOUBLE PRECISION array, dimension (N)
117: *          The first M elements contain the selected eigenvalues in
118: *          ascending order.
119: *
120: *  Z       (output) COMPLEX*16 array, dimension (LDZ, max(1,M))
121: *          If JOBZ = 'V', then if INFO = 0, the first M columns of Z
122: *          contain the orthonormal eigenvectors of the matrix A
123: *          corresponding to the selected eigenvalues, with the i-th
124: *          column of Z holding the eigenvector associated with W(i).
125: *          If an eigenvector fails to converge, then that column of Z
126: *          contains the latest approximation to the eigenvector, and the
127: *          index of the eigenvector is returned in IFAIL.
128: *          If JOBZ = 'N', then Z is not referenced.
129: *          Note: the user must ensure that at least max(1,M) columns are
130: *          supplied in the array Z; if RANGE = 'V', the exact value of M
131: *          is not known in advance and an upper bound must be used.
132: *
133: *  LDZ     (input) INTEGER
134: *          The leading dimension of the array Z.  LDZ >= 1, and if
135: *          JOBZ = 'V', LDZ >= max(1,N).
136: *
137: *  WORK    (workspace) COMPLEX*16 array, dimension (N)
138: *
139: *  RWORK   (workspace) DOUBLE PRECISION array, dimension (7*N)
140: *
141: *  IWORK   (workspace) INTEGER array, dimension (5*N)
142: *
143: *  IFAIL   (output) INTEGER array, dimension (N)
144: *          If JOBZ = 'V', then if INFO = 0, the first M elements of
145: *          IFAIL are zero.  If INFO > 0, then IFAIL contains the
146: *          indices of the eigenvectors that failed to converge.
147: *          If JOBZ = 'N', then IFAIL is not referenced.
148: *
149: *  INFO    (output) INTEGER
150: *          = 0:  successful exit
151: *          < 0:  if INFO = -i, the i-th argument had an illegal value
152: *          > 0:  if INFO = i, then i eigenvectors failed to converge.
153: *                Their indices are stored in array IFAIL.
154: *
155: *  =====================================================================
156: *
157: *     .. Parameters ..
158:       DOUBLE PRECISION   ZERO, ONE
159:       PARAMETER          ( ZERO = 0.0D0, ONE = 1.0D0 )
160:       COMPLEX*16         CZERO, CONE
161:       PARAMETER          ( CZERO = ( 0.0D0, 0.0D0 ),
162:      $                   CONE = ( 1.0D0, 0.0D0 ) )
163: *     ..
164: *     .. Local Scalars ..
165:       LOGICAL            ALLEIG, INDEIG, LOWER, TEST, VALEIG, WANTZ
166:       CHARACTER          ORDER
167:       INTEGER            I, IINFO, IMAX, INDD, INDE, INDEE, INDIBL,
168:      $                   INDISP, INDIWK, INDRWK, INDWRK, ISCALE, ITMP1,
169:      $                   J, JJ, NSPLIT
170:       DOUBLE PRECISION   ABSTLL, ANRM, BIGNUM, EPS, RMAX, RMIN, SAFMIN,
171:      $                   SIGMA, SMLNUM, TMP1, VLL, VUU
172:       COMPLEX*16         CTMP1
173: *     ..
174: *     .. External Functions ..
175:       LOGICAL            LSAME
176:       DOUBLE PRECISION   DLAMCH, ZLANHB
177:       EXTERNAL           LSAME, DLAMCH, ZLANHB
178: *     ..
179: *     .. External Subroutines ..
180:       EXTERNAL           DCOPY, DSCAL, DSTEBZ, DSTERF, XERBLA, ZCOPY,
181:      $                   ZGEMV, ZHBTRD, ZLACPY, ZLASCL, ZSTEIN, ZSTEQR,
182:      $                   ZSWAP
183: *     ..
184: *     .. Intrinsic Functions ..
185:       INTRINSIC          DBLE, MAX, MIN, SQRT
186: *     ..
187: *     .. Executable Statements ..
188: *
189: *     Test the input parameters.
190: *
191:       WANTZ = LSAME( JOBZ, 'V' )
192:       ALLEIG = LSAME( RANGE, 'A' )
193:       VALEIG = LSAME( RANGE, 'V' )
194:       INDEIG = LSAME( RANGE, 'I' )
195:       LOWER = LSAME( UPLO, 'L' )
196: *
197:       INFO = 0
198:       IF( .NOT.( WANTZ .OR. LSAME( JOBZ, 'N' ) ) ) THEN
199:          INFO = -1
200:       ELSE IF( .NOT.( ALLEIG .OR. VALEIG .OR. INDEIG ) ) THEN
201:          INFO = -2
202:       ELSE IF( .NOT.( LOWER .OR. LSAME( UPLO, 'U' ) ) ) THEN
203:          INFO = -3
204:       ELSE IF( N.LT.0 ) THEN
205:          INFO = -4
206:       ELSE IF( KD.LT.0 ) THEN
207:          INFO = -5
208:       ELSE IF( LDAB.LT.KD+1 ) THEN
209:          INFO = -7
210:       ELSE IF( WANTZ .AND. LDQ.LT.MAX( 1, N ) ) THEN
211:          INFO = -9
212:       ELSE
213:          IF( VALEIG ) THEN
214:             IF( N.GT.0 .AND. VU.LE.VL )
215:      $         INFO = -11
216:          ELSE IF( INDEIG ) THEN
217:             IF( IL.LT.1 .OR. IL.GT.MAX( 1, N ) ) THEN
218:                INFO = -12
219:             ELSE IF( IU.LT.MIN( N, IL ) .OR. IU.GT.N ) THEN
220:                INFO = -13
221:             END IF
222:          END IF
223:       END IF
224:       IF( INFO.EQ.0 ) THEN
225:          IF( LDZ.LT.1 .OR. ( WANTZ .AND. LDZ.LT.N ) )
226:      $      INFO = -18
227:       END IF
228: *
229:       IF( INFO.NE.0 ) THEN
230:          CALL XERBLA( 'ZHBEVX', -INFO )
231:          RETURN
232:       END IF
233: *
234: *     Quick return if possible
235: *
236:       M = 0
237:       IF( N.EQ.0 )
238:      $   RETURN
239: *
240:       IF( N.EQ.1 ) THEN
241:          M = 1
242:          IF( LOWER ) THEN
243:             CTMP1 = AB( 1, 1 )
244:          ELSE
245:             CTMP1 = AB( KD+1, 1 )
246:          END IF
247:          TMP1 = DBLE( CTMP1 )
248:          IF( VALEIG ) THEN
249:             IF( .NOT.( VL.LT.TMP1 .AND. VU.GE.TMP1 ) )
250:      $         M = 0
251:          END IF
252:          IF( M.EQ.1 ) THEN
253:             W( 1 ) = CTMP1
254:             IF( WANTZ )
255:      $         Z( 1, 1 ) = CONE
256:          END IF
257:          RETURN
258:       END IF
259: *
260: *     Get machine constants.
261: *
262:       SAFMIN = DLAMCH( 'Safe minimum' )
263:       EPS = DLAMCH( 'Precision' )
264:       SMLNUM = SAFMIN / EPS
265:       BIGNUM = ONE / SMLNUM
266:       RMIN = SQRT( SMLNUM )
267:       RMAX = MIN( SQRT( BIGNUM ), ONE / SQRT( SQRT( SAFMIN ) ) )
268: *
269: *     Scale matrix to allowable range, if necessary.
270: *
271:       ISCALE = 0
272:       ABSTLL = ABSTOL
273:       IF( VALEIG ) THEN
274:          VLL = VL
275:          VUU = VU
276:       ELSE
277:          VLL = ZERO
278:          VUU = ZERO
279:       END IF
280:       ANRM = ZLANHB( 'M', UPLO, N, KD, AB, LDAB, RWORK )
281:       IF( ANRM.GT.ZERO .AND. ANRM.LT.RMIN ) THEN
282:          ISCALE = 1
283:          SIGMA = RMIN / ANRM
284:       ELSE IF( ANRM.GT.RMAX ) THEN
285:          ISCALE = 1
286:          SIGMA = RMAX / ANRM
287:       END IF
288:       IF( ISCALE.EQ.1 ) THEN
289:          IF( LOWER ) THEN
290:             CALL ZLASCL( 'B', KD, KD, ONE, SIGMA, N, N, AB, LDAB, INFO )
291:          ELSE
292:             CALL ZLASCL( 'Q', KD, KD, ONE, SIGMA, N, N, AB, LDAB, INFO )
293:          END IF
294:          IF( ABSTOL.GT.0 )
295:      $      ABSTLL = ABSTOL*SIGMA
296:          IF( VALEIG ) THEN
297:             VLL = VL*SIGMA
298:             VUU = VU*SIGMA
299:          END IF
300:       END IF
301: *
302: *     Call ZHBTRD to reduce Hermitian band matrix to tridiagonal form.
303: *
304:       INDD = 1
305:       INDE = INDD + N
306:       INDRWK = INDE + N
307:       INDWRK = 1
308:       CALL ZHBTRD( JOBZ, UPLO, N, KD, AB, LDAB, RWORK( INDD ),
309:      $             RWORK( INDE ), Q, LDQ, WORK( INDWRK ), IINFO )
310: *
311: *     If all eigenvalues are desired and ABSTOL is less than or equal
312: *     to zero, then call DSTERF or ZSTEQR.  If this fails for some
313: *     eigenvalue, then try DSTEBZ.
314: *
315:       TEST = .FALSE.
316:       IF (INDEIG) THEN
317:          IF (IL.EQ.1 .AND. IU.EQ.N) THEN
318:             TEST = .TRUE.
319:          END IF
320:       END IF
321:       IF ((ALLEIG .OR. TEST) .AND. (ABSTOL.LE.ZERO)) THEN
322:          CALL DCOPY( N, RWORK( INDD ), 1, W, 1 )
323:          INDEE = INDRWK + 2*N
324:          IF( .NOT.WANTZ ) THEN
325:             CALL DCOPY( N-1, RWORK( INDE ), 1, RWORK( INDEE ), 1 )
326:             CALL DSTERF( N, W, RWORK( INDEE ), INFO )
327:          ELSE
328:             CALL ZLACPY( 'A', N, N, Q, LDQ, Z, LDZ )
329:             CALL DCOPY( N-1, RWORK( INDE ), 1, RWORK( INDEE ), 1 )
330:             CALL ZSTEQR( JOBZ, N, W, RWORK( INDEE ), Z, LDZ,
331:      $                   RWORK( INDRWK ), INFO )
332:             IF( INFO.EQ.0 ) THEN
333:                DO 10 I = 1, N
334:                   IFAIL( I ) = 0
335:    10          CONTINUE
336:             END IF
337:          END IF
338:          IF( INFO.EQ.0 ) THEN
339:             M = N
340:             GO TO 30
341:          END IF
342:          INFO = 0
343:       END IF
344: *
345: *     Otherwise, call DSTEBZ and, if eigenvectors are desired, ZSTEIN.
346: *
347:       IF( WANTZ ) THEN
348:          ORDER = 'B'
349:       ELSE
350:          ORDER = 'E'
351:       END IF
352:       INDIBL = 1
353:       INDISP = INDIBL + N
354:       INDIWK = INDISP + N
355:       CALL DSTEBZ( RANGE, ORDER, N, VLL, VUU, IL, IU, ABSTLL,
356:      $             RWORK( INDD ), RWORK( INDE ), M, NSPLIT, W,
357:      $             IWORK( INDIBL ), IWORK( INDISP ), RWORK( INDRWK ),
358:      $             IWORK( INDIWK ), INFO )
359: *
360:       IF( WANTZ ) THEN
361:          CALL ZSTEIN( N, RWORK( INDD ), RWORK( INDE ), M, W,
362:      $                IWORK( INDIBL ), IWORK( INDISP ), Z, LDZ,
363:      $                RWORK( INDRWK ), IWORK( INDIWK ), IFAIL, INFO )
364: *
365: *        Apply unitary matrix used in reduction to tridiagonal
366: *        form to eigenvectors returned by ZSTEIN.
367: *
368:          DO 20 J = 1, M
369:             CALL ZCOPY( N, Z( 1, J ), 1, WORK( 1 ), 1 )
370:             CALL ZGEMV( 'N', N, N, CONE, Q, LDQ, WORK, 1, CZERO,
371:      $                  Z( 1, J ), 1 )
372:    20    CONTINUE
373:       END IF
374: *
375: *     If matrix was scaled, then rescale eigenvalues appropriately.
376: *
377:    30 CONTINUE
378:       IF( ISCALE.EQ.1 ) THEN
379:          IF( INFO.EQ.0 ) THEN
380:             IMAX = M
381:          ELSE
382:             IMAX = INFO - 1
383:          END IF
384:          CALL DSCAL( IMAX, ONE / SIGMA, W, 1 )
385:       END IF
386: *
387: *     If eigenvalues are not in order, then sort them, along with
388: *     eigenvectors.
389: *
390:       IF( WANTZ ) THEN
391:          DO 50 J = 1, M - 1
392:             I = 0
393:             TMP1 = W( J )
394:             DO 40 JJ = J + 1, M
395:                IF( W( JJ ).LT.TMP1 ) THEN
396:                   I = JJ
397:                   TMP1 = W( JJ )
398:                END IF
399:    40       CONTINUE
400: *
401:             IF( I.NE.0 ) THEN
402:                ITMP1 = IWORK( INDIBL+I-1 )
403:                W( I ) = W( J )
404:                IWORK( INDIBL+I-1 ) = IWORK( INDIBL+J-1 )
405:                W( J ) = TMP1
406:                IWORK( INDIBL+J-1 ) = ITMP1
407:                CALL ZSWAP( N, Z( 1, I ), 1, Z( 1, J ), 1 )
408:                IF( INFO.NE.0 ) THEN
409:                   ITMP1 = IFAIL( I )
410:                   IFAIL( I ) = IFAIL( J )
411:                   IFAIL( J ) = ITMP1
412:                END IF
413:             END IF
414:    50    CONTINUE
415:       END IF
416: *
417:       RETURN
418: *
419: *     End of ZHBEVX
420: *
421:       END
422: