C_LAPACK: Fixes to make it compile with MSVC (#3605)
[platform/upstream/openblas.git] / lapack-netlib / SRC / stgsy2.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 real c_b27 = -1.f;
518 static real c_b42 = 1.f;
519 static real c_b56 = 0.f;
520
521 /* > \brief \b STGSY2 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 STGSY2 + dependencies */
530 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/stgsy2.
531 f"> */
532 /* > [TGZ]</a> */
533 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/stgsy2.
534 f"> */
535 /* > [ZIP]</a> */
536 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/stgsy2.
537 f"> */
538 /* > [TXT]</a> */
539 /* > \endhtmlonly */
540
541 /*  Definition: */
542 /*  =========== */
543
544 /*       SUBROUTINE STGSY2( 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 /*       REAL               RDSCAL, RDSUM, SCALE */
552 /*       INTEGER            IWORK( * ) */
553 /*       REAL               A( LDA, * ), B( LDB, * ), C( LDC, * ), */
554 /*      $                   D( LDD, * ), E( LDE, * ), F( LDF, * ) */
555
556
557 /* > \par Purpose: */
558 /*  ============= */
559 /* > */
560 /* > \verbatim */
561 /* > */
562 /* > STGSY2 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 SLACON. */
594 /* > */
595 /* > STGSY2 also (IJOB >= 1) contributes to the computation in STGSYL */
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 /* > STGSYL. See STGSYL 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. (SGECON 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 REAL 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 REAL 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 REAL 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 REAL 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 REAL 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 REAL 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 REAL */
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 REAL */
731 /* >          On entry, the sum of squares of computed contributions to */
732 /* >          the Dif-estimate under computation by STGSYL, 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 STGSY2 is called by STGSYL. */
738 /* > \endverbatim */
739 /* > */
740 /* > \param[in,out] RDSCAL */
741 /* > \verbatim */
742 /* >          RDSCAL is REAL */
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 STGSY2 is called by */
748 /* >                STGSYL. */
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 realSYauxiliary */
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 stgsy2_(char *trans, integer *ijob, integer *m, integer *
793         n, real *a, integer *lda, real *b, integer *ldb, real *c__, integer *
794         ldc, real *d__, integer *ldd, real *e, integer *lde, real *f, integer 
795         *ldf, real *scale, real *rdsum, real *rdscal, integer *iwork, integer 
796         *pq, integer *info)
797 {
798     /* System generated locals */
799     integer a_dim1, a_offset, b_dim1, b_offset, c_dim1, c_offset, d_dim1, 
800             d_offset, e_dim1, e_offset, f_dim1, f_offset, i__1, i__2, i__3;
801
802     /* Local variables */
803     extern /* Subroutine */ int sger_(integer *, integer *, real *, real *, 
804             integer *, real *, integer *, real *, integer *);
805     integer ierr, zdim, ipiv[8], jpiv[8], i__, j, k, p, q;
806     real alpha, z__[64] /* was [8][8] */;
807     extern logical lsame_(char *, char *);
808     extern /* Subroutine */ int sscal_(integer *, real *, real *, integer *), 
809             sgemm_(char *, char *, integer *, integer *, integer *, real *, 
810             real *, integer *, real *, integer *, real *, real *, integer *), sgemv_(char *, integer *, integer *, real *, 
811             real *, integer *, real *, integer *, real *, real *, integer *), scopy_(integer *, real *, integer *, real *, integer *), 
812             saxpy_(integer *, real *, real *, integer *, real *, integer *), 
813             sgesc2_(integer *, real *, integer *, real *, integer *, integer *
814             , real *), sgetc2_(integer *, real *, integer *, integer *, 
815             integer *, integer *);
816     integer ie, je, mb, nb, ii, jj, is, js;
817     real scaloc;
818     extern /* Subroutine */ int slatdf_(integer *, integer *, real *, integer 
819             *, real *, real *, real *, integer *, integer *), xerbla_(char *, 
820             integer *, ftnlen), slaset_(char *, integer *, integer *, real *, 
821             real *, real *, integer *);
822     logical notran;
823     real rhs[8];
824     integer isp1, jsp1;
825
826
827 /*  -- LAPACK auxiliary routine (version 3.7.0) -- */
828 /*  -- LAPACK is a software package provided by Univ. of Tennessee,    -- */
829 /*  -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
830 /*     December 2016 */
831
832
833 /*  ===================================================================== */
834 /*  Replaced various illegal calls to SCOPY by calls to SLASET. */
835 /*  Sven Hammarling, 27/5/02. */
836
837
838 /*     Decode and test input parameters */
839
840     /* Parameter adjustments */
841     a_dim1 = *lda;
842     a_offset = 1 + a_dim1 * 1;
843     a -= a_offset;
844     b_dim1 = *ldb;
845     b_offset = 1 + b_dim1 * 1;
846     b -= b_offset;
847     c_dim1 = *ldc;
848     c_offset = 1 + c_dim1 * 1;
849     c__ -= c_offset;
850     d_dim1 = *ldd;
851     d_offset = 1 + d_dim1 * 1;
852     d__ -= d_offset;
853     e_dim1 = *lde;
854     e_offset = 1 + e_dim1 * 1;
855     e -= e_offset;
856     f_dim1 = *ldf;
857     f_offset = 1 + f_dim1 * 1;
858     f -= f_offset;
859     --iwork;
860
861     /* Function Body */
862     *info = 0;
863     ierr = 0;
864     notran = lsame_(trans, "N");
865     if (! notran && ! lsame_(trans, "T")) {
866         *info = -1;
867     } else if (notran) {
868         if (*ijob < 0 || *ijob > 2) {
869             *info = -2;
870         }
871     }
872     if (*info == 0) {
873         if (*m <= 0) {
874             *info = -3;
875         } else if (*n <= 0) {
876             *info = -4;
877         } else if (*lda < f2cmax(1,*m)) {
878             *info = -6;
879         } else if (*ldb < f2cmax(1,*n)) {
880             *info = -8;
881         } else if (*ldc < f2cmax(1,*m)) {
882             *info = -10;
883         } else if (*ldd < f2cmax(1,*m)) {
884             *info = -12;
885         } else if (*lde < f2cmax(1,*n)) {
886             *info = -14;
887         } else if (*ldf < f2cmax(1,*m)) {
888             *info = -16;
889         }
890     }
891     if (*info != 0) {
892         i__1 = -(*info);
893         xerbla_("STGSY2", &i__1, (ftnlen)6);
894         return 0;
895     }
896
897 /*     Determine block structure of A */
898
899     *pq = 0;
900     p = 0;
901     i__ = 1;
902 L10:
903     if (i__ > *m) {
904         goto L20;
905     }
906     ++p;
907     iwork[p] = i__;
908     if (i__ == *m) {
909         goto L20;
910     }
911     if (a[i__ + 1 + i__ * a_dim1] != 0.f) {
912         i__ += 2;
913     } else {
914         ++i__;
915     }
916     goto L10;
917 L20:
918     iwork[p + 1] = *m + 1;
919
920 /*     Determine block structure of B */
921
922     q = p + 1;
923     j = 1;
924 L30:
925     if (j > *n) {
926         goto L40;
927     }
928     ++q;
929     iwork[q] = j;
930     if (j == *n) {
931         goto L40;
932     }
933     if (b[j + 1 + j * b_dim1] != 0.f) {
934         j += 2;
935     } else {
936         ++j;
937     }
938     goto L30;
939 L40:
940     iwork[q + 1] = *n + 1;
941     *pq = p * (q - p - 1);
942
943     if (notran) {
944
945 /*        Solve (I, J) - subsystem */
946 /*           A(I, I) * R(I, J) - L(I, J) * B(J, J) = C(I, J) */
947 /*           D(I, I) * R(I, J) - L(I, J) * E(J, J) = F(I, J) */
948 /*        for I = P, P - 1, ..., 1; J = 1, 2, ..., Q */
949
950         *scale = 1.f;
951         scaloc = 1.f;
952         i__1 = q;
953         for (j = p + 2; j <= i__1; ++j) {
954             js = iwork[j];
955             jsp1 = js + 1;
956             je = iwork[j + 1] - 1;
957             nb = je - js + 1;
958             for (i__ = p; i__ >= 1; --i__) {
959
960                 is = iwork[i__];
961                 isp1 = is + 1;
962                 ie = iwork[i__ + 1] - 1;
963                 mb = ie - is + 1;
964                 zdim = mb * nb << 1;
965
966                 if (mb == 1 && nb == 1) {
967
968 /*                 Build a 2-by-2 system Z * x = RHS */
969
970                     z__[0] = a[is + is * a_dim1];
971                     z__[1] = d__[is + is * d_dim1];
972                     z__[8] = -b[js + js * b_dim1];
973                     z__[9] = -e[js + js * e_dim1];
974
975 /*                 Set up right hand side(s) */
976
977                     rhs[0] = c__[is + js * c_dim1];
978                     rhs[1] = f[is + js * f_dim1];
979
980 /*                 Solve Z * x = RHS */
981
982                     sgetc2_(&zdim, z__, &c__8, ipiv, jpiv, &ierr);
983                     if (ierr > 0) {
984                         *info = ierr;
985                     }
986
987                     if (*ijob == 0) {
988                         sgesc2_(&zdim, z__, &c__8, rhs, ipiv, jpiv, &scaloc);
989                         if (scaloc != 1.f) {
990                             i__2 = *n;
991                             for (k = 1; k <= i__2; ++k) {
992                                 sscal_(m, &scaloc, &c__[k * c_dim1 + 1], &
993                                         c__1);
994                                 sscal_(m, &scaloc, &f[k * f_dim1 + 1], &c__1);
995 /* L50: */
996                             }
997                             *scale *= scaloc;
998                         }
999                     } else {
1000                         slatdf_(ijob, &zdim, z__, &c__8, rhs, rdsum, rdscal, 
1001                                 ipiv, jpiv);
1002                     }
1003
1004 /*                 Unpack solution vector(s) */
1005
1006                     c__[is + js * c_dim1] = rhs[0];
1007                     f[is + js * f_dim1] = rhs[1];
1008
1009 /*                 Substitute R(I, J) and L(I, J) into remaining */
1010 /*                 equation. */
1011
1012                     if (i__ > 1) {
1013                         alpha = -rhs[0];
1014                         i__2 = is - 1;
1015                         saxpy_(&i__2, &alpha, &a[is * a_dim1 + 1], &c__1, &
1016                                 c__[js * c_dim1 + 1], &c__1);
1017                         i__2 = is - 1;
1018                         saxpy_(&i__2, &alpha, &d__[is * d_dim1 + 1], &c__1, &
1019                                 f[js * f_dim1 + 1], &c__1);
1020                     }
1021                     if (j < q) {
1022                         i__2 = *n - je;
1023                         saxpy_(&i__2, &rhs[1], &b[js + (je + 1) * b_dim1], 
1024                                 ldb, &c__[is + (je + 1) * c_dim1], ldc);
1025                         i__2 = *n - je;
1026                         saxpy_(&i__2, &rhs[1], &e[js + (je + 1) * e_dim1], 
1027                                 lde, &f[is + (je + 1) * f_dim1], ldf);
1028                     }
1029
1030                 } else if (mb == 1 && nb == 2) {
1031
1032 /*                 Build a 4-by-4 system Z * x = RHS */
1033
1034                     z__[0] = a[is + is * a_dim1];
1035                     z__[1] = 0.f;
1036                     z__[2] = d__[is + is * d_dim1];
1037                     z__[3] = 0.f;
1038
1039                     z__[8] = 0.f;
1040                     z__[9] = a[is + is * a_dim1];
1041                     z__[10] = 0.f;
1042                     z__[11] = d__[is + is * d_dim1];
1043
1044                     z__[16] = -b[js + js * b_dim1];
1045                     z__[17] = -b[js + jsp1 * b_dim1];
1046                     z__[18] = -e[js + js * e_dim1];
1047                     z__[19] = -e[js + jsp1 * e_dim1];
1048
1049                     z__[24] = -b[jsp1 + js * b_dim1];
1050                     z__[25] = -b[jsp1 + jsp1 * b_dim1];
1051                     z__[26] = 0.f;
1052                     z__[27] = -e[jsp1 + jsp1 * e_dim1];
1053
1054 /*                 Set up right hand side(s) */
1055
1056                     rhs[0] = c__[is + js * c_dim1];
1057                     rhs[1] = c__[is + jsp1 * c_dim1];
1058                     rhs[2] = f[is + js * f_dim1];
1059                     rhs[3] = f[is + jsp1 * f_dim1];
1060
1061 /*                 Solve Z * x = RHS */
1062
1063                     sgetc2_(&zdim, z__, &c__8, ipiv, jpiv, &ierr);
1064                     if (ierr > 0) {
1065                         *info = ierr;
1066                     }
1067
1068                     if (*ijob == 0) {
1069                         sgesc2_(&zdim, z__, &c__8, rhs, ipiv, jpiv, &scaloc);
1070                         if (scaloc != 1.f) {
1071                             i__2 = *n;
1072                             for (k = 1; k <= i__2; ++k) {
1073                                 sscal_(m, &scaloc, &c__[k * c_dim1 + 1], &
1074                                         c__1);
1075                                 sscal_(m, &scaloc, &f[k * f_dim1 + 1], &c__1);
1076 /* L60: */
1077                             }
1078                             *scale *= scaloc;
1079                         }
1080                     } else {
1081                         slatdf_(ijob, &zdim, z__, &c__8, rhs, rdsum, rdscal, 
1082                                 ipiv, jpiv);
1083                     }
1084
1085 /*                 Unpack solution vector(s) */
1086
1087                     c__[is + js * c_dim1] = rhs[0];
1088                     c__[is + jsp1 * c_dim1] = rhs[1];
1089                     f[is + js * f_dim1] = rhs[2];
1090                     f[is + jsp1 * f_dim1] = rhs[3];
1091
1092 /*                 Substitute R(I, J) and L(I, J) into remaining */
1093 /*                 equation. */
1094
1095                     if (i__ > 1) {
1096                         i__2 = is - 1;
1097                         sger_(&i__2, &nb, &c_b27, &a[is * a_dim1 + 1], &c__1, 
1098                                 rhs, &c__1, &c__[js * c_dim1 + 1], ldc);
1099                         i__2 = is - 1;
1100                         sger_(&i__2, &nb, &c_b27, &d__[is * d_dim1 + 1], &
1101                                 c__1, rhs, &c__1, &f[js * f_dim1 + 1], ldf);
1102                     }
1103                     if (j < q) {
1104                         i__2 = *n - je;
1105                         saxpy_(&i__2, &rhs[2], &b[js + (je + 1) * b_dim1], 
1106                                 ldb, &c__[is + (je + 1) * c_dim1], ldc);
1107                         i__2 = *n - je;
1108                         saxpy_(&i__2, &rhs[2], &e[js + (je + 1) * e_dim1], 
1109                                 lde, &f[is + (je + 1) * f_dim1], ldf);
1110                         i__2 = *n - je;
1111                         saxpy_(&i__2, &rhs[3], &b[jsp1 + (je + 1) * b_dim1], 
1112                                 ldb, &c__[is + (je + 1) * c_dim1], ldc);
1113                         i__2 = *n - je;
1114                         saxpy_(&i__2, &rhs[3], &e[jsp1 + (je + 1) * e_dim1], 
1115                                 lde, &f[is + (je + 1) * f_dim1], ldf);
1116                     }
1117
1118                 } else if (mb == 2 && nb == 1) {
1119
1120 /*                 Build a 4-by-4 system Z * x = RHS */
1121
1122                     z__[0] = a[is + is * a_dim1];
1123                     z__[1] = a[isp1 + is * a_dim1];
1124                     z__[2] = d__[is + is * d_dim1];
1125                     z__[3] = 0.f;
1126
1127                     z__[8] = a[is + isp1 * a_dim1];
1128                     z__[9] = a[isp1 + isp1 * a_dim1];
1129                     z__[10] = d__[is + isp1 * d_dim1];
1130                     z__[11] = d__[isp1 + isp1 * d_dim1];
1131
1132                     z__[16] = -b[js + js * b_dim1];
1133                     z__[17] = 0.f;
1134                     z__[18] = -e[js + js * e_dim1];
1135                     z__[19] = 0.f;
1136
1137                     z__[24] = 0.f;
1138                     z__[25] = -b[js + js * b_dim1];
1139                     z__[26] = 0.f;
1140                     z__[27] = -e[js + js * e_dim1];
1141
1142 /*                 Set up right hand side(s) */
1143
1144                     rhs[0] = c__[is + js * c_dim1];
1145                     rhs[1] = c__[isp1 + js * c_dim1];
1146                     rhs[2] = f[is + js * f_dim1];
1147                     rhs[3] = f[isp1 + js * f_dim1];
1148
1149 /*                 Solve Z * x = RHS */
1150
1151                     sgetc2_(&zdim, z__, &c__8, ipiv, jpiv, &ierr);
1152                     if (ierr > 0) {
1153                         *info = ierr;
1154                     }
1155                     if (*ijob == 0) {
1156                         sgesc2_(&zdim, z__, &c__8, rhs, ipiv, jpiv, &scaloc);
1157                         if (scaloc != 1.f) {
1158                             i__2 = *n;
1159                             for (k = 1; k <= i__2; ++k) {
1160                                 sscal_(m, &scaloc, &c__[k * c_dim1 + 1], &
1161                                         c__1);
1162                                 sscal_(m, &scaloc, &f[k * f_dim1 + 1], &c__1);
1163 /* L70: */
1164                             }
1165                             *scale *= scaloc;
1166                         }
1167                     } else {
1168                         slatdf_(ijob, &zdim, z__, &c__8, rhs, rdsum, rdscal, 
1169                                 ipiv, jpiv);
1170                     }
1171
1172 /*                 Unpack solution vector(s) */
1173
1174                     c__[is + js * c_dim1] = rhs[0];
1175                     c__[isp1 + js * c_dim1] = rhs[1];
1176                     f[is + js * f_dim1] = rhs[2];
1177                     f[isp1 + js * f_dim1] = rhs[3];
1178
1179 /*                 Substitute R(I, J) and L(I, J) into remaining */
1180 /*                 equation. */
1181
1182                     if (i__ > 1) {
1183                         i__2 = is - 1;
1184                         sgemv_("N", &i__2, &mb, &c_b27, &a[is * a_dim1 + 1], 
1185                                 lda, rhs, &c__1, &c_b42, &c__[js * c_dim1 + 1]
1186                                 , &c__1);
1187                         i__2 = is - 1;
1188                         sgemv_("N", &i__2, &mb, &c_b27, &d__[is * d_dim1 + 1],
1189                                  ldd, rhs, &c__1, &c_b42, &f[js * f_dim1 + 1],
1190                                  &c__1);
1191                     }
1192                     if (j < q) {
1193                         i__2 = *n - je;
1194                         sger_(&mb, &i__2, &c_b42, &rhs[2], &c__1, &b[js + (je 
1195                                 + 1) * b_dim1], ldb, &c__[is + (je + 1) * 
1196                                 c_dim1], ldc);
1197                         i__2 = *n - je;
1198                         sger_(&mb, &i__2, &c_b42, &rhs[2], &c__1, &e[js + (je 
1199                                 + 1) * e_dim1], lde, &f[is + (je + 1) * 
1200                                 f_dim1], ldf);
1201                     }
1202
1203                 } else if (mb == 2 && nb == 2) {
1204
1205 /*                 Build an 8-by-8 system Z * x = RHS */
1206
1207                     slaset_("F", &c__8, &c__8, &c_b56, &c_b56, z__, &c__8);
1208
1209                     z__[0] = a[is + is * a_dim1];
1210                     z__[1] = a[isp1 + is * a_dim1];
1211                     z__[4] = d__[is + is * d_dim1];
1212
1213                     z__[8] = a[is + isp1 * a_dim1];
1214                     z__[9] = a[isp1 + isp1 * a_dim1];
1215                     z__[12] = d__[is + isp1 * d_dim1];
1216                     z__[13] = d__[isp1 + isp1 * d_dim1];
1217
1218                     z__[18] = a[is + is * a_dim1];
1219                     z__[19] = a[isp1 + is * a_dim1];
1220                     z__[22] = d__[is + is * d_dim1];
1221
1222                     z__[26] = a[is + isp1 * a_dim1];
1223                     z__[27] = a[isp1 + isp1 * a_dim1];
1224                     z__[30] = d__[is + isp1 * d_dim1];
1225                     z__[31] = d__[isp1 + isp1 * d_dim1];
1226
1227                     z__[32] = -b[js + js * b_dim1];
1228                     z__[34] = -b[js + jsp1 * b_dim1];
1229                     z__[36] = -e[js + js * e_dim1];
1230                     z__[38] = -e[js + jsp1 * e_dim1];
1231
1232                     z__[41] = -b[js + js * b_dim1];
1233                     z__[43] = -b[js + jsp1 * b_dim1];
1234                     z__[45] = -e[js + js * e_dim1];
1235                     z__[47] = -e[js + jsp1 * e_dim1];
1236
1237                     z__[48] = -b[jsp1 + js * b_dim1];
1238                     z__[50] = -b[jsp1 + jsp1 * b_dim1];
1239                     z__[54] = -e[jsp1 + jsp1 * e_dim1];
1240
1241                     z__[57] = -b[jsp1 + js * b_dim1];
1242                     z__[59] = -b[jsp1 + jsp1 * b_dim1];
1243                     z__[63] = -e[jsp1 + jsp1 * e_dim1];
1244
1245 /*                 Set up right hand side(s) */
1246
1247                     k = 1;
1248                     ii = mb * nb + 1;
1249                     i__2 = nb - 1;
1250                     for (jj = 0; jj <= i__2; ++jj) {
1251                         scopy_(&mb, &c__[is + (js + jj) * c_dim1], &c__1, &
1252                                 rhs[k - 1], &c__1);
1253                         scopy_(&mb, &f[is + (js + jj) * f_dim1], &c__1, &rhs[
1254                                 ii - 1], &c__1);
1255                         k += mb;
1256                         ii += mb;
1257 /* L80: */
1258                     }
1259
1260 /*                 Solve Z * x = RHS */
1261
1262                     sgetc2_(&zdim, z__, &c__8, ipiv, jpiv, &ierr);
1263                     if (ierr > 0) {
1264                         *info = ierr;
1265                     }
1266                     if (*ijob == 0) {
1267                         sgesc2_(&zdim, z__, &c__8, rhs, ipiv, jpiv, &scaloc);
1268                         if (scaloc != 1.f) {
1269                             i__2 = *n;
1270                             for (k = 1; k <= i__2; ++k) {
1271                                 sscal_(m, &scaloc, &c__[k * c_dim1 + 1], &
1272                                         c__1);
1273                                 sscal_(m, &scaloc, &f[k * f_dim1 + 1], &c__1);
1274 /* L90: */
1275                             }
1276                             *scale *= scaloc;
1277                         }
1278                     } else {
1279                         slatdf_(ijob, &zdim, z__, &c__8, rhs, rdsum, rdscal, 
1280                                 ipiv, jpiv);
1281                     }
1282
1283 /*                 Unpack solution vector(s) */
1284
1285                     k = 1;
1286                     ii = mb * nb + 1;
1287                     i__2 = nb - 1;
1288                     for (jj = 0; jj <= i__2; ++jj) {
1289                         scopy_(&mb, &rhs[k - 1], &c__1, &c__[is + (js + jj) * 
1290                                 c_dim1], &c__1);
1291                         scopy_(&mb, &rhs[ii - 1], &c__1, &f[is + (js + jj) * 
1292                                 f_dim1], &c__1);
1293                         k += mb;
1294                         ii += mb;
1295 /* L100: */
1296                     }
1297
1298 /*                 Substitute R(I, J) and L(I, J) into remaining */
1299 /*                 equation. */
1300
1301                     if (i__ > 1) {
1302                         i__2 = is - 1;
1303                         sgemm_("N", "N", &i__2, &nb, &mb, &c_b27, &a[is * 
1304                                 a_dim1 + 1], lda, rhs, &mb, &c_b42, &c__[js * 
1305                                 c_dim1 + 1], ldc);
1306                         i__2 = is - 1;
1307                         sgemm_("N", "N", &i__2, &nb, &mb, &c_b27, &d__[is * 
1308                                 d_dim1 + 1], ldd, rhs, &mb, &c_b42, &f[js * 
1309                                 f_dim1 + 1], ldf);
1310                     }
1311                     if (j < q) {
1312                         k = mb * nb + 1;
1313                         i__2 = *n - je;
1314                         sgemm_("N", "N", &mb, &i__2, &nb, &c_b42, &rhs[k - 1],
1315                                  &mb, &b[js + (je + 1) * b_dim1], ldb, &c_b42,
1316                                  &c__[is + (je + 1) * c_dim1], ldc);
1317                         i__2 = *n - je;
1318                         sgemm_("N", "N", &mb, &i__2, &nb, &c_b42, &rhs[k - 1],
1319                                  &mb, &e[js + (je + 1) * e_dim1], lde, &c_b42,
1320                                  &f[is + (je + 1) * f_dim1], ldf);
1321                     }
1322
1323                 }
1324
1325 /* L110: */
1326             }
1327 /* L120: */
1328         }
1329     } else {
1330
1331 /*        Solve (I, J) - subsystem */
1332 /*             A(I, I)**T * R(I, J) + D(I, I)**T * L(J, J)  =  C(I, J) */
1333 /*             R(I, I)  * B(J, J) + L(I, J)  * E(J, J)  = -F(I, J) */
1334 /*        for I = 1, 2, ..., P, J = Q, Q - 1, ..., 1 */
1335
1336         *scale = 1.f;
1337         scaloc = 1.f;
1338         i__1 = p;
1339         for (i__ = 1; i__ <= i__1; ++i__) {
1340
1341             is = iwork[i__];
1342             isp1 = is + 1;
1343             ie = iwork[i__ + 1] - 1;
1344             mb = ie - is + 1;
1345             i__2 = p + 2;
1346             for (j = q; j >= i__2; --j) {
1347
1348                 js = iwork[j];
1349                 jsp1 = js + 1;
1350                 je = iwork[j + 1] - 1;
1351                 nb = je - js + 1;
1352                 zdim = mb * nb << 1;
1353                 if (mb == 1 && nb == 1) {
1354
1355 /*                 Build a 2-by-2 system Z**T * x = RHS */
1356
1357                     z__[0] = a[is + is * a_dim1];
1358                     z__[1] = -b[js + js * b_dim1];
1359                     z__[8] = d__[is + is * d_dim1];
1360                     z__[9] = -e[js + js * e_dim1];
1361
1362 /*                 Set up right hand side(s) */
1363
1364                     rhs[0] = c__[is + js * c_dim1];
1365                     rhs[1] = f[is + js * f_dim1];
1366
1367 /*                 Solve Z**T * x = RHS */
1368
1369                     sgetc2_(&zdim, z__, &c__8, ipiv, jpiv, &ierr);
1370                     if (ierr > 0) {
1371                         *info = ierr;
1372                     }
1373
1374                     sgesc2_(&zdim, z__, &c__8, rhs, ipiv, jpiv, &scaloc);
1375                     if (scaloc != 1.f) {
1376                         i__3 = *n;
1377                         for (k = 1; k <= i__3; ++k) {
1378                             sscal_(m, &scaloc, &c__[k * c_dim1 + 1], &c__1);
1379                             sscal_(m, &scaloc, &f[k * f_dim1 + 1], &c__1);
1380 /* L130: */
1381                         }
1382                         *scale *= scaloc;
1383                     }
1384
1385 /*                 Unpack solution vector(s) */
1386
1387                     c__[is + js * c_dim1] = rhs[0];
1388                     f[is + js * f_dim1] = rhs[1];
1389
1390 /*                 Substitute R(I, J) and L(I, J) into remaining */
1391 /*                 equation. */
1392
1393                     if (j > p + 2) {
1394                         alpha = rhs[0];
1395                         i__3 = js - 1;
1396                         saxpy_(&i__3, &alpha, &b[js * b_dim1 + 1], &c__1, &f[
1397                                 is + f_dim1], ldf);
1398                         alpha = rhs[1];
1399                         i__3 = js - 1;
1400                         saxpy_(&i__3, &alpha, &e[js * e_dim1 + 1], &c__1, &f[
1401                                 is + f_dim1], ldf);
1402                     }
1403                     if (i__ < p) {
1404                         alpha = -rhs[0];
1405                         i__3 = *m - ie;
1406                         saxpy_(&i__3, &alpha, &a[is + (ie + 1) * a_dim1], lda,
1407                                  &c__[ie + 1 + js * c_dim1], &c__1);
1408                         alpha = -rhs[1];
1409                         i__3 = *m - ie;
1410                         saxpy_(&i__3, &alpha, &d__[is + (ie + 1) * d_dim1], 
1411                                 ldd, &c__[ie + 1 + js * c_dim1], &c__1);
1412                     }
1413
1414                 } else if (mb == 1 && nb == 2) {
1415
1416 /*                 Build a 4-by-4 system Z**T * x = RHS */
1417
1418                     z__[0] = a[is + is * a_dim1];
1419                     z__[1] = 0.f;
1420                     z__[2] = -b[js + js * b_dim1];
1421                     z__[3] = -b[jsp1 + js * b_dim1];
1422
1423                     z__[8] = 0.f;
1424                     z__[9] = a[is + is * a_dim1];
1425                     z__[10] = -b[js + jsp1 * b_dim1];
1426                     z__[11] = -b[jsp1 + jsp1 * b_dim1];
1427
1428                     z__[16] = d__[is + is * d_dim1];
1429                     z__[17] = 0.f;
1430                     z__[18] = -e[js + js * e_dim1];
1431                     z__[19] = 0.f;
1432
1433                     z__[24] = 0.f;
1434                     z__[25] = d__[is + is * d_dim1];
1435                     z__[26] = -e[js + jsp1 * e_dim1];
1436                     z__[27] = -e[jsp1 + jsp1 * e_dim1];
1437
1438 /*                 Set up right hand side(s) */
1439
1440                     rhs[0] = c__[is + js * c_dim1];
1441                     rhs[1] = c__[is + jsp1 * c_dim1];
1442                     rhs[2] = f[is + js * f_dim1];
1443                     rhs[3] = f[is + jsp1 * f_dim1];
1444
1445 /*                 Solve Z**T * x = RHS */
1446
1447                     sgetc2_(&zdim, z__, &c__8, ipiv, jpiv, &ierr);
1448                     if (ierr > 0) {
1449                         *info = ierr;
1450                     }
1451                     sgesc2_(&zdim, z__, &c__8, rhs, ipiv, jpiv, &scaloc);
1452                     if (scaloc != 1.f) {
1453                         i__3 = *n;
1454                         for (k = 1; k <= i__3; ++k) {
1455                             sscal_(m, &scaloc, &c__[k * c_dim1 + 1], &c__1);
1456                             sscal_(m, &scaloc, &f[k * f_dim1 + 1], &c__1);
1457 /* L140: */
1458                         }
1459                         *scale *= scaloc;
1460                     }
1461
1462 /*                 Unpack solution vector(s) */
1463
1464                     c__[is + js * c_dim1] = rhs[0];
1465                     c__[is + jsp1 * c_dim1] = rhs[1];
1466                     f[is + js * f_dim1] = rhs[2];
1467                     f[is + jsp1 * f_dim1] = rhs[3];
1468
1469 /*                 Substitute R(I, J) and L(I, J) into remaining */
1470 /*                 equation. */
1471
1472                     if (j > p + 2) {
1473                         i__3 = js - 1;
1474                         saxpy_(&i__3, rhs, &b[js * b_dim1 + 1], &c__1, &f[is 
1475                                 + f_dim1], ldf);
1476                         i__3 = js - 1;
1477                         saxpy_(&i__3, &rhs[1], &b[jsp1 * b_dim1 + 1], &c__1, &
1478                                 f[is + f_dim1], ldf);
1479                         i__3 = js - 1;
1480                         saxpy_(&i__3, &rhs[2], &e[js * e_dim1 + 1], &c__1, &f[
1481                                 is + f_dim1], ldf);
1482                         i__3 = js - 1;
1483                         saxpy_(&i__3, &rhs[3], &e[jsp1 * e_dim1 + 1], &c__1, &
1484                                 f[is + f_dim1], ldf);
1485                     }
1486                     if (i__ < p) {
1487                         i__3 = *m - ie;
1488                         sger_(&i__3, &nb, &c_b27, &a[is + (ie + 1) * a_dim1], 
1489                                 lda, rhs, &c__1, &c__[ie + 1 + js * c_dim1], 
1490                                 ldc);
1491                         i__3 = *m - ie;
1492                         sger_(&i__3, &nb, &c_b27, &d__[is + (ie + 1) * d_dim1]
1493                                 , ldd, &rhs[2], &c__1, &c__[ie + 1 + js * 
1494                                 c_dim1], ldc);
1495                     }
1496
1497                 } else if (mb == 2 && nb == 1) {
1498
1499 /*                 Build a 4-by-4 system Z**T * x = RHS */
1500
1501                     z__[0] = a[is + is * a_dim1];
1502                     z__[1] = a[is + isp1 * a_dim1];
1503                     z__[2] = -b[js + js * b_dim1];
1504                     z__[3] = 0.f;
1505
1506                     z__[8] = a[isp1 + is * a_dim1];
1507                     z__[9] = a[isp1 + isp1 * a_dim1];
1508                     z__[10] = 0.f;
1509                     z__[11] = -b[js + js * b_dim1];
1510
1511                     z__[16] = d__[is + is * d_dim1];
1512                     z__[17] = d__[is + isp1 * d_dim1];
1513                     z__[18] = -e[js + js * e_dim1];
1514                     z__[19] = 0.f;
1515
1516                     z__[24] = 0.f;
1517                     z__[25] = d__[isp1 + isp1 * d_dim1];
1518                     z__[26] = 0.f;
1519                     z__[27] = -e[js + js * e_dim1];
1520
1521 /*                 Set up right hand side(s) */
1522
1523                     rhs[0] = c__[is + js * c_dim1];
1524                     rhs[1] = c__[isp1 + js * c_dim1];
1525                     rhs[2] = f[is + js * f_dim1];
1526                     rhs[3] = f[isp1 + js * f_dim1];
1527
1528 /*                 Solve Z**T * x = RHS */
1529
1530                     sgetc2_(&zdim, z__, &c__8, ipiv, jpiv, &ierr);
1531                     if (ierr > 0) {
1532                         *info = ierr;
1533                     }
1534
1535                     sgesc2_(&zdim, z__, &c__8, rhs, ipiv, jpiv, &scaloc);
1536                     if (scaloc != 1.f) {
1537                         i__3 = *n;
1538                         for (k = 1; k <= i__3; ++k) {
1539                             sscal_(m, &scaloc, &c__[k * c_dim1 + 1], &c__1);
1540                             sscal_(m, &scaloc, &f[k * f_dim1 + 1], &c__1);
1541 /* L150: */
1542                         }
1543                         *scale *= scaloc;
1544                     }
1545
1546 /*                 Unpack solution vector(s) */
1547
1548                     c__[is + js * c_dim1] = rhs[0];
1549                     c__[isp1 + js * c_dim1] = rhs[1];
1550                     f[is + js * f_dim1] = rhs[2];
1551                     f[isp1 + js * f_dim1] = rhs[3];
1552
1553 /*                 Substitute R(I, J) and L(I, J) into remaining */
1554 /*                 equation. */
1555
1556                     if (j > p + 2) {
1557                         i__3 = js - 1;
1558                         sger_(&mb, &i__3, &c_b42, rhs, &c__1, &b[js * b_dim1 
1559                                 + 1], &c__1, &f[is + f_dim1], ldf);
1560                         i__3 = js - 1;
1561                         sger_(&mb, &i__3, &c_b42, &rhs[2], &c__1, &e[js * 
1562                                 e_dim1 + 1], &c__1, &f[is + f_dim1], ldf);
1563                     }
1564                     if (i__ < p) {
1565                         i__3 = *m - ie;
1566                         sgemv_("T", &mb, &i__3, &c_b27, &a[is + (ie + 1) * 
1567                                 a_dim1], lda, rhs, &c__1, &c_b42, &c__[ie + 1 
1568                                 + js * c_dim1], &c__1);
1569                         i__3 = *m - ie;
1570                         sgemv_("T", &mb, &i__3, &c_b27, &d__[is + (ie + 1) * 
1571                                 d_dim1], ldd, &rhs[2], &c__1, &c_b42, &c__[ie 
1572                                 + 1 + js * c_dim1], &c__1);
1573                     }
1574
1575                 } else if (mb == 2 && nb == 2) {
1576
1577 /*                 Build an 8-by-8 system Z**T * x = RHS */
1578
1579                     slaset_("F", &c__8, &c__8, &c_b56, &c_b56, z__, &c__8);
1580
1581                     z__[0] = a[is + is * a_dim1];
1582                     z__[1] = a[is + isp1 * a_dim1];
1583                     z__[4] = -b[js + js * b_dim1];
1584                     z__[6] = -b[jsp1 + js * b_dim1];
1585
1586                     z__[8] = a[isp1 + is * a_dim1];
1587                     z__[9] = a[isp1 + isp1 * a_dim1];
1588                     z__[13] = -b[js + js * b_dim1];
1589                     z__[15] = -b[jsp1 + js * b_dim1];
1590
1591                     z__[18] = a[is + is * a_dim1];
1592                     z__[19] = a[is + isp1 * a_dim1];
1593                     z__[20] = -b[js + jsp1 * b_dim1];
1594                     z__[22] = -b[jsp1 + jsp1 * b_dim1];
1595
1596                     z__[26] = a[isp1 + is * a_dim1];
1597                     z__[27] = a[isp1 + isp1 * a_dim1];
1598                     z__[29] = -b[js + jsp1 * b_dim1];
1599                     z__[31] = -b[jsp1 + jsp1 * b_dim1];
1600
1601                     z__[32] = d__[is + is * d_dim1];
1602                     z__[33] = d__[is + isp1 * d_dim1];
1603                     z__[36] = -e[js + js * e_dim1];
1604
1605                     z__[41] = d__[isp1 + isp1 * d_dim1];
1606                     z__[45] = -e[js + js * e_dim1];
1607
1608                     z__[50] = d__[is + is * d_dim1];
1609                     z__[51] = d__[is + isp1 * d_dim1];
1610                     z__[52] = -e[js + jsp1 * e_dim1];
1611                     z__[54] = -e[jsp1 + jsp1 * e_dim1];
1612
1613                     z__[59] = d__[isp1 + isp1 * d_dim1];
1614                     z__[61] = -e[js + jsp1 * e_dim1];
1615                     z__[63] = -e[jsp1 + jsp1 * e_dim1];
1616
1617 /*                 Set up right hand side(s) */
1618
1619                     k = 1;
1620                     ii = mb * nb + 1;
1621                     i__3 = nb - 1;
1622                     for (jj = 0; jj <= i__3; ++jj) {
1623                         scopy_(&mb, &c__[is + (js + jj) * c_dim1], &c__1, &
1624                                 rhs[k - 1], &c__1);
1625                         scopy_(&mb, &f[is + (js + jj) * f_dim1], &c__1, &rhs[
1626                                 ii - 1], &c__1);
1627                         k += mb;
1628                         ii += mb;
1629 /* L160: */
1630                     }
1631
1632
1633 /*                 Solve Z**T * x = RHS */
1634
1635                     sgetc2_(&zdim, z__, &c__8, ipiv, jpiv, &ierr);
1636                     if (ierr > 0) {
1637                         *info = ierr;
1638                     }
1639
1640                     sgesc2_(&zdim, z__, &c__8, rhs, ipiv, jpiv, &scaloc);
1641                     if (scaloc != 1.f) {
1642                         i__3 = *n;
1643                         for (k = 1; k <= i__3; ++k) {
1644                             sscal_(m, &scaloc, &c__[k * c_dim1 + 1], &c__1);
1645                             sscal_(m, &scaloc, &f[k * f_dim1 + 1], &c__1);
1646 /* L170: */
1647                         }
1648                         *scale *= scaloc;
1649                     }
1650
1651 /*                 Unpack solution vector(s) */
1652
1653                     k = 1;
1654                     ii = mb * nb + 1;
1655                     i__3 = nb - 1;
1656                     for (jj = 0; jj <= i__3; ++jj) {
1657                         scopy_(&mb, &rhs[k - 1], &c__1, &c__[is + (js + jj) * 
1658                                 c_dim1], &c__1);
1659                         scopy_(&mb, &rhs[ii - 1], &c__1, &f[is + (js + jj) * 
1660                                 f_dim1], &c__1);
1661                         k += mb;
1662                         ii += mb;
1663 /* L180: */
1664                     }
1665
1666 /*                 Substitute R(I, J) and L(I, J) into remaining */
1667 /*                 equation. */
1668
1669                     if (j > p + 2) {
1670                         i__3 = js - 1;
1671                         sgemm_("N", "T", &mb, &i__3, &nb, &c_b42, &c__[is + 
1672                                 js * c_dim1], ldc, &b[js * b_dim1 + 1], ldb, &
1673                                 c_b42, &f[is + f_dim1], ldf);
1674                         i__3 = js - 1;
1675                         sgemm_("N", "T", &mb, &i__3, &nb, &c_b42, &f[is + js *
1676                                  f_dim1], ldf, &e[js * e_dim1 + 1], lde, &
1677                                 c_b42, &f[is + f_dim1], ldf);
1678                     }
1679                     if (i__ < p) {
1680                         i__3 = *m - ie;
1681                         sgemm_("T", "N", &i__3, &nb, &mb, &c_b27, &a[is + (ie 
1682                                 + 1) * a_dim1], lda, &c__[is + js * c_dim1], 
1683                                 ldc, &c_b42, &c__[ie + 1 + js * c_dim1], ldc);
1684                         i__3 = *m - ie;
1685                         sgemm_("T", "N", &i__3, &nb, &mb, &c_b27, &d__[is + (
1686                                 ie + 1) * d_dim1], ldd, &f[is + js * f_dim1], 
1687                                 ldf, &c_b42, &c__[ie + 1 + js * c_dim1], ldc);
1688                     }
1689
1690                 }
1691
1692 /* L190: */
1693             }
1694 /* L200: */
1695         }
1696
1697     }
1698     return 0;
1699
1700 /*     End of STGSY2 */
1701
1702 } /* stgsy2_ */
1703