SSWAP(3dxml) — Subroutines
Name
sswap, dswap, cswap, zswap − Exchange the elements of two vectors
FORMAT
{S,D,C,Z}SWAP (n, x, incx, y, incy)
Arguments
ninteger∗4
On entry, the number of elements in the vector x.
On exit, n is unchanged.
xreal∗4 | real∗8 | complex∗8 | complex∗16
On entry, a one-dimensional array X of length at least (1+(n-1)∗|incx|), containing the elements of the vector x.
On exit, if n<=0, x is unchanged. If n > 0, x is overwritten; the elements in the array X that are the vector x are overwritten by the vector y.
incxinteger∗4
On entry, the increment for the array X.
If incx >= 0, vector x is stored forward in the array, so that x(i) is stored in location X(1+(i-1)∗incx).
If incx < 0, vector x is stored backward in the array, so that x(i) is stored in location X(1+(n-i)∗|incx|).
On exit, incx is unchanged.
yreal∗4 | real∗8 | complex∗8 | complex∗16
On entry, a one-dimensional array Y of length at least (1+(n-1)∗|incy|).
On exit, if n<=0, y is unchanged. If n > 0, y is overwritten; the elements in the array Y that are the vector y are overwritten by the vector x.
incyinteger∗4
On entry, the increment for the array Y.
If incy >= 0, vector y is stored forward in the array, so that y(i) is stored in location Y(1+(i-1)∗incy).
If incy < 0, vector y is stored backward in the array, so that y(i) is stored in location Y(1+(n-i)∗|incy|).
On exit, incy is unchanged.
Description
These subroutines swap n elements of the vector x with n elements of vector y: x<=>y
If any element of x shares a memory location with an element of y, the results are unpredictable.
If n<=0, x and y are unchanged.
You can use these subroutines to invert the storage of elements of a vector within itself. If incx > 0, each element x(i) is moved from location X(1+(i-1)∗incx) to location X(1+(n-i)∗incx). The following code fragment inverts the storage of elements of a vector within itself:
NN = N/2
LHALF = 1+(N-NN)∗INCX
CALL SSWAP(NN,X,INCX,X(LHALF),-INCX)
Example
INTEGER∗4 INCX, INCY, N
REAL∗4 X(20), Y(20)
INCX = 1
INCY = 1
N = 20
CALL SSWAP(N,X,INCX,Y,INCY)
The preceding FORTRAN code swaps the contents of vectors x and y.
INCX = 1
INCY = -1
N = 50
CALL SSWAP(N,X,INCX,X(51),INCY)
The preceding FORTRAN code inverts the order of storage of the elements of x within itself; that is, it moves x(1),...,x(100) to x(100),...,x(1).