return 1;
}
-int 2d_event_init(2d_lattice *2d_l)
+int d2_event_init(d2_lattice *d2_l)
{
- 2d_l->dfb->GetInputDevice(2d_l->dfb,DIDID_KEYBOARD,&(2d_l->keyboard));
- 2d_l->keyboard->CreateEventBuffer(2d_l->keyboard,&(2d_l->k_buffer));
+ d2_l->dfb->GetInputDevice(d2_l->dfb,DIDID_KEYBOARD,&(d2_l->keyboard));
+ d2_l->keyboard->CreateEventBuffer(d2_l->keyboard,&(d2_l->k_buffer));
return 1;
}
int d3_event_init(d3_lattice *d3_l)
{
- d3_l->dfb->GetInputDevice(d3_l->dfb,DIDID_KEYBOARD,&(3d_l->keyboard));
+ d3_l->dfb->GetInputDevice(d3_l->dfb,DIDID_KEYBOARD,&(d3_l->keyboard));
d3_l->keyboard->CreateEventBuffer(d3_l->keyboard,&(d3_l->k_buffer));
return 1;
{
if(ke.key_id==DIKI_LEFT && *x!=0) *x-=1;
if(ke.key_id==DIKI_RIGHT && *x!=d3_l->max_x-1) *x+=1;
- if(ke.key_id==DIET_DOWN && *y!=0) *y-=1;
- if(ke.key_id==DIET_UP && *y!=d3_l->max_y-1) *y+=1;
- if(ke.key_id==DIET_PAGE_DOWN && *z!=0) *z-=1;
- if(ke.key_id==DIET_PAGE_UP && *z!=d3_l->mac_z-1) *z+=1;
- if(ke.key_id==DIKI_Q) *quit=1;
+ if(ke.key_id==DIKI_DOWN && *y!=0) *y-=1;
+ if(ke.key_id==DIKI_UP && *y!=d3_l->max_y-1) *y+=1;
+ if(ke.key_id==DIKI_PAGE_DOWN && *z!=0) *z-=1;
+ if(ke.key_id==DIKI_PAGE_UP && *z!=d3_l->max_z-1) *z+=1;
+ if(ke.key_id==DIKI_Q) *q=1;
if(ke.key_id==DIKI_ESCAPE) *esc=1;
}
return 1;
}
-int process_cell(3d_lattice *3d_l,u32 x,u32 y,u32 z,int r,double a,double b,int *t_c)
+int process_cell(d3_lattice *d3_l,u32 x,u32 y,u32 z,int r,double a,double b,int *t_c)
{
unsigned char *thiz;
int *conc;
int i,j;
double p;
- thiz=3d_l->status+x+y*d3_l->max_x+z*d3_l->max_x*d3_l->max_y;
- conc=3d_l->extra+x+y*d3_l->max_x+z*d3_l->max_x*d3_l->max_y;
+ thiz=d3_l->status+x+y*d3_l->max_x+z*d3_l->max_x*d3_l->max_y;
+ conc=d3_l->extra+x+y*d3_l->max_x+z*d3_l->max_x*d3_l->max_y;
p=b*URAND_MAX;
for(i=-r;i<=r;i++)
{
return 1;
}
-int distrib_c(3d_lattice *3d_l,int t_c,double a,double b)
+int distrib_c(d3_lattice *d3_l,int t_c,double a,double b)
{
int i,j,k,total,area,sum;
int temp,left;
}
}
}
- left=(((i+1)*a+b)*t_c/sum)%area_h[i];
+ left=(int)(((i+1)*a+b)*t_c/sum)%area_h[i];
while(left)
{
x=get_rand(d3_l->max_x);
return 1;
}
-int save_to_file(char *sf,3d_lattice *3d_l)
+int save_to_file(char *sf,d3_lattice *d3_l)
{
int sf_fd,c;
puts("cannot open save file");
return -1;
}
- if(write(sf_fd,3d_l,sizeof(3d_lattice))<sizeof(3d_lattice))
+ if(write(sf_fd,d3_l,sizeof(d3_lattice))<sizeof(d3_lattice))
{
- puts("failed saving 3d lattice struct");
+ puts("failed saving d3 lattice struct");
return -1;
}
c=d3_l->max_x*d3_l->max_y*d3_l->max_z;
- if(write(sf_fd,3d_l->status,c*sizeof(unsigned char)<c*sizeof(unsigned char))
+ if(write(sf_fd,d3_l->status,c*sizeof(unsigned char))<c*sizeof(unsigned char))
{
- puts("failed saving status of 3d lattice sites");
+ puts("failed saving status of d3 lattice sites");
return -1;
}
- if(write(sf_fd,3d_l->extra,c*sizeof(int)<c*sizeof(int))
+ if(write(sf_fd,d3_l->extra,c*sizeof(int))<c*sizeof(int))
{
puts("failed saving sites concentration");
return -1;
return 1;
}
-int load_from_file(char *lf,3d_lattice *3d_l)
+int load_from_file(char *lf,d3_lattice *d3_l)
{
int lf_fd,c;
puts("cannot open load file");
return -1;
}
- if(read(lf_fd,3d_l,sizeof(3d_lattice))<sizeof(3d_lattice))
+ if(read(lf_fd,d3_l,sizeof(d3_lattice))<sizeof(d3_lattice))
{
puts("failed reading d3 lattice struct");
return -1;
puts("cannot allocate concentration buffer");
return -1;
}
- if(read(lf_fd,3d_l->status,c*sizeof(unsigned char))<c*sizeof(unsigned char))
+ if(read(lf_fd,d3_l->status,c*sizeof(unsigned char))<c*sizeof(unsigned char))
{
- puts("failed reading status of 3d lattice sites");
+ puts("failed reading status of d3 lattice sites");
return -1;
}
- if(read(lf_fd,3d_l->extra,c*sizeof(int))<c*sizeof(int))
+ if(read(lf_fd,d3_l->extra,c*sizeof(int))<c*sizeof(int))
{
puts("failed reading sites concentration");
return -1;
char s_file[MAX_CHARS];
char l_file[MAX_CHARS];
char r_file[MAX_CHARS];
- x_txt[MAX_TXT];
- y_txt[MAX_TXT];
- z_txt[MAX_TXT];
- status_txt[MAX_TXT];
- conc_txt[MAX_TXT];
- steps_txt[MAX_TXT];
- cc_txt[MAX_TXT];
- **arg_v;
+ char x_txt[MAX_TXT];
+ char y_txt[MAX_TXT];
+ char z_txt[MAX_TXT];
+ char status_txt[MAX_TXT];
+ char conc_txt[MAX_TXT];
+ char steps_txt[MAX_TXT];
+ char cc_txt[MAX_TXT];
+ char **arg_v;
d3_lattice d3_l;
max_x=X;
strcpy(l_file,"");
strcpy(r_file,"");
- for(i=1,i<argc,i++)
+ for(i=1;i<argc;i++)
{
if(argv[i][0]=='-')
{
{
i=max_x*max_y*max_z;
d3_lattice_init(&argc,argv,&d3_l,max_x,max_y,max_z);
- if((d3_l->status=(unsigned char *)malloc(i*sizeof(unsigned char)))==NULL)
+ if((d3_l.status=(unsigned char *)malloc(i*sizeof(unsigned char)))==NULL)
{
puts("failed allocating status buffer");
return -1;
}
- memset(d3_l->status,0,i*sizeof(unsigned char));
- if((d3_l->extra=(int *)malloc(i*sizeof(int)))==NULL)
+ memset(d3_l.status,0,i*sizeof(unsigned char));
+ if((d3_l.extra=(int *)malloc(i*sizeof(int)))==NULL)
{
puts("failed allocating concentration buffer");
return -1;
}
- memset(d3_l->extra,0,i*sizeof(int));
+ memset(d3_l.extra,0,i*sizeof(int));
} else
{
load_from_file(l_file,&d3_l);
- d3_lattice_init(&argc,argv,&d3_l,d3_l->max_x,d3_l->max_y,d3_l->max_z);
+ d3_lattice_init(&argc,argv,&d3_l,d3_l.max_x,d3_l.max_y,d3_l.max_z);
}
d3_event_init(&d3_l);
{
while((i<steps) && (quit==0) && (escape==0))
{
- x_c=rand_get(d3_l->max_x);
- y_c=rand_get(d3_l->max_y);
- z_c=rand_get_lgp(d3_l->max_z,a_el,b_el);
- distrib_c(&3d_l,cc,a_cd,b_cd);
- process_cell(&3d_l,x_c,y_c,z_c,range,a_ap,b_ap,&cc);
+ x_c=rand_get(d3_l.max_x);
+ y_c=rand_get(d3_l.max_y);
+ z_c=rand_get_lgp(d3_l.max_z,a_el,b_el);
+ distrib_c(&d3_l,cc,a_cd,b_cd);
+ process_cell(&d3_l,x_c,y_c,z_c,range,a_ap,b_ap,&cc);
if(i%refresh==0)
{
sprintf(x_txt,"x: %d",x);
sprintf(y_txt,"y: %d",y);
sprintf(z_txt,"z: %d",z);
- 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');
- sprintf(conc_txt,"conc: %d",*(d3_l->extra+x+y*d3_l->max_x+z*d3_l->max_x*d3_l->max_y));
+ 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');
+ sprintf(conc_txt,"conc: %d",*(d3_l.extra+x+y*d3_l.max_x+z*d3_l.max_x*d3_l.max_y));
sprintf(steps_txt,"step: %d",i);
sprintf(cc_txt,"total c: %d",cc);
arg_v[1]=x_txt;
sprintf(x_txt,"x: %d",x);
sprintf(y_txt,"y: %d",y);
sprintf(z_txt,"z: %d",z);
- 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');
- sprintf(conc_txt,"conc: %d",*(d3_l->extra+x+y*d3_l->max_x+z*d3_l->max_x*d3_l->max_y));
+ 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');
+ sprintf(conc_txt,"conc: %d",*(d3_l.extra+x+y*d3_l.max_x+z*d3_l.max_x*d3_l.max_y));
strcpy(steps_txt,"step: end!");
sprintf(cc_txt,"total c: %d",cc);
arg_v[1]=x_txt;