-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdiscard_empty.c
117 lines (77 loc) · 2.58 KB
/
discard_empty.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
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
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#define Mearth 5.98e27
int argc;
char **argv;
int main (int argc, char **argv) {
int nel, ntot;
char filename1[255], filenameout[255], firstletter[400];
/*char crap[400];*/
FILE * fid;
FILE * fidout;
float totalvolfrac;
if (argc !=2) {
printf("Usage: discard_empty input_filename\n");
exit(0);
}
sprintf(filename1, "%s", argv[1]);
sprintf(filenameout, "%s.no_empties.txt", argv[1]);
printf("input filename=%s\n", filename1);
printf("output filename=%s\n", filenameout);
fid=fopen(filename1, "r");
fidout=fopen(filenameout, "w");
if (fid == NULL){
printf("(Input file not found):\n");
printf("%s\n", filename1);
exit(0);
}
if (fidout == NULL) {
printf("(Invalid output file name):\n");
printf("%s\n", filenameout);
exit(0);
}
rewind(fid);
rewind(fidout);
fgets(firstletter, 400, fid);
/*fprintf(stderr, "firstletter=%s\n", firstletter);*/
float xloc, yloc, zloc, vx, vy, vz, dx, dy, dz, p, dens, tk, m1, m2, m3, m4, v1, v2, v3, v4;
float mt;
nel=0;
ntot=0;
mt=0.0;
fprintf(fidout, " \n");
while(feof(fid) == 0) {
/********** DEBUG ************/
/*while(ntot < 1){ */
/********** DEBUG ************/
totalvolfrac=0.0;
fgets(firstletter, 400, fid);
/********** DEBUG ************/
/*fprintf(stderr, "first line of numerical data=%s\n", firstletter); */
/********** DEBUG ************/
sscanf(firstletter, "%e%e%e%e%e%e%e%e%e%e%e%e%e%e%e%e%e%e%e%e", &xloc, &yloc, &zloc, &dx, &dy, &dz, &vx, &vy, &vz, &p, &dens, &tk, &m1, &m2, &m3, &m4, &v1, &v2, &v3, &v4);
/********** DEBUG ************/
/*fprintf(stderr, "xloc=%e, yloc=%e, zloc=%e\n", xloc, yloc, zloc);
fprintf(stderr, "dx=%e, dy=%e, dz=%e\n", dx, dy, dz);
fprintf(stderr, "vz=%e, p=%e, dens=%e, tk=%e, m1=%e, m2=%e\n", vz, p, dens, tk, m1, m2);
fprintf(stderr, "m3=%e, m4=%e, v1=%e, v2=%e, v3=%e, v4=%e\n", m3, m4, v1, v2, v3, v4);*/
/********** DEBUG ************/
totalvolfrac=v1+v2+v3+v4;
if(dens > 5.0e-6) /*If there's stuff in this cell (above Robin's density cutoff -- ACB modified 6.14.10)... write to output file*/
{
fprintf(fidout, "%e,%e,%e,%e,%e,%e,%e,%e,%e,%e,%e,%e,%e,%e,%e,%e,%e, %e\n", xloc, yloc, zloc, vx, vy, vz, p, dens, tk, m1, m2, m3, m4, v1, v2, v3, v4, totalvolfrac);
nel=nel+1;
mt=mt+(m1+m2+m3+m4);
}
ntot=ntot+1;
}
fprintf(stderr, "number of cells written=%d\n", nel);
fprintf(stderr, "percent kept=%e\n", (nel/(1.0*ntot))*100.0);
rewind(fidout);
fprintf(fidout, "%d", nel);
fclose(fidout);
fclose(fid);
fprintf(stderr, "total mass in domain=%e (grams), total mass in domain=%e (earth masses)\n", mt, mt/Mearth);
return(0);
}