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 real c_b12 = 0.f;
00019 static real c_b13 = 1.f;
00020 static integer c__1 = 1;
00021 static integer c__3 = 3;
00022
00023 int shgeqz_(char *job, char *compq, char *compz, integer *n,
00024 integer *ilo, integer *ihi, real *h__, integer *ldh, real *t, integer
00025 *ldt, real *alphar, real *alphai, real *beta, real *q, integer *ldq,
00026 real *z__, integer *ldz, real *work, integer *lwork, integer *info)
00027 {
00028
00029 integer h_dim1, h_offset, q_dim1, q_offset, t_dim1, t_offset, z_dim1,
00030 z_offset, i__1, i__2, i__3, i__4;
00031 real r__1, r__2, r__3, r__4;
00032
00033
00034 double sqrt(doublereal);
00035
00036
00037 real c__;
00038 integer j;
00039 real s, v[3], s1, s2, t1, u1, u2, a11, a12, a21, a22, b11, b22, c12, c21;
00040 integer jc;
00041 real an, bn, cl, cq, cr;
00042 integer in;
00043 real u12, w11, w12, w21;
00044 integer jr;
00045 real cz, w22, sl, wi, sr, vs, wr, b1a, b2a, a1i, a2i, b1i, b2i, a1r, a2r,
00046 b1r, b2r, wr2, ad11, ad12, ad21, ad22, c11i, c22i;
00047 integer jch;
00048 real c11r, c22r;
00049 logical ilq;
00050 real u12l, tau, sqi;
00051 logical ilz;
00052 real ulp, sqr, szi, szr, ad11l, ad12l, ad21l, ad22l, ad32l, wabs, atol,
00053 btol, temp;
00054 extern int srot_(integer *, real *, integer *, real *,
00055 integer *, real *, real *), slag2_(real *, integer *, real *,
00056 integer *, real *, real *, real *, real *, real *, real *);
00057 real temp2, s1inv, scale;
00058 extern logical lsame_(char *, char *);
00059 integer iiter, ilast, jiter;
00060 real anorm, bnorm;
00061 integer maxit;
00062 real tempi, tempr;
00063 logical ilazr2;
00064 extern doublereal slapy2_(real *, real *), slapy3_(real *, real *, real *)
00065 ;
00066 extern int slasv2_(real *, real *, real *, real *, real *
00067 , real *, real *, real *, real *);
00068 real ascale, bscale;
00069 extern doublereal slamch_(char *);
00070 real safmin;
00071 extern int slarfg_(integer *, real *, real *, integer *,
00072 real *);
00073 real safmax;
00074 extern int xerbla_(char *, integer *);
00075 real eshift;
00076 logical ilschr;
00077 integer icompq, ilastm;
00078 extern doublereal slanhs_(char *, integer *, real *, integer *, real *);
00079 extern int slartg_(real *, real *, real *, real *, real *
00080 );
00081 integer ischur;
00082 extern int slaset_(char *, integer *, integer *, real *,
00083 real *, real *, integer *);
00084 logical ilazro;
00085 integer icompz, ifirst, ifrstm, istart;
00086 logical ilpivt, lquery;
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
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
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309 h_dim1 = *ldh;
00310 h_offset = 1 + h_dim1;
00311 h__ -= h_offset;
00312 t_dim1 = *ldt;
00313 t_offset = 1 + t_dim1;
00314 t -= t_offset;
00315 --alphar;
00316 --alphai;
00317 --beta;
00318 q_dim1 = *ldq;
00319 q_offset = 1 + q_dim1;
00320 q -= q_offset;
00321 z_dim1 = *ldz;
00322 z_offset = 1 + z_dim1;
00323 z__ -= z_offset;
00324 --work;
00325
00326
00327 if (lsame_(job, "E")) {
00328 ilschr = FALSE_;
00329 ischur = 1;
00330 } else if (lsame_(job, "S")) {
00331 ilschr = TRUE_;
00332 ischur = 2;
00333 } else {
00334 ischur = 0;
00335 }
00336
00337 if (lsame_(compq, "N")) {
00338 ilq = FALSE_;
00339 icompq = 1;
00340 } else if (lsame_(compq, "V")) {
00341 ilq = TRUE_;
00342 icompq = 2;
00343 } else if (lsame_(compq, "I")) {
00344 ilq = TRUE_;
00345 icompq = 3;
00346 } else {
00347 icompq = 0;
00348 }
00349
00350 if (lsame_(compz, "N")) {
00351 ilz = FALSE_;
00352 icompz = 1;
00353 } else if (lsame_(compz, "V")) {
00354 ilz = TRUE_;
00355 icompz = 2;
00356 } else if (lsame_(compz, "I")) {
00357 ilz = TRUE_;
00358 icompz = 3;
00359 } else {
00360 icompz = 0;
00361 }
00362
00363
00364
00365 *info = 0;
00366 work[1] = (real) max(1,*n);
00367 lquery = *lwork == -1;
00368 if (ischur == 0) {
00369 *info = -1;
00370 } else if (icompq == 0) {
00371 *info = -2;
00372 } else if (icompz == 0) {
00373 *info = -3;
00374 } else if (*n < 0) {
00375 *info = -4;
00376 } else if (*ilo < 1) {
00377 *info = -5;
00378 } else if (*ihi > *n || *ihi < *ilo - 1) {
00379 *info = -6;
00380 } else if (*ldh < *n) {
00381 *info = -8;
00382 } else if (*ldt < *n) {
00383 *info = -10;
00384 } else if (*ldq < 1 || ilq && *ldq < *n) {
00385 *info = -15;
00386 } else if (*ldz < 1 || ilz && *ldz < *n) {
00387 *info = -17;
00388 } else if (*lwork < max(1,*n) && ! lquery) {
00389 *info = -19;
00390 }
00391 if (*info != 0) {
00392 i__1 = -(*info);
00393 xerbla_("SHGEQZ", &i__1);
00394 return 0;
00395 } else if (lquery) {
00396 return 0;
00397 }
00398
00399
00400
00401 if (*n <= 0) {
00402 work[1] = 1.f;
00403 return 0;
00404 }
00405
00406
00407
00408 if (icompq == 3) {
00409 slaset_("Full", n, n, &c_b12, &c_b13, &q[q_offset], ldq);
00410 }
00411 if (icompz == 3) {
00412 slaset_("Full", n, n, &c_b12, &c_b13, &z__[z_offset], ldz);
00413 }
00414
00415
00416
00417 in = *ihi + 1 - *ilo;
00418 safmin = slamch_("S");
00419 safmax = 1.f / safmin;
00420 ulp = slamch_("E") * slamch_("B");
00421 anorm = slanhs_("F", &in, &h__[*ilo + *ilo * h_dim1], ldh, &work[1]);
00422 bnorm = slanhs_("F", &in, &t[*ilo + *ilo * t_dim1], ldt, &work[1]);
00423
00424 r__1 = safmin, r__2 = ulp * anorm;
00425 atol = dmax(r__1,r__2);
00426
00427 r__1 = safmin, r__2 = ulp * bnorm;
00428 btol = dmax(r__1,r__2);
00429 ascale = 1.f / dmax(safmin,anorm);
00430 bscale = 1.f / dmax(safmin,bnorm);
00431
00432
00433
00434 i__1 = *n;
00435 for (j = *ihi + 1; j <= i__1; ++j) {
00436 if (t[j + j * t_dim1] < 0.f) {
00437 if (ilschr) {
00438 i__2 = j;
00439 for (jr = 1; jr <= i__2; ++jr) {
00440 h__[jr + j * h_dim1] = -h__[jr + j * h_dim1];
00441 t[jr + j * t_dim1] = -t[jr + j * t_dim1];
00442
00443 }
00444 } else {
00445 h__[j + j * h_dim1] = -h__[j + j * h_dim1];
00446 t[j + j * t_dim1] = -t[j + j * t_dim1];
00447 }
00448 if (ilz) {
00449 i__2 = *n;
00450 for (jr = 1; jr <= i__2; ++jr) {
00451 z__[jr + j * z_dim1] = -z__[jr + j * z_dim1];
00452
00453 }
00454 }
00455 }
00456 alphar[j] = h__[j + j * h_dim1];
00457 alphai[j] = 0.f;
00458 beta[j] = t[j + j * t_dim1];
00459
00460 }
00461
00462
00463
00464 if (*ihi < *ilo) {
00465 goto L380;
00466 }
00467
00468
00469
00470
00471
00472
00473
00474
00475
00476
00477
00478
00479
00480
00481
00482
00483 ilast = *ihi;
00484 if (ilschr) {
00485 ifrstm = 1;
00486 ilastm = *n;
00487 } else {
00488 ifrstm = *ilo;
00489 ilastm = *ihi;
00490 }
00491 iiter = 0;
00492 eshift = 0.f;
00493 maxit = (*ihi - *ilo + 1) * 30;
00494
00495 i__1 = maxit;
00496 for (jiter = 1; jiter <= i__1; ++jiter) {
00497
00498
00499
00500
00501
00502
00503
00504 if (ilast == *ilo) {
00505
00506
00507
00508 goto L80;
00509 } else {
00510 if ((r__1 = h__[ilast + (ilast - 1) * h_dim1], dabs(r__1)) <=
00511 atol) {
00512 h__[ilast + (ilast - 1) * h_dim1] = 0.f;
00513 goto L80;
00514 }
00515 }
00516
00517 if ((r__1 = t[ilast + ilast * t_dim1], dabs(r__1)) <= btol) {
00518 t[ilast + ilast * t_dim1] = 0.f;
00519 goto L70;
00520 }
00521
00522
00523
00524 i__2 = *ilo;
00525 for (j = ilast - 1; j >= i__2; --j) {
00526
00527
00528
00529 if (j == *ilo) {
00530 ilazro = TRUE_;
00531 } else {
00532 if ((r__1 = h__[j + (j - 1) * h_dim1], dabs(r__1)) <= atol) {
00533 h__[j + (j - 1) * h_dim1] = 0.f;
00534 ilazro = TRUE_;
00535 } else {
00536 ilazro = FALSE_;
00537 }
00538 }
00539
00540
00541
00542 if ((r__1 = t[j + j * t_dim1], dabs(r__1)) < btol) {
00543 t[j + j * t_dim1] = 0.f;
00544
00545
00546
00547 ilazr2 = FALSE_;
00548 if (! ilazro) {
00549 temp = (r__1 = h__[j + (j - 1) * h_dim1], dabs(r__1));
00550 temp2 = (r__1 = h__[j + j * h_dim1], dabs(r__1));
00551 tempr = dmax(temp,temp2);
00552 if (tempr < 1.f && tempr != 0.f) {
00553 temp /= tempr;
00554 temp2 /= tempr;
00555 }
00556 if (temp * (ascale * (r__1 = h__[j + 1 + j * h_dim1],
00557 dabs(r__1))) <= temp2 * (ascale * atol)) {
00558 ilazr2 = TRUE_;
00559 }
00560 }
00561
00562
00563
00564
00565
00566
00567
00568 if (ilazro || ilazr2) {
00569 i__3 = ilast - 1;
00570 for (jch = j; jch <= i__3; ++jch) {
00571 temp = h__[jch + jch * h_dim1];
00572 slartg_(&temp, &h__[jch + 1 + jch * h_dim1], &c__, &s,
00573 &h__[jch + jch * h_dim1]);
00574 h__[jch + 1 + jch * h_dim1] = 0.f;
00575 i__4 = ilastm - jch;
00576 srot_(&i__4, &h__[jch + (jch + 1) * h_dim1], ldh, &
00577 h__[jch + 1 + (jch + 1) * h_dim1], ldh, &c__,
00578 &s);
00579 i__4 = ilastm - jch;
00580 srot_(&i__4, &t[jch + (jch + 1) * t_dim1], ldt, &t[
00581 jch + 1 + (jch + 1) * t_dim1], ldt, &c__, &s);
00582 if (ilq) {
00583 srot_(n, &q[jch * q_dim1 + 1], &c__1, &q[(jch + 1)
00584 * q_dim1 + 1], &c__1, &c__, &s);
00585 }
00586 if (ilazr2) {
00587 h__[jch + (jch - 1) * h_dim1] *= c__;
00588 }
00589 ilazr2 = FALSE_;
00590 if ((r__1 = t[jch + 1 + (jch + 1) * t_dim1], dabs(
00591 r__1)) >= btol) {
00592 if (jch + 1 >= ilast) {
00593 goto L80;
00594 } else {
00595 ifirst = jch + 1;
00596 goto L110;
00597 }
00598 }
00599 t[jch + 1 + (jch + 1) * t_dim1] = 0.f;
00600
00601 }
00602 goto L70;
00603 } else {
00604
00605
00606
00607
00608 i__3 = ilast - 1;
00609 for (jch = j; jch <= i__3; ++jch) {
00610 temp = t[jch + (jch + 1) * t_dim1];
00611 slartg_(&temp, &t[jch + 1 + (jch + 1) * t_dim1], &c__,
00612 &s, &t[jch + (jch + 1) * t_dim1]);
00613 t[jch + 1 + (jch + 1) * t_dim1] = 0.f;
00614 if (jch < ilastm - 1) {
00615 i__4 = ilastm - jch - 1;
00616 srot_(&i__4, &t[jch + (jch + 2) * t_dim1], ldt, &
00617 t[jch + 1 + (jch + 2) * t_dim1], ldt, &
00618 c__, &s);
00619 }
00620 i__4 = ilastm - jch + 2;
00621 srot_(&i__4, &h__[jch + (jch - 1) * h_dim1], ldh, &
00622 h__[jch + 1 + (jch - 1) * h_dim1], ldh, &c__,
00623 &s);
00624 if (ilq) {
00625 srot_(n, &q[jch * q_dim1 + 1], &c__1, &q[(jch + 1)
00626 * q_dim1 + 1], &c__1, &c__, &s);
00627 }
00628 temp = h__[jch + 1 + jch * h_dim1];
00629 slartg_(&temp, &h__[jch + 1 + (jch - 1) * h_dim1], &
00630 c__, &s, &h__[jch + 1 + jch * h_dim1]);
00631 h__[jch + 1 + (jch - 1) * h_dim1] = 0.f;
00632 i__4 = jch + 1 - ifrstm;
00633 srot_(&i__4, &h__[ifrstm + jch * h_dim1], &c__1, &h__[
00634 ifrstm + (jch - 1) * h_dim1], &c__1, &c__, &s)
00635 ;
00636 i__4 = jch - ifrstm;
00637 srot_(&i__4, &t[ifrstm + jch * t_dim1], &c__1, &t[
00638 ifrstm + (jch - 1) * t_dim1], &c__1, &c__, &s)
00639 ;
00640 if (ilz) {
00641 srot_(n, &z__[jch * z_dim1 + 1], &c__1, &z__[(jch
00642 - 1) * z_dim1 + 1], &c__1, &c__, &s);
00643 }
00644
00645 }
00646 goto L70;
00647 }
00648 } else if (ilazro) {
00649
00650
00651
00652 ifirst = j;
00653 goto L110;
00654 }
00655
00656
00657
00658
00659 }
00660
00661
00662
00663 *info = *n + 1;
00664 goto L420;
00665
00666
00667
00668
00669 L70:
00670 temp = h__[ilast + ilast * h_dim1];
00671 slartg_(&temp, &h__[ilast + (ilast - 1) * h_dim1], &c__, &s, &h__[
00672 ilast + ilast * h_dim1]);
00673 h__[ilast + (ilast - 1) * h_dim1] = 0.f;
00674 i__2 = ilast - ifrstm;
00675 srot_(&i__2, &h__[ifrstm + ilast * h_dim1], &c__1, &h__[ifrstm + (
00676 ilast - 1) * h_dim1], &c__1, &c__, &s);
00677 i__2 = ilast - ifrstm;
00678 srot_(&i__2, &t[ifrstm + ilast * t_dim1], &c__1, &t[ifrstm + (ilast -
00679 1) * t_dim1], &c__1, &c__, &s);
00680 if (ilz) {
00681 srot_(n, &z__[ilast * z_dim1 + 1], &c__1, &z__[(ilast - 1) *
00682 z_dim1 + 1], &c__1, &c__, &s);
00683 }
00684
00685
00686
00687
00688 L80:
00689 if (t[ilast + ilast * t_dim1] < 0.f) {
00690 if (ilschr) {
00691 i__2 = ilast;
00692 for (j = ifrstm; j <= i__2; ++j) {
00693 h__[j + ilast * h_dim1] = -h__[j + ilast * h_dim1];
00694 t[j + ilast * t_dim1] = -t[j + ilast * t_dim1];
00695
00696 }
00697 } else {
00698 h__[ilast + ilast * h_dim1] = -h__[ilast + ilast * h_dim1];
00699 t[ilast + ilast * t_dim1] = -t[ilast + ilast * t_dim1];
00700 }
00701 if (ilz) {
00702 i__2 = *n;
00703 for (j = 1; j <= i__2; ++j) {
00704 z__[j + ilast * z_dim1] = -z__[j + ilast * z_dim1];
00705
00706 }
00707 }
00708 }
00709 alphar[ilast] = h__[ilast + ilast * h_dim1];
00710 alphai[ilast] = 0.f;
00711 beta[ilast] = t[ilast + ilast * t_dim1];
00712
00713
00714
00715 --ilast;
00716 if (ilast < *ilo) {
00717 goto L380;
00718 }
00719
00720
00721
00722 iiter = 0;
00723 eshift = 0.f;
00724 if (! ilschr) {
00725 ilastm = ilast;
00726 if (ifrstm > ilast) {
00727 ifrstm = *ilo;
00728 }
00729 }
00730 goto L350;
00731
00732
00733
00734
00735
00736
00737 L110:
00738 ++iiter;
00739 if (! ilschr) {
00740 ifrstm = ifirst;
00741 }
00742
00743
00744
00745
00746
00747
00748
00749 if (iiter / 10 * 10 == iiter) {
00750
00751
00752
00753
00754 if ((real) maxit * safmin * (r__1 = h__[ilast - 1 + ilast *
00755 h_dim1], dabs(r__1)) < (r__2 = t[ilast - 1 + (ilast - 1) *
00756 t_dim1], dabs(r__2))) {
00757 eshift += h__[ilast - 1 + ilast * h_dim1] / t[ilast - 1 + (
00758 ilast - 1) * t_dim1];
00759 } else {
00760 eshift += 1.f / (safmin * (real) maxit);
00761 }
00762 s1 = 1.f;
00763 wr = eshift;
00764
00765 } else {
00766
00767
00768
00769
00770
00771 r__1 = safmin * 100.f;
00772 slag2_(&h__[ilast - 1 + (ilast - 1) * h_dim1], ldh, &t[ilast - 1
00773 + (ilast - 1) * t_dim1], ldt, &r__1, &s1, &s2, &wr, &wr2,
00774 &wi);
00775
00776
00777
00778 r__3 = 1.f, r__4 = dabs(wr), r__3 = max(r__3,r__4), r__4 = dabs(
00779 wi);
00780 r__1 = s1, r__2 = safmin * dmax(r__3,r__4);
00781 temp = dmax(r__1,r__2);
00782 if (wi != 0.f) {
00783 goto L200;
00784 }
00785 }
00786
00787
00788
00789 temp = dmin(ascale,1.f) * (safmax * .5f);
00790 if (s1 > temp) {
00791 scale = temp / s1;
00792 } else {
00793 scale = 1.f;
00794 }
00795
00796 temp = dmin(bscale,1.f) * (safmax * .5f);
00797 if (dabs(wr) > temp) {
00798
00799 r__1 = scale, r__2 = temp / dabs(wr);
00800 scale = dmin(r__1,r__2);
00801 }
00802 s1 = scale * s1;
00803 wr = scale * wr;
00804
00805
00806
00807 i__2 = ifirst + 1;
00808 for (j = ilast - 1; j >= i__2; --j) {
00809 istart = j;
00810 temp = (r__1 = s1 * h__[j + (j - 1) * h_dim1], dabs(r__1));
00811 temp2 = (r__1 = s1 * h__[j + j * h_dim1] - wr * t[j + j * t_dim1],
00812 dabs(r__1));
00813 tempr = dmax(temp,temp2);
00814 if (tempr < 1.f && tempr != 0.f) {
00815 temp /= tempr;
00816 temp2 /= tempr;
00817 }
00818 if ((r__1 = ascale * h__[j + 1 + j * h_dim1] * temp, dabs(r__1))
00819 <= ascale * atol * temp2) {
00820 goto L130;
00821 }
00822
00823 }
00824
00825 istart = ifirst;
00826 L130:
00827
00828
00829
00830
00831
00832 temp = s1 * h__[istart + istart * h_dim1] - wr * t[istart + istart *
00833 t_dim1];
00834 temp2 = s1 * h__[istart + 1 + istart * h_dim1];
00835 slartg_(&temp, &temp2, &c__, &s, &tempr);
00836
00837
00838
00839 i__2 = ilast - 1;
00840 for (j = istart; j <= i__2; ++j) {
00841 if (j > istart) {
00842 temp = h__[j + (j - 1) * h_dim1];
00843 slartg_(&temp, &h__[j + 1 + (j - 1) * h_dim1], &c__, &s, &h__[
00844 j + (j - 1) * h_dim1]);
00845 h__[j + 1 + (j - 1) * h_dim1] = 0.f;
00846 }
00847
00848 i__3 = ilastm;
00849 for (jc = j; jc <= i__3; ++jc) {
00850 temp = c__ * h__[j + jc * h_dim1] + s * h__[j + 1 + jc *
00851 h_dim1];
00852 h__[j + 1 + jc * h_dim1] = -s * h__[j + jc * h_dim1] + c__ *
00853 h__[j + 1 + jc * h_dim1];
00854 h__[j + jc * h_dim1] = temp;
00855 temp2 = c__ * t[j + jc * t_dim1] + s * t[j + 1 + jc * t_dim1];
00856 t[j + 1 + jc * t_dim1] = -s * t[j + jc * t_dim1] + c__ * t[j
00857 + 1 + jc * t_dim1];
00858 t[j + jc * t_dim1] = temp2;
00859
00860 }
00861 if (ilq) {
00862 i__3 = *n;
00863 for (jr = 1; jr <= i__3; ++jr) {
00864 temp = c__ * q[jr + j * q_dim1] + s * q[jr + (j + 1) *
00865 q_dim1];
00866 q[jr + (j + 1) * q_dim1] = -s * q[jr + j * q_dim1] + c__ *
00867 q[jr + (j + 1) * q_dim1];
00868 q[jr + j * q_dim1] = temp;
00869
00870 }
00871 }
00872
00873 temp = t[j + 1 + (j + 1) * t_dim1];
00874 slartg_(&temp, &t[j + 1 + j * t_dim1], &c__, &s, &t[j + 1 + (j +
00875 1) * t_dim1]);
00876 t[j + 1 + j * t_dim1] = 0.f;
00877
00878
00879 i__4 = j + 2;
00880 i__3 = min(i__4,ilast);
00881 for (jr = ifrstm; jr <= i__3; ++jr) {
00882 temp = c__ * h__[jr + (j + 1) * h_dim1] + s * h__[jr + j *
00883 h_dim1];
00884 h__[jr + j * h_dim1] = -s * h__[jr + (j + 1) * h_dim1] + c__ *
00885 h__[jr + j * h_dim1];
00886 h__[jr + (j + 1) * h_dim1] = temp;
00887
00888 }
00889 i__3 = j;
00890 for (jr = ifrstm; jr <= i__3; ++jr) {
00891 temp = c__ * t[jr + (j + 1) * t_dim1] + s * t[jr + j * t_dim1]
00892 ;
00893 t[jr + j * t_dim1] = -s * t[jr + (j + 1) * t_dim1] + c__ * t[
00894 jr + j * t_dim1];
00895 t[jr + (j + 1) * t_dim1] = temp;
00896
00897 }
00898 if (ilz) {
00899 i__3 = *n;
00900 for (jr = 1; jr <= i__3; ++jr) {
00901 temp = c__ * z__[jr + (j + 1) * z_dim1] + s * z__[jr + j *
00902 z_dim1];
00903 z__[jr + j * z_dim1] = -s * z__[jr + (j + 1) * z_dim1] +
00904 c__ * z__[jr + j * z_dim1];
00905 z__[jr + (j + 1) * z_dim1] = temp;
00906
00907 }
00908 }
00909
00910 }
00911
00912 goto L350;
00913
00914
00915
00916
00917
00918
00919
00920
00921 L200:
00922 if (ifirst + 1 == ilast) {
00923
00924
00925
00926
00927
00928
00929
00930
00931
00932 slasv2_(&t[ilast - 1 + (ilast - 1) * t_dim1], &t[ilast - 1 +
00933 ilast * t_dim1], &t[ilast + ilast * t_dim1], &b22, &b11, &
00934 sr, &cr, &sl, &cl);
00935
00936 if (b11 < 0.f) {
00937 cr = -cr;
00938 sr = -sr;
00939 b11 = -b11;
00940 b22 = -b22;
00941 }
00942
00943 i__2 = ilastm + 1 - ifirst;
00944 srot_(&i__2, &h__[ilast - 1 + (ilast - 1) * h_dim1], ldh, &h__[
00945 ilast + (ilast - 1) * h_dim1], ldh, &cl, &sl);
00946 i__2 = ilast + 1 - ifrstm;
00947 srot_(&i__2, &h__[ifrstm + (ilast - 1) * h_dim1], &c__1, &h__[
00948 ifrstm + ilast * h_dim1], &c__1, &cr, &sr);
00949
00950 if (ilast < ilastm) {
00951 i__2 = ilastm - ilast;
00952 srot_(&i__2, &t[ilast - 1 + (ilast + 1) * t_dim1], ldt, &t[
00953 ilast + (ilast + 1) * t_dim1], ldt, &cl, &sl);
00954 }
00955 if (ifrstm < ilast - 1) {
00956 i__2 = ifirst - ifrstm;
00957 srot_(&i__2, &t[ifrstm + (ilast - 1) * t_dim1], &c__1, &t[
00958 ifrstm + ilast * t_dim1], &c__1, &cr, &sr);
00959 }
00960
00961 if (ilq) {
00962 srot_(n, &q[(ilast - 1) * q_dim1 + 1], &c__1, &q[ilast *
00963 q_dim1 + 1], &c__1, &cl, &sl);
00964 }
00965 if (ilz) {
00966 srot_(n, &z__[(ilast - 1) * z_dim1 + 1], &c__1, &z__[ilast *
00967 z_dim1 + 1], &c__1, &cr, &sr);
00968 }
00969
00970 t[ilast - 1 + (ilast - 1) * t_dim1] = b11;
00971 t[ilast - 1 + ilast * t_dim1] = 0.f;
00972 t[ilast + (ilast - 1) * t_dim1] = 0.f;
00973 t[ilast + ilast * t_dim1] = b22;
00974
00975
00976
00977 if (b22 < 0.f) {
00978 i__2 = ilast;
00979 for (j = ifrstm; j <= i__2; ++j) {
00980 h__[j + ilast * h_dim1] = -h__[j + ilast * h_dim1];
00981 t[j + ilast * t_dim1] = -t[j + ilast * t_dim1];
00982
00983 }
00984
00985 if (ilz) {
00986 i__2 = *n;
00987 for (j = 1; j <= i__2; ++j) {
00988 z__[j + ilast * z_dim1] = -z__[j + ilast * z_dim1];
00989
00990 }
00991 }
00992 }
00993
00994
00995
00996
00997
00998 r__1 = safmin * 100.f;
00999 slag2_(&h__[ilast - 1 + (ilast - 1) * h_dim1], ldh, &t[ilast - 1
01000 + (ilast - 1) * t_dim1], ldt, &r__1, &s1, &temp, &wr, &
01001 temp2, &wi);
01002
01003
01004
01005
01006 if (wi == 0.f) {
01007 goto L350;
01008 }
01009 s1inv = 1.f / s1;
01010
01011
01012
01013 a11 = h__[ilast - 1 + (ilast - 1) * h_dim1];
01014 a21 = h__[ilast + (ilast - 1) * h_dim1];
01015 a12 = h__[ilast - 1 + ilast * h_dim1];
01016 a22 = h__[ilast + ilast * h_dim1];
01017
01018
01019
01020
01021
01022
01023
01024 c11r = s1 * a11 - wr * b11;
01025 c11i = -wi * b11;
01026 c12 = s1 * a12;
01027 c21 = s1 * a21;
01028 c22r = s1 * a22 - wr * b22;
01029 c22i = -wi * b22;
01030
01031 if (dabs(c11r) + dabs(c11i) + dabs(c12) > dabs(c21) + dabs(c22r)
01032 + dabs(c22i)) {
01033 t1 = slapy3_(&c12, &c11r, &c11i);
01034 cz = c12 / t1;
01035 szr = -c11r / t1;
01036 szi = -c11i / t1;
01037 } else {
01038 cz = slapy2_(&c22r, &c22i);
01039 if (cz <= safmin) {
01040 cz = 0.f;
01041 szr = 1.f;
01042 szi = 0.f;
01043 } else {
01044 tempr = c22r / cz;
01045 tempi = c22i / cz;
01046 t1 = slapy2_(&cz, &c21);
01047 cz /= t1;
01048 szr = -c21 * tempr / t1;
01049 szi = c21 * tempi / t1;
01050 }
01051 }
01052
01053
01054
01055
01056
01057
01058
01059 an = dabs(a11) + dabs(a12) + dabs(a21) + dabs(a22);
01060 bn = dabs(b11) + dabs(b22);
01061 wabs = dabs(wr) + dabs(wi);
01062 if (s1 * an > wabs * bn) {
01063 cq = cz * b11;
01064 sqr = szr * b22;
01065 sqi = -szi * b22;
01066 } else {
01067 a1r = cz * a11 + szr * a12;
01068 a1i = szi * a12;
01069 a2r = cz * a21 + szr * a22;
01070 a2i = szi * a22;
01071 cq = slapy2_(&a1r, &a1i);
01072 if (cq <= safmin) {
01073 cq = 0.f;
01074 sqr = 1.f;
01075 sqi = 0.f;
01076 } else {
01077 tempr = a1r / cq;
01078 tempi = a1i / cq;
01079 sqr = tempr * a2r + tempi * a2i;
01080 sqi = tempi * a2r - tempr * a2i;
01081 }
01082 }
01083 t1 = slapy3_(&cq, &sqr, &sqi);
01084 cq /= t1;
01085 sqr /= t1;
01086 sqi /= t1;
01087
01088
01089
01090 tempr = sqr * szr - sqi * szi;
01091 tempi = sqr * szi + sqi * szr;
01092 b1r = cq * cz * b11 + tempr * b22;
01093 b1i = tempi * b22;
01094 b1a = slapy2_(&b1r, &b1i);
01095 b2r = cq * cz * b22 + tempr * b11;
01096 b2i = -tempi * b11;
01097 b2a = slapy2_(&b2r, &b2i);
01098
01099
01100
01101 beta[ilast - 1] = b1a;
01102 beta[ilast] = b2a;
01103 alphar[ilast - 1] = wr * b1a * s1inv;
01104 alphai[ilast - 1] = wi * b1a * s1inv;
01105 alphar[ilast] = wr * b2a * s1inv;
01106 alphai[ilast] = -(wi * b2a) * s1inv;
01107
01108
01109
01110 ilast = ifirst - 1;
01111 if (ilast < *ilo) {
01112 goto L380;
01113 }
01114
01115
01116
01117 iiter = 0;
01118 eshift = 0.f;
01119 if (! ilschr) {
01120 ilastm = ilast;
01121 if (ifrstm > ilast) {
01122 ifrstm = *ilo;
01123 }
01124 }
01125 goto L350;
01126 } else {
01127
01128
01129
01130
01131
01132
01133
01134
01135
01136
01137
01138
01139
01140 ad11 = ascale * h__[ilast - 1 + (ilast - 1) * h_dim1] / (bscale *
01141 t[ilast - 1 + (ilast - 1) * t_dim1]);
01142 ad21 = ascale * h__[ilast + (ilast - 1) * h_dim1] / (bscale * t[
01143 ilast - 1 + (ilast - 1) * t_dim1]);
01144 ad12 = ascale * h__[ilast - 1 + ilast * h_dim1] / (bscale * t[
01145 ilast + ilast * t_dim1]);
01146 ad22 = ascale * h__[ilast + ilast * h_dim1] / (bscale * t[ilast +
01147 ilast * t_dim1]);
01148 u12 = t[ilast - 1 + ilast * t_dim1] / t[ilast + ilast * t_dim1];
01149 ad11l = ascale * h__[ifirst + ifirst * h_dim1] / (bscale * t[
01150 ifirst + ifirst * t_dim1]);
01151 ad21l = ascale * h__[ifirst + 1 + ifirst * h_dim1] / (bscale * t[
01152 ifirst + ifirst * t_dim1]);
01153 ad12l = ascale * h__[ifirst + (ifirst + 1) * h_dim1] / (bscale *
01154 t[ifirst + 1 + (ifirst + 1) * t_dim1]);
01155 ad22l = ascale * h__[ifirst + 1 + (ifirst + 1) * h_dim1] / (
01156 bscale * t[ifirst + 1 + (ifirst + 1) * t_dim1]);
01157 ad32l = ascale * h__[ifirst + 2 + (ifirst + 1) * h_dim1] / (
01158 bscale * t[ifirst + 1 + (ifirst + 1) * t_dim1]);
01159 u12l = t[ifirst + (ifirst + 1) * t_dim1] / t[ifirst + 1 + (ifirst
01160 + 1) * t_dim1];
01161
01162 v[0] = (ad11 - ad11l) * (ad22 - ad11l) - ad12 * ad21 + ad21 * u12
01163 * ad11l + (ad12l - ad11l * u12l) * ad21l;
01164 v[1] = (ad22l - ad11l - ad21l * u12l - (ad11 - ad11l) - (ad22 -
01165 ad11l) + ad21 * u12) * ad21l;
01166 v[2] = ad32l * ad21l;
01167
01168 istart = ifirst;
01169
01170 slarfg_(&c__3, v, &v[1], &c__1, &tau);
01171 v[0] = 1.f;
01172
01173
01174
01175 i__2 = ilast - 2;
01176 for (j = istart; j <= i__2; ++j) {
01177
01178
01179
01180
01181
01182 if (j > istart) {
01183 v[0] = h__[j + (j - 1) * h_dim1];
01184 v[1] = h__[j + 1 + (j - 1) * h_dim1];
01185 v[2] = h__[j + 2 + (j - 1) * h_dim1];
01186
01187 slarfg_(&c__3, &h__[j + (j - 1) * h_dim1], &v[1], &c__1, &
01188 tau);
01189 v[0] = 1.f;
01190 h__[j + 1 + (j - 1) * h_dim1] = 0.f;
01191 h__[j + 2 + (j - 1) * h_dim1] = 0.f;
01192 }
01193
01194 i__3 = ilastm;
01195 for (jc = j; jc <= i__3; ++jc) {
01196 temp = tau * (h__[j + jc * h_dim1] + v[1] * h__[j + 1 +
01197 jc * h_dim1] + v[2] * h__[j + 2 + jc * h_dim1]);
01198 h__[j + jc * h_dim1] -= temp;
01199 h__[j + 1 + jc * h_dim1] -= temp * v[1];
01200 h__[j + 2 + jc * h_dim1] -= temp * v[2];
01201 temp2 = tau * (t[j + jc * t_dim1] + v[1] * t[j + 1 + jc *
01202 t_dim1] + v[2] * t[j + 2 + jc * t_dim1]);
01203 t[j + jc * t_dim1] -= temp2;
01204 t[j + 1 + jc * t_dim1] -= temp2 * v[1];
01205 t[j + 2 + jc * t_dim1] -= temp2 * v[2];
01206
01207 }
01208 if (ilq) {
01209 i__3 = *n;
01210 for (jr = 1; jr <= i__3; ++jr) {
01211 temp = tau * (q[jr + j * q_dim1] + v[1] * q[jr + (j +
01212 1) * q_dim1] + v[2] * q[jr + (j + 2) * q_dim1]
01213 );
01214 q[jr + j * q_dim1] -= temp;
01215 q[jr + (j + 1) * q_dim1] -= temp * v[1];
01216 q[jr + (j + 2) * q_dim1] -= temp * v[2];
01217
01218 }
01219 }
01220
01221
01222
01223
01224
01225 ilpivt = FALSE_;
01226
01227 r__3 = (r__1 = t[j + 1 + (j + 1) * t_dim1], dabs(r__1)), r__4
01228 = (r__2 = t[j + 1 + (j + 2) * t_dim1], dabs(r__2));
01229 temp = dmax(r__3,r__4);
01230
01231 r__3 = (r__1 = t[j + 2 + (j + 1) * t_dim1], dabs(r__1)), r__4
01232 = (r__2 = t[j + 2 + (j + 2) * t_dim1], dabs(r__2));
01233 temp2 = dmax(r__3,r__4);
01234 if (dmax(temp,temp2) < safmin) {
01235 scale = 0.f;
01236 u1 = 1.f;
01237 u2 = 0.f;
01238 goto L250;
01239 } else if (temp >= temp2) {
01240 w11 = t[j + 1 + (j + 1) * t_dim1];
01241 w21 = t[j + 2 + (j + 1) * t_dim1];
01242 w12 = t[j + 1 + (j + 2) * t_dim1];
01243 w22 = t[j + 2 + (j + 2) * t_dim1];
01244 u1 = t[j + 1 + j * t_dim1];
01245 u2 = t[j + 2 + j * t_dim1];
01246 } else {
01247 w21 = t[j + 1 + (j + 1) * t_dim1];
01248 w11 = t[j + 2 + (j + 1) * t_dim1];
01249 w22 = t[j + 1 + (j + 2) * t_dim1];
01250 w12 = t[j + 2 + (j + 2) * t_dim1];
01251 u2 = t[j + 1 + j * t_dim1];
01252 u1 = t[j + 2 + j * t_dim1];
01253 }
01254
01255
01256
01257 if (dabs(w12) > dabs(w11)) {
01258 ilpivt = TRUE_;
01259 temp = w12;
01260 temp2 = w22;
01261 w12 = w11;
01262 w22 = w21;
01263 w11 = temp;
01264 w21 = temp2;
01265 }
01266
01267
01268
01269 temp = w21 / w11;
01270 u2 -= temp * u1;
01271 w22 -= temp * w12;
01272 w21 = 0.f;
01273
01274
01275
01276 scale = 1.f;
01277 if (dabs(w22) < safmin) {
01278 scale = 0.f;
01279 u2 = 1.f;
01280 u1 = -w12 / w11;
01281 goto L250;
01282 }
01283 if (dabs(w22) < dabs(u2)) {
01284 scale = (r__1 = w22 / u2, dabs(r__1));
01285 }
01286 if (dabs(w11) < dabs(u1)) {
01287
01288 r__2 = scale, r__3 = (r__1 = w11 / u1, dabs(r__1));
01289 scale = dmin(r__2,r__3);
01290 }
01291
01292
01293
01294 u2 = scale * u2 / w22;
01295 u1 = (scale * u1 - w12 * u2) / w11;
01296
01297 L250:
01298 if (ilpivt) {
01299 temp = u2;
01300 u2 = u1;
01301 u1 = temp;
01302 }
01303
01304
01305
01306
01307 r__1 = scale;
01308
01309 r__2 = u1;
01310
01311 r__3 = u2;
01312 t1 = sqrt(r__1 * r__1 + r__2 * r__2 + r__3 * r__3);
01313 tau = scale / t1 + 1.f;
01314 vs = -1.f / (scale + t1);
01315 v[0] = 1.f;
01316 v[1] = vs * u1;
01317 v[2] = vs * u2;
01318
01319
01320
01321
01322 i__4 = j + 3;
01323 i__3 = min(i__4,ilast);
01324 for (jr = ifrstm; jr <= i__3; ++jr) {
01325 temp = tau * (h__[jr + j * h_dim1] + v[1] * h__[jr + (j +
01326 1) * h_dim1] + v[2] * h__[jr + (j + 2) * h_dim1]);
01327 h__[jr + j * h_dim1] -= temp;
01328 h__[jr + (j + 1) * h_dim1] -= temp * v[1];
01329 h__[jr + (j + 2) * h_dim1] -= temp * v[2];
01330
01331 }
01332 i__3 = j + 2;
01333 for (jr = ifrstm; jr <= i__3; ++jr) {
01334 temp = tau * (t[jr + j * t_dim1] + v[1] * t[jr + (j + 1) *
01335 t_dim1] + v[2] * t[jr + (j + 2) * t_dim1]);
01336 t[jr + j * t_dim1] -= temp;
01337 t[jr + (j + 1) * t_dim1] -= temp * v[1];
01338 t[jr + (j + 2) * t_dim1] -= temp * v[2];
01339
01340 }
01341 if (ilz) {
01342 i__3 = *n;
01343 for (jr = 1; jr <= i__3; ++jr) {
01344 temp = tau * (z__[jr + j * z_dim1] + v[1] * z__[jr + (
01345 j + 1) * z_dim1] + v[2] * z__[jr + (j + 2) *
01346 z_dim1]);
01347 z__[jr + j * z_dim1] -= temp;
01348 z__[jr + (j + 1) * z_dim1] -= temp * v[1];
01349 z__[jr + (j + 2) * z_dim1] -= temp * v[2];
01350
01351 }
01352 }
01353 t[j + 1 + j * t_dim1] = 0.f;
01354 t[j + 2 + j * t_dim1] = 0.f;
01355
01356 }
01357
01358
01359
01360
01361
01362 j = ilast - 1;
01363 temp = h__[j + (j - 1) * h_dim1];
01364 slartg_(&temp, &h__[j + 1 + (j - 1) * h_dim1], &c__, &s, &h__[j +
01365 (j - 1) * h_dim1]);
01366 h__[j + 1 + (j - 1) * h_dim1] = 0.f;
01367
01368 i__2 = ilastm;
01369 for (jc = j; jc <= i__2; ++jc) {
01370 temp = c__ * h__[j + jc * h_dim1] + s * h__[j + 1 + jc *
01371 h_dim1];
01372 h__[j + 1 + jc * h_dim1] = -s * h__[j + jc * h_dim1] + c__ *
01373 h__[j + 1 + jc * h_dim1];
01374 h__[j + jc * h_dim1] = temp;
01375 temp2 = c__ * t[j + jc * t_dim1] + s * t[j + 1 + jc * t_dim1];
01376 t[j + 1 + jc * t_dim1] = -s * t[j + jc * t_dim1] + c__ * t[j
01377 + 1 + jc * t_dim1];
01378 t[j + jc * t_dim1] = temp2;
01379
01380 }
01381 if (ilq) {
01382 i__2 = *n;
01383 for (jr = 1; jr <= i__2; ++jr) {
01384 temp = c__ * q[jr + j * q_dim1] + s * q[jr + (j + 1) *
01385 q_dim1];
01386 q[jr + (j + 1) * q_dim1] = -s * q[jr + j * q_dim1] + c__ *
01387 q[jr + (j + 1) * q_dim1];
01388 q[jr + j * q_dim1] = temp;
01389
01390 }
01391 }
01392
01393
01394
01395 temp = t[j + 1 + (j + 1) * t_dim1];
01396 slartg_(&temp, &t[j + 1 + j * t_dim1], &c__, &s, &t[j + 1 + (j +
01397 1) * t_dim1]);
01398 t[j + 1 + j * t_dim1] = 0.f;
01399
01400 i__2 = ilast;
01401 for (jr = ifrstm; jr <= i__2; ++jr) {
01402 temp = c__ * h__[jr + (j + 1) * h_dim1] + s * h__[jr + j *
01403 h_dim1];
01404 h__[jr + j * h_dim1] = -s * h__[jr + (j + 1) * h_dim1] + c__ *
01405 h__[jr + j * h_dim1];
01406 h__[jr + (j + 1) * h_dim1] = temp;
01407
01408 }
01409 i__2 = ilast - 1;
01410 for (jr = ifrstm; jr <= i__2; ++jr) {
01411 temp = c__ * t[jr + (j + 1) * t_dim1] + s * t[jr + j * t_dim1]
01412 ;
01413 t[jr + j * t_dim1] = -s * t[jr + (j + 1) * t_dim1] + c__ * t[
01414 jr + j * t_dim1];
01415 t[jr + (j + 1) * t_dim1] = temp;
01416
01417 }
01418 if (ilz) {
01419 i__2 = *n;
01420 for (jr = 1; jr <= i__2; ++jr) {
01421 temp = c__ * z__[jr + (j + 1) * z_dim1] + s * z__[jr + j *
01422 z_dim1];
01423 z__[jr + j * z_dim1] = -s * z__[jr + (j + 1) * z_dim1] +
01424 c__ * z__[jr + j * z_dim1];
01425 z__[jr + (j + 1) * z_dim1] = temp;
01426
01427 }
01428 }
01429
01430
01431
01432 }
01433
01434 goto L350;
01435
01436
01437
01438 L350:
01439
01440 ;
01441 }
01442
01443
01444
01445 *info = ilast;
01446 goto L420;
01447
01448
01449
01450 L380:
01451
01452
01453
01454 i__1 = *ilo - 1;
01455 for (j = 1; j <= i__1; ++j) {
01456 if (t[j + j * t_dim1] < 0.f) {
01457 if (ilschr) {
01458 i__2 = j;
01459 for (jr = 1; jr <= i__2; ++jr) {
01460 h__[jr + j * h_dim1] = -h__[jr + j * h_dim1];
01461 t[jr + j * t_dim1] = -t[jr + j * t_dim1];
01462
01463 }
01464 } else {
01465 h__[j + j * h_dim1] = -h__[j + j * h_dim1];
01466 t[j + j * t_dim1] = -t[j + j * t_dim1];
01467 }
01468 if (ilz) {
01469 i__2 = *n;
01470 for (jr = 1; jr <= i__2; ++jr) {
01471 z__[jr + j * z_dim1] = -z__[jr + j * z_dim1];
01472
01473 }
01474 }
01475 }
01476 alphar[j] = h__[j + j * h_dim1];
01477 alphai[j] = 0.f;
01478 beta[j] = t[j + j * t_dim1];
01479
01480 }
01481
01482
01483
01484 *info = 0;
01485
01486
01487
01488 L420:
01489 work[1] = (real) (*n);
01490 return 0;
01491
01492
01493
01494 }