sswap.f 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. *DECK SSWAP
  2. SUBROUTINE SSWAP (N, SX, INCX, SY, INCY)
  3. C***BEGIN PROLOGUE SSWAP
  4. C***PURPOSE Interchange two vectors.
  5. C***LIBRARY SLATEC (BLAS)
  6. C***CATEGORY D1A5
  7. C***TYPE SINGLE PRECISION (SSWAP-S, DSWAP-D, CSWAP-C, ISWAP-I)
  8. C***KEYWORDS BLAS, INTERCHANGE, LINEAR ALGEBRA, VECTOR
  9. C***AUTHOR Lawson, C. L., (JPL)
  10. C Hanson, R. J., (SNLA)
  11. C Kincaid, D. R., (U. of Texas)
  12. C Krogh, F. T., (JPL)
  13. C***DESCRIPTION
  14. C
  15. C B L A S Subprogram
  16. C Description of Parameters
  17. C
  18. C --Input--
  19. C N number of elements in input vector(s)
  20. C SX single precision vector with N elements
  21. C INCX storage spacing between elements of SX
  22. C SY single precision vector with N elements
  23. C INCY storage spacing between elements of SY
  24. C
  25. C --Output--
  26. C SX input vector SY (unchanged if N .LE. 0)
  27. C SY input vector SX (unchanged if N .LE. 0)
  28. C
  29. C Interchange single precision SX and single precision SY.
  30. C For I = 0 to N-1, interchange SX(LX+I*INCX) and SY(LY+I*INCY),
  31. C where LX = 1 if INCX .GE. 0, else LX = 1+(1-N)*INCX, and LY is
  32. C defined in a similar way using INCY.
  33. C
  34. C***REFERENCES C. L. Lawson, R. J. Hanson, D. R. Kincaid and F. T.
  35. C Krogh, Basic linear algebra subprograms for Fortran
  36. C usage, Algorithm No. 539, Transactions on Mathematical
  37. C Software 5, 3 (September 1979), pp. 308-323.
  38. C***ROUTINES CALLED (NONE)
  39. C***REVISION HISTORY (YYMMDD)
  40. C 791001 DATE WRITTEN
  41. C 890831 Modified array declarations. (WRB)
  42. C 890831 REVISION DATE from Version 3.2
  43. C 891214 Prologue converted to Version 4.0 format. (BAB)
  44. C 920310 Corrected definition of LX in DESCRIPTION. (WRB)
  45. C 920501 Reformatted the REFERENCES section. (WRB)
  46. C***END PROLOGUE SSWAP
  47. REAL SX(*), SY(*), STEMP1, STEMP2, STEMP3
  48. C***FIRST EXECUTABLE STATEMENT SSWAP
  49. IF (N .LE. 0) RETURN
  50. IF (INCX .EQ. INCY) IF (INCX-1) 5,20,60
  51. C
  52. C Code for unequal or nonpositive increments.
  53. C
  54. 5 IX = 1
  55. IY = 1
  56. IF (INCX .LT. 0) IX = (-N+1)*INCX + 1
  57. IF (INCY .LT. 0) IY = (-N+1)*INCY + 1
  58. DO 10 I = 1,N
  59. STEMP1 = SX(IX)
  60. SX(IX) = SY(IY)
  61. SY(IY) = STEMP1
  62. IX = IX + INCX
  63. IY = IY + INCY
  64. 10 CONTINUE
  65. RETURN
  66. C
  67. C Code for both increments equal to 1.
  68. C
  69. C Clean-up loop so remaining vector length is a multiple of 3.
  70. C
  71. 20 M = MOD(N,3)
  72. IF (M .EQ. 0) GO TO 40
  73. DO 30 I = 1,M
  74. STEMP1 = SX(I)
  75. SX(I) = SY(I)
  76. SY(I) = STEMP1
  77. 30 CONTINUE
  78. IF (N .LT. 3) RETURN
  79. 40 MP1 = M + 1
  80. DO 50 I = MP1,N,3
  81. STEMP1 = SX(I)
  82. STEMP2 = SX(I+1)
  83. STEMP3 = SX(I+2)
  84. SX(I) = SY(I)
  85. SX(I+1) = SY(I+1)
  86. SX(I+2) = SY(I+2)
  87. SY(I) = STEMP1
  88. SY(I+1) = STEMP2
  89. SY(I+2) = STEMP3
  90. 50 CONTINUE
  91. RETURN
  92. C
  93. C Code for equal, positive, non-unit increments.
  94. C
  95. 60 NS = N*INCX
  96. DO 70 I = 1,NS,INCX
  97. STEMP1 = SX(I)
  98. SX(I) = SY(I)
  99. SY(I) = STEMP1
  100. 70 CONTINUE
  101. RETURN
  102. END