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 zgeev_(char *jobvl, char *jobvr, integer *n,
00023 doublecomplex *a, integer *lda, doublecomplex *w, doublecomplex *vl,
00024 integer *ldvl, doublecomplex *vr, integer *ldvr, doublecomplex *work,
00025 integer *lwork, doublereal *rwork, integer *info)
00026 {
00027
00028 integer a_dim1, a_offset, vl_dim1, vl_offset, vr_dim1, vr_offset, i__1,
00029 i__2, i__3;
00030 doublereal d__1, d__2;
00031 doublecomplex z__1, z__2;
00032
00033
00034 double sqrt(doublereal), d_imag(doublecomplex *);
00035 void d_cnjg(doublecomplex *, doublecomplex *);
00036
00037
00038 integer i__, k, ihi;
00039 doublereal scl;
00040 integer ilo;
00041 doublereal dum[1], eps;
00042 doublecomplex tmp;
00043 integer ibal;
00044 char side[1];
00045 doublereal anrm;
00046 integer ierr, itau, iwrk, nout;
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 zgebak_(char *, char *, integer *, integer *,
00055 integer *, doublereal *, integer *, doublecomplex *, integer *,
00056 integer *), zgebal_(char *, integer *,
00057 doublecomplex *, integer *, integer *, integer *, doublereal *,
00058 integer *);
00059 extern integer idamax_(integer *, doublereal *, integer *);
00060 extern int xerbla_(char *, integer *);
00061 extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
00062 integer *, integer *);
00063 logical select[1];
00064 extern int zdscal_(integer *, doublereal *,
00065 doublecomplex *, integer *);
00066 doublereal bignum;
00067 extern doublereal zlange_(char *, integer *, integer *, doublecomplex *,
00068 integer *, doublereal *);
00069 extern int zgehrd_(integer *, integer *, integer *,
00070 doublecomplex *, integer *, doublecomplex *, doublecomplex *,
00071 integer *, integer *), zlascl_(char *, integer *, integer *,
00072 doublereal *, doublereal *, integer *, integer *, doublecomplex *,
00073 integer *, integer *), zlacpy_(char *, integer *,
00074 integer *, doublecomplex *, integer *, doublecomplex *, integer *);
00075 integer minwrk, maxwrk;
00076 logical wantvl;
00077 doublereal smlnum;
00078 integer hswork, irwork;
00079 extern int zhseqr_(char *, char *, integer *, integer *,
00080 integer *, doublecomplex *, integer *, doublecomplex *,
00081 doublecomplex *, integer *, doublecomplex *, integer *, integer *), ztrevc_(char *, char *, logical *, integer *,
00082 doublecomplex *, integer *, doublecomplex *, integer *,
00083 doublecomplex *, integer *, integer *, integer *, doublecomplex *,
00084 doublereal *, integer *);
00085 logical lquery, wantvr;
00086 extern int zunghr_(integer *, integer *, integer *,
00087 doublecomplex *, integer *, doublecomplex *, doublecomplex *,
00088 integer *, integer *);
00089
00090
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 a_dim1 = *lda;
00204 a_offset = 1 + a_dim1;
00205 a -= a_offset;
00206 --w;
00207 vl_dim1 = *ldvl;
00208 vl_offset = 1 + vl_dim1;
00209 vl -= vl_offset;
00210 vr_dim1 = *ldvr;
00211 vr_offset = 1 + vr_dim1;
00212 vr -= vr_offset;
00213 --work;
00214 --rwork;
00215
00216
00217 *info = 0;
00218 lquery = *lwork == -1;
00219 wantvl = lsame_(jobvl, "V");
00220 wantvr = lsame_(jobvr, "V");
00221 if (! wantvl && ! lsame_(jobvl, "N")) {
00222 *info = -1;
00223 } else if (! wantvr && ! lsame_(jobvr, "N")) {
00224 *info = -2;
00225 } else if (*n < 0) {
00226 *info = -3;
00227 } else if (*lda < max(1,*n)) {
00228 *info = -5;
00229 } else if (*ldvl < 1 || wantvl && *ldvl < *n) {
00230 *info = -8;
00231 } else if (*ldvr < 1 || wantvr && *ldvr < *n) {
00232 *info = -10;
00233 }
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246 if (*info == 0) {
00247 if (*n == 0) {
00248 minwrk = 1;
00249 maxwrk = 1;
00250 } else {
00251 maxwrk = *n + *n * ilaenv_(&c__1, "ZGEHRD", " ", n, &c__1, n, &
00252 c__0);
00253 minwrk = *n << 1;
00254 if (wantvl) {
00255
00256 i__1 = maxwrk, i__2 = *n + (*n - 1) * ilaenv_(&c__1, "ZUNGHR",
00257 " ", n, &c__1, n, &c_n1);
00258 maxwrk = max(i__1,i__2);
00259 zhseqr_("S", "V", n, &c__1, n, &a[a_offset], lda, &w[1], &vl[
00260 vl_offset], ldvl, &work[1], &c_n1, info);
00261 } else if (wantvr) {
00262
00263 i__1 = maxwrk, i__2 = *n + (*n - 1) * ilaenv_(&c__1, "ZUNGHR",
00264 " ", n, &c__1, n, &c_n1);
00265 maxwrk = max(i__1,i__2);
00266 zhseqr_("S", "V", n, &c__1, n, &a[a_offset], lda, &w[1], &vr[
00267 vr_offset], ldvr, &work[1], &c_n1, info);
00268 } else {
00269 zhseqr_("E", "N", n, &c__1, n, &a[a_offset], lda, &w[1], &vr[
00270 vr_offset], ldvr, &work[1], &c_n1, info);
00271 }
00272 hswork = (integer) work[1].r;
00273
00274 i__1 = max(maxwrk,hswork);
00275 maxwrk = max(i__1,minwrk);
00276 }
00277 work[1].r = (doublereal) maxwrk, work[1].i = 0.;
00278
00279 if (*lwork < minwrk && ! lquery) {
00280 *info = -12;
00281 }
00282 }
00283
00284 if (*info != 0) {
00285 i__1 = -(*info);
00286 xerbla_("ZGEEV ", &i__1);
00287 return 0;
00288 } else if (lquery) {
00289 return 0;
00290 }
00291
00292
00293
00294 if (*n == 0) {
00295 return 0;
00296 }
00297
00298
00299
00300 eps = dlamch_("P");
00301 smlnum = dlamch_("S");
00302 bignum = 1. / smlnum;
00303 dlabad_(&smlnum, &bignum);
00304 smlnum = sqrt(smlnum) / eps;
00305 bignum = 1. / smlnum;
00306
00307
00308
00309 anrm = zlange_("M", n, n, &a[a_offset], lda, dum);
00310 scalea = FALSE_;
00311 if (anrm > 0. && anrm < smlnum) {
00312 scalea = TRUE_;
00313 cscale = smlnum;
00314 } else if (anrm > bignum) {
00315 scalea = TRUE_;
00316 cscale = bignum;
00317 }
00318 if (scalea) {
00319 zlascl_("G", &c__0, &c__0, &anrm, &cscale, n, n, &a[a_offset], lda, &
00320 ierr);
00321 }
00322
00323
00324
00325
00326
00327 ibal = 1;
00328 zgebal_("B", n, &a[a_offset], lda, &ilo, &ihi, &rwork[ibal], &ierr);
00329
00330
00331
00332
00333
00334 itau = 1;
00335 iwrk = itau + *n;
00336 i__1 = *lwork - iwrk + 1;
00337 zgehrd_(n, &ilo, &ihi, &a[a_offset], lda, &work[itau], &work[iwrk], &i__1,
00338 &ierr);
00339
00340 if (wantvl) {
00341
00342
00343
00344
00345 *(unsigned char *)side = 'L';
00346 zlacpy_("L", n, n, &a[a_offset], lda, &vl[vl_offset], ldvl)
00347 ;
00348
00349
00350
00351
00352
00353 i__1 = *lwork - iwrk + 1;
00354 zunghr_(n, &ilo, &ihi, &vl[vl_offset], ldvl, &work[itau], &work[iwrk],
00355 &i__1, &ierr);
00356
00357
00358
00359
00360
00361 iwrk = itau;
00362 i__1 = *lwork - iwrk + 1;
00363 zhseqr_("S", "V", n, &ilo, &ihi, &a[a_offset], lda, &w[1], &vl[
00364 vl_offset], ldvl, &work[iwrk], &i__1, info);
00365
00366 if (wantvr) {
00367
00368
00369
00370
00371 *(unsigned char *)side = 'B';
00372 zlacpy_("F", n, n, &vl[vl_offset], ldvl, &vr[vr_offset], ldvr);
00373 }
00374
00375 } else if (wantvr) {
00376
00377
00378
00379
00380 *(unsigned char *)side = 'R';
00381 zlacpy_("L", n, n, &a[a_offset], lda, &vr[vr_offset], ldvr)
00382 ;
00383
00384
00385
00386
00387
00388 i__1 = *lwork - iwrk + 1;
00389 zunghr_(n, &ilo, &ihi, &vr[vr_offset], ldvr, &work[itau], &work[iwrk],
00390 &i__1, &ierr);
00391
00392
00393
00394
00395
00396 iwrk = itau;
00397 i__1 = *lwork - iwrk + 1;
00398 zhseqr_("S", "V", n, &ilo, &ihi, &a[a_offset], lda, &w[1], &vr[
00399 vr_offset], ldvr, &work[iwrk], &i__1, info);
00400
00401 } else {
00402
00403
00404
00405
00406
00407 iwrk = itau;
00408 i__1 = *lwork - iwrk + 1;
00409 zhseqr_("E", "N", n, &ilo, &ihi, &a[a_offset], lda, &w[1], &vr[
00410 vr_offset], ldvr, &work[iwrk], &i__1, info);
00411 }
00412
00413
00414
00415 if (*info > 0) {
00416 goto L50;
00417 }
00418
00419 if (wantvl || wantvr) {
00420
00421
00422
00423
00424
00425 irwork = ibal + *n;
00426 ztrevc_(side, "B", select, n, &a[a_offset], lda, &vl[vl_offset], ldvl,
00427 &vr[vr_offset], ldvr, n, &nout, &work[iwrk], &rwork[irwork],
00428 &ierr);
00429 }
00430
00431 if (wantvl) {
00432
00433
00434
00435
00436
00437 zgebak_("B", "L", n, &ilo, &ihi, &rwork[ibal], n, &vl[vl_offset],
00438 ldvl, &ierr);
00439
00440
00441
00442 i__1 = *n;
00443 for (i__ = 1; i__ <= i__1; ++i__) {
00444 scl = 1. / dznrm2_(n, &vl[i__ * vl_dim1 + 1], &c__1);
00445 zdscal_(n, &scl, &vl[i__ * vl_dim1 + 1], &c__1);
00446 i__2 = *n;
00447 for (k = 1; k <= i__2; ++k) {
00448 i__3 = k + i__ * vl_dim1;
00449
00450 d__1 = vl[i__3].r;
00451
00452 d__2 = d_imag(&vl[k + i__ * vl_dim1]);
00453 rwork[irwork + k - 1] = d__1 * d__1 + d__2 * d__2;
00454
00455 }
00456 k = idamax_(n, &rwork[irwork], &c__1);
00457 d_cnjg(&z__2, &vl[k + i__ * vl_dim1]);
00458 d__1 = sqrt(rwork[irwork + k - 1]);
00459 z__1.r = z__2.r / d__1, z__1.i = z__2.i / d__1;
00460 tmp.r = z__1.r, tmp.i = z__1.i;
00461 zscal_(n, &tmp, &vl[i__ * vl_dim1 + 1], &c__1);
00462 i__2 = k + i__ * vl_dim1;
00463 i__3 = k + i__ * vl_dim1;
00464 d__1 = vl[i__3].r;
00465 z__1.r = d__1, z__1.i = 0.;
00466 vl[i__2].r = z__1.r, vl[i__2].i = z__1.i;
00467
00468 }
00469 }
00470
00471 if (wantvr) {
00472
00473
00474
00475
00476
00477 zgebak_("B", "R", n, &ilo, &ihi, &rwork[ibal], n, &vr[vr_offset],
00478 ldvr, &ierr);
00479
00480
00481
00482 i__1 = *n;
00483 for (i__ = 1; i__ <= i__1; ++i__) {
00484 scl = 1. / dznrm2_(n, &vr[i__ * vr_dim1 + 1], &c__1);
00485 zdscal_(n, &scl, &vr[i__ * vr_dim1 + 1], &c__1);
00486 i__2 = *n;
00487 for (k = 1; k <= i__2; ++k) {
00488 i__3 = k + i__ * vr_dim1;
00489
00490 d__1 = vr[i__3].r;
00491
00492 d__2 = d_imag(&vr[k + i__ * vr_dim1]);
00493 rwork[irwork + k - 1] = d__1 * d__1 + d__2 * d__2;
00494
00495 }
00496 k = idamax_(n, &rwork[irwork], &c__1);
00497 d_cnjg(&z__2, &vr[k + i__ * vr_dim1]);
00498 d__1 = sqrt(rwork[irwork + k - 1]);
00499 z__1.r = z__2.r / d__1, z__1.i = z__2.i / d__1;
00500 tmp.r = z__1.r, tmp.i = z__1.i;
00501 zscal_(n, &tmp, &vr[i__ * vr_dim1 + 1], &c__1);
00502 i__2 = k + i__ * vr_dim1;
00503 i__3 = k + i__ * vr_dim1;
00504 d__1 = vr[i__3].r;
00505 z__1.r = d__1, z__1.i = 0.;
00506 vr[i__2].r = z__1.r, vr[i__2].i = z__1.i;
00507
00508 }
00509 }
00510
00511
00512
00513 L50:
00514 if (scalea) {
00515 i__1 = *n - *info;
00516
00517 i__3 = *n - *info;
00518 i__2 = max(i__3,1);
00519 zlascl_("G", &c__0, &c__0, &cscale, &anrm, &i__1, &c__1, &w[*info + 1]
00520 , &i__2, &ierr);
00521 if (*info > 0) {
00522 i__1 = ilo - 1;
00523 zlascl_("G", &c__0, &c__0, &cscale, &anrm, &i__1, &c__1, &w[1], n,
00524 &ierr);
00525 }
00526 }
00527
00528 work[1].r = (doublereal) maxwrk, work[1].i = 0.;
00529 return 0;
00530
00531
00532
00533 }