001:       SUBROUTINE ZHPGV( ITYPE, JOBZ, UPLO, N, AP, BP, W, Z, LDZ, WORK,
002:      $                  RWORK, INFO )
003: *
004: *  -- LAPACK driver routine (version 3.2) --
005: *  -- LAPACK is a software package provided by Univ. of Tennessee,    --
006: *  -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
007: *     November 2006
008: *
009: *     .. Scalar Arguments ..
010:       CHARACTER          JOBZ, UPLO
011:       INTEGER            INFO, ITYPE, LDZ, N
012: *     ..
013: *     .. Array Arguments ..
014:       DOUBLE PRECISION   RWORK( * ), W( * )
015:       COMPLEX*16         AP( * ), BP( * ), WORK( * ), Z( LDZ, * )
016: *     ..
017: *
018: *  Purpose
019: *  =======
020: *
021: *  ZHPGV computes all the eigenvalues and, optionally, the eigenvectors
022: *  of a complex generalized Hermitian-definite eigenproblem, of the form
023: *  A*x=(lambda)*B*x,  A*Bx=(lambda)*x,  or B*A*x=(lambda)*x.
024: *  Here A and B are assumed to be Hermitian, stored in packed format,
025: *  and B is also positive definite.
026: *
027: *  Arguments
028: *  =========
029: *
030: *  ITYPE   (input) INTEGER
031: *          Specifies the problem type to be solved:
032: *          = 1:  A*x = (lambda)*B*x
033: *          = 2:  A*B*x = (lambda)*x
034: *          = 3:  B*A*x = (lambda)*x
035: *
036: *  JOBZ    (input) CHARACTER*1
037: *          = 'N':  Compute eigenvalues only;
038: *          = 'V':  Compute eigenvalues and eigenvectors.
039: *
040: *  UPLO    (input) CHARACTER*1
041: *          = 'U':  Upper triangles of A and B are stored;
042: *          = 'L':  Lower triangles of A and B are stored.
043: *
044: *  N       (input) INTEGER
045: *          The order of the matrices A and B.  N >= 0.
046: *
047: *  AP      (input/output) COMPLEX*16 array, dimension (N*(N+1)/2)
048: *          On entry, the upper or lower triangle of the Hermitian matrix
049: *          A, packed columnwise in a linear array.  The j-th column of A
050: *          is stored in the array AP as follows:
051: *          if UPLO = 'U', AP(i + (j-1)*j/2) = A(i,j) for 1<=i<=j;
052: *          if UPLO = 'L', AP(i + (j-1)*(2*n-j)/2) = A(i,j) for j<=i<=n.
053: *
054: *          On exit, the contents of AP are destroyed.
055: *
056: *  BP      (input/output) COMPLEX*16 array, dimension (N*(N+1)/2)
057: *          On entry, the upper or lower triangle of the Hermitian matrix
058: *          B, packed columnwise in a linear array.  The j-th column of B
059: *          is stored in the array BP as follows:
060: *          if UPLO = 'U', BP(i + (j-1)*j/2) = B(i,j) for 1<=i<=j;
061: *          if UPLO = 'L', BP(i + (j-1)*(2*n-j)/2) = B(i,j) for j<=i<=n.
062: *
063: *          On exit, the triangular factor U or L from the Cholesky
064: *          factorization B = U**H*U or B = L*L**H, in the same storage
065: *          format as B.
066: *
067: *  W       (output) DOUBLE PRECISION array, dimension (N)
068: *          If INFO = 0, the eigenvalues in ascending order.
069: *
070: *  Z       (output) COMPLEX*16 array, dimension (LDZ, N)
071: *          If JOBZ = 'V', then if INFO = 0, Z contains the matrix Z of
072: *          eigenvectors.  The eigenvectors are normalized as follows:
073: *          if ITYPE = 1 or 2, Z**H*B*Z = I;
074: *          if ITYPE = 3, Z**H*inv(B)*Z = I.
075: *          If JOBZ = 'N', then Z is not referenced.
076: *
077: *  LDZ     (input) INTEGER
078: *          The leading dimension of the array Z.  LDZ >= 1, and if
079: *          JOBZ = 'V', LDZ >= max(1,N).
080: *
081: *  WORK    (workspace) COMPLEX*16 array, dimension (max(1, 2*N-1))
082: *
083: *  RWORK   (workspace) DOUBLE PRECISION array, dimension (max(1, 3*N-2))
084: *
085: *  INFO    (output) INTEGER
086: *          = 0:  successful exit
087: *          < 0:  if INFO = -i, the i-th argument had an illegal value
088: *          > 0:  ZPPTRF or ZHPEV returned an error code:
089: *             <= N:  if INFO = i, ZHPEV failed to converge;
090: *                    i off-diagonal elements of an intermediate
091: *                    tridiagonal form did not convergeto zero;
092: *             > N:   if INFO = N + i, for 1 <= i <= n, then the leading
093: *                    minor of order i of B is not positive definite.
094: *                    The factorization of B could not be completed and
095: *                    no eigenvalues or eigenvectors were computed.
096: *
097: *  =====================================================================
098: *
099: *     .. Local Scalars ..
100:       LOGICAL            UPPER, WANTZ
101:       CHARACTER          TRANS
102:       INTEGER            J, NEIG
103: *     ..
104: *     .. External Functions ..
105:       LOGICAL            LSAME
106:       EXTERNAL           LSAME
107: *     ..
108: *     .. External Subroutines ..
109:       EXTERNAL           XERBLA, ZHPEV, ZHPGST, ZPPTRF, ZTPMV, ZTPSV
110: *     ..
111: *     .. Executable Statements ..
112: *
113: *     Test the input parameters.
114: *
115:       WANTZ = LSAME( JOBZ, 'V' )
116:       UPPER = LSAME( UPLO, 'U' )
117: *
118:       INFO = 0
119:       IF( ITYPE.LT.1 .OR. ITYPE.GT.3 ) THEN
120:          INFO = -1
121:       ELSE IF( .NOT.( WANTZ .OR. LSAME( JOBZ, 'N' ) ) ) THEN
122:          INFO = -2
123:       ELSE IF( .NOT.( UPPER .OR. LSAME( UPLO, 'L' ) ) ) THEN
124:          INFO = -3
125:       ELSE IF( N.LT.0 ) THEN
126:          INFO = -4
127:       ELSE IF( LDZ.LT.1 .OR. ( WANTZ .AND. LDZ.LT.N ) ) THEN
128:          INFO = -9
129:       END IF
130:       IF( INFO.NE.0 ) THEN
131:          CALL XERBLA( 'ZHPGV ', -INFO )
132:          RETURN
133:       END IF
134: *
135: *     Quick return if possible
136: *
137:       IF( N.EQ.0 )
138:      $   RETURN
139: *
140: *     Form a Cholesky factorization of B.
141: *
142:       CALL ZPPTRF( UPLO, N, BP, INFO )
143:       IF( INFO.NE.0 ) THEN
144:          INFO = N + INFO
145:          RETURN
146:       END IF
147: *
148: *     Transform problem to standard eigenvalue problem and solve.
149: *
150:       CALL ZHPGST( ITYPE, UPLO, N, AP, BP, INFO )
151:       CALL ZHPEV( JOBZ, UPLO, N, AP, W, Z, LDZ, WORK, RWORK, INFO )
152: *
153:       IF( WANTZ ) THEN
154: *
155: *        Backtransform eigenvectors to the original problem.
156: *
157:          NEIG = N
158:          IF( INFO.GT.0 )
159:      $      NEIG = INFO - 1
160:          IF( ITYPE.EQ.1 .OR. ITYPE.EQ.2 ) THEN
161: *
162: *           For A*x=(lambda)*B*x and A*B*x=(lambda)*x;
163: *           backtransform eigenvectors: x = inv(L)'*y or inv(U)*y
164: *
165:             IF( UPPER ) THEN
166:                TRANS = 'N'
167:             ELSE
168:                TRANS = 'C'
169:             END IF
170: *
171:             DO 10 J = 1, NEIG
172:                CALL ZTPSV( UPLO, TRANS, 'Non-unit', N, BP, Z( 1, J ),
173:      $                     1 )
174:    10       CONTINUE
175: *
176:          ELSE IF( ITYPE.EQ.3 ) THEN
177: *
178: *           For B*A*x=(lambda)*x;
179: *           backtransform eigenvectors: x = L*y or U'*y
180: *
181:             IF( UPPER ) THEN
182:                TRANS = 'C'
183:             ELSE
184:                TRANS = 'N'
185:             END IF
186: *
187:             DO 20 J = 1, NEIG
188:                CALL ZTPMV( UPLO, TRANS, 'Non-unit', N, BP, Z( 1, J ),
189:      $                     1 )
190:    20       CONTINUE
191:          END IF
192:       END IF
193:       RETURN
194: *
195: *     End of ZHPGV
196: *
197:       END
198: