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.

ctrsyl3.c 60 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022
  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]/Cd(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. #define myexp_(w) my_expfunc(w)
  239. static int my_expfunc(float *x) {int e; (void)frexpf(*x,&e); return e;}
  240. /* procedure parameter types for -A and -C++ */
  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 complex c_b1 = {1.f,0.f};
  487. static integer c__1 = 1;
  488. static integer c_n1 = -1;
  489. static real c_b18 = 2.f;
  490. static real c_b106 = 1.f;
  491. /* > \brief \b CTRSYL3 */
  492. /* Definition: */
  493. /* =========== */
  494. /* > \par Purpose */
  495. /* ============= */
  496. /* > */
  497. /* > \verbatim */
  498. /* > */
  499. /* > CTRSYL3 solves the complex Sylvester matrix equation: */
  500. /* > */
  501. /* > op(A)*X + X*op(B) = scale*C or */
  502. /* > op(A)*X - X*op(B) = scale*C, */
  503. /* > */
  504. /* > where op(A) = A or A**H, and A and B are both upper triangular. A is */
  505. /* > M-by-M and B is N-by-N; the right hand side C and the solution X are */
  506. /* > M-by-N; and scale is an output scale factor, set <= 1 to avoid */
  507. /* > overflow in X. */
  508. /* > */
  509. /* > This is the block version of the algorithm. */
  510. /* > \endverbatim */
  511. /* Arguments */
  512. /* ========= */
  513. /* > \param[in] TRANA */
  514. /* > \verbatim */
  515. /* > TRANA is CHARACTER*1 */
  516. /* > Specifies the option op(A): */
  517. /* > = 'N': op(A) = A (No transpose) */
  518. /* > = 'C': op(A) = A**H (Conjugate transpose) */
  519. /* > \endverbatim */
  520. /* > */
  521. /* > \param[in] TRANB */
  522. /* > \verbatim */
  523. /* > TRANB is CHARACTER*1 */
  524. /* > Specifies the option op(B): */
  525. /* > = 'N': op(B) = B (No transpose) */
  526. /* > = 'C': op(B) = B**H (Conjugate transpose) */
  527. /* > \endverbatim */
  528. /* > */
  529. /* > \param[in] ISGN */
  530. /* > \verbatim */
  531. /* > ISGN is INTEGER */
  532. /* > Specifies the sign in the equation: */
  533. /* > = +1: solve op(A)*X + X*op(B) = scale*C */
  534. /* > = -1: solve op(A)*X - X*op(B) = scale*C */
  535. /* > \endverbatim */
  536. /* > */
  537. /* > \param[in] M */
  538. /* > \verbatim */
  539. /* > M is INTEGER */
  540. /* > The order of the matrix A, and the number of rows in the */
  541. /* > matrices X and C. M >= 0. */
  542. /* > \endverbatim */
  543. /* > */
  544. /* > \param[in] N */
  545. /* > \verbatim */
  546. /* > N is INTEGER */
  547. /* > The order of the matrix B, and the number of columns in the */
  548. /* > matrices X and C. N >= 0. */
  549. /* > \endverbatim */
  550. /* > */
  551. /* > \param[in] A */
  552. /* > \verbatim */
  553. /* > A is COMPLEX array, dimension (LDA,M) */
  554. /* > The upper triangular matrix A. */
  555. /* > \endverbatim */
  556. /* > */
  557. /* > \param[in] LDA */
  558. /* > \verbatim */
  559. /* > LDA is INTEGER */
  560. /* > The leading dimension of the array A. LDA >= f2cmax(1,M). */
  561. /* > \endverbatim */
  562. /* > */
  563. /* > \param[in] B */
  564. /* > \verbatim */
  565. /* > B is COMPLEX array, dimension (LDB,N) */
  566. /* > The upper triangular matrix B. */
  567. /* > \endverbatim */
  568. /* > */
  569. /* > \param[in] LDB */
  570. /* > \verbatim */
  571. /* > LDB is INTEGER */
  572. /* > The leading dimension of the array B. LDB >= f2cmax(1,N). */
  573. /* > \endverbatim */
  574. /* > */
  575. /* > \param[in,out] C */
  576. /* > \verbatim */
  577. /* > C is COMPLEX array, dimension (LDC,N) */
  578. /* > On entry, the M-by-N right hand side matrix C. */
  579. /* > On exit, C is overwritten by the solution matrix X. */
  580. /* > \endverbatim */
  581. /* > */
  582. /* > \param[in] LDC */
  583. /* > \verbatim */
  584. /* > LDC is INTEGER */
  585. /* > The leading dimension of the array C. LDC >= f2cmax(1,M) */
  586. /* > \endverbatim */
  587. /* > */
  588. /* > \param[out] SCALE */
  589. /* > \verbatim */
  590. /* > SCALE is REAL */
  591. /* > The scale factor, scale, set <= 1 to avoid overflow in X. */
  592. /* > \endverbatim */
  593. /* > */
  594. /* > \param[out] SWORK */
  595. /* > \verbatim */
  596. /* > SWORK is REAL array, dimension (MAX(2, ROWS), MAX(1,COLS)). */
  597. /* > On exit, if INFO = 0, SWORK(1) returns the optimal value ROWS */
  598. /* > and SWORK(2) returns the optimal COLS. */
  599. /* > \endverbatim */
  600. /* > */
  601. /* > \param[in] LDSWORK */
  602. /* > \verbatim */
  603. /* > LDSWORK is INTEGER */
  604. /* > LDSWORK >= MAX(2,ROWS), where ROWS = ((M + NB - 1) / NB + 1) */
  605. /* > and NB is the optimal block size. */
  606. /* > */
  607. /* > If LDSWORK = -1, then a workspace query is assumed; the routine */
  608. /* > only calculates the optimal dimensions of the SWORK matrix, */
  609. /* > returns these values as the first and second entry of the SWORK */
  610. /* > matrix, and no error message related LWORK is issued by XERBLA. */
  611. /* > \endverbatim */
  612. /* > */
  613. /* > \param[out] INFO */
  614. /* > \verbatim */
  615. /* > INFO is INTEGER */
  616. /* > = 0: successful exit */
  617. /* > < 0: if INFO = -i, the i-th argument had an illegal value */
  618. /* > = 1: A and B have common or very close eigenvalues; perturbed */
  619. /* > values were used to solve the equation (but the matrices */
  620. /* > A and B are unchanged). */
  621. /* > \endverbatim */
  622. /* > \ingroup complexSYcomputational */
  623. /* ===================================================================== */
  624. /* References: */
  625. /* E. S. Quintana-Orti and R. A. Van De Geijn (2003). Formal derivation of */
  626. /* algorithms: The triangular Sylvester equation, ACM Transactions */
  627. /* on Mathematical Software (TOMS), volume 29, pages 218--243. */
  628. /* A. Schwarz and C. C. Kjelgaard Mikkelsen (2020). Robust Task-Parallel */
  629. /* Solution of the Triangular Sylvester Equation. Lecture Notes in */
  630. /* Computer Science, vol 12043, pages 82--92, Springer. */
  631. /* Contributor: */
  632. /* Angelika Schwarz, Umea University, Sweden. */
  633. /* ===================================================================== */
  634. /* Subroutine */ void ctrsyl3_(char *trana, char *tranb, integer *isgn,
  635. integer *m, integer *n, complex *a, integer *lda, complex *b, integer
  636. *ldb, complex *c__, integer *ldc, real *scale, real *swork, integer *
  637. ldswork, integer *info)
  638. {
  639. /* System generated locals */
  640. integer a_dim1, a_offset, b_dim1, b_offset, c_dim1, c_offset, swork_dim1,
  641. swork_offset, i__1, i__2, i__3, i__4, i__5, i__6;
  642. real r__1, r__2, r__3, r__4;
  643. complex q__1;
  644. /* Local variables */
  645. real scal;
  646. complex csgn;
  647. real anrm, bnrm, cnrm;
  648. integer awrk, bwrk;
  649. real *wnrm, xnrm;
  650. integer i__, j, k, l;
  651. extern /* Subroutine */ void cgemm_(char *, char *, integer *, integer *,
  652. integer *, complex *, complex *, integer *, complex *, integer *,
  653. complex *, complex *, integer *);
  654. extern logical lsame_(char *, char *);
  655. integer iinfo, i1, i2, j1, j2, k1, k2, l1, l2;
  656. // extern integer myexp_(real *);
  657. integer nb, jj, ll;
  658. extern real clange_(char *, integer *, integer *, complex *, integer *,
  659. real *);
  660. extern /* Subroutine */ void clascl_(char *, integer *, integer *, real *,
  661. real *, integer *, integer *, complex *, integer *, integer *);
  662. real scaloc;
  663. extern real slamch_(char *);
  664. extern /* Subroutine */ void csscal_(integer *, real *, complex *, integer
  665. *);
  666. real scamin;
  667. extern /* Subroutine */ int xerbla_(char *, integer *, ftnlen );
  668. extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
  669. integer *, integer *, ftnlen, ftnlen);
  670. real bignum;
  671. extern real slarmm_(real *, real *, real *);
  672. logical notrna, notrnb;
  673. real smlnum;
  674. extern /* Subroutine */ void ctrsyl_(char *, char *, integer *, integer *,
  675. integer *, complex *, integer *, complex *, integer *, complex *,
  676. integer *, real *, integer *);
  677. logical lquery;
  678. integer nba, nbb;
  679. real buf, sgn;
  680. /* Decode and Test input parameters */
  681. /* Parameter adjustments */
  682. a_dim1 = *lda;
  683. a_offset = 1 + a_dim1 * 1;
  684. a -= a_offset;
  685. b_dim1 = *ldb;
  686. b_offset = 1 + b_dim1 * 1;
  687. b -= b_offset;
  688. c_dim1 = *ldc;
  689. c_offset = 1 + c_dim1 * 1;
  690. c__ -= c_offset;
  691. swork_dim1 = *ldswork;
  692. swork_offset = 1 + swork_dim1 * 1;
  693. swork -= swork_offset;
  694. /* Function Body */
  695. notrna = lsame_(trana, "N");
  696. notrnb = lsame_(tranb, "N");
  697. /* Use the same block size for all matrices. */
  698. /* Computing MAX */
  699. i__1 = 8, i__2 = ilaenv_(&c__1, "CTRSYL", "", m, n, &c_n1, &c_n1, (ftnlen)
  700. 6, (ftnlen)0);
  701. nb = f2cmax(i__1,i__2);
  702. /* Compute number of blocks in A and B */
  703. /* Computing MAX */
  704. i__1 = 1, i__2 = (*m + nb - 1) / nb;
  705. nba = f2cmax(i__1,i__2);
  706. /* Computing MAX */
  707. i__1 = 1, i__2 = (*n + nb - 1) / nb;
  708. nbb = f2cmax(i__1,i__2);
  709. /* Compute workspace */
  710. *info = 0;
  711. lquery = *ldswork == -1;
  712. if (lquery) {
  713. *ldswork = 2;
  714. swork[swork_dim1 + 1] = (real) f2cmax(nba,nbb);
  715. swork[swork_dim1 + 2] = (real) ((nbb << 1) + nba);
  716. }
  717. /* Test the input arguments */
  718. if (! notrna && ! lsame_(trana, "C")) {
  719. *info = -1;
  720. } else if (! notrnb && ! lsame_(tranb, "C")) {
  721. *info = -2;
  722. } else if (*isgn != 1 && *isgn != -1) {
  723. *info = -3;
  724. } else if (*m < 0) {
  725. *info = -4;
  726. } else if (*n < 0) {
  727. *info = -5;
  728. } else if (*lda < f2cmax(1,*m)) {
  729. *info = -7;
  730. } else if (*ldb < f2cmax(1,*n)) {
  731. *info = -9;
  732. } else if (*ldc < f2cmax(1,*m)) {
  733. *info = -11;
  734. }
  735. if (*info != 0) {
  736. i__1 = -(*info);
  737. xerbla_("CTRSYL3", &i__1, 7);
  738. return;
  739. } else if (lquery) {
  740. return;
  741. }
  742. /* Quick return if possible */
  743. *scale = 1.f;
  744. if (*m == 0 || *n == 0) {
  745. return;
  746. }
  747. wnrm = (real*)malloc(f2cmax(*m,*n)*sizeof(real));
  748. /* Use unblocked code for small problems or if insufficient */
  749. /* workspace is provided */
  750. if (f2cmin(nba,nbb) == 1 || *ldswork < f2cmax(nba,nbb)) {
  751. ctrsyl_(trana, tranb, isgn, m, n, &a[a_offset], lda, &b[b_offset],
  752. ldb, &c__[c_offset], ldc, scale, info);
  753. return;
  754. }
  755. /* Set constants to control overflow */
  756. smlnum = slamch_("S");
  757. bignum = 1.f / smlnum;
  758. /* Set local scaling factors. */
  759. i__1 = nbb;
  760. for (l = 1; l <= i__1; ++l) {
  761. i__2 = nba;
  762. for (k = 1; k <= i__2; ++k) {
  763. swork[k + l * swork_dim1] = 1.f;
  764. }
  765. }
  766. /* Fallback scaling factor to prevent flushing of SWORK( K, L ) to zero. */
  767. /* This scaling is to ensure compatibility with TRSYL and may get flushed. */
  768. buf = 1.f;
  769. /* Compute upper bounds of blocks of A and B */
  770. awrk = nbb;
  771. i__1 = nba;
  772. for (k = 1; k <= i__1; ++k) {
  773. k1 = (k - 1) * nb + 1;
  774. /* Computing MIN */
  775. i__2 = k * nb;
  776. k2 = f2cmin(i__2,*m) + 1;
  777. i__2 = nba;
  778. for (l = k; l <= i__2; ++l) {
  779. l1 = (l - 1) * nb + 1;
  780. /* Computing MIN */
  781. i__3 = l * nb;
  782. l2 = f2cmin(i__3,*m) + 1;
  783. if (notrna) {
  784. i__3 = k2 - k1;
  785. i__4 = l2 - l1;
  786. swork[k + (awrk + l) * swork_dim1] = clange_("I", &i__3, &
  787. i__4, &a[k1 + l1 * a_dim1], lda, wnrm);
  788. } else {
  789. i__3 = k2 - k1;
  790. i__4 = l2 - l1;
  791. swork[l + (awrk + k) * swork_dim1] = clange_("1", &i__3, &
  792. i__4, &a[k1 + l1 * a_dim1], lda, wnrm);
  793. }
  794. }
  795. }
  796. bwrk = nbb + nba;
  797. i__1 = nbb;
  798. for (k = 1; k <= i__1; ++k) {
  799. k1 = (k - 1) * nb + 1;
  800. /* Computing MIN */
  801. i__2 = k * nb;
  802. k2 = f2cmin(i__2,*n) + 1;
  803. i__2 = nbb;
  804. for (l = k; l <= i__2; ++l) {
  805. l1 = (l - 1) * nb + 1;
  806. /* Computing MIN */
  807. i__3 = l * nb;
  808. l2 = f2cmin(i__3,*n) + 1;
  809. if (notrnb) {
  810. i__3 = k2 - k1;
  811. i__4 = l2 - l1;
  812. swork[k + (bwrk + l) * swork_dim1] = clange_("I", &i__3, &
  813. i__4, &b[k1 + l1 * b_dim1], ldb, wnrm);
  814. } else {
  815. i__3 = k2 - k1;
  816. i__4 = l2 - l1;
  817. swork[l + (bwrk + k) * swork_dim1] = clange_("1", &i__3, &
  818. i__4, &b[k1 + l1 * b_dim1], ldb, wnrm);
  819. }
  820. }
  821. }
  822. sgn = (real) (*isgn);
  823. q__1.r = sgn, q__1.i = 0.f;
  824. csgn.r = q__1.r, csgn.i = q__1.i;
  825. if (notrna && notrnb) {
  826. /* Solve A*X + ISGN*X*B = scale*C. */
  827. /* The (K,L)th block of X is determined starting from */
  828. /* bottom-left corner column by column by */
  829. /* A(K,K)*X(K,L) + ISGN*X(K,L)*B(L,L) = C(K,L) - R(K,L) */
  830. /* Where */
  831. /* M L-1 */
  832. /* R(K,L) = SUM [A(K,I)*X(I,L)] + ISGN*SUM [X(K,J)*B(J,L)]. */
  833. /* I=K+1 J=1 */
  834. /* Start loop over block rows (index = K) and block columns (index = L) */
  835. for (k = nba; k >= 1; --k) {
  836. /* K1: row index of the first row in X( K, L ) */
  837. /* K2: row index of the first row in X( K+1, L ) */
  838. /* so the K2 - K1 is the column count of the block X( K, L ) */
  839. k1 = (k - 1) * nb + 1;
  840. /* Computing MIN */
  841. i__1 = k * nb;
  842. k2 = f2cmin(i__1,*m) + 1;
  843. i__1 = nbb;
  844. for (l = 1; l <= i__1; ++l) {
  845. /* L1: column index of the first column in X( K, L ) */
  846. /* L2: column index of the first column in X( K, L + 1) */
  847. /* so that L2 - L1 is the row count of the block X( K, L ) */
  848. l1 = (l - 1) * nb + 1;
  849. /* Computing MIN */
  850. i__2 = l * nb;
  851. l2 = f2cmin(i__2,*n) + 1;
  852. i__2 = k2 - k1;
  853. i__3 = l2 - l1;
  854. ctrsyl_(trana, tranb, isgn, &i__2, &i__3, &a[k1 + k1 * a_dim1]
  855. , lda, &b[l1 + l1 * b_dim1], ldb, &c__[k1 + l1 *
  856. c_dim1], ldc, &scaloc, &iinfo);
  857. *info = f2cmax(*info,iinfo);
  858. if (scaloc * swork[k + l * swork_dim1] == 0.f) {
  859. if (scaloc == 0.f) {
  860. /* The magnitude of the largest entry of X(K1:K2-1, L1:L2-1) */
  861. /* is larger than the product of BIGNUM**2 and cannot be */
  862. /* represented in the form (1/SCALE)*X(K1:K2-1, L1:L2-1). */
  863. /* Mark the computation as pointless. */
  864. buf = 0.f;
  865. } else {
  866. /* Use second scaling factor to prevent flushing to zero. */
  867. i__2 = myexp_(&scaloc);
  868. buf *= pow_ri(&c_b18, &i__2);
  869. }
  870. i__2 = nbb;
  871. for (jj = 1; jj <= i__2; ++jj) {
  872. i__3 = nba;
  873. for (ll = 1; ll <= i__3; ++ll) {
  874. /* Bound by BIGNUM to not introduce Inf. The value */
  875. /* is irrelevant; corresponding entries of the */
  876. /* solution will be flushed in consistency scaling. */
  877. /* Computing MIN */
  878. i__4 = myexp_(&scaloc);
  879. r__1 = bignum, r__2 = swork[ll + jj * swork_dim1]
  880. / pow_ri(&c_b18, &i__4);
  881. swork[ll + jj * swork_dim1] = f2cmin(r__1,r__2);
  882. }
  883. }
  884. }
  885. swork[k + l * swork_dim1] = scaloc * swork[k + l * swork_dim1]
  886. ;
  887. i__2 = k2 - k1;
  888. i__3 = l2 - l1;
  889. xnrm = clange_("I", &i__2, &i__3, &c__[k1 + l1 * c_dim1], ldc,
  890. wnrm);
  891. for (i__ = k - 1; i__ >= 1; --i__) {
  892. /* C( I, L ) := C( I, L ) - A( I, K ) * C( K, L ) */
  893. i1 = (i__ - 1) * nb + 1;
  894. /* Computing MIN */
  895. i__2 = i__ * nb;
  896. i2 = f2cmin(i__2,*m) + 1;
  897. /* Compute scaling factor to survive the linear update */
  898. /* simulating consistent scaling. */
  899. i__2 = i2 - i1;
  900. i__3 = l2 - l1;
  901. cnrm = clange_("I", &i__2, &i__3, &c__[i1 + l1 * c_dim1],
  902. ldc, wnrm);
  903. /* Computing MIN */
  904. r__1 = swork[i__ + l * swork_dim1], r__2 = swork[k + l *
  905. swork_dim1];
  906. scamin = f2cmin(r__1,r__2);
  907. cnrm *= scamin / swork[i__ + l * swork_dim1];
  908. xnrm *= scamin / swork[k + l * swork_dim1];
  909. anrm = swork[i__ + (awrk + k) * swork_dim1];
  910. scaloc = slarmm_(&anrm, &xnrm, &cnrm);
  911. if (scaloc * scamin == 0.f) {
  912. /* Use second scaling factor to prevent flushing to zero. */
  913. i__2 = myexp_(&scaloc);
  914. buf *= pow_ri(&c_b18, &i__2);
  915. i__2 = nbb;
  916. for (jj = 1; jj <= i__2; ++jj) {
  917. i__3 = nba;
  918. for (ll = 1; ll <= i__3; ++ll) {
  919. /* Computing MIN */
  920. i__4 = myexp_(&scaloc);
  921. r__1 = bignum, r__2 = swork[ll + jj *
  922. swork_dim1] / pow_ri(&c_b18, &i__4);
  923. swork[ll + jj * swork_dim1] = f2cmin(r__1,r__2);
  924. }
  925. }
  926. i__2 = myexp_(&scaloc);
  927. scamin /= pow_ri(&c_b18, &i__2);
  928. i__2 = myexp_(&scaloc);
  929. scaloc /= pow_ri(&c_b18, &i__2);
  930. }
  931. cnrm *= scaloc;
  932. xnrm *= scaloc;
  933. /* Simultaneously apply the robust update factor and the */
  934. /* consistency scaling factor to C( I, L ) and C( K, L ). */
  935. scal = scamin / swork[k + l * swork_dim1] * scaloc;
  936. if (scal != 1.f) {
  937. i__2 = l2 - 1;
  938. for (jj = l1; jj <= i__2; ++jj) {
  939. i__3 = k2 - k1;
  940. csscal_(&i__3, &scal, &c__[k1 + jj * c_dim1], &
  941. c__1);
  942. }
  943. }
  944. scal = scamin / swork[i__ + l * swork_dim1] * scaloc;
  945. if (scal != 1.f) {
  946. i__2 = l2 - 1;
  947. for (ll = l1; ll <= i__2; ++ll) {
  948. i__3 = i2 - i1;
  949. csscal_(&i__3, &scal, &c__[i1 + ll * c_dim1], &
  950. c__1);
  951. }
  952. }
  953. /* Record current scaling factor */
  954. swork[k + l * swork_dim1] = scamin * scaloc;
  955. swork[i__ + l * swork_dim1] = scamin * scaloc;
  956. i__2 = i2 - i1;
  957. i__3 = l2 - l1;
  958. i__4 = k2 - k1;
  959. q__1.r = -1.f, q__1.i = 0.f;
  960. cgemm_("N", "N", &i__2, &i__3, &i__4, &q__1, &a[i1 + k1 *
  961. a_dim1], lda, &c__[k1 + l1 * c_dim1], ldc, &c_b1,
  962. &c__[i1 + l1 * c_dim1], ldc)
  963. ;
  964. }
  965. i__2 = nbb;
  966. for (j = l + 1; j <= i__2; ++j) {
  967. /* C( K, J ) := C( K, J ) - SGN * C( K, L ) * B( L, J ) */
  968. j1 = (j - 1) * nb + 1;
  969. /* Computing MIN */
  970. i__3 = j * nb;
  971. j2 = f2cmin(i__3,*n) + 1;
  972. /* Compute scaling factor to survive the linear update */
  973. /* simulating consistent scaling. */
  974. i__3 = k2 - k1;
  975. i__4 = j2 - j1;
  976. cnrm = clange_("I", &i__3, &i__4, &c__[k1 + j1 * c_dim1],
  977. ldc, wnrm);
  978. /* Computing MIN */
  979. r__1 = swork[k + j * swork_dim1], r__2 = swork[k + l *
  980. swork_dim1];
  981. scamin = f2cmin(r__1,r__2);
  982. cnrm *= scamin / swork[k + j * swork_dim1];
  983. xnrm *= scamin / swork[k + l * swork_dim1];
  984. bnrm = swork[l + (bwrk + j) * swork_dim1];
  985. scaloc = slarmm_(&bnrm, &xnrm, &cnrm);
  986. if (scaloc * scamin == 0.f) {
  987. /* Use second scaling factor to prevent flushing to zero. */
  988. i__3 = myexp_(&scaloc);
  989. buf *= pow_ri(&c_b18, &i__3);
  990. i__3 = nbb;
  991. for (jj = 1; jj <= i__3; ++jj) {
  992. i__4 = nba;
  993. for (ll = 1; ll <= i__4; ++ll) {
  994. /* Computing MIN */
  995. i__5 = myexp_(&scaloc);
  996. r__1 = bignum, r__2 = swork[ll + jj *
  997. swork_dim1] / pow_ri(&c_b18, &i__5);
  998. swork[ll + jj * swork_dim1] = f2cmin(r__1,r__2);
  999. }
  1000. }
  1001. i__3 = myexp_(&scaloc);
  1002. scamin /= pow_ri(&c_b18, &i__3);
  1003. i__3 = myexp_(&scaloc);
  1004. scaloc /= pow_ri(&c_b18, &i__3);
  1005. }
  1006. cnrm *= scaloc;
  1007. xnrm *= scaloc;
  1008. /* Simultaneously apply the robust update factor and the */
  1009. /* consistency scaling factor to C( K, J ) and C( K, L). */
  1010. scal = scamin / swork[k + l * swork_dim1] * scaloc;
  1011. if (scal != 1.f) {
  1012. i__3 = l2 - 1;
  1013. for (ll = l1; ll <= i__3; ++ll) {
  1014. i__4 = k2 - k1;
  1015. csscal_(&i__4, &scal, &c__[k1 + ll * c_dim1], &
  1016. c__1);
  1017. }
  1018. }
  1019. scal = scamin / swork[k + j * swork_dim1] * scaloc;
  1020. if (scal != 1.f) {
  1021. i__3 = j2 - 1;
  1022. for (jj = j1; jj <= i__3; ++jj) {
  1023. i__4 = k2 - k1;
  1024. csscal_(&i__4, &scal, &c__[k1 + jj * c_dim1], &
  1025. c__1);
  1026. }
  1027. }
  1028. /* Record current scaling factor */
  1029. swork[k + l * swork_dim1] = scamin * scaloc;
  1030. swork[k + j * swork_dim1] = scamin * scaloc;
  1031. i__3 = k2 - k1;
  1032. i__4 = j2 - j1;
  1033. i__5 = l2 - l1;
  1034. q__1.r = -csgn.r, q__1.i = -csgn.i;
  1035. cgemm_("N", "N", &i__3, &i__4, &i__5, &q__1, &c__[k1 + l1
  1036. * c_dim1], ldc, &b[l1 + j1 * b_dim1], ldb, &c_b1,
  1037. &c__[k1 + j1 * c_dim1], ldc)
  1038. ;
  1039. }
  1040. }
  1041. }
  1042. } else if (! notrna && notrnb) {
  1043. /* Solve A**H *X + ISGN*X*B = scale*C. */
  1044. /* The (K,L)th block of X is determined starting from */
  1045. /* upper-left corner column by column by */
  1046. /* A(K,K)**H*X(K,L) + ISGN*X(K,L)*B(L,L) = C(K,L) - R(K,L) */
  1047. /* Where */
  1048. /* K-1 L-1 */
  1049. /* R(K,L) = SUM [A(I,K)**H*X(I,L)] +ISGN*SUM [X(K,J)*B(J,L)] */
  1050. /* I=1 J=1 */
  1051. /* Start loop over block rows (index = K) and block columns (index = L) */
  1052. i__1 = nba;
  1053. for (k = 1; k <= i__1; ++k) {
  1054. /* K1: row index of the first row in X( K, L ) */
  1055. /* K2: row index of the first row in X( K+1, L ) */
  1056. /* so the K2 - K1 is the column count of the block X( K, L ) */
  1057. k1 = (k - 1) * nb + 1;
  1058. /* Computing MIN */
  1059. i__2 = k * nb;
  1060. k2 = f2cmin(i__2,*m) + 1;
  1061. i__2 = nbb;
  1062. for (l = 1; l <= i__2; ++l) {
  1063. /* L1: column index of the first column in X( K, L ) */
  1064. /* L2: column index of the first column in X( K, L + 1) */
  1065. /* so that L2 - L1 is the row count of the block X( K, L ) */
  1066. l1 = (l - 1) * nb + 1;
  1067. /* Computing MIN */
  1068. i__3 = l * nb;
  1069. l2 = f2cmin(i__3,*n) + 1;
  1070. i__3 = k2 - k1;
  1071. i__4 = l2 - l1;
  1072. ctrsyl_(trana, tranb, isgn, &i__3, &i__4, &a[k1 + k1 * a_dim1]
  1073. , lda, &b[l1 + l1 * b_dim1], ldb, &c__[k1 + l1 *
  1074. c_dim1], ldc, &scaloc, &iinfo);
  1075. *info = f2cmax(*info,iinfo);
  1076. if (scaloc * swork[k + l * swork_dim1] == 0.f) {
  1077. if (scaloc == 0.f) {
  1078. /* The magnitude of the largest entry of X(K1:K2-1, L1:L2-1) */
  1079. /* is larger than the product of BIGNUM**2 and cannot be */
  1080. /* represented in the form (1/SCALE)*X(K1:K2-1, L1:L2-1). */
  1081. /* Mark the computation as pointless. */
  1082. buf = 0.f;
  1083. } else {
  1084. /* Use second scaling factor to prevent flushing to zero. */
  1085. i__3 = myexp_(&scaloc);
  1086. buf *= pow_ri(&c_b18, &i__3);
  1087. }
  1088. i__3 = nbb;
  1089. for (jj = 1; jj <= i__3; ++jj) {
  1090. i__4 = nba;
  1091. for (ll = 1; ll <= i__4; ++ll) {
  1092. /* Bound by BIGNUM to not introduce Inf. The value */
  1093. /* is irrelevant; corresponding entries of the */
  1094. /* solution will be flushed in consistency scaling. */
  1095. /* Computing MIN */
  1096. i__5 = myexp_(&scaloc);
  1097. r__1 = bignum, r__2 = swork[ll + jj * swork_dim1]
  1098. / pow_ri(&c_b18, &i__5);
  1099. swork[ll + jj * swork_dim1] = f2cmin(r__1,r__2);
  1100. }
  1101. }
  1102. }
  1103. swork[k + l * swork_dim1] = scaloc * swork[k + l * swork_dim1]
  1104. ;
  1105. i__3 = k2 - k1;
  1106. i__4 = l2 - l1;
  1107. xnrm = clange_("I", &i__3, &i__4, &c__[k1 + l1 * c_dim1], ldc,
  1108. wnrm);
  1109. i__3 = nba;
  1110. for (i__ = k + 1; i__ <= i__3; ++i__) {
  1111. /* C( I, L ) := C( I, L ) - A( K, I )**H * C( K, L ) */
  1112. i1 = (i__ - 1) * nb + 1;
  1113. /* Computing MIN */
  1114. i__4 = i__ * nb;
  1115. i2 = f2cmin(i__4,*m) + 1;
  1116. /* Compute scaling factor to survive the linear update */
  1117. /* simulating consistent scaling. */
  1118. i__4 = i2 - i1;
  1119. i__5 = l2 - l1;
  1120. cnrm = clange_("I", &i__4, &i__5, &c__[i1 + l1 * c_dim1],
  1121. ldc, wnrm);
  1122. /* Computing MIN */
  1123. r__1 = swork[i__ + l * swork_dim1], r__2 = swork[k + l *
  1124. swork_dim1];
  1125. scamin = f2cmin(r__1,r__2);
  1126. cnrm *= scamin / swork[i__ + l * swork_dim1];
  1127. xnrm *= scamin / swork[k + l * swork_dim1];
  1128. anrm = swork[i__ + (awrk + k) * swork_dim1];
  1129. scaloc = slarmm_(&anrm, &xnrm, &cnrm);
  1130. if (scaloc * scamin == 0.f) {
  1131. /* Use second scaling factor to prevent flushing to zero. */
  1132. i__4 = myexp_(&scaloc);
  1133. buf *= pow_ri(&c_b18, &i__4);
  1134. i__4 = nbb;
  1135. for (jj = 1; jj <= i__4; ++jj) {
  1136. i__5 = nba;
  1137. for (ll = 1; ll <= i__5; ++ll) {
  1138. /* Computing MIN */
  1139. i__6 = myexp_(&scaloc);
  1140. r__1 = bignum, r__2 = swork[ll + jj *
  1141. swork_dim1] / pow_ri(&c_b18, &i__6);
  1142. swork[ll + jj * swork_dim1] = f2cmin(r__1,r__2);
  1143. }
  1144. }
  1145. i__4 = myexp_(&scaloc);
  1146. scamin /= pow_ri(&c_b18, &i__4);
  1147. i__4 = myexp_(&scaloc);
  1148. scaloc /= pow_ri(&c_b18, &i__4);
  1149. }
  1150. cnrm *= scaloc;
  1151. xnrm *= scaloc;
  1152. /* Simultaneously apply the robust update factor and the */
  1153. /* consistency scaling factor to to C( I, L ) and C( K, L). */
  1154. scal = scamin / swork[k + l * swork_dim1] * scaloc;
  1155. if (scal != 1.f) {
  1156. i__4 = l2 - 1;
  1157. for (ll = l1; ll <= i__4; ++ll) {
  1158. i__5 = k2 - k1;
  1159. csscal_(&i__5, &scal, &c__[k1 + ll * c_dim1], &
  1160. c__1);
  1161. }
  1162. }
  1163. scal = scamin / swork[i__ + l * swork_dim1] * scaloc;
  1164. if (scal != 1.f) {
  1165. i__4 = l2 - 1;
  1166. for (ll = l1; ll <= i__4; ++ll) {
  1167. i__5 = i2 - i1;
  1168. csscal_(&i__5, &scal, &c__[i1 + ll * c_dim1], &
  1169. c__1);
  1170. }
  1171. }
  1172. /* Record current scaling factor */
  1173. swork[k + l * swork_dim1] = scamin * scaloc;
  1174. swork[i__ + l * swork_dim1] = scamin * scaloc;
  1175. i__4 = i2 - i1;
  1176. i__5 = l2 - l1;
  1177. i__6 = k2 - k1;
  1178. q__1.r = -1.f, q__1.i = 0.f;
  1179. cgemm_("C", "N", &i__4, &i__5, &i__6, &q__1, &a[k1 + i1 *
  1180. a_dim1], lda, &c__[k1 + l1 * c_dim1], ldc, &c_b1,
  1181. &c__[i1 + l1 * c_dim1], ldc)
  1182. ;
  1183. }
  1184. i__3 = nbb;
  1185. for (j = l + 1; j <= i__3; ++j) {
  1186. /* C( K, J ) := C( K, J ) - SGN * C( K, L ) * B( L, J ) */
  1187. j1 = (j - 1) * nb + 1;
  1188. /* Computing MIN */
  1189. i__4 = j * nb;
  1190. j2 = f2cmin(i__4,*n) + 1;
  1191. /* Compute scaling factor to survive the linear update */
  1192. /* simulating consistent scaling. */
  1193. i__4 = k2 - k1;
  1194. i__5 = j2 - j1;
  1195. cnrm = clange_("I", &i__4, &i__5, &c__[k1 + j1 * c_dim1],
  1196. ldc, wnrm);
  1197. /* Computing MIN */
  1198. r__1 = swork[k + j * swork_dim1], r__2 = swork[k + l *
  1199. swork_dim1];
  1200. scamin = f2cmin(r__1,r__2);
  1201. cnrm *= scamin / swork[k + j * swork_dim1];
  1202. xnrm *= scamin / swork[k + l * swork_dim1];
  1203. bnrm = swork[l + (bwrk + j) * swork_dim1];
  1204. scaloc = slarmm_(&bnrm, &xnrm, &cnrm);
  1205. if (scaloc * scamin == 0.f) {
  1206. /* Use second scaling factor to prevent flushing to zero. */
  1207. i__4 = myexp_(&scaloc);
  1208. buf *= pow_ri(&c_b18, &i__4);
  1209. i__4 = nbb;
  1210. for (jj = 1; jj <= i__4; ++jj) {
  1211. i__5 = nba;
  1212. for (ll = 1; ll <= i__5; ++ll) {
  1213. /* Computing MIN */
  1214. i__6 = myexp_(&scaloc);
  1215. r__1 = bignum, r__2 = swork[ll + jj *
  1216. swork_dim1] / pow_ri(&c_b18, &i__6);
  1217. swork[ll + jj * swork_dim1] = f2cmin(r__1,r__2);
  1218. }
  1219. }
  1220. i__4 = myexp_(&scaloc);
  1221. scamin /= pow_ri(&c_b18, &i__4);
  1222. i__4 = myexp_(&scaloc);
  1223. scaloc /= pow_ri(&c_b18, &i__4);
  1224. }
  1225. cnrm *= scaloc;
  1226. xnrm *= scaloc;
  1227. /* Simultaneously apply the robust update factor and the */
  1228. /* consistency scaling factor to to C( K, J ) and C( K, L). */
  1229. scal = scamin / swork[k + l * swork_dim1] * scaloc;
  1230. if (scal != 1.f) {
  1231. i__4 = l2 - 1;
  1232. for (ll = l1; ll <= i__4; ++ll) {
  1233. i__5 = k2 - k1;
  1234. csscal_(&i__5, &scal, &c__[k1 + ll * c_dim1], &
  1235. c__1);
  1236. }
  1237. }
  1238. scal = scamin / swork[k + j * swork_dim1] * scaloc;
  1239. if (scal != 1.f) {
  1240. i__4 = j2 - 1;
  1241. for (jj = j1; jj <= i__4; ++jj) {
  1242. i__5 = k2 - k1;
  1243. csscal_(&i__5, &scal, &c__[k1 + jj * c_dim1], &
  1244. c__1);
  1245. }
  1246. }
  1247. /* Record current scaling factor */
  1248. swork[k + l * swork_dim1] = scamin * scaloc;
  1249. swork[k + j * swork_dim1] = scamin * scaloc;
  1250. i__4 = k2 - k1;
  1251. i__5 = j2 - j1;
  1252. i__6 = l2 - l1;
  1253. q__1.r = -csgn.r, q__1.i = -csgn.i;
  1254. cgemm_("N", "N", &i__4, &i__5, &i__6, &q__1, &c__[k1 + l1
  1255. * c_dim1], ldc, &b[l1 + j1 * b_dim1], ldb, &c_b1,
  1256. &c__[k1 + j1 * c_dim1], ldc)
  1257. ;
  1258. }
  1259. }
  1260. }
  1261. } else if (! notrna && ! notrnb) {
  1262. /* Solve A**H *X + ISGN*X*B**H = scale*C. */
  1263. /* The (K,L)th block of X is determined starting from */
  1264. /* top-right corner column by column by */
  1265. /* A(K,K)**H*X(K,L) + ISGN*X(K,L)*B(L,L)**H = C(K,L) - R(K,L) */
  1266. /* Where */
  1267. /* K-1 N */
  1268. /* R(K,L) = SUM [A(I,K)**H*X(I,L)] + ISGN*SUM [X(K,J)*B(L,J)**H]. */
  1269. /* I=1 J=L+1 */
  1270. /* Start loop over block rows (index = K) and block columns (index = L) */
  1271. i__1 = nba;
  1272. for (k = 1; k <= i__1; ++k) {
  1273. /* K1: row index of the first row in X( K, L ) */
  1274. /* K2: row index of the first row in X( K+1, L ) */
  1275. /* so the K2 - K1 is the column count of the block X( K, L ) */
  1276. k1 = (k - 1) * nb + 1;
  1277. /* Computing MIN */
  1278. i__2 = k * nb;
  1279. k2 = f2cmin(i__2,*m) + 1;
  1280. for (l = nbb; l >= 1; --l) {
  1281. /* L1: column index of the first column in X( K, L ) */
  1282. /* L2: column index of the first column in X( K, L + 1) */
  1283. /* so that L2 - L1 is the row count of the block X( K, L ) */
  1284. l1 = (l - 1) * nb + 1;
  1285. /* Computing MIN */
  1286. i__2 = l * nb;
  1287. l2 = f2cmin(i__2,*n) + 1;
  1288. i__2 = k2 - k1;
  1289. i__3 = l2 - l1;
  1290. ctrsyl_(trana, tranb, isgn, &i__2, &i__3, &a[k1 + k1 * a_dim1]
  1291. , lda, &b[l1 + l1 * b_dim1], ldb, &c__[k1 + l1 *
  1292. c_dim1], ldc, &scaloc, &iinfo);
  1293. *info = f2cmax(*info,iinfo);
  1294. if (scaloc * swork[k + l * swork_dim1] == 0.f) {
  1295. if (scaloc == 0.f) {
  1296. /* The magnitude of the largest entry of X(K1:K2-1, L1:L2-1) */
  1297. /* is larger than the product of BIGNUM**2 and cannot be */
  1298. /* represented in the form (1/SCALE)*X(K1:K2-1, L1:L2-1). */
  1299. /* Mark the computation as pointless. */
  1300. buf = 0.f;
  1301. } else {
  1302. /* Use second scaling factor to prevent flushing to zero. */
  1303. i__2 = myexp_(&scaloc);
  1304. buf *= pow_ri(&c_b18, &i__2);
  1305. }
  1306. i__2 = nbb;
  1307. for (jj = 1; jj <= i__2; ++jj) {
  1308. i__3 = nba;
  1309. for (ll = 1; ll <= i__3; ++ll) {
  1310. /* Bound by BIGNUM to not introduce Inf. The value */
  1311. /* is irrelevant; corresponding entries of the */
  1312. /* solution will be flushed in consistency scaling. */
  1313. /* Computing MIN */
  1314. i__4 = myexp_(&scaloc);
  1315. r__1 = bignum, r__2 = swork[ll + jj * swork_dim1]
  1316. / pow_ri(&c_b18, &i__4);
  1317. swork[ll + jj * swork_dim1] = f2cmin(r__1,r__2);
  1318. }
  1319. }
  1320. }
  1321. swork[k + l * swork_dim1] = scaloc * swork[k + l * swork_dim1]
  1322. ;
  1323. i__2 = k2 - k1;
  1324. i__3 = l2 - l1;
  1325. xnrm = clange_("I", &i__2, &i__3, &c__[k1 + l1 * c_dim1], ldc,
  1326. wnrm);
  1327. i__2 = nba;
  1328. for (i__ = k + 1; i__ <= i__2; ++i__) {
  1329. /* C( I, L ) := C( I, L ) - A( K, I )**H * C( K, L ) */
  1330. i1 = (i__ - 1) * nb + 1;
  1331. /* Computing MIN */
  1332. i__3 = i__ * nb;
  1333. i2 = f2cmin(i__3,*m) + 1;
  1334. /* Compute scaling factor to survive the linear update */
  1335. /* simulating consistent scaling. */
  1336. i__3 = i2 - i1;
  1337. i__4 = l2 - l1;
  1338. cnrm = clange_("I", &i__3, &i__4, &c__[i1 + l1 * c_dim1],
  1339. ldc, wnrm);
  1340. /* Computing MIN */
  1341. r__1 = swork[i__ + l * swork_dim1], r__2 = swork[k + l *
  1342. swork_dim1];
  1343. scamin = f2cmin(r__1,r__2);
  1344. cnrm *= scamin / swork[i__ + l * swork_dim1];
  1345. xnrm *= scamin / swork[k + l * swork_dim1];
  1346. anrm = swork[i__ + (awrk + k) * swork_dim1];
  1347. scaloc = slarmm_(&anrm, &xnrm, &cnrm);
  1348. if (scaloc * scamin == 0.f) {
  1349. /* Use second scaling factor to prevent flushing to zero. */
  1350. i__3 = myexp_(&scaloc);
  1351. buf *= pow_ri(&c_b18, &i__3);
  1352. i__3 = nbb;
  1353. for (jj = 1; jj <= i__3; ++jj) {
  1354. i__4 = nba;
  1355. for (ll = 1; ll <= i__4; ++ll) {
  1356. /* Computing MIN */
  1357. i__5 = myexp_(&scaloc);
  1358. r__1 = bignum, r__2 = swork[ll + jj *
  1359. swork_dim1] / pow_ri(&c_b18, &i__5);
  1360. swork[ll + jj * swork_dim1] = f2cmin(r__1,r__2);
  1361. }
  1362. }
  1363. i__3 = myexp_(&scaloc);
  1364. scamin /= pow_ri(&c_b18, &i__3);
  1365. i__3 = myexp_(&scaloc);
  1366. scaloc /= pow_ri(&c_b18, &i__3);
  1367. }
  1368. cnrm *= scaloc;
  1369. xnrm *= scaloc;
  1370. /* Simultaneously apply the robust update factor and the */
  1371. /* consistency scaling factor to C( I, L ) and C( K, L). */
  1372. scal = scamin / swork[k + l * swork_dim1] * scaloc;
  1373. if (scal != 1.f) {
  1374. i__3 = l2 - 1;
  1375. for (ll = l1; ll <= i__3; ++ll) {
  1376. i__4 = k2 - k1;
  1377. csscal_(&i__4, &scal, &c__[k1 + ll * c_dim1], &
  1378. c__1);
  1379. }
  1380. }
  1381. scal = scamin / swork[i__ + l * swork_dim1] * scaloc;
  1382. if (scal != 1.f) {
  1383. i__3 = l2 - 1;
  1384. for (ll = l1; ll <= i__3; ++ll) {
  1385. i__4 = i2 - i1;
  1386. csscal_(&i__4, &scal, &c__[i1 + ll * c_dim1], &
  1387. c__1);
  1388. }
  1389. }
  1390. /* Record current scaling factor */
  1391. swork[k + l * swork_dim1] = scamin * scaloc;
  1392. swork[i__ + l * swork_dim1] = scamin * scaloc;
  1393. i__3 = i2 - i1;
  1394. i__4 = l2 - l1;
  1395. i__5 = k2 - k1;
  1396. q__1.r = -1.f, q__1.i = 0.f;
  1397. cgemm_("C", "N", &i__3, &i__4, &i__5, &q__1, &a[k1 + i1 *
  1398. a_dim1], lda, &c__[k1 + l1 * c_dim1], ldc, &c_b1,
  1399. &c__[i1 + l1 * c_dim1], ldc)
  1400. ;
  1401. }
  1402. i__2 = l - 1;
  1403. for (j = 1; j <= i__2; ++j) {
  1404. /* C( K, J ) := C( K, J ) - SGN * C( K, L ) * B( J, L )**H */
  1405. j1 = (j - 1) * nb + 1;
  1406. /* Computing MIN */
  1407. i__3 = j * nb;
  1408. j2 = f2cmin(i__3,*n) + 1;
  1409. /* Compute scaling factor to survive the linear update */
  1410. /* simulating consistent scaling. */
  1411. i__3 = k2 - k1;
  1412. i__4 = j2 - j1;
  1413. cnrm = clange_("I", &i__3, &i__4, &c__[k1 + j1 * c_dim1],
  1414. ldc, wnrm);
  1415. /* Computing MIN */
  1416. r__1 = swork[k + j * swork_dim1], r__2 = swork[k + l *
  1417. swork_dim1];
  1418. scamin = f2cmin(r__1,r__2);
  1419. cnrm *= scamin / swork[k + j * swork_dim1];
  1420. xnrm *= scamin / swork[k + l * swork_dim1];
  1421. bnrm = swork[l + (bwrk + j) * swork_dim1];
  1422. scaloc = slarmm_(&bnrm, &xnrm, &cnrm);
  1423. if (scaloc * scamin == 0.f) {
  1424. /* Use second scaling factor to prevent flushing to zero. */
  1425. i__3 = myexp_(&scaloc);
  1426. buf *= pow_ri(&c_b18, &i__3);
  1427. i__3 = nbb;
  1428. for (jj = 1; jj <= i__3; ++jj) {
  1429. i__4 = nba;
  1430. for (ll = 1; ll <= i__4; ++ll) {
  1431. /* Computing MIN */
  1432. i__5 = myexp_(&scaloc);
  1433. r__1 = bignum, r__2 = swork[ll + jj *
  1434. swork_dim1] / pow_ri(&c_b18, &i__5);
  1435. swork[ll + jj * swork_dim1] = f2cmin(r__1,r__2);
  1436. }
  1437. }
  1438. i__3 = myexp_(&scaloc);
  1439. scamin /= pow_ri(&c_b18, &i__3);
  1440. i__3 = myexp_(&scaloc);
  1441. scaloc /= pow_ri(&c_b18, &i__3);
  1442. }
  1443. cnrm *= scaloc;
  1444. xnrm *= scaloc;
  1445. /* Simultaneously apply the robust update factor and the */
  1446. /* consistency scaling factor to C( K, J ) and C( K, L). */
  1447. scal = scamin / swork[k + l * swork_dim1] * scaloc;
  1448. if (scal != 1.f) {
  1449. i__3 = l2 - 1;
  1450. for (ll = l1; ll <= i__3; ++ll) {
  1451. i__4 = k2 - k1;
  1452. csscal_(&i__4, &scal, &c__[k1 + ll * c_dim1], &
  1453. c__1);
  1454. }
  1455. }
  1456. scal = scamin / swork[k + j * swork_dim1] * scaloc;
  1457. if (scal != 1.f) {
  1458. i__3 = j2 - 1;
  1459. for (jj = j1; jj <= i__3; ++jj) {
  1460. i__4 = k2 - k1;
  1461. csscal_(&i__4, &scal, &c__[k1 + jj * c_dim1], &
  1462. c__1);
  1463. }
  1464. }
  1465. /* Record current scaling factor */
  1466. swork[k + l * swork_dim1] = scamin * scaloc;
  1467. swork[k + j * swork_dim1] = scamin * scaloc;
  1468. i__3 = k2 - k1;
  1469. i__4 = j2 - j1;
  1470. i__5 = l2 - l1;
  1471. q__1.r = -csgn.r, q__1.i = -csgn.i;
  1472. cgemm_("N", "C", &i__3, &i__4, &i__5, &q__1, &c__[k1 + l1
  1473. * c_dim1], ldc, &b[j1 + l1 * b_dim1], ldb, &c_b1,
  1474. &c__[k1 + j1 * c_dim1], ldc)
  1475. ;
  1476. }
  1477. }
  1478. }
  1479. } else if (notrna && ! notrnb) {
  1480. /* Solve A*X + ISGN*X*B**H = scale*C. */
  1481. /* The (K,L)th block of X is determined starting from */
  1482. /* bottom-right corner column by column by */
  1483. /* A(K,K)*X(K,L) + ISGN*X(K,L)*B(L,L)**H = C(K,L) - R(K,L) */
  1484. /* Where */
  1485. /* M N */
  1486. /* R(K,L) = SUM [A(K,I)*X(I,L)] + ISGN*SUM [X(K,J)*B(L,J)**H]. */
  1487. /* I=K+1 J=L+1 */
  1488. /* Start loop over block rows (index = K) and block columns (index = L) */
  1489. for (k = nba; k >= 1; --k) {
  1490. /* K1: row index of the first row in X( K, L ) */
  1491. /* K2: row index of the first row in X( K+1, L ) */
  1492. /* so the K2 - K1 is the column count of the block X( K, L ) */
  1493. k1 = (k - 1) * nb + 1;
  1494. /* Computing MIN */
  1495. i__1 = k * nb;
  1496. k2 = f2cmin(i__1,*m) + 1;
  1497. for (l = nbb; l >= 1; --l) {
  1498. /* L1: column index of the first column in X( K, L ) */
  1499. /* L2: column index of the first column in X( K, L + 1) */
  1500. /* so that L2 - L1 is the row count of the block X( K, L ) */
  1501. l1 = (l - 1) * nb + 1;
  1502. /* Computing MIN */
  1503. i__1 = l * nb;
  1504. l2 = f2cmin(i__1,*n) + 1;
  1505. i__1 = k2 - k1;
  1506. i__2 = l2 - l1;
  1507. ctrsyl_(trana, tranb, isgn, &i__1, &i__2, &a[k1 + k1 * a_dim1]
  1508. , lda, &b[l1 + l1 * b_dim1], ldb, &c__[k1 + l1 *
  1509. c_dim1], ldc, &scaloc, &iinfo);
  1510. *info = f2cmax(*info,iinfo);
  1511. if (scaloc * swork[k + l * swork_dim1] == 0.f) {
  1512. if (scaloc == 0.f) {
  1513. /* The magnitude of the largest entry of X(K1:K2-1, L1:L2-1) */
  1514. /* is larger than the product of BIGNUM**2 and cannot be */
  1515. /* represented in the form (1/SCALE)*X(K1:K2-1, L1:L2-1). */
  1516. /* Mark the computation as pointless. */
  1517. buf = 0.f;
  1518. } else {
  1519. /* Use second scaling factor to prevent flushing to zero. */
  1520. i__1 = myexp_(&scaloc);
  1521. buf *= pow_ri(&c_b18, &i__1);
  1522. }
  1523. i__1 = nbb;
  1524. for (jj = 1; jj <= i__1; ++jj) {
  1525. i__2 = nba;
  1526. for (ll = 1; ll <= i__2; ++ll) {
  1527. /* Bound by BIGNUM to not introduce Inf. The value */
  1528. /* is irrelevant; corresponding entries of the */
  1529. /* solution will be flushed in consistency scaling. */
  1530. /* Computing MIN */
  1531. i__3 = myexp_(&scaloc);
  1532. r__1 = bignum, r__2 = swork[ll + jj * swork_dim1]
  1533. / pow_ri(&c_b18, &i__3);
  1534. swork[ll + jj * swork_dim1] = f2cmin(r__1,r__2);
  1535. }
  1536. }
  1537. }
  1538. swork[k + l * swork_dim1] = scaloc * swork[k + l * swork_dim1]
  1539. ;
  1540. i__1 = k2 - k1;
  1541. i__2 = l2 - l1;
  1542. xnrm = clange_("I", &i__1, &i__2, &c__[k1 + l1 * c_dim1], ldc,
  1543. wnrm);
  1544. i__1 = k - 1;
  1545. for (i__ = 1; i__ <= i__1; ++i__) {
  1546. /* C( I, L ) := C( I, L ) - A( I, K ) * C( K, L ) */
  1547. i1 = (i__ - 1) * nb + 1;
  1548. /* Computing MIN */
  1549. i__2 = i__ * nb;
  1550. i2 = f2cmin(i__2,*m) + 1;
  1551. /* Compute scaling factor to survive the linear update */
  1552. /* simulating consistent scaling. */
  1553. i__2 = i2 - i1;
  1554. i__3 = l2 - l1;
  1555. cnrm = clange_("I", &i__2, &i__3, &c__[i1 + l1 * c_dim1],
  1556. ldc, wnrm);
  1557. /* Computing MIN */
  1558. r__1 = swork[i__ + l * swork_dim1], r__2 = swork[k + l *
  1559. swork_dim1];
  1560. scamin = f2cmin(r__1,r__2);
  1561. cnrm *= scamin / swork[i__ + l * swork_dim1];
  1562. xnrm *= scamin / swork[k + l * swork_dim1];
  1563. anrm = swork[i__ + (awrk + k) * swork_dim1];
  1564. scaloc = slarmm_(&anrm, &xnrm, &cnrm);
  1565. if (scaloc * scamin == 0.f) {
  1566. /* Use second scaling factor to prevent flushing to zero. */
  1567. i__2 = myexp_(&scaloc);
  1568. buf *= pow_ri(&c_b18, &i__2);
  1569. i__2 = nbb;
  1570. for (jj = 1; jj <= i__2; ++jj) {
  1571. i__3 = nba;
  1572. for (ll = 1; ll <= i__3; ++ll) {
  1573. /* Computing MIN */
  1574. i__4 = myexp_(&scaloc);
  1575. r__1 = bignum, r__2 = swork[ll + jj *
  1576. swork_dim1] / pow_ri(&c_b18, &i__4);
  1577. swork[ll + jj * swork_dim1] = f2cmin(r__1,r__2);
  1578. }
  1579. }
  1580. i__2 = myexp_(&scaloc);
  1581. scamin /= pow_ri(&c_b18, &i__2);
  1582. i__2 = myexp_(&scaloc);
  1583. scaloc /= pow_ri(&c_b18, &i__2);
  1584. }
  1585. cnrm *= scaloc;
  1586. xnrm *= scaloc;
  1587. /* Simultaneously apply the robust update factor and the */
  1588. /* consistency scaling factor to C( I, L ) and C( K, L). */
  1589. scal = scamin / swork[k + l * swork_dim1] * scaloc;
  1590. if (scal != 1.f) {
  1591. i__2 = l2 - 1;
  1592. for (ll = l1; ll <= i__2; ++ll) {
  1593. i__3 = k2 - k1;
  1594. csscal_(&i__3, &scal, &c__[k1 + ll * c_dim1], &
  1595. c__1);
  1596. }
  1597. }
  1598. scal = scamin / swork[i__ + l * swork_dim1] * scaloc;
  1599. if (scal != 1.f) {
  1600. i__2 = l2 - 1;
  1601. for (ll = l1; ll <= i__2; ++ll) {
  1602. i__3 = i2 - i1;
  1603. csscal_(&i__3, &scal, &c__[i1 + ll * c_dim1], &
  1604. c__1);
  1605. }
  1606. }
  1607. /* Record current scaling factor */
  1608. swork[k + l * swork_dim1] = scamin * scaloc;
  1609. swork[i__ + l * swork_dim1] = scamin * scaloc;
  1610. i__2 = i2 - i1;
  1611. i__3 = l2 - l1;
  1612. i__4 = k2 - k1;
  1613. q__1.r = -1.f, q__1.i = 0.f;
  1614. cgemm_("N", "N", &i__2, &i__3, &i__4, &q__1, &a[i1 + k1 *
  1615. a_dim1], lda, &c__[k1 + l1 * c_dim1], ldc, &c_b1,
  1616. &c__[i1 + l1 * c_dim1], ldc)
  1617. ;
  1618. }
  1619. i__1 = l - 1;
  1620. for (j = 1; j <= i__1; ++j) {
  1621. /* C( K, J ) := C( K, J ) - SGN * C( K, L ) * B( J, L )**H */
  1622. j1 = (j - 1) * nb + 1;
  1623. /* Computing MIN */
  1624. i__2 = j * nb;
  1625. j2 = f2cmin(i__2,*n) + 1;
  1626. /* Compute scaling factor to survive the linear update */
  1627. /* simulating consistent scaling. */
  1628. i__2 = k2 - k1;
  1629. i__3 = j2 - j1;
  1630. cnrm = clange_("I", &i__2, &i__3, &c__[k1 + j1 * c_dim1],
  1631. ldc, wnrm);
  1632. /* Computing MIN */
  1633. r__1 = swork[k + j * swork_dim1], r__2 = swork[k + l *
  1634. swork_dim1];
  1635. scamin = f2cmin(r__1,r__2);
  1636. cnrm *= scamin / swork[k + j * swork_dim1];
  1637. xnrm *= scamin / swork[k + l * swork_dim1];
  1638. bnrm = swork[l + (bwrk + j) * swork_dim1];
  1639. scaloc = slarmm_(&bnrm, &xnrm, &cnrm);
  1640. if (scaloc * scamin == 0.f) {
  1641. /* Use second scaling factor to prevent flushing to zero. */
  1642. i__2 = myexp_(&scaloc);
  1643. buf *= pow_ri(&c_b18, &i__2);
  1644. i__2 = nbb;
  1645. for (jj = 1; jj <= i__2; ++jj) {
  1646. i__3 = nba;
  1647. for (ll = 1; ll <= i__3; ++ll) {
  1648. /* Computing MIN */
  1649. i__4 = myexp_(&scaloc);
  1650. r__1 = bignum, r__2 = swork[ll + jj *
  1651. swork_dim1] / pow_ri(&c_b18, &i__4);
  1652. swork[ll + jj * swork_dim1] = f2cmin(r__1,r__2);
  1653. }
  1654. }
  1655. i__2 = myexp_(&scaloc);
  1656. scamin /= pow_ri(&c_b18, &i__2);
  1657. i__2 = myexp_(&scaloc);
  1658. scaloc /= pow_ri(&c_b18, &i__2);
  1659. }
  1660. cnrm *= scaloc;
  1661. xnrm *= scaloc;
  1662. /* Simultaneously apply the robust update factor and the */
  1663. /* consistency scaling factor to C( K, J ) and C( K, L). */
  1664. scal = scamin / swork[k + l * swork_dim1] * scaloc;
  1665. if (scal != 1.f) {
  1666. i__2 = l2 - 1;
  1667. for (jj = l1; jj <= i__2; ++jj) {
  1668. i__3 = k2 - k1;
  1669. csscal_(&i__3, &scal, &c__[k1 + jj * c_dim1], &
  1670. c__1);
  1671. }
  1672. }
  1673. scal = scamin / swork[k + j * swork_dim1] * scaloc;
  1674. if (scal != 1.f) {
  1675. i__2 = j2 - 1;
  1676. for (jj = j1; jj <= i__2; ++jj) {
  1677. i__3 = k2 - k1;
  1678. csscal_(&i__3, &scal, &c__[k1 + jj * c_dim1], &
  1679. c__1);
  1680. }
  1681. }
  1682. /* Record current scaling factor */
  1683. swork[k + l * swork_dim1] = scamin * scaloc;
  1684. swork[k + j * swork_dim1] = scamin * scaloc;
  1685. i__2 = k2 - k1;
  1686. i__3 = j2 - j1;
  1687. i__4 = l2 - l1;
  1688. q__1.r = -csgn.r, q__1.i = -csgn.i;
  1689. cgemm_("N", "C", &i__2, &i__3, &i__4, &q__1, &c__[k1 + l1
  1690. * c_dim1], ldc, &b[j1 + l1 * b_dim1], ldb, &c_b1,
  1691. &c__[k1 + j1 * c_dim1], ldc)
  1692. ;
  1693. }
  1694. }
  1695. }
  1696. }
  1697. free(wnrm);
  1698. /* Reduce local scaling factors */
  1699. *scale = swork[swork_dim1 + 1];
  1700. i__1 = nba;
  1701. for (k = 1; k <= i__1; ++k) {
  1702. i__2 = nbb;
  1703. for (l = 1; l <= i__2; ++l) {
  1704. /* Computing MIN */
  1705. r__1 = *scale, r__2 = swork[k + l * swork_dim1];
  1706. *scale = f2cmin(r__1,r__2);
  1707. }
  1708. }
  1709. if (*scale == 0.f) {
  1710. /* The magnitude of the largest entry of the solution is larger */
  1711. /* than the product of BIGNUM**2 and cannot be represented in the */
  1712. /* form (1/SCALE)*X if SCALE is REAL. Set SCALE to */
  1713. /* zero and give up. */
  1714. swork[swork_dim1 + 1] = (real) f2cmax(nba,nbb);
  1715. swork[swork_dim1 + 2] = (real) ((nbb << 1) + nba);
  1716. return;
  1717. }
  1718. /* Realize consistent scaling */
  1719. i__1 = nba;
  1720. for (k = 1; k <= i__1; ++k) {
  1721. k1 = (k - 1) * nb + 1;
  1722. /* Computing MIN */
  1723. i__2 = k * nb;
  1724. k2 = f2cmin(i__2,*m) + 1;
  1725. i__2 = nbb;
  1726. for (l = 1; l <= i__2; ++l) {
  1727. l1 = (l - 1) * nb + 1;
  1728. /* Computing MIN */
  1729. i__3 = l * nb;
  1730. l2 = f2cmin(i__3,*n) + 1;
  1731. scal = *scale / swork[k + l * swork_dim1];
  1732. if (scal != 1.f) {
  1733. i__3 = l2 - 1;
  1734. for (ll = l1; ll <= i__3; ++ll) {
  1735. i__4 = k2 - k1;
  1736. csscal_(&i__4, &scal, &c__[k1 + ll * c_dim1], &c__1);
  1737. }
  1738. }
  1739. }
  1740. }
  1741. if (buf != 1.f && buf > 0.f) {
  1742. /* Decrease SCALE as much as possible. */
  1743. /* Computing MIN */
  1744. r__1 = *scale / smlnum, r__2 = 1.f / buf;
  1745. scaloc = f2cmin(r__1,r__2);
  1746. buf *= scaloc;
  1747. *scale /= scaloc;
  1748. }
  1749. if (buf != 1.f && buf > 0.f) {
  1750. /* In case of overly aggressive scaling during the computation, */
  1751. /* flushing of the global scale factor may be prevented by */
  1752. /* undoing some of the scaling. This step is to ensure that */
  1753. /* this routine flushes only scale factors that TRSYL also */
  1754. /* flushes and be usable as a drop-in replacement. */
  1755. /* How much can the normwise largest entry be upscaled? */
  1756. /* Computing MAX */
  1757. i__1 = c_dim1 + 1;
  1758. r__3 = (r__1 = c__[i__1].r, abs(r__1)), r__4 = (r__2 = r_imag(&c__[
  1759. c_dim1 + 1]), abs(r__2));
  1760. scal = f2cmax(r__3,r__4);
  1761. i__1 = *m;
  1762. for (k = 1; k <= i__1; ++k) {
  1763. i__2 = *n;
  1764. for (l = 1; l <= i__2; ++l) {
  1765. /* Computing MAX */
  1766. i__3 = k + l * c_dim1;
  1767. r__3 = scal, r__4 = (r__1 = c__[i__3].r, abs(r__1)), r__3 =
  1768. f2cmax(r__3,r__4), r__4 = (r__2 = r_imag(&c__[k + l *
  1769. c_dim1]), abs(r__2));
  1770. scal = f2cmax(r__3,r__4);
  1771. }
  1772. }
  1773. /* Increase BUF as close to 1 as possible and apply scaling. */
  1774. /* Computing MIN */
  1775. r__1 = bignum / scal, r__2 = 1.f / buf;
  1776. scaloc = f2cmin(r__1,r__2);
  1777. buf *= scaloc;
  1778. clascl_("G", &c_n1, &c_n1, &c_b106, &scaloc, m, n, &c__[c_offset],
  1779. ldc, &iinfo);
  1780. }
  1781. /* Combine with buffer scaling factor. SCALE will be flushed if */
  1782. /* BUF is less than one here. */
  1783. *scale *= buf;
  1784. /* Restore workspace dimensions */
  1785. swork[swork_dim1 + 1] = (real) f2cmax(nba,nbb);
  1786. swork[swork_dim1 + 2] = (real) ((nbb << 1) + nba);
  1787. return;
  1788. /* End of CTRSYL3 */
  1789. } /* ctrsyl3_ */