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.

cgghd3.c 54 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768
  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 complex c_b1 = {1.f,0.f};
  485. static complex c_b2 = {0.f,0.f};
  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 CGGHD3 */
  492. /* =========== DOCUMENTATION =========== */
  493. /* Online html documentation available at */
  494. /* http://www.netlib.org/lapack/explore-html/ */
  495. /* > \htmlonly */
  496. /* > Download CGGHD3 + dependencies */
  497. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/cgghd3.
  498. f"> */
  499. /* > [TGZ]</a> */
  500. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/cgghd3.
  501. f"> */
  502. /* > [ZIP]</a> */
  503. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/cgghd3.
  504. f"> */
  505. /* > [TXT]</a> */
  506. /* > \endhtmlonly */
  507. /* Definition: */
  508. /* =========== */
  509. /* SUBROUTINE CGGHD3( 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 A( LDA, * ), B( LDB, * ), Q( LDQ, * ), */
  514. /* $ Z( LDZ, * ), WORK( * ) */
  515. /* > \par Purpose: */
  516. /* ============= */
  517. /* > */
  518. /* > \verbatim */
  519. /* > */
  520. /* > */
  521. /* > CGGHD3 reduces a pair of complex matrices (A,B) to generalized upper */
  522. /* > Hessenberg form using unitary transformations, where A is a */
  523. /* > general matrix and B is upper triangular. The form of the */
  524. /* > generalized eigenvalue problem is */
  525. /* > A*x = lambda*B*x, */
  526. /* > and B is typically made upper triangular by computing its QR */
  527. /* > factorization and moving the unitary matrix Q to the left side */
  528. /* > of the equation. */
  529. /* > */
  530. /* > This subroutine simultaneously reduces A to a Hessenberg matrix H: */
  531. /* > Q**H*A*Z = H */
  532. /* > and transforms B to another upper triangular matrix T: */
  533. /* > Q**H*B*Z = T */
  534. /* > in order to reduce the problem to its standard form */
  535. /* > H*y = lambda*T*y */
  536. /* > where y = Z**H*x. */
  537. /* > */
  538. /* > The unitary matrices Q and Z are determined as products of Givens */
  539. /* > rotations. They may either be formed explicitly, or they may be */
  540. /* > postmultiplied into input matrices Q1 and Z1, so that */
  541. /* > */
  542. /* > Q1 * A * Z1**H = (Q1*Q) * H * (Z1*Z)**H */
  543. /* > */
  544. /* > Q1 * B * Z1**H = (Q1*Q) * T * (Z1*Z)**H */
  545. /* > */
  546. /* > If Q1 is the unitary matrix from the QR factorization of B in the */
  547. /* > original equation A*x = lambda*B*x, then CGGHD3 reduces the original */
  548. /* > problem to generalized Hessenberg form. */
  549. /* > */
  550. /* > This is a blocked variant of CGGHRD, using matrix-matrix */
  551. /* > multiplications for parts of the computation to enhance performance. */
  552. /* > \endverbatim */
  553. /* Arguments: */
  554. /* ========== */
  555. /* > \param[in] COMPQ */
  556. /* > \verbatim */
  557. /* > COMPQ is CHARACTER*1 */
  558. /* > = 'N': do not compute Q; */
  559. /* > = 'I': Q is initialized to the unit matrix, and the */
  560. /* > unitary matrix Q is returned; */
  561. /* > = 'V': Q must contain a unitary matrix Q1 on entry, */
  562. /* > and the product Q1*Q is returned. */
  563. /* > \endverbatim */
  564. /* > */
  565. /* > \param[in] COMPZ */
  566. /* > \verbatim */
  567. /* > COMPZ is CHARACTER*1 */
  568. /* > = 'N': do not compute Z; */
  569. /* > = 'I': Z is initialized to the unit matrix, and the */
  570. /* > unitary matrix Z is returned; */
  571. /* > = 'V': Z must contain a unitary matrix Z1 on entry, */
  572. /* > and the product Z1*Z is returned. */
  573. /* > \endverbatim */
  574. /* > */
  575. /* > \param[in] N */
  576. /* > \verbatim */
  577. /* > N is INTEGER */
  578. /* > The order of the matrices A and B. N >= 0. */
  579. /* > \endverbatim */
  580. /* > */
  581. /* > \param[in] ILO */
  582. /* > \verbatim */
  583. /* > ILO is INTEGER */
  584. /* > \endverbatim */
  585. /* > */
  586. /* > \param[in] IHI */
  587. /* > \verbatim */
  588. /* > IHI is INTEGER */
  589. /* > */
  590. /* > ILO and IHI mark the rows and columns of A which are to be */
  591. /* > reduced. It is assumed that A is already upper triangular */
  592. /* > in rows and columns 1:ILO-1 and IHI+1:N. ILO and IHI are */
  593. /* > normally set by a previous call to CGGBAL; otherwise they */
  594. /* > should be set to 1 and N respectively. */
  595. /* > 1 <= ILO <= IHI <= N, if N > 0; ILO=1 and IHI=0, if N=0. */
  596. /* > \endverbatim */
  597. /* > */
  598. /* > \param[in,out] A */
  599. /* > \verbatim */
  600. /* > A is COMPLEX array, dimension (LDA, N) */
  601. /* > On entry, the N-by-N general matrix to be reduced. */
  602. /* > On exit, the upper triangle and the first subdiagonal of A */
  603. /* > are overwritten with the upper Hessenberg matrix H, and the */
  604. /* > rest is set to zero. */
  605. /* > \endverbatim */
  606. /* > */
  607. /* > \param[in] LDA */
  608. /* > \verbatim */
  609. /* > LDA is INTEGER */
  610. /* > The leading dimension of the array A. LDA >= f2cmax(1,N). */
  611. /* > \endverbatim */
  612. /* > */
  613. /* > \param[in,out] B */
  614. /* > \verbatim */
  615. /* > B is COMPLEX array, dimension (LDB, N) */
  616. /* > On entry, the N-by-N upper triangular matrix B. */
  617. /* > On exit, the upper triangular matrix T = Q**H B Z. The */
  618. /* > elements below the diagonal are set to zero. */
  619. /* > \endverbatim */
  620. /* > */
  621. /* > \param[in] LDB */
  622. /* > \verbatim */
  623. /* > LDB is INTEGER */
  624. /* > The leading dimension of the array B. LDB >= f2cmax(1,N). */
  625. /* > \endverbatim */
  626. /* > */
  627. /* > \param[in,out] Q */
  628. /* > \verbatim */
  629. /* > Q is COMPLEX array, dimension (LDQ, N) */
  630. /* > On entry, if COMPQ = 'V', the unitary matrix Q1, typically */
  631. /* > from the QR factorization of B. */
  632. /* > On exit, if COMPQ='I', the unitary matrix Q, and if */
  633. /* > COMPQ = 'V', the product Q1*Q. */
  634. /* > Not referenced if COMPQ='N'. */
  635. /* > \endverbatim */
  636. /* > */
  637. /* > \param[in] LDQ */
  638. /* > \verbatim */
  639. /* > LDQ is INTEGER */
  640. /* > The leading dimension of the array Q. */
  641. /* > LDQ >= N if COMPQ='V' or 'I'; LDQ >= 1 otherwise. */
  642. /* > \endverbatim */
  643. /* > */
  644. /* > \param[in,out] Z */
  645. /* > \verbatim */
  646. /* > Z is COMPLEX array, dimension (LDZ, N) */
  647. /* > On entry, if COMPZ = 'V', the unitary matrix Z1. */
  648. /* > On exit, if COMPZ='I', the unitary matrix Z, and if */
  649. /* > COMPZ = 'V', the product Z1*Z. */
  650. /* > Not referenced if COMPZ='N'. */
  651. /* > \endverbatim */
  652. /* > */
  653. /* > \param[in] LDZ */
  654. /* > \verbatim */
  655. /* > LDZ is INTEGER */
  656. /* > The leading dimension of the array Z. */
  657. /* > LDZ >= N if COMPZ='V' or 'I'; LDZ >= 1 otherwise. */
  658. /* > \endverbatim */
  659. /* > */
  660. /* > \param[out] WORK */
  661. /* > \verbatim */
  662. /* > WORK is COMPLEX array, dimension (LWORK) */
  663. /* > On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */
  664. /* > \endverbatim */
  665. /* > */
  666. /* > \param[in] LWORK */
  667. /* > \verbatim */
  668. /* > LWORK is INTEGER */
  669. /* > The length of the array WORK. LWORK >= 1. */
  670. /* > For optimum performance LWORK >= 6*N*NB, where NB is the */
  671. /* > optimal blocksize. */
  672. /* > */
  673. /* > If LWORK = -1, then a workspace query is assumed; the routine */
  674. /* > only calculates the optimal size of the WORK array, returns */
  675. /* > this value as the first entry of the WORK array, and no error */
  676. /* > message related to LWORK is issued by XERBLA. */
  677. /* > \endverbatim */
  678. /* > */
  679. /* > \param[out] INFO */
  680. /* > \verbatim */
  681. /* > INFO is INTEGER */
  682. /* > = 0: successful exit. */
  683. /* > < 0: if INFO = -i, the i-th argument had an illegal value. */
  684. /* > \endverbatim */
  685. /* Authors: */
  686. /* ======== */
  687. /* > \author Univ. of Tennessee */
  688. /* > \author Univ. of California Berkeley */
  689. /* > \author Univ. of Colorado Denver */
  690. /* > \author NAG Ltd. */
  691. /* > \date January 2015 */
  692. /* > \ingroup complexOTHERcomputational */
  693. /* > \par Further Details: */
  694. /* ===================== */
  695. /* > */
  696. /* > \verbatim */
  697. /* > */
  698. /* > This routine reduces A to Hessenberg form and maintains B in */
  699. /* > using a blocked variant of Moler and Stewart's original algorithm, */
  700. /* > as described by Kagstrom, Kressner, Quintana-Orti, and Quintana-Orti */
  701. /* > (BIT 2008). */
  702. /* > \endverbatim */
  703. /* > */
  704. /* ===================================================================== */
  705. /* Subroutine */ void cgghd3_(char *compq, char *compz, integer *n, integer *
  706. ilo, integer *ihi, complex *a, integer *lda, complex *b, integer *ldb,
  707. complex *q, integer *ldq, complex *z__, integer *ldz, complex *work,
  708. integer *lwork, integer *info)
  709. {
  710. /* System generated locals */
  711. integer a_dim1, a_offset, b_dim1, b_offset, q_dim1, q_offset, z_dim1,
  712. z_offset, i__1, i__2, i__3, i__4, i__5, i__6, i__7, i__8, i__9;
  713. complex q__1, q__2, q__3, q__4;
  714. /* Local variables */
  715. logical blk22;
  716. integer cola, jcol, ierr;
  717. complex temp;
  718. extern /* Subroutine */ void crot_(integer *, complex *, integer *,
  719. complex *, integer *, real *, complex *);
  720. integer jrow, topq, ppwo;
  721. complex temp1, temp2, temp3;
  722. real c__;
  723. integer kacc22, i__, j, k;
  724. complex s;
  725. extern /* Subroutine */ void cgemm_(char *, char *, integer *, integer *,
  726. integer *, complex *, complex *, integer *, complex *, integer *,
  727. complex *, complex *, integer *);
  728. extern logical lsame_(char *, char *);
  729. extern /* Subroutine */ void cgemv_(char *, integer *, integer *, complex *
  730. , complex *, integer *, complex *, integer *, complex *, complex *
  731. , integer *);
  732. integer nbmin;
  733. extern /* Subroutine */ void cunm22_(char *, char *, integer *, integer *,
  734. integer *, integer *, complex *, integer *, complex *, integer *,
  735. complex *, integer *, integer *);
  736. complex ctemp;
  737. integer nblst;
  738. logical initq;
  739. complex c1, c2;
  740. logical wantq;
  741. integer j0;
  742. extern /* Subroutine */ void ctrmv_(char *, char *, char *, integer *,
  743. complex *, integer *, complex *, integer *);
  744. logical initz, wantz;
  745. complex s1, s2;
  746. char compq2[1], compz2[1];
  747. integer nb, jj, nh;
  748. extern /* Subroutine */ void cgghrd_(char *, char *, integer *, integer *,
  749. integer *, complex *, integer *, complex *, integer *, complex *,
  750. integer *, complex *, integer *, integer *);
  751. integer nx, pw;
  752. extern /* Subroutine */ void claset_(char *, integer *, integer *, complex
  753. *, complex *, complex *, integer *), clartg_(complex *,
  754. complex *, real *, complex *, complex *), clacpy_(char *, integer
  755. *, integer *, complex *, integer *, complex *, integer *);
  756. extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
  757. integer *, integer *, ftnlen, ftnlen);
  758. extern /* Subroutine */ int xerbla_(char *, integer *, ftnlen);
  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, "CGGHD3", " ", 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. q__1.r = (real) lwkopt, q__1.i = 0.f;
  790. work[1].r = q__1.r, work[1].i = q__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_("CGGHD3", &i__1, (ftnlen)6);
  820. return;
  821. } else if (lquery) {
  822. return;
  823. }
  824. /* Initialize Q and Z if desired. */
  825. if (initq) {
  826. claset_("All", n, n, &c_b2, &c_b1, &q[q_offset], ldq);
  827. }
  828. if (initz) {
  829. claset_("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. claset_("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.f, work[1].i = 0.f;
  841. return;
  842. }
  843. /* Determine the blocksize. */
  844. nbmin = ilaenv_(&c__2, "CGGHD3", " ", 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, "CGGHD3", " ", 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, "CGGHD3", " ", 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, "CGGHD3", " ", 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. claset_("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. claset_("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. clartg_(&temp, &a[i__ + j * a_dim1], &c__, &s, &a[i__ - 1
  912. + j * a_dim1]);
  913. i__5 = i__ + j * a_dim1;
  914. q__1.r = c__, q__1.i = 0.f;
  915. a[i__5].r = q__1.r, a[i__5].i = q__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. q__2.r = ctemp.r * temp.r - ctemp.i * temp.i, q__2.i =
  935. ctemp.r * temp.i + ctemp.i * temp.r;
  936. i__7 = jj;
  937. q__3.r = s.r * work[i__7].r - s.i * work[i__7].i,
  938. q__3.i = s.r * work[i__7].i + s.i * work[i__7]
  939. .r;
  940. q__1.r = q__2.r - q__3.r, q__1.i = q__2.i - q__3.i;
  941. work[i__6].r = q__1.r, work[i__6].i = q__1.i;
  942. i__6 = jj;
  943. r_cnjg(&q__3, &s);
  944. q__2.r = q__3.r * temp.r - q__3.i * temp.i, q__2.i =
  945. q__3.r * temp.i + q__3.i * temp.r;
  946. i__7 = jj;
  947. q__4.r = ctemp.r * work[i__7].r - ctemp.i * work[i__7]
  948. .i, q__4.i = ctemp.r * work[i__7].i + ctemp.i
  949. * work[i__7].r;
  950. q__1.r = q__2.r + q__4.r, q__1.i = q__2.i + q__4.i;
  951. work[i__6].r = q__1.r, work[i__6].i = q__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. q__2.r = ctemp.r * temp.r - ctemp.i * temp.i,
  976. q__2.i = ctemp.r * temp.i + ctemp.i *
  977. temp.r;
  978. i__9 = jj;
  979. q__3.r = s.r * work[i__9].r - s.i * work[i__9].i,
  980. q__3.i = s.r * work[i__9].i + s.i * work[
  981. i__9].r;
  982. q__1.r = q__2.r - q__3.r, q__1.i = q__2.i -
  983. q__3.i;
  984. work[i__8].r = q__1.r, work[i__8].i = q__1.i;
  985. i__8 = jj;
  986. r_cnjg(&q__3, &s);
  987. q__2.r = q__3.r * temp.r - q__3.i * temp.i,
  988. q__2.i = q__3.r * temp.i + q__3.i *
  989. temp.r;
  990. i__9 = jj;
  991. q__4.r = ctemp.r * work[i__9].r - ctemp.i * work[
  992. i__9].i, q__4.i = ctemp.r * work[i__9].i
  993. + ctemp.i * work[i__9].r;
  994. q__1.r = q__2.r + q__4.r, q__1.i = q__2.i +
  995. q__4.i;
  996. work[i__8].r = q__1.r, work[i__8].i = q__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. q__2.r = ctemp.r * temp.r - ctemp.i * temp.i, q__2.i =
  1027. ctemp.r * temp.i + ctemp.i * temp.r;
  1028. r_cnjg(&q__4, &s);
  1029. i__7 = i__ - 1 + jj * b_dim1;
  1030. q__3.r = q__4.r * b[i__7].r - q__4.i * b[i__7].i,
  1031. q__3.i = q__4.r * b[i__7].i + q__4.i * b[i__7]
  1032. .r;
  1033. q__1.r = q__2.r - q__3.r, q__1.i = q__2.i - q__3.i;
  1034. b[i__4].r = q__1.r, b[i__4].i = q__1.i;
  1035. i__4 = i__ - 1 + jj * b_dim1;
  1036. q__2.r = s.r * temp.r - s.i * temp.i, q__2.i = s.r *
  1037. temp.i + s.i * temp.r;
  1038. i__7 = i__ - 1 + jj * b_dim1;
  1039. q__3.r = ctemp.r * b[i__7].r - ctemp.i * b[i__7].i,
  1040. q__3.i = ctemp.r * b[i__7].i + ctemp.i * b[
  1041. i__7].r;
  1042. q__1.r = q__2.r + q__3.r, q__1.i = q__2.i + q__3.i;
  1043. b[i__4].r = q__1.r, b[i__4].i = q__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. clartg_(&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.f, b[i__6].i = 0.f;
  1053. i__6 = jj - top;
  1054. crot_(&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. q__1.r = c__, q__1.i = 0.f;
  1058. a[i__6].r = q__1.r, a[i__6].i = q__1.i;
  1059. i__6 = jj + 1 + j * b_dim1;
  1060. r_cnjg(&q__2, &s);
  1061. q__1.r = -q__2.r, q__1.i = -q__2.i;
  1062. b[i__6].r = q__1.r, b[i__6].i = q__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. q__1.r = -b[i__6].r, q__1.i = -b[i__6].i;
  1073. s.r = q__1.r, s.i = q__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. q__1.r = -b[i__6].r, q__1.i = -b[i__6].i;
  1078. s1.r = q__1.r, s1.i = q__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. q__1.r = -b[i__6].r, q__1.i = -b[i__6].i;
  1083. s2.r = q__1.r, s2.i = q__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. q__2.r = c2.r * temp3.r - c2.i * temp3.i, q__2.i =
  1096. c2.r * temp3.i + c2.i * temp3.r;
  1097. r_cnjg(&q__4, &s2);
  1098. q__3.r = q__4.r * temp2.r - q__4.i * temp2.i, q__3.i =
  1099. q__4.r * temp2.i + q__4.i * temp2.r;
  1100. q__1.r = q__2.r + q__3.r, q__1.i = q__2.i + q__3.i;
  1101. a[i__4].r = q__1.r, a[i__4].i = q__1.i;
  1102. q__3.r = -s2.r, q__3.i = -s2.i;
  1103. q__2.r = q__3.r * temp3.r - q__3.i * temp3.i, q__2.i =
  1104. q__3.r * temp3.i + q__3.i * temp3.r;
  1105. q__4.r = c2.r * temp2.r - c2.i * temp2.i, q__4.i =
  1106. c2.r * temp2.i + c2.i * temp2.r;
  1107. q__1.r = q__2.r + q__4.r, q__1.i = q__2.i + q__4.i;
  1108. temp2.r = q__1.r, temp2.i = q__1.i;
  1109. i__4 = k + (j + i__ + 2) * a_dim1;
  1110. q__2.r = c1.r * temp2.r - c1.i * temp2.i, q__2.i =
  1111. c1.r * temp2.i + c1.i * temp2.r;
  1112. r_cnjg(&q__4, &s1);
  1113. q__3.r = q__4.r * temp1.r - q__4.i * temp1.i, q__3.i =
  1114. q__4.r * temp1.i + q__4.i * temp1.r;
  1115. q__1.r = q__2.r + q__3.r, q__1.i = q__2.i + q__3.i;
  1116. a[i__4].r = q__1.r, a[i__4].i = q__1.i;
  1117. q__3.r = -s1.r, q__3.i = -s1.i;
  1118. q__2.r = q__3.r * temp2.r - q__3.i * temp2.i, q__2.i =
  1119. q__3.r * temp2.i + q__3.i * temp2.r;
  1120. q__4.r = c1.r * temp1.r - c1.i * temp1.i, q__4.i =
  1121. c1.r * temp1.i + c1.i * temp1.r;
  1122. q__1.r = q__2.r + q__4.r, q__1.i = q__2.i + q__4.i;
  1123. temp1.r = q__1.r, temp1.i = q__1.i;
  1124. i__4 = k + (j + i__ + 1) * a_dim1;
  1125. q__2.r = ctemp.r * temp1.r - ctemp.i * temp1.i,
  1126. q__2.i = ctemp.r * temp1.i + ctemp.i *
  1127. temp1.r;
  1128. r_cnjg(&q__4, &s);
  1129. q__3.r = q__4.r * temp.r - q__4.i * temp.i, q__3.i =
  1130. q__4.r * temp.i + q__4.i * temp.r;
  1131. q__1.r = q__2.r + q__3.r, q__1.i = q__2.i + q__3.i;
  1132. a[i__4].r = q__1.r, a[i__4].i = q__1.i;
  1133. i__4 = k + (j + i__) * a_dim1;
  1134. q__3.r = -s.r, q__3.i = -s.i;
  1135. q__2.r = q__3.r * temp1.r - q__3.i * temp1.i, q__2.i =
  1136. q__3.r * temp1.i + q__3.i * temp1.r;
  1137. q__4.r = ctemp.r * temp.r - ctemp.i * temp.i, q__4.i =
  1138. ctemp.r * temp.i + ctemp.i * temp.r;
  1139. q__1.r = q__2.r + q__4.r, q__1.i = q__2.i + q__4.i;
  1140. a[i__4].r = q__1.r, a[i__4].i = q__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__ = (doublereal) a[i__5].r;
  1147. i__5 = *ihi - top;
  1148. r_cnjg(&q__2, &b[j + 1 + i__ + j * b_dim1]);
  1149. q__1.r = -q__2.r, q__1.i = -q__2.i;
  1150. crot_(&i__5, &a[top + 1 + (j + i__ + 1) * a_dim1], &
  1151. c__1, &a[top + 1 + (j + i__) * a_dim1], &c__1,
  1152. &c__, &q__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. cgemv_("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. ctrmv_("Lower", "Conjugate", "Non-unit", &i__5, &work[len
  1179. * nblst + 1], &nblst, &work[pw + len], &c__1);
  1180. i__5 = nblst - len;
  1181. cgemv_("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. ctrmv_("Upper", "Conjugate", "Non-unit", &len, &work[
  1229. ppwo + nnb], &i__4, &work[pw], &c__1);
  1230. i__4 = nnb << 1;
  1231. ctrmv_("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. cgemv_("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. cgemv_("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. cgemm_("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. clacpy_("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. cunm22_("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. cgemm_("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. clacpy_("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. cgemm_("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. clacpy_("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. cunm22_("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. cgemm_("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. clacpy_("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. claset_("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. claset_("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.f, a[i__5].i = 0.f;
  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.f, b[i__5].i = 0.f;
  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. q__2.r = ctemp.r * temp.r - ctemp.i * temp.i,
  1386. q__2.i = ctemp.r * temp.i + ctemp.i *
  1387. temp.r;
  1388. r_cnjg(&q__4, &s);
  1389. i__7 = jj;
  1390. q__3.r = q__4.r * work[i__7].r - q__4.i * work[
  1391. i__7].i, q__3.i = q__4.r * work[i__7].i +
  1392. q__4.i * work[i__7].r;
  1393. q__1.r = q__2.r - q__3.r, q__1.i = q__2.i -
  1394. q__3.i;
  1395. work[i__4].r = q__1.r, work[i__4].i = q__1.i;
  1396. i__4 = jj;
  1397. q__2.r = s.r * temp.r - s.i * temp.i, q__2.i =
  1398. s.r * temp.i + s.i * temp.r;
  1399. i__7 = jj;
  1400. q__3.r = ctemp.r * work[i__7].r - ctemp.i * work[
  1401. i__7].i, q__3.i = ctemp.r * work[i__7].i
  1402. + ctemp.i * work[i__7].r;
  1403. q__1.r = q__2.r + q__3.r, q__1.i = q__2.i +
  1404. q__3.i;
  1405. work[i__4].r = q__1.r, work[i__4].i = q__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.f, a[i__7].i = 0.f;
  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.f, b[i__7].i = 0.f;
  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. q__2.r = ctemp.r * temp.r - ctemp.i * temp.i,
  1435. q__2.i = ctemp.r * temp.i + ctemp.i *
  1436. temp.r;
  1437. r_cnjg(&q__4, &s);
  1438. i__9 = jj;
  1439. q__3.r = q__4.r * work[i__9].r - q__4.i *
  1440. work[i__9].i, q__3.i = q__4.r * work[
  1441. i__9].i + q__4.i * work[i__9].r;
  1442. q__1.r = q__2.r - q__3.r, q__1.i = q__2.i -
  1443. q__3.i;
  1444. work[i__8].r = q__1.r, work[i__8].i = q__1.i;
  1445. i__8 = jj;
  1446. q__2.r = s.r * temp.r - s.i * temp.i, q__2.i =
  1447. s.r * temp.i + s.i * temp.r;
  1448. i__9 = jj;
  1449. q__3.r = ctemp.r * work[i__9].r - ctemp.i *
  1450. work[i__9].i, q__3.i = ctemp.r * work[
  1451. i__9].i + ctemp.i * work[i__9].r;
  1452. q__1.r = q__2.r + q__3.r, q__1.i = q__2.i +
  1453. q__3.i;
  1454. work[i__8].r = q__1.r, work[i__8].i = q__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. claset_("Lower", &i__3, &nnb, &c_b2, &c_b2, &a[jcol + 2 +
  1465. jcol * a_dim1], lda);
  1466. i__3 = *ihi - jcol - 1;
  1467. claset_("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. cgemm_("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. clacpy_("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. cunm22_("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. cgemm_("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. clacpy_("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. cgemm_("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. clacpy_("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. cunm22_("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. cgemm_("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. clacpy_("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. cgemm_("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. clacpy_("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. cunm22_("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. cgemm_("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. clacpy_("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. cgghrd_(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. q__1.r = (real) lwkopt, q__1.i = 0.f;
  1609. work[1].r = q__1.r, work[1].i = q__1.i;
  1610. return;
  1611. /* End of CGGHD3 */
  1612. } /* cgghd3_ */