001:       SUBROUTINE CHPGV( ITYPE, JOBZ, UPLO, N, AP, BP, W, Z, LDZ, WORK,
002:      $                  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, LDZ, N
011: *     ..
012: *     .. Array Arguments ..
013:       REAL               RWORK( * ), W( * )
014:       COMPLEX            AP( * ), BP( * ), WORK( * ), Z( LDZ, * )
015: *     ..
016: *
017: *  Purpose
018: *  =======
019: *
020: *  CHPGV 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, stored in packed format,
024: *  and B is also 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: *  AP      (input/output) COMPLEX array, dimension (N*(N+1)/2)
047: *          On entry, the upper or lower triangle of the Hermitian matrix
048: *          A, packed columnwise in a linear array.  The j-th column of A
049: *          is stored in the array AP as follows:
050: *          if UPLO = 'U', AP(i + (j-1)*j/2) = A(i,j) for 1<=i<=j;
051: *          if UPLO = 'L', AP(i + (j-1)*(2*n-j)/2) = A(i,j) for j<=i<=n.
052: *
053: *          On exit, the contents of AP are destroyed.
054: *
055: *  BP      (input/output) COMPLEX array, dimension (N*(N+1)/2)
056: *          On entry, the upper or lower triangle of the Hermitian matrix
057: *          B, packed columnwise in a linear array.  The j-th column of B
058: *          is stored in the array BP as follows:
059: *          if UPLO = 'U', BP(i + (j-1)*j/2) = B(i,j) for 1<=i<=j;
060: *          if UPLO = 'L', BP(i + (j-1)*(2*n-j)/2) = B(i,j) for j<=i<=n.
061: *
062: *          On exit, the triangular factor U or L from the Cholesky
063: *          factorization B = U**H*U or B = L*L**H, in the same storage
064: *          format as B.
065: *
066: *  W       (output) REAL array, dimension (N)
067: *          If INFO = 0, the eigenvalues in ascending order.
068: *
069: *  Z       (output) COMPLEX array, dimension (LDZ, N)
070: *          If JOBZ = 'V', then if INFO = 0, Z contains the matrix Z of
071: *          eigenvectors.  The eigenvectors are normalized as follows:
072: *          if ITYPE = 1 or 2, Z**H*B*Z = I;
073: *          if ITYPE = 3, Z**H*inv(B)*Z = I.
074: *          If JOBZ = 'N', then Z is not referenced.
075: *
076: *  LDZ     (input) INTEGER
077: *          The leading dimension of the array Z.  LDZ >= 1, and if
078: *          JOBZ = 'V', LDZ >= max(1,N).
079: *
080: *  WORK    (workspace) COMPLEX array, dimension (max(1, 2*N-1))
081: *
082: *  RWORK   (workspace) REAL array, dimension (max(1, 3*N-2))
083: *
084: *  INFO    (output) INTEGER
085: *          = 0:  successful exit
086: *          < 0:  if INFO = -i, the i-th argument had an illegal value
087: *          > 0:  CPPTRF or CHPEV returned an error code:
088: *             <= N:  if INFO = i, CHPEV failed to converge;
089: *                    i off-diagonal elements of an intermediate
090: *                    tridiagonal form did not convergeto zero;
091: *             > N:   if INFO = N + i, for 1 <= i <= n, then the leading
092: *                    minor of order i of B is not positive definite.
093: *                    The factorization of B could not be completed and
094: *                    no eigenvalues or eigenvectors were computed.
095: *
096: *  =====================================================================
097: *
098: *     .. Local Scalars ..
099:       LOGICAL            UPPER, WANTZ
100:       CHARACTER          TRANS
101:       INTEGER            J, NEIG
102: *     ..
103: *     .. External Functions ..
104:       LOGICAL            LSAME
105:       EXTERNAL           LSAME
106: *     ..
107: *     .. External Subroutines ..
108:       EXTERNAL           CHPEV, CHPGST, CPPTRF, CTPMV, CTPSV, XERBLA
109: *     ..
110: *     .. Executable Statements ..
111: *
112: *     Test the input parameters.
113: *
114:       WANTZ = LSAME( JOBZ, 'V' )
115:       UPPER = LSAME( UPLO, 'U' )
116: *
117:       INFO = 0
118:       IF( ITYPE.LT.1 .OR. ITYPE.GT.3 ) THEN
119:          INFO = -1
120:       ELSE IF( .NOT.( WANTZ .OR. LSAME( JOBZ, 'N' ) ) ) THEN
121:          INFO = -2
122:       ELSE IF( .NOT.( UPPER .OR. LSAME( UPLO, 'L' ) ) ) THEN
123:          INFO = -3
124:       ELSE IF( N.LT.0 ) THEN
125:          INFO = -4
126:       ELSE IF( LDZ.LT.1 .OR. ( WANTZ .AND. LDZ.LT.N ) ) THEN
127:          INFO = -9
128:       END IF
129:       IF( INFO.NE.0 ) THEN
130:          CALL XERBLA( 'CHPGV ', -INFO )
131:          RETURN
132:       END IF
133: *
134: *     Quick return if possible
135: *
136:       IF( N.EQ.0 )
137:      $   RETURN
138: *
139: *     Form a Cholesky factorization of B.
140: *
141:       CALL CPPTRF( UPLO, N, BP, INFO )
142:       IF( INFO.NE.0 ) THEN
143:          INFO = N + INFO
144:          RETURN
145:       END IF
146: *
147: *     Transform problem to standard eigenvalue problem and solve.
148: *
149:       CALL CHPGST( ITYPE, UPLO, N, AP, BP, INFO )
150:       CALL CHPEV( JOBZ, UPLO, N, AP, W, Z, LDZ, WORK, RWORK, INFO )
151: *
152:       IF( WANTZ ) THEN
153: *
154: *        Backtransform eigenvectors to the original problem.
155: *
156:          NEIG = N
157:          IF( INFO.GT.0 )
158:      $      NEIG = INFO - 1
159:          IF( ITYPE.EQ.1 .OR. ITYPE.EQ.2 ) THEN
160: *
161: *           For A*x=(lambda)*B*x and A*B*x=(lambda)*x;
162: *           backtransform eigenvectors: x = inv(L)'*y or inv(U)*y
163: *
164:             IF( UPPER ) THEN
165:                TRANS = 'N'
166:             ELSE
167:                TRANS = 'C'
168:             END IF
169: *
170:             DO 10 J = 1, NEIG
171:                CALL CTPSV( UPLO, TRANS, 'Non-unit', N, BP, Z( 1, J ),
172:      $                     1 )
173:    10       CONTINUE
174: *
175:          ELSE IF( ITYPE.EQ.3 ) THEN
176: *
177: *           For B*A*x=(lambda)*x;
178: *           backtransform eigenvectors: x = L*y or U'*y
179: *
180:             IF( UPPER ) THEN
181:                TRANS = 'C'
182:             ELSE
183:                TRANS = 'N'
184:             END IF
185: *
186:             DO 20 J = 1, NEIG
187:                CALL CTPMV( UPLO, TRANS, 'Non-unit', N, BP, Z( 1, J ),
188:      $                     1 )
189:    20       CONTINUE
190:          END IF
191:       END IF
192:       RETURN
193: *
194: *     End of CHPGV
195: *
196:       END
197: