TYCHO  1.3.0
 All Data Structures Files Functions Variables Enumerations Enumerator
/home/kapf/tycho_docu/write_tyc.c
Go to the documentation of this file.
1 
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <math.h>
10 
11 #include "variables_global.h"
12 #include "prototypes.h"
13 
17 int write_tyc(int x, int y, int z, int counter) {
18  FILE *fd;
19  char filename[600];
20  int i, j, k, tmp1;
21  double tmp;
22 
23  sprintf(filename, "%srho_%i.tyc", output_dir, counter);
24  fd = fopen(filename, "wb");
25  if (fd == NULL) {
26  printf("-----------------------------------\n");
27  printf("The output directory does not exist\n");
28  printf("-----------------------------------\n");
29  exit(13);
30  }
31  fprintf(fd, "TYCHO Density File\n%g\n%i\n%i\n%i\n%i\n", time_sim, x, y, z, counter);
32  fseek(fd, 200, SEEK_SET);
33  for (i = 0; i < x; i++) {
34  for (j = 0; j < y; j++) {
35  for (k = 0; k < z; k++) {
36  tmp = rho[i][j][k];
37  if (isnan(tmp)) {
38  printf("NaN in density array %i %i %i\n", i, j, k);
39  exit(0);
40  }
41  fwrite(&tmp, 1, sizeof (double), fd);
42  }
43  }
44  }
45  fclose(fd);
46 
47 
48  sprintf(filename, "%stemp_%i.tyc", output_dir, counter);
49  fd = fopen(filename, "wb");
50  fprintf(fd, "TYCHO Temperature File\n%g\n%i\n%i\n%i\n%i\n", time_sim, x, y, z, counter);
51  fseek(fd, 200, SEEK_SET);
52  for (i = 0; i < x; i++) {
53  for (j = 0; j < y; j++) {
54  for (k = 0; k < z; k++) {
55  tmp = pre[i][j][k] / (gasconstant * rho[i][j][k]);
56  if (isnan(tmp)) {
57  printf("NaN in temperature array %i %i %i\n", i, j, k);
58  printf("%g %g %i\n", pre[i][j][k], rho[i][j][k], dom[i][j][k]);
59  exit(1);
60  }
61  fwrite(&tmp, 1, sizeof (double), fd);
62  }
63  }
64  }
65  fclose(fd);
66 
67  sprintf(filename, "%spressure_%i.tyc", output_dir, counter);
68  fd = fopen(filename, "wb");
69  fprintf(fd, "TYCHO Pressure File\n%g\n%i\n%i\n%i\n%i\n", time_sim, x, y, z, counter);
70  fseek(fd, 200, SEEK_SET);
71  for (i = 0; i < x; i++) {
72  for (j = 0; j < y; j++) {
73  for (k = 0; k < z; k++) {
74  if (dom[i][j][k] == 0) tmp = pre[i][j][k];
75  if (dom[i][j][k] == 1) tmp = 0.0;
76  if (isnan(tmp)) {
77  printf("NaN in pressure array %i %i %i\n", i, j, k);
78  exit(1);
79  }
80  fwrite(&tmp, 1, sizeof (double), fd);
81  }
82  }
83  }
84  fclose(fd);
85 
86 
87  sprintf(filename, "%svel_%i.tyc", output_dir, counter);
88  fd = fopen(filename, "wb");
89  fprintf(fd, "TYCHO Velocity File\n%g\n%i\n%i\n%i\n%i\n", time_sim, x, y, z, counter);
90  fseek(fd, 200, SEEK_SET);
91  for (i = 0; i < x; i++) {
92  for (j = 0; j < y; j++) {
93  for (k = 0; k < z; k++) {
94  tmp = vx[i][j][k];
95  if (isnan(tmp)) {
96  printf("NaN in vx array %i %i %i\n", i, j, k);
97  exit(1);
98  }
99  fwrite(&tmp, 1, sizeof (double), fd);
100  tmp = vy[i][j][k];
101  if (isnan(tmp)) {
102  printf("NaN in vy array %i %i %i\n", i, j, k);
103  exit(1);
104  }
105  fwrite(&tmp, 1, sizeof (double), fd);
106  tmp = vz[i][j][k];
107  if (isnan(tmp)) {
108  printf("NaN in vz array %i %i %i\n", i, j, k);
109  exit(1);
110  }
111  fwrite(&tmp, 1, sizeof (double), fd);
112  }
113  }
114  }
115  fclose(fd);
116 
117 
118  if (with_obstacles == 1) {
119  sprintf(filename, "%spressure_on_solid_%i.tyc", output_dir, counter);
120  fd = fopen(filename, "wb");
121  fprintf(fd, "TYCHO pressure on solid File\n%g\n%i\n%i\n%i\n%i\n", time_sim, x, y, z, counter);
122  fseek(fd, 200, SEEK_SET);
123  for (i = 0; i < x; i++) {
124  for (j = 0; j < y; j++) {
125  for (k = 0; k < z; k++) {
126  tmp = pressure_on_solid[i][j][k];
127  fwrite(&tmp, 1, sizeof (double), fd);
128  }
129  }
130  }
131  fclose(fd);
132 
133  if ((with_sound_emitter == 1) && (dB_Map_ready == 1)) {
134  sprintf(filename, "%sdB_map_%i.tyc", output_dir, counter);
135  fd = fopen(filename, "wb");
136  fprintf(fd, "TYCHO dba_map\n%g\n%i\n%i\n%i\n%i\n", time_sim, x, y, z, counter);
137  fseek(fd, 200, SEEK_SET);
138  for (i = 0; i < x; i++) {
139  for (j = 0; j < y; j++) {
140  for (k = 0; k < z; k++) {
141  tmp = dB_map[i][j][k];
142  if (isnan(tmp)) {
143  printf("NaN in dB_map array %i %i %i\n", i, j, k);
144  exit(1);
145  }
146 
147  fwrite(&tmp, 1, sizeof (double), fd);
148  }
149  }
150  }
151  fclose(fd);
152  }
153  }
154 
155  if (advection == 1) {
156  sprintf(filename, "%smarker_%i.tyc", output_dir, counter);
157  fd = fopen(filename, "wb");
158  fprintf(fd, "TYCHO Marker File%g\n%i\n%i\n%i\n%i\n", time_sim, x, y, z, counter);
159  fseek(fd, 200, SEEK_SET);
160  for (i = 0; i < x; i++) {
161  for (j = 0; j < y; j++) {
162  for (k = 0; k < z; k++) {
163  tmp = marker[i][j][k];
164  if (isnan(tmp)) {
165  printf("NaN in marker array %i %i %i\n", i, j, k);
166  exit(1);
167  }
168  fwrite(&tmp, 1, sizeof (double), fd);
169  }
170  }
171  }
172  fclose(fd);
173  }
174 
175  return 0;
176 }