001:       SUBROUTINE SSPGVX( ITYPE, JOBZ, RANGE, UPLO, N, AP, BP, VL, VU,
002:      $                   IL, IU, ABSTOL, M, W, Z, LDZ, WORK, IWORK,
003:      $                   IFAIL, INFO )
004: *
005: *  -- LAPACK driver routine (version 3.2) --
006: *  -- LAPACK is a software package provided by Univ. of Tennessee,    --
007: *  -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
008: *     November 2006
009: *
010: *     .. Scalar Arguments ..
011:       CHARACTER          JOBZ, RANGE, UPLO
012:       INTEGER            IL, INFO, ITYPE, IU, LDZ, M, N
013:       REAL               ABSTOL, VL, VU
014: *     ..
015: *     .. Array Arguments ..
016:       INTEGER            IFAIL( * ), IWORK( * )
017:       REAL               AP( * ), BP( * ), W( * ), WORK( * ),
018:      $                   Z( LDZ, * )
019: *     ..
020: *
021: *  Purpose
022: *  =======
023: *
024: *  SSPGVX computes selected eigenvalues, and optionally, eigenvectors
025: *  of a real generalized symmetric-definite eigenproblem, of the form
026: *  A*x=(lambda)*B*x,  A*Bx=(lambda)*x,  or B*A*x=(lambda)*x.  Here A
027: *  and B are assumed to be symmetric, stored in packed storage, and B
028: *  is also positive definite.  Eigenvalues and eigenvectors can be
029: *  selected by specifying either a range of values or a range of indices
030: *  for the desired eigenvalues.
031: *
032: *  Arguments
033: *  =========
034: *
035: *  ITYPE   (input) INTEGER
036: *          Specifies the problem type to be solved:
037: *          = 1:  A*x = (lambda)*B*x
038: *          = 2:  A*B*x = (lambda)*x
039: *          = 3:  B*A*x = (lambda)*x
040: *
041: *  JOBZ    (input) CHARACTER*1
042: *          = 'N':  Compute eigenvalues only;
043: *          = 'V':  Compute eigenvalues and eigenvectors.
044: *
045: *  RANGE   (input) CHARACTER*1
046: *          = 'A': all eigenvalues will be found.
047: *          = 'V': all eigenvalues in the half-open interval (VL,VU]
048: *                 will be found.
049: *          = 'I': the IL-th through IU-th eigenvalues will be found.
050: *
051: *  UPLO    (input) CHARACTER*1
052: *          = 'U':  Upper triangle of A and B are stored;
053: *          = 'L':  Lower triangle of A and B are stored.
054: *
055: *  N       (input) INTEGER
056: *          The order of the matrix pencil (A,B).  N >= 0.
057: *
058: *  AP      (input/output) REAL array, dimension (N*(N+1)/2)
059: *          On entry, the upper or lower triangle of the symmetric matrix
060: *          A, packed columnwise in a linear array.  The j-th column of A
061: *          is stored in the array AP as follows:
062: *          if UPLO = 'U', AP(i + (j-1)*j/2) = A(i,j) for 1<=i<=j;
063: *          if UPLO = 'L', AP(i + (j-1)*(2*n-j)/2) = A(i,j) for j<=i<=n.
064: *
065: *          On exit, the contents of AP are destroyed.
066: *
067: *  BP      (input/output) REAL array, dimension (N*(N+1)/2)
068: *          On entry, the upper or lower triangle of the symmetric matrix
069: *          B, packed columnwise in a linear array.  The j-th column of B
070: *          is stored in the array BP as follows:
071: *          if UPLO = 'U', BP(i + (j-1)*j/2) = B(i,j) for 1<=i<=j;
072: *          if UPLO = 'L', BP(i + (j-1)*(2*n-j)/2) = B(i,j) for j<=i<=n.
073: *
074: *          On exit, the triangular factor U or L from the Cholesky
075: *          factorization B = U**T*U or B = L*L**T, in the same storage
076: *          format as B.
077: *
078: *  VL      (input) REAL
079: *  VU      (input) REAL
080: *          If RANGE='V', the lower and upper bounds of the interval to
081: *          be searched for eigenvalues. VL < VU.
082: *          Not referenced if RANGE = 'A' or 'I'.
083: *
084: *  IL      (input) INTEGER
085: *  IU      (input) INTEGER
086: *          If RANGE='I', the indices (in ascending order) of the
087: *          smallest and largest eigenvalues to be returned.
088: *          1 <= IL <= IU <= N, if N > 0; IL = 1 and IU = 0 if N = 0.
089: *          Not referenced if RANGE = 'A' or 'V'.
090: *
091: *  ABSTOL  (input) REAL
092: *          The absolute error tolerance for the eigenvalues.
093: *          An approximate eigenvalue is accepted as converged
094: *          when it is determined to lie in an interval [a,b]
095: *          of width less than or equal to
096: *
097: *                  ABSTOL + EPS *   max( |a|,|b| ) ,
098: *
099: *          where EPS is the machine precision.  If ABSTOL is less than
100: *          or equal to zero, then  EPS*|T|  will be used in its place,
101: *          where |T| is the 1-norm of the tridiagonal matrix obtained
102: *          by reducing A to tridiagonal form.
103: *
104: *          Eigenvalues will be computed most accurately when ABSTOL is
105: *          set to twice the underflow threshold 2*SLAMCH('S'), not zero.
106: *          If this routine returns with INFO>0, indicating that some
107: *          eigenvectors did not converge, try setting ABSTOL to
108: *          2*SLAMCH('S').
109: *
110: *  M       (output) INTEGER
111: *          The total number of eigenvalues found.  0 <= M <= N.
112: *          If RANGE = 'A', M = N, and if RANGE = 'I', M = IU-IL+1.
113: *
114: *  W       (output) REAL array, dimension (N)
115: *          On normal exit, the first M elements contain the selected
116: *          eigenvalues in ascending order.
117: *
118: *  Z       (output) REAL array, dimension (LDZ, max(1,M))
119: *          If JOBZ = 'N', then Z is not referenced.
120: *          If JOBZ = 'V', then if INFO = 0, the first M columns of Z
121: *          contain the orthonormal eigenvectors of the matrix A
122: *          corresponding to the selected eigenvalues, with the i-th
123: *          column of Z holding the eigenvector associated with W(i).
124: *          The eigenvectors are normalized as follows:
125: *          if ITYPE = 1 or 2, Z**T*B*Z = I;
126: *          if ITYPE = 3, Z**T*inv(B)*Z = I.
127: *
128: *          If an eigenvector fails to converge, then that column of Z
129: *          contains the latest approximation to the eigenvector, and the
130: *          index of the eigenvector is returned in IFAIL.
131: *          Note: the user must ensure that at least max(1,M) columns are
132: *          supplied in the array Z; if RANGE = 'V', the exact value of M
133: *          is not known in advance and an upper bound must be used.
134: *
135: *  LDZ     (input) INTEGER
136: *          The leading dimension of the array Z.  LDZ >= 1, and if
137: *          JOBZ = 'V', LDZ >= max(1,N).
138: *
139: *  WORK    (workspace) REAL array, dimension (8*N)
140: *
141: *  IWORK   (workspace) INTEGER array, dimension (5*N)
142: *
143: *  IFAIL   (output) INTEGER array, dimension (N)
144: *          If JOBZ = 'V', then if INFO = 0, the first M elements of
145: *          IFAIL are zero.  If INFO > 0, then IFAIL contains the
146: *          indices of the eigenvectors that failed to converge.
147: *          If JOBZ = 'N', then IFAIL is not referenced.
148: *
149: *  INFO    (output) INTEGER
150: *          = 0:  successful exit
151: *          < 0:  if INFO = -i, the i-th argument had an illegal value
152: *          > 0:  SPPTRF or SSPEVX returned an error code:
153: *             <= N:  if INFO = i, SSPEVX failed to converge;
154: *                    i eigenvectors failed to converge.  Their indices
155: *                    are stored in array IFAIL.
156: *             > N:   if INFO = N + i, for 1 <= i <= N, then the leading
157: *                    minor of order i of B is not positive definite.
158: *                    The factorization of B could not be completed and
159: *                    no eigenvalues or eigenvectors were computed.
160: *
161: *  Further Details
162: *  ===============
163: *
164: *  Based on contributions by
165: *     Mark Fahey, Department of Mathematics, Univ. of Kentucky, USA
166: *
167: * =====================================================================
168: *
169: *     .. Local Scalars ..
170:       LOGICAL            ALLEIG, INDEIG, UPPER, VALEIG, WANTZ
171:       CHARACTER          TRANS
172:       INTEGER            J
173: *     ..
174: *     .. External Functions ..
175:       LOGICAL            LSAME
176:       EXTERNAL           LSAME
177: *     ..
178: *     .. External Subroutines ..
179:       EXTERNAL           SPPTRF, SSPEVX, SSPGST, STPMV, STPSV, XERBLA
180: *     ..
181: *     .. Intrinsic Functions ..
182:       INTRINSIC          MIN
183: *     ..
184: *     .. Executable Statements ..
185: *
186: *     Test the input parameters.
187: *
188:       UPPER = LSAME( UPLO, 'U' )
189:       WANTZ = LSAME( JOBZ, 'V' )
190:       ALLEIG = LSAME( RANGE, 'A' )
191:       VALEIG = LSAME( RANGE, 'V' )
192:       INDEIG = LSAME( RANGE, 'I' )
193: *
194:       INFO = 0
195:       IF( ITYPE.LT.1 .OR. ITYPE.GT.3 ) THEN
196:          INFO = -1
197:       ELSE IF( .NOT.( WANTZ .OR. LSAME( JOBZ, 'N' ) ) ) THEN
198:          INFO = -2
199:       ELSE IF( .NOT.( ALLEIG .OR. VALEIG .OR. INDEIG ) ) THEN
200:          INFO = -3
201:       ELSE IF( .NOT.( UPPER .OR. LSAME( UPLO, 'L' ) ) ) THEN
202:          INFO = -4
203:       ELSE IF( N.LT.0 ) THEN
204:          INFO = -5
205:       ELSE
206:          IF( VALEIG ) THEN
207:             IF( N.GT.0 .AND. VU.LE.VL ) THEN
208:                INFO = -9
209:             END IF
210:          ELSE IF( INDEIG ) THEN
211:             IF( IL.LT.1 ) THEN
212:                INFO = -10
213:             ELSE IF( IU.LT.MIN( N, IL ) .OR. IU.GT.N ) THEN
214:                INFO = -11
215:             END IF
216:          END IF
217:       END IF
218:       IF( INFO.EQ.0 ) THEN
219:          IF( LDZ.LT.1 .OR. ( WANTZ .AND. LDZ.LT.N ) ) THEN
220:             INFO = -16
221:          END IF
222:       END IF
223: *
224:       IF( INFO.NE.0 ) THEN
225:          CALL XERBLA( 'SSPGVX', -INFO )
226:          RETURN
227:       END IF
228: *
229: *     Quick return if possible
230: *
231:       M = 0
232:       IF( N.EQ.0 )
233:      $   RETURN
234: *
235: *     Form a Cholesky factorization of B.
236: *
237:       CALL SPPTRF( UPLO, N, BP, INFO )
238:       IF( INFO.NE.0 ) THEN
239:          INFO = N + INFO
240:          RETURN
241:       END IF
242: *
243: *     Transform problem to standard eigenvalue problem and solve.
244: *
245:       CALL SSPGST( ITYPE, UPLO, N, AP, BP, INFO )
246:       CALL SSPEVX( JOBZ, RANGE, UPLO, N, AP, VL, VU, IL, IU, ABSTOL, M,
247:      $             W, Z, LDZ, WORK, IWORK, IFAIL, INFO )
248: *
249:       IF( WANTZ ) THEN
250: *
251: *        Backtransform eigenvectors to the original problem.
252: *
253:          IF( INFO.GT.0 )
254:      $      M = INFO - 1
255:          IF( ITYPE.EQ.1 .OR. ITYPE.EQ.2 ) THEN
256: *
257: *           For A*x=(lambda)*B*x and A*B*x=(lambda)*x;
258: *           backtransform eigenvectors: x = inv(L)'*y or inv(U)*y
259: *
260:             IF( UPPER ) THEN
261:                TRANS = 'N'
262:             ELSE
263:                TRANS = 'T'
264:             END IF
265: *
266:             DO 10 J = 1, M
267:                CALL STPSV( UPLO, TRANS, 'Non-unit', N, BP, Z( 1, J ),
268:      $                     1 )
269:    10       CONTINUE
270: *
271:          ELSE IF( ITYPE.EQ.3 ) THEN
272: *
273: *           For B*A*x=(lambda)*x;
274: *           backtransform eigenvectors: x = L*y or U'*y
275: *
276:             IF( UPPER ) THEN
277:                TRANS = 'T'
278:             ELSE
279:                TRANS = 'N'
280:             END IF
281: *
282:             DO 20 J = 1, M
283:                CALL STPMV( UPLO, TRANS, 'Non-unit', N, BP, Z( 1, J ),
284:      $                     1 )
285:    20       CONTINUE
286:          END IF
287:       END IF
288: *
289:       RETURN
290: *
291: *     End of SSPGVX
292: *
293:       END
294: