1 /* lapack/complex16/ztrexc.f -- translated by f2c (version 20090411).
2    You must link the resulting object file with libf2c:
3         on Microsoft Windows system, link with libf2c.lib;
4         on Linux or Unix systems, link with .../path/to/libf2c.a -lm
5         or, if you install libf2c.a in a standard place, with -lf2c -lm
6         -- in that order, at the end of the command line, as in
7                 cc *.o -lf2c -lm
8         Source for libf2c is in /netlib/f2c/libf2c.zip, e.g.,
9 
10                 http://www.netlib.org/f2c/libf2c.zip
11 */
12 
13 #ifdef __cplusplus
14 extern "C" {
15 #endif
16 #include "v3p_netlib.h"
17 
18 /* Table of constant values */
19 
20 static integer c__1 = 1;
21 
22 /*<       SUBROUTINE ZTREXC( COMPQ, N, T, LDT, Q, LDQ, IFST, ILST, INFO ) >*/
ztrexc_(char * compq,integer * n,doublecomplex * t,integer * ldt,doublecomplex * q,integer * ldq,integer * ifst,integer * ilst,integer * info,ftnlen compq_len)23 /* Subroutine */ int ztrexc_(char *compq, integer *n, doublecomplex *t,
24         integer *ldt, doublecomplex *q, integer *ldq, integer *ifst, integer *
25         ilst, integer *info, ftnlen compq_len)
26 {
27     /* System generated locals */
28     integer q_dim1, q_offset, t_dim1, t_offset, i__1, i__2, i__3;
29     doublecomplex z__1;
30 
31     /* Builtin functions */
32     void d_cnjg(doublecomplex *, doublecomplex *);
33 
34     /* Local variables */
35     integer k, m1, m2, m3;
36     doublereal cs;
37     doublecomplex t11, t22, sn, temp;
38     extern /* Subroutine */ int zrot_(integer *, doublecomplex *, integer *,
39             doublecomplex *, integer *, doublereal *, doublecomplex *);
40     extern logical lsame_(const char *, const char *, ftnlen, ftnlen);
41     logical wantq;
42     extern /* Subroutine */ int xerbla_(char *, integer *, ftnlen), zlartg_(
43             doublecomplex *, doublecomplex *, doublereal *, doublecomplex *,
44             doublecomplex *);
45      (void)compq_len;
46 
47 /*  -- LAPACK routine (version 3.2) -- */
48 /*  -- LAPACK is a software package provided by Univ. of Tennessee,    -- */
49 /*  -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
50 /*     November 2006 */
51 
52 /*     .. Scalar Arguments .. */
53 /*<       CHARACTER          COMPQ >*/
54 /*<       INTEGER            IFST, ILST, INFO, LDQ, LDT, N >*/
55 /*     .. */
56 /*     .. Array Arguments .. */
57 /*<       COMPLEX*16         Q( LDQ, * ), T( LDT, * ) >*/
58 /*     .. */
59 
60 /*  Purpose */
61 /*  ======= */
62 
63 /*  ZTREXC reorders the Schur factorization of a complex matrix */
64 /*  A = Q*T*Q**H, so that the diagonal element of T with row index IFST */
65 /*  is moved to row ILST. */
66 
67 /*  The Schur form T is reordered by a unitary similarity transformation */
68 /*  Z**H*T*Z, and optionally the matrix Q of Schur vectors is updated by */
69 /*  postmultplying it with Z. */
70 
71 /*  Arguments */
72 /*  ========= */
73 
74 /*  COMPQ   (input) CHARACTER*1 */
75 /*          = 'V':  update the matrix Q of Schur vectors; */
76 /*          = 'N':  do not update Q. */
77 
78 /*  N       (input) INTEGER */
79 /*          The order of the matrix T. N >= 0. */
80 
81 /*  T       (input/output) COMPLEX*16 array, dimension (LDT,N) */
82 /*          On entry, the upper triangular matrix T. */
83 /*          On exit, the reordered upper triangular matrix. */
84 
85 /*  LDT     (input) INTEGER */
86 /*          The leading dimension of the array T. LDT >= max(1,N). */
87 
88 /*  Q       (input/output) COMPLEX*16 array, dimension (LDQ,N) */
89 /*          On entry, if COMPQ = 'V', the matrix Q of Schur vectors. */
90 /*          On exit, if COMPQ = 'V', Q has been postmultiplied by the */
91 /*          unitary transformation matrix Z which reorders T. */
92 /*          If COMPQ = 'N', Q is not referenced. */
93 
94 /*  LDQ     (input) INTEGER */
95 /*          The leading dimension of the array Q.  LDQ >= max(1,N). */
96 
97 /*  IFST    (input) INTEGER */
98 /*  ILST    (input) INTEGER */
99 /*          Specify the reordering of the diagonal elements of T: */
100 /*          The element with row index IFST is moved to row ILST by a */
101 /*          sequence of transpositions between adjacent elements. */
102 /*          1 <= IFST <= N; 1 <= ILST <= N. */
103 
104 /*  INFO    (output) INTEGER */
105 /*          = 0:  successful exit */
106 /*          < 0:  if INFO = -i, the i-th argument had an illegal value */
107 
108 /*  ===================================================================== */
109 
110 /*     .. Local Scalars .. */
111 /*<       LOGICAL            WANTQ >*/
112 /*<       INTEGER            K, M1, M2, M3 >*/
113 /*<       DOUBLE PRECISION   CS >*/
114 /*<       COMPLEX*16         SN, T11, T22, TEMP >*/
115 /*     .. */
116 /*     .. External Functions .. */
117 /*<       LOGICAL            LSAME >*/
118 /*<       EXTERNAL           LSAME >*/
119 /*     .. */
120 /*     .. External Subroutines .. */
121 /*<       EXTERNAL           XERBLA, ZLARTG, ZROT >*/
122 /*     .. */
123 /*     .. Intrinsic Functions .. */
124 /*<       INTRINSIC          DCONJG, MAX >*/
125 /*     .. */
126 /*     .. Executable Statements .. */
127 
128 /*     Decode and test the input parameters. */
129 
130 /*<       INFO = 0 >*/
131     /* Parameter adjustments */
132     t_dim1 = *ldt;
133     t_offset = 1 + t_dim1;
134     t -= t_offset;
135     q_dim1 = *ldq;
136     q_offset = 1 + q_dim1;
137     q -= q_offset;
138 
139     /* Function Body */
140     *info = 0;
141 /*<       WANTQ = LSAME( COMPQ, 'V' ) >*/
142     wantq = lsame_(compq, "V", (ftnlen)1, (ftnlen)1);
143 /*<       IF( .NOT.LSAME( COMPQ, 'N' ) .AND. .NOT.WANTQ ) THEN >*/
144     if (! lsame_(compq, "N", (ftnlen)1, (ftnlen)1) && ! wantq) {
145 /*<          INFO = -1 >*/
146         *info = -1;
147 /*<       ELSE IF( N.LT.0 ) THEN >*/
148     } else if (*n < 0) {
149 /*<          INFO = -2 >*/
150         *info = -2;
151 /*<       ELSE IF( LDT.LT.MAX( 1, N ) ) THEN >*/
152     } else if (*ldt < max(1,*n)) {
153 /*<          INFO = -4 >*/
154         *info = -4;
155 /*<       ELSE IF( LDQ.LT.1 .OR. ( WANTQ .AND. LDQ.LT.MAX( 1, N ) ) ) THEN >*/
156     } else if (*ldq < 1 || (wantq && *ldq < max(1,*n))) {
157 /*<          INFO = -6 >*/
158         *info = -6;
159 /*<       ELSE IF( IFST.LT.1 .OR. IFST.GT.N ) THEN >*/
160     } else if (*ifst < 1 || *ifst > *n) {
161 /*<          INFO = -7 >*/
162         *info = -7;
163 /*<       ELSE IF( ILST.LT.1 .OR. ILST.GT.N ) THEN >*/
164     } else if (*ilst < 1 || *ilst > *n) {
165 /*<          INFO = -8 >*/
166         *info = -8;
167 /*<       END IF >*/
168     }
169 /*<       IF( INFO.NE.0 ) THEN >*/
170     if (*info != 0) {
171 /*<          CALL XERBLA( 'ZTREXC', -INFO ) >*/
172         i__1 = -(*info);
173         xerbla_("ZTREXC", &i__1, (ftnlen)6);
174 /*<          RETURN >*/
175         return 0;
176 /*<       END IF >*/
177     }
178 
179 /*     Quick return if possible */
180 
181 /*<    >*/
182     if (*n == 1 || *ifst == *ilst) {
183         return 0;
184     }
185 
186 /*<       IF( IFST.LT.ILST ) THEN >*/
187     if (*ifst < *ilst) {
188 
189 /*        Move the IFST-th diagonal element forward down the diagonal. */
190 
191 /*<          M1 = 0 >*/
192         m1 = 0;
193 /*<          M2 = -1 >*/
194         m2 = -1;
195 /*<          M3 = 1 >*/
196         m3 = 1;
197 /*<       ELSE >*/
198     } else {
199 
200 /*        Move the IFST-th diagonal element backward up the diagonal. */
201 
202 /*<          M1 = -1 >*/
203         m1 = -1;
204 /*<          M2 = 0 >*/
205         m2 = 0;
206 /*<          M3 = -1 >*/
207         m3 = -1;
208 /*<       END IF >*/
209     }
210 
211 /*<       DO 10 K = IFST + M1, ILST + M2, M3 >*/
212     i__1 = *ilst + m2;
213     i__2 = m3;
214     for (k = *ifst + m1; i__2 < 0 ? k >= i__1 : k <= i__1; k += i__2) {
215 
216 /*        Interchange the k-th and (k+1)-th diagonal elements. */
217 
218 /*<          T11 = T( K, K ) >*/
219         i__3 = k + k * t_dim1;
220         t11.r = t[i__3].r, t11.i = t[i__3].i;
221 /*<          T22 = T( K+1, K+1 ) >*/
222         i__3 = k + 1 + (k + 1) * t_dim1;
223         t22.r = t[i__3].r, t22.i = t[i__3].i;
224 
225 /*        Determine the transformation to perform the interchange. */
226 
227 /*<          CALL ZLARTG( T( K, K+1 ), T22-T11, CS, SN, TEMP ) >*/
228         z__1.r = t22.r - t11.r, z__1.i = t22.i - t11.i;
229         zlartg_(&t[k + (k + 1) * t_dim1], &z__1, &cs, &sn, &temp);
230 
231 /*        Apply transformation to the matrix T. */
232 
233 /*<    >*/
234         if (k + 2 <= *n) {
235             i__3 = *n - k - 1;
236             zrot_(&i__3, &t[k + (k + 2) * t_dim1], ldt, &t[k + 1 + (k + 2) *
237                     t_dim1], ldt, &cs, &sn);
238         }
239 /*<    >*/
240         i__3 = k - 1;
241         d_cnjg(&z__1, &sn);
242         zrot_(&i__3, &t[k * t_dim1 + 1], &c__1, &t[(k + 1) * t_dim1 + 1], &
243                 c__1, &cs, &z__1);
244 
245 /*<          T( K, K ) = T22 >*/
246         i__3 = k + k * t_dim1;
247         t[i__3].r = t22.r, t[i__3].i = t22.i;
248 /*<          T( K+1, K+1 ) = T11 >*/
249         i__3 = k + 1 + (k + 1) * t_dim1;
250         t[i__3].r = t11.r, t[i__3].i = t11.i;
251 
252 /*<          IF( WANTQ ) THEN >*/
253         if (wantq) {
254 
255 /*           Accumulate transformation in the matrix Q. */
256 
257 /*<    >*/
258             d_cnjg(&z__1, &sn);
259             zrot_(n, &q[k * q_dim1 + 1], &c__1, &q[(k + 1) * q_dim1 + 1], &
260                     c__1, &cs, &z__1);
261 /*<          END IF >*/
262         }
263 
264 /*<    10 CONTINUE >*/
265 /* L10: */
266     }
267 
268 /*<       RETURN >*/
269     return 0;
270 
271 /*     End of ZTREXC */
272 
273 /*<       END >*/
274 } /* ztrexc_ */
275 
276 #ifdef __cplusplus
277         }
278 #endif
279