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 puts("-N <file> \t specify nuclear energy loss profile file");
82 printf("-H <value> \t collisions per ion in simulation window (default %d)\n",CPI);
83 puts("-m <value> \t specify c->a carbon saturation");
88 int process_cell(d3_lattice *d3_l,u32 x,u32 y,u32 z,info *my_info)
96 thiz=d3_l->status+x+y*d3_l->max_x+z*d3_l->max_x*d3_l->max_y;
97 conc=d3_l->extra+x+y*d3_l->max_x+z*d3_l->max_x*d3_l->max_y;
98 p=my_info->b_ap*URAND_MAX;
99 for(i=-(my_info->range);i<=my_info->range;i++)
101 for(j=-(my_info->range);j<=my_info->range;j++)
105 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;
106 if(*(d3_l->status+off)&AMORPH) p+=my_info->a_ap*(*(d3_l->extra+off))*URAND_MAX/(i*i+j*j);
110 p+=*conc*my_info->a_cp*URAND_MAX;
113 if(get_rand(URAND_MAX)<=p) MAKE_AMORPH(thiz);
116 /* assume 1-p probability */
117 if(get_rand(URAND_MAX)>p) MAKE_CRYST(thiz);
123 int distrib_c(d3_lattice *d3_l,info *my_info,int step,double c_ratio,u32 rj_m,u32 *rj_g)
130 /* put one c ion somewhere in the lattice */
131 if(my_info->cc<c_ratio*step)
133 x=get_rand(d3_l->max_x);
134 y=get_rand(d3_l->max_y);
135 // printf("nd: %d %d\n",x,y);
136 // z=get_rand_lgp(d3_l->max_z,my_info->a_cd,my_info->b_cd);
137 z=get_rand_reject(d3_l->max_z,rj_m,rj_g);
139 *(d3_l->extra+x+y*d3_l->max_x+z*d3_l->max_x*d3_l->max_y)+=1;
143 if(step%my_info->diff_rate==0)
146 for(i=0;i<d3_l->max_x;i++)
148 for(j=0;j<d3_l->max_y;j++)
150 for(k=0;k<d3_l->max_z;k++)
152 offset=i+j*d3_l->max_x+k*d3_l->max_x*d3_l->max_y;
153 /* case amorph: amorph <- cryst diffusion */
154 if(*(d3_l->status+offset)&AMORPH && *(d3_l->extra+offset)<my_info->c_sat)
160 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;
162 if(!(*(d3_l->status+off)&AMORPH)) carry=(int)(my_info->dr_ac*(*(d3_l->extra+off)));
165 *(d3_l->extra+offset)+=carry;
166 *(d3_l->extra+off)-=carry;
174 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;
176 if(!(*(d3_l->status+off)&AMORPH)) carry=(int)(my_info->dr_ac*(*(d3_l->extra+off)));
179 *(d3_l->extra+offset)+=carry;
180 *(d3_l->extra+off)-=carry;
188 off=i+j*d3_l->max_x+(k-1)*d3_l->max_x*d3_l->max_y;
190 if(!*(d3_l->status+off)&AMORPH) carry=(int)(my_info->dr_ac*(*(d3_l->extra+off)));
193 *(d3_l->extra+off)-=carry;
194 *(d3_l->extra+offset)+=carry;
199 off=i+j*d3_l->max_x+(k+1)*d3_l->max_x*d3_l->max_y;
201 if(!*(d3_l->status+off)&AMORPH) carry=(int)(my_info->dr_ac*(*(d3_l->extra+off)));
204 *(d3_l->extra+off)-=carry;
205 *(d3_l->extra+offset)+=carry;
210 /* case not amorph: cryst <-> cryst diffusion */
211 if(my_info->c_diff) {
212 /* if there is c diff, no diff in z-direction */
218 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;
220 if(!(*(d3_l->status+off)&AMORPH))
222 carry=(int)(my_info->dr_cc*(*(d3_l->extra+off)-*(d3_l->extra+offset))/2);
225 *(d3_l->extra+offset)+=carry;
226 *(d3_l->extra+off)-=carry;
235 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;
237 if(!(*(d3_l->status+off)&AMORPH))
239 carry=(int)(my_info->dr_cc*(*(d3_l->extra+off)-*(d3_l->extra+offset))/2);
242 *(d3_l->extra+offset)+=carry;
243 *(d3_l->extra+off)-=carry;
256 } /* if step modulo diff_rate == 0 */
261 int calc_pressure(d3_lattice *d3_l,int range)
267 for(x=0;x<d3_l->max_x;x++)
269 for(y=0;y<d3_l->max_y;y++)
271 for(z=0;z<d3_l->max_z;z++)
274 for(i=-range;i<=range;i++)
276 for(j=-range;j<=range;j++)
280 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;
281 if(*(d3_l->status+off)&AMORPH) count+=((double)*(d3_l->extra+off))/(i*i+j*j);
285 if(count>max) max=count;
290 for(x=0;x<d3_l->max_x;x++)
292 for(y=0;y<d3_l->max_y;y++)
294 for(z=0;z<d3_l->max_z;z++)
297 for(i=-range;i<=range;i++)
299 for(j=-range;j<=range;j++)
303 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;
304 if(*(d3_l->status+off)&AMORPH) count+=((double)*(d3_l->extra+off))/(i*i+j*j);
308 *(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);
316 int calc_max_extra(d3_lattice *d3_l)
321 for(x=0;x<d3_l->max_x;x++)
323 for(y=0;y<d3_l->max_y;y++)
325 for(z=0;z<d3_l->max_z;z++)
327 off=x+y*d3_l->max_x+z*d3_l->max_x*d3_l->max_y;
328 if(*(d3_l->extra+off)>max) max=*(d3_l->extra+off);
336 int write_ac_distr(d3_lattice *d3_l,int ac_distr)
342 if(ac_distr==1) strcpy(file,"a.plot");
343 if(ac_distr==2) strcpy(file,"c.plot");
344 if(ac_distr==3) strcpy(file,"b.plot");
346 if((fd=open(file,O_WRONLY|O_CREAT))<0)
348 puts("cannot open plot file");
352 for(z=0;z<d3_l->max_z;z++)
355 for(x=0;x<d3_l->max_x;x++)
357 for(y=0;y<d3_l->max_y;y++)
359 offset=x+y*d3_l->max_x+z*d3_l->max_x*d3_l->max_y;
361 if(*(d3_l->status+offset)&AMORPH) count+=*(d3_l->extra+offset);
363 if(!(*(d3_l->status+offset)&AMORPH)) count+=*(d3_l->extra+offset);
364 if(ac_distr==3) count+=*(d3_l->extra+offset);
367 dprintf(fd,"%d %d\n",z,count);
374 int write_bmp(d3_lattice *d3_l,int window,u32 x,u32 y,u32 z,int max)
376 int fd,i,j,size=0,foo=0,k,sum;
377 int width=0,height=0;
378 char bmpfile[MAX_CHARS];
383 sprintf(bmpfile,"x-z_%d.bmp",y);
385 size=(foo+(4-foo%4))*d3_l->max_z;
391 sprintf(bmpfile,"y-z_%d.bmp",x);
393 size=(foo+(4-foo%4))*d3_l->max_z;
399 sprintf(bmpfile,"x-y_%d.bmp",z);
401 size=(foo+(4-foo%4))*d3_l->max_y;
407 sprintf(bmpfile,"x-z_cdistr_%d.bmp",y);
409 size=(foo+(4-foo%4))*d3_l->max_z;
415 sprintf(bmpfile,"y-z_cdistr_%d.bmp",x);
417 size=(foo+(4-foo%4))*d3_l->max_z;
423 sprintf(bmpfile,"x-y_cdistr_%d.bmp",z);
425 size=(foo+(4-foo%4))*d3_l->max_y;
430 if((fd=open(bmpfile,O_WRONLY|O_CREAT))<0)
432 puts("cannot open bmp file");
437 buf[0]='B'; /* std header start */
439 buf[2]=(size+0x36)&0xff; /* file size */
440 buf[3]=(size+0x36)>>8;
442 buf[10]=0x36; /* offset to data */
444 buf[14]=0x28; /* length of bmp info header */
446 buf[18]=width&0xff; /* width and height */
452 buf[26]=1; /* # planes -> 1 */
454 buf[28]=24; /* bits per pixel -> 2^24 (true color) */
456 memset(buf+30,0,4); /* compression -> none */
457 buf[34]=size&0xff; /* data size */
460 buf[38]=0x12; /* res: pixel/meter */
466 memset(buf+46,0,8); /* no colors, no important colors */
468 if(write(fd,buf,54)<54)
470 puts("failed writing bmp header");
475 for(j=0;j<d3_l->max_z;j++)
477 for(i=0;i<d3_l->max_x;i++)
481 if(*(d3_l->status+i+(((y+k+d3_l->max_y)%d3_l->max_y)*d3_l->max_x)+(d3_l->max_z-j-1)*d3_l->max_x*d3_l->max_y)&RED) sum+=0xff;
483 memset(buf,(unsigned char)sum,3);
484 if(write(fd,buf,3)<3)
486 puts("failed writing rgb values to bmp file");
492 memset(buf,0,4-foo%4);
493 if(write(fd,buf,4-foo%4)<4-foo%4)
495 puts("failed writing 4 byte ending");
503 for(j=0;j<d3_l->max_z;j++)
505 for(i=0;i<d3_l->max_y;i++)
509 if(*(d3_l->status+((x+k+d3_l->max_x)%d3_l->max_x)+i*d3_l->max_x+(d3_l->max_z-j-1)*d3_l->max_x*d3_l->max_y)&RED) sum+=0xff;
511 memset(buf,(unsigned char)sum,3);
512 if(write(fd,buf,3)<3)
514 puts("failed writing rgb values to bmp file");
520 memset(buf,0,4-foo%4);
521 if(write(fd,buf,4-foo%4)<4-foo%4)
523 puts("failed writing 4 byte ending");
531 for(j=0;j<d3_l->max_y;j++)
533 for(i=0;i<d3_l->max_x;i++)
535 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);
536 else memset(buf,0,3);
537 if(write(fd,buf,3)<3)
539 puts("failed writing rgb values to bmp file");
545 memset(buf,0,4-foo%4);
546 if(write(fd,buf,4-foo%4)<4-foo%4)
548 puts("failed writing 4 byte ending");
556 for(j=0;j<d3_l->max_z;j++)
558 for(i=0;i<d3_l->max_x;i++)
560 sum=*(d3_l->extra+i+y*d3_l->max_x+(d3_l->max_z-j-1)*d3_l->max_x*d3_l->max_y);
562 memset(buf,(unsigned char)sum,3);
563 if(write(fd,buf,3)<3)
565 puts("failed writing rgb values to bmp file");
571 memset(buf,0,4-foo%4);
572 if(write(fd,buf,4-foo%4)<4-foo%4)
574 puts("failed writing 4 byte ending");
582 for(j=0;j<d3_l->max_z;j++)
584 for(i=0;i<d3_l->max_x;i++)
586 sum=*(d3_l->extra+x+i*d3_l->max_x+(d3_l->max_z-j-1)*d3_l->max_x*d3_l->max_y);
588 memset(buf,(unsigned char)sum,3);
589 if(write(fd,buf,3)<3)
591 puts("failed writing rgb values to bmp file");
597 memset(buf,0,4-foo%4);
598 if(write(fd,buf,4-foo%4)<4-foo%4)
600 puts("failed writing 4 byte ending");
608 for(j=0;j<d3_l->max_z;j++)
610 for(i=0;i<d3_l->max_x;i++)
612 sum=*(d3_l->extra+i+(d3_l->max_y-j-1)*d3_l->max_x+z*d3_l->max_x*d3_l->max_y);
614 memset(buf,(unsigned char)sum,3);
615 if(write(fd,buf,3)<3)
617 puts("failed writing rgb values to bmp file");
623 memset(buf,0,4-foo%4);
624 if(write(fd,buf,4-foo%4)<4-foo%4)
626 puts("failed writing 4 byte ending");
637 int save_to_file(char *sf,d3_lattice *d3_l,info *my_inf)
641 if((sf_fd=open(sf,O_WRONLY|O_CREAT))<0)
643 puts("cannot open save file");
646 if(write(sf_fd,d3_l,sizeof(d3_lattice))<sizeof(d3_lattice))
648 puts("failed saving d3 lattice struct");
651 if(write(sf_fd,my_inf,sizeof(info))<sizeof(info))
653 puts("failed saving info struct");
656 c=d3_l->max_x*d3_l->max_y*d3_l->max_z;
657 if(write(sf_fd,d3_l->status,c*sizeof(unsigned char))<c*sizeof(unsigned char))
659 puts("failed saving status of d3 lattice sites");
662 if(write(sf_fd,d3_l->extra,c*sizeof(int))<c*sizeof(int))
664 puts("failed saving sites concentration");
672 int load_from_file(char *lf,d3_lattice *d3_l,info *my_inf)
676 if((lf_fd=open(lf,O_RDONLY))<0)
678 puts("cannot open load file");
681 if(read(lf_fd,d3_l,sizeof(d3_lattice))<sizeof(d3_lattice))
683 puts("failed reading d3 lattice struct");
686 if(read(lf_fd,my_inf,sizeof(info))<sizeof(info))
688 puts("failed reading info struct");
691 c=d3_l->max_x*d3_l->max_y*d3_l->max_z;
692 if((d3_l->status=(unsigned char*)malloc(c*sizeof(unsigned char)))==NULL)
694 puts("cannot allocate status buffer");
697 if((d3_l->extra=(int *)malloc(c*sizeof(int)))==NULL)
699 puts("cannot allocate concentration buffer");
702 if(read(lf_fd,d3_l->status,c*sizeof(unsigned char))<c*sizeof(unsigned char))
704 puts("failed reading status of d3 lattice sites");
707 if(read(lf_fd,d3_l->extra,c*sizeof(int))<c*sizeof(int))
709 puts("failed reading sites concentration");
717 int convert_file(char *cf,d3_lattice *d3_l)
722 if((c_fd=open(cf,O_WRONLY|O_CREAT))<0)
724 puts("cannot open convert file");
727 dprintf(c_fd,"# created by nlsop (gnuplot format)\n");
728 for(x=0;x<d3_l->max_x;x++)
730 for(y=0;y<d3_l->max_y;y++)
732 for(z=0;z<d3_l->max_z;z++)
734 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);
743 int get_c_ratio(double *c_ratio,char *pfile,info *my_info,d3_lattice *d3_l)
748 unsigned char buf[32];
752 if((p_fd=open(pfile,O_RDONLY))<0)
754 puts("cannot open profile file");
771 a=atof(p)/10; /* nm */
774 if(a>my_info->b_cd*CELL_LENGTH && a<(my_info->b_cd+d3_l->max_z)*CELL_LENGTH) d+=b;
784 u32 get_reject_graph(info *my_info,d3_lattice *d3_l,char *file,u32 *graph) {
793 if((fd=open(file,O_RDONLY))<0)
795 puts("cannot open file to calculate rejection graph");
798 if((flag=(unsigned char *)malloc(d3_l->max_z))==NULL)
800 puts("cannot malloc flag memory for rejection graph");
803 memset(flag,0,d3_l->max_z);
804 memset(graph,0,d3_l->max_z*sizeof(u32));
811 k=read(fd,&buf[i],1);
812 if((buf[i]=='\n')||(k==0)) break;
817 a=atof(p)/10; /* nm */
820 if(a>d3_l->max_z*CELL_LENGTH) k=0;
823 graph[(int)(a/CELL_LENGTH)]=(int)(URAND_MAX*b);
824 flag[(int)(a/CELL_LENGTH)]=1;
828 /* do (linear) interpolation here! */
836 while(flag[i]==0&&i<d3_l->max_z) i++;
837 for(k=j+1;k<i;k++) graph[k]=(int)((k-j)*((int)graph[i]-(int)graph[j])/(i-j))+graph[j];
838 if(graph[i]>max) max=graph[i];
843 // printf("debug: (interpolated c profile)\n");
844 // for(i=0;i<d3_l->max_z;i++) printf("%d %d\n",i,graph[i]);
849 int main(int argc,char **argv)
851 u32 x,y,z,x_c,y_c,z_c;
852 int i,j,quit,escape,switchmode,nowait,bmp,ac_distr;
855 char s_file[MAX_CHARS];
856 char s_file_tmp[MAX_CHARS];
857 char l_file[MAX_CHARS];
858 char c_file[MAX_CHARS];
859 char p_file[MAX_CHARS];
860 char n_e_file[MAX_CHARS];
862 char r_file[MAX_CHARS];
864 char xyz_txt[MAX_TXT];
865 char status_txt[MAX_TXT];
866 char conc_txt[MAX_TXT];
867 char steps_txt[MAX_TXT];
868 char cc_txt[MAX_TXT];
871 char ap_txt[MAX_TXT];
872 char el_txt[MAX_TXT];
873 char cd_txt[MAX_TXT];
875 char cp_txt[MAX_TXT];
876 char zdiff_txt[MAX_TXT];
877 char diff_txt[MAX_TXT];
878 char dr_ac_txt[MAX_TXT];
879 char dr_cc_txt[MAX_TXT];
880 char dose_txt[MAX_TXT];
881 char mode_txt[MAX_TXT];
882 char *arg_v[MAX_ARGV];
914 my_info.diff_rate=DIFF_RATE;
925 strcpy(p_file,IMP_PROFILE);
926 strcpy(n_e_file,NEL_PROFILE);
946 my_info.a_el=atof(argv[++i]);
949 my_info.b_el=atof(argv[++i]);
952 d3_l.max_x=atoi(argv[++i]);
955 d3_l.max_y=atoi(argv[++i]);
958 d3_l.max_z=atoi(argv[++i]);
968 my_info.steps=atoi(argv[++i]);
971 refresh=atoi(argv[++i]);
974 my_info.range=atoi(argv[++i]);
977 my_info.a_ap=atof(argv[++i]);
980 my_info.b_ap=atof(argv[++i]);
983 my_info.a_cp=atof(argv[++i]);
986 my_info.a_cd=atof(argv[++i]);
989 my_info.b_cd=atof(argv[++i]);
992 resave=atoi(argv[++i]);
995 strcpy(l_file,argv[++i]);
996 if(i<argc-1) if(argv[i+1][0]!='-') strcpy(c_file,argv[++i]);
1000 my_info.dr_ac=atof(argv[++i]);
1003 my_info.dr_cc=atof(argv[++i]);
1006 my_info.diff_rate=atoi(argv[++i]);
1009 strcpy(l_file,argv[++i]);
1012 strcpy(s_file,argv[++i]);
1015 strcpy(r_file,argv[++i]);
1018 strcpy(p_file,argv[++i]);
1021 strcpy(n_e_file,argv[++i]);
1024 strcpy(l_file,argv[++i]);
1025 if(i<argc-1) if(argv[i+1][0]!='-') c_step=atoi(argv[++i]);
1028 my_info.cpi=atoi(argv[++i]);
1031 my_info.c_sat=atoi(argv[++i]);
1045 if(!strcmp(s_file,""))
1047 puts("NODFB defined, run with -S option");
1052 if(!strcmp(r_file,"")) rand_init(NULL);
1053 else rand_init(r_file);
1055 if(!strcmp(l_file,""))
1057 i=d3_l.max_x*d3_l.max_y*d3_l.max_z;
1059 d3_lattice_init(&argc,argv,&d3_l);
1061 if((d3_l.status=(unsigned char *)malloc(i*sizeof(unsigned char)))==NULL)
1063 puts("failed allocating status buffer");
1066 memset(d3_l.status,0,i*sizeof(unsigned char));
1067 if((d3_l.extra=(int *)malloc(i*sizeof(int)))==NULL)
1069 puts("failed allocating concentration buffer");
1072 memset(d3_l.extra,0,i*sizeof(int));
1075 load_from_file(l_file,&d3_l,&my_info);
1078 if(!strcmp(c_file,"")) sprintf(c_file,"%s_gnuplot",l_file);
1079 printf("converting file %s to %s\n",l_file,c_file);
1080 convert_file(c_file,&d3_l);
1085 else d3_lattice_init(&argc,argv,&d3_l);
1090 d3_event_init(&d3_l);
1094 strcpy(a_txt,"args:");
1095 sprintf(s_txt,"steps: %d",my_info.steps);
1096 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));
1097 sprintf(r_txt,"pressure range: %d",my_info.range);
1098 sprintf(ap_txt,"a_ap: %f b_ap: %f",my_info.a_ap,my_info.b_ap);
1099 sprintf(el_txt,"a_el: %f b_el: %f",my_info.a_el,my_info.b_el);
1100 sprintf(cd_txt,"a_cd: %f b_cd: %f",my_info.a_cd,my_info.b_cd);
1101 sprintf(cp_txt,"a_cp: %f",my_info.a_cp);
1102 sprintf(dr_ac_txt,"a/c diffusion rate: %f",my_info.dr_ac);
1103 if(my_info.c_diff!=0) sprintf(dr_cc_txt,"c/c diffusion rate: %f",my_info.dr_cc);
1104 else sprintf(dr_cc_txt,"c/c diffusion rate: none");
1105 sprintf(zdiff_txt,"diffusion in z direction: %c",my_info.z_diff?'y':'n');
1106 sprintf(diff_txt,"diffusion every %d steps",my_info.diff_rate);
1107 strcpy(mode_txt,"view: a/c mode");
1110 arg_v[3]=status_txt;
1119 arg_v[12]=zdiff_txt;
1131 arg_v[24]=dr_ac_txt;
1132 arg_v[25]=dr_cc_txt;
1135 if((!strcmp(l_file,""))||(c_step))
1137 /* calculate ratio of c_simwindow / c_total */
1138 if(get_c_ratio(&c_ratio,p_file,&my_info,&d3_l)!=1)
1140 puts("failed calculating ratio");
1143 /* compute graphs for random number rejection method */
1144 if((c_profile=(u32 *)malloc(d3_l.max_z*sizeof(unsigned int)))==NULL)
1146 puts("failed allocating memory for carbon profile graph");
1149 if((n_e_loss=(u32 *)malloc(d3_l.max_z*sizeof(unsigned int)))==NULL)
1151 puts("failed allocating memory for nuclear energy loss graph");
1154 ip_max=get_reject_graph(&my_info,&d3_l,p_file,c_profile);
1155 ne_max=get_reject_graph(&my_info,&d3_l,n_e_file,n_e_loss);
1161 printf("%d\n",get_rand_reject(d3_l.max_z,ip_max,c_profile));
1164 printf("%d\n",get_rand_reject(d3_l.max_z,ne_max,n_e_loss));
1169 i=(c_step?c_step:0);
1170 while((i<my_info.steps) && (quit==0) && (escape==0))
1172 for(j=0;j<my_info.cpi;j++)
1174 x_c=get_rand(d3_l.max_x);
1175 y_c=get_rand(d3_l.max_y);
1176 // z_c=get_rand_lgp(d3_l.max_z,my_info.a_el,my_info.b_el);
1177 z_c=get_rand_reject(d3_l.max_z,ne_max,n_e_loss);
1178 process_cell(&d3_l,x_c,y_c,z_c,&my_info);
1180 distrib_c(&d3_l,&my_info,i,c_ratio,ip_max,c_profile);
1184 sprintf(xyz_txt,"x: %d y: %d z: %d",x+1,y+1,z+1);
1185 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');
1186 sprintf(conc_txt,"conc: %d",*(d3_l.extra+x+y*d3_l.max_x+z*d3_l.max_x*d3_l.max_y));
1187 sprintf(steps_txt,"step: %d",i);
1188 sprintf(cc_txt,"total c: %d",my_info.cc);
1189 d3_lattice_draw(&d3_l,x,y,z,25,arg_v,mode,0);
1192 if(i%resave==0 && strcmp(s_file,"") && resave!=0 && i!=0)
1194 sprintf(s_file_tmp,"%s_%d_of_%d",s_file,i,my_info.steps);
1195 save_to_file(s_file_tmp,&d3_l,&my_info);
1197 printf("saved %s\n",s_file_tmp);
1204 if(strcmp(s_file,""))
1206 printf("saved %s\n",s_file);
1207 save_to_file(s_file,&d3_l,&my_info);
1211 /* allocating buffer for pressure values */
1212 if((d3_l.v_ptr=malloc(d3_l.max_x*d3_l.max_y*d3_l.max_z*sizeof(unsigned char)))==NULL)
1214 puts("cannot allocate buffer for pressure values");
1218 calc_pressure(&d3_l,my_info.range);
1219 max_extra=calc_max_extra(&d3_l);
1221 while((quit==0) && (escape==0) && (nowait==0))
1224 if(switchmode==0) mode=0;
1225 if(switchmode==1) mode=1;
1226 if(switchmode==2) mode=2;
1228 sprintf(xyz_txt,"x: %d y: %d z: %d",x+1,y+1,z+1);
1229 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');
1230 sprintf(conc_txt,"conc: %d",*(d3_l.extra+x+y*d3_l.max_x+z*d3_l.max_x*d3_l.max_y));
1231 sprintf(steps_txt,"step: end");
1232 sprintf(cc_txt,"total c: %d",my_info.cc);
1233 if(switchmode==0) strcpy(mode_txt,"view: a/c mode");
1234 if(switchmode==1) strcpy(mode_txt,"view: c conc mode");
1235 if(switchmode==2) strcpy(mode_txt,"view: a pressure mode");
1236 d3_lattice_draw(&d3_l,x,y,z,25,arg_v,mode,max_extra);
1239 scan_event(&d3_l,&x,&y,&z,&quit,&escape,&switchmode,&bmp,&ac_distr);
1240 if(bmp) write_bmp(&d3_l,bmp,x,y,z,max_extra);
1241 if(ac_distr) write_ac_distr(&d3_l,ac_distr);
1244 d3_lattice_release(&d3_l);