Skip to content

Commit f18ce3b

Browse files
committed
Added files via upload
Calculates the masses of the impactor and target from the output of the zeroth time step in CTH.
1 parent e708106 commit f18ce3b

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

masses.c

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#include <stdlib.h>
2+
#include <stdio.h>
3+
#include <math.h>
4+
5+
6+
int argc;
7+
char **argv;
8+
9+
int main (int argc, char **argv) {
10+
int nel, ntot;
11+
char filename1[255], firstletter[256];
12+
FILE * fid;
13+
float mt, miron, mdunite;
14+
15+
if (argc !=2) {
16+
printf("Usage: masses filename\n");
17+
exit(0);
18+
}
19+
20+
21+
sprintf(filename1, "%s", argv[1]);
22+
23+
printf("input filename=%s\n", filename1);
24+
25+
fid=fopen(filename1, "r");
26+
27+
28+
if (fid == NULL){
29+
printf("(Input file not found):\n");
30+
printf("%s\n", filename1);
31+
exit(0);
32+
}
33+
34+
rewind(fid);
35+
36+
fgets(firstletter, 255, fid);
37+
38+
float xloc, yloc, zloc, vx, vy, vz, p, dens, tk, m1, m2, m3, m4, v1, v2, v3, v4;
39+
40+
nel=0;
41+
ntot=0;
42+
mt=0.0;
43+
miron=0.0;
44+
mdunite=0.0;
45+
46+
47+
while(feof(fid) == 0) {
48+
49+
fgets(firstletter, 255, fid);
50+
sscanf(firstletter, "%e%e%e%e%e%e%e%e%e%e%e%e%e%e%e%e%e", &xloc, &yloc, &zloc, &vx, &vy, &vz, &p, &dens, &tk, &m1, &m2, &m3, &m4, &v1, &v2, &v3, &v4);
51+
52+
mt=mt+(m1+m2+m3+m4);
53+
miron=miron+(m2+m4);
54+
mdunite=mdunite+(m1+m3);
55+
}
56+
fclose(fid);
57+
58+
printf("%e,%e,%e,%e\n", mt, miron, mdunite, miron/mt);
59+
60+
61+
return(0);
62+
}
63+

0 commit comments

Comments
 (0)