added average feature (needs to get extended)
authorhackbard <hackbard@sage.physik.uni-augsburg.de>
Sun, 13 Sep 2009 14:06:01 +0000 (16:06 +0200)
committerhackbard <hackbard@sage.physik.uni-augsburg.de>
Sun, 13 Sep 2009 14:06:01 +0000 (16:06 +0200)
vasp_tools/pc_calc.c
vasp_tools/pc_script

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;
 
 }
index 59bd85f..807d506 100755 (executable)
@@ -5,12 +5,17 @@ if [ ! -d $1 ]; then
        exit
 fi
 
-if [ ! -f $1/OUTCAR ]; then
+app=""
+if [ ! -z $2 ]; then
+       app=".${2}"
+fi
+
+if [ ! -f $1/OUTCAR${app} ]; then
        echo "no vasp data found in $1 ..."
        exit
 fi
 
-if [ ! -d $1/video ]; then
+if [ ! -d $1/video${app} ]; then
        echo "no video directory found ..."
        echo "forgot to run outcar2moldyn?"
        exit
@@ -22,17 +27,23 @@ echo "-> reading in sx sy and sz is not correct ..."
 echo "WARNING !!!!"
 echo
 
-line=`sed -n -e '/length of/,/FORCES/p' $1/OUTCAR | grep ^\ \ \  | tail -1`
+line=`sed -n -e '/length of/,/FORCES/p' $1/OUTCAR${app} | \
+       grep ^\ \ \  | tail -1`
 
 sx=`echo $line | awk '{ print $1 }'`
 sy=`echo $line | awk '{ print $2 }'`
 sz=`echo $line | awk '{ print $3 }'`
 
-file=`ls $1/video/atomic_conf*.xyz | tail -1`
+if [ -z $2 ] ; then
+       files=`ls $1/video/atomic_conf*.xyz | tail -1`
+else
+       files=`ls $1/video${app}/atomic_conf*.xyz`
+fi
 
-echo "running on $file using $sx $sy $sz ..."
+echo "running on $files using $sx $sy $sz ..."
 
-./pc_calc $file $sx $sy $sz | grep ^pc | \
+#./pc_calc $sx $sy $sz $files
+./pc_calc $sx $sy $sz $files | grep ^pc | \
        awk '{ print $2 " " $3 " " $4 " "$5 }' > pc.txt
 
 echo "done"