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 static integer c__0 = 0;
00020 static integer c_n1 = -1;
00021
00022 int cgeesx_(char *jobvs, char *sort, L_fp select, char *
00023 sense, integer *n, complex *a, integer *lda, integer *sdim, complex *
00024 w, complex *vs, integer *ldvs, real *rconde, real *rcondv, complex *
00025 work, integer *lwork, real *rwork, logical *bwork, integer *info)
00026 {
00027
00028 integer a_dim1, a_offset, vs_dim1, vs_offset, i__1, i__2;
00029
00030
00031 double sqrt(doublereal);
00032
00033
00034 integer i__, ihi, ilo;
00035 real dum[1], eps;
00036 integer ibal;
00037 real anrm;
00038 integer ierr, itau, iwrk, lwrk, icond, ieval;
00039 extern logical lsame_(char *, char *);
00040 extern int ccopy_(integer *, complex *, integer *,
00041 complex *, integer *), cgebak_(char *, char *, integer *, integer
00042 *, integer *, real *, integer *, complex *, integer *, integer *), cgebal_(char *, integer *, complex *, integer *,
00043 integer *, integer *, real *, integer *), slabad_(real *,
00044 real *);
00045 logical scalea;
00046 extern doublereal clange_(char *, integer *, integer *, complex *,
00047 integer *, real *);
00048 real cscale;
00049 extern int cgehrd_(integer *, integer *, integer *,
00050 complex *, integer *, complex *, complex *, integer *, integer *),
00051 clascl_(char *, integer *, integer *, real *, real *, integer *,
00052 integer *, complex *, integer *, integer *);
00053 extern doublereal slamch_(char *);
00054 extern int clacpy_(char *, integer *, integer *, complex
00055 *, integer *, complex *, integer *), xerbla_(char *,
00056 integer *);
00057 extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
00058 integer *, integer *);
00059 real bignum;
00060 extern int slascl_(char *, integer *, integer *, real *,
00061 real *, integer *, integer *, real *, integer *, integer *), chseqr_(char *, char *, integer *, integer *, integer *,
00062 complex *, integer *, complex *, complex *, integer *, complex *,
00063 integer *, integer *), cunghr_(integer *, integer
00064 *, integer *, complex *, integer *, complex *, complex *, integer
00065 *, integer *);
00066 logical wantsb;
00067 extern int ctrsen_(char *, char *, logical *, integer *,
00068 complex *, integer *, complex *, integer *, complex *, integer *,
00069 real *, real *, complex *, integer *, integer *);
00070 logical wantse;
00071 integer minwrk, maxwrk;
00072 logical wantsn;
00073 real smlnum;
00074 integer hswork;
00075 logical wantst, wantsv, wantvs;
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 a_dim1 = *lda;
00236 a_offset = 1 + a_dim1;
00237 a -= a_offset;
00238 --w;
00239 vs_dim1 = *ldvs;
00240 vs_offset = 1 + vs_dim1;
00241 vs -= vs_offset;
00242 --work;
00243 --rwork;
00244 --bwork;
00245
00246
00247 *info = 0;
00248 wantvs = lsame_(jobvs, "V");
00249 wantst = lsame_(sort, "S");
00250 wantsn = lsame_(sense, "N");
00251 wantse = lsame_(sense, "E");
00252 wantsv = lsame_(sense, "V");
00253 wantsb = lsame_(sense, "B");
00254 if (! wantvs && ! lsame_(jobvs, "N")) {
00255 *info = -1;
00256 } else if (! wantst && ! lsame_(sort, "N")) {
00257 *info = -2;
00258 } else if (! (wantsn || wantse || wantsv || wantsb) || ! wantst && !
00259 wantsn) {
00260 *info = -4;
00261 } else if (*n < 0) {
00262 *info = -5;
00263 } else if (*lda < max(1,*n)) {
00264 *info = -7;
00265 } else if (*ldvs < 1 || wantvs && *ldvs < *n) {
00266 *info = -11;
00267 }
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283 if (*info == 0) {
00284 if (*n == 0) {
00285 minwrk = 1;
00286 lwrk = 1;
00287 } else {
00288 maxwrk = *n + *n * ilaenv_(&c__1, "CGEHRD", " ", n, &c__1, n, &
00289 c__0);
00290 minwrk = *n << 1;
00291
00292 chseqr_("S", jobvs, n, &c__1, n, &a[a_offset], lda, &w[1], &vs[
00293 vs_offset], ldvs, &work[1], &c_n1, &ieval);
00294 hswork = work[1].r;
00295
00296 if (! wantvs) {
00297 maxwrk = max(maxwrk,hswork);
00298 } else {
00299
00300 i__1 = maxwrk, i__2 = *n + (*n - 1) * ilaenv_(&c__1, "CUNGHR",
00301 " ", n, &c__1, n, &c_n1);
00302 maxwrk = max(i__1,i__2);
00303 maxwrk = max(maxwrk,hswork);
00304 }
00305 lwrk = maxwrk;
00306 if (! wantsn) {
00307
00308 i__1 = lwrk, i__2 = *n * *n / 2;
00309 lwrk = max(i__1,i__2);
00310 }
00311 }
00312 work[1].r = (real) lwrk, work[1].i = 0.f;
00313
00314 if (*lwork < minwrk) {
00315 *info = -15;
00316 }
00317 }
00318
00319 if (*info != 0) {
00320 i__1 = -(*info);
00321 xerbla_("CGEESX", &i__1);
00322 return 0;
00323 }
00324
00325
00326
00327 if (*n == 0) {
00328 *sdim = 0;
00329 return 0;
00330 }
00331
00332
00333
00334 eps = slamch_("P");
00335 smlnum = slamch_("S");
00336 bignum = 1.f / smlnum;
00337 slabad_(&smlnum, &bignum);
00338 smlnum = sqrt(smlnum) / eps;
00339 bignum = 1.f / smlnum;
00340
00341
00342
00343 anrm = clange_("M", n, n, &a[a_offset], lda, dum);
00344 scalea = FALSE_;
00345 if (anrm > 0.f && anrm < smlnum) {
00346 scalea = TRUE_;
00347 cscale = smlnum;
00348 } else if (anrm > bignum) {
00349 scalea = TRUE_;
00350 cscale = bignum;
00351 }
00352 if (scalea) {
00353 clascl_("G", &c__0, &c__0, &anrm, &cscale, n, n, &a[a_offset], lda, &
00354 ierr);
00355 }
00356
00357
00358
00359
00360
00361
00362 ibal = 1;
00363 cgebal_("P", n, &a[a_offset], lda, &ilo, &ihi, &rwork[ibal], &ierr);
00364
00365
00366
00367
00368
00369 itau = 1;
00370 iwrk = *n + itau;
00371 i__1 = *lwork - iwrk + 1;
00372 cgehrd_(n, &ilo, &ihi, &a[a_offset], lda, &work[itau], &work[iwrk], &i__1,
00373 &ierr);
00374
00375 if (wantvs) {
00376
00377
00378
00379 clacpy_("L", n, n, &a[a_offset], lda, &vs[vs_offset], ldvs)
00380 ;
00381
00382
00383
00384
00385
00386 i__1 = *lwork - iwrk + 1;
00387 cunghr_(n, &ilo, &ihi, &vs[vs_offset], ldvs, &work[itau], &work[iwrk],
00388 &i__1, &ierr);
00389 }
00390
00391 *sdim = 0;
00392
00393
00394
00395
00396
00397 iwrk = itau;
00398 i__1 = *lwork - iwrk + 1;
00399 chseqr_("S", jobvs, n, &ilo, &ihi, &a[a_offset], lda, &w[1], &vs[
00400 vs_offset], ldvs, &work[iwrk], &i__1, &ieval);
00401 if (ieval > 0) {
00402 *info = ieval;
00403 }
00404
00405
00406
00407 if (wantst && *info == 0) {
00408 if (scalea) {
00409 clascl_("G", &c__0, &c__0, &cscale, &anrm, n, &c__1, &w[1], n, &
00410 ierr);
00411 }
00412 i__1 = *n;
00413 for (i__ = 1; i__ <= i__1; ++i__) {
00414 bwork[i__] = (*select)(&w[i__]);
00415
00416 }
00417
00418
00419
00420
00421
00422
00423
00424 i__1 = *lwork - iwrk + 1;
00425 ctrsen_(sense, jobvs, &bwork[1], n, &a[a_offset], lda, &vs[vs_offset],
00426 ldvs, &w[1], sdim, rconde, rcondv, &work[iwrk], &i__1, &
00427 icond);
00428 if (! wantsn) {
00429
00430 i__1 = maxwrk, i__2 = (*sdim << 1) * (*n - *sdim);
00431 maxwrk = max(i__1,i__2);
00432 }
00433 if (icond == -14) {
00434
00435
00436
00437 *info = -15;
00438 }
00439 }
00440
00441 if (wantvs) {
00442
00443
00444
00445
00446
00447 cgebak_("P", "R", n, &ilo, &ihi, &rwork[ibal], n, &vs[vs_offset],
00448 ldvs, &ierr);
00449 }
00450
00451 if (scalea) {
00452
00453
00454
00455 clascl_("U", &c__0, &c__0, &cscale, &anrm, n, n, &a[a_offset], lda, &
00456 ierr);
00457 i__1 = *lda + 1;
00458 ccopy_(n, &a[a_offset], &i__1, &w[1], &c__1);
00459 if ((wantsv || wantsb) && *info == 0) {
00460 dum[0] = *rcondv;
00461 slascl_("G", &c__0, &c__0, &cscale, &anrm, &c__1, &c__1, dum, &
00462 c__1, &ierr);
00463 *rcondv = dum[0];
00464 }
00465 }
00466
00467 work[1].r = (real) maxwrk, work[1].i = 0.f;
00468 return 0;
00469
00470
00471
00472 }