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 complex c_b2 = {1.f,0.f};
00019 static integer c__1 = 1;
00020
00021 int ctrevc_(char *side, char *howmny, logical *select,
00022 integer *n, complex *t, integer *ldt, complex *vl, integer *ldvl,
00023 complex *vr, integer *ldvr, integer *mm, integer *m, complex *work,
00024 real *rwork, integer *info)
00025 {
00026
00027 integer t_dim1, t_offset, vl_dim1, vl_offset, vr_dim1, vr_offset, i__1,
00028 i__2, i__3, i__4, i__5;
00029 real r__1, r__2, r__3;
00030 complex q__1, q__2;
00031
00032
00033 double r_imag(complex *);
00034 void r_cnjg(complex *, complex *);
00035
00036
00037 integer i__, j, k, ii, ki, is;
00038 real ulp;
00039 logical allv;
00040 real unfl, ovfl, smin;
00041 logical over;
00042 real scale;
00043 extern logical lsame_(char *, char *);
00044 extern int cgemv_(char *, integer *, integer *, complex *
00045 , complex *, integer *, complex *, integer *, complex *, complex *
00046 , integer *);
00047 real remax;
00048 extern int ccopy_(integer *, complex *, integer *,
00049 complex *, integer *);
00050 logical leftv, bothv, somev;
00051 extern int slabad_(real *, real *);
00052 extern integer icamax_(integer *, complex *, integer *);
00053 extern doublereal slamch_(char *);
00054 extern int csscal_(integer *, real *, complex *, integer
00055 *), xerbla_(char *, integer *), clatrs_(char *, char *,
00056 char *, char *, integer *, complex *, integer *, complex *, real *
00057 , real *, integer *);
00058 extern doublereal scasum_(integer *, complex *, integer *);
00059 logical rightv;
00060 real smlnum;
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
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211 --select;
00212 t_dim1 = *ldt;
00213 t_offset = 1 + t_dim1;
00214 t -= t_offset;
00215 vl_dim1 = *ldvl;
00216 vl_offset = 1 + vl_dim1;
00217 vl -= vl_offset;
00218 vr_dim1 = *ldvr;
00219 vr_offset = 1 + vr_dim1;
00220 vr -= vr_offset;
00221 --work;
00222 --rwork;
00223
00224
00225 bothv = lsame_(side, "B");
00226 rightv = lsame_(side, "R") || bothv;
00227 leftv = lsame_(side, "L") || bothv;
00228
00229 allv = lsame_(howmny, "A");
00230 over = lsame_(howmny, "B");
00231 somev = lsame_(howmny, "S");
00232
00233
00234
00235
00236 if (somev) {
00237 *m = 0;
00238 i__1 = *n;
00239 for (j = 1; j <= i__1; ++j) {
00240 if (select[j]) {
00241 ++(*m);
00242 }
00243
00244 }
00245 } else {
00246 *m = *n;
00247 }
00248
00249 *info = 0;
00250 if (! rightv && ! leftv) {
00251 *info = -1;
00252 } else if (! allv && ! over && ! somev) {
00253 *info = -2;
00254 } else if (*n < 0) {
00255 *info = -4;
00256 } else if (*ldt < max(1,*n)) {
00257 *info = -6;
00258 } else if (*ldvl < 1 || leftv && *ldvl < *n) {
00259 *info = -8;
00260 } else if (*ldvr < 1 || rightv && *ldvr < *n) {
00261 *info = -10;
00262 } else if (*mm < *m) {
00263 *info = -11;
00264 }
00265 if (*info != 0) {
00266 i__1 = -(*info);
00267 xerbla_("CTREVC", &i__1);
00268 return 0;
00269 }
00270
00271
00272
00273 if (*n == 0) {
00274 return 0;
00275 }
00276
00277
00278
00279 unfl = slamch_("Safe minimum");
00280 ovfl = 1.f / unfl;
00281 slabad_(&unfl, &ovfl);
00282 ulp = slamch_("Precision");
00283 smlnum = unfl * (*n / ulp);
00284
00285
00286
00287 i__1 = *n;
00288 for (i__ = 1; i__ <= i__1; ++i__) {
00289 i__2 = i__ + *n;
00290 i__3 = i__ + i__ * t_dim1;
00291 work[i__2].r = t[i__3].r, work[i__2].i = t[i__3].i;
00292
00293 }
00294
00295
00296
00297
00298 rwork[1] = 0.f;
00299 i__1 = *n;
00300 for (j = 2; j <= i__1; ++j) {
00301 i__2 = j - 1;
00302 rwork[j] = scasum_(&i__2, &t[j * t_dim1 + 1], &c__1);
00303
00304 }
00305
00306 if (rightv) {
00307
00308
00309
00310 is = *m;
00311 for (ki = *n; ki >= 1; --ki) {
00312
00313 if (somev) {
00314 if (! select[ki]) {
00315 goto L80;
00316 }
00317 }
00318
00319 i__1 = ki + ki * t_dim1;
00320 r__3 = ulp * ((r__1 = t[i__1].r, dabs(r__1)) + (r__2 = r_imag(&t[
00321 ki + ki * t_dim1]), dabs(r__2)));
00322 smin = dmax(r__3,smlnum);
00323
00324 work[1].r = 1.f, work[1].i = 0.f;
00325
00326
00327
00328 i__1 = ki - 1;
00329 for (k = 1; k <= i__1; ++k) {
00330 i__2 = k;
00331 i__3 = k + ki * t_dim1;
00332 q__1.r = -t[i__3].r, q__1.i = -t[i__3].i;
00333 work[i__2].r = q__1.r, work[i__2].i = q__1.i;
00334
00335 }
00336
00337
00338
00339
00340 i__1 = ki - 1;
00341 for (k = 1; k <= i__1; ++k) {
00342 i__2 = k + k * t_dim1;
00343 i__3 = k + k * t_dim1;
00344 i__4 = ki + ki * t_dim1;
00345 q__1.r = t[i__3].r - t[i__4].r, q__1.i = t[i__3].i - t[i__4]
00346 .i;
00347 t[i__2].r = q__1.r, t[i__2].i = q__1.i;
00348 i__2 = k + k * t_dim1;
00349 if ((r__1 = t[i__2].r, dabs(r__1)) + (r__2 = r_imag(&t[k + k *
00350 t_dim1]), dabs(r__2)) < smin) {
00351 i__3 = k + k * t_dim1;
00352 t[i__3].r = smin, t[i__3].i = 0.f;
00353 }
00354
00355 }
00356
00357 if (ki > 1) {
00358 i__1 = ki - 1;
00359 clatrs_("Upper", "No transpose", "Non-unit", "Y", &i__1, &t[
00360 t_offset], ldt, &work[1], &scale, &rwork[1], info);
00361 i__1 = ki;
00362 work[i__1].r = scale, work[i__1].i = 0.f;
00363 }
00364
00365
00366
00367 if (! over) {
00368 ccopy_(&ki, &work[1], &c__1, &vr[is * vr_dim1 + 1], &c__1);
00369
00370 ii = icamax_(&ki, &vr[is * vr_dim1 + 1], &c__1);
00371 i__1 = ii + is * vr_dim1;
00372 remax = 1.f / ((r__1 = vr[i__1].r, dabs(r__1)) + (r__2 =
00373 r_imag(&vr[ii + is * vr_dim1]), dabs(r__2)));
00374 csscal_(&ki, &remax, &vr[is * vr_dim1 + 1], &c__1);
00375
00376 i__1 = *n;
00377 for (k = ki + 1; k <= i__1; ++k) {
00378 i__2 = k + is * vr_dim1;
00379 vr[i__2].r = 0.f, vr[i__2].i = 0.f;
00380
00381 }
00382 } else {
00383 if (ki > 1) {
00384 i__1 = ki - 1;
00385 q__1.r = scale, q__1.i = 0.f;
00386 cgemv_("N", n, &i__1, &c_b2, &vr[vr_offset], ldvr, &work[
00387 1], &c__1, &q__1, &vr[ki * vr_dim1 + 1], &c__1);
00388 }
00389
00390 ii = icamax_(n, &vr[ki * vr_dim1 + 1], &c__1);
00391 i__1 = ii + ki * vr_dim1;
00392 remax = 1.f / ((r__1 = vr[i__1].r, dabs(r__1)) + (r__2 =
00393 r_imag(&vr[ii + ki * vr_dim1]), dabs(r__2)));
00394 csscal_(n, &remax, &vr[ki * vr_dim1 + 1], &c__1);
00395 }
00396
00397
00398
00399 i__1 = ki - 1;
00400 for (k = 1; k <= i__1; ++k) {
00401 i__2 = k + k * t_dim1;
00402 i__3 = k + *n;
00403 t[i__2].r = work[i__3].r, t[i__2].i = work[i__3].i;
00404
00405 }
00406
00407 --is;
00408 L80:
00409 ;
00410 }
00411 }
00412
00413 if (leftv) {
00414
00415
00416
00417 is = 1;
00418 i__1 = *n;
00419 for (ki = 1; ki <= i__1; ++ki) {
00420
00421 if (somev) {
00422 if (! select[ki]) {
00423 goto L130;
00424 }
00425 }
00426
00427 i__2 = ki + ki * t_dim1;
00428 r__3 = ulp * ((r__1 = t[i__2].r, dabs(r__1)) + (r__2 = r_imag(&t[
00429 ki + ki * t_dim1]), dabs(r__2)));
00430 smin = dmax(r__3,smlnum);
00431
00432 i__2 = *n;
00433 work[i__2].r = 1.f, work[i__2].i = 0.f;
00434
00435
00436
00437 i__2 = *n;
00438 for (k = ki + 1; k <= i__2; ++k) {
00439 i__3 = k;
00440 r_cnjg(&q__2, &t[ki + k * t_dim1]);
00441 q__1.r = -q__2.r, q__1.i = -q__2.i;
00442 work[i__3].r = q__1.r, work[i__3].i = q__1.i;
00443
00444 }
00445
00446
00447
00448
00449 i__2 = *n;
00450 for (k = ki + 1; k <= i__2; ++k) {
00451 i__3 = k + k * t_dim1;
00452 i__4 = k + k * t_dim1;
00453 i__5 = ki + ki * t_dim1;
00454 q__1.r = t[i__4].r - t[i__5].r, q__1.i = t[i__4].i - t[i__5]
00455 .i;
00456 t[i__3].r = q__1.r, t[i__3].i = q__1.i;
00457 i__3 = k + k * t_dim1;
00458 if ((r__1 = t[i__3].r, dabs(r__1)) + (r__2 = r_imag(&t[k + k *
00459 t_dim1]), dabs(r__2)) < smin) {
00460 i__4 = k + k * t_dim1;
00461 t[i__4].r = smin, t[i__4].i = 0.f;
00462 }
00463
00464 }
00465
00466 if (ki < *n) {
00467 i__2 = *n - ki;
00468 clatrs_("Upper", "Conjugate transpose", "Non-unit", "Y", &
00469 i__2, &t[ki + 1 + (ki + 1) * t_dim1], ldt, &work[ki +
00470 1], &scale, &rwork[1], info);
00471 i__2 = ki;
00472 work[i__2].r = scale, work[i__2].i = 0.f;
00473 }
00474
00475
00476
00477 if (! over) {
00478 i__2 = *n - ki + 1;
00479 ccopy_(&i__2, &work[ki], &c__1, &vl[ki + is * vl_dim1], &c__1)
00480 ;
00481
00482 i__2 = *n - ki + 1;
00483 ii = icamax_(&i__2, &vl[ki + is * vl_dim1], &c__1) + ki - 1;
00484 i__2 = ii + is * vl_dim1;
00485 remax = 1.f / ((r__1 = vl[i__2].r, dabs(r__1)) + (r__2 =
00486 r_imag(&vl[ii + is * vl_dim1]), dabs(r__2)));
00487 i__2 = *n - ki + 1;
00488 csscal_(&i__2, &remax, &vl[ki + is * vl_dim1], &c__1);
00489
00490 i__2 = ki - 1;
00491 for (k = 1; k <= i__2; ++k) {
00492 i__3 = k + is * vl_dim1;
00493 vl[i__3].r = 0.f, vl[i__3].i = 0.f;
00494
00495 }
00496 } else {
00497 if (ki < *n) {
00498 i__2 = *n - ki;
00499 q__1.r = scale, q__1.i = 0.f;
00500 cgemv_("N", n, &i__2, &c_b2, &vl[(ki + 1) * vl_dim1 + 1],
00501 ldvl, &work[ki + 1], &c__1, &q__1, &vl[ki *
00502 vl_dim1 + 1], &c__1);
00503 }
00504
00505 ii = icamax_(n, &vl[ki * vl_dim1 + 1], &c__1);
00506 i__2 = ii + ki * vl_dim1;
00507 remax = 1.f / ((r__1 = vl[i__2].r, dabs(r__1)) + (r__2 =
00508 r_imag(&vl[ii + ki * vl_dim1]), dabs(r__2)));
00509 csscal_(n, &remax, &vl[ki * vl_dim1 + 1], &c__1);
00510 }
00511
00512
00513
00514 i__2 = *n;
00515 for (k = ki + 1; k <= i__2; ++k) {
00516 i__3 = k + k * t_dim1;
00517 i__4 = k + *n;
00518 t[i__3].r = work[i__4].r, t[i__3].i = work[i__4].i;
00519
00520 }
00521
00522 ++is;
00523 L130:
00524 ;
00525 }
00526 }
00527
00528 return 0;
00529
00530
00531
00532 }