float-store bugfix (unstatisfying!) + slightly new design of sic.c
[physik/posic.git] / pair_correlation_calc.c
1 /*
2  * calcultae pair correlation function
3  *
4  * author: frank.zirkelbach@physik.uni-augsburg.de
5  *
6  */
7
8 #define _GNU_SOURCE
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include <unistd.h>
12 #include <string.h>
13 #include <sys/types.h>
14 #include <sys/stat.h>
15 #include <fcntl.h>
16
17 #include "moldyn.h"
18
19 int usage(char *prog) {
20
21         printf("\nusage:\n");
22         printf("  %s <save file> <dr>\n\n",prog);
23
24         return -1;
25 }
26
27 int main(int argc,char **argv) {
28
29         t_moldyn moldyn;
30         int ret;
31         double *stat;
32         int slots;
33         int i;
34         double dr;
35         int fd;
36
37         if(argc!=3) {
38                 usage(argv[0]);
39                 return -1;
40         }
41
42         memset(&moldyn,0,sizeof(t_moldyn));
43
44         ret=moldyn_read_save_file(&moldyn,argv[1]);
45         if(ret) {
46                 printf("[pair corr calc] exit!\n");
47                 return ret;
48         }
49
50         //moldyn.cutoff*=2;
51         //moldyn.cutoff_square*=4;
52
53         dr=atof(argv[2]);
54         slots=moldyn.cutoff/dr;
55         printf("[pair corr calc]\n");
56         printf("  slots: %d\n",slots);
57         printf("  cutoff: %f\n",moldyn.cutoff);
58         printf("  dr: %f\n",dr);
59
60         stat=(double *)malloc(3*slots*sizeof(double));
61         if(stat==NULL) {
62                 perror("[pair corr calc] alloc mem");
63                 return -1;
64         }
65
66         calculate_pair_correlation(&moldyn,dr,stat);
67
68         fd=open("pair_corr_func_ab.txt",
69                 O_WRONLY|O_CREAT|O_TRUNC,S_IRUSR|S_IWUSR);
70         dprintf(fd,"# type a - type b bonds\n");
71         for(i=0;i<slots;i++)
72                 dprintf(fd,"%f %f\n",i*dr,stat[i]);
73         close(fd);
74                 
75         fd=open("pair_corr_func_aa.txt",
76                 O_WRONLY|O_CREAT|O_TRUNC,S_IRUSR|S_IWUSR);
77         dprintf(fd,"# type a - type a bonds\n");
78         for(i=0;i<slots;i++)
79                 dprintf(fd,"%f %f\n",i*dr,stat[slots+i]);
80         close(fd);
81                 
82         fd=open("pair_corr_func_bb.txt",
83                 O_WRONLY|O_CREAT|O_TRUNC,S_IRUSR|S_IWUSR);
84         dprintf(fd,"# type a - type b bonds\n");
85         for(i=0;i<slots;i++)
86                 dprintf(fd,"%f %f\n",i*dr,stat[2*slots+i]);
87         close(fd);
88                 
89         free(stat);
90
91         return 0;
92 }