ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE/staticProps/staticProps.cpp
Revision: 1043
Committed: Mon Feb 9 20:38:38 2004 UTC (20 years, 5 months ago) by mmeineke
File size: 11080 byte(s)
Log Message:
 started a bug fix on the massive memory overusage by OOPSE

File Contents

# Content
1 #include <iostream>
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include <string.h>
5 #include <vector>
6
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 #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 using namespace std;
24
25 int main(int argC,char* argV[]){
26
27 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 bool separateOut;
43 bool havePairCorrs;
44 bool haveStaticCorrs;
45
46 int nBins;
47
48 vector<PairCorrList> theList;
49 pairCorrEnum pairType;
50
51 char* pair1;
52 char* pair2;
53
54 char dumpName[2000];
55 char* endTest;
56 int nameLength;
57 int nFrames;
58 char* inName;
59 SimSetup* startMe;
60 SimInfo* infoArray;
61 DumpReader* reader;
62 AllCorr theCorrs;
63
64 // first things first, all of the initializations
65
66 fflush(stdout);
67 srand48( 1337 ); // the random number generator.
68 initSimError(); // the error handler
69
70 outPrefix = NULL;
71 inName = NULL;
72
73 conversionError = false;
74 optionError = false;
75
76 havePrefix = false;
77 haveMaxLength = false;
78
79 haveStaticCorrs = false;
80 havePairCorrs = false;
81 separateOut = false;
82
83 maxLength = 1.0;
84 nBins = 100;
85
86 programName = argV[0]; /*save the program name in case we need it*/
87
88 for( i = 1; i < argC; i++){
89
90 if(argV[i][0] =='-'){
91
92 // parse the option
93
94 if(argV[i][1] == '-' ){
95
96 // parse long word options
97
98 if( !strcmp( argV[i], "--gofr" ) ){
99
100 i++;
101 if( i>=argC ){
102 sprintf( painCave.errMsg,
103 "\n"
104 "not enough arguments for --gofr\n");
105 usage();
106 painCave.isFatal = 1;
107 simError();
108 }
109 pair1 = argV[i];
110
111 i++;
112 if( i>=argC ){
113 sprintf( painCave.errMsg,
114 "\n"
115 "not enough arguments for --gofr\n");
116 usage();
117 painCave.isFatal = 1;
118 simError();
119 }
120 pair2 = argV[i];
121
122 pairType = gofr;
123 theList.push_back(PairCorrList( pairType, pair1, pair2 ));
124 havePairCorrs = true;
125 }
126
127 else if( !strcmp( argV[i], "--gofrTheta" ) ){
128
129 i++;
130 if( i>=argC ){
131 sprintf( painCave.errMsg,
132 "\n"
133 "not enough arguments for --gofrTheta\n");
134 usage();
135 painCave.isFatal = 1;
136 simError();
137 }
138 pair1 = argV[i];
139
140 i++;
141 if( i>=argC ){
142 sprintf( painCave.errMsg,
143 "\n"
144 "not enough arguments for --gofrTheta\n");
145 usage();
146 painCave.isFatal = 1;
147 simError();
148 }
149 pair2 = argV[i];
150
151 pairType = gofrTheta;
152 theList.push_back(PairCorrList( pairType, pair1, pair2 ));
153 havePairCorrs = true;
154 }
155
156 else if( !strcmp( argV[i], "--gofrOmega" ) ){
157
158 i++;
159 if( i>=argC ){
160 sprintf( painCave.errMsg,
161 "\n"
162 "not enough arguments for --gofrOmega\n");
163 usage();
164 painCave.isFatal = 1;
165 simError();
166 }
167 pair1 = argV[i];
168
169 i++;
170 if( i>=argC ){
171 sprintf( painCave.errMsg,
172 "\n"
173 "not enough arguments for --gofrOmega\n");
174 usage();
175 painCave.isFatal = 1;
176 simError();
177 }
178 pair2 = argV[i];
179
180 pairType = gofrOmega;
181 theList.push_back(PairCorrList( pairType, pair1, pair2 ));
182 havePairCorrs = true;
183 }
184
185 else if( !strcmp( argV[i], "--version") ){
186
187 printf("\n"
188 "staticProps version %d.%d\n"
189 "\n",
190 VERSION_MAJOR, VERSION_MINOR );
191 exit(0);
192
193 }
194
195 else if( !strcmp( argV[i], "--help") ){
196
197 usage();
198 exit(0);
199 }
200
201 // anything else is an error
202
203 else{
204 fprintf( stderr,
205 "Invalid option \"%s\"\n", argV[i] );
206 usage();
207 exit(0);
208 }
209 }
210
211 else{
212
213 // parse single character options
214
215 done =0;
216 j = 1;
217 currentFlag = argV[i][j];
218 while( (currentFlag != '\0') && (!done) ){
219
220 switch(currentFlag){
221
222 case 'o':
223 // -o <prefix> => the output prefix.
224
225 j++;
226 currentFlag = argV[i][j];
227
228 if( currentFlag != '\0' ) optionError = true;
229
230 if( optionError ){
231 sprintf( painCave.errMsg,
232 "\n"
233 "The -o flag should end an option sequence.\n"
234 " example: -r <outname> *NOT* -or <outname>\n" );
235 usage();
236 painCave.isFatal = 1;
237 simError();
238 }
239
240 i++;
241 if( i>=argC ){
242 sprintf( painCave.errMsg,
243 "\n"
244 "not enough arguments for -o\n");
245 usage();
246 painCave.isFatal = 1;
247 simError();
248 }
249
250 outPrefix = argV[i];
251 if( outPrefix[0] == '-' ) optionError = true;
252
253 if( optionError ){
254 sprintf( painCave.errMsg,
255 "\n"
256 "\"%s\" is not a valid out prefix/name.\n"
257 "Out prefix/name should not begin with a dash.\n",
258 outPrefix );
259 usage();
260 painCave.isFatal = 1;
261 simError();
262 }
263
264 havePrefix = true;
265 done = true;
266 break;
267
268 case 'l':
269 // -l <double> set <double> to the maxLength
270
271 haveMaxLength = true;
272 j++;
273 currentFlag = argV[i][j];
274
275 if( currentFlag != '\0' ) optionError = true;
276
277 if( optionError ){
278 sprintf( painCave.errMsg,
279 "\n"
280 "The -l flag should end an option sequence.\n"
281 " example: -sl <double> *NOT* -ls <double>\n" );
282 usage();
283 painCave.isFatal = 1;
284 simError();
285 }
286
287 i++;
288 if( i>=argC ){
289 sprintf( painCave.errMsg,
290 "\n"
291 "not enough arguments for -l\n");
292 usage();
293 painCave.isFatal = 1;
294 simError();
295 }
296
297 maxLength = strtod( argV[i], &conversionCheck);
298 if( conversionCheck == argV[i] ) conversionError = true;
299 if( *conversionCheck != '\0' ) conversionError = true;
300
301 if( conversionError ){
302 sprintf( painCave.errMsg,
303 "Error converting \"%s\" to a double for maxLength.\n",
304 argV[i] );
305 usage();
306 painCave.isFatal = 1;
307 simError();
308 }
309
310 done = true;
311
312 break;
313
314 case 's':
315 // -s turn on separate output files
316
317 separateOut = true;
318 break;
319
320 case 'n':
321 // -n <int> set <int> to the nBins
322
323 j++;
324 currentFlag = argV[i][j];
325
326 if( currentFlag != '\0' ) optionError = true;
327
328 if( optionError ){
329 sprintf( painCave.errMsg,
330 "\n"
331 "The -n flag should end an option sequence.\n"
332 " example: -sn <int> *NOT* -ns <int>\n" );
333 usage();
334 painCave.isFatal = 1;
335 simError();
336 }
337
338 i++;
339 if( i>=argC ){
340 sprintf( painCave.errMsg,
341 "\n"
342 "not enough arguments for -n\n");
343 usage();
344 painCave.isFatal = 1;
345 simError();
346 }
347
348 nBins = strtol( argV[i], &conversionCheck, 10 );
349 if( conversionCheck == argV[i] ) conversionError = true;
350 if( *conversionCheck != '\0' ) conversionError = true;
351
352 if( conversionError ){
353 sprintf( painCave.errMsg,
354 "Error converting \"%s\" to an int for nBins.\n",
355 argV[i] );
356 usage();
357 painCave.isFatal = 1;
358 simError();
359 }
360
361 if( nBins < 1 ){
362 sprintf( painCave.errMsg,
363 "nBins error: nBins = %d is less than 1.\n",
364 nBins );
365 usage();
366 painCave.isFatal = 1;
367 simError();
368 }
369
370 done = true;
371
372 break;
373
374 default:
375
376 sprintf(painCave.errMsg,
377 "\n"
378 "Bad option \"-%c\"\n", currentFlag);
379 usage();
380 painCave.isFatal = 1;
381 simError();
382 }
383 j++;
384 currentFlag = argV[i][j];
385 }
386 }
387 }
388
389 else{
390
391 if( inName != NULL ){
392 sprintf( painCave.errMsg,
393 "Error at \"%s\", program does not currently support\n"
394 "more than one input bass file.\n"
395 "\n",
396 argV[i]);
397 usage();
398 painCave.isFatal = 1;
399 simError();
400 }
401
402 inName = argV[i];
403
404 }
405 }
406
407 if( inName == NULL ){
408 sprintf( painCave.errMsg,
409 "Error, bass file is needed to run.\n" );
410 usage();
411 painCave.isFatal = 1;
412 simError();
413 }
414
415 // make the dump name
416
417 strcpy( dumpName, inName );
418 nameLength = strlen( dumpName );
419 endTest = &(dumpName[nameLength - 5]);
420 if( !strcmp( endTest, ".bass" ) ){
421 strcpy( endTest, ".dump" );
422 }
423 else if( !strcmp( endTest, ".BASS" ) ){
424 strcpy( endTest, ".dump" );
425 }
426 else{
427 strcat( dumpName, ".dump" );
428 }
429
430 // count the number of frames in the dump file.
431
432 printf("Counting the number of frames in \"%s\"... ", dumpName );
433 fflush(stdout);
434
435 reader = new DumpReader( dumpName );
436 nFrames = reader->getNframes();
437
438 printf("done.\n"
439 "\tFound %d frames.\n"
440 "\n",
441 nFrames );
442 fflush(stdout);
443
444 infoArray = new SimInfo;
445
446 printf("Parsing the bass file, and initializing the "
447 "Simulation Frames..." );
448 fflush(stdout);
449
450 startMe = new SimSetup();
451 startMe->setSimInfo( infoArray );
452 startMe->suspendInit();
453 startMe->parseFile( inName );
454 startMe->createSim();
455
456 delete startMe;
457
458 printf("done.\n");
459 fflush(stdout);
460
461 printf("Initializing the pair correlations..." );
462 fflush(stdout);
463
464 if(haveMaxLength)
465 theCorrs.setMaxLength( maxLength );
466
467 theCorrs.setNbins( nBins );
468 theCorrs.setFrames( infoArray, nFrames, reader );
469 theCorrs.setPairCorrList( theList );
470 theCorrs.initCorrelations( outPrefix, separateOut, havePairCorrs,
471 haveStaticCorrs );
472
473 printf("done\n");
474 fflush(stdout);
475
476 theCorrs.calcCorrelations();
477
478 return 0 ;
479 }
480
481
482 /***************************************************************************
483 * prints out the usage for the command line arguments, then exits.
484 ***************************************************************************/
485
486 void usage(){
487 (void)fprintf(stdout,
488 "\n"
489 "The proper usage is: %s [options] <input_file>\n"
490 "\n"
491 "Options:\n"
492 "\n"
493 " short:\n"
494 " ------\n"
495 " -o <name> The output prefix\n"
496 " -n <nBins> Set the number of bins in the Histogram.\n"
497 " *Defaults to 100\n"
498 " -l <maxLength> set the maximum value of r\n"
499 " *Defaults to 1/2 smallest length of first frame.\n"
500 " -s Turn on separate output files\n"
501 " *Defaults to single output file.\n"
502 "\n"
503 " long:\n"
504 " -----\n"
505 " --gofr <atom1> <atom2> g(r) for atom1 and atom2\n"
506 " *note: \"_ALL_\" matches all atoms\n"
507 " --gofrTheta <atom1> <atom2> g(r, theta) for atom1 and atom2\n"
508 " *note: \"_ALL_\" matches all atoms\n"
509 " --gofrOmega <atom1> <atom2> g(r, omega) for atom1 and atom2\n"
510 " *note: \"_ALL_\" matches all atoms\n"
511 " --version displays the version number\n"
512 " --help displays this help message.\n"
513
514 "\n"
515 "\n",
516 programName);
517 }