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.

sgghrd.c 19 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656
  1. #include <math.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <stdio.h>
  5. #include <complex.h>
  6. #ifdef complex
  7. #undef complex
  8. #endif
  9. #ifdef I
  10. #undef I
  11. #endif
  12. #if defined(_WIN64)
  13. typedef long long BLASLONG;
  14. typedef unsigned long long BLASULONG;
  15. #else
  16. typedef long BLASLONG;
  17. typedef unsigned long BLASULONG;
  18. #endif
  19. #ifdef LAPACK_ILP64
  20. typedef BLASLONG blasint;
  21. #if defined(_WIN64)
  22. #define blasabs(x) llabs(x)
  23. #else
  24. #define blasabs(x) labs(x)
  25. #endif
  26. #else
  27. typedef int blasint;
  28. #define blasabs(x) abs(x)
  29. #endif
  30. typedef blasint integer;
  31. typedef unsigned int uinteger;
  32. typedef char *address;
  33. typedef short int shortint;
  34. typedef float real;
  35. typedef double doublereal;
  36. typedef struct { real r, i; } complex;
  37. typedef struct { doublereal r, i; } doublecomplex;
  38. #ifdef _MSC_VER
  39. static inline _Fcomplex Cf(complex *z) {_Fcomplex zz={z->r , z->i}; return zz;}
  40. static inline _Dcomplex Cd(doublecomplex *z) {_Dcomplex zz={z->r , z->i};return zz;}
  41. static inline _Fcomplex * _pCf(complex *z) {return (_Fcomplex*)z;}
  42. static inline _Dcomplex * _pCd(doublecomplex *z) {return (_Dcomplex*)z;}
  43. #else
  44. static inline _Complex float Cf(complex *z) {return z->r + z->i*_Complex_I;}
  45. static inline _Complex double Cd(doublecomplex *z) {return z->r + z->i*_Complex_I;}
  46. static inline _Complex float * _pCf(complex *z) {return (_Complex float*)z;}
  47. static inline _Complex double * _pCd(doublecomplex *z) {return (_Complex double*)z;}
  48. #endif
  49. #define pCf(z) (*_pCf(z))
  50. #define pCd(z) (*_pCd(z))
  51. typedef blasint logical;
  52. typedef char logical1;
  53. typedef char integer1;
  54. #define TRUE_ (1)
  55. #define FALSE_ (0)
  56. /* Extern is for use with -E */
  57. #ifndef Extern
  58. #define Extern extern
  59. #endif
  60. /* I/O stuff */
  61. typedef int flag;
  62. typedef int ftnlen;
  63. typedef int ftnint;
  64. /*external read, write*/
  65. typedef struct
  66. { flag cierr;
  67. ftnint ciunit;
  68. flag ciend;
  69. char *cifmt;
  70. ftnint cirec;
  71. } cilist;
  72. /*internal read, write*/
  73. typedef struct
  74. { flag icierr;
  75. char *iciunit;
  76. flag iciend;
  77. char *icifmt;
  78. ftnint icirlen;
  79. ftnint icirnum;
  80. } icilist;
  81. /*open*/
  82. typedef struct
  83. { flag oerr;
  84. ftnint ounit;
  85. char *ofnm;
  86. ftnlen ofnmlen;
  87. char *osta;
  88. char *oacc;
  89. char *ofm;
  90. ftnint orl;
  91. char *oblnk;
  92. } olist;
  93. /*close*/
  94. typedef struct
  95. { flag cerr;
  96. ftnint cunit;
  97. char *csta;
  98. } cllist;
  99. /*rewind, backspace, endfile*/
  100. typedef struct
  101. { flag aerr;
  102. ftnint aunit;
  103. } alist;
  104. /* inquire */
  105. typedef struct
  106. { flag inerr;
  107. ftnint inunit;
  108. char *infile;
  109. ftnlen infilen;
  110. ftnint *inex; /*parameters in standard's order*/
  111. ftnint *inopen;
  112. ftnint *innum;
  113. ftnint *innamed;
  114. char *inname;
  115. ftnlen innamlen;
  116. char *inacc;
  117. ftnlen inacclen;
  118. char *inseq;
  119. ftnlen inseqlen;
  120. char *indir;
  121. ftnlen indirlen;
  122. char *infmt;
  123. ftnlen infmtlen;
  124. char *inform;
  125. ftnint informlen;
  126. char *inunf;
  127. ftnlen inunflen;
  128. ftnint *inrecl;
  129. ftnint *innrec;
  130. char *inblank;
  131. ftnlen inblanklen;
  132. } inlist;
  133. #define VOID void
  134. union Multitype { /* for multiple entry points */
  135. integer1 g;
  136. shortint h;
  137. integer i;
  138. /* longint j; */
  139. real r;
  140. doublereal d;
  141. complex c;
  142. doublecomplex z;
  143. };
  144. typedef union Multitype Multitype;
  145. struct Vardesc { /* for Namelist */
  146. char *name;
  147. char *addr;
  148. ftnlen *dims;
  149. int type;
  150. };
  151. typedef struct Vardesc Vardesc;
  152. struct Namelist {
  153. char *name;
  154. Vardesc **vars;
  155. int nvars;
  156. };
  157. typedef struct Namelist Namelist;
  158. #define abs(x) ((x) >= 0 ? (x) : -(x))
  159. #define dabs(x) (fabs(x))
  160. #define f2cmin(a,b) ((a) <= (b) ? (a) : (b))
  161. #define f2cmax(a,b) ((a) >= (b) ? (a) : (b))
  162. #define dmin(a,b) (f2cmin(a,b))
  163. #define dmax(a,b) (f2cmax(a,b))
  164. #define bit_test(a,b) ((a) >> (b) & 1)
  165. #define bit_clear(a,b) ((a) & ~((uinteger)1 << (b)))
  166. #define bit_set(a,b) ((a) | ((uinteger)1 << (b)))
  167. #define abort_() { sig_die("Fortran abort routine called", 1); }
  168. #define c_abs(z) (cabsf(Cf(z)))
  169. #define c_cos(R,Z) { pCf(R)=ccos(Cf(Z)); }
  170. #ifdef _MSC_VER
  171. #define c_div(c, a, b) {Cf(c)._Val[0] = (Cf(a)._Val[0]/Cf(b)._Val[0]); Cf(c)._Val[1]=(Cf(a)._Val[1]/Cf(b)._Val[1]);}
  172. #define z_div(c, a, b) {Cd(c)._Val[0] = (Cd(a)._Val[0]/Cd(b)._Val[0]); Cd(c)._Val[1]=(Cd(a)._Val[1]/df(b)._Val[1]);}
  173. #else
  174. #define c_div(c, a, b) {pCf(c) = Cf(a)/Cf(b);}
  175. #define z_div(c, a, b) {pCd(c) = Cd(a)/Cd(b);}
  176. #endif
  177. #define c_exp(R, Z) {pCf(R) = cexpf(Cf(Z));}
  178. #define c_log(R, Z) {pCf(R) = clogf(Cf(Z));}
  179. #define c_sin(R, Z) {pCf(R) = csinf(Cf(Z));}
  180. //#define c_sqrt(R, Z) {*(R) = csqrtf(Cf(Z));}
  181. #define c_sqrt(R, Z) {pCf(R) = csqrtf(Cf(Z));}
  182. #define d_abs(x) (fabs(*(x)))
  183. #define d_acos(x) (acos(*(x)))
  184. #define d_asin(x) (asin(*(x)))
  185. #define d_atan(x) (atan(*(x)))
  186. #define d_atn2(x, y) (atan2(*(x),*(y)))
  187. #define d_cnjg(R, Z) { pCd(R) = conj(Cd(Z)); }
  188. #define r_cnjg(R, Z) { pCf(R) = conjf(Cf(Z)); }
  189. #define d_cos(x) (cos(*(x)))
  190. #define d_cosh(x) (cosh(*(x)))
  191. #define d_dim(__a, __b) ( *(__a) > *(__b) ? *(__a) - *(__b) : 0.0 )
  192. #define d_exp(x) (exp(*(x)))
  193. #define d_imag(z) (cimag(Cd(z)))
  194. #define r_imag(z) (cimagf(Cf(z)))
  195. #define d_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
  196. #define r_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
  197. #define d_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
  198. #define r_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
  199. #define d_log(x) (log(*(x)))
  200. #define d_mod(x, y) (fmod(*(x), *(y)))
  201. #define u_nint(__x) ((__x)>=0 ? floor((__x) + .5) : -floor(.5 - (__x)))
  202. #define d_nint(x) u_nint(*(x))
  203. #define u_sign(__a,__b) ((__b) >= 0 ? ((__a) >= 0 ? (__a) : -(__a)) : -((__a) >= 0 ? (__a) : -(__a)))
  204. #define d_sign(a,b) u_sign(*(a),*(b))
  205. #define r_sign(a,b) u_sign(*(a),*(b))
  206. #define d_sin(x) (sin(*(x)))
  207. #define d_sinh(x) (sinh(*(x)))
  208. #define d_sqrt(x) (sqrt(*(x)))
  209. #define d_tan(x) (tan(*(x)))
  210. #define d_tanh(x) (tanh(*(x)))
  211. #define i_abs(x) abs(*(x))
  212. #define i_dnnt(x) ((integer)u_nint(*(x)))
  213. #define i_len(s, n) (n)
  214. #define i_nint(x) ((integer)u_nint(*(x)))
  215. #define i_sign(a,b) ((integer)u_sign((integer)*(a),(integer)*(b)))
  216. #define 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++ = ' '; }
  217. #define s_cmp(a,b,c,d) ((integer)strncmp((a),(b),f2cmin((c),(d))))
  218. #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]; }
  219. #define sig_die(s, kill) { exit(1); }
  220. #define s_stop(s, n) {exit(0);}
  221. #define z_abs(z) (cabs(Cd(z)))
  222. #define z_exp(R, Z) {pCd(R) = cexp(Cd(Z));}
  223. #define z_sqrt(R, Z) {pCd(R) = csqrt(Cd(Z));}
  224. #define myexit_() break;
  225. #define mycycle() continue;
  226. #define myceiling(w) {ceil(w)}
  227. #define myhuge(w) {HUGE_VAL}
  228. //#define mymaxloc_(w,s,e,n) {if (sizeof(*(w)) == sizeof(double)) dmaxloc_((w),*(s),*(e),n); else dmaxloc_((w),*(s),*(e),n);}
  229. #define mymaxloc(w,s,e,n) {dmaxloc_(w,*(s),*(e),n)}
  230. /* -- translated by f2c (version 20000121).
  231. You must link the resulting object file with the libraries:
  232. -lf2c -lm (in that order)
  233. */
  234. /* Table of constant values */
  235. static real c_b10 = 0.f;
  236. static real c_b11 = 1.f;
  237. static integer c__1 = 1;
  238. /* > \brief \b SGGHRD */
  239. /* =========== DOCUMENTATION =========== */
  240. /* Online html documentation available at */
  241. /* http://www.netlib.org/lapack/explore-html/ */
  242. /* > \htmlonly */
  243. /* > Download SGGHRD + dependencies */
  244. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/sgghrd.
  245. f"> */
  246. /* > [TGZ]</a> */
  247. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/sgghrd.
  248. f"> */
  249. /* > [ZIP]</a> */
  250. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/sgghrd.
  251. f"> */
  252. /* > [TXT]</a> */
  253. /* > \endhtmlonly */
  254. /* Definition: */
  255. /* =========== */
  256. /* SUBROUTINE SGGHRD( COMPQ, COMPZ, N, ILO, IHI, A, LDA, B, LDB, Q, */
  257. /* LDQ, Z, LDZ, INFO ) */
  258. /* CHARACTER COMPQ, COMPZ */
  259. /* INTEGER IHI, ILO, INFO, LDA, LDB, LDQ, LDZ, N */
  260. /* REAL A( LDA, * ), B( LDB, * ), Q( LDQ, * ), */
  261. /* $ Z( LDZ, * ) */
  262. /* > \par Purpose: */
  263. /* ============= */
  264. /* > */
  265. /* > \verbatim */
  266. /* > */
  267. /* > SGGHRD reduces a pair of real matrices (A,B) to generalized upper */
  268. /* > Hessenberg form using orthogonal transformations, where A is a */
  269. /* > general matrix and B is upper triangular. The form of the */
  270. /* > generalized eigenvalue problem is */
  271. /* > A*x = lambda*B*x, */
  272. /* > and B is typically made upper triangular by computing its QR */
  273. /* > factorization and moving the orthogonal matrix Q to the left side */
  274. /* > of the equation. */
  275. /* > */
  276. /* > This subroutine simultaneously reduces A to a Hessenberg matrix H: */
  277. /* > Q**T*A*Z = H */
  278. /* > and transforms B to another upper triangular matrix T: */
  279. /* > Q**T*B*Z = T */
  280. /* > in order to reduce the problem to its standard form */
  281. /* > H*y = lambda*T*y */
  282. /* > where y = Z**T*x. */
  283. /* > */
  284. /* > The orthogonal matrices Q and Z are determined as products of Givens */
  285. /* > rotations. They may either be formed explicitly, or they may be */
  286. /* > postmultiplied into input matrices Q1 and Z1, so that */
  287. /* > */
  288. /* > Q1 * A * Z1**T = (Q1*Q) * H * (Z1*Z)**T */
  289. /* > */
  290. /* > Q1 * B * Z1**T = (Q1*Q) * T * (Z1*Z)**T */
  291. /* > */
  292. /* > If Q1 is the orthogonal matrix from the QR factorization of B in the */
  293. /* > original equation A*x = lambda*B*x, then SGGHRD reduces the original */
  294. /* > problem to generalized Hessenberg form. */
  295. /* > \endverbatim */
  296. /* Arguments: */
  297. /* ========== */
  298. /* > \param[in] COMPQ */
  299. /* > \verbatim */
  300. /* > COMPQ is CHARACTER*1 */
  301. /* > = 'N': do not compute Q; */
  302. /* > = 'I': Q is initialized to the unit matrix, and the */
  303. /* > orthogonal matrix Q is returned; */
  304. /* > = 'V': Q must contain an orthogonal matrix Q1 on entry, */
  305. /* > and the product Q1*Q is returned. */
  306. /* > \endverbatim */
  307. /* > */
  308. /* > \param[in] COMPZ */
  309. /* > \verbatim */
  310. /* > COMPZ is CHARACTER*1 */
  311. /* > = 'N': do not compute Z; */
  312. /* > = 'I': Z is initialized to the unit matrix, and the */
  313. /* > orthogonal matrix Z is returned; */
  314. /* > = 'V': Z must contain an orthogonal matrix Z1 on entry, */
  315. /* > and the product Z1*Z is returned. */
  316. /* > \endverbatim */
  317. /* > */
  318. /* > \param[in] N */
  319. /* > \verbatim */
  320. /* > N is INTEGER */
  321. /* > The order of the matrices A and B. N >= 0. */
  322. /* > \endverbatim */
  323. /* > */
  324. /* > \param[in] ILO */
  325. /* > \verbatim */
  326. /* > ILO is INTEGER */
  327. /* > \endverbatim */
  328. /* > */
  329. /* > \param[in] IHI */
  330. /* > \verbatim */
  331. /* > IHI is INTEGER */
  332. /* > */
  333. /* > ILO and IHI mark the rows and columns of A which are to be */
  334. /* > reduced. It is assumed that A is already upper triangular */
  335. /* > in rows and columns 1:ILO-1 and IHI+1:N. ILO and IHI are */
  336. /* > normally set by a previous call to SGGBAL; otherwise they */
  337. /* > should be set to 1 and N respectively. */
  338. /* > 1 <= ILO <= IHI <= N, if N > 0; ILO=1 and IHI=0, if N=0. */
  339. /* > \endverbatim */
  340. /* > */
  341. /* > \param[in,out] A */
  342. /* > \verbatim */
  343. /* > A is REAL array, dimension (LDA, N) */
  344. /* > On entry, the N-by-N general matrix to be reduced. */
  345. /* > On exit, the upper triangle and the first subdiagonal of A */
  346. /* > are overwritten with the upper Hessenberg matrix H, and the */
  347. /* > rest is set to zero. */
  348. /* > \endverbatim */
  349. /* > */
  350. /* > \param[in] LDA */
  351. /* > \verbatim */
  352. /* > LDA is INTEGER */
  353. /* > The leading dimension of the array A. LDA >= f2cmax(1,N). */
  354. /* > \endverbatim */
  355. /* > */
  356. /* > \param[in,out] B */
  357. /* > \verbatim */
  358. /* > B is REAL array, dimension (LDB, N) */
  359. /* > On entry, the N-by-N upper triangular matrix B. */
  360. /* > On exit, the upper triangular matrix T = Q**T B Z. The */
  361. /* > elements below the diagonal are set to zero. */
  362. /* > \endverbatim */
  363. /* > */
  364. /* > \param[in] LDB */
  365. /* > \verbatim */
  366. /* > LDB is INTEGER */
  367. /* > The leading dimension of the array B. LDB >= f2cmax(1,N). */
  368. /* > \endverbatim */
  369. /* > */
  370. /* > \param[in,out] Q */
  371. /* > \verbatim */
  372. /* > Q is REAL array, dimension (LDQ, N) */
  373. /* > On entry, if COMPQ = 'V', the orthogonal matrix Q1, */
  374. /* > typically from the QR factorization of B. */
  375. /* > On exit, if COMPQ='I', the orthogonal matrix Q, and if */
  376. /* > COMPQ = 'V', the product Q1*Q. */
  377. /* > Not referenced if COMPQ='N'. */
  378. /* > \endverbatim */
  379. /* > */
  380. /* > \param[in] LDQ */
  381. /* > \verbatim */
  382. /* > LDQ is INTEGER */
  383. /* > The leading dimension of the array Q. */
  384. /* > LDQ >= N if COMPQ='V' or 'I'; LDQ >= 1 otherwise. */
  385. /* > \endverbatim */
  386. /* > */
  387. /* > \param[in,out] Z */
  388. /* > \verbatim */
  389. /* > Z is REAL array, dimension (LDZ, N) */
  390. /* > On entry, if COMPZ = 'V', the orthogonal matrix Z1. */
  391. /* > On exit, if COMPZ='I', the orthogonal matrix Z, and if */
  392. /* > COMPZ = 'V', the product Z1*Z. */
  393. /* > Not referenced if COMPZ='N'. */
  394. /* > \endverbatim */
  395. /* > */
  396. /* > \param[in] LDZ */
  397. /* > \verbatim */
  398. /* > LDZ is INTEGER */
  399. /* > The leading dimension of the array Z. */
  400. /* > LDZ >= N if COMPZ='V' or 'I'; LDZ >= 1 otherwise. */
  401. /* > \endverbatim */
  402. /* > */
  403. /* > \param[out] INFO */
  404. /* > \verbatim */
  405. /* > INFO is INTEGER */
  406. /* > = 0: successful exit. */
  407. /* > < 0: if INFO = -i, the i-th argument had an illegal value. */
  408. /* > \endverbatim */
  409. /* Authors: */
  410. /* ======== */
  411. /* > \author Univ. of Tennessee */
  412. /* > \author Univ. of California Berkeley */
  413. /* > \author Univ. of Colorado Denver */
  414. /* > \author NAG Ltd. */
  415. /* > \date December 2016 */
  416. /* > \ingroup realOTHERcomputational */
  417. /* > \par Further Details: */
  418. /* ===================== */
  419. /* > */
  420. /* > \verbatim */
  421. /* > */
  422. /* > This routine reduces A to Hessenberg and B to triangular form by */
  423. /* > an unblocked reduction, as described in _Matrix_Computations_, */
  424. /* > by Golub and Van Loan (Johns Hopkins Press.) */
  425. /* > \endverbatim */
  426. /* > */
  427. /* ===================================================================== */
  428. /* Subroutine */ void sgghrd_(char *compq, char *compz, integer *n, integer *
  429. ilo, integer *ihi, real *a, integer *lda, real *b, integer *ldb, real
  430. *q, integer *ldq, real *z__, integer *ldz, integer *info)
  431. {
  432. /* System generated locals */
  433. integer a_dim1, a_offset, b_dim1, b_offset, q_dim1, q_offset, z_dim1,
  434. z_offset, i__1, i__2, i__3;
  435. /* Local variables */
  436. integer jcol;
  437. real temp;
  438. integer jrow;
  439. extern /* Subroutine */ void srot_(integer *, real *, integer *, real *,
  440. integer *, real *, real *);
  441. real c__, s;
  442. extern logical lsame_(char *, char *);
  443. extern /* Subroutine */ int xerbla_(char *, integer *, ftnlen);
  444. integer icompq;
  445. extern /* Subroutine */ void slaset_(char *, integer *, integer *, real *,
  446. real *, real *, integer *), slartg_(real *, real *, real *
  447. , real *, real *);
  448. integer icompz;
  449. logical ilq, ilz;
  450. /* -- LAPACK computational routine (version 3.7.0) -- */
  451. /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
  452. /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
  453. /* December 2016 */
  454. /* ===================================================================== */
  455. /* Decode COMPQ */
  456. /* Parameter adjustments */
  457. a_dim1 = *lda;
  458. a_offset = 1 + a_dim1 * 1;
  459. a -= a_offset;
  460. b_dim1 = *ldb;
  461. b_offset = 1 + b_dim1 * 1;
  462. b -= b_offset;
  463. q_dim1 = *ldq;
  464. q_offset = 1 + q_dim1 * 1;
  465. q -= q_offset;
  466. z_dim1 = *ldz;
  467. z_offset = 1 + z_dim1 * 1;
  468. z__ -= z_offset;
  469. /* Function Body */
  470. if (lsame_(compq, "N")) {
  471. ilq = FALSE_;
  472. icompq = 1;
  473. } else if (lsame_(compq, "V")) {
  474. ilq = TRUE_;
  475. icompq = 2;
  476. } else if (lsame_(compq, "I")) {
  477. ilq = TRUE_;
  478. icompq = 3;
  479. } else {
  480. icompq = 0;
  481. }
  482. /* Decode COMPZ */
  483. if (lsame_(compz, "N")) {
  484. ilz = FALSE_;
  485. icompz = 1;
  486. } else if (lsame_(compz, "V")) {
  487. ilz = TRUE_;
  488. icompz = 2;
  489. } else if (lsame_(compz, "I")) {
  490. ilz = TRUE_;
  491. icompz = 3;
  492. } else {
  493. icompz = 0;
  494. }
  495. /* Test the input parameters. */
  496. *info = 0;
  497. if (icompq <= 0) {
  498. *info = -1;
  499. } else if (icompz <= 0) {
  500. *info = -2;
  501. } else if (*n < 0) {
  502. *info = -3;
  503. } else if (*ilo < 1) {
  504. *info = -4;
  505. } else if (*ihi > *n || *ihi < *ilo - 1) {
  506. *info = -5;
  507. } else if (*lda < f2cmax(1,*n)) {
  508. *info = -7;
  509. } else if (*ldb < f2cmax(1,*n)) {
  510. *info = -9;
  511. } else if (ilq && *ldq < *n || *ldq < 1) {
  512. *info = -11;
  513. } else if (ilz && *ldz < *n || *ldz < 1) {
  514. *info = -13;
  515. }
  516. if (*info != 0) {
  517. i__1 = -(*info);
  518. xerbla_("SGGHRD", &i__1, (ftnlen)6);
  519. return;
  520. }
  521. /* Initialize Q and Z if desired. */
  522. if (icompq == 3) {
  523. slaset_("Full", n, n, &c_b10, &c_b11, &q[q_offset], ldq);
  524. }
  525. if (icompz == 3) {
  526. slaset_("Full", n, n, &c_b10, &c_b11, &z__[z_offset], ldz);
  527. }
  528. /* Quick return if possible */
  529. if (*n <= 1) {
  530. return;
  531. }
  532. /* Zero out lower triangle of B */
  533. i__1 = *n - 1;
  534. for (jcol = 1; jcol <= i__1; ++jcol) {
  535. i__2 = *n;
  536. for (jrow = jcol + 1; jrow <= i__2; ++jrow) {
  537. b[jrow + jcol * b_dim1] = 0.f;
  538. /* L10: */
  539. }
  540. /* L20: */
  541. }
  542. /* Reduce A and B */
  543. i__1 = *ihi - 2;
  544. for (jcol = *ilo; jcol <= i__1; ++jcol) {
  545. i__2 = jcol + 2;
  546. for (jrow = *ihi; jrow >= i__2; --jrow) {
  547. /* Step 1: rotate rows JROW-1, JROW to kill A(JROW,JCOL) */
  548. temp = a[jrow - 1 + jcol * a_dim1];
  549. slartg_(&temp, &a[jrow + jcol * a_dim1], &c__, &s, &a[jrow - 1 +
  550. jcol * a_dim1]);
  551. a[jrow + jcol * a_dim1] = 0.f;
  552. i__3 = *n - jcol;
  553. srot_(&i__3, &a[jrow - 1 + (jcol + 1) * a_dim1], lda, &a[jrow + (
  554. jcol + 1) * a_dim1], lda, &c__, &s);
  555. i__3 = *n + 2 - jrow;
  556. srot_(&i__3, &b[jrow - 1 + (jrow - 1) * b_dim1], ldb, &b[jrow + (
  557. jrow - 1) * b_dim1], ldb, &c__, &s);
  558. if (ilq) {
  559. srot_(n, &q[(jrow - 1) * q_dim1 + 1], &c__1, &q[jrow * q_dim1
  560. + 1], &c__1, &c__, &s);
  561. }
  562. /* Step 2: rotate columns JROW, JROW-1 to kill B(JROW,JROW-1) */
  563. temp = b[jrow + jrow * b_dim1];
  564. slartg_(&temp, &b[jrow + (jrow - 1) * b_dim1], &c__, &s, &b[jrow
  565. + jrow * b_dim1]);
  566. b[jrow + (jrow - 1) * b_dim1] = 0.f;
  567. srot_(ihi, &a[jrow * a_dim1 + 1], &c__1, &a[(jrow - 1) * a_dim1 +
  568. 1], &c__1, &c__, &s);
  569. i__3 = jrow - 1;
  570. srot_(&i__3, &b[jrow * b_dim1 + 1], &c__1, &b[(jrow - 1) * b_dim1
  571. + 1], &c__1, &c__, &s);
  572. if (ilz) {
  573. srot_(n, &z__[jrow * z_dim1 + 1], &c__1, &z__[(jrow - 1) *
  574. z_dim1 + 1], &c__1, &c__, &s);
  575. }
  576. /* L30: */
  577. }
  578. /* L40: */
  579. }
  580. return;
  581. /* End of SGGHRD */
  582. } /* sgghrd_ */