001:       SUBROUTINE ZGEBAK( JOB, SIDE, N, ILO, IHI, SCALE, M, V, LDV,
002:      $                   INFO )
003: *
004: *  -- LAPACK routine (version 3.2) --
005: *     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
006: *     November 2006
007: *
008: *     .. Scalar Arguments ..
009:       CHARACTER          JOB, SIDE
010:       INTEGER            IHI, ILO, INFO, LDV, M, N
011: *     ..
012: *     .. Array Arguments ..
013:       DOUBLE PRECISION   SCALE( * )
014:       COMPLEX*16         V( LDV, * )
015: *     ..
016: *
017: *  Purpose
018: *  =======
019: *
020: *  ZGEBAK forms the right or left eigenvectors of a complex general
021: *  matrix by backward transformation on the computed eigenvectors of the
022: *  balanced matrix output by ZGEBAL.
023: *
024: *  Arguments
025: *  =========
026: *
027: *  JOB     (input) CHARACTER*1
028: *          Specifies the type of backward transformation required:
029: *          = 'N', do nothing, return immediately;
030: *          = 'P', do backward transformation for permutation only;
031: *          = 'S', do backward transformation for scaling only;
032: *          = 'B', do backward transformations for both permutation and
033: *                 scaling.
034: *          JOB must be the same as the argument JOB supplied to ZGEBAL.
035: *
036: *  SIDE    (input) CHARACTER*1
037: *          = 'R':  V contains right eigenvectors;
038: *          = 'L':  V contains left eigenvectors.
039: *
040: *  N       (input) INTEGER
041: *          The number of rows of the matrix V.  N >= 0.
042: *
043: *  ILO     (input) INTEGER
044: *  IHI     (input) INTEGER
045: *          The integers ILO and IHI determined by ZGEBAL.
046: *          1 <= ILO <= IHI <= N, if N > 0; ILO=1 and IHI=0, if N=0.
047: *
048: *  SCALE   (input) DOUBLE PRECISION array, dimension (N)
049: *          Details of the permutation and scaling factors, as returned
050: *          by ZGEBAL.
051: *
052: *  M       (input) INTEGER
053: *          The number of columns of the matrix V.  M >= 0.
054: *
055: *  V       (input/output) COMPLEX*16 array, dimension (LDV,M)
056: *          On entry, the matrix of right or left eigenvectors to be
057: *          transformed, as returned by ZHSEIN or ZTREVC.
058: *          On exit, V is overwritten by the transformed eigenvectors.
059: *
060: *  LDV     (input) INTEGER
061: *          The leading dimension of the array V. LDV >= max(1,N).
062: *
063: *  INFO    (output) INTEGER
064: *          = 0:  successful exit
065: *          < 0:  if INFO = -i, the i-th argument had an illegal value.
066: *
067: *  =====================================================================
068: *
069: *     .. Parameters ..
070:       DOUBLE PRECISION   ONE
071:       PARAMETER          ( ONE = 1.0D+0 )
072: *     ..
073: *     .. Local Scalars ..
074:       LOGICAL            LEFTV, RIGHTV
075:       INTEGER            I, II, K
076:       DOUBLE PRECISION   S
077: *     ..
078: *     .. External Functions ..
079:       LOGICAL            LSAME
080:       EXTERNAL           LSAME
081: *     ..
082: *     .. External Subroutines ..
083:       EXTERNAL           XERBLA, ZDSCAL, ZSWAP
084: *     ..
085: *     .. Intrinsic Functions ..
086:       INTRINSIC          MAX, MIN
087: *     ..
088: *     .. Executable Statements ..
089: *
090: *     Decode and Test the input parameters
091: *
092:       RIGHTV = LSAME( SIDE, 'R' )
093:       LEFTV = LSAME( SIDE, 'L' )
094: *
095:       INFO = 0
096:       IF( .NOT.LSAME( JOB, 'N' ) .AND. .NOT.LSAME( JOB, 'P' ) .AND.
097:      $    .NOT.LSAME( JOB, 'S' ) .AND. .NOT.LSAME( JOB, 'B' ) ) THEN
098:          INFO = -1
099:       ELSE IF( .NOT.RIGHTV .AND. .NOT.LEFTV ) THEN
100:          INFO = -2
101:       ELSE IF( N.LT.0 ) THEN
102:          INFO = -3
103:       ELSE IF( ILO.LT.1 .OR. ILO.GT.MAX( 1, N ) ) THEN
104:          INFO = -4
105:       ELSE IF( IHI.LT.MIN( ILO, N ) .OR. IHI.GT.N ) THEN
106:          INFO = -5
107:       ELSE IF( M.LT.0 ) THEN
108:          INFO = -7
109:       ELSE IF( LDV.LT.MAX( 1, N ) ) THEN
110:          INFO = -9
111:       END IF
112:       IF( INFO.NE.0 ) THEN
113:          CALL XERBLA( 'ZGEBAK', -INFO )
114:          RETURN
115:       END IF
116: *
117: *     Quick return if possible
118: *
119:       IF( N.EQ.0 )
120:      $   RETURN
121:       IF( M.EQ.0 )
122:      $   RETURN
123:       IF( LSAME( JOB, 'N' ) )
124:      $   RETURN
125: *
126:       IF( ILO.EQ.IHI )
127:      $   GO TO 30
128: *
129: *     Backward balance
130: *
131:       IF( LSAME( JOB, 'S' ) .OR. LSAME( JOB, 'B' ) ) THEN
132: *
133:          IF( RIGHTV ) THEN
134:             DO 10 I = ILO, IHI
135:                S = SCALE( I )
136:                CALL ZDSCAL( M, S, V( I, 1 ), LDV )
137:    10       CONTINUE
138:          END IF
139: *
140:          IF( LEFTV ) THEN
141:             DO 20 I = ILO, IHI
142:                S = ONE / SCALE( I )
143:                CALL ZDSCAL( M, S, V( I, 1 ), LDV )
144:    20       CONTINUE
145:          END IF
146: *
147:       END IF
148: *
149: *     Backward permutation
150: *
151: *     For  I = ILO-1 step -1 until 1,
152: *              IHI+1 step 1 until N do --
153: *
154:    30 CONTINUE
155:       IF( LSAME( JOB, 'P' ) .OR. LSAME( JOB, 'B' ) ) THEN
156:          IF( RIGHTV ) THEN
157:             DO 40 II = 1, N
158:                I = II
159:                IF( I.GE.ILO .AND. I.LE.IHI )
160:      $            GO TO 40
161:                IF( I.LT.ILO )
162:      $            I = ILO - II
163:                K = SCALE( I )
164:                IF( K.EQ.I )
165:      $            GO TO 40
166:                CALL ZSWAP( M, V( I, 1 ), LDV, V( K, 1 ), LDV )
167:    40       CONTINUE
168:          END IF
169: *
170:          IF( LEFTV ) THEN
171:             DO 50 II = 1, N
172:                I = II
173:                IF( I.GE.ILO .AND. I.LE.IHI )
174:      $            GO TO 50
175:                IF( I.LT.ILO )
176:      $            I = ILO - II
177:                K = SCALE( I )
178:                IF( K.EQ.I )
179:      $            GO TO 50
180:                CALL ZSWAP( M, V( I, 1 ), LDV, V( K, 1 ), LDV )
181:    50       CONTINUE
182:          END IF
183:       END IF
184: *
185:       RETURN
186: *
187: *     End of ZGEBAK
188: *
189:       END
190: