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 static doublereal c_b36 = 0.;
00022 static doublereal c_b37 = 1.;
00023
00024 int dggev_(char *jobvl, char *jobvr, integer *n, doublereal *
00025 a, integer *lda, doublereal *b, integer *ldb, doublereal *alphar,
00026 doublereal *alphai, doublereal *beta, doublereal *vl, integer *ldvl,
00027 doublereal *vr, integer *ldvr, doublereal *work, integer *lwork,
00028 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;
00033 doublereal d__1, d__2, d__3, d__4;
00034
00035
00036 double sqrt(doublereal);
00037
00038
00039 integer jc, in, jr, ihi, ilo;
00040 doublereal eps;
00041 logical ilv;
00042 doublereal anrm, bnrm;
00043 integer ierr, itau;
00044 doublereal temp;
00045 logical ilvl, ilvr;
00046 integer iwrk;
00047 extern logical lsame_(char *, char *);
00048 integer ileft, icols, irows;
00049 extern int dlabad_(doublereal *, doublereal *), dggbak_(
00050 char *, char *, integer *, integer *, integer *, doublereal *,
00051 doublereal *, integer *, doublereal *, integer *, integer *), dggbal_(char *, integer *, doublereal *, integer
00052 *, doublereal *, integer *, integer *, integer *, doublereal *,
00053 doublereal *, doublereal *, integer *);
00054 extern doublereal dlamch_(char *), dlange_(char *, integer *,
00055 integer *, doublereal *, integer *, doublereal *);
00056 extern int dgghrd_(char *, char *, integer *, integer *,
00057 integer *, doublereal *, integer *, doublereal *, integer *,
00058 doublereal *, integer *, doublereal *, integer *, integer *), dlascl_(char *, integer *, integer *, doublereal
00059 *, doublereal *, integer *, integer *, doublereal *, integer *,
00060 integer *);
00061 logical ilascl, ilbscl;
00062 extern int dgeqrf_(integer *, integer *, doublereal *,
00063 integer *, doublereal *, doublereal *, integer *, integer *),
00064 dlacpy_(char *, integer *, integer *, doublereal *, integer *,
00065 doublereal *, integer *), dlaset_(char *, integer *,
00066 integer *, doublereal *, doublereal *, doublereal *, integer *), dtgevc_(char *, char *, logical *, integer *, doublereal
00067 *, integer *, doublereal *, integer *, doublereal *, integer *,
00068 doublereal *, integer *, integer *, integer *, doublereal *,
00069 integer *);
00070 logical ldumma[1];
00071 char chtemp[1];
00072 doublereal bignum;
00073 extern int dhgeqz_(char *, char *, char *, integer *,
00074 integer *, integer *, doublereal *, integer *, doublereal *,
00075 integer *, doublereal *, doublereal *, doublereal *, doublereal *,
00076 integer *, doublereal *, integer *, doublereal *, integer *,
00077 integer *), xerbla_(char *, integer *);
00078 extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
00079 integer *, integer *);
00080 integer ijobvl, iright, ijobvr;
00081 extern int dorgqr_(integer *, integer *, integer *,
00082 doublereal *, integer *, doublereal *, doublereal *, integer *,
00083 integer *);
00084 doublereal anrmto, bnrmto;
00085 extern int dormqr_(char *, char *, integer *, integer *,
00086 integer *, doublereal *, integer *, doublereal *, doublereal *,
00087 integer *, doublereal *, integer *, integer *);
00088 integer minwrk, maxwrk;
00089 doublereal smlnum;
00090 logical lquery;
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
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243 a_dim1 = *lda;
00244 a_offset = 1 + a_dim1;
00245 a -= a_offset;
00246 b_dim1 = *ldb;
00247 b_offset = 1 + b_dim1;
00248 b -= b_offset;
00249 --alphar;
00250 --alphai;
00251 --beta;
00252 vl_dim1 = *ldvl;
00253 vl_offset = 1 + vl_dim1;
00254 vl -= vl_offset;
00255 vr_dim1 = *ldvr;
00256 vr_offset = 1 + vr_dim1;
00257 vr -= vr_offset;
00258 --work;
00259
00260
00261 if (lsame_(jobvl, "N")) {
00262 ijobvl = 1;
00263 ilvl = FALSE_;
00264 } else if (lsame_(jobvl, "V")) {
00265 ijobvl = 2;
00266 ilvl = TRUE_;
00267 } else {
00268 ijobvl = -1;
00269 ilvl = FALSE_;
00270 }
00271
00272 if (lsame_(jobvr, "N")) {
00273 ijobvr = 1;
00274 ilvr = FALSE_;
00275 } else if (lsame_(jobvr, "V")) {
00276 ijobvr = 2;
00277 ilvr = TRUE_;
00278 } else {
00279 ijobvr = -1;
00280 ilvr = FALSE_;
00281 }
00282 ilv = ilvl || ilvr;
00283
00284
00285
00286 *info = 0;
00287 lquery = *lwork == -1;
00288 if (ijobvl <= 0) {
00289 *info = -1;
00290 } else if (ijobvr <= 0) {
00291 *info = -2;
00292 } else if (*n < 0) {
00293 *info = -3;
00294 } else if (*lda < max(1,*n)) {
00295 *info = -5;
00296 } else if (*ldb < max(1,*n)) {
00297 *info = -7;
00298 } else if (*ldvl < 1 || ilvl && *ldvl < *n) {
00299 *info = -12;
00300 } else if (*ldvr < 1 || ilvr && *ldvr < *n) {
00301 *info = -14;
00302 }
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312 if (*info == 0) {
00313
00314 i__1 = 1, i__2 = *n << 3;
00315 minwrk = max(i__1,i__2);
00316
00317 i__1 = 1, i__2 = *n * (ilaenv_(&c__1, "DGEQRF", " ", n, &c__1, n, &
00318 c__0) + 7);
00319 maxwrk = max(i__1,i__2);
00320
00321 i__1 = maxwrk, i__2 = *n * (ilaenv_(&c__1, "DORMQR", " ", n, &c__1, n,
00322 &c__0) + 7);
00323 maxwrk = max(i__1,i__2);
00324 if (ilvl) {
00325
00326 i__1 = maxwrk, i__2 = *n * (ilaenv_(&c__1, "DORGQR", " ", n, &
00327 c__1, n, &c_n1) + 7);
00328 maxwrk = max(i__1,i__2);
00329 }
00330 work[1] = (doublereal) maxwrk;
00331
00332 if (*lwork < minwrk && ! lquery) {
00333 *info = -16;
00334 }
00335 }
00336
00337 if (*info != 0) {
00338 i__1 = -(*info);
00339 xerbla_("DGGEV ", &i__1);
00340 return 0;
00341 } else if (lquery) {
00342 return 0;
00343 }
00344
00345
00346
00347 if (*n == 0) {
00348 return 0;
00349 }
00350
00351
00352
00353 eps = dlamch_("P");
00354 smlnum = dlamch_("S");
00355 bignum = 1. / smlnum;
00356 dlabad_(&smlnum, &bignum);
00357 smlnum = sqrt(smlnum) / eps;
00358 bignum = 1. / smlnum;
00359
00360
00361
00362 anrm = dlange_("M", n, n, &a[a_offset], lda, &work[1]);
00363 ilascl = FALSE_;
00364 if (anrm > 0. && anrm < smlnum) {
00365 anrmto = smlnum;
00366 ilascl = TRUE_;
00367 } else if (anrm > bignum) {
00368 anrmto = bignum;
00369 ilascl = TRUE_;
00370 }
00371 if (ilascl) {
00372 dlascl_("G", &c__0, &c__0, &anrm, &anrmto, n, n, &a[a_offset], lda, &
00373 ierr);
00374 }
00375
00376
00377
00378 bnrm = dlange_("M", n, n, &b[b_offset], ldb, &work[1]);
00379 ilbscl = FALSE_;
00380 if (bnrm > 0. && bnrm < smlnum) {
00381 bnrmto = smlnum;
00382 ilbscl = TRUE_;
00383 } else if (bnrm > bignum) {
00384 bnrmto = bignum;
00385 ilbscl = TRUE_;
00386 }
00387 if (ilbscl) {
00388 dlascl_("G", &c__0, &c__0, &bnrm, &bnrmto, n, n, &b[b_offset], ldb, &
00389 ierr);
00390 }
00391
00392
00393
00394
00395 ileft = 1;
00396 iright = *n + 1;
00397 iwrk = iright + *n;
00398 dggbal_("P", n, &a[a_offset], lda, &b[b_offset], ldb, &ilo, &ihi, &work[
00399 ileft], &work[iright], &work[iwrk], &ierr);
00400
00401
00402
00403
00404 irows = ihi + 1 - ilo;
00405 if (ilv) {
00406 icols = *n + 1 - ilo;
00407 } else {
00408 icols = irows;
00409 }
00410 itau = iwrk;
00411 iwrk = itau + irows;
00412 i__1 = *lwork + 1 - iwrk;
00413 dgeqrf_(&irows, &icols, &b[ilo + ilo * b_dim1], ldb, &work[itau], &work[
00414 iwrk], &i__1, &ierr);
00415
00416
00417
00418
00419 i__1 = *lwork + 1 - iwrk;
00420 dormqr_("L", "T", &irows, &icols, &irows, &b[ilo + ilo * b_dim1], ldb, &
00421 work[itau], &a[ilo + ilo * a_dim1], lda, &work[iwrk], &i__1, &
00422 ierr);
00423
00424
00425
00426
00427 if (ilvl) {
00428 dlaset_("Full", n, n, &c_b36, &c_b37, &vl[vl_offset], ldvl)
00429 ;
00430 if (irows > 1) {
00431 i__1 = irows - 1;
00432 i__2 = irows - 1;
00433 dlacpy_("L", &i__1, &i__2, &b[ilo + 1 + ilo * b_dim1], ldb, &vl[
00434 ilo + 1 + ilo * vl_dim1], ldvl);
00435 }
00436 i__1 = *lwork + 1 - iwrk;
00437 dorgqr_(&irows, &irows, &irows, &vl[ilo + ilo * vl_dim1], ldvl, &work[
00438 itau], &work[iwrk], &i__1, &ierr);
00439 }
00440
00441
00442
00443 if (ilvr) {
00444 dlaset_("Full", n, n, &c_b36, &c_b37, &vr[vr_offset], ldvr)
00445 ;
00446 }
00447
00448
00449
00450
00451 if (ilv) {
00452
00453
00454
00455 dgghrd_(jobvl, jobvr, n, &ilo, &ihi, &a[a_offset], lda, &b[b_offset],
00456 ldb, &vl[vl_offset], ldvl, &vr[vr_offset], ldvr, &ierr);
00457 } else {
00458 dgghrd_("N", "N", &irows, &c__1, &irows, &a[ilo + ilo * a_dim1], lda,
00459 &b[ilo + ilo * b_dim1], ldb, &vl[vl_offset], ldvl, &vr[
00460 vr_offset], ldvr, &ierr);
00461 }
00462
00463
00464
00465
00466
00467 iwrk = itau;
00468 if (ilv) {
00469 *(unsigned char *)chtemp = 'S';
00470 } else {
00471 *(unsigned char *)chtemp = 'E';
00472 }
00473 i__1 = *lwork + 1 - iwrk;
00474 dhgeqz_(chtemp, jobvl, jobvr, n, &ilo, &ihi, &a[a_offset], lda, &b[
00475 b_offset], ldb, &alphar[1], &alphai[1], &beta[1], &vl[vl_offset],
00476 ldvl, &vr[vr_offset], ldvr, &work[iwrk], &i__1, &ierr);
00477 if (ierr != 0) {
00478 if (ierr > 0 && ierr <= *n) {
00479 *info = ierr;
00480 } else if (ierr > *n && ierr <= *n << 1) {
00481 *info = ierr - *n;
00482 } else {
00483 *info = *n + 1;
00484 }
00485 goto L110;
00486 }
00487
00488
00489
00490
00491 if (ilv) {
00492 if (ilvl) {
00493 if (ilvr) {
00494 *(unsigned char *)chtemp = 'B';
00495 } else {
00496 *(unsigned char *)chtemp = 'L';
00497 }
00498 } else {
00499 *(unsigned char *)chtemp = 'R';
00500 }
00501 dtgevc_(chtemp, "B", ldumma, n, &a[a_offset], lda, &b[b_offset], ldb,
00502 &vl[vl_offset], ldvl, &vr[vr_offset], ldvr, n, &in, &work[
00503 iwrk], &ierr);
00504 if (ierr != 0) {
00505 *info = *n + 2;
00506 goto L110;
00507 }
00508
00509
00510
00511
00512 if (ilvl) {
00513 dggbak_("P", "L", n, &ilo, &ihi, &work[ileft], &work[iright], n, &
00514 vl[vl_offset], ldvl, &ierr);
00515 i__1 = *n;
00516 for (jc = 1; jc <= i__1; ++jc) {
00517 if (alphai[jc] < 0.) {
00518 goto L50;
00519 }
00520 temp = 0.;
00521 if (alphai[jc] == 0.) {
00522 i__2 = *n;
00523 for (jr = 1; jr <= i__2; ++jr) {
00524
00525 d__2 = temp, d__3 = (d__1 = vl[jr + jc * vl_dim1],
00526 abs(d__1));
00527 temp = max(d__2,d__3);
00528
00529 }
00530 } else {
00531 i__2 = *n;
00532 for (jr = 1; jr <= i__2; ++jr) {
00533
00534 d__3 = temp, d__4 = (d__1 = vl[jr + jc * vl_dim1],
00535 abs(d__1)) + (d__2 = vl[jr + (jc + 1) *
00536 vl_dim1], abs(d__2));
00537 temp = max(d__3,d__4);
00538
00539 }
00540 }
00541 if (temp < smlnum) {
00542 goto L50;
00543 }
00544 temp = 1. / temp;
00545 if (alphai[jc] == 0.) {
00546 i__2 = *n;
00547 for (jr = 1; jr <= i__2; ++jr) {
00548 vl[jr + jc * vl_dim1] *= temp;
00549
00550 }
00551 } else {
00552 i__2 = *n;
00553 for (jr = 1; jr <= i__2; ++jr) {
00554 vl[jr + jc * vl_dim1] *= temp;
00555 vl[jr + (jc + 1) * vl_dim1] *= temp;
00556
00557 }
00558 }
00559 L50:
00560 ;
00561 }
00562 }
00563 if (ilvr) {
00564 dggbak_("P", "R", n, &ilo, &ihi, &work[ileft], &work[iright], n, &
00565 vr[vr_offset], ldvr, &ierr);
00566 i__1 = *n;
00567 for (jc = 1; jc <= i__1; ++jc) {
00568 if (alphai[jc] < 0.) {
00569 goto L100;
00570 }
00571 temp = 0.;
00572 if (alphai[jc] == 0.) {
00573 i__2 = *n;
00574 for (jr = 1; jr <= i__2; ++jr) {
00575
00576 d__2 = temp, d__3 = (d__1 = vr[jr + jc * vr_dim1],
00577 abs(d__1));
00578 temp = max(d__2,d__3);
00579
00580 }
00581 } else {
00582 i__2 = *n;
00583 for (jr = 1; jr <= i__2; ++jr) {
00584
00585 d__3 = temp, d__4 = (d__1 = vr[jr + jc * vr_dim1],
00586 abs(d__1)) + (d__2 = vr[jr + (jc + 1) *
00587 vr_dim1], abs(d__2));
00588 temp = max(d__3,d__4);
00589
00590 }
00591 }
00592 if (temp < smlnum) {
00593 goto L100;
00594 }
00595 temp = 1. / temp;
00596 if (alphai[jc] == 0.) {
00597 i__2 = *n;
00598 for (jr = 1; jr <= i__2; ++jr) {
00599 vr[jr + jc * vr_dim1] *= temp;
00600
00601 }
00602 } else {
00603 i__2 = *n;
00604 for (jr = 1; jr <= i__2; ++jr) {
00605 vr[jr + jc * vr_dim1] *= temp;
00606 vr[jr + (jc + 1) * vr_dim1] *= temp;
00607
00608 }
00609 }
00610 L100:
00611 ;
00612 }
00613 }
00614
00615
00616
00617 }
00618
00619
00620
00621 if (ilascl) {
00622 dlascl_("G", &c__0, &c__0, &anrmto, &anrm, n, &c__1, &alphar[1], n, &
00623 ierr);
00624 dlascl_("G", &c__0, &c__0, &anrmto, &anrm, n, &c__1, &alphai[1], n, &
00625 ierr);
00626 }
00627
00628 if (ilbscl) {
00629 dlascl_("G", &c__0, &c__0, &bnrmto, &bnrm, n, &c__1, &beta[1], n, &
00630 ierr);
00631 }
00632
00633 L110:
00634
00635 work[1] = (doublereal) maxwrk;
00636
00637 return 0;
00638
00639
00640
00641 }