3 * =========== DOCUMENTATION ===========
5 * Online html documentation available at
6 * http://www.netlib.org/lapack/explore-html/
9 *> Download DTREXC + dependencies
10 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dtrexc.f">
12 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dtrexc.f">
14 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dtrexc.f">
21 * SUBROUTINE DTREXC( COMPQ, N, T, LDT, Q, LDQ, IFST, ILST, WORK,
24 * .. Scalar Arguments ..
26 * INTEGER IFST, ILST, INFO, LDQ, LDT, N
28 * .. Array Arguments ..
29 * DOUBLE PRECISION Q( LDQ, * ), T( LDT, * ), WORK( * )
38 *> DTREXC reorders the real Schur factorization of a real matrix
39 *> A = Q*T*Q**T, so that the diagonal block of T with row index IFST is
42 *> The real Schur form T is reordered by an orthogonal similarity
43 *> transformation Z**T*T*Z, and optionally the matrix Q of Schur vectors
44 *> is updated by postmultiplying it with Z.
46 *> T must be in Schur canonical form (as returned by DHSEQR), that is,
47 *> block upper triangular with 1-by-1 and 2-by-2 diagonal blocks; each
48 *> 2-by-2 diagonal block has its diagonal elements equal and its
49 *> off-diagonal elements of opposite sign.
57 *> COMPQ is CHARACTER*1
58 *> = 'V': update the matrix Q of Schur vectors;
59 *> = 'N': do not update Q.
65 *> The order of the matrix T. N >= 0.
70 *> T is DOUBLE PRECISION array, dimension (LDT,N)
71 *> On entry, the upper quasi-triangular matrix T, in Schur
72 *> Schur canonical form.
73 *> On exit, the reordered upper quasi-triangular matrix, again
74 *> in Schur canonical form.
80 *> The leading dimension of the array T. LDT >= max(1,N).
85 *> Q is DOUBLE PRECISION array, dimension (LDQ,N)
86 *> On entry, if COMPQ = 'V', the matrix Q of Schur vectors.
87 *> On exit, if COMPQ = 'V', Q has been postmultiplied by the
88 *> orthogonal transformation matrix Z which reorders T.
89 *> If COMPQ = 'N', Q is not referenced.
95 *> The leading dimension of the array Q. LDQ >= 1, and if
96 *> COMPQ = 'V', LDQ >= max(1,N).
99 *> \param[in,out] IFST
104 *> \param[in,out] ILST
108 *> Specify the reordering of the diagonal blocks of T.
109 *> The block with row index IFST is moved to row ILST, by a
110 *> sequence of transpositions between adjacent blocks.
111 *> On exit, if IFST pointed on entry to the second row of a
112 *> 2-by-2 block, it is changed to point to the first row; ILST
113 *> always points to the first row of the block in its final
114 *> position (which may differ from its input value by +1 or -1).
115 *> 1 <= IFST <= N; 1 <= ILST <= N.
120 *> WORK is DOUBLE PRECISION array, dimension (N)
126 *> = 0: successful exit
127 *> < 0: if INFO = -i, the i-th argument had an illegal value
128 *> = 1: two adjacent blocks were too close to swap (the problem
129 *> is very ill-conditioned); T may have been partially
130 *> reordered, and ILST points to the first row of the
131 *> current position of the block being moved.
137 *> \author Univ. of Tennessee
138 *> \author Univ. of California Berkeley
139 *> \author Univ. of Colorado Denver
142 *> \date November 2011
144 *> \ingroup doubleOTHERcomputational
146 * =====================================================================
147 SUBROUTINE DTREXC( COMPQ, N, T, LDT, Q, LDQ, IFST, ILST, WORK,
150 * -- LAPACK computational routine (version 3.4.0) --
151 * -- LAPACK is a software package provided by Univ. of Tennessee, --
152 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
155 * .. Scalar Arguments ..
157 INTEGER IFST, ILST, INFO, LDQ, LDT, N
159 * .. Array Arguments ..
160 DOUBLE PRECISION Q( LDQ, * ), T( LDT, * ), WORK( * )
163 * =====================================================================
166 DOUBLE PRECISION ZERO
167 PARAMETER ( ZERO = 0.0D+0 )
169 * .. Local Scalars ..
171 INTEGER HERE, NBF, NBL, NBNEXT
173 * .. External Functions ..
177 * .. External Subroutines ..
178 EXTERNAL DLAEXC, XERBLA
180 * .. Intrinsic Functions ..
183 * .. Executable Statements ..
185 * Decode and test the input arguments.
188 WANTQ = LSAME( COMPQ, 'V' )
189 IF( .NOT.WANTQ .AND. .NOT.LSAME( COMPQ, 'N' ) ) THEN
191 ELSE IF( N.LT.0 ) THEN
193 ELSE IF( LDT.LT.MAX( 1, N ) ) THEN
195 ELSE IF( LDQ.LT.1 .OR. ( WANTQ .AND. LDQ.LT.MAX( 1, N ) ) ) THEN
197 ELSE IF(( IFST.LT.1 .OR. IFST.GT.N ).AND.( N.GT.0 )) THEN
199 ELSE IF(( ILST.LT.1 .OR. ILST.GT.N ).AND.( N.GT.0 )) THEN
203 CALL XERBLA( 'DTREXC', -INFO )
207 * Quick return if possible
212 * Determine the first row of specified block
213 * and find out it is 1 by 1 or 2 by 2.
216 IF( T( IFST, IFST-1 ).NE.ZERO )
221 IF( T( IFST+1, IFST ).NE.ZERO )
225 * Determine the first row of the final block
226 * and find out it is 1 by 1 or 2 by 2.
229 IF( T( ILST, ILST-1 ).NE.ZERO )
234 IF( T( ILST+1, ILST ).NE.ZERO )
241 IF( IFST.LT.ILST ) THEN
245 IF( NBF.EQ.2 .AND. NBL.EQ.1 )
247 IF( NBF.EQ.1 .AND. NBL.EQ.2 )
254 * Swap block with next one below
256 IF( NBF.EQ.1 .OR. NBF.EQ.2 ) THEN
258 * Current block either 1 by 1 or 2 by 2
261 IF( HERE+NBF+1.LE.N ) THEN
262 IF( T( HERE+NBF+1, HERE+NBF ).NE.ZERO )
265 CALL DLAEXC( WANTQ, N, T, LDT, Q, LDQ, HERE, NBF, NBNEXT,
273 * Test if 2 by 2 block breaks into two 1 by 1 blocks
276 IF( T( HERE+1, HERE ).EQ.ZERO )
282 * Current block consists of two 1 by 1 blocks each of which
283 * must be swapped individually
286 IF( HERE+3.LE.N ) THEN
287 IF( T( HERE+3, HERE+2 ).NE.ZERO )
290 CALL DLAEXC( WANTQ, N, T, LDT, Q, LDQ, HERE+1, 1, NBNEXT,
296 IF( NBNEXT.EQ.1 ) THEN
298 * Swap two 1 by 1 blocks, no problems possible
300 CALL DLAEXC( WANTQ, N, T, LDT, Q, LDQ, HERE, 1, NBNEXT,
305 * Recompute NBNEXT in case 2 by 2 split
307 IF( T( HERE+2, HERE+1 ).EQ.ZERO )
309 IF( NBNEXT.EQ.2 ) THEN
311 * 2 by 2 Block did not split
313 CALL DLAEXC( WANTQ, N, T, LDT, Q, LDQ, HERE, 1,
314 $ NBNEXT, WORK, INFO )
322 * 2 by 2 Block did split
324 CALL DLAEXC( WANTQ, N, T, LDT, Q, LDQ, HERE, 1, 1,
326 CALL DLAEXC( WANTQ, N, T, LDT, Q, LDQ, HERE+1, 1, 1,
340 * Swap block with next one above
342 IF( NBF.EQ.1 .OR. NBF.EQ.2 ) THEN
344 * Current block either 1 by 1 or 2 by 2
348 IF( T( HERE-1, HERE-2 ).NE.ZERO )
351 CALL DLAEXC( WANTQ, N, T, LDT, Q, LDQ, HERE-NBNEXT, NBNEXT,
359 * Test if 2 by 2 block breaks into two 1 by 1 blocks
362 IF( T( HERE+1, HERE ).EQ.ZERO )
368 * Current block consists of two 1 by 1 blocks each of which
369 * must be swapped individually
373 IF( T( HERE-1, HERE-2 ).NE.ZERO )
376 CALL DLAEXC( WANTQ, N, T, LDT, Q, LDQ, HERE-NBNEXT, NBNEXT,
382 IF( NBNEXT.EQ.1 ) THEN
384 * Swap two 1 by 1 blocks, no problems possible
386 CALL DLAEXC( WANTQ, N, T, LDT, Q, LDQ, HERE, NBNEXT, 1,
391 * Recompute NBNEXT in case 2 by 2 split
393 IF( T( HERE, HERE-1 ).EQ.ZERO )
395 IF( NBNEXT.EQ.2 ) THEN
397 * 2 by 2 Block did not split
399 CALL DLAEXC( WANTQ, N, T, LDT, Q, LDQ, HERE-1, 2, 1,
408 * 2 by 2 Block did split
410 CALL DLAEXC( WANTQ, N, T, LDT, Q, LDQ, HERE, 1, 1,
412 CALL DLAEXC( WANTQ, N, T, LDT, Q, LDQ, HERE-1, 1, 1,