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