You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

stgsy2.c 49 kB

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