-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbin2sim.cpp
More file actions
158 lines (144 loc) · 4.52 KB
/
bin2sim.cpp
File metadata and controls
158 lines (144 loc) · 4.52 KB
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Purpose: Read the data from a Gadget file and write it in a
simulation file in ASCII format.
Changes log:
- Apr/7-JZ: Checked
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
*/
#include <dynamo.h>
int main(int argc,char *argv[])
{
//////////////////////////////////////////////////////////////
//PROGRAM VARIBALES
//////////////////////////////////////////////////////////////
char simulation[FSIZE]="",snapshot[FSIZE]="";
char binfile[FSIZE]="",simfile[FSIZE]="";
bool qsub=false;
//////////////////////////////////////////////////////////////
//INITIALIZE
//////////////////////////////////////////////////////////////
TITLE(stdout,'*',"CONVERSION FROM BINARY TO ASCII SIMULATION");
//////////////////////////////////////////////////////////////
//SET OPTIONS AND USAGE
//////////////////////////////////////////////////////////////
SET_OPTIONS(":hvVSs:n:d:");
SET_USAGE(
"=======================================================================================\n"
"Usage:\n\n"
"\t./program -s <simulation_name> -n <number_snapshot> [-d <simulation_datafile>]\n"
"\t [-S]\n"
"\n"
"Read the data from <simulation_name>_<number_snapshot> and convert to\n"
"ascii in <simulation_datafile>\n"
"\n"
"Optional:\n"
"\n"
"\t-S : include index from substructure description file\n"
"\t <simulation_name>.sub\n"
"=======================================================================================\n"
);
//////////////////////////////////////////////////////////////
//READ OPTIONS
//////////////////////////////////////////////////////////////
while(ITEROPTIONS){
switch(OPTION){
case 's':
strcpy(simulation,optarg);
break;
case 'n':
strcpy(snapshot,optarg);
break;
case 'd':
strcpy(simfile,optarg);
break;
case 'S':
qsub=true;
break;
//========================================
//COMMON
//========================================
case 'v':
VERBOSITY=1;
break;
case 'V':
VERBOSITY=2;
break;
OPTION_ERRORS;
}
}
//////////////////////////////////////////////////////////////
//VALIDATE OPTIONS
//////////////////////////////////////////////////////////////
if(isBlank(simulation)){
fprintf(stderr,"Error: No simulation name was provided\n");
PRINT_USAGE;
EXIT;
}
if(isBlank(snapshot)){
fprintf(stderr,"Error: No snapshot number provided\n");
PRINT_USAGE;
EXIT;
}
sprintf(binfile,"%s_%s",simulation,snapshot);
if(!fileExists(binfile)){
fprintf(stderr,"Error: Binary file '%s' does not exist\n",
binfile);
PRINT_USAGE;
EXIT;
}
if(qsub){
char subfile[FSIZE];
sprintf(subfile,"%s.sub",simulation);
if(!fileExists(subfile)){
fprintf(stderr,"Error: Substructure file '%s' does not exist\n",
subfile);
PRINT_USAGE;
EXIT;
}
}
if(isBlank(simfile)){
sprintf(simfile,"%s.sim",binfile);
}
/*
if(fileExists(simfile)){
fprintf(stderr,"Simulation file '%s' already exist. Do you want to continue? ",simfile);
pause();
}
*/
//////////////////////////////////////////////////////////////
//REPORT INPUT INFORMATION
//////////////////////////////////////////////////////////////
if(VERBOSE(1)){
fprintf(stdout,"Simulation: %s\n",simulation);
fprintf(stdout,"Snapshot: %s\n",snapshot);
fprintf(stdout,"Simulation file: %s\n",simfile);
}
//////////////////////////////////////////////////////////////
//PROGRAM
//////////////////////////////////////////////////////////////
//========================================
//READ GADGET
//========================================
STPRINTF("Reading data from gadget file...\n");
SHeader sheader;
particles parts;
parts=readGadget(simulation,snapshot,&sheader,qsub);
STPRINTF("\t%d particles read...\n",sheader.ntot);
if(VERBOSE(2)) checkSimulation(sheader);
//========================================
//UPDATE HEADER
//========================================
STPRINTF("Computing properties from data read from file... ");
updateParticles(parts,sheader);
updateHeader(parts,&sheader);
fprintf(stdout,"Done.\n");
if(VERBOSE(2)) checkSimulation(sheader);
//========================================
//WRITE SIMULATION FILE
//========================================
STPRINTF("Writing simulation file...");
writeSimulation(parts,sheader,simfile);
fprintf(stdout,"Done.\n");
return 0;
}