4 * author: frank zirkelbach (frank.zirkelbach@physik.uni-augsburg.de)
6 * this program tries helping to understand the amorphous depuration
7 * and recrystallization of SiCx while ion implantation at temperatures
8 * below 400 degree celsius.
9 * hopefully the program will simulate the stabilization of the
10 * selforganizing lamella structure in the observed behaviour.
13 * - J. K. N. Lindner. Habilationsschrift, Universitaet Augsburg.
14 * - Maik Haeberlen. Diplomarbeit, Universitaet Augsburg.
16 * Copyright (C) 2004 Frank Zirkelbach
18 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation; either version 2 of the License, or
21 * (at your option) any later version.
23 * This program is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
28 * You should have received a copy of the GNU General Public License
29 * along with this program; if not, write to the Free Software
30 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
38 #include <sys/types.h>
48 #define MAKE_AMORPH(N) *(N)|=AMORPH
49 #define MAKE_CRYST(N) *(N)&=~AMORPH
55 puts("-n \t\t no user interaction");
56 puts("-Z \t\t cryst -> amorph c diffusion in z direction");
57 puts("-i \t\t no cryst to cryst diffusion");
58 printf("-a <value> \t slope of nuclear energy loss (default %f)\n",A_EL);
59 printf("-b <value> \t nuclear energy loss offset (default %f)\n",B_EL);
60 printf("-x <value> \t # x cells (default %d)\n",X);
61 printf("-y <value> \t # y cells (default %d)\n",Y);
62 printf("-z <value> \t # z cells (default %d)\n",Z);
63 printf("-s <value> \t steps (default %d)\n",STEPS);
64 printf("-d <value> \t refresh display (default %d)\n",REFRESH);
65 printf("-r <value> \t amorphous influence range (default %d)\n",RANGE);
66 printf("-f <value> \t pressure = <value> * 1/distance^2 (default %f)\n",A_AP);
67 printf("-p <value> \t pressure offset (default %f)\n",B_AP);
68 printf("-F <value> \t proportionality constant between c conc and ability to get amorphous (default %f)\n",A_CP);
69 printf("-A <value> \t slope of linear c distribution (default %f)\n",A_CD);
70 printf("-B <value> \t linear c distribution offset (default %f)\n",B_CD);
71 printf("-D <value> \t diffusion rate from cryst to amorph cells (default %f)\n",DR_AC);
72 printf("-c <value> \t diffusion rate in cryst cells (default %f)\n",DR_CC);
73 printf("-e <value> \t do diffusion every <value> steps (default %d)\n",DIFF_RATE);
74 puts("-g <file> <step> continue simulation from file and step (step > 0)!");
75 printf("-W <value> \t write every <value> steps to save file (default %d)\n",RESAVE);
76 puts("-C <file> \t convert file to gnuplot format");
77 puts("-L <file> \t load from file");
78 puts("-S <file> \t save to file");
79 puts("-R <file> \t read from random file");
80 puts("-P <file> \t specify implantation profile file");
81 printf("-H <value> \t collisions per ion in simulation window (default %d)\n",CPI);
86 int process_cell(d3_lattice *d3_l,u32 x,u32 y,u32 z,info *my_info)
94 thiz=d3_l->status+x+y*d3_l->max_x+z*d3_l->max_x*d3_l->max_y;
95 conc=d3_l->extra+x+y*d3_l->max_x+z*d3_l->max_x*d3_l->max_y;
96 p=my_info->b_ap*URAND_MAX;
97 for(i=-(my_info->range);i<=my_info->range;i++)
99 for(j=-(my_info->range);j<=my_info->range;j++)
103 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;
104 if(*(d3_l->status+off)&AMORPH) p+=my_info->a_ap*(*(d3_l->extra+off))*URAND_MAX/(i*i+j*j);
108 p+=*conc*my_info->a_cp*URAND_MAX;
111 if(get_rand(URAND_MAX)<=p) MAKE_AMORPH(thiz);
114 /* assume 1-p probability */
115 if(get_rand(URAND_MAX)>p) MAKE_CRYST(thiz);
121 int distrib_c(d3_lattice *d3_l,info *my_info,int step,double c_ratio)
128 /* put one c ion somewhere in the lattice */
129 if(my_info->cc<c_ratio*step)
131 x=get_rand(d3_l->max_x);
132 y=get_rand(d3_l->max_y);
133 // printf("nd: %d %d\n",x,y);
134 z=get_rand_lgp(d3_l->max_z,my_info->a_cd,my_info->b_cd);
135 // printf("ld: %d\n",z);
136 *(d3_l->extra+x+y*d3_l->max_x+z*d3_l->max_x*d3_l->max_y)+=1;
140 if(step%my_info->diff_rate==0)
143 for(i=0;i<d3_l->max_x;i++)
145 for(j=0;j<d3_l->max_y;j++)
147 for(k=0;k<d3_l->max_z;k++)
149 offset=i+j*d3_l->max_x+k*d3_l->max_x*d3_l->max_y;
150 /* case amorph: amorph <- cryst diffusion */
151 if(*(d3_l->status+offset)&AMORPH)
157 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;
159 if(!(*(d3_l->status+off)&AMORPH)) carry=(int)(my_info->dr_ac*(*(d3_l->extra+off)));
162 *(d3_l->extra+offset)+=carry;
163 *(d3_l->extra+off)-=carry;
171 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;
173 if(!(*(d3_l->status+off)&AMORPH)) carry=(int)(my_info->dr_ac*(*(d3_l->extra+off)));
176 *(d3_l->extra+offset)+=carry;
177 *(d3_l->extra+off)-=carry;
185 off=i+j*d3_l->max_x+(k-1)*d3_l->max_x*d3_l->max_y;
187 if(!*(d3_l->status+off)&AMORPH) carry=(int)(my_info->dr_ac*(*(d3_l->extra+off)));
190 *(d3_l->extra+off)-=carry;
191 *(d3_l->extra+offset)+=carry;
196 off=i+j*d3_l->max_x+(k+1)*d3_l->max_x*d3_l->max_y;
198 if(!*(d3_l->status+off)&AMORPH) carry=(int)(my_info->dr_ac*(*(d3_l->extra+off)));
201 *(d3_l->extra+off)-=carry;
202 *(d3_l->extra+offset)+=carry;
207 /* case not amorph: cryst <-> cryst diffusion */
208 if(my_info->c_diff) {
209 /* if there is c diff, no diff in z-direction */
215 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;
217 if(!(*(d3_l->status+off)&AMORPH))
219 carry=(int)(my_info->dr_cc*(*(d3_l->extra+off)-*(d3_l->extra+offset))/2);
222 *(d3_l->extra+offset)+=carry;
223 *(d3_l->extra+off)-=carry;
232 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;
234 if(!(*(d3_l->status+off)&AMORPH))
236 carry=(int)(my_info->dr_cc*(*(d3_l->extra+off)-*(d3_l->extra+offset))/2);
239 *(d3_l->extra+offset)+=carry;
240 *(d3_l->extra+off)-=carry;
253 } /* if step modulo diff_rate == 0 */
258 int calc_pressure(d3_lattice *d3_l,int range)
264 for(x=0;x<d3_l->max_x;x++)
266 for(y=0;y<d3_l->max_y;y++)
268 for(z=0;z<d3_l->max_z;z++)
271 for(i=-range;i<=range;i++)
273 for(j=-range;j<=range;j++)
277 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;
278 if(*(d3_l->status+off)&AMORPH) count+=((double)*(d3_l->extra+off))/(i*i+j*j);
282 if(count>max) max=count;
287 for(x=0;x<d3_l->max_x;x++)
289 for(y=0;y<d3_l->max_y;y++)
291 for(z=0;z<d3_l->max_z;z++)
294 for(i=-range;i<=range;i++)
296 for(j=-range;j<=range;j++)
300 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;
301 if(*(d3_l->status+off)&AMORPH) count+=((double)*(d3_l->extra+off))/(i*i+j*j);
305 *(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);
313 int calc_max_extra(d3_lattice *d3_l)
318 for(x=0;x<d3_l->max_x;x++)
320 for(y=0;y<d3_l->max_y;y++)
322 for(z=0;z<d3_l->max_z;z++)
324 off=x+y*d3_l->max_x+z*d3_l->max_x*d3_l->max_y;
325 if(*(d3_l->extra+off)>max) max=*(d3_l->extra+off);
333 int write_ac_distr(d3_lattice *d3_l,int ac_distr)
339 if(ac_distr==1) strcpy(file,"a.plot");
340 if(ac_distr==2) strcpy(file,"c.plot");
341 if(ac_distr==3) strcpy(file,"b.plot");
343 if((fd=open(file,O_WRONLY|O_CREAT))<0)
345 puts("cannot open plot file");
349 for(z=0;z<d3_l->max_z;z++)
351 for(x=0;x<d3_l->max_x;x++)
353 for(y=0;y<d3_l->max_y;y++)
355 offset=x+y*d3_l->max_x+z*d3_l->max_x*d3_l->max_y;
357 if(*(d3_l->status+offset)&AMORPH) count+=*(d3_l->extra+offset);
359 if(!(*(d3_l->status+offset)&AMORPH)) count+=*(d3_l->extra+offset);
360 if(ac_distr==3) count+=*(d3_l->extra+offset);
363 dprintf(fd,"%d %d\n",z,count);
370 int write_bmp(d3_lattice *d3_l,int window,u32 x,u32 y,u32 z)
372 int fd,i,j,size=0,foo=0,end=0;
373 int width=0,height=0;
374 char bmpfile[MAX_CHARS];
377 if(((window==4)||(window==5))&&(d3_l->max_z<FFT_HEIGHT) )
379 puts("error: z < FFT_HEIGHT!");
380 puts("not writing bmp file ...");
386 sprintf(bmpfile,"x-z_%d.bmp",y);
390 size=(foo+(4-foo%4))*d3_l->max_z;
395 size=(foo+(4-foo%4))*FFT_HEIGHT;
396 end=d3_l->max_z-FFT_HEIGHT;
403 sprintf(bmpfile,"y-z_%d.bmp",x);
407 size=(foo+(4-foo%4))*d3_l->max_z;
412 size=(foo+(4-foo%4))*FFT_HEIGHT;
413 end=d3_l->max_z-FFT_HEIGHT;
420 sprintf(bmpfile,"x-y_%d.bmp",z);
422 size=(foo+(4-foo%4))*d3_l->max_y;
427 if((fd=open(bmpfile,O_WRONLY|O_CREAT))<0)
429 puts("cannot open bmp file");
434 buf[0]='B'; /* std header start */
436 buf[2]=(size+0x36)&0xff; /* file size */
437 buf[3]=(size+0x36)>>8;
439 buf[10]=0x36; /* offset to data */
441 buf[14]=0x28; /* length of bmp info header */
443 buf[18]=width&0xff; /* width and height */
449 buf[26]=1; /* # planes -> 1 */
451 buf[28]=24; /* bits per pixel -> 2^24 (true color) */
453 memset(buf+30,0,4); /* compression -> none */
454 buf[34]=size&0xff; /* data size */
457 buf[38]=0x12; /* res: pixel/meter */
463 memset(buf+46,0,8); /* no colors, no important colors */
465 if(write(fd,buf,54)<54)
467 puts("failed writing bmp header");
472 for(j=0;j<d3_l->max_z-end;j++)
474 for(i=0;i<d3_l->max_x;i++)
476 if(*(d3_l->status+i+y*d3_l->max_x+(d3_l->max_z-j-1)*d3_l->max_x*d3_l->max_y)&RED) memset(buf,0xff,3);
477 else memset(buf,0,3);
478 if(write(fd,buf,3)<3)
480 puts("failed writing rgb values to bmp file");
486 memset(buf,0,4-foo%4);
487 if(write(fd,buf,4-foo%4)<4-foo%4)
489 puts("failed writing 4 byte ending");
497 for(j=0;j<d3_l->max_z-end;j++)
499 for(i=0;i<d3_l->max_y;i++)
501 if(*(d3_l->status+x+i*d3_l->max_x+(d3_l->max_z-j-1)*d3_l->max_x*d3_l->max_y)&RED) memset(buf,0xff,3);
502 else memset(buf,0,3);
503 if(write(fd,buf,3)<3)
505 puts("failed writing rgb values to bmp file");
511 memset(buf,0,4-foo%4);
512 if(write(fd,buf,4-foo%4)<4-foo%4)
514 puts("failed writing 4 byte ending");
522 for(j=0;j<d3_l->max_y;j++)
524 for(i=0;i<d3_l->max_x;i++)
526 if(*(d3_l->status+i+(d3_l->max_y-j-1)*d3_l->max_x+z*d3_l->max_x*d3_l->max_y)&RED) memset(buf,0xff,3);
527 else memset(buf,0,3);
528 if(write(fd,buf,3)<3)
530 puts("failed writing rgb values to bmp file");
536 memset(buf,0,4-foo%4);
537 if(write(fd,buf,4-foo%4)<4-foo%4)
539 puts("failed writing 4 byte ending");
550 int save_to_file(char *sf,d3_lattice *d3_l,info *my_inf)
554 if((sf_fd=open(sf,O_WRONLY|O_CREAT))<0)
556 puts("cannot open save file");
559 if(write(sf_fd,d3_l,sizeof(d3_lattice))<sizeof(d3_lattice))
561 puts("failed saving d3 lattice struct");
564 if(write(sf_fd,my_inf,sizeof(info))<sizeof(info))
566 puts("failed saving info struct");
569 c=d3_l->max_x*d3_l->max_y*d3_l->max_z;
570 if(write(sf_fd,d3_l->status,c*sizeof(unsigned char))<c*sizeof(unsigned char))
572 puts("failed saving status of d3 lattice sites");
575 if(write(sf_fd,d3_l->extra,c*sizeof(int))<c*sizeof(int))
577 puts("failed saving sites concentration");
585 int load_from_file(char *lf,d3_lattice *d3_l,info *my_inf)
589 if((lf_fd=open(lf,O_RDONLY))<0)
591 puts("cannot open load file");
594 if(read(lf_fd,d3_l,sizeof(d3_lattice))<sizeof(d3_lattice))
596 puts("failed reading d3 lattice struct");
599 if(read(lf_fd,my_inf,sizeof(info))<sizeof(info))
601 puts("failed reading info struct");
604 c=d3_l->max_x*d3_l->max_y*d3_l->max_z;
605 if((d3_l->status=(unsigned char*)malloc(c*sizeof(unsigned char)))==NULL)
607 puts("cannot allocate status buffer");
610 if((d3_l->extra=(int *)malloc(c*sizeof(int)))==NULL)
612 puts("cannot allocate concentration buffer");
615 if(read(lf_fd,d3_l->status,c*sizeof(unsigned char))<c*sizeof(unsigned char))
617 puts("failed reading status of d3 lattice sites");
620 if(read(lf_fd,d3_l->extra,c*sizeof(int))<c*sizeof(int))
622 puts("failed reading sites concentration");
630 int convert_file(char *cf,d3_lattice *d3_l)
635 if((c_fd=open(cf,O_WRONLY|O_CREAT))<0)
637 puts("cannot open convert file");
640 dprintf(c_fd,"# created by nlsop (gnuplot format)\n");
641 for(x=0;x<d3_l->max_x;x++)
643 for(y=0;y<d3_l->max_y;y++)
645 for(z=0;z<d3_l->max_z;z++)
647 if(*(d3_l->status+x+y*d3_l->max_x+z*d3_l->max_x*d3_l->max_y)&AMORPH) dprintf(c_fd,"%d %d %d\n",x,y,z);
656 int get_c_ratio(double *c_ratio,char *pfile,info *my_info,d3_lattice *d3_l)
661 unsigned char buf[32];
665 if((p_fd=open(pfile,O_RDONLY))<0)
667 puts("cannot open profile file");
684 a=atof(p)/10; /* nm */
687 if(a>my_info->b_cd*CELL_LENGTH && a<(my_info->b_cd+d3_l->max_z)*CELL_LENGTH) d+=b;
697 int get_reject_graph(info *my_info,d3_lattice *d3_l,char *file,u32 *graph) {
704 if((fd=open(file,O_RDONLY))<0)
706 puts("cannot open file to calculate rejection graph");
709 if((flag=(unsigned char *)malloc(d3_l->max_z))==NULL)
711 puts("cannot malloc flag memory for rejection graph");
714 memset(flag,0,d3_l->max_z);
715 memset(graph,0,d3_l->max_z*sizeof(u32));
722 k=read(fd,&buf[i],1);
723 if((buf[i]=='\n')||(k==0)) break;
728 a=atof(p)/10; /* nm */
731 if(a>d3_l->max_z*CELL_LENGTH) k=0;
734 graph[(int)(a/CELL_LENGTH)]=(int)(URAND_MAX*b);
735 flag[(int)(a/CELL_LENGTH)]=1;
739 /* do (linear) interpolation here! */
749 printf("%s graph:\n",file);
750 for(i=0;i<d3_l->max_z;i++) printf("%02d | %d\n",i,graph[i]);
755 int main(int argc,char **argv)
757 u32 x,y,z,x_c,y_c,z_c;
758 int i,j,quit,escape,switchmode,nowait,bmp,ac_distr;
761 char s_file[MAX_CHARS];
762 char s_file_tmp[MAX_CHARS];
763 char l_file[MAX_CHARS];
764 char c_file[MAX_CHARS];
765 char p_file[MAX_CHARS];
767 char r_file[MAX_CHARS];
769 char xyz_txt[MAX_TXT];
770 char status_txt[MAX_TXT];
771 char conc_txt[MAX_TXT];
772 char steps_txt[MAX_TXT];
773 char cc_txt[MAX_TXT];
776 char ap_txt[MAX_TXT];
777 char el_txt[MAX_TXT];
778 char cd_txt[MAX_TXT];
780 char cp_txt[MAX_TXT];
781 char zdiff_txt[MAX_TXT];
782 char diff_txt[MAX_TXT];
783 char dr_ac_txt[MAX_TXT];
784 char dr_cc_txt[MAX_TXT];
785 char dose_txt[MAX_TXT];
786 char mode_txt[MAX_TXT];
787 char *arg_v[MAX_ARGV];
818 my_info.diff_rate=DIFF_RATE;
828 strcpy(p_file,IMP_PROFILE);
846 my_info.a_el=atof(argv[++i]);
849 my_info.b_el=atof(argv[++i]);
852 d3_l.max_x=atoi(argv[++i]);
855 d3_l.max_y=atoi(argv[++i]);
858 d3_l.max_z=atoi(argv[++i]);
868 my_info.steps=atoi(argv[++i]);
871 refresh=atoi(argv[++i]);
874 my_info.range=atoi(argv[++i]);
877 my_info.a_ap=atof(argv[++i]);
880 my_info.b_ap=atof(argv[++i]);
883 my_info.a_cp=atof(argv[++i]);
886 my_info.a_cd=atof(argv[++i]);
889 my_info.b_cd=atof(argv[++i]);
892 resave=atoi(argv[++i]);
895 strcpy(l_file,argv[++i]);
896 if(i<argc-1) if(argv[i+1][0]!='-') strcpy(c_file,argv[++i]);
900 my_info.dr_ac=atof(argv[++i]);
903 my_info.dr_cc=atof(argv[++i]);
906 my_info.diff_rate=atoi(argv[++i]);
909 strcpy(l_file,argv[++i]);
912 strcpy(s_file,argv[++i]);
915 strcpy(r_file,argv[++i]);
918 strcpy(p_file,argv[++i]);
921 strcpy(l_file,argv[++i]);
922 if(i<argc-1) if(argv[i+1][0]!='-') c_step=atoi(argv[++i]);
925 my_info.cpi=atoi(argv[++i]);
939 if(!strcmp(s_file,""))
941 puts("NODFB defined, run with -S option");
946 if(!strcmp(r_file,"")) rand_init(NULL);
947 else rand_init(r_file);
949 if(!strcmp(l_file,""))
951 i=d3_l.max_x*d3_l.max_y*d3_l.max_z;
953 d3_lattice_init(&argc,argv,&d3_l);
955 if((d3_l.status=(unsigned char *)malloc(i*sizeof(unsigned char)))==NULL)
957 puts("failed allocating status buffer");
960 memset(d3_l.status,0,i*sizeof(unsigned char));
961 if((d3_l.extra=(int *)malloc(i*sizeof(int)))==NULL)
963 puts("failed allocating concentration buffer");
966 memset(d3_l.extra,0,i*sizeof(int));
969 load_from_file(l_file,&d3_l,&my_info);
972 if(!strcmp(c_file,"")) sprintf(c_file,"%s_gnuplot",l_file);
973 printf("converting file %s to %s\n",l_file,c_file);
974 convert_file(c_file,&d3_l);
979 else d3_lattice_init(&argc,argv,&d3_l);
984 d3_event_init(&d3_l);
988 strcpy(a_txt,"args:");
989 sprintf(s_txt,"steps: %d",my_info.steps);
990 sprintf(dose_txt,"dose: %.2fe+17 C/cm²",my_info.steps*1.0/(d3_l.max_x*d3_l.max_y*CELL_LENGTH*CELL_LENGTH*1000));
991 sprintf(r_txt,"pressure range: %d",my_info.range);
992 sprintf(ap_txt,"a_ap: %.4f b_ap: %.3f",my_info.a_ap,my_info.b_ap);
993 sprintf(el_txt,"a_el: %.3f b_el: %.3f",my_info.a_el,my_info.b_el);
994 sprintf(cd_txt,"a_cd: %.3f b_cd: %.3f",my_info.a_cd,my_info.b_cd);
995 sprintf(cp_txt,"a_cp: %.5f",my_info.a_cp);
996 sprintf(dr_ac_txt,"a/c diffusion rate: %.4f",my_info.dr_ac);
997 if(my_info.c_diff!=0) sprintf(dr_cc_txt,"c/c diffusion rate: %.4f",my_info.dr_cc);
998 else sprintf(dr_cc_txt,"c/c diffusion rate: none");
999 sprintf(zdiff_txt,"diffusion in z direction: %c",my_info.z_diff?'y':'n');
1000 sprintf(diff_txt,"diffusion every %d steps",my_info.diff_rate);
1001 strcpy(mode_txt,"view: a/c mode");
1004 arg_v[3]=status_txt;
1013 arg_v[12]=zdiff_txt;
1025 arg_v[24]=dr_ac_txt;
1026 arg_v[25]=dr_cc_txt;
1029 if((!strcmp(l_file,""))||(c_step))
1031 /* calculate ratio of c_simwindow / c_total */
1032 if(get_c_ratio(&c_ratio,p_file,&my_info,&d3_l)!=1)
1034 puts("failed calculating ratio");
1037 /* compute graphs for random number rejection method */
1038 if((c_profile=(u32 *)malloc(d3_l.max_z*sizeof(unsigned int)))==NULL)
1040 puts("failed allocating memory for carbon profile graph");
1043 if((n_e_loss=(u32 *)malloc(d3_l.max_z*sizeof(unsigned int)))==NULL)
1045 puts("failed allocating memory for nuclear energy loss graph");
1048 if(get_reject_graph(&my_info,&d3_l,p_file,c_profile)!=1)
1050 puts("failed to get reject graph");
1054 /* break here for testing ... */
1057 i=(c_step?c_step:0);
1058 while((i<my_info.steps) && (quit==0) && (escape==0))
1060 for(j=0;j<my_info.cpi;j++)
1062 x_c=get_rand(d3_l.max_x);
1063 y_c=get_rand(d3_l.max_y);
1064 z_c=get_rand_lgp(d3_l.max_z,my_info.a_el,my_info.b_el);
1065 process_cell(&d3_l,x_c,y_c,z_c,&my_info);
1067 distrib_c(&d3_l,&my_info,i,c_ratio);
1071 sprintf(xyz_txt,"x: %d y: %d z: %d",x+1,y+1,z+1);
1072 sprintf(status_txt,"status: %c",(*(d3_l.status+x+y*d3_l.max_x+z*d3_l.max_x*d3_l.max_y)&AMORPH)?'a':'c');
1073 sprintf(conc_txt,"conc: %d",*(d3_l.extra+x+y*d3_l.max_x+z*d3_l.max_x*d3_l.max_y));
1074 sprintf(steps_txt,"step: %d",i);
1075 sprintf(cc_txt,"total c: %d",my_info.cc);
1076 d3_lattice_draw(&d3_l,x,y,z,25,arg_v,mode,0);
1079 if(i%resave==0 && strcmp(s_file,"") && resave!=0 && i!=0)
1081 sprintf(s_file_tmp,"%s_%d_of_%d",s_file,i,my_info.steps);
1082 save_to_file(s_file_tmp,&d3_l,&my_info);
1084 printf("saved %s\n",s_file_tmp);
1091 if(strcmp(s_file,""))
1093 printf("saved %s\n",s_file);
1094 save_to_file(s_file,&d3_l,&my_info);
1098 /* allocating buffer for pressure values */
1099 if((d3_l.v_ptr=malloc(d3_l.max_x*d3_l.max_y*d3_l.max_z*sizeof(unsigned char)))==NULL)
1101 puts("cannot allocate buffer for pressure values");
1105 calc_pressure(&d3_l,my_info.range);
1106 max_extra=calc_max_extra(&d3_l);
1108 while((quit==0) && (escape==0) && (nowait==0))
1111 if(switchmode==0) mode=0;
1112 if(switchmode==1) mode=1;
1113 if(switchmode==2) mode=2;
1115 sprintf(xyz_txt,"x: %d y: %d z: %d",x+1,y+1,z+1);
1116 sprintf(status_txt,"status: %c",(*(d3_l.status+x+y*d3_l.max_x+z*d3_l.max_x*d3_l.max_y)&AMORPH)?'a':'c');
1117 sprintf(conc_txt,"conc: %d",*(d3_l.extra+x+y*d3_l.max_x+z*d3_l.max_x*d3_l.max_y));
1118 sprintf(steps_txt,"step: end");
1119 sprintf(cc_txt,"total c: %d",my_info.cc);
1120 if(switchmode==0) strcpy(mode_txt,"view: a/c mode");
1121 if(switchmode==1) strcpy(mode_txt,"view: c conc mode");
1122 if(switchmode==2) strcpy(mode_txt,"view: a pressure mode");
1123 d3_lattice_draw(&d3_l,x,y,z,25,arg_v,mode,max_extra);
1126 scan_event(&d3_l,&x,&y,&z,&quit,&escape,&switchmode,&bmp,&ac_distr);
1127 if(bmp) write_bmp(&d3_l,bmp,x,y,z);
1128 if(ac_distr) write_ac_distr(&d3_l,ac_distr);
1131 d3_lattice_release(&d3_l);