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 int logical;
  52. typedef short int shortlogical;
  53. typedef char logical1;
  54. typedef char integer1;
  55. #define TRUE_ (1)
  56. #define FALSE_ (0)
  57. /* Extern is for use with -E */
  58. #ifndef Extern
  59. #define Extern extern
  60. #endif
  61. /* I/O stuff */
  62. typedef int flag;
  63. typedef int ftnlen;
  64. typedef int ftnint;
  65. /*external read, write*/
  66. typedef struct
  67. { flag cierr;
  68. ftnint ciunit;
  69. flag ciend;
  70. char *cifmt;
  71. ftnint cirec;
  72. } cilist;
  73. /*internal read, write*/
  74. typedef struct
  75. { flag icierr;
  76. char *iciunit;
  77. flag iciend;
  78. char *icifmt;
  79. ftnint icirlen;
  80. ftnint icirnum;
  81. } icilist;
  82. /*open*/
  83. typedef struct
  84. { flag oerr;
  85. ftnint ounit;
  86. char *ofnm;
  87. ftnlen ofnmlen;
  88. char *osta;
  89. char *oacc;
  90. char *ofm;
  91. ftnint orl;
  92. char *oblnk;
  93. } olist;
  94. /*close*/
  95. typedef struct
  96. { flag cerr;
  97. ftnint cunit;
  98. char *csta;
  99. } cllist;
  100. /*rewind, backspace, endfile*/
  101. typedef struct
  102. { flag aerr;
  103. ftnint aunit;
  104. } alist;
  105. /* inquire */
  106. typedef struct
  107. { flag inerr;
  108. ftnint inunit;
  109. char *infile;
  110. ftnlen infilen;
  111. ftnint *inex; /*parameters in standard's order*/
  112. ftnint *inopen;
  113. ftnint *innum;
  114. ftnint *innamed;
  115. char *inname;
  116. ftnlen innamlen;
  117. char *inacc;
  118. ftnlen inacclen;
  119. char *inseq;
  120. ftnlen inseqlen;
  121. char *indir;
  122. ftnlen indirlen;
  123. char *infmt;
  124. ftnlen infmtlen;
  125. char *inform;
  126. ftnint informlen;
  127. char *inunf;
  128. ftnlen inunflen;
  129. ftnint *inrecl;
  130. ftnint *innrec;
  131. char *inblank;
  132. ftnlen inblanklen;
  133. } inlist;
  134. #define VOID void
  135. union Multitype { /* for multiple entry points */
  136. integer1 g;
  137. shortint h;
  138. integer i;
  139. /* longint j; */
  140. real r;
  141. doublereal d;
  142. complex c;
  143. doublecomplex z;
  144. };
  145. typedef union Multitype Multitype;
  146. struct Vardesc { /* for Namelist */
  147. char *name;
  148. char *addr;
  149. ftnlen *dims;
  150. int type;
  151. };
  152. typedef struct Vardesc Vardesc;
  153. struct Namelist {
  154. char *name;
  155. Vardesc **vars;
  156. int nvars;
  157. };
  158. typedef struct Namelist Namelist;
  159. #define abs(x) ((x) >= 0 ? (x) : -(x))
  160. #define dabs(x) (fabs(x))
  161. #define f2cmin(a,b) ((a) <= (b) ? (a) : (b))
  162. #define f2cmax(a,b) ((a) >= (b) ? (a) : (b))
  163. #define dmin(a,b) (f2cmin(a,b))
  164. #define dmax(a,b) (f2cmax(a,b))
  165. #define bit_test(a,b) ((a) >> (b) & 1)
  166. #define bit_clear(a,b) ((a) & ~((uinteger)1 << (b)))
  167. #define bit_set(a,b) ((a) | ((uinteger)1 << (b)))
  168. #define abort_() { sig_die("Fortran abort routine called", 1); }
  169. #define c_abs(z) (cabsf(Cf(z)))
  170. #define c_cos(R,Z) { pCf(R)=ccos(Cf(Z)); }
  171. #ifdef _MSC_VER
  172. #define c_div(c, a, b) {Cf(c)._Val[0] = (Cf(a)._Val[0]/Cf(b)._Val[0]); Cf(c)._Val[1]=(Cf(a)._Val[1]/Cf(b)._Val[1]);}
  173. #define z_div(c, a, b) {Cd(c)._Val[0] = (Cd(a)._Val[0]/Cd(b)._Val[0]); Cd(c)._Val[1]=(Cd(a)._Val[1]/Cd(b)._Val[1]);}
  174. #else
  175. #define c_div(c, a, b) {pCf(c) = Cf(a)/Cf(b);}
  176. #define z_div(c, a, b) {pCd(c) = Cd(a)/Cd(b);}
  177. #endif
  178. #define c_exp(R, Z) {pCf(R) = cexpf(Cf(Z));}
  179. #define c_log(R, Z) {pCf(R) = clogf(Cf(Z));}
  180. #define c_sin(R, Z) {pCf(R) = csinf(Cf(Z));}
  181. //#define c_sqrt(R, Z) {*(R) = csqrtf(Cf(Z));}
  182. #define c_sqrt(R, Z) {pCf(R) = csqrtf(Cf(Z));}
  183. #define d_abs(x) (fabs(*(x)))
  184. #define d_acos(x) (acos(*(x)))
  185. #define d_asin(x) (asin(*(x)))
  186. #define d_atan(x) (atan(*(x)))
  187. #define d_atn2(x, y) (atan2(*(x),*(y)))
  188. #define d_cnjg(R, Z) { pCd(R) = conj(Cd(Z)); }
  189. #define r_cnjg(R, Z) { pCf(R) = conjf(Cf(Z)); }
  190. #define d_cos(x) (cos(*(x)))
  191. #define d_cosh(x) (cosh(*(x)))
  192. #define d_dim(__a, __b) ( *(__a) > *(__b) ? *(__a) - *(__b) : 0.0 )
  193. #define d_exp(x) (exp(*(x)))
  194. #define d_imag(z) (cimag(Cd(z)))
  195. #define r_imag(z) (cimagf(Cf(z)))
  196. #define d_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
  197. #define r_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
  198. #define d_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
  199. #define r_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
  200. #define d_log(x) (log(*(x)))
  201. #define d_mod(x, y) (fmod(*(x), *(y)))
  202. #define u_nint(__x) ((__x)>=0 ? floor((__x) + .5) : -floor(.5 - (__x)))
  203. #define d_nint(x) u_nint(*(x))
  204. #define u_sign(__a,__b) ((__b) >= 0 ? ((__a) >= 0 ? (__a) : -(__a)) : -((__a) >= 0 ? (__a) : -(__a)))
  205. #define d_sign(a,b) u_sign(*(a),*(b))
  206. #define r_sign(a,b) u_sign(*(a),*(b))
  207. #define d_sin(x) (sin(*(x)))
  208. #define d_sinh(x) (sinh(*(x)))
  209. #define d_sqrt(x) (sqrt(*(x)))
  210. #define d_tan(x) (tan(*(x)))
  211. #define d_tanh(x) (tanh(*(x)))
  212. #define i_abs(x) abs(*(x))
  213. #define i_dnnt(x) ((integer)u_nint(*(x)))
  214. #define i_len(s, n) (n)
  215. #define i_nint(x) ((integer)u_nint(*(x)))
  216. #define i_sign(a,b) ((integer)u_sign((integer)*(a),(integer)*(b)))
  217. #define pow_dd(ap, bp) ( pow(*(ap), *(bp)))
  218. #define pow_si(B,E) spow_ui(*(B),*(E))
  219. #define pow_ri(B,E) spow_ui(*(B),*(E))
  220. #define pow_di(B,E) dpow_ui(*(B),*(E))
  221. #define pow_zi(p, a, b) {pCd(p) = zpow_ui(Cd(a), *(b));}
  222. #define pow_ci(p, a, b) {pCf(p) = cpow_ui(Cf(a), *(b));}
  223. #define pow_zz(R,A,B) {pCd(R) = cpow(Cd(A),*(B));}
  224. #define s_cat(lpp, rpp, rnp, np, llp) { ftnlen i, nc, ll; char *f__rp, *lp; ll = (llp); lp = (lpp); for(i=0; i < (int)*(np); ++i) { nc = ll; if((rnp)[i] < nc) nc = (rnp)[i]; ll -= nc; f__rp = (rpp)[i]; while(--nc >= 0) *lp++ = *(f__rp)++; } while(--ll >= 0) *lp++ = ' '; }
  225. #define s_cmp(a,b,c,d) ((integer)strncmp((a),(b),f2cmin((c),(d))))
  226. #define s_copy(A,B,C,D) { int __i,__m; for (__i=0, __m=f2cmin((C),(D)); __i<__m && (B)[__i] != 0; ++__i) (A)[__i] = (B)[__i]; }
  227. #define sig_die(s, kill) { exit(1); }
  228. #define s_stop(s, n) {exit(0);}
  229. static char junk[] = "\n@(#)LIBF77 VERSION 19990503\n";
  230. #define z_abs(z) (cabs(Cd(z)))
  231. #define z_exp(R, Z) {pCd(R) = cexp(Cd(Z));}
  232. #define z_sqrt(R, Z) {pCd(R) = csqrt(Cd(Z));}
  233. #define myexit_() break;
  234. #define mycycle_() continue;
  235. #define myceiling_(w) {ceil(w)}
  236. #define myhuge_(w) {HUGE_VAL}
  237. //#define mymaxloc_(w,s,e,n) {if (sizeof(*(w)) == sizeof(double)) dmaxloc_((w),*(s),*(e),n); else dmaxloc_((w),*(s),*(e),n);}
  238. #define mymaxloc_(w,s,e,n) dmaxloc_(w,*(s),*(e),n)
  239. #define myexp_(w) my_expfunc(w)
  240. static int my_expfunc(float *x) {int e; (void)frexpf(*x,&e); return e;}
  241. /* procedure parameter types for -A and -C++ */
  242. #define F2C_proc_par_types 1
  243. #ifdef __cplusplus
  244. typedef logical (*L_fp)(...);
  245. #else
  246. typedef logical (*L_fp)();
  247. #endif
  248. static float spow_ui(float x, integer n) {
  249. float pow=1.0; unsigned long int u;
  250. if(n != 0) {
  251. if(n < 0) n = -n, x = 1/x;
  252. for(u = n; ; ) {
  253. if(u & 01) pow *= x;
  254. if(u >>= 1) x *= x;
  255. else break;
  256. }
  257. }
  258. return pow;
  259. }
  260. static double dpow_ui(double x, integer n) {
  261. double pow=1.0; unsigned long int u;
  262. if(n != 0) {
  263. if(n < 0) n = -n, x = 1/x;
  264. for(u = n; ; ) {
  265. if(u & 01) pow *= x;
  266. if(u >>= 1) x *= x;
  267. else break;
  268. }
  269. }
  270. return pow;
  271. }
  272. #ifdef _MSC_VER
  273. static _Fcomplex cpow_ui(complex x, integer n) {
  274. complex pow={1.0,0.0}; unsigned long int u;
  275. if(n != 0) {
  276. if(n < 0) n = -n, x.r = 1/x.r, x.i=1/x.i;
  277. for(u = n; ; ) {
  278. if(u & 01) pow.r *= x.r, pow.i *= x.i;
  279. if(u >>= 1) x.r *= x.r, x.i *= x.i;
  280. else break;
  281. }
  282. }
  283. _Fcomplex p={pow.r, pow.i};
  284. return p;
  285. }
  286. #else
  287. static _Complex float cpow_ui(_Complex float x, integer n) {
  288. _Complex float pow=1.0; unsigned long int u;
  289. if(n != 0) {
  290. if(n < 0) n = -n, x = 1/x;
  291. for(u = n; ; ) {
  292. if(u & 01) pow *= x;
  293. if(u >>= 1) x *= x;
  294. else break;
  295. }
  296. }
  297. return pow;
  298. }
  299. #endif
  300. #ifdef _MSC_VER
  301. static _Dcomplex zpow_ui(_Dcomplex x, integer n) {
  302. _Dcomplex pow={1.0,0.0}; unsigned long int u;
  303. if(n != 0) {
  304. if(n < 0) n = -n, x._Val[0] = 1/x._Val[0], x._Val[1] =1/x._Val[1];
  305. for(u = n; ; ) {
  306. if(u & 01) pow._Val[0] *= x._Val[0], pow._Val[1] *= x._Val[1];
  307. if(u >>= 1) x._Val[0] *= x._Val[0], x._Val[1] *= x._Val[1];
  308. else break;
  309. }
  310. }
  311. _Dcomplex p = {pow._Val[0], pow._Val[1]};
  312. return p;
  313. }
  314. #else
  315. static _Complex double zpow_ui(_Complex double x, integer n) {
  316. _Complex double pow=1.0; unsigned long int u;
  317. if(n != 0) {
  318. if(n < 0) n = -n, x = 1/x;
  319. for(u = n; ; ) {
  320. if(u & 01) pow *= x;
  321. if(u >>= 1) x *= x;
  322. else break;
  323. }
  324. }
  325. return pow;
  326. }
  327. #endif
  328. static integer pow_ii(integer x, integer n) {
  329. integer pow; unsigned long int u;
  330. if (n <= 0) {
  331. if (n == 0 || x == 1) pow = 1;
  332. else if (x != -1) pow = x == 0 ? 1/x : 0;
  333. else n = -n;
  334. }
  335. if ((n > 0) || !(n == 0 || x == 1 || x != -1)) {
  336. u = n;
  337. for(pow = 1; ; ) {
  338. if(u & 01) pow *= x;
  339. if(u >>= 1) x *= x;
  340. else break;
  341. }
  342. }
  343. return pow;
  344. }
  345. static integer dmaxloc_(double *w, integer s, integer e, integer *n)
  346. {
  347. double m; integer i, mi;
  348. for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
  349. if (w[i-1]>m) mi=i ,m=w[i-1];
  350. return mi-s+1;
  351. }
  352. static integer smaxloc_(float *w, integer s, integer e, integer *n)
  353. {
  354. float m; integer i, mi;
  355. for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
  356. if (w[i-1]>m) mi=i ,m=w[i-1];
  357. return mi-s+1;
  358. }
  359. static inline void cdotc_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
  360. integer n = *n_, incx = *incx_, incy = *incy_, i;
  361. #ifdef _MSC_VER
  362. _Fcomplex zdotc = {0.0, 0.0};
  363. if (incx == 1 && incy == 1) {
  364. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  365. zdotc._Val[0] += conjf(Cf(&x[i]))._Val[0] * Cf(&y[i])._Val[0];
  366. zdotc._Val[1] += conjf(Cf(&x[i]))._Val[1] * Cf(&y[i])._Val[1];
  367. }
  368. } else {
  369. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  370. zdotc._Val[0] += conjf(Cf(&x[i*incx]))._Val[0] * Cf(&y[i*incy])._Val[0];
  371. zdotc._Val[1] += conjf(Cf(&x[i*incx]))._Val[1] * Cf(&y[i*incy])._Val[1];
  372. }
  373. }
  374. pCf(z) = zdotc;
  375. }
  376. #else
  377. _Complex float zdotc = 0.0;
  378. if (incx == 1 && incy == 1) {
  379. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  380. zdotc += conjf(Cf(&x[i])) * Cf(&y[i]);
  381. }
  382. } else {
  383. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  384. zdotc += conjf(Cf(&x[i*incx])) * Cf(&y[i*incy]);
  385. }
  386. }
  387. pCf(z) = zdotc;
  388. }
  389. #endif
  390. static inline void zdotc_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
  391. integer n = *n_, incx = *incx_, incy = *incy_, i;
  392. #ifdef _MSC_VER
  393. _Dcomplex zdotc = {0.0, 0.0};
  394. if (incx == 1 && incy == 1) {
  395. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  396. zdotc._Val[0] += conj(Cd(&x[i]))._Val[0] * Cd(&y[i])._Val[0];
  397. zdotc._Val[1] += conj(Cd(&x[i]))._Val[1] * Cd(&y[i])._Val[1];
  398. }
  399. } else {
  400. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  401. zdotc._Val[0] += conj(Cd(&x[i*incx]))._Val[0] * Cd(&y[i*incy])._Val[0];
  402. zdotc._Val[1] += conj(Cd(&x[i*incx]))._Val[1] * Cd(&y[i*incy])._Val[1];
  403. }
  404. }
  405. pCd(z) = zdotc;
  406. }
  407. #else
  408. _Complex double zdotc = 0.0;
  409. if (incx == 1 && incy == 1) {
  410. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  411. zdotc += conj(Cd(&x[i])) * Cd(&y[i]);
  412. }
  413. } else {
  414. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  415. zdotc += conj(Cd(&x[i*incx])) * Cd(&y[i*incy]);
  416. }
  417. }
  418. pCd(z) = zdotc;
  419. }
  420. #endif
  421. static inline void cdotu_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
  422. integer n = *n_, incx = *incx_, incy = *incy_, i;
  423. #ifdef _MSC_VER
  424. _Fcomplex zdotc = {0.0, 0.0};
  425. if (incx == 1 && incy == 1) {
  426. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  427. zdotc._Val[0] += Cf(&x[i])._Val[0] * Cf(&y[i])._Val[0];
  428. zdotc._Val[1] += Cf(&x[i])._Val[1] * Cf(&y[i])._Val[1];
  429. }
  430. } else {
  431. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  432. zdotc._Val[0] += Cf(&x[i*incx])._Val[0] * Cf(&y[i*incy])._Val[0];
  433. zdotc._Val[1] += Cf(&x[i*incx])._Val[1] * Cf(&y[i*incy])._Val[1];
  434. }
  435. }
  436. pCf(z) = zdotc;
  437. }
  438. #else
  439. _Complex float zdotc = 0.0;
  440. if (incx == 1 && incy == 1) {
  441. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  442. zdotc += Cf(&x[i]) * Cf(&y[i]);
  443. }
  444. } else {
  445. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  446. zdotc += Cf(&x[i*incx]) * Cf(&y[i*incy]);
  447. }
  448. }
  449. pCf(z) = zdotc;
  450. }
  451. #endif
  452. static inline void zdotu_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
  453. integer n = *n_, incx = *incx_, incy = *incy_, i;
  454. #ifdef _MSC_VER
  455. _Dcomplex zdotc = {0.0, 0.0};
  456. if (incx == 1 && incy == 1) {
  457. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  458. zdotc._Val[0] += Cd(&x[i])._Val[0] * Cd(&y[i])._Val[0];
  459. zdotc._Val[1] += Cd(&x[i])._Val[1] * Cd(&y[i])._Val[1];
  460. }
  461. } else {
  462. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  463. zdotc._Val[0] += Cd(&x[i*incx])._Val[0] * Cd(&y[i*incy])._Val[0];
  464. zdotc._Val[1] += Cd(&x[i*incx])._Val[1] * Cd(&y[i*incy])._Val[1];
  465. }
  466. }
  467. pCd(z) = zdotc;
  468. }
  469. #else
  470. _Complex double zdotc = 0.0;
  471. if (incx == 1 && incy == 1) {
  472. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  473. zdotc += Cd(&x[i]) * Cd(&y[i]);
  474. }
  475. } else {
  476. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  477. zdotc += Cd(&x[i*incx]) * Cd(&y[i*incy]);
  478. }
  479. }
  480. pCd(z) = zdotc;
  481. }
  482. #endif
  483. /* -- translated by f2c (version 20000121).
  484. You must link the resulting object file with the libraries:
  485. -lf2c -lm (in that order)
  486. */
  487. /* Table of constant values */
  488. static complex c_b1 = {1.f,0.f};
  489. static integer c__1 = 1;
  490. static integer c_n1 = -1;
  491. static real c_b18 = 2.f;
  492. static real c_b106 = 1.f;
  493. /* > \brief \b CTRSYL3 */
  494. /* Definition: */
  495. /* =========== */
  496. /* > \par Purpose */
  497. /* ============= */
  498. /* > */
  499. /* > \verbatim */
  500. /* > */
  501. /* > CTRSYL3 solves the complex Sylvester matrix equation: */
  502. /* > */
  503. /* > op(A)*X + X*op(B) = scale*C or */
  504. /* > op(A)*X - X*op(B) = scale*C, */
  505. /* > */
  506. /* > where op(A) = A or A**H, and A and B are both upper triangular. A is */
  507. /* > M-by-M and B is N-by-N; the right hand side C and the solution X are */
  508. /* > M-by-N; and scale is an output scale factor, set <= 1 to avoid */
  509. /* > overflow in X. */
  510. /* > */
  511. /* > This is the block version of the algorithm. */
  512. /* > \endverbatim */
  513. /* Arguments */
  514. /* ========= */
  515. /* > \param[in] TRANA */
  516. /* > \verbatim */
  517. /* > TRANA is CHARACTER*1 */
  518. /* > Specifies the option op(A): */
  519. /* > = 'N': op(A) = A (No transpose) */
  520. /* > = 'C': op(A) = A**H (Conjugate transpose) */
  521. /* > \endverbatim */
  522. /* > */
  523. /* > \param[in] TRANB */
  524. /* > \verbatim */
  525. /* > TRANB is CHARACTER*1 */
  526. /* > Specifies the option op(B): */
  527. /* > = 'N': op(B) = B (No transpose) */
  528. /* > = 'C': op(B) = B**H (Conjugate transpose) */
  529. /* > \endverbatim */
  530. /* > */
  531. /* > \param[in] ISGN */
  532. /* > \verbatim */
  533. /* > ISGN is INTEGER */
  534. /* > Specifies the sign in the equation: */
  535. /* > = +1: solve op(A)*X + X*op(B) = scale*C */
  536. /* > = -1: solve op(A)*X - X*op(B) = scale*C */
  537. /* > \endverbatim */
  538. /* > */
  539. /* > \param[in] M */
  540. /* > \verbatim */
  541. /* > M is INTEGER */
  542. /* > The order of the matrix A, and the number of rows in the */
  543. /* > matrices X and C. M >= 0. */
  544. /* > \endverbatim */
  545. /* > */
  546. /* > \param[in] N */
  547. /* > \verbatim */
  548. /* > N is INTEGER */
  549. /* > The order of the matrix B, and the number of columns in the */
  550. /* > matrices X and C. N >= 0. */
  551. /* > \endverbatim */
  552. /* > */
  553. /* > \param[in] A */
  554. /* > \verbatim */
  555. /* > A is COMPLEX array, dimension (LDA,M) */
  556. /* > The upper triangular matrix A. */
  557. /* > \endverbatim */
  558. /* > */
  559. /* > \param[in] LDA */
  560. /* > \verbatim */
  561. /* > LDA is INTEGER */
  562. /* > The leading dimension of the array A. LDA >= f2cmax(1,M). */
  563. /* > \endverbatim */
  564. /* > */
  565. /* > \param[in] B */
  566. /* > \verbatim */
  567. /* > B is COMPLEX array, dimension (LDB,N) */
  568. /* > The upper triangular matrix B. */
  569. /* > \endverbatim */
  570. /* > */
  571. /* > \param[in] LDB */
  572. /* > \verbatim */
  573. /* > LDB is INTEGER */
  574. /* > The leading dimension of the array B. LDB >= f2cmax(1,N). */
  575. /* > \endverbatim */
  576. /* > */
  577. /* > \param[in,out] C */
  578. /* > \verbatim */
  579. /* > C is COMPLEX array, dimension (LDC,N) */
  580. /* > On entry, the M-by-N right hand side matrix C. */
  581. /* > On exit, C is overwritten by the solution matrix X. */
  582. /* > \endverbatim */
  583. /* > */
  584. /* > \param[in] LDC */
  585. /* > \verbatim */
  586. /* > LDC is INTEGER */
  587. /* > The leading dimension of the array C. LDC >= f2cmax(1,M) */
  588. /* > \endverbatim */
  589. /* > */
  590. /* > \param[out] SCALE */
  591. /* > \verbatim */
  592. /* > SCALE is REAL */
  593. /* > The scale factor, scale, set <= 1 to avoid overflow in X. */
  594. /* > \endverbatim */
  595. /* > */
  596. /* > \param[out] SWORK */
  597. /* > \verbatim */
  598. /* > SWORK is REAL array, dimension (MAX(2, ROWS), MAX(1,COLS)). */
  599. /* > On exit, if INFO = 0, SWORK(1) returns the optimal value ROWS */
  600. /* > and SWORK(2) returns the optimal COLS. */
  601. /* > \endverbatim */
  602. /* > */
  603. /* > \param[in] LDSWORK */
  604. /* > \verbatim */
  605. /* > LDSWORK is INTEGER */
  606. /* > LDSWORK >= MAX(2,ROWS), where ROWS = ((M + NB - 1) / NB + 1) */
  607. /* > and NB is the optimal block size. */
  608. /* > */
  609. /* > If LDSWORK = -1, then a workspace query is assumed; the routine */
  610. /* > only calculates the optimal dimensions of the SWORK matrix, */
  611. /* > returns these values as the first and second entry of the SWORK */
  612. /* > matrix, and no error message related LWORK is issued by XERBLA. */
  613. /* > \endverbatim */
  614. /* > */
  615. /* > \param[out] INFO */
  616. /* > \verbatim */
  617. /* > INFO is INTEGER */
  618. /* > = 0: successful exit */
  619. /* > < 0: if INFO = -i, the i-th argument had an illegal value */
  620. /* > = 1: A and B have common or very close eigenvalues; perturbed */
  621. /* > values were used to solve the equation (but the matrices */
  622. /* > A and B are unchanged). */
  623. /* > \endverbatim */
  624. /* > \ingroup complexSYcomputational */
  625. /* ===================================================================== */
  626. /* References: */
  627. /* E. S. Quintana-Orti and R. A. Van De Geijn (2003). Formal derivation of */
  628. /* algorithms: The triangular Sylvester equation, ACM Transactions */
  629. /* on Mathematical Software (TOMS), volume 29, pages 218--243. */
  630. /* A. Schwarz and C. C. Kjelgaard Mikkelsen (2020). Robust Task-Parallel */
  631. /* Solution of the Triangular Sylvester Equation. Lecture Notes in */
  632. /* Computer Science, vol 12043, pages 82--92, Springer. */
  633. /* Contributor: */
  634. /* Angelika Schwarz, Umea University, Sweden. */
  635. /* ===================================================================== */
  636. /* Subroutine */ void ctrsyl3_(char *trana, char *tranb, integer *isgn,
  637. integer *m, integer *n, complex *a, integer *lda, complex *b, integer
  638. *ldb, complex *c__, integer *ldc, real *scale, real *swork, integer *
  639. ldswork, integer *info)
  640. {
  641. /* System generated locals */
  642. integer a_dim1, a_offset, b_dim1, b_offset, c_dim1, c_offset, swork_dim1,
  643. swork_offset, i__1, i__2, i__3, i__4, i__5, i__6;
  644. real r__1, r__2, r__3, r__4;
  645. complex q__1;
  646. /* Local variables */
  647. real scal;
  648. complex csgn;
  649. real anrm, bnrm, cnrm;
  650. integer awrk, bwrk;
  651. real *wnrm, xnrm;
  652. integer i__, j, k, l;
  653. extern /* Subroutine */ void cgemm_(char *, char *, integer *, integer *,
  654. integer *, complex *, complex *, integer *, complex *, integer *,
  655. complex *, complex *, integer *);
  656. extern logical lsame_(char *, char *);
  657. integer iinfo, i1, i2, j1, j2, k1, k2, l1, l2;
  658. // extern integer myexp_(real *);
  659. integer nb, jj, ll;
  660. extern real clange_(char *, integer *, integer *, complex *, integer *,
  661. real *);
  662. extern /* Subroutine */ void clascl_(char *, integer *, integer *, real *,
  663. real *, integer *, integer *, complex *, integer *, integer *);
  664. real scaloc;
  665. extern real slamch_(char *);
  666. extern /* Subroutine */ void csscal_(integer *, real *, complex *, integer
  667. *);
  668. real scamin;
  669. extern /* Subroutine */ int xerbla_(char *, integer *, ftnlen );
  670. extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
  671. integer *, integer *, ftnlen, ftnlen);
  672. real bignum;
  673. extern real slarmm_(real *, real *, real *);
  674. logical notrna, notrnb;
  675. real smlnum;
  676. extern /* Subroutine */ void ctrsyl_(char *, char *, integer *, integer *,
  677. integer *, complex *, integer *, complex *, integer *, complex *,
  678. integer *, real *, integer *);
  679. logical lquery;
  680. integer nba, nbb;
  681. real buf, sgn;
  682. /* Decode and Test input parameters */
  683. /* Parameter adjustments */
  684. a_dim1 = *lda;
  685. a_offset = 1 + a_dim1 * 1;
  686. a -= a_offset;
  687. b_dim1 = *ldb;
  688. b_offset = 1 + b_dim1 * 1;
  689. b -= b_offset;
  690. c_dim1 = *ldc;
  691. c_offset = 1 + c_dim1 * 1;
  692. c__ -= c_offset;
  693. swork_dim1 = *ldswork;
  694. swork_offset = 1 + swork_dim1 * 1;
  695. swork -= swork_offset;
  696. /* Function Body */
  697. notrna = lsame_(trana, "N");
  698. notrnb = lsame_(tranb, "N");
  699. /* Use the same block size for all matrices. */
  700. /* Computing MAX */
  701. i__1 = 8, i__2 = ilaenv_(&c__1, "CTRSYL", "", m, n, &c_n1, &c_n1, (ftnlen)
  702. 6, (ftnlen)0);
  703. nb = f2cmax(i__1,i__2);
  704. /* Compute number of blocks in A and B */
  705. /* Computing MAX */
  706. i__1 = 1, i__2 = (*m + nb - 1) / nb;
  707. nba = f2cmax(i__1,i__2);
  708. /* Computing MAX */
  709. i__1 = 1, i__2 = (*n + nb - 1) / nb;
  710. nbb = f2cmax(i__1,i__2);
  711. /* Compute workspace */
  712. *info = 0;
  713. lquery = *ldswork == -1;
  714. if (lquery) {
  715. *ldswork = 2;
  716. swork[swork_dim1 + 1] = (real) f2cmax(nba,nbb);
  717. swork[swork_dim1 + 2] = (real) ((nbb << 1) + nba);
  718. }
  719. /* Test the input arguments */
  720. if (! notrna && ! lsame_(trana, "C")) {
  721. *info = -1;
  722. } else if (! notrnb && ! lsame_(tranb, "C")) {
  723. *info = -2;
  724. } else if (*isgn != 1 && *isgn != -1) {
  725. *info = -3;
  726. } else if (*m < 0) {
  727. *info = -4;
  728. } else if (*n < 0) {
  729. *info = -5;
  730. } else if (*lda < f2cmax(1,*m)) {
  731. *info = -7;
  732. } else if (*ldb < f2cmax(1,*n)) {
  733. *info = -9;
  734. } else if (*ldc < f2cmax(1,*m)) {
  735. *info = -11;
  736. }
  737. if (*info != 0) {
  738. i__1 = -(*info);
  739. xerbla_("CTRSYL3", &i__1, 7);
  740. return;
  741. } else if (lquery) {
  742. return;
  743. }
  744. /* Quick return if possible */
  745. *scale = 1.f;
  746. if (*m == 0 || *n == 0) {
  747. return;
  748. }
  749. wnrm = (real*)malloc(f2cmax(*m,*n)*sizeof(real));
  750. /* Use unblocked code for small problems or if insufficient */
  751. /* workspace is provided */
  752. if (f2cmin(nba,nbb) == 1 || *ldswork < f2cmax(nba,nbb)) {
  753. ctrsyl_(trana, tranb, isgn, m, n, &a[a_offset], lda, &b[b_offset],
  754. ldb, &c__[c_offset], ldc, scale, info);
  755. return;
  756. }
  757. /* Set constants to control overflow */
  758. smlnum = slamch_("S");
  759. bignum = 1.f / smlnum;
  760. /* Set local scaling factors. */
  761. i__1 = nbb;
  762. for (l = 1; l <= i__1; ++l) {
  763. i__2 = nba;
  764. for (k = 1; k <= i__2; ++k) {
  765. swork[k + l * swork_dim1] = 1.f;
  766. }
  767. }
  768. /* Fallback scaling factor to prevent flushing of SWORK( K, L ) to zero. */
  769. /* This scaling is to ensure compatibility with TRSYL and may get flushed. */
  770. buf = 1.f;
  771. /* Compute upper bounds of blocks of A and B */
  772. awrk = nbb;
  773. i__1 = nba;
  774. for (k = 1; k <= i__1; ++k) {
  775. k1 = (k - 1) * nb + 1;
  776. /* Computing MIN */
  777. i__2 = k * nb;
  778. k2 = f2cmin(i__2,*m) + 1;
  779. i__2 = nba;
  780. for (l = k; l <= i__2; ++l) {
  781. l1 = (l - 1) * nb + 1;
  782. /* Computing MIN */
  783. i__3 = l * nb;
  784. l2 = f2cmin(i__3,*m) + 1;
  785. if (notrna) {
  786. i__3 = k2 - k1;
  787. i__4 = l2 - l1;
  788. swork[k + (awrk + l) * swork_dim1] = clange_("I", &i__3, &
  789. i__4, &a[k1 + l1 * a_dim1], lda, wnrm);
  790. } else {
  791. i__3 = k2 - k1;
  792. i__4 = l2 - l1;
  793. swork[l + (awrk + k) * swork_dim1] = clange_("1", &i__3, &
  794. i__4, &a[k1 + l1 * a_dim1], lda, wnrm);
  795. }
  796. }
  797. }
  798. bwrk = nbb + nba;
  799. i__1 = nbb;
  800. for (k = 1; k <= i__1; ++k) {
  801. k1 = (k - 1) * nb + 1;
  802. /* Computing MIN */
  803. i__2 = k * nb;
  804. k2 = f2cmin(i__2,*n) + 1;
  805. i__2 = nbb;
  806. for (l = k; l <= i__2; ++l) {
  807. l1 = (l - 1) * nb + 1;
  808. /* Computing MIN */
  809. i__3 = l * nb;
  810. l2 = f2cmin(i__3,*n) + 1;
  811. if (notrnb) {
  812. i__3 = k2 - k1;
  813. i__4 = l2 - l1;
  814. swork[k + (bwrk + l) * swork_dim1] = clange_("I", &i__3, &
  815. i__4, &b[k1 + l1 * b_dim1], ldb, wnrm);
  816. } else {
  817. i__3 = k2 - k1;
  818. i__4 = l2 - l1;
  819. swork[l + (bwrk + k) * swork_dim1] = clange_("1", &i__3, &
  820. i__4, &b[k1 + l1 * b_dim1], ldb, wnrm);
  821. }
  822. }
  823. }
  824. sgn = (real) (*isgn);
  825. q__1.r = sgn, q__1.i = 0.f;
  826. csgn.r = q__1.r, csgn.i = q__1.i;
  827. if (notrna && notrnb) {
  828. /* Solve A*X + ISGN*X*B = scale*C. */
  829. /* The (K,L)th block of X is determined starting from */
  830. /* bottom-left corner column by column by */
  831. /* A(K,K)*X(K,L) + ISGN*X(K,L)*B(L,L) = C(K,L) - R(K,L) */
  832. /* Where */
  833. /* M L-1 */
  834. /* R(K,L) = SUM [A(K,I)*X(I,L)] + ISGN*SUM [X(K,J)*B(J,L)]. */
  835. /* I=K+1 J=1 */
  836. /* Start loop over block rows (index = K) and block columns (index = L) */
  837. for (k = nba; k >= 1; --k) {
  838. /* K1: row index of the first row in X( K, L ) */
  839. /* K2: row index of the first row in X( K+1, L ) */
  840. /* so the K2 - K1 is the column count of the block X( K, L ) */
  841. k1 = (k - 1) * nb + 1;
  842. /* Computing MIN */
  843. i__1 = k * nb;
  844. k2 = f2cmin(i__1,*m) + 1;
  845. i__1 = nbb;
  846. for (l = 1; l <= i__1; ++l) {
  847. /* L1: column index of the first column in X( K, L ) */
  848. /* L2: column index of the first column in X( K, L + 1) */
  849. /* so that L2 - L1 is the row count of the block X( K, L ) */
  850. l1 = (l - 1) * nb + 1;
  851. /* Computing MIN */
  852. i__2 = l * nb;
  853. l2 = f2cmin(i__2,*n) + 1;
  854. i__2 = k2 - k1;
  855. i__3 = l2 - l1;
  856. ctrsyl_(trana, tranb, isgn, &i__2, &i__3, &a[k1 + k1 * a_dim1]
  857. , lda, &b[l1 + l1 * b_dim1], ldb, &c__[k1 + l1 *
  858. c_dim1], ldc, &scaloc, &iinfo);
  859. *info = f2cmax(*info,iinfo);
  860. if (scaloc * swork[k + l * swork_dim1] == 0.f) {
  861. if (scaloc == 0.f) {
  862. /* The magnitude of the largest entry of X(K1:K2-1, L1:L2-1) */
  863. /* is larger than the product of BIGNUM**2 and cannot be */
  864. /* represented in the form (1/SCALE)*X(K1:K2-1, L1:L2-1). */
  865. /* Mark the computation as pointless. */
  866. buf = 0.f;
  867. } else {
  868. /* Use second scaling factor to prevent flushing to zero. */
  869. i__2 = myexp_(&scaloc);
  870. buf *= pow_ri(&c_b18, &i__2);
  871. }
  872. i__2 = nbb;
  873. for (jj = 1; jj <= i__2; ++jj) {
  874. i__3 = nba;
  875. for (ll = 1; ll <= i__3; ++ll) {
  876. /* Bound by BIGNUM to not introduce Inf. The value */
  877. /* is irrelevant; corresponding entries of the */
  878. /* solution will be flushed in consistency scaling. */
  879. /* Computing MIN */
  880. i__4 = myexp_(&scaloc);
  881. r__1 = bignum, r__2 = swork[ll + jj * swork_dim1]
  882. / pow_ri(&c_b18, &i__4);
  883. swork[ll + jj * swork_dim1] = f2cmin(r__1,r__2);
  884. }
  885. }
  886. }
  887. swork[k + l * swork_dim1] = scaloc * swork[k + l * swork_dim1]
  888. ;
  889. i__2 = k2 - k1;
  890. i__3 = l2 - l1;
  891. xnrm = clange_("I", &i__2, &i__3, &c__[k1 + l1 * c_dim1], ldc,
  892. wnrm);
  893. for (i__ = k - 1; i__ >= 1; --i__) {
  894. /* C( I, L ) := C( I, L ) - A( I, K ) * C( K, L ) */
  895. i1 = (i__ - 1) * nb + 1;
  896. /* Computing MIN */
  897. i__2 = i__ * nb;
  898. i2 = f2cmin(i__2,*m) + 1;
  899. /* Compute scaling factor to survive the linear update */
  900. /* simulating consistent scaling. */
  901. i__2 = i2 - i1;
  902. i__3 = l2 - l1;
  903. cnrm = clange_("I", &i__2, &i__3, &c__[i1 + l1 * c_dim1],
  904. ldc, wnrm);
  905. /* Computing MIN */
  906. r__1 = swork[i__ + l * swork_dim1], r__2 = swork[k + l *
  907. swork_dim1];
  908. scamin = f2cmin(r__1,r__2);
  909. cnrm *= scamin / swork[i__ + l * swork_dim1];
  910. xnrm *= scamin / swork[k + l * swork_dim1];
  911. anrm = swork[i__ + (awrk + k) * swork_dim1];
  912. scaloc = slarmm_(&anrm, &xnrm, &cnrm);
  913. if (scaloc * scamin == 0.f) {
  914. /* Use second scaling factor to prevent flushing to zero. */
  915. i__2 = myexp_(&scaloc);
  916. buf *= pow_ri(&c_b18, &i__2);
  917. i__2 = nbb;
  918. for (jj = 1; jj <= i__2; ++jj) {
  919. i__3 = nba;
  920. for (ll = 1; ll <= i__3; ++ll) {
  921. /* Computing MIN */
  922. i__4 = myexp_(&scaloc);
  923. r__1 = bignum, r__2 = swork[ll + jj *
  924. swork_dim1] / pow_ri(&c_b18, &i__4);
  925. swork[ll + jj * swork_dim1] = f2cmin(r__1,r__2);
  926. }
  927. }
  928. i__2 = myexp_(&scaloc);
  929. scamin /= pow_ri(&c_b18, &i__2);
  930. i__2 = myexp_(&scaloc);
  931. scaloc /= pow_ri(&c_b18, &i__2);
  932. }
  933. cnrm *= scaloc;
  934. xnrm *= scaloc;
  935. /* Simultaneously apply the robust update factor and the */
  936. /* consistency scaling factor to C( I, L ) and C( K, L ). */
  937. scal = scamin / swork[k + l * swork_dim1] * scaloc;
  938. if (scal != 1.f) {
  939. i__2 = l2 - 1;
  940. for (jj = l1; jj <= i__2; ++jj) {
  941. i__3 = k2 - k1;
  942. csscal_(&i__3, &scal, &c__[k1 + jj * c_dim1], &
  943. c__1);
  944. }
  945. }
  946. scal = scamin / swork[i__ + l * swork_dim1] * scaloc;
  947. if (scal != 1.f) {
  948. i__2 = l2 - 1;
  949. for (ll = l1; ll <= i__2; ++ll) {
  950. i__3 = i2 - i1;
  951. csscal_(&i__3, &scal, &c__[i1 + ll * c_dim1], &
  952. c__1);
  953. }
  954. }
  955. /* Record current scaling factor */
  956. swork[k + l * swork_dim1] = scamin * scaloc;
  957. swork[i__ + l * swork_dim1] = scamin * scaloc;
  958. i__2 = i2 - i1;
  959. i__3 = l2 - l1;
  960. i__4 = k2 - k1;
  961. q__1.r = -1.f, q__1.i = 0.f;
  962. cgemm_("N", "N", &i__2, &i__3, &i__4, &q__1, &a[i1 + k1 *
  963. a_dim1], lda, &c__[k1 + l1 * c_dim1], ldc, &c_b1,
  964. &c__[i1 + l1 * c_dim1], ldc)
  965. ;
  966. }
  967. i__2 = nbb;
  968. for (j = l + 1; j <= i__2; ++j) {
  969. /* C( K, J ) := C( K, J ) - SGN * C( K, L ) * B( L, J ) */
  970. j1 = (j - 1) * nb + 1;
  971. /* Computing MIN */
  972. i__3 = j * nb;
  973. j2 = f2cmin(i__3,*n) + 1;
  974. /* Compute scaling factor to survive the linear update */
  975. /* simulating consistent scaling. */
  976. i__3 = k2 - k1;
  977. i__4 = j2 - j1;
  978. cnrm = clange_("I", &i__3, &i__4, &c__[k1 + j1 * c_dim1],
  979. ldc, wnrm);
  980. /* Computing MIN */
  981. r__1 = swork[k + j * swork_dim1], r__2 = swork[k + l *
  982. swork_dim1];
  983. scamin = f2cmin(r__1,r__2);
  984. cnrm *= scamin / swork[k + j * swork_dim1];
  985. xnrm *= scamin / swork[k + l * swork_dim1];
  986. bnrm = swork[l + (bwrk + j) * swork_dim1];
  987. scaloc = slarmm_(&bnrm, &xnrm, &cnrm);
  988. if (scaloc * scamin == 0.f) {
  989. /* Use second scaling factor to prevent flushing to zero. */
  990. i__3 = myexp_(&scaloc);
  991. buf *= pow_ri(&c_b18, &i__3);
  992. i__3 = nbb;
  993. for (jj = 1; jj <= i__3; ++jj) {
  994. i__4 = nba;
  995. for (ll = 1; ll <= i__4; ++ll) {
  996. /* Computing MIN */
  997. i__5 = myexp_(&scaloc);
  998. r__1 = bignum, r__2 = swork[ll + jj *
  999. swork_dim1] / pow_ri(&c_b18, &i__5);
  1000. swork[ll + jj * swork_dim1] = f2cmin(r__1,r__2);
  1001. }
  1002. }
  1003. i__3 = myexp_(&scaloc);
  1004. scamin /= pow_ri(&c_b18, &i__3);
  1005. i__3 = myexp_(&scaloc);
  1006. scaloc /= pow_ri(&c_b18, &i__3);
  1007. }
  1008. cnrm *= scaloc;
  1009. xnrm *= scaloc;
  1010. /* Simultaneously apply the robust update factor and the */
  1011. /* consistency scaling factor to C( K, J ) and C( K, L). */
  1012. scal = scamin / swork[k + l * swork_dim1] * scaloc;
  1013. if (scal != 1.f) {
  1014. i__3 = l2 - 1;
  1015. for (ll = l1; ll <= i__3; ++ll) {
  1016. i__4 = k2 - k1;
  1017. csscal_(&i__4, &scal, &c__[k1 + ll * c_dim1], &
  1018. c__1);
  1019. }
  1020. }
  1021. scal = scamin / swork[k + j * swork_dim1] * scaloc;
  1022. if (scal != 1.f) {
  1023. i__3 = j2 - 1;
  1024. for (jj = j1; jj <= i__3; ++jj) {
  1025. i__4 = k2 - k1;
  1026. csscal_(&i__4, &scal, &c__[k1 + jj * c_dim1], &
  1027. c__1);
  1028. }
  1029. }
  1030. /* Record current scaling factor */
  1031. swork[k + l * swork_dim1] = scamin * scaloc;
  1032. swork[k + j * swork_dim1] = scamin * scaloc;
  1033. i__3 = k2 - k1;
  1034. i__4 = j2 - j1;
  1035. i__5 = l2 - l1;
  1036. q__1.r = -csgn.r, q__1.i = -csgn.i;
  1037. cgemm_("N", "N", &i__3, &i__4, &i__5, &q__1, &c__[k1 + l1
  1038. * c_dim1], ldc, &b[l1 + j1 * b_dim1], ldb, &c_b1,
  1039. &c__[k1 + j1 * c_dim1], ldc)
  1040. ;
  1041. }
  1042. }
  1043. }
  1044. } else if (! notrna && notrnb) {
  1045. /* Solve A**H *X + ISGN*X*B = scale*C. */
  1046. /* The (K,L)th block of X is determined starting from */
  1047. /* upper-left corner column by column by */
  1048. /* A(K,K)**H*X(K,L) + ISGN*X(K,L)*B(L,L) = C(K,L) - R(K,L) */
  1049. /* Where */
  1050. /* K-1 L-1 */
  1051. /* R(K,L) = SUM [A(I,K)**H*X(I,L)] +ISGN*SUM [X(K,J)*B(J,L)] */
  1052. /* I=1 J=1 */
  1053. /* Start loop over block rows (index = K) and block columns (index = L) */
  1054. i__1 = nba;
  1055. for (k = 1; k <= i__1; ++k) {
  1056. /* K1: row index of the first row in X( K, L ) */
  1057. /* K2: row index of the first row in X( K+1, L ) */
  1058. /* so the K2 - K1 is the column count of the block X( K, L ) */
  1059. k1 = (k - 1) * nb + 1;
  1060. /* Computing MIN */
  1061. i__2 = k * nb;
  1062. k2 = f2cmin(i__2,*m) + 1;
  1063. i__2 = nbb;
  1064. for (l = 1; l <= i__2; ++l) {
  1065. /* L1: column index of the first column in X( K, L ) */
  1066. /* L2: column index of the first column in X( K, L + 1) */
  1067. /* so that L2 - L1 is the row count of the block X( K, L ) */
  1068. l1 = (l - 1) * nb + 1;
  1069. /* Computing MIN */
  1070. i__3 = l * nb;
  1071. l2 = f2cmin(i__3,*n) + 1;
  1072. i__3 = k2 - k1;
  1073. i__4 = l2 - l1;
  1074. ctrsyl_(trana, tranb, isgn, &i__3, &i__4, &a[k1 + k1 * a_dim1]
  1075. , lda, &b[l1 + l1 * b_dim1], ldb, &c__[k1 + l1 *
  1076. c_dim1], ldc, &scaloc, &iinfo);
  1077. *info = f2cmax(*info,iinfo);
  1078. if (scaloc * swork[k + l * swork_dim1] == 0.f) {
  1079. if (scaloc == 0.f) {
  1080. /* The magnitude of the largest entry of X(K1:K2-1, L1:L2-1) */
  1081. /* is larger than the product of BIGNUM**2 and cannot be */
  1082. /* represented in the form (1/SCALE)*X(K1:K2-1, L1:L2-1). */
  1083. /* Mark the computation as pointless. */
  1084. buf = 0.f;
  1085. } else {
  1086. /* Use second scaling factor to prevent flushing to zero. */
  1087. i__3 = myexp_(&scaloc);
  1088. buf *= pow_ri(&c_b18, &i__3);
  1089. }
  1090. i__3 = nbb;
  1091. for (jj = 1; jj <= i__3; ++jj) {
  1092. i__4 = nba;
  1093. for (ll = 1; ll <= i__4; ++ll) {
  1094. /* Bound by BIGNUM to not introduce Inf. The value */
  1095. /* is irrelevant; corresponding entries of the */
  1096. /* solution will be flushed in consistency scaling. */
  1097. /* Computing MIN */
  1098. i__5 = myexp_(&scaloc);
  1099. r__1 = bignum, r__2 = swork[ll + jj * swork_dim1]
  1100. / pow_ri(&c_b18, &i__5);
  1101. swork[ll + jj * swork_dim1] = f2cmin(r__1,r__2);
  1102. }
  1103. }
  1104. }
  1105. swork[k + l * swork_dim1] = scaloc * swork[k + l * swork_dim1]
  1106. ;
  1107. i__3 = k2 - k1;
  1108. i__4 = l2 - l1;
  1109. xnrm = clange_("I", &i__3, &i__4, &c__[k1 + l1 * c_dim1], ldc,
  1110. wnrm);
  1111. i__3 = nba;
  1112. for (i__ = k + 1; i__ <= i__3; ++i__) {
  1113. /* C( I, L ) := C( I, L ) - A( K, I )**H * C( K, L ) */
  1114. i1 = (i__ - 1) * nb + 1;
  1115. /* Computing MIN */
  1116. i__4 = i__ * nb;
  1117. i2 = f2cmin(i__4,*m) + 1;
  1118. /* Compute scaling factor to survive the linear update */
  1119. /* simulating consistent scaling. */
  1120. i__4 = i2 - i1;
  1121. i__5 = l2 - l1;
  1122. cnrm = clange_("I", &i__4, &i__5, &c__[i1 + l1 * c_dim1],
  1123. ldc, wnrm);
  1124. /* Computing MIN */
  1125. r__1 = swork[i__ + l * swork_dim1], r__2 = swork[k + l *
  1126. swork_dim1];
  1127. scamin = f2cmin(r__1,r__2);
  1128. cnrm *= scamin / swork[i__ + l * swork_dim1];
  1129. xnrm *= scamin / swork[k + l * swork_dim1];
  1130. anrm = swork[i__ + (awrk + k) * swork_dim1];
  1131. scaloc = slarmm_(&anrm, &xnrm, &cnrm);
  1132. if (scaloc * scamin == 0.f) {
  1133. /* Use second scaling factor to prevent flushing to zero. */
  1134. i__4 = myexp_(&scaloc);
  1135. buf *= pow_ri(&c_b18, &i__4);
  1136. i__4 = nbb;
  1137. for (jj = 1; jj <= i__4; ++jj) {
  1138. i__5 = nba;
  1139. for (ll = 1; ll <= i__5; ++ll) {
  1140. /* Computing MIN */
  1141. i__6 = myexp_(&scaloc);
  1142. r__1 = bignum, r__2 = swork[ll + jj *
  1143. swork_dim1] / pow_ri(&c_b18, &i__6);
  1144. swork[ll + jj * swork_dim1] = f2cmin(r__1,r__2);
  1145. }
  1146. }
  1147. i__4 = myexp_(&scaloc);
  1148. scamin /= pow_ri(&c_b18, &i__4);
  1149. i__4 = myexp_(&scaloc);
  1150. scaloc /= pow_ri(&c_b18, &i__4);
  1151. }
  1152. cnrm *= scaloc;
  1153. xnrm *= scaloc;
  1154. /* Simultaneously apply the robust update factor and the */
  1155. /* consistency scaling factor to to C( I, L ) and C( K, L). */
  1156. scal = scamin / swork[k + l * swork_dim1] * scaloc;
  1157. if (scal != 1.f) {
  1158. i__4 = l2 - 1;
  1159. for (ll = l1; ll <= i__4; ++ll) {
  1160. i__5 = k2 - k1;
  1161. csscal_(&i__5, &scal, &c__[k1 + ll * c_dim1], &
  1162. c__1);
  1163. }
  1164. }
  1165. scal = scamin / swork[i__ + l * swork_dim1] * scaloc;
  1166. if (scal != 1.f) {
  1167. i__4 = l2 - 1;
  1168. for (ll = l1; ll <= i__4; ++ll) {
  1169. i__5 = i2 - i1;
  1170. csscal_(&i__5, &scal, &c__[i1 + ll * c_dim1], &
  1171. c__1);
  1172. }
  1173. }
  1174. /* Record current scaling factor */
  1175. swork[k + l * swork_dim1] = scamin * scaloc;
  1176. swork[i__ + l * swork_dim1] = scamin * scaloc;
  1177. i__4 = i2 - i1;
  1178. i__5 = l2 - l1;
  1179. i__6 = k2 - k1;
  1180. q__1.r = -1.f, q__1.i = 0.f;
  1181. cgemm_("C", "N", &i__4, &i__5, &i__6, &q__1, &a[k1 + i1 *
  1182. a_dim1], lda, &c__[k1 + l1 * c_dim1], ldc, &c_b1,
  1183. &c__[i1 + l1 * c_dim1], ldc)
  1184. ;
  1185. }
  1186. i__3 = nbb;
  1187. for (j = l + 1; j <= i__3; ++j) {
  1188. /* C( K, J ) := C( K, J ) - SGN * C( K, L ) * B( L, J ) */
  1189. j1 = (j - 1) * nb + 1;
  1190. /* Computing MIN */
  1191. i__4 = j * nb;
  1192. j2 = f2cmin(i__4,*n) + 1;
  1193. /* Compute scaling factor to survive the linear update */
  1194. /* simulating consistent scaling. */
  1195. i__4 = k2 - k1;
  1196. i__5 = j2 - j1;
  1197. cnrm = clange_("I", &i__4, &i__5, &c__[k1 + j1 * c_dim1],
  1198. ldc, wnrm);
  1199. /* Computing MIN */
  1200. r__1 = swork[k + j * swork_dim1], r__2 = swork[k + l *
  1201. swork_dim1];
  1202. scamin = f2cmin(r__1,r__2);
  1203. cnrm *= scamin / swork[k + j * swork_dim1];
  1204. xnrm *= scamin / swork[k + l * swork_dim1];
  1205. bnrm = swork[l + (bwrk + j) * swork_dim1];
  1206. scaloc = slarmm_(&bnrm, &xnrm, &cnrm);
  1207. if (scaloc * scamin == 0.f) {
  1208. /* Use second scaling factor to prevent flushing to zero. */
  1209. i__4 = myexp_(&scaloc);
  1210. buf *= pow_ri(&c_b18, &i__4);
  1211. i__4 = nbb;
  1212. for (jj = 1; jj <= i__4; ++jj) {
  1213. i__5 = nba;
  1214. for (ll = 1; ll <= i__5; ++ll) {
  1215. /* Computing MIN */
  1216. i__6 = myexp_(&scaloc);
  1217. r__1 = bignum, r__2 = swork[ll + jj *
  1218. swork_dim1] / pow_ri(&c_b18, &i__6);
  1219. swork[ll + jj * swork_dim1] = f2cmin(r__1,r__2);
  1220. }
  1221. }
  1222. i__4 = myexp_(&scaloc);
  1223. scamin /= pow_ri(&c_b18, &i__4);
  1224. i__4 = myexp_(&scaloc);
  1225. scaloc /= pow_ri(&c_b18, &i__4);
  1226. }
  1227. cnrm *= scaloc;
  1228. xnrm *= scaloc;
  1229. /* Simultaneously apply the robust update factor and the */
  1230. /* consistency scaling factor to to C( K, J ) and C( K, L). */
  1231. scal = scamin / swork[k + l * swork_dim1] * scaloc;
  1232. if (scal != 1.f) {
  1233. i__4 = l2 - 1;
  1234. for (ll = l1; ll <= i__4; ++ll) {
  1235. i__5 = k2 - k1;
  1236. csscal_(&i__5, &scal, &c__[k1 + ll * c_dim1], &
  1237. c__1);
  1238. }
  1239. }
  1240. scal = scamin / swork[k + j * swork_dim1] * scaloc;
  1241. if (scal != 1.f) {
  1242. i__4 = j2 - 1;
  1243. for (jj = j1; jj <= i__4; ++jj) {
  1244. i__5 = k2 - k1;
  1245. csscal_(&i__5, &scal, &c__[k1 + jj * c_dim1], &
  1246. c__1);
  1247. }
  1248. }
  1249. /* Record current scaling factor */
  1250. swork[k + l * swork_dim1] = scamin * scaloc;
  1251. swork[k + j * swork_dim1] = scamin * scaloc;
  1252. i__4 = k2 - k1;
  1253. i__5 = j2 - j1;
  1254. i__6 = l2 - l1;
  1255. q__1.r = -csgn.r, q__1.i = -csgn.i;
  1256. cgemm_("N", "N", &i__4, &i__5, &i__6, &q__1, &c__[k1 + l1
  1257. * c_dim1], ldc, &b[l1 + j1 * b_dim1], ldb, &c_b1,
  1258. &c__[k1 + j1 * c_dim1], ldc)
  1259. ;
  1260. }
  1261. }
  1262. }
  1263. } else if (! notrna && ! notrnb) {
  1264. /* Solve A**H *X + ISGN*X*B**H = scale*C. */
  1265. /* The (K,L)th block of X is determined starting from */
  1266. /* top-right corner column by column by */
  1267. /* A(K,K)**H*X(K,L) + ISGN*X(K,L)*B(L,L)**H = C(K,L) - R(K,L) */
  1268. /* Where */
  1269. /* K-1 N */
  1270. /* R(K,L) = SUM [A(I,K)**H*X(I,L)] + ISGN*SUM [X(K,J)*B(L,J)**H]. */
  1271. /* I=1 J=L+1 */
  1272. /* Start loop over block rows (index = K) and block columns (index = L) */
  1273. i__1 = nba;
  1274. for (k = 1; k <= i__1; ++k) {
  1275. /* K1: row index of the first row in X( K, L ) */
  1276. /* K2: row index of the first row in X( K+1, L ) */
  1277. /* so the K2 - K1 is the column count of the block X( K, L ) */
  1278. k1 = (k - 1) * nb + 1;
  1279. /* Computing MIN */
  1280. i__2 = k * nb;
  1281. k2 = f2cmin(i__2,*m) + 1;
  1282. for (l = nbb; l >= 1; --l) {
  1283. /* L1: column index of the first column in X( K, L ) */
  1284. /* L2: column index of the first column in X( K, L + 1) */
  1285. /* so that L2 - L1 is the row count of the block X( K, L ) */
  1286. l1 = (l - 1) * nb + 1;
  1287. /* Computing MIN */
  1288. i__2 = l * nb;
  1289. l2 = f2cmin(i__2,*n) + 1;
  1290. i__2 = k2 - k1;
  1291. i__3 = l2 - l1;
  1292. ctrsyl_(trana, tranb, isgn, &i__2, &i__3, &a[k1 + k1 * a_dim1]
  1293. , lda, &b[l1 + l1 * b_dim1], ldb, &c__[k1 + l1 *
  1294. c_dim1], ldc, &scaloc, &iinfo);
  1295. *info = f2cmax(*info,iinfo);
  1296. if (scaloc * swork[k + l * swork_dim1] == 0.f) {
  1297. if (scaloc == 0.f) {
  1298. /* The magnitude of the largest entry of X(K1:K2-1, L1:L2-1) */
  1299. /* is larger than the product of BIGNUM**2 and cannot be */
  1300. /* represented in the form (1/SCALE)*X(K1:K2-1, L1:L2-1). */
  1301. /* Mark the computation as pointless. */
  1302. buf = 0.f;
  1303. } else {
  1304. /* Use second scaling factor to prevent flushing to zero. */
  1305. i__2 = myexp_(&scaloc);
  1306. buf *= pow_ri(&c_b18, &i__2);
  1307. }
  1308. i__2 = nbb;
  1309. for (jj = 1; jj <= i__2; ++jj) {
  1310. i__3 = nba;
  1311. for (ll = 1; ll <= i__3; ++ll) {
  1312. /* Bound by BIGNUM to not introduce Inf. The value */
  1313. /* is irrelevant; corresponding entries of the */
  1314. /* solution will be flushed in consistency scaling. */
  1315. /* Computing MIN */
  1316. i__4 = myexp_(&scaloc);
  1317. r__1 = bignum, r__2 = swork[ll + jj * swork_dim1]
  1318. / pow_ri(&c_b18, &i__4);
  1319. swork[ll + jj * swork_dim1] = f2cmin(r__1,r__2);
  1320. }
  1321. }
  1322. }
  1323. swork[k + l * swork_dim1] = scaloc * swork[k + l * swork_dim1]
  1324. ;
  1325. i__2 = k2 - k1;
  1326. i__3 = l2 - l1;
  1327. xnrm = clange_("I", &i__2, &i__3, &c__[k1 + l1 * c_dim1], ldc,
  1328. wnrm);
  1329. i__2 = nba;
  1330. for (i__ = k + 1; i__ <= i__2; ++i__) {
  1331. /* C( I, L ) := C( I, L ) - A( K, I )**H * C( K, L ) */
  1332. i1 = (i__ - 1) * nb + 1;
  1333. /* Computing MIN */
  1334. i__3 = i__ * nb;
  1335. i2 = f2cmin(i__3,*m) + 1;
  1336. /* Compute scaling factor to survive the linear update */
  1337. /* simulating consistent scaling. */
  1338. i__3 = i2 - i1;
  1339. i__4 = l2 - l1;
  1340. cnrm = clange_("I", &i__3, &i__4, &c__[i1 + l1 * c_dim1],
  1341. ldc, wnrm);
  1342. /* Computing MIN */
  1343. r__1 = swork[i__ + l * swork_dim1], r__2 = swork[k + l *
  1344. swork_dim1];
  1345. scamin = f2cmin(r__1,r__2);
  1346. cnrm *= scamin / swork[i__ + l * swork_dim1];
  1347. xnrm *= scamin / swork[k + l * swork_dim1];
  1348. anrm = swork[i__ + (awrk + k) * swork_dim1];
  1349. scaloc = slarmm_(&anrm, &xnrm, &cnrm);
  1350. if (scaloc * scamin == 0.f) {
  1351. /* Use second scaling factor to prevent flushing to zero. */
  1352. i__3 = myexp_(&scaloc);
  1353. buf *= pow_ri(&c_b18, &i__3);
  1354. i__3 = nbb;
  1355. for (jj = 1; jj <= i__3; ++jj) {
  1356. i__4 = nba;
  1357. for (ll = 1; ll <= i__4; ++ll) {
  1358. /* Computing MIN */
  1359. i__5 = myexp_(&scaloc);
  1360. r__1 = bignum, r__2 = swork[ll + jj *
  1361. swork_dim1] / pow_ri(&c_b18, &i__5);
  1362. swork[ll + jj * swork_dim1] = f2cmin(r__1,r__2);
  1363. }
  1364. }
  1365. i__3 = myexp_(&scaloc);
  1366. scamin /= pow_ri(&c_b18, &i__3);
  1367. i__3 = myexp_(&scaloc);
  1368. scaloc /= pow_ri(&c_b18, &i__3);
  1369. }
  1370. cnrm *= scaloc;
  1371. xnrm *= scaloc;
  1372. /* Simultaneously apply the robust update factor and the */
  1373. /* consistency scaling factor to C( I, L ) and C( K, L). */
  1374. scal = scamin / swork[k + l * swork_dim1] * scaloc;
  1375. if (scal != 1.f) {
  1376. i__3 = l2 - 1;
  1377. for (ll = l1; ll <= i__3; ++ll) {
  1378. i__4 = k2 - k1;
  1379. csscal_(&i__4, &scal, &c__[k1 + ll * c_dim1], &
  1380. c__1);
  1381. }
  1382. }
  1383. scal = scamin / swork[i__ + l * swork_dim1] * scaloc;
  1384. if (scal != 1.f) {
  1385. i__3 = l2 - 1;
  1386. for (ll = l1; ll <= i__3; ++ll) {
  1387. i__4 = i2 - i1;
  1388. csscal_(&i__4, &scal, &c__[i1 + ll * c_dim1], &
  1389. c__1);
  1390. }
  1391. }
  1392. /* Record current scaling factor */
  1393. swork[k + l * swork_dim1] = scamin * scaloc;
  1394. swork[i__ + l * swork_dim1] = scamin * scaloc;
  1395. i__3 = i2 - i1;
  1396. i__4 = l2 - l1;
  1397. i__5 = k2 - k1;
  1398. q__1.r = -1.f, q__1.i = 0.f;
  1399. cgemm_("C", "N", &i__3, &i__4, &i__5, &q__1, &a[k1 + i1 *
  1400. a_dim1], lda, &c__[k1 + l1 * c_dim1], ldc, &c_b1,
  1401. &c__[i1 + l1 * c_dim1], ldc)
  1402. ;
  1403. }
  1404. i__2 = l - 1;
  1405. for (j = 1; j <= i__2; ++j) {
  1406. /* C( K, J ) := C( K, J ) - SGN * C( K, L ) * B( J, L )**H */
  1407. j1 = (j - 1) * nb + 1;
  1408. /* Computing MIN */
  1409. i__3 = j * nb;
  1410. j2 = f2cmin(i__3,*n) + 1;
  1411. /* Compute scaling factor to survive the linear update */
  1412. /* simulating consistent scaling. */
  1413. i__3 = k2 - k1;
  1414. i__4 = j2 - j1;
  1415. cnrm = clange_("I", &i__3, &i__4, &c__[k1 + j1 * c_dim1],
  1416. ldc, wnrm);
  1417. /* Computing MIN */
  1418. r__1 = swork[k + j * swork_dim1], r__2 = swork[k + l *
  1419. swork_dim1];
  1420. scamin = f2cmin(r__1,r__2);
  1421. cnrm *= scamin / swork[k + j * swork_dim1];
  1422. xnrm *= scamin / swork[k + l * swork_dim1];
  1423. bnrm = swork[l + (bwrk + j) * swork_dim1];
  1424. scaloc = slarmm_(&bnrm, &xnrm, &cnrm);
  1425. if (scaloc * scamin == 0.f) {
  1426. /* Use second scaling factor to prevent flushing to zero. */
  1427. i__3 = myexp_(&scaloc);
  1428. buf *= pow_ri(&c_b18, &i__3);
  1429. i__3 = nbb;
  1430. for (jj = 1; jj <= i__3; ++jj) {
  1431. i__4 = nba;
  1432. for (ll = 1; ll <= i__4; ++ll) {
  1433. /* Computing MIN */
  1434. i__5 = myexp_(&scaloc);
  1435. r__1 = bignum, r__2 = swork[ll + jj *
  1436. swork_dim1] / pow_ri(&c_b18, &i__5);
  1437. swork[ll + jj * swork_dim1] = f2cmin(r__1,r__2);
  1438. }
  1439. }
  1440. i__3 = myexp_(&scaloc);
  1441. scamin /= pow_ri(&c_b18, &i__3);
  1442. i__3 = myexp_(&scaloc);
  1443. scaloc /= pow_ri(&c_b18, &i__3);
  1444. }
  1445. cnrm *= scaloc;
  1446. xnrm *= scaloc;
  1447. /* Simultaneously apply the robust update factor and the */
  1448. /* consistency scaling factor to C( K, J ) and C( K, L). */
  1449. scal = scamin / swork[k + l * swork_dim1] * scaloc;
  1450. if (scal != 1.f) {
  1451. i__3 = l2 - 1;
  1452. for (ll = l1; ll <= i__3; ++ll) {
  1453. i__4 = k2 - k1;
  1454. csscal_(&i__4, &scal, &c__[k1 + ll * c_dim1], &
  1455. c__1);
  1456. }
  1457. }
  1458. scal = scamin / swork[k + j * swork_dim1] * scaloc;
  1459. if (scal != 1.f) {
  1460. i__3 = j2 - 1;
  1461. for (jj = j1; jj <= i__3; ++jj) {
  1462. i__4 = k2 - k1;
  1463. csscal_(&i__4, &scal, &c__[k1 + jj * c_dim1], &
  1464. c__1);
  1465. }
  1466. }
  1467. /* Record current scaling factor */
  1468. swork[k + l * swork_dim1] = scamin * scaloc;
  1469. swork[k + j * swork_dim1] = scamin * scaloc;
  1470. i__3 = k2 - k1;
  1471. i__4 = j2 - j1;
  1472. i__5 = l2 - l1;
  1473. q__1.r = -csgn.r, q__1.i = -csgn.i;
  1474. cgemm_("N", "C", &i__3, &i__4, &i__5, &q__1, &c__[k1 + l1
  1475. * c_dim1], ldc, &b[j1 + l1 * b_dim1], ldb, &c_b1,
  1476. &c__[k1 + j1 * c_dim1], ldc)
  1477. ;
  1478. }
  1479. }
  1480. }
  1481. } else if (notrna && ! notrnb) {
  1482. /* Solve A*X + ISGN*X*B**H = scale*C. */
  1483. /* The (K,L)th block of X is determined starting from */
  1484. /* bottom-right corner column by column by */
  1485. /* A(K,K)*X(K,L) + ISGN*X(K,L)*B(L,L)**H = C(K,L) - R(K,L) */
  1486. /* Where */
  1487. /* M N */
  1488. /* R(K,L) = SUM [A(K,I)*X(I,L)] + ISGN*SUM [X(K,J)*B(L,J)**H]. */
  1489. /* I=K+1 J=L+1 */
  1490. /* Start loop over block rows (index = K) and block columns (index = L) */
  1491. for (k = nba; k >= 1; --k) {
  1492. /* K1: row index of the first row in X( K, L ) */
  1493. /* K2: row index of the first row in X( K+1, L ) */
  1494. /* so the K2 - K1 is the column count of the block X( K, L ) */
  1495. k1 = (k - 1) * nb + 1;
  1496. /* Computing MIN */
  1497. i__1 = k * nb;
  1498. k2 = f2cmin(i__1,*m) + 1;
  1499. for (l = nbb; l >= 1; --l) {
  1500. /* L1: column index of the first column in X( K, L ) */
  1501. /* L2: column index of the first column in X( K, L + 1) */
  1502. /* so that L2 - L1 is the row count of the block X( K, L ) */
  1503. l1 = (l - 1) * nb + 1;
  1504. /* Computing MIN */
  1505. i__1 = l * nb;
  1506. l2 = f2cmin(i__1,*n) + 1;
  1507. i__1 = k2 - k1;
  1508. i__2 = l2 - l1;
  1509. ctrsyl_(trana, tranb, isgn, &i__1, &i__2, &a[k1 + k1 * a_dim1]
  1510. , lda, &b[l1 + l1 * b_dim1], ldb, &c__[k1 + l1 *
  1511. c_dim1], ldc, &scaloc, &iinfo);
  1512. *info = f2cmax(*info,iinfo);
  1513. if (scaloc * swork[k + l * swork_dim1] == 0.f) {
  1514. if (scaloc == 0.f) {
  1515. /* The magnitude of the largest entry of X(K1:K2-1, L1:L2-1) */
  1516. /* is larger than the product of BIGNUM**2 and cannot be */
  1517. /* represented in the form (1/SCALE)*X(K1:K2-1, L1:L2-1). */
  1518. /* Mark the computation as pointless. */
  1519. buf = 0.f;
  1520. } else {
  1521. /* Use second scaling factor to prevent flushing to zero. */
  1522. i__1 = myexp_(&scaloc);
  1523. buf *= pow_ri(&c_b18, &i__1);
  1524. }
  1525. i__1 = nbb;
  1526. for (jj = 1; jj <= i__1; ++jj) {
  1527. i__2 = nba;
  1528. for (ll = 1; ll <= i__2; ++ll) {
  1529. /* Bound by BIGNUM to not introduce Inf. The value */
  1530. /* is irrelevant; corresponding entries of the */
  1531. /* solution will be flushed in consistency scaling. */
  1532. /* Computing MIN */
  1533. i__3 = myexp_(&scaloc);
  1534. r__1 = bignum, r__2 = swork[ll + jj * swork_dim1]
  1535. / pow_ri(&c_b18, &i__3);
  1536. swork[ll + jj * swork_dim1] = f2cmin(r__1,r__2);
  1537. }
  1538. }
  1539. }
  1540. swork[k + l * swork_dim1] = scaloc * swork[k + l * swork_dim1]
  1541. ;
  1542. i__1 = k2 - k1;
  1543. i__2 = l2 - l1;
  1544. xnrm = clange_("I", &i__1, &i__2, &c__[k1 + l1 * c_dim1], ldc,
  1545. wnrm);
  1546. i__1 = k - 1;
  1547. for (i__ = 1; i__ <= i__1; ++i__) {
  1548. /* C( I, L ) := C( I, L ) - A( I, K ) * C( K, L ) */
  1549. i1 = (i__ - 1) * nb + 1;
  1550. /* Computing MIN */
  1551. i__2 = i__ * nb;
  1552. i2 = f2cmin(i__2,*m) + 1;
  1553. /* Compute scaling factor to survive the linear update */
  1554. /* simulating consistent scaling. */
  1555. i__2 = i2 - i1;
  1556. i__3 = l2 - l1;
  1557. cnrm = clange_("I", &i__2, &i__3, &c__[i1 + l1 * c_dim1],
  1558. ldc, wnrm);
  1559. /* Computing MIN */
  1560. r__1 = swork[i__ + l * swork_dim1], r__2 = swork[k + l *
  1561. swork_dim1];
  1562. scamin = f2cmin(r__1,r__2);
  1563. cnrm *= scamin / swork[i__ + l * swork_dim1];
  1564. xnrm *= scamin / swork[k + l * swork_dim1];
  1565. anrm = swork[i__ + (awrk + k) * swork_dim1];
  1566. scaloc = slarmm_(&anrm, &xnrm, &cnrm);
  1567. if (scaloc * scamin == 0.f) {
  1568. /* Use second scaling factor to prevent flushing to zero. */
  1569. i__2 = myexp_(&scaloc);
  1570. buf *= pow_ri(&c_b18, &i__2);
  1571. i__2 = nbb;
  1572. for (jj = 1; jj <= i__2; ++jj) {
  1573. i__3 = nba;
  1574. for (ll = 1; ll <= i__3; ++ll) {
  1575. /* Computing MIN */
  1576. i__4 = myexp_(&scaloc);
  1577. r__1 = bignum, r__2 = swork[ll + jj *
  1578. swork_dim1] / pow_ri(&c_b18, &i__4);
  1579. swork[ll + jj * swork_dim1] = f2cmin(r__1,r__2);
  1580. }
  1581. }
  1582. i__2 = myexp_(&scaloc);
  1583. scamin /= pow_ri(&c_b18, &i__2);
  1584. i__2 = myexp_(&scaloc);
  1585. scaloc /= pow_ri(&c_b18, &i__2);
  1586. }
  1587. cnrm *= scaloc;
  1588. xnrm *= scaloc;
  1589. /* Simultaneously apply the robust update factor and the */
  1590. /* consistency scaling factor to C( I, L ) and C( K, L). */
  1591. scal = scamin / swork[k + l * swork_dim1] * scaloc;
  1592. if (scal != 1.f) {
  1593. i__2 = l2 - 1;
  1594. for (ll = l1; ll <= i__2; ++ll) {
  1595. i__3 = k2 - k1;
  1596. csscal_(&i__3, &scal, &c__[k1 + ll * c_dim1], &
  1597. c__1);
  1598. }
  1599. }
  1600. scal = scamin / swork[i__ + l * swork_dim1] * scaloc;
  1601. if (scal != 1.f) {
  1602. i__2 = l2 - 1;
  1603. for (ll = l1; ll <= i__2; ++ll) {
  1604. i__3 = i2 - i1;
  1605. csscal_(&i__3, &scal, &c__[i1 + ll * c_dim1], &
  1606. c__1);
  1607. }
  1608. }
  1609. /* Record current scaling factor */
  1610. swork[k + l * swork_dim1] = scamin * scaloc;
  1611. swork[i__ + l * swork_dim1] = scamin * scaloc;
  1612. i__2 = i2 - i1;
  1613. i__3 = l2 - l1;
  1614. i__4 = k2 - k1;
  1615. q__1.r = -1.f, q__1.i = 0.f;
  1616. cgemm_("N", "N", &i__2, &i__3, &i__4, &q__1, &a[i1 + k1 *
  1617. a_dim1], lda, &c__[k1 + l1 * c_dim1], ldc, &c_b1,
  1618. &c__[i1 + l1 * c_dim1], ldc)
  1619. ;
  1620. }
  1621. i__1 = l - 1;
  1622. for (j = 1; j <= i__1; ++j) {
  1623. /* C( K, J ) := C( K, J ) - SGN * C( K, L ) * B( J, L )**H */
  1624. j1 = (j - 1) * nb + 1;
  1625. /* Computing MIN */
  1626. i__2 = j * nb;
  1627. j2 = f2cmin(i__2,*n) + 1;
  1628. /* Compute scaling factor to survive the linear update */
  1629. /* simulating consistent scaling. */
  1630. i__2 = k2 - k1;
  1631. i__3 = j2 - j1;
  1632. cnrm = clange_("I", &i__2, &i__3, &c__[k1 + j1 * c_dim1],
  1633. ldc, wnrm);
  1634. /* Computing MIN */
  1635. r__1 = swork[k + j * swork_dim1], r__2 = swork[k + l *
  1636. swork_dim1];
  1637. scamin = f2cmin(r__1,r__2);
  1638. cnrm *= scamin / swork[k + j * swork_dim1];
  1639. xnrm *= scamin / swork[k + l * swork_dim1];
  1640. bnrm = swork[l + (bwrk + j) * swork_dim1];
  1641. scaloc = slarmm_(&bnrm, &xnrm, &cnrm);
  1642. if (scaloc * scamin == 0.f) {
  1643. /* Use second scaling factor to prevent flushing to zero. */
  1644. i__2 = myexp_(&scaloc);
  1645. buf *= pow_ri(&c_b18, &i__2);
  1646. i__2 = nbb;
  1647. for (jj = 1; jj <= i__2; ++jj) {
  1648. i__3 = nba;
  1649. for (ll = 1; ll <= i__3; ++ll) {
  1650. /* Computing MIN */
  1651. i__4 = myexp_(&scaloc);
  1652. r__1 = bignum, r__2 = swork[ll + jj *
  1653. swork_dim1] / pow_ri(&c_b18, &i__4);
  1654. swork[ll + jj * swork_dim1] = f2cmin(r__1,r__2);
  1655. }
  1656. }
  1657. i__2 = myexp_(&scaloc);
  1658. scamin /= pow_ri(&c_b18, &i__2);
  1659. i__2 = myexp_(&scaloc);
  1660. scaloc /= pow_ri(&c_b18, &i__2);
  1661. }
  1662. cnrm *= scaloc;
  1663. xnrm *= scaloc;
  1664. /* Simultaneously apply the robust update factor and the */
  1665. /* consistency scaling factor to C( K, J ) and C( K, L). */
  1666. scal = scamin / swork[k + l * swork_dim1] * scaloc;
  1667. if (scal != 1.f) {
  1668. i__2 = l2 - 1;
  1669. for (jj = l1; jj <= i__2; ++jj) {
  1670. i__3 = k2 - k1;
  1671. csscal_(&i__3, &scal, &c__[k1 + jj * c_dim1], &
  1672. c__1);
  1673. }
  1674. }
  1675. scal = scamin / swork[k + j * swork_dim1] * scaloc;
  1676. if (scal != 1.f) {
  1677. i__2 = j2 - 1;
  1678. for (jj = j1; jj <= i__2; ++jj) {
  1679. i__3 = k2 - k1;
  1680. csscal_(&i__3, &scal, &c__[k1 + jj * c_dim1], &
  1681. c__1);
  1682. }
  1683. }
  1684. /* Record current scaling factor */
  1685. swork[k + l * swork_dim1] = scamin * scaloc;
  1686. swork[k + j * swork_dim1] = scamin * scaloc;
  1687. i__2 = k2 - k1;
  1688. i__3 = j2 - j1;
  1689. i__4 = l2 - l1;
  1690. q__1.r = -csgn.r, q__1.i = -csgn.i;
  1691. cgemm_("N", "C", &i__2, &i__3, &i__4, &q__1, &c__[k1 + l1
  1692. * c_dim1], ldc, &b[j1 + l1 * b_dim1], ldb, &c_b1,
  1693. &c__[k1 + j1 * c_dim1], ldc)
  1694. ;
  1695. }
  1696. }
  1697. }
  1698. }
  1699. free(wnrm);
  1700. /* Reduce local scaling factors */
  1701. *scale = swork[swork_dim1 + 1];
  1702. i__1 = nba;
  1703. for (k = 1; k <= i__1; ++k) {
  1704. i__2 = nbb;
  1705. for (l = 1; l <= i__2; ++l) {
  1706. /* Computing MIN */
  1707. r__1 = *scale, r__2 = swork[k + l * swork_dim1];
  1708. *scale = f2cmin(r__1,r__2);
  1709. }
  1710. }
  1711. if (*scale == 0.f) {
  1712. /* The magnitude of the largest entry of the solution is larger */
  1713. /* than the product of BIGNUM**2 and cannot be represented in the */
  1714. /* form (1/SCALE)*X if SCALE is REAL. Set SCALE to */
  1715. /* zero and give up. */
  1716. swork[swork_dim1 + 1] = (real) f2cmax(nba,nbb);
  1717. swork[swork_dim1 + 2] = (real) ((nbb << 1) + nba);
  1718. return;
  1719. }
  1720. /* Realize consistent scaling */
  1721. i__1 = nba;
  1722. for (k = 1; k <= i__1; ++k) {
  1723. k1 = (k - 1) * nb + 1;
  1724. /* Computing MIN */
  1725. i__2 = k * nb;
  1726. k2 = f2cmin(i__2,*m) + 1;
  1727. i__2 = nbb;
  1728. for (l = 1; l <= i__2; ++l) {
  1729. l1 = (l - 1) * nb + 1;
  1730. /* Computing MIN */
  1731. i__3 = l * nb;
  1732. l2 = f2cmin(i__3,*n) + 1;
  1733. scal = *scale / swork[k + l * swork_dim1];
  1734. if (scal != 1.f) {
  1735. i__3 = l2 - 1;
  1736. for (ll = l1; ll <= i__3; ++ll) {
  1737. i__4 = k2 - k1;
  1738. csscal_(&i__4, &scal, &c__[k1 + ll * c_dim1], &c__1);
  1739. }
  1740. }
  1741. }
  1742. }
  1743. if (buf != 1.f && buf > 0.f) {
  1744. /* Decrease SCALE as much as possible. */
  1745. /* Computing MIN */
  1746. r__1 = *scale / smlnum, r__2 = 1.f / buf;
  1747. scaloc = f2cmin(r__1,r__2);
  1748. buf *= scaloc;
  1749. *scale /= scaloc;
  1750. }
  1751. if (buf != 1.f && buf > 0.f) {
  1752. /* In case of overly aggressive scaling during the computation, */
  1753. /* flushing of the global scale factor may be prevented by */
  1754. /* undoing some of the scaling. This step is to ensure that */
  1755. /* this routine flushes only scale factors that TRSYL also */
  1756. /* flushes and be usable as a drop-in replacement. */
  1757. /* How much can the normwise largest entry be upscaled? */
  1758. /* Computing MAX */
  1759. i__1 = c_dim1 + 1;
  1760. r__3 = (r__1 = c__[i__1].r, abs(r__1)), r__4 = (r__2 = r_imag(&c__[
  1761. c_dim1 + 1]), abs(r__2));
  1762. scal = f2cmax(r__3,r__4);
  1763. i__1 = *m;
  1764. for (k = 1; k <= i__1; ++k) {
  1765. i__2 = *n;
  1766. for (l = 1; l <= i__2; ++l) {
  1767. /* Computing MAX */
  1768. i__3 = k + l * c_dim1;
  1769. r__3 = scal, r__4 = (r__1 = c__[i__3].r, abs(r__1)), r__3 =
  1770. f2cmax(r__3,r__4), r__4 = (r__2 = r_imag(&c__[k + l *
  1771. c_dim1]), abs(r__2));
  1772. scal = f2cmax(r__3,r__4);
  1773. }
  1774. }
  1775. /* Increase BUF as close to 1 as possible and apply scaling. */
  1776. /* Computing MIN */
  1777. r__1 = bignum / scal, r__2 = 1.f / buf;
  1778. scaloc = f2cmin(r__1,r__2);
  1779. buf *= scaloc;
  1780. clascl_("G", &c_n1, &c_n1, &c_b106, &scaloc, m, n, &c__[c_offset],
  1781. ldc, &iinfo);
  1782. }
  1783. /* Combine with buffer scaling factor. SCALE will be flushed if */
  1784. /* BUF is less than one here. */
  1785. *scale *= buf;
  1786. /* Restore workspace dimensions */
  1787. swork[swork_dim1 + 1] = (real) f2cmax(nba,nbb);
  1788. swork[swork_dim1 + 2] = (real) ((nbb << 1) + nba);
  1789. return;
  1790. /* End of CTRSYL3 */
  1791. } /* ctrsyl3_ */