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