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 cgees_(char *jobvs, char *sort, L_fp select, integer *n,
00023 complex *a, integer *lda, integer *sdim, complex *w, complex *vs,
00024 integer *ldvs, complex *work, integer *lwork, real *rwork, logical *
00025 bwork, integer *info)
00026 {
00027
00028 integer a_dim1, a_offset, vs_dim1, vs_offset, i__1, i__2;
00029
00030
00031 double sqrt(doublereal);
00032
00033
00034 integer i__;
00035 real s;
00036 integer ihi, ilo;
00037 real dum[1], eps, sep;
00038 integer ibal;
00039 real anrm;
00040 integer ierr, itau, iwrk, icond, ieval;
00041 extern logical lsame_(char *, char *);
00042 extern int ccopy_(integer *, complex *, integer *,
00043 complex *, integer *), cgebak_(char *, char *, integer *, integer
00044 *, integer *, real *, integer *, complex *, integer *, integer *), cgebal_(char *, integer *, complex *, integer *,
00045 integer *, integer *, real *, integer *), slabad_(real *,
00046 real *);
00047 logical scalea;
00048 extern doublereal clange_(char *, integer *, integer *, complex *,
00049 integer *, real *);
00050 real cscale;
00051 extern int cgehrd_(integer *, integer *, integer *,
00052 complex *, integer *, complex *, complex *, integer *, integer *),
00053 clascl_(char *, integer *, integer *, real *, real *, integer *,
00054 integer *, complex *, integer *, integer *);
00055 extern doublereal slamch_(char *);
00056 extern int clacpy_(char *, integer *, integer *, complex
00057 *, integer *, complex *, integer *), xerbla_(char *,
00058 integer *);
00059 extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
00060 integer *, integer *);
00061 real bignum;
00062 extern int chseqr_(char *, char *, integer *, integer *,
00063 integer *, complex *, integer *, complex *, complex *, integer *,
00064 complex *, integer *, integer *), cunghr_(integer
00065 *, integer *, integer *, complex *, integer *, complex *, complex
00066 *, integer *, integer *), ctrsen_(char *, char *, logical *,
00067 integer *, complex *, integer *, complex *, integer *, complex *,
00068 integer *, real *, real *, complex *, integer *, integer *);
00069 integer minwrk, maxwrk;
00070 real smlnum;
00071 integer hswork;
00072 logical wantst, lquery, wantvs;
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
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
00200
00201 a_dim1 = *lda;
00202 a_offset = 1 + a_dim1;
00203 a -= a_offset;
00204 --w;
00205 vs_dim1 = *ldvs;
00206 vs_offset = 1 + vs_dim1;
00207 vs -= vs_offset;
00208 --work;
00209 --rwork;
00210 --bwork;
00211
00212
00213 *info = 0;
00214 lquery = *lwork == -1;
00215 wantvs = lsame_(jobvs, "V");
00216 wantst = lsame_(sort, "S");
00217 if (! wantvs && ! lsame_(jobvs, "N")) {
00218 *info = -1;
00219 } else if (! wantst && ! lsame_(sort, "N")) {
00220 *info = -2;
00221 } else if (*n < 0) {
00222 *info = -4;
00223 } else if (*lda < max(1,*n)) {
00224 *info = -6;
00225 } else if (*ldvs < 1 || wantvs && *ldvs < *n) {
00226 *info = -10;
00227 }
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240 if (*info == 0) {
00241 if (*n == 0) {
00242 minwrk = 1;
00243 maxwrk = 1;
00244 } else {
00245 maxwrk = *n + *n * ilaenv_(&c__1, "CGEHRD", " ", n, &c__1, n, &
00246 c__0);
00247 minwrk = *n << 1;
00248
00249 chseqr_("S", jobvs, n, &c__1, n, &a[a_offset], lda, &w[1], &vs[
00250 vs_offset], ldvs, &work[1], &c_n1, &ieval);
00251 hswork = work[1].r;
00252
00253 if (! wantvs) {
00254 maxwrk = max(maxwrk,hswork);
00255 } else {
00256
00257 i__1 = maxwrk, i__2 = *n + (*n - 1) * ilaenv_(&c__1, "CUNGHR",
00258 " ", n, &c__1, n, &c_n1);
00259 maxwrk = max(i__1,i__2);
00260 maxwrk = max(maxwrk,hswork);
00261 }
00262 }
00263 work[1].r = (real) maxwrk, work[1].i = 0.f;
00264
00265 if (*lwork < minwrk && ! lquery) {
00266 *info = -12;
00267 }
00268 }
00269
00270 if (*info != 0) {
00271 i__1 = -(*info);
00272 xerbla_("CGEES ", &i__1);
00273 return 0;
00274 } else if (lquery) {
00275 return 0;
00276 }
00277
00278
00279
00280 if (*n == 0) {
00281 *sdim = 0;
00282 return 0;
00283 }
00284
00285
00286
00287 eps = slamch_("P");
00288 smlnum = slamch_("S");
00289 bignum = 1.f / smlnum;
00290 slabad_(&smlnum, &bignum);
00291 smlnum = sqrt(smlnum) / eps;
00292 bignum = 1.f / smlnum;
00293
00294
00295
00296 anrm = clange_("M", n, n, &a[a_offset], lda, dum);
00297 scalea = FALSE_;
00298 if (anrm > 0.f && anrm < smlnum) {
00299 scalea = TRUE_;
00300 cscale = smlnum;
00301 } else if (anrm > bignum) {
00302 scalea = TRUE_;
00303 cscale = bignum;
00304 }
00305 if (scalea) {
00306 clascl_("G", &c__0, &c__0, &anrm, &cscale, n, n, &a[a_offset], lda, &
00307 ierr);
00308 }
00309
00310
00311
00312
00313
00314 ibal = 1;
00315 cgebal_("P", n, &a[a_offset], lda, &ilo, &ihi, &rwork[ibal], &ierr);
00316
00317
00318
00319
00320
00321 itau = 1;
00322 iwrk = *n + itau;
00323 i__1 = *lwork - iwrk + 1;
00324 cgehrd_(n, &ilo, &ihi, &a[a_offset], lda, &work[itau], &work[iwrk], &i__1,
00325 &ierr);
00326
00327 if (wantvs) {
00328
00329
00330
00331 clacpy_("L", n, n, &a[a_offset], lda, &vs[vs_offset], ldvs)
00332 ;
00333
00334
00335
00336
00337
00338 i__1 = *lwork - iwrk + 1;
00339 cunghr_(n, &ilo, &ihi, &vs[vs_offset], ldvs, &work[itau], &work[iwrk],
00340 &i__1, &ierr);
00341 }
00342
00343 *sdim = 0;
00344
00345
00346
00347
00348
00349 iwrk = itau;
00350 i__1 = *lwork - iwrk + 1;
00351 chseqr_("S", jobvs, n, &ilo, &ihi, &a[a_offset], lda, &w[1], &vs[
00352 vs_offset], ldvs, &work[iwrk], &i__1, &ieval);
00353 if (ieval > 0) {
00354 *info = ieval;
00355 }
00356
00357
00358
00359 if (wantst && *info == 0) {
00360 if (scalea) {
00361 clascl_("G", &c__0, &c__0, &cscale, &anrm, n, &c__1, &w[1], n, &
00362 ierr);
00363 }
00364 i__1 = *n;
00365 for (i__ = 1; i__ <= i__1; ++i__) {
00366 bwork[i__] = (*select)(&w[i__]);
00367
00368 }
00369
00370
00371
00372
00373
00374 i__1 = *lwork - iwrk + 1;
00375 ctrsen_("N", jobvs, &bwork[1], n, &a[a_offset], lda, &vs[vs_offset],
00376 ldvs, &w[1], sdim, &s, &sep, &work[iwrk], &i__1, &icond);
00377 }
00378
00379 if (wantvs) {
00380
00381
00382
00383
00384
00385 cgebak_("P", "R", n, &ilo, &ihi, &rwork[ibal], n, &vs[vs_offset],
00386 ldvs, &ierr);
00387 }
00388
00389 if (scalea) {
00390
00391
00392
00393 clascl_("U", &c__0, &c__0, &cscale, &anrm, n, n, &a[a_offset], lda, &
00394 ierr);
00395 i__1 = *lda + 1;
00396 ccopy_(n, &a[a_offset], &i__1, &w[1], &c__1);
00397 }
00398
00399 work[1].r = (real) maxwrk, work[1].i = 0.f;
00400 return 0;
00401
00402
00403
00404 }