added average feature (needs to get extended)
[physik/posic.git] / vasp_tools / pc_calc.c
index 10275d2..f37506f 100644 (file)
@@ -47,28 +47,61 @@ int main(int argc,char **argv) {
 
        t_atom *atom;
        double *aslot,*bslot,*cslot;
-       int acnt,bcnt,ccnt,cnt,count,slots;
+       int cnt,count,fcnt,slots;
        int fd;
        char buf[256],*wptr;
        int i,j,k;
        double dx2,dy2,dz2,dist,norm;
        double sx,sy,sz;
 
-       if(argc!=5) {
-               printf("usage: %s file sx sy sz\n",argv[0]);
+       atom=NULL;
+
+       if(argc<5) {
+               printf("usage: %s sx sy sz file1 file2 ...\n",argv[0]);
                return -1;
        }
 
-       fd=open(argv[1],O_RDONLY);
+       sx=atof(argv[1]);
+       sy=atof(argv[2]);
+       sz=atof(argv[3]);
+
+       // prepare pc
+
+       slots=MAXR/DELTA;
+       aslot=malloc(slots*sizeof(double));
+       if(aslot==NULL) {
+               perror("slot a\n");
+               return -1;
+       }
+       memset(aslot,0,slots*sizeof(double));
+       bslot=malloc(slots*sizeof(double));
+       if(bslot==NULL) {
+               perror("slot a\n");
+               return -1;
+       }
+       memset(bslot,0,slots*sizeof(double));
+       cslot=malloc(slots*sizeof(double));
+       if(cslot==NULL) {
+               perror("slot a\n");
+               return -1;
+       }
+       memset(cslot,0,slots*sizeof(double));
+
+       printf("i: allocated 3 times %d slots ...\n",slots);
+
+       // use all given files ...
+       printf("using files:\n");
+       for(fcnt=4;fcnt<argc;fcnt++)
+               printf(" %d: %s\n",fcnt-4,argv[fcnt]);
+
+       for(fcnt=4;fcnt<argc;fcnt++) {
+
+       fd=open(argv[fcnt],O_RDONLY);
        if(fd<0) {
                perror("open file\n");
                return fd;
        }
 
-       sx=atof(argv[2]);
-       sy=atof(argv[3]);
-       sz=atof(argv[4]);
-
        // first line
        cnt=get_line(fd,buf,256);
 
@@ -97,34 +130,6 @@ int main(int argc,char **argv) {
 
        printf("i: read in %d atoms ...\n",count);
 
-       // prepare pc
-
-       slots=MAXR/DELTA;
-       aslot=malloc(slots*sizeof(double));
-       if(aslot==NULL) {
-               perror("slot a\n");
-               return -1;
-       }
-       memset(aslot,0,slots*sizeof(double));
-       bslot=malloc(slots*sizeof(double));
-       if(bslot==NULL) {
-               perror("slot a\n");
-               return -1;
-       }
-       memset(bslot,0,slots*sizeof(double));
-       cslot=malloc(slots*sizeof(double));
-       if(cslot==NULL) {
-               perror("slot a\n");
-               return -1;
-       }
-       memset(cslot,0,slots*sizeof(double));
-
-       printf("i: allocated 3 times %d slots ...\n",slots);
-
-       acnt=0;
-       bcnt=0;
-       ccnt=0;
-
        // calc pc
 
        for(i=0;i<count;i++) {
@@ -153,19 +158,19 @@ int main(int argc,char **argv) {
                        k=dist/DELTA;
                        if((atom[i].type=='S')&&(atom[j].type=='S')) {
                                aslot[k]+=1;
-                               acnt+=1;
                        }
                        else if((atom[i].type=='C')&&(atom[j].type=='C')) {
                                bslot[k]+=1;
-                               bcnt+=1;
                        }
                        else {
                                cslot[k]+=1;
-                               ccnt+=1;
                        }
                }
        }
 
+               close(fd);
+       }
+
        // normalization and output
 
        for(i=1;i<slots;i++) {
@@ -182,8 +187,6 @@ int main(int argc,char **argv) {
 
        free(atom);
 
-       close(fd);
-
        return 0;
 
 }