001:       SUBROUTINE SSPGV( ITYPE, JOBZ, UPLO, N, AP, BP, W, Z, LDZ, WORK,
002:      $                  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               AP( * ), BP( * ), W( * ), WORK( * ),
014:      $                   Z( LDZ, * )
015: *     ..
016: *
017: *  Purpose
018: *  =======
019: *
020: *  SSPGV computes all the eigenvalues and, optionally, the eigenvectors
021: *  of a real generalized symmetric-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 symmetric, 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) REAL array, dimension
047: *                            (N*(N+1)/2)
048: *          On entry, the upper or lower triangle of the symmetric 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) REAL array, dimension (N*(N+1)/2)
057: *          On entry, the upper or lower triangle of the symmetric 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**T*U or B = L*L**T, in the same storage
065: *          format as B.
066: *
067: *  W       (output) REAL array, dimension (N)
068: *          If INFO = 0, the eigenvalues in ascending order.
069: *
070: *  Z       (output) REAL 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**T*B*Z = I;
074: *          if ITYPE = 3, Z**T*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) REAL array, dimension (3*N)
082: *
083: *  INFO    (output) INTEGER
084: *          = 0:  successful exit
085: *          < 0:  if INFO = -i, the i-th argument had an illegal value
086: *          > 0:  SPPTRF or SSPEV returned an error code:
087: *             <= N:  if INFO = i, SSPEV failed to converge;
088: *                    i off-diagonal elements of an intermediate
089: *                    tridiagonal form did not converge to zero.
090: *             > N:   if INFO = n + i, for 1 <= i <= n, then the leading
091: *                    minor of order i of B is not positive definite.
092: *                    The factorization of B could not be completed and
093: *                    no eigenvalues or eigenvectors were computed.
094: *
095: *  =====================================================================
096: *
097: *     .. Local Scalars ..
098:       LOGICAL            UPPER, WANTZ
099:       CHARACTER          TRANS
100:       INTEGER            J, NEIG
101: *     ..
102: *     .. External Functions ..
103:       LOGICAL            LSAME
104:       EXTERNAL           LSAME
105: *     ..
106: *     .. External Subroutines ..
107:       EXTERNAL           SPPTRF, SSPEV, SSPGST, STPMV, STPSV, XERBLA
108: *     ..
109: *     .. Executable Statements ..
110: *
111: *     Test the input parameters.
112: *
113:       WANTZ = LSAME( JOBZ, 'V' )
114:       UPPER = LSAME( UPLO, 'U' )
115: *
116:       INFO = 0
117:       IF( ITYPE.LT.1 .OR. ITYPE.GT.3 ) THEN
118:          INFO = -1
119:       ELSE IF( .NOT.( WANTZ .OR. LSAME( JOBZ, 'N' ) ) ) THEN
120:          INFO = -2
121:       ELSE IF( .NOT.( UPPER .OR. LSAME( UPLO, 'L' ) ) ) THEN
122:          INFO = -3
123:       ELSE IF( N.LT.0 ) THEN
124:          INFO = -4
125:       ELSE IF( LDZ.LT.1 .OR. ( WANTZ .AND. LDZ.LT.N ) ) THEN
126:          INFO = -9
127:       END IF
128:       IF( INFO.NE.0 ) THEN
129:          CALL XERBLA( 'SSPGV ', -INFO )
130:          RETURN
131:       END IF
132: *
133: *     Quick return if possible
134: *
135:       IF( N.EQ.0 )
136:      $   RETURN
137: *
138: *     Form a Cholesky factorization of B.
139: *
140:       CALL SPPTRF( UPLO, N, BP, INFO )
141:       IF( INFO.NE.0 ) THEN
142:          INFO = N + INFO
143:          RETURN
144:       END IF
145: *
146: *     Transform problem to standard eigenvalue problem and solve.
147: *
148:       CALL SSPGST( ITYPE, UPLO, N, AP, BP, INFO )
149:       CALL SSPEV( JOBZ, UPLO, N, AP, W, Z, LDZ, WORK, INFO )
150: *
151:       IF( WANTZ ) THEN
152: *
153: *        Backtransform eigenvectors to the original problem.
154: *
155:          NEIG = N
156:          IF( INFO.GT.0 )
157:      $      NEIG = INFO - 1
158:          IF( ITYPE.EQ.1 .OR. ITYPE.EQ.2 ) THEN
159: *
160: *           For A*x=(lambda)*B*x and A*B*x=(lambda)*x;
161: *           backtransform eigenvectors: x = inv(L)'*y or inv(U)*y
162: *
163:             IF( UPPER ) THEN
164:                TRANS = 'N'
165:             ELSE
166:                TRANS = 'T'
167:             END IF
168: *
169:             DO 10 J = 1, NEIG
170:                CALL STPSV( UPLO, TRANS, 'Non-unit', N, BP, Z( 1, J ),
171:      $                     1 )
172:    10       CONTINUE
173: *
174:          ELSE IF( ITYPE.EQ.3 ) THEN
175: *
176: *           For B*A*x=(lambda)*x;
177: *           backtransform eigenvectors: x = L*y or U'*y
178: *
179:             IF( UPPER ) THEN
180:                TRANS = 'T'
181:             ELSE
182:                TRANS = 'N'
183:             END IF
184: *
185:             DO 20 J = 1, NEIG
186:                CALL STPMV( UPLO, TRANS, 'Non-unit', N, BP, Z( 1, J ),
187:      $                     1 )
188:    20       CONTINUE
189:          END IF
190:       END IF
191:       RETURN
192: *
193: *     End of SSPGV
194: *
195:       END
196: