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.

clagge.c 22 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782
  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 char integer1;
  52. #define TRUE_ (1)
  53. #define FALSE_ (0)
  54. /* Extern is for use with -E */
  55. #ifndef Extern
  56. #define Extern extern
  57. #endif
  58. /* I/O stuff */
  59. typedef int flag;
  60. typedef int ftnlen;
  61. typedef int ftnint;
  62. /*external read, write*/
  63. typedef struct
  64. { flag cierr;
  65. ftnint ciunit;
  66. flag ciend;
  67. char *cifmt;
  68. ftnint cirec;
  69. } cilist;
  70. /*internal read, write*/
  71. typedef struct
  72. { flag icierr;
  73. char *iciunit;
  74. flag iciend;
  75. char *icifmt;
  76. ftnint icirlen;
  77. ftnint icirnum;
  78. } icilist;
  79. /*open*/
  80. typedef struct
  81. { flag oerr;
  82. ftnint ounit;
  83. char *ofnm;
  84. ftnlen ofnmlen;
  85. char *osta;
  86. char *oacc;
  87. char *ofm;
  88. ftnint orl;
  89. char *oblnk;
  90. } olist;
  91. /*close*/
  92. typedef struct
  93. { flag cerr;
  94. ftnint cunit;
  95. char *csta;
  96. } cllist;
  97. /*rewind, backspace, endfile*/
  98. typedef struct
  99. { flag aerr;
  100. ftnint aunit;
  101. } alist;
  102. /* inquire */
  103. typedef struct
  104. { flag inerr;
  105. ftnint inunit;
  106. char *infile;
  107. ftnlen infilen;
  108. ftnint *inex; /*parameters in standard's order*/
  109. ftnint *inopen;
  110. ftnint *innum;
  111. ftnint *innamed;
  112. char *inname;
  113. ftnlen innamlen;
  114. char *inacc;
  115. ftnlen inacclen;
  116. char *inseq;
  117. ftnlen inseqlen;
  118. char *indir;
  119. ftnlen indirlen;
  120. char *infmt;
  121. ftnlen infmtlen;
  122. char *inform;
  123. ftnint informlen;
  124. char *inunf;
  125. ftnlen inunflen;
  126. ftnint *inrecl;
  127. ftnint *innrec;
  128. char *inblank;
  129. ftnlen inblanklen;
  130. } inlist;
  131. #define VOID void
  132. union Multitype { /* for multiple entry points */
  133. integer1 g;
  134. shortint h;
  135. integer i;
  136. /* longint j; */
  137. real r;
  138. doublereal d;
  139. complex c;
  140. doublecomplex z;
  141. };
  142. typedef union Multitype Multitype;
  143. struct Vardesc { /* for Namelist */
  144. char *name;
  145. char *addr;
  146. ftnlen *dims;
  147. int type;
  148. };
  149. typedef struct Vardesc Vardesc;
  150. struct Namelist {
  151. char *name;
  152. Vardesc **vars;
  153. int nvars;
  154. };
  155. typedef struct Namelist Namelist;
  156. #define abs(x) ((x) >= 0 ? (x) : -(x))
  157. #define dabs(x) (fabs(x))
  158. #define f2cmin(a,b) ((a) <= (b) ? (a) : (b))
  159. #define f2cmax(a,b) ((a) >= (b) ? (a) : (b))
  160. #define dmin(a,b) (f2cmin(a,b))
  161. #define dmax(a,b) (f2cmax(a,b))
  162. #define bit_test(a,b) ((a) >> (b) & 1)
  163. #define bit_clear(a,b) ((a) & ~((uinteger)1 << (b)))
  164. #define bit_set(a,b) ((a) | ((uinteger)1 << (b)))
  165. #define abort_() { sig_die("Fortran abort routine called", 1); }
  166. #define c_abs(z) (cabsf(Cf(z)))
  167. #define c_cos(R,Z) { pCf(R)=ccos(Cf(Z)); }
  168. #ifdef _MSC_VER
  169. #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]);}
  170. #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]);}
  171. #else
  172. #define c_div(c, a, b) {pCf(c) = Cf(a)/Cf(b);}
  173. #define z_div(c, a, b) {pCd(c) = Cd(a)/Cd(b);}
  174. #endif
  175. #define c_exp(R, Z) {pCf(R) = cexpf(Cf(Z));}
  176. #define c_log(R, Z) {pCf(R) = clogf(Cf(Z));}
  177. #define c_sin(R, Z) {pCf(R) = csinf(Cf(Z));}
  178. //#define c_sqrt(R, Z) {*(R) = csqrtf(Cf(Z));}
  179. #define c_sqrt(R, Z) {pCf(R) = csqrtf(Cf(Z));}
  180. #define d_abs(x) (fabs(*(x)))
  181. #define d_acos(x) (acos(*(x)))
  182. #define d_asin(x) (asin(*(x)))
  183. #define d_atan(x) (atan(*(x)))
  184. #define d_atn2(x, y) (atan2(*(x),*(y)))
  185. #define d_cnjg(R, Z) { pCd(R) = conj(Cd(Z)); }
  186. #define r_cnjg(R, Z) { pCf(R) = conjf(Cf(Z)); }
  187. #define d_cos(x) (cos(*(x)))
  188. #define d_cosh(x) (cosh(*(x)))
  189. #define d_dim(__a, __b) ( *(__a) > *(__b) ? *(__a) - *(__b) : 0.0 )
  190. #define d_exp(x) (exp(*(x)))
  191. #define d_imag(z) (cimag(Cd(z)))
  192. #define r_imag(z) (cimagf(Cf(z)))
  193. #define d_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
  194. #define r_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
  195. #define d_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
  196. #define r_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
  197. #define d_log(x) (log(*(x)))
  198. #define d_mod(x, y) (fmod(*(x), *(y)))
  199. #define u_nint(__x) ((__x)>=0 ? floor((__x) + .5) : -floor(.5 - (__x)))
  200. #define d_nint(x) u_nint(*(x))
  201. #define u_sign(__a,__b) ((__b) >= 0 ? ((__a) >= 0 ? (__a) : -(__a)) : -((__a) >= 0 ? (__a) : -(__a)))
  202. #define d_sign(a,b) u_sign(*(a),*(b))
  203. #define r_sign(a,b) u_sign(*(a),*(b))
  204. #define d_sin(x) (sin(*(x)))
  205. #define d_sinh(x) (sinh(*(x)))
  206. #define d_sqrt(x) (sqrt(*(x)))
  207. #define d_tan(x) (tan(*(x)))
  208. #define d_tanh(x) (tanh(*(x)))
  209. #define i_abs(x) abs(*(x))
  210. #define i_dnnt(x) ((integer)u_nint(*(x)))
  211. #define i_len(s, n) (n)
  212. #define i_nint(x) ((integer)u_nint(*(x)))
  213. #define i_sign(a,b) ((integer)u_sign((integer)*(a),(integer)*(b)))
  214. #define pow_dd(ap, bp) ( pow(*(ap), *(bp)))
  215. #define pow_si(B,E) spow_ui(*(B),*(E))
  216. #define pow_ri(B,E) spow_ui(*(B),*(E))
  217. #define pow_di(B,E) dpow_ui(*(B),*(E))
  218. #define pow_zi(p, a, b) {pCd(p) = zpow_ui(Cd(a), *(b));}
  219. #define pow_ci(p, a, b) {pCf(p) = cpow_ui(Cf(a), *(b));}
  220. #define pow_zz(R,A,B) {pCd(R) = cpow(Cd(A),*(B));}
  221. #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++ = ' '; }
  222. #define s_cmp(a,b,c,d) ((integer)strncmp((a),(b),f2cmin((c),(d))))
  223. #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]; }
  224. #define sig_die(s, kill) { exit(1); }
  225. #define s_stop(s, n) {exit(0);}
  226. #define z_abs(z) (cabs(Cd(z)))
  227. #define z_exp(R, Z) {pCd(R) = cexp(Cd(Z));}
  228. #define z_sqrt(R, Z) {pCd(R) = csqrt(Cd(Z));}
  229. #define myexit_() break;
  230. #define mycycle() continue;
  231. #define myceiling(w) {ceil(w)}
  232. #define myhuge(w) {HUGE_VAL}
  233. //#define mymaxloc_(w,s,e,n) {if (sizeof(*(w)) == sizeof(double)) dmaxloc_((w),*(s),*(e),n); else dmaxloc_((w),*(s),*(e),n);}
  234. #define mymaxloc(w,s,e,n) {dmaxloc_(w,*(s),*(e),n)}
  235. /* procedure parameter types for -A and -C++ */
  236. /* Table of constant values */
  237. static complex c_b1 = {0.f,0.f};
  238. static complex c_b2 = {1.f,0.f};
  239. static integer c__3 = 3;
  240. static integer c__1 = 1;
  241. /* > \brief \b CLAGGE */
  242. /* =========== DOCUMENTATION =========== */
  243. /* Online html documentation available at */
  244. /* http://www.netlib.org/lapack/explore-html/ */
  245. /* Definition: */
  246. /* =========== */
  247. /* SUBROUTINE CLAGGE( M, N, KL, KU, D, A, LDA, ISEED, WORK, INFO ) */
  248. /* INTEGER INFO, KL, KU, LDA, M, N */
  249. /* INTEGER ISEED( 4 ) */
  250. /* REAL D( * ) */
  251. /* COMPLEX A( LDA, * ), WORK( * ) */
  252. /* > \par Purpose: */
  253. /* ============= */
  254. /* > */
  255. /* > \verbatim */
  256. /* > */
  257. /* > CLAGGE generates a complex general m by n matrix A, by pre- and post- */
  258. /* > multiplying a real diagonal matrix D with random unitary matrices: */
  259. /* > A = U*D*V. The lower and upper bandwidths may then be reduced to */
  260. /* > kl and ku by additional unitary transformations. */
  261. /* > \endverbatim */
  262. /* Arguments: */
  263. /* ========== */
  264. /* > \param[in] M */
  265. /* > \verbatim */
  266. /* > M is INTEGER */
  267. /* > The number of rows of the matrix A. M >= 0. */
  268. /* > \endverbatim */
  269. /* > */
  270. /* > \param[in] N */
  271. /* > \verbatim */
  272. /* > N is INTEGER */
  273. /* > The number of columns of the matrix A. N >= 0. */
  274. /* > \endverbatim */
  275. /* > */
  276. /* > \param[in] KL */
  277. /* > \verbatim */
  278. /* > KL is INTEGER */
  279. /* > The number of nonzero subdiagonals within the band of A. */
  280. /* > 0 <= KL <= M-1. */
  281. /* > \endverbatim */
  282. /* > */
  283. /* > \param[in] KU */
  284. /* > \verbatim */
  285. /* > KU is INTEGER */
  286. /* > The number of nonzero superdiagonals within the band of A. */
  287. /* > 0 <= KU <= N-1. */
  288. /* > \endverbatim */
  289. /* > */
  290. /* > \param[in] D */
  291. /* > \verbatim */
  292. /* > D is REAL array, dimension (f2cmin(M,N)) */
  293. /* > The diagonal elements of the diagonal matrix D. */
  294. /* > \endverbatim */
  295. /* > */
  296. /* > \param[out] A */
  297. /* > \verbatim */
  298. /* > A is COMPLEX array, dimension (LDA,N) */
  299. /* > The generated m by n matrix A. */
  300. /* > \endverbatim */
  301. /* > */
  302. /* > \param[in] LDA */
  303. /* > \verbatim */
  304. /* > LDA is INTEGER */
  305. /* > The leading dimension of the array A. LDA >= M. */
  306. /* > \endverbatim */
  307. /* > */
  308. /* > \param[in,out] ISEED */
  309. /* > \verbatim */
  310. /* > ISEED is INTEGER array, dimension (4) */
  311. /* > On entry, the seed of the random number generator; the array */
  312. /* > elements must be between 0 and 4095, and ISEED(4) must be */
  313. /* > odd. */
  314. /* > On exit, the seed is updated. */
  315. /* > \endverbatim */
  316. /* > */
  317. /* > \param[out] WORK */
  318. /* > \verbatim */
  319. /* > WORK is COMPLEX array, dimension (M+N) */
  320. /* > \endverbatim */
  321. /* > */
  322. /* > \param[out] INFO */
  323. /* > \verbatim */
  324. /* > INFO is INTEGER */
  325. /* > = 0: successful exit */
  326. /* > < 0: if INFO = -i, the i-th argument had an illegal value */
  327. /* > \endverbatim */
  328. /* Authors: */
  329. /* ======== */
  330. /* > \author Univ. of Tennessee */
  331. /* > \author Univ. of California Berkeley */
  332. /* > \author Univ. of Colorado Denver */
  333. /* > \author NAG Ltd. */
  334. /* > \date December 2016 */
  335. /* > \ingroup complex_matgen */
  336. /* ===================================================================== */
  337. /* Subroutine */ void clagge_(integer *m, integer *n, integer *kl, integer *ku,
  338. real *d__, complex *a, integer *lda, integer *iseed, complex *work,
  339. integer *info)
  340. {
  341. /* System generated locals */
  342. integer a_dim1, a_offset, i__1, i__2, i__3;
  343. real r__1;
  344. complex q__1;
  345. /* Local variables */
  346. integer i__, j;
  347. extern /* Subroutine */ void cgerc_(integer *, integer *, complex *,
  348. complex *, integer *, complex *, integer *, complex *, integer *),
  349. cscal_(integer *, complex *, complex *, integer *), cgemv_(char *
  350. , integer *, integer *, complex *, complex *, integer *, complex *
  351. , integer *, complex *, complex *, integer *);
  352. extern real scnrm2_(integer *, complex *, integer *);
  353. complex wa, wb;
  354. extern /* Subroutine */ void clacgv_(integer *, complex *, integer *);
  355. real wn;
  356. extern /* Subroutine */ int xerbla_(char *, integer *, ftnlen);
  357. extern void clarnv_(
  358. integer *, integer *, integer *, complex *);
  359. complex tau;
  360. /* -- LAPACK auxiliary routine (version 3.7.0) -- */
  361. /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
  362. /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
  363. /* December 2016 */
  364. /* ===================================================================== */
  365. /* Test the input arguments */
  366. /* Parameter adjustments */
  367. --d__;
  368. a_dim1 = *lda;
  369. a_offset = 1 + a_dim1 * 1;
  370. a -= a_offset;
  371. --iseed;
  372. --work;
  373. /* Function Body */
  374. *info = 0;
  375. if (*m < 0) {
  376. *info = -1;
  377. } else if (*n < 0) {
  378. *info = -2;
  379. } else if (*kl < 0 || *kl > *m - 1) {
  380. *info = -3;
  381. } else if (*ku < 0 || *ku > *n - 1) {
  382. *info = -4;
  383. } else if (*lda < f2cmax(1,*m)) {
  384. *info = -7;
  385. }
  386. if (*info < 0) {
  387. i__1 = -(*info);
  388. xerbla_("CLAGGE", &i__1, 6);
  389. return;
  390. }
  391. /* initialize A to diagonal matrix */
  392. i__1 = *n;
  393. for (j = 1; j <= i__1; ++j) {
  394. i__2 = *m;
  395. for (i__ = 1; i__ <= i__2; ++i__) {
  396. i__3 = i__ + j * a_dim1;
  397. a[i__3].r = 0.f, a[i__3].i = 0.f;
  398. /* L10: */
  399. }
  400. /* L20: */
  401. }
  402. i__1 = f2cmin(*m,*n);
  403. for (i__ = 1; i__ <= i__1; ++i__) {
  404. i__2 = i__ + i__ * a_dim1;
  405. i__3 = i__;
  406. a[i__2].r = d__[i__3], a[i__2].i = 0.f;
  407. /* L30: */
  408. }
  409. /* Quick exit if the user wants a diagonal matrix */
  410. if (*kl == 0 && *ku == 0) {
  411. return;
  412. }
  413. /* pre- and post-multiply A by random unitary matrices */
  414. for (i__ = f2cmin(*m,*n); i__ >= 1; --i__) {
  415. if (i__ < *m) {
  416. /* generate random reflection */
  417. i__1 = *m - i__ + 1;
  418. clarnv_(&c__3, &iseed[1], &i__1, &work[1]);
  419. i__1 = *m - i__ + 1;
  420. wn = scnrm2_(&i__1, &work[1], &c__1);
  421. r__1 = wn / c_abs(&work[1]);
  422. q__1.r = r__1 * work[1].r, q__1.i = r__1 * work[1].i;
  423. wa.r = q__1.r, wa.i = q__1.i;
  424. if (wn == 0.f) {
  425. tau.r = 0.f, tau.i = 0.f;
  426. } else {
  427. q__1.r = work[1].r + wa.r, q__1.i = work[1].i + wa.i;
  428. wb.r = q__1.r, wb.i = q__1.i;
  429. i__1 = *m - i__;
  430. c_div(&q__1, &c_b2, &wb);
  431. cscal_(&i__1, &q__1, &work[2], &c__1);
  432. work[1].r = 1.f, work[1].i = 0.f;
  433. c_div(&q__1, &wb, &wa);
  434. r__1 = q__1.r;
  435. tau.r = r__1, tau.i = 0.f;
  436. }
  437. /* multiply A(i:m,i:n) by random reflection from the left */
  438. i__1 = *m - i__ + 1;
  439. i__2 = *n - i__ + 1;
  440. cgemv_("Conjugate transpose", &i__1, &i__2, &c_b2, &a[i__ + i__ *
  441. a_dim1], lda, &work[1], &c__1, &c_b1, &work[*m + 1], &
  442. c__1);
  443. i__1 = *m - i__ + 1;
  444. i__2 = *n - i__ + 1;
  445. q__1.r = -tau.r, q__1.i = -tau.i;
  446. cgerc_(&i__1, &i__2, &q__1, &work[1], &c__1, &work[*m + 1], &c__1,
  447. &a[i__ + i__ * a_dim1], lda);
  448. }
  449. if (i__ < *n) {
  450. /* generate random reflection */
  451. i__1 = *n - i__ + 1;
  452. clarnv_(&c__3, &iseed[1], &i__1, &work[1]);
  453. i__1 = *n - i__ + 1;
  454. wn = scnrm2_(&i__1, &work[1], &c__1);
  455. r__1 = wn / c_abs(&work[1]);
  456. q__1.r = r__1 * work[1].r, q__1.i = r__1 * work[1].i;
  457. wa.r = q__1.r, wa.i = q__1.i;
  458. if (wn == 0.f) {
  459. tau.r = 0.f, tau.i = 0.f;
  460. } else {
  461. q__1.r = work[1].r + wa.r, q__1.i = work[1].i + wa.i;
  462. wb.r = q__1.r, wb.i = q__1.i;
  463. i__1 = *n - i__;
  464. c_div(&q__1, &c_b2, &wb);
  465. cscal_(&i__1, &q__1, &work[2], &c__1);
  466. work[1].r = 1.f, work[1].i = 0.f;
  467. c_div(&q__1, &wb, &wa);
  468. r__1 = q__1.r;
  469. tau.r = r__1, tau.i = 0.f;
  470. }
  471. /* multiply A(i:m,i:n) by random reflection from the right */
  472. i__1 = *m - i__ + 1;
  473. i__2 = *n - i__ + 1;
  474. cgemv_("No transpose", &i__1, &i__2, &c_b2, &a[i__ + i__ * a_dim1]
  475. , lda, &work[1], &c__1, &c_b1, &work[*n + 1], &c__1);
  476. i__1 = *m - i__ + 1;
  477. i__2 = *n - i__ + 1;
  478. q__1.r = -tau.r, q__1.i = -tau.i;
  479. cgerc_(&i__1, &i__2, &q__1, &work[*n + 1], &c__1, &work[1], &c__1,
  480. &a[i__ + i__ * a_dim1], lda);
  481. }
  482. /* L40: */
  483. }
  484. /* Reduce number of subdiagonals to KL and number of superdiagonals */
  485. /* to KU */
  486. /* Computing MAX */
  487. i__2 = *m - 1 - *kl, i__3 = *n - 1 - *ku;
  488. i__1 = f2cmax(i__2,i__3);
  489. for (i__ = 1; i__ <= i__1; ++i__) {
  490. if (*kl <= *ku) {
  491. /* annihilate subdiagonal elements first (necessary if KL = 0) */
  492. /* Computing MIN */
  493. i__2 = *m - 1 - *kl;
  494. if (i__ <= f2cmin(i__2,*n)) {
  495. /* generate reflection to annihilate A(kl+i+1:m,i) */
  496. i__2 = *m - *kl - i__ + 1;
  497. wn = scnrm2_(&i__2, &a[*kl + i__ + i__ * a_dim1], &c__1);
  498. r__1 = wn / c_abs(&a[*kl + i__ + i__ * a_dim1]);
  499. i__2 = *kl + i__ + i__ * a_dim1;
  500. q__1.r = r__1 * a[i__2].r, q__1.i = r__1 * a[i__2].i;
  501. wa.r = q__1.r, wa.i = q__1.i;
  502. if (wn == 0.f) {
  503. tau.r = 0.f, tau.i = 0.f;
  504. } else {
  505. i__2 = *kl + i__ + i__ * a_dim1;
  506. q__1.r = a[i__2].r + wa.r, q__1.i = a[i__2].i + wa.i;
  507. wb.r = q__1.r, wb.i = q__1.i;
  508. i__2 = *m - *kl - i__;
  509. c_div(&q__1, &c_b2, &wb);
  510. cscal_(&i__2, &q__1, &a[*kl + i__ + 1 + i__ * a_dim1], &
  511. c__1);
  512. i__2 = *kl + i__ + i__ * a_dim1;
  513. a[i__2].r = 1.f, a[i__2].i = 0.f;
  514. c_div(&q__1, &wb, &wa);
  515. r__1 = q__1.r;
  516. tau.r = r__1, tau.i = 0.f;
  517. }
  518. /* apply reflection to A(kl+i:m,i+1:n) from the left */
  519. i__2 = *m - *kl - i__ + 1;
  520. i__3 = *n - i__;
  521. cgemv_("Conjugate transpose", &i__2, &i__3, &c_b2, &a[*kl +
  522. i__ + (i__ + 1) * a_dim1], lda, &a[*kl + i__ + i__ *
  523. a_dim1], &c__1, &c_b1, &work[1], &c__1);
  524. i__2 = *m - *kl - i__ + 1;
  525. i__3 = *n - i__;
  526. q__1.r = -tau.r, q__1.i = -tau.i;
  527. cgerc_(&i__2, &i__3, &q__1, &a[*kl + i__ + i__ * a_dim1], &
  528. c__1, &work[1], &c__1, &a[*kl + i__ + (i__ + 1) *
  529. a_dim1], lda);
  530. i__2 = *kl + i__ + i__ * a_dim1;
  531. q__1.r = -wa.r, q__1.i = -wa.i;
  532. a[i__2].r = q__1.r, a[i__2].i = q__1.i;
  533. }
  534. /* Computing MIN */
  535. i__2 = *n - 1 - *ku;
  536. if (i__ <= f2cmin(i__2,*m)) {
  537. /* generate reflection to annihilate A(i,ku+i+1:n) */
  538. i__2 = *n - *ku - i__ + 1;
  539. wn = scnrm2_(&i__2, &a[i__ + (*ku + i__) * a_dim1], lda);
  540. r__1 = wn / c_abs(&a[i__ + (*ku + i__) * a_dim1]);
  541. i__2 = i__ + (*ku + i__) * a_dim1;
  542. q__1.r = r__1 * a[i__2].r, q__1.i = r__1 * a[i__2].i;
  543. wa.r = q__1.r, wa.i = q__1.i;
  544. if (wn == 0.f) {
  545. tau.r = 0.f, tau.i = 0.f;
  546. } else {
  547. i__2 = i__ + (*ku + i__) * a_dim1;
  548. q__1.r = a[i__2].r + wa.r, q__1.i = a[i__2].i + wa.i;
  549. wb.r = q__1.r, wb.i = q__1.i;
  550. i__2 = *n - *ku - i__;
  551. c_div(&q__1, &c_b2, &wb);
  552. cscal_(&i__2, &q__1, &a[i__ + (*ku + i__ + 1) * a_dim1],
  553. lda);
  554. i__2 = i__ + (*ku + i__) * a_dim1;
  555. a[i__2].r = 1.f, a[i__2].i = 0.f;
  556. c_div(&q__1, &wb, &wa);
  557. r__1 = q__1.r;
  558. tau.r = r__1, tau.i = 0.f;
  559. }
  560. /* apply reflection to A(i+1:m,ku+i:n) from the right */
  561. i__2 = *n - *ku - i__ + 1;
  562. clacgv_(&i__2, &a[i__ + (*ku + i__) * a_dim1], lda);
  563. i__2 = *m - i__;
  564. i__3 = *n - *ku - i__ + 1;
  565. cgemv_("No transpose", &i__2, &i__3, &c_b2, &a[i__ + 1 + (*ku
  566. + i__) * a_dim1], lda, &a[i__ + (*ku + i__) * a_dim1],
  567. lda, &c_b1, &work[1], &c__1);
  568. i__2 = *m - i__;
  569. i__3 = *n - *ku - i__ + 1;
  570. q__1.r = -tau.r, q__1.i = -tau.i;
  571. cgerc_(&i__2, &i__3, &q__1, &work[1], &c__1, &a[i__ + (*ku +
  572. i__) * a_dim1], lda, &a[i__ + 1 + (*ku + i__) *
  573. a_dim1], lda);
  574. i__2 = i__ + (*ku + i__) * a_dim1;
  575. q__1.r = -wa.r, q__1.i = -wa.i;
  576. a[i__2].r = q__1.r, a[i__2].i = q__1.i;
  577. }
  578. } else {
  579. /* annihilate superdiagonal elements first (necessary if */
  580. /* KU = 0) */
  581. /* Computing MIN */
  582. i__2 = *n - 1 - *ku;
  583. if (i__ <= f2cmin(i__2,*m)) {
  584. /* generate reflection to annihilate A(i,ku+i+1:n) */
  585. i__2 = *n - *ku - i__ + 1;
  586. wn = scnrm2_(&i__2, &a[i__ + (*ku + i__) * a_dim1], lda);
  587. r__1 = wn / c_abs(&a[i__ + (*ku + i__) * a_dim1]);
  588. i__2 = i__ + (*ku + i__) * a_dim1;
  589. q__1.r = r__1 * a[i__2].r, q__1.i = r__1 * a[i__2].i;
  590. wa.r = q__1.r, wa.i = q__1.i;
  591. if (wn == 0.f) {
  592. tau.r = 0.f, tau.i = 0.f;
  593. } else {
  594. i__2 = i__ + (*ku + i__) * a_dim1;
  595. q__1.r = a[i__2].r + wa.r, q__1.i = a[i__2].i + wa.i;
  596. wb.r = q__1.r, wb.i = q__1.i;
  597. i__2 = *n - *ku - i__;
  598. c_div(&q__1, &c_b2, &wb);
  599. cscal_(&i__2, &q__1, &a[i__ + (*ku + i__ + 1) * a_dim1],
  600. lda);
  601. i__2 = i__ + (*ku + i__) * a_dim1;
  602. a[i__2].r = 1.f, a[i__2].i = 0.f;
  603. c_div(&q__1, &wb, &wa);
  604. r__1 = q__1.r;
  605. tau.r = r__1, tau.i = 0.f;
  606. }
  607. /* apply reflection to A(i+1:m,ku+i:n) from the right */
  608. i__2 = *n - *ku - i__ + 1;
  609. clacgv_(&i__2, &a[i__ + (*ku + i__) * a_dim1], lda);
  610. i__2 = *m - i__;
  611. i__3 = *n - *ku - i__ + 1;
  612. cgemv_("No transpose", &i__2, &i__3, &c_b2, &a[i__ + 1 + (*ku
  613. + i__) * a_dim1], lda, &a[i__ + (*ku + i__) * a_dim1],
  614. lda, &c_b1, &work[1], &c__1);
  615. i__2 = *m - i__;
  616. i__3 = *n - *ku - i__ + 1;
  617. q__1.r = -tau.r, q__1.i = -tau.i;
  618. cgerc_(&i__2, &i__3, &q__1, &work[1], &c__1, &a[i__ + (*ku +
  619. i__) * a_dim1], lda, &a[i__ + 1 + (*ku + i__) *
  620. a_dim1], lda);
  621. i__2 = i__ + (*ku + i__) * a_dim1;
  622. q__1.r = -wa.r, q__1.i = -wa.i;
  623. a[i__2].r = q__1.r, a[i__2].i = q__1.i;
  624. }
  625. /* Computing MIN */
  626. i__2 = *m - 1 - *kl;
  627. if (i__ <= f2cmin(i__2,*n)) {
  628. /* generate reflection to annihilate A(kl+i+1:m,i) */
  629. i__2 = *m - *kl - i__ + 1;
  630. wn = scnrm2_(&i__2, &a[*kl + i__ + i__ * a_dim1], &c__1);
  631. r__1 = wn / c_abs(&a[*kl + i__ + i__ * a_dim1]);
  632. i__2 = *kl + i__ + i__ * a_dim1;
  633. q__1.r = r__1 * a[i__2].r, q__1.i = r__1 * a[i__2].i;
  634. wa.r = q__1.r, wa.i = q__1.i;
  635. if (wn == 0.f) {
  636. tau.r = 0.f, tau.i = 0.f;
  637. } else {
  638. i__2 = *kl + i__ + i__ * a_dim1;
  639. q__1.r = a[i__2].r + wa.r, q__1.i = a[i__2].i + wa.i;
  640. wb.r = q__1.r, wb.i = q__1.i;
  641. i__2 = *m - *kl - i__;
  642. c_div(&q__1, &c_b2, &wb);
  643. cscal_(&i__2, &q__1, &a[*kl + i__ + 1 + i__ * a_dim1], &
  644. c__1);
  645. i__2 = *kl + i__ + i__ * a_dim1;
  646. a[i__2].r = 1.f, a[i__2].i = 0.f;
  647. c_div(&q__1, &wb, &wa);
  648. r__1 = q__1.r;
  649. tau.r = r__1, tau.i = 0.f;
  650. }
  651. /* apply reflection to A(kl+i:m,i+1:n) from the left */
  652. i__2 = *m - *kl - i__ + 1;
  653. i__3 = *n - i__;
  654. cgemv_("Conjugate transpose", &i__2, &i__3, &c_b2, &a[*kl +
  655. i__ + (i__ + 1) * a_dim1], lda, &a[*kl + i__ + i__ *
  656. a_dim1], &c__1, &c_b1, &work[1], &c__1);
  657. i__2 = *m - *kl - i__ + 1;
  658. i__3 = *n - i__;
  659. q__1.r = -tau.r, q__1.i = -tau.i;
  660. cgerc_(&i__2, &i__3, &q__1, &a[*kl + i__ + i__ * a_dim1], &
  661. c__1, &work[1], &c__1, &a[*kl + i__ + (i__ + 1) *
  662. a_dim1], lda);
  663. i__2 = *kl + i__ + i__ * a_dim1;
  664. q__1.r = -wa.r, q__1.i = -wa.i;
  665. a[i__2].r = q__1.r, a[i__2].i = q__1.i;
  666. }
  667. }
  668. if (i__ <= *n) {
  669. i__2 = *m;
  670. for (j = *kl + i__ + 1; j <= i__2; ++j) {
  671. i__3 = j + i__ * a_dim1;
  672. a[i__3].r = 0.f, a[i__3].i = 0.f;
  673. /* L50: */
  674. }
  675. }
  676. if (i__ <= *m) {
  677. i__2 = *n;
  678. for (j = *ku + i__ + 1; j <= i__2; ++j) {
  679. i__3 = i__ + j * a_dim1;
  680. a[i__3].r = 0.f, a[i__3].i = 0.f;
  681. /* L60: */
  682. }
  683. }
  684. /* L70: */
  685. }
  686. return;
  687. /* End of CLAGGE */
  688. } /* clagge_ */