001:       SUBROUTINE DSPGV( ITYPE, JOBZ, UPLO, N, AP, BP, W, Z, LDZ, WORK,
002:      $                  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   AP( * ), BP( * ), W( * ), WORK( * ),
015:      $                   Z( LDZ, * )
016: *     ..
017: *
018: *  Purpose
019: *  =======
020: *
021: *  DSPGV computes all the eigenvalues and, optionally, the eigenvectors
022: *  of a real generalized symmetric-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 symmetric, 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) DOUBLE PRECISION array, dimension
048: *                            (N*(N+1)/2)
049: *          On entry, the upper or lower triangle of the symmetric matrix
050: *          A, packed columnwise in a linear array.  The j-th column of A
051: *          is stored in the array AP as follows:
052: *          if UPLO = 'U', AP(i + (j-1)*j/2) = A(i,j) for 1<=i<=j;
053: *          if UPLO = 'L', AP(i + (j-1)*(2*n-j)/2) = A(i,j) for j<=i<=n.
054: *
055: *          On exit, the contents of AP are destroyed.
056: *
057: *  BP      (input/output) DOUBLE PRECISION array, dimension (N*(N+1)/2)
058: *          On entry, the upper or lower triangle of the symmetric matrix
059: *          B, packed columnwise in a linear array.  The j-th column of B
060: *          is stored in the array BP as follows:
061: *          if UPLO = 'U', BP(i + (j-1)*j/2) = B(i,j) for 1<=i<=j;
062: *          if UPLO = 'L', BP(i + (j-1)*(2*n-j)/2) = B(i,j) for j<=i<=n.
063: *
064: *          On exit, the triangular factor U or L from the Cholesky
065: *          factorization B = U**T*U or B = L*L**T, in the same storage
066: *          format as B.
067: *
068: *  W       (output) DOUBLE PRECISION array, dimension (N)
069: *          If INFO = 0, the eigenvalues in ascending order.
070: *
071: *  Z       (output) DOUBLE PRECISION array, dimension (LDZ, N)
072: *          If JOBZ = 'V', then if INFO = 0, Z contains the matrix Z of
073: *          eigenvectors.  The eigenvectors are normalized as follows:
074: *          if ITYPE = 1 or 2, Z**T*B*Z = I;
075: *          if ITYPE = 3, Z**T*inv(B)*Z = I.
076: *          If JOBZ = 'N', then Z is not referenced.
077: *
078: *  LDZ     (input) INTEGER
079: *          The leading dimension of the array Z.  LDZ >= 1, and if
080: *          JOBZ = 'V', LDZ >= max(1,N).
081: *
082: *  WORK    (workspace) DOUBLE PRECISION array, dimension (3*N)
083: *
084: *  INFO    (output) INTEGER
085: *          = 0:  successful exit
086: *          < 0:  if INFO = -i, the i-th argument had an illegal value
087: *          > 0:  DPPTRF or DSPEV returned an error code:
088: *             <= N:  if INFO = i, DSPEV failed to converge;
089: *                    i off-diagonal elements of an intermediate
090: *                    tridiagonal form did not converge to 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           DPPTRF, DSPEV, DSPGST, DTPMV, DTPSV, 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( 'DSPGV ', -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 DPPTRF( 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 DSPGST( ITYPE, UPLO, N, AP, BP, INFO )
150:       CALL DSPEV( JOBZ, UPLO, N, AP, W, Z, LDZ, WORK, 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 = 'T'
168:             END IF
169: *
170:             DO 10 J = 1, NEIG
171:                CALL DTPSV( 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 = 'T'
182:             ELSE
183:                TRANS = 'N'
184:             END IF
185: *
186:             DO 20 J = 1, NEIG
187:                CALL DTPMV( 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 DSPGV
195: *
196:       END
197: