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