+ int i,j,k,c;
+ int offset,off;
+ int carry;
+
+ /* put one c ion somewhere in the lattice */
+ if(my_info->cc<c_ratio*step)
+ {
+ x=get_rand(d3_l->max_x);
+ y=get_rand(d3_l->max_y);
+ z=get_rand_lgp(d3_l->max_z,my_info->a_cd,my_info->b_cd);
+ *(d3_l->extra+x+y*d3_l->max_x+z*d3_l->max_x*d3_l->max_y)+=1;
+ (my_info->cc)++;
+ }
+
+ if(step%my_info->diff_rate==0)
+ {
+
+ for(i=0;i<d3_l->max_x;i++)
+ {
+ for(j=0;j<d3_l->max_y;j++)
+ {
+ for(k=0;k<d3_l->max_z;k++)
+ {
+ offset=i+j*d3_l->max_x+k*d3_l->max_x*d3_l->max_y;
+ /* case amorph - amorph <-> cryst diffusion */
+ if(*(d3_l->status+offset)&AMORPH)
+ {
+ for(c=-1;c<=1;c++)
+ {
+ if(c!=0)
+ {
+ off=((i+d3_l->max_x+c)%d3_l->max_x)+j*d3_l->max_x+k*d3_l->max_x*d3_l->max_y;
+ carry=0;
+ if(!(*(d3_l->status+off)&AMORPH)) carry=(int)(my_info->dr_ac*(*(d3_l->extra+off)));
+ if(carry!=0)
+ {
+ *(d3_l->extra+offset)+=carry;
+ *(d3_l->extra+off)-=carry;
+ }
+ }
+ }
+ for(c=-1;c<=1;c++)
+ {
+ if(c!=0)
+ {
+ off=i+((j+c+d3_l->max_y)%d3_l->max_y)*d3_l->max_x+k*d3_l->max_x*d3_l->max_y;
+ carry=0;
+ if(!(*(d3_l->status+off)&AMORPH)) carry=(int)(my_info->dr_ac*(*(d3_l->extra+off)));
+ if(carry!=0)
+ {
+ *(d3_l->extra+offset)+=carry;
+ *(d3_l->extra+off)-=carry;
+ }
+ }
+ }
+ if(my_info->z_diff)
+ {
+ for(c=-1;c<=1;c++)
+ {
+ if(c!=0)
+ {
+ off=i+j*d3_l->max_x+((k+c+d3_l->max_z)%d3_l->max_z)*d3_l->max_x*d3_l->max_y;
+ carry=0;
+ if(!*(d3_l->status+off)&AMORPH) carry=(int)(my_info->dr_ac*(*(d3_l->extra+off)));
+ if(carry!=0)
+ {
+ *(d3_l->extra+off)-=carry;
+ *(d3_l->extra+offset)+=carry;
+ }
+ }
+ }
+ }
+ } else
+ /* case not amorph - cryst <-> cryst diffusion */
+ {
+ for(c=-1;c<=1;c++)
+ {
+ if(c!=0)
+ {
+ off=i+((j+c+d3_l->max_y)%d3_l->max_y)*d3_l->max_x+k*d3_l->max_x*d3_l->max_y;
+ carry=0;
+ if(!(*(d3_l->status+off)&AMORPH))
+ {
+ carry=(int)(my_info->dr_cc*(*(d3_l->extra+off)-*(d3_l->extra+offset))/2);
+ if(carry!=0)
+ {
+ *(d3_l->extra+offset)+=carry;
+ *(d3_l->extra+off)-=carry;
+ }
+ }
+ }
+ }
+ for(c=-1;c<=1;c++)
+ {
+ if(c!=0)
+ {
+ off=((i+c+d3_l->max_x)%d3_l->max_x)+j*d3_l->max_x+k*d3_l->max_x*d3_l->max_y;
+ carry=0;
+ if(!(*(d3_l->status+off)&AMORPH))
+ {
+ carry=(int)(my_info->dr_cc*(*(d3_l->extra+off)-*(d3_l->extra+offset))/2);
+ if(carry!=0)
+ {
+ *(d3_l->extra+offset)+=carry;
+ *(d3_l->extra+off)-=carry;
+ }
+ }
+ }
+ }
+ }
+ } /* for z */
+ } /* for y */
+ } /* for x */