Copy vector

Fortran Equivalent

SCOPY/DCOPY/ICOPY/CCOPY/CCOPYC/ZCOPY/ZCOPYC

SUBROUTINE SCOPY (N, X,INCX, Y,INCY)

REAL*4 X(*),Y(*)

IF ( N .LE. 0 ) RETURN

IX = 1

IY = 1

IF ( INCX .LT. 0 ) IX = 1 - (N-1) * INCX

IF ( INCY .LT. 0 ) IY = 1 - (N-1) * INCY

DO 10 I = 1, N

Y(IY) = X(IX)

IX = IX + INCX

IY = IY + INCY

10CONTINUE RETURN END

Example 1 Copy the REAL*8 vector x into y, where x and y are vectors 10 elements long stored in one-dimensional arrays X and Y of dimension 20.

INTEGER*4 N,INCX,INCY

REAL*8

X(20),Y(20)

N = 10

 

INCX = 1

 

INCY

= 1

 

CALL

DCOPY (N,X,INCX,Y,INCY)

Example 2 Initialize a one-dimensional array to zero.

INTEGER*4

N

REAL*8

Y(20)

N = 10

 

CALL DCOPY (N,0.0D0,0,Y,1)

Chapter 2 Basic Vector Operations 83