dcopy.f 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. *DECK DCOPY
  2. SUBROUTINE DCOPY (N, DX, INCX, DY, INCY)
  3. C***BEGIN PROLOGUE DCOPY
  4. C***PURPOSE Copy a vector.
  5. C***LIBRARY SLATEC (BLAS)
  6. C***CATEGORY D1A5
  7. C***TYPE DOUBLE PRECISION (SCOPY-S, DCOPY-D, CCOPY-C, ICOPY-I)
  8. C***KEYWORDS BLAS, COPY, 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 DX double precision vector with N elements
  21. C INCX storage spacing between elements of DX
  22. C DY double precision vector with N elements
  23. C INCY storage spacing between elements of DY
  24. C
  25. C --Output--
  26. C DY copy of vector DX (unchanged if N .LE. 0)
  27. C
  28. C Copy double precision DX to double precision DY.
  29. C For I = 0 to N-1, copy DX(LX+I*INCX) to DY(LY+I*INCY),
  30. C where LX = 1 if INCX .GE. 0, else LX = 1+(1-N)*INCX, and LY is
  31. C defined in a similar way using INCY.
  32. C
  33. C***REFERENCES C. L. Lawson, R. J. Hanson, D. R. Kincaid and F. T.
  34. C Krogh, Basic linear algebra subprograms for Fortran
  35. C usage, Algorithm No. 539, Transactions on Mathematical
  36. C Software 5, 3 (September 1979), pp. 308-323.
  37. C***ROUTINES CALLED (NONE)
  38. C***REVISION HISTORY (YYMMDD)
  39. C 791001 DATE WRITTEN
  40. C 890831 Modified array declarations. (WRB)
  41. C 890831 REVISION DATE from Version 3.2
  42. C 891214 Prologue converted to Version 4.0 format. (BAB)
  43. C 920310 Corrected definition of LX in DESCRIPTION. (WRB)
  44. C 920501 Reformatted the REFERENCES section. (WRB)
  45. C***END PROLOGUE DCOPY
  46. DOUBLE PRECISION DX(*), DY(*)
  47. C***FIRST EXECUTABLE STATEMENT DCOPY
  48. IF (N .LE. 0) RETURN
  49. IF (INCX .EQ. INCY) IF (INCX-1) 5,20,60
  50. C
  51. C Code for unequal or nonpositive increments.
  52. C
  53. 5 IX = 1
  54. IY = 1
  55. IF (INCX .LT. 0) IX = (-N+1)*INCX + 1
  56. IF (INCY .LT. 0) IY = (-N+1)*INCY + 1
  57. DO 10 I = 1,N
  58. DY(IY) = DX(IX)
  59. IX = IX + INCX
  60. IY = IY + INCY
  61. 10 CONTINUE
  62. RETURN
  63. C
  64. C Code for both increments equal to 1.
  65. C
  66. C Clean-up loop so remaining vector length is a multiple of 7.
  67. C
  68. 20 M = MOD(N,7)
  69. IF (M .EQ. 0) GO TO 40
  70. DO 30 I = 1,M
  71. DY(I) = DX(I)
  72. 30 CONTINUE
  73. IF (N .LT. 7) RETURN
  74. 40 MP1 = M + 1
  75. DO 50 I = MP1,N,7
  76. DY(I) = DX(I)
  77. DY(I+1) = DX(I+1)
  78. DY(I+2) = DX(I+2)
  79. DY(I+3) = DX(I+3)
  80. DY(I+4) = DX(I+4)
  81. DY(I+5) = DX(I+5)
  82. DY(I+6) = DX(I+6)
  83. 50 CONTINUE
  84. RETURN
  85. C
  86. C Code for equal, positive, non-unit increments.
  87. C
  88. 60 NS = N*INCX
  89. DO 70 I = 1,NS,INCX
  90. DY(I) = DX(I)
  91. 70 CONTINUE
  92. RETURN
  93. END