-
Notifications
You must be signed in to change notification settings - Fork 0
/
io.h
138 lines (112 loc) · 2.4 KB
/
io.h
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
void read_dbl(int f, double ****vel)
{
FILE *fp;
double d;
long int offset;
char filenumb[5];
char filename[100];
int i,j,k,dir;
sprintf(filenumb,"%04d",f);
strcat(filename,datdir);
strcat(filename,prefix);
strcat(filename,filenumb);
strcat(filename,suffix);
printf("%s\n",filename);
fp = fopen(filename,"rb");
if(fp==NULL){
printf("fopen error (1)");
exit(0);
}
for(i=0;i<nx;i++){
for(j=0;j<ny;j++){
for(k=0;k<nz;k++){
for(dir=0;dir<nv;dir++){
offset = i*ny*nz+j*ny+k + (dir+1)*nx*ny*nz;
fseek(fp,sizeof(double)*offset,SEEK_SET);
fread(&d,sizeof(double),1,fp);
vel[dir][i][j][k] = d;
}
}
}
}
fclose(fp);
return;
}
void printarray4d(int n0, int n1, int n2, int n3, double ****vel)
{
int n,i,j,k;
for(n=0;n<n0;n++){
for(i=0;i<n1;i++){
for(j=0;j<n2;j++){
for(k=0;k<n3;k++){
printf("%d,%2d,%2d,%2d,%16.12f\n",n,i,j,k,vel[n][i][j][k]);
}
}
}
}
return;
}
void write_velk(int dir, double ****velk, fftw_complex *out)
{
int i,j,k;
double real, imag;
for(i=0;i<nx;i++){
for(j=0;j<ny;j++){
for(k=0;k<nz/2+1;k++){
real = creal(out[i*nx*ny+j*ny+k]);
imag = cimag(out[i*nx*ny+j*ny+k]);
velk[dir][i][j][k]=sqrt(real*real+imag*imag);
}
}
}
return;
}
void write_output(int type, int f, int n0, int n1, int n2, int n3, double ****velk)
{
FILE *fp;
double d;
long int offset;
char filenumb[5];
char filename[100];
sprintf(filenumb,"%04d",f);
strcat(filename,datdir);
strcat(filename,prefix);
strcat(filename,filenumb);
if(type == 0){
strcat(filename,".dbl");
}
if(type == 1){
strcat(filename,".vtk");
}
printf("%s\n",filename);
int n,i,j,k;
if(type == 0){
fp = fopen(filename,"wb");
for(n=0;n<n0;n++){
for(i=0;i<n1;i++){
for(j=0;j<n2;j++){
for(k=0;k<n3;k++){
fwrite(velk[n][i][j][k],sizeof(double),1,fp);
}
}
}
}
fclose(fp);
}
if(type == 1){
fp = fopen(filename,"r");
fclose(fp);
for(n=0;n<n0;n++){
fp = fopen(filename,"r");
for(i=0;i<n1;i++){
for(j=0;j<n2;j++){
for(k=0;k<n3;k++){
fwrite(velk[n][i][j][k],sizeof(double),1,fp);
}
}
}
}
fclose(fp);
}
}
}