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 complex c_b1 = {0.f,0.f};
00019 static complex c_b2 = {1.f,0.f};
00020 static integer c__1 = 1;
00021 static integer c__0 = 0;
00022 static integer c_n1 = -1;
00023
00024 int cgges_(char *jobvsl, char *jobvsr, char *sort, L_fp
00025 selctg, integer *n, complex *a, integer *lda, complex *b, integer *
00026 ldb, integer *sdim, complex *alpha, complex *beta, complex *vsl,
00027 integer *ldvsl, complex *vsr, integer *ldvsr, complex *work, integer *
00028 lwork, real *rwork, logical *bwork, integer *info)
00029 {
00030
00031 integer a_dim1, a_offset, b_dim1, b_offset, vsl_dim1, vsl_offset,
00032 vsr_dim1, vsr_offset, i__1, i__2;
00033
00034
00035 double sqrt(doublereal);
00036
00037
00038 integer i__;
00039 real dif[2];
00040 integer ihi, ilo;
00041 real eps, anrm, bnrm;
00042 integer idum[1], ierr, itau, iwrk;
00043 real pvsl, pvsr;
00044 extern logical lsame_(char *, char *);
00045 integer ileft, icols;
00046 logical cursl, ilvsl, ilvsr;
00047 integer irwrk, irows;
00048 extern int cggbak_(char *, char *, integer *, integer *,
00049 integer *, real *, real *, integer *, complex *, integer *,
00050 integer *), cggbal_(char *, integer *, complex *,
00051 integer *, complex *, integer *, integer *, integer *, real *,
00052 real *, real *, integer *), slabad_(real *, real *);
00053 extern doublereal clange_(char *, integer *, integer *, complex *,
00054 integer *, real *);
00055 extern int cgghrd_(char *, char *, integer *, integer *,
00056 integer *, complex *, integer *, complex *, integer *, complex *,
00057 integer *, complex *, integer *, integer *),
00058 clascl_(char *, integer *, integer *, real *, real *, integer *,
00059 integer *, complex *, integer *, integer *);
00060 logical ilascl, ilbscl;
00061 extern int cgeqrf_(integer *, integer *, complex *,
00062 integer *, complex *, complex *, integer *, integer *);
00063 extern doublereal slamch_(char *);
00064 extern int clacpy_(char *, integer *, integer *, complex
00065 *, integer *, complex *, integer *), claset_(char *,
00066 integer *, integer *, complex *, complex *, complex *, integer *), xerbla_(char *, integer *);
00067 extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
00068 integer *, integer *);
00069 real bignum;
00070 extern int chgeqz_(char *, char *, char *, integer *,
00071 integer *, integer *, complex *, integer *, complex *, integer *,
00072 complex *, complex *, complex *, integer *, complex *, integer *,
00073 complex *, integer *, real *, integer *),
00074 ctgsen_(integer *, logical *, logical *, logical *, integer *,
00075 complex *, integer *, complex *, integer *, complex *, complex *,
00076 complex *, integer *, complex *, integer *, integer *, real *,
00077 real *, real *, complex *, integer *, integer *, integer *,
00078 integer *);
00079 integer ijobvl, iright, ijobvr;
00080 real anrmto;
00081 integer lwkmin;
00082 logical lastsl;
00083 real bnrmto;
00084 extern int cungqr_(integer *, integer *, integer *,
00085 complex *, integer *, complex *, complex *, integer *, integer *),
00086 cunmqr_(char *, char *, integer *, integer *, integer *, complex
00087 *, integer *, complex *, complex *, integer *, complex *, integer
00088 *, integer *);
00089 real smlnum;
00090 logical wantst, lquery;
00091 integer lwkopt;
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
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 a_dim1 = *lda;
00272 a_offset = 1 + a_dim1;
00273 a -= a_offset;
00274 b_dim1 = *ldb;
00275 b_offset = 1 + b_dim1;
00276 b -= b_offset;
00277 --alpha;
00278 --beta;
00279 vsl_dim1 = *ldvsl;
00280 vsl_offset = 1 + vsl_dim1;
00281 vsl -= vsl_offset;
00282 vsr_dim1 = *ldvsr;
00283 vsr_offset = 1 + vsr_dim1;
00284 vsr -= vsr_offset;
00285 --work;
00286 --rwork;
00287 --bwork;
00288
00289
00290 if (lsame_(jobvsl, "N")) {
00291 ijobvl = 1;
00292 ilvsl = FALSE_;
00293 } else if (lsame_(jobvsl, "V")) {
00294 ijobvl = 2;
00295 ilvsl = TRUE_;
00296 } else {
00297 ijobvl = -1;
00298 ilvsl = FALSE_;
00299 }
00300
00301 if (lsame_(jobvsr, "N")) {
00302 ijobvr = 1;
00303 ilvsr = FALSE_;
00304 } else if (lsame_(jobvsr, "V")) {
00305 ijobvr = 2;
00306 ilvsr = TRUE_;
00307 } else {
00308 ijobvr = -1;
00309 ilvsr = FALSE_;
00310 }
00311
00312 wantst = lsame_(sort, "S");
00313
00314
00315
00316 *info = 0;
00317 lquery = *lwork == -1;
00318 if (ijobvl <= 0) {
00319 *info = -1;
00320 } else if (ijobvr <= 0) {
00321 *info = -2;
00322 } else if (! wantst && ! lsame_(sort, "N")) {
00323 *info = -3;
00324 } else if (*n < 0) {
00325 *info = -5;
00326 } else if (*lda < max(1,*n)) {
00327 *info = -7;
00328 } else if (*ldb < max(1,*n)) {
00329 *info = -9;
00330 } else if (*ldvsl < 1 || ilvsl && *ldvsl < *n) {
00331 *info = -14;
00332 } else if (*ldvsr < 1 || ilvsr && *ldvsr < *n) {
00333 *info = -16;
00334 }
00335
00336
00337
00338
00339
00340
00341
00342
00343 if (*info == 0) {
00344
00345 i__1 = 1, i__2 = *n << 1;
00346 lwkmin = max(i__1,i__2);
00347
00348 i__1 = 1, i__2 = *n + *n * ilaenv_(&c__1, "CGEQRF", " ", n, &c__1, n,
00349 &c__0);
00350 lwkopt = max(i__1,i__2);
00351
00352 i__1 = lwkopt, i__2 = *n + *n * ilaenv_(&c__1, "CUNMQR", " ", n, &
00353 c__1, n, &c_n1);
00354 lwkopt = max(i__1,i__2);
00355 if (ilvsl) {
00356
00357 i__1 = lwkopt, i__2 = *n + *n * ilaenv_(&c__1, "CUNGQR", " ", n, &
00358 c__1, n, &c_n1);
00359 lwkopt = max(i__1,i__2);
00360 }
00361 work[1].r = (real) lwkopt, work[1].i = 0.f;
00362
00363 if (*lwork < lwkmin && ! lquery) {
00364 *info = -18;
00365 }
00366 }
00367
00368 if (*info != 0) {
00369 i__1 = -(*info);
00370 xerbla_("CGGES ", &i__1);
00371 return 0;
00372 } else if (lquery) {
00373 return 0;
00374 }
00375
00376
00377
00378 if (*n == 0) {
00379 *sdim = 0;
00380 return 0;
00381 }
00382
00383
00384
00385 eps = slamch_("P");
00386 smlnum = slamch_("S");
00387 bignum = 1.f / smlnum;
00388 slabad_(&smlnum, &bignum);
00389 smlnum = sqrt(smlnum) / eps;
00390 bignum = 1.f / smlnum;
00391
00392
00393
00394 anrm = clange_("M", n, n, &a[a_offset], lda, &rwork[1]);
00395 ilascl = FALSE_;
00396 if (anrm > 0.f && anrm < smlnum) {
00397 anrmto = smlnum;
00398 ilascl = TRUE_;
00399 } else if (anrm > bignum) {
00400 anrmto = bignum;
00401 ilascl = TRUE_;
00402 }
00403
00404 if (ilascl) {
00405 clascl_("G", &c__0, &c__0, &anrm, &anrmto, n, n, &a[a_offset], lda, &
00406 ierr);
00407 }
00408
00409
00410
00411 bnrm = clange_("M", n, n, &b[b_offset], ldb, &rwork[1]);
00412 ilbscl = FALSE_;
00413 if (bnrm > 0.f && bnrm < smlnum) {
00414 bnrmto = smlnum;
00415 ilbscl = TRUE_;
00416 } else if (bnrm > bignum) {
00417 bnrmto = bignum;
00418 ilbscl = TRUE_;
00419 }
00420
00421 if (ilbscl) {
00422 clascl_("G", &c__0, &c__0, &bnrm, &bnrmto, n, n, &b[b_offset], ldb, &
00423 ierr);
00424 }
00425
00426
00427
00428
00429 ileft = 1;
00430 iright = *n + 1;
00431 irwrk = iright + *n;
00432 cggbal_("P", n, &a[a_offset], lda, &b[b_offset], ldb, &ilo, &ihi, &rwork[
00433 ileft], &rwork[iright], &rwork[irwrk], &ierr);
00434
00435
00436
00437
00438 irows = ihi + 1 - ilo;
00439 icols = *n + 1 - ilo;
00440 itau = 1;
00441 iwrk = itau + irows;
00442 i__1 = *lwork + 1 - iwrk;
00443 cgeqrf_(&irows, &icols, &b[ilo + ilo * b_dim1], ldb, &work[itau], &work[
00444 iwrk], &i__1, &ierr);
00445
00446
00447
00448
00449 i__1 = *lwork + 1 - iwrk;
00450 cunmqr_("L", "C", &irows, &icols, &irows, &b[ilo + ilo * b_dim1], ldb, &
00451 work[itau], &a[ilo + ilo * a_dim1], lda, &work[iwrk], &i__1, &
00452 ierr);
00453
00454
00455
00456
00457 if (ilvsl) {
00458 claset_("Full", n, n, &c_b1, &c_b2, &vsl[vsl_offset], ldvsl);
00459 if (irows > 1) {
00460 i__1 = irows - 1;
00461 i__2 = irows - 1;
00462 clacpy_("L", &i__1, &i__2, &b[ilo + 1 + ilo * b_dim1], ldb, &vsl[
00463 ilo + 1 + ilo * vsl_dim1], ldvsl);
00464 }
00465 i__1 = *lwork + 1 - iwrk;
00466 cungqr_(&irows, &irows, &irows, &vsl[ilo + ilo * vsl_dim1], ldvsl, &
00467 work[itau], &work[iwrk], &i__1, &ierr);
00468 }
00469
00470
00471
00472 if (ilvsr) {
00473 claset_("Full", n, n, &c_b1, &c_b2, &vsr[vsr_offset], ldvsr);
00474 }
00475
00476
00477
00478
00479 cgghrd_(jobvsl, jobvsr, n, &ilo, &ihi, &a[a_offset], lda, &b[b_offset],
00480 ldb, &vsl[vsl_offset], ldvsl, &vsr[vsr_offset], ldvsr, &ierr);
00481
00482 *sdim = 0;
00483
00484
00485
00486
00487
00488 iwrk = itau;
00489 i__1 = *lwork + 1 - iwrk;
00490 chgeqz_("S", jobvsl, jobvsr, n, &ilo, &ihi, &a[a_offset], lda, &b[
00491 b_offset], ldb, &alpha[1], &beta[1], &vsl[vsl_offset], ldvsl, &
00492 vsr[vsr_offset], ldvsr, &work[iwrk], &i__1, &rwork[irwrk], &ierr);
00493 if (ierr != 0) {
00494 if (ierr > 0 && ierr <= *n) {
00495 *info = ierr;
00496 } else if (ierr > *n && ierr <= *n << 1) {
00497 *info = ierr - *n;
00498 } else {
00499 *info = *n + 1;
00500 }
00501 goto L30;
00502 }
00503
00504
00505
00506
00507 if (wantst) {
00508
00509
00510
00511 if (ilascl) {
00512 clascl_("G", &c__0, &c__0, &anrm, &anrmto, n, &c__1, &alpha[1], n,
00513 &ierr);
00514 }
00515 if (ilbscl) {
00516 clascl_("G", &c__0, &c__0, &bnrm, &bnrmto, n, &c__1, &beta[1], n,
00517 &ierr);
00518 }
00519
00520
00521
00522 i__1 = *n;
00523 for (i__ = 1; i__ <= i__1; ++i__) {
00524 bwork[i__] = (*selctg)(&alpha[i__], &beta[i__]);
00525
00526 }
00527
00528 i__1 = *lwork - iwrk + 1;
00529 ctgsen_(&c__0, &ilvsl, &ilvsr, &bwork[1], n, &a[a_offset], lda, &b[
00530 b_offset], ldb, &alpha[1], &beta[1], &vsl[vsl_offset], ldvsl,
00531 &vsr[vsr_offset], ldvsr, sdim, &pvsl, &pvsr, dif, &work[iwrk],
00532 &i__1, idum, &c__1, &ierr);
00533 if (ierr == 1) {
00534 *info = *n + 3;
00535 }
00536
00537 }
00538
00539
00540
00541
00542 if (ilvsl) {
00543 cggbak_("P", "L", n, &ilo, &ihi, &rwork[ileft], &rwork[iright], n, &
00544 vsl[vsl_offset], ldvsl, &ierr);
00545 }
00546 if (ilvsr) {
00547 cggbak_("P", "R", n, &ilo, &ihi, &rwork[ileft], &rwork[iright], n, &
00548 vsr[vsr_offset], ldvsr, &ierr);
00549 }
00550
00551
00552
00553 if (ilascl) {
00554 clascl_("U", &c__0, &c__0, &anrmto, &anrm, n, n, &a[a_offset], lda, &
00555 ierr);
00556 clascl_("G", &c__0, &c__0, &anrmto, &anrm, n, &c__1, &alpha[1], n, &
00557 ierr);
00558 }
00559
00560 if (ilbscl) {
00561 clascl_("U", &c__0, &c__0, &bnrmto, &bnrm, n, n, &b[b_offset], ldb, &
00562 ierr);
00563 clascl_("G", &c__0, &c__0, &bnrmto, &bnrm, n, &c__1, &beta[1], n, &
00564 ierr);
00565 }
00566
00567 if (wantst) {
00568
00569
00570
00571 lastsl = TRUE_;
00572 *sdim = 0;
00573 i__1 = *n;
00574 for (i__ = 1; i__ <= i__1; ++i__) {
00575 cursl = (*selctg)(&alpha[i__], &beta[i__]);
00576 if (cursl) {
00577 ++(*sdim);
00578 }
00579 if (cursl && ! lastsl) {
00580 *info = *n + 2;
00581 }
00582 lastsl = cursl;
00583
00584 }
00585
00586 }
00587
00588 L30:
00589
00590 work[1].r = (real) lwkopt, work[1].i = 0.f;
00591
00592 return 0;
00593
00594
00595
00596 }