001:       SUBROUTINE SGEHD2( N, ILO, IHI, A, LDA, TAU, WORK, INFO )
002: *
003: *  -- LAPACK routine (version 3.2) --
004: *  -- LAPACK is a software package provided by Univ. of Tennessee,    --
005: *  -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
006: *     November 2006
007: *
008: *     .. Scalar Arguments ..
009:       INTEGER            IHI, ILO, INFO, LDA, N
010: *     ..
011: *     .. Array Arguments ..
012:       REAL               A( LDA, * ), TAU( * ), WORK( * )
013: *     ..
014: *
015: *  Purpose
016: *  =======
017: *
018: *  SGEHD2 reduces a real general matrix A to upper Hessenberg form H by
019: *  an orthogonal similarity transformation:  Q' * A * Q = H .
020: *
021: *  Arguments
022: *  =========
023: *
024: *  N       (input) INTEGER
025: *          The order of the matrix A.  N >= 0.
026: *
027: *  ILO     (input) INTEGER
028: *  IHI     (input) INTEGER
029: *          It is assumed that A is already upper triangular in rows
030: *          and columns 1:ILO-1 and IHI+1:N. ILO and IHI are normally
031: *          set by a previous call to SGEBAL; otherwise they should be
032: *          set to 1 and N respectively. See Further Details.
033: *          1 <= ILO <= IHI <= max(1,N).
034: *
035: *  A       (input/output) REAL array, dimension (LDA,N)
036: *          On entry, the n by n general matrix to be reduced.
037: *          On exit, the upper triangle and the first subdiagonal of A
038: *          are overwritten with the upper Hessenberg matrix H, and the
039: *          elements below the first subdiagonal, with the array TAU,
040: *          represent the orthogonal matrix Q as a product of elementary
041: *          reflectors. See Further Details.
042: *
043: *  LDA     (input) INTEGER
044: *          The leading dimension of the array A.  LDA >= max(1,N).
045: *
046: *  TAU     (output) REAL array, dimension (N-1)
047: *          The scalar factors of the elementary reflectors (see Further
048: *          Details).
049: *
050: *  WORK    (workspace) REAL array, dimension (N)
051: *
052: *  INFO    (output) INTEGER
053: *          = 0:  successful exit.
054: *          < 0:  if INFO = -i, the i-th argument had an illegal value.
055: *
056: *  Further Details
057: *  ===============
058: *
059: *  The matrix Q is represented as a product of (ihi-ilo) elementary
060: *  reflectors
061: *
062: *     Q = H(ilo) H(ilo+1) . . . H(ihi-1).
063: *
064: *  Each H(i) has the form
065: *
066: *     H(i) = I - tau * v * v'
067: *
068: *  where tau is a real scalar, and v is a real vector with
069: *  v(1:i) = 0, v(i+1) = 1 and v(ihi+1:n) = 0; v(i+2:ihi) is stored on
070: *  exit in A(i+2:ihi,i), and tau in TAU(i).
071: *
072: *  The contents of A are illustrated by the following example, with
073: *  n = 7, ilo = 2 and ihi = 6:
074: *
075: *  on entry,                        on exit,
076: *
077: *  ( a   a   a   a   a   a   a )    (  a   a   h   h   h   h   a )
078: *  (     a   a   a   a   a   a )    (      a   h   h   h   h   a )
079: *  (     a   a   a   a   a   a )    (      h   h   h   h   h   h )
080: *  (     a   a   a   a   a   a )    (      v2  h   h   h   h   h )
081: *  (     a   a   a   a   a   a )    (      v2  v3  h   h   h   h )
082: *  (     a   a   a   a   a   a )    (      v2  v3  v4  h   h   h )
083: *  (                         a )    (                          a )
084: *
085: *  where a denotes an element of the original matrix A, h denotes a
086: *  modified element of the upper Hessenberg matrix H, and vi denotes an
087: *  element of the vector defining H(i).
088: *
089: *  =====================================================================
090: *
091: *     .. Parameters ..
092:       REAL               ONE
093:       PARAMETER          ( ONE = 1.0E+0 )
094: *     ..
095: *     .. Local Scalars ..
096:       INTEGER            I
097:       REAL               AII
098: *     ..
099: *     .. External Subroutines ..
100:       EXTERNAL           SLARF, SLARFG, XERBLA
101: *     ..
102: *     .. Intrinsic Functions ..
103:       INTRINSIC          MAX, MIN
104: *     ..
105: *     .. Executable Statements ..
106: *
107: *     Test the input parameters
108: *
109:       INFO = 0
110:       IF( N.LT.0 ) THEN
111:          INFO = -1
112:       ELSE IF( ILO.LT.1 .OR. ILO.GT.MAX( 1, N ) ) THEN
113:          INFO = -2
114:       ELSE IF( IHI.LT.MIN( ILO, N ) .OR. IHI.GT.N ) THEN
115:          INFO = -3
116:       ELSE IF( LDA.LT.MAX( 1, N ) ) THEN
117:          INFO = -5
118:       END IF
119:       IF( INFO.NE.0 ) THEN
120:          CALL XERBLA( 'SGEHD2', -INFO )
121:          RETURN
122:       END IF
123: *
124:       DO 10 I = ILO, IHI - 1
125: *
126: *        Compute elementary reflector H(i) to annihilate A(i+2:ihi,i)
127: *
128:          CALL SLARFG( IHI-I, A( I+1, I ), A( MIN( I+2, N ), I ), 1,
129:      $                TAU( I ) )
130:          AII = A( I+1, I )
131:          A( I+1, I ) = ONE
132: *
133: *        Apply H(i) to A(1:ihi,i+1:ihi) from the right
134: *
135:          CALL SLARF( 'Right', IHI, IHI-I, A( I+1, I ), 1, TAU( I ),
136:      $               A( 1, I+1 ), LDA, WORK )
137: *
138: *        Apply H(i) to A(i+1:ihi,i+1:n) from the left
139: *
140:          CALL SLARF( 'Left', IHI-I, N-I, A( I+1, I ), 1, TAU( I ),
141:      $               A( I+1, I+1 ), LDA, WORK )
142: *
143:          A( I+1, I ) = AII
144:    10 CONTINUE
145: *
146:       RETURN
147: *
148: *     End of SGEHD2
149: *
150:       END
151: