scasum.f 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. *DECK SCASUM
  2. FUNCTION SCASUM (N, CX, INCX)
  3. C***BEGIN PROLOGUE SCASUM
  4. C***PURPOSE Compute the sum of the magnitudes of the real and
  5. C imaginary elements of a complex vector.
  6. C***LIBRARY SLATEC (BLAS)
  7. C***CATEGORY D1A3A
  8. C***TYPE COMPLEX (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 CX complex vector with N elements
  22. C INCX storage spacing between elements of CX
  23. C
  24. C --Output--
  25. C SCASUM single precision result (zero if N .LE. 0)
  26. C
  27. C Returns sums of magnitudes of real and imaginary parts of
  28. C components of CX. Note that this is not the L1 norm of CX.
  29. C CASUM = sum from 0 to N-1 of ABS(REAL(CX(IX+I*INCX))) +
  30. C ABS(IMAG(CX(IX+I*INCX))),
  31. C where IX = 1 if INCX .GE. 0, else IX = 1+(1-N)*INCX.
  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 900821 Modified to correct problem with a negative increment.
  44. C (WRB)
  45. C 920501 Reformatted the REFERENCES section. (WRB)
  46. C***END PROLOGUE SCASUM
  47. COMPLEX CX(*)
  48. INTEGER I, INCX, IX, N
  49. C***FIRST EXECUTABLE STATEMENT SCASUM
  50. SCASUM = 0.0E0
  51. IF (N .LE. 0) RETURN
  52. C
  53. IF (INCX .EQ. 1) GOTO 20
  54. C
  55. C Code for increment not equal to 1.
  56. C
  57. IX = 1
  58. IF (INCX .LT. 0) IX = (-N+1)*INCX + 1
  59. DO 10 I = 1,N
  60. SCASUM = SCASUM + ABS(REAL(CX(IX))) + ABS(AIMAG(CX(IX)))
  61. IX = IX + INCX
  62. 10 CONTINUE
  63. RETURN
  64. C
  65. C Code for increment equal to 1.
  66. C
  67. 20 DO 30 I = 1,N
  68. SCASUM = SCASUM + ABS(REAL(CX(I))) + ABS(AIMAG(CX(I)))
  69. 30 CONTINUE
  70. RETURN
  71. END