-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathssum.for
50 lines (50 loc) · 1.65 KB
/
ssum.for
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
C Purpose: Sum the values of a single precision vector.
C
C Usage: SSUM(N, SX, INCX)
C
C Arguments:
C N - Length of vectors X. (Input)
C SX - Real vector of length N*INCX. (Input)
C INCX - Displacement between elements of SX. (Input)
C X(I) is defined to be SX(1+(I-1)*INCX). INCX must be
C greater than 0.
C SSUM - Single precision sum from I=1 to N of X(I). (Output)
C X(I) refers to a specific element of SX.
C
C-----------------------------------------------------------------------
C
REAL FUNCTION SSUM (N, SX, INCX)
C SPECIFICATIONS FOR ARGUMENTS
INTEGER N, INCX
REAL SX(*)
C SPECIFICATIONS FOR LOCAL VARIABLES
INTEGER I, M, MP1, NINCX
C SPECIFICATIONS FOR SPECIAL CASES
C INTRINSIC MOD
INTRINSIC MOD
INTEGER MOD
C
SSUM = 0.0E0
IF (N .GT. 0) THEN
IF (INCX .NE. 1) THEN
C CODE FOR INCREMENT NOT EQUAL TO 1
NINCX = N*INCX
DO 10 I=1, NINCX, INCX
SSUM = SSUM + SX(I)
10 CONTINUE
ELSE
C CODE FOR INCREMENT EQUAL TO 1
M = MOD(N,6)
C CLEAN-UP LOOP
DO 30 I=1, M
SSUM = SSUM + SX(I)
30 CONTINUE
MP1 = M + 1
DO 40 I=MP1, N, 6
SSUM = SSUM + SX(I) + SX(I+1) + SX(I+2) + SX(I+3) +
& SX(I+4) + SX(I+5)
40 CONTINUE
END IF
END IF
RETURN
END