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.

zgghd3.c 54 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765
  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 doublecomplex c_b1 = {1.,0.};
  485. static doublecomplex c_b2 = {0.,0.};
  486. static integer c__1 = 1;
  487. static integer c_n1 = -1;
  488. static integer c__2 = 2;
  489. static integer c__3 = 3;
  490. static integer c__16 = 16;
  491. /* > \brief \b ZGGHD3 */
  492. /* =========== DOCUMENTATION =========== */
  493. /* Online html documentation available at */
  494. /* http://www.netlib.org/lapack/explore-html/ */
  495. /* > \htmlonly */
  496. /* > Download ZGGHD3 + dependencies */
  497. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/zgghd3.
  498. f"> */
  499. /* > [TGZ]</a> */
  500. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/zgghd3.
  501. f"> */
  502. /* > [ZIP]</a> */
  503. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/zgghd3.
  504. f"> */
  505. /* > [TXT]</a> */
  506. /* > \endhtmlonly */
  507. /* Definition: */
  508. /* =========== */
  509. /* SUBROUTINE ZGGHD3( COMPQ, COMPZ, N, ILO, IHI, A, LDA, B, LDB, Q, */
  510. /* LDQ, Z, LDZ, WORK, LWORK, INFO ) */
  511. /* CHARACTER COMPQ, COMPZ */
  512. /* INTEGER IHI, ILO, INFO, LDA, LDB, LDQ, LDZ, N, LWORK */
  513. /* COMPLEX*16 A( LDA, * ), B( LDB, * ), Q( LDQ, * ), */
  514. /* $ Z( LDZ, * ), WORK( * ) */
  515. /* > \par Purpose: */
  516. /* ============= */
  517. /* > */
  518. /* > \verbatim */
  519. /* > */
  520. /* > ZGGHD3 reduces a pair of complex matrices (A,B) to generalized upper */
  521. /* > Hessenberg form using unitary transformations, where A is a */
  522. /* > general matrix and B is upper triangular. The form of the */
  523. /* > generalized eigenvalue problem is */
  524. /* > A*x = lambda*B*x, */
  525. /* > and B is typically made upper triangular by computing its QR */
  526. /* > factorization and moving the unitary matrix Q to the left side */
  527. /* > of the equation. */
  528. /* > */
  529. /* > This subroutine simultaneously reduces A to a Hessenberg matrix H: */
  530. /* > Q**H*A*Z = H */
  531. /* > and transforms B to another upper triangular matrix T: */
  532. /* > Q**H*B*Z = T */
  533. /* > in order to reduce the problem to its standard form */
  534. /* > H*y = lambda*T*y */
  535. /* > where y = Z**H*x. */
  536. /* > */
  537. /* > The unitary matrices Q and Z are determined as products of Givens */
  538. /* > rotations. They may either be formed explicitly, or they may be */
  539. /* > postmultiplied into input matrices Q1 and Z1, so that */
  540. /* > Q1 * A * Z1**H = (Q1*Q) * H * (Z1*Z)**H */
  541. /* > Q1 * B * Z1**H = (Q1*Q) * T * (Z1*Z)**H */
  542. /* > If Q1 is the unitary matrix from the QR factorization of B in the */
  543. /* > original equation A*x = lambda*B*x, then ZGGHD3 reduces the original */
  544. /* > problem to generalized Hessenberg form. */
  545. /* > */
  546. /* > This is a blocked variant of CGGHRD, using matrix-matrix */
  547. /* > multiplications for parts of the computation to enhance performance. */
  548. /* > \endverbatim */
  549. /* Arguments: */
  550. /* ========== */
  551. /* > \param[in] COMPQ */
  552. /* > \verbatim */
  553. /* > COMPQ is CHARACTER*1 */
  554. /* > = 'N': do not compute Q; */
  555. /* > = 'I': Q is initialized to the unit matrix, and the */
  556. /* > unitary matrix Q is returned; */
  557. /* > = 'V': Q must contain a unitary matrix Q1 on entry, */
  558. /* > and the product Q1*Q is returned. */
  559. /* > \endverbatim */
  560. /* > */
  561. /* > \param[in] COMPZ */
  562. /* > \verbatim */
  563. /* > COMPZ is CHARACTER*1 */
  564. /* > = 'N': do not compute Z; */
  565. /* > = 'I': Z is initialized to the unit matrix, and the */
  566. /* > unitary matrix Z is returned; */
  567. /* > = 'V': Z must contain a unitary matrix Z1 on entry, */
  568. /* > and the product Z1*Z is returned. */
  569. /* > \endverbatim */
  570. /* > */
  571. /* > \param[in] N */
  572. /* > \verbatim */
  573. /* > N is INTEGER */
  574. /* > The order of the matrices A and B. N >= 0. */
  575. /* > \endverbatim */
  576. /* > */
  577. /* > \param[in] ILO */
  578. /* > \verbatim */
  579. /* > ILO is INTEGER */
  580. /* > \endverbatim */
  581. /* > */
  582. /* > \param[in] IHI */
  583. /* > \verbatim */
  584. /* > IHI is INTEGER */
  585. /* > */
  586. /* > ILO and IHI mark the rows and columns of A which are to be */
  587. /* > reduced. It is assumed that A is already upper triangular */
  588. /* > in rows and columns 1:ILO-1 and IHI+1:N. ILO and IHI are */
  589. /* > normally set by a previous call to ZGGBAL; otherwise they */
  590. /* > should be set to 1 and N respectively. */
  591. /* > 1 <= ILO <= IHI <= N, if N > 0; ILO=1 and IHI=0, if N=0. */
  592. /* > \endverbatim */
  593. /* > */
  594. /* > \param[in,out] A */
  595. /* > \verbatim */
  596. /* > A is COMPLEX*16 array, dimension (LDA, N) */
  597. /* > On entry, the N-by-N general matrix to be reduced. */
  598. /* > On exit, the upper triangle and the first subdiagonal of A */
  599. /* > are overwritten with the upper Hessenberg matrix H, and the */
  600. /* > rest is set to zero. */
  601. /* > \endverbatim */
  602. /* > */
  603. /* > \param[in] LDA */
  604. /* > \verbatim */
  605. /* > LDA is INTEGER */
  606. /* > The leading dimension of the array A. LDA >= f2cmax(1,N). */
  607. /* > \endverbatim */
  608. /* > */
  609. /* > \param[in,out] B */
  610. /* > \verbatim */
  611. /* > B is COMPLEX*16 array, dimension (LDB, N) */
  612. /* > On entry, the N-by-N upper triangular matrix B. */
  613. /* > On exit, the upper triangular matrix T = Q**H B Z. The */
  614. /* > elements below the diagonal are set to zero. */
  615. /* > \endverbatim */
  616. /* > */
  617. /* > \param[in] LDB */
  618. /* > \verbatim */
  619. /* > LDB is INTEGER */
  620. /* > The leading dimension of the array B. LDB >= f2cmax(1,N). */
  621. /* > \endverbatim */
  622. /* > */
  623. /* > \param[in,out] Q */
  624. /* > \verbatim */
  625. /* > Q is COMPLEX*16 array, dimension (LDQ, N) */
  626. /* > On entry, if COMPQ = 'V', the unitary matrix Q1, typically */
  627. /* > from the QR factorization of B. */
  628. /* > On exit, if COMPQ='I', the unitary matrix Q, and if */
  629. /* > COMPQ = 'V', the product Q1*Q. */
  630. /* > Not referenced if COMPQ='N'. */
  631. /* > \endverbatim */
  632. /* > */
  633. /* > \param[in] LDQ */
  634. /* > \verbatim */
  635. /* > LDQ is INTEGER */
  636. /* > The leading dimension of the array Q. */
  637. /* > LDQ >= N if COMPQ='V' or 'I'; LDQ >= 1 otherwise. */
  638. /* > \endverbatim */
  639. /* > */
  640. /* > \param[in,out] Z */
  641. /* > \verbatim */
  642. /* > Z is COMPLEX*16 array, dimension (LDZ, N) */
  643. /* > On entry, if COMPZ = 'V', the unitary matrix Z1. */
  644. /* > On exit, if COMPZ='I', the unitary matrix Z, and if */
  645. /* > COMPZ = 'V', the product Z1*Z. */
  646. /* > Not referenced if COMPZ='N'. */
  647. /* > \endverbatim */
  648. /* > */
  649. /* > \param[in] LDZ */
  650. /* > \verbatim */
  651. /* > LDZ is INTEGER */
  652. /* > The leading dimension of the array Z. */
  653. /* > LDZ >= N if COMPZ='V' or 'I'; LDZ >= 1 otherwise. */
  654. /* > \endverbatim */
  655. /* > */
  656. /* > \param[out] WORK */
  657. /* > \verbatim */
  658. /* > WORK is COMPLEX*16 array, dimension (LWORK) */
  659. /* > On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */
  660. /* > \endverbatim */
  661. /* > */
  662. /* > \param[in] LWORK */
  663. /* > \verbatim */
  664. /* > LWORK is INTEGER */
  665. /* > The length of the array WORK. LWORK >= 1. */
  666. /* > For optimum performance LWORK >= 6*N*NB, where NB is the */
  667. /* > optimal blocksize. */
  668. /* > */
  669. /* > If LWORK = -1, then a workspace query is assumed; the routine */
  670. /* > only calculates the optimal size of the WORK array, returns */
  671. /* > this value as the first entry of the WORK array, and no error */
  672. /* > message related to LWORK is issued by XERBLA. */
  673. /* > \endverbatim */
  674. /* > */
  675. /* > \param[out] INFO */
  676. /* > \verbatim */
  677. /* > INFO is INTEGER */
  678. /* > = 0: successful exit. */
  679. /* > < 0: if INFO = -i, the i-th argument had an illegal value. */
  680. /* > \endverbatim */
  681. /* Authors: */
  682. /* ======== */
  683. /* > \author Univ. of Tennessee */
  684. /* > \author Univ. of California Berkeley */
  685. /* > \author Univ. of Colorado Denver */
  686. /* > \author NAG Ltd. */
  687. /* > \date January 2015 */
  688. /* > \ingroup complex16OTHERcomputational */
  689. /* > \par Further Details: */
  690. /* ===================== */
  691. /* > */
  692. /* > \verbatim */
  693. /* > */
  694. /* > This routine reduces A to Hessenberg form and maintains B in */
  695. /* > using a blocked variant of Moler and Stewart's original algorithm, */
  696. /* > as described by Kagstrom, Kressner, Quintana-Orti, and Quintana-Orti */
  697. /* > (BIT 2008). */
  698. /* > \endverbatim */
  699. /* > */
  700. /* ===================================================================== */
  701. /* Subroutine */ void zgghd3_(char *compq, char *compz, integer *n, integer *
  702. ilo, integer *ihi, doublecomplex *a, integer *lda, doublecomplex *b,
  703. integer *ldb, doublecomplex *q, integer *ldq, doublecomplex *z__,
  704. integer *ldz, doublecomplex *work, integer *lwork, integer *info)
  705. {
  706. /* System generated locals */
  707. integer a_dim1, a_offset, b_dim1, b_offset, q_dim1, q_offset, z_dim1,
  708. z_offset, i__1, i__2, i__3, i__4, i__5, i__6, i__7, i__8, i__9;
  709. doublecomplex z__1, z__2, z__3, z__4;
  710. /* Local variables */
  711. logical blk22;
  712. integer cola, jcol, ierr;
  713. doublecomplex temp;
  714. integer jrow, topq, ppwo;
  715. extern /* Subroutine */ void zrot_(integer *, doublecomplex *, integer *,
  716. doublecomplex *, integer *, doublereal *, doublecomplex *);
  717. doublecomplex temp1, temp2, temp3;
  718. doublereal c__;
  719. integer kacc22, i__, j, k;
  720. doublecomplex s;
  721. extern logical lsame_(char *, char *);
  722. integer nbmin;
  723. doublecomplex ctemp;
  724. extern /* Subroutine */ void zgemm_(char *, char *, integer *, integer *,
  725. integer *, doublecomplex *, doublecomplex *, integer *,
  726. doublecomplex *, integer *, doublecomplex *, doublecomplex *,
  727. integer *);
  728. integer nblst;
  729. logical initq;
  730. doublecomplex c1, c2;
  731. extern /* Subroutine */ void zgemv_(char *, integer *, integer *,
  732. doublecomplex *, doublecomplex *, integer *, doublecomplex *,
  733. integer *, doublecomplex *, doublecomplex *, integer *);
  734. logical wantq;
  735. integer j0;
  736. logical initz;
  737. extern /* Subroutine */ void zunm22_(char *, char *, integer *, integer *,
  738. integer *, integer *, doublecomplex *, integer *, doublecomplex *,
  739. integer *, doublecomplex *, integer *, integer *)
  740. ;
  741. logical wantz;
  742. doublecomplex s1, s2;
  743. extern /* Subroutine */ void ztrmv_(char *, char *, char *, integer *,
  744. doublecomplex *, integer *, doublecomplex *, integer *);
  745. char compq2[1], compz2[1];
  746. integer nb, jj, nh, nx, pw;
  747. extern /* Subroutine */ int xerbla_(char *, integer *, ftnlen);
  748. extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
  749. integer *, integer *, ftnlen, ftnlen);
  750. extern /* Subroutine */ void zgghrd_(char *, char *, integer *, integer *,
  751. integer *, doublecomplex *, integer *, doublecomplex *, integer *,
  752. doublecomplex *, integer *, doublecomplex *, integer *, integer *
  753. ), zlaset_(char *, integer *, integer *,
  754. doublecomplex *, doublecomplex *, doublecomplex *, integer *), zlartg_(doublecomplex *, doublecomplex *, doublereal *,
  755. doublecomplex *, doublecomplex *), zlacpy_(char *, integer *,
  756. integer *, doublecomplex *, integer *, doublecomplex *, integer *);
  757. integer lwkopt;
  758. logical lquery;
  759. integer nnb, len, top, ppw, n2nb;
  760. /* -- LAPACK computational routine (version 3.8.0) -- */
  761. /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
  762. /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
  763. /* January 2015 */
  764. /* ===================================================================== */
  765. /* Decode and test the input parameters. */
  766. /* Parameter adjustments */
  767. a_dim1 = *lda;
  768. a_offset = 1 + a_dim1 * 1;
  769. a -= a_offset;
  770. b_dim1 = *ldb;
  771. b_offset = 1 + b_dim1 * 1;
  772. b -= b_offset;
  773. q_dim1 = *ldq;
  774. q_offset = 1 + q_dim1 * 1;
  775. q -= q_offset;
  776. z_dim1 = *ldz;
  777. z_offset = 1 + z_dim1 * 1;
  778. z__ -= z_offset;
  779. --work;
  780. /* Function Body */
  781. *info = 0;
  782. nb = ilaenv_(&c__1, "ZGGHD3", " ", n, ilo, ihi, &c_n1, (ftnlen)6, (ftnlen)
  783. 1);
  784. /* Computing MAX */
  785. i__1 = *n * 6 * nb;
  786. lwkopt = f2cmax(i__1,1);
  787. z__1.r = (doublereal) lwkopt, z__1.i = 0.;
  788. work[1].r = z__1.r, work[1].i = z__1.i;
  789. initq = lsame_(compq, "I");
  790. wantq = initq || lsame_(compq, "V");
  791. initz = lsame_(compz, "I");
  792. wantz = initz || lsame_(compz, "V");
  793. lquery = *lwork == -1;
  794. if (! lsame_(compq, "N") && ! wantq) {
  795. *info = -1;
  796. } else if (! lsame_(compz, "N") && ! wantz) {
  797. *info = -2;
  798. } else if (*n < 0) {
  799. *info = -3;
  800. } else if (*ilo < 1) {
  801. *info = -4;
  802. } else if (*ihi > *n || *ihi < *ilo - 1) {
  803. *info = -5;
  804. } else if (*lda < f2cmax(1,*n)) {
  805. *info = -7;
  806. } else if (*ldb < f2cmax(1,*n)) {
  807. *info = -9;
  808. } else if (wantq && *ldq < *n || *ldq < 1) {
  809. *info = -11;
  810. } else if (wantz && *ldz < *n || *ldz < 1) {
  811. *info = -13;
  812. } else if (*lwork < 1 && ! lquery) {
  813. *info = -15;
  814. }
  815. if (*info != 0) {
  816. i__1 = -(*info);
  817. xerbla_("ZGGHD3", &i__1, (ftnlen)6);
  818. return;
  819. } else if (lquery) {
  820. return;
  821. }
  822. /* Initialize Q and Z if desired. */
  823. if (initq) {
  824. zlaset_("All", n, n, &c_b2, &c_b1, &q[q_offset], ldq);
  825. }
  826. if (initz) {
  827. zlaset_("All", n, n, &c_b2, &c_b1, &z__[z_offset], ldz);
  828. }
  829. /* Zero out lower triangle of B. */
  830. if (*n > 1) {
  831. i__1 = *n - 1;
  832. i__2 = *n - 1;
  833. zlaset_("Lower", &i__1, &i__2, &c_b2, &c_b2, &b[b_dim1 + 2], ldb);
  834. }
  835. /* Quick return if possible */
  836. nh = *ihi - *ilo + 1;
  837. if (nh <= 1) {
  838. work[1].r = 1., work[1].i = 0.;
  839. return;
  840. }
  841. /* Determine the blocksize. */
  842. nbmin = ilaenv_(&c__2, "ZGGHD3", " ", n, ilo, ihi, &c_n1, (ftnlen)6, (
  843. ftnlen)1);
  844. if (nb > 1 && nb < nh) {
  845. /* Determine when to use unblocked instead of blocked code. */
  846. /* Computing MAX */
  847. i__1 = nb, i__2 = ilaenv_(&c__3, "ZGGHD3", " ", n, ilo, ihi, &c_n1, (
  848. ftnlen)6, (ftnlen)1);
  849. nx = f2cmax(i__1,i__2);
  850. if (nx < nh) {
  851. /* Determine if workspace is large enough for blocked code. */
  852. if (*lwork < lwkopt) {
  853. /* Not enough workspace to use optimal NB: determine the */
  854. /* minimum value of NB, and reduce NB or force use of */
  855. /* unblocked code. */
  856. /* Computing MAX */
  857. i__1 = 2, i__2 = ilaenv_(&c__2, "ZGGHD3", " ", n, ilo, ihi, &
  858. c_n1, (ftnlen)6, (ftnlen)1);
  859. nbmin = f2cmax(i__1,i__2);
  860. if (*lwork >= *n * 6 * nbmin) {
  861. nb = *lwork / (*n * 6);
  862. } else {
  863. nb = 1;
  864. }
  865. }
  866. }
  867. }
  868. if (nb < nbmin || nb >= nh) {
  869. /* Use unblocked code below */
  870. jcol = *ilo;
  871. } else {
  872. /* Use blocked code */
  873. kacc22 = ilaenv_(&c__16, "ZGGHD3", " ", n, ilo, ihi, &c_n1, (ftnlen)6,
  874. (ftnlen)1);
  875. blk22 = kacc22 == 2;
  876. i__1 = *ihi - 2;
  877. i__2 = nb;
  878. for (jcol = *ilo; i__2 < 0 ? jcol >= i__1 : jcol <= i__1; jcol +=
  879. i__2) {
  880. /* Computing MIN */
  881. i__3 = nb, i__4 = *ihi - jcol - 1;
  882. nnb = f2cmin(i__3,i__4);
  883. /* Initialize small unitary factors that will hold the */
  884. /* accumulated Givens rotations in workspace. */
  885. /* N2NB denotes the number of 2*NNB-by-2*NNB factors */
  886. /* NBLST denotes the (possibly smaller) order of the last */
  887. /* factor. */
  888. n2nb = (*ihi - jcol - 1) / nnb - 1;
  889. nblst = *ihi - jcol - n2nb * nnb;
  890. zlaset_("All", &nblst, &nblst, &c_b2, &c_b1, &work[1], &nblst);
  891. pw = nblst * nblst + 1;
  892. i__3 = n2nb;
  893. for (i__ = 1; i__ <= i__3; ++i__) {
  894. i__4 = nnb << 1;
  895. i__5 = nnb << 1;
  896. i__6 = nnb << 1;
  897. zlaset_("All", &i__4, &i__5, &c_b2, &c_b1, &work[pw], &i__6);
  898. pw += (nnb << 2) * nnb;
  899. }
  900. /* Reduce columns JCOL:JCOL+NNB-1 of A to Hessenberg form. */
  901. i__3 = jcol + nnb - 1;
  902. for (j = jcol; j <= i__3; ++j) {
  903. /* Reduce Jth column of A. Store cosines and sines in Jth */
  904. /* column of A and B, respectively. */
  905. i__4 = j + 2;
  906. for (i__ = *ihi; i__ >= i__4; --i__) {
  907. i__5 = i__ - 1 + j * a_dim1;
  908. temp.r = a[i__5].r, temp.i = a[i__5].i;
  909. zlartg_(&temp, &a[i__ + j * a_dim1], &c__, &s, &a[i__ - 1
  910. + j * a_dim1]);
  911. i__5 = i__ + j * a_dim1;
  912. z__1.r = c__, z__1.i = 0.;
  913. a[i__5].r = z__1.r, a[i__5].i = z__1.i;
  914. i__5 = i__ + j * b_dim1;
  915. b[i__5].r = s.r, b[i__5].i = s.i;
  916. }
  917. /* Accumulate Givens rotations into workspace array. */
  918. ppw = (nblst + 1) * (nblst - 2) - j + jcol + 1;
  919. len = j + 2 - jcol;
  920. jrow = j + n2nb * nnb + 2;
  921. i__4 = jrow;
  922. for (i__ = *ihi; i__ >= i__4; --i__) {
  923. i__5 = i__ + j * a_dim1;
  924. ctemp.r = a[i__5].r, ctemp.i = a[i__5].i;
  925. i__5 = i__ + j * b_dim1;
  926. s.r = b[i__5].r, s.i = b[i__5].i;
  927. i__5 = ppw + len - 1;
  928. for (jj = ppw; jj <= i__5; ++jj) {
  929. i__6 = jj + nblst;
  930. temp.r = work[i__6].r, temp.i = work[i__6].i;
  931. i__6 = jj + nblst;
  932. z__2.r = ctemp.r * temp.r - ctemp.i * temp.i, z__2.i =
  933. ctemp.r * temp.i + ctemp.i * temp.r;
  934. i__7 = jj;
  935. z__3.r = s.r * work[i__7].r - s.i * work[i__7].i,
  936. z__3.i = s.r * work[i__7].i + s.i * work[i__7]
  937. .r;
  938. z__1.r = z__2.r - z__3.r, z__1.i = z__2.i - z__3.i;
  939. work[i__6].r = z__1.r, work[i__6].i = z__1.i;
  940. i__6 = jj;
  941. d_cnjg(&z__3, &s);
  942. z__2.r = z__3.r * temp.r - z__3.i * temp.i, z__2.i =
  943. z__3.r * temp.i + z__3.i * temp.r;
  944. i__7 = jj;
  945. z__4.r = ctemp.r * work[i__7].r - ctemp.i * work[i__7]
  946. .i, z__4.i = ctemp.r * work[i__7].i + ctemp.i
  947. * work[i__7].r;
  948. z__1.r = z__2.r + z__4.r, z__1.i = z__2.i + z__4.i;
  949. work[i__6].r = z__1.r, work[i__6].i = z__1.i;
  950. }
  951. ++len;
  952. ppw = ppw - nblst - 1;
  953. }
  954. ppwo = nblst * nblst + (nnb + j - jcol - 1 << 1) * nnb + nnb;
  955. j0 = jrow - nnb;
  956. i__4 = j + 2;
  957. i__5 = -nnb;
  958. for (jrow = j0; i__5 < 0 ? jrow >= i__4 : jrow <= i__4; jrow
  959. += i__5) {
  960. ppw = ppwo;
  961. len = j + 2 - jcol;
  962. i__6 = jrow;
  963. for (i__ = jrow + nnb - 1; i__ >= i__6; --i__) {
  964. i__7 = i__ + j * a_dim1;
  965. ctemp.r = a[i__7].r, ctemp.i = a[i__7].i;
  966. i__7 = i__ + j * b_dim1;
  967. s.r = b[i__7].r, s.i = b[i__7].i;
  968. i__7 = ppw + len - 1;
  969. for (jj = ppw; jj <= i__7; ++jj) {
  970. i__8 = jj + (nnb << 1);
  971. temp.r = work[i__8].r, temp.i = work[i__8].i;
  972. i__8 = jj + (nnb << 1);
  973. z__2.r = ctemp.r * temp.r - ctemp.i * temp.i,
  974. z__2.i = ctemp.r * temp.i + ctemp.i *
  975. temp.r;
  976. i__9 = jj;
  977. z__3.r = s.r * work[i__9].r - s.i * work[i__9].i,
  978. z__3.i = s.r * work[i__9].i + s.i * work[
  979. i__9].r;
  980. z__1.r = z__2.r - z__3.r, z__1.i = z__2.i -
  981. z__3.i;
  982. work[i__8].r = z__1.r, work[i__8].i = z__1.i;
  983. i__8 = jj;
  984. d_cnjg(&z__3, &s);
  985. z__2.r = z__3.r * temp.r - z__3.i * temp.i,
  986. z__2.i = z__3.r * temp.i + z__3.i *
  987. temp.r;
  988. i__9 = jj;
  989. z__4.r = ctemp.r * work[i__9].r - ctemp.i * work[
  990. i__9].i, z__4.i = ctemp.r * work[i__9].i
  991. + ctemp.i * work[i__9].r;
  992. z__1.r = z__2.r + z__4.r, z__1.i = z__2.i +
  993. z__4.i;
  994. work[i__8].r = z__1.r, work[i__8].i = z__1.i;
  995. }
  996. ++len;
  997. ppw = ppw - (nnb << 1) - 1;
  998. }
  999. ppwo += (nnb << 2) * nnb;
  1000. }
  1001. /* TOP denotes the number of top rows in A and B that will */
  1002. /* not be updated during the next steps. */
  1003. if (jcol <= 2) {
  1004. top = 0;
  1005. } else {
  1006. top = jcol;
  1007. }
  1008. /* Propagate transformations through B and replace stored */
  1009. /* left sines/cosines by right sines/cosines. */
  1010. i__5 = j + 1;
  1011. for (jj = *n; jj >= i__5; --jj) {
  1012. /* Update JJth column of B. */
  1013. /* Computing MIN */
  1014. i__4 = jj + 1;
  1015. i__6 = j + 2;
  1016. for (i__ = f2cmin(i__4,*ihi); i__ >= i__6; --i__) {
  1017. i__4 = i__ + j * a_dim1;
  1018. ctemp.r = a[i__4].r, ctemp.i = a[i__4].i;
  1019. i__4 = i__ + j * b_dim1;
  1020. s.r = b[i__4].r, s.i = b[i__4].i;
  1021. i__4 = i__ + jj * b_dim1;
  1022. temp.r = b[i__4].r, temp.i = b[i__4].i;
  1023. i__4 = i__ + jj * b_dim1;
  1024. z__2.r = ctemp.r * temp.r - ctemp.i * temp.i, z__2.i =
  1025. ctemp.r * temp.i + ctemp.i * temp.r;
  1026. d_cnjg(&z__4, &s);
  1027. i__7 = i__ - 1 + jj * b_dim1;
  1028. z__3.r = z__4.r * b[i__7].r - z__4.i * b[i__7].i,
  1029. z__3.i = z__4.r * b[i__7].i + z__4.i * b[i__7]
  1030. .r;
  1031. z__1.r = z__2.r - z__3.r, z__1.i = z__2.i - z__3.i;
  1032. b[i__4].r = z__1.r, b[i__4].i = z__1.i;
  1033. i__4 = i__ - 1 + jj * b_dim1;
  1034. z__2.r = s.r * temp.r - s.i * temp.i, z__2.i = s.r *
  1035. temp.i + s.i * temp.r;
  1036. i__7 = i__ - 1 + jj * b_dim1;
  1037. z__3.r = ctemp.r * b[i__7].r - ctemp.i * b[i__7].i,
  1038. z__3.i = ctemp.r * b[i__7].i + ctemp.i * b[
  1039. i__7].r;
  1040. z__1.r = z__2.r + z__3.r, z__1.i = z__2.i + z__3.i;
  1041. b[i__4].r = z__1.r, b[i__4].i = z__1.i;
  1042. }
  1043. /* Annihilate B( JJ+1, JJ ). */
  1044. if (jj < *ihi) {
  1045. i__6 = jj + 1 + (jj + 1) * b_dim1;
  1046. temp.r = b[i__6].r, temp.i = b[i__6].i;
  1047. zlartg_(&temp, &b[jj + 1 + jj * b_dim1], &c__, &s, &b[
  1048. jj + 1 + (jj + 1) * b_dim1]);
  1049. i__6 = jj + 1 + jj * b_dim1;
  1050. b[i__6].r = 0., b[i__6].i = 0.;
  1051. i__6 = jj - top;
  1052. zrot_(&i__6, &b[top + 1 + (jj + 1) * b_dim1], &c__1, &
  1053. b[top + 1 + jj * b_dim1], &c__1, &c__, &s);
  1054. i__6 = jj + 1 + j * a_dim1;
  1055. z__1.r = c__, z__1.i = 0.;
  1056. a[i__6].r = z__1.r, a[i__6].i = z__1.i;
  1057. i__6 = jj + 1 + j * b_dim1;
  1058. d_cnjg(&z__2, &s);
  1059. z__1.r = -z__2.r, z__1.i = -z__2.i;
  1060. b[i__6].r = z__1.r, b[i__6].i = z__1.i;
  1061. }
  1062. }
  1063. /* Update A by transformations from right. */
  1064. jj = (*ihi - j - 1) % 3;
  1065. i__5 = jj + 1;
  1066. for (i__ = *ihi - j - 3; i__ >= i__5; i__ += -3) {
  1067. i__6 = j + 1 + i__ + j * a_dim1;
  1068. ctemp.r = a[i__6].r, ctemp.i = a[i__6].i;
  1069. i__6 = j + 1 + i__ + j * b_dim1;
  1070. z__1.r = -b[i__6].r, z__1.i = -b[i__6].i;
  1071. s.r = z__1.r, s.i = z__1.i;
  1072. i__6 = j + 2 + i__ + j * a_dim1;
  1073. c1.r = a[i__6].r, c1.i = a[i__6].i;
  1074. i__6 = j + 2 + i__ + j * b_dim1;
  1075. z__1.r = -b[i__6].r, z__1.i = -b[i__6].i;
  1076. s1.r = z__1.r, s1.i = z__1.i;
  1077. i__6 = j + 3 + i__ + j * a_dim1;
  1078. c2.r = a[i__6].r, c2.i = a[i__6].i;
  1079. i__6 = j + 3 + i__ + j * b_dim1;
  1080. z__1.r = -b[i__6].r, z__1.i = -b[i__6].i;
  1081. s2.r = z__1.r, s2.i = z__1.i;
  1082. i__6 = *ihi;
  1083. for (k = top + 1; k <= i__6; ++k) {
  1084. i__4 = k + (j + i__) * a_dim1;
  1085. temp.r = a[i__4].r, temp.i = a[i__4].i;
  1086. i__4 = k + (j + i__ + 1) * a_dim1;
  1087. temp1.r = a[i__4].r, temp1.i = a[i__4].i;
  1088. i__4 = k + (j + i__ + 2) * a_dim1;
  1089. temp2.r = a[i__4].r, temp2.i = a[i__4].i;
  1090. i__4 = k + (j + i__ + 3) * a_dim1;
  1091. temp3.r = a[i__4].r, temp3.i = a[i__4].i;
  1092. i__4 = k + (j + i__ + 3) * a_dim1;
  1093. z__2.r = c2.r * temp3.r - c2.i * temp3.i, z__2.i =
  1094. c2.r * temp3.i + c2.i * temp3.r;
  1095. d_cnjg(&z__4, &s2);
  1096. z__3.r = z__4.r * temp2.r - z__4.i * temp2.i, z__3.i =
  1097. z__4.r * temp2.i + z__4.i * temp2.r;
  1098. z__1.r = z__2.r + z__3.r, z__1.i = z__2.i + z__3.i;
  1099. a[i__4].r = z__1.r, a[i__4].i = z__1.i;
  1100. z__3.r = -s2.r, z__3.i = -s2.i;
  1101. z__2.r = z__3.r * temp3.r - z__3.i * temp3.i, z__2.i =
  1102. z__3.r * temp3.i + z__3.i * temp3.r;
  1103. z__4.r = c2.r * temp2.r - c2.i * temp2.i, z__4.i =
  1104. c2.r * temp2.i + c2.i * temp2.r;
  1105. z__1.r = z__2.r + z__4.r, z__1.i = z__2.i + z__4.i;
  1106. temp2.r = z__1.r, temp2.i = z__1.i;
  1107. i__4 = k + (j + i__ + 2) * a_dim1;
  1108. z__2.r = c1.r * temp2.r - c1.i * temp2.i, z__2.i =
  1109. c1.r * temp2.i + c1.i * temp2.r;
  1110. d_cnjg(&z__4, &s1);
  1111. z__3.r = z__4.r * temp1.r - z__4.i * temp1.i, z__3.i =
  1112. z__4.r * temp1.i + z__4.i * temp1.r;
  1113. z__1.r = z__2.r + z__3.r, z__1.i = z__2.i + z__3.i;
  1114. a[i__4].r = z__1.r, a[i__4].i = z__1.i;
  1115. z__3.r = -s1.r, z__3.i = -s1.i;
  1116. z__2.r = z__3.r * temp2.r - z__3.i * temp2.i, z__2.i =
  1117. z__3.r * temp2.i + z__3.i * temp2.r;
  1118. z__4.r = c1.r * temp1.r - c1.i * temp1.i, z__4.i =
  1119. c1.r * temp1.i + c1.i * temp1.r;
  1120. z__1.r = z__2.r + z__4.r, z__1.i = z__2.i + z__4.i;
  1121. temp1.r = z__1.r, temp1.i = z__1.i;
  1122. i__4 = k + (j + i__ + 1) * a_dim1;
  1123. z__2.r = ctemp.r * temp1.r - ctemp.i * temp1.i,
  1124. z__2.i = ctemp.r * temp1.i + ctemp.i *
  1125. temp1.r;
  1126. d_cnjg(&z__4, &s);
  1127. z__3.r = z__4.r * temp.r - z__4.i * temp.i, z__3.i =
  1128. z__4.r * temp.i + z__4.i * temp.r;
  1129. z__1.r = z__2.r + z__3.r, z__1.i = z__2.i + z__3.i;
  1130. a[i__4].r = z__1.r, a[i__4].i = z__1.i;
  1131. i__4 = k + (j + i__) * a_dim1;
  1132. z__3.r = -s.r, z__3.i = -s.i;
  1133. z__2.r = z__3.r * temp1.r - z__3.i * temp1.i, z__2.i =
  1134. z__3.r * temp1.i + z__3.i * temp1.r;
  1135. z__4.r = ctemp.r * temp.r - ctemp.i * temp.i, z__4.i =
  1136. ctemp.r * temp.i + ctemp.i * temp.r;
  1137. z__1.r = z__2.r + z__4.r, z__1.i = z__2.i + z__4.i;
  1138. a[i__4].r = z__1.r, a[i__4].i = z__1.i;
  1139. }
  1140. }
  1141. if (jj > 0) {
  1142. for (i__ = jj; i__ >= 1; --i__) {
  1143. i__5 = j + 1 + i__ + j * a_dim1;
  1144. c__ = a[i__5].r;
  1145. i__5 = *ihi - top;
  1146. d_cnjg(&z__2, &b[j + 1 + i__ + j * b_dim1]);
  1147. z__1.r = -z__2.r, z__1.i = -z__2.i;
  1148. zrot_(&i__5, &a[top + 1 + (j + i__ + 1) * a_dim1], &
  1149. c__1, &a[top + 1 + (j + i__) * a_dim1], &c__1,
  1150. &c__, &z__1);
  1151. }
  1152. }
  1153. /* Update (J+1)th column of A by transformations from left. */
  1154. if (j < jcol + nnb - 1) {
  1155. len = j + 1 - jcol;
  1156. /* Multiply with the trailing accumulated unitary */
  1157. /* matrix, which takes the form */
  1158. /* [ U11 U12 ] */
  1159. /* U = [ ], */
  1160. /* [ U21 U22 ] */
  1161. /* where U21 is a LEN-by-LEN matrix and U12 is lower */
  1162. /* triangular. */
  1163. jrow = *ihi - nblst + 1;
  1164. zgemv_("Conjugate", &nblst, &len, &c_b1, &work[1], &nblst,
  1165. &a[jrow + (j + 1) * a_dim1], &c__1, &c_b2, &work[
  1166. pw], &c__1);
  1167. ppw = pw + len;
  1168. i__5 = jrow + nblst - len - 1;
  1169. for (i__ = jrow; i__ <= i__5; ++i__) {
  1170. i__6 = ppw;
  1171. i__4 = i__ + (j + 1) * a_dim1;
  1172. work[i__6].r = a[i__4].r, work[i__6].i = a[i__4].i;
  1173. ++ppw;
  1174. }
  1175. i__5 = nblst - len;
  1176. ztrmv_("Lower", "Conjugate", "Non-unit", &i__5, &work[len
  1177. * nblst + 1], &nblst, &work[pw + len], &c__1);
  1178. i__5 = nblst - len;
  1179. zgemv_("Conjugate", &len, &i__5, &c_b1, &work[(len + 1) *
  1180. nblst - len + 1], &nblst, &a[jrow + nblst - len +
  1181. (j + 1) * a_dim1], &c__1, &c_b1, &work[pw + len],
  1182. &c__1);
  1183. ppw = pw;
  1184. i__5 = jrow + nblst - 1;
  1185. for (i__ = jrow; i__ <= i__5; ++i__) {
  1186. i__6 = i__ + (j + 1) * a_dim1;
  1187. i__4 = ppw;
  1188. a[i__6].r = work[i__4].r, a[i__6].i = work[i__4].i;
  1189. ++ppw;
  1190. }
  1191. /* Multiply with the other accumulated unitary */
  1192. /* matrices, which take the form */
  1193. /* [ U11 U12 0 ] */
  1194. /* [ ] */
  1195. /* U = [ U21 U22 0 ], */
  1196. /* [ ] */
  1197. /* [ 0 0 I ] */
  1198. /* where I denotes the (NNB-LEN)-by-(NNB-LEN) identity */
  1199. /* matrix, U21 is a LEN-by-LEN upper triangular matrix */
  1200. /* and U12 is an NNB-by-NNB lower triangular matrix. */
  1201. ppwo = nblst * nblst + 1;
  1202. j0 = jrow - nnb;
  1203. i__5 = jcol + 1;
  1204. i__6 = -nnb;
  1205. for (jrow = j0; i__6 < 0 ? jrow >= i__5 : jrow <= i__5;
  1206. jrow += i__6) {
  1207. ppw = pw + len;
  1208. i__4 = jrow + nnb - 1;
  1209. for (i__ = jrow; i__ <= i__4; ++i__) {
  1210. i__7 = ppw;
  1211. i__8 = i__ + (j + 1) * a_dim1;
  1212. work[i__7].r = a[i__8].r, work[i__7].i = a[i__8]
  1213. .i;
  1214. ++ppw;
  1215. }
  1216. ppw = pw;
  1217. i__4 = jrow + nnb + len - 1;
  1218. for (i__ = jrow + nnb; i__ <= i__4; ++i__) {
  1219. i__7 = ppw;
  1220. i__8 = i__ + (j + 1) * a_dim1;
  1221. work[i__7].r = a[i__8].r, work[i__7].i = a[i__8]
  1222. .i;
  1223. ++ppw;
  1224. }
  1225. i__4 = nnb << 1;
  1226. ztrmv_("Upper", "Conjugate", "Non-unit", &len, &work[
  1227. ppwo + nnb], &i__4, &work[pw], &c__1);
  1228. i__4 = nnb << 1;
  1229. ztrmv_("Lower", "Conjugate", "Non-unit", &nnb, &work[
  1230. ppwo + (len << 1) * nnb], &i__4, &work[pw +
  1231. len], &c__1);
  1232. i__4 = nnb << 1;
  1233. zgemv_("Conjugate", &nnb, &len, &c_b1, &work[ppwo], &
  1234. i__4, &a[jrow + (j + 1) * a_dim1], &c__1, &
  1235. c_b1, &work[pw], &c__1);
  1236. i__4 = nnb << 1;
  1237. zgemv_("Conjugate", &len, &nnb, &c_b1, &work[ppwo + (
  1238. len << 1) * nnb + nnb], &i__4, &a[jrow + nnb
  1239. + (j + 1) * a_dim1], &c__1, &c_b1, &work[pw +
  1240. len], &c__1);
  1241. ppw = pw;
  1242. i__4 = jrow + len + nnb - 1;
  1243. for (i__ = jrow; i__ <= i__4; ++i__) {
  1244. i__7 = i__ + (j + 1) * a_dim1;
  1245. i__8 = ppw;
  1246. a[i__7].r = work[i__8].r, a[i__7].i = work[i__8]
  1247. .i;
  1248. ++ppw;
  1249. }
  1250. ppwo += (nnb << 2) * nnb;
  1251. }
  1252. }
  1253. }
  1254. /* Apply accumulated unitary matrices to A. */
  1255. cola = *n - jcol - nnb + 1;
  1256. j = *ihi - nblst + 1;
  1257. zgemm_("Conjugate", "No Transpose", &nblst, &cola, &nblst, &c_b1,
  1258. &work[1], &nblst, &a[j + (jcol + nnb) * a_dim1], lda, &
  1259. c_b2, &work[pw], &nblst);
  1260. zlacpy_("All", &nblst, &cola, &work[pw], &nblst, &a[j + (jcol +
  1261. nnb) * a_dim1], lda);
  1262. ppwo = nblst * nblst + 1;
  1263. j0 = j - nnb;
  1264. i__3 = jcol + 1;
  1265. i__6 = -nnb;
  1266. for (j = j0; i__6 < 0 ? j >= i__3 : j <= i__3; j += i__6) {
  1267. if (blk22) {
  1268. /* Exploit the structure of */
  1269. /* [ U11 U12 ] */
  1270. /* U = [ ] */
  1271. /* [ U21 U22 ], */
  1272. /* where all blocks are NNB-by-NNB, U21 is upper */
  1273. /* triangular and U12 is lower triangular. */
  1274. i__5 = nnb << 1;
  1275. i__4 = nnb << 1;
  1276. i__7 = *lwork - pw + 1;
  1277. zunm22_("Left", "Conjugate", &i__5, &cola, &nnb, &nnb, &
  1278. work[ppwo], &i__4, &a[j + (jcol + nnb) * a_dim1],
  1279. lda, &work[pw], &i__7, &ierr);
  1280. } else {
  1281. /* Ignore the structure of U. */
  1282. i__5 = nnb << 1;
  1283. i__4 = nnb << 1;
  1284. i__7 = nnb << 1;
  1285. i__8 = nnb << 1;
  1286. zgemm_("Conjugate", "No Transpose", &i__5, &cola, &i__4, &
  1287. c_b1, &work[ppwo], &i__7, &a[j + (jcol + nnb) *
  1288. a_dim1], lda, &c_b2, &work[pw], &i__8);
  1289. i__5 = nnb << 1;
  1290. i__4 = nnb << 1;
  1291. zlacpy_("All", &i__5, &cola, &work[pw], &i__4, &a[j + (
  1292. jcol + nnb) * a_dim1], lda);
  1293. }
  1294. ppwo += (nnb << 2) * nnb;
  1295. }
  1296. /* Apply accumulated unitary matrices to Q. */
  1297. if (wantq) {
  1298. j = *ihi - nblst + 1;
  1299. if (initq) {
  1300. /* Computing MAX */
  1301. i__6 = 2, i__3 = j - jcol + 1;
  1302. topq = f2cmax(i__6,i__3);
  1303. nh = *ihi - topq + 1;
  1304. } else {
  1305. topq = 1;
  1306. nh = *n;
  1307. }
  1308. zgemm_("No Transpose", "No Transpose", &nh, &nblst, &nblst, &
  1309. c_b1, &q[topq + j * q_dim1], ldq, &work[1], &nblst, &
  1310. c_b2, &work[pw], &nh);
  1311. zlacpy_("All", &nh, &nblst, &work[pw], &nh, &q[topq + j *
  1312. q_dim1], ldq);
  1313. ppwo = nblst * nblst + 1;
  1314. j0 = j - nnb;
  1315. i__6 = jcol + 1;
  1316. i__3 = -nnb;
  1317. for (j = j0; i__3 < 0 ? j >= i__6 : j <= i__6; j += i__3) {
  1318. if (initq) {
  1319. /* Computing MAX */
  1320. i__5 = 2, i__4 = j - jcol + 1;
  1321. topq = f2cmax(i__5,i__4);
  1322. nh = *ihi - topq + 1;
  1323. }
  1324. if (blk22) {
  1325. /* Exploit the structure of U. */
  1326. i__5 = nnb << 1;
  1327. i__4 = nnb << 1;
  1328. i__7 = *lwork - pw + 1;
  1329. zunm22_("Right", "No Transpose", &nh, &i__5, &nnb, &
  1330. nnb, &work[ppwo], &i__4, &q[topq + j * q_dim1]
  1331. , ldq, &work[pw], &i__7, &ierr);
  1332. } else {
  1333. /* Ignore the structure of U. */
  1334. i__5 = nnb << 1;
  1335. i__4 = nnb << 1;
  1336. i__7 = nnb << 1;
  1337. zgemm_("No Transpose", "No Transpose", &nh, &i__5, &
  1338. i__4, &c_b1, &q[topq + j * q_dim1], ldq, &
  1339. work[ppwo], &i__7, &c_b2, &work[pw], &nh);
  1340. i__5 = nnb << 1;
  1341. zlacpy_("All", &nh, &i__5, &work[pw], &nh, &q[topq +
  1342. j * q_dim1], ldq);
  1343. }
  1344. ppwo += (nnb << 2) * nnb;
  1345. }
  1346. }
  1347. /* Accumulate right Givens rotations if required. */
  1348. if (wantz || top > 0) {
  1349. /* Initialize small unitary factors that will hold the */
  1350. /* accumulated Givens rotations in workspace. */
  1351. zlaset_("All", &nblst, &nblst, &c_b2, &c_b1, &work[1], &nblst);
  1352. pw = nblst * nblst + 1;
  1353. i__3 = n2nb;
  1354. for (i__ = 1; i__ <= i__3; ++i__) {
  1355. i__6 = nnb << 1;
  1356. i__5 = nnb << 1;
  1357. i__4 = nnb << 1;
  1358. zlaset_("All", &i__6, &i__5, &c_b2, &c_b1, &work[pw], &
  1359. i__4);
  1360. pw += (nnb << 2) * nnb;
  1361. }
  1362. /* Accumulate Givens rotations into workspace array. */
  1363. i__3 = jcol + nnb - 1;
  1364. for (j = jcol; j <= i__3; ++j) {
  1365. ppw = (nblst + 1) * (nblst - 2) - j + jcol + 1;
  1366. len = j + 2 - jcol;
  1367. jrow = j + n2nb * nnb + 2;
  1368. i__6 = jrow;
  1369. for (i__ = *ihi; i__ >= i__6; --i__) {
  1370. i__5 = i__ + j * a_dim1;
  1371. ctemp.r = a[i__5].r, ctemp.i = a[i__5].i;
  1372. i__5 = i__ + j * a_dim1;
  1373. a[i__5].r = 0., a[i__5].i = 0.;
  1374. i__5 = i__ + j * b_dim1;
  1375. s.r = b[i__5].r, s.i = b[i__5].i;
  1376. i__5 = i__ + j * b_dim1;
  1377. b[i__5].r = 0., b[i__5].i = 0.;
  1378. i__5 = ppw + len - 1;
  1379. for (jj = ppw; jj <= i__5; ++jj) {
  1380. i__4 = jj + nblst;
  1381. temp.r = work[i__4].r, temp.i = work[i__4].i;
  1382. i__4 = jj + nblst;
  1383. z__2.r = ctemp.r * temp.r - ctemp.i * temp.i,
  1384. z__2.i = ctemp.r * temp.i + ctemp.i *
  1385. temp.r;
  1386. d_cnjg(&z__4, &s);
  1387. i__7 = jj;
  1388. z__3.r = z__4.r * work[i__7].r - z__4.i * work[
  1389. i__7].i, z__3.i = z__4.r * work[i__7].i +
  1390. z__4.i * work[i__7].r;
  1391. z__1.r = z__2.r - z__3.r, z__1.i = z__2.i -
  1392. z__3.i;
  1393. work[i__4].r = z__1.r, work[i__4].i = z__1.i;
  1394. i__4 = jj;
  1395. z__2.r = s.r * temp.r - s.i * temp.i, z__2.i =
  1396. s.r * temp.i + s.i * temp.r;
  1397. i__7 = jj;
  1398. z__3.r = ctemp.r * work[i__7].r - ctemp.i * work[
  1399. i__7].i, z__3.i = ctemp.r * work[i__7].i
  1400. + ctemp.i * work[i__7].r;
  1401. z__1.r = z__2.r + z__3.r, z__1.i = z__2.i +
  1402. z__3.i;
  1403. work[i__4].r = z__1.r, work[i__4].i = z__1.i;
  1404. }
  1405. ++len;
  1406. ppw = ppw - nblst - 1;
  1407. }
  1408. ppwo = nblst * nblst + (nnb + j - jcol - 1 << 1) * nnb +
  1409. nnb;
  1410. j0 = jrow - nnb;
  1411. i__6 = j + 2;
  1412. i__5 = -nnb;
  1413. for (jrow = j0; i__5 < 0 ? jrow >= i__6 : jrow <= i__6;
  1414. jrow += i__5) {
  1415. ppw = ppwo;
  1416. len = j + 2 - jcol;
  1417. i__4 = jrow;
  1418. for (i__ = jrow + nnb - 1; i__ >= i__4; --i__) {
  1419. i__7 = i__ + j * a_dim1;
  1420. ctemp.r = a[i__7].r, ctemp.i = a[i__7].i;
  1421. i__7 = i__ + j * a_dim1;
  1422. a[i__7].r = 0., a[i__7].i = 0.;
  1423. i__7 = i__ + j * b_dim1;
  1424. s.r = b[i__7].r, s.i = b[i__7].i;
  1425. i__7 = i__ + j * b_dim1;
  1426. b[i__7].r = 0., b[i__7].i = 0.;
  1427. i__7 = ppw + len - 1;
  1428. for (jj = ppw; jj <= i__7; ++jj) {
  1429. i__8 = jj + (nnb << 1);
  1430. temp.r = work[i__8].r, temp.i = work[i__8].i;
  1431. i__8 = jj + (nnb << 1);
  1432. z__2.r = ctemp.r * temp.r - ctemp.i * temp.i,
  1433. z__2.i = ctemp.r * temp.i + ctemp.i *
  1434. temp.r;
  1435. d_cnjg(&z__4, &s);
  1436. i__9 = jj;
  1437. z__3.r = z__4.r * work[i__9].r - z__4.i *
  1438. work[i__9].i, z__3.i = z__4.r * work[
  1439. i__9].i + z__4.i * work[i__9].r;
  1440. z__1.r = z__2.r - z__3.r, z__1.i = z__2.i -
  1441. z__3.i;
  1442. work[i__8].r = z__1.r, work[i__8].i = z__1.i;
  1443. i__8 = jj;
  1444. z__2.r = s.r * temp.r - s.i * temp.i, z__2.i =
  1445. s.r * temp.i + s.i * temp.r;
  1446. i__9 = jj;
  1447. z__3.r = ctemp.r * work[i__9].r - ctemp.i *
  1448. work[i__9].i, z__3.i = ctemp.r * work[
  1449. i__9].i + ctemp.i * work[i__9].r;
  1450. z__1.r = z__2.r + z__3.r, z__1.i = z__2.i +
  1451. z__3.i;
  1452. work[i__8].r = z__1.r, work[i__8].i = z__1.i;
  1453. }
  1454. ++len;
  1455. ppw = ppw - (nnb << 1) - 1;
  1456. }
  1457. ppwo += (nnb << 2) * nnb;
  1458. }
  1459. }
  1460. } else {
  1461. i__3 = *ihi - jcol - 1;
  1462. zlaset_("Lower", &i__3, &nnb, &c_b2, &c_b2, &a[jcol + 2 +
  1463. jcol * a_dim1], lda);
  1464. i__3 = *ihi - jcol - 1;
  1465. zlaset_("Lower", &i__3, &nnb, &c_b2, &c_b2, &b[jcol + 2 +
  1466. jcol * b_dim1], ldb);
  1467. }
  1468. /* Apply accumulated unitary matrices to A and B. */
  1469. if (top > 0) {
  1470. j = *ihi - nblst + 1;
  1471. zgemm_("No Transpose", "No Transpose", &top, &nblst, &nblst, &
  1472. c_b1, &a[j * a_dim1 + 1], lda, &work[1], &nblst, &
  1473. c_b2, &work[pw], &top);
  1474. zlacpy_("All", &top, &nblst, &work[pw], &top, &a[j * a_dim1 +
  1475. 1], lda);
  1476. ppwo = nblst * nblst + 1;
  1477. j0 = j - nnb;
  1478. i__3 = jcol + 1;
  1479. i__5 = -nnb;
  1480. for (j = j0; i__5 < 0 ? j >= i__3 : j <= i__3; j += i__5) {
  1481. if (blk22) {
  1482. /* Exploit the structure of U. */
  1483. i__6 = nnb << 1;
  1484. i__4 = nnb << 1;
  1485. i__7 = *lwork - pw + 1;
  1486. zunm22_("Right", "No Transpose", &top, &i__6, &nnb, &
  1487. nnb, &work[ppwo], &i__4, &a[j * a_dim1 + 1],
  1488. lda, &work[pw], &i__7, &ierr);
  1489. } else {
  1490. /* Ignore the structure of U. */
  1491. i__6 = nnb << 1;
  1492. i__4 = nnb << 1;
  1493. i__7 = nnb << 1;
  1494. zgemm_("No Transpose", "No Transpose", &top, &i__6, &
  1495. i__4, &c_b1, &a[j * a_dim1 + 1], lda, &work[
  1496. ppwo], &i__7, &c_b2, &work[pw], &top);
  1497. i__6 = nnb << 1;
  1498. zlacpy_("All", &top, &i__6, &work[pw], &top, &a[j *
  1499. a_dim1 + 1], lda);
  1500. }
  1501. ppwo += (nnb << 2) * nnb;
  1502. }
  1503. j = *ihi - nblst + 1;
  1504. zgemm_("No Transpose", "No Transpose", &top, &nblst, &nblst, &
  1505. c_b1, &b[j * b_dim1 + 1], ldb, &work[1], &nblst, &
  1506. c_b2, &work[pw], &top);
  1507. zlacpy_("All", &top, &nblst, &work[pw], &top, &b[j * b_dim1 +
  1508. 1], ldb);
  1509. ppwo = nblst * nblst + 1;
  1510. j0 = j - nnb;
  1511. i__5 = jcol + 1;
  1512. i__3 = -nnb;
  1513. for (j = j0; i__3 < 0 ? j >= i__5 : j <= i__5; j += i__3) {
  1514. if (blk22) {
  1515. /* Exploit the structure of U. */
  1516. i__6 = nnb << 1;
  1517. i__4 = nnb << 1;
  1518. i__7 = *lwork - pw + 1;
  1519. zunm22_("Right", "No Transpose", &top, &i__6, &nnb, &
  1520. nnb, &work[ppwo], &i__4, &b[j * b_dim1 + 1],
  1521. ldb, &work[pw], &i__7, &ierr);
  1522. } else {
  1523. /* Ignore the structure of U. */
  1524. i__6 = nnb << 1;
  1525. i__4 = nnb << 1;
  1526. i__7 = nnb << 1;
  1527. zgemm_("No Transpose", "No Transpose", &top, &i__6, &
  1528. i__4, &c_b1, &b[j * b_dim1 + 1], ldb, &work[
  1529. ppwo], &i__7, &c_b2, &work[pw], &top);
  1530. i__6 = nnb << 1;
  1531. zlacpy_("All", &top, &i__6, &work[pw], &top, &b[j *
  1532. b_dim1 + 1], ldb);
  1533. }
  1534. ppwo += (nnb << 2) * nnb;
  1535. }
  1536. }
  1537. /* Apply accumulated unitary matrices to Z. */
  1538. if (wantz) {
  1539. j = *ihi - nblst + 1;
  1540. if (initq) {
  1541. /* Computing MAX */
  1542. i__3 = 2, i__5 = j - jcol + 1;
  1543. topq = f2cmax(i__3,i__5);
  1544. nh = *ihi - topq + 1;
  1545. } else {
  1546. topq = 1;
  1547. nh = *n;
  1548. }
  1549. zgemm_("No Transpose", "No Transpose", &nh, &nblst, &nblst, &
  1550. c_b1, &z__[topq + j * z_dim1], ldz, &work[1], &nblst,
  1551. &c_b2, &work[pw], &nh);
  1552. zlacpy_("All", &nh, &nblst, &work[pw], &nh, &z__[topq + j *
  1553. z_dim1], ldz);
  1554. ppwo = nblst * nblst + 1;
  1555. j0 = j - nnb;
  1556. i__3 = jcol + 1;
  1557. i__5 = -nnb;
  1558. for (j = j0; i__5 < 0 ? j >= i__3 : j <= i__3; j += i__5) {
  1559. if (initq) {
  1560. /* Computing MAX */
  1561. i__6 = 2, i__4 = j - jcol + 1;
  1562. topq = f2cmax(i__6,i__4);
  1563. nh = *ihi - topq + 1;
  1564. }
  1565. if (blk22) {
  1566. /* Exploit the structure of U. */
  1567. i__6 = nnb << 1;
  1568. i__4 = nnb << 1;
  1569. i__7 = *lwork - pw + 1;
  1570. zunm22_("Right", "No Transpose", &nh, &i__6, &nnb, &
  1571. nnb, &work[ppwo], &i__4, &z__[topq + j *
  1572. z_dim1], ldz, &work[pw], &i__7, &ierr);
  1573. } else {
  1574. /* Ignore the structure of U. */
  1575. i__6 = nnb << 1;
  1576. i__4 = nnb << 1;
  1577. i__7 = nnb << 1;
  1578. zgemm_("No Transpose", "No Transpose", &nh, &i__6, &
  1579. i__4, &c_b1, &z__[topq + j * z_dim1], ldz, &
  1580. work[ppwo], &i__7, &c_b2, &work[pw], &nh);
  1581. i__6 = nnb << 1;
  1582. zlacpy_("All", &nh, &i__6, &work[pw], &nh, &z__[topq
  1583. + j * z_dim1], ldz);
  1584. }
  1585. ppwo += (nnb << 2) * nnb;
  1586. }
  1587. }
  1588. }
  1589. }
  1590. /* Use unblocked code to reduce the rest of the matrix */
  1591. /* Avoid re-initialization of modified Q and Z. */
  1592. *(unsigned char *)compq2 = *(unsigned char *)compq;
  1593. *(unsigned char *)compz2 = *(unsigned char *)compz;
  1594. if (jcol != *ilo) {
  1595. if (wantq) {
  1596. *(unsigned char *)compq2 = 'V';
  1597. }
  1598. if (wantz) {
  1599. *(unsigned char *)compz2 = 'V';
  1600. }
  1601. }
  1602. if (jcol < *ihi) {
  1603. zgghrd_(compq2, compz2, n, &jcol, ihi, &a[a_offset], lda, &b[b_offset]
  1604. , ldb, &q[q_offset], ldq, &z__[z_offset], ldz, &ierr);
  1605. }
  1606. z__1.r = (doublereal) lwkopt, z__1.i = 0.;
  1607. work[1].r = z__1.r, work[1].i = z__1.i;
  1608. return;
  1609. /* End of ZGGHD3 */
  1610. } /* zgghd3_ */