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 cnt,count,fcnt,slots;
54 double dx2,dy2,dz2,dist,norm;
60 printf("usage: %s sx sy sz file1 file2 ...\n",argv[0]);
71 aslot=malloc(slots*sizeof(double));
76 memset(aslot,0,slots*sizeof(double));
77 bslot=malloc(slots*sizeof(double));
82 memset(bslot,0,slots*sizeof(double));
83 cslot=malloc(slots*sizeof(double));
88 memset(cslot,0,slots*sizeof(double));
90 printf("i: allocated 3 times %d slots ...\n",slots);
92 // use all given files ...
93 printf("using files:\n");
94 for(fcnt=4;fcnt<argc;fcnt++)
95 printf(" %d: %s\n",fcnt-4,argv[fcnt]);
97 for(fcnt=4;fcnt<argc;fcnt++) {
99 fd=open(argv[fcnt],O_RDONLY);
101 perror("open file\n");
106 cnt=get_line(fd,buf,256);
111 cnt=get_line(fd,buf,256);
115 // there is (another) atom
117 atom=realloc(atom,(count+1)*sizeof(t_atom));
118 wptr=strtok(buf," ");
119 atom[count].type=wptr[0];
121 wptr=strtok(NULL," ");
122 atom[count].x=atof(wptr);
123 wptr=strtok(NULL," ");
124 atom[count].y=atof(wptr);
125 wptr=strtok(NULL," ");
126 atom[count].z=atof(wptr);
131 printf("i: read in %d atoms ...\n",count);
135 for(i=0;i<count;i++) {
137 dx2=atom[i].x-atom[j].x;
143 dy2=atom[i].y-atom[j].y;
149 dz2=atom[i].z-atom[j].z;
155 dist=sqrt(dx2+dy2+dz2);
159 if((atom[i].type=='S')&&(atom[j].type=='S')) {
162 else if((atom[i].type=='C')&&(atom[j].type=='C')) {
174 // normalization and output
176 for(i=1;i<slots;i++) {
177 norm=4*M_PI*(i*DELTA)*(i*DELTA)*DELTA;
178 printf("pc: %f %f %f %f\n",i*DELTA,