-int calc_fluctuations(double start,double end,char *file) {
-
- int fd;
- int count,ret;
- double time,pot,kin,tot;
- double p_m,k_m,t_m;
- double p2_m,k2_m,t2_m;
- double p_sum,k_sum,t_sum;
- char buf[LINE_MAX];
-
- fd=open(file,O_RDONLY);
- if(fd<0) {
- perror("[moldyn] post proc open");
- return fd;
- }
-
- /* first calc the averages */
- p_sum=0.0;
- k_sum=0.0;
- t_sum=0.0;
- count=0;
- while(1) {
- ret=read_line(fd,buf);
- if(ret<0) break;
-printf("%d\n",ret);
- if(buf[0]=='#') continue;
- sscanf(buf,"%lf %lf %lf %lf",&time,&kin,&pot,&tot);
-printf("%f %f %f %f\n",time,pot,kin,tot);
- //if(time>end) break;
- if((time>=start)&(time<=end)) {
- p_sum+=pot;
- k_sum+=kin;
- t_sum+=tot;
- count+=1;
- }
- }
-
- p_m=p_sum/count;
- k_m=k_sum/count;
- t_m=t_sum/count;
-
- /* mean square fluctuations */
- if(lseek(fd,SEEK_SET,0)<0) {
- perror("[moldyn] lseek");
- return -1;
- }
- count=0;
- p_sum=0.0;
- k_sum=0.0;
- t_sum=0.0;
- while(1) {
- ret=read_line(fd,buf);
- if(ret<0) break;
- if(buf[0]=='#') continue;
- sscanf(buf,"%lf %lf %lf %lf",&time,&kin,&pot,&tot);
- if(time>end) break;
- if((time>=start)&(time<=end)) {
- p_sum+=((pot-p_m)*(pot-p_m));
- k_sum+=((kin-k_m)*(kin-k_m));
- t_sum+=((tot-t_m)*(tot-t_m));
- count+=1;
- }
- }
-
- p2_m=p_sum/count;
- k2_m=k_sum/count;
- t2_m=t_sum/count;
-
- printf("[moldyn] fluctuations (%f - %f):\n",start,end);
- printf(" - averages : %f %f %f\n",k_m,p_m,t_m);
- printf(" - mean square: %f %f %f\n",k2_m,p2_m,t2_m);
-
- close(fd);
-
- return 0;
-}