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