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 doublecomplex c_b1 = {0.,0.};
00019 static doublecomplex c_b2 = {1.,0.};
00020 static integer c__1 = 1;
00021 static doublereal c_b39 = -1.;
00022 static doublereal c_b42 = 1.;
00023
00024 int ztgsja_(char *jobu, char *jobv, char *jobq, integer *m,
00025 integer *p, integer *n, integer *k, integer *l, doublecomplex *a,
00026 integer *lda, doublecomplex *b, integer *ldb, doublereal *tola,
00027 doublereal *tolb, doublereal *alpha, doublereal *beta, doublecomplex *
00028 u, integer *ldu, doublecomplex *v, integer *ldv, doublecomplex *q,
00029 integer *ldq, doublecomplex *work, integer *ncycle, integer *info)
00030 {
00031
00032 integer a_dim1, a_offset, b_dim1, b_offset, q_dim1, q_offset, u_dim1,
00033 u_offset, v_dim1, v_offset, i__1, i__2, i__3, i__4;
00034 doublereal d__1;
00035 doublecomplex z__1;
00036
00037
00038 void d_cnjg(doublecomplex *, doublecomplex *);
00039
00040
00041 integer i__, j;
00042 doublereal a1, b1, a3, b3;
00043 doublecomplex a2, b2;
00044 doublereal csq, csu, csv;
00045 doublecomplex snq;
00046 doublereal rwk;
00047 doublecomplex snu, snv;
00048 extern int zrot_(integer *, doublecomplex *, integer *,
00049 doublecomplex *, integer *, doublereal *, doublecomplex *);
00050 doublereal gamma;
00051 extern logical lsame_(char *, char *);
00052 logical initq, initu, initv, wantq, upper;
00053 doublereal error, ssmin;
00054 logical wantu, wantv;
00055 extern int zcopy_(integer *, doublecomplex *, integer *,
00056 doublecomplex *, integer *), zlags2_(logical *, doublereal *,
00057 doublecomplex *, doublereal *, doublereal *, doublecomplex *,
00058 doublereal *, doublereal *, doublecomplex *, doublereal *,
00059 doublecomplex *, doublereal *, doublecomplex *);
00060 integer kcycle;
00061 extern int dlartg_(doublereal *, doublereal *,
00062 doublereal *, doublereal *, doublereal *), xerbla_(char *,
00063 integer *), zdscal_(integer *, doublereal *,
00064 doublecomplex *, integer *), zlapll_(integer *, doublecomplex *,
00065 integer *, doublecomplex *, integer *, doublereal *), zlaset_(
00066 char *, integer *, integer *, doublecomplex *, doublecomplex *,
00067 doublecomplex *, integer *);
00068
00069
00070
00071
00072
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
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
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335 a_dim1 = *lda;
00336 a_offset = 1 + a_dim1;
00337 a -= a_offset;
00338 b_dim1 = *ldb;
00339 b_offset = 1 + b_dim1;
00340 b -= b_offset;
00341 --alpha;
00342 --beta;
00343 u_dim1 = *ldu;
00344 u_offset = 1 + u_dim1;
00345 u -= u_offset;
00346 v_dim1 = *ldv;
00347 v_offset = 1 + v_dim1;
00348 v -= v_offset;
00349 q_dim1 = *ldq;
00350 q_offset = 1 + q_dim1;
00351 q -= q_offset;
00352 --work;
00353
00354
00355 initu = lsame_(jobu, "I");
00356 wantu = initu || lsame_(jobu, "U");
00357
00358 initv = lsame_(jobv, "I");
00359 wantv = initv || lsame_(jobv, "V");
00360
00361 initq = lsame_(jobq, "I");
00362 wantq = initq || lsame_(jobq, "Q");
00363
00364 *info = 0;
00365 if (! (initu || wantu || lsame_(jobu, "N"))) {
00366 *info = -1;
00367 } else if (! (initv || wantv || lsame_(jobv, "N")))
00368 {
00369 *info = -2;
00370 } else if (! (initq || wantq || lsame_(jobq, "N")))
00371 {
00372 *info = -3;
00373 } else if (*m < 0) {
00374 *info = -4;
00375 } else if (*p < 0) {
00376 *info = -5;
00377 } else if (*n < 0) {
00378 *info = -6;
00379 } else if (*lda < max(1,*m)) {
00380 *info = -10;
00381 } else if (*ldb < max(1,*p)) {
00382 *info = -12;
00383 } else if (*ldu < 1 || wantu && *ldu < *m) {
00384 *info = -18;
00385 } else if (*ldv < 1 || wantv && *ldv < *p) {
00386 *info = -20;
00387 } else if (*ldq < 1 || wantq && *ldq < *n) {
00388 *info = -22;
00389 }
00390 if (*info != 0) {
00391 i__1 = -(*info);
00392 xerbla_("ZTGSJA", &i__1);
00393 return 0;
00394 }
00395
00396
00397
00398 if (initu) {
00399 zlaset_("Full", m, m, &c_b1, &c_b2, &u[u_offset], ldu);
00400 }
00401 if (initv) {
00402 zlaset_("Full", p, p, &c_b1, &c_b2, &v[v_offset], ldv);
00403 }
00404 if (initq) {
00405 zlaset_("Full", n, n, &c_b1, &c_b2, &q[q_offset], ldq);
00406 }
00407
00408
00409
00410 upper = FALSE_;
00411 for (kcycle = 1; kcycle <= 40; ++kcycle) {
00412
00413 upper = ! upper;
00414
00415 i__1 = *l - 1;
00416 for (i__ = 1; i__ <= i__1; ++i__) {
00417 i__2 = *l;
00418 for (j = i__ + 1; j <= i__2; ++j) {
00419
00420 a1 = 0.;
00421 a2.r = 0., a2.i = 0.;
00422 a3 = 0.;
00423 if (*k + i__ <= *m) {
00424 i__3 = *k + i__ + (*n - *l + i__) * a_dim1;
00425 a1 = a[i__3].r;
00426 }
00427 if (*k + j <= *m) {
00428 i__3 = *k + j + (*n - *l + j) * a_dim1;
00429 a3 = a[i__3].r;
00430 }
00431
00432 i__3 = i__ + (*n - *l + i__) * b_dim1;
00433 b1 = b[i__3].r;
00434 i__3 = j + (*n - *l + j) * b_dim1;
00435 b3 = b[i__3].r;
00436
00437 if (upper) {
00438 if (*k + i__ <= *m) {
00439 i__3 = *k + i__ + (*n - *l + j) * a_dim1;
00440 a2.r = a[i__3].r, a2.i = a[i__3].i;
00441 }
00442 i__3 = i__ + (*n - *l + j) * b_dim1;
00443 b2.r = b[i__3].r, b2.i = b[i__3].i;
00444 } else {
00445 if (*k + j <= *m) {
00446 i__3 = *k + j + (*n - *l + i__) * a_dim1;
00447 a2.r = a[i__3].r, a2.i = a[i__3].i;
00448 }
00449 i__3 = j + (*n - *l + i__) * b_dim1;
00450 b2.r = b[i__3].r, b2.i = b[i__3].i;
00451 }
00452
00453 zlags2_(&upper, &a1, &a2, &a3, &b1, &b2, &b3, &csu, &snu, &
00454 csv, &snv, &csq, &snq);
00455
00456
00457
00458 if (*k + j <= *m) {
00459 d_cnjg(&z__1, &snu);
00460 zrot_(l, &a[*k + j + (*n - *l + 1) * a_dim1], lda, &a[*k
00461 + i__ + (*n - *l + 1) * a_dim1], lda, &csu, &z__1)
00462 ;
00463 }
00464
00465
00466
00467 d_cnjg(&z__1, &snv);
00468 zrot_(l, &b[j + (*n - *l + 1) * b_dim1], ldb, &b[i__ + (*n - *
00469 l + 1) * b_dim1], ldb, &csv, &z__1);
00470
00471
00472
00473
00474
00475 i__4 = *k + *l;
00476 i__3 = min(i__4,*m);
00477 zrot_(&i__3, &a[(*n - *l + j) * a_dim1 + 1], &c__1, &a[(*n - *
00478 l + i__) * a_dim1 + 1], &c__1, &csq, &snq);
00479
00480 zrot_(l, &b[(*n - *l + j) * b_dim1 + 1], &c__1, &b[(*n - *l +
00481 i__) * b_dim1 + 1], &c__1, &csq, &snq);
00482
00483 if (upper) {
00484 if (*k + i__ <= *m) {
00485 i__3 = *k + i__ + (*n - *l + j) * a_dim1;
00486 a[i__3].r = 0., a[i__3].i = 0.;
00487 }
00488 i__3 = i__ + (*n - *l + j) * b_dim1;
00489 b[i__3].r = 0., b[i__3].i = 0.;
00490 } else {
00491 if (*k + j <= *m) {
00492 i__3 = *k + j + (*n - *l + i__) * a_dim1;
00493 a[i__3].r = 0., a[i__3].i = 0.;
00494 }
00495 i__3 = j + (*n - *l + i__) * b_dim1;
00496 b[i__3].r = 0., b[i__3].i = 0.;
00497 }
00498
00499
00500
00501 if (*k + i__ <= *m) {
00502 i__3 = *k + i__ + (*n - *l + i__) * a_dim1;
00503 i__4 = *k + i__ + (*n - *l + i__) * a_dim1;
00504 d__1 = a[i__4].r;
00505 a[i__3].r = d__1, a[i__3].i = 0.;
00506 }
00507 if (*k + j <= *m) {
00508 i__3 = *k + j + (*n - *l + j) * a_dim1;
00509 i__4 = *k + j + (*n - *l + j) * a_dim1;
00510 d__1 = a[i__4].r;
00511 a[i__3].r = d__1, a[i__3].i = 0.;
00512 }
00513 i__3 = i__ + (*n - *l + i__) * b_dim1;
00514 i__4 = i__ + (*n - *l + i__) * b_dim1;
00515 d__1 = b[i__4].r;
00516 b[i__3].r = d__1, b[i__3].i = 0.;
00517 i__3 = j + (*n - *l + j) * b_dim1;
00518 i__4 = j + (*n - *l + j) * b_dim1;
00519 d__1 = b[i__4].r;
00520 b[i__3].r = d__1, b[i__3].i = 0.;
00521
00522
00523
00524 if (wantu && *k + j <= *m) {
00525 zrot_(m, &u[(*k + j) * u_dim1 + 1], &c__1, &u[(*k + i__) *
00526 u_dim1 + 1], &c__1, &csu, &snu);
00527 }
00528
00529 if (wantv) {
00530 zrot_(p, &v[j * v_dim1 + 1], &c__1, &v[i__ * v_dim1 + 1],
00531 &c__1, &csv, &snv);
00532 }
00533
00534 if (wantq) {
00535 zrot_(n, &q[(*n - *l + j) * q_dim1 + 1], &c__1, &q[(*n - *
00536 l + i__) * q_dim1 + 1], &c__1, &csq, &snq);
00537 }
00538
00539
00540 }
00541
00542 }
00543
00544 if (! upper) {
00545
00546
00547
00548
00549
00550
00551
00552 error = 0.;
00553
00554 i__2 = *l, i__3 = *m - *k;
00555 i__1 = min(i__2,i__3);
00556 for (i__ = 1; i__ <= i__1; ++i__) {
00557 i__2 = *l - i__ + 1;
00558 zcopy_(&i__2, &a[*k + i__ + (*n - *l + i__) * a_dim1], lda, &
00559 work[1], &c__1);
00560 i__2 = *l - i__ + 1;
00561 zcopy_(&i__2, &b[i__ + (*n - *l + i__) * b_dim1], ldb, &work[*
00562 l + 1], &c__1);
00563 i__2 = *l - i__ + 1;
00564 zlapll_(&i__2, &work[1], &c__1, &work[*l + 1], &c__1, &ssmin);
00565 error = max(error,ssmin);
00566
00567 }
00568
00569 if (abs(error) <= min(*tola,*tolb)) {
00570 goto L50;
00571 }
00572 }
00573
00574
00575
00576
00577 }
00578
00579
00580
00581 *info = 1;
00582 goto L100;
00583
00584 L50:
00585
00586
00587
00588
00589
00590 i__1 = *k;
00591 for (i__ = 1; i__ <= i__1; ++i__) {
00592 alpha[i__] = 1.;
00593 beta[i__] = 0.;
00594
00595 }
00596
00597
00598 i__2 = *l, i__3 = *m - *k;
00599 i__1 = min(i__2,i__3);
00600 for (i__ = 1; i__ <= i__1; ++i__) {
00601
00602 i__2 = *k + i__ + (*n - *l + i__) * a_dim1;
00603 a1 = a[i__2].r;
00604 i__2 = i__ + (*n - *l + i__) * b_dim1;
00605 b1 = b[i__2].r;
00606
00607 if (a1 != 0.) {
00608 gamma = b1 / a1;
00609
00610 if (gamma < 0.) {
00611 i__2 = *l - i__ + 1;
00612 zdscal_(&i__2, &c_b39, &b[i__ + (*n - *l + i__) * b_dim1],
00613 ldb);
00614 if (wantv) {
00615 zdscal_(p, &c_b39, &v[i__ * v_dim1 + 1], &c__1);
00616 }
00617 }
00618
00619 d__1 = abs(gamma);
00620 dlartg_(&d__1, &c_b42, &beta[*k + i__], &alpha[*k + i__], &rwk);
00621
00622 if (alpha[*k + i__] >= beta[*k + i__]) {
00623 i__2 = *l - i__ + 1;
00624 d__1 = 1. / alpha[*k + i__];
00625 zdscal_(&i__2, &d__1, &a[*k + i__ + (*n - *l + i__) * a_dim1],
00626 lda);
00627 } else {
00628 i__2 = *l - i__ + 1;
00629 d__1 = 1. / beta[*k + i__];
00630 zdscal_(&i__2, &d__1, &b[i__ + (*n - *l + i__) * b_dim1], ldb)
00631 ;
00632 i__2 = *l - i__ + 1;
00633 zcopy_(&i__2, &b[i__ + (*n - *l + i__) * b_dim1], ldb, &a[*k
00634 + i__ + (*n - *l + i__) * a_dim1], lda);
00635 }
00636
00637 } else {
00638 alpha[*k + i__] = 0.;
00639 beta[*k + i__] = 1.;
00640 i__2 = *l - i__ + 1;
00641 zcopy_(&i__2, &b[i__ + (*n - *l + i__) * b_dim1], ldb, &a[*k +
00642 i__ + (*n - *l + i__) * a_dim1], lda);
00643 }
00644
00645 }
00646
00647
00648
00649 i__1 = *k + *l;
00650 for (i__ = *m + 1; i__ <= i__1; ++i__) {
00651 alpha[i__] = 0.;
00652 beta[i__] = 1.;
00653
00654 }
00655
00656 if (*k + *l < *n) {
00657 i__1 = *n;
00658 for (i__ = *k + *l + 1; i__ <= i__1; ++i__) {
00659 alpha[i__] = 0.;
00660 beta[i__] = 0.;
00661
00662 }
00663 }
00664
00665 L100:
00666 *ncycle = kcycle;
00667
00668 return 0;
00669
00670
00671
00672 }