ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/madProps/madProps.c
Revision: 43
Committed: Fri Jul 19 19:05:59 2002 UTC (22 years ago) by mmeineke
Content type: text/plain
File size: 8376 byte(s)
Log Message:

finished working on the command line options, and started working on the GofR

File Contents

# Content
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <math.h>
5
6
7 #include "madProps.h"
8 #include "frameCount.h"
9
10 char *program_name; /*the name of the program */
11
12 void usage(void);
13
14 int main(argc, argv)
15 int argc;
16 char *argv[];
17 {
18
19
20 struct xyz_frame *dumpArray;
21 int nFrames; // the nu8mvber of frames
22 int lineNum = 0; // keeps track of the line number
23 int n_atoms; // the number of atoms
24 int i,j; // loop counters
25
26 char read_buffer[2000]; /*the line buffer for reading */
27 char *foo; /*the pointer to the current string token */
28 FILE *in_file; /* the input file */
29 char *in_name = NULL; /*the name of the input file */
30 char *out_prefix; // the output prefix
31 char current_flag; // used in parseing the flags
32
33
34
35 int done = 0; // multipurpose boolean
36 int have_prefix = 0; // prefix boolean
37 int calcRMSD = 0;
38
39 int calcGofR = 0;
40 char gofR1[30];
41 char gofR2[30];
42
43 int calcMuCorr = 0;
44 char muCorr[30];
45
46 int calcCosCorr = 0;
47 char cosCorr1[30];
48 char cosCorr2[30];
49
50
51
52 program_name = argv[0]; /*save the program name in case we need it*/
53
54 for( i = 1; i < argc; i++){
55
56 if(argv[i][0] =='-'){
57
58 // parse the option
59
60 if(argv[i][1] == '-' ){
61
62 // parse long word options
63
64 if( !strcmp( argv[i], "--GofR" ) ){
65 calcGofR = 1;
66 i++;
67 strcpy( gofR1, argv[i] );
68 i++;
69 strcpy( gofR2, argv[i] );
70 }
71
72 else if( !strcmp( argv[i], "--MuCorr") ){
73 calcMuCorr = 1;
74 i++;
75 strcpy( muCorr, argv[i] );
76 }
77
78 else if( !strcmp( argv[i], "--CosCorr" ) ){
79 calcCosCorr = 1;
80 i++;
81 strcpy( cosCorr1, argv[i] );
82 i++;
83 strcpy( cosCorr2, argv[i] );
84 }
85
86 else{
87 fprintf( stderr,
88 "Invalid option \"%s\"\n", argv[i] );
89 usage();
90 }
91 }
92
93 else{
94
95 // parse single character options
96
97 done =0;
98 j = 1;
99 current_flag = argv[i][j];
100 while( (current_flag != '\0') && (!done) ){
101
102 switch(current_flag){
103
104 case 'o':
105 // -o <prefix> => the output prefix.
106
107 i++;
108 out_prefix = argv[i];
109 have_prefix = 1;
110 done = 1;
111 break;
112
113 case 'h':
114 // -h => give the usage
115
116 usage();
117 break;
118
119 case 'r':
120 // calculates the rmsd
121
122 calcRMSD = 1;
123 break;
124
125 case 'g':
126 // calculate all to all g(r)
127
128 calcGofR = 1;
129 strcpy( gofR1, "all" );
130 strcpy( gofR2, "all" );
131 break;
132
133 default:
134
135 fprintf( stderr, "about to print bad option\n" );
136
137 (void)fprintf(stderr, "Bad option \"-%s\"\n", current_flag);
138 usage();
139 }
140 j++;
141 current_flag = argv[i][j];
142 }
143 }
144 }
145
146 else{
147
148 if( in_name != NULL ){
149 fprintf( stderr,
150 "Error at \"%s\", program does not currently support\n"
151 "more than one input file.\n"
152 "\n",
153 argv[i]);
154 usage();
155 }
156
157 in_name = argv[i];
158 }
159 }
160
161 if(in_name == NULL){
162 usage();
163 }
164
165 if( !have_prefix ) out_prefix = in_name;
166
167 printf( "Counting number of frames..." );
168 fflush( stdout );
169
170 nFrames = frameCount( in_name );
171
172 printf( "done.\n"
173 "nframes = %d\n"
174 "\n",
175 nFrames );
176 fflush( stdout );
177
178 in_file = fopen(in_name, "r");
179 if(in_file == NULL){
180 printf("Cannot open file: %s\n", in_name);
181 exit(8);
182 }
183
184 // create the array of frames
185
186 dumpArray = (struct xyz_frame*)calloc( nFrames,
187 sizeof( struct xyz_frame ) );
188
189 // read the frames
190
191 printf( "Reading the frames into the coordinate arrays..." );
192 fflush( stdout );
193
194 for(j =0; j<nFrames; j++ ){
195
196 // read the number of atoms
197
198 fgets(read_buffer, sizeof(read_buffer), in_file);
199 lineNum++;
200
201 n_atoms = atoi( read_buffer );
202 dumpArray[j].nAtoms = n_atoms;
203
204 dumpArray[j].r =
205 (struct coords *)calloc(n_atoms, sizeof(struct coords));
206
207 if( calcMuCorr || calcCosCorr ){
208 dumpArray[j].v =
209 (struct vect *)calloc(n_atoms, sizeof(struct vect));
210 }
211
212 //read the time and the box sizes
213
214 fgets(read_buffer, sizeof(read_buffer), in_file);
215 lineNum++;
216
217 foo = strtok(read_buffer, " ,;\t");
218 if(foo == NULL){
219 printf("error in reading time at line %d\n", lineNum);
220 exit(8);
221 }
222
223 dumpArray[j].time = atof( foo );
224
225 foo = strtok(NULL, " ,;\t");
226 if(foo == NULL){
227 printf("error in reading boxX at line %d\n", lineNum);
228 exit(8);
229 }
230
231 dumpArray[j].boxX = atof( foo );
232
233 foo = strtok(NULL, " ,;\t");
234 if(foo == NULL){
235 printf("error in reading boxY at line %d\n", lineNum);
236 exit(8);
237 }
238
239 dumpArray[j].boxY = atof( foo );
240
241 foo = strtok(NULL, " ,;\t");
242 if(foo == NULL){
243 printf("error in reading boxZ at line %d\n", lineNum);
244 exit(8);
245 }
246
247 dumpArray[j].boxZ = atof( foo );
248
249
250 for( i=0; i < n_atoms; i++){
251
252 fgets(read_buffer, sizeof(read_buffer), in_file);
253 lineNum++;
254
255 // get the name and positions
256
257 foo = strtok(read_buffer, " ,;\t");
258 if(foo == NULL){
259 printf("error in reading atom name at line %d\n", lineNum );
260 exit(8);
261 }
262
263 strcpy(dumpArray[j].r[i].name, foo); /*copy the atom name */
264
265 foo = strtok(NULL, " ,;\t");
266 if(foo == NULL){
267 printf("error in reading position x at line %d\n", lineNum);
268 exit(8);
269 }
270
271 dumpArray[j].r[i].x = atof( foo );
272
273 foo = strtok(NULL, " ,;\t");
274 if(foo == NULL){
275 printf("error in reading position y at line %d\n", lineNum);
276 exit(8);
277 }
278
279 dumpArray[j].r[i].y = atof( foo );
280
281 foo = strtok(NULL, " ,;\t");
282 if(foo == NULL){
283 printf("error in reading position z at line %d\n", lineNum);
284 exit(8);
285 }
286
287 dumpArray[j].r[i].z = atof( foo );
288
289 if( calcCosCorr || calcMuCorr ){
290
291 foo = strtok(NULL, " ,;\t");
292 if(foo == NULL){
293
294 dumpArray[j].v[i].x = 0.0;
295 dumpArray[j].v[i].y = 0.0;
296 dumpArray[j].v[i].z = 0.0;
297 }
298 else{
299
300 dumpArray[j].v[i].x = atof( foo );
301
302 foo = strtok(NULL, " ,;\t");
303 if(foo == NULL){
304 printf("error in reading vector y at line %d\n", lineNum);
305 exit(8);
306 }
307
308 dumpArray[j].v[i].y = atof( foo );
309
310 foo = strtok(NULL, " ,;\t");
311 if(foo == NULL){
312 printf("error in reading vector z at line %d\n", lineNum);
313 exit(8);
314 }
315
316 dumpArray[j].v[i].z = atof( foo );
317 }
318 }
319
320 }
321 }
322
323 (void)fclose(in_file);
324
325 printf( "done\n"
326 "\n" );
327 fflush( stdout );
328
329
330
331 // do calculations here.
332
333 if( calcGofR ){
334
335 fprintf( stdout,
336 "Calculating the g(r) between atoms \"%s\" and \"%s\"...",
337 gofR1, gofR2 );
338 fflush( stdout );
339
340 // gofr call
341 GofR( out_prefix, gofR1, gofR2, dumpArray, nFrames );
342
343 fprintf( stdout,
344 " done.\n"
345 "\n");
346 fflush(stdout);
347 }
348
349 if( calcRMSD ){
350
351 fprintf( stdout,
352 "Calculating the RMSD..." );
353 fflush( stdout );
354
355 // RMSD call
356
357
358 fprintf( stdout,
359 " done.\n"
360 "\n");
361 fflush(stdout);
362 }
363
364 if( calcMuCorr ){
365
366 fprintf( stdout,
367 "Calculating the mu correlation for \"%s\"...",
368 muCorr);
369 fflush( stdout );
370
371 // muCorr call
372
373
374 fprintf( stdout,
375 " done.\n"
376 "\n");
377 fflush(stdout);
378 }
379
380 if( calcCosCorr ){
381
382 fprintf( stdout,
383 "Calculating the cos correlation between \"%s\" and \"%s\"...",
384 cosCorr1, cosCorr2 );
385 fflush( stdout );
386
387 // cosCorr call
388
389
390 fprintf( stdout,
391 " done.\n"
392 "\n");
393 fflush(stdout);
394 }
395
396
397 return 0;
398
399 }
400
401
402
403 /***************************************************************************
404 * prints out the usage for the command line arguments, then exits.
405 ***************************************************************************/
406
407 void usage(){
408 (void)fprintf(stdout,
409 "The proper usage is: %s [options] <xyz_file>\n"
410 "\n"
411 "Options:\n"
412 "\n"
413 " short:\n"
414 " ------\n"
415 " -h Display this message\n"
416 " -o <prefix> The output prefix\n"
417 " -r Calculate the RMSD\n"
418 " -g Calculate all to all g(r)\n"
419
420 "\n"
421 " long:\n"
422 " -----\n"
423 " --GofR <atom1> <atom2> Calculates g(r) between atom1 and atom 2\n"
424 " -note: \"all\" will do all atoms\n"
425 " --MuCorr <atom> Calculate mu correlation of atom\n"
426 " --CosCorr <atom1> <atom2> Calculate the cos correlation between atom1 and atom2\n"
427
428
429 "\n"
430 "\n",
431 program_name);
432 exit(8);
433 }