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