sasum.f 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. *DECK SASUM
  2. REAL FUNCTION SASUM (N, SX, INCX)
  3. C***BEGIN PROLOGUE SASUM
  4. C***PURPOSE Compute the sum of the magnitudes of the elements of a
  5. C vector.
  6. C***LIBRARY SLATEC (BLAS)
  7. C***CATEGORY D1A3A
  8. C***TYPE SINGLE PRECISION (SASUM-S, DASUM-D, SCASUM-C)
  9. C***KEYWORDS BLAS, LINEAR ALGEBRA, SUM OF MAGNITUDES OF A VECTOR
  10. C***AUTHOR Lawson, C. L., (JPL)
  11. C Hanson, R. J., (SNLA)
  12. C Kincaid, D. R., (U. of Texas)
  13. C Krogh, F. T., (JPL)
  14. C***DESCRIPTION
  15. C
  16. C B L A S Subprogram
  17. C Description of Parameters
  18. C
  19. C --Input--
  20. C N number of elements in input vector(S)
  21. C SX single precision vector with N elements
  22. C INCX storage spacing between elements of SX
  23. C
  24. C --Output--
  25. C SASUM single precision result (zero if N .LE. 0)
  26. C
  27. C Returns sum of magnitudes of single precision SX.
  28. C SASUM = sum from 0 to N-1 of ABS(SX(IX+I*INCX)),
  29. C where IX = 1 if INCX .GE. 0, else IX = 1+(1-N)*INCX.
  30. C
  31. C***REFERENCES C. L. Lawson, R. J. Hanson, D. R. Kincaid and F. T.
  32. C Krogh, Basic linear algebra subprograms for Fortran
  33. C usage, Algorithm No. 539, Transactions on Mathematical
  34. C Software 5, 3 (September 1979), pp. 308-323.
  35. C***ROUTINES CALLED (NONE)
  36. C***REVISION HISTORY (YYMMDD)
  37. C 791001 DATE WRITTEN
  38. C 890831 Modified array declarations. (WRB)
  39. C 890831 REVISION DATE from Version 3.2
  40. C 891214 Prologue converted to Version 4.0 format. (BAB)
  41. C 900821 Modified to correct problem with a negative increment.
  42. C (WRB)
  43. C 920501 Reformatted the REFERENCES section. (WRB)
  44. C***END PROLOGUE SASUM
  45. REAL SX(*)
  46. INTEGER I, INCX, IX, M, MP1, N
  47. C***FIRST EXECUTABLE STATEMENT SASUM
  48. SASUM = 0.0E0
  49. IF (N .LE. 0) RETURN
  50. C
  51. IF (INCX .EQ. 1) GOTO 20
  52. C
  53. C Code for increment not equal to 1.
  54. C
  55. IX = 1
  56. IF (INCX .LT. 0) IX = (-N+1)*INCX + 1
  57. DO 10 I = 1,N
  58. SASUM = SASUM + ABS(SX(IX))
  59. IX = IX + INCX
  60. 10 CONTINUE
  61. RETURN
  62. C
  63. C Code for increment equal to 1.
  64. C
  65. C Clean-up loop so remaining vector length is a multiple of 6.
  66. C
  67. 20 M = MOD(N,6)
  68. IF (M .EQ. 0) GOTO 40
  69. DO 30 I = 1,M
  70. SASUM = SASUM + ABS(SX(I))
  71. 30 CONTINUE
  72. IF (N .LT. 6) RETURN
  73. 40 MP1 = M + 1
  74. DO 50 I = MP1,N,6
  75. SASUM = SASUM + ABS(SX(I)) + ABS(SX(I+1)) + ABS(SX(I+2)) +
  76. 1 ABS(SX(I+3)) + ABS(SX(I+4)) + ABS(SX(I+5))
  77. 50 CONTINUE
  78. RETURN
  79. END