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