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 complex c_b1 = {0.f,0.f};
00019 static complex c_b2 = {1.f,0.f};
00020 static integer c__1 = 1;
00021 static integer c_n1 = -1;
00022 static real c_b29 = 1.f;
00023
00024 int cgegv_(char *jobvl, char *jobvr, integer *n, complex *a,
00025 integer *lda, complex *b, integer *ldb, complex *alpha, complex *beta,
00026 complex *vl, integer *ldvl, complex *vr, integer *ldvr, complex *
00027 work, integer *lwork, real *rwork, integer *info)
00028 {
00029
00030 integer a_dim1, a_offset, b_dim1, b_offset, vl_dim1, vl_offset, vr_dim1,
00031 vr_offset, i__1, i__2, i__3, i__4;
00032 real r__1, r__2, r__3, r__4;
00033 complex q__1, q__2;
00034
00035
00036 double r_imag(complex *);
00037
00038
00039 integer jc, nb, in, jr, nb1, nb2, nb3, ihi, ilo;
00040 real eps;
00041 logical ilv;
00042 real absb, anrm, bnrm;
00043 integer itau;
00044 real temp;
00045 logical ilvl, ilvr;
00046 integer lopt;
00047 real anrm1, anrm2, bnrm1, bnrm2, absai, scale, absar, sbeta;
00048 extern logical lsame_(char *, char *);
00049 integer ileft, iinfo, icols, iwork, irows;
00050 extern int cggbak_(char *, char *, integer *, integer *,
00051 integer *, real *, real *, integer *, complex *, integer *,
00052 integer *), cggbal_(char *, integer *, complex *,
00053 integer *, complex *, integer *, integer *, integer *, real *,
00054 real *, real *, integer *);
00055 extern doublereal clange_(char *, integer *, integer *, complex *,
00056 integer *, real *);
00057 extern int cgghrd_(char *, char *, integer *, integer *,
00058 integer *, complex *, integer *, complex *, integer *, complex *,
00059 integer *, complex *, integer *, integer *);
00060 real salfai;
00061 extern int clascl_(char *, integer *, integer *, real *,
00062 real *, integer *, integer *, complex *, integer *, integer *), cgeqrf_(integer *, integer *, complex *, integer *,
00063 complex *, complex *, integer *, integer *);
00064 real salfar;
00065 extern doublereal slamch_(char *);
00066 extern int clacpy_(char *, integer *, integer *, complex
00067 *, integer *, complex *, integer *), claset_(char *,
00068 integer *, integer *, complex *, complex *, complex *, integer *);
00069 real safmin;
00070 extern int ctgevc_(char *, char *, logical *, integer *,
00071 complex *, integer *, complex *, integer *, complex *, integer *,
00072 complex *, integer *, integer *, integer *, complex *, real *,
00073 integer *);
00074 real safmax;
00075 char chtemp[1];
00076 logical ldumma[1];
00077 extern int chgeqz_(char *, char *, char *, integer *,
00078 integer *, integer *, complex *, integer *, complex *, integer *,
00079 complex *, complex *, complex *, integer *, complex *, integer *,
00080 complex *, integer *, real *, integer *),
00081 xerbla_(char *, integer *);
00082 extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
00083 integer *, integer *);
00084 integer ijobvl, iright;
00085 logical ilimit;
00086 integer ijobvr;
00087 extern int cungqr_(integer *, integer *, integer *,
00088 complex *, integer *, complex *, complex *, integer *, integer *);
00089 integer lwkmin;
00090 extern int cunmqr_(char *, char *, integer *, integer *,
00091 integer *, complex *, integer *, complex *, complex *, integer *,
00092 complex *, integer *, integer *);
00093 integer irwork, lwkopt;
00094 logical lquery;
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
00302
00303
00304
00305
00306 a_dim1 = *lda;
00307 a_offset = 1 + a_dim1;
00308 a -= a_offset;
00309 b_dim1 = *ldb;
00310 b_offset = 1 + b_dim1;
00311 b -= b_offset;
00312 --alpha;
00313 --beta;
00314 vl_dim1 = *ldvl;
00315 vl_offset = 1 + vl_dim1;
00316 vl -= vl_offset;
00317 vr_dim1 = *ldvr;
00318 vr_offset = 1 + vr_dim1;
00319 vr -= vr_offset;
00320 --work;
00321 --rwork;
00322
00323
00324 if (lsame_(jobvl, "N")) {
00325 ijobvl = 1;
00326 ilvl = FALSE_;
00327 } else if (lsame_(jobvl, "V")) {
00328 ijobvl = 2;
00329 ilvl = TRUE_;
00330 } else {
00331 ijobvl = -1;
00332 ilvl = FALSE_;
00333 }
00334
00335 if (lsame_(jobvr, "N")) {
00336 ijobvr = 1;
00337 ilvr = FALSE_;
00338 } else if (lsame_(jobvr, "V")) {
00339 ijobvr = 2;
00340 ilvr = TRUE_;
00341 } else {
00342 ijobvr = -1;
00343 ilvr = FALSE_;
00344 }
00345 ilv = ilvl || ilvr;
00346
00347
00348
00349
00350 i__1 = *n << 1;
00351 lwkmin = max(i__1,1);
00352 lwkopt = lwkmin;
00353 work[1].r = (real) lwkopt, work[1].i = 0.f;
00354 lquery = *lwork == -1;
00355 *info = 0;
00356 if (ijobvl <= 0) {
00357 *info = -1;
00358 } else if (ijobvr <= 0) {
00359 *info = -2;
00360 } else if (*n < 0) {
00361 *info = -3;
00362 } else if (*lda < max(1,*n)) {
00363 *info = -5;
00364 } else if (*ldb < max(1,*n)) {
00365 *info = -7;
00366 } else if (*ldvl < 1 || ilvl && *ldvl < *n) {
00367 *info = -11;
00368 } else if (*ldvr < 1 || ilvr && *ldvr < *n) {
00369 *info = -13;
00370 } else if (*lwork < lwkmin && ! lquery) {
00371 *info = -15;
00372 }
00373
00374 if (*info == 0) {
00375 nb1 = ilaenv_(&c__1, "CGEQRF", " ", n, n, &c_n1, &c_n1);
00376 nb2 = ilaenv_(&c__1, "CUNMQR", " ", n, n, n, &c_n1);
00377 nb3 = ilaenv_(&c__1, "CUNGQR", " ", n, n, n, &c_n1);
00378
00379 i__1 = max(nb1,nb2);
00380 nb = max(i__1,nb3);
00381
00382 i__1 = *n << 1, i__2 = *n * (nb + 1);
00383 lopt = max(i__1,i__2);
00384 work[1].r = (real) lopt, work[1].i = 0.f;
00385 }
00386
00387 if (*info != 0) {
00388 i__1 = -(*info);
00389 xerbla_("CGEGV ", &i__1);
00390 return 0;
00391 } else if (lquery) {
00392 return 0;
00393 }
00394
00395
00396
00397 if (*n == 0) {
00398 return 0;
00399 }
00400
00401
00402
00403 eps = slamch_("E") * slamch_("B");
00404 safmin = slamch_("S");
00405 safmin += safmin;
00406 safmax = 1.f / safmin;
00407
00408
00409
00410 anrm = clange_("M", n, n, &a[a_offset], lda, &rwork[1]);
00411 anrm1 = anrm;
00412 anrm2 = 1.f;
00413 if (anrm < 1.f) {
00414 if (safmax * anrm < 1.f) {
00415 anrm1 = safmin;
00416 anrm2 = safmax * anrm;
00417 }
00418 }
00419
00420 if (anrm > 0.f) {
00421 clascl_("G", &c_n1, &c_n1, &anrm, &c_b29, n, n, &a[a_offset], lda, &
00422 iinfo);
00423 if (iinfo != 0) {
00424 *info = *n + 10;
00425 return 0;
00426 }
00427 }
00428
00429
00430
00431 bnrm = clange_("M", n, n, &b[b_offset], ldb, &rwork[1]);
00432 bnrm1 = bnrm;
00433 bnrm2 = 1.f;
00434 if (bnrm < 1.f) {
00435 if (safmax * bnrm < 1.f) {
00436 bnrm1 = safmin;
00437 bnrm2 = safmax * bnrm;
00438 }
00439 }
00440
00441 if (bnrm > 0.f) {
00442 clascl_("G", &c_n1, &c_n1, &bnrm, &c_b29, n, n, &b[b_offset], ldb, &
00443 iinfo);
00444 if (iinfo != 0) {
00445 *info = *n + 10;
00446 return 0;
00447 }
00448 }
00449
00450
00451
00452
00453 ileft = 1;
00454 iright = *n + 1;
00455 irwork = iright + *n;
00456 cggbal_("P", n, &a[a_offset], lda, &b[b_offset], ldb, &ilo, &ihi, &rwork[
00457 ileft], &rwork[iright], &rwork[irwork], &iinfo);
00458 if (iinfo != 0) {
00459 *info = *n + 1;
00460 goto L80;
00461 }
00462
00463
00464
00465 irows = ihi + 1 - ilo;
00466 if (ilv) {
00467 icols = *n + 1 - ilo;
00468 } else {
00469 icols = irows;
00470 }
00471 itau = 1;
00472 iwork = itau + irows;
00473 i__1 = *lwork + 1 - iwork;
00474 cgeqrf_(&irows, &icols, &b[ilo + ilo * b_dim1], ldb, &work[itau], &work[
00475 iwork], &i__1, &iinfo);
00476 if (iinfo >= 0) {
00477
00478 i__3 = iwork;
00479 i__1 = lwkopt, i__2 = (integer) work[i__3].r + iwork - 1;
00480 lwkopt = max(i__1,i__2);
00481 }
00482 if (iinfo != 0) {
00483 *info = *n + 2;
00484 goto L80;
00485 }
00486
00487 i__1 = *lwork + 1 - iwork;
00488 cunmqr_("L", "C", &irows, &icols, &irows, &b[ilo + ilo * b_dim1], ldb, &
00489 work[itau], &a[ilo + ilo * a_dim1], lda, &work[iwork], &i__1, &
00490 iinfo);
00491 if (iinfo >= 0) {
00492
00493 i__3 = iwork;
00494 i__1 = lwkopt, i__2 = (integer) work[i__3].r + iwork - 1;
00495 lwkopt = max(i__1,i__2);
00496 }
00497 if (iinfo != 0) {
00498 *info = *n + 3;
00499 goto L80;
00500 }
00501
00502 if (ilvl) {
00503 claset_("Full", n, n, &c_b1, &c_b2, &vl[vl_offset], ldvl);
00504 i__1 = irows - 1;
00505 i__2 = irows - 1;
00506 clacpy_("L", &i__1, &i__2, &b[ilo + 1 + ilo * b_dim1], ldb, &vl[ilo +
00507 1 + ilo * vl_dim1], ldvl);
00508 i__1 = *lwork + 1 - iwork;
00509 cungqr_(&irows, &irows, &irows, &vl[ilo + ilo * vl_dim1], ldvl, &work[
00510 itau], &work[iwork], &i__1, &iinfo);
00511 if (iinfo >= 0) {
00512
00513 i__3 = iwork;
00514 i__1 = lwkopt, i__2 = (integer) work[i__3].r + iwork - 1;
00515 lwkopt = max(i__1,i__2);
00516 }
00517 if (iinfo != 0) {
00518 *info = *n + 4;
00519 goto L80;
00520 }
00521 }
00522
00523 if (ilvr) {
00524 claset_("Full", n, n, &c_b1, &c_b2, &vr[vr_offset], ldvr);
00525 }
00526
00527
00528
00529 if (ilv) {
00530
00531
00532
00533 cgghrd_(jobvl, jobvr, n, &ilo, &ihi, &a[a_offset], lda, &b[b_offset],
00534 ldb, &vl[vl_offset], ldvl, &vr[vr_offset], ldvr, &iinfo);
00535 } else {
00536 cgghrd_("N", "N", &irows, &c__1, &irows, &a[ilo + ilo * a_dim1], lda,
00537 &b[ilo + ilo * b_dim1], ldb, &vl[vl_offset], ldvl, &vr[
00538 vr_offset], ldvr, &iinfo);
00539 }
00540 if (iinfo != 0) {
00541 *info = *n + 5;
00542 goto L80;
00543 }
00544
00545
00546
00547 iwork = itau;
00548 if (ilv) {
00549 *(unsigned char *)chtemp = 'S';
00550 } else {
00551 *(unsigned char *)chtemp = 'E';
00552 }
00553 i__1 = *lwork + 1 - iwork;
00554 chgeqz_(chtemp, jobvl, jobvr, n, &ilo, &ihi, &a[a_offset], lda, &b[
00555 b_offset], ldb, &alpha[1], &beta[1], &vl[vl_offset], ldvl, &vr[
00556 vr_offset], ldvr, &work[iwork], &i__1, &rwork[irwork], &iinfo);
00557 if (iinfo >= 0) {
00558
00559 i__3 = iwork;
00560 i__1 = lwkopt, i__2 = (integer) work[i__3].r + iwork - 1;
00561 lwkopt = max(i__1,i__2);
00562 }
00563 if (iinfo != 0) {
00564 if (iinfo > 0 && iinfo <= *n) {
00565 *info = iinfo;
00566 } else if (iinfo > *n && iinfo <= *n << 1) {
00567 *info = iinfo - *n;
00568 } else {
00569 *info = *n + 6;
00570 }
00571 goto L80;
00572 }
00573
00574 if (ilv) {
00575
00576
00577
00578 if (ilvl) {
00579 if (ilvr) {
00580 *(unsigned char *)chtemp = 'B';
00581 } else {
00582 *(unsigned char *)chtemp = 'L';
00583 }
00584 } else {
00585 *(unsigned char *)chtemp = 'R';
00586 }
00587
00588 ctgevc_(chtemp, "B", ldumma, n, &a[a_offset], lda, &b[b_offset], ldb,
00589 &vl[vl_offset], ldvl, &vr[vr_offset], ldvr, n, &in, &work[
00590 iwork], &rwork[irwork], &iinfo);
00591 if (iinfo != 0) {
00592 *info = *n + 7;
00593 goto L80;
00594 }
00595
00596
00597
00598 if (ilvl) {
00599 cggbak_("P", "L", n, &ilo, &ihi, &rwork[ileft], &rwork[iright], n,
00600 &vl[vl_offset], ldvl, &iinfo);
00601 if (iinfo != 0) {
00602 *info = *n + 8;
00603 goto L80;
00604 }
00605 i__1 = *n;
00606 for (jc = 1; jc <= i__1; ++jc) {
00607 temp = 0.f;
00608 i__2 = *n;
00609 for (jr = 1; jr <= i__2; ++jr) {
00610
00611 i__3 = jr + jc * vl_dim1;
00612 r__3 = temp, r__4 = (r__1 = vl[i__3].r, dabs(r__1)) + (
00613 r__2 = r_imag(&vl[jr + jc * vl_dim1]), dabs(r__2))
00614 ;
00615 temp = dmax(r__3,r__4);
00616
00617 }
00618 if (temp < safmin) {
00619 goto L30;
00620 }
00621 temp = 1.f / temp;
00622 i__2 = *n;
00623 for (jr = 1; jr <= i__2; ++jr) {
00624 i__3 = jr + jc * vl_dim1;
00625 i__4 = jr + jc * vl_dim1;
00626 q__1.r = temp * vl[i__4].r, q__1.i = temp * vl[i__4].i;
00627 vl[i__3].r = q__1.r, vl[i__3].i = q__1.i;
00628
00629 }
00630 L30:
00631 ;
00632 }
00633 }
00634 if (ilvr) {
00635 cggbak_("P", "R", n, &ilo, &ihi, &rwork[ileft], &rwork[iright], n,
00636 &vr[vr_offset], ldvr, &iinfo);
00637 if (iinfo != 0) {
00638 *info = *n + 9;
00639 goto L80;
00640 }
00641 i__1 = *n;
00642 for (jc = 1; jc <= i__1; ++jc) {
00643 temp = 0.f;
00644 i__2 = *n;
00645 for (jr = 1; jr <= i__2; ++jr) {
00646
00647 i__3 = jr + jc * vr_dim1;
00648 r__3 = temp, r__4 = (r__1 = vr[i__3].r, dabs(r__1)) + (
00649 r__2 = r_imag(&vr[jr + jc * vr_dim1]), dabs(r__2))
00650 ;
00651 temp = dmax(r__3,r__4);
00652
00653 }
00654 if (temp < safmin) {
00655 goto L60;
00656 }
00657 temp = 1.f / temp;
00658 i__2 = *n;
00659 for (jr = 1; jr <= i__2; ++jr) {
00660 i__3 = jr + jc * vr_dim1;
00661 i__4 = jr + jc * vr_dim1;
00662 q__1.r = temp * vr[i__4].r, q__1.i = temp * vr[i__4].i;
00663 vr[i__3].r = q__1.r, vr[i__3].i = q__1.i;
00664
00665 }
00666 L60:
00667 ;
00668 }
00669 }
00670
00671
00672
00673 }
00674
00675
00676
00677
00678
00679
00680
00681
00682
00683 i__1 = *n;
00684 for (jc = 1; jc <= i__1; ++jc) {
00685 i__2 = jc;
00686 absar = (r__1 = alpha[i__2].r, dabs(r__1));
00687 absai = (r__1 = r_imag(&alpha[jc]), dabs(r__1));
00688 i__2 = jc;
00689 absb = (r__1 = beta[i__2].r, dabs(r__1));
00690 i__2 = jc;
00691 salfar = anrm * alpha[i__2].r;
00692 salfai = anrm * r_imag(&alpha[jc]);
00693 i__2 = jc;
00694 sbeta = bnrm * beta[i__2].r;
00695 ilimit = FALSE_;
00696 scale = 1.f;
00697
00698
00699
00700
00701 r__1 = safmin, r__2 = eps * absar, r__1 = max(r__1,r__2), r__2 = eps *
00702 absb;
00703 if (dabs(salfai) < safmin && absai >= dmax(r__1,r__2)) {
00704 ilimit = TRUE_;
00705
00706 r__1 = safmin, r__2 = anrm2 * absai;
00707 scale = safmin / anrm1 / dmax(r__1,r__2);
00708 }
00709
00710
00711
00712
00713 r__1 = safmin, r__2 = eps * absai, r__1 = max(r__1,r__2), r__2 = eps *
00714 absb;
00715 if (dabs(salfar) < safmin && absar >= dmax(r__1,r__2)) {
00716 ilimit = TRUE_;
00717
00718
00719 r__3 = safmin, r__4 = anrm2 * absar;
00720 r__1 = scale, r__2 = safmin / anrm1 / dmax(r__3,r__4);
00721 scale = dmax(r__1,r__2);
00722 }
00723
00724
00725
00726
00727 r__1 = safmin, r__2 = eps * absar, r__1 = max(r__1,r__2), r__2 = eps *
00728 absai;
00729 if (dabs(sbeta) < safmin && absb >= dmax(r__1,r__2)) {
00730 ilimit = TRUE_;
00731
00732
00733 r__3 = safmin, r__4 = bnrm2 * absb;
00734 r__1 = scale, r__2 = safmin / bnrm1 / dmax(r__3,r__4);
00735 scale = dmax(r__1,r__2);
00736 }
00737
00738
00739
00740 if (ilimit) {
00741
00742 r__1 = dabs(salfar), r__2 = dabs(salfai), r__1 = max(r__1,r__2),
00743 r__2 = dabs(sbeta);
00744 temp = scale * safmin * dmax(r__1,r__2);
00745 if (temp > 1.f) {
00746 scale /= temp;
00747 }
00748 if (scale < 1.f) {
00749 ilimit = FALSE_;
00750 }
00751 }
00752
00753
00754
00755 if (ilimit) {
00756 i__2 = jc;
00757 salfar = scale * alpha[i__2].r * anrm;
00758 salfai = scale * r_imag(&alpha[jc]) * anrm;
00759 i__2 = jc;
00760 q__2.r = scale * beta[i__2].r, q__2.i = scale * beta[i__2].i;
00761 q__1.r = bnrm * q__2.r, q__1.i = bnrm * q__2.i;
00762 sbeta = q__1.r;
00763 }
00764 i__2 = jc;
00765 q__1.r = salfar, q__1.i = salfai;
00766 alpha[i__2].r = q__1.r, alpha[i__2].i = q__1.i;
00767 i__2 = jc;
00768 beta[i__2].r = sbeta, beta[i__2].i = 0.f;
00769
00770 }
00771
00772 L80:
00773 work[1].r = (real) lwkopt, work[1].i = 0.f;
00774
00775 return 0;
00776
00777
00778
00779 }