C_LAPACK: Fixes to make it compile with MSVC (#3605)
[platform/upstream/openblas.git] / lapack-netlib / SRC / dtgsy2.c
1 #include <math.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <stdio.h>
5 #include <complex.h>
6 #ifdef complex
7 #undef complex
8 #endif
9 #ifdef I
10 #undef I
11 #endif
12
13 #if defined(_WIN64)
14 typedef long long BLASLONG;
15 typedef unsigned long long BLASULONG;
16 #else
17 typedef long BLASLONG;
18 typedef unsigned long BLASULONG;
19 #endif
20
21 #ifdef LAPACK_ILP64
22 typedef BLASLONG blasint;
23 #if defined(_WIN64)
24 #define blasabs(x) llabs(x)
25 #else
26 #define blasabs(x) labs(x)
27 #endif
28 #else
29 typedef int blasint;
30 #define blasabs(x) abs(x)
31 #endif
32
33 typedef blasint integer;
34
35 typedef unsigned int uinteger;
36 typedef char *address;
37 typedef short int shortint;
38 typedef float real;
39 typedef double doublereal;
40 typedef struct { real r, i; } complex;
41 typedef struct { doublereal r, i; } doublecomplex;
42 #ifdef _MSC_VER
43 static inline _Fcomplex Cf(complex *z) {_Fcomplex zz={z->r , z->i}; return zz;}
44 static inline _Dcomplex Cd(doublecomplex *z) {_Dcomplex zz={z->r , z->i};return zz;}
45 static inline _Fcomplex * _pCf(complex *z) {return (_Fcomplex*)z;}
46 static inline _Dcomplex * _pCd(doublecomplex *z) {return (_Dcomplex*)z;}
47 #else
48 static inline _Complex float Cf(complex *z) {return z->r + z->i*_Complex_I;}
49 static inline _Complex double Cd(doublecomplex *z) {return z->r + z->i*_Complex_I;}
50 static inline _Complex float * _pCf(complex *z) {return (_Complex float*)z;}
51 static inline _Complex double * _pCd(doublecomplex *z) {return (_Complex double*)z;}
52 #endif
53 #define pCf(z) (*_pCf(z))
54 #define pCd(z) (*_pCd(z))
55 typedef int logical;
56 typedef short int shortlogical;
57 typedef char logical1;
58 typedef char integer1;
59
60 #define TRUE_ (1)
61 #define FALSE_ (0)
62
63 /* Extern is for use with -E */
64 #ifndef Extern
65 #define Extern extern
66 #endif
67
68 /* I/O stuff */
69
70 typedef int flag;
71 typedef int ftnlen;
72 typedef int ftnint;
73
74 /*external read, write*/
75 typedef struct
76 {       flag cierr;
77         ftnint ciunit;
78         flag ciend;
79         char *cifmt;
80         ftnint cirec;
81 } cilist;
82
83 /*internal read, write*/
84 typedef struct
85 {       flag icierr;
86         char *iciunit;
87         flag iciend;
88         char *icifmt;
89         ftnint icirlen;
90         ftnint icirnum;
91 } icilist;
92
93 /*open*/
94 typedef struct
95 {       flag oerr;
96         ftnint ounit;
97         char *ofnm;
98         ftnlen ofnmlen;
99         char *osta;
100         char *oacc;
101         char *ofm;
102         ftnint orl;
103         char *oblnk;
104 } olist;
105
106 /*close*/
107 typedef struct
108 {       flag cerr;
109         ftnint cunit;
110         char *csta;
111 } cllist;
112
113 /*rewind, backspace, endfile*/
114 typedef struct
115 {       flag aerr;
116         ftnint aunit;
117 } alist;
118
119 /* inquire */
120 typedef struct
121 {       flag inerr;
122         ftnint inunit;
123         char *infile;
124         ftnlen infilen;
125         ftnint  *inex;  /*parameters in standard's order*/
126         ftnint  *inopen;
127         ftnint  *innum;
128         ftnint  *innamed;
129         char    *inname;
130         ftnlen  innamlen;
131         char    *inacc;
132         ftnlen  inacclen;
133         char    *inseq;
134         ftnlen  inseqlen;
135         char    *indir;
136         ftnlen  indirlen;
137         char    *infmt;
138         ftnlen  infmtlen;
139         char    *inform;
140         ftnint  informlen;
141         char    *inunf;
142         ftnlen  inunflen;
143         ftnint  *inrecl;
144         ftnint  *innrec;
145         char    *inblank;
146         ftnlen  inblanklen;
147 } inlist;
148
149 #define VOID void
150
151 union Multitype {       /* for multiple entry points */
152         integer1 g;
153         shortint h;
154         integer i;
155         /* longint j; */
156         real r;
157         doublereal d;
158         complex c;
159         doublecomplex z;
160         };
161
162 typedef union Multitype Multitype;
163
164 struct Vardesc {        /* for Namelist */
165         char *name;
166         char *addr;
167         ftnlen *dims;
168         int  type;
169         };
170 typedef struct Vardesc Vardesc;
171
172 struct Namelist {
173         char *name;
174         Vardesc **vars;
175         int nvars;
176         };
177 typedef struct Namelist Namelist;
178
179 #define abs(x) ((x) >= 0 ? (x) : -(x))
180 #define dabs(x) (fabs(x))
181 #define f2cmin(a,b) ((a) <= (b) ? (a) : (b))
182 #define f2cmax(a,b) ((a) >= (b) ? (a) : (b))
183 #define dmin(a,b) (f2cmin(a,b))
184 #define dmax(a,b) (f2cmax(a,b))
185 #define bit_test(a,b)   ((a) >> (b) & 1)
186 #define bit_clear(a,b)  ((a) & ~((uinteger)1 << (b)))
187 #define bit_set(a,b)    ((a) |  ((uinteger)1 << (b)))
188
189 #define abort_() { sig_die("Fortran abort routine called", 1); }
190 #define c_abs(z) (cabsf(Cf(z)))
191 #define c_cos(R,Z) { pCf(R)=ccos(Cf(Z)); }
192 #ifdef _MSC_VER
193 #define c_div(c, a, b) {Cf(c)._Val[0] = (Cf(a)._Val[0]/Cf(b)._Val[0]); Cf(c)._Val[1]=(Cf(a)._Val[1]/Cf(b)._Val[1]);}
194 #define z_div(c, a, b) {Cd(c)._Val[0] = (Cd(a)._Val[0]/Cd(b)._Val[0]); Cd(c)._Val[1]=(Cd(a)._Val[1]/df(b)._Val[1]);}
195 #else
196 #define c_div(c, a, b) {pCf(c) = Cf(a)/Cf(b);}
197 #define z_div(c, a, b) {pCd(c) = Cd(a)/Cd(b);}
198 #endif
199 #define c_exp(R, Z) {pCf(R) = cexpf(Cf(Z));}
200 #define c_log(R, Z) {pCf(R) = clogf(Cf(Z));}
201 #define c_sin(R, Z) {pCf(R) = csinf(Cf(Z));}
202 //#define c_sqrt(R, Z) {*(R) = csqrtf(Cf(Z));}
203 #define c_sqrt(R, Z) {pCf(R) = csqrtf(Cf(Z));}
204 #define d_abs(x) (fabs(*(x)))
205 #define d_acos(x) (acos(*(x)))
206 #define d_asin(x) (asin(*(x)))
207 #define d_atan(x) (atan(*(x)))
208 #define d_atn2(x, y) (atan2(*(x),*(y)))
209 #define d_cnjg(R, Z) { pCd(R) = conj(Cd(Z)); }
210 #define r_cnjg(R, Z) { pCf(R) = conjf(Cf(Z)); }
211 #define d_cos(x) (cos(*(x)))
212 #define d_cosh(x) (cosh(*(x)))
213 #define d_dim(__a, __b) ( *(__a) > *(__b) ? *(__a) - *(__b) : 0.0 )
214 #define d_exp(x) (exp(*(x)))
215 #define d_imag(z) (cimag(Cd(z)))
216 #define r_imag(z) (cimagf(Cf(z)))
217 #define d_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
218 #define r_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
219 #define d_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
220 #define r_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
221 #define d_log(x) (log(*(x)))
222 #define d_mod(x, y) (fmod(*(x), *(y)))
223 #define u_nint(__x) ((__x)>=0 ? floor((__x) + .5) : -floor(.5 - (__x)))
224 #define d_nint(x) u_nint(*(x))
225 #define u_sign(__a,__b) ((__b) >= 0 ? ((__a) >= 0 ? (__a) : -(__a)) : -((__a) >= 0 ? (__a) : -(__a)))
226 #define d_sign(a,b) u_sign(*(a),*(b))
227 #define r_sign(a,b) u_sign(*(a),*(b))
228 #define d_sin(x) (sin(*(x)))
229 #define d_sinh(x) (sinh(*(x)))
230 #define d_sqrt(x) (sqrt(*(x)))
231 #define d_tan(x) (tan(*(x)))
232 #define d_tanh(x) (tanh(*(x)))
233 #define i_abs(x) abs(*(x))
234 #define i_dnnt(x) ((integer)u_nint(*(x)))
235 #define i_len(s, n) (n)
236 #define i_nint(x) ((integer)u_nint(*(x)))
237 #define i_sign(a,b) ((integer)u_sign((integer)*(a),(integer)*(b)))
238 #define pow_dd(ap, bp) ( pow(*(ap), *(bp)))
239 #define pow_si(B,E) spow_ui(*(B),*(E))
240 #define pow_ri(B,E) spow_ui(*(B),*(E))
241 #define pow_di(B,E) dpow_ui(*(B),*(E))
242 #define pow_zi(p, a, b) {pCd(p) = zpow_ui(Cd(a), *(b));}
243 #define pow_ci(p, a, b) {pCf(p) = cpow_ui(Cf(a), *(b));}
244 #define pow_zz(R,A,B) {pCd(R) = cpow(Cd(A),*(B));}
245 #define s_cat(lpp, rpp, rnp, np, llp) {         ftnlen i, nc, ll; char *f__rp, *lp;     ll = (llp); lp = (lpp);         for(i=0; i < (int)*(np); ++i) {                 nc = ll;                if((rnp)[i] < nc) nc = (rnp)[i];                ll -= nc;               f__rp = (rpp)[i];               while(--nc >= 0) *lp++ = *(f__rp)++;         }  while(--ll >= 0) *lp++ = ' '; }
246 #define s_cmp(a,b,c,d) ((integer)strncmp((a),(b),f2cmin((c),(d))))
247 #define s_copy(A,B,C,D) { int __i,__m; for (__i=0, __m=f2cmin((C),(D)); __i<__m && (B)[__i] != 0; ++__i) (A)[__i] = (B)[__i]; }
248 #define sig_die(s, kill) { exit(1); }
249 #define s_stop(s, n) {exit(0);}
250 static char junk[] = "\n@(#)LIBF77 VERSION 19990503\n";
251 #define z_abs(z) (cabs(Cd(z)))
252 #define z_exp(R, Z) {pCd(R) = cexp(Cd(Z));}
253 #define z_sqrt(R, Z) {pCd(R) = csqrt(Cd(Z));}
254 #define myexit_() break;
255 #define mycycle() continue;
256 #define myceiling(w) {ceil(w)}
257 #define myhuge(w) {HUGE_VAL}
258 //#define mymaxloc_(w,s,e,n) {if (sizeof(*(w)) == sizeof(double)) dmaxloc_((w),*(s),*(e),n); else dmaxloc_((w),*(s),*(e),n);}
259 #define mymaxloc(w,s,e,n) {dmaxloc_(w,*(s),*(e),n)}
260
261 /* procedure parameter types for -A and -C++ */
262
263 #define F2C_proc_par_types 1
264 #ifdef __cplusplus
265 typedef logical (*L_fp)(...);
266 #else
267 typedef logical (*L_fp)();
268 #endif
269
270 static float spow_ui(float x, integer n) {
271         float pow=1.0; unsigned long int u;
272         if(n != 0) {
273                 if(n < 0) n = -n, x = 1/x;
274                 for(u = n; ; ) {
275                         if(u & 01) pow *= x;
276                         if(u >>= 1) x *= x;
277                         else break;
278                 }
279         }
280         return pow;
281 }
282 static double dpow_ui(double x, integer n) {
283         double pow=1.0; unsigned long int u;
284         if(n != 0) {
285                 if(n < 0) n = -n, x = 1/x;
286                 for(u = n; ; ) {
287                         if(u & 01) pow *= x;
288                         if(u >>= 1) x *= x;
289                         else break;
290                 }
291         }
292         return pow;
293 }
294 #ifdef _MSC_VER
295 static _Fcomplex cpow_ui(complex x, integer n) {
296         complex pow={1.0,0.0}; unsigned long int u;
297                 if(n != 0) {
298                 if(n < 0) n = -n, x.r = 1/x.r, x.i=1/x.i;
299                 for(u = n; ; ) {
300                         if(u & 01) pow.r *= x.r, pow.i *= x.i;
301                         if(u >>= 1) x.r *= x.r, x.i *= x.i;
302                         else break;
303                 }
304         }
305         _Fcomplex p={pow.r, pow.i};
306         return p;
307 }
308 #else
309 static _Complex float cpow_ui(_Complex float x, integer n) {
310         _Complex float pow=1.0; unsigned long int u;
311         if(n != 0) {
312                 if(n < 0) n = -n, x = 1/x;
313                 for(u = n; ; ) {
314                         if(u & 01) pow *= x;
315                         if(u >>= 1) x *= x;
316                         else break;
317                 }
318         }
319         return pow;
320 }
321 #endif
322 #ifdef _MSC_VER
323 static _Dcomplex zpow_ui(_Dcomplex x, integer n) {
324         _Dcomplex pow={1.0,0.0}; unsigned long int u;
325         if(n != 0) {
326                 if(n < 0) n = -n, x._Val[0] = 1/x._Val[0], x._Val[1] =1/x._Val[1];
327                 for(u = n; ; ) {
328                         if(u & 01) pow._Val[0] *= x._Val[0], pow._Val[1] *= x._Val[1];
329                         if(u >>= 1) x._Val[0] *= x._Val[0], x._Val[1] *= x._Val[1];
330                         else break;
331                 }
332         }
333         _Dcomplex p = {pow._Val[0], pow._Val[1]};
334         return p;
335 }
336 #else
337 static _Complex double zpow_ui(_Complex double x, integer n) {
338         _Complex double pow=1.0; unsigned long int u;
339         if(n != 0) {
340                 if(n < 0) n = -n, x = 1/x;
341                 for(u = n; ; ) {
342                         if(u & 01) pow *= x;
343                         if(u >>= 1) x *= x;
344                         else break;
345                 }
346         }
347         return pow;
348 }
349 #endif
350 static integer pow_ii(integer x, integer n) {
351         integer pow; unsigned long int u;
352         if (n <= 0) {
353                 if (n == 0 || x == 1) pow = 1;
354                 else if (x != -1) pow = x == 0 ? 1/x : 0;
355                 else n = -n;
356         }
357         if ((n > 0) || !(n == 0 || x == 1 || x != -1)) {
358                 u = n;
359                 for(pow = 1; ; ) {
360                         if(u & 01) pow *= x;
361                         if(u >>= 1) x *= x;
362                         else break;
363                 }
364         }
365         return pow;
366 }
367 static integer dmaxloc_(double *w, integer s, integer e, integer *n)
368 {
369         double m; integer i, mi;
370         for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
371                 if (w[i-1]>m) mi=i ,m=w[i-1];
372         return mi-s+1;
373 }
374 static integer smaxloc_(float *w, integer s, integer e, integer *n)
375 {
376         float m; integer i, mi;
377         for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
378                 if (w[i-1]>m) mi=i ,m=w[i-1];
379         return mi-s+1;
380 }
381 static inline void cdotc_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
382         integer n = *n_, incx = *incx_, incy = *incy_, i;
383 #ifdef _MSC_VER
384         _Fcomplex zdotc = {0.0, 0.0};
385         if (incx == 1 && incy == 1) {
386                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
387                         zdotc._Val[0] += conjf(Cf(&x[i]))._Val[0] * Cf(&y[i])._Val[0];
388                         zdotc._Val[1] += conjf(Cf(&x[i]))._Val[1] * Cf(&y[i])._Val[1];
389                 }
390         } else {
391                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
392                         zdotc._Val[0] += conjf(Cf(&x[i*incx]))._Val[0] * Cf(&y[i*incy])._Val[0];
393                         zdotc._Val[1] += conjf(Cf(&x[i*incx]))._Val[1] * Cf(&y[i*incy])._Val[1];
394                 }
395         }
396         pCf(z) = zdotc;
397 }
398 #else
399         _Complex float zdotc = 0.0;
400         if (incx == 1 && incy == 1) {
401                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
402                         zdotc += conjf(Cf(&x[i])) * Cf(&y[i]);
403                 }
404         } else {
405                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
406                         zdotc += conjf(Cf(&x[i*incx])) * Cf(&y[i*incy]);
407                 }
408         }
409         pCf(z) = zdotc;
410 }
411 #endif
412 static inline void zdotc_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
413         integer n = *n_, incx = *incx_, incy = *incy_, i;
414 #ifdef _MSC_VER
415         _Dcomplex zdotc = {0.0, 0.0};
416         if (incx == 1 && incy == 1) {
417                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
418                         zdotc._Val[0] += conj(Cd(&x[i]))._Val[0] * Cd(&y[i])._Val[0];
419                         zdotc._Val[1] += conj(Cd(&x[i]))._Val[1] * Cd(&y[i])._Val[1];
420                 }
421         } else {
422                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
423                         zdotc._Val[0] += conj(Cd(&x[i*incx]))._Val[0] * Cd(&y[i*incy])._Val[0];
424                         zdotc._Val[1] += conj(Cd(&x[i*incx]))._Val[1] * Cd(&y[i*incy])._Val[1];
425                 }
426         }
427         pCd(z) = zdotc;
428 }
429 #else
430         _Complex double zdotc = 0.0;
431         if (incx == 1 && incy == 1) {
432                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
433                         zdotc += conj(Cd(&x[i])) * Cd(&y[i]);
434                 }
435         } else {
436                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
437                         zdotc += conj(Cd(&x[i*incx])) * Cd(&y[i*incy]);
438                 }
439         }
440         pCd(z) = zdotc;
441 }
442 #endif  
443 static inline void cdotu_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
444         integer n = *n_, incx = *incx_, incy = *incy_, i;
445 #ifdef _MSC_VER
446         _Fcomplex zdotc = {0.0, 0.0};
447         if (incx == 1 && incy == 1) {
448                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
449                         zdotc._Val[0] += Cf(&x[i])._Val[0] * Cf(&y[i])._Val[0];
450                         zdotc._Val[1] += Cf(&x[i])._Val[1] * Cf(&y[i])._Val[1];
451                 }
452         } else {
453                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
454                         zdotc._Val[0] += Cf(&x[i*incx])._Val[0] * Cf(&y[i*incy])._Val[0];
455                         zdotc._Val[1] += Cf(&x[i*incx])._Val[1] * Cf(&y[i*incy])._Val[1];
456                 }
457         }
458         pCf(z) = zdotc;
459 }
460 #else
461         _Complex float zdotc = 0.0;
462         if (incx == 1 && incy == 1) {
463                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
464                         zdotc += Cf(&x[i]) * Cf(&y[i]);
465                 }
466         } else {
467                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
468                         zdotc += Cf(&x[i*incx]) * Cf(&y[i*incy]);
469                 }
470         }
471         pCf(z) = zdotc;
472 }
473 #endif
474 static inline void zdotu_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
475         integer n = *n_, incx = *incx_, incy = *incy_, i;
476 #ifdef _MSC_VER
477         _Dcomplex zdotc = {0.0, 0.0};
478         if (incx == 1 && incy == 1) {
479                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
480                         zdotc._Val[0] += Cd(&x[i])._Val[0] * Cd(&y[i])._Val[0];
481                         zdotc._Val[1] += Cd(&x[i])._Val[1] * Cd(&y[i])._Val[1];
482                 }
483         } else {
484                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
485                         zdotc._Val[0] += Cd(&x[i*incx])._Val[0] * Cd(&y[i*incy])._Val[0];
486                         zdotc._Val[1] += Cd(&x[i*incx])._Val[1] * Cd(&y[i*incy])._Val[1];
487                 }
488         }
489         pCd(z) = zdotc;
490 }
491 #else
492         _Complex double zdotc = 0.0;
493         if (incx == 1 && incy == 1) {
494                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
495                         zdotc += Cd(&x[i]) * Cd(&y[i]);
496                 }
497         } else {
498                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
499                         zdotc += Cd(&x[i*incx]) * Cd(&y[i*incy]);
500                 }
501         }
502         pCd(z) = zdotc;
503 }
504 #endif
505 /*  -- translated by f2c (version 20000121).
506    You must link the resulting object file with the libraries:
507         -lf2c -lm   (in that order)
508 */
509
510
511
512
513 /* Table of constant values */
514
515 static integer c__8 = 8;
516 static integer c__1 = 1;
517 static doublereal c_b27 = -1.;
518 static doublereal c_b42 = 1.;
519 static doublereal c_b56 = 0.;
520
521 /* > \brief \b DTGSY2 solves the generalized Sylvester equation (unblocked algorithm). */
522
523 /*  =========== DOCUMENTATION =========== */
524
525 /* Online html documentation available at */
526 /*            http://www.netlib.org/lapack/explore-html/ */
527
528 /* > \htmlonly */
529 /* > Download DTGSY2 + dependencies */
530 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dtgsy2.
531 f"> */
532 /* > [TGZ]</a> */
533 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dtgsy2.
534 f"> */
535 /* > [ZIP]</a> */
536 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dtgsy2.
537 f"> */
538 /* > [TXT]</a> */
539 /* > \endhtmlonly */
540
541 /*  Definition: */
542 /*  =========== */
543
544 /*       SUBROUTINE DTGSY2( TRANS, IJOB, M, N, A, LDA, B, LDB, C, LDC, D, */
545 /*                          LDD, E, LDE, F, LDF, SCALE, RDSUM, RDSCAL, */
546 /*                          IWORK, PQ, INFO ) */
547
548 /*       CHARACTER          TRANS */
549 /*       INTEGER            IJOB, INFO, LDA, LDB, LDC, LDD, LDE, LDF, M, N, */
550 /*      $                   PQ */
551 /*       DOUBLE PRECISION   RDSCAL, RDSUM, SCALE */
552 /*       INTEGER            IWORK( * ) */
553 /*       DOUBLE PRECISION   A( LDA, * ), B( LDB, * ), C( LDC, * ), */
554 /*      $                   D( LDD, * ), E( LDE, * ), F( LDF, * ) */
555
556
557 /* > \par Purpose: */
558 /*  ============= */
559 /* > */
560 /* > \verbatim */
561 /* > */
562 /* > DTGSY2 solves the generalized Sylvester equation: */
563 /* > */
564 /* >             A * R - L * B = scale * C                (1) */
565 /* >             D * R - L * E = scale * F, */
566 /* > */
567 /* > using Level 1 and 2 BLAS. where R and L are unknown M-by-N matrices, */
568 /* > (A, D), (B, E) and (C, F) are given matrix pairs of size M-by-M, */
569 /* > N-by-N and M-by-N, respectively, with real entries. (A, D) and (B, E) */
570 /* > must be in generalized Schur canonical form, i.e. A, B are upper */
571 /* > quasi triangular and D, E are upper triangular. The solution (R, L) */
572 /* > overwrites (C, F). 0 <= SCALE <= 1 is an output scaling factor */
573 /* > chosen to avoid overflow. */
574 /* > */
575 /* > In matrix notation solving equation (1) corresponds to solve */
576 /* > Z*x = scale*b, where Z is defined as */
577 /* > */
578 /* >        Z = [ kron(In, A)  -kron(B**T, Im) ]             (2) */
579 /* >            [ kron(In, D)  -kron(E**T, Im) ], */
580 /* > */
581 /* > Ik is the identity matrix of size k and X**T is the transpose of X. */
582 /* > kron(X, Y) is the Kronecker product between the matrices X and Y. */
583 /* > In the process of solving (1), we solve a number of such systems */
584 /* > where Dim(In), Dim(In) = 1 or 2. */
585 /* > */
586 /* > If TRANS = 'T', solve the transposed system Z**T*y = scale*b for y, */
587 /* > which is equivalent to solve for R and L in */
588 /* > */
589 /* >             A**T * R  + D**T * L   = scale * C           (3) */
590 /* >             R  * B**T + L  * E**T  = scale * -F */
591 /* > */
592 /* > This case is used to compute an estimate of Dif[(A, D), (B, E)] = */
593 /* > sigma_min(Z) using reverse communication with DLACON. */
594 /* > */
595 /* > DTGSY2 also (IJOB >= 1) contributes to the computation in DTGSYL */
596 /* > of an upper bound on the separation between to matrix pairs. Then */
597 /* > the input (A, D), (B, E) are sub-pencils of the matrix pair in */
598 /* > DTGSYL. See DTGSYL for details. */
599 /* > \endverbatim */
600
601 /*  Arguments: */
602 /*  ========== */
603
604 /* > \param[in] TRANS */
605 /* > \verbatim */
606 /* >          TRANS is CHARACTER*1 */
607 /* >          = 'N': solve the generalized Sylvester equation (1). */
608 /* >          = 'T': solve the 'transposed' system (3). */
609 /* > \endverbatim */
610 /* > */
611 /* > \param[in] IJOB */
612 /* > \verbatim */
613 /* >          IJOB is INTEGER */
614 /* >          Specifies what kind of functionality to be performed. */
615 /* >          = 0: solve (1) only. */
616 /* >          = 1: A contribution from this subsystem to a Frobenius */
617 /* >               norm-based estimate of the separation between two matrix */
618 /* >               pairs is computed. (look ahead strategy is used). */
619 /* >          = 2: A contribution from this subsystem to a Frobenius */
620 /* >               norm-based estimate of the separation between two matrix */
621 /* >               pairs is computed. (DGECON on sub-systems is used.) */
622 /* >          Not referenced if TRANS = 'T'. */
623 /* > \endverbatim */
624 /* > */
625 /* > \param[in] M */
626 /* > \verbatim */
627 /* >          M is INTEGER */
628 /* >          On entry, M specifies the order of A and D, and the row */
629 /* >          dimension of C, F, R and L. */
630 /* > \endverbatim */
631 /* > */
632 /* > \param[in] N */
633 /* > \verbatim */
634 /* >          N is INTEGER */
635 /* >          On entry, N specifies the order of B and E, and the column */
636 /* >          dimension of C, F, R and L. */
637 /* > \endverbatim */
638 /* > */
639 /* > \param[in] A */
640 /* > \verbatim */
641 /* >          A is DOUBLE PRECISION array, dimension (LDA, M) */
642 /* >          On entry, A contains an upper quasi triangular matrix. */
643 /* > \endverbatim */
644 /* > */
645 /* > \param[in] LDA */
646 /* > \verbatim */
647 /* >          LDA is INTEGER */
648 /* >          The leading dimension of the matrix A. LDA >= f2cmax(1, M). */
649 /* > \endverbatim */
650 /* > */
651 /* > \param[in] B */
652 /* > \verbatim */
653 /* >          B is DOUBLE PRECISION array, dimension (LDB, N) */
654 /* >          On entry, B contains an upper quasi triangular matrix. */
655 /* > \endverbatim */
656 /* > */
657 /* > \param[in] LDB */
658 /* > \verbatim */
659 /* >          LDB is INTEGER */
660 /* >          The leading dimension of the matrix B. LDB >= f2cmax(1, N). */
661 /* > \endverbatim */
662 /* > */
663 /* > \param[in,out] C */
664 /* > \verbatim */
665 /* >          C is DOUBLE PRECISION array, dimension (LDC, N) */
666 /* >          On entry, C contains the right-hand-side of the first matrix */
667 /* >          equation in (1). */
668 /* >          On exit, if IJOB = 0, C has been overwritten by the */
669 /* >          solution R. */
670 /* > \endverbatim */
671 /* > */
672 /* > \param[in] LDC */
673 /* > \verbatim */
674 /* >          LDC is INTEGER */
675 /* >          The leading dimension of the matrix C. LDC >= f2cmax(1, M). */
676 /* > \endverbatim */
677 /* > */
678 /* > \param[in] D */
679 /* > \verbatim */
680 /* >          D is DOUBLE PRECISION array, dimension (LDD, M) */
681 /* >          On entry, D contains an upper triangular matrix. */
682 /* > \endverbatim */
683 /* > */
684 /* > \param[in] LDD */
685 /* > \verbatim */
686 /* >          LDD is INTEGER */
687 /* >          The leading dimension of the matrix D. LDD >= f2cmax(1, M). */
688 /* > \endverbatim */
689 /* > */
690 /* > \param[in] E */
691 /* > \verbatim */
692 /* >          E is DOUBLE PRECISION array, dimension (LDE, N) */
693 /* >          On entry, E contains an upper triangular matrix. */
694 /* > \endverbatim */
695 /* > */
696 /* > \param[in] LDE */
697 /* > \verbatim */
698 /* >          LDE is INTEGER */
699 /* >          The leading dimension of the matrix E. LDE >= f2cmax(1, N). */
700 /* > \endverbatim */
701 /* > */
702 /* > \param[in,out] F */
703 /* > \verbatim */
704 /* >          F is DOUBLE PRECISION array, dimension (LDF, N) */
705 /* >          On entry, F contains the right-hand-side of the second matrix */
706 /* >          equation in (1). */
707 /* >          On exit, if IJOB = 0, F has been overwritten by the */
708 /* >          solution L. */
709 /* > \endverbatim */
710 /* > */
711 /* > \param[in] LDF */
712 /* > \verbatim */
713 /* >          LDF is INTEGER */
714 /* >          The leading dimension of the matrix F. LDF >= f2cmax(1, M). */
715 /* > \endverbatim */
716 /* > */
717 /* > \param[out] SCALE */
718 /* > \verbatim */
719 /* >          SCALE is DOUBLE PRECISION */
720 /* >          On exit, 0 <= SCALE <= 1. If 0 < SCALE < 1, the solutions */
721 /* >          R and L (C and F on entry) will hold the solutions to a */
722 /* >          slightly perturbed system but the input matrices A, B, D and */
723 /* >          E have not been changed. If SCALE = 0, R and L will hold the */
724 /* >          solutions to the homogeneous system with C = F = 0. Normally, */
725 /* >          SCALE = 1. */
726 /* > \endverbatim */
727 /* > */
728 /* > \param[in,out] RDSUM */
729 /* > \verbatim */
730 /* >          RDSUM is DOUBLE PRECISION */
731 /* >          On entry, the sum of squares of computed contributions to */
732 /* >          the Dif-estimate under computation by DTGSYL, where the */
733 /* >          scaling factor RDSCAL (see below) has been factored out. */
734 /* >          On exit, the corresponding sum of squares updated with the */
735 /* >          contributions from the current sub-system. */
736 /* >          If TRANS = 'T' RDSUM is not touched. */
737 /* >          NOTE: RDSUM only makes sense when DTGSY2 is called by DTGSYL. */
738 /* > \endverbatim */
739 /* > */
740 /* > \param[in,out] RDSCAL */
741 /* > \verbatim */
742 /* >          RDSCAL is DOUBLE PRECISION */
743 /* >          On entry, scaling factor used to prevent overflow in RDSUM. */
744 /* >          On exit, RDSCAL is updated w.r.t. the current contributions */
745 /* >          in RDSUM. */
746 /* >          If TRANS = 'T', RDSCAL is not touched. */
747 /* >          NOTE: RDSCAL only makes sense when DTGSY2 is called by */
748 /* >                DTGSYL. */
749 /* > \endverbatim */
750 /* > */
751 /* > \param[out] IWORK */
752 /* > \verbatim */
753 /* >          IWORK is INTEGER array, dimension (M+N+2) */
754 /* > \endverbatim */
755 /* > */
756 /* > \param[out] PQ */
757 /* > \verbatim */
758 /* >          PQ is INTEGER */
759 /* >          On exit, the number of subsystems (of size 2-by-2, 4-by-4 and */
760 /* >          8-by-8) solved by this routine. */
761 /* > \endverbatim */
762 /* > */
763 /* > \param[out] INFO */
764 /* > \verbatim */
765 /* >          INFO is INTEGER */
766 /* >          On exit, if INFO is set to */
767 /* >            =0: Successful exit */
768 /* >            <0: If INFO = -i, the i-th argument had an illegal value. */
769 /* >            >0: The matrix pairs (A, D) and (B, E) have common or very */
770 /* >                close eigenvalues. */
771 /* > \endverbatim */
772
773 /*  Authors: */
774 /*  ======== */
775
776 /* > \author Univ. of Tennessee */
777 /* > \author Univ. of California Berkeley */
778 /* > \author Univ. of Colorado Denver */
779 /* > \author NAG Ltd. */
780
781 /* > \date December 2016 */
782
783 /* > \ingroup doubleSYauxiliary */
784
785 /* > \par Contributors: */
786 /*  ================== */
787 /* > */
788 /* >     Bo Kagstrom and Peter Poromaa, Department of Computing Science, */
789 /* >     Umea University, S-901 87 Umea, Sweden. */
790
791 /*  ===================================================================== */
792 /* Subroutine */ int dtgsy2_(char *trans, integer *ijob, integer *m, integer *
793         n, doublereal *a, integer *lda, doublereal *b, integer *ldb, 
794         doublereal *c__, integer *ldc, doublereal *d__, integer *ldd, 
795         doublereal *e, integer *lde, doublereal *f, integer *ldf, doublereal *
796         scale, doublereal *rdsum, doublereal *rdscal, integer *iwork, integer 
797         *pq, integer *info)
798 {
799     /* System generated locals */
800     integer a_dim1, a_offset, b_dim1, b_offset, c_dim1, c_offset, d_dim1, 
801             d_offset, e_dim1, e_offset, f_dim1, f_offset, i__1, i__2, i__3;
802
803     /* Local variables */
804     extern /* Subroutine */ int dger_(integer *, integer *, doublereal *, 
805             doublereal *, integer *, doublereal *, integer *, doublereal *, 
806             integer *);
807     integer ierr, zdim, ipiv[8], jpiv[8], i__, j, k, p, q;
808     doublereal alpha;
809     extern /* Subroutine */ int dscal_(integer *, doublereal *, doublereal *, 
810             integer *), dgemm_(char *, char *, integer *, integer *, integer *
811             , doublereal *, doublereal *, integer *, doublereal *, integer *, 
812             doublereal *, doublereal *, integer *);
813     doublereal z__[64]  /* was [8][8] */;
814     extern logical lsame_(char *, char *);
815     extern /* Subroutine */ int dgemv_(char *, integer *, integer *, 
816             doublereal *, doublereal *, integer *, doublereal *, integer *, 
817             doublereal *, doublereal *, integer *), dcopy_(integer *, 
818             doublereal *, integer *, doublereal *, integer *), daxpy_(integer 
819             *, doublereal *, doublereal *, integer *, doublereal *, integer *)
820             , dgesc2_(integer *, doublereal *, integer *, doublereal *, 
821             integer *, integer *, doublereal *), dgetc2_(integer *, 
822             doublereal *, integer *, integer *, integer *, integer *);
823     integer ie, je, mb, nb, ii, jj, is, js;
824     extern /* Subroutine */ int dlatdf_(integer *, integer *, doublereal *, 
825             integer *, doublereal *, doublereal *, doublereal *, integer *, 
826             integer *);
827     doublereal scaloc;
828     extern /* Subroutine */ int dlaset_(char *, integer *, integer *, 
829             doublereal *, doublereal *, doublereal *, integer *), 
830             xerbla_(char *, integer *, ftnlen);
831     logical notran;
832     doublereal rhs[8];
833     integer isp1, jsp1;
834
835
836 /*  -- LAPACK auxiliary routine (version 3.7.0) -- */
837 /*  -- LAPACK is a software package provided by Univ. of Tennessee,    -- */
838 /*  -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
839 /*     December 2016 */
840
841
842 /*  ===================================================================== */
843 /*  Replaced various illegal calls to DCOPY by calls to DLASET. */
844 /*  Sven Hammarling, 27/5/02. */
845
846
847 /*     Decode and test input parameters */
848
849     /* Parameter adjustments */
850     a_dim1 = *lda;
851     a_offset = 1 + a_dim1 * 1;
852     a -= a_offset;
853     b_dim1 = *ldb;
854     b_offset = 1 + b_dim1 * 1;
855     b -= b_offset;
856     c_dim1 = *ldc;
857     c_offset = 1 + c_dim1 * 1;
858     c__ -= c_offset;
859     d_dim1 = *ldd;
860     d_offset = 1 + d_dim1 * 1;
861     d__ -= d_offset;
862     e_dim1 = *lde;
863     e_offset = 1 + e_dim1 * 1;
864     e -= e_offset;
865     f_dim1 = *ldf;
866     f_offset = 1 + f_dim1 * 1;
867     f -= f_offset;
868     --iwork;
869
870     /* Function Body */
871     *info = 0;
872     ierr = 0;
873     notran = lsame_(trans, "N");
874     if (! notran && ! lsame_(trans, "T")) {
875         *info = -1;
876     } else if (notran) {
877         if (*ijob < 0 || *ijob > 2) {
878             *info = -2;
879         }
880     }
881     if (*info == 0) {
882         if (*m <= 0) {
883             *info = -3;
884         } else if (*n <= 0) {
885             *info = -4;
886         } else if (*lda < f2cmax(1,*m)) {
887             *info = -6;
888         } else if (*ldb < f2cmax(1,*n)) {
889             *info = -8;
890         } else if (*ldc < f2cmax(1,*m)) {
891             *info = -10;
892         } else if (*ldd < f2cmax(1,*m)) {
893             *info = -12;
894         } else if (*lde < f2cmax(1,*n)) {
895             *info = -14;
896         } else if (*ldf < f2cmax(1,*m)) {
897             *info = -16;
898         }
899     }
900     if (*info != 0) {
901         i__1 = -(*info);
902         xerbla_("DTGSY2", &i__1, (ftnlen)6);
903         return 0;
904     }
905
906 /*     Determine block structure of A */
907
908     *pq = 0;
909     p = 0;
910     i__ = 1;
911 L10:
912     if (i__ > *m) {
913         goto L20;
914     }
915     ++p;
916     iwork[p] = i__;
917     if (i__ == *m) {
918         goto L20;
919     }
920     if (a[i__ + 1 + i__ * a_dim1] != 0.) {
921         i__ += 2;
922     } else {
923         ++i__;
924     }
925     goto L10;
926 L20:
927     iwork[p + 1] = *m + 1;
928
929 /*     Determine block structure of B */
930
931     q = p + 1;
932     j = 1;
933 L30:
934     if (j > *n) {
935         goto L40;
936     }
937     ++q;
938     iwork[q] = j;
939     if (j == *n) {
940         goto L40;
941     }
942     if (b[j + 1 + j * b_dim1] != 0.) {
943         j += 2;
944     } else {
945         ++j;
946     }
947     goto L30;
948 L40:
949     iwork[q + 1] = *n + 1;
950     *pq = p * (q - p - 1);
951
952     if (notran) {
953
954 /*        Solve (I, J) - subsystem */
955 /*           A(I, I) * R(I, J) - L(I, J) * B(J, J) = C(I, J) */
956 /*           D(I, I) * R(I, J) - L(I, J) * E(J, J) = F(I, J) */
957 /*        for I = P, P - 1, ..., 1; J = 1, 2, ..., Q */
958
959         *scale = 1.;
960         scaloc = 1.;
961         i__1 = q;
962         for (j = p + 2; j <= i__1; ++j) {
963             js = iwork[j];
964             jsp1 = js + 1;
965             je = iwork[j + 1] - 1;
966             nb = je - js + 1;
967             for (i__ = p; i__ >= 1; --i__) {
968
969                 is = iwork[i__];
970                 isp1 = is + 1;
971                 ie = iwork[i__ + 1] - 1;
972                 mb = ie - is + 1;
973                 zdim = mb * nb << 1;
974
975                 if (mb == 1 && nb == 1) {
976
977 /*                 Build a 2-by-2 system Z * x = RHS */
978
979                     z__[0] = a[is + is * a_dim1];
980                     z__[1] = d__[is + is * d_dim1];
981                     z__[8] = -b[js + js * b_dim1];
982                     z__[9] = -e[js + js * e_dim1];
983
984 /*                 Set up right hand side(s) */
985
986                     rhs[0] = c__[is + js * c_dim1];
987                     rhs[1] = f[is + js * f_dim1];
988
989 /*                 Solve Z * x = RHS */
990
991                     dgetc2_(&zdim, z__, &c__8, ipiv, jpiv, &ierr);
992                     if (ierr > 0) {
993                         *info = ierr;
994                     }
995
996                     if (*ijob == 0) {
997                         dgesc2_(&zdim, z__, &c__8, rhs, ipiv, jpiv, &scaloc);
998                         if (scaloc != 1.) {
999                             i__2 = *n;
1000                             for (k = 1; k <= i__2; ++k) {
1001                                 dscal_(m, &scaloc, &c__[k * c_dim1 + 1], &
1002                                         c__1);
1003                                 dscal_(m, &scaloc, &f[k * f_dim1 + 1], &c__1);
1004 /* L50: */
1005                             }
1006                             *scale *= scaloc;
1007                         }
1008                     } else {
1009                         dlatdf_(ijob, &zdim, z__, &c__8, rhs, rdsum, rdscal, 
1010                                 ipiv, jpiv);
1011                     }
1012
1013 /*                 Unpack solution vector(s) */
1014
1015                     c__[is + js * c_dim1] = rhs[0];
1016                     f[is + js * f_dim1] = rhs[1];
1017
1018 /*                 Substitute R(I, J) and L(I, J) into remaining */
1019 /*                 equation. */
1020
1021                     if (i__ > 1) {
1022                         alpha = -rhs[0];
1023                         i__2 = is - 1;
1024                         daxpy_(&i__2, &alpha, &a[is * a_dim1 + 1], &c__1, &
1025                                 c__[js * c_dim1 + 1], &c__1);
1026                         i__2 = is - 1;
1027                         daxpy_(&i__2, &alpha, &d__[is * d_dim1 + 1], &c__1, &
1028                                 f[js * f_dim1 + 1], &c__1);
1029                     }
1030                     if (j < q) {
1031                         i__2 = *n - je;
1032                         daxpy_(&i__2, &rhs[1], &b[js + (je + 1) * b_dim1], 
1033                                 ldb, &c__[is + (je + 1) * c_dim1], ldc);
1034                         i__2 = *n - je;
1035                         daxpy_(&i__2, &rhs[1], &e[js + (je + 1) * e_dim1], 
1036                                 lde, &f[is + (je + 1) * f_dim1], ldf);
1037                     }
1038
1039                 } else if (mb == 1 && nb == 2) {
1040
1041 /*                 Build a 4-by-4 system Z * x = RHS */
1042
1043                     z__[0] = a[is + is * a_dim1];
1044                     z__[1] = 0.;
1045                     z__[2] = d__[is + is * d_dim1];
1046                     z__[3] = 0.;
1047
1048                     z__[8] = 0.;
1049                     z__[9] = a[is + is * a_dim1];
1050                     z__[10] = 0.;
1051                     z__[11] = d__[is + is * d_dim1];
1052
1053                     z__[16] = -b[js + js * b_dim1];
1054                     z__[17] = -b[js + jsp1 * b_dim1];
1055                     z__[18] = -e[js + js * e_dim1];
1056                     z__[19] = -e[js + jsp1 * e_dim1];
1057
1058                     z__[24] = -b[jsp1 + js * b_dim1];
1059                     z__[25] = -b[jsp1 + jsp1 * b_dim1];
1060                     z__[26] = 0.;
1061                     z__[27] = -e[jsp1 + jsp1 * e_dim1];
1062
1063 /*                 Set up right hand side(s) */
1064
1065                     rhs[0] = c__[is + js * c_dim1];
1066                     rhs[1] = c__[is + jsp1 * c_dim1];
1067                     rhs[2] = f[is + js * f_dim1];
1068                     rhs[3] = f[is + jsp1 * f_dim1];
1069
1070 /*                 Solve Z * x = RHS */
1071
1072                     dgetc2_(&zdim, z__, &c__8, ipiv, jpiv, &ierr);
1073                     if (ierr > 0) {
1074                         *info = ierr;
1075                     }
1076
1077                     if (*ijob == 0) {
1078                         dgesc2_(&zdim, z__, &c__8, rhs, ipiv, jpiv, &scaloc);
1079                         if (scaloc != 1.) {
1080                             i__2 = *n;
1081                             for (k = 1; k <= i__2; ++k) {
1082                                 dscal_(m, &scaloc, &c__[k * c_dim1 + 1], &
1083                                         c__1);
1084                                 dscal_(m, &scaloc, &f[k * f_dim1 + 1], &c__1);
1085 /* L60: */
1086                             }
1087                             *scale *= scaloc;
1088                         }
1089                     } else {
1090                         dlatdf_(ijob, &zdim, z__, &c__8, rhs, rdsum, rdscal, 
1091                                 ipiv, jpiv);
1092                     }
1093
1094 /*                 Unpack solution vector(s) */
1095
1096                     c__[is + js * c_dim1] = rhs[0];
1097                     c__[is + jsp1 * c_dim1] = rhs[1];
1098                     f[is + js * f_dim1] = rhs[2];
1099                     f[is + jsp1 * f_dim1] = rhs[3];
1100
1101 /*                 Substitute R(I, J) and L(I, J) into remaining */
1102 /*                 equation. */
1103
1104                     if (i__ > 1) {
1105                         i__2 = is - 1;
1106                         dger_(&i__2, &nb, &c_b27, &a[is * a_dim1 + 1], &c__1, 
1107                                 rhs, &c__1, &c__[js * c_dim1 + 1], ldc);
1108                         i__2 = is - 1;
1109                         dger_(&i__2, &nb, &c_b27, &d__[is * d_dim1 + 1], &
1110                                 c__1, rhs, &c__1, &f[js * f_dim1 + 1], ldf);
1111                     }
1112                     if (j < q) {
1113                         i__2 = *n - je;
1114                         daxpy_(&i__2, &rhs[2], &b[js + (je + 1) * b_dim1], 
1115                                 ldb, &c__[is + (je + 1) * c_dim1], ldc);
1116                         i__2 = *n - je;
1117                         daxpy_(&i__2, &rhs[2], &e[js + (je + 1) * e_dim1], 
1118                                 lde, &f[is + (je + 1) * f_dim1], ldf);
1119                         i__2 = *n - je;
1120                         daxpy_(&i__2, &rhs[3], &b[jsp1 + (je + 1) * b_dim1], 
1121                                 ldb, &c__[is + (je + 1) * c_dim1], ldc);
1122                         i__2 = *n - je;
1123                         daxpy_(&i__2, &rhs[3], &e[jsp1 + (je + 1) * e_dim1], 
1124                                 lde, &f[is + (je + 1) * f_dim1], ldf);
1125                     }
1126
1127                 } else if (mb == 2 && nb == 1) {
1128
1129 /*                 Build a 4-by-4 system Z * x = RHS */
1130
1131                     z__[0] = a[is + is * a_dim1];
1132                     z__[1] = a[isp1 + is * a_dim1];
1133                     z__[2] = d__[is + is * d_dim1];
1134                     z__[3] = 0.;
1135
1136                     z__[8] = a[is + isp1 * a_dim1];
1137                     z__[9] = a[isp1 + isp1 * a_dim1];
1138                     z__[10] = d__[is + isp1 * d_dim1];
1139                     z__[11] = d__[isp1 + isp1 * d_dim1];
1140
1141                     z__[16] = -b[js + js * b_dim1];
1142                     z__[17] = 0.;
1143                     z__[18] = -e[js + js * e_dim1];
1144                     z__[19] = 0.;
1145
1146                     z__[24] = 0.;
1147                     z__[25] = -b[js + js * b_dim1];
1148                     z__[26] = 0.;
1149                     z__[27] = -e[js + js * e_dim1];
1150
1151 /*                 Set up right hand side(s) */
1152
1153                     rhs[0] = c__[is + js * c_dim1];
1154                     rhs[1] = c__[isp1 + js * c_dim1];
1155                     rhs[2] = f[is + js * f_dim1];
1156                     rhs[3] = f[isp1 + js * f_dim1];
1157
1158 /*                 Solve Z * x = RHS */
1159
1160                     dgetc2_(&zdim, z__, &c__8, ipiv, jpiv, &ierr);
1161                     if (ierr > 0) {
1162                         *info = ierr;
1163                     }
1164                     if (*ijob == 0) {
1165                         dgesc2_(&zdim, z__, &c__8, rhs, ipiv, jpiv, &scaloc);
1166                         if (scaloc != 1.) {
1167                             i__2 = *n;
1168                             for (k = 1; k <= i__2; ++k) {
1169                                 dscal_(m, &scaloc, &c__[k * c_dim1 + 1], &
1170                                         c__1);
1171                                 dscal_(m, &scaloc, &f[k * f_dim1 + 1], &c__1);
1172 /* L70: */
1173                             }
1174                             *scale *= scaloc;
1175                         }
1176                     } else {
1177                         dlatdf_(ijob, &zdim, z__, &c__8, rhs, rdsum, rdscal, 
1178                                 ipiv, jpiv);
1179                     }
1180
1181 /*                 Unpack solution vector(s) */
1182
1183                     c__[is + js * c_dim1] = rhs[0];
1184                     c__[isp1 + js * c_dim1] = rhs[1];
1185                     f[is + js * f_dim1] = rhs[2];
1186                     f[isp1 + js * f_dim1] = rhs[3];
1187
1188 /*                 Substitute R(I, J) and L(I, J) into remaining */
1189 /*                 equation. */
1190
1191                     if (i__ > 1) {
1192                         i__2 = is - 1;
1193                         dgemv_("N", &i__2, &mb, &c_b27, &a[is * a_dim1 + 1], 
1194                                 lda, rhs, &c__1, &c_b42, &c__[js * c_dim1 + 1]
1195                                 , &c__1);
1196                         i__2 = is - 1;
1197                         dgemv_("N", &i__2, &mb, &c_b27, &d__[is * d_dim1 + 1],
1198                                  ldd, rhs, &c__1, &c_b42, &f[js * f_dim1 + 1],
1199                                  &c__1);
1200                     }
1201                     if (j < q) {
1202                         i__2 = *n - je;
1203                         dger_(&mb, &i__2, &c_b42, &rhs[2], &c__1, &b[js + (je 
1204                                 + 1) * b_dim1], ldb, &c__[is + (je + 1) * 
1205                                 c_dim1], ldc);
1206                         i__2 = *n - je;
1207                         dger_(&mb, &i__2, &c_b42, &rhs[2], &c__1, &e[js + (je 
1208                                 + 1) * e_dim1], lde, &f[is + (je + 1) * 
1209                                 f_dim1], ldf);
1210                     }
1211
1212                 } else if (mb == 2 && nb == 2) {
1213
1214 /*                 Build an 8-by-8 system Z * x = RHS */
1215
1216                     dlaset_("F", &c__8, &c__8, &c_b56, &c_b56, z__, &c__8);
1217
1218                     z__[0] = a[is + is * a_dim1];
1219                     z__[1] = a[isp1 + is * a_dim1];
1220                     z__[4] = d__[is + is * d_dim1];
1221
1222                     z__[8] = a[is + isp1 * a_dim1];
1223                     z__[9] = a[isp1 + isp1 * a_dim1];
1224                     z__[12] = d__[is + isp1 * d_dim1];
1225                     z__[13] = d__[isp1 + isp1 * d_dim1];
1226
1227                     z__[18] = a[is + is * a_dim1];
1228                     z__[19] = a[isp1 + is * a_dim1];
1229                     z__[22] = d__[is + is * d_dim1];
1230
1231                     z__[26] = a[is + isp1 * a_dim1];
1232                     z__[27] = a[isp1 + isp1 * a_dim1];
1233                     z__[30] = d__[is + isp1 * d_dim1];
1234                     z__[31] = d__[isp1 + isp1 * d_dim1];
1235
1236                     z__[32] = -b[js + js * b_dim1];
1237                     z__[34] = -b[js + jsp1 * b_dim1];
1238                     z__[36] = -e[js + js * e_dim1];
1239                     z__[38] = -e[js + jsp1 * e_dim1];
1240
1241                     z__[41] = -b[js + js * b_dim1];
1242                     z__[43] = -b[js + jsp1 * b_dim1];
1243                     z__[45] = -e[js + js * e_dim1];
1244                     z__[47] = -e[js + jsp1 * e_dim1];
1245
1246                     z__[48] = -b[jsp1 + js * b_dim1];
1247                     z__[50] = -b[jsp1 + jsp1 * b_dim1];
1248                     z__[54] = -e[jsp1 + jsp1 * e_dim1];
1249
1250                     z__[57] = -b[jsp1 + js * b_dim1];
1251                     z__[59] = -b[jsp1 + jsp1 * b_dim1];
1252                     z__[63] = -e[jsp1 + jsp1 * e_dim1];
1253
1254 /*                 Set up right hand side(s) */
1255
1256                     k = 1;
1257                     ii = mb * nb + 1;
1258                     i__2 = nb - 1;
1259                     for (jj = 0; jj <= i__2; ++jj) {
1260                         dcopy_(&mb, &c__[is + (js + jj) * c_dim1], &c__1, &
1261                                 rhs[k - 1], &c__1);
1262                         dcopy_(&mb, &f[is + (js + jj) * f_dim1], &c__1, &rhs[
1263                                 ii - 1], &c__1);
1264                         k += mb;
1265                         ii += mb;
1266 /* L80: */
1267                     }
1268
1269 /*                 Solve Z * x = RHS */
1270
1271                     dgetc2_(&zdim, z__, &c__8, ipiv, jpiv, &ierr);
1272                     if (ierr > 0) {
1273                         *info = ierr;
1274                     }
1275                     if (*ijob == 0) {
1276                         dgesc2_(&zdim, z__, &c__8, rhs, ipiv, jpiv, &scaloc);
1277                         if (scaloc != 1.) {
1278                             i__2 = *n;
1279                             for (k = 1; k <= i__2; ++k) {
1280                                 dscal_(m, &scaloc, &c__[k * c_dim1 + 1], &
1281                                         c__1);
1282                                 dscal_(m, &scaloc, &f[k * f_dim1 + 1], &c__1);
1283 /* L90: */
1284                             }
1285                             *scale *= scaloc;
1286                         }
1287                     } else {
1288                         dlatdf_(ijob, &zdim, z__, &c__8, rhs, rdsum, rdscal, 
1289                                 ipiv, jpiv);
1290                     }
1291
1292 /*                 Unpack solution vector(s) */
1293
1294                     k = 1;
1295                     ii = mb * nb + 1;
1296                     i__2 = nb - 1;
1297                     for (jj = 0; jj <= i__2; ++jj) {
1298                         dcopy_(&mb, &rhs[k - 1], &c__1, &c__[is + (js + jj) * 
1299                                 c_dim1], &c__1);
1300                         dcopy_(&mb, &rhs[ii - 1], &c__1, &f[is + (js + jj) * 
1301                                 f_dim1], &c__1);
1302                         k += mb;
1303                         ii += mb;
1304 /* L100: */
1305                     }
1306
1307 /*                 Substitute R(I, J) and L(I, J) into remaining */
1308 /*                 equation. */
1309
1310                     if (i__ > 1) {
1311                         i__2 = is - 1;
1312                         dgemm_("N", "N", &i__2, &nb, &mb, &c_b27, &a[is * 
1313                                 a_dim1 + 1], lda, rhs, &mb, &c_b42, &c__[js * 
1314                                 c_dim1 + 1], ldc);
1315                         i__2 = is - 1;
1316                         dgemm_("N", "N", &i__2, &nb, &mb, &c_b27, &d__[is * 
1317                                 d_dim1 + 1], ldd, rhs, &mb, &c_b42, &f[js * 
1318                                 f_dim1 + 1], ldf);
1319                     }
1320                     if (j < q) {
1321                         k = mb * nb + 1;
1322                         i__2 = *n - je;
1323                         dgemm_("N", "N", &mb, &i__2, &nb, &c_b42, &rhs[k - 1],
1324                                  &mb, &b[js + (je + 1) * b_dim1], ldb, &c_b42,
1325                                  &c__[is + (je + 1) * c_dim1], ldc);
1326                         i__2 = *n - je;
1327                         dgemm_("N", "N", &mb, &i__2, &nb, &c_b42, &rhs[k - 1],
1328                                  &mb, &e[js + (je + 1) * e_dim1], lde, &c_b42,
1329                                  &f[is + (je + 1) * f_dim1], ldf);
1330                     }
1331
1332                 }
1333
1334 /* L110: */
1335             }
1336 /* L120: */
1337         }
1338     } else {
1339
1340 /*        Solve (I, J) - subsystem */
1341 /*             A(I, I)**T * R(I, J) + D(I, I)**T * L(J, J)  =  C(I, J) */
1342 /*             R(I, I)  * B(J, J) + L(I, J)  * E(J, J)  = -F(I, J) */
1343 /*        for I = 1, 2, ..., P, J = Q, Q - 1, ..., 1 */
1344
1345         *scale = 1.;
1346         scaloc = 1.;
1347         i__1 = p;
1348         for (i__ = 1; i__ <= i__1; ++i__) {
1349
1350             is = iwork[i__];
1351             isp1 = is + 1;
1352             ie = iwork[i__ + 1] - 1;
1353             mb = ie - is + 1;
1354             i__2 = p + 2;
1355             for (j = q; j >= i__2; --j) {
1356
1357                 js = iwork[j];
1358                 jsp1 = js + 1;
1359                 je = iwork[j + 1] - 1;
1360                 nb = je - js + 1;
1361                 zdim = mb * nb << 1;
1362                 if (mb == 1 && nb == 1) {
1363
1364 /*                 Build a 2-by-2 system Z**T * x = RHS */
1365
1366                     z__[0] = a[is + is * a_dim1];
1367                     z__[1] = -b[js + js * b_dim1];
1368                     z__[8] = d__[is + is * d_dim1];
1369                     z__[9] = -e[js + js * e_dim1];
1370
1371 /*                 Set up right hand side(s) */
1372
1373                     rhs[0] = c__[is + js * c_dim1];
1374                     rhs[1] = f[is + js * f_dim1];
1375
1376 /*                 Solve Z**T * x = RHS */
1377
1378                     dgetc2_(&zdim, z__, &c__8, ipiv, jpiv, &ierr);
1379                     if (ierr > 0) {
1380                         *info = ierr;
1381                     }
1382
1383                     dgesc2_(&zdim, z__, &c__8, rhs, ipiv, jpiv, &scaloc);
1384                     if (scaloc != 1.) {
1385                         i__3 = *n;
1386                         for (k = 1; k <= i__3; ++k) {
1387                             dscal_(m, &scaloc, &c__[k * c_dim1 + 1], &c__1);
1388                             dscal_(m, &scaloc, &f[k * f_dim1 + 1], &c__1);
1389 /* L130: */
1390                         }
1391                         *scale *= scaloc;
1392                     }
1393
1394 /*                 Unpack solution vector(s) */
1395
1396                     c__[is + js * c_dim1] = rhs[0];
1397                     f[is + js * f_dim1] = rhs[1];
1398
1399 /*                 Substitute R(I, J) and L(I, J) into remaining */
1400 /*                 equation. */
1401
1402                     if (j > p + 2) {
1403                         alpha = rhs[0];
1404                         i__3 = js - 1;
1405                         daxpy_(&i__3, &alpha, &b[js * b_dim1 + 1], &c__1, &f[
1406                                 is + f_dim1], ldf);
1407                         alpha = rhs[1];
1408                         i__3 = js - 1;
1409                         daxpy_(&i__3, &alpha, &e[js * e_dim1 + 1], &c__1, &f[
1410                                 is + f_dim1], ldf);
1411                     }
1412                     if (i__ < p) {
1413                         alpha = -rhs[0];
1414                         i__3 = *m - ie;
1415                         daxpy_(&i__3, &alpha, &a[is + (ie + 1) * a_dim1], lda,
1416                                  &c__[ie + 1 + js * c_dim1], &c__1);
1417                         alpha = -rhs[1];
1418                         i__3 = *m - ie;
1419                         daxpy_(&i__3, &alpha, &d__[is + (ie + 1) * d_dim1], 
1420                                 ldd, &c__[ie + 1 + js * c_dim1], &c__1);
1421                     }
1422
1423                 } else if (mb == 1 && nb == 2) {
1424
1425 /*                 Build a 4-by-4 system Z**T * x = RHS */
1426
1427                     z__[0] = a[is + is * a_dim1];
1428                     z__[1] = 0.;
1429                     z__[2] = -b[js + js * b_dim1];
1430                     z__[3] = -b[jsp1 + js * b_dim1];
1431
1432                     z__[8] = 0.;
1433                     z__[9] = a[is + is * a_dim1];
1434                     z__[10] = -b[js + jsp1 * b_dim1];
1435                     z__[11] = -b[jsp1 + jsp1 * b_dim1];
1436
1437                     z__[16] = d__[is + is * d_dim1];
1438                     z__[17] = 0.;
1439                     z__[18] = -e[js + js * e_dim1];
1440                     z__[19] = 0.;
1441
1442                     z__[24] = 0.;
1443                     z__[25] = d__[is + is * d_dim1];
1444                     z__[26] = -e[js + jsp1 * e_dim1];
1445                     z__[27] = -e[jsp1 + jsp1 * e_dim1];
1446
1447 /*                 Set up right hand side(s) */
1448
1449                     rhs[0] = c__[is + js * c_dim1];
1450                     rhs[1] = c__[is + jsp1 * c_dim1];
1451                     rhs[2] = f[is + js * f_dim1];
1452                     rhs[3] = f[is + jsp1 * f_dim1];
1453
1454 /*                 Solve Z**T * x = RHS */
1455
1456                     dgetc2_(&zdim, z__, &c__8, ipiv, jpiv, &ierr);
1457                     if (ierr > 0) {
1458                         *info = ierr;
1459                     }
1460                     dgesc2_(&zdim, z__, &c__8, rhs, ipiv, jpiv, &scaloc);
1461                     if (scaloc != 1.) {
1462                         i__3 = *n;
1463                         for (k = 1; k <= i__3; ++k) {
1464                             dscal_(m, &scaloc, &c__[k * c_dim1 + 1], &c__1);
1465                             dscal_(m, &scaloc, &f[k * f_dim1 + 1], &c__1);
1466 /* L140: */
1467                         }
1468                         *scale *= scaloc;
1469                     }
1470
1471 /*                 Unpack solution vector(s) */
1472
1473                     c__[is + js * c_dim1] = rhs[0];
1474                     c__[is + jsp1 * c_dim1] = rhs[1];
1475                     f[is + js * f_dim1] = rhs[2];
1476                     f[is + jsp1 * f_dim1] = rhs[3];
1477
1478 /*                 Substitute R(I, J) and L(I, J) into remaining */
1479 /*                 equation. */
1480
1481                     if (j > p + 2) {
1482                         i__3 = js - 1;
1483                         daxpy_(&i__3, rhs, &b[js * b_dim1 + 1], &c__1, &f[is 
1484                                 + f_dim1], ldf);
1485                         i__3 = js - 1;
1486                         daxpy_(&i__3, &rhs[1], &b[jsp1 * b_dim1 + 1], &c__1, &
1487                                 f[is + f_dim1], ldf);
1488                         i__3 = js - 1;
1489                         daxpy_(&i__3, &rhs[2], &e[js * e_dim1 + 1], &c__1, &f[
1490                                 is + f_dim1], ldf);
1491                         i__3 = js - 1;
1492                         daxpy_(&i__3, &rhs[3], &e[jsp1 * e_dim1 + 1], &c__1, &
1493                                 f[is + f_dim1], ldf);
1494                     }
1495                     if (i__ < p) {
1496                         i__3 = *m - ie;
1497                         dger_(&i__3, &nb, &c_b27, &a[is + (ie + 1) * a_dim1], 
1498                                 lda, rhs, &c__1, &c__[ie + 1 + js * c_dim1], 
1499                                 ldc);
1500                         i__3 = *m - ie;
1501                         dger_(&i__3, &nb, &c_b27, &d__[is + (ie + 1) * d_dim1]
1502                                 , ldd, &rhs[2], &c__1, &c__[ie + 1 + js * 
1503                                 c_dim1], ldc);
1504                     }
1505
1506                 } else if (mb == 2 && nb == 1) {
1507
1508 /*                 Build a 4-by-4 system Z**T * x = RHS */
1509
1510                     z__[0] = a[is + is * a_dim1];
1511                     z__[1] = a[is + isp1 * a_dim1];
1512                     z__[2] = -b[js + js * b_dim1];
1513                     z__[3] = 0.;
1514
1515                     z__[8] = a[isp1 + is * a_dim1];
1516                     z__[9] = a[isp1 + isp1 * a_dim1];
1517                     z__[10] = 0.;
1518                     z__[11] = -b[js + js * b_dim1];
1519
1520                     z__[16] = d__[is + is * d_dim1];
1521                     z__[17] = d__[is + isp1 * d_dim1];
1522                     z__[18] = -e[js + js * e_dim1];
1523                     z__[19] = 0.;
1524
1525                     z__[24] = 0.;
1526                     z__[25] = d__[isp1 + isp1 * d_dim1];
1527                     z__[26] = 0.;
1528                     z__[27] = -e[js + js * e_dim1];
1529
1530 /*                 Set up right hand side(s) */
1531
1532                     rhs[0] = c__[is + js * c_dim1];
1533                     rhs[1] = c__[isp1 + js * c_dim1];
1534                     rhs[2] = f[is + js * f_dim1];
1535                     rhs[3] = f[isp1 + js * f_dim1];
1536
1537 /*                 Solve Z**T * x = RHS */
1538
1539                     dgetc2_(&zdim, z__, &c__8, ipiv, jpiv, &ierr);
1540                     if (ierr > 0) {
1541                         *info = ierr;
1542                     }
1543
1544                     dgesc2_(&zdim, z__, &c__8, rhs, ipiv, jpiv, &scaloc);
1545                     if (scaloc != 1.) {
1546                         i__3 = *n;
1547                         for (k = 1; k <= i__3; ++k) {
1548                             dscal_(m, &scaloc, &c__[k * c_dim1 + 1], &c__1);
1549                             dscal_(m, &scaloc, &f[k * f_dim1 + 1], &c__1);
1550 /* L150: */
1551                         }
1552                         *scale *= scaloc;
1553                     }
1554
1555 /*                 Unpack solution vector(s) */
1556
1557                     c__[is + js * c_dim1] = rhs[0];
1558                     c__[isp1 + js * c_dim1] = rhs[1];
1559                     f[is + js * f_dim1] = rhs[2];
1560                     f[isp1 + js * f_dim1] = rhs[3];
1561
1562 /*                 Substitute R(I, J) and L(I, J) into remaining */
1563 /*                 equation. */
1564
1565                     if (j > p + 2) {
1566                         i__3 = js - 1;
1567                         dger_(&mb, &i__3, &c_b42, rhs, &c__1, &b[js * b_dim1 
1568                                 + 1], &c__1, &f[is + f_dim1], ldf);
1569                         i__3 = js - 1;
1570                         dger_(&mb, &i__3, &c_b42, &rhs[2], &c__1, &e[js * 
1571                                 e_dim1 + 1], &c__1, &f[is + f_dim1], ldf);
1572                     }
1573                     if (i__ < p) {
1574                         i__3 = *m - ie;
1575                         dgemv_("T", &mb, &i__3, &c_b27, &a[is + (ie + 1) * 
1576                                 a_dim1], lda, rhs, &c__1, &c_b42, &c__[ie + 1 
1577                                 + js * c_dim1], &c__1);
1578                         i__3 = *m - ie;
1579                         dgemv_("T", &mb, &i__3, &c_b27, &d__[is + (ie + 1) * 
1580                                 d_dim1], ldd, &rhs[2], &c__1, &c_b42, &c__[ie 
1581                                 + 1 + js * c_dim1], &c__1);
1582                     }
1583
1584                 } else if (mb == 2 && nb == 2) {
1585
1586 /*                 Build an 8-by-8 system Z**T * x = RHS */
1587
1588                     dlaset_("F", &c__8, &c__8, &c_b56, &c_b56, z__, &c__8);
1589
1590                     z__[0] = a[is + is * a_dim1];
1591                     z__[1] = a[is + isp1 * a_dim1];
1592                     z__[4] = -b[js + js * b_dim1];
1593                     z__[6] = -b[jsp1 + js * b_dim1];
1594
1595                     z__[8] = a[isp1 + is * a_dim1];
1596                     z__[9] = a[isp1 + isp1 * a_dim1];
1597                     z__[13] = -b[js + js * b_dim1];
1598                     z__[15] = -b[jsp1 + js * b_dim1];
1599
1600                     z__[18] = a[is + is * a_dim1];
1601                     z__[19] = a[is + isp1 * a_dim1];
1602                     z__[20] = -b[js + jsp1 * b_dim1];
1603                     z__[22] = -b[jsp1 + jsp1 * b_dim1];
1604
1605                     z__[26] = a[isp1 + is * a_dim1];
1606                     z__[27] = a[isp1 + isp1 * a_dim1];
1607                     z__[29] = -b[js + jsp1 * b_dim1];
1608                     z__[31] = -b[jsp1 + jsp1 * b_dim1];
1609
1610                     z__[32] = d__[is + is * d_dim1];
1611                     z__[33] = d__[is + isp1 * d_dim1];
1612                     z__[36] = -e[js + js * e_dim1];
1613
1614                     z__[41] = d__[isp1 + isp1 * d_dim1];
1615                     z__[45] = -e[js + js * e_dim1];
1616
1617                     z__[50] = d__[is + is * d_dim1];
1618                     z__[51] = d__[is + isp1 * d_dim1];
1619                     z__[52] = -e[js + jsp1 * e_dim1];
1620                     z__[54] = -e[jsp1 + jsp1 * e_dim1];
1621
1622                     z__[59] = d__[isp1 + isp1 * d_dim1];
1623                     z__[61] = -e[js + jsp1 * e_dim1];
1624                     z__[63] = -e[jsp1 + jsp1 * e_dim1];
1625
1626 /*                 Set up right hand side(s) */
1627
1628                     k = 1;
1629                     ii = mb * nb + 1;
1630                     i__3 = nb - 1;
1631                     for (jj = 0; jj <= i__3; ++jj) {
1632                         dcopy_(&mb, &c__[is + (js + jj) * c_dim1], &c__1, &
1633                                 rhs[k - 1], &c__1);
1634                         dcopy_(&mb, &f[is + (js + jj) * f_dim1], &c__1, &rhs[
1635                                 ii - 1], &c__1);
1636                         k += mb;
1637                         ii += mb;
1638 /* L160: */
1639                     }
1640
1641
1642 /*                 Solve Z**T * x = RHS */
1643
1644                     dgetc2_(&zdim, z__, &c__8, ipiv, jpiv, &ierr);
1645                     if (ierr > 0) {
1646                         *info = ierr;
1647                     }
1648
1649                     dgesc2_(&zdim, z__, &c__8, rhs, ipiv, jpiv, &scaloc);
1650                     if (scaloc != 1.) {
1651                         i__3 = *n;
1652                         for (k = 1; k <= i__3; ++k) {
1653                             dscal_(m, &scaloc, &c__[k * c_dim1 + 1], &c__1);
1654                             dscal_(m, &scaloc, &f[k * f_dim1 + 1], &c__1);
1655 /* L170: */
1656                         }
1657                         *scale *= scaloc;
1658                     }
1659
1660 /*                 Unpack solution vector(s) */
1661
1662                     k = 1;
1663                     ii = mb * nb + 1;
1664                     i__3 = nb - 1;
1665                     for (jj = 0; jj <= i__3; ++jj) {
1666                         dcopy_(&mb, &rhs[k - 1], &c__1, &c__[is + (js + jj) * 
1667                                 c_dim1], &c__1);
1668                         dcopy_(&mb, &rhs[ii - 1], &c__1, &f[is + (js + jj) * 
1669                                 f_dim1], &c__1);
1670                         k += mb;
1671                         ii += mb;
1672 /* L180: */
1673                     }
1674
1675 /*                 Substitute R(I, J) and L(I, J) into remaining */
1676 /*                 equation. */
1677
1678                     if (j > p + 2) {
1679                         i__3 = js - 1;
1680                         dgemm_("N", "T", &mb, &i__3, &nb, &c_b42, &c__[is + 
1681                                 js * c_dim1], ldc, &b[js * b_dim1 + 1], ldb, &
1682                                 c_b42, &f[is + f_dim1], ldf);
1683                         i__3 = js - 1;
1684                         dgemm_("N", "T", &mb, &i__3, &nb, &c_b42, &f[is + js *
1685                                  f_dim1], ldf, &e[js * e_dim1 + 1], lde, &
1686                                 c_b42, &f[is + f_dim1], ldf);
1687                     }
1688                     if (i__ < p) {
1689                         i__3 = *m - ie;
1690                         dgemm_("T", "N", &i__3, &nb, &mb, &c_b27, &a[is + (ie 
1691                                 + 1) * a_dim1], lda, &c__[is + js * c_dim1], 
1692                                 ldc, &c_b42, &c__[ie + 1 + js * c_dim1], ldc);
1693                         i__3 = *m - ie;
1694                         dgemm_("T", "N", &i__3, &nb, &mb, &c_b27, &d__[is + (
1695                                 ie + 1) * d_dim1], ldd, &f[is + js * f_dim1], 
1696                                 ldf, &c_b42, &c__[ie + 1 + js * c_dim1], ldc);
1697                     }
1698
1699                 }
1700
1701 /* L190: */
1702             }
1703 /* L200: */
1704         }
1705
1706     }
1707     return 0;
1708
1709 /*     End of DTGSY2 */
1710
1711 } /* dtgsy2_ */
1712