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.

dtrsyl3.c 62 kB

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