+ 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)
+ {
+ if(k!=0)
+ {
+ off=i+j*d3_l->max_x+(k-1)*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;
+ }
+ }
+ if(k!=d3_l->max_z-1)
+ {
+ off=i+j*d3_l->max_x+(k+1)*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 */
+ if(my_info->c_diff) {
+ /* if there is c diff, no diff in z-direction */
+ {
+ 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;
+ }
+ }
+ }
+ }
+ }
+ /* end test */
+ }
+ /* */
+ } /* for z */
+ } /* for y */
+ } /* for x */
+
+ } /* if step modulo diff_rate == 0 */
+
+ return 1;
+}
+
+int calc_pressure(d3_lattice *d3_l,int range)
+{
+ int i,j,off;
+ double count,max=0;
+ int x,y,z;
+
+ for(x=0;x<d3_l->max_x;x++)
+ {
+ for(y=0;y<d3_l->max_y;y++)
+ {
+ for(z=0;z<d3_l->max_z;z++)
+ {
+ count=0;
+ for(i=-range;i<=range;i++)
+ {
+ for(j=-range;j<=range;j++)
+ {
+ if(i!=0 && j!=0)
+ {
+ off=((x+d3_l->max_x+i)%d3_l->max_x)+((y+d3_l->max_y+j)%d3_l->max_x)*d3_l->max_x+z*d3_l->max_x*d3_l->max_y;
+ if(*(d3_l->status+off)&AMORPH) count+=((double)*(d3_l->extra+off))/(i*i+j*j);
+ }
+ }
+ }
+ if(count>max) max=count;
+ }
+ }
+ }
+
+ for(x=0;x<d3_l->max_x;x++)
+ {
+ for(y=0;y<d3_l->max_y;y++)
+ {
+ for(z=0;z<d3_l->max_z;z++)
+ {
+ count=0;
+ for(i=-range;i<=range;i++)
+ {
+ for(j=-range;j<=range;j++)
+ {
+ if(i!=0 && j!=0)
+ {
+ off=((x+d3_l->max_x+i)%d3_l->max_x)+((y+d3_l->max_y+j)%d3_l->max_x)*d3_l->max_x+z*d3_l->max_x*d3_l->max_y;
+ if(*(d3_l->status+off)&AMORPH) count+=((double)*(d3_l->extra+off))/(i*i+j*j);
+ }
+ }
+ }
+ *(unsigned char *)(d3_l->v_ptr+x+y*d3_l->max_x+z*d3_l->max_x*d3_l->max_y)=(unsigned char)(count*255/max);
+ }
+ }