+ int x,y,z;
+ int off,max=0;
+
+ 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++)
+ {
+ off=x+y*d3_l->max_x+z*d3_l->max_x*d3_l->max_y;
+ if(*(d3_l->extra+off)>max) max=*(d3_l->extra+off);
+ }
+ }
+ }
+
+ return max;
+}
+
+int write_ac_distr(d3_lattice *d3_l,int ac_distr)
+{
+ int fd,x,y,z;
+ int count,offset;
+ char file[32];
+ int si_count;
+
+ si_count=d3_l->max_x*d3_l->max_y*SI_PER_VOLUME;
+ if(ac_distr==1) strcpy(file,"carbon_in_av.plot");
+ if(ac_distr==2) strcpy(file,"carbon_in_cv.plot");
+ if(ac_distr==3) strcpy(file,"carbon.plot");
+ if(ac_distr==4) strcpy(file,"amorphous_volumes.plot");
+
+ if((fd=open(file,O_WRONLY|O_CREAT))<0)
+ {
+ puts("cannot open plot file");
+ return -1;
+ }
+
+ for(z=0;z<d3_l->max_z;z++)
+ {
+ count=0;
+ for(x=0;x<d3_l->max_x;x++)
+ {
+ for(y=0;y<d3_l->max_y;y++)
+ {
+ offset=x+y*d3_l->max_x+z*d3_l->max_x*d3_l->max_y;
+ if(ac_distr==1)
+ if(*(d3_l->status+offset)&AMORPH) count+=*(d3_l->extra+offset);
+ if(ac_distr==2)
+ if(!(*(d3_l->status+offset)&AMORPH)) count+=*(d3_l->extra+offset);
+ if(ac_distr==3) count+=*(d3_l->extra+offset);
+ if(ac_distr==4)
+ if(*(d3_l->status+offset)&AMORPH) count+=1;
+ }
+ }
+ if(ac_distr==4) dprintf(fd,"%d %d\n",z*CELL_LENGTH,count);
+ else dprintf(fd,"%d %f\n",z*CELL_LENGTH,100.0*count/si_count);
+ }
+ close(fd);
+
+ return 1;
+}
+
+int write_bmp(d3_lattice *d3_l,int window,u32 x,u32 y,u32 z,int max)
+{
+ int fd,i,j,size=0,foo=0,k,sum;
+ int width=0,height=0;
+ char bmpfile[MAX_CHARS];
+ char buf[128];
+
+ if(window==1)
+ {
+ sprintf(bmpfile,"x-z_%d.bmp",y);
+ foo=3*d3_l->max_x;
+ size=(foo+(4-foo%4))*d3_l->max_z;
+ height=d3_l->max_z;
+ width=d3_l->max_x;
+ }
+ if(window==2)
+ {
+ sprintf(bmpfile,"y-z_%d.bmp",x);
+ foo=3*d3_l->max_y;
+ size=(foo+(4-foo%4))*d3_l->max_z;
+ height=d3_l->max_z;
+ width=d3_l->max_y;
+ }
+ if(window==3)
+ {
+ sprintf(bmpfile,"x-y_%d.bmp",z);
+ foo=3*d3_l->max_x;
+ size=(foo+(4-foo%4))*d3_l->max_y;
+ width=d3_l->max_x;
+ height=d3_l->max_y;
+ }
+ if(window==4)
+ {
+ sprintf(bmpfile,"x-z_cdistr_%d.bmp",y);
+ foo=3*d3_l->max_x;
+ size=(foo+(4-foo%4))*d3_l->max_z;
+ height=d3_l->max_z;
+ width=d3_l->max_x;
+ }
+ if(window==5)
+ {
+ sprintf(bmpfile,"y-z_cdistr_%d.bmp",x);
+ foo=3*d3_l->max_y;
+ size=(foo+(4-foo%4))*d3_l->max_z;
+ height=d3_l->max_z;
+ width=d3_l->max_y;
+ }
+ if(window==6)
+ {
+ sprintf(bmpfile,"x-y_cdistr_%d.bmp",z);
+ foo=3*d3_l->max_x;
+ size=(foo+(4-foo%4))*d3_l->max_y;
+ width=d3_l->max_x;
+ height=d3_l->max_y;
+ }
+ if(window==7)
+ {
+ sprintf(bmpfile,"x-z_a_cdistr_%d.bmp",y);
+ foo=3*d3_l->max_x;
+ size=(foo+(4-foo%4))*d3_l->max_z;
+ height=d3_l->max_z;
+ width=d3_l->max_x;
+ }
+ if(window==8)
+ {
+ sprintf(bmpfile,"y-z_a_cdistr_%d.bmp",x);
+ foo=3*d3_l->max_y;
+ size=(foo+(4-foo%4))*d3_l->max_z;
+ height=d3_l->max_z;
+ width=d3_l->max_y;
+ }
+ if(window==9)
+ {
+ sprintf(bmpfile,"x-y_a_cdistr_%d.bmp",z);
+ foo=3*d3_l->max_x;
+ size=(foo+(4-foo%4))*d3_l->max_y;
+ height=d3_l->max_y;
+ width=d3_l->max_x;
+ }
+ if(window==10)
+ {
+ sprintf(bmpfile,"x-z_c_cdistr_%d.bmp",y);
+ foo=3*d3_l->max_x;
+ size=(foo+(4-foo%4))*d3_l->max_z;
+ height=d3_l->max_z;
+ width=d3_l->max_x;
+ }
+ if(window==11)
+ {
+ sprintf(bmpfile,"y-z_c_cdistr_%d.bmp",x);
+ foo=3*d3_l->max_y;
+ size=(foo+(4-foo%4))*d3_l->max_z;
+ height=d3_l->max_z;
+ width=d3_l->max_y;
+ }
+ if(window==12)
+ {
+ sprintf(bmpfile,"x-y_c_cdistr_%d.bmp",z);
+ foo=3*d3_l->max_x;
+ size=(foo+(4-foo%4))*d3_l->max_y;
+ height=d3_l->max_y;
+ width=d3_l->max_x;
+ }
+ if((fd=open(bmpfile,O_WRONLY|O_CREAT))<0)
+ {
+ puts("cannot open bmp file");
+ return -1;
+ }