-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathupdatesim.cpp
More file actions
104 lines (93 loc) · 2.97 KB
/
updatesim.cpp
File metadata and controls
104 lines (93 loc) · 2.97 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
#include <dynamo.h>
int main(int argc,char *argv[])
{
//////////////////////////////////////////////////////////////
//PROGRAM VARIBALES
//////////////////////////////////////////////////////////////
char simfile[FSIZE]="",nsimfile[FSIZE]="";
int i;
//////////////////////////////////////////////////////////////
//INITIALIZE
//////////////////////////////////////////////////////////////
TITLE(stdout,'*',"UPDATE SIMFILE");
//////////////////////////////////////////////////////////////
//SET OPTIONS AND USAGE
//////////////////////////////////////////////////////////////
SET_OPTIONS(":hvVf:s:n:c:b:t:N:");
SET_USAGE(
"=======================================================================================\n"
"Usage:\n\n"
"\t./program -f <simfile> [-s <new_simfile>]\n"
"\n"
"Update particle properties in simulation file <simfile>. If no new simulation file is\n"
"provided the updated data will be stored in <simfile>.\n"
"=======================================================================================\n"
);
//////////////////////////////////////////////////////////////
//READ OPTIONS
//////////////////////////////////////////////////////////////
while(ITEROPTIONS){
switch(OPTION){
case 'f':
strcpy(simfile,optarg);
break;
case 's':
strcpy(nsimfile,optarg);
break;
//========================================
//COMMON
//========================================
case 'v':
VERBOSITY=1;
break;
case 'V':
VERBOSITY=2;
break;
//DETECT ERRORS
OPTION_ERRORS;
}
}
//////////////////////////////////////////////////////////////
//VALIDATE OPTIONS
//////////////////////////////////////////////////////////////
if(isBlank(simfile)){
fprintf(stderr,"Error: No simfile was provided\n");
PRINT_USAGE;
EXIT;
}
if(!fileExists(simfile)){
fprintf(stderr,"Error: Simfile '%s' does not exist\n",simfile);
PRINT_USAGE;
EXIT;
}
if(isBlank(nsimfile)){
strcpy(nsimfile,simfile);
}
//////////////////////////////////////////////////////////////
//REPORT INPUT INFORMATION
//////////////////////////////////////////////////////////////
if(VERBOSE(1)){
fprintf(stdout,"Simulation file: %s\n",simfile);
}
//////////////////////////////////////////////////////////////
//PROGRAM
//////////////////////////////////////////////////////////////
particles parts;
SHeader sheader;
int ntot;
//Read simulation data
ntot=countLines(simfile);
STPRINTF("Reading %d particles in simulation data...\n",ntot);
parts=readSimulation(simfile,&sheader);
sheader.ntot=ntot;
//Update particles and header
STPRINTF("Updating particles and header...\n");
updateParticles(parts,sheader);
updateHeader(parts,&sheader);
STPRINTF("\t%d particles updated...\n",sheader.ntot);
//Write updated simulation
STPRINTF("Saving simulation file '%s'...\n",nsimfile);
writeSimulation(parts,sheader,nsimfile);
STPRINTF("Done.\n");
return 0;
}