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 int logical;
  52. typedef short int shortlogical;
  53. typedef char logical1;
  54. typedef char integer1;
  55. #define TRUE_ (1)
  56. #define FALSE_ (0)
  57. /* Extern is for use with -E */
  58. #ifndef Extern
  59. #define Extern extern
  60. #endif
  61. /* I/O stuff */
  62. typedef int flag;
  63. typedef int ftnlen;
  64. typedef int ftnint;
  65. /*external read, write*/
  66. typedef struct
  67. { flag cierr;
  68. ftnint ciunit;
  69. flag ciend;
  70. char *cifmt;
  71. ftnint cirec;
  72. } cilist;
  73. /*internal read, write*/
  74. typedef struct
  75. { flag icierr;
  76. char *iciunit;
  77. flag iciend;
  78. char *icifmt;
  79. ftnint icirlen;
  80. ftnint icirnum;
  81. } icilist;
  82. /*open*/
  83. typedef struct
  84. { flag oerr;
  85. ftnint ounit;
  86. char *ofnm;
  87. ftnlen ofnmlen;
  88. char *osta;
  89. char *oacc;
  90. char *ofm;
  91. ftnint orl;
  92. char *oblnk;
  93. } olist;
  94. /*close*/
  95. typedef struct
  96. { flag cerr;
  97. ftnint cunit;
  98. char *csta;
  99. } cllist;
  100. /*rewind, backspace, endfile*/
  101. typedef struct
  102. { flag aerr;
  103. ftnint aunit;
  104. } alist;
  105. /* inquire */
  106. typedef struct
  107. { flag inerr;
  108. ftnint inunit;
  109. char *infile;
  110. ftnlen infilen;
  111. ftnint *inex; /*parameters in standard's order*/
  112. ftnint *inopen;
  113. ftnint *innum;
  114. ftnint *innamed;
  115. char *inname;
  116. ftnlen innamlen;
  117. char *inacc;
  118. ftnlen inacclen;
  119. char *inseq;
  120. ftnlen inseqlen;
  121. char *indir;
  122. ftnlen indirlen;
  123. char *infmt;
  124. ftnlen infmtlen;
  125. char *inform;
  126. ftnint informlen;
  127. char *inunf;
  128. ftnlen inunflen;
  129. ftnint *inrecl;
  130. ftnint *innrec;
  131. char *inblank;
  132. ftnlen inblanklen;
  133. } inlist;
  134. #define VOID void
  135. union Multitype { /* for multiple entry points */
  136. integer1 g;
  137. shortint h;
  138. integer i;
  139. /* longint j; */
  140. real r;
  141. doublereal d;
  142. complex c;
  143. doublecomplex z;
  144. };
  145. typedef union Multitype Multitype;
  146. struct Vardesc { /* for Namelist */
  147. char *name;
  148. char *addr;
  149. ftnlen *dims;
  150. int type;
  151. };
  152. typedef struct Vardesc Vardesc;
  153. struct Namelist {
  154. char *name;
  155. Vardesc **vars;
  156. int nvars;
  157. };
  158. typedef struct Namelist Namelist;
  159. #define abs(x) ((x) >= 0 ? (x) : -(x))
  160. #define dabs(x) (fabs(x))
  161. #define f2cmin(a,b) ((a) <= (b) ? (a) : (b))
  162. #define f2cmax(a,b) ((a) >= (b) ? (a) : (b))
  163. #define dmin(a,b) (f2cmin(a,b))
  164. #define dmax(a,b) (f2cmax(a,b))
  165. #define bit_test(a,b) ((a) >> (b) & 1)
  166. #define bit_clear(a,b) ((a) & ~((uinteger)1 << (b)))
  167. #define bit_set(a,b) ((a) | ((uinteger)1 << (b)))
  168. #define abort_() { sig_die("Fortran abort routine called", 1); }
  169. #define c_abs(z) (cabsf(Cf(z)))
  170. #define c_cos(R,Z) { pCf(R)=ccos(Cf(Z)); }
  171. #ifdef _MSC_VER
  172. #define c_div(c, a, b) {Cf(c)._Val[0] = (Cf(a)._Val[0]/Cf(b)._Val[0]); Cf(c)._Val[1]=(Cf(a)._Val[1]/Cf(b)._Val[1]);}
  173. #define z_div(c, a, b) {Cd(c)._Val[0] = (Cd(a)._Val[0]/Cd(b)._Val[0]); Cd(c)._Val[1]=(Cd(a)._Val[1]/df(b)._Val[1]);}
  174. #else
  175. #define c_div(c, a, b) {pCf(c) = Cf(a)/Cf(b);}
  176. #define z_div(c, a, b) {pCd(c) = Cd(a)/Cd(b);}
  177. #endif
  178. #define c_exp(R, Z) {pCf(R) = cexpf(Cf(Z));}
  179. #define c_log(R, Z) {pCf(R) = clogf(Cf(Z));}
  180. #define c_sin(R, Z) {pCf(R) = csinf(Cf(Z));}
  181. //#define c_sqrt(R, Z) {*(R) = csqrtf(Cf(Z));}
  182. #define c_sqrt(R, Z) {pCf(R) = csqrtf(Cf(Z));}
  183. #define d_abs(x) (fabs(*(x)))
  184. #define d_acos(x) (acos(*(x)))
  185. #define d_asin(x) (asin(*(x)))
  186. #define d_atan(x) (atan(*(x)))
  187. #define d_atn2(x, y) (atan2(*(x),*(y)))
  188. #define d_cnjg(R, Z) { pCd(R) = conj(Cd(Z)); }
  189. #define r_cnjg(R, Z) { pCf(R) = conjf(Cf(Z)); }
  190. #define d_cos(x) (cos(*(x)))
  191. #define d_cosh(x) (cosh(*(x)))
  192. #define d_dim(__a, __b) ( *(__a) > *(__b) ? *(__a) - *(__b) : 0.0 )
  193. #define d_exp(x) (exp(*(x)))
  194. #define d_imag(z) (cimag(Cd(z)))
  195. #define r_imag(z) (cimagf(Cf(z)))
  196. #define d_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
  197. #define r_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
  198. #define d_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
  199. #define r_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
  200. #define d_log(x) (log(*(x)))
  201. #define d_mod(x, y) (fmod(*(x), *(y)))
  202. #define u_nint(__x) ((__x)>=0 ? floor((__x) + .5) : -floor(.5 - (__x)))
  203. #define d_nint(x) u_nint(*(x))
  204. #define u_sign(__a,__b) ((__b) >= 0 ? ((__a) >= 0 ? (__a) : -(__a)) : -((__a) >= 0 ? (__a) : -(__a)))
  205. #define d_sign(a,b) u_sign(*(a),*(b))
  206. #define r_sign(a,b) u_sign(*(a),*(b))
  207. #define d_sin(x) (sin(*(x)))
  208. #define d_sinh(x) (sinh(*(x)))
  209. #define d_sqrt(x) (sqrt(*(x)))
  210. #define d_tan(x) (tan(*(x)))
  211. #define d_tanh(x) (tanh(*(x)))
  212. #define i_abs(x) abs(*(x))
  213. #define i_dnnt(x) ((integer)u_nint(*(x)))
  214. #define i_len(s, n) (n)
  215. #define i_nint(x) ((integer)u_nint(*(x)))
  216. #define i_sign(a,b) ((integer)u_sign((integer)*(a),(integer)*(b)))
  217. #define pow_dd(ap, bp) ( pow(*(ap), *(bp)))
  218. #define pow_si(B,E) spow_ui(*(B),*(E))
  219. #define pow_ri(B,E) spow_ui(*(B),*(E))
  220. #define pow_di(B,E) dpow_ui(*(B),*(E))
  221. #define pow_zi(p, a, b) {pCd(p) = zpow_ui(Cd(a), *(b));}
  222. #define pow_ci(p, a, b) {pCf(p) = cpow_ui(Cf(a), *(b));}
  223. #define pow_zz(R,A,B) {pCd(R) = cpow(Cd(A),*(B));}
  224. #define s_cat(lpp, rpp, rnp, np, llp) { ftnlen i, nc, ll; char *f__rp, *lp; ll = (llp); lp = (lpp); for(i=0; i < (int)*(np); ++i) { nc = ll; if((rnp)[i] < nc) nc = (rnp)[i]; ll -= nc; f__rp = (rpp)[i]; while(--nc >= 0) *lp++ = *(f__rp)++; } while(--ll >= 0) *lp++ = ' '; }
  225. #define s_cmp(a,b,c,d) ((integer)strncmp((a),(b),f2cmin((c),(d))))
  226. #define s_copy(A,B,C,D) { int __i,__m; for (__i=0, __m=f2cmin((C),(D)); __i<__m && (B)[__i] != 0; ++__i) (A)[__i] = (B)[__i]; }
  227. #define sig_die(s, kill) { exit(1); }
  228. #define s_stop(s, n) {exit(0);}
  229. static char junk[] = "\n@(#)LIBF77 VERSION 19990503\n";
  230. #define z_abs(z) (cabs(Cd(z)))
  231. #define z_exp(R, Z) {pCd(R) = cexp(Cd(Z));}
  232. #define z_sqrt(R, Z) {pCd(R) = csqrt(Cd(Z));}
  233. #define myexit_() break;
  234. #define mycycle() continue;
  235. #define myceiling(w) {ceil(w)}
  236. #define myhuge(w) {HUGE_VAL}
  237. //#define mymaxloc_(w,s,e,n) {if (sizeof(*(w)) == sizeof(double)) dmaxloc_((w),*(s),*(e),n); else dmaxloc_((w),*(s),*(e),n);}
  238. #define mymaxloc(w,s,e,n) {dmaxloc_(w,*(s),*(e),n)}
  239. /* procedure parameter types for -A and -C++ */
  240. #define F2C_proc_par_types 1
  241. #ifdef __cplusplus
  242. typedef logical (*L_fp)(...);
  243. #else
  244. typedef logical (*L_fp)();
  245. #endif
  246. static float spow_ui(float x, integer n) {
  247. float pow=1.0; unsigned long int u;
  248. if(n != 0) {
  249. if(n < 0) n = -n, x = 1/x;
  250. for(u = n; ; ) {
  251. if(u & 01) pow *= x;
  252. if(u >>= 1) x *= x;
  253. else break;
  254. }
  255. }
  256. return pow;
  257. }
  258. static double dpow_ui(double x, integer n) {
  259. double pow=1.0; unsigned long int u;
  260. if(n != 0) {
  261. if(n < 0) n = -n, x = 1/x;
  262. for(u = n; ; ) {
  263. if(u & 01) pow *= x;
  264. if(u >>= 1) x *= x;
  265. else break;
  266. }
  267. }
  268. return pow;
  269. }
  270. #ifdef _MSC_VER
  271. static _Fcomplex cpow_ui(complex x, integer n) {
  272. complex pow={1.0,0.0}; unsigned long int u;
  273. if(n != 0) {
  274. if(n < 0) n = -n, x.r = 1/x.r, x.i=1/x.i;
  275. for(u = n; ; ) {
  276. if(u & 01) pow.r *= x.r, pow.i *= x.i;
  277. if(u >>= 1) x.r *= x.r, x.i *= x.i;
  278. else break;
  279. }
  280. }
  281. _Fcomplex p={pow.r, pow.i};
  282. return p;
  283. }
  284. #else
  285. static _Complex float cpow_ui(_Complex float x, integer n) {
  286. _Complex float pow=1.0; unsigned long int u;
  287. if(n != 0) {
  288. if(n < 0) n = -n, x = 1/x;
  289. for(u = n; ; ) {
  290. if(u & 01) pow *= x;
  291. if(u >>= 1) x *= x;
  292. else break;
  293. }
  294. }
  295. return pow;
  296. }
  297. #endif
  298. #ifdef _MSC_VER
  299. static _Dcomplex zpow_ui(_Dcomplex x, integer n) {
  300. _Dcomplex pow={1.0,0.0}; unsigned long int u;
  301. if(n != 0) {
  302. if(n < 0) n = -n, x._Val[0] = 1/x._Val[0], x._Val[1] =1/x._Val[1];
  303. for(u = n; ; ) {
  304. if(u & 01) pow._Val[0] *= x._Val[0], pow._Val[1] *= x._Val[1];
  305. if(u >>= 1) x._Val[0] *= x._Val[0], x._Val[1] *= x._Val[1];
  306. else break;
  307. }
  308. }
  309. _Dcomplex p = {pow._Val[0], pow._Val[1]};
  310. return p;
  311. }
  312. #else
  313. static _Complex double zpow_ui(_Complex double x, integer n) {
  314. _Complex double pow=1.0; unsigned long int u;
  315. if(n != 0) {
  316. if(n < 0) n = -n, x = 1/x;
  317. for(u = n; ; ) {
  318. if(u & 01) pow *= x;
  319. if(u >>= 1) x *= x;
  320. else break;
  321. }
  322. }
  323. return pow;
  324. }
  325. #endif
  326. static integer pow_ii(integer x, integer n) {
  327. integer pow; unsigned long int u;
  328. if (n <= 0) {
  329. if (n == 0 || x == 1) pow = 1;
  330. else if (x != -1) pow = x == 0 ? 1/x : 0;
  331. else n = -n;
  332. }
  333. if ((n > 0) || !(n == 0 || x == 1 || x != -1)) {
  334. u = n;
  335. for(pow = 1; ; ) {
  336. if(u & 01) pow *= x;
  337. if(u >>= 1) x *= x;
  338. else break;
  339. }
  340. }
  341. return pow;
  342. }
  343. static integer dmaxloc_(double *w, integer s, integer e, integer *n)
  344. {
  345. double m; integer i, mi;
  346. for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
  347. if (w[i-1]>m) mi=i ,m=w[i-1];
  348. return mi-s+1;
  349. }
  350. static integer smaxloc_(float *w, integer s, integer e, integer *n)
  351. {
  352. float m; integer i, mi;
  353. for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
  354. if (w[i-1]>m) mi=i ,m=w[i-1];
  355. return mi-s+1;
  356. }
  357. static inline void cdotc_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
  358. integer n = *n_, incx = *incx_, incy = *incy_, i;
  359. #ifdef _MSC_VER
  360. _Fcomplex zdotc = {0.0, 0.0};
  361. if (incx == 1 && incy == 1) {
  362. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  363. zdotc._Val[0] += conjf(Cf(&x[i]))._Val[0] * Cf(&y[i])._Val[0];
  364. zdotc._Val[1] += conjf(Cf(&x[i]))._Val[1] * Cf(&y[i])._Val[1];
  365. }
  366. } else {
  367. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  368. zdotc._Val[0] += conjf(Cf(&x[i*incx]))._Val[0] * Cf(&y[i*incy])._Val[0];
  369. zdotc._Val[1] += conjf(Cf(&x[i*incx]))._Val[1] * Cf(&y[i*incy])._Val[1];
  370. }
  371. }
  372. pCf(z) = zdotc;
  373. }
  374. #else
  375. _Complex float zdotc = 0.0;
  376. if (incx == 1 && incy == 1) {
  377. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  378. zdotc += conjf(Cf(&x[i])) * Cf(&y[i]);
  379. }
  380. } else {
  381. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  382. zdotc += conjf(Cf(&x[i*incx])) * Cf(&y[i*incy]);
  383. }
  384. }
  385. pCf(z) = zdotc;
  386. }
  387. #endif
  388. static inline void zdotc_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
  389. integer n = *n_, incx = *incx_, incy = *incy_, i;
  390. #ifdef _MSC_VER
  391. _Dcomplex zdotc = {0.0, 0.0};
  392. if (incx == 1 && incy == 1) {
  393. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  394. zdotc._Val[0] += conj(Cd(&x[i]))._Val[0] * Cd(&y[i])._Val[0];
  395. zdotc._Val[1] += conj(Cd(&x[i]))._Val[1] * Cd(&y[i])._Val[1];
  396. }
  397. } else {
  398. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  399. zdotc._Val[0] += conj(Cd(&x[i*incx]))._Val[0] * Cd(&y[i*incy])._Val[0];
  400. zdotc._Val[1] += conj(Cd(&x[i*incx]))._Val[1] * Cd(&y[i*incy])._Val[1];
  401. }
  402. }
  403. pCd(z) = zdotc;
  404. }
  405. #else
  406. _Complex double zdotc = 0.0;
  407. if (incx == 1 && incy == 1) {
  408. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  409. zdotc += conj(Cd(&x[i])) * Cd(&y[i]);
  410. }
  411. } else {
  412. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  413. zdotc += conj(Cd(&x[i*incx])) * Cd(&y[i*incy]);
  414. }
  415. }
  416. pCd(z) = zdotc;
  417. }
  418. #endif
  419. static inline void cdotu_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
  420. integer n = *n_, incx = *incx_, incy = *incy_, i;
  421. #ifdef _MSC_VER
  422. _Fcomplex zdotc = {0.0, 0.0};
  423. if (incx == 1 && incy == 1) {
  424. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  425. zdotc._Val[0] += Cf(&x[i])._Val[0] * Cf(&y[i])._Val[0];
  426. zdotc._Val[1] += Cf(&x[i])._Val[1] * Cf(&y[i])._Val[1];
  427. }
  428. } else {
  429. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  430. zdotc._Val[0] += Cf(&x[i*incx])._Val[0] * Cf(&y[i*incy])._Val[0];
  431. zdotc._Val[1] += Cf(&x[i*incx])._Val[1] * Cf(&y[i*incy])._Val[1];
  432. }
  433. }
  434. pCf(z) = zdotc;
  435. }
  436. #else
  437. _Complex float zdotc = 0.0;
  438. if (incx == 1 && incy == 1) {
  439. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  440. zdotc += Cf(&x[i]) * Cf(&y[i]);
  441. }
  442. } else {
  443. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  444. zdotc += Cf(&x[i*incx]) * Cf(&y[i*incy]);
  445. }
  446. }
  447. pCf(z) = zdotc;
  448. }
  449. #endif
  450. static inline void zdotu_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
  451. integer n = *n_, incx = *incx_, incy = *incy_, i;
  452. #ifdef _MSC_VER
  453. _Dcomplex zdotc = {0.0, 0.0};
  454. if (incx == 1 && incy == 1) {
  455. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  456. zdotc._Val[0] += Cd(&x[i])._Val[0] * Cd(&y[i])._Val[0];
  457. zdotc._Val[1] += Cd(&x[i])._Val[1] * Cd(&y[i])._Val[1];
  458. }
  459. } else {
  460. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  461. zdotc._Val[0] += Cd(&x[i*incx])._Val[0] * Cd(&y[i*incy])._Val[0];
  462. zdotc._Val[1] += Cd(&x[i*incx])._Val[1] * Cd(&y[i*incy])._Val[1];
  463. }
  464. }
  465. pCd(z) = zdotc;
  466. }
  467. #else
  468. _Complex double zdotc = 0.0;
  469. if (incx == 1 && incy == 1) {
  470. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  471. zdotc += Cd(&x[i]) * Cd(&y[i]);
  472. }
  473. } else {
  474. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  475. zdotc += Cd(&x[i*incx]) * Cd(&y[i*incy]);
  476. }
  477. }
  478. pCd(z) = zdotc;
  479. }
  480. #endif
  481. /* -- translated by f2c (version 20000121).
  482. You must link the resulting object file with the libraries:
  483. -lf2c -lm (in that order)
  484. */
  485. /* Table of constant values */
  486. static doublecomplex c_b1 = {1.,0.};
  487. static doublecomplex c_b2 = {0.,0.};
  488. static integer c__1 = 1;
  489. static integer c_n1 = -1;
  490. static integer c__2 = 2;
  491. static integer c__3 = 3;
  492. static integer c__16 = 16;
  493. /* > \brief \b ZGGHD3 */
  494. /* =========== DOCUMENTATION =========== */
  495. /* Online html documentation available at */
  496. /* http://www.netlib.org/lapack/explore-html/ */
  497. /* > \htmlonly */
  498. /* > Download ZGGHD3 + dependencies */
  499. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/zgghd3.
  500. f"> */
  501. /* > [TGZ]</a> */
  502. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/zgghd3.
  503. f"> */
  504. /* > [ZIP]</a> */
  505. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/zgghd3.
  506. f"> */
  507. /* > [TXT]</a> */
  508. /* > \endhtmlonly */
  509. /* Definition: */
  510. /* =========== */
  511. /* SUBROUTINE ZGGHD3( COMPQ, COMPZ, N, ILO, IHI, A, LDA, B, LDB, Q, */
  512. /* LDQ, Z, LDZ, WORK, LWORK, INFO ) */
  513. /* CHARACTER COMPQ, COMPZ */
  514. /* INTEGER IHI, ILO, INFO, LDA, LDB, LDQ, LDZ, N, LWORK */
  515. /* COMPLEX*16 A( LDA, * ), B( LDB, * ), Q( LDQ, * ), */
  516. /* $ Z( LDZ, * ), WORK( * ) */
  517. /* > \par Purpose: */
  518. /* ============= */
  519. /* > */
  520. /* > \verbatim */
  521. /* > */
  522. /* > ZGGHD3 reduces a pair of complex matrices (A,B) to generalized upper */
  523. /* > Hessenberg form using unitary transformations, where A is a */
  524. /* > general matrix and B is upper triangular. The form of the */
  525. /* > generalized eigenvalue problem is */
  526. /* > A*x = lambda*B*x, */
  527. /* > and B is typically made upper triangular by computing its QR */
  528. /* > factorization and moving the unitary matrix Q to the left side */
  529. /* > of the equation. */
  530. /* > */
  531. /* > This subroutine simultaneously reduces A to a Hessenberg matrix H: */
  532. /* > Q**H*A*Z = H */
  533. /* > and transforms B to another upper triangular matrix T: */
  534. /* > Q**H*B*Z = T */
  535. /* > in order to reduce the problem to its standard form */
  536. /* > H*y = lambda*T*y */
  537. /* > where y = Z**H*x. */
  538. /* > */
  539. /* > The unitary matrices Q and Z are determined as products of Givens */
  540. /* > rotations. They may either be formed explicitly, or they may be */
  541. /* > postmultiplied into input matrices Q1 and Z1, so that */
  542. /* > Q1 * A * Z1**H = (Q1*Q) * H * (Z1*Z)**H */
  543. /* > Q1 * B * Z1**H = (Q1*Q) * T * (Z1*Z)**H */
  544. /* > If Q1 is the unitary matrix from the QR factorization of B in the */
  545. /* > original equation A*x = lambda*B*x, then ZGGHD3 reduces the original */
  546. /* > problem to generalized Hessenberg form. */
  547. /* > */
  548. /* > This is a blocked variant of CGGHRD, using matrix-matrix */
  549. /* > multiplications for parts of the computation to enhance performance. */
  550. /* > \endverbatim */
  551. /* Arguments: */
  552. /* ========== */
  553. /* > \param[in] COMPQ */
  554. /* > \verbatim */
  555. /* > COMPQ is CHARACTER*1 */
  556. /* > = 'N': do not compute Q; */
  557. /* > = 'I': Q is initialized to the unit matrix, and the */
  558. /* > unitary matrix Q is returned; */
  559. /* > = 'V': Q must contain a unitary matrix Q1 on entry, */
  560. /* > and the product Q1*Q is returned. */
  561. /* > \endverbatim */
  562. /* > */
  563. /* > \param[in] COMPZ */
  564. /* > \verbatim */
  565. /* > COMPZ is CHARACTER*1 */
  566. /* > = 'N': do not compute Z; */
  567. /* > = 'I': Z is initialized to the unit matrix, and the */
  568. /* > unitary matrix Z is returned; */
  569. /* > = 'V': Z must contain a unitary matrix Z1 on entry, */
  570. /* > and the product Z1*Z is returned. */
  571. /* > \endverbatim */
  572. /* > */
  573. /* > \param[in] N */
  574. /* > \verbatim */
  575. /* > N is INTEGER */
  576. /* > The order of the matrices A and B. N >= 0. */
  577. /* > \endverbatim */
  578. /* > */
  579. /* > \param[in] ILO */
  580. /* > \verbatim */
  581. /* > ILO is INTEGER */
  582. /* > \endverbatim */
  583. /* > */
  584. /* > \param[in] IHI */
  585. /* > \verbatim */
  586. /* > IHI is INTEGER */
  587. /* > */
  588. /* > ILO and IHI mark the rows and columns of A which are to be */
  589. /* > reduced. It is assumed that A is already upper triangular */
  590. /* > in rows and columns 1:ILO-1 and IHI+1:N. ILO and IHI are */
  591. /* > normally set by a previous call to ZGGBAL; otherwise they */
  592. /* > should be set to 1 and N respectively. */
  593. /* > 1 <= ILO <= IHI <= N, if N > 0; ILO=1 and IHI=0, if N=0. */
  594. /* > \endverbatim */
  595. /* > */
  596. /* > \param[in,out] A */
  597. /* > \verbatim */
  598. /* > A is COMPLEX*16 array, dimension (LDA, N) */
  599. /* > On entry, the N-by-N general matrix to be reduced. */
  600. /* > On exit, the upper triangle and the first subdiagonal of A */
  601. /* > are overwritten with the upper Hessenberg matrix H, and the */
  602. /* > rest is set to zero. */
  603. /* > \endverbatim */
  604. /* > */
  605. /* > \param[in] LDA */
  606. /* > \verbatim */
  607. /* > LDA is INTEGER */
  608. /* > The leading dimension of the array A. LDA >= f2cmax(1,N). */
  609. /* > \endverbatim */
  610. /* > */
  611. /* > \param[in,out] B */
  612. /* > \verbatim */
  613. /* > B is COMPLEX*16 array, dimension (LDB, N) */
  614. /* > On entry, the N-by-N upper triangular matrix B. */
  615. /* > On exit, the upper triangular matrix T = Q**H B Z. The */
  616. /* > elements below the diagonal are set to zero. */
  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] Q */
  626. /* > \verbatim */
  627. /* > Q is COMPLEX*16 array, dimension (LDQ, N) */
  628. /* > On entry, if COMPQ = 'V', the unitary matrix Q1, typically */
  629. /* > from the QR factorization of B. */
  630. /* > On exit, if COMPQ='I', the unitary matrix Q, and if */
  631. /* > COMPQ = 'V', the product Q1*Q. */
  632. /* > Not referenced if COMPQ='N'. */
  633. /* > \endverbatim */
  634. /* > */
  635. /* > \param[in] LDQ */
  636. /* > \verbatim */
  637. /* > LDQ is INTEGER */
  638. /* > The leading dimension of the array Q. */
  639. /* > LDQ >= N if COMPQ='V' or 'I'; LDQ >= 1 otherwise. */
  640. /* > \endverbatim */
  641. /* > */
  642. /* > \param[in,out] Z */
  643. /* > \verbatim */
  644. /* > Z is COMPLEX*16 array, dimension (LDZ, N) */
  645. /* > On entry, if COMPZ = 'V', the unitary matrix Z1. */
  646. /* > On exit, if COMPZ='I', the unitary matrix Z, and if */
  647. /* > COMPZ = 'V', the product Z1*Z. */
  648. /* > Not referenced if COMPZ='N'. */
  649. /* > \endverbatim */
  650. /* > */
  651. /* > \param[in] LDZ */
  652. /* > \verbatim */
  653. /* > LDZ is INTEGER */
  654. /* > The leading dimension of the array Z. */
  655. /* > LDZ >= N if COMPZ='V' or 'I'; LDZ >= 1 otherwise. */
  656. /* > \endverbatim */
  657. /* > */
  658. /* > \param[out] WORK */
  659. /* > \verbatim */
  660. /* > WORK is COMPLEX*16 array, dimension (LWORK) */
  661. /* > On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */
  662. /* > \endverbatim */
  663. /* > */
  664. /* > \param[in] LWORK */
  665. /* > \verbatim */
  666. /* > LWORK is INTEGER */
  667. /* > The length of the array WORK. LWORK >= 1. */
  668. /* > For optimum performance LWORK >= 6*N*NB, where NB is the */
  669. /* > optimal blocksize. */
  670. /* > */
  671. /* > If LWORK = -1, then a workspace query is assumed; the routine */
  672. /* > only calculates the optimal size of the WORK array, returns */
  673. /* > this value as the first entry of the WORK array, and no error */
  674. /* > message related to LWORK is issued by XERBLA. */
  675. /* > \endverbatim */
  676. /* > */
  677. /* > \param[out] INFO */
  678. /* > \verbatim */
  679. /* > INFO is INTEGER */
  680. /* > = 0: successful exit. */
  681. /* > < 0: if INFO = -i, the i-th argument had an illegal value. */
  682. /* > \endverbatim */
  683. /* Authors: */
  684. /* ======== */
  685. /* > \author Univ. of Tennessee */
  686. /* > \author Univ. of California Berkeley */
  687. /* > \author Univ. of Colorado Denver */
  688. /* > \author NAG Ltd. */
  689. /* > \date January 2015 */
  690. /* > \ingroup complex16OTHERcomputational */
  691. /* > \par Further Details: */
  692. /* ===================== */
  693. /* > */
  694. /* > \verbatim */
  695. /* > */
  696. /* > This routine reduces A to Hessenberg form and maintains B in */
  697. /* > using a blocked variant of Moler and Stewart's original algorithm, */
  698. /* > as described by Kagstrom, Kressner, Quintana-Orti, and Quintana-Orti */
  699. /* > (BIT 2008). */
  700. /* > \endverbatim */
  701. /* > */
  702. /* ===================================================================== */
  703. /* Subroutine */ void zgghd3_(char *compq, char *compz, integer *n, integer *
  704. ilo, integer *ihi, doublecomplex *a, integer *lda, doublecomplex *b,
  705. integer *ldb, doublecomplex *q, integer *ldq, doublecomplex *z__,
  706. integer *ldz, doublecomplex *work, integer *lwork, integer *info)
  707. {
  708. /* System generated locals */
  709. integer a_dim1, a_offset, b_dim1, b_offset, q_dim1, q_offset, z_dim1,
  710. z_offset, i__1, i__2, i__3, i__4, i__5, i__6, i__7, i__8, i__9;
  711. doublecomplex z__1, z__2, z__3, z__4;
  712. /* Local variables */
  713. logical blk22;
  714. integer cola, jcol, ierr;
  715. doublecomplex temp;
  716. integer jrow, topq, ppwo;
  717. extern /* Subroutine */ void zrot_(integer *, doublecomplex *, integer *,
  718. doublecomplex *, integer *, doublereal *, doublecomplex *);
  719. doublecomplex temp1, temp2, temp3;
  720. doublereal c__;
  721. integer kacc22, i__, j, k;
  722. doublecomplex s;
  723. extern logical lsame_(char *, char *);
  724. integer nbmin;
  725. doublecomplex ctemp;
  726. extern /* Subroutine */ void zgemm_(char *, char *, integer *, integer *,
  727. integer *, doublecomplex *, doublecomplex *, integer *,
  728. doublecomplex *, integer *, doublecomplex *, doublecomplex *,
  729. integer *);
  730. integer nblst;
  731. logical initq;
  732. doublecomplex c1, c2;
  733. extern /* Subroutine */ void zgemv_(char *, integer *, integer *,
  734. doublecomplex *, doublecomplex *, integer *, doublecomplex *,
  735. integer *, doublecomplex *, doublecomplex *, integer *);
  736. logical wantq;
  737. integer j0;
  738. logical initz;
  739. extern /* Subroutine */ void zunm22_(char *, char *, integer *, integer *,
  740. integer *, integer *, doublecomplex *, integer *, doublecomplex *,
  741. integer *, doublecomplex *, integer *, integer *)
  742. ;
  743. logical wantz;
  744. doublecomplex s1, s2;
  745. extern /* Subroutine */ void ztrmv_(char *, char *, char *, integer *,
  746. doublecomplex *, integer *, doublecomplex *, integer *);
  747. char compq2[1], compz2[1];
  748. integer nb, jj, nh, nx, pw;
  749. extern /* Subroutine */ int xerbla_(char *, integer *, ftnlen);
  750. extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
  751. integer *, integer *, ftnlen, ftnlen);
  752. extern /* Subroutine */ void zgghrd_(char *, char *, integer *, integer *,
  753. integer *, doublecomplex *, integer *, doublecomplex *, integer *,
  754. doublecomplex *, integer *, doublecomplex *, integer *, integer *
  755. ), zlaset_(char *, integer *, integer *,
  756. doublecomplex *, doublecomplex *, doublecomplex *, integer *), zlartg_(doublecomplex *, doublecomplex *, doublereal *,
  757. doublecomplex *, doublecomplex *), zlacpy_(char *, integer *,
  758. integer *, doublecomplex *, integer *, doublecomplex *, integer *);
  759. integer lwkopt;
  760. logical lquery;
  761. integer nnb, len, top, ppw, n2nb;
  762. /* -- LAPACK computational routine (version 3.8.0) -- */
  763. /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
  764. /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
  765. /* January 2015 */
  766. /* ===================================================================== */
  767. /* Decode and test the input parameters. */
  768. /* Parameter adjustments */
  769. a_dim1 = *lda;
  770. a_offset = 1 + a_dim1 * 1;
  771. a -= a_offset;
  772. b_dim1 = *ldb;
  773. b_offset = 1 + b_dim1 * 1;
  774. b -= b_offset;
  775. q_dim1 = *ldq;
  776. q_offset = 1 + q_dim1 * 1;
  777. q -= q_offset;
  778. z_dim1 = *ldz;
  779. z_offset = 1 + z_dim1 * 1;
  780. z__ -= z_offset;
  781. --work;
  782. /* Function Body */
  783. *info = 0;
  784. nb = ilaenv_(&c__1, "ZGGHD3", " ", n, ilo, ihi, &c_n1, (ftnlen)6, (ftnlen)
  785. 1);
  786. /* Computing MAX */
  787. i__1 = *n * 6 * nb;
  788. lwkopt = f2cmax(i__1,1);
  789. z__1.r = (doublereal) lwkopt, z__1.i = 0.;
  790. work[1].r = z__1.r, work[1].i = z__1.i;
  791. initq = lsame_(compq, "I");
  792. wantq = initq || lsame_(compq, "V");
  793. initz = lsame_(compz, "I");
  794. wantz = initz || lsame_(compz, "V");
  795. lquery = *lwork == -1;
  796. if (! lsame_(compq, "N") && ! wantq) {
  797. *info = -1;
  798. } else if (! lsame_(compz, "N") && ! wantz) {
  799. *info = -2;
  800. } else if (*n < 0) {
  801. *info = -3;
  802. } else if (*ilo < 1) {
  803. *info = -4;
  804. } else if (*ihi > *n || *ihi < *ilo - 1) {
  805. *info = -5;
  806. } else if (*lda < f2cmax(1,*n)) {
  807. *info = -7;
  808. } else if (*ldb < f2cmax(1,*n)) {
  809. *info = -9;
  810. } else if (wantq && *ldq < *n || *ldq < 1) {
  811. *info = -11;
  812. } else if (wantz && *ldz < *n || *ldz < 1) {
  813. *info = -13;
  814. } else if (*lwork < 1 && ! lquery) {
  815. *info = -15;
  816. }
  817. if (*info != 0) {
  818. i__1 = -(*info);
  819. xerbla_("ZGGHD3", &i__1, (ftnlen)6);
  820. return;
  821. } else if (lquery) {
  822. return;
  823. }
  824. /* Initialize Q and Z if desired. */
  825. if (initq) {
  826. zlaset_("All", n, n, &c_b2, &c_b1, &q[q_offset], ldq);
  827. }
  828. if (initz) {
  829. zlaset_("All", n, n, &c_b2, &c_b1, &z__[z_offset], ldz);
  830. }
  831. /* Zero out lower triangle of B. */
  832. if (*n > 1) {
  833. i__1 = *n - 1;
  834. i__2 = *n - 1;
  835. zlaset_("Lower", &i__1, &i__2, &c_b2, &c_b2, &b[b_dim1 + 2], ldb);
  836. }
  837. /* Quick return if possible */
  838. nh = *ihi - *ilo + 1;
  839. if (nh <= 1) {
  840. work[1].r = 1., work[1].i = 0.;
  841. return;
  842. }
  843. /* Determine the blocksize. */
  844. nbmin = ilaenv_(&c__2, "ZGGHD3", " ", n, ilo, ihi, &c_n1, (ftnlen)6, (
  845. ftnlen)1);
  846. if (nb > 1 && nb < nh) {
  847. /* Determine when to use unblocked instead of blocked code. */
  848. /* Computing MAX */
  849. i__1 = nb, i__2 = ilaenv_(&c__3, "ZGGHD3", " ", n, ilo, ihi, &c_n1, (
  850. ftnlen)6, (ftnlen)1);
  851. nx = f2cmax(i__1,i__2);
  852. if (nx < nh) {
  853. /* Determine if workspace is large enough for blocked code. */
  854. if (*lwork < lwkopt) {
  855. /* Not enough workspace to use optimal NB: determine the */
  856. /* minimum value of NB, and reduce NB or force use of */
  857. /* unblocked code. */
  858. /* Computing MAX */
  859. i__1 = 2, i__2 = ilaenv_(&c__2, "ZGGHD3", " ", n, ilo, ihi, &
  860. c_n1, (ftnlen)6, (ftnlen)1);
  861. nbmin = f2cmax(i__1,i__2);
  862. if (*lwork >= *n * 6 * nbmin) {
  863. nb = *lwork / (*n * 6);
  864. } else {
  865. nb = 1;
  866. }
  867. }
  868. }
  869. }
  870. if (nb < nbmin || nb >= nh) {
  871. /* Use unblocked code below */
  872. jcol = *ilo;
  873. } else {
  874. /* Use blocked code */
  875. kacc22 = ilaenv_(&c__16, "ZGGHD3", " ", n, ilo, ihi, &c_n1, (ftnlen)6,
  876. (ftnlen)1);
  877. blk22 = kacc22 == 2;
  878. i__1 = *ihi - 2;
  879. i__2 = nb;
  880. for (jcol = *ilo; i__2 < 0 ? jcol >= i__1 : jcol <= i__1; jcol +=
  881. i__2) {
  882. /* Computing MIN */
  883. i__3 = nb, i__4 = *ihi - jcol - 1;
  884. nnb = f2cmin(i__3,i__4);
  885. /* Initialize small unitary factors that will hold the */
  886. /* accumulated Givens rotations in workspace. */
  887. /* N2NB denotes the number of 2*NNB-by-2*NNB factors */
  888. /* NBLST denotes the (possibly smaller) order of the last */
  889. /* factor. */
  890. n2nb = (*ihi - jcol - 1) / nnb - 1;
  891. nblst = *ihi - jcol - n2nb * nnb;
  892. zlaset_("All", &nblst, &nblst, &c_b2, &c_b1, &work[1], &nblst);
  893. pw = nblst * nblst + 1;
  894. i__3 = n2nb;
  895. for (i__ = 1; i__ <= i__3; ++i__) {
  896. i__4 = nnb << 1;
  897. i__5 = nnb << 1;
  898. i__6 = nnb << 1;
  899. zlaset_("All", &i__4, &i__5, &c_b2, &c_b1, &work[pw], &i__6);
  900. pw += (nnb << 2) * nnb;
  901. }
  902. /* Reduce columns JCOL:JCOL+NNB-1 of A to Hessenberg form. */
  903. i__3 = jcol + nnb - 1;
  904. for (j = jcol; j <= i__3; ++j) {
  905. /* Reduce Jth column of A. Store cosines and sines in Jth */
  906. /* column of A and B, respectively. */
  907. i__4 = j + 2;
  908. for (i__ = *ihi; i__ >= i__4; --i__) {
  909. i__5 = i__ - 1 + j * a_dim1;
  910. temp.r = a[i__5].r, temp.i = a[i__5].i;
  911. zlartg_(&temp, &a[i__ + j * a_dim1], &c__, &s, &a[i__ - 1
  912. + j * a_dim1]);
  913. i__5 = i__ + j * a_dim1;
  914. z__1.r = c__, z__1.i = 0.;
  915. a[i__5].r = z__1.r, a[i__5].i = z__1.i;
  916. i__5 = i__ + j * b_dim1;
  917. b[i__5].r = s.r, b[i__5].i = s.i;
  918. }
  919. /* Accumulate Givens rotations into workspace array. */
  920. ppw = (nblst + 1) * (nblst - 2) - j + jcol + 1;
  921. len = j + 2 - jcol;
  922. jrow = j + n2nb * nnb + 2;
  923. i__4 = jrow;
  924. for (i__ = *ihi; i__ >= i__4; --i__) {
  925. i__5 = i__ + j * a_dim1;
  926. ctemp.r = a[i__5].r, ctemp.i = a[i__5].i;
  927. i__5 = i__ + j * b_dim1;
  928. s.r = b[i__5].r, s.i = b[i__5].i;
  929. i__5 = ppw + len - 1;
  930. for (jj = ppw; jj <= i__5; ++jj) {
  931. i__6 = jj + nblst;
  932. temp.r = work[i__6].r, temp.i = work[i__6].i;
  933. i__6 = jj + nblst;
  934. z__2.r = ctemp.r * temp.r - ctemp.i * temp.i, z__2.i =
  935. ctemp.r * temp.i + ctemp.i * temp.r;
  936. i__7 = jj;
  937. z__3.r = s.r * work[i__7].r - s.i * work[i__7].i,
  938. z__3.i = s.r * work[i__7].i + s.i * work[i__7]
  939. .r;
  940. z__1.r = z__2.r - z__3.r, z__1.i = z__2.i - z__3.i;
  941. work[i__6].r = z__1.r, work[i__6].i = z__1.i;
  942. i__6 = jj;
  943. d_cnjg(&z__3, &s);
  944. z__2.r = z__3.r * temp.r - z__3.i * temp.i, z__2.i =
  945. z__3.r * temp.i + z__3.i * temp.r;
  946. i__7 = jj;
  947. z__4.r = ctemp.r * work[i__7].r - ctemp.i * work[i__7]
  948. .i, z__4.i = ctemp.r * work[i__7].i + ctemp.i
  949. * work[i__7].r;
  950. z__1.r = z__2.r + z__4.r, z__1.i = z__2.i + z__4.i;
  951. work[i__6].r = z__1.r, work[i__6].i = z__1.i;
  952. }
  953. ++len;
  954. ppw = ppw - nblst - 1;
  955. }
  956. ppwo = nblst * nblst + (nnb + j - jcol - 1 << 1) * nnb + nnb;
  957. j0 = jrow - nnb;
  958. i__4 = j + 2;
  959. i__5 = -nnb;
  960. for (jrow = j0; i__5 < 0 ? jrow >= i__4 : jrow <= i__4; jrow
  961. += i__5) {
  962. ppw = ppwo;
  963. len = j + 2 - jcol;
  964. i__6 = jrow;
  965. for (i__ = jrow + nnb - 1; i__ >= i__6; --i__) {
  966. i__7 = i__ + j * a_dim1;
  967. ctemp.r = a[i__7].r, ctemp.i = a[i__7].i;
  968. i__7 = i__ + j * b_dim1;
  969. s.r = b[i__7].r, s.i = b[i__7].i;
  970. i__7 = ppw + len - 1;
  971. for (jj = ppw; jj <= i__7; ++jj) {
  972. i__8 = jj + (nnb << 1);
  973. temp.r = work[i__8].r, temp.i = work[i__8].i;
  974. i__8 = jj + (nnb << 1);
  975. z__2.r = ctemp.r * temp.r - ctemp.i * temp.i,
  976. z__2.i = ctemp.r * temp.i + ctemp.i *
  977. temp.r;
  978. i__9 = jj;
  979. z__3.r = s.r * work[i__9].r - s.i * work[i__9].i,
  980. z__3.i = s.r * work[i__9].i + s.i * work[
  981. i__9].r;
  982. z__1.r = z__2.r - z__3.r, z__1.i = z__2.i -
  983. z__3.i;
  984. work[i__8].r = z__1.r, work[i__8].i = z__1.i;
  985. i__8 = jj;
  986. d_cnjg(&z__3, &s);
  987. z__2.r = z__3.r * temp.r - z__3.i * temp.i,
  988. z__2.i = z__3.r * temp.i + z__3.i *
  989. temp.r;
  990. i__9 = jj;
  991. z__4.r = ctemp.r * work[i__9].r - ctemp.i * work[
  992. i__9].i, z__4.i = ctemp.r * work[i__9].i
  993. + ctemp.i * work[i__9].r;
  994. z__1.r = z__2.r + z__4.r, z__1.i = z__2.i +
  995. z__4.i;
  996. work[i__8].r = z__1.r, work[i__8].i = z__1.i;
  997. }
  998. ++len;
  999. ppw = ppw - (nnb << 1) - 1;
  1000. }
  1001. ppwo += (nnb << 2) * nnb;
  1002. }
  1003. /* TOP denotes the number of top rows in A and B that will */
  1004. /* not be updated during the next steps. */
  1005. if (jcol <= 2) {
  1006. top = 0;
  1007. } else {
  1008. top = jcol;
  1009. }
  1010. /* Propagate transformations through B and replace stored */
  1011. /* left sines/cosines by right sines/cosines. */
  1012. i__5 = j + 1;
  1013. for (jj = *n; jj >= i__5; --jj) {
  1014. /* Update JJth column of B. */
  1015. /* Computing MIN */
  1016. i__4 = jj + 1;
  1017. i__6 = j + 2;
  1018. for (i__ = f2cmin(i__4,*ihi); i__ >= i__6; --i__) {
  1019. i__4 = i__ + j * a_dim1;
  1020. ctemp.r = a[i__4].r, ctemp.i = a[i__4].i;
  1021. i__4 = i__ + j * b_dim1;
  1022. s.r = b[i__4].r, s.i = b[i__4].i;
  1023. i__4 = i__ + jj * b_dim1;
  1024. temp.r = b[i__4].r, temp.i = b[i__4].i;
  1025. i__4 = i__ + jj * b_dim1;
  1026. z__2.r = ctemp.r * temp.r - ctemp.i * temp.i, z__2.i =
  1027. ctemp.r * temp.i + ctemp.i * temp.r;
  1028. d_cnjg(&z__4, &s);
  1029. i__7 = i__ - 1 + jj * b_dim1;
  1030. z__3.r = z__4.r * b[i__7].r - z__4.i * b[i__7].i,
  1031. z__3.i = z__4.r * b[i__7].i + z__4.i * b[i__7]
  1032. .r;
  1033. z__1.r = z__2.r - z__3.r, z__1.i = z__2.i - z__3.i;
  1034. b[i__4].r = z__1.r, b[i__4].i = z__1.i;
  1035. i__4 = i__ - 1 + jj * b_dim1;
  1036. z__2.r = s.r * temp.r - s.i * temp.i, z__2.i = s.r *
  1037. temp.i + s.i * temp.r;
  1038. i__7 = i__ - 1 + jj * b_dim1;
  1039. z__3.r = ctemp.r * b[i__7].r - ctemp.i * b[i__7].i,
  1040. z__3.i = ctemp.r * b[i__7].i + ctemp.i * b[
  1041. i__7].r;
  1042. z__1.r = z__2.r + z__3.r, z__1.i = z__2.i + z__3.i;
  1043. b[i__4].r = z__1.r, b[i__4].i = z__1.i;
  1044. }
  1045. /* Annihilate B( JJ+1, JJ ). */
  1046. if (jj < *ihi) {
  1047. i__6 = jj + 1 + (jj + 1) * b_dim1;
  1048. temp.r = b[i__6].r, temp.i = b[i__6].i;
  1049. zlartg_(&temp, &b[jj + 1 + jj * b_dim1], &c__, &s, &b[
  1050. jj + 1 + (jj + 1) * b_dim1]);
  1051. i__6 = jj + 1 + jj * b_dim1;
  1052. b[i__6].r = 0., b[i__6].i = 0.;
  1053. i__6 = jj - top;
  1054. zrot_(&i__6, &b[top + 1 + (jj + 1) * b_dim1], &c__1, &
  1055. b[top + 1 + jj * b_dim1], &c__1, &c__, &s);
  1056. i__6 = jj + 1 + j * a_dim1;
  1057. z__1.r = c__, z__1.i = 0.;
  1058. a[i__6].r = z__1.r, a[i__6].i = z__1.i;
  1059. i__6 = jj + 1 + j * b_dim1;
  1060. d_cnjg(&z__2, &s);
  1061. z__1.r = -z__2.r, z__1.i = -z__2.i;
  1062. b[i__6].r = z__1.r, b[i__6].i = z__1.i;
  1063. }
  1064. }
  1065. /* Update A by transformations from right. */
  1066. jj = (*ihi - j - 1) % 3;
  1067. i__5 = jj + 1;
  1068. for (i__ = *ihi - j - 3; i__ >= i__5; i__ += -3) {
  1069. i__6 = j + 1 + i__ + j * a_dim1;
  1070. ctemp.r = a[i__6].r, ctemp.i = a[i__6].i;
  1071. i__6 = j + 1 + i__ + j * b_dim1;
  1072. z__1.r = -b[i__6].r, z__1.i = -b[i__6].i;
  1073. s.r = z__1.r, s.i = z__1.i;
  1074. i__6 = j + 2 + i__ + j * a_dim1;
  1075. c1.r = a[i__6].r, c1.i = a[i__6].i;
  1076. i__6 = j + 2 + i__ + j * b_dim1;
  1077. z__1.r = -b[i__6].r, z__1.i = -b[i__6].i;
  1078. s1.r = z__1.r, s1.i = z__1.i;
  1079. i__6 = j + 3 + i__ + j * a_dim1;
  1080. c2.r = a[i__6].r, c2.i = a[i__6].i;
  1081. i__6 = j + 3 + i__ + j * b_dim1;
  1082. z__1.r = -b[i__6].r, z__1.i = -b[i__6].i;
  1083. s2.r = z__1.r, s2.i = z__1.i;
  1084. i__6 = *ihi;
  1085. for (k = top + 1; k <= i__6; ++k) {
  1086. i__4 = k + (j + i__) * a_dim1;
  1087. temp.r = a[i__4].r, temp.i = a[i__4].i;
  1088. i__4 = k + (j + i__ + 1) * a_dim1;
  1089. temp1.r = a[i__4].r, temp1.i = a[i__4].i;
  1090. i__4 = k + (j + i__ + 2) * a_dim1;
  1091. temp2.r = a[i__4].r, temp2.i = a[i__4].i;
  1092. i__4 = k + (j + i__ + 3) * a_dim1;
  1093. temp3.r = a[i__4].r, temp3.i = a[i__4].i;
  1094. i__4 = k + (j + i__ + 3) * a_dim1;
  1095. z__2.r = c2.r * temp3.r - c2.i * temp3.i, z__2.i =
  1096. c2.r * temp3.i + c2.i * temp3.r;
  1097. d_cnjg(&z__4, &s2);
  1098. z__3.r = z__4.r * temp2.r - z__4.i * temp2.i, z__3.i =
  1099. z__4.r * temp2.i + z__4.i * temp2.r;
  1100. z__1.r = z__2.r + z__3.r, z__1.i = z__2.i + z__3.i;
  1101. a[i__4].r = z__1.r, a[i__4].i = z__1.i;
  1102. z__3.r = -s2.r, z__3.i = -s2.i;
  1103. z__2.r = z__3.r * temp3.r - z__3.i * temp3.i, z__2.i =
  1104. z__3.r * temp3.i + z__3.i * temp3.r;
  1105. z__4.r = c2.r * temp2.r - c2.i * temp2.i, z__4.i =
  1106. c2.r * temp2.i + c2.i * temp2.r;
  1107. z__1.r = z__2.r + z__4.r, z__1.i = z__2.i + z__4.i;
  1108. temp2.r = z__1.r, temp2.i = z__1.i;
  1109. i__4 = k + (j + i__ + 2) * a_dim1;
  1110. z__2.r = c1.r * temp2.r - c1.i * temp2.i, z__2.i =
  1111. c1.r * temp2.i + c1.i * temp2.r;
  1112. d_cnjg(&z__4, &s1);
  1113. z__3.r = z__4.r * temp1.r - z__4.i * temp1.i, z__3.i =
  1114. z__4.r * temp1.i + z__4.i * temp1.r;
  1115. z__1.r = z__2.r + z__3.r, z__1.i = z__2.i + z__3.i;
  1116. a[i__4].r = z__1.r, a[i__4].i = z__1.i;
  1117. z__3.r = -s1.r, z__3.i = -s1.i;
  1118. z__2.r = z__3.r * temp2.r - z__3.i * temp2.i, z__2.i =
  1119. z__3.r * temp2.i + z__3.i * temp2.r;
  1120. z__4.r = c1.r * temp1.r - c1.i * temp1.i, z__4.i =
  1121. c1.r * temp1.i + c1.i * temp1.r;
  1122. z__1.r = z__2.r + z__4.r, z__1.i = z__2.i + z__4.i;
  1123. temp1.r = z__1.r, temp1.i = z__1.i;
  1124. i__4 = k + (j + i__ + 1) * a_dim1;
  1125. z__2.r = ctemp.r * temp1.r - ctemp.i * temp1.i,
  1126. z__2.i = ctemp.r * temp1.i + ctemp.i *
  1127. temp1.r;
  1128. d_cnjg(&z__4, &s);
  1129. z__3.r = z__4.r * temp.r - z__4.i * temp.i, z__3.i =
  1130. z__4.r * temp.i + z__4.i * temp.r;
  1131. z__1.r = z__2.r + z__3.r, z__1.i = z__2.i + z__3.i;
  1132. a[i__4].r = z__1.r, a[i__4].i = z__1.i;
  1133. i__4 = k + (j + i__) * a_dim1;
  1134. z__3.r = -s.r, z__3.i = -s.i;
  1135. z__2.r = z__3.r * temp1.r - z__3.i * temp1.i, z__2.i =
  1136. z__3.r * temp1.i + z__3.i * temp1.r;
  1137. z__4.r = ctemp.r * temp.r - ctemp.i * temp.i, z__4.i =
  1138. ctemp.r * temp.i + ctemp.i * temp.r;
  1139. z__1.r = z__2.r + z__4.r, z__1.i = z__2.i + z__4.i;
  1140. a[i__4].r = z__1.r, a[i__4].i = z__1.i;
  1141. }
  1142. }
  1143. if (jj > 0) {
  1144. for (i__ = jj; i__ >= 1; --i__) {
  1145. i__5 = j + 1 + i__ + j * a_dim1;
  1146. c__ = a[i__5].r;
  1147. i__5 = *ihi - top;
  1148. d_cnjg(&z__2, &b[j + 1 + i__ + j * b_dim1]);
  1149. z__1.r = -z__2.r, z__1.i = -z__2.i;
  1150. zrot_(&i__5, &a[top + 1 + (j + i__ + 1) * a_dim1], &
  1151. c__1, &a[top + 1 + (j + i__) * a_dim1], &c__1,
  1152. &c__, &z__1);
  1153. }
  1154. }
  1155. /* Update (J+1)th column of A by transformations from left. */
  1156. if (j < jcol + nnb - 1) {
  1157. len = j + 1 - jcol;
  1158. /* Multiply with the trailing accumulated unitary */
  1159. /* matrix, which takes the form */
  1160. /* [ U11 U12 ] */
  1161. /* U = [ ], */
  1162. /* [ U21 U22 ] */
  1163. /* where U21 is a LEN-by-LEN matrix and U12 is lower */
  1164. /* triangular. */
  1165. jrow = *ihi - nblst + 1;
  1166. zgemv_("Conjugate", &nblst, &len, &c_b1, &work[1], &nblst,
  1167. &a[jrow + (j + 1) * a_dim1], &c__1, &c_b2, &work[
  1168. pw], &c__1);
  1169. ppw = pw + len;
  1170. i__5 = jrow + nblst - len - 1;
  1171. for (i__ = jrow; i__ <= i__5; ++i__) {
  1172. i__6 = ppw;
  1173. i__4 = i__ + (j + 1) * a_dim1;
  1174. work[i__6].r = a[i__4].r, work[i__6].i = a[i__4].i;
  1175. ++ppw;
  1176. }
  1177. i__5 = nblst - len;
  1178. ztrmv_("Lower", "Conjugate", "Non-unit", &i__5, &work[len
  1179. * nblst + 1], &nblst, &work[pw + len], &c__1);
  1180. i__5 = nblst - len;
  1181. zgemv_("Conjugate", &len, &i__5, &c_b1, &work[(len + 1) *
  1182. nblst - len + 1], &nblst, &a[jrow + nblst - len +
  1183. (j + 1) * a_dim1], &c__1, &c_b1, &work[pw + len],
  1184. &c__1);
  1185. ppw = pw;
  1186. i__5 = jrow + nblst - 1;
  1187. for (i__ = jrow; i__ <= i__5; ++i__) {
  1188. i__6 = i__ + (j + 1) * a_dim1;
  1189. i__4 = ppw;
  1190. a[i__6].r = work[i__4].r, a[i__6].i = work[i__4].i;
  1191. ++ppw;
  1192. }
  1193. /* Multiply with the other accumulated unitary */
  1194. /* matrices, which take the form */
  1195. /* [ U11 U12 0 ] */
  1196. /* [ ] */
  1197. /* U = [ U21 U22 0 ], */
  1198. /* [ ] */
  1199. /* [ 0 0 I ] */
  1200. /* where I denotes the (NNB-LEN)-by-(NNB-LEN) identity */
  1201. /* matrix, U21 is a LEN-by-LEN upper triangular matrix */
  1202. /* and U12 is an NNB-by-NNB lower triangular matrix. */
  1203. ppwo = nblst * nblst + 1;
  1204. j0 = jrow - nnb;
  1205. i__5 = jcol + 1;
  1206. i__6 = -nnb;
  1207. for (jrow = j0; i__6 < 0 ? jrow >= i__5 : jrow <= i__5;
  1208. jrow += i__6) {
  1209. ppw = pw + len;
  1210. i__4 = jrow + nnb - 1;
  1211. for (i__ = jrow; i__ <= i__4; ++i__) {
  1212. i__7 = ppw;
  1213. i__8 = i__ + (j + 1) * a_dim1;
  1214. work[i__7].r = a[i__8].r, work[i__7].i = a[i__8]
  1215. .i;
  1216. ++ppw;
  1217. }
  1218. ppw = pw;
  1219. i__4 = jrow + nnb + len - 1;
  1220. for (i__ = jrow + nnb; i__ <= i__4; ++i__) {
  1221. i__7 = ppw;
  1222. i__8 = i__ + (j + 1) * a_dim1;
  1223. work[i__7].r = a[i__8].r, work[i__7].i = a[i__8]
  1224. .i;
  1225. ++ppw;
  1226. }
  1227. i__4 = nnb << 1;
  1228. ztrmv_("Upper", "Conjugate", "Non-unit", &len, &work[
  1229. ppwo + nnb], &i__4, &work[pw], &c__1);
  1230. i__4 = nnb << 1;
  1231. ztrmv_("Lower", "Conjugate", "Non-unit", &nnb, &work[
  1232. ppwo + (len << 1) * nnb], &i__4, &work[pw +
  1233. len], &c__1);
  1234. i__4 = nnb << 1;
  1235. zgemv_("Conjugate", &nnb, &len, &c_b1, &work[ppwo], &
  1236. i__4, &a[jrow + (j + 1) * a_dim1], &c__1, &
  1237. c_b1, &work[pw], &c__1);
  1238. i__4 = nnb << 1;
  1239. zgemv_("Conjugate", &len, &nnb, &c_b1, &work[ppwo + (
  1240. len << 1) * nnb + nnb], &i__4, &a[jrow + nnb
  1241. + (j + 1) * a_dim1], &c__1, &c_b1, &work[pw +
  1242. len], &c__1);
  1243. ppw = pw;
  1244. i__4 = jrow + len + nnb - 1;
  1245. for (i__ = jrow; i__ <= i__4; ++i__) {
  1246. i__7 = i__ + (j + 1) * a_dim1;
  1247. i__8 = ppw;
  1248. a[i__7].r = work[i__8].r, a[i__7].i = work[i__8]
  1249. .i;
  1250. ++ppw;
  1251. }
  1252. ppwo += (nnb << 2) * nnb;
  1253. }
  1254. }
  1255. }
  1256. /* Apply accumulated unitary matrices to A. */
  1257. cola = *n - jcol - nnb + 1;
  1258. j = *ihi - nblst + 1;
  1259. zgemm_("Conjugate", "No Transpose", &nblst, &cola, &nblst, &c_b1,
  1260. &work[1], &nblst, &a[j + (jcol + nnb) * a_dim1], lda, &
  1261. c_b2, &work[pw], &nblst);
  1262. zlacpy_("All", &nblst, &cola, &work[pw], &nblst, &a[j + (jcol +
  1263. nnb) * a_dim1], lda);
  1264. ppwo = nblst * nblst + 1;
  1265. j0 = j - nnb;
  1266. i__3 = jcol + 1;
  1267. i__6 = -nnb;
  1268. for (j = j0; i__6 < 0 ? j >= i__3 : j <= i__3; j += i__6) {
  1269. if (blk22) {
  1270. /* Exploit the structure of */
  1271. /* [ U11 U12 ] */
  1272. /* U = [ ] */
  1273. /* [ U21 U22 ], */
  1274. /* where all blocks are NNB-by-NNB, U21 is upper */
  1275. /* triangular and U12 is lower triangular. */
  1276. i__5 = nnb << 1;
  1277. i__4 = nnb << 1;
  1278. i__7 = *lwork - pw + 1;
  1279. zunm22_("Left", "Conjugate", &i__5, &cola, &nnb, &nnb, &
  1280. work[ppwo], &i__4, &a[j + (jcol + nnb) * a_dim1],
  1281. lda, &work[pw], &i__7, &ierr);
  1282. } else {
  1283. /* Ignore the structure of U. */
  1284. i__5 = nnb << 1;
  1285. i__4 = nnb << 1;
  1286. i__7 = nnb << 1;
  1287. i__8 = nnb << 1;
  1288. zgemm_("Conjugate", "No Transpose", &i__5, &cola, &i__4, &
  1289. c_b1, &work[ppwo], &i__7, &a[j + (jcol + nnb) *
  1290. a_dim1], lda, &c_b2, &work[pw], &i__8);
  1291. i__5 = nnb << 1;
  1292. i__4 = nnb << 1;
  1293. zlacpy_("All", &i__5, &cola, &work[pw], &i__4, &a[j + (
  1294. jcol + nnb) * a_dim1], lda);
  1295. }
  1296. ppwo += (nnb << 2) * nnb;
  1297. }
  1298. /* Apply accumulated unitary matrices to Q. */
  1299. if (wantq) {
  1300. j = *ihi - nblst + 1;
  1301. if (initq) {
  1302. /* Computing MAX */
  1303. i__6 = 2, i__3 = j - jcol + 1;
  1304. topq = f2cmax(i__6,i__3);
  1305. nh = *ihi - topq + 1;
  1306. } else {
  1307. topq = 1;
  1308. nh = *n;
  1309. }
  1310. zgemm_("No Transpose", "No Transpose", &nh, &nblst, &nblst, &
  1311. c_b1, &q[topq + j * q_dim1], ldq, &work[1], &nblst, &
  1312. c_b2, &work[pw], &nh);
  1313. zlacpy_("All", &nh, &nblst, &work[pw], &nh, &q[topq + j *
  1314. q_dim1], ldq);
  1315. ppwo = nblst * nblst + 1;
  1316. j0 = j - nnb;
  1317. i__6 = jcol + 1;
  1318. i__3 = -nnb;
  1319. for (j = j0; i__3 < 0 ? j >= i__6 : j <= i__6; j += i__3) {
  1320. if (initq) {
  1321. /* Computing MAX */
  1322. i__5 = 2, i__4 = j - jcol + 1;
  1323. topq = f2cmax(i__5,i__4);
  1324. nh = *ihi - topq + 1;
  1325. }
  1326. if (blk22) {
  1327. /* Exploit the structure of U. */
  1328. i__5 = nnb << 1;
  1329. i__4 = nnb << 1;
  1330. i__7 = *lwork - pw + 1;
  1331. zunm22_("Right", "No Transpose", &nh, &i__5, &nnb, &
  1332. nnb, &work[ppwo], &i__4, &q[topq + j * q_dim1]
  1333. , ldq, &work[pw], &i__7, &ierr);
  1334. } else {
  1335. /* Ignore the structure of U. */
  1336. i__5 = nnb << 1;
  1337. i__4 = nnb << 1;
  1338. i__7 = nnb << 1;
  1339. zgemm_("No Transpose", "No Transpose", &nh, &i__5, &
  1340. i__4, &c_b1, &q[topq + j * q_dim1], ldq, &
  1341. work[ppwo], &i__7, &c_b2, &work[pw], &nh);
  1342. i__5 = nnb << 1;
  1343. zlacpy_("All", &nh, &i__5, &work[pw], &nh, &q[topq +
  1344. j * q_dim1], ldq);
  1345. }
  1346. ppwo += (nnb << 2) * nnb;
  1347. }
  1348. }
  1349. /* Accumulate right Givens rotations if required. */
  1350. if (wantz || top > 0) {
  1351. /* Initialize small unitary factors that will hold the */
  1352. /* accumulated Givens rotations in workspace. */
  1353. zlaset_("All", &nblst, &nblst, &c_b2, &c_b1, &work[1], &nblst);
  1354. pw = nblst * nblst + 1;
  1355. i__3 = n2nb;
  1356. for (i__ = 1; i__ <= i__3; ++i__) {
  1357. i__6 = nnb << 1;
  1358. i__5 = nnb << 1;
  1359. i__4 = nnb << 1;
  1360. zlaset_("All", &i__6, &i__5, &c_b2, &c_b1, &work[pw], &
  1361. i__4);
  1362. pw += (nnb << 2) * nnb;
  1363. }
  1364. /* Accumulate Givens rotations into workspace array. */
  1365. i__3 = jcol + nnb - 1;
  1366. for (j = jcol; j <= i__3; ++j) {
  1367. ppw = (nblst + 1) * (nblst - 2) - j + jcol + 1;
  1368. len = j + 2 - jcol;
  1369. jrow = j + n2nb * nnb + 2;
  1370. i__6 = jrow;
  1371. for (i__ = *ihi; i__ >= i__6; --i__) {
  1372. i__5 = i__ + j * a_dim1;
  1373. ctemp.r = a[i__5].r, ctemp.i = a[i__5].i;
  1374. i__5 = i__ + j * a_dim1;
  1375. a[i__5].r = 0., a[i__5].i = 0.;
  1376. i__5 = i__ + j * b_dim1;
  1377. s.r = b[i__5].r, s.i = b[i__5].i;
  1378. i__5 = i__ + j * b_dim1;
  1379. b[i__5].r = 0., b[i__5].i = 0.;
  1380. i__5 = ppw + len - 1;
  1381. for (jj = ppw; jj <= i__5; ++jj) {
  1382. i__4 = jj + nblst;
  1383. temp.r = work[i__4].r, temp.i = work[i__4].i;
  1384. i__4 = jj + nblst;
  1385. z__2.r = ctemp.r * temp.r - ctemp.i * temp.i,
  1386. z__2.i = ctemp.r * temp.i + ctemp.i *
  1387. temp.r;
  1388. d_cnjg(&z__4, &s);
  1389. i__7 = jj;
  1390. z__3.r = z__4.r * work[i__7].r - z__4.i * work[
  1391. i__7].i, z__3.i = z__4.r * work[i__7].i +
  1392. z__4.i * work[i__7].r;
  1393. z__1.r = z__2.r - z__3.r, z__1.i = z__2.i -
  1394. z__3.i;
  1395. work[i__4].r = z__1.r, work[i__4].i = z__1.i;
  1396. i__4 = jj;
  1397. z__2.r = s.r * temp.r - s.i * temp.i, z__2.i =
  1398. s.r * temp.i + s.i * temp.r;
  1399. i__7 = jj;
  1400. z__3.r = ctemp.r * work[i__7].r - ctemp.i * work[
  1401. i__7].i, z__3.i = ctemp.r * work[i__7].i
  1402. + ctemp.i * work[i__7].r;
  1403. z__1.r = z__2.r + z__3.r, z__1.i = z__2.i +
  1404. z__3.i;
  1405. work[i__4].r = z__1.r, work[i__4].i = z__1.i;
  1406. }
  1407. ++len;
  1408. ppw = ppw - nblst - 1;
  1409. }
  1410. ppwo = nblst * nblst + (nnb + j - jcol - 1 << 1) * nnb +
  1411. nnb;
  1412. j0 = jrow - nnb;
  1413. i__6 = j + 2;
  1414. i__5 = -nnb;
  1415. for (jrow = j0; i__5 < 0 ? jrow >= i__6 : jrow <= i__6;
  1416. jrow += i__5) {
  1417. ppw = ppwo;
  1418. len = j + 2 - jcol;
  1419. i__4 = jrow;
  1420. for (i__ = jrow + nnb - 1; i__ >= i__4; --i__) {
  1421. i__7 = i__ + j * a_dim1;
  1422. ctemp.r = a[i__7].r, ctemp.i = a[i__7].i;
  1423. i__7 = i__ + j * a_dim1;
  1424. a[i__7].r = 0., a[i__7].i = 0.;
  1425. i__7 = i__ + j * b_dim1;
  1426. s.r = b[i__7].r, s.i = b[i__7].i;
  1427. i__7 = i__ + j * b_dim1;
  1428. b[i__7].r = 0., b[i__7].i = 0.;
  1429. i__7 = ppw + len - 1;
  1430. for (jj = ppw; jj <= i__7; ++jj) {
  1431. i__8 = jj + (nnb << 1);
  1432. temp.r = work[i__8].r, temp.i = work[i__8].i;
  1433. i__8 = jj + (nnb << 1);
  1434. z__2.r = ctemp.r * temp.r - ctemp.i * temp.i,
  1435. z__2.i = ctemp.r * temp.i + ctemp.i *
  1436. temp.r;
  1437. d_cnjg(&z__4, &s);
  1438. i__9 = jj;
  1439. z__3.r = z__4.r * work[i__9].r - z__4.i *
  1440. work[i__9].i, z__3.i = z__4.r * work[
  1441. i__9].i + z__4.i * work[i__9].r;
  1442. z__1.r = z__2.r - z__3.r, z__1.i = z__2.i -
  1443. z__3.i;
  1444. work[i__8].r = z__1.r, work[i__8].i = z__1.i;
  1445. i__8 = jj;
  1446. z__2.r = s.r * temp.r - s.i * temp.i, z__2.i =
  1447. s.r * temp.i + s.i * temp.r;
  1448. i__9 = jj;
  1449. z__3.r = ctemp.r * work[i__9].r - ctemp.i *
  1450. work[i__9].i, z__3.i = ctemp.r * work[
  1451. i__9].i + ctemp.i * work[i__9].r;
  1452. z__1.r = z__2.r + z__3.r, z__1.i = z__2.i +
  1453. z__3.i;
  1454. work[i__8].r = z__1.r, work[i__8].i = z__1.i;
  1455. }
  1456. ++len;
  1457. ppw = ppw - (nnb << 1) - 1;
  1458. }
  1459. ppwo += (nnb << 2) * nnb;
  1460. }
  1461. }
  1462. } else {
  1463. i__3 = *ihi - jcol - 1;
  1464. zlaset_("Lower", &i__3, &nnb, &c_b2, &c_b2, &a[jcol + 2 +
  1465. jcol * a_dim1], lda);
  1466. i__3 = *ihi - jcol - 1;
  1467. zlaset_("Lower", &i__3, &nnb, &c_b2, &c_b2, &b[jcol + 2 +
  1468. jcol * b_dim1], ldb);
  1469. }
  1470. /* Apply accumulated unitary matrices to A and B. */
  1471. if (top > 0) {
  1472. j = *ihi - nblst + 1;
  1473. zgemm_("No Transpose", "No Transpose", &top, &nblst, &nblst, &
  1474. c_b1, &a[j * a_dim1 + 1], lda, &work[1], &nblst, &
  1475. c_b2, &work[pw], &top);
  1476. zlacpy_("All", &top, &nblst, &work[pw], &top, &a[j * a_dim1 +
  1477. 1], lda);
  1478. ppwo = nblst * nblst + 1;
  1479. j0 = j - nnb;
  1480. i__3 = jcol + 1;
  1481. i__5 = -nnb;
  1482. for (j = j0; i__5 < 0 ? j >= i__3 : j <= i__3; j += i__5) {
  1483. if (blk22) {
  1484. /* Exploit the structure of U. */
  1485. i__6 = nnb << 1;
  1486. i__4 = nnb << 1;
  1487. i__7 = *lwork - pw + 1;
  1488. zunm22_("Right", "No Transpose", &top, &i__6, &nnb, &
  1489. nnb, &work[ppwo], &i__4, &a[j * a_dim1 + 1],
  1490. lda, &work[pw], &i__7, &ierr);
  1491. } else {
  1492. /* Ignore the structure of U. */
  1493. i__6 = nnb << 1;
  1494. i__4 = nnb << 1;
  1495. i__7 = nnb << 1;
  1496. zgemm_("No Transpose", "No Transpose", &top, &i__6, &
  1497. i__4, &c_b1, &a[j * a_dim1 + 1], lda, &work[
  1498. ppwo], &i__7, &c_b2, &work[pw], &top);
  1499. i__6 = nnb << 1;
  1500. zlacpy_("All", &top, &i__6, &work[pw], &top, &a[j *
  1501. a_dim1 + 1], lda);
  1502. }
  1503. ppwo += (nnb << 2) * nnb;
  1504. }
  1505. j = *ihi - nblst + 1;
  1506. zgemm_("No Transpose", "No Transpose", &top, &nblst, &nblst, &
  1507. c_b1, &b[j * b_dim1 + 1], ldb, &work[1], &nblst, &
  1508. c_b2, &work[pw], &top);
  1509. zlacpy_("All", &top, &nblst, &work[pw], &top, &b[j * b_dim1 +
  1510. 1], ldb);
  1511. ppwo = nblst * nblst + 1;
  1512. j0 = j - nnb;
  1513. i__5 = jcol + 1;
  1514. i__3 = -nnb;
  1515. for (j = j0; i__3 < 0 ? j >= i__5 : j <= i__5; j += i__3) {
  1516. if (blk22) {
  1517. /* Exploit the structure of U. */
  1518. i__6 = nnb << 1;
  1519. i__4 = nnb << 1;
  1520. i__7 = *lwork - pw + 1;
  1521. zunm22_("Right", "No Transpose", &top, &i__6, &nnb, &
  1522. nnb, &work[ppwo], &i__4, &b[j * b_dim1 + 1],
  1523. ldb, &work[pw], &i__7, &ierr);
  1524. } else {
  1525. /* Ignore the structure of U. */
  1526. i__6 = nnb << 1;
  1527. i__4 = nnb << 1;
  1528. i__7 = nnb << 1;
  1529. zgemm_("No Transpose", "No Transpose", &top, &i__6, &
  1530. i__4, &c_b1, &b[j * b_dim1 + 1], ldb, &work[
  1531. ppwo], &i__7, &c_b2, &work[pw], &top);
  1532. i__6 = nnb << 1;
  1533. zlacpy_("All", &top, &i__6, &work[pw], &top, &b[j *
  1534. b_dim1 + 1], ldb);
  1535. }
  1536. ppwo += (nnb << 2) * nnb;
  1537. }
  1538. }
  1539. /* Apply accumulated unitary matrices to Z. */
  1540. if (wantz) {
  1541. j = *ihi - nblst + 1;
  1542. if (initq) {
  1543. /* Computing MAX */
  1544. i__3 = 2, i__5 = j - jcol + 1;
  1545. topq = f2cmax(i__3,i__5);
  1546. nh = *ihi - topq + 1;
  1547. } else {
  1548. topq = 1;
  1549. nh = *n;
  1550. }
  1551. zgemm_("No Transpose", "No Transpose", &nh, &nblst, &nblst, &
  1552. c_b1, &z__[topq + j * z_dim1], ldz, &work[1], &nblst,
  1553. &c_b2, &work[pw], &nh);
  1554. zlacpy_("All", &nh, &nblst, &work[pw], &nh, &z__[topq + j *
  1555. z_dim1], ldz);
  1556. ppwo = nblst * nblst + 1;
  1557. j0 = j - nnb;
  1558. i__3 = jcol + 1;
  1559. i__5 = -nnb;
  1560. for (j = j0; i__5 < 0 ? j >= i__3 : j <= i__3; j += i__5) {
  1561. if (initq) {
  1562. /* Computing MAX */
  1563. i__6 = 2, i__4 = j - jcol + 1;
  1564. topq = f2cmax(i__6,i__4);
  1565. nh = *ihi - topq + 1;
  1566. }
  1567. if (blk22) {
  1568. /* Exploit the structure of U. */
  1569. i__6 = nnb << 1;
  1570. i__4 = nnb << 1;
  1571. i__7 = *lwork - pw + 1;
  1572. zunm22_("Right", "No Transpose", &nh, &i__6, &nnb, &
  1573. nnb, &work[ppwo], &i__4, &z__[topq + j *
  1574. z_dim1], ldz, &work[pw], &i__7, &ierr);
  1575. } else {
  1576. /* Ignore the structure of U. */
  1577. i__6 = nnb << 1;
  1578. i__4 = nnb << 1;
  1579. i__7 = nnb << 1;
  1580. zgemm_("No Transpose", "No Transpose", &nh, &i__6, &
  1581. i__4, &c_b1, &z__[topq + j * z_dim1], ldz, &
  1582. work[ppwo], &i__7, &c_b2, &work[pw], &nh);
  1583. i__6 = nnb << 1;
  1584. zlacpy_("All", &nh, &i__6, &work[pw], &nh, &z__[topq
  1585. + j * z_dim1], ldz);
  1586. }
  1587. ppwo += (nnb << 2) * nnb;
  1588. }
  1589. }
  1590. }
  1591. }
  1592. /* Use unblocked code to reduce the rest of the matrix */
  1593. /* Avoid re-initialization of modified Q and Z. */
  1594. *(unsigned char *)compq2 = *(unsigned char *)compq;
  1595. *(unsigned char *)compz2 = *(unsigned char *)compz;
  1596. if (jcol != *ilo) {
  1597. if (wantq) {
  1598. *(unsigned char *)compq2 = 'V';
  1599. }
  1600. if (wantz) {
  1601. *(unsigned char *)compz2 = 'V';
  1602. }
  1603. }
  1604. if (jcol < *ihi) {
  1605. zgghrd_(compq2, compz2, n, &jcol, ihi, &a[a_offset], lda, &b[b_offset]
  1606. , ldb, &q[q_offset], ldq, &z__[z_offset], ldz, &ierr);
  1607. }
  1608. z__1.r = (doublereal) lwkopt, z__1.i = 0.;
  1609. work[1].r = z__1.r, work[1].i = z__1.i;
  1610. return;
  1611. /* End of ZGGHD3 */
  1612. } /* zgghd3_ */