001:       SUBROUTINE ZUNG2R( M, N, K, A, LDA, TAU, WORK, INFO )
002: *
003: *  -- LAPACK 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, K, LDA, M, N
009: *     ..
010: *     .. Array Arguments ..
011:       COMPLEX*16         A( LDA, * ), TAU( * ), WORK( * )
012: *     ..
013: *
014: *  Purpose
015: *  =======
016: *
017: *  ZUNG2R generates an m by n complex matrix Q with orthonormal columns,
018: *  which is defined as the first n columns of a product of k elementary
019: *  reflectors of order m
020: *
021: *        Q  =  H(1) H(2) . . . H(k)
022: *
023: *  as returned by ZGEQRF.
024: *
025: *  Arguments
026: *  =========
027: *
028: *  M       (input) INTEGER
029: *          The number of rows of the matrix Q. M >= 0.
030: *
031: *  N       (input) INTEGER
032: *          The number of columns of the matrix Q. M >= N >= 0.
033: *
034: *  K       (input) INTEGER
035: *          The number of elementary reflectors whose product defines the
036: *          matrix Q. N >= K >= 0.
037: *
038: *  A       (input/output) COMPLEX*16 array, dimension (LDA,N)
039: *          On entry, the i-th column must contain the vector which
040: *          defines the elementary reflector H(i), for i = 1,2,...,k, as
041: *          returned by ZGEQRF in the first k columns of its array
042: *          argument A.
043: *          On exit, the m by n matrix Q.
044: *
045: *  LDA     (input) INTEGER
046: *          The first dimension of the array A. LDA >= max(1,M).
047: *
048: *  TAU     (input) COMPLEX*16 array, dimension (K)
049: *          TAU(i) must contain the scalar factor of the elementary
050: *          reflector H(i), as returned by ZGEQRF.
051: *
052: *  WORK    (workspace) COMPLEX*16 array, dimension (N)
053: *
054: *  INFO    (output) INTEGER
055: *          = 0: successful exit
056: *          < 0: if INFO = -i, the i-th argument has an illegal value
057: *
058: *  =====================================================================
059: *
060: *     .. Parameters ..
061:       COMPLEX*16         ONE, ZERO
062:       PARAMETER          ( ONE = ( 1.0D+0, 0.0D+0 ),
063:      $                   ZERO = ( 0.0D+0, 0.0D+0 ) )
064: *     ..
065: *     .. Local Scalars ..
066:       INTEGER            I, J, L
067: *     ..
068: *     .. External Subroutines ..
069:       EXTERNAL           XERBLA, ZLARF, ZSCAL
070: *     ..
071: *     .. Intrinsic Functions ..
072:       INTRINSIC          MAX
073: *     ..
074: *     .. Executable Statements ..
075: *
076: *     Test the input arguments
077: *
078:       INFO = 0
079:       IF( M.LT.0 ) THEN
080:          INFO = -1
081:       ELSE IF( N.LT.0 .OR. N.GT.M ) THEN
082:          INFO = -2
083:       ELSE IF( K.LT.0 .OR. K.GT.N ) THEN
084:          INFO = -3
085:       ELSE IF( LDA.LT.MAX( 1, M ) ) THEN
086:          INFO = -5
087:       END IF
088:       IF( INFO.NE.0 ) THEN
089:          CALL XERBLA( 'ZUNG2R', -INFO )
090:          RETURN
091:       END IF
092: *
093: *     Quick return if possible
094: *
095:       IF( N.LE.0 )
096:      $   RETURN
097: *
098: *     Initialise columns k+1:n to columns of the unit matrix
099: *
100:       DO 20 J = K + 1, N
101:          DO 10 L = 1, M
102:             A( L, J ) = ZERO
103:    10    CONTINUE
104:          A( J, J ) = ONE
105:    20 CONTINUE
106: *
107:       DO 40 I = K, 1, -1
108: *
109: *        Apply H(i) to A(i:m,i:n) from the left
110: *
111:          IF( I.LT.N ) THEN
112:             A( I, I ) = ONE
113:             CALL ZLARF( 'Left', M-I+1, N-I, A( I, I ), 1, TAU( I ),
114:      $                  A( I, I+1 ), LDA, WORK )
115:          END IF
116:          IF( I.LT.M )
117:      $      CALL ZSCAL( M-I, -TAU( I ), A( I+1, I ), 1 )
118:          A( I, I ) = ONE - TAU( I )
119: *
120: *        Set A(1:i-1,i) to zero
121: *
122:          DO 30 L = 1, I - 1
123:             A( L, I ) = ZERO
124:    30    CONTINUE
125:    40 CONTINUE
126:       RETURN
127: *
128: *     End of ZUNG2R
129: *
130:       END
131: