added display support (init by now) (dfb-api)
[physik/morpheus.git] / main.c
1 /*
2  * morpheus - main.c
3  *
4  * this program tries helping to understand the amorphous depuration
5  * and recrystallization of SiCx while ion implanation. hopefully the program 
6  * will simulate the stabilization of the selforganizing structure in the
7  * observed behaviour.
8  *
9  * refs: 
10  *  - J. K. N. Lindner. Habilationsschrift, Universitaet Augsburg.
11  *  - Maik Haeberlen. Diplomarbeit, Universitaet Augsburg.
12  */
13
14 #include <stdio.h>
15 #include <stdlib.h>
16 #include <sys/types.h>
17 #include <sys/stat.h>
18 #include <fcntl.h>
19
20 #include "defines.h"
21
22 /* global variables */
23 u32 sum_z_cells;
24 int random_fd; /* /dev/urandom file descriptor */
25
26 int usage()
27 {
28  puts("usage:");
29  puts("-h: help");
30  puts("-a <value> \t slope of nuclear energy loss (default 1)");
31  puts("-c <value> \t nuclear enery loss at depths 0 (default 0)");
32  puts("-x <value> \t # x cells (default 50)");
33  puts("-y <value> \t # y cells (default 50)");
34  puts("-z <value> \t # z cells (default 100)");
35  puts("-s <value> \t # steps to calculate (default 5000)");
36  puts("-X <value> \t display area intercept point x (default 25)");
37  puts("-Y <value> \t display area intercept point y (default 25)");
38  puts("-Z <value> \t display area intercept point z (default 50)");
39  puts("-d <value> \t refresh every <value> loops (default 100)");
40  return -23;
41 }
42
43 int make_amorph(u32 *cell)
44 {
45  *cell=*cell|AMORPH;
46  return 23;
47 }
48
49 int make_cryst(u32 *cell)
50 {
51  *cell=*cell&(~AMORPH);
52  return 23;
53 }
54
55 /* look at cell ... */
56 int process_cell(u32 *cell)
57 {
58  /* tag it ... testing! */
59  make_amorph(cell);
60  
61  return 23;
62 }
63
64 int main(int argc,char **argv) 
65 {
66  u32 x_cell,y_cell,z_cell; /* amount of segments */
67  u32 x,y,z; /* cells */
68  int i; /* for counting */
69  int slope_nel,start_nel; /* nuclear energy loss: slope, constant */
70  int steps; /* # steps */
71  void *cell_p;
72  struct __display display;
73  u32 display_x,display_y,display_z; /* intercept point of diplayed areas */
74  u32 display_refresh_rate; /* refresh rate for display */
75
76  /* default values */
77  x_cell=DEFAULT_X_SEG;
78  y_cell=DEFAULT_Y_SEG;
79  z_cell=DEFAULT_Z_SEG;
80  slope_nel=DEFAULT_SLOPE_NEL;
81  start_nel=DEFAULT_START_NEL;
82  steps=DEFAULT_STEPS;
83  display_x=DEFAULT_DISPLAY_X-1;
84  display_y=DEFAULT_DISPLAY_Y-1;
85  display_z=DEFAULT_DISPLAY_Z-1;
86  display_refresh_rate=DEFAULT_DISPLAY_REF_RATE;
87  
88  /* parse command args */
89  for(i=1;i<argc;i++)
90  {
91   if(argv[i][0]=='-')
92   {
93    switch(argv[i][1])
94    {
95     case 'h':
96      usage();
97      return 23;
98      break;
99     case 'a':
100      slope_nel=atoi(argv[++i]);
101      break;
102     case 'c':
103      start_nel=atoi(argv[++i]);
104      break;
105     case 'x':
106      x_cell=atoi(argv[++i]);
107      break;
108     case 'y':
109      y_cell=atoi(argv[++i]);
110      break;
111     case 'z':
112      z_cell=atoi(argv[++i]);
113      break;
114     case 's':
115      steps=atoi(argv[++i]);
116      break;
117     case 'X':
118      display_x=atoi(argv[++i]);
119      break;
120     case 'Y':
121      display_y=atoi(argv[++i]);
122      break;
123     case 'Z':
124      display_z=atoi(argv[++i]);
125      break;
126     case 'd':
127      display_refresh_rate=atoi(argv[++i]);
128      break;
129     default:
130      usage();
131      return -23;
132    }
133   } else usage();
134  }
135
136  /* open random fd */
137  if((random_fd=open("/dev/urandom",O_RDONLY))<0)
138  {
139   puts("cannot open /dev/urandom\n");
140   return -23;
141  }
142
143  /* calculate sum_z_cells one time! */
144  sum_z_cells=0;
145  for(i=1;i<=z_cell;i++) sum_z_cells+=(start_nel+i*slope_nel);
146  printfd("debug: sum z cells -> %d\n",sum_z_cells);
147
148
149  /* testing ... */
150
151  /* allocate cells */
152  if((cell_p=malloc(x_cell*y_cell*z_cell*sizeof(u32)))==NULL)
153  {
154   puts("failed allocating memory for cells\n");
155   return -23;
156  }
157  memset(cell_p,0,x_cell*y_cell*z_cell*sizeof(u32));
158
159  /* init display */
160  display_init(x_cell,y_cell,z_cell,&display,cell_p,&argc,argv);
161
162  /* main routine */
163  for(i=0;i<steps;i++)
164  {
165   x=rand_get(x_cell);
166   y=rand_get(y_cell);
167   z=rand_get_lgp(slope_nel,start_nel);
168
169   /* todo */
170   // distrib_c_conc(cell_p);
171   process_cell((u32 *)(cell_p+x+y*(x_cell-1)+z*(x_cell-1)*(y_cell-1)));
172
173   /* display stuff */
174   if((i%display_refresh_rate)==0)
175   {
176    puts("refreshing diplay ...");
177    // display_draw(&display,display_x,display_y,display_z);
178   }
179   /* */
180  }
181   
182  /* display again and quit when button hit */
183  puts("hit button to quit ...");
184  getchar();
185
186  return 23;
187 }