-
Notifications
You must be signed in to change notification settings - Fork 0
/
young.c
65 lines (59 loc) · 1.35 KB
/
young.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <stdio.h>
#include <stdlib.h>
int main()
{
size_t n = 256, m = 3*n;
char *file = "young.in";
double speed = 0.35;
char type = 1;
FILE *fp;
fp = fopen(file, "wb");
// header of the file
fwrite(&type, sizeof(char), 1, fp);
fwrite(&n, sizeof(size_t), 1, fp);
fwrite(&m, sizeof(size_t), 1, fp);
fwrite(&speed, sizeof(double), 1, fp);
char cell_type;
double cell_value;
// now the real part
for(size_t i = 0; i < n; i++)
{
for(size_t j = 0; j < m; j++)
{
// if(j == 0) // walls at the left
// {
// cell_type = 1;
// cell_value = 0;
// }
// else if((i == 0 || i == (n-1) && j <= m/3)) // walls on top and bottom and beginning
// {
// cell_type = 1;
// cell_value = 0;
// }
// else
if(j == m/3 && !(i >= n/3-2 && i <= n/3+2) && !(i >= 2*n/3-2 && i <= 2*n/3+2)) // walls except at two points
{
cell_type = 1;
cell_value = 0;
}
else if(j == (m/2-1)) // sensors at the end
{
cell_type = 2;
cell_value = 0;
}
else if((j >= m/6 && j <= m/6+8) && (i >= (n/2-1-4) && i <= (n/2+4))) // source
{
cell_type = 0;
cell_value = 3;
}
else // Basic case
{
cell_type = 0;
cell_value = 0;
}
fwrite(&cell_type, sizeof(char), 1, fp);
fwrite(&cell_value, sizeof(double), 1, fp);
}
}
fclose(fp);
}