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 sgees_(char *jobvs, char *sort, L_fp select, integer *n,
00023 real *a, integer *lda, integer *sdim, real *wr, real *wi, real *vs,
00024 integer *ldvs, real *work, integer *lwork, logical *bwork, integer *
00025 info)
00026 {
00027
00028 integer a_dim1, a_offset, vs_dim1, vs_offset, i__1, i__2, i__3;
00029
00030
00031 double sqrt(doublereal);
00032
00033
00034 integer i__;
00035 real s;
00036 integer i1, i2, ip, ihi, ilo;
00037 real dum[1], eps, sep;
00038 integer ibal;
00039 real anrm;
00040 integer idum[1], ierr, itau, iwrk, inxt, icond, ieval;
00041 extern logical lsame_(char *, char *);
00042 logical cursl;
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 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 real smlnum;
00071 integer hswork;
00072 extern int strsen_(char *, char *, logical *, integer *,
00073 real *, integer *, real *, integer *, real *, real *, integer *,
00074 real *, real *, real *, integer *, integer *, integer *, integer *
00075 );
00076 logical wantst, lquery, wantvs;
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 a_dim1 = *lda;
00225 a_offset = 1 + a_dim1;
00226 a -= a_offset;
00227 --wr;
00228 --wi;
00229 vs_dim1 = *ldvs;
00230 vs_offset = 1 + vs_dim1;
00231 vs -= vs_offset;
00232 --work;
00233 --bwork;
00234
00235
00236 *info = 0;
00237 lquery = *lwork == -1;
00238 wantvs = lsame_(jobvs, "V");
00239 wantst = lsame_(sort, "S");
00240 if (! wantvs && ! lsame_(jobvs, "N")) {
00241 *info = -1;
00242 } else if (! wantst && ! lsame_(sort, "N")) {
00243 *info = -2;
00244 } else if (*n < 0) {
00245 *info = -4;
00246 } else if (*lda < max(1,*n)) {
00247 *info = -6;
00248 } else if (*ldvs < 1 || wantvs && *ldvs < *n) {
00249 *info = -11;
00250 }
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262 if (*info == 0) {
00263 if (*n == 0) {
00264 minwrk = 1;
00265 maxwrk = 1;
00266 } else {
00267 maxwrk = (*n << 1) + *n * ilaenv_(&c__1, "SGEHRD", " ", n, &c__1,
00268 n, &c__0);
00269 minwrk = *n * 3;
00270
00271 shseqr_("S", jobvs, n, &c__1, n, &a[a_offset], lda, &wr[1], &wi[1]
00272 , &vs[vs_offset], ldvs, &work[1], &c_n1, &ieval);
00273 hswork = work[1];
00274
00275 if (! wantvs) {
00276
00277 i__1 = maxwrk, i__2 = *n + hswork;
00278 maxwrk = max(i__1,i__2);
00279 } else {
00280
00281 i__1 = maxwrk, i__2 = (*n << 1) + (*n - 1) * ilaenv_(&c__1,
00282 "SORGHR", " ", n, &c__1, n, &c_n1);
00283 maxwrk = max(i__1,i__2);
00284
00285 i__1 = maxwrk, i__2 = *n + hswork;
00286 maxwrk = max(i__1,i__2);
00287 }
00288 }
00289 work[1] = (real) maxwrk;
00290
00291 if (*lwork < minwrk && ! lquery) {
00292 *info = -13;
00293 }
00294 }
00295
00296 if (*info != 0) {
00297 i__1 = -(*info);
00298 xerbla_("SGEES ", &i__1);
00299 return 0;
00300 } else if (lquery) {
00301 return 0;
00302 }
00303
00304
00305
00306 if (*n == 0) {
00307 *sdim = 0;
00308 return 0;
00309 }
00310
00311
00312
00313 eps = slamch_("P");
00314 smlnum = slamch_("S");
00315 bignum = 1.f / smlnum;
00316 slabad_(&smlnum, &bignum);
00317 smlnum = sqrt(smlnum) / eps;
00318 bignum = 1.f / smlnum;
00319
00320
00321
00322 anrm = slange_("M", n, n, &a[a_offset], lda, dum);
00323 scalea = FALSE_;
00324 if (anrm > 0.f && anrm < smlnum) {
00325 scalea = TRUE_;
00326 cscale = smlnum;
00327 } else if (anrm > bignum) {
00328 scalea = TRUE_;
00329 cscale = bignum;
00330 }
00331 if (scalea) {
00332 slascl_("G", &c__0, &c__0, &anrm, &cscale, n, n, &a[a_offset], lda, &
00333 ierr);
00334 }
00335
00336
00337
00338
00339 ibal = 1;
00340 sgebal_("P", n, &a[a_offset], lda, &ilo, &ihi, &work[ibal], &ierr);
00341
00342
00343
00344
00345 itau = *n + ibal;
00346 iwrk = *n + itau;
00347 i__1 = *lwork - iwrk + 1;
00348 sgehrd_(n, &ilo, &ihi, &a[a_offset], lda, &work[itau], &work[iwrk], &i__1,
00349 &ierr);
00350
00351 if (wantvs) {
00352
00353
00354
00355 slacpy_("L", n, n, &a[a_offset], lda, &vs[vs_offset], ldvs)
00356 ;
00357
00358
00359
00360
00361 i__1 = *lwork - iwrk + 1;
00362 sorghr_(n, &ilo, &ihi, &vs[vs_offset], ldvs, &work[itau], &work[iwrk],
00363 &i__1, &ierr);
00364 }
00365
00366 *sdim = 0;
00367
00368
00369
00370
00371 iwrk = itau;
00372 i__1 = *lwork - iwrk + 1;
00373 shseqr_("S", jobvs, n, &ilo, &ihi, &a[a_offset], lda, &wr[1], &wi[1], &vs[
00374 vs_offset], ldvs, &work[iwrk], &i__1, &ieval);
00375 if (ieval > 0) {
00376 *info = ieval;
00377 }
00378
00379
00380
00381 if (wantst && *info == 0) {
00382 if (scalea) {
00383 slascl_("G", &c__0, &c__0, &cscale, &anrm, n, &c__1, &wr[1], n, &
00384 ierr);
00385 slascl_("G", &c__0, &c__0, &cscale, &anrm, n, &c__1, &wi[1], n, &
00386 ierr);
00387 }
00388 i__1 = *n;
00389 for (i__ = 1; i__ <= i__1; ++i__) {
00390 bwork[i__] = (*select)(&wr[i__], &wi[i__]);
00391
00392 }
00393
00394
00395
00396
00397 i__1 = *lwork - iwrk + 1;
00398 strsen_("N", jobvs, &bwork[1], n, &a[a_offset], lda, &vs[vs_offset],
00399 ldvs, &wr[1], &wi[1], sdim, &s, &sep, &work[iwrk], &i__1,
00400 idum, &c__1, &icond);
00401 if (icond > 0) {
00402 *info = *n + icond;
00403 }
00404 }
00405
00406 if (wantvs) {
00407
00408
00409
00410
00411 sgebak_("P", "R", n, &ilo, &ihi, &work[ibal], n, &vs[vs_offset], ldvs,
00412 &ierr);
00413 }
00414
00415 if (scalea) {
00416
00417
00418
00419 slascl_("H", &c__0, &c__0, &cscale, &anrm, n, n, &a[a_offset], lda, &
00420 ierr);
00421 i__1 = *lda + 1;
00422 scopy_(n, &a[a_offset], &i__1, &wr[1], &c__1);
00423 if (cscale == smlnum) {
00424
00425
00426
00427
00428
00429 if (ieval > 0) {
00430 i1 = ieval + 1;
00431 i2 = ihi - 1;
00432 i__1 = ilo - 1;
00433
00434 i__3 = ilo - 1;
00435 i__2 = max(i__3,1);
00436 slascl_("G", &c__0, &c__0, &cscale, &anrm, &i__1, &c__1, &wi[
00437 1], &i__2, &ierr);
00438 } else if (wantst) {
00439 i1 = 1;
00440 i2 = *n - 1;
00441 } else {
00442 i1 = ilo;
00443 i2 = ihi - 1;
00444 }
00445 inxt = i1 - 1;
00446 i__1 = i2;
00447 for (i__ = i1; i__ <= i__1; ++i__) {
00448 if (i__ < inxt) {
00449 goto L20;
00450 }
00451 if (wi[i__] == 0.f) {
00452 inxt = i__ + 1;
00453 } else {
00454 if (a[i__ + 1 + i__ * a_dim1] == 0.f) {
00455 wi[i__] = 0.f;
00456 wi[i__ + 1] = 0.f;
00457 } else if (a[i__ + 1 + i__ * a_dim1] != 0.f && a[i__ + (
00458 i__ + 1) * a_dim1] == 0.f) {
00459 wi[i__] = 0.f;
00460 wi[i__ + 1] = 0.f;
00461 if (i__ > 1) {
00462 i__2 = i__ - 1;
00463 sswap_(&i__2, &a[i__ * a_dim1 + 1], &c__1, &a[(
00464 i__ + 1) * a_dim1 + 1], &c__1);
00465 }
00466 if (*n > i__ + 1) {
00467 i__2 = *n - i__ - 1;
00468 sswap_(&i__2, &a[i__ + (i__ + 2) * a_dim1], lda, &
00469 a[i__ + 1 + (i__ + 2) * a_dim1], lda);
00470 }
00471 if (wantvs) {
00472 sswap_(n, &vs[i__ * vs_dim1 + 1], &c__1, &vs[(i__
00473 + 1) * vs_dim1 + 1], &c__1);
00474 }
00475 a[i__ + (i__ + 1) * a_dim1] = a[i__ + 1 + i__ *
00476 a_dim1];
00477 a[i__ + 1 + i__ * a_dim1] = 0.f;
00478 }
00479 inxt = i__ + 2;
00480 }
00481 L20:
00482 ;
00483 }
00484 }
00485
00486
00487
00488 i__1 = *n - ieval;
00489
00490 i__3 = *n - ieval;
00491 i__2 = max(i__3,1);
00492 slascl_("G", &c__0, &c__0, &cscale, &anrm, &i__1, &c__1, &wi[ieval +
00493 1], &i__2, &ierr);
00494 }
00495
00496 if (wantst && *info == 0) {
00497
00498
00499
00500 lastsl = TRUE_;
00501 lst2sl = TRUE_;
00502 *sdim = 0;
00503 ip = 0;
00504 i__1 = *n;
00505 for (i__ = 1; i__ <= i__1; ++i__) {
00506 cursl = (*select)(&wr[i__], &wi[i__]);
00507 if (wi[i__] == 0.f) {
00508 if (cursl) {
00509 ++(*sdim);
00510 }
00511 ip = 0;
00512 if (cursl && ! lastsl) {
00513 *info = *n + 2;
00514 }
00515 } else {
00516 if (ip == 1) {
00517
00518
00519
00520 cursl = cursl || lastsl;
00521 lastsl = cursl;
00522 if (cursl) {
00523 *sdim += 2;
00524 }
00525 ip = -1;
00526 if (cursl && ! lst2sl) {
00527 *info = *n + 2;
00528 }
00529 } else {
00530
00531
00532
00533 ip = 1;
00534 }
00535 }
00536 lst2sl = lastsl;
00537 lastsl = cursl;
00538
00539 }
00540 }
00541
00542 work[1] = (real) maxwrk;
00543 return 0;
00544
00545
00546
00547 }