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.

dgghd3.c 44 kB

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