Previous Next Contents Generated Index Doc Set Home



Swap Two Vectors

The subroutines described in this section exchange the vectors x and y.

Calling Sequence

CALL DSWAP 
(N, DX, INCX, DY, INCY)
CALL SSWAP 
(N, SX, INCX, SY, INCY)
CALL ZSWAP 
(N, ZX, INCX, ZY, INCY)
CALL CSWAP 
(N, CX, INCX, CY, INCY)






void dswap 
(int n, double *dx, int incx, double *dy, int incy)
void sswap 
(int n, float *sx, int incx, float *sy, int incy)
void zswap 
(int n, doublecomplex *zx, int incx, doublecomplex *zy, 
int incy)
void cswap 
(int n, complex *cx, int incx, complex *cy, int incy)

Arguments

N

Number of elements in the vector. N 0.

xX

Input vector X; the size of array X must be at least max(1,N*|INCX|).

INCX

Specifies the storage spacing between successive elements of the vector X. A value of one indicates that the elements of the vector are consecutive in memory.

If X refers to a two-dimensional array and the value of INCX is equal to the leading dimension of X then the elements of the vector will be a row of X.

If X refers to a two-dimensional array and the value of INCX is equal to the leading dimension of X plus one then the elements of the vector will be a diagonal of X.

xY

Result vector Y; the size of array Y must be at least max(1,N*|INCY|).

INCY

Specifies the storage spacing between successive elements of the vector Y. A value of one indicates that the elements of the vector are consecutive in memory.

If Y refers to a two-dimensional array and the value of INCY is equal to the leading dimension of Y then the elements of the vector will be a row of Y.

If Y refers to a two-dimensional array and the value of INCY is equal to the leading dimension of Y plus one then the elements of the vector will be a diagonal of Y.

Sample Program

 
      PROGRAM TEST
      IMPLICIT NONE
      INTEGER N
      PARAMETER (N = 3)
      INTEGER I, INCX, INCY, J, LARGE
      DOUBLE PRECISION A(N,N)
      INTEGER IDAMAX
      EXTERNAL DSWAP, IDAMAX
C
C     Initialize the array A to store the matrix A shown below.
C
C         1.0  1.5  4.5
C     A = 3.0  2.5  9.5
C         2.0  3.5  5.5
C
      DATA A / 1.0D0, 3.0D0, 2.0D0, 1.5D0, 2.5D0, 3.5D0,
     $         4.5D0, 9.5D0, 5.5D0 /
C
      PRINT 1000
      PRINT 1010, ((A(I,J), J = 1, N), I = 1, N)
C
C     Find the largest element in column 1.
C
      INCX = 1
      LARGE = IDAMAX (N, A, INCX)
C
C     Swap the first row with the row containing the largest
C     element in column 1.
C
      INCX = N
      INCY = N
      CALL DSWAP (N, A(1,1), INCX, A(LARGE,1), INCY)
      PRINT 1020
      PRINT 1010, ((A(I,J), J = 1, N), I = 1, N)
C
 1000 FORMAT (1X, 'A:')
 1010 FORMAT (3(3(2X, F3.1) / ))
 1020 FORMAT (1X, 'A'':')
C
      END
 

Sample Output

 
 A:
  1.0  1.5  4.5
  3.0  2.5  9.5
  2.0  3.5  5.5



 A':
  3.0  2.5  9.5
  1.0  1.5  4.5
  2.0  3.5  5.5










Previous Next Contents Generated Index Doc Set Home