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 sgeesx_(char *jobvs, char *sort, L_fp select, char *
00023 sense, integer *n, real *a, integer *lda, integer *sdim, real *wr,
00024 real *wi, real *vs, integer *ldvs, real *rconde, real *rcondv, real *
00025 work, integer *lwork, integer *iwork, integer *liwork, logical *bwork,
00026 integer *info)
00027 {
00028
00029 integer a_dim1, a_offset, vs_dim1, vs_offset, i__1, i__2, i__3;
00030
00031
00032 double sqrt(doublereal);
00033
00034
00035 integer i__, i1, i2, ip, ihi, ilo;
00036 real dum[1], eps;
00037 integer ibal;
00038 real anrm;
00039 integer ierr, itau, iwrk, lwrk, inxt, icond, ieval;
00040 extern logical lsame_(char *, char *);
00041 logical cursl;
00042 integer liwrk;
00043 extern int scopy_(integer *, real *, integer *, real *,
00044 integer *), sswap_(integer *, real *, integer *, real *, integer *
00045 );
00046 logical lst2sl;
00047 extern int slabad_(real *, real *);
00048 logical scalea;
00049 real cscale;
00050 extern int sgebak_(char *, char *, integer *, integer *,
00051 integer *, real *, integer *, real *, integer *, integer *), sgebal_(char *, integer *, real *, integer *,
00052 integer *, integer *, real *, integer *);
00053 extern doublereal slamch_(char *), slange_(char *, integer *,
00054 integer *, real *, integer *, real *);
00055 extern int sgehrd_(integer *, integer *, integer *, real
00056 *, integer *, real *, real *, integer *, integer *), xerbla_(char
00057 *, integer *);
00058 extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
00059 integer *, integer *);
00060 real bignum;
00061 extern int slascl_(char *, integer *, integer *, real *,
00062 real *, integer *, integer *, real *, integer *, integer *), slacpy_(char *, integer *, integer *, real *, integer *,
00063 real *, integer *);
00064 logical wantsb, wantse, lastsl;
00065 extern int sorghr_(integer *, integer *, integer *, real
00066 *, integer *, real *, real *, integer *, integer *), shseqr_(char
00067 *, char *, integer *, integer *, integer *, real *, integer *,
00068 real *, real *, real *, integer *, real *, integer *, integer *);
00069 integer minwrk, maxwrk;
00070 logical wantsn;
00071 real smlnum;
00072 integer hswork;
00073 extern int strsen_(char *, char *, logical *, integer *,
00074 real *, integer *, real *, integer *, real *, real *, integer *,
00075 real *, real *, real *, integer *, integer *, integer *, integer *
00076 );
00077 logical wantst, lquery, wantsv, wantvs;
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
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271 a_dim1 = *lda;
00272 a_offset = 1 + a_dim1;
00273 a -= a_offset;
00274 --wr;
00275 --wi;
00276 vs_dim1 = *ldvs;
00277 vs_offset = 1 + vs_dim1;
00278 vs -= vs_offset;
00279 --work;
00280 --iwork;
00281 --bwork;
00282
00283
00284 *info = 0;
00285 wantvs = lsame_(jobvs, "V");
00286 wantst = lsame_(sort, "S");
00287 wantsn = lsame_(sense, "N");
00288 wantse = lsame_(sense, "E");
00289 wantsv = lsame_(sense, "V");
00290 wantsb = lsame_(sense, "B");
00291 lquery = *lwork == -1 || *liwork == -1;
00292 if (! wantvs && ! lsame_(jobvs, "N")) {
00293 *info = -1;
00294 } else if (! wantst && ! lsame_(sort, "N")) {
00295 *info = -2;
00296 } else if (! (wantsn || wantse || wantsv || wantsb) || ! wantst && !
00297 wantsn) {
00298 *info = -4;
00299 } else if (*n < 0) {
00300 *info = -5;
00301 } else if (*lda < max(1,*n)) {
00302 *info = -7;
00303 } else if (*ldvs < 1 || wantvs && *ldvs < *n) {
00304 *info = -12;
00305 }
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321 if (*info == 0) {
00322 liwrk = 1;
00323 if (*n == 0) {
00324 minwrk = 1;
00325 lwrk = 1;
00326 } else {
00327 maxwrk = (*n << 1) + *n * ilaenv_(&c__1, "SGEHRD", " ", n, &c__1,
00328 n, &c__0);
00329 minwrk = *n * 3;
00330
00331 shseqr_("S", jobvs, n, &c__1, n, &a[a_offset], lda, &wr[1], &wi[1]
00332 , &vs[vs_offset], ldvs, &work[1], &c_n1, &ieval);
00333 hswork = work[1];
00334
00335 if (! wantvs) {
00336
00337 i__1 = maxwrk, i__2 = *n + hswork;
00338 maxwrk = max(i__1,i__2);
00339 } else {
00340
00341 i__1 = maxwrk, i__2 = (*n << 1) + (*n - 1) * ilaenv_(&c__1,
00342 "SORGHR", " ", n, &c__1, n, &c_n1);
00343 maxwrk = max(i__1,i__2);
00344
00345 i__1 = maxwrk, i__2 = *n + hswork;
00346 maxwrk = max(i__1,i__2);
00347 }
00348 lwrk = maxwrk;
00349 if (! wantsn) {
00350
00351 i__1 = lwrk, i__2 = *n + *n * *n / 2;
00352 lwrk = max(i__1,i__2);
00353 }
00354 if (wantsv || wantsb) {
00355 liwrk = *n * *n / 4;
00356 }
00357 }
00358 iwork[1] = liwrk;
00359 work[1] = (real) lwrk;
00360
00361 if (*lwork < minwrk && ! lquery) {
00362 *info = -16;
00363 } else if (*liwork < 1 && ! lquery) {
00364 *info = -18;
00365 }
00366 }
00367
00368 if (*info != 0) {
00369 i__1 = -(*info);
00370 xerbla_("SGEESX", &i__1);
00371 return 0;
00372 }
00373
00374
00375
00376 if (*n == 0) {
00377 *sdim = 0;
00378 return 0;
00379 }
00380
00381
00382
00383 eps = slamch_("P");
00384 smlnum = slamch_("S");
00385 bignum = 1.f / smlnum;
00386 slabad_(&smlnum, &bignum);
00387 smlnum = sqrt(smlnum) / eps;
00388 bignum = 1.f / smlnum;
00389
00390
00391
00392 anrm = slange_("M", n, n, &a[a_offset], lda, dum);
00393 scalea = FALSE_;
00394 if (anrm > 0.f && anrm < smlnum) {
00395 scalea = TRUE_;
00396 cscale = smlnum;
00397 } else if (anrm > bignum) {
00398 scalea = TRUE_;
00399 cscale = bignum;
00400 }
00401 if (scalea) {
00402 slascl_("G", &c__0, &c__0, &anrm, &cscale, n, n, &a[a_offset], lda, &
00403 ierr);
00404 }
00405
00406
00407
00408
00409 ibal = 1;
00410 sgebal_("P", n, &a[a_offset], lda, &ilo, &ihi, &work[ibal], &ierr);
00411
00412
00413
00414
00415 itau = *n + ibal;
00416 iwrk = *n + itau;
00417 i__1 = *lwork - iwrk + 1;
00418 sgehrd_(n, &ilo, &ihi, &a[a_offset], lda, &work[itau], &work[iwrk], &i__1,
00419 &ierr);
00420
00421 if (wantvs) {
00422
00423
00424
00425 slacpy_("L", n, n, &a[a_offset], lda, &vs[vs_offset], ldvs)
00426 ;
00427
00428
00429
00430
00431 i__1 = *lwork - iwrk + 1;
00432 sorghr_(n, &ilo, &ihi, &vs[vs_offset], ldvs, &work[itau], &work[iwrk],
00433 &i__1, &ierr);
00434 }
00435
00436 *sdim = 0;
00437
00438
00439
00440
00441 iwrk = itau;
00442 i__1 = *lwork - iwrk + 1;
00443 shseqr_("S", jobvs, n, &ilo, &ihi, &a[a_offset], lda, &wr[1], &wi[1], &vs[
00444 vs_offset], ldvs, &work[iwrk], &i__1, &ieval);
00445 if (ieval > 0) {
00446 *info = ieval;
00447 }
00448
00449
00450
00451 if (wantst && *info == 0) {
00452 if (scalea) {
00453 slascl_("G", &c__0, &c__0, &cscale, &anrm, n, &c__1, &wr[1], n, &
00454 ierr);
00455 slascl_("G", &c__0, &c__0, &cscale, &anrm, n, &c__1, &wi[1], n, &
00456 ierr);
00457 }
00458 i__1 = *n;
00459 for (i__ = 1; i__ <= i__1; ++i__) {
00460 bwork[i__] = (*select)(&wr[i__], &wi[i__]);
00461
00462 }
00463
00464
00465
00466
00467
00468
00469
00470
00471 i__1 = *lwork - iwrk + 1;
00472 strsen_(sense, jobvs, &bwork[1], n, &a[a_offset], lda, &vs[vs_offset],
00473 ldvs, &wr[1], &wi[1], sdim, rconde, rcondv, &work[iwrk], &
00474 i__1, &iwork[1], liwork, &icond);
00475 if (! wantsn) {
00476
00477 i__1 = maxwrk, i__2 = *n + (*sdim << 1) * (*n - *sdim);
00478 maxwrk = max(i__1,i__2);
00479 }
00480 if (icond == -15) {
00481
00482
00483
00484 *info = -16;
00485 } else if (icond == -17) {
00486
00487
00488
00489 *info = -18;
00490 } else if (icond > 0) {
00491
00492
00493
00494 *info = icond + *n;
00495 }
00496 }
00497
00498 if (wantvs) {
00499
00500
00501
00502
00503 sgebak_("P", "R", n, &ilo, &ihi, &work[ibal], n, &vs[vs_offset], ldvs,
00504 &ierr);
00505 }
00506
00507 if (scalea) {
00508
00509
00510
00511 slascl_("H", &c__0, &c__0, &cscale, &anrm, n, n, &a[a_offset], lda, &
00512 ierr);
00513 i__1 = *lda + 1;
00514 scopy_(n, &a[a_offset], &i__1, &wr[1], &c__1);
00515 if ((wantsv || wantsb) && *info == 0) {
00516 dum[0] = *rcondv;
00517 slascl_("G", &c__0, &c__0, &cscale, &anrm, &c__1, &c__1, dum, &
00518 c__1, &ierr);
00519 *rcondv = dum[0];
00520 }
00521 if (cscale == smlnum) {
00522
00523
00524
00525
00526
00527 if (ieval > 0) {
00528 i1 = ieval + 1;
00529 i2 = ihi - 1;
00530 i__1 = ilo - 1;
00531 slascl_("G", &c__0, &c__0, &cscale, &anrm, &i__1, &c__1, &wi[
00532 1], n, &ierr);
00533 } else if (wantst) {
00534 i1 = 1;
00535 i2 = *n - 1;
00536 } else {
00537 i1 = ilo;
00538 i2 = ihi - 1;
00539 }
00540 inxt = i1 - 1;
00541 i__1 = i2;
00542 for (i__ = i1; i__ <= i__1; ++i__) {
00543 if (i__ < inxt) {
00544 goto L20;
00545 }
00546 if (wi[i__] == 0.f) {
00547 inxt = i__ + 1;
00548 } else {
00549 if (a[i__ + 1 + i__ * a_dim1] == 0.f) {
00550 wi[i__] = 0.f;
00551 wi[i__ + 1] = 0.f;
00552 } else if (a[i__ + 1 + i__ * a_dim1] != 0.f && a[i__ + (
00553 i__ + 1) * a_dim1] == 0.f) {
00554 wi[i__] = 0.f;
00555 wi[i__ + 1] = 0.f;
00556 if (i__ > 1) {
00557 i__2 = i__ - 1;
00558 sswap_(&i__2, &a[i__ * a_dim1 + 1], &c__1, &a[(
00559 i__ + 1) * a_dim1 + 1], &c__1);
00560 }
00561 if (*n > i__ + 1) {
00562 i__2 = *n - i__ - 1;
00563 sswap_(&i__2, &a[i__ + (i__ + 2) * a_dim1], lda, &
00564 a[i__ + 1 + (i__ + 2) * a_dim1], lda);
00565 }
00566 sswap_(n, &vs[i__ * vs_dim1 + 1], &c__1, &vs[(i__ + 1)
00567 * vs_dim1 + 1], &c__1);
00568 a[i__ + (i__ + 1) * a_dim1] = a[i__ + 1 + i__ *
00569 a_dim1];
00570 a[i__ + 1 + i__ * a_dim1] = 0.f;
00571 }
00572 inxt = i__ + 2;
00573 }
00574 L20:
00575 ;
00576 }
00577 }
00578 i__1 = *n - ieval;
00579
00580 i__3 = *n - ieval;
00581 i__2 = max(i__3,1);
00582 slascl_("G", &c__0, &c__0, &cscale, &anrm, &i__1, &c__1, &wi[ieval +
00583 1], &i__2, &ierr);
00584 }
00585
00586 if (wantst && *info == 0) {
00587
00588
00589
00590 lastsl = TRUE_;
00591 lst2sl = TRUE_;
00592 *sdim = 0;
00593 ip = 0;
00594 i__1 = *n;
00595 for (i__ = 1; i__ <= i__1; ++i__) {
00596 cursl = (*select)(&wr[i__], &wi[i__]);
00597 if (wi[i__] == 0.f) {
00598 if (cursl) {
00599 ++(*sdim);
00600 }
00601 ip = 0;
00602 if (cursl && ! lastsl) {
00603 *info = *n + 2;
00604 }
00605 } else {
00606 if (ip == 1) {
00607
00608
00609
00610 cursl = cursl || lastsl;
00611 lastsl = cursl;
00612 if (cursl) {
00613 *sdim += 2;
00614 }
00615 ip = -1;
00616 if (cursl && ! lst2sl) {
00617 *info = *n + 2;
00618 }
00619 } else {
00620
00621
00622
00623 ip = 1;
00624 }
00625 }
00626 lst2sl = lastsl;
00627 lastsl = cursl;
00628
00629 }
00630 }
00631
00632 work[1] = (real) maxwrk;
00633 if (wantsv || wantsb) {
00634 iwork[1] = *sdim * (*n - *sdim);
00635 } else {
00636 iwork[1] = 1;
00637 }
00638
00639 return 0;
00640
00641
00642
00643 }