cswap.f 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. *DECK CSWAP
  2. SUBROUTINE CSWAP (N, CX, INCX, CY, INCY)
  3. C***BEGIN PROLOGUE CSWAP
  4. C***PURPOSE Interchange two vectors.
  5. C***LIBRARY SLATEC (BLAS)
  6. C***CATEGORY D1A5
  7. C***TYPE COMPLEX (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 CX complex vector with N elements
  21. C INCX storage spacing between elements of CX
  22. C CY complex vector with N elements
  23. C INCY storage spacing between elements of CY
  24. C
  25. C --Output--
  26. C CX input vector CY (unchanged if N .LE. 0)
  27. C CY input vector CX (unchanged if N .LE. 0)
  28. C
  29. C Interchange complex CX and complex CY
  30. C For I = 0 to N-1, interchange CX(LX+I*INCX) and CY(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 CSWAP
  47. COMPLEX CX(*),CY(*),CTEMP
  48. C***FIRST EXECUTABLE STATEMENT CSWAP
  49. IF (N .LE. 0) RETURN
  50. IF (INCX.EQ.INCY .AND. INCX.GT.0) GO TO 20
  51. C
  52. C Code for unequal or nonpositive increments.
  53. C
  54. KX = 1
  55. KY = 1
  56. IF (INCX .LT. 0) KX = 1+(1-N)*INCX
  57. IF (INCY .LT. 0) KY = 1+(1-N)*INCY
  58. DO 10 I = 1,N
  59. CTEMP = CX(KX)
  60. CX(KX) = CY(KY)
  61. CY(KY) = CTEMP
  62. KX = KX + INCX
  63. KY = KY + INCY
  64. 10 CONTINUE
  65. RETURN
  66. C
  67. C Code for equal, positive, non-unit increments.
  68. C
  69. 20 NS = N*INCX
  70. DO 30 I = 1,NS,INCX
  71. CTEMP = CX(I)
  72. CX(I) = CY(I)
  73. CY(I) = CTEMP
  74. 30 CONTINUE
  75. RETURN
  76. END