102
103
104
105
106
107
108 INTEGER INCX, N
109 COMPLEX*16 ALPHA, TAU
110
111
112 COMPLEX*16 X( * )
113
114
115
116
117
118 DOUBLE PRECISION TWO, ONE, ZERO
119 parameter( two = 2.0d+0, one = 1.0d+0, zero = 0.0d+0 )
120
121
122 INTEGER J, KNT
123 DOUBLE PRECISION ALPHI, ALPHR, BETA, BIGNUM, EPS, SMLNUM, XNORM
124 COMPLEX*16 SAVEALPHA
125
126
127 DOUBLE PRECISION DLAMCH, DLAPY3, DLAPY2, DZNRM2
128 COMPLEX*16 ZLADIV
131
132
133 INTRINSIC abs, dble, dcmplx, dimag, sign
134
135
137
138
139
140 IF( n.LE.0 ) THEN
141 tau = zero
142 RETURN
143 END IF
144
145 eps =
dlamch(
'Precision' )
146 xnorm =
dznrm2( n-1, x, incx )
147 alphr = dble( alpha )
148 alphi = dimag( alpha )
149
150 IF( xnorm.LE.eps*abs(alpha) .AND. alphi.EQ.zero ) THEN
151
152
153
154 IF( alphr.GE.zero ) THEN
155
156
157
158 tau = zero
159 ELSE
160
161
162 tau = two
163 DO j = 1, n-1
164 x( 1 + (j-1)*incx ) = zero
165 END DO
166 alpha = -alpha
167 END IF
168 ELSE
169
170
171
172 beta = sign(
dlapy3( alphr, alphi, xnorm ), alphr )
174 bignum = one / smlnum
175
176 knt = 0
177 IF( abs( beta ).LT.smlnum ) THEN
178
179
180
181 10 CONTINUE
182 knt = knt + 1
183 CALL zdscal( n-1, bignum, x, incx )
184 beta = beta*bignum
185 alphi = alphi*bignum
186 alphr = alphr*bignum
187 IF( (abs( beta ).LT.smlnum) .AND. (knt .LT. 20) )
188 $ GO TO 10
189
190
191
192 xnorm =
dznrm2( n-1, x, incx )
193 alpha = dcmplx( alphr, alphi )
194 beta = sign(
dlapy3( alphr, alphi, xnorm ), alphr )
195 END IF
196 savealpha = alpha
197 alpha = alpha + beta
198 IF( beta.LT.zero ) THEN
199 beta = -beta
200 tau = -alpha / beta
201 ELSE
202 alphr = alphi * (alphi/dble( alpha ))
203 alphr = alphr + xnorm * (xnorm/dble( alpha ))
204 tau = dcmplx( alphr/beta, -alphi/beta )
205 alpha = dcmplx( -alphr, alphi )
206 END IF
207 alpha =
zladiv( dcmplx( one ), alpha )
208
209 IF ( abs(tau).LE.smlnum ) THEN
210
211
212
213
214
215
216
217
218 alphr = dble( savealpha )
219 alphi = dimag( savealpha )
220 IF( alphi.EQ.zero ) THEN
221 IF( alphr.GE.zero ) THEN
222 tau = zero
223 ELSE
224 tau = two
225 DO j = 1, n-1
226 x( 1 + (j-1)*incx ) = zero
227 END DO
228 beta = dble( -savealpha )
229 END IF
230 ELSE
231 xnorm =
dlapy2( alphr, alphi )
232 tau = dcmplx( one - alphr / xnorm, -alphi / xnorm )
233 DO j = 1, n-1
234 x( 1 + (j-1)*incx ) = zero
235 END DO
236 beta = xnorm
237 END IF
238
239 ELSE
240
241
242
243 CALL zscal( n-1, alpha, x, incx )
244
245 END IF
246
247
248
249 DO 20 j = 1, knt
250 beta = beta*smlnum
251 20 CONTINUE
252 alpha = beta
253 END IF
254
255 RETURN
256
257
258
complex *16 function zladiv(x, y)
ZLADIV performs complex division in real arithmetic, avoiding unnecessary overflow.
double precision function dlamch(cmach)
DLAMCH
double precision function dlapy2(x, y)
DLAPY2 returns sqrt(x2+y2).
double precision function dlapy3(x, y, z)
DLAPY3 returns sqrt(x2+y2+z2).
real(wp) function dznrm2(n, x, incx)
DZNRM2
subroutine zdscal(n, da, zx, incx)
ZDSCAL
subroutine zscal(n, za, zx, incx)
ZSCAL