subroutine saxpy (n, sa, sx, incx, sy, incy) C***BEGIN PROLOGUE SAXPY C***PURPOSE Compute a constant times a vector plus a vector. C***CATEGORY D1A7 C***TYPE SINGLE PRECISION (SAXPY-S, DAXPY-D, CAXPY-C) C***KEYWORDS BLAS, LINEAR ALGEBRA, TRIAD, VECTOR C***AUTHOR Lawson, C. L., (JPL) C Hanson, R. J., (SNLA) C Kincaid, D. R., (U. of Texas) C Krogh, F. T., (JPL) C***DESCRIPTION C C B L A S Subprogram C Description of Parameters C C --Input-- c n number of elements in input vector(s) c sa single precision scalar multiplier c sx single precision vector with n elements c incx storage spacing between elements of sx c sy single precision vector with n elements c incy storage spacing between elements of sy C C --Output-- c sy single precision result (unchanged if n .le. 0) C C Overwrite single precision SY with single precision SA*SX +SY. C For I = 0 to N-1, replace SY(LY+I*INCY) with SA*SX(LX+I*INCX) + C SY(LY+I*INCY), C where LX = 1 if INCX .GE. 0, else LX = 1+(1-N)*INCX, and LY is C defined in a similar way using INCY. C C***REFERENCES C. L. Lawson, R. J. Hanson, D. R. Kincaid and F. T. C Krogh, Basic linear algebra subprograms for Fortran C usage, Algorithm No. 539, Transactions on Mathematical C Software 5, 3 (September 1979), pp. 308-323. C***ROUTINES CALLED (NONE) C***REVISION HISTORY (YYMMDD) C 791001 DATE WRITTEN C 890831 Modified array declarations. (WRB) C 890831 REVISION DATE from Version 3.2 C 891214 Prologue converted to Version 4.0 format. (BAB) C 920310 Corrected definition of LX in DESCRIPTION. (WRB) C 920501 Reformatted the REFERENCES section. (WRB) C 010807 Added specific declaration for all variables (FAF) C***END PROLOGUE SAXPY real sx(*), sy(*), sa integer incy, incx, n, ix, iy, i, m, mp1, ns c***first executable statement saxpy if (n.le.0 .or. sa.eq.0.0e0) return if (incx .eq. incy) if (incx-1) 5,20,60 c c code for unequal or nonpositive increments. c 5 ix = 1 iy = 1 if (incx .lt. 0) ix = (-n+1)*incx + 1 if (incy .lt. 0) iy = (-n+1)*incy + 1 do 10 i = 1,n sy(iy) = sy(iy) + sa*sx(ix) ix = ix + incx iy = iy + incy 10 continue return c c code for both increments equal to 1. c c clean-up loop so remaining vector length is a multiple of 4. c 20 m = mod(n,4) if (m .eq. 0) go to 40 do 30 i = 1,m sy(i) = sy(i) + sa*sx(i) 30 continue if (n .lt. 4) return 40 mp1 = m + 1 do 50 i = mp1,n,4 sy(i) = sy(i) + sa*sx(i) sy(i+1) = sy(i+1) + sa*sx(i+1) sy(i+2) = sy(i+2) + sa*sx(i+2) sy(i+3) = sy(i+3) + sa*sx(i+3) 50 continue return c c code for equal, positive, non-unit increments. c 60 ns = n*incx do 70 i = 1,ns,incx sy(i) = sa*sx(i) + sy(i) 70 continue return end