1 /* ./src_f77/cgerq2.f -- translated by f2c (version 20030320).
2 You must link the resulting object file with the libraries:
3 -lf2c -lm (in that order)
4 */
5
6 #include <punc/vf2c.h>
7
cgerq2_(integer * m,integer * n,complex * a,integer * lda,complex * tau,complex * work,integer * info)8 /* Subroutine */ int cgerq2_(integer *m, integer *n, complex *a, integer *lda,
9 complex *tau, complex *work, integer *info)
10 {
11 /* System generated locals */
12 integer a_dim1, a_offset, i__1, i__2;
13
14 /* Local variables */
15 static integer i__, k;
16 static complex alpha;
17 extern /* Subroutine */ int clarf_(char *, integer *, integer *, complex *
18 , integer *, complex *, complex *, integer *, complex *, ftnlen),
19 clarfg_(integer *, complex *, complex *, integer *, complex *),
20 clacgv_(integer *, complex *, integer *), xerbla_(char *, integer
21 *, ftnlen);
22
23
24 /* -- LAPACK routine (version 3.0) -- */
25 /* Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd., */
26 /* Courant Institute, Argonne National Lab, and Rice University */
27 /* September 30, 1994 */
28
29 /* .. Scalar Arguments .. */
30 /* .. */
31 /* .. Array Arguments .. */
32 /* .. */
33
34 /* Purpose */
35 /* ======= */
36
37 /* CGERQ2 computes an RQ factorization of a complex m by n matrix A: */
38 /* A = R * Q. */
39
40 /* Arguments */
41 /* ========= */
42
43 /* M (input) INTEGER */
44 /* The number of rows of the matrix A. M >= 0. */
45
46 /* N (input) INTEGER */
47 /* The number of columns of the matrix A. N >= 0. */
48
49 /* A (input/output) COMPLEX array, dimension (LDA,N) */
50 /* On entry, the m by n matrix A. */
51 /* On exit, if m <= n, the upper triangle of the subarray */
52 /* A(1:m,n-m+1:n) contains the m by m upper triangular matrix R; */
53 /* if m >= n, the elements on and above the (m-n)-th subdiagonal */
54 /* contain the m by n upper trapezoidal matrix R; the remaining */
55 /* elements, with the array TAU, represent the unitary matrix */
56 /* Q as a product of elementary reflectors (see Further */
57 /* Details). */
58
59 /* LDA (input) INTEGER */
60 /* The leading dimension of the array A. LDA >= max(1,M). */
61
62 /* TAU (output) COMPLEX array, dimension (min(M,N)) */
63 /* The scalar factors of the elementary reflectors (see Further */
64 /* Details). */
65
66 /* WORK (workspace) COMPLEX array, dimension (M) */
67
68 /* INFO (output) INTEGER */
69 /* = 0: successful exit */
70 /* < 0: if INFO = -i, the i-th argument had an illegal value */
71
72 /* Further Details */
73 /* =============== */
74
75 /* The matrix Q is represented as a product of elementary reflectors */
76
77 /* Q = H(1)' H(2)' . . . H(k)', where k = min(m,n). */
78
79 /* Each H(i) has the form */
80
81 /* H(i) = I - tau * v * v' */
82
83 /* where tau is a complex scalar, and v is a complex vector with */
84 /* v(n-k+i+1:n) = 0 and v(n-k+i) = 1; conjg(v(1:n-k+i-1)) is stored on */
85 /* exit in A(m-k+i,1:n-k+i-1), and tau in TAU(i). */
86
87 /* ===================================================================== */
88
89 /* .. Parameters .. */
90 /* .. */
91 /* .. Local Scalars .. */
92 /* .. */
93 /* .. External Subroutines .. */
94 /* .. */
95 /* .. Intrinsic Functions .. */
96 /* .. */
97 /* .. Executable Statements .. */
98
99 /* Test the input arguments */
100
101 /* Parameter adjustments */
102 a_dim1 = *lda;
103 a_offset = 1 + a_dim1;
104 a -= a_offset;
105 --tau;
106 --work;
107
108 /* Function Body */
109 *info = 0;
110 if (*m < 0) {
111 *info = -1;
112 } else if (*n < 0) {
113 *info = -2;
114 } else if (*lda < max(1,*m)) {
115 *info = -4;
116 }
117 if (*info != 0) {
118 i__1 = -(*info);
119 xerbla_("CGERQ2", &i__1, (ftnlen)6);
120 return 0;
121 }
122
123 k = min(*m,*n);
124
125 for (i__ = k; i__ >= 1; --i__) {
126
127 /* Generate elementary reflector H(i) to annihilate */
128 /* A(m-k+i,1:n-k+i-1) */
129
130 i__1 = *n - k + i__;
131 clacgv_(&i__1, &a[*m - k + i__ + a_dim1], lda);
132 i__1 = *m - k + i__ + (*n - k + i__) * a_dim1;
133 alpha.r = a[i__1].r, alpha.i = a[i__1].i;
134 i__1 = *n - k + i__;
135 clarfg_(&i__1, &alpha, &a[*m - k + i__ + a_dim1], lda, &tau[i__]);
136
137 /* Apply H(i) to A(1:m-k+i-1,1:n-k+i) from the right */
138
139 i__1 = *m - k + i__ + (*n - k + i__) * a_dim1;
140 a[i__1].r = 1.f, a[i__1].i = 0.f;
141 i__1 = *m - k + i__ - 1;
142 i__2 = *n - k + i__;
143 clarf_("Right", &i__1, &i__2, &a[*m - k + i__ + a_dim1], lda, &tau[
144 i__], &a[a_offset], lda, &work[1], (ftnlen)5);
145 i__1 = *m - k + i__ + (*n - k + i__) * a_dim1;
146 a[i__1].r = alpha.r, a[i__1].i = alpha.i;
147 i__1 = *n - k + i__ - 1;
148 clacgv_(&i__1, &a[*m - k + i__ + a_dim1], lda);
149 /* L10: */
150 }
151 return 0;
152
153 /* End of CGERQ2 */
154
155 } /* cgerq2_ */
156
157