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.

ztgsyl.c 38 kB

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