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