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 integer c__2 = 2;
00020 static integer c_n1 = -1;
00021 static integer c__5 = 5;
00022 static integer c__1 = 1;
00023 static complex c_b44 = {-1.f,0.f};
00024 static complex c_b45 = {1.f,0.f};
00025
00026 int ctgsyl_(char *trans, integer *ijob, integer *m, integer *
00027 n, complex *a, integer *lda, complex *b, integer *ldb, complex *c__,
00028 integer *ldc, complex *d__, integer *ldd, complex *e, integer *lde,
00029 complex *f, integer *ldf, real *scale, real *dif, complex *work,
00030 integer *lwork, integer *iwork, integer *info)
00031 {
00032
00033 integer a_dim1, a_offset, b_dim1, b_offset, c_dim1, c_offset, d_dim1,
00034 d_offset, e_dim1, e_offset, f_dim1, f_offset, i__1, i__2, i__3,
00035 i__4;
00036 complex q__1;
00037
00038
00039 double sqrt(doublereal);
00040
00041
00042 integer i__, j, k, p, q, ie, je, mb, nb, is, js, pq;
00043 real dsum;
00044 extern int cscal_(integer *, complex *, complex *,
00045 integer *), cgemm_(char *, char *, integer *, integer *, integer *
00046 , complex *, complex *, integer *, complex *, integer *, complex *
00047 , complex *, integer *);
00048 extern logical lsame_(char *, char *);
00049 integer ifunc, linfo, lwmin;
00050 real scale2;
00051 extern int ctgsy2_(char *, integer *, integer *, integer
00052 *, complex *, integer *, complex *, integer *, complex *, integer
00053 *, complex *, integer *, complex *, integer *, complex *, integer
00054 *, real *, real *, real *, integer *);
00055 real dscale, scaloc;
00056 extern int clacpy_(char *, integer *, integer *, complex
00057 *, integer *, complex *, integer *), claset_(char *,
00058 integer *, integer *, complex *, complex *, complex *, integer *), xerbla_(char *, integer *);
00059 extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
00060 integer *, integer *);
00061 integer iround;
00062 logical notran;
00063 integer isolve;
00064 logical lquery;
00065
00066
00067
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 a_dim1 = *lda;
00267 a_offset = 1 + a_dim1;
00268 a -= a_offset;
00269 b_dim1 = *ldb;
00270 b_offset = 1 + b_dim1;
00271 b -= b_offset;
00272 c_dim1 = *ldc;
00273 c_offset = 1 + c_dim1;
00274 c__ -= c_offset;
00275 d_dim1 = *ldd;
00276 d_offset = 1 + d_dim1;
00277 d__ -= d_offset;
00278 e_dim1 = *lde;
00279 e_offset = 1 + e_dim1;
00280 e -= e_offset;
00281 f_dim1 = *ldf;
00282 f_offset = 1 + f_dim1;
00283 f -= f_offset;
00284 --work;
00285 --iwork;
00286
00287
00288 *info = 0;
00289 notran = lsame_(trans, "N");
00290 lquery = *lwork == -1;
00291
00292 if (! notran && ! lsame_(trans, "C")) {
00293 *info = -1;
00294 } else if (notran) {
00295 if (*ijob < 0 || *ijob > 4) {
00296 *info = -2;
00297 }
00298 }
00299 if (*info == 0) {
00300 if (*m <= 0) {
00301 *info = -3;
00302 } else if (*n <= 0) {
00303 *info = -4;
00304 } else if (*lda < max(1,*m)) {
00305 *info = -6;
00306 } else if (*ldb < max(1,*n)) {
00307 *info = -8;
00308 } else if (*ldc < max(1,*m)) {
00309 *info = -10;
00310 } else if (*ldd < max(1,*m)) {
00311 *info = -12;
00312 } else if (*lde < max(1,*n)) {
00313 *info = -14;
00314 } else if (*ldf < max(1,*m)) {
00315 *info = -16;
00316 }
00317 }
00318
00319 if (*info == 0) {
00320 if (notran) {
00321 if (*ijob == 1 || *ijob == 2) {
00322
00323 i__1 = 1, i__2 = (*m << 1) * *n;
00324 lwmin = max(i__1,i__2);
00325 } else {
00326 lwmin = 1;
00327 }
00328 } else {
00329 lwmin = 1;
00330 }
00331 work[1].r = (real) lwmin, work[1].i = 0.f;
00332
00333 if (*lwork < lwmin && ! lquery) {
00334 *info = -20;
00335 }
00336 }
00337
00338 if (*info != 0) {
00339 i__1 = -(*info);
00340 xerbla_("CTGSYL", &i__1);
00341 return 0;
00342 } else if (lquery) {
00343 return 0;
00344 }
00345
00346
00347
00348 if (*m == 0 || *n == 0) {
00349 *scale = 1.f;
00350 if (notran) {
00351 if (*ijob != 0) {
00352 *dif = 0.f;
00353 }
00354 }
00355 return 0;
00356 }
00357
00358
00359
00360 mb = ilaenv_(&c__2, "CTGSYL", trans, m, n, &c_n1, &c_n1);
00361 nb = ilaenv_(&c__5, "CTGSYL", trans, m, n, &c_n1, &c_n1);
00362
00363 isolve = 1;
00364 ifunc = 0;
00365 if (notran) {
00366 if (*ijob >= 3) {
00367 ifunc = *ijob - 2;
00368 claset_("F", m, n, &c_b1, &c_b1, &c__[c_offset], ldc);
00369 claset_("F", m, n, &c_b1, &c_b1, &f[f_offset], ldf);
00370 } else if (*ijob >= 1 && notran) {
00371 isolve = 2;
00372 }
00373 }
00374
00375 if (mb <= 1 && nb <= 1 || mb >= *m && nb >= *n) {
00376
00377
00378
00379 i__1 = isolve;
00380 for (iround = 1; iround <= i__1; ++iround) {
00381
00382 *scale = 1.f;
00383 dscale = 0.f;
00384 dsum = 1.f;
00385 pq = *m * *n;
00386 ctgsy2_(trans, &ifunc, m, n, &a[a_offset], lda, &b[b_offset], ldb,
00387 &c__[c_offset], ldc, &d__[d_offset], ldd, &e[e_offset],
00388 lde, &f[f_offset], ldf, scale, &dsum, &dscale, info);
00389 if (dscale != 0.f) {
00390 if (*ijob == 1 || *ijob == 3) {
00391 *dif = sqrt((real) ((*m << 1) * *n)) / (dscale * sqrt(
00392 dsum));
00393 } else {
00394 *dif = sqrt((real) pq) / (dscale * sqrt(dsum));
00395 }
00396 }
00397 if (isolve == 2 && iround == 1) {
00398 if (notran) {
00399 ifunc = *ijob;
00400 }
00401 scale2 = *scale;
00402 clacpy_("F", m, n, &c__[c_offset], ldc, &work[1], m);
00403 clacpy_("F", m, n, &f[f_offset], ldf, &work[*m * *n + 1], m);
00404 claset_("F", m, n, &c_b1, &c_b1, &c__[c_offset], ldc);
00405 claset_("F", m, n, &c_b1, &c_b1, &f[f_offset], ldf)
00406 ;
00407 } else if (isolve == 2 && iround == 2) {
00408 clacpy_("F", m, n, &work[1], m, &c__[c_offset], ldc);
00409 clacpy_("F", m, n, &work[*m * *n + 1], m, &f[f_offset], ldf);
00410 *scale = scale2;
00411 }
00412
00413 }
00414
00415 return 0;
00416
00417 }
00418
00419
00420
00421 p = 0;
00422 i__ = 1;
00423 L40:
00424 if (i__ > *m) {
00425 goto L50;
00426 }
00427 ++p;
00428 iwork[p] = i__;
00429 i__ += mb;
00430 if (i__ >= *m) {
00431 goto L50;
00432 }
00433 goto L40;
00434 L50:
00435 iwork[p + 1] = *m + 1;
00436 if (iwork[p] == iwork[p + 1]) {
00437 --p;
00438 }
00439
00440
00441
00442 q = p + 1;
00443 j = 1;
00444 L60:
00445 if (j > *n) {
00446 goto L70;
00447 }
00448
00449 ++q;
00450 iwork[q] = j;
00451 j += nb;
00452 if (j >= *n) {
00453 goto L70;
00454 }
00455 goto L60;
00456
00457 L70:
00458 iwork[q + 1] = *n + 1;
00459 if (iwork[q] == iwork[q + 1]) {
00460 --q;
00461 }
00462
00463 if (notran) {
00464 i__1 = isolve;
00465 for (iround = 1; iround <= i__1; ++iround) {
00466
00467
00468
00469
00470
00471
00472 pq = 0;
00473 *scale = 1.f;
00474 dscale = 0.f;
00475 dsum = 1.f;
00476 i__2 = q;
00477 for (j = p + 2; j <= i__2; ++j) {
00478 js = iwork[j];
00479 je = iwork[j + 1] - 1;
00480 nb = je - js + 1;
00481 for (i__ = p; i__ >= 1; --i__) {
00482 is = iwork[i__];
00483 ie = iwork[i__ + 1] - 1;
00484 mb = ie - is + 1;
00485 ctgsy2_(trans, &ifunc, &mb, &nb, &a[is + is * a_dim1],
00486 lda, &b[js + js * b_dim1], ldb, &c__[is + js *
00487 c_dim1], ldc, &d__[is + is * d_dim1], ldd, &e[js
00488 + js * e_dim1], lde, &f[is + js * f_dim1], ldf, &
00489 scaloc, &dsum, &dscale, &linfo);
00490 if (linfo > 0) {
00491 *info = linfo;
00492 }
00493 pq += mb * nb;
00494 if (scaloc != 1.f) {
00495 i__3 = js - 1;
00496 for (k = 1; k <= i__3; ++k) {
00497 q__1.r = scaloc, q__1.i = 0.f;
00498 cscal_(m, &q__1, &c__[k * c_dim1 + 1], &c__1);
00499 q__1.r = scaloc, q__1.i = 0.f;
00500 cscal_(m, &q__1, &f[k * f_dim1 + 1], &c__1);
00501
00502 }
00503 i__3 = je;
00504 for (k = js; k <= i__3; ++k) {
00505 i__4 = is - 1;
00506 q__1.r = scaloc, q__1.i = 0.f;
00507 cscal_(&i__4, &q__1, &c__[k * c_dim1 + 1], &c__1);
00508 i__4 = is - 1;
00509 q__1.r = scaloc, q__1.i = 0.f;
00510 cscal_(&i__4, &q__1, &f[k * f_dim1 + 1], &c__1);
00511
00512 }
00513 i__3 = je;
00514 for (k = js; k <= i__3; ++k) {
00515 i__4 = *m - ie;
00516 q__1.r = scaloc, q__1.i = 0.f;
00517 cscal_(&i__4, &q__1, &c__[ie + 1 + k * c_dim1], &
00518 c__1);
00519 i__4 = *m - ie;
00520 q__1.r = scaloc, q__1.i = 0.f;
00521 cscal_(&i__4, &q__1, &f[ie + 1 + k * f_dim1], &
00522 c__1);
00523
00524 }
00525 i__3 = *n;
00526 for (k = je + 1; k <= i__3; ++k) {
00527 q__1.r = scaloc, q__1.i = 0.f;
00528 cscal_(m, &q__1, &c__[k * c_dim1 + 1], &c__1);
00529 q__1.r = scaloc, q__1.i = 0.f;
00530 cscal_(m, &q__1, &f[k * f_dim1 + 1], &c__1);
00531
00532 }
00533 *scale *= scaloc;
00534 }
00535
00536
00537
00538 if (i__ > 1) {
00539 i__3 = is - 1;
00540 cgemm_("N", "N", &i__3, &nb, &mb, &c_b44, &a[is *
00541 a_dim1 + 1], lda, &c__[is + js * c_dim1], ldc,
00542 &c_b45, &c__[js * c_dim1 + 1], ldc);
00543 i__3 = is - 1;
00544 cgemm_("N", "N", &i__3, &nb, &mb, &c_b44, &d__[is *
00545 d_dim1 + 1], ldd, &c__[is + js * c_dim1], ldc,
00546 &c_b45, &f[js * f_dim1 + 1], ldf);
00547 }
00548 if (j < q) {
00549 i__3 = *n - je;
00550 cgemm_("N", "N", &mb, &i__3, &nb, &c_b45, &f[is + js *
00551 f_dim1], ldf, &b[js + (je + 1) * b_dim1],
00552 ldb, &c_b45, &c__[is + (je + 1) * c_dim1],
00553 ldc);
00554 i__3 = *n - je;
00555 cgemm_("N", "N", &mb, &i__3, &nb, &c_b45, &f[is + js *
00556 f_dim1], ldf, &e[js + (je + 1) * e_dim1],
00557 lde, &c_b45, &f[is + (je + 1) * f_dim1], ldf);
00558 }
00559
00560 }
00561
00562 }
00563 if (dscale != 0.f) {
00564 if (*ijob == 1 || *ijob == 3) {
00565 *dif = sqrt((real) ((*m << 1) * *n)) / (dscale * sqrt(
00566 dsum));
00567 } else {
00568 *dif = sqrt((real) pq) / (dscale * sqrt(dsum));
00569 }
00570 }
00571 if (isolve == 2 && iround == 1) {
00572 if (notran) {
00573 ifunc = *ijob;
00574 }
00575 scale2 = *scale;
00576 clacpy_("F", m, n, &c__[c_offset], ldc, &work[1], m);
00577 clacpy_("F", m, n, &f[f_offset], ldf, &work[*m * *n + 1], m);
00578 claset_("F", m, n, &c_b1, &c_b1, &c__[c_offset], ldc);
00579 claset_("F", m, n, &c_b1, &c_b1, &f[f_offset], ldf)
00580 ;
00581 } else if (isolve == 2 && iround == 2) {
00582 clacpy_("F", m, n, &work[1], m, &c__[c_offset], ldc);
00583 clacpy_("F", m, n, &work[*m * *n + 1], m, &f[f_offset], ldf);
00584 *scale = scale2;
00585 }
00586
00587 }
00588 } else {
00589
00590
00591
00592
00593
00594
00595 *scale = 1.f;
00596 i__1 = p;
00597 for (i__ = 1; i__ <= i__1; ++i__) {
00598 is = iwork[i__];
00599 ie = iwork[i__ + 1] - 1;
00600 mb = ie - is + 1;
00601 i__2 = p + 2;
00602 for (j = q; j >= i__2; --j) {
00603 js = iwork[j];
00604 je = iwork[j + 1] - 1;
00605 nb = je - js + 1;
00606 ctgsy2_(trans, &ifunc, &mb, &nb, &a[is + is * a_dim1], lda, &
00607 b[js + js * b_dim1], ldb, &c__[is + js * c_dim1], ldc,
00608 &d__[is + is * d_dim1], ldd, &e[js + js * e_dim1],
00609 lde, &f[is + js * f_dim1], ldf, &scaloc, &dsum, &
00610 dscale, &linfo);
00611 if (linfo > 0) {
00612 *info = linfo;
00613 }
00614 if (scaloc != 1.f) {
00615 i__3 = js - 1;
00616 for (k = 1; k <= i__3; ++k) {
00617 q__1.r = scaloc, q__1.i = 0.f;
00618 cscal_(m, &q__1, &c__[k * c_dim1 + 1], &c__1);
00619 q__1.r = scaloc, q__1.i = 0.f;
00620 cscal_(m, &q__1, &f[k * f_dim1 + 1], &c__1);
00621
00622 }
00623 i__3 = je;
00624 for (k = js; k <= i__3; ++k) {
00625 i__4 = is - 1;
00626 q__1.r = scaloc, q__1.i = 0.f;
00627 cscal_(&i__4, &q__1, &c__[k * c_dim1 + 1], &c__1);
00628 i__4 = is - 1;
00629 q__1.r = scaloc, q__1.i = 0.f;
00630 cscal_(&i__4, &q__1, &f[k * f_dim1 + 1], &c__1);
00631
00632 }
00633 i__3 = je;
00634 for (k = js; k <= i__3; ++k) {
00635 i__4 = *m - ie;
00636 q__1.r = scaloc, q__1.i = 0.f;
00637 cscal_(&i__4, &q__1, &c__[ie + 1 + k * c_dim1], &c__1)
00638 ;
00639 i__4 = *m - ie;
00640 q__1.r = scaloc, q__1.i = 0.f;
00641 cscal_(&i__4, &q__1, &f[ie + 1 + k * f_dim1], &c__1);
00642
00643 }
00644 i__3 = *n;
00645 for (k = je + 1; k <= i__3; ++k) {
00646 q__1.r = scaloc, q__1.i = 0.f;
00647 cscal_(m, &q__1, &c__[k * c_dim1 + 1], &c__1);
00648 q__1.r = scaloc, q__1.i = 0.f;
00649 cscal_(m, &q__1, &f[k * f_dim1 + 1], &c__1);
00650
00651 }
00652 *scale *= scaloc;
00653 }
00654
00655
00656
00657 if (j > p + 2) {
00658 i__3 = js - 1;
00659 cgemm_("N", "C", &mb, &i__3, &nb, &c_b45, &c__[is + js *
00660 c_dim1], ldc, &b[js * b_dim1 + 1], ldb, &c_b45, &
00661 f[is + f_dim1], ldf);
00662 i__3 = js - 1;
00663 cgemm_("N", "C", &mb, &i__3, &nb, &c_b45, &f[is + js *
00664 f_dim1], ldf, &e[js * e_dim1 + 1], lde, &c_b45, &
00665 f[is + f_dim1], ldf);
00666 }
00667 if (i__ < p) {
00668 i__3 = *m - ie;
00669 cgemm_("C", "N", &i__3, &nb, &mb, &c_b44, &a[is + (ie + 1)
00670 * a_dim1], lda, &c__[is + js * c_dim1], ldc, &
00671 c_b45, &c__[ie + 1 + js * c_dim1], ldc);
00672 i__3 = *m - ie;
00673 cgemm_("C", "N", &i__3, &nb, &mb, &c_b44, &d__[is + (ie +
00674 1) * d_dim1], ldd, &f[is + js * f_dim1], ldf, &
00675 c_b45, &c__[ie + 1 + js * c_dim1], ldc);
00676 }
00677
00678 }
00679
00680 }
00681 }
00682
00683 work[1].r = (real) lwmin, work[1].i = 0.f;
00684
00685 return 0;
00686
00687
00688
00689 }