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.

dtgsyl.c 38 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301
  1. #include <math.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <stdio.h>
  5. #include <complex.h>
  6. #ifdef complex
  7. #undef complex
  8. #endif
  9. #ifdef I
  10. #undef I
  11. #endif
  12. #if defined(_WIN64)
  13. typedef long long BLASLONG;
  14. typedef unsigned long long BLASULONG;
  15. #else
  16. typedef long BLASLONG;
  17. typedef unsigned long BLASULONG;
  18. #endif
  19. #ifdef LAPACK_ILP64
  20. typedef BLASLONG blasint;
  21. #if defined(_WIN64)
  22. #define blasabs(x) llabs(x)
  23. #else
  24. #define blasabs(x) labs(x)
  25. #endif
  26. #else
  27. typedef int blasint;
  28. #define blasabs(x) abs(x)
  29. #endif
  30. typedef blasint integer;
  31. typedef unsigned int uinteger;
  32. typedef char *address;
  33. typedef short int shortint;
  34. typedef float real;
  35. typedef double doublereal;
  36. typedef struct { real r, i; } complex;
  37. typedef struct { doublereal r, i; } doublecomplex;
  38. #ifdef _MSC_VER
  39. static inline _Fcomplex Cf(complex *z) {_Fcomplex zz={z->r , z->i}; return zz;}
  40. static inline _Dcomplex Cd(doublecomplex *z) {_Dcomplex zz={z->r , z->i};return zz;}
  41. static inline _Fcomplex * _pCf(complex *z) {return (_Fcomplex*)z;}
  42. static inline _Dcomplex * _pCd(doublecomplex *z) {return (_Dcomplex*)z;}
  43. #else
  44. static inline _Complex float Cf(complex *z) {return z->r + z->i*_Complex_I;}
  45. static inline _Complex double Cd(doublecomplex *z) {return z->r + z->i*_Complex_I;}
  46. static inline _Complex float * _pCf(complex *z) {return (_Complex float*)z;}
  47. static inline _Complex double * _pCd(doublecomplex *z) {return (_Complex double*)z;}
  48. #endif
  49. #define pCf(z) (*_pCf(z))
  50. #define pCd(z) (*_pCd(z))
  51. typedef blasint logical;
  52. typedef char logical1;
  53. typedef char integer1;
  54. #define TRUE_ (1)
  55. #define FALSE_ (0)
  56. /* Extern is for use with -E */
  57. #ifndef Extern
  58. #define Extern extern
  59. #endif
  60. /* I/O stuff */
  61. typedef int flag;
  62. typedef int ftnlen;
  63. typedef int ftnint;
  64. /*external read, write*/
  65. typedef struct
  66. { flag cierr;
  67. ftnint ciunit;
  68. flag ciend;
  69. char *cifmt;
  70. ftnint cirec;
  71. } cilist;
  72. /*internal read, write*/
  73. typedef struct
  74. { flag icierr;
  75. char *iciunit;
  76. flag iciend;
  77. char *icifmt;
  78. ftnint icirlen;
  79. ftnint icirnum;
  80. } icilist;
  81. /*open*/
  82. typedef struct
  83. { flag oerr;
  84. ftnint ounit;
  85. char *ofnm;
  86. ftnlen ofnmlen;
  87. char *osta;
  88. char *oacc;
  89. char *ofm;
  90. ftnint orl;
  91. char *oblnk;
  92. } olist;
  93. /*close*/
  94. typedef struct
  95. { flag cerr;
  96. ftnint cunit;
  97. char *csta;
  98. } cllist;
  99. /*rewind, backspace, endfile*/
  100. typedef struct
  101. { flag aerr;
  102. ftnint aunit;
  103. } alist;
  104. /* inquire */
  105. typedef struct
  106. { flag inerr;
  107. ftnint inunit;
  108. char *infile;
  109. ftnlen infilen;
  110. ftnint *inex; /*parameters in standard's order*/
  111. ftnint *inopen;
  112. ftnint *innum;
  113. ftnint *innamed;
  114. char *inname;
  115. ftnlen innamlen;
  116. char *inacc;
  117. ftnlen inacclen;
  118. char *inseq;
  119. ftnlen inseqlen;
  120. char *indir;
  121. ftnlen indirlen;
  122. char *infmt;
  123. ftnlen infmtlen;
  124. char *inform;
  125. ftnint informlen;
  126. char *inunf;
  127. ftnlen inunflen;
  128. ftnint *inrecl;
  129. ftnint *innrec;
  130. char *inblank;
  131. ftnlen inblanklen;
  132. } inlist;
  133. #define VOID void
  134. union Multitype { /* for multiple entry points */
  135. integer1 g;
  136. shortint h;
  137. integer i;
  138. /* longint j; */
  139. real r;
  140. doublereal d;
  141. complex c;
  142. doublecomplex z;
  143. };
  144. typedef union Multitype Multitype;
  145. struct Vardesc { /* for Namelist */
  146. char *name;
  147. char *addr;
  148. ftnlen *dims;
  149. int type;
  150. };
  151. typedef struct Vardesc Vardesc;
  152. struct Namelist {
  153. char *name;
  154. Vardesc **vars;
  155. int nvars;
  156. };
  157. typedef struct Namelist Namelist;
  158. #define abs(x) ((x) >= 0 ? (x) : -(x))
  159. #define dabs(x) (fabs(x))
  160. #define f2cmin(a,b) ((a) <= (b) ? (a) : (b))
  161. #define f2cmax(a,b) ((a) >= (b) ? (a) : (b))
  162. #define dmin(a,b) (f2cmin(a,b))
  163. #define dmax(a,b) (f2cmax(a,b))
  164. #define bit_test(a,b) ((a) >> (b) & 1)
  165. #define bit_clear(a,b) ((a) & ~((uinteger)1 << (b)))
  166. #define bit_set(a,b) ((a) | ((uinteger)1 << (b)))
  167. #define abort_() { sig_die("Fortran abort routine called", 1); }
  168. #define c_abs(z) (cabsf(Cf(z)))
  169. #define c_cos(R,Z) { pCf(R)=ccos(Cf(Z)); }
  170. #ifdef _MSC_VER
  171. #define c_div(c, a, b) {Cf(c)._Val[0] = (Cf(a)._Val[0]/Cf(b)._Val[0]); Cf(c)._Val[1]=(Cf(a)._Val[1]/Cf(b)._Val[1]);}
  172. #define z_div(c, a, b) {Cd(c)._Val[0] = (Cd(a)._Val[0]/Cd(b)._Val[0]); Cd(c)._Val[1]=(Cd(a)._Val[1]/df(b)._Val[1]);}
  173. #else
  174. #define c_div(c, a, b) {pCf(c) = Cf(a)/Cf(b);}
  175. #define z_div(c, a, b) {pCd(c) = Cd(a)/Cd(b);}
  176. #endif
  177. #define c_exp(R, Z) {pCf(R) = cexpf(Cf(Z));}
  178. #define c_log(R, Z) {pCf(R) = clogf(Cf(Z));}
  179. #define c_sin(R, Z) {pCf(R) = csinf(Cf(Z));}
  180. //#define c_sqrt(R, Z) {*(R) = csqrtf(Cf(Z));}
  181. #define c_sqrt(R, Z) {pCf(R) = csqrtf(Cf(Z));}
  182. #define d_abs(x) (fabs(*(x)))
  183. #define d_acos(x) (acos(*(x)))
  184. #define d_asin(x) (asin(*(x)))
  185. #define d_atan(x) (atan(*(x)))
  186. #define d_atn2(x, y) (atan2(*(x),*(y)))
  187. #define d_cnjg(R, Z) { pCd(R) = conj(Cd(Z)); }
  188. #define r_cnjg(R, Z) { pCf(R) = conjf(Cf(Z)); }
  189. #define d_cos(x) (cos(*(x)))
  190. #define d_cosh(x) (cosh(*(x)))
  191. #define d_dim(__a, __b) ( *(__a) > *(__b) ? *(__a) - *(__b) : 0.0 )
  192. #define d_exp(x) (exp(*(x)))
  193. #define d_imag(z) (cimag(Cd(z)))
  194. #define r_imag(z) (cimagf(Cf(z)))
  195. #define d_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
  196. #define r_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
  197. #define d_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
  198. #define r_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
  199. #define d_log(x) (log(*(x)))
  200. #define d_mod(x, y) (fmod(*(x), *(y)))
  201. #define u_nint(__x) ((__x)>=0 ? floor((__x) + .5) : -floor(.5 - (__x)))
  202. #define d_nint(x) u_nint(*(x))
  203. #define u_sign(__a,__b) ((__b) >= 0 ? ((__a) >= 0 ? (__a) : -(__a)) : -((__a) >= 0 ? (__a) : -(__a)))
  204. #define d_sign(a,b) u_sign(*(a),*(b))
  205. #define r_sign(a,b) u_sign(*(a),*(b))
  206. #define d_sin(x) (sin(*(x)))
  207. #define d_sinh(x) (sinh(*(x)))
  208. #define d_sqrt(x) (sqrt(*(x)))
  209. #define d_tan(x) (tan(*(x)))
  210. #define d_tanh(x) (tanh(*(x)))
  211. #define i_abs(x) abs(*(x))
  212. #define i_dnnt(x) ((integer)u_nint(*(x)))
  213. #define i_len(s, n) (n)
  214. #define i_nint(x) ((integer)u_nint(*(x)))
  215. #define i_sign(a,b) ((integer)u_sign((integer)*(a),(integer)*(b)))
  216. #define pow_dd(ap, bp) ( pow(*(ap), *(bp)))
  217. #define pow_si(B,E) spow_ui(*(B),*(E))
  218. #define pow_ri(B,E) spow_ui(*(B),*(E))
  219. #define pow_di(B,E) dpow_ui(*(B),*(E))
  220. #define pow_zi(p, a, b) {pCd(p) = zpow_ui(Cd(a), *(b));}
  221. #define pow_ci(p, a, b) {pCf(p) = cpow_ui(Cf(a), *(b));}
  222. #define pow_zz(R,A,B) {pCd(R) = cpow(Cd(A),*(B));}
  223. #define s_cat(lpp, rpp, rnp, np, llp) { ftnlen i, nc, ll; char *f__rp, *lp; ll = (llp); lp = (lpp); for(i=0; i < (int)*(np); ++i) { nc = ll; if((rnp)[i] < nc) nc = (rnp)[i]; ll -= nc; f__rp = (rpp)[i]; while(--nc >= 0) *lp++ = *(f__rp)++; } while(--ll >= 0) *lp++ = ' '; }
  224. #define s_cmp(a,b,c,d) ((integer)strncmp((a),(b),f2cmin((c),(d))))
  225. #define s_copy(A,B,C,D) { int __i,__m; for (__i=0, __m=f2cmin((C),(D)); __i<__m && (B)[__i] != 0; ++__i) (A)[__i] = (B)[__i]; }
  226. #define sig_die(s, kill) { exit(1); }
  227. #define s_stop(s, n) {exit(0);}
  228. static char junk[] = "\n@(#)LIBF77 VERSION 19990503\n";
  229. #define z_abs(z) (cabs(Cd(z)))
  230. #define z_exp(R, Z) {pCd(R) = cexp(Cd(Z));}
  231. #define z_sqrt(R, Z) {pCd(R) = csqrt(Cd(Z));}
  232. #define myexit_() break;
  233. #define mycycle() continue;
  234. #define myceiling(w) {ceil(w)}
  235. #define myhuge(w) {HUGE_VAL}
  236. //#define mymaxloc_(w,s,e,n) {if (sizeof(*(w)) == sizeof(double)) dmaxloc_((w),*(s),*(e),n); else dmaxloc_((w),*(s),*(e),n);}
  237. #define mymaxloc(w,s,e,n) {dmaxloc_(w,*(s),*(e),n)}
  238. /* procedure parameter types for -A and -C++ */
  239. #ifdef __cplusplus
  240. typedef logical (*L_fp)(...);
  241. #else
  242. typedef logical (*L_fp)();
  243. #endif
  244. static float spow_ui(float x, integer n) {
  245. float pow=1.0; unsigned long int u;
  246. if(n != 0) {
  247. if(n < 0) n = -n, x = 1/x;
  248. for(u = n; ; ) {
  249. if(u & 01) pow *= x;
  250. if(u >>= 1) x *= x;
  251. else break;
  252. }
  253. }
  254. return pow;
  255. }
  256. static double dpow_ui(double x, integer n) {
  257. double pow=1.0; unsigned long int u;
  258. if(n != 0) {
  259. if(n < 0) n = -n, x = 1/x;
  260. for(u = n; ; ) {
  261. if(u & 01) pow *= x;
  262. if(u >>= 1) x *= x;
  263. else break;
  264. }
  265. }
  266. return pow;
  267. }
  268. #ifdef _MSC_VER
  269. static _Fcomplex cpow_ui(complex x, integer n) {
  270. complex pow={1.0,0.0}; unsigned long int u;
  271. if(n != 0) {
  272. if(n < 0) n = -n, x.r = 1/x.r, x.i=1/x.i;
  273. for(u = n; ; ) {
  274. if(u & 01) pow.r *= x.r, pow.i *= x.i;
  275. if(u >>= 1) x.r *= x.r, x.i *= x.i;
  276. else break;
  277. }
  278. }
  279. _Fcomplex p={pow.r, pow.i};
  280. return p;
  281. }
  282. #else
  283. static _Complex float cpow_ui(_Complex float x, integer n) {
  284. _Complex float pow=1.0; unsigned long int u;
  285. if(n != 0) {
  286. if(n < 0) n = -n, x = 1/x;
  287. for(u = n; ; ) {
  288. if(u & 01) pow *= x;
  289. if(u >>= 1) x *= x;
  290. else break;
  291. }
  292. }
  293. return pow;
  294. }
  295. #endif
  296. #ifdef _MSC_VER
  297. static _Dcomplex zpow_ui(_Dcomplex x, integer n) {
  298. _Dcomplex pow={1.0,0.0}; unsigned long int u;
  299. if(n != 0) {
  300. if(n < 0) n = -n, x._Val[0] = 1/x._Val[0], x._Val[1] =1/x._Val[1];
  301. for(u = n; ; ) {
  302. if(u & 01) pow._Val[0] *= x._Val[0], pow._Val[1] *= x._Val[1];
  303. if(u >>= 1) x._Val[0] *= x._Val[0], x._Val[1] *= x._Val[1];
  304. else break;
  305. }
  306. }
  307. _Dcomplex p = {pow._Val[0], pow._Val[1]};
  308. return p;
  309. }
  310. #else
  311. static _Complex double zpow_ui(_Complex double x, integer n) {
  312. _Complex double pow=1.0; unsigned long int u;
  313. if(n != 0) {
  314. if(n < 0) n = -n, x = 1/x;
  315. for(u = n; ; ) {
  316. if(u & 01) pow *= x;
  317. if(u >>= 1) x *= x;
  318. else break;
  319. }
  320. }
  321. return pow;
  322. }
  323. #endif
  324. static integer pow_ii(integer x, integer n) {
  325. integer pow; unsigned long int u;
  326. if (n <= 0) {
  327. if (n == 0 || x == 1) pow = 1;
  328. else if (x != -1) pow = x == 0 ? 1/x : 0;
  329. else n = -n;
  330. }
  331. if ((n > 0) || !(n == 0 || x == 1 || x != -1)) {
  332. u = n;
  333. for(pow = 1; ; ) {
  334. if(u & 01) pow *= x;
  335. if(u >>= 1) x *= x;
  336. else break;
  337. }
  338. }
  339. return pow;
  340. }
  341. static integer dmaxloc_(double *w, integer s, integer e, integer *n)
  342. {
  343. double m; integer i, mi;
  344. for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
  345. if (w[i-1]>m) mi=i ,m=w[i-1];
  346. return mi-s+1;
  347. }
  348. static integer smaxloc_(float *w, integer s, integer e, integer *n)
  349. {
  350. float m; integer i, mi;
  351. for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
  352. if (w[i-1]>m) mi=i ,m=w[i-1];
  353. return mi-s+1;
  354. }
  355. static inline void cdotc_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
  356. integer n = *n_, incx = *incx_, incy = *incy_, i;
  357. #ifdef _MSC_VER
  358. _Fcomplex zdotc = {0.0, 0.0};
  359. if (incx == 1 && incy == 1) {
  360. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  361. zdotc._Val[0] += conjf(Cf(&x[i]))._Val[0] * Cf(&y[i])._Val[0];
  362. zdotc._Val[1] += conjf(Cf(&x[i]))._Val[1] * Cf(&y[i])._Val[1];
  363. }
  364. } else {
  365. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  366. zdotc._Val[0] += conjf(Cf(&x[i*incx]))._Val[0] * Cf(&y[i*incy])._Val[0];
  367. zdotc._Val[1] += conjf(Cf(&x[i*incx]))._Val[1] * Cf(&y[i*incy])._Val[1];
  368. }
  369. }
  370. pCf(z) = zdotc;
  371. }
  372. #else
  373. _Complex float zdotc = 0.0;
  374. if (incx == 1 && incy == 1) {
  375. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  376. zdotc += conjf(Cf(&x[i])) * Cf(&y[i]);
  377. }
  378. } else {
  379. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  380. zdotc += conjf(Cf(&x[i*incx])) * Cf(&y[i*incy]);
  381. }
  382. }
  383. pCf(z) = zdotc;
  384. }
  385. #endif
  386. static inline void zdotc_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
  387. integer n = *n_, incx = *incx_, incy = *incy_, i;
  388. #ifdef _MSC_VER
  389. _Dcomplex zdotc = {0.0, 0.0};
  390. if (incx == 1 && incy == 1) {
  391. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  392. zdotc._Val[0] += conj(Cd(&x[i]))._Val[0] * Cd(&y[i])._Val[0];
  393. zdotc._Val[1] += conj(Cd(&x[i]))._Val[1] * Cd(&y[i])._Val[1];
  394. }
  395. } else {
  396. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  397. zdotc._Val[0] += conj(Cd(&x[i*incx]))._Val[0] * Cd(&y[i*incy])._Val[0];
  398. zdotc._Val[1] += conj(Cd(&x[i*incx]))._Val[1] * Cd(&y[i*incy])._Val[1];
  399. }
  400. }
  401. pCd(z) = zdotc;
  402. }
  403. #else
  404. _Complex double zdotc = 0.0;
  405. if (incx == 1 && incy == 1) {
  406. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  407. zdotc += conj(Cd(&x[i])) * Cd(&y[i]);
  408. }
  409. } else {
  410. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  411. zdotc += conj(Cd(&x[i*incx])) * Cd(&y[i*incy]);
  412. }
  413. }
  414. pCd(z) = zdotc;
  415. }
  416. #endif
  417. static inline void cdotu_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
  418. integer n = *n_, incx = *incx_, incy = *incy_, i;
  419. #ifdef _MSC_VER
  420. _Fcomplex zdotc = {0.0, 0.0};
  421. if (incx == 1 && incy == 1) {
  422. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  423. zdotc._Val[0] += Cf(&x[i])._Val[0] * Cf(&y[i])._Val[0];
  424. zdotc._Val[1] += Cf(&x[i])._Val[1] * Cf(&y[i])._Val[1];
  425. }
  426. } else {
  427. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  428. zdotc._Val[0] += Cf(&x[i*incx])._Val[0] * Cf(&y[i*incy])._Val[0];
  429. zdotc._Val[1] += Cf(&x[i*incx])._Val[1] * Cf(&y[i*incy])._Val[1];
  430. }
  431. }
  432. pCf(z) = zdotc;
  433. }
  434. #else
  435. _Complex float zdotc = 0.0;
  436. if (incx == 1 && incy == 1) {
  437. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  438. zdotc += Cf(&x[i]) * Cf(&y[i]);
  439. }
  440. } else {
  441. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  442. zdotc += Cf(&x[i*incx]) * Cf(&y[i*incy]);
  443. }
  444. }
  445. pCf(z) = zdotc;
  446. }
  447. #endif
  448. static inline void zdotu_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
  449. integer n = *n_, incx = *incx_, incy = *incy_, i;
  450. #ifdef _MSC_VER
  451. _Dcomplex zdotc = {0.0, 0.0};
  452. if (incx == 1 && incy == 1) {
  453. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  454. zdotc._Val[0] += Cd(&x[i])._Val[0] * Cd(&y[i])._Val[0];
  455. zdotc._Val[1] += Cd(&x[i])._Val[1] * Cd(&y[i])._Val[1];
  456. }
  457. } else {
  458. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  459. zdotc._Val[0] += Cd(&x[i*incx])._Val[0] * Cd(&y[i*incy])._Val[0];
  460. zdotc._Val[1] += Cd(&x[i*incx])._Val[1] * Cd(&y[i*incy])._Val[1];
  461. }
  462. }
  463. pCd(z) = zdotc;
  464. }
  465. #else
  466. _Complex double zdotc = 0.0;
  467. if (incx == 1 && incy == 1) {
  468. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  469. zdotc += Cd(&x[i]) * Cd(&y[i]);
  470. }
  471. } else {
  472. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  473. zdotc += Cd(&x[i*incx]) * Cd(&y[i*incy]);
  474. }
  475. }
  476. pCd(z) = zdotc;
  477. }
  478. #endif
  479. /* -- translated by f2c (version 20000121).
  480. You must link the resulting object file with the libraries:
  481. -lf2c -lm (in that order)
  482. */
  483. /* Table of constant values */
  484. static integer c__2 = 2;
  485. static integer c_n1 = -1;
  486. static integer c__5 = 5;
  487. static doublereal c_b14 = 0.;
  488. static integer c__1 = 1;
  489. static doublereal c_b51 = -1.;
  490. static doublereal c_b52 = 1.;
  491. /* > \brief \b DTGSYL */
  492. /* =========== DOCUMENTATION =========== */
  493. /* Online html documentation available at */
  494. /* http://www.netlib.org/lapack/explore-html/ */
  495. /* > \htmlonly */
  496. /* > Download DTGSYL + dependencies */
  497. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dtgsyl.
  498. f"> */
  499. /* > [TGZ]</a> */
  500. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dtgsyl.
  501. f"> */
  502. /* > [ZIP]</a> */
  503. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dtgsyl.
  504. f"> */
  505. /* > [TXT]</a> */
  506. /* > \endhtmlonly */
  507. /* Definition: */
  508. /* =========== */
  509. /* SUBROUTINE DTGSYL( TRANS, IJOB, M, N, A, LDA, B, LDB, C, LDC, D, */
  510. /* LDD, E, LDE, F, LDF, SCALE, DIF, WORK, LWORK, */
  511. /* IWORK, INFO ) */
  512. /* CHARACTER TRANS */
  513. /* INTEGER IJOB, INFO, LDA, LDB, LDC, LDD, LDE, LDF, */
  514. /* $ LWORK, M, N */
  515. /* DOUBLE PRECISION DIF, SCALE */
  516. /* INTEGER IWORK( * ) */
  517. /* DOUBLE PRECISION A( LDA, * ), B( LDB, * ), C( LDC, * ), */
  518. /* $ D( LDD, * ), E( LDE, * ), F( LDF, * ), */
  519. /* $ WORK( * ) */
  520. /* > \par Purpose: */
  521. /* ============= */
  522. /* > */
  523. /* > \verbatim */
  524. /* > */
  525. /* > DTGSYL solves the generalized Sylvester equation: */
  526. /* > */
  527. /* > A * R - L * B = scale * C (1) */
  528. /* > D * R - L * E = scale * F */
  529. /* > */
  530. /* > where R and L are unknown m-by-n matrices, (A, D), (B, E) and */
  531. /* > (C, F) are given matrix pairs of size m-by-m, n-by-n and m-by-n, */
  532. /* > respectively, with real entries. (A, D) and (B, E) must be in */
  533. /* > generalized (real) Schur canonical form, i.e. A, B are upper quasi */
  534. /* > triangular and D, E are upper triangular. */
  535. /* > */
  536. /* > The solution (R, L) overwrites (C, F). 0 <= SCALE <= 1 is an output */
  537. /* > scaling factor chosen to avoid overflow. */
  538. /* > */
  539. /* > In matrix notation (1) is equivalent to solve Zx = scale b, where */
  540. /* > Z is defined as */
  541. /* > */
  542. /* > Z = [ kron(In, A) -kron(B**T, Im) ] (2) */
  543. /* > [ kron(In, D) -kron(E**T, Im) ]. */
  544. /* > */
  545. /* > Here Ik is the identity matrix of size k and X**T is the transpose of */
  546. /* > X. kron(X, Y) is the Kronecker product between the matrices X and Y. */
  547. /* > */
  548. /* > If TRANS = 'T', DTGSYL solves the transposed system Z**T*y = scale*b, */
  549. /* > which is equivalent to solve for R and L in */
  550. /* > */
  551. /* > A**T * R + D**T * L = scale * C (3) */
  552. /* > R * B**T + L * E**T = scale * -F */
  553. /* > */
  554. /* > This case (TRANS = 'T') is used to compute an one-norm-based estimate */
  555. /* > of Dif[(A,D), (B,E)], the separation between the matrix pairs (A,D) */
  556. /* > and (B,E), using DLACON. */
  557. /* > */
  558. /* > If IJOB >= 1, DTGSYL computes a Frobenius norm-based estimate */
  559. /* > of Dif[(A,D),(B,E)]. That is, the reciprocal of a lower bound on the */
  560. /* > reciprocal of the smallest singular value of Z. See [1-2] for more */
  561. /* > information. */
  562. /* > */
  563. /* > This is a level 3 BLAS algorithm. */
  564. /* > \endverbatim */
  565. /* Arguments: */
  566. /* ========== */
  567. /* > \param[in] TRANS */
  568. /* > \verbatim */
  569. /* > TRANS is CHARACTER*1 */
  570. /* > = 'N': solve the generalized Sylvester equation (1). */
  571. /* > = 'T': solve the 'transposed' system (3). */
  572. /* > \endverbatim */
  573. /* > */
  574. /* > \param[in] IJOB */
  575. /* > \verbatim */
  576. /* > IJOB is INTEGER */
  577. /* > Specifies what kind of functionality to be performed. */
  578. /* > = 0: solve (1) only. */
  579. /* > = 1: The functionality of 0 and 3. */
  580. /* > = 2: The functionality of 0 and 4. */
  581. /* > = 3: Only an estimate of Dif[(A,D), (B,E)] is computed. */
  582. /* > (look ahead strategy IJOB = 1 is used). */
  583. /* > = 4: Only an estimate of Dif[(A,D), (B,E)] is computed. */
  584. /* > ( DGECON on sub-systems is used ). */
  585. /* > Not referenced if TRANS = 'T'. */
  586. /* > \endverbatim */
  587. /* > */
  588. /* > \param[in] M */
  589. /* > \verbatim */
  590. /* > M is INTEGER */
  591. /* > The order of the matrices A and D, and the row dimension of */
  592. /* > the matrices C, F, R and L. */
  593. /* > \endverbatim */
  594. /* > */
  595. /* > \param[in] N */
  596. /* > \verbatim */
  597. /* > N is INTEGER */
  598. /* > The order of the matrices B and E, and the column dimension */
  599. /* > of the matrices C, F, R and L. */
  600. /* > \endverbatim */
  601. /* > */
  602. /* > \param[in] A */
  603. /* > \verbatim */
  604. /* > A is DOUBLE PRECISION array, dimension (LDA, M) */
  605. /* > The upper quasi triangular matrix A. */
  606. /* > \endverbatim */
  607. /* > */
  608. /* > \param[in] LDA */
  609. /* > \verbatim */
  610. /* > LDA is INTEGER */
  611. /* > The leading dimension of the array A. LDA >= f2cmax(1, M). */
  612. /* > \endverbatim */
  613. /* > */
  614. /* > \param[in] B */
  615. /* > \verbatim */
  616. /* > B is DOUBLE PRECISION array, dimension (LDB, N) */
  617. /* > The upper quasi triangular matrix B. */
  618. /* > \endverbatim */
  619. /* > */
  620. /* > \param[in] LDB */
  621. /* > \verbatim */
  622. /* > LDB is INTEGER */
  623. /* > The leading dimension of the array B. LDB >= f2cmax(1, N). */
  624. /* > \endverbatim */
  625. /* > */
  626. /* > \param[in,out] C */
  627. /* > \verbatim */
  628. /* > C is DOUBLE PRECISION array, dimension (LDC, N) */
  629. /* > On entry, C contains the right-hand-side of the first matrix */
  630. /* > equation in (1) or (3). */
  631. /* > On exit, if IJOB = 0, 1 or 2, C has been overwritten by */
  632. /* > the solution R. If IJOB = 3 or 4 and TRANS = 'N', C holds R, */
  633. /* > the solution achieved during the computation of the */
  634. /* > Dif-estimate. */
  635. /* > \endverbatim */
  636. /* > */
  637. /* > \param[in] LDC */
  638. /* > \verbatim */
  639. /* > LDC is INTEGER */
  640. /* > The leading dimension of the array C. LDC >= f2cmax(1, M). */
  641. /* > \endverbatim */
  642. /* > */
  643. /* > \param[in] D */
  644. /* > \verbatim */
  645. /* > D is DOUBLE PRECISION array, dimension (LDD, M) */
  646. /* > The upper triangular matrix D. */
  647. /* > \endverbatim */
  648. /* > */
  649. /* > \param[in] LDD */
  650. /* > \verbatim */
  651. /* > LDD is INTEGER */
  652. /* > The leading dimension of the array D. LDD >= f2cmax(1, M). */
  653. /* > \endverbatim */
  654. /* > */
  655. /* > \param[in] E */
  656. /* > \verbatim */
  657. /* > E is DOUBLE PRECISION array, dimension (LDE, N) */
  658. /* > The upper triangular matrix E. */
  659. /* > \endverbatim */
  660. /* > */
  661. /* > \param[in] LDE */
  662. /* > \verbatim */
  663. /* > LDE is INTEGER */
  664. /* > The leading dimension of the array E. LDE >= f2cmax(1, N). */
  665. /* > \endverbatim */
  666. /* > */
  667. /* > \param[in,out] F */
  668. /* > \verbatim */
  669. /* > F is DOUBLE PRECISION array, dimension (LDF, N) */
  670. /* > On entry, F contains the right-hand-side of the second matrix */
  671. /* > equation in (1) or (3). */
  672. /* > On exit, if IJOB = 0, 1 or 2, F has been overwritten by */
  673. /* > the solution L. If IJOB = 3 or 4 and TRANS = 'N', F holds L, */
  674. /* > the solution achieved during the computation of the */
  675. /* > Dif-estimate. */
  676. /* > \endverbatim */
  677. /* > */
  678. /* > \param[in] LDF */
  679. /* > \verbatim */
  680. /* > LDF is INTEGER */
  681. /* > The leading dimension of the array F. LDF >= f2cmax(1, M). */
  682. /* > \endverbatim */
  683. /* > */
  684. /* > \param[out] DIF */
  685. /* > \verbatim */
  686. /* > DIF is DOUBLE PRECISION */
  687. /* > On exit DIF is the reciprocal of a lower bound of the */
  688. /* > reciprocal of the Dif-function, i.e. DIF is an upper bound of */
  689. /* > Dif[(A,D), (B,E)] = sigma_min(Z), where Z as in (2). */
  690. /* > IF IJOB = 0 or TRANS = 'T', DIF is not touched. */
  691. /* > \endverbatim */
  692. /* > */
  693. /* > \param[out] SCALE */
  694. /* > \verbatim */
  695. /* > SCALE is DOUBLE PRECISION */
  696. /* > On exit SCALE is the scaling factor in (1) or (3). */
  697. /* > If 0 < SCALE < 1, C and F hold the solutions R and L, resp., */
  698. /* > to a slightly perturbed system but the input matrices A, B, D */
  699. /* > and E have not been changed. If SCALE = 0, C and F hold the */
  700. /* > solutions R and L, respectively, to the homogeneous system */
  701. /* > with C = F = 0. Normally, SCALE = 1. */
  702. /* > \endverbatim */
  703. /* > */
  704. /* > \param[out] WORK */
  705. /* > \verbatim */
  706. /* > WORK is DOUBLE PRECISION array, dimension (MAX(1,LWORK)) */
  707. /* > On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */
  708. /* > \endverbatim */
  709. /* > */
  710. /* > \param[in] LWORK */
  711. /* > \verbatim */
  712. /* > LWORK is INTEGER */
  713. /* > The dimension of the array WORK. LWORK > = 1. */
  714. /* > If IJOB = 1 or 2 and TRANS = 'N', LWORK >= f2cmax(1,2*M*N). */
  715. /* > */
  716. /* > If LWORK = -1, then a workspace query is assumed; the routine */
  717. /* > only calculates the optimal size of the WORK array, returns */
  718. /* > this value as the first entry of the WORK array, and no error */
  719. /* > message related to LWORK is issued by XERBLA. */
  720. /* > \endverbatim */
  721. /* > */
  722. /* > \param[out] IWORK */
  723. /* > \verbatim */
  724. /* > IWORK is INTEGER array, dimension (M+N+6) */
  725. /* > \endverbatim */
  726. /* > */
  727. /* > \param[out] INFO */
  728. /* > \verbatim */
  729. /* > INFO is INTEGER */
  730. /* > =0: successful exit */
  731. /* > <0: If INFO = -i, the i-th argument had an illegal value. */
  732. /* > >0: (A, D) and (B, E) have common or close eigenvalues. */
  733. /* > \endverbatim */
  734. /* Authors: */
  735. /* ======== */
  736. /* > \author Univ. of Tennessee */
  737. /* > \author Univ. of California Berkeley */
  738. /* > \author Univ. of Colorado Denver */
  739. /* > \author NAG Ltd. */
  740. /* > \date December 2016 */
  741. /* > \ingroup doubleSYcomputational */
  742. /* > \par Contributors: */
  743. /* ================== */
  744. /* > */
  745. /* > Bo Kagstrom and Peter Poromaa, Department of Computing Science, */
  746. /* > Umea University, S-901 87 Umea, Sweden. */
  747. /* > \par References: */
  748. /* ================ */
  749. /* > */
  750. /* > \verbatim */
  751. /* > */
  752. /* > [1] B. Kagstrom and P. Poromaa, LAPACK-Style Algorithms and Software */
  753. /* > for Solving the Generalized Sylvester Equation and Estimating the */
  754. /* > Separation between Regular Matrix Pairs, Report UMINF - 93.23, */
  755. /* > Department of Computing Science, Umea University, S-901 87 Umea, */
  756. /* > Sweden, December 1993, Revised April 1994, Also as LAPACK Working */
  757. /* > Note 75. To appear in ACM Trans. on Math. Software, Vol 22, */
  758. /* > No 1, 1996. */
  759. /* > */
  760. /* > [2] B. Kagstrom, A Perturbation Analysis of the Generalized Sylvester */
  761. /* > Equation (AR - LB, DR - LE ) = (C, F), SIAM J. Matrix Anal. */
  762. /* > Appl., 15(4):1045-1060, 1994 */
  763. /* > */
  764. /* > [3] B. Kagstrom and L. Westin, Generalized Schur Methods with */
  765. /* > Condition Estimators for Solving the Generalized Sylvester */
  766. /* > Equation, IEEE Transactions on Automatic Control, Vol. 34, No. 7, */
  767. /* > July 1989, pp 745-751. */
  768. /* > \endverbatim */
  769. /* > */
  770. /* ===================================================================== */
  771. /* Subroutine */ void dtgsyl_(char *trans, integer *ijob, integer *m, integer *
  772. n, doublereal *a, integer *lda, doublereal *b, integer *ldb,
  773. doublereal *c__, integer *ldc, doublereal *d__, integer *ldd,
  774. doublereal *e, integer *lde, doublereal *f, integer *ldf, doublereal *
  775. scale, doublereal *dif, doublereal *work, integer *lwork, integer *
  776. iwork, integer *info)
  777. {
  778. /* System generated locals */
  779. integer a_dim1, a_offset, b_dim1, b_offset, c_dim1, c_offset, d_dim1,
  780. d_offset, e_dim1, e_offset, f_dim1, f_offset, i__1, i__2, i__3,
  781. i__4;
  782. /* Local variables */
  783. doublereal dsum;
  784. integer ppqq, i__, j, k, p, q;
  785. extern /* Subroutine */ void dscal_(integer *, doublereal *, doublereal *,
  786. integer *), dgemm_(char *, char *, integer *, integer *, integer *
  787. , doublereal *, doublereal *, integer *, doublereal *, integer *,
  788. doublereal *, doublereal *, integer *);
  789. extern logical lsame_(char *, char *);
  790. integer ifunc, linfo, lwmin;
  791. doublereal scale2;
  792. extern /* Subroutine */ void dtgsy2_(char *, integer *, integer *, integer
  793. *, doublereal *, integer *, doublereal *, integer *, doublereal *,
  794. integer *, doublereal *, integer *, doublereal *, integer *,
  795. doublereal *, integer *, doublereal *, doublereal *, doublereal *,
  796. integer *, integer *, integer *);
  797. integer ie, je, mb, nb;
  798. doublereal dscale;
  799. integer is, js, pq;
  800. doublereal scaloc;
  801. extern /* Subroutine */ void dlacpy_(char *, integer *, integer *,
  802. doublereal *, integer *, doublereal *, integer *),
  803. dlaset_(char *, integer *, integer *, doublereal *, doublereal *,
  804. doublereal *, integer *);
  805. extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
  806. integer *, integer *, ftnlen, ftnlen);
  807. extern /* Subroutine */ int xerbla_(char *, integer *, ftnlen);
  808. integer iround;
  809. logical notran;
  810. integer isolve;
  811. logical lquery;
  812. /* -- LAPACK computational routine (version 3.7.0) -- */
  813. /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
  814. /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
  815. /* December 2016 */
  816. /* ===================================================================== */
  817. /* Replaced various illegal calls to DCOPY by calls to DLASET. */
  818. /* Sven Hammarling, 1/5/02. */
  819. /* Decode and test input parameters */
  820. /* Parameter adjustments */
  821. a_dim1 = *lda;
  822. a_offset = 1 + a_dim1 * 1;
  823. a -= a_offset;
  824. b_dim1 = *ldb;
  825. b_offset = 1 + b_dim1 * 1;
  826. b -= b_offset;
  827. c_dim1 = *ldc;
  828. c_offset = 1 + c_dim1 * 1;
  829. c__ -= c_offset;
  830. d_dim1 = *ldd;
  831. d_offset = 1 + d_dim1 * 1;
  832. d__ -= d_offset;
  833. e_dim1 = *lde;
  834. e_offset = 1 + e_dim1 * 1;
  835. e -= e_offset;
  836. f_dim1 = *ldf;
  837. f_offset = 1 + f_dim1 * 1;
  838. f -= f_offset;
  839. --work;
  840. --iwork;
  841. /* Function Body */
  842. *info = 0;
  843. notran = lsame_(trans, "N");
  844. lquery = *lwork == -1;
  845. if (! notran && ! lsame_(trans, "T")) {
  846. *info = -1;
  847. } else if (notran) {
  848. if (*ijob < 0 || *ijob > 4) {
  849. *info = -2;
  850. }
  851. }
  852. if (*info == 0) {
  853. if (*m <= 0) {
  854. *info = -3;
  855. } else if (*n <= 0) {
  856. *info = -4;
  857. } else if (*lda < f2cmax(1,*m)) {
  858. *info = -6;
  859. } else if (*ldb < f2cmax(1,*n)) {
  860. *info = -8;
  861. } else if (*ldc < f2cmax(1,*m)) {
  862. *info = -10;
  863. } else if (*ldd < f2cmax(1,*m)) {
  864. *info = -12;
  865. } else if (*lde < f2cmax(1,*n)) {
  866. *info = -14;
  867. } else if (*ldf < f2cmax(1,*m)) {
  868. *info = -16;
  869. }
  870. }
  871. if (*info == 0) {
  872. if (notran) {
  873. if (*ijob == 1 || *ijob == 2) {
  874. /* Computing MAX */
  875. i__1 = 1, i__2 = (*m << 1) * *n;
  876. lwmin = f2cmax(i__1,i__2);
  877. } else {
  878. lwmin = 1;
  879. }
  880. } else {
  881. lwmin = 1;
  882. }
  883. work[1] = (doublereal) lwmin;
  884. if (*lwork < lwmin && ! lquery) {
  885. *info = -20;
  886. }
  887. }
  888. if (*info != 0) {
  889. i__1 = -(*info);
  890. xerbla_("DTGSYL", &i__1, (ftnlen)6);
  891. return;
  892. } else if (lquery) {
  893. return;
  894. }
  895. /* Quick return if possible */
  896. if (*m == 0 || *n == 0) {
  897. *scale = 1.;
  898. if (notran) {
  899. if (*ijob != 0) {
  900. *dif = 0.;
  901. }
  902. }
  903. return;
  904. }
  905. /* Determine optimal block sizes MB and NB */
  906. mb = ilaenv_(&c__2, "DTGSYL", trans, m, n, &c_n1, &c_n1, (ftnlen)6, (
  907. ftnlen)1);
  908. nb = ilaenv_(&c__5, "DTGSYL", trans, m, n, &c_n1, &c_n1, (ftnlen)6, (
  909. ftnlen)1);
  910. isolve = 1;
  911. ifunc = 0;
  912. if (notran) {
  913. if (*ijob >= 3) {
  914. ifunc = *ijob - 2;
  915. dlaset_("F", m, n, &c_b14, &c_b14, &c__[c_offset], ldc)
  916. ;
  917. dlaset_("F", m, n, &c_b14, &c_b14, &f[f_offset], ldf);
  918. } else if (*ijob >= 1) {
  919. isolve = 2;
  920. }
  921. }
  922. if (mb <= 1 && nb <= 1 || mb >= *m && nb >= *n) {
  923. i__1 = isolve;
  924. for (iround = 1; iround <= i__1; ++iround) {
  925. /* Use unblocked Level 2 solver */
  926. dscale = 0.;
  927. dsum = 1.;
  928. pq = 0;
  929. dtgsy2_(trans, &ifunc, m, n, &a[a_offset], lda, &b[b_offset], ldb,
  930. &c__[c_offset], ldc, &d__[d_offset], ldd, &e[e_offset],
  931. lde, &f[f_offset], ldf, scale, &dsum, &dscale, &iwork[1],
  932. &pq, info);
  933. if (dscale != 0.) {
  934. if (*ijob == 1 || *ijob == 3) {
  935. *dif = sqrt((doublereal) ((*m << 1) * *n)) / (dscale *
  936. sqrt(dsum));
  937. } else {
  938. *dif = sqrt((doublereal) pq) / (dscale * sqrt(dsum));
  939. }
  940. }
  941. if (isolve == 2 && iround == 1) {
  942. if (notran) {
  943. ifunc = *ijob;
  944. }
  945. scale2 = *scale;
  946. dlacpy_("F", m, n, &c__[c_offset], ldc, &work[1], m);
  947. dlacpy_("F", m, n, &f[f_offset], ldf, &work[*m * *n + 1], m);
  948. dlaset_("F", m, n, &c_b14, &c_b14, &c__[c_offset], ldc);
  949. dlaset_("F", m, n, &c_b14, &c_b14, &f[f_offset], ldf);
  950. } else if (isolve == 2 && iround == 2) {
  951. dlacpy_("F", m, n, &work[1], m, &c__[c_offset], ldc);
  952. dlacpy_("F", m, n, &work[*m * *n + 1], m, &f[f_offset], ldf);
  953. *scale = scale2;
  954. }
  955. /* L30: */
  956. }
  957. return;
  958. }
  959. /* Determine block structure of A */
  960. p = 0;
  961. i__ = 1;
  962. L40:
  963. if (i__ > *m) {
  964. goto L50;
  965. }
  966. ++p;
  967. iwork[p] = i__;
  968. i__ += mb;
  969. if (i__ >= *m) {
  970. goto L50;
  971. }
  972. if (a[i__ + (i__ - 1) * a_dim1] != 0.) {
  973. ++i__;
  974. }
  975. goto L40;
  976. L50:
  977. iwork[p + 1] = *m + 1;
  978. if (iwork[p] == iwork[p + 1]) {
  979. --p;
  980. }
  981. /* Determine block structure of B */
  982. q = p + 1;
  983. j = 1;
  984. L60:
  985. if (j > *n) {
  986. goto L70;
  987. }
  988. ++q;
  989. iwork[q] = j;
  990. j += nb;
  991. if (j >= *n) {
  992. goto L70;
  993. }
  994. if (b[j + (j - 1) * b_dim1] != 0.) {
  995. ++j;
  996. }
  997. goto L60;
  998. L70:
  999. iwork[q + 1] = *n + 1;
  1000. if (iwork[q] == iwork[q + 1]) {
  1001. --q;
  1002. }
  1003. if (notran) {
  1004. i__1 = isolve;
  1005. for (iround = 1; iround <= i__1; ++iround) {
  1006. /* Solve (I, J)-subsystem */
  1007. /* A(I, I) * R(I, J) - L(I, J) * B(J, J) = C(I, J) */
  1008. /* D(I, I) * R(I, J) - L(I, J) * E(J, J) = F(I, J) */
  1009. /* for I = P, P - 1,..., 1; J = 1, 2,..., Q */
  1010. dscale = 0.;
  1011. dsum = 1.;
  1012. pq = 0;
  1013. *scale = 1.;
  1014. i__2 = q;
  1015. for (j = p + 2; j <= i__2; ++j) {
  1016. js = iwork[j];
  1017. je = iwork[j + 1] - 1;
  1018. nb = je - js + 1;
  1019. for (i__ = p; i__ >= 1; --i__) {
  1020. is = iwork[i__];
  1021. ie = iwork[i__ + 1] - 1;
  1022. mb = ie - is + 1;
  1023. ppqq = 0;
  1024. dtgsy2_(trans, &ifunc, &mb, &nb, &a[is + is * a_dim1],
  1025. lda, &b[js + js * b_dim1], ldb, &c__[is + js *
  1026. c_dim1], ldc, &d__[is + is * d_dim1], ldd, &e[js
  1027. + js * e_dim1], lde, &f[is + js * f_dim1], ldf, &
  1028. scaloc, &dsum, &dscale, &iwork[q + 2], &ppqq, &
  1029. linfo);
  1030. if (linfo > 0) {
  1031. *info = linfo;
  1032. }
  1033. pq += ppqq;
  1034. if (scaloc != 1.) {
  1035. i__3 = js - 1;
  1036. for (k = 1; k <= i__3; ++k) {
  1037. dscal_(m, &scaloc, &c__[k * c_dim1 + 1], &c__1);
  1038. dscal_(m, &scaloc, &f[k * f_dim1 + 1], &c__1);
  1039. /* L80: */
  1040. }
  1041. i__3 = je;
  1042. for (k = js; k <= i__3; ++k) {
  1043. i__4 = is - 1;
  1044. dscal_(&i__4, &scaloc, &c__[k * c_dim1 + 1], &
  1045. c__1);
  1046. i__4 = is - 1;
  1047. dscal_(&i__4, &scaloc, &f[k * f_dim1 + 1], &c__1);
  1048. /* L90: */
  1049. }
  1050. i__3 = je;
  1051. for (k = js; k <= i__3; ++k) {
  1052. i__4 = *m - ie;
  1053. dscal_(&i__4, &scaloc, &c__[ie + 1 + k * c_dim1],
  1054. &c__1);
  1055. i__4 = *m - ie;
  1056. dscal_(&i__4, &scaloc, &f[ie + 1 + k * f_dim1], &
  1057. c__1);
  1058. /* L100: */
  1059. }
  1060. i__3 = *n;
  1061. for (k = je + 1; k <= i__3; ++k) {
  1062. dscal_(m, &scaloc, &c__[k * c_dim1 + 1], &c__1);
  1063. dscal_(m, &scaloc, &f[k * f_dim1 + 1], &c__1);
  1064. /* L110: */
  1065. }
  1066. *scale *= scaloc;
  1067. }
  1068. /* Substitute R(I, J) and L(I, J) into remaining */
  1069. /* equation. */
  1070. if (i__ > 1) {
  1071. i__3 = is - 1;
  1072. dgemm_("N", "N", &i__3, &nb, &mb, &c_b51, &a[is *
  1073. a_dim1 + 1], lda, &c__[is + js * c_dim1], ldc,
  1074. &c_b52, &c__[js * c_dim1 + 1], ldc);
  1075. i__3 = is - 1;
  1076. dgemm_("N", "N", &i__3, &nb, &mb, &c_b51, &d__[is *
  1077. d_dim1 + 1], ldd, &c__[is + js * c_dim1], ldc,
  1078. &c_b52, &f[js * f_dim1 + 1], ldf);
  1079. }
  1080. if (j < q) {
  1081. i__3 = *n - je;
  1082. dgemm_("N", "N", &mb, &i__3, &nb, &c_b52, &f[is + js *
  1083. f_dim1], ldf, &b[js + (je + 1) * b_dim1],
  1084. ldb, &c_b52, &c__[is + (je + 1) * c_dim1],
  1085. ldc);
  1086. i__3 = *n - je;
  1087. dgemm_("N", "N", &mb, &i__3, &nb, &c_b52, &f[is + js *
  1088. f_dim1], ldf, &e[js + (je + 1) * e_dim1],
  1089. lde, &c_b52, &f[is + (je + 1) * f_dim1], ldf);
  1090. }
  1091. /* L120: */
  1092. }
  1093. /* L130: */
  1094. }
  1095. if (dscale != 0.) {
  1096. if (*ijob == 1 || *ijob == 3) {
  1097. *dif = sqrt((doublereal) ((*m << 1) * *n)) / (dscale *
  1098. sqrt(dsum));
  1099. } else {
  1100. *dif = sqrt((doublereal) pq) / (dscale * sqrt(dsum));
  1101. }
  1102. }
  1103. if (isolve == 2 && iround == 1) {
  1104. if (notran) {
  1105. ifunc = *ijob;
  1106. }
  1107. scale2 = *scale;
  1108. dlacpy_("F", m, n, &c__[c_offset], ldc, &work[1], m);
  1109. dlacpy_("F", m, n, &f[f_offset], ldf, &work[*m * *n + 1], m);
  1110. dlaset_("F", m, n, &c_b14, &c_b14, &c__[c_offset], ldc);
  1111. dlaset_("F", m, n, &c_b14, &c_b14, &f[f_offset], ldf);
  1112. } else if (isolve == 2 && iround == 2) {
  1113. dlacpy_("F", m, n, &work[1], m, &c__[c_offset], ldc);
  1114. dlacpy_("F", m, n, &work[*m * *n + 1], m, &f[f_offset], ldf);
  1115. *scale = scale2;
  1116. }
  1117. /* L150: */
  1118. }
  1119. } else {
  1120. /* Solve transposed (I, J)-subsystem */
  1121. /* A(I, I)**T * R(I, J) + D(I, I)**T * L(I, J) = C(I, J) */
  1122. /* R(I, J) * B(J, J)**T + L(I, J) * E(J, J)**T = -F(I, J) */
  1123. /* for I = 1,2,..., P; J = Q, Q-1,..., 1 */
  1124. *scale = 1.;
  1125. i__1 = p;
  1126. for (i__ = 1; i__ <= i__1; ++i__) {
  1127. is = iwork[i__];
  1128. ie = iwork[i__ + 1] - 1;
  1129. mb = ie - is + 1;
  1130. i__2 = p + 2;
  1131. for (j = q; j >= i__2; --j) {
  1132. js = iwork[j];
  1133. je = iwork[j + 1] - 1;
  1134. nb = je - js + 1;
  1135. dtgsy2_(trans, &ifunc, &mb, &nb, &a[is + is * a_dim1], lda, &
  1136. b[js + js * b_dim1], ldb, &c__[is + js * c_dim1], ldc,
  1137. &d__[is + is * d_dim1], ldd, &e[js + js * e_dim1],
  1138. lde, &f[is + js * f_dim1], ldf, &scaloc, &dsum, &
  1139. dscale, &iwork[q + 2], &ppqq, &linfo);
  1140. if (linfo > 0) {
  1141. *info = linfo;
  1142. }
  1143. if (scaloc != 1.) {
  1144. i__3 = js - 1;
  1145. for (k = 1; k <= i__3; ++k) {
  1146. dscal_(m, &scaloc, &c__[k * c_dim1 + 1], &c__1);
  1147. dscal_(m, &scaloc, &f[k * f_dim1 + 1], &c__1);
  1148. /* L160: */
  1149. }
  1150. i__3 = je;
  1151. for (k = js; k <= i__3; ++k) {
  1152. i__4 = is - 1;
  1153. dscal_(&i__4, &scaloc, &c__[k * c_dim1 + 1], &c__1);
  1154. i__4 = is - 1;
  1155. dscal_(&i__4, &scaloc, &f[k * f_dim1 + 1], &c__1);
  1156. /* L170: */
  1157. }
  1158. i__3 = je;
  1159. for (k = js; k <= i__3; ++k) {
  1160. i__4 = *m - ie;
  1161. dscal_(&i__4, &scaloc, &c__[ie + 1 + k * c_dim1], &
  1162. c__1);
  1163. i__4 = *m - ie;
  1164. dscal_(&i__4, &scaloc, &f[ie + 1 + k * f_dim1], &c__1)
  1165. ;
  1166. /* L180: */
  1167. }
  1168. i__3 = *n;
  1169. for (k = je + 1; k <= i__3; ++k) {
  1170. dscal_(m, &scaloc, &c__[k * c_dim1 + 1], &c__1);
  1171. dscal_(m, &scaloc, &f[k * f_dim1 + 1], &c__1);
  1172. /* L190: */
  1173. }
  1174. *scale *= scaloc;
  1175. }
  1176. /* Substitute R(I, J) and L(I, J) into remaining equation. */
  1177. if (j > p + 2) {
  1178. i__3 = js - 1;
  1179. dgemm_("N", "T", &mb, &i__3, &nb, &c_b52, &c__[is + js *
  1180. c_dim1], ldc, &b[js * b_dim1 + 1], ldb, &c_b52, &
  1181. f[is + f_dim1], ldf);
  1182. i__3 = js - 1;
  1183. dgemm_("N", "T", &mb, &i__3, &nb, &c_b52, &f[is + js *
  1184. f_dim1], ldf, &e[js * e_dim1 + 1], lde, &c_b52, &
  1185. f[is + f_dim1], ldf);
  1186. }
  1187. if (i__ < p) {
  1188. i__3 = *m - ie;
  1189. dgemm_("T", "N", &i__3, &nb, &mb, &c_b51, &a[is + (ie + 1)
  1190. * a_dim1], lda, &c__[is + js * c_dim1], ldc, &
  1191. c_b52, &c__[ie + 1 + js * c_dim1], ldc);
  1192. i__3 = *m - ie;
  1193. dgemm_("T", "N", &i__3, &nb, &mb, &c_b51, &d__[is + (ie +
  1194. 1) * d_dim1], ldd, &f[is + js * f_dim1], ldf, &
  1195. c_b52, &c__[ie + 1 + js * c_dim1], ldc);
  1196. }
  1197. /* L200: */
  1198. }
  1199. /* L210: */
  1200. }
  1201. }
  1202. work[1] = (doublereal) lwmin;
  1203. return;
  1204. /* End of DTGSYL */
  1205. } /* dtgsyl_ */