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__1 = 1;
00019
00020 int ctrsna_(char *job, char *howmny, logical *select,
00021 integer *n, complex *t, integer *ldt, complex *vl, integer *ldvl,
00022 complex *vr, integer *ldvr, real *s, real *sep, integer *mm, integer *
00023 m, complex *work, integer *ldwork, real *rwork, integer *info)
00024 {
00025
00026 integer t_dim1, t_offset, vl_dim1, vl_offset, vr_dim1, vr_offset,
00027 work_dim1, work_offset, i__1, i__2, i__3, i__4, i__5;
00028 real r__1, r__2;
00029 complex q__1;
00030
00031
00032 double c_abs(complex *), r_imag(complex *);
00033
00034
00035 integer i__, j, k, ks, ix;
00036 real eps, est;
00037 integer kase, ierr;
00038 complex prod;
00039 real lnrm, rnrm, scale;
00040 extern VOID cdotc_(complex *, integer *, complex *, integer
00041 *, complex *, integer *);
00042 extern logical lsame_(char *, char *);
00043 integer isave[3];
00044 complex dummy[1];
00045 logical wants;
00046 extern int clacn2_(integer *, complex *, complex *, real
00047 *, integer *, integer *);
00048 real xnorm;
00049 extern doublereal scnrm2_(integer *, complex *, integer *);
00050 extern int slabad_(real *, real *);
00051 extern integer icamax_(integer *, complex *, integer *);
00052 extern doublereal slamch_(char *);
00053 extern int clacpy_(char *, integer *, integer *, complex
00054 *, integer *, complex *, integer *), xerbla_(char *,
00055 integer *);
00056 real bignum;
00057 logical wantbh;
00058 extern int clatrs_(char *, char *, char *, char *,
00059 integer *, complex *, integer *, complex *, real *, real *,
00060 integer *), csrscl_(integer *,
00061 real *, complex *, integer *), ctrexc_(char *, integer *, complex
00062 *, integer *, complex *, integer *, integer *, integer *, integer
00063 *);
00064 logical somcon;
00065 char normin[1];
00066 real smlnum;
00067 logical wantsp;
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
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242 --select;
00243 t_dim1 = *ldt;
00244 t_offset = 1 + t_dim1;
00245 t -= t_offset;
00246 vl_dim1 = *ldvl;
00247 vl_offset = 1 + vl_dim1;
00248 vl -= vl_offset;
00249 vr_dim1 = *ldvr;
00250 vr_offset = 1 + vr_dim1;
00251 vr -= vr_offset;
00252 --s;
00253 --sep;
00254 work_dim1 = *ldwork;
00255 work_offset = 1 + work_dim1;
00256 work -= work_offset;
00257 --rwork;
00258
00259
00260 wantbh = lsame_(job, "B");
00261 wants = lsame_(job, "E") || wantbh;
00262 wantsp = lsame_(job, "V") || wantbh;
00263
00264 somcon = lsame_(howmny, "S");
00265
00266
00267
00268
00269 if (somcon) {
00270 *m = 0;
00271 i__1 = *n;
00272 for (j = 1; j <= i__1; ++j) {
00273 if (select[j]) {
00274 ++(*m);
00275 }
00276
00277 }
00278 } else {
00279 *m = *n;
00280 }
00281
00282 *info = 0;
00283 if (! wants && ! wantsp) {
00284 *info = -1;
00285 } else if (! lsame_(howmny, "A") && ! somcon) {
00286 *info = -2;
00287 } else if (*n < 0) {
00288 *info = -4;
00289 } else if (*ldt < max(1,*n)) {
00290 *info = -6;
00291 } else if (*ldvl < 1 || wants && *ldvl < *n) {
00292 *info = -8;
00293 } else if (*ldvr < 1 || wants && *ldvr < *n) {
00294 *info = -10;
00295 } else if (*mm < *m) {
00296 *info = -13;
00297 } else if (*ldwork < 1 || wantsp && *ldwork < *n) {
00298 *info = -16;
00299 }
00300 if (*info != 0) {
00301 i__1 = -(*info);
00302 xerbla_("CTRSNA", &i__1);
00303 return 0;
00304 }
00305
00306
00307
00308 if (*n == 0) {
00309 return 0;
00310 }
00311
00312 if (*n == 1) {
00313 if (somcon) {
00314 if (! select[1]) {
00315 return 0;
00316 }
00317 }
00318 if (wants) {
00319 s[1] = 1.f;
00320 }
00321 if (wantsp) {
00322 sep[1] = c_abs(&t[t_dim1 + 1]);
00323 }
00324 return 0;
00325 }
00326
00327
00328
00329 eps = slamch_("P");
00330 smlnum = slamch_("S") / eps;
00331 bignum = 1.f / smlnum;
00332 slabad_(&smlnum, &bignum);
00333
00334 ks = 1;
00335 i__1 = *n;
00336 for (k = 1; k <= i__1; ++k) {
00337
00338 if (somcon) {
00339 if (! select[k]) {
00340 goto L50;
00341 }
00342 }
00343
00344 if (wants) {
00345
00346
00347
00348
00349 cdotc_(&q__1, n, &vr[ks * vr_dim1 + 1], &c__1, &vl[ks * vl_dim1 +
00350 1], &c__1);
00351 prod.r = q__1.r, prod.i = q__1.i;
00352 rnrm = scnrm2_(n, &vr[ks * vr_dim1 + 1], &c__1);
00353 lnrm = scnrm2_(n, &vl[ks * vl_dim1 + 1], &c__1);
00354 s[ks] = c_abs(&prod) / (rnrm * lnrm);
00355
00356 }
00357
00358 if (wantsp) {
00359
00360
00361
00362
00363
00364
00365
00366 clacpy_("Full", n, n, &t[t_offset], ldt, &work[work_offset],
00367 ldwork);
00368 ctrexc_("No Q", n, &work[work_offset], ldwork, dummy, &c__1, &k, &
00369 c__1, &ierr);
00370
00371
00372
00373 i__2 = *n;
00374 for (i__ = 2; i__ <= i__2; ++i__) {
00375 i__3 = i__ + i__ * work_dim1;
00376 i__4 = i__ + i__ * work_dim1;
00377 i__5 = work_dim1 + 1;
00378 q__1.r = work[i__4].r - work[i__5].r, q__1.i = work[i__4].i -
00379 work[i__5].i;
00380 work[i__3].r = q__1.r, work[i__3].i = q__1.i;
00381
00382 }
00383
00384
00385
00386
00387 sep[ks] = 0.f;
00388 est = 0.f;
00389 kase = 0;
00390 *(unsigned char *)normin = 'N';
00391 L30:
00392 i__2 = *n - 1;
00393 clacn2_(&i__2, &work[(*n + 1) * work_dim1 + 1], &work[work_offset]
00394 , &est, &kase, isave);
00395
00396 if (kase != 0) {
00397 if (kase == 1) {
00398
00399
00400
00401 i__2 = *n - 1;
00402 clatrs_("Upper", "Conjugate transpose", "Nonunit", normin,
00403 &i__2, &work[(work_dim1 << 1) + 2], ldwork, &
00404 work[work_offset], &scale, &rwork[1], &ierr);
00405 } else {
00406
00407
00408
00409 i__2 = *n - 1;
00410 clatrs_("Upper", "No transpose", "Nonunit", normin, &i__2,
00411 &work[(work_dim1 << 1) + 2], ldwork, &work[
00412 work_offset], &scale, &rwork[1], &ierr);
00413 }
00414 *(unsigned char *)normin = 'Y';
00415 if (scale != 1.f) {
00416
00417
00418
00419
00420 i__2 = *n - 1;
00421 ix = icamax_(&i__2, &work[work_offset], &c__1);
00422 i__2 = ix + work_dim1;
00423 xnorm = (r__1 = work[i__2].r, dabs(r__1)) + (r__2 =
00424 r_imag(&work[ix + work_dim1]), dabs(r__2));
00425 if (scale < xnorm * smlnum || scale == 0.f) {
00426 goto L40;
00427 }
00428 csrscl_(n, &scale, &work[work_offset], &c__1);
00429 }
00430 goto L30;
00431 }
00432
00433 sep[ks] = 1.f / dmax(est,smlnum);
00434 }
00435
00436 L40:
00437 ++ks;
00438 L50:
00439 ;
00440 }
00441 return 0;
00442
00443
00444
00445 }