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 dgeevx_(char *balanc, char *jobvl, char *jobvr, char *
00023 sense, integer *n, doublereal *a, integer *lda, doublereal *wr,
00024 doublereal *wi, doublereal *vl, integer *ldvl, doublereal *vr,
00025 integer *ldvr, integer *ilo, integer *ihi, doublereal *scale,
00026 doublereal *abnrm, doublereal *rconde, doublereal *rcondv, doublereal
00027 *work, integer *lwork, integer *iwork, integer *info)
00028 {
00029
00030 integer a_dim1, a_offset, vl_dim1, vl_offset, vr_dim1, vr_offset, i__1,
00031 i__2, i__3;
00032 doublereal d__1, d__2;
00033
00034
00035 double sqrt(doublereal);
00036
00037
00038 integer i__, k;
00039 doublereal r__, cs, sn;
00040 char job[1];
00041 doublereal scl, dum[1], eps;
00042 char side[1];
00043 doublereal anrm;
00044 integer ierr, itau;
00045 extern int drot_(integer *, doublereal *, integer *,
00046 doublereal *, integer *, doublereal *, doublereal *);
00047 integer iwrk, nout;
00048 extern doublereal dnrm2_(integer *, doublereal *, integer *);
00049 extern int dscal_(integer *, doublereal *, doublereal *,
00050 integer *);
00051 integer icond;
00052 extern logical lsame_(char *, char *);
00053 extern doublereal dlapy2_(doublereal *, doublereal *);
00054 extern int dlabad_(doublereal *, doublereal *), dgebak_(
00055 char *, char *, integer *, integer *, integer *, doublereal *,
00056 integer *, doublereal *, integer *, integer *),
00057 dgebal_(char *, integer *, doublereal *, integer *, integer *,
00058 integer *, doublereal *, integer *);
00059 logical scalea;
00060 extern doublereal dlamch_(char *);
00061 doublereal cscale;
00062 extern doublereal dlange_(char *, integer *, integer *, doublereal *,
00063 integer *, doublereal *);
00064 extern int dgehrd_(integer *, integer *, integer *,
00065 doublereal *, integer *, doublereal *, doublereal *, integer *,
00066 integer *), dlascl_(char *, integer *, integer *, doublereal *,
00067 doublereal *, integer *, integer *, doublereal *, integer *,
00068 integer *);
00069 extern integer idamax_(integer *, doublereal *, integer *);
00070 extern int dlacpy_(char *, integer *, integer *,
00071 doublereal *, integer *, doublereal *, integer *),
00072 dlartg_(doublereal *, doublereal *, doublereal *, doublereal *,
00073 doublereal *), xerbla_(char *, integer *);
00074 logical select[1];
00075 extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
00076 integer *, integer *);
00077 doublereal bignum;
00078 extern int dorghr_(integer *, integer *, integer *,
00079 doublereal *, integer *, doublereal *, doublereal *, integer *,
00080 integer *), dhseqr_(char *, char *, integer *, integer *, integer
00081 *, doublereal *, integer *, doublereal *, doublereal *,
00082 doublereal *, integer *, doublereal *, integer *, integer *), dtrevc_(char *, char *, logical *, integer *,
00083 doublereal *, integer *, doublereal *, integer *, doublereal *,
00084 integer *, integer *, integer *, doublereal *, integer *), dtrsna_(char *, char *, logical *, integer *, doublereal
00085 *, integer *, doublereal *, integer *, doublereal *, integer *,
00086 doublereal *, doublereal *, integer *, integer *, doublereal *,
00087 integer *, integer *, integer *);
00088 integer minwrk, maxwrk;
00089 logical wantvl, wntsnb;
00090 integer hswork;
00091 logical wntsne;
00092 doublereal smlnum;
00093 logical lquery, wantvr, wntsnn, wntsnv;
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
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301 a_dim1 = *lda;
00302 a_offset = 1 + a_dim1;
00303 a -= a_offset;
00304 --wr;
00305 --wi;
00306 vl_dim1 = *ldvl;
00307 vl_offset = 1 + vl_dim1;
00308 vl -= vl_offset;
00309 vr_dim1 = *ldvr;
00310 vr_offset = 1 + vr_dim1;
00311 vr -= vr_offset;
00312 --scale;
00313 --rconde;
00314 --rcondv;
00315 --work;
00316 --iwork;
00317
00318
00319 *info = 0;
00320 lquery = *lwork == -1;
00321 wantvl = lsame_(jobvl, "V");
00322 wantvr = lsame_(jobvr, "V");
00323 wntsnn = lsame_(sense, "N");
00324 wntsne = lsame_(sense, "E");
00325 wntsnv = lsame_(sense, "V");
00326 wntsnb = lsame_(sense, "B");
00327 if (! (lsame_(balanc, "N") || lsame_(balanc, "S") || lsame_(balanc, "P")
00328 || lsame_(balanc, "B"))) {
00329 *info = -1;
00330 } else if (! wantvl && ! lsame_(jobvl, "N")) {
00331 *info = -2;
00332 } else if (! wantvr && ! lsame_(jobvr, "N")) {
00333 *info = -3;
00334 } else if (! (wntsnn || wntsne || wntsnb || wntsnv) || (wntsne || wntsnb)
00335 && ! (wantvl && wantvr)) {
00336 *info = -4;
00337 } else if (*n < 0) {
00338 *info = -5;
00339 } else if (*lda < max(1,*n)) {
00340 *info = -7;
00341 } else if (*ldvl < 1 || wantvl && *ldvl < *n) {
00342 *info = -11;
00343 } else if (*ldvr < 1 || wantvr && *ldvr < *n) {
00344 *info = -13;
00345 }
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357 if (*info == 0) {
00358 if (*n == 0) {
00359 minwrk = 1;
00360 maxwrk = 1;
00361 } else {
00362 maxwrk = *n + *n * ilaenv_(&c__1, "DGEHRD", " ", n, &c__1, n, &
00363 c__0);
00364
00365 if (wantvl) {
00366 dhseqr_("S", "V", n, &c__1, n, &a[a_offset], lda, &wr[1], &wi[
00367 1], &vl[vl_offset], ldvl, &work[1], &c_n1, info);
00368 } else if (wantvr) {
00369 dhseqr_("S", "V", n, &c__1, n, &a[a_offset], lda, &wr[1], &wi[
00370 1], &vr[vr_offset], ldvr, &work[1], &c_n1, info);
00371 } else {
00372 if (wntsnn) {
00373 dhseqr_("E", "N", n, &c__1, n, &a[a_offset], lda, &wr[1],
00374 &wi[1], &vr[vr_offset], ldvr, &work[1], &c_n1,
00375 info);
00376 } else {
00377 dhseqr_("S", "N", n, &c__1, n, &a[a_offset], lda, &wr[1],
00378 &wi[1], &vr[vr_offset], ldvr, &work[1], &c_n1,
00379 info);
00380 }
00381 }
00382 hswork = (integer) work[1];
00383
00384 if (! wantvl && ! wantvr) {
00385 minwrk = *n << 1;
00386 if (! wntsnn) {
00387
00388 i__1 = minwrk, i__2 = *n * *n + *n * 6;
00389 minwrk = max(i__1,i__2);
00390 }
00391 maxwrk = max(maxwrk,hswork);
00392 if (! wntsnn) {
00393
00394 i__1 = maxwrk, i__2 = *n * *n + *n * 6;
00395 maxwrk = max(i__1,i__2);
00396 }
00397 } else {
00398 minwrk = *n * 3;
00399 if (! wntsnn && ! wntsne) {
00400
00401 i__1 = minwrk, i__2 = *n * *n + *n * 6;
00402 minwrk = max(i__1,i__2);
00403 }
00404 maxwrk = max(maxwrk,hswork);
00405
00406 i__1 = maxwrk, i__2 = *n + (*n - 1) * ilaenv_(&c__1, "DORGHR",
00407 " ", n, &c__1, n, &c_n1);
00408 maxwrk = max(i__1,i__2);
00409 if (! wntsnn && ! wntsne) {
00410
00411 i__1 = maxwrk, i__2 = *n * *n + *n * 6;
00412 maxwrk = max(i__1,i__2);
00413 }
00414
00415 i__1 = maxwrk, i__2 = *n * 3;
00416 maxwrk = max(i__1,i__2);
00417 }
00418 maxwrk = max(maxwrk,minwrk);
00419 }
00420 work[1] = (doublereal) maxwrk;
00421
00422 if (*lwork < minwrk && ! lquery) {
00423 *info = -21;
00424 }
00425 }
00426
00427 if (*info != 0) {
00428 i__1 = -(*info);
00429 xerbla_("DGEEVX", &i__1);
00430 return 0;
00431 } else if (lquery) {
00432 return 0;
00433 }
00434
00435
00436
00437 if (*n == 0) {
00438 return 0;
00439 }
00440
00441
00442
00443 eps = dlamch_("P");
00444 smlnum = dlamch_("S");
00445 bignum = 1. / smlnum;
00446 dlabad_(&smlnum, &bignum);
00447 smlnum = sqrt(smlnum) / eps;
00448 bignum = 1. / smlnum;
00449
00450
00451
00452 icond = 0;
00453 anrm = dlange_("M", n, n, &a[a_offset], lda, dum);
00454 scalea = FALSE_;
00455 if (anrm > 0. && anrm < smlnum) {
00456 scalea = TRUE_;
00457 cscale = smlnum;
00458 } else if (anrm > bignum) {
00459 scalea = TRUE_;
00460 cscale = bignum;
00461 }
00462 if (scalea) {
00463 dlascl_("G", &c__0, &c__0, &anrm, &cscale, n, n, &a[a_offset], lda, &
00464 ierr);
00465 }
00466
00467
00468
00469 dgebal_(balanc, n, &a[a_offset], lda, ilo, ihi, &scale[1], &ierr);
00470 *abnrm = dlange_("1", n, n, &a[a_offset], lda, dum);
00471 if (scalea) {
00472 dum[0] = *abnrm;
00473 dlascl_("G", &c__0, &c__0, &cscale, &anrm, &c__1, &c__1, dum, &c__1, &
00474 ierr);
00475 *abnrm = dum[0];
00476 }
00477
00478
00479
00480
00481 itau = 1;
00482 iwrk = itau + *n;
00483 i__1 = *lwork - iwrk + 1;
00484 dgehrd_(n, ilo, ihi, &a[a_offset], lda, &work[itau], &work[iwrk], &i__1, &
00485 ierr);
00486
00487 if (wantvl) {
00488
00489
00490
00491
00492 *(unsigned char *)side = 'L';
00493 dlacpy_("L", n, n, &a[a_offset], lda, &vl[vl_offset], ldvl)
00494 ;
00495
00496
00497
00498
00499 i__1 = *lwork - iwrk + 1;
00500 dorghr_(n, ilo, ihi, &vl[vl_offset], ldvl, &work[itau], &work[iwrk], &
00501 i__1, &ierr);
00502
00503
00504
00505
00506 iwrk = itau;
00507 i__1 = *lwork - iwrk + 1;
00508 dhseqr_("S", "V", n, ilo, ihi, &a[a_offset], lda, &wr[1], &wi[1], &vl[
00509 vl_offset], ldvl, &work[iwrk], &i__1, info);
00510
00511 if (wantvr) {
00512
00513
00514
00515
00516 *(unsigned char *)side = 'B';
00517 dlacpy_("F", n, n, &vl[vl_offset], ldvl, &vr[vr_offset], ldvr);
00518 }
00519
00520 } else if (wantvr) {
00521
00522
00523
00524
00525 *(unsigned char *)side = 'R';
00526 dlacpy_("L", n, n, &a[a_offset], lda, &vr[vr_offset], ldvr)
00527 ;
00528
00529
00530
00531
00532 i__1 = *lwork - iwrk + 1;
00533 dorghr_(n, ilo, ihi, &vr[vr_offset], ldvr, &work[itau], &work[iwrk], &
00534 i__1, &ierr);
00535
00536
00537
00538
00539 iwrk = itau;
00540 i__1 = *lwork - iwrk + 1;
00541 dhseqr_("S", "V", n, ilo, ihi, &a[a_offset], lda, &wr[1], &wi[1], &vr[
00542 vr_offset], ldvr, &work[iwrk], &i__1, info);
00543
00544 } else {
00545
00546
00547
00548
00549 if (wntsnn) {
00550 *(unsigned char *)job = 'E';
00551 } else {
00552 *(unsigned char *)job = 'S';
00553 }
00554
00555
00556
00557 iwrk = itau;
00558 i__1 = *lwork - iwrk + 1;
00559 dhseqr_(job, "N", n, ilo, ihi, &a[a_offset], lda, &wr[1], &wi[1], &vr[
00560 vr_offset], ldvr, &work[iwrk], &i__1, info);
00561 }
00562
00563
00564
00565 if (*info > 0) {
00566 goto L50;
00567 }
00568
00569 if (wantvl || wantvr) {
00570
00571
00572
00573
00574 dtrevc_(side, "B", select, n, &a[a_offset], lda, &vl[vl_offset], ldvl,
00575 &vr[vr_offset], ldvr, n, &nout, &work[iwrk], &ierr);
00576 }
00577
00578
00579
00580
00581 if (! wntsnn) {
00582 dtrsna_(sense, "A", select, n, &a[a_offset], lda, &vl[vl_offset],
00583 ldvl, &vr[vr_offset], ldvr, &rconde[1], &rcondv[1], n, &nout,
00584 &work[iwrk], n, &iwork[1], &icond);
00585 }
00586
00587 if (wantvl) {
00588
00589
00590
00591 dgebak_(balanc, "L", n, ilo, ihi, &scale[1], n, &vl[vl_offset], ldvl,
00592 &ierr);
00593
00594
00595
00596 i__1 = *n;
00597 for (i__ = 1; i__ <= i__1; ++i__) {
00598 if (wi[i__] == 0.) {
00599 scl = 1. / dnrm2_(n, &vl[i__ * vl_dim1 + 1], &c__1);
00600 dscal_(n, &scl, &vl[i__ * vl_dim1 + 1], &c__1);
00601 } else if (wi[i__] > 0.) {
00602 d__1 = dnrm2_(n, &vl[i__ * vl_dim1 + 1], &c__1);
00603 d__2 = dnrm2_(n, &vl[(i__ + 1) * vl_dim1 + 1], &c__1);
00604 scl = 1. / dlapy2_(&d__1, &d__2);
00605 dscal_(n, &scl, &vl[i__ * vl_dim1 + 1], &c__1);
00606 dscal_(n, &scl, &vl[(i__ + 1) * vl_dim1 + 1], &c__1);
00607 i__2 = *n;
00608 for (k = 1; k <= i__2; ++k) {
00609
00610 d__1 = vl[k + i__ * vl_dim1];
00611
00612 d__2 = vl[k + (i__ + 1) * vl_dim1];
00613 work[k] = d__1 * d__1 + d__2 * d__2;
00614
00615 }
00616 k = idamax_(n, &work[1], &c__1);
00617 dlartg_(&vl[k + i__ * vl_dim1], &vl[k + (i__ + 1) * vl_dim1],
00618 &cs, &sn, &r__);
00619 drot_(n, &vl[i__ * vl_dim1 + 1], &c__1, &vl[(i__ + 1) *
00620 vl_dim1 + 1], &c__1, &cs, &sn);
00621 vl[k + (i__ + 1) * vl_dim1] = 0.;
00622 }
00623
00624 }
00625 }
00626
00627 if (wantvr) {
00628
00629
00630
00631 dgebak_(balanc, "R", n, ilo, ihi, &scale[1], n, &vr[vr_offset], ldvr,
00632 &ierr);
00633
00634
00635
00636 i__1 = *n;
00637 for (i__ = 1; i__ <= i__1; ++i__) {
00638 if (wi[i__] == 0.) {
00639 scl = 1. / dnrm2_(n, &vr[i__ * vr_dim1 + 1], &c__1);
00640 dscal_(n, &scl, &vr[i__ * vr_dim1 + 1], &c__1);
00641 } else if (wi[i__] > 0.) {
00642 d__1 = dnrm2_(n, &vr[i__ * vr_dim1 + 1], &c__1);
00643 d__2 = dnrm2_(n, &vr[(i__ + 1) * vr_dim1 + 1], &c__1);
00644 scl = 1. / dlapy2_(&d__1, &d__2);
00645 dscal_(n, &scl, &vr[i__ * vr_dim1 + 1], &c__1);
00646 dscal_(n, &scl, &vr[(i__ + 1) * vr_dim1 + 1], &c__1);
00647 i__2 = *n;
00648 for (k = 1; k <= i__2; ++k) {
00649
00650 d__1 = vr[k + i__ * vr_dim1];
00651
00652 d__2 = vr[k + (i__ + 1) * vr_dim1];
00653 work[k] = d__1 * d__1 + d__2 * d__2;
00654
00655 }
00656 k = idamax_(n, &work[1], &c__1);
00657 dlartg_(&vr[k + i__ * vr_dim1], &vr[k + (i__ + 1) * vr_dim1],
00658 &cs, &sn, &r__);
00659 drot_(n, &vr[i__ * vr_dim1 + 1], &c__1, &vr[(i__ + 1) *
00660 vr_dim1 + 1], &c__1, &cs, &sn);
00661 vr[k + (i__ + 1) * vr_dim1] = 0.;
00662 }
00663
00664 }
00665 }
00666
00667
00668
00669 L50:
00670 if (scalea) {
00671 i__1 = *n - *info;
00672
00673 i__3 = *n - *info;
00674 i__2 = max(i__3,1);
00675 dlascl_("G", &c__0, &c__0, &cscale, &anrm, &i__1, &c__1, &wr[*info +
00676 1], &i__2, &ierr);
00677 i__1 = *n - *info;
00678
00679 i__3 = *n - *info;
00680 i__2 = max(i__3,1);
00681 dlascl_("G", &c__0, &c__0, &cscale, &anrm, &i__1, &c__1, &wi[*info +
00682 1], &i__2, &ierr);
00683 if (*info == 0) {
00684 if ((wntsnv || wntsnb) && icond == 0) {
00685 dlascl_("G", &c__0, &c__0, &cscale, &anrm, n, &c__1, &rcondv[
00686 1], n, &ierr);
00687 }
00688 } else {
00689 i__1 = *ilo - 1;
00690 dlascl_("G", &c__0, &c__0, &cscale, &anrm, &i__1, &c__1, &wr[1],
00691 n, &ierr);
00692 i__1 = *ilo - 1;
00693 dlascl_("G", &c__0, &c__0, &cscale, &anrm, &i__1, &c__1, &wi[1],
00694 n, &ierr);
00695 }
00696 }
00697
00698 work[1] = (doublereal) maxwrk;
00699 return 0;
00700
00701
00702
00703 }