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