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 doublecomplex c_b1 = {0.,0.};
00019 static doublecomplex c_b2 = {1.,0.};
00020 static integer c__1 = 1;
00021 static integer c__0 = 0;
00022
00023 int zggevx_(char *balanc, char *jobvl, char *jobvr, char *
00024 sense, integer *n, doublecomplex *a, integer *lda, doublecomplex *b,
00025 integer *ldb, doublecomplex *alpha, doublecomplex *beta,
00026 doublecomplex *vl, integer *ldvl, doublecomplex *vr, integer *ldvr,
00027 integer *ilo, integer *ihi, doublereal *lscale, doublereal *rscale,
00028 doublereal *abnrm, doublereal *bbnrm, doublereal *rconde, doublereal *
00029 rcondv, doublecomplex *work, integer *lwork, doublereal *rwork,
00030 integer *iwork, logical *bwork, integer *info)
00031 {
00032
00033 integer a_dim1, a_offset, b_dim1, b_offset, vl_dim1, vl_offset, vr_dim1,
00034 vr_offset, i__1, i__2, i__3, i__4;
00035 doublereal d__1, d__2, d__3, d__4;
00036 doublecomplex z__1;
00037
00038
00039 double sqrt(doublereal), d_imag(doublecomplex *);
00040
00041
00042 integer i__, j, m, jc, in, jr;
00043 doublereal eps;
00044 logical ilv;
00045 doublereal anrm, bnrm;
00046 integer ierr, itau;
00047 doublereal temp;
00048 logical ilvl, ilvr;
00049 integer iwrk, iwrk1;
00050 extern logical lsame_(char *, char *);
00051 integer icols;
00052 logical noscl;
00053 integer irows;
00054 extern int dlabad_(doublereal *, doublereal *);
00055 extern doublereal dlamch_(char *);
00056 extern int dlascl_(char *, integer *, integer *,
00057 doublereal *, doublereal *, integer *, integer *, doublereal *,
00058 integer *, integer *), zggbak_(char *, char *, integer *,
00059 integer *, integer *, doublereal *, doublereal *, integer *,
00060 doublecomplex *, integer *, integer *), zggbal_(
00061 char *, integer *, doublecomplex *, integer *, doublecomplex *,
00062 integer *, integer *, integer *, doublereal *, doublereal *,
00063 doublereal *, integer *);
00064 logical ilascl, ilbscl;
00065 extern int xerbla_(char *, integer *);
00066 extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
00067 integer *, integer *);
00068 logical ldumma[1];
00069 char chtemp[1];
00070 doublereal bignum;
00071 extern doublereal zlange_(char *, integer *, integer *, doublecomplex *,
00072 integer *, doublereal *);
00073 integer ijobvl;
00074 extern int zgghrd_(char *, char *, integer *, integer *,
00075 integer *, doublecomplex *, integer *, doublecomplex *, integer *,
00076 doublecomplex *, integer *, doublecomplex *, integer *, integer *
00077 ), zlascl_(char *, integer *, integer *,
00078 doublereal *, doublereal *, integer *, integer *, doublecomplex *,
00079 integer *, integer *);
00080 integer ijobvr;
00081 logical wantsb;
00082 extern int zgeqrf_(integer *, integer *, doublecomplex *,
00083 integer *, doublecomplex *, doublecomplex *, integer *, integer *
00084 );
00085 doublereal anrmto;
00086 logical wantse;
00087 doublereal bnrmto;
00088 extern int zlacpy_(char *, integer *, integer *,
00089 doublecomplex *, integer *, doublecomplex *, integer *),
00090 zlaset_(char *, integer *, integer *, doublecomplex *,
00091 doublecomplex *, doublecomplex *, integer *), ztgevc_(
00092 char *, char *, logical *, integer *, doublecomplex *, integer *,
00093 doublecomplex *, integer *, doublecomplex *, integer *,
00094 doublecomplex *, integer *, integer *, integer *, doublecomplex *,
00095 doublereal *, integer *), ztgsna_(char *, char *,
00096 logical *, integer *, doublecomplex *, integer *, doublecomplex *
00097 , integer *, doublecomplex *, integer *, doublecomplex *, integer
00098 *, doublereal *, doublereal *, integer *, integer *,
00099 doublecomplex *, integer *, integer *, integer *);
00100 integer minwrk;
00101 extern int zhgeqz_(char *, char *, char *, integer *,
00102 integer *, integer *, doublecomplex *, integer *, doublecomplex *,
00103 integer *, doublecomplex *, doublecomplex *, doublecomplex *,
00104 integer *, doublecomplex *, integer *, doublecomplex *, integer *,
00105 doublereal *, integer *);
00106 integer maxwrk;
00107 logical wantsn;
00108 doublereal smlnum;
00109 logical lquery, wantsv;
00110 extern int zungqr_(integer *, integer *, integer *,
00111 doublecomplex *, integer *, doublecomplex *, doublecomplex *,
00112 integer *, integer *), zunmqr_(char *, char *, integer *, integer
00113 *, integer *, doublecomplex *, integer *, doublecomplex *,
00114 doublecomplex *, integer *, doublecomplex *, integer *, integer *);
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
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369 a_dim1 = *lda;
00370 a_offset = 1 + a_dim1;
00371 a -= a_offset;
00372 b_dim1 = *ldb;
00373 b_offset = 1 + b_dim1;
00374 b -= b_offset;
00375 --alpha;
00376 --beta;
00377 vl_dim1 = *ldvl;
00378 vl_offset = 1 + vl_dim1;
00379 vl -= vl_offset;
00380 vr_dim1 = *ldvr;
00381 vr_offset = 1 + vr_dim1;
00382 vr -= vr_offset;
00383 --lscale;
00384 --rscale;
00385 --rconde;
00386 --rcondv;
00387 --work;
00388 --rwork;
00389 --iwork;
00390 --bwork;
00391
00392
00393 if (lsame_(jobvl, "N")) {
00394 ijobvl = 1;
00395 ilvl = FALSE_;
00396 } else if (lsame_(jobvl, "V")) {
00397 ijobvl = 2;
00398 ilvl = TRUE_;
00399 } else {
00400 ijobvl = -1;
00401 ilvl = FALSE_;
00402 }
00403
00404 if (lsame_(jobvr, "N")) {
00405 ijobvr = 1;
00406 ilvr = FALSE_;
00407 } else if (lsame_(jobvr, "V")) {
00408 ijobvr = 2;
00409 ilvr = TRUE_;
00410 } else {
00411 ijobvr = -1;
00412 ilvr = FALSE_;
00413 }
00414 ilv = ilvl || ilvr;
00415
00416 noscl = lsame_(balanc, "N") || lsame_(balanc, "P");
00417 wantsn = lsame_(sense, "N");
00418 wantse = lsame_(sense, "E");
00419 wantsv = lsame_(sense, "V");
00420 wantsb = lsame_(sense, "B");
00421
00422
00423
00424 *info = 0;
00425 lquery = *lwork == -1;
00426 if (! (noscl || lsame_(balanc, "S") || lsame_(
00427 balanc, "B"))) {
00428 *info = -1;
00429 } else if (ijobvl <= 0) {
00430 *info = -2;
00431 } else if (ijobvr <= 0) {
00432 *info = -3;
00433 } else if (! (wantsn || wantse || wantsb || wantsv)) {
00434 *info = -4;
00435 } else if (*n < 0) {
00436 *info = -5;
00437 } else if (*lda < max(1,*n)) {
00438 *info = -7;
00439 } else if (*ldb < max(1,*n)) {
00440 *info = -9;
00441 } else if (*ldvl < 1 || ilvl && *ldvl < *n) {
00442 *info = -13;
00443 } else if (*ldvr < 1 || ilvr && *ldvr < *n) {
00444 *info = -15;
00445 }
00446
00447
00448
00449
00450
00451
00452
00453
00454
00455 if (*info == 0) {
00456 if (*n == 0) {
00457 minwrk = 1;
00458 maxwrk = 1;
00459 } else {
00460 minwrk = *n << 1;
00461 if (wantse) {
00462 minwrk = *n << 2;
00463 } else if (wantsv || wantsb) {
00464 minwrk = (*n << 1) * (*n + 1);
00465 }
00466 maxwrk = minwrk;
00467
00468 i__1 = maxwrk, i__2 = *n + *n * ilaenv_(&c__1, "ZGEQRF", " ", n, &
00469 c__1, n, &c__0);
00470 maxwrk = max(i__1,i__2);
00471
00472 i__1 = maxwrk, i__2 = *n + *n * ilaenv_(&c__1, "ZUNMQR", " ", n, &
00473 c__1, n, &c__0);
00474 maxwrk = max(i__1,i__2);
00475 if (ilvl) {
00476
00477 i__1 = maxwrk, i__2 = *n + *n * ilaenv_(&c__1, "ZUNGQR",
00478 " ", n, &c__1, n, &c__0);
00479 maxwrk = max(i__1,i__2);
00480 }
00481 }
00482 work[1].r = (doublereal) maxwrk, work[1].i = 0.;
00483
00484 if (*lwork < minwrk && ! lquery) {
00485 *info = -25;
00486 }
00487 }
00488
00489 if (*info != 0) {
00490 i__1 = -(*info);
00491 xerbla_("ZGGEVX", &i__1);
00492 return 0;
00493 } else if (lquery) {
00494 return 0;
00495 }
00496
00497
00498
00499 if (*n == 0) {
00500 return 0;
00501 }
00502
00503
00504
00505 eps = dlamch_("P");
00506 smlnum = dlamch_("S");
00507 bignum = 1. / smlnum;
00508 dlabad_(&smlnum, &bignum);
00509 smlnum = sqrt(smlnum) / eps;
00510 bignum = 1. / smlnum;
00511
00512
00513
00514 anrm = zlange_("M", n, n, &a[a_offset], lda, &rwork[1]);
00515 ilascl = FALSE_;
00516 if (anrm > 0. && anrm < smlnum) {
00517 anrmto = smlnum;
00518 ilascl = TRUE_;
00519 } else if (anrm > bignum) {
00520 anrmto = bignum;
00521 ilascl = TRUE_;
00522 }
00523 if (ilascl) {
00524 zlascl_("G", &c__0, &c__0, &anrm, &anrmto, n, n, &a[a_offset], lda, &
00525 ierr);
00526 }
00527
00528
00529
00530 bnrm = zlange_("M", n, n, &b[b_offset], ldb, &rwork[1]);
00531 ilbscl = FALSE_;
00532 if (bnrm > 0. && bnrm < smlnum) {
00533 bnrmto = smlnum;
00534 ilbscl = TRUE_;
00535 } else if (bnrm > bignum) {
00536 bnrmto = bignum;
00537 ilbscl = TRUE_;
00538 }
00539 if (ilbscl) {
00540 zlascl_("G", &c__0, &c__0, &bnrm, &bnrmto, n, n, &b[b_offset], ldb, &
00541 ierr);
00542 }
00543
00544
00545
00546
00547 zggbal_(balanc, n, &a[a_offset], lda, &b[b_offset], ldb, ilo, ihi, &
00548 lscale[1], &rscale[1], &rwork[1], &ierr);
00549
00550
00551
00552 *abnrm = zlange_("1", n, n, &a[a_offset], lda, &rwork[1]);
00553 if (ilascl) {
00554 rwork[1] = *abnrm;
00555 dlascl_("G", &c__0, &c__0, &anrmto, &anrm, &c__1, &c__1, &rwork[1], &
00556 c__1, &ierr);
00557 *abnrm = rwork[1];
00558 }
00559
00560 *bbnrm = zlange_("1", n, n, &b[b_offset], ldb, &rwork[1]);
00561 if (ilbscl) {
00562 rwork[1] = *bbnrm;
00563 dlascl_("G", &c__0, &c__0, &bnrmto, &bnrm, &c__1, &c__1, &rwork[1], &
00564 c__1, &ierr);
00565 *bbnrm = rwork[1];
00566 }
00567
00568
00569
00570
00571 irows = *ihi + 1 - *ilo;
00572 if (ilv || ! wantsn) {
00573 icols = *n + 1 - *ilo;
00574 } else {
00575 icols = irows;
00576 }
00577 itau = 1;
00578 iwrk = itau + irows;
00579 i__1 = *lwork + 1 - iwrk;
00580 zgeqrf_(&irows, &icols, &b[*ilo + *ilo * b_dim1], ldb, &work[itau], &work[
00581 iwrk], &i__1, &ierr);
00582
00583
00584
00585
00586 i__1 = *lwork + 1 - iwrk;
00587 zunmqr_("L", "C", &irows, &icols, &irows, &b[*ilo + *ilo * b_dim1], ldb, &
00588 work[itau], &a[*ilo + *ilo * a_dim1], lda, &work[iwrk], &i__1, &
00589 ierr);
00590
00591
00592
00593
00594 if (ilvl) {
00595 zlaset_("Full", n, n, &c_b1, &c_b2, &vl[vl_offset], ldvl);
00596 if (irows > 1) {
00597 i__1 = irows - 1;
00598 i__2 = irows - 1;
00599 zlacpy_("L", &i__1, &i__2, &b[*ilo + 1 + *ilo * b_dim1], ldb, &vl[
00600 *ilo + 1 + *ilo * vl_dim1], ldvl);
00601 }
00602 i__1 = *lwork + 1 - iwrk;
00603 zungqr_(&irows, &irows, &irows, &vl[*ilo + *ilo * vl_dim1], ldvl, &
00604 work[itau], &work[iwrk], &i__1, &ierr);
00605 }
00606
00607 if (ilvr) {
00608 zlaset_("Full", n, n, &c_b1, &c_b2, &vr[vr_offset], ldvr);
00609 }
00610
00611
00612
00613
00614 if (ilv || ! wantsn) {
00615
00616
00617
00618 zgghrd_(jobvl, jobvr, n, ilo, ihi, &a[a_offset], lda, &b[b_offset],
00619 ldb, &vl[vl_offset], ldvl, &vr[vr_offset], ldvr, &ierr);
00620 } else {
00621 zgghrd_("N", "N", &irows, &c__1, &irows, &a[*ilo + *ilo * a_dim1],
00622 lda, &b[*ilo + *ilo * b_dim1], ldb, &vl[vl_offset], ldvl, &vr[
00623 vr_offset], ldvr, &ierr);
00624 }
00625
00626
00627
00628
00629
00630
00631 iwrk = itau;
00632 if (ilv || ! wantsn) {
00633 *(unsigned char *)chtemp = 'S';
00634 } else {
00635 *(unsigned char *)chtemp = 'E';
00636 }
00637
00638 i__1 = *lwork + 1 - iwrk;
00639 zhgeqz_(chtemp, jobvl, jobvr, n, ilo, ihi, &a[a_offset], lda, &b[b_offset]
00640 , ldb, &alpha[1], &beta[1], &vl[vl_offset], ldvl, &vr[vr_offset],
00641 ldvr, &work[iwrk], &i__1, &rwork[1], &ierr);
00642 if (ierr != 0) {
00643 if (ierr > 0 && ierr <= *n) {
00644 *info = ierr;
00645 } else if (ierr > *n && ierr <= *n << 1) {
00646 *info = ierr - *n;
00647 } else {
00648 *info = *n + 1;
00649 }
00650 goto L90;
00651 }
00652
00653
00654
00655
00656
00657
00658
00659 if (ilv || ! wantsn) {
00660 if (ilv) {
00661 if (ilvl) {
00662 if (ilvr) {
00663 *(unsigned char *)chtemp = 'B';
00664 } else {
00665 *(unsigned char *)chtemp = 'L';
00666 }
00667 } else {
00668 *(unsigned char *)chtemp = 'R';
00669 }
00670
00671 ztgevc_(chtemp, "B", ldumma, n, &a[a_offset], lda, &b[b_offset],
00672 ldb, &vl[vl_offset], ldvl, &vr[vr_offset], ldvr, n, &in, &
00673 work[iwrk], &rwork[1], &ierr);
00674 if (ierr != 0) {
00675 *info = *n + 2;
00676 goto L90;
00677 }
00678 }
00679
00680 if (! wantsn) {
00681
00682
00683
00684
00685
00686
00687
00688
00689
00690
00691 i__1 = *n;
00692 for (i__ = 1; i__ <= i__1; ++i__) {
00693
00694 i__2 = *n;
00695 for (j = 1; j <= i__2; ++j) {
00696 bwork[j] = FALSE_;
00697
00698 }
00699 bwork[i__] = TRUE_;
00700
00701 iwrk = *n + 1;
00702 iwrk1 = iwrk + *n;
00703
00704 if (wantse || wantsb) {
00705 ztgevc_("B", "S", &bwork[1], n, &a[a_offset], lda, &b[
00706 b_offset], ldb, &work[1], n, &work[iwrk], n, &
00707 c__1, &m, &work[iwrk1], &rwork[1], &ierr);
00708 if (ierr != 0) {
00709 *info = *n + 2;
00710 goto L90;
00711 }
00712 }
00713
00714 i__2 = *lwork - iwrk1 + 1;
00715 ztgsna_(sense, "S", &bwork[1], n, &a[a_offset], lda, &b[
00716 b_offset], ldb, &work[1], n, &work[iwrk], n, &rconde[
00717 i__], &rcondv[i__], &c__1, &m, &work[iwrk1], &i__2, &
00718 iwork[1], &ierr);
00719
00720
00721 }
00722 }
00723 }
00724
00725
00726
00727
00728 if (ilvl) {
00729 zggbak_(balanc, "L", n, ilo, ihi, &lscale[1], &rscale[1], n, &vl[
00730 vl_offset], ldvl, &ierr);
00731
00732 i__1 = *n;
00733 for (jc = 1; jc <= i__1; ++jc) {
00734 temp = 0.;
00735 i__2 = *n;
00736 for (jr = 1; jr <= i__2; ++jr) {
00737
00738 i__3 = jr + jc * vl_dim1;
00739 d__3 = temp, d__4 = (d__1 = vl[i__3].r, abs(d__1)) + (d__2 =
00740 d_imag(&vl[jr + jc * vl_dim1]), abs(d__2));
00741 temp = max(d__3,d__4);
00742
00743 }
00744 if (temp < smlnum) {
00745 goto L50;
00746 }
00747 temp = 1. / temp;
00748 i__2 = *n;
00749 for (jr = 1; jr <= i__2; ++jr) {
00750 i__3 = jr + jc * vl_dim1;
00751 i__4 = jr + jc * vl_dim1;
00752 z__1.r = temp * vl[i__4].r, z__1.i = temp * vl[i__4].i;
00753 vl[i__3].r = z__1.r, vl[i__3].i = z__1.i;
00754
00755 }
00756 L50:
00757 ;
00758 }
00759 }
00760
00761 if (ilvr) {
00762 zggbak_(balanc, "R", n, ilo, ihi, &lscale[1], &rscale[1], n, &vr[
00763 vr_offset], ldvr, &ierr);
00764 i__1 = *n;
00765 for (jc = 1; jc <= i__1; ++jc) {
00766 temp = 0.;
00767 i__2 = *n;
00768 for (jr = 1; jr <= i__2; ++jr) {
00769
00770 i__3 = jr + jc * vr_dim1;
00771 d__3 = temp, d__4 = (d__1 = vr[i__3].r, abs(d__1)) + (d__2 =
00772 d_imag(&vr[jr + jc * vr_dim1]), abs(d__2));
00773 temp = max(d__3,d__4);
00774
00775 }
00776 if (temp < smlnum) {
00777 goto L80;
00778 }
00779 temp = 1. / temp;
00780 i__2 = *n;
00781 for (jr = 1; jr <= i__2; ++jr) {
00782 i__3 = jr + jc * vr_dim1;
00783 i__4 = jr + jc * vr_dim1;
00784 z__1.r = temp * vr[i__4].r, z__1.i = temp * vr[i__4].i;
00785 vr[i__3].r = z__1.r, vr[i__3].i = z__1.i;
00786
00787 }
00788 L80:
00789 ;
00790 }
00791 }
00792
00793
00794
00795 if (ilascl) {
00796 zlascl_("G", &c__0, &c__0, &anrmto, &anrm, n, &c__1, &alpha[1], n, &
00797 ierr);
00798 }
00799
00800 if (ilbscl) {
00801 zlascl_("G", &c__0, &c__0, &bnrmto, &bnrm, n, &c__1, &beta[1], n, &
00802 ierr);
00803 }
00804
00805 L90:
00806 work[1].r = (doublereal) maxwrk, work[1].i = 0.;
00807
00808 return 0;
00809
00810
00811
00812 }