001:       SUBROUTINE DLAED7( ICOMPQ, N, QSIZ, TLVLS, CURLVL, CURPBM, D, Q,
002:      $                   LDQ, INDXQ, RHO, CUTPNT, QSTORE, QPTR, PRMPTR,
003:      $                   PERM, GIVPTR, GIVCOL, GIVNUM, WORK, IWORK,
004:      $                   INFO )
005: *
006: *  -- LAPACK routine (version 3.2) --
007: *     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
008: *     November 2006
009: *
010: *     .. Scalar Arguments ..
011:       INTEGER            CURLVL, CURPBM, CUTPNT, ICOMPQ, INFO, LDQ, N,
012:      $                   QSIZ, TLVLS
013:       DOUBLE PRECISION   RHO
014: *     ..
015: *     .. Array Arguments ..
016:       INTEGER            GIVCOL( 2, * ), GIVPTR( * ), INDXQ( * ),
017:      $                   IWORK( * ), PERM( * ), PRMPTR( * ), QPTR( * )
018:       DOUBLE PRECISION   D( * ), GIVNUM( 2, * ), Q( LDQ, * ),
019:      $                   QSTORE( * ), WORK( * )
020: *     ..
021: *
022: *  Purpose
023: *  =======
024: *
025: *  DLAED7 computes the updated eigensystem of a diagonal
026: *  matrix after modification by a rank-one symmetric matrix. This
027: *  routine is used only for the eigenproblem which requires all
028: *  eigenvalues and optionally eigenvectors of a dense symmetric matrix
029: *  that has been reduced to tridiagonal form.  DLAED1 handles
030: *  the case in which all eigenvalues and eigenvectors of a symmetric
031: *  tridiagonal matrix are desired.
032: *
033: *    T = Q(in) ( D(in) + RHO * Z*Z' ) Q'(in) = Q(out) * D(out) * Q'(out)
034: *
035: *     where Z = Q'u, u is a vector of length N with ones in the
036: *     CUTPNT and CUTPNT + 1 th elements and zeros elsewhere.
037: *
038: *     The eigenvectors of the original matrix are stored in Q, and the
039: *     eigenvalues are in D.  The algorithm consists of three stages:
040: *
041: *        The first stage consists of deflating the size of the problem
042: *        when there are multiple eigenvalues or if there is a zero in
043: *        the Z vector.  For each such occurence the dimension of the
044: *        secular equation problem is reduced by one.  This stage is
045: *        performed by the routine DLAED8.
046: *
047: *        The second stage consists of calculating the updated
048: *        eigenvalues. This is done by finding the roots of the secular
049: *        equation via the routine DLAED4 (as called by DLAED9).
050: *        This routine also calculates the eigenvectors of the current
051: *        problem.
052: *
053: *        The final stage consists of computing the updated eigenvectors
054: *        directly using the updated eigenvalues.  The eigenvectors for
055: *        the current problem are multiplied with the eigenvectors from
056: *        the overall problem.
057: *
058: *  Arguments
059: *  =========
060: *
061: *  ICOMPQ  (input) INTEGER
062: *          = 0:  Compute eigenvalues only.
063: *          = 1:  Compute eigenvectors of original dense symmetric matrix
064: *                also.  On entry, Q contains the orthogonal matrix used
065: *                to reduce the original matrix to tridiagonal form.
066: *
067: *  N      (input) INTEGER
068: *         The dimension of the symmetric tridiagonal matrix.  N >= 0.
069: *
070: *  QSIZ   (input) INTEGER
071: *         The dimension of the orthogonal matrix used to reduce
072: *         the full matrix to tridiagonal form.  QSIZ >= N if ICOMPQ = 1.
073: *
074: *  TLVLS  (input) INTEGER
075: *         The total number of merging levels in the overall divide and
076: *         conquer tree.
077: *
078: *  CURLVL (input) INTEGER
079: *         The current level in the overall merge routine,
080: *         0 <= CURLVL <= TLVLS.
081: *
082: *  CURPBM (input) INTEGER
083: *         The current problem in the current level in the overall
084: *         merge routine (counting from upper left to lower right).
085: *
086: *  D      (input/output) DOUBLE PRECISION array, dimension (N)
087: *         On entry, the eigenvalues of the rank-1-perturbed matrix.
088: *         On exit, the eigenvalues of the repaired matrix.
089: *
090: *  Q      (input/output) DOUBLE PRECISION array, dimension (LDQ, N)
091: *         On entry, the eigenvectors of the rank-1-perturbed matrix.
092: *         On exit, the eigenvectors of the repaired tridiagonal matrix.
093: *
094: *  LDQ    (input) INTEGER
095: *         The leading dimension of the array Q.  LDQ >= max(1,N).
096: *
097: *  INDXQ  (output) INTEGER array, dimension (N)
098: *         The permutation which will reintegrate the subproblem just
099: *         solved back into sorted order, i.e., D( INDXQ( I = 1, N ) )
100: *         will be in ascending order.
101: *
102: *  RHO    (input) DOUBLE PRECISION
103: *         The subdiagonal element used to create the rank-1
104: *         modification.
105: *
106: *  CUTPNT (input) INTEGER
107: *         Contains the location of the last eigenvalue in the leading
108: *         sub-matrix.  min(1,N) <= CUTPNT <= N.
109: *
110: *  QSTORE (input/output) DOUBLE PRECISION array, dimension (N**2+1)
111: *         Stores eigenvectors of submatrices encountered during
112: *         divide and conquer, packed together. QPTR points to
113: *         beginning of the submatrices.
114: *
115: *  QPTR   (input/output) INTEGER array, dimension (N+2)
116: *         List of indices pointing to beginning of submatrices stored
117: *         in QSTORE. The submatrices are numbered starting at the
118: *         bottom left of the divide and conquer tree, from left to
119: *         right and bottom to top.
120: *
121: *  PRMPTR (input) INTEGER array, dimension (N lg N)
122: *         Contains a list of pointers which indicate where in PERM a
123: *         level's permutation is stored.  PRMPTR(i+1) - PRMPTR(i)
124: *         indicates the size of the permutation and also the size of
125: *         the full, non-deflated problem.
126: *
127: *  PERM   (input) INTEGER array, dimension (N lg N)
128: *         Contains the permutations (from deflation and sorting) to be
129: *         applied to each eigenblock.
130: *
131: *  GIVPTR (input) INTEGER array, dimension (N lg N)
132: *         Contains a list of pointers which indicate where in GIVCOL a
133: *         level's Givens rotations are stored.  GIVPTR(i+1) - GIVPTR(i)
134: *         indicates the number of Givens rotations.
135: *
136: *  GIVCOL (input) INTEGER array, dimension (2, N lg N)
137: *         Each pair of numbers indicates a pair of columns to take place
138: *         in a Givens rotation.
139: *
140: *  GIVNUM (input) DOUBLE PRECISION array, dimension (2, N lg N)
141: *         Each number indicates the S value to be used in the
142: *         corresponding Givens rotation.
143: *
144: *  WORK   (workspace) DOUBLE PRECISION array, dimension (3*N+QSIZ*N)
145: *
146: *  IWORK  (workspace) INTEGER array, dimension (4*N)
147: *
148: *  INFO   (output) INTEGER
149: *          = 0:  successful exit.
150: *          < 0:  if INFO = -i, the i-th argument had an illegal value.
151: *          > 0:  if INFO = 1, an eigenvalue did not converge
152: *
153: *  Further Details
154: *  ===============
155: *
156: *  Based on contributions by
157: *     Jeff Rutter, Computer Science Division, University of California
158: *     at Berkeley, USA
159: *
160: *  =====================================================================
161: *
162: *     .. Parameters ..
163:       DOUBLE PRECISION   ONE, ZERO
164:       PARAMETER          ( ONE = 1.0D0, ZERO = 0.0D0 )
165: *     ..
166: *     .. Local Scalars ..
167:       INTEGER            COLTYP, CURR, I, IDLMDA, INDX, INDXC, INDXP,
168:      $                   IQ2, IS, IW, IZ, K, LDQ2, N1, N2, PTR
169: *     ..
170: *     .. External Subroutines ..
171:       EXTERNAL           DGEMM, DLAED8, DLAED9, DLAEDA, DLAMRG, XERBLA
172: *     ..
173: *     .. Intrinsic Functions ..
174:       INTRINSIC          MAX, MIN
175: *     ..
176: *     .. Executable Statements ..
177: *
178: *     Test the input parameters.
179: *
180:       INFO = 0
181: *
182:       IF( ICOMPQ.LT.0 .OR. ICOMPQ.GT.1 ) THEN
183:          INFO = -1
184:       ELSE IF( N.LT.0 ) THEN
185:          INFO = -2
186:       ELSE IF( ICOMPQ.EQ.1 .AND. QSIZ.LT.N ) THEN
187:          INFO = -4
188:       ELSE IF( LDQ.LT.MAX( 1, N ) ) THEN
189:          INFO = -9
190:       ELSE IF( MIN( 1, N ).GT.CUTPNT .OR. N.LT.CUTPNT ) THEN
191:          INFO = -12
192:       END IF
193:       IF( INFO.NE.0 ) THEN
194:          CALL XERBLA( 'DLAED7', -INFO )
195:          RETURN
196:       END IF
197: *
198: *     Quick return if possible
199: *
200:       IF( N.EQ.0 )
201:      $   RETURN
202: *
203: *     The following values are for bookkeeping purposes only.  They are
204: *     integer pointers which indicate the portion of the workspace
205: *     used by a particular array in DLAED8 and DLAED9.
206: *
207:       IF( ICOMPQ.EQ.1 ) THEN
208:          LDQ2 = QSIZ
209:       ELSE
210:          LDQ2 = N
211:       END IF
212: *
213:       IZ = 1
214:       IDLMDA = IZ + N
215:       IW = IDLMDA + N
216:       IQ2 = IW + N
217:       IS = IQ2 + N*LDQ2
218: *
219:       INDX = 1
220:       INDXC = INDX + N
221:       COLTYP = INDXC + N
222:       INDXP = COLTYP + N
223: *
224: *     Form the z-vector which consists of the last row of Q_1 and the
225: *     first row of Q_2.
226: *
227:       PTR = 1 + 2**TLVLS
228:       DO 10 I = 1, CURLVL - 1
229:          PTR = PTR + 2**( TLVLS-I )
230:    10 CONTINUE
231:       CURR = PTR + CURPBM
232:       CALL DLAEDA( N, TLVLS, CURLVL, CURPBM, PRMPTR, PERM, GIVPTR,
233:      $             GIVCOL, GIVNUM, QSTORE, QPTR, WORK( IZ ),
234:      $             WORK( IZ+N ), INFO )
235: *
236: *     When solving the final problem, we no longer need the stored data,
237: *     so we will overwrite the data from this level onto the previously
238: *     used storage space.
239: *
240:       IF( CURLVL.EQ.TLVLS ) THEN
241:          QPTR( CURR ) = 1
242:          PRMPTR( CURR ) = 1
243:          GIVPTR( CURR ) = 1
244:       END IF
245: *
246: *     Sort and Deflate eigenvalues.
247: *
248:       CALL DLAED8( ICOMPQ, K, N, QSIZ, D, Q, LDQ, INDXQ, RHO, CUTPNT,
249:      $             WORK( IZ ), WORK( IDLMDA ), WORK( IQ2 ), LDQ2,
250:      $             WORK( IW ), PERM( PRMPTR( CURR ) ), GIVPTR( CURR+1 ),
251:      $             GIVCOL( 1, GIVPTR( CURR ) ),
252:      $             GIVNUM( 1, GIVPTR( CURR ) ), IWORK( INDXP ),
253:      $             IWORK( INDX ), INFO )
254:       PRMPTR( CURR+1 ) = PRMPTR( CURR ) + N
255:       GIVPTR( CURR+1 ) = GIVPTR( CURR+1 ) + GIVPTR( CURR )
256: *
257: *     Solve Secular Equation.
258: *
259:       IF( K.NE.0 ) THEN
260:          CALL DLAED9( K, 1, K, N, D, WORK( IS ), K, RHO, WORK( IDLMDA ),
261:      $                WORK( IW ), QSTORE( QPTR( CURR ) ), K, INFO )
262:          IF( INFO.NE.0 )
263:      $      GO TO 30
264:          IF( ICOMPQ.EQ.1 ) THEN
265:             CALL DGEMM( 'N', 'N', QSIZ, K, K, ONE, WORK( IQ2 ), LDQ2,
266:      $                  QSTORE( QPTR( CURR ) ), K, ZERO, Q, LDQ )
267:          END IF
268:          QPTR( CURR+1 ) = QPTR( CURR ) + K**2
269: *
270: *     Prepare the INDXQ sorting permutation.
271: *
272:          N1 = K
273:          N2 = N - K
274:          CALL DLAMRG( N1, N2, D, 1, -1, INDXQ )
275:       ELSE
276:          QPTR( CURR+1 ) = QPTR( CURR )
277:          DO 20 I = 1, N
278:             INDXQ( I ) = I
279:    20    CONTINUE
280:       END IF
281: *
282:    30 CONTINUE
283:       RETURN
284: *
285: *     End of DLAED7
286: *
287:       END
288: