1 |
mmeineke |
672 |
#include <iostream> |
2 |
mmeineke |
795 |
#include <stdio.h> |
3 |
|
|
#include <stdlib.h> |
4 |
|
|
#include <string.h> |
5 |
|
|
#include <vector> |
6 |
mmeineke |
672 |
|
7 |
|
|
#include "simError.h" |
8 |
|
|
#include "SimSetup.hpp" |
9 |
|
|
#include "SimInfo.hpp" |
10 |
|
|
#include "Atom.hpp" |
11 |
|
|
#include "Integrator.hpp" |
12 |
|
|
#include "Thermo.hpp" |
13 |
|
|
#include "ReadWrite.hpp" |
14 |
|
|
|
15 |
mmeineke |
795 |
#include "PairCorrList.hpp" |
16 |
|
|
#include "AllCorr.hpp" |
17 |
|
|
|
18 |
|
|
#define VERSION_MAJOR 0 |
19 |
|
|
#define VERSION_MINOR 1 |
20 |
|
|
|
21 |
|
|
char *programName; /*the name of the program */ |
22 |
|
|
void usage(void); |
23 |
mmeineke |
672 |
using namespace std; |
24 |
|
|
|
25 |
mmeineke |
795 |
int main(int argC,char* argV[]){ |
26 |
mmeineke |
672 |
|
27 |
mmeineke |
795 |
int i,j; // loop counters |
28 |
|
|
|
29 |
|
|
char* outPrefix; // the output prefix |
30 |
|
|
|
31 |
|
|
char* conversionCheck; |
32 |
|
|
bool conversionError; |
33 |
|
|
bool optionError; |
34 |
|
|
|
35 |
|
|
char currentFlag; // used in parsing the flags |
36 |
|
|
bool done = false; // multipurpose boolean |
37 |
|
|
bool havePrefix; // boolean for the output prefix |
38 |
|
|
|
39 |
|
|
bool haveMaxLength; |
40 |
|
|
double maxLength; |
41 |
|
|
|
42 |
|
|
vector<PairCorrList> theList; |
43 |
|
|
pairCorrEnum pairType; |
44 |
|
|
|
45 |
|
|
char* pair1; |
46 |
|
|
char* pair2; |
47 |
|
|
|
48 |
mmeineke |
672 |
char dumpName[2000]; |
49 |
|
|
char* endTest; |
50 |
|
|
int nameLength; |
51 |
|
|
int nFrames; |
52 |
mmeineke |
795 |
char* inName; |
53 |
mmeineke |
672 |
SimSetup* startMe; |
54 |
|
|
SimInfo* infoArray; |
55 |
|
|
DumpReader* reader; |
56 |
mmeineke |
795 |
AllCorr theCorrs; |
57 |
mmeineke |
672 |
|
58 |
|
|
// first things first, all of the initializations |
59 |
|
|
|
60 |
|
|
printf("Initializing stuff ....\n"); |
61 |
|
|
fflush(sdtout); |
62 |
|
|
srand48( 1337 ); // the random number generator. |
63 |
|
|
initSimError(); // the error handler |
64 |
mmeineke |
795 |
|
65 |
|
|
outPrefix = NULL; |
66 |
|
|
inName = NULL; |
67 |
mmeineke |
672 |
|
68 |
mmeineke |
795 |
conversionError = false; |
69 |
|
|
optionError = false; |
70 |
|
|
|
71 |
|
|
havePrefix = false; |
72 |
|
|
haveMaxLength = false; |
73 |
|
|
|
74 |
|
|
maxLength = 1.0; |
75 |
|
|
|
76 |
|
|
programName = argv[0]; /*save the program name in case we need it*/ |
77 |
|
|
|
78 |
|
|
for( i = 1; i < argC; i++){ |
79 |
|
|
|
80 |
|
|
if(argV[i][0] =='-'){ |
81 |
|
|
|
82 |
|
|
// parse the option |
83 |
|
|
|
84 |
|
|
if(argV[i][1] == '-' ){ |
85 |
|
|
|
86 |
|
|
// parse long word options |
87 |
|
|
|
88 |
|
|
if( !strcmp( argV[i], "--gofr" ) ){ |
89 |
|
|
|
90 |
|
|
i++; |
91 |
|
|
if( i>=argC ){ |
92 |
|
|
sprintf( painCave.errMsg, |
93 |
|
|
"\n" |
94 |
|
|
"not enough arguments for --gofr\n"); |
95 |
|
|
usage(); |
96 |
|
|
painCave.isFatal = 1; |
97 |
|
|
simError(); |
98 |
|
|
} |
99 |
|
|
pair1 = argV[i]; |
100 |
|
|
|
101 |
|
|
i++; |
102 |
|
|
if( i>=argC ){ |
103 |
|
|
sprintf( painCave.errMsg, |
104 |
|
|
"\n" |
105 |
|
|
"not enough arguments for --gofr\n"); |
106 |
|
|
usage(); |
107 |
|
|
painCave.isFatal = 1; |
108 |
|
|
simError(); |
109 |
|
|
} |
110 |
|
|
pair2 = argV[i]; |
111 |
|
|
|
112 |
|
|
pairType = gofr; |
113 |
|
|
theList.push_back(PairCorrList( pairType, pair1, pair2 )); |
114 |
|
|
} |
115 |
|
|
|
116 |
|
|
else if( !strcmp( argV[i], "--version") ){ |
117 |
|
|
|
118 |
|
|
printf("\n" |
119 |
|
|
"staticProps version %d.%d\n" |
120 |
|
|
"\n", |
121 |
|
|
VERSION_MAJOR, VERSION_MINOR ); |
122 |
|
|
exit(0); |
123 |
|
|
|
124 |
|
|
} |
125 |
|
|
|
126 |
|
|
else if( !strcmp( argV[i], "--help") ){ |
127 |
|
|
|
128 |
|
|
usage(); |
129 |
|
|
exit(0); |
130 |
|
|
} |
131 |
|
|
|
132 |
|
|
// anything else is an error |
133 |
|
|
|
134 |
|
|
else{ |
135 |
|
|
fprintf( stderr, |
136 |
|
|
"Invalid option \"%s\"\n", argV[i] ); |
137 |
|
|
usage(); |
138 |
|
|
exit(0); |
139 |
|
|
} |
140 |
|
|
} |
141 |
|
|
|
142 |
|
|
else{ |
143 |
|
|
|
144 |
|
|
// parse single character options |
145 |
|
|
|
146 |
|
|
done =0; |
147 |
|
|
j = 1; |
148 |
|
|
currentFlag = argV[i][j]; |
149 |
|
|
while( (currentFlag != '\0') && (!done) ){ |
150 |
|
|
|
151 |
|
|
switch(currentFlag){ |
152 |
|
|
|
153 |
|
|
case 'o': |
154 |
|
|
// -o <prefix> => the output prefix. |
155 |
|
|
|
156 |
|
|
j++; |
157 |
|
|
currentFlag = argV[i][j]; |
158 |
|
|
|
159 |
|
|
if( currentFlag != '\0' ) optionError = true; |
160 |
|
|
|
161 |
|
|
if( optionError ){ |
162 |
|
|
sprintf( painCave.errMsg, |
163 |
|
|
"\n" |
164 |
|
|
"The -o flag should end an option sequence.\n" |
165 |
|
|
" example: -r <outname> *NOT* -or <outname>\n" ); |
166 |
|
|
usage(); |
167 |
|
|
painCave.isFatal = 1; |
168 |
|
|
simError(); |
169 |
|
|
} |
170 |
|
|
|
171 |
|
|
i++; |
172 |
|
|
if( i>=argC ){ |
173 |
|
|
sprintf( painCave.errMsg, |
174 |
|
|
"\n" |
175 |
|
|
"not enough arguments for -o\n"); |
176 |
|
|
usage(); |
177 |
|
|
painCave.isFatal = 1; |
178 |
|
|
simError(); |
179 |
|
|
} |
180 |
|
|
|
181 |
|
|
outPrefix = argV[i]; |
182 |
|
|
if( outPrefix[0] == '-' ) optionError = true; |
183 |
|
|
|
184 |
|
|
if( optionError ){ |
185 |
|
|
sprintf( painCave.errMsg, |
186 |
|
|
"\n" |
187 |
|
|
"\"%s\" is not a valid out prefix/name.\n" |
188 |
|
|
"Out prefix/name should not begin with a dash.\n", |
189 |
|
|
outPrefix ); |
190 |
|
|
usage(); |
191 |
|
|
painCave.isFatal = 1; |
192 |
|
|
simError(); |
193 |
|
|
} |
194 |
|
|
|
195 |
|
|
havePrefix = true; |
196 |
|
|
done = true; |
197 |
|
|
break; |
198 |
|
|
|
199 |
|
|
case 'l': |
200 |
|
|
// -l <double> set <double> to the maxLength |
201 |
|
|
|
202 |
|
|
haveMaxLength = true; |
203 |
|
|
j++; |
204 |
|
|
currentFlag = argV[i][j]; |
205 |
|
|
|
206 |
|
|
if( currentFlag != '\0' ) optionError = true; |
207 |
|
|
|
208 |
|
|
if( optionError ){ |
209 |
|
|
sprintf( painCave.errMsg, |
210 |
|
|
"\n" |
211 |
|
|
"The -i flag should end an option sequence.\n" |
212 |
|
|
" example: -ri <int> *NOT* -ir <int>\n" ); |
213 |
|
|
usage(); |
214 |
|
|
painCave.isFatal = 1; |
215 |
|
|
simError(); |
216 |
|
|
} |
217 |
|
|
|
218 |
|
|
i++; |
219 |
|
|
if( i>=argC ){ |
220 |
|
|
sprintf( painCave.errMsg, |
221 |
|
|
"\n" |
222 |
|
|
"not enough arguments for -i\n"); |
223 |
|
|
usage(); |
224 |
|
|
painCave.isFatal = 1; |
225 |
|
|
simError(); |
226 |
|
|
} |
227 |
|
|
|
228 |
|
|
maxLength = strtod( argV[i], &conversionCheck, 10 ); |
229 |
|
|
if( conversionCheck == argV[i] ) conversionError = true; |
230 |
|
|
if( *conversionCheck != '\0' ) conversionError = true; |
231 |
|
|
|
232 |
|
|
if( conversionError ){ |
233 |
|
|
sprintf( painCave.errMsg, |
234 |
|
|
"Error converting \"%s\" to a double for maxLength.\n", |
235 |
|
|
argV[i] ); |
236 |
|
|
usage(); |
237 |
|
|
painCave.isFatal = 1; |
238 |
|
|
simError(); |
239 |
|
|
} |
240 |
|
|
|
241 |
|
|
done = true; |
242 |
|
|
|
243 |
|
|
break; |
244 |
|
|
|
245 |
|
|
default: |
246 |
|
|
|
247 |
|
|
sprintf(painCave.errMsg, |
248 |
|
|
"\n" |
249 |
|
|
"Bad option \"-%c\"\n", currentFlag); |
250 |
|
|
usage(); |
251 |
|
|
painCave.isFatal = 1; |
252 |
|
|
simError(); |
253 |
|
|
} |
254 |
|
|
j++; |
255 |
|
|
currentFlag = argV[i][j]; |
256 |
|
|
} |
257 |
|
|
} |
258 |
|
|
} |
259 |
|
|
|
260 |
|
|
else{ |
261 |
|
|
|
262 |
|
|
if( inName != NULL ){ |
263 |
|
|
sprintf( painCave.errMsg, |
264 |
|
|
"Error at \"%s\", program does not currently support\n" |
265 |
|
|
"more than one input bass file.\n" |
266 |
|
|
"\n", |
267 |
|
|
argV[i]); |
268 |
|
|
usage(); |
269 |
|
|
painCave.isFatal = 1; |
270 |
|
|
simError(); |
271 |
|
|
} |
272 |
|
|
|
273 |
|
|
inName = argV[i]; |
274 |
|
|
|
275 |
|
|
} |
276 |
|
|
} |
277 |
|
|
|
278 |
|
|
if( inName == NULL ){ |
279 |
mmeineke |
672 |
sprintf( painCave.errMsg, |
280 |
|
|
"Error, bass file is needed to run.\n" ); |
281 |
mmeineke |
795 |
usage(); |
282 |
mmeineke |
672 |
painCave.isFatal = 1; |
283 |
|
|
simError(); |
284 |
|
|
} |
285 |
|
|
|
286 |
|
|
// make the dump name |
287 |
|
|
|
288 |
mmeineke |
795 |
strcpy( dumpName, inName ); |
289 |
mmeineke |
672 |
nameLength = strlen( dumpName ); |
290 |
|
|
endTest = &(dumpName[nameLength - 5]); |
291 |
|
|
if( !strcmp( endTest, ".bass" ) ){ |
292 |
|
|
strcpy( endTest, ".dump" ); |
293 |
|
|
} |
294 |
|
|
else if( !strcmp( endTest, ".BASS" ) ){ |
295 |
|
|
strcpy( endTest, ".dump" ); |
296 |
|
|
} |
297 |
|
|
else{ |
298 |
mmeineke |
795 |
strcat( dumpName, ".dump" ); |
299 |
mmeineke |
672 |
} |
300 |
|
|
|
301 |
|
|
// count the number of frames in the dump file. |
302 |
|
|
|
303 |
|
|
printf("Counting the number of frames in \"%s\"... ", dumpName ); |
304 |
|
|
fflush(stdout); |
305 |
|
|
|
306 |
|
|
reader = new DumpReader( dumpName ); |
307 |
|
|
nFrames = reader->getNframes(); |
308 |
|
|
|
309 |
|
|
printf("done.\n" |
310 |
|
|
"\tFound %d frames.\n" |
311 |
|
|
"\n", |
312 |
|
|
nFrames ); |
313 |
|
|
fflush(stdout); |
314 |
|
|
|
315 |
|
|
infoArray = new SimInfo[nFrames]; |
316 |
|
|
|
317 |
mmeineke |
735 |
printf("Parsing the bass file, and initializing the " |
318 |
mmeineke |
672 |
"Simulation Frames..." ); |
319 |
|
|
fflush(stdout); |
320 |
|
|
|
321 |
|
|
startMe = new SimSetup(); |
322 |
|
|
startMe->setSimInfo( infoArray, nFrames ); |
323 |
mmeineke |
795 |
startMe->parseFile( inName ); |
324 |
mmeineke |
672 |
startMe->createSim(); |
325 |
|
|
|
326 |
|
|
delete startMe; |
327 |
|
|
|
328 |
|
|
printf("done.\n"); |
329 |
|
|
fflush(stdout); |
330 |
|
|
|
331 |
mmeineke |
795 |
printf("Initializing the pair correlations..." ); |
332 |
|
|
fflush(stdout); |
333 |
|
|
|
334 |
|
|
theCorrs.setCorrList( theList ); |
335 |
|
|
theCorrs.setFrames( infoArray, nFrames, reader ); |
336 |
|
|
theCorrs.initCorrelations( outPrefix ); |
337 |
mmeineke |
672 |
|
338 |
mmeineke |
795 |
printf("done\n"); |
339 |
|
|
fflush(stdout); |
340 |
|
|
|
341 |
|
|
theCorrs.calcCorrelations(); |
342 |
|
|
|
343 |
mmeineke |
672 |
return 0 ; |
344 |
|
|
} |
345 |
|
|
|
346 |
mmeineke |
795 |
|
347 |
|
|
/*************************************************************************** |
348 |
|
|
* prints out the usage for the command line arguments, then exits. |
349 |
|
|
***************************************************************************/ |
350 |
|
|
|
351 |
|
|
void usage(){ |
352 |
|
|
(void)fprintf(stdout, |
353 |
|
|
"\n" |
354 |
|
|
"The proper usage is: %s [options] <input_file>\n" |
355 |
|
|
"\n" |
356 |
|
|
"Options:\n" |
357 |
|
|
"\n" |
358 |
|
|
" short:\n" |
359 |
|
|
" ------\n" |
360 |
|
|
" -o <name> The output prefix\n" |
361 |
|
|
" -l <maxLength> set the maximum value of r\n" |
362 |
|
|
" *Defaults to 1/2 smallest length of first frame.\n" |
363 |
|
|
" -s Turn on separate output files\n" |
364 |
|
|
" *Defaults to single output file.\n" |
365 |
|
|
"\n" |
366 |
|
|
" long:\n" |
367 |
|
|
" -----\n" |
368 |
|
|
" --gofr <atom1> <atom2> g(r) for atom1 and atom2\n" |
369 |
|
|
" *note: \"_ALL_\" matches all atoms/n" |
370 |
|
|
" --version displays the version number\n" |
371 |
|
|
" --help displays this help message.\n" |
372 |
|
|
|
373 |
|
|
"\n" |
374 |
|
|
"\n", |
375 |
|
|
programName); |
376 |
|
|
} |