001:       SUBROUTINE ZHEGV( ITYPE, JOBZ, UPLO, N, A, LDA, B, LDB, W, WORK,
002:      $                  LWORK, 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, ITYPE, LDA, LDB, LWORK, N
011: *     ..
012: *     .. Array Arguments ..
013:       DOUBLE PRECISION   RWORK( * ), W( * )
014:       COMPLEX*16         A( LDA, * ), B( LDB, * ), WORK( * )
015: *     ..
016: *
017: *  Purpose
018: *  =======
019: *
020: *  ZHEGV computes all the eigenvalues, and optionally, the eigenvectors
021: *  of a complex generalized Hermitian-definite eigenproblem, of the form
022: *  A*x=(lambda)*B*x,  A*Bx=(lambda)*x,  or B*A*x=(lambda)*x.
023: *  Here A and B are assumed to be Hermitian and B is also
024: *  positive definite.
025: *
026: *  Arguments
027: *  =========
028: *
029: *  ITYPE   (input) INTEGER
030: *          Specifies the problem type to be solved:
031: *          = 1:  A*x = (lambda)*B*x
032: *          = 2:  A*B*x = (lambda)*x
033: *          = 3:  B*A*x = (lambda)*x
034: *
035: *  JOBZ    (input) CHARACTER*1
036: *          = 'N':  Compute eigenvalues only;
037: *          = 'V':  Compute eigenvalues and eigenvectors.
038: *
039: *  UPLO    (input) CHARACTER*1
040: *          = 'U':  Upper triangles of A and B are stored;
041: *          = 'L':  Lower triangles of A and B are stored.
042: *
043: *  N       (input) INTEGER
044: *          The order of the matrices A and B.  N >= 0.
045: *
046: *  A       (input/output) COMPLEX*16 array, dimension (LDA, N)
047: *          On entry, the Hermitian matrix A.  If UPLO = 'U', the
048: *          leading N-by-N upper triangular part of A contains the
049: *          upper triangular part of the matrix A.  If UPLO = 'L',
050: *          the leading N-by-N lower triangular part of A contains
051: *          the lower triangular part of the matrix A.
052: *
053: *          On exit, if JOBZ = 'V', then if INFO = 0, A contains the
054: *          matrix Z of eigenvectors.  The eigenvectors are normalized
055: *          as follows:
056: *          if ITYPE = 1 or 2, Z**H*B*Z = I;
057: *          if ITYPE = 3, Z**H*inv(B)*Z = I.
058: *          If JOBZ = 'N', then on exit the upper triangle (if UPLO='U')
059: *          or the lower triangle (if UPLO='L') of A, including the
060: *          diagonal, is destroyed.
061: *
062: *  LDA     (input) INTEGER
063: *          The leading dimension of the array A.  LDA >= max(1,N).
064: *
065: *  B       (input/output) COMPLEX*16 array, dimension (LDB, N)
066: *          On entry, the Hermitian positive definite matrix B.
067: *          If UPLO = 'U', the leading N-by-N upper triangular part of B
068: *          contains the upper triangular part of the matrix B.
069: *          If UPLO = 'L', the leading N-by-N lower triangular part of B
070: *          contains the lower triangular part of the matrix B.
071: *
072: *          On exit, if INFO <= N, the part of B containing the matrix is
073: *          overwritten by the triangular factor U or L from the Cholesky
074: *          factorization B = U**H*U or B = L*L**H.
075: *
076: *  LDB     (input) INTEGER
077: *          The leading dimension of the array B.  LDB >= max(1,N).
078: *
079: *  W       (output) DOUBLE PRECISION array, dimension (N)
080: *          If INFO = 0, the eigenvalues in ascending order.
081: *
082: *  WORK    (workspace/output) COMPLEX*16 array, dimension (MAX(1,LWORK))
083: *          On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
084: *
085: *  LWORK   (input) INTEGER
086: *          The length of the array WORK.  LWORK >= max(1,2*N-1).
087: *          For optimal efficiency, LWORK >= (NB+1)*N,
088: *          where NB is the blocksize for ZHETRD returned by ILAENV.
089: *
090: *          If LWORK = -1, then a workspace query is assumed; the routine
091: *          only calculates the optimal size of the WORK array, returns
092: *          this value as the first entry of the WORK array, and no error
093: *          message related to LWORK is issued by XERBLA.
094: *
095: *  RWORK   (workspace) DOUBLE PRECISION array, dimension (max(1, 3*N-2))
096: *
097: *  INFO    (output) INTEGER
098: *          = 0:  successful exit
099: *          < 0:  if INFO = -i, the i-th argument had an illegal value
100: *          > 0:  ZPOTRF or ZHEEV returned an error code:
101: *             <= N:  if INFO = i, ZHEEV failed to converge;
102: *                    i off-diagonal elements of an intermediate
103: *                    tridiagonal form did not converge to zero;
104: *             > N:   if INFO = N + i, for 1 <= i <= N, then the leading
105: *                    minor of order i of B is not positive definite.
106: *                    The factorization of B could not be completed and
107: *                    no eigenvalues or eigenvectors were computed.
108: *
109: *  =====================================================================
110: *
111: *     .. Parameters ..
112:       COMPLEX*16         ONE
113:       PARAMETER          ( ONE = ( 1.0D+0, 0.0D+0 ) )
114: *     ..
115: *     .. Local Scalars ..
116:       LOGICAL            LQUERY, UPPER, WANTZ
117:       CHARACTER          TRANS
118:       INTEGER            LWKOPT, NB, NEIG
119: *     ..
120: *     .. External Functions ..
121:       LOGICAL            LSAME
122:       INTEGER            ILAENV
123:       EXTERNAL           LSAME, ILAENV
124: *     ..
125: *     .. External Subroutines ..
126:       EXTERNAL           XERBLA, ZHEEV, ZHEGST, ZPOTRF, ZTRMM, ZTRSM
127: *     ..
128: *     .. Intrinsic Functions ..
129:       INTRINSIC          MAX
130: *     ..
131: *     .. Executable Statements ..
132: *
133: *     Test the input parameters.
134: *
135:       WANTZ = LSAME( JOBZ, 'V' )
136:       UPPER = LSAME( UPLO, 'U' )
137:       LQUERY = ( LWORK.EQ.-1 )
138: *
139:       INFO = 0
140:       IF( ITYPE.LT.1 .OR. ITYPE.GT.3 ) THEN
141:          INFO = -1
142:       ELSE IF( .NOT.( WANTZ .OR. LSAME( JOBZ, 'N' ) ) ) THEN
143:          INFO = -2
144:       ELSE IF( .NOT.( UPPER .OR. LSAME( UPLO, 'L' ) ) ) THEN
145:          INFO = -3
146:       ELSE IF( N.LT.0 ) THEN
147:          INFO = -4
148:       ELSE IF( LDA.LT.MAX( 1, N ) ) THEN
149:          INFO = -6
150:       ELSE IF( LDB.LT.MAX( 1, N ) ) THEN
151:          INFO = -8
152:       END IF
153: *
154:       IF( INFO.EQ.0 ) THEN
155:          NB = ILAENV( 1, 'ZHETRD', UPLO, N, -1, -1, -1 )
156:          LWKOPT = MAX( 1, ( NB + 1 )*N )
157:          WORK( 1 ) = LWKOPT
158: *
159:          IF( LWORK.LT.MAX( 1, 2*N - 1 ) .AND. .NOT.LQUERY ) THEN
160:             INFO = -11
161:          END IF
162:       END IF
163: *
164:       IF( INFO.NE.0 ) THEN
165:          CALL XERBLA( 'ZHEGV ', -INFO )
166:          RETURN
167:       ELSE IF( LQUERY ) THEN
168:          RETURN
169:       END IF
170: *
171: *     Quick return if possible
172: *
173:       IF( N.EQ.0 )
174:      $   RETURN
175: *
176: *     Form a Cholesky factorization of B.
177: *
178:       CALL ZPOTRF( UPLO, N, B, LDB, INFO )
179:       IF( INFO.NE.0 ) THEN
180:          INFO = N + INFO
181:          RETURN
182:       END IF
183: *
184: *     Transform problem to standard eigenvalue problem and solve.
185: *
186:       CALL ZHEGST( ITYPE, UPLO, N, A, LDA, B, LDB, INFO )
187:       CALL ZHEEV( JOBZ, UPLO, N, A, LDA, W, WORK, LWORK, RWORK, INFO )
188: *
189:       IF( WANTZ ) THEN
190: *
191: *        Backtransform eigenvectors to the original problem.
192: *
193:          NEIG = N
194:          IF( INFO.GT.0 )
195:      $      NEIG = INFO - 1
196:          IF( ITYPE.EQ.1 .OR. ITYPE.EQ.2 ) THEN
197: *
198: *           For A*x=(lambda)*B*x and A*B*x=(lambda)*x;
199: *           backtransform eigenvectors: x = inv(L)'*y or inv(U)*y
200: *
201:             IF( UPPER ) THEN
202:                TRANS = 'N'
203:             ELSE
204:                TRANS = 'C'
205:             END IF
206: *
207:             CALL ZTRSM( 'Left', UPLO, TRANS, 'Non-unit', N, NEIG, ONE,
208:      $                  B, LDB, A, LDA )
209: *
210:          ELSE IF( ITYPE.EQ.3 ) THEN
211: *
212: *           For B*A*x=(lambda)*x;
213: *           backtransform eigenvectors: x = L*y or U'*y
214: *
215:             IF( UPPER ) THEN
216:                TRANS = 'C'
217:             ELSE
218:                TRANS = 'N'
219:             END IF
220: *
221:             CALL ZTRMM( 'Left', UPLO, TRANS, 'Non-unit', N, NEIG, ONE,
222:      $                  B, LDB, A, LDA )
223:          END IF
224:       END IF
225: *
226:       WORK( 1 ) = LWKOPT
227: *
228:       RETURN
229: *
230: *     End of ZHEGV
231: *
232:       END
233: