#include "display.h"
/* global variables */
+u32 *rand_buf,*rand_current;
u32 gr;
int random_fd; /* /dev/urandom file descriptor */
int distrib_c_conc(cell *cell_p,int c_c0,int c_slope,u32 c_conc,u32 x_max,u32 y_max,u32 z_max)
{
- /* cryst. c to distribute */
-
int i,j;
- u32 area,c_area,total;
+ u32 area,c_area,total,count;
u32 x,y,z,sum_c_z;
total=0;
for(i=0;i<z_max;i++)
{
+ count=0;
c_area=(c_conc*(c_c0+(i+1)*c_slope))/sum_c_z;
for(j=0;j<area;j++)
- {
+ {
+ if(!(cell_p+j+i*area)->status&AMORPH) count++;
+ }
+ for(j=0;j<area;j++)
+ {
if(!(cell_p+j+i*area)->status&AMORPH)
{
- (cell_p+j+i*area)->conc=c_area/area;
- total+=c_area/area;
+ (cell_p+j+i*area)->conc=c_area/count;
+ total+=c_area/count;
}
}
j=0;
- while(j<c_area%area)
+ while(j<c_area%count)
{
x=rand_get(x_max);
y=rand_get(y_max);
cell *this_cell;
int i,j,k;
double pressure;
+
this_cell=cell_p+x+y*x_max+z*x_max*y_max;
pressure=p0*URAND_2BYTE_MAX;
+
for(i=-range;i<=range;i++)
{
for(j=-range;j<=range;j++)
}
}
}
+ pressure*=this_cell->conc;
if(this_cell->status&AMORPH)
{
/* wrong probability! just test by now ...*/
for(i=1;i<=z_cell;i++) gr+=i;
printfd("debug: gr = %d\n",gr);
+ /* allocate random number buffer */
+ printf("malloc will free %d bytes now ...\n",RAND_BUF_SIZE);
+ if((rand_buf=(u32 *)malloc(RAND_BUF_SIZE))==NULL)
+ {
+ puts("failed allocating memory for random numbers");
+ return -23;
+ }
+ rand_current=rand_buf+RAND_BUF_SIZE;
+
/* allocate cells */
printf("malloc will free %d bytes now ...\n",x_cell*y_cell*z_cell*sizeof(cell));
if((cell_p=(cell *)malloc(x_cell*y_cell*z_cell*sizeof(cell)))==NULL)
{
- puts("failed allocating memory for cells\n");
+ puts("failed allocating memory for cells");
return -23;
}
memset(cell_p,0,x_cell*y_cell*z_cell*sizeof(cell));
x=rand_get(x_cell);
y=rand_get(y_cell);
z=rand_get_lgp(slope_nel,start_nel,z_cell);
+ printfd("x = %u, y = %u, z = %u\n",x,y,z);
/* todo */
- // distrib_c_conc(cell_p,c_dist_c0,c_dist_slope,c_conc,x_cell,y_cell,z_cell);
+ distrib_c_conc(cell_p,c_dist_c0,c_dist_slope,c_conc,x_cell,y_cell,z_cell);
// process_cell(cell_p+x+y*x_cell+z*x_cell*y_cell);
process_cell(cell_p,x,y,z,x_cell,y_cell,z_cell,a_p_range,a_p_faktor,a_p_p0,&c_conc);
/* global and extern variables */
extern u32 gr;
extern int random_fd;
+extern u32 *rand_buf,*rand_current;
/* return random integer between 0 - max-1 */
u32 rand_get(u32 max)
{
- u32 rand_int;
- if(read(random_fd,&rand_int,4)!=4)
+ if(rand_current==rand_buf+RAND_BUF_SIZE)
{
- puts("failed reading 4 bytes of random data");
- return -23;
+ printfd("debug: reading new random bytes\n");
+ if(read(random_fd,rand_buf,RAND_BUF_SIZE)!=RAND_BUF_SIZE)
+ {
+ puts("failed reading viel bytes of random data");
+ return -23;
+ }
+ rand_current=rand_buf;
}
/* cells numbered 0...max-1 */
- return((u32)(rand_int*(max*1.0/URAND_MAX)));
+ return((u32)(*(rand_current++)*(max*1.0/URAND_MAX)));
}
/* get z value (linear growth of probability with depths) */
return(i-1); /* return values 0...z_cell-1 */
}
-