2 * pc_calc.c - calculate the pc
4 * author: frank.zirkelbach@physik.uni-augsburg.de
11 #include <sys/types.h>
22 typedef struct s_atom {
27 int get_line(int fd,char *line,int max) {
34 if(count==max) return count;
35 ret=read(fd,line+count,1);
36 if(ret<=0) return ret;
37 if(line[count]=='\n') {
38 memset(line+count,0,max-count-1);
46 int main(int argc,char **argv) {
49 double *aslot,*bslot,*cslot;
50 int acnt,bcnt,ccnt,cnt,count,slots;
54 double dx2,dy2,dz2,dist,norm;
58 printf("usage: %s file sx sy sz\n",argv[0]);
62 fd=open(argv[1],O_RDONLY);
64 perror("open file\n");
73 cnt=get_line(fd,buf,256);
78 cnt=get_line(fd,buf,256);
82 // there is (another) atom
84 atom=realloc(atom,(count+1)*sizeof(t_atom));
86 atom[count].type=wptr[0];
88 wptr=strtok(NULL," ");
89 atom[count].x=atof(wptr);
90 wptr=strtok(NULL," ");
91 atom[count].y=atof(wptr);
92 wptr=strtok(NULL," ");
93 atom[count].z=atof(wptr);
98 printf("i: read in %d atoms ...\n",count);
103 aslot=malloc(slots*sizeof(double));
108 memset(aslot,0,slots*sizeof(double));
109 bslot=malloc(slots*sizeof(double));
114 memset(bslot,0,slots*sizeof(double));
115 cslot=malloc(slots*sizeof(double));
120 memset(cslot,0,slots*sizeof(double));
122 printf("i: allocated 3 times %d slots ...\n",slots);
130 for(i=0;i<count;i++) {
132 dx2=atom[i].x-atom[j].x;
138 dy2=atom[i].y-atom[j].y;
144 dz2=atom[i].z-atom[j].z;
150 dist=sqrt(dx2+dy2+dz2);
154 if((atom[i].type=='S')&&(atom[j].type=='S')) {
158 else if((atom[i].type=='C')&&(atom[j].type=='C')) {
169 // normalization and output
171 for(i=1;i<slots;i++) {
172 norm=4*M_PI*(i*DELTA)*(i*DELTA)*DELTA;
173 printf("pc: %f %f %f %f\n",i*DELTA,