f8d14372382a621f4d65c2be3607ed3a3d81a83e
[alexxy/gromacs.git] / src / gmxlib / gmx_blas / dasum.c
1 #include <math.h>
2 #include "gmx_blas.h"
3
4 double
5 F77_FUNC(dasum,DASUM)(int *n__, 
6                       double *dx, 
7                       int *incx__)
8 {
9     int i__1, i__2;
10     
11     int i__, m, mp1;
12     double dtemp;
13     int nincx;
14     
15     int n = *n__;
16     int incx = *incx__;
17     
18     --dx;
19     
20     dtemp = 0.;
21     if (n <= 0 || incx <= 0) {
22         return 0.0;
23     }
24     if (incx != 1) {
25         nincx = n * incx;
26         i__1 = nincx;
27         i__2 = incx;
28         for (i__ = 1; i__2 < 0 ? i__ >= i__1 : i__ <= i__1; i__ += i__2) {
29             dtemp += fabs(dx[i__]);
30         }
31         return dtemp;
32     }
33     
34     m = n % 6;
35     if (m != 0) {
36         i__2 = m;
37         for (i__ = 1; i__ <= i__2; ++i__) {
38             dtemp += fabs(dx[i__]);
39         }
40         if (n < 6) {
41             return dtemp;
42         }
43     }
44     mp1 = m + 1;
45     i__2 = n;
46     for (i__ = mp1; i__ <= i__2; i__ += 6) {
47         dtemp = dtemp + fabs(dx[i__]) + fabs(dx[i__ + 1]) + 
48         fabs(dx[i__ + 2]) + fabs(dx[i__+ 3]) + fabs(dx[i__ + 4]) +
49         fabs(dx[i__ + 5]);
50     }
51     return dtemp;
52 }
53
54