LAPACK  3.10.0
LAPACK: Linear Algebra PACKage

◆ clargv()

subroutine clargv ( integer  N,
complex, dimension( * )  X,
integer  INCX,
complex, dimension( * )  Y,
integer  INCY,
real, dimension( * )  C,
integer  INCC 
)

CLARGV generates a vector of plane rotations with real cosines and complex sines.

Download CLARGV + dependencies [TGZ] [ZIP] [TXT]

Purpose:
 CLARGV generates a vector of complex plane rotations with real
 cosines, determined by elements of the complex vectors x and y.
 For i = 1,2,...,n

    (        c(i)   s(i) ) ( x(i) ) = ( r(i) )
    ( -conjg(s(i))  c(i) ) ( y(i) ) = (   0  )

    where c(i)**2 + ABS(s(i))**2 = 1

 The following conventions are used (these are the same as in CLARTG,
 but differ from the BLAS1 routine CROTG):
    If y(i)=0, then c(i)=1 and s(i)=0.
    If x(i)=0, then c(i)=0 and s(i) is chosen so that r(i) is real.
Parameters
[in]N
          N is INTEGER
          The number of plane rotations to be generated.
[in,out]X
          X is COMPLEX array, dimension (1+(N-1)*INCX)
          On entry, the vector x.
          On exit, x(i) is overwritten by r(i), for i = 1,...,n.
[in]INCX
          INCX is INTEGER
          The increment between elements of X. INCX > 0.
[in,out]Y
          Y is COMPLEX array, dimension (1+(N-1)*INCY)
          On entry, the vector y.
          On exit, the sines of the plane rotations.
[in]INCY
          INCY is INTEGER
          The increment between elements of Y. INCY > 0.
[out]C
          C is REAL array, dimension (1+(N-1)*INCC)
          The cosines of the plane rotations.
[in]INCC
          INCC is INTEGER
          The increment between elements of C. INCC > 0.
Author
Univ. of Tennessee
Univ. of California Berkeley
Univ. of Colorado Denver
NAG Ltd.
Further Details:
  6-6-96 - Modified with a new algorithm by W. Kahan and J. Demmel

  This version has a few statements commented out for thread safety
  (machine parameters are computed on each entry). 10 feb 03, SJH.

Definition at line 121 of file clargv.f.

122 *
123 * -- LAPACK auxiliary routine --
124 * -- LAPACK is a software package provided by Univ. of Tennessee, --
125 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
126 *
127 * .. Scalar Arguments ..
128  INTEGER INCC, INCX, INCY, N
129 * ..
130 * .. Array Arguments ..
131  REAL C( * )
132  COMPLEX X( * ), Y( * )
133 * ..
134 *
135 * =====================================================================
136 *
137 * .. Parameters ..
138  REAL TWO, ONE, ZERO
139  parameter( two = 2.0e+0, one = 1.0e+0, zero = 0.0e+0 )
140  COMPLEX CZERO
141  parameter( czero = ( 0.0e+0, 0.0e+0 ) )
142 * ..
143 * .. Local Scalars ..
144 * LOGICAL FIRST
145  INTEGER COUNT, I, IC, IX, IY, J
146  REAL CS, D, DI, DR, EPS, F2, F2S, G2, G2S, SAFMIN,
147  $ SAFMN2, SAFMX2, SCALE
148  COMPLEX F, FF, FS, G, GS, R, SN
149 * ..
150 * .. External Functions ..
151  REAL SLAMCH, SLAPY2
152  EXTERNAL slamch, slapy2
153 * ..
154 * .. Intrinsic Functions ..
155  INTRINSIC abs, aimag, cmplx, conjg, int, log, max, real,
156  $ sqrt
157 * ..
158 * .. Statement Functions ..
159  REAL ABS1, ABSSQ
160 * ..
161 * .. Save statement ..
162 * SAVE FIRST, SAFMX2, SAFMIN, SAFMN2
163 * ..
164 * .. Data statements ..
165 * DATA FIRST / .TRUE. /
166 * ..
167 * .. Statement Function definitions ..
168  abs1( ff ) = max( abs( real( ff ) ), abs( aimag( ff ) ) )
169  abssq( ff ) = real( ff )**2 + aimag( ff )**2
170 * ..
171 * .. Executable Statements ..
172 *
173 * IF( FIRST ) THEN
174 * FIRST = .FALSE.
175  safmin = slamch( 'S' )
176  eps = slamch( 'E' )
177  safmn2 = slamch( 'B' )**int( log( safmin / eps ) /
178  $ log( slamch( 'B' ) ) / two )
179  safmx2 = one / safmn2
180 * END IF
181  ix = 1
182  iy = 1
183  ic = 1
184  DO 60 i = 1, n
185  f = x( ix )
186  g = y( iy )
187 *
188 * Use identical algorithm as in CLARTG
189 *
190  scale = max( abs1( f ), abs1( g ) )
191  fs = f
192  gs = g
193  count = 0
194  IF( scale.GE.safmx2 ) THEN
195  10 CONTINUE
196  count = count + 1
197  fs = fs*safmn2
198  gs = gs*safmn2
199  scale = scale*safmn2
200  IF( scale.GE.safmx2 .AND. count .LT. 20 )
201  $ GO TO 10
202  ELSE IF( scale.LE.safmn2 ) THEN
203  IF( g.EQ.czero ) THEN
204  cs = one
205  sn = czero
206  r = f
207  GO TO 50
208  END IF
209  20 CONTINUE
210  count = count - 1
211  fs = fs*safmx2
212  gs = gs*safmx2
213  scale = scale*safmx2
214  IF( scale.LE.safmn2 )
215  $ GO TO 20
216  END IF
217  f2 = abssq( fs )
218  g2 = abssq( gs )
219  IF( f2.LE.max( g2, one )*safmin ) THEN
220 *
221 * This is a rare case: F is very small.
222 *
223  IF( f.EQ.czero ) THEN
224  cs = zero
225  r = slapy2( real( g ), aimag( g ) )
226 * Do complex/real division explicitly with two real
227 * divisions
228  d = slapy2( real( gs ), aimag( gs ) )
229  sn = cmplx( real( gs ) / d, -aimag( gs ) / d )
230  GO TO 50
231  END IF
232  f2s = slapy2( real( fs ), aimag( fs ) )
233 * G2 and G2S are accurate
234 * G2 is at least SAFMIN, and G2S is at least SAFMN2
235  g2s = sqrt( g2 )
236 * Error in CS from underflow in F2S is at most
237 * UNFL / SAFMN2 .lt. sqrt(UNFL*EPS) .lt. EPS
238 * If MAX(G2,ONE)=G2, then F2 .lt. G2*SAFMIN,
239 * and so CS .lt. sqrt(SAFMIN)
240 * If MAX(G2,ONE)=ONE, then F2 .lt. SAFMIN
241 * and so CS .lt. sqrt(SAFMIN)/SAFMN2 = sqrt(EPS)
242 * Therefore, CS = F2S/G2S / sqrt( 1 + (F2S/G2S)**2 ) = F2S/G2S
243  cs = f2s / g2s
244 * Make sure abs(FF) = 1
245 * Do complex/real division explicitly with 2 real divisions
246  IF( abs1( f ).GT.one ) THEN
247  d = slapy2( real( f ), aimag( f ) )
248  ff = cmplx( real( f ) / d, aimag( f ) / d )
249  ELSE
250  dr = safmx2*real( f )
251  di = safmx2*aimag( f )
252  d = slapy2( dr, di )
253  ff = cmplx( dr / d, di / d )
254  END IF
255  sn = ff*cmplx( real( gs ) / g2s, -aimag( gs ) / g2s )
256  r = cs*f + sn*g
257  ELSE
258 *
259 * This is the most common case.
260 * Neither F2 nor F2/G2 are less than SAFMIN
261 * F2S cannot overflow, and it is accurate
262 *
263  f2s = sqrt( one+g2 / f2 )
264 * Do the F2S(real)*FS(complex) multiply with two real
265 * multiplies
266  r = cmplx( f2s*real( fs ), f2s*aimag( fs ) )
267  cs = one / f2s
268  d = f2 + g2
269 * Do complex/real division explicitly with two real divisions
270  sn = cmplx( real( r ) / d, aimag( r ) / d )
271  sn = sn*conjg( gs )
272  IF( count.NE.0 ) THEN
273  IF( count.GT.0 ) THEN
274  DO 30 j = 1, count
275  r = r*safmx2
276  30 CONTINUE
277  ELSE
278  DO 40 j = 1, -count
279  r = r*safmn2
280  40 CONTINUE
281  END IF
282  END IF
283  END IF
284  50 CONTINUE
285  c( ic ) = cs
286  y( iy ) = sn
287  x( ix ) = r
288  ic = ic + incc
289  iy = iy + incy
290  ix = ix + incx
291  60 CONTINUE
292  RETURN
293 *
294 * End of CLARGV
295 *
real function slapy2(X, Y)
SLAPY2 returns sqrt(x2+y2).
Definition: slapy2.f:63
real function slamch(CMACH)
SLAMCH
Definition: slamch.f:68
Here is the caller graph for this function: