001:       SUBROUTINE ZLAQP2( M, N, OFFSET, A, LDA, JPVT, TAU, VN1, VN2,
002:      $                   WORK )
003: *
004: *  -- LAPACK auxiliary routine (version 3.2) --
005: *     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
006: *     November 2006
007: *
008: *     .. Scalar Arguments ..
009:       INTEGER            LDA, M, N, OFFSET
010: *     ..
011: *     .. Array Arguments ..
012:       INTEGER            JPVT( * )
013:       DOUBLE PRECISION   VN1( * ), VN2( * )
014:       COMPLEX*16         A( LDA, * ), TAU( * ), WORK( * )
015: *     ..
016: *
017: *  Purpose
018: *  =======
019: *
020: *  ZLAQP2 computes a QR factorization with column pivoting of
021: *  the block A(OFFSET+1:M,1:N).
022: *  The block A(1:OFFSET,1:N) is accordingly pivoted, but not factorized.
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: *  OFFSET  (input) INTEGER
034: *          The number of rows of the matrix A that must be pivoted
035: *          but no factorized. OFFSET >= 0.
036: *
037: *  A       (input/output) COMPLEX*16 array, dimension (LDA,N)
038: *          On entry, the M-by-N matrix A.
039: *          On exit, the upper triangle of block A(OFFSET+1:M,1:N) is
040: *          the triangular factor obtained; the elements in block
041: *          A(OFFSET+1:M,1:N) below the diagonal, together with the
042: *          array TAU, represent the orthogonal matrix Q as a product of
043: *          elementary reflectors. Block A(1:OFFSET,1:N) has been
044: *          accordingly pivoted, but no factorized.
045: *
046: *  LDA     (input) INTEGER
047: *          The leading dimension of the array A. LDA >= max(1,M).
048: *
049: *  JPVT    (input/output) INTEGER array, dimension (N)
050: *          On entry, if JPVT(i) .ne. 0, the i-th column of A is permuted
051: *          to the front of A*P (a leading column); if JPVT(i) = 0,
052: *          the i-th column of A is a free column.
053: *          On exit, if JPVT(i) = k, then the i-th column of A*P
054: *          was the k-th column of A.
055: *
056: *  TAU     (output) COMPLEX*16 array, dimension (min(M,N))
057: *          The scalar factors of the elementary reflectors.
058: *
059: *  VN1     (input/output) DOUBLE PRECISION array, dimension (N)
060: *          The vector with the partial column norms.
061: *
062: *  VN2     (input/output) DOUBLE PRECISION array, dimension (N)
063: *          The vector with the exact column norms.
064: *
065: *  WORK    (workspace) COMPLEX*16 array, dimension (N)
066: *
067: *  Further Details
068: *  ===============
069: *
070: *  Based on contributions by
071: *    G. Quintana-Orti, Depto. de Informatica, Universidad Jaime I, Spain
072: *    X. Sun, Computer Science Dept., Duke University, USA
073: *
074: *  Partial column norm updating strategy modified by
075: *    Z. Drmac and Z. Bujanovic, Dept. of Mathematics,
076: *    University of Zagreb, Croatia.
077: *    June 2006.
078: *  For more details see LAPACK Working Note 176.
079: *  =====================================================================
080: *
081: *     .. Parameters ..
082:       DOUBLE PRECISION   ZERO, ONE
083:       COMPLEX*16         CONE
084:       PARAMETER          ( ZERO = 0.0D+0, ONE = 1.0D+0,
085:      $                   CONE = ( 1.0D+0, 0.0D+0 ) )
086: *     ..
087: *     .. Local Scalars ..
088:       INTEGER            I, ITEMP, J, MN, OFFPI, PVT
089:       DOUBLE PRECISION   TEMP, TEMP2, TOL3Z
090:       COMPLEX*16         AII
091: *     ..
092: *     .. External Subroutines ..
093:       EXTERNAL           ZLARF, ZLARFP, ZSWAP
094: *     ..
095: *     .. Intrinsic Functions ..
096:       INTRINSIC          ABS, DCONJG, MAX, MIN, SQRT
097: *     ..
098: *     .. External Functions ..
099:       INTEGER            IDAMAX
100:       DOUBLE PRECISION   DLAMCH, DZNRM2
101:       EXTERNAL           IDAMAX, DLAMCH, DZNRM2
102: *     ..
103: *     .. Executable Statements ..
104: *
105:       MN = MIN( M-OFFSET, N )
106:       TOL3Z = SQRT(DLAMCH('Epsilon'))
107: *
108: *     Compute factorization.
109: *
110:       DO 20 I = 1, MN
111: *
112:          OFFPI = OFFSET + I
113: *
114: *        Determine ith pivot column and swap if necessary.
115: *
116:          PVT = ( I-1 ) + IDAMAX( N-I+1, VN1( I ), 1 )
117: *
118:          IF( PVT.NE.I ) THEN
119:             CALL ZSWAP( M, A( 1, PVT ), 1, A( 1, I ), 1 )
120:             ITEMP = JPVT( PVT )
121:             JPVT( PVT ) = JPVT( I )
122:             JPVT( I ) = ITEMP
123:             VN1( PVT ) = VN1( I )
124:             VN2( PVT ) = VN2( I )
125:          END IF
126: *
127: *        Generate elementary reflector H(i).
128: *
129:          IF( OFFPI.LT.M ) THEN
130:             CALL ZLARFP( M-OFFPI+1, A( OFFPI, I ), A( OFFPI+1, I ), 1,
131:      $                   TAU( I ) )
132:          ELSE
133:             CALL ZLARFP( 1, A( M, I ), A( M, I ), 1, TAU( I ) )
134:          END IF
135: *
136:          IF( I.LT.N ) THEN
137: *
138: *           Apply H(i)' to A(offset+i:m,i+1:n) from the left.
139: *
140:             AII = A( OFFPI, I )
141:             A( OFFPI, I ) = CONE
142:             CALL ZLARF( 'Left', M-OFFPI+1, N-I, A( OFFPI, I ), 1,
143:      $                  DCONJG( TAU( I ) ), A( OFFPI, I+1 ), LDA,
144:      $                  WORK( 1 ) )
145:             A( OFFPI, I ) = AII
146:          END IF
147: *
148: *        Update partial column norms.
149: *
150:          DO 10 J = I + 1, N
151:             IF( VN1( J ).NE.ZERO ) THEN
152: *
153: *              NOTE: The following 4 lines follow from the analysis in
154: *              Lapack Working Note 176.
155: *
156:                TEMP = ONE - ( ABS( A( OFFPI, J ) ) / VN1( J ) )**2
157:                TEMP = MAX( TEMP, ZERO )
158:                TEMP2 = TEMP*( VN1( J ) / VN2( J ) )**2
159:                IF( TEMP2 .LE. TOL3Z ) THEN
160:                   IF( OFFPI.LT.M ) THEN
161:                      VN1( J ) = DZNRM2( M-OFFPI, A( OFFPI+1, J ), 1 )
162:                      VN2( J ) = VN1( J )
163:                   ELSE
164:                      VN1( J ) = ZERO
165:                      VN2( J ) = ZERO
166:                   END IF
167:                ELSE
168:                   VN1( J ) = VN1( J )*SQRT( TEMP )
169:                END IF
170:             END IF
171:    10    CONTINUE
172: *
173:    20 CONTINUE
174: *
175:       RETURN
176: *
177: *     End of ZLAQP2
178: *
179:       END
180: