3 * =========== DOCUMENTATION ===========
5 * Online html documentation available at
6 * http://www.netlib.org/lapack/explore-html/
9 *> Download STREXC + dependencies
10 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/strexc.f">
12 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/strexc.f">
14 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/strexc.f">
21 * SUBROUTINE STREXC( COMPQ, N, T, LDT, Q, LDQ, IFST, ILST, WORK,
24 * .. Scalar Arguments ..
26 * INTEGER IFST, ILST, INFO, LDQ, LDT, N
28 * .. Array Arguments ..
29 * REAL Q( LDQ, * ), T( LDT, * ), WORK( * )
38 *> STREXC 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 SHSEQR), 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.
66 *> If N == 0 arguments ILST and IFST may be any value.
71 *> T is REAL array, dimension (LDT,N)
72 *> On entry, the upper quasi-triangular matrix T, in Schur
73 *> Schur canonical form.
74 *> On exit, the reordered upper quasi-triangular matrix, again
75 *> in Schur canonical form.
81 *> The leading dimension of the array T. LDT >= max(1,N).
86 *> Q is REAL array, dimension (LDQ,N)
87 *> On entry, if COMPQ = 'V', the matrix Q of Schur vectors.
88 *> On exit, if COMPQ = 'V', Q has been postmultiplied by the
89 *> orthogonal transformation matrix Z which reorders T.
90 *> If COMPQ = 'N', Q is not referenced.
96 *> The leading dimension of the array Q. LDQ >= 1, and if
97 *> COMPQ = 'V', LDQ >= max(1,N).
100 *> \param[in,out] IFST
105 *> \param[in,out] ILST
109 *> Specify the reordering of the diagonal blocks of T.
110 *> The block with row index IFST is moved to row ILST, by a
111 *> sequence of transpositions between adjacent blocks.
112 *> On exit, if IFST pointed on entry to the second row of a
113 *> 2-by-2 block, it is changed to point to the first row; ILST
114 *> always points to the first row of the block in its final
115 *> position (which may differ from its input value by +1 or -1).
116 *> 1 <= IFST <= N; 1 <= ILST <= N.
121 *> WORK is REAL array, dimension (N)
127 *> = 0: successful exit
128 *> < 0: if INFO = -i, the i-th argument had an illegal value
129 *> = 1: two adjacent blocks were too close to swap (the problem
130 *> is very ill-conditioned); T may have been partially
131 *> reordered, and ILST points to the first row of the
132 *> current position of the block being moved.
138 *> \author Univ. of Tennessee
139 *> \author Univ. of California Berkeley
140 *> \author Univ. of Colorado Denver
143 *> \date November 2011
145 *> \ingroup realOTHERcomputational
147 * =====================================================================
148 SUBROUTINE STREXC( COMPQ, N, T, LDT, Q, LDQ, IFST, ILST, WORK,
151 * -- LAPACK computational routine (version 3.4.0) --
152 * -- LAPACK is a software package provided by Univ. of Tennessee, --
153 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
156 * .. Scalar Arguments ..
158 INTEGER IFST, ILST, INFO, LDQ, LDT, N
160 * .. Array Arguments ..
161 REAL Q( LDQ, * ), T( LDT, * ), WORK( * )
164 * =====================================================================
168 PARAMETER ( ZERO = 0.0E+0 )
170 * .. Local Scalars ..
172 INTEGER HERE, NBF, NBL, NBNEXT
174 * .. External Functions ..
178 * .. External Subroutines ..
179 EXTERNAL SLAEXC, XERBLA
181 * .. Intrinsic Functions ..
184 * .. Executable Statements ..
186 * Decode and test the input arguments.
189 WANTQ = LSAME( COMPQ, 'V' )
190 IF( .NOT.WANTQ .AND. .NOT.LSAME( COMPQ, 'N' ) ) THEN
192 ELSE IF( N.LT.0 ) THEN
194 ELSE IF( LDT.LT.MAX( 1, N ) ) THEN
196 ELSE IF( LDQ.LT.1 .OR. ( WANTQ .AND. LDQ.LT.MAX( 1, N ) ) ) THEN
198 ELSE IF(( IFST.LT.1 .OR. IFST.GT.N ).AND.( N.GT.0 )) THEN
200 ELSE IF(( ILST.LT.1 .OR. ILST.GT.N ).AND.( N.GT.0 )) THEN
204 CALL XERBLA( 'STREXC', -INFO )
208 * Quick return if possible
213 * Determine the first row of specified block
214 * and find out it is 1 by 1 or 2 by 2.
217 IF( T( IFST, IFST-1 ).NE.ZERO )
222 IF( T( IFST+1, IFST ).NE.ZERO )
226 * Determine the first row of the final block
227 * and find out it is 1 by 1 or 2 by 2.
230 IF( T( ILST, ILST-1 ).NE.ZERO )
235 IF( T( ILST+1, ILST ).NE.ZERO )
242 IF( IFST.LT.ILST ) THEN
246 IF( NBF.EQ.2 .AND. NBL.EQ.1 )
248 IF( NBF.EQ.1 .AND. NBL.EQ.2 )
255 * Swap block with next one below
257 IF( NBF.EQ.1 .OR. NBF.EQ.2 ) THEN
259 * Current block either 1 by 1 or 2 by 2
262 IF( HERE+NBF+1.LE.N ) THEN
263 IF( T( HERE+NBF+1, HERE+NBF ).NE.ZERO )
266 CALL SLAEXC( WANTQ, N, T, LDT, Q, LDQ, HERE, NBF, NBNEXT,
274 * Test if 2 by 2 block breaks into two 1 by 1 blocks
277 IF( T( HERE+1, HERE ).EQ.ZERO )
283 * Current block consists of two 1 by 1 blocks each of which
284 * must be swapped individually
287 IF( HERE+3.LE.N ) THEN
288 IF( T( HERE+3, HERE+2 ).NE.ZERO )
291 CALL SLAEXC( WANTQ, N, T, LDT, Q, LDQ, HERE+1, 1, NBNEXT,
297 IF( NBNEXT.EQ.1 ) THEN
299 * Swap two 1 by 1 blocks, no problems possible
301 CALL SLAEXC( WANTQ, N, T, LDT, Q, LDQ, HERE, 1, NBNEXT,
306 * Recompute NBNEXT in case 2 by 2 split
308 IF( T( HERE+2, HERE+1 ).EQ.ZERO )
310 IF( NBNEXT.EQ.2 ) THEN
312 * 2 by 2 Block did not split
314 CALL SLAEXC( WANTQ, N, T, LDT, Q, LDQ, HERE, 1,
315 $ NBNEXT, WORK, INFO )
323 * 2 by 2 Block did split
325 CALL SLAEXC( WANTQ, N, T, LDT, Q, LDQ, HERE, 1, 1,
327 CALL SLAEXC( WANTQ, N, T, LDT, Q, LDQ, HERE+1, 1, 1,
341 * Swap block with next one above
343 IF( NBF.EQ.1 .OR. NBF.EQ.2 ) THEN
345 * Current block either 1 by 1 or 2 by 2
349 IF( T( HERE-1, HERE-2 ).NE.ZERO )
352 CALL SLAEXC( WANTQ, N, T, LDT, Q, LDQ, HERE-NBNEXT, NBNEXT,
360 * Test if 2 by 2 block breaks into two 1 by 1 blocks
363 IF( T( HERE+1, HERE ).EQ.ZERO )
369 * Current block consists of two 1 by 1 blocks each of which
370 * must be swapped individually
374 IF( T( HERE-1, HERE-2 ).NE.ZERO )
377 CALL SLAEXC( WANTQ, N, T, LDT, Q, LDQ, HERE-NBNEXT, NBNEXT,
383 IF( NBNEXT.EQ.1 ) THEN
385 * Swap two 1 by 1 blocks, no problems possible
387 CALL SLAEXC( WANTQ, N, T, LDT, Q, LDQ, HERE, NBNEXT, 1,
392 * Recompute NBNEXT in case 2 by 2 split
394 IF( T( HERE, HERE-1 ).EQ.ZERO )
396 IF( NBNEXT.EQ.2 ) THEN
398 * 2 by 2 Block did not split
400 CALL SLAEXC( WANTQ, N, T, LDT, Q, LDQ, HERE-1, 2, 1,
409 * 2 by 2 Block did split
411 CALL SLAEXC( WANTQ, N, T, LDT, Q, LDQ, HERE, 1, 1,
413 CALL SLAEXC( WANTQ, N, T, LDT, Q, LDQ, HERE-1, 1, 1,