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 static integer c_n1 = -1;
00023
00024 int zggev_(char *jobvl, char *jobvr, integer *n,
00025 doublecomplex *a, integer *lda, doublecomplex *b, integer *ldb,
00026 doublecomplex *alpha, doublecomplex *beta, doublecomplex *vl, integer
00027 *ldvl, doublecomplex *vr, integer *ldvr, doublecomplex *work, integer
00028 *lwork, doublereal *rwork, integer *info)
00029 {
00030
00031 integer a_dim1, a_offset, b_dim1, b_offset, vl_dim1, vl_offset, vr_dim1,
00032 vr_offset, i__1, i__2, i__3, i__4;
00033 doublereal d__1, d__2, d__3, d__4;
00034 doublecomplex z__1;
00035
00036
00037 double sqrt(doublereal), d_imag(doublecomplex *);
00038
00039
00040 integer jc, in, jr, ihi, ilo;
00041 doublereal eps;
00042 logical ilv;
00043 doublereal anrm, bnrm;
00044 integer ierr, itau;
00045 doublereal temp;
00046 logical ilvl, ilvr;
00047 integer iwrk;
00048 extern logical lsame_(char *, char *);
00049 integer ileft, icols, irwrk, irows;
00050 extern int dlabad_(doublereal *, doublereal *);
00051 extern doublereal dlamch_(char *);
00052 extern int zggbak_(char *, char *, integer *, integer *,
00053 integer *, doublereal *, doublereal *, integer *, doublecomplex *,
00054 integer *, integer *), zggbal_(char *, integer *,
00055 doublecomplex *, integer *, doublecomplex *, integer *, integer *
00056 , integer *, doublereal *, doublereal *, doublereal *, integer *);
00057 logical ilascl, ilbscl;
00058 extern int xerbla_(char *, integer *);
00059 extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
00060 integer *, integer *);
00061 logical ldumma[1];
00062 char chtemp[1];
00063 doublereal bignum;
00064 extern doublereal zlange_(char *, integer *, integer *, doublecomplex *,
00065 integer *, doublereal *);
00066 integer ijobvl, iright;
00067 extern int zgghrd_(char *, char *, integer *, integer *,
00068 integer *, doublecomplex *, integer *, doublecomplex *, integer *,
00069 doublecomplex *, integer *, doublecomplex *, integer *, integer *
00070 ), zlascl_(char *, integer *, integer *,
00071 doublereal *, doublereal *, integer *, integer *, doublecomplex *,
00072 integer *, integer *);
00073 integer ijobvr;
00074 extern int zgeqrf_(integer *, integer *, doublecomplex *,
00075 integer *, doublecomplex *, doublecomplex *, integer *, integer *
00076 );
00077 doublereal anrmto;
00078 integer lwkmin;
00079 doublereal bnrmto;
00080 extern int zlacpy_(char *, integer *, integer *,
00081 doublecomplex *, integer *, doublecomplex *, integer *),
00082 zlaset_(char *, integer *, integer *, doublecomplex *,
00083 doublecomplex *, doublecomplex *, integer *), ztgevc_(
00084 char *, char *, logical *, integer *, doublecomplex *, integer *,
00085 doublecomplex *, integer *, doublecomplex *, integer *,
00086 doublecomplex *, integer *, integer *, integer *, doublecomplex *,
00087 doublereal *, integer *), zhgeqz_(char *, char *,
00088 char *, integer *, integer *, integer *, doublecomplex *,
00089 integer *, doublecomplex *, integer *, doublecomplex *,
00090 doublecomplex *, doublecomplex *, integer *, doublecomplex *,
00091 integer *, doublecomplex *, integer *, doublereal *, integer *);
00092 doublereal smlnum;
00093 integer lwkopt;
00094 logical lquery;
00095 extern int zungqr_(integer *, integer *, integer *,
00096 doublecomplex *, integer *, doublecomplex *, doublecomplex *,
00097 integer *, integer *), zunmqr_(char *, char *, integer *, integer
00098 *, integer *, doublecomplex *, integer *, doublecomplex *,
00099 doublecomplex *, integer *, doublecomplex *, integer *, integer *);
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 a_dim1 = *lda;
00248 a_offset = 1 + a_dim1;
00249 a -= a_offset;
00250 b_dim1 = *ldb;
00251 b_offset = 1 + b_dim1;
00252 b -= b_offset;
00253 --alpha;
00254 --beta;
00255 vl_dim1 = *ldvl;
00256 vl_offset = 1 + vl_dim1;
00257 vl -= vl_offset;
00258 vr_dim1 = *ldvr;
00259 vr_offset = 1 + vr_dim1;
00260 vr -= vr_offset;
00261 --work;
00262 --rwork;
00263
00264
00265 if (lsame_(jobvl, "N")) {
00266 ijobvl = 1;
00267 ilvl = FALSE_;
00268 } else if (lsame_(jobvl, "V")) {
00269 ijobvl = 2;
00270 ilvl = TRUE_;
00271 } else {
00272 ijobvl = -1;
00273 ilvl = FALSE_;
00274 }
00275
00276 if (lsame_(jobvr, "N")) {
00277 ijobvr = 1;
00278 ilvr = FALSE_;
00279 } else if (lsame_(jobvr, "V")) {
00280 ijobvr = 2;
00281 ilvr = TRUE_;
00282 } else {
00283 ijobvr = -1;
00284 ilvr = FALSE_;
00285 }
00286 ilv = ilvl || ilvr;
00287
00288
00289
00290 *info = 0;
00291 lquery = *lwork == -1;
00292 if (ijobvl <= 0) {
00293 *info = -1;
00294 } else if (ijobvr <= 0) {
00295 *info = -2;
00296 } else if (*n < 0) {
00297 *info = -3;
00298 } else if (*lda < max(1,*n)) {
00299 *info = -5;
00300 } else if (*ldb < max(1,*n)) {
00301 *info = -7;
00302 } else if (*ldvl < 1 || ilvl && *ldvl < *n) {
00303 *info = -11;
00304 } else if (*ldvr < 1 || ilvr && *ldvr < *n) {
00305 *info = -13;
00306 }
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316 if (*info == 0) {
00317
00318 i__1 = 1, i__2 = *n << 1;
00319 lwkmin = max(i__1,i__2);
00320
00321 i__1 = 1, i__2 = *n + *n * ilaenv_(&c__1, "ZGEQRF", " ", n, &c__1, n,
00322 &c__0);
00323 lwkopt = max(i__1,i__2);
00324
00325 i__1 = lwkopt, i__2 = *n + *n * ilaenv_(&c__1, "ZUNMQR", " ", n, &
00326 c__1, n, &c__0);
00327 lwkopt = max(i__1,i__2);
00328 if (ilvl) {
00329
00330 i__1 = lwkopt, i__2 = *n + *n * ilaenv_(&c__1, "ZUNGQR", " ", n, &
00331 c__1, n, &c_n1);
00332 lwkopt = max(i__1,i__2);
00333 }
00334 work[1].r = (doublereal) lwkopt, work[1].i = 0.;
00335
00336 if (*lwork < lwkmin && ! lquery) {
00337 *info = -15;
00338 }
00339 }
00340
00341 if (*info != 0) {
00342 i__1 = -(*info);
00343 xerbla_("ZGGEV ", &i__1);
00344 return 0;
00345 } else if (lquery) {
00346 return 0;
00347 }
00348
00349
00350
00351 if (*n == 0) {
00352 return 0;
00353 }
00354
00355
00356
00357 eps = dlamch_("E") * dlamch_("B");
00358 smlnum = dlamch_("S");
00359 bignum = 1. / smlnum;
00360 dlabad_(&smlnum, &bignum);
00361 smlnum = sqrt(smlnum) / eps;
00362 bignum = 1. / smlnum;
00363
00364
00365
00366 anrm = zlange_("M", n, n, &a[a_offset], lda, &rwork[1]);
00367 ilascl = FALSE_;
00368 if (anrm > 0. && anrm < smlnum) {
00369 anrmto = smlnum;
00370 ilascl = TRUE_;
00371 } else if (anrm > bignum) {
00372 anrmto = bignum;
00373 ilascl = TRUE_;
00374 }
00375 if (ilascl) {
00376 zlascl_("G", &c__0, &c__0, &anrm, &anrmto, n, n, &a[a_offset], lda, &
00377 ierr);
00378 }
00379
00380
00381
00382 bnrm = zlange_("M", n, n, &b[b_offset], ldb, &rwork[1]);
00383 ilbscl = FALSE_;
00384 if (bnrm > 0. && bnrm < smlnum) {
00385 bnrmto = smlnum;
00386 ilbscl = TRUE_;
00387 } else if (bnrm > bignum) {
00388 bnrmto = bignum;
00389 ilbscl = TRUE_;
00390 }
00391 if (ilbscl) {
00392 zlascl_("G", &c__0, &c__0, &bnrm, &bnrmto, n, n, &b[b_offset], ldb, &
00393 ierr);
00394 }
00395
00396
00397
00398
00399 ileft = 1;
00400 iright = *n + 1;
00401 irwrk = iright + *n;
00402 zggbal_("P", n, &a[a_offset], lda, &b[b_offset], ldb, &ilo, &ihi, &rwork[
00403 ileft], &rwork[iright], &rwork[irwrk], &ierr);
00404
00405
00406
00407
00408 irows = ihi + 1 - ilo;
00409 if (ilv) {
00410 icols = *n + 1 - ilo;
00411 } else {
00412 icols = irows;
00413 }
00414 itau = 1;
00415 iwrk = itau + irows;
00416 i__1 = *lwork + 1 - iwrk;
00417 zgeqrf_(&irows, &icols, &b[ilo + ilo * b_dim1], ldb, &work[itau], &work[
00418 iwrk], &i__1, &ierr);
00419
00420
00421
00422
00423 i__1 = *lwork + 1 - iwrk;
00424 zunmqr_("L", "C", &irows, &icols, &irows, &b[ilo + ilo * b_dim1], ldb, &
00425 work[itau], &a[ilo + ilo * a_dim1], lda, &work[iwrk], &i__1, &
00426 ierr);
00427
00428
00429
00430
00431 if (ilvl) {
00432 zlaset_("Full", n, n, &c_b1, &c_b2, &vl[vl_offset], ldvl);
00433 if (irows > 1) {
00434 i__1 = irows - 1;
00435 i__2 = irows - 1;
00436 zlacpy_("L", &i__1, &i__2, &b[ilo + 1 + ilo * b_dim1], ldb, &vl[
00437 ilo + 1 + ilo * vl_dim1], ldvl);
00438 }
00439 i__1 = *lwork + 1 - iwrk;
00440 zungqr_(&irows, &irows, &irows, &vl[ilo + ilo * vl_dim1], ldvl, &work[
00441 itau], &work[iwrk], &i__1, &ierr);
00442 }
00443
00444
00445
00446 if (ilvr) {
00447 zlaset_("Full", n, n, &c_b1, &c_b2, &vr[vr_offset], ldvr);
00448 }
00449
00450
00451
00452 if (ilv) {
00453
00454
00455
00456 zgghrd_(jobvl, jobvr, n, &ilo, &ihi, &a[a_offset], lda, &b[b_offset],
00457 ldb, &vl[vl_offset], ldvl, &vr[vr_offset], ldvr, &ierr);
00458 } else {
00459 zgghrd_("N", "N", &irows, &c__1, &irows, &a[ilo + ilo * a_dim1], lda,
00460 &b[ilo + ilo * b_dim1], ldb, &vl[vl_offset], ldvl, &vr[
00461 vr_offset], ldvr, &ierr);
00462 }
00463
00464
00465
00466
00467
00468
00469 iwrk = itau;
00470 if (ilv) {
00471 *(unsigned char *)chtemp = 'S';
00472 } else {
00473 *(unsigned char *)chtemp = 'E';
00474 }
00475 i__1 = *lwork + 1 - iwrk;
00476 zhgeqz_(chtemp, jobvl, jobvr, n, &ilo, &ihi, &a[a_offset], lda, &b[
00477 b_offset], ldb, &alpha[1], &beta[1], &vl[vl_offset], ldvl, &vr[
00478 vr_offset], ldvr, &work[iwrk], &i__1, &rwork[irwrk], &ierr);
00479 if (ierr != 0) {
00480 if (ierr > 0 && ierr <= *n) {
00481 *info = ierr;
00482 } else if (ierr > *n && ierr <= *n << 1) {
00483 *info = ierr - *n;
00484 } else {
00485 *info = *n + 1;
00486 }
00487 goto L70;
00488 }
00489
00490
00491
00492
00493
00494 if (ilv) {
00495 if (ilvl) {
00496 if (ilvr) {
00497 *(unsigned char *)chtemp = 'B';
00498 } else {
00499 *(unsigned char *)chtemp = 'L';
00500 }
00501 } else {
00502 *(unsigned char *)chtemp = 'R';
00503 }
00504
00505 ztgevc_(chtemp, "B", ldumma, n, &a[a_offset], lda, &b[b_offset], ldb,
00506 &vl[vl_offset], ldvl, &vr[vr_offset], ldvr, n, &in, &work[
00507 iwrk], &rwork[irwrk], &ierr);
00508 if (ierr != 0) {
00509 *info = *n + 2;
00510 goto L70;
00511 }
00512
00513
00514
00515
00516 if (ilvl) {
00517 zggbak_("P", "L", n, &ilo, &ihi, &rwork[ileft], &rwork[iright], n,
00518 &vl[vl_offset], ldvl, &ierr);
00519 i__1 = *n;
00520 for (jc = 1; jc <= i__1; ++jc) {
00521 temp = 0.;
00522 i__2 = *n;
00523 for (jr = 1; jr <= i__2; ++jr) {
00524
00525 i__3 = jr + jc * vl_dim1;
00526 d__3 = temp, d__4 = (d__1 = vl[i__3].r, abs(d__1)) + (
00527 d__2 = d_imag(&vl[jr + jc * vl_dim1]), abs(d__2));
00528 temp = max(d__3,d__4);
00529
00530 }
00531 if (temp < smlnum) {
00532 goto L30;
00533 }
00534 temp = 1. / temp;
00535 i__2 = *n;
00536 for (jr = 1; jr <= i__2; ++jr) {
00537 i__3 = jr + jc * vl_dim1;
00538 i__4 = jr + jc * vl_dim1;
00539 z__1.r = temp * vl[i__4].r, z__1.i = temp * vl[i__4].i;
00540 vl[i__3].r = z__1.r, vl[i__3].i = z__1.i;
00541
00542 }
00543 L30:
00544 ;
00545 }
00546 }
00547 if (ilvr) {
00548 zggbak_("P", "R", n, &ilo, &ihi, &rwork[ileft], &rwork[iright], n,
00549 &vr[vr_offset], ldvr, &ierr);
00550 i__1 = *n;
00551 for (jc = 1; jc <= i__1; ++jc) {
00552 temp = 0.;
00553 i__2 = *n;
00554 for (jr = 1; jr <= i__2; ++jr) {
00555
00556 i__3 = jr + jc * vr_dim1;
00557 d__3 = temp, d__4 = (d__1 = vr[i__3].r, abs(d__1)) + (
00558 d__2 = d_imag(&vr[jr + jc * vr_dim1]), abs(d__2));
00559 temp = max(d__3,d__4);
00560
00561 }
00562 if (temp < smlnum) {
00563 goto L60;
00564 }
00565 temp = 1. / temp;
00566 i__2 = *n;
00567 for (jr = 1; jr <= i__2; ++jr) {
00568 i__3 = jr + jc * vr_dim1;
00569 i__4 = jr + jc * vr_dim1;
00570 z__1.r = temp * vr[i__4].r, z__1.i = temp * vr[i__4].i;
00571 vr[i__3].r = z__1.r, vr[i__3].i = z__1.i;
00572
00573 }
00574 L60:
00575 ;
00576 }
00577 }
00578 }
00579
00580
00581
00582 if (ilascl) {
00583 zlascl_("G", &c__0, &c__0, &anrmto, &anrm, n, &c__1, &alpha[1], n, &
00584 ierr);
00585 }
00586
00587 if (ilbscl) {
00588 zlascl_("G", &c__0, &c__0, &bnrmto, &bnrm, n, &c__1, &beta[1], n, &
00589 ierr);
00590 }
00591
00592 L70:
00593 work[1].r = (doublereal) lwkopt, work[1].i = 0.;
00594
00595 return 0;
00596
00597
00598
00599 }