HP MLIB User's Guide Vol. 1 7th Ed.
Chapter 2 Basic Vector Operations 73
Two sided vector clip SCLIP/DCLIP/ICLIP
incy Increment for the array y, incy ≠ 0:
incy > 0 y is stored forward in array y; that is,
y
i
is stored in y((i−1)×incy+1).
incy < 0 y is stored backward in array y; that
is, y
i
is stored in y((i−n)×incy+1).
Use incy = 1 if the vector y is stored contiguously in
array y; that is, if y
i
is stored in y(i). Refer to “BLAS
Indexing Conventions” in the introduction to this
chapter.
Output y Array of length leny = (n−1)×|incy|+1 containing the
n-vector y. If n ≤ 0, then y is unchanged. Otherwise, y is
set as specified in “Purpose.”
Notes x and y can be the same array if incx = incy. Otherwise, the result is
unspecified if x and y overlap such that any element of x shares a memory
location with any element of y.
Fortran
Equivalent
SUBROUTINE SCLIP (N, A,B, X,INCX, Y,INCY)
REAL*4 A,B,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) = MIN ( MAX ( X(IX) , A ) , B )
IX = IX + INCX
IY = IY + INCY
10 CONTINUE
RETURN
END
Example Clip the REAL*8 vector x between −1 and 1 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 A,B,X(20),Y(20)
N = 10
INCX = 1
INCY = 1
A = -1.0D0
B = 1.0D0
CALL DCLIP (N,A,B,X,INCX,Y,INCY)