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