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 static real c_b38 = 0.f;
00022 static real c_b39 = 1.f;
00023
00024 int sgges_(char *jobvsl, char *jobvsr, char *sort, L_fp
00025 selctg, integer *n, real *a, integer *lda, real *b, integer *ldb,
00026 integer *sdim, real *alphar, real *alphai, real *beta, real *vsl,
00027 integer *ldvsl, real *vsr, integer *ldvsr, real *work, integer *lwork,
00028 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 real r__1;
00034
00035
00036 double sqrt(doublereal);
00037
00038
00039 integer i__, ip;
00040 real dif[2];
00041 integer ihi, ilo;
00042 real eps, anrm, bnrm;
00043 integer idum[1], ierr, itau, iwrk;
00044 real pvsl, pvsr;
00045 extern logical lsame_(char *, char *);
00046 integer ileft, icols;
00047 logical cursl, ilvsl, ilvsr;
00048 integer irows;
00049 logical lst2sl;
00050 extern int slabad_(real *, real *), sggbak_(char *, char
00051 *, integer *, integer *, integer *, real *, real *, integer *,
00052 real *, integer *, integer *), sggbal_(char *,
00053 integer *, real *, integer *, real *, integer *, integer *,
00054 integer *, real *, real *, real *, integer *);
00055 logical ilascl, ilbscl;
00056 extern doublereal slamch_(char *), slange_(char *, integer *,
00057 integer *, real *, integer *, real *);
00058 real safmin;
00059 extern int sgghrd_(char *, char *, integer *, integer *,
00060 integer *, real *, integer *, real *, integer *, real *, integer *
00061 , real *, integer *, integer *);
00062 real safmax;
00063 extern int xerbla_(char *, integer *);
00064 real bignum;
00065 extern int slascl_(char *, integer *, integer *, real *,
00066 real *, integer *, integer *, real *, integer *, integer *);
00067 extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
00068 integer *, integer *);
00069 integer ijobvl, iright;
00070 extern int sgeqrf_(integer *, integer *, real *, integer
00071 *, real *, real *, integer *, integer *);
00072 integer ijobvr;
00073 extern int slacpy_(char *, integer *, integer *, real *,
00074 integer *, real *, integer *), slaset_(char *, integer *,
00075 integer *, real *, real *, real *, integer *);
00076 real anrmto, bnrmto;
00077 logical lastsl;
00078 extern int shgeqz_(char *, char *, char *, integer *,
00079 integer *, integer *, real *, integer *, real *, integer *, real *
00080 , real *, real *, real *, integer *, real *, integer *, real *,
00081 integer *, integer *), stgsen_(integer *,
00082 logical *, logical *, logical *, integer *, real *, integer *,
00083 real *, integer *, real *, real *, real *, real *, integer *,
00084 real *, integer *, integer *, real *, real *, real *, real *,
00085 integer *, integer *, integer *, integer *);
00086 integer minwrk, maxwrk;
00087 real smlnum;
00088 extern int sorgqr_(integer *, integer *, integer *, real
00089 *, integer *, real *, real *, integer *, integer *);
00090 logical wantst, lquery;
00091 extern int sormqr_(char *, char *, integer *, integer *,
00092 integer *, real *, integer *, real *, real *, integer *, real *,
00093 integer *, integer *);
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
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287 a_dim1 = *lda;
00288 a_offset = 1 + a_dim1;
00289 a -= a_offset;
00290 b_dim1 = *ldb;
00291 b_offset = 1 + b_dim1;
00292 b -= b_offset;
00293 --alphar;
00294 --alphai;
00295 --beta;
00296 vsl_dim1 = *ldvsl;
00297 vsl_offset = 1 + vsl_dim1;
00298 vsl -= vsl_offset;
00299 vsr_dim1 = *ldvsr;
00300 vsr_offset = 1 + vsr_dim1;
00301 vsr -= vsr_offset;
00302 --work;
00303 --bwork;
00304
00305
00306 if (lsame_(jobvsl, "N")) {
00307 ijobvl = 1;
00308 ilvsl = FALSE_;
00309 } else if (lsame_(jobvsl, "V")) {
00310 ijobvl = 2;
00311 ilvsl = TRUE_;
00312 } else {
00313 ijobvl = -1;
00314 ilvsl = FALSE_;
00315 }
00316
00317 if (lsame_(jobvsr, "N")) {
00318 ijobvr = 1;
00319 ilvsr = FALSE_;
00320 } else if (lsame_(jobvsr, "V")) {
00321 ijobvr = 2;
00322 ilvsr = TRUE_;
00323 } else {
00324 ijobvr = -1;
00325 ilvsr = FALSE_;
00326 }
00327
00328 wantst = lsame_(sort, "S");
00329
00330
00331
00332 *info = 0;
00333 lquery = *lwork == -1;
00334 if (ijobvl <= 0) {
00335 *info = -1;
00336 } else if (ijobvr <= 0) {
00337 *info = -2;
00338 } else if (! wantst && ! lsame_(sort, "N")) {
00339 *info = -3;
00340 } else if (*n < 0) {
00341 *info = -5;
00342 } else if (*lda < max(1,*n)) {
00343 *info = -7;
00344 } else if (*ldb < max(1,*n)) {
00345 *info = -9;
00346 } else if (*ldvsl < 1 || ilvsl && *ldvsl < *n) {
00347 *info = -15;
00348 } else if (*ldvsr < 1 || ilvsr && *ldvsr < *n) {
00349 *info = -17;
00350 }
00351
00352
00353
00354
00355
00356
00357
00358
00359 if (*info == 0) {
00360 if (*n > 0) {
00361
00362 i__1 = *n << 3, i__2 = *n * 6 + 16;
00363 minwrk = max(i__1,i__2);
00364 maxwrk = minwrk - *n + *n * ilaenv_(&c__1, "SGEQRF", " ", n, &
00365 c__1, n, &c__0);
00366
00367 i__1 = maxwrk, i__2 = minwrk - *n + *n * ilaenv_(&c__1, "SORMQR",
00368 " ", n, &c__1, n, &c_n1);
00369 maxwrk = max(i__1,i__2);
00370 if (ilvsl) {
00371
00372 i__1 = maxwrk, i__2 = minwrk - *n + *n * ilaenv_(&c__1, "SOR"
00373 "GQR", " ", n, &c__1, n, &c_n1);
00374 maxwrk = max(i__1,i__2);
00375 }
00376 } else {
00377 minwrk = 1;
00378 maxwrk = 1;
00379 }
00380 work[1] = (real) maxwrk;
00381
00382 if (*lwork < minwrk && ! lquery) {
00383 *info = -19;
00384 }
00385 }
00386
00387 if (*info != 0) {
00388 i__1 = -(*info);
00389 xerbla_("SGGES ", &i__1);
00390 return 0;
00391 } else if (lquery) {
00392 return 0;
00393 }
00394
00395
00396
00397 if (*n == 0) {
00398 *sdim = 0;
00399 return 0;
00400 }
00401
00402
00403
00404 eps = slamch_("P");
00405 safmin = slamch_("S");
00406 safmax = 1.f / safmin;
00407 slabad_(&safmin, &safmax);
00408 smlnum = sqrt(safmin) / eps;
00409 bignum = 1.f / smlnum;
00410
00411
00412
00413 anrm = slange_("M", n, n, &a[a_offset], lda, &work[1]);
00414 ilascl = FALSE_;
00415 if (anrm > 0.f && anrm < smlnum) {
00416 anrmto = smlnum;
00417 ilascl = TRUE_;
00418 } else if (anrm > bignum) {
00419 anrmto = bignum;
00420 ilascl = TRUE_;
00421 }
00422 if (ilascl) {
00423 slascl_("G", &c__0, &c__0, &anrm, &anrmto, n, n, &a[a_offset], lda, &
00424 ierr);
00425 }
00426
00427
00428
00429 bnrm = slange_("M", n, n, &b[b_offset], ldb, &work[1]);
00430 ilbscl = FALSE_;
00431 if (bnrm > 0.f && bnrm < smlnum) {
00432 bnrmto = smlnum;
00433 ilbscl = TRUE_;
00434 } else if (bnrm > bignum) {
00435 bnrmto = bignum;
00436 ilbscl = TRUE_;
00437 }
00438 if (ilbscl) {
00439 slascl_("G", &c__0, &c__0, &bnrm, &bnrmto, n, n, &b[b_offset], ldb, &
00440 ierr);
00441 }
00442
00443
00444
00445
00446 ileft = 1;
00447 iright = *n + 1;
00448 iwrk = iright + *n;
00449 sggbal_("P", n, &a[a_offset], lda, &b[b_offset], ldb, &ilo, &ihi, &work[
00450 ileft], &work[iright], &work[iwrk], &ierr);
00451
00452
00453
00454
00455 irows = ihi + 1 - ilo;
00456 icols = *n + 1 - ilo;
00457 itau = iwrk;
00458 iwrk = itau + irows;
00459 i__1 = *lwork + 1 - iwrk;
00460 sgeqrf_(&irows, &icols, &b[ilo + ilo * b_dim1], ldb, &work[itau], &work[
00461 iwrk], &i__1, &ierr);
00462
00463
00464
00465
00466 i__1 = *lwork + 1 - iwrk;
00467 sormqr_("L", "T", &irows, &icols, &irows, &b[ilo + ilo * b_dim1], ldb, &
00468 work[itau], &a[ilo + ilo * a_dim1], lda, &work[iwrk], &i__1, &
00469 ierr);
00470
00471
00472
00473
00474 if (ilvsl) {
00475 slaset_("Full", n, n, &c_b38, &c_b39, &vsl[vsl_offset], ldvsl);
00476 if (irows > 1) {
00477 i__1 = irows - 1;
00478 i__2 = irows - 1;
00479 slacpy_("L", &i__1, &i__2, &b[ilo + 1 + ilo * b_dim1], ldb, &vsl[
00480 ilo + 1 + ilo * vsl_dim1], ldvsl);
00481 }
00482 i__1 = *lwork + 1 - iwrk;
00483 sorgqr_(&irows, &irows, &irows, &vsl[ilo + ilo * vsl_dim1], ldvsl, &
00484 work[itau], &work[iwrk], &i__1, &ierr);
00485 }
00486
00487
00488
00489 if (ilvsr) {
00490 slaset_("Full", n, n, &c_b38, &c_b39, &vsr[vsr_offset], ldvsr);
00491 }
00492
00493
00494
00495
00496 sgghrd_(jobvsl, jobvsr, n, &ilo, &ihi, &a[a_offset], lda, &b[b_offset],
00497 ldb, &vsl[vsl_offset], ldvsl, &vsr[vsr_offset], ldvsr, &ierr);
00498
00499
00500
00501
00502 iwrk = itau;
00503 i__1 = *lwork + 1 - iwrk;
00504 shgeqz_("S", jobvsl, jobvsr, n, &ilo, &ihi, &a[a_offset], lda, &b[
00505 b_offset], ldb, &alphar[1], &alphai[1], &beta[1], &vsl[vsl_offset]
00506 , ldvsl, &vsr[vsr_offset], ldvsr, &work[iwrk], &i__1, &ierr);
00507 if (ierr != 0) {
00508 if (ierr > 0 && ierr <= *n) {
00509 *info = ierr;
00510 } else if (ierr > *n && ierr <= *n << 1) {
00511 *info = ierr - *n;
00512 } else {
00513 *info = *n + 1;
00514 }
00515 goto L40;
00516 }
00517
00518
00519
00520
00521 *sdim = 0;
00522 if (wantst) {
00523
00524
00525
00526 if (ilascl) {
00527 slascl_("G", &c__0, &c__0, &anrmto, &anrm, n, &c__1, &alphar[1],
00528 n, &ierr);
00529 slascl_("G", &c__0, &c__0, &anrmto, &anrm, n, &c__1, &alphai[1],
00530 n, &ierr);
00531 }
00532 if (ilbscl) {
00533 slascl_("G", &c__0, &c__0, &bnrmto, &bnrm, n, &c__1, &beta[1], n,
00534 &ierr);
00535 }
00536
00537
00538
00539 i__1 = *n;
00540 for (i__ = 1; i__ <= i__1; ++i__) {
00541 bwork[i__] = (*selctg)(&alphar[i__], &alphai[i__], &beta[i__]);
00542
00543 }
00544
00545 i__1 = *lwork - iwrk + 1;
00546 stgsen_(&c__0, &ilvsl, &ilvsr, &bwork[1], n, &a[a_offset], lda, &b[
00547 b_offset], ldb, &alphar[1], &alphai[1], &beta[1], &vsl[
00548 vsl_offset], ldvsl, &vsr[vsr_offset], ldvsr, sdim, &pvsl, &
00549 pvsr, dif, &work[iwrk], &i__1, idum, &c__1, &ierr);
00550 if (ierr == 1) {
00551 *info = *n + 3;
00552 }
00553
00554 }
00555
00556
00557
00558
00559 if (ilvsl) {
00560 sggbak_("P", "L", n, &ilo, &ihi, &work[ileft], &work[iright], n, &vsl[
00561 vsl_offset], ldvsl, &ierr);
00562 }
00563
00564 if (ilvsr) {
00565 sggbak_("P", "R", n, &ilo, &ihi, &work[ileft], &work[iright], n, &vsr[
00566 vsr_offset], ldvsr, &ierr);
00567 }
00568
00569
00570
00571
00572
00573 if (ilascl) {
00574 i__1 = *n;
00575 for (i__ = 1; i__ <= i__1; ++i__) {
00576 if (alphai[i__] != 0.f) {
00577 if (alphar[i__] / safmax > anrmto / anrm || safmin / alphar[
00578 i__] > anrm / anrmto) {
00579 work[1] = (r__1 = a[i__ + i__ * a_dim1] / alphar[i__],
00580 dabs(r__1));
00581 beta[i__] *= work[1];
00582 alphar[i__] *= work[1];
00583 alphai[i__] *= work[1];
00584 } else if (alphai[i__] / safmax > anrmto / anrm || safmin /
00585 alphai[i__] > anrm / anrmto) {
00586 work[1] = (r__1 = a[i__ + (i__ + 1) * a_dim1] / alphai[
00587 i__], dabs(r__1));
00588 beta[i__] *= work[1];
00589 alphar[i__] *= work[1];
00590 alphai[i__] *= work[1];
00591 }
00592 }
00593
00594 }
00595 }
00596
00597 if (ilbscl) {
00598 i__1 = *n;
00599 for (i__ = 1; i__ <= i__1; ++i__) {
00600 if (alphai[i__] != 0.f) {
00601 if (beta[i__] / safmax > bnrmto / bnrm || safmin / beta[i__]
00602 > bnrm / bnrmto) {
00603 work[1] = (r__1 = b[i__ + i__ * b_dim1] / beta[i__], dabs(
00604 r__1));
00605 beta[i__] *= work[1];
00606 alphar[i__] *= work[1];
00607 alphai[i__] *= work[1];
00608 }
00609 }
00610
00611 }
00612 }
00613
00614
00615
00616 if (ilascl) {
00617 slascl_("H", &c__0, &c__0, &anrmto, &anrm, n, n, &a[a_offset], lda, &
00618 ierr);
00619 slascl_("G", &c__0, &c__0, &anrmto, &anrm, n, &c__1, &alphar[1], n, &
00620 ierr);
00621 slascl_("G", &c__0, &c__0, &anrmto, &anrm, n, &c__1, &alphai[1], n, &
00622 ierr);
00623 }
00624
00625 if (ilbscl) {
00626 slascl_("U", &c__0, &c__0, &bnrmto, &bnrm, n, n, &b[b_offset], ldb, &
00627 ierr);
00628 slascl_("G", &c__0, &c__0, &bnrmto, &bnrm, n, &c__1, &beta[1], n, &
00629 ierr);
00630 }
00631
00632 if (wantst) {
00633
00634
00635
00636 lastsl = TRUE_;
00637 lst2sl = TRUE_;
00638 *sdim = 0;
00639 ip = 0;
00640 i__1 = *n;
00641 for (i__ = 1; i__ <= i__1; ++i__) {
00642 cursl = (*selctg)(&alphar[i__], &alphai[i__], &beta[i__]);
00643 if (alphai[i__] == 0.f) {
00644 if (cursl) {
00645 ++(*sdim);
00646 }
00647 ip = 0;
00648 if (cursl && ! lastsl) {
00649 *info = *n + 2;
00650 }
00651 } else {
00652 if (ip == 1) {
00653
00654
00655
00656 cursl = cursl || lastsl;
00657 lastsl = cursl;
00658 if (cursl) {
00659 *sdim += 2;
00660 }
00661 ip = -1;
00662 if (cursl && ! lst2sl) {
00663 *info = *n + 2;
00664 }
00665 } else {
00666
00667
00668
00669 ip = 1;
00670 }
00671 }
00672 lst2sl = lastsl;
00673 lastsl = cursl;
00674
00675 }
00676
00677 }
00678
00679 L40:
00680
00681 work[1] = (real) maxwrk;
00682
00683 return 0;
00684
00685
00686
00687 }