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