001:       SUBROUTINE CGEQPF( M, N, A, LDA, JPVT, TAU, WORK, RWORK, INFO )
002: *
003: *  -- LAPACK deprecated driver routine (version 3.2) --
004: *     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
005: *     November 2006
006: *
007: *     .. Scalar Arguments ..
008:       INTEGER            INFO, LDA, M, N
009: *     ..
010: *     .. Array Arguments ..
011:       INTEGER            JPVT( * )
012:       REAL               RWORK( * )
013:       COMPLEX            A( LDA, * ), TAU( * ), WORK( * )
014: *     ..
015: *
016: *  Purpose
017: *  =======
018: *
019: *  This routine is deprecated and has been replaced by routine CGEQP3.
020: *
021: *  CGEQPF computes a QR factorization with column pivoting of a
022: *  complex M-by-N matrix A: A*P = Q*R.
023: *
024: *  Arguments
025: *  =========
026: *
027: *  M       (input) INTEGER
028: *          The number of rows of the matrix A. M >= 0.
029: *
030: *  N       (input) INTEGER
031: *          The number of columns of the matrix A. N >= 0
032: *
033: *  A       (input/output) COMPLEX array, dimension (LDA,N)
034: *          On entry, the M-by-N matrix A.
035: *          On exit, the upper triangle of the array contains the
036: *          min(M,N)-by-N upper triangular matrix R; the elements
037: *          below the diagonal, together with the array TAU,
038: *          represent the unitary matrix Q as a product of
039: *          min(m,n) elementary reflectors.
040: *
041: *  LDA     (input) INTEGER
042: *          The leading dimension of the array A. LDA >= max(1,M).
043: *
044: *  JPVT    (input/output) INTEGER array, dimension (N)
045: *          On entry, if JPVT(i) .ne. 0, the i-th column of A is permuted
046: *          to the front of A*P (a leading column); if JPVT(i) = 0,
047: *          the i-th column of A is a free column.
048: *          On exit, if JPVT(i) = k, then the i-th column of A*P
049: *          was the k-th column of A.
050: *
051: *  TAU     (output) COMPLEX array, dimension (min(M,N))
052: *          The scalar factors of the elementary reflectors.
053: *
054: *  WORK    (workspace) COMPLEX array, dimension (N)
055: *
056: *  RWORK   (workspace) REAL array, dimension (2*N)
057: *
058: *  INFO    (output) INTEGER
059: *          = 0:  successful exit
060: *          < 0:  if INFO = -i, the i-th argument had an illegal value
061: *
062: *  Further Details
063: *  ===============
064: *
065: *  The matrix Q is represented as a product of elementary reflectors
066: *
067: *     Q = H(1) H(2) . . . H(n)
068: *
069: *  Each H(i) has the form
070: *
071: *     H = I - tau * v * v'
072: *
073: *  where tau is a complex scalar, and v is a complex vector with
074: *  v(1:i-1) = 0 and v(i) = 1; v(i+1:m) is stored on exit in A(i+1:m,i).
075: *
076: *  The matrix P is represented in jpvt as follows: If
077: *     jpvt(j) = i
078: *  then the jth column of P is the ith canonical unit vector.
079: *
080: *  Partial column norm updating strategy modified by
081: *    Z. Drmac and Z. Bujanovic, Dept. of Mathematics,
082: *    University of Zagreb, Croatia.
083: *    June 2006.
084: *  For more details see LAPACK Working Note 176.
085: *
086: *  =====================================================================
087: *
088: *     .. Parameters ..
089:       REAL               ZERO, ONE
090:       PARAMETER          ( ZERO = 0.0E+0, ONE = 1.0E+0 )
091: *     ..
092: *     .. Local Scalars ..
093:       INTEGER            I, ITEMP, J, MA, MN, PVT
094:       REAL               TEMP, TEMP2, TOL3Z
095:       COMPLEX            AII
096: *     ..
097: *     .. External Subroutines ..
098:       EXTERNAL           CGEQR2, CLARF, CLARFG, CSWAP, CUNM2R, XERBLA
099: *     ..
100: *     .. Intrinsic Functions ..
101:       INTRINSIC          ABS, CMPLX, CONJG, MAX, MIN, SQRT
102: *     ..
103: *     .. External Functions ..
104:       INTEGER            ISAMAX
105:       REAL               SCNRM2, SLAMCH
106:       EXTERNAL           ISAMAX, SCNRM2, SLAMCH
107: *     ..
108: *     .. Executable Statements ..
109: *
110: *     Test the input arguments
111: *
112:       INFO = 0
113:       IF( M.LT.0 ) THEN
114:          INFO = -1
115:       ELSE IF( N.LT.0 ) THEN
116:          INFO = -2
117:       ELSE IF( LDA.LT.MAX( 1, M ) ) THEN
118:          INFO = -4
119:       END IF
120:       IF( INFO.NE.0 ) THEN
121:          CALL XERBLA( 'CGEQPF', -INFO )
122:          RETURN
123:       END IF
124: *
125:       MN = MIN( M, N )
126:       TOL3Z = SQRT(SLAMCH('Epsilon'))
127: *
128: *     Move initial columns up front
129: *
130:       ITEMP = 1
131:       DO 10 I = 1, N
132:          IF( JPVT( I ).NE.0 ) THEN
133:             IF( I.NE.ITEMP ) THEN
134:                CALL CSWAP( M, A( 1, I ), 1, A( 1, ITEMP ), 1 )
135:                JPVT( I ) = JPVT( ITEMP )
136:                JPVT( ITEMP ) = I
137:             ELSE
138:                JPVT( I ) = I
139:             END IF
140:             ITEMP = ITEMP + 1
141:          ELSE
142:             JPVT( I ) = I
143:          END IF
144:    10 CONTINUE
145:       ITEMP = ITEMP - 1
146: *
147: *     Compute the QR factorization and update remaining columns
148: *
149:       IF( ITEMP.GT.0 ) THEN
150:          MA = MIN( ITEMP, M )
151:          CALL CGEQR2( M, MA, A, LDA, TAU, WORK, INFO )
152:          IF( MA.LT.N ) THEN
153:             CALL CUNM2R( 'Left', 'Conjugate transpose', M, N-MA, MA, A,
154:      $                   LDA, TAU, A( 1, MA+1 ), LDA, WORK, INFO )
155:          END IF
156:       END IF
157: *
158:       IF( ITEMP.LT.MN ) THEN
159: *
160: *        Initialize partial column norms. The first n elements of
161: *        work store the exact column norms.
162: *
163:          DO 20 I = ITEMP + 1, N
164:             RWORK( I ) = SCNRM2( M-ITEMP, A( ITEMP+1, I ), 1 )
165:             RWORK( N+I ) = RWORK( I )
166:    20    CONTINUE
167: *
168: *        Compute factorization
169: *
170:          DO 40 I = ITEMP + 1, MN
171: *
172: *           Determine ith pivot column and swap if necessary
173: *
174:             PVT = ( I-1 ) + ISAMAX( N-I+1, RWORK( I ), 1 )
175: *
176:             IF( PVT.NE.I ) THEN
177:                CALL CSWAP( M, A( 1, PVT ), 1, A( 1, I ), 1 )
178:                ITEMP = JPVT( PVT )
179:                JPVT( PVT ) = JPVT( I )
180:                JPVT( I ) = ITEMP
181:                RWORK( PVT ) = RWORK( I )
182:                RWORK( N+PVT ) = RWORK( N+I )
183:             END IF
184: *
185: *           Generate elementary reflector H(i)
186: *
187:             AII = A( I, I )
188:             CALL CLARFG( M-I+1, AII, A( MIN( I+1, M ), I ), 1,
189:      $                   TAU( I ) )
190:             A( I, I ) = AII
191: *
192:             IF( I.LT.N ) THEN
193: *
194: *              Apply H(i) to A(i:m,i+1:n) from the left
195: *
196:                AII = A( I, I )
197:                A( I, I ) = CMPLX( ONE )
198:                CALL CLARF( 'Left', M-I+1, N-I, A( I, I ), 1,
199:      $                     CONJG( TAU( I ) ), A( I, I+1 ), LDA, WORK )
200:                A( I, I ) = AII
201:             END IF
202: *
203: *           Update partial column norms
204: *
205:             DO 30 J = I + 1, N
206:                IF( RWORK( J ).NE.ZERO ) THEN
207: *
208: *                 NOTE: The following 4 lines follow from the analysis in
209: *                 Lapack Working Note 176.
210: *                 
211:                   TEMP = ABS( A( I, J ) ) / RWORK( J )
212:                   TEMP = MAX( ZERO, ( ONE+TEMP )*( ONE-TEMP ) )
213:                   TEMP2 = TEMP*( RWORK( J ) / RWORK( N+J ) )**2
214:                   IF( TEMP2 .LE. TOL3Z ) THEN 
215:                      IF( M-I.GT.0 ) THEN
216:                         RWORK( J ) = SCNRM2( M-I, A( I+1, J ), 1 )
217:                         RWORK( N+J ) = RWORK( J )
218:                      ELSE
219:                         RWORK( J ) = ZERO
220:                         RWORK( N+J ) = ZERO
221:                      END IF
222:                   ELSE
223:                      RWORK( J ) = RWORK( J )*SQRT( TEMP )
224:                   END IF
225:                END IF
226:    30       CONTINUE
227: *
228:    40    CONTINUE
229:       END IF
230:       RETURN
231: *
232: *     End of CGEQPF
233: *
234:       END
235: