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