001:       SUBROUTINE DSPGVD( ITYPE, JOBZ, UPLO, N, AP, BP, W, Z, LDZ, WORK,
002:      $                   LWORK, IWORK, LIWORK, 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, LIWORK, LWORK, N
011: *     ..
012: *     .. Array Arguments ..
013:       INTEGER            IWORK( * )
014:       DOUBLE PRECISION   AP( * ), BP( * ), W( * ), WORK( * ),
015:      $                   Z( LDZ, * )
016: *     ..
017: *
018: *  Purpose
019: *  =======
020: *
021: *  DSPGVD 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.  Here A and
024: *  B are assumed to be symmetric, stored in packed format, and B is also
025: *  positive definite.
026: *  If eigenvectors are desired, it uses a divide and conquer algorithm.
027: *
028: *  The divide and conquer algorithm makes very mild assumptions about
029: *  floating point arithmetic. It will work on machines with a guard
030: *  digit in add/subtract, or on those binary machines without guard
031: *  digits which subtract like the Cray X-MP, Cray Y-MP, Cray C-90, or
032: *  Cray-2. It could conceivably fail on hexadecimal or decimal machines
033: *  without guard digits, but we know of none.
034: *
035: *  Arguments
036: *  =========
037: *
038: *  ITYPE   (input) INTEGER
039: *          Specifies the problem type to be solved:
040: *          = 1:  A*x = (lambda)*B*x
041: *          = 2:  A*B*x = (lambda)*x
042: *          = 3:  B*A*x = (lambda)*x
043: *
044: *  JOBZ    (input) CHARACTER*1
045: *          = 'N':  Compute eigenvalues only;
046: *          = 'V':  Compute eigenvalues and eigenvectors.
047: *
048: *  UPLO    (input) CHARACTER*1
049: *          = 'U':  Upper triangles of A and B are stored;
050: *          = 'L':  Lower triangles of A and B are stored.
051: *
052: *  N       (input) INTEGER
053: *          The order of the matrices A and B.  N >= 0.
054: *
055: *  AP      (input/output) DOUBLE PRECISION array, dimension (N*(N+1)/2)
056: *          On entry, the upper or lower triangle of the symmetric matrix
057: *          A, packed columnwise in a linear array.  The j-th column of A
058: *          is stored in the array AP as follows:
059: *          if UPLO = 'U', AP(i + (j-1)*j/2) = A(i,j) for 1<=i<=j;
060: *          if UPLO = 'L', AP(i + (j-1)*(2*n-j)/2) = A(i,j) for j<=i<=n.
061: *
062: *          On exit, the contents of AP are destroyed.
063: *
064: *  BP      (input/output) DOUBLE PRECISION array, dimension (N*(N+1)/2)
065: *          On entry, the upper or lower triangle of the symmetric matrix
066: *          B, packed columnwise in a linear array.  The j-th column of B
067: *          is stored in the array BP as follows:
068: *          if UPLO = 'U', BP(i + (j-1)*j/2) = B(i,j) for 1<=i<=j;
069: *          if UPLO = 'L', BP(i + (j-1)*(2*n-j)/2) = B(i,j) for j<=i<=n.
070: *
071: *          On exit, the triangular factor U or L from the Cholesky
072: *          factorization B = U**T*U or B = L*L**T, in the same storage
073: *          format as B.
074: *
075: *  W       (output) DOUBLE PRECISION array, dimension (N)
076: *          If INFO = 0, the eigenvalues in ascending order.
077: *
078: *  Z       (output) DOUBLE PRECISION array, dimension (LDZ, N)
079: *          If JOBZ = 'V', then if INFO = 0, Z contains the matrix Z of
080: *          eigenvectors.  The eigenvectors are normalized as follows:
081: *          if ITYPE = 1 or 2, Z**T*B*Z = I;
082: *          if ITYPE = 3, Z**T*inv(B)*Z = I.
083: *          If JOBZ = 'N', then Z is not referenced.
084: *
085: *  LDZ     (input) INTEGER
086: *          The leading dimension of the array Z.  LDZ >= 1, and if
087: *          JOBZ = 'V', LDZ >= max(1,N).
088: *
089: *  WORK    (workspace/output) DOUBLE PRECISION array, dimension (MAX(1,LWORK))
090: *          On exit, if INFO = 0, WORK(1) returns the required LWORK.
091: *
092: *  LWORK   (input) INTEGER
093: *          The dimension of the array WORK.
094: *          If N <= 1,               LWORK >= 1.
095: *          If JOBZ = 'N' and N > 1, LWORK >= 2*N.
096: *          If JOBZ = 'V' and N > 1, LWORK >= 1 + 6*N + 2*N**2.
097: *
098: *          If LWORK = -1, then a workspace query is assumed; the routine
099: *          only calculates the required sizes of the WORK and IWORK
100: *          arrays, returns these values as the first entries of the WORK
101: *          and IWORK arrays, and no error message related to LWORK or
102: *          LIWORK is issued by XERBLA.
103: *
104: *  IWORK   (workspace/output) INTEGER array, dimension (MAX(1,LIWORK))
105: *          On exit, if INFO = 0, IWORK(1) returns the required LIWORK.
106: *
107: *  LIWORK  (input) INTEGER
108: *          The dimension of the array IWORK.
109: *          If JOBZ  = 'N' or N <= 1, LIWORK >= 1.
110: *          If JOBZ  = 'V' and N > 1, LIWORK >= 3 + 5*N.
111: *
112: *          If LIWORK = -1, then a workspace query is assumed; the
113: *          routine only calculates the required sizes of the WORK and
114: *          IWORK arrays, returns these values as the first entries of
115: *          the WORK and IWORK arrays, and no error message related to
116: *          LWORK or LIWORK is issued by XERBLA.
117: *
118: *  INFO    (output) INTEGER
119: *          = 0:  successful exit
120: *          < 0:  if INFO = -i, the i-th argument had an illegal value
121: *          > 0:  DPPTRF or DSPEVD returned an error code:
122: *             <= N:  if INFO = i, DSPEVD failed to converge;
123: *                    i off-diagonal elements of an intermediate
124: *                    tridiagonal form did not converge to zero;
125: *             > N:   if INFO = N + i, for 1 <= i <= N, then the leading
126: *                    minor of order i of B is not positive definite.
127: *                    The factorization of B could not be completed and
128: *                    no eigenvalues or eigenvectors were computed.
129: *
130: *  Further Details
131: *  ===============
132: *
133: *  Based on contributions by
134: *     Mark Fahey, Department of Mathematics, Univ. of Kentucky, USA
135: *
136: *  =====================================================================
137: *
138: *     .. Parameters ..
139:       DOUBLE PRECISION   TWO
140:       PARAMETER          ( TWO = 2.0D+0 )
141: *     ..
142: *     .. Local Scalars ..
143:       LOGICAL            LQUERY, UPPER, WANTZ
144:       CHARACTER          TRANS
145:       INTEGER            J, LIWMIN, LWMIN, NEIG
146: *     ..
147: *     .. External Functions ..
148:       LOGICAL            LSAME
149:       EXTERNAL           LSAME
150: *     ..
151: *     .. External Subroutines ..
152:       EXTERNAL           DPPTRF, DSPEVD, DSPGST, DTPMV, DTPSV, XERBLA
153: *     ..
154: *     .. Intrinsic Functions ..
155:       INTRINSIC          DBLE, MAX
156: *     ..
157: *     .. Executable Statements ..
158: *
159: *     Test the input parameters.
160: *
161:       WANTZ = LSAME( JOBZ, 'V' )
162:       UPPER = LSAME( UPLO, 'U' )
163:       LQUERY = ( LWORK.EQ.-1 .OR. LIWORK.EQ.-1 )
164: *
165:       INFO = 0
166:       IF( ITYPE.LT.1 .OR. ITYPE.GT.3 ) THEN
167:          INFO = -1
168:       ELSE IF( .NOT.( WANTZ .OR. LSAME( JOBZ, 'N' ) ) ) THEN
169:          INFO = -2
170:       ELSE IF( .NOT.( UPPER .OR. LSAME( UPLO, 'L' ) ) ) THEN
171:          INFO = -3
172:       ELSE IF( N.LT.0 ) THEN
173:          INFO = -4
174:       ELSE IF( LDZ.LT.1 .OR. ( WANTZ .AND. LDZ.LT.N ) ) THEN
175:          INFO = -9
176:       END IF
177: *
178:       IF( INFO.EQ.0 ) THEN
179:          IF( N.LE.1 ) THEN
180:             LIWMIN = 1
181:             LWMIN = 1
182:          ELSE
183:             IF( WANTZ ) THEN
184:                LIWMIN = 3 + 5*N
185:                LWMIN = 1 + 6*N + 2*N**2
186:             ELSE
187:                LIWMIN = 1
188:                LWMIN = 2*N
189:             END IF
190:          END IF
191:          WORK( 1 ) = LWMIN
192:          IWORK( 1 ) = LIWMIN
193: *
194:          IF( LWORK.LT.LWMIN .AND. .NOT.LQUERY ) THEN
195:             INFO = -11
196:          ELSE IF( LIWORK.LT.LIWMIN .AND. .NOT.LQUERY ) THEN
197:             INFO = -13
198:          END IF
199:       END IF
200: *
201:       IF( INFO.NE.0 ) THEN
202:          CALL XERBLA( 'DSPGVD', -INFO )
203:          RETURN
204:       ELSE IF( LQUERY ) THEN
205:          RETURN
206:       END IF
207: *
208: *     Quick return if possible
209: *
210:       IF( N.EQ.0 )
211:      $   RETURN
212: *
213: *     Form a Cholesky factorization of BP.
214: *
215:       CALL DPPTRF( UPLO, N, BP, INFO )
216:       IF( INFO.NE.0 ) THEN
217:          INFO = N + INFO
218:          RETURN
219:       END IF
220: *
221: *     Transform problem to standard eigenvalue problem and solve.
222: *
223:       CALL DSPGST( ITYPE, UPLO, N, AP, BP, INFO )
224:       CALL DSPEVD( JOBZ, UPLO, N, AP, W, Z, LDZ, WORK, LWORK, IWORK,
225:      $             LIWORK, INFO )
226:       LWMIN = MAX( DBLE( LWMIN ), DBLE( WORK( 1 ) ) )
227:       LIWMIN = MAX( DBLE( LIWMIN ), DBLE( IWORK( 1 ) ) )
228: *
229:       IF( WANTZ ) THEN
230: *
231: *        Backtransform eigenvectors to the original problem.
232: *
233:          NEIG = N
234:          IF( INFO.GT.0 )
235:      $      NEIG = INFO - 1
236:          IF( ITYPE.EQ.1 .OR. ITYPE.EQ.2 ) THEN
237: *
238: *           For A*x=(lambda)*B*x and A*B*x=(lambda)*x;
239: *           backtransform eigenvectors: x = inv(L)'*y or inv(U)*y
240: *
241:             IF( UPPER ) THEN
242:                TRANS = 'N'
243:             ELSE
244:                TRANS = 'T'
245:             END IF
246: *
247:             DO 10 J = 1, NEIG
248:                CALL DTPSV( UPLO, TRANS, 'Non-unit', N, BP, Z( 1, J ),
249:      $                     1 )
250:    10       CONTINUE
251: *
252:          ELSE IF( ITYPE.EQ.3 ) THEN
253: *
254: *           For B*A*x=(lambda)*x;
255: *           backtransform eigenvectors: x = L*y or U'*y
256: *
257:             IF( UPPER ) THEN
258:                TRANS = 'T'
259:             ELSE
260:                TRANS = 'N'
261:             END IF
262: *
263:             DO 20 J = 1, NEIG
264:                CALL DTPMV( UPLO, TRANS, 'Non-unit', N, BP, Z( 1, J ),
265:      $                     1 )
266:    20       CONTINUE
267:          END IF
268:       END IF
269: *
270:       WORK( 1 ) = LWMIN
271:       IWORK( 1 ) = LIWMIN
272: *
273:       RETURN
274: *
275: *     End of DSPGVD
276: *
277:       END
278: