00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #include "f2c.h"
00014 #include "blaswrap.h"
00015
00016
00017
00018 static integer c__2 = 2;
00019 static integer c__1 = 1;
00020
00021 int ztgex2_(logical *wantq, logical *wantz, integer *n,
00022 doublecomplex *a, integer *lda, doublecomplex *b, integer *ldb,
00023 doublecomplex *q, integer *ldq, doublecomplex *z__, integer *ldz,
00024 integer *j1, integer *info)
00025 {
00026
00027 integer a_dim1, a_offset, b_dim1, b_offset, q_dim1, q_offset, z_dim1,
00028 z_offset, i__1, i__2, i__3;
00029 doublereal d__1;
00030 doublecomplex z__1, z__2, z__3;
00031
00032
00033 double sqrt(doublereal), z_abs(doublecomplex *);
00034 void d_cnjg(doublecomplex *, doublecomplex *);
00035
00036
00037 doublecomplex f, g;
00038 integer i__, m;
00039 doublecomplex s[4] , t[4] ;
00040 doublereal cq, sa, sb, cz;
00041 doublecomplex sq;
00042 doublereal ss, ws;
00043 doublecomplex sz;
00044 doublereal eps, sum;
00045 logical weak;
00046 doublecomplex cdum, work[8];
00047 extern int zrot_(integer *, doublecomplex *, integer *,
00048 doublecomplex *, integer *, doublereal *, doublecomplex *);
00049 doublereal scale;
00050 extern doublereal dlamch_(char *);
00051 logical dtrong;
00052 doublereal thresh;
00053 extern int zlacpy_(char *, integer *, integer *,
00054 doublecomplex *, integer *, doublecomplex *, integer *),
00055 zlartg_(doublecomplex *, doublecomplex *, doublereal *,
00056 doublecomplex *, doublecomplex *);
00057 doublereal smlnum;
00058 extern int zlassq_(integer *, doublecomplex *, integer *,
00059 doublereal *, doublereal *);
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185 a_dim1 = *lda;
00186 a_offset = 1 + a_dim1;
00187 a -= a_offset;
00188 b_dim1 = *ldb;
00189 b_offset = 1 + b_dim1;
00190 b -= b_offset;
00191 q_dim1 = *ldq;
00192 q_offset = 1 + q_dim1;
00193 q -= q_offset;
00194 z_dim1 = *ldz;
00195 z_offset = 1 + z_dim1;
00196 z__ -= z_offset;
00197
00198
00199 *info = 0;
00200
00201
00202
00203 if (*n <= 1) {
00204 return 0;
00205 }
00206
00207 m = 2;
00208 weak = FALSE_;
00209 dtrong = FALSE_;
00210
00211
00212
00213 zlacpy_("Full", &m, &m, &a[*j1 + *j1 * a_dim1], lda, s, &c__2);
00214 zlacpy_("Full", &m, &m, &b[*j1 + *j1 * b_dim1], ldb, t, &c__2);
00215
00216
00217
00218 eps = dlamch_("P");
00219 smlnum = dlamch_("S") / eps;
00220 scale = 0.;
00221 sum = 1.;
00222 zlacpy_("Full", &m, &m, s, &c__2, work, &m);
00223 zlacpy_("Full", &m, &m, t, &c__2, &work[m * m], &m);
00224 i__1 = (m << 1) * m;
00225 zlassq_(&i__1, work, &c__1, &scale, &sum);
00226 sa = scale * sqrt(sum);
00227
00228 d__1 = eps * 10. * sa;
00229 thresh = max(d__1,smlnum);
00230
00231
00232
00233
00234 z__2.r = s[3].r * t[0].r - s[3].i * t[0].i, z__2.i = s[3].r * t[0].i + s[
00235 3].i * t[0].r;
00236 z__3.r = t[3].r * s[0].r - t[3].i * s[0].i, z__3.i = t[3].r * s[0].i + t[
00237 3].i * s[0].r;
00238 z__1.r = z__2.r - z__3.r, z__1.i = z__2.i - z__3.i;
00239 f.r = z__1.r, f.i = z__1.i;
00240 z__2.r = s[3].r * t[2].r - s[3].i * t[2].i, z__2.i = s[3].r * t[2].i + s[
00241 3].i * t[2].r;
00242 z__3.r = t[3].r * s[2].r - t[3].i * s[2].i, z__3.i = t[3].r * s[2].i + t[
00243 3].i * s[2].r;
00244 z__1.r = z__2.r - z__3.r, z__1.i = z__2.i - z__3.i;
00245 g.r = z__1.r, g.i = z__1.i;
00246 sa = z_abs(&s[3]);
00247 sb = z_abs(&t[3]);
00248 zlartg_(&g, &f, &cz, &sz, &cdum);
00249 z__1.r = -sz.r, z__1.i = -sz.i;
00250 sz.r = z__1.r, sz.i = z__1.i;
00251 d_cnjg(&z__1, &sz);
00252 zrot_(&c__2, s, &c__1, &s[2], &c__1, &cz, &z__1);
00253 d_cnjg(&z__1, &sz);
00254 zrot_(&c__2, t, &c__1, &t[2], &c__1, &cz, &z__1);
00255 if (sa >= sb) {
00256 zlartg_(s, &s[1], &cq, &sq, &cdum);
00257 } else {
00258 zlartg_(t, &t[1], &cq, &sq, &cdum);
00259 }
00260 zrot_(&c__2, s, &c__2, &s[1], &c__2, &cq, &sq);
00261 zrot_(&c__2, t, &c__2, &t[1], &c__2, &cq, &sq);
00262
00263
00264
00265 ws = z_abs(&s[1]) + z_abs(&t[1]);
00266 weak = ws <= thresh;
00267 if (! weak) {
00268 goto L20;
00269 }
00270
00271 if (TRUE_) {
00272
00273
00274
00275
00276 zlacpy_("Full", &m, &m, s, &c__2, work, &m);
00277 zlacpy_("Full", &m, &m, t, &c__2, &work[m * m], &m);
00278 d_cnjg(&z__2, &sz);
00279 z__1.r = -z__2.r, z__1.i = -z__2.i;
00280 zrot_(&c__2, work, &c__1, &work[2], &c__1, &cz, &z__1);
00281 d_cnjg(&z__2, &sz);
00282 z__1.r = -z__2.r, z__1.i = -z__2.i;
00283 zrot_(&c__2, &work[4], &c__1, &work[6], &c__1, &cz, &z__1);
00284 z__1.r = -sq.r, z__1.i = -sq.i;
00285 zrot_(&c__2, work, &c__2, &work[1], &c__2, &cq, &z__1);
00286 z__1.r = -sq.r, z__1.i = -sq.i;
00287 zrot_(&c__2, &work[4], &c__2, &work[5], &c__2, &cq, &z__1);
00288 for (i__ = 1; i__ <= 2; ++i__) {
00289 i__1 = i__ - 1;
00290 i__2 = i__ - 1;
00291 i__3 = *j1 + i__ - 1 + *j1 * a_dim1;
00292 z__1.r = work[i__2].r - a[i__3].r, z__1.i = work[i__2].i - a[i__3]
00293 .i;
00294 work[i__1].r = z__1.r, work[i__1].i = z__1.i;
00295 i__1 = i__ + 1;
00296 i__2 = i__ + 1;
00297 i__3 = *j1 + i__ - 1 + (*j1 + 1) * a_dim1;
00298 z__1.r = work[i__2].r - a[i__3].r, z__1.i = work[i__2].i - a[i__3]
00299 .i;
00300 work[i__1].r = z__1.r, work[i__1].i = z__1.i;
00301 i__1 = i__ + 3;
00302 i__2 = i__ + 3;
00303 i__3 = *j1 + i__ - 1 + *j1 * b_dim1;
00304 z__1.r = work[i__2].r - b[i__3].r, z__1.i = work[i__2].i - b[i__3]
00305 .i;
00306 work[i__1].r = z__1.r, work[i__1].i = z__1.i;
00307 i__1 = i__ + 5;
00308 i__2 = i__ + 5;
00309 i__3 = *j1 + i__ - 1 + (*j1 + 1) * b_dim1;
00310 z__1.r = work[i__2].r - b[i__3].r, z__1.i = work[i__2].i - b[i__3]
00311 .i;
00312 work[i__1].r = z__1.r, work[i__1].i = z__1.i;
00313
00314 }
00315 scale = 0.;
00316 sum = 1.;
00317 i__1 = (m << 1) * m;
00318 zlassq_(&i__1, work, &c__1, &scale, &sum);
00319 ss = scale * sqrt(sum);
00320 dtrong = ss <= thresh;
00321 if (! dtrong) {
00322 goto L20;
00323 }
00324 }
00325
00326
00327
00328
00329 i__1 = *j1 + 1;
00330 d_cnjg(&z__1, &sz);
00331 zrot_(&i__1, &a[*j1 * a_dim1 + 1], &c__1, &a[(*j1 + 1) * a_dim1 + 1], &
00332 c__1, &cz, &z__1);
00333 i__1 = *j1 + 1;
00334 d_cnjg(&z__1, &sz);
00335 zrot_(&i__1, &b[*j1 * b_dim1 + 1], &c__1, &b[(*j1 + 1) * b_dim1 + 1], &
00336 c__1, &cz, &z__1);
00337 i__1 = *n - *j1 + 1;
00338 zrot_(&i__1, &a[*j1 + *j1 * a_dim1], lda, &a[*j1 + 1 + *j1 * a_dim1], lda,
00339 &cq, &sq);
00340 i__1 = *n - *j1 + 1;
00341 zrot_(&i__1, &b[*j1 + *j1 * b_dim1], ldb, &b[*j1 + 1 + *j1 * b_dim1], ldb,
00342 &cq, &sq);
00343
00344
00345
00346 i__1 = *j1 + 1 + *j1 * a_dim1;
00347 a[i__1].r = 0., a[i__1].i = 0.;
00348 i__1 = *j1 + 1 + *j1 * b_dim1;
00349 b[i__1].r = 0., b[i__1].i = 0.;
00350
00351
00352
00353 if (*wantz) {
00354 d_cnjg(&z__1, &sz);
00355 zrot_(n, &z__[*j1 * z_dim1 + 1], &c__1, &z__[(*j1 + 1) * z_dim1 + 1],
00356 &c__1, &cz, &z__1);
00357 }
00358 if (*wantq) {
00359 d_cnjg(&z__1, &sq);
00360 zrot_(n, &q[*j1 * q_dim1 + 1], &c__1, &q[(*j1 + 1) * q_dim1 + 1], &
00361 c__1, &cq, &z__1);
00362 }
00363
00364
00365
00366 return 0;
00367
00368
00369
00370 L20:
00371 *info = 1;
00372 return 0;
00373
00374
00375
00376 }