#define DEFAULT_Y_SEG 50
#define DEFAULT_Z_SEG 100
-#define DEFAULT_SLOPE_CC 1
-#define DEFAULT_START_CC 0
+#define DEFAULT_SLOPE_NEL 1
+#define DEFAULT_START_NEL 0
+
+#define DEFAULT_STEPS 5000
/* program defines, dont touch ;) */
#define DEBUG 0
#endif
+#define URAND_MAX 0xffffffff
+
+typedef unsigned int u32;
+typedef long long unsigned int u64;
+
#define printfd(fmt,args...) if(DEBUG) printf(fmt,##args);
+/* segment struct
+ *
+ * not used by now
+ */
+struct __segment
+{
+ u32 status; /* C concentration */
+}
+
+/* masks for u32 segments */
+#define AMORPH 0x00000001
+#define CRYSTAL 0x00000000
+#define C_CONC_MASK 0xfffffffe
+
#include <stdio.h>
#include <stdlib.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+
#include "defines.h"
/* global variables */
-int sum_z_segments;
+u32 sum_z_segments;
+int random_fd; /* /dev/urandom file descriptor */
int usage()
{
puts("usage:");
puts("-h: help");
- puts("-a <value> \t slope of C concentration with depth (default 1)");
- puts("-c <value> \t concentration at depths 0 (default 0)");
+ puts("-a <value> \t slope of nuclear energy loss (default 1)");
+ puts("-c <value> \t nuclear enery loss at depths 0 (default 0)");
puts("-x <value> \t # x segments (default 50)");
puts("-y <value> \t # y segments (default 50)");
puts("-z <value> \t # z segments (default 100)");
+ puts("-s <value> \t # steps to calculate (default 5000");
return -23;
}
-int main(int argc,char **argv) {
- int x_seg,y_seg,z_seg; /* amount of segments */
- int x,y,z; /* segments */
+int make_amorph(u32 *segment)
+{
+ *segment=*segment|AMORPH
+ return 23;
+}
+
+/* look at segment ... */
+int process_segment(u32 *segment)
+{
+ /* tag it ... testing! */
+ make_amorph(segment);
+
+ return 23;
+}
+
+int main(int argc,char **argv)
+{
+ u32 x_seg,y_seg,z_seg; /* amount of segments */
+ u32 x,y,z; /* segments */
int i; /* for counting */
- int slope_cc,start_cc; /* C concentration: slope, c(0) */
+ int slope_nel,start_nel; /* nuclear energy loss: slope, constant */
+ int steps; /* # steps */
+ void *segments_p;
/* default values */
- x_seg=DEFAULT_X_SEG-1;
- y_seg=DEFAULT_Y_SEG-1;
- z_seg=DEFAULT_Z_SEG-1;
- slope_cc=DEFAULT_SLOPE_CC;
- start_cc=DEFAULT_START_CC;
+ x_seg=DEFAULT_X_SEG;
+ y_seg=DEFAULT_Y_SEG;
+ z_seg=DEFAULT_Z_SEG;
+ slope_nel=DEFAULT_SLOPE_NEL;
+ start_nel=DEFAULT_START_NEL;
+ steps=DEFAULT_STEPS;
/* parse command args */
for(i=1;i<argc;i++)
return 23;
break;
case 'a':
- slope_cc=atoi(argv[++i]);
+ slope_nel=atoi(argv[++i]);
break;
case 'c':
- start_cc=atoi(argv[++i]);
+ start_nel=atoi(argv[++i]);
break;
case 'x':
x_seg=atoi(argv[++i]);
case 'z':
z_seg=atoi(argv[++i]);
break;
+ case 's':
+ steps=atoi(argv[++i]);
+ break;
+ default:
+ usage();
+ return -23;
}
} else usage();
}
+ /* open random fd */
+ if((random_fd=open("/dev/urandom",O_RDONLY))<0)
+ {
+ puts("cannot open /dev/urandom\n");
+ return -23;
+ }
+
/* calculate sum_z_segments one time! */
sum_z_segments=0;
- for(i=0;i<z_seg;i++) sum_z_segments+=(start_cc+i*slope_cc);
+ for(i=1;i<=z_seg;i++) sum_z_segments+=(start_nel+i*slope_nel);
printfd("debug: sum z segments -> %d\n",sum_z_segments);
/* testing ... */
- for(i=0;i<100;i++)
+ /* allocate segments */
+ if((segments_p=malloc(x_seg*y_seg*z_seg*sizeof(u32)))==NULL)
+ {
+ puts("failed allocating memory for segments\n");
+ return -23;
+ }
+ memset(segments_p,0,x_seg*y_seg*z_seg*sizeof(u32));
+
+ /* main routine */
+ for(i=0;i<steps;i++)
{
x=rand_get(x_seg);
y=rand_get(y_seg);
- z=rand_get_lgp(slope_cc,start_cc);
- printf ("x=%d y=%d z=%d\n",x,y,z);
+ z=rand_get_lgp(slope_nel,start_nel);
+
+ /* todo */
+ distrib_c_conc(segments_p);
+ process_segment((u32)(segments_p+x+y*(x_seg-1)+z*(x_seg-1)*(y_seg-1)));
+ display(segments_p);
+ /* */
+
}
return 23;
}
#include <stdio.h>
#include <stdlib.h>
+#include <unistd.h>
#include "defines.h"
-extern int sum_z_segments;
+/* global & extern variables */
+extern u32 sum_z_segments;
+extern int random_fd;
/* return random integer between 0 - max */
-int rand_get(int max) {
- return((int) (rand() * (max*1.0/RAND_MAX)) );
+u32 rand_get(u32 max)
+{
+ u32 rand_int;
+ if(read(random_fd,&rand_int,4)!=4)
+ {
+ puts("failed reading 4 bytes of random data");
+ return -23;
+ }
+ /* segments numbered 0...max-1 */
+ return((u32)(rand_int*(max*1.0/URAND_MAX)));
}
/* get z value (linear growth of probability with depths) */
-int rand_get_lgp(int slope_cc,int start_cc) {
- int z,i;
- z=rand_get(sum_z_segments);
- for(i=0;;i++) {
- z-=i*slope_cc;
+u32 rand_get_lgp(int slope_nel,int start_nel) {
+ int z;
+ u32 i;
+ z=rand_get(sum_z_segments)+1; /* +1 as rand_get returns values 0...max-1 */
+ for(i=1;;i++) {
+ z-=(start_nel+i*slope_nel);
if(z<=0) break;
}
- return i;
+ return(i-1); /* return values 0...z_seg-1 */
}