added del_atom function
authorhackbard <hackbard@sage.physik.uni-augsburg.de>
Thu, 4 Oct 2007 12:25:31 +0000 (14:25 +0200)
committerhackbard <hackbard@sage.physik.uni-augsburg.de>
Thu, 4 Oct 2007 12:25:31 +0000 (14:25 +0200)
moldyn.c
moldyn.h

index 415581c..41e022a 100644 (file)
--- a/moldyn.c
+++ b/moldyn.c
@@ -558,6 +558,35 @@ int add_atom(t_moldyn *moldyn,int element,double mass,u8 brand,u8 attr,
        return 0;
 }
 
+int del_atom(t_moldyn *moldyn,int tag) {
+
+       t_atom *new,*old;
+       int cnt;
+
+       old=moldyn->atom;
+
+       new=(t_atom *)malloc((moldyn->count-1)*sizeof(t_atom));
+       if(!new) {
+               perror("[moldyn]malloc (del atom)");
+               return -1;
+       }
+
+       for(cnt=0;cnt<tag;cnt++)
+               new[cnt]=old[cnt];
+       
+       for(cnt=tag+1;cnt<moldyn->count;cnt++) {
+               new[cnt-1]=old[cnt];
+               new[cnt-1].tag=cnt-1;
+       }
+
+       moldyn->count-=1;
+       moldyn->atom=new;
+
+       free(old);
+
+       return 0;
+}
+
 /* cubic init */
 int cubic_init(int a,int b,int c,double lc,t_atom *atom,t_3dvec *origin) {
 
index 36e701e..0078990 100644 (file)
--- a/moldyn.h
+++ b/moldyn.h
@@ -417,6 +417,7 @@ int create_lattice(t_moldyn *moldyn,u8 type,double lc,int element,double mass,
                    u8 attr,u8 brand,int a,int b,int c,t_3dvec *origin);
 int add_atom(t_moldyn *moldyn,int element,double mass,u8 brand,u8 attr,
              t_3dvec *r,t_3dvec *v);
+int del_atom(t_moldyn *moldyn,int tag);
 int cubic_init(int a,int b,int c,double lc,t_atom *atom,t_3dvec *origin);
 int fcc_init(int a,int b,int c,double lc,t_atom *atom,t_3dvec *origin);
 int diamond_init(int a,int b,int c,double lc,t_atom *atom,t_3dvec *origin);