fixed create_lattice routine
[physik/posic.git] / moldyn.c
index 9d782d6..515a273 100644 (file)
--- a/moldyn.c
+++ b/moldyn.c
@@ -185,17 +185,15 @@ int create_lattice(t_moldyn *moldyn,u8 type,double lc,int element,double mass,
        int count;
        int ret;
        t_3dvec origin;
-       t_atom *atom;
 
        count=a*b*c;
-       atom=moldyn->atom;
 
        if(type==FCC) count*=4;
 
        if(type==DIAMOND) count*=8;
 
-       atom=malloc(count*sizeof(t_atom));
-       if(atom==NULL) {
+       moldyn->atom=malloc(count*sizeof(t_atom));
+       if(moldyn->atom==NULL) {
                perror("malloc (atoms)");
                return -1;
        }
@@ -204,10 +202,10 @@ int create_lattice(t_moldyn *moldyn,u8 type,double lc,int element,double mass,
 
        switch(type) {
                case FCC:
-                       ret=fcc_init(a,b,c,lc,atom,&origin);
+                       ret=fcc_init(a,b,c,lc,moldyn->atom,&origin);
                        break;
                case DIAMOND:
-                       ret=diamond_init(a,b,c,lc,atom,&origin);
+                       ret=diamond_init(a,b,c,lc,moldyn->atom,&origin);
                        break;
                default:
                        printf("unknown lattice type (%02x)\n",type);
@@ -225,10 +223,10 @@ int create_lattice(t_moldyn *moldyn,u8 type,double lc,int element,double mass,
        moldyn->count=count;
 
        while(count) {
-               atom[count-1].element=element;
-               atom[count-1].mass=mass;
-               atom[count-1].attr=attr;
-               atom[count-1].bnum=bnum;
+               moldyn->atom[count-1].element=element;
+               moldyn->atom[count-1].mass=mass;
+               moldyn->atom[count-1].attr=attr;
+               moldyn->atom[count-1].bnum=bnum;
                count-=1;
        }