dtgsy2.c 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114
  1. /* dtgsy2.f -- translated by f2c (version 20061008).
  2. You must link the resulting object file with libf2c:
  3. on Microsoft Windows system, link with libf2c.lib;
  4. on Linux or Unix systems, link with .../path/to/libf2c.a -lm
  5. or, if you install libf2c.a in a standard place, with -lf2c -lm
  6. -- in that order, at the end of the command line, as in
  7. cc *.o -lf2c -lm
  8. Source for libf2c is in /netlib/f2c/libf2c.zip, e.g.,
  9. http://www.netlib.org/f2c/libf2c.zip
  10. */
  11. #include "f2c.h"
  12. #include "blaswrap.h"
  13. /* Table of constant values */
  14. static integer c__8 = 8;
  15. static integer c__1 = 1;
  16. static doublereal c_b27 = -1.;
  17. static doublereal c_b42 = 1.;
  18. static doublereal c_b56 = 0.;
  19. /* Subroutine */ int dtgsy2_(char *trans, integer *ijob, integer *m, integer *
  20. n, doublereal *a, integer *lda, doublereal *b, integer *ldb,
  21. doublereal *c__, integer *ldc, doublereal *d__, integer *ldd,
  22. doublereal *e, integer *lde, doublereal *f, integer *ldf, doublereal *
  23. scale, doublereal *rdsum, doublereal *rdscal, integer *iwork, integer
  24. *pq, integer *info)
  25. {
  26. /* System generated locals */
  27. integer a_dim1, a_offset, b_dim1, b_offset, c_dim1, c_offset, d_dim1,
  28. d_offset, e_dim1, e_offset, f_dim1, f_offset, i__1, i__2, i__3;
  29. /* Local variables */
  30. integer i__, j, k, p, q;
  31. doublereal z__[64] /* was [8][8] */;
  32. integer ie, je, mb, nb, ii, jj, is, js;
  33. doublereal rhs[8];
  34. integer isp1, jsp1;
  35. extern /* Subroutine */ int dger_(integer *, integer *, doublereal *,
  36. doublereal *, integer *, doublereal *, integer *, doublereal *,
  37. integer *);
  38. integer ierr, zdim, ipiv[8], jpiv[8];
  39. doublereal alpha;
  40. extern /* Subroutine */ int dscal_(integer *, doublereal *, doublereal *,
  41. integer *), dgemm_(char *, char *, integer *, integer *, integer *
  42. , doublereal *, doublereal *, integer *, doublereal *, integer *,
  43. doublereal *, doublereal *, integer *);
  44. extern logical lsame_(char *, char *);
  45. extern /* Subroutine */ int dgemv_(char *, integer *, integer *,
  46. doublereal *, doublereal *, integer *, doublereal *, integer *,
  47. doublereal *, doublereal *, integer *), dcopy_(integer *,
  48. doublereal *, integer *, doublereal *, integer *), daxpy_(integer
  49. *, doublereal *, doublereal *, integer *, doublereal *, integer *)
  50. , dgesc2_(integer *, doublereal *, integer *, doublereal *,
  51. integer *, integer *, doublereal *), dgetc2_(integer *,
  52. doublereal *, integer *, integer *, integer *, integer *),
  53. dlatdf_(integer *, integer *, doublereal *, integer *, doublereal
  54. *, doublereal *, doublereal *, integer *, integer *);
  55. doublereal scaloc;
  56. extern /* Subroutine */ int dlaset_(char *, integer *, integer *,
  57. doublereal *, doublereal *, doublereal *, integer *),
  58. xerbla_(char *, integer *);
  59. logical notran;
  60. /* -- LAPACK auxiliary routine (version 3.2) -- */
  61. /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
  62. /* January 2007 */
  63. /* .. Scalar Arguments .. */
  64. /* .. */
  65. /* .. Array Arguments .. */
  66. /* .. */
  67. /* Purpose */
  68. /* ======= */
  69. /* DTGSY2 solves the generalized Sylvester equation: */
  70. /* A * R - L * B = scale * C (1) */
  71. /* D * R - L * E = scale * F, */
  72. /* using Level 1 and 2 BLAS. where R and L are unknown M-by-N matrices, */
  73. /* (A, D), (B, E) and (C, F) are given matrix pairs of size M-by-M, */
  74. /* N-by-N and M-by-N, respectively, with real entries. (A, D) and (B, E) */
  75. /* must be in generalized Schur canonical form, i.e. A, B are upper */
  76. /* quasi triangular and D, E are upper triangular. The solution (R, L) */
  77. /* overwrites (C, F). 0 <= SCALE <= 1 is an output scaling factor */
  78. /* chosen to avoid overflow. */
  79. /* In matrix notation solving equation (1) corresponds to solve */
  80. /* Z*x = scale*b, where Z is defined as */
  81. /* Z = [ kron(In, A) -kron(B', Im) ] (2) */
  82. /* [ kron(In, D) -kron(E', Im) ], */
  83. /* Ik is the identity matrix of size k and X' is the transpose of X. */
  84. /* kron(X, Y) is the Kronecker product between the matrices X and Y. */
  85. /* In the process of solving (1), we solve a number of such systems */
  86. /* where Dim(In), Dim(In) = 1 or 2. */
  87. /* If TRANS = 'T', solve the transposed system Z'*y = scale*b for y, */
  88. /* which is equivalent to solve for R and L in */
  89. /* A' * R + D' * L = scale * C (3) */
  90. /* R * B' + L * E' = scale * -F */
  91. /* This case is used to compute an estimate of Dif[(A, D), (B, E)] = */
  92. /* sigma_min(Z) using reverse communicaton with DLACON. */
  93. /* DTGSY2 also (IJOB >= 1) contributes to the computation in DTGSYL */
  94. /* of an upper bound on the separation between to matrix pairs. Then */
  95. /* the input (A, D), (B, E) are sub-pencils of the matrix pair in */
  96. /* DTGSYL. See DTGSYL for details. */
  97. /* Arguments */
  98. /* ========= */
  99. /* TRANS (input) CHARACTER*1 */
  100. /* = 'N', solve the generalized Sylvester equation (1). */
  101. /* = 'T': solve the 'transposed' system (3). */
  102. /* IJOB (input) INTEGER */
  103. /* Specifies what kind of functionality to be performed. */
  104. /* = 0: solve (1) only. */
  105. /* = 1: A contribution from this subsystem to a Frobenius */
  106. /* norm-based estimate of the separation between two matrix */
  107. /* pairs is computed. (look ahead strategy is used). */
  108. /* = 2: A contribution from this subsystem to a Frobenius */
  109. /* norm-based estimate of the separation between two matrix */
  110. /* pairs is computed. (DGECON on sub-systems is used.) */
  111. /* Not referenced if TRANS = 'T'. */
  112. /* M (input) INTEGER */
  113. /* On entry, M specifies the order of A and D, and the row */
  114. /* dimension of C, F, R and L. */
  115. /* N (input) INTEGER */
  116. /* On entry, N specifies the order of B and E, and the column */
  117. /* dimension of C, F, R and L. */
  118. /* A (input) DOUBLE PRECISION array, dimension (LDA, M) */
  119. /* On entry, A contains an upper quasi triangular matrix. */
  120. /* LDA (input) INTEGER */
  121. /* The leading dimension of the matrix A. LDA >= max(1, M). */
  122. /* B (input) DOUBLE PRECISION array, dimension (LDB, N) */
  123. /* On entry, B contains an upper quasi triangular matrix. */
  124. /* LDB (input) INTEGER */
  125. /* The leading dimension of the matrix B. LDB >= max(1, N). */
  126. /* C (input/output) DOUBLE PRECISION array, dimension (LDC, N) */
  127. /* On entry, C contains the right-hand-side of the first matrix */
  128. /* equation in (1). */
  129. /* On exit, if IJOB = 0, C has been overwritten by the */
  130. /* solution R. */
  131. /* LDC (input) INTEGER */
  132. /* The leading dimension of the matrix C. LDC >= max(1, M). */
  133. /* D (input) DOUBLE PRECISION array, dimension (LDD, M) */
  134. /* On entry, D contains an upper triangular matrix. */
  135. /* LDD (input) INTEGER */
  136. /* The leading dimension of the matrix D. LDD >= max(1, M). */
  137. /* E (input) DOUBLE PRECISION array, dimension (LDE, N) */
  138. /* On entry, E contains an upper triangular matrix. */
  139. /* LDE (input) INTEGER */
  140. /* The leading dimension of the matrix E. LDE >= max(1, N). */
  141. /* F (input/output) DOUBLE PRECISION array, dimension (LDF, N) */
  142. /* On entry, F contains the right-hand-side of the second matrix */
  143. /* equation in (1). */
  144. /* On exit, if IJOB = 0, F has been overwritten by the */
  145. /* solution L. */
  146. /* LDF (input) INTEGER */
  147. /* The leading dimension of the matrix F. LDF >= max(1, M). */
  148. /* SCALE (output) DOUBLE PRECISION */
  149. /* On exit, 0 <= SCALE <= 1. If 0 < SCALE < 1, the solutions */
  150. /* R and L (C and F on entry) will hold the solutions to a */
  151. /* slightly perturbed system but the input matrices A, B, D and */
  152. /* E have not been changed. If SCALE = 0, R and L will hold the */
  153. /* solutions to the homogeneous system with C = F = 0. Normally, */
  154. /* SCALE = 1. */
  155. /* RDSUM (input/output) DOUBLE PRECISION */
  156. /* On entry, the sum of squares of computed contributions to */
  157. /* the Dif-estimate under computation by DTGSYL, where the */
  158. /* scaling factor RDSCAL (see below) has been factored out. */
  159. /* On exit, the corresponding sum of squares updated with the */
  160. /* contributions from the current sub-system. */
  161. /* If TRANS = 'T' RDSUM is not touched. */
  162. /* NOTE: RDSUM only makes sense when DTGSY2 is called by DTGSYL. */
  163. /* RDSCAL (input/output) DOUBLE PRECISION */
  164. /* On entry, scaling factor used to prevent overflow in RDSUM. */
  165. /* On exit, RDSCAL is updated w.r.t. the current contributions */
  166. /* in RDSUM. */
  167. /* If TRANS = 'T', RDSCAL is not touched. */
  168. /* NOTE: RDSCAL only makes sense when DTGSY2 is called by */
  169. /* DTGSYL. */
  170. /* IWORK (workspace) INTEGER array, dimension (M+N+2) */
  171. /* PQ (output) INTEGER */
  172. /* On exit, the number of subsystems (of size 2-by-2, 4-by-4 and */
  173. /* 8-by-8) solved by this routine. */
  174. /* INFO (output) INTEGER */
  175. /* On exit, if INFO is set to */
  176. /* =0: Successful exit */
  177. /* <0: If INFO = -i, the i-th argument had an illegal value. */
  178. /* >0: The matrix pairs (A, D) and (B, E) have common or very */
  179. /* close eigenvalues. */
  180. /* Further Details */
  181. /* =============== */
  182. /* Based on contributions by */
  183. /* Bo Kagstrom and Peter Poromaa, Department of Computing Science, */
  184. /* Umea University, S-901 87 Umea, Sweden. */
  185. /* ===================================================================== */
  186. /* Replaced various illegal calls to DCOPY by calls to DLASET. */
  187. /* Sven Hammarling, 27/5/02. */
  188. /* .. Parameters .. */
  189. /* .. */
  190. /* .. Local Scalars .. */
  191. /* .. */
  192. /* .. Local Arrays .. */
  193. /* .. */
  194. /* .. External Functions .. */
  195. /* .. */
  196. /* .. External Subroutines .. */
  197. /* .. */
  198. /* .. Intrinsic Functions .. */
  199. /* .. */
  200. /* .. Executable Statements .. */
  201. /* Decode and test input parameters */
  202. /* Parameter adjustments */
  203. a_dim1 = *lda;
  204. a_offset = 1 + a_dim1;
  205. a -= a_offset;
  206. b_dim1 = *ldb;
  207. b_offset = 1 + b_dim1;
  208. b -= b_offset;
  209. c_dim1 = *ldc;
  210. c_offset = 1 + c_dim1;
  211. c__ -= c_offset;
  212. d_dim1 = *ldd;
  213. d_offset = 1 + d_dim1;
  214. d__ -= d_offset;
  215. e_dim1 = *lde;
  216. e_offset = 1 + e_dim1;
  217. e -= e_offset;
  218. f_dim1 = *ldf;
  219. f_offset = 1 + f_dim1;
  220. f -= f_offset;
  221. --iwork;
  222. /* Function Body */
  223. *info = 0;
  224. ierr = 0;
  225. notran = lsame_(trans, "N");
  226. if (! notran && ! lsame_(trans, "T")) {
  227. *info = -1;
  228. } else if (notran) {
  229. if (*ijob < 0 || *ijob > 2) {
  230. *info = -2;
  231. }
  232. }
  233. if (*info == 0) {
  234. if (*m <= 0) {
  235. *info = -3;
  236. } else if (*n <= 0) {
  237. *info = -4;
  238. } else if (*lda < max(1,*m)) {
  239. *info = -5;
  240. } else if (*ldb < max(1,*n)) {
  241. *info = -8;
  242. } else if (*ldc < max(1,*m)) {
  243. *info = -10;
  244. } else if (*ldd < max(1,*m)) {
  245. *info = -12;
  246. } else if (*lde < max(1,*n)) {
  247. *info = -14;
  248. } else if (*ldf < max(1,*m)) {
  249. *info = -16;
  250. }
  251. }
  252. if (*info != 0) {
  253. i__1 = -(*info);
  254. xerbla_("DTGSY2", &i__1);
  255. return 0;
  256. }
  257. /* Determine block structure of A */
  258. *pq = 0;
  259. p = 0;
  260. i__ = 1;
  261. L10:
  262. if (i__ > *m) {
  263. goto L20;
  264. }
  265. ++p;
  266. iwork[p] = i__;
  267. if (i__ == *m) {
  268. goto L20;
  269. }
  270. if (a[i__ + 1 + i__ * a_dim1] != 0.) {
  271. i__ += 2;
  272. } else {
  273. ++i__;
  274. }
  275. goto L10;
  276. L20:
  277. iwork[p + 1] = *m + 1;
  278. /* Determine block structure of B */
  279. q = p + 1;
  280. j = 1;
  281. L30:
  282. if (j > *n) {
  283. goto L40;
  284. }
  285. ++q;
  286. iwork[q] = j;
  287. if (j == *n) {
  288. goto L40;
  289. }
  290. if (b[j + 1 + j * b_dim1] != 0.) {
  291. j += 2;
  292. } else {
  293. ++j;
  294. }
  295. goto L30;
  296. L40:
  297. iwork[q + 1] = *n + 1;
  298. *pq = p * (q - p - 1);
  299. if (notran) {
  300. /* Solve (I, J) - subsystem */
  301. /* A(I, I) * R(I, J) - L(I, J) * B(J, J) = C(I, J) */
  302. /* D(I, I) * R(I, J) - L(I, J) * E(J, J) = F(I, J) */
  303. /* for I = P, P - 1, ..., 1; J = 1, 2, ..., Q */
  304. *scale = 1.;
  305. scaloc = 1.;
  306. i__1 = q;
  307. for (j = p + 2; j <= i__1; ++j) {
  308. js = iwork[j];
  309. jsp1 = js + 1;
  310. je = iwork[j + 1] - 1;
  311. nb = je - js + 1;
  312. for (i__ = p; i__ >= 1; --i__) {
  313. is = iwork[i__];
  314. isp1 = is + 1;
  315. ie = iwork[i__ + 1] - 1;
  316. mb = ie - is + 1;
  317. zdim = mb * nb << 1;
  318. if (mb == 1 && nb == 1) {
  319. /* Build a 2-by-2 system Z * x = RHS */
  320. z__[0] = a[is + is * a_dim1];
  321. z__[1] = d__[is + is * d_dim1];
  322. z__[8] = -b[js + js * b_dim1];
  323. z__[9] = -e[js + js * e_dim1];
  324. /* Set up right hand side(s) */
  325. rhs[0] = c__[is + js * c_dim1];
  326. rhs[1] = f[is + js * f_dim1];
  327. /* Solve Z * x = RHS */
  328. dgetc2_(&zdim, z__, &c__8, ipiv, jpiv, &ierr);
  329. if (ierr > 0) {
  330. *info = ierr;
  331. }
  332. if (*ijob == 0) {
  333. dgesc2_(&zdim, z__, &c__8, rhs, ipiv, jpiv, &scaloc);
  334. if (scaloc != 1.) {
  335. i__2 = *n;
  336. for (k = 1; k <= i__2; ++k) {
  337. dscal_(m, &scaloc, &c__[k * c_dim1 + 1], &
  338. c__1);
  339. dscal_(m, &scaloc, &f[k * f_dim1 + 1], &c__1);
  340. /* L50: */
  341. }
  342. *scale *= scaloc;
  343. }
  344. } else {
  345. dlatdf_(ijob, &zdim, z__, &c__8, rhs, rdsum, rdscal,
  346. ipiv, jpiv);
  347. }
  348. /* Unpack solution vector(s) */
  349. c__[is + js * c_dim1] = rhs[0];
  350. f[is + js * f_dim1] = rhs[1];
  351. /* Substitute R(I, J) and L(I, J) into remaining */
  352. /* equation. */
  353. if (i__ > 1) {
  354. alpha = -rhs[0];
  355. i__2 = is - 1;
  356. daxpy_(&i__2, &alpha, &a[is * a_dim1 + 1], &c__1, &
  357. c__[js * c_dim1 + 1], &c__1);
  358. i__2 = is - 1;
  359. daxpy_(&i__2, &alpha, &d__[is * d_dim1 + 1], &c__1, &
  360. f[js * f_dim1 + 1], &c__1);
  361. }
  362. if (j < q) {
  363. i__2 = *n - je;
  364. daxpy_(&i__2, &rhs[1], &b[js + (je + 1) * b_dim1],
  365. ldb, &c__[is + (je + 1) * c_dim1], ldc);
  366. i__2 = *n - je;
  367. daxpy_(&i__2, &rhs[1], &e[js + (je + 1) * e_dim1],
  368. lde, &f[is + (je + 1) * f_dim1], ldf);
  369. }
  370. } else if (mb == 1 && nb == 2) {
  371. /* Build a 4-by-4 system Z * x = RHS */
  372. z__[0] = a[is + is * a_dim1];
  373. z__[1] = 0.;
  374. z__[2] = d__[is + is * d_dim1];
  375. z__[3] = 0.;
  376. z__[8] = 0.;
  377. z__[9] = a[is + is * a_dim1];
  378. z__[10] = 0.;
  379. z__[11] = d__[is + is * d_dim1];
  380. z__[16] = -b[js + js * b_dim1];
  381. z__[17] = -b[js + jsp1 * b_dim1];
  382. z__[18] = -e[js + js * e_dim1];
  383. z__[19] = -e[js + jsp1 * e_dim1];
  384. z__[24] = -b[jsp1 + js * b_dim1];
  385. z__[25] = -b[jsp1 + jsp1 * b_dim1];
  386. z__[26] = 0.;
  387. z__[27] = -e[jsp1 + jsp1 * e_dim1];
  388. /* Set up right hand side(s) */
  389. rhs[0] = c__[is + js * c_dim1];
  390. rhs[1] = c__[is + jsp1 * c_dim1];
  391. rhs[2] = f[is + js * f_dim1];
  392. rhs[3] = f[is + jsp1 * f_dim1];
  393. /* Solve Z * x = RHS */
  394. dgetc2_(&zdim, z__, &c__8, ipiv, jpiv, &ierr);
  395. if (ierr > 0) {
  396. *info = ierr;
  397. }
  398. if (*ijob == 0) {
  399. dgesc2_(&zdim, z__, &c__8, rhs, ipiv, jpiv, &scaloc);
  400. if (scaloc != 1.) {
  401. i__2 = *n;
  402. for (k = 1; k <= i__2; ++k) {
  403. dscal_(m, &scaloc, &c__[k * c_dim1 + 1], &
  404. c__1);
  405. dscal_(m, &scaloc, &f[k * f_dim1 + 1], &c__1);
  406. /* L60: */
  407. }
  408. *scale *= scaloc;
  409. }
  410. } else {
  411. dlatdf_(ijob, &zdim, z__, &c__8, rhs, rdsum, rdscal,
  412. ipiv, jpiv);
  413. }
  414. /* Unpack solution vector(s) */
  415. c__[is + js * c_dim1] = rhs[0];
  416. c__[is + jsp1 * c_dim1] = rhs[1];
  417. f[is + js * f_dim1] = rhs[2];
  418. f[is + jsp1 * f_dim1] = rhs[3];
  419. /* Substitute R(I, J) and L(I, J) into remaining */
  420. /* equation. */
  421. if (i__ > 1) {
  422. i__2 = is - 1;
  423. dger_(&i__2, &nb, &c_b27, &a[is * a_dim1 + 1], &c__1,
  424. rhs, &c__1, &c__[js * c_dim1 + 1], ldc);
  425. i__2 = is - 1;
  426. dger_(&i__2, &nb, &c_b27, &d__[is * d_dim1 + 1], &
  427. c__1, rhs, &c__1, &f[js * f_dim1 + 1], ldf);
  428. }
  429. if (j < q) {
  430. i__2 = *n - je;
  431. daxpy_(&i__2, &rhs[2], &b[js + (je + 1) * b_dim1],
  432. ldb, &c__[is + (je + 1) * c_dim1], ldc);
  433. i__2 = *n - je;
  434. daxpy_(&i__2, &rhs[2], &e[js + (je + 1) * e_dim1],
  435. lde, &f[is + (je + 1) * f_dim1], ldf);
  436. i__2 = *n - je;
  437. daxpy_(&i__2, &rhs[3], &b[jsp1 + (je + 1) * b_dim1],
  438. ldb, &c__[is + (je + 1) * c_dim1], ldc);
  439. i__2 = *n - je;
  440. daxpy_(&i__2, &rhs[3], &e[jsp1 + (je + 1) * e_dim1],
  441. lde, &f[is + (je + 1) * f_dim1], ldf);
  442. }
  443. } else if (mb == 2 && nb == 1) {
  444. /* Build a 4-by-4 system Z * x = RHS */
  445. z__[0] = a[is + is * a_dim1];
  446. z__[1] = a[isp1 + is * a_dim1];
  447. z__[2] = d__[is + is * d_dim1];
  448. z__[3] = 0.;
  449. z__[8] = a[is + isp1 * a_dim1];
  450. z__[9] = a[isp1 + isp1 * a_dim1];
  451. z__[10] = d__[is + isp1 * d_dim1];
  452. z__[11] = d__[isp1 + isp1 * d_dim1];
  453. z__[16] = -b[js + js * b_dim1];
  454. z__[17] = 0.;
  455. z__[18] = -e[js + js * e_dim1];
  456. z__[19] = 0.;
  457. z__[24] = 0.;
  458. z__[25] = -b[js + js * b_dim1];
  459. z__[26] = 0.;
  460. z__[27] = -e[js + js * e_dim1];
  461. /* Set up right hand side(s) */
  462. rhs[0] = c__[is + js * c_dim1];
  463. rhs[1] = c__[isp1 + js * c_dim1];
  464. rhs[2] = f[is + js * f_dim1];
  465. rhs[3] = f[isp1 + js * f_dim1];
  466. /* Solve Z * x = RHS */
  467. dgetc2_(&zdim, z__, &c__8, ipiv, jpiv, &ierr);
  468. if (ierr > 0) {
  469. *info = ierr;
  470. }
  471. if (*ijob == 0) {
  472. dgesc2_(&zdim, z__, &c__8, rhs, ipiv, jpiv, &scaloc);
  473. if (scaloc != 1.) {
  474. i__2 = *n;
  475. for (k = 1; k <= i__2; ++k) {
  476. dscal_(m, &scaloc, &c__[k * c_dim1 + 1], &
  477. c__1);
  478. dscal_(m, &scaloc, &f[k * f_dim1 + 1], &c__1);
  479. /* L70: */
  480. }
  481. *scale *= scaloc;
  482. }
  483. } else {
  484. dlatdf_(ijob, &zdim, z__, &c__8, rhs, rdsum, rdscal,
  485. ipiv, jpiv);
  486. }
  487. /* Unpack solution vector(s) */
  488. c__[is + js * c_dim1] = rhs[0];
  489. c__[isp1 + js * c_dim1] = rhs[1];
  490. f[is + js * f_dim1] = rhs[2];
  491. f[isp1 + js * f_dim1] = rhs[3];
  492. /* Substitute R(I, J) and L(I, J) into remaining */
  493. /* equation. */
  494. if (i__ > 1) {
  495. i__2 = is - 1;
  496. dgemv_("N", &i__2, &mb, &c_b27, &a[is * a_dim1 + 1],
  497. lda, rhs, &c__1, &c_b42, &c__[js * c_dim1 + 1]
  498. , &c__1);
  499. i__2 = is - 1;
  500. dgemv_("N", &i__2, &mb, &c_b27, &d__[is * d_dim1 + 1],
  501. ldd, rhs, &c__1, &c_b42, &f[js * f_dim1 + 1],
  502. &c__1);
  503. }
  504. if (j < q) {
  505. i__2 = *n - je;
  506. dger_(&mb, &i__2, &c_b42, &rhs[2], &c__1, &b[js + (je
  507. + 1) * b_dim1], ldb, &c__[is + (je + 1) *
  508. c_dim1], ldc);
  509. i__2 = *n - je;
  510. dger_(&mb, &i__2, &c_b42, &rhs[2], &c__1, &e[js + (je
  511. + 1) * e_dim1], lde, &f[is + (je + 1) *
  512. f_dim1], ldf);
  513. }
  514. } else if (mb == 2 && nb == 2) {
  515. /* Build an 8-by-8 system Z * x = RHS */
  516. dlaset_("F", &c__8, &c__8, &c_b56, &c_b56, z__, &c__8);
  517. z__[0] = a[is + is * a_dim1];
  518. z__[1] = a[isp1 + is * a_dim1];
  519. z__[4] = d__[is + is * d_dim1];
  520. z__[8] = a[is + isp1 * a_dim1];
  521. z__[9] = a[isp1 + isp1 * a_dim1];
  522. z__[12] = d__[is + isp1 * d_dim1];
  523. z__[13] = d__[isp1 + isp1 * d_dim1];
  524. z__[18] = a[is + is * a_dim1];
  525. z__[19] = a[isp1 + is * a_dim1];
  526. z__[22] = d__[is + is * d_dim1];
  527. z__[26] = a[is + isp1 * a_dim1];
  528. z__[27] = a[isp1 + isp1 * a_dim1];
  529. z__[30] = d__[is + isp1 * d_dim1];
  530. z__[31] = d__[isp1 + isp1 * d_dim1];
  531. z__[32] = -b[js + js * b_dim1];
  532. z__[34] = -b[js + jsp1 * b_dim1];
  533. z__[36] = -e[js + js * e_dim1];
  534. z__[38] = -e[js + jsp1 * e_dim1];
  535. z__[41] = -b[js + js * b_dim1];
  536. z__[43] = -b[js + jsp1 * b_dim1];
  537. z__[45] = -e[js + js * e_dim1];
  538. z__[47] = -e[js + jsp1 * e_dim1];
  539. z__[48] = -b[jsp1 + js * b_dim1];
  540. z__[50] = -b[jsp1 + jsp1 * b_dim1];
  541. z__[54] = -e[jsp1 + jsp1 * e_dim1];
  542. z__[57] = -b[jsp1 + js * b_dim1];
  543. z__[59] = -b[jsp1 + jsp1 * b_dim1];
  544. z__[63] = -e[jsp1 + jsp1 * e_dim1];
  545. /* Set up right hand side(s) */
  546. k = 1;
  547. ii = mb * nb + 1;
  548. i__2 = nb - 1;
  549. for (jj = 0; jj <= i__2; ++jj) {
  550. dcopy_(&mb, &c__[is + (js + jj) * c_dim1], &c__1, &
  551. rhs[k - 1], &c__1);
  552. dcopy_(&mb, &f[is + (js + jj) * f_dim1], &c__1, &rhs[
  553. ii - 1], &c__1);
  554. k += mb;
  555. ii += mb;
  556. /* L80: */
  557. }
  558. /* Solve Z * x = RHS */
  559. dgetc2_(&zdim, z__, &c__8, ipiv, jpiv, &ierr);
  560. if (ierr > 0) {
  561. *info = ierr;
  562. }
  563. if (*ijob == 0) {
  564. dgesc2_(&zdim, z__, &c__8, rhs, ipiv, jpiv, &scaloc);
  565. if (scaloc != 1.) {
  566. i__2 = *n;
  567. for (k = 1; k <= i__2; ++k) {
  568. dscal_(m, &scaloc, &c__[k * c_dim1 + 1], &
  569. c__1);
  570. dscal_(m, &scaloc, &f[k * f_dim1 + 1], &c__1);
  571. /* L90: */
  572. }
  573. *scale *= scaloc;
  574. }
  575. } else {
  576. dlatdf_(ijob, &zdim, z__, &c__8, rhs, rdsum, rdscal,
  577. ipiv, jpiv);
  578. }
  579. /* Unpack solution vector(s) */
  580. k = 1;
  581. ii = mb * nb + 1;
  582. i__2 = nb - 1;
  583. for (jj = 0; jj <= i__2; ++jj) {
  584. dcopy_(&mb, &rhs[k - 1], &c__1, &c__[is + (js + jj) *
  585. c_dim1], &c__1);
  586. dcopy_(&mb, &rhs[ii - 1], &c__1, &f[is + (js + jj) *
  587. f_dim1], &c__1);
  588. k += mb;
  589. ii += mb;
  590. /* L100: */
  591. }
  592. /* Substitute R(I, J) and L(I, J) into remaining */
  593. /* equation. */
  594. if (i__ > 1) {
  595. i__2 = is - 1;
  596. dgemm_("N", "N", &i__2, &nb, &mb, &c_b27, &a[is *
  597. a_dim1 + 1], lda, rhs, &mb, &c_b42, &c__[js *
  598. c_dim1 + 1], ldc);
  599. i__2 = is - 1;
  600. dgemm_("N", "N", &i__2, &nb, &mb, &c_b27, &d__[is *
  601. d_dim1 + 1], ldd, rhs, &mb, &c_b42, &f[js *
  602. f_dim1 + 1], ldf);
  603. }
  604. if (j < q) {
  605. k = mb * nb + 1;
  606. i__2 = *n - je;
  607. dgemm_("N", "N", &mb, &i__2, &nb, &c_b42, &rhs[k - 1],
  608. &mb, &b[js + (je + 1) * b_dim1], ldb, &c_b42,
  609. &c__[is + (je + 1) * c_dim1], ldc);
  610. i__2 = *n - je;
  611. dgemm_("N", "N", &mb, &i__2, &nb, &c_b42, &rhs[k - 1],
  612. &mb, &e[js + (je + 1) * e_dim1], lde, &c_b42,
  613. &f[is + (je + 1) * f_dim1], ldf);
  614. }
  615. }
  616. /* L110: */
  617. }
  618. /* L120: */
  619. }
  620. } else {
  621. /* Solve (I, J) - subsystem */
  622. /* A(I, I)' * R(I, J) + D(I, I)' * L(J, J) = C(I, J) */
  623. /* R(I, I) * B(J, J) + L(I, J) * E(J, J) = -F(I, J) */
  624. /* for I = 1, 2, ..., P, J = Q, Q - 1, ..., 1 */
  625. *scale = 1.;
  626. scaloc = 1.;
  627. i__1 = p;
  628. for (i__ = 1; i__ <= i__1; ++i__) {
  629. is = iwork[i__];
  630. isp1 = is + 1;
  631. ie = i__;
  632. mb = ie - is + 1;
  633. i__2 = p + 2;
  634. for (j = q; j >= i__2; --j) {
  635. js = iwork[j];
  636. jsp1 = js + 1;
  637. je = iwork[j + 1] - 1;
  638. nb = je - js + 1;
  639. zdim = mb * nb << 1;
  640. if (mb == 1 && nb == 1) {
  641. /* Build a 2-by-2 system Z' * x = RHS */
  642. z__[0] = a[is + is * a_dim1];
  643. z__[1] = -b[js + js * b_dim1];
  644. z__[8] = d__[is + is * d_dim1];
  645. z__[9] = -e[js + js * e_dim1];
  646. /* Set up right hand side(s) */
  647. rhs[0] = c__[is + js * c_dim1];
  648. rhs[1] = f[is + js * f_dim1];
  649. /* Solve Z' * x = RHS */
  650. dgetc2_(&zdim, z__, &c__8, ipiv, jpiv, &ierr);
  651. if (ierr > 0) {
  652. *info = ierr;
  653. }
  654. dgesc2_(&zdim, z__, &c__8, rhs, ipiv, jpiv, &scaloc);
  655. if (scaloc != 1.) {
  656. i__3 = *n;
  657. for (k = 1; k <= i__3; ++k) {
  658. dscal_(m, &scaloc, &c__[k * c_dim1 + 1], &c__1);
  659. dscal_(m, &scaloc, &f[k * f_dim1 + 1], &c__1);
  660. /* L130: */
  661. }
  662. *scale *= scaloc;
  663. }
  664. /* Unpack solution vector(s) */
  665. c__[is + js * c_dim1] = rhs[0];
  666. f[is + js * f_dim1] = rhs[1];
  667. /* Substitute R(I, J) and L(I, J) into remaining */
  668. /* equation. */
  669. if (j > p + 2) {
  670. alpha = rhs[0];
  671. i__3 = js - 1;
  672. daxpy_(&i__3, &alpha, &b[js * b_dim1 + 1], &c__1, &f[
  673. is + f_dim1], ldf);
  674. alpha = rhs[1];
  675. i__3 = js - 1;
  676. daxpy_(&i__3, &alpha, &e[js * e_dim1 + 1], &c__1, &f[
  677. is + f_dim1], ldf);
  678. }
  679. if (i__ < p) {
  680. alpha = -rhs[0];
  681. i__3 = *m - ie;
  682. daxpy_(&i__3, &alpha, &a[is + (ie + 1) * a_dim1], lda,
  683. &c__[ie + 1 + js * c_dim1], &c__1);
  684. alpha = -rhs[1];
  685. i__3 = *m - ie;
  686. daxpy_(&i__3, &alpha, &d__[is + (ie + 1) * d_dim1],
  687. ldd, &c__[ie + 1 + js * c_dim1], &c__1);
  688. }
  689. } else if (mb == 1 && nb == 2) {
  690. /* Build a 4-by-4 system Z' * x = RHS */
  691. z__[0] = a[is + is * a_dim1];
  692. z__[1] = 0.;
  693. z__[2] = -b[js + js * b_dim1];
  694. z__[3] = -b[jsp1 + js * b_dim1];
  695. z__[8] = 0.;
  696. z__[9] = a[is + is * a_dim1];
  697. z__[10] = -b[js + jsp1 * b_dim1];
  698. z__[11] = -b[jsp1 + jsp1 * b_dim1];
  699. z__[16] = d__[is + is * d_dim1];
  700. z__[17] = 0.;
  701. z__[18] = -e[js + js * e_dim1];
  702. z__[19] = 0.;
  703. z__[24] = 0.;
  704. z__[25] = d__[is + is * d_dim1];
  705. z__[26] = -e[js + jsp1 * e_dim1];
  706. z__[27] = -e[jsp1 + jsp1 * e_dim1];
  707. /* Set up right hand side(s) */
  708. rhs[0] = c__[is + js * c_dim1];
  709. rhs[1] = c__[is + jsp1 * c_dim1];
  710. rhs[2] = f[is + js * f_dim1];
  711. rhs[3] = f[is + jsp1 * f_dim1];
  712. /* Solve Z' * x = RHS */
  713. dgetc2_(&zdim, z__, &c__8, ipiv, jpiv, &ierr);
  714. if (ierr > 0) {
  715. *info = ierr;
  716. }
  717. dgesc2_(&zdim, z__, &c__8, rhs, ipiv, jpiv, &scaloc);
  718. if (scaloc != 1.) {
  719. i__3 = *n;
  720. for (k = 1; k <= i__3; ++k) {
  721. dscal_(m, &scaloc, &c__[k * c_dim1 + 1], &c__1);
  722. dscal_(m, &scaloc, &f[k * f_dim1 + 1], &c__1);
  723. /* L140: */
  724. }
  725. *scale *= scaloc;
  726. }
  727. /* Unpack solution vector(s) */
  728. c__[is + js * c_dim1] = rhs[0];
  729. c__[is + jsp1 * c_dim1] = rhs[1];
  730. f[is + js * f_dim1] = rhs[2];
  731. f[is + jsp1 * f_dim1] = rhs[3];
  732. /* Substitute R(I, J) and L(I, J) into remaining */
  733. /* equation. */
  734. if (j > p + 2) {
  735. i__3 = js - 1;
  736. daxpy_(&i__3, rhs, &b[js * b_dim1 + 1], &c__1, &f[is
  737. + f_dim1], ldf);
  738. i__3 = js - 1;
  739. daxpy_(&i__3, &rhs[1], &b[jsp1 * b_dim1 + 1], &c__1, &
  740. f[is + f_dim1], ldf);
  741. i__3 = js - 1;
  742. daxpy_(&i__3, &rhs[2], &e[js * e_dim1 + 1], &c__1, &f[
  743. is + f_dim1], ldf);
  744. i__3 = js - 1;
  745. daxpy_(&i__3, &rhs[3], &e[jsp1 * e_dim1 + 1], &c__1, &
  746. f[is + f_dim1], ldf);
  747. }
  748. if (i__ < p) {
  749. i__3 = *m - ie;
  750. dger_(&i__3, &nb, &c_b27, &a[is + (ie + 1) * a_dim1],
  751. lda, rhs, &c__1, &c__[ie + 1 + js * c_dim1],
  752. ldc);
  753. i__3 = *m - ie;
  754. dger_(&i__3, &nb, &c_b27, &d__[is + (ie + 1) * d_dim1]
  755. , ldd, &rhs[2], &c__1, &c__[ie + 1 + js *
  756. c_dim1], ldc);
  757. }
  758. } else if (mb == 2 && nb == 1) {
  759. /* Build a 4-by-4 system Z' * x = RHS */
  760. z__[0] = a[is + is * a_dim1];
  761. z__[1] = a[is + isp1 * a_dim1];
  762. z__[2] = -b[js + js * b_dim1];
  763. z__[3] = 0.;
  764. z__[8] = a[isp1 + is * a_dim1];
  765. z__[9] = a[isp1 + isp1 * a_dim1];
  766. z__[10] = 0.;
  767. z__[11] = -b[js + js * b_dim1];
  768. z__[16] = d__[is + is * d_dim1];
  769. z__[17] = d__[is + isp1 * d_dim1];
  770. z__[18] = -e[js + js * e_dim1];
  771. z__[19] = 0.;
  772. z__[24] = 0.;
  773. z__[25] = d__[isp1 + isp1 * d_dim1];
  774. z__[26] = 0.;
  775. z__[27] = -e[js + js * e_dim1];
  776. /* Set up right hand side(s) */
  777. rhs[0] = c__[is + js * c_dim1];
  778. rhs[1] = c__[isp1 + js * c_dim1];
  779. rhs[2] = f[is + js * f_dim1];
  780. rhs[3] = f[isp1 + js * f_dim1];
  781. /* Solve Z' * x = RHS */
  782. dgetc2_(&zdim, z__, &c__8, ipiv, jpiv, &ierr);
  783. if (ierr > 0) {
  784. *info = ierr;
  785. }
  786. dgesc2_(&zdim, z__, &c__8, rhs, ipiv, jpiv, &scaloc);
  787. if (scaloc != 1.) {
  788. i__3 = *n;
  789. for (k = 1; k <= i__3; ++k) {
  790. dscal_(m, &scaloc, &c__[k * c_dim1 + 1], &c__1);
  791. dscal_(m, &scaloc, &f[k * f_dim1 + 1], &c__1);
  792. /* L150: */
  793. }
  794. *scale *= scaloc;
  795. }
  796. /* Unpack solution vector(s) */
  797. c__[is + js * c_dim1] = rhs[0];
  798. c__[isp1 + js * c_dim1] = rhs[1];
  799. f[is + js * f_dim1] = rhs[2];
  800. f[isp1 + js * f_dim1] = rhs[3];
  801. /* Substitute R(I, J) and L(I, J) into remaining */
  802. /* equation. */
  803. if (j > p + 2) {
  804. i__3 = js - 1;
  805. dger_(&mb, &i__3, &c_b42, rhs, &c__1, &b[js * b_dim1
  806. + 1], &c__1, &f[is + f_dim1], ldf);
  807. i__3 = js - 1;
  808. dger_(&mb, &i__3, &c_b42, &rhs[2], &c__1, &e[js *
  809. e_dim1 + 1], &c__1, &f[is + f_dim1], ldf);
  810. }
  811. if (i__ < p) {
  812. i__3 = *m - ie;
  813. dgemv_("T", &mb, &i__3, &c_b27, &a[is + (ie + 1) *
  814. a_dim1], lda, rhs, &c__1, &c_b42, &c__[ie + 1
  815. + js * c_dim1], &c__1);
  816. i__3 = *m - ie;
  817. dgemv_("T", &mb, &i__3, &c_b27, &d__[is + (ie + 1) *
  818. d_dim1], ldd, &rhs[2], &c__1, &c_b42, &c__[ie
  819. + 1 + js * c_dim1], &c__1);
  820. }
  821. } else if (mb == 2 && nb == 2) {
  822. /* Build an 8-by-8 system Z' * x = RHS */
  823. dlaset_("F", &c__8, &c__8, &c_b56, &c_b56, z__, &c__8);
  824. z__[0] = a[is + is * a_dim1];
  825. z__[1] = a[is + isp1 * a_dim1];
  826. z__[4] = -b[js + js * b_dim1];
  827. z__[6] = -b[jsp1 + js * b_dim1];
  828. z__[8] = a[isp1 + is * a_dim1];
  829. z__[9] = a[isp1 + isp1 * a_dim1];
  830. z__[13] = -b[js + js * b_dim1];
  831. z__[15] = -b[jsp1 + js * b_dim1];
  832. z__[18] = a[is + is * a_dim1];
  833. z__[19] = a[is + isp1 * a_dim1];
  834. z__[20] = -b[js + jsp1 * b_dim1];
  835. z__[22] = -b[jsp1 + jsp1 * b_dim1];
  836. z__[26] = a[isp1 + is * a_dim1];
  837. z__[27] = a[isp1 + isp1 * a_dim1];
  838. z__[29] = -b[js + jsp1 * b_dim1];
  839. z__[31] = -b[jsp1 + jsp1 * b_dim1];
  840. z__[32] = d__[is + is * d_dim1];
  841. z__[33] = d__[is + isp1 * d_dim1];
  842. z__[36] = -e[js + js * e_dim1];
  843. z__[41] = d__[isp1 + isp1 * d_dim1];
  844. z__[45] = -e[js + js * e_dim1];
  845. z__[50] = d__[is + is * d_dim1];
  846. z__[51] = d__[is + isp1 * d_dim1];
  847. z__[52] = -e[js + jsp1 * e_dim1];
  848. z__[54] = -e[jsp1 + jsp1 * e_dim1];
  849. z__[59] = d__[isp1 + isp1 * d_dim1];
  850. z__[61] = -e[js + jsp1 * e_dim1];
  851. z__[63] = -e[jsp1 + jsp1 * e_dim1];
  852. /* Set up right hand side(s) */
  853. k = 1;
  854. ii = mb * nb + 1;
  855. i__3 = nb - 1;
  856. for (jj = 0; jj <= i__3; ++jj) {
  857. dcopy_(&mb, &c__[is + (js + jj) * c_dim1], &c__1, &
  858. rhs[k - 1], &c__1);
  859. dcopy_(&mb, &f[is + (js + jj) * f_dim1], &c__1, &rhs[
  860. ii - 1], &c__1);
  861. k += mb;
  862. ii += mb;
  863. /* L160: */
  864. }
  865. /* Solve Z' * x = RHS */
  866. dgetc2_(&zdim, z__, &c__8, ipiv, jpiv, &ierr);
  867. if (ierr > 0) {
  868. *info = ierr;
  869. }
  870. dgesc2_(&zdim, z__, &c__8, rhs, ipiv, jpiv, &scaloc);
  871. if (scaloc != 1.) {
  872. i__3 = *n;
  873. for (k = 1; k <= i__3; ++k) {
  874. dscal_(m, &scaloc, &c__[k * c_dim1 + 1], &c__1);
  875. dscal_(m, &scaloc, &f[k * f_dim1 + 1], &c__1);
  876. /* L170: */
  877. }
  878. *scale *= scaloc;
  879. }
  880. /* Unpack solution vector(s) */
  881. k = 1;
  882. ii = mb * nb + 1;
  883. i__3 = nb - 1;
  884. for (jj = 0; jj <= i__3; ++jj) {
  885. dcopy_(&mb, &rhs[k - 1], &c__1, &c__[is + (js + jj) *
  886. c_dim1], &c__1);
  887. dcopy_(&mb, &rhs[ii - 1], &c__1, &f[is + (js + jj) *
  888. f_dim1], &c__1);
  889. k += mb;
  890. ii += mb;
  891. /* L180: */
  892. }
  893. /* Substitute R(I, J) and L(I, J) into remaining */
  894. /* equation. */
  895. if (j > p + 2) {
  896. i__3 = js - 1;
  897. dgemm_("N", "T", &mb, &i__3, &nb, &c_b42, &c__[is +
  898. js * c_dim1], ldc, &b[js * b_dim1 + 1], ldb, &
  899. c_b42, &f[is + f_dim1], ldf);
  900. i__3 = js - 1;
  901. dgemm_("N", "T", &mb, &i__3, &nb, &c_b42, &f[is + js *
  902. f_dim1], ldf, &e[js * e_dim1 + 1], lde, &
  903. c_b42, &f[is + f_dim1], ldf);
  904. }
  905. if (i__ < p) {
  906. i__3 = *m - ie;
  907. dgemm_("T", "N", &i__3, &nb, &mb, &c_b27, &a[is + (ie
  908. + 1) * a_dim1], lda, &c__[is + js * c_dim1],
  909. ldc, &c_b42, &c__[ie + 1 + js * c_dim1], ldc);
  910. i__3 = *m - ie;
  911. dgemm_("T", "N", &i__3, &nb, &mb, &c_b27, &d__[is + (
  912. ie + 1) * d_dim1], ldd, &f[is + js * f_dim1],
  913. ldf, &c_b42, &c__[ie + 1 + js * c_dim1], ldc);
  914. }
  915. }
  916. /* L190: */
  917. }
  918. /* L200: */
  919. }
  920. }
  921. return 0;
  922. /* End of DTGSY2 */
  923. } /* dtgsy2_ */