4 * This source code is part of
8 * GROningen MAchine for Chemical Simulations
11 * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others.
12 * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
13 * Copyright (c) 2001-2004, The GROMACS development team,
14 * check out http://www.gromacs.org for more information.
16 * This program is free software; you can redistribute it and/or
17 * modify it under the terms of the GNU General Public License
18 * as published by the Free Software Foundation; either version 2
19 * of the License, or (at your option) any later version.
21 * If you want to redistribute modifications, please consider that
22 * scientific software is very special. Version control is crucial -
23 * bugs must be traceable. We will be happy to consider code for
24 * inclusion in the official distribution, but derived work must not
25 * be called official GROMACS. Details are found in the README & COPYING
26 * files - if they are missing, get the official version at www.gromacs.org.
28 * To help us fund GROMACS development, we humbly ask that you cite
29 * the papers on the package - you can find them in the top README file.
31 * For more info, check our website at http://www.gromacs.org
34 * Green Red Orange Magenta Azure Cyan Skyblue
43 static void my_usage(char *prog
,char *arg
)
45 fprintf(stderr
," Usage: %s [-p] [-s] [-c #columns]"
46 " naver < infile > outfile\n",prog
);
47 fprintf(stderr
,"-p means picoseconds rather than nanoseconds\n");
48 fprintf(stderr
,"-s means silent rather than verbose\n");
49 fprintf(stderr
,"Don't ever use argument %s again!\n",arg
);
53 void lsq_y_ax_b_double(int n
, double x
[], double y
[], double *a
, double *b
)
59 for (i
=0; (i
< n
); i
++) {
65 *a
=(n
*yx
-sy
*sx
)/(n
*xx
-sx
*sx
);
69 int main(int argc
, char *argv
[])
71 double *x
,**y
,value
=0.001;
72 double *yav
,yyy
,yyy2
,ymin
,ymax
,aver
,var
,sd
;
73 int i
,j
,k
,nav
=100,ncol
=1,MAX
=50000;
75 bool bSilent
=FALSE
,bVerySilent
=FALSE
;
76 double lsq_a
,lsq_b
,rms_res
;
78 for(i
=1; (i
<argc
); i
++) {
79 if (argv
[i
][0] == '-')
85 MAX
=iscan(argc
,argv
,&i
);
88 ncol
=iscan(argc
,argv
,&i
);
94 bVerySilent
=bSilent
=TRUE
;
97 my_usage(argv
[0],argv
[i
]);
103 fprintf(stderr
,"Will average stdin with %d columns, over %d points\n",
109 for(i
=0; (i
<ncol
); i
++) {
115 if (scanf("%s",buf
) == 1) {
116 if ((buf
[0] != '@') && (buf
[0] != '#')) {
117 sscanf(buf
,"%lf",&x
[i
]);
118 for(k
=0; (k
<ncol
); k
++)
119 scanf("%lf",&(y
[k
][i
]));
122 printf("%10e",x
[i
-nav
/2]*value
);
123 for(k
=0; (k
<ncol
); k
++) {
125 for(j
=i
-nav
+1; (j
<=i
); j
++)
129 printf(" %10e",yav
[k
]);
137 while (getc(stdin
) != '\n')
143 } while (((int)strlen(buf
) > 0) && (i
<MAX
));
147 fprintf(stderr
,"%3s %12s %12s %12s %12s %12s %12s %12s\n",
148 "i","min","aver","max","var","sd","drift","fluc");
149 for(k
=0; (k
<ncol
); k
++) {
154 for(j
=1; (j
<i
); j
++) {
164 var
=yyy2
/i
-aver
*aver
;
167 lsq_y_ax_b_double(i
,x
,y
[k
],&lsq_a
,&lsq_b
);
170 rms_res
+=sqr(y
[k
][j
]-(lsq_a
*x
[j
]+lsq_b
));
171 rms_res
=sqrt(rms_res
/i
);
173 fprintf(stderr
,"%3d %12g %12g %12g %12g %12g %12g %12g\n",
174 k
,ymin
,aver
,ymax
,var
,sd
,lsq_a
,rms_res
);