ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/madProps/madProps.c
(Generate patch)

Comparing:
branches/mmeineke/madProps/madProps.c (file contents), Revision 38 by mmeineke, Fri Jul 19 01:37:38 2002 UTC vs.
trunk/madProps/madProps.c (file contents), Revision 45 by mmeineke, Tue Jul 23 16:08:35 2002 UTC

# Line 3 | Line 3
3   #include <string.h>
4   #include <math.h>
5  
6 +
7 + #include "madProps.h"
8   #include "frameCount.h"
9  
8 struct coords{
9  double x;
10  double y;
11  double z;
12  char name[30];
13 };
14
15
16 struct xyz_frame{
17  int nAtoms;
18  double time;
19  double boxX, boxY, boxZ;
20  struct coords *r;
21 };
22
10   char *program_name; /*the name of the program */
11  
12   void usage(void);
# Line 35 | Line 22 | int main(argc, argv)
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 +  int isFirst;
26  
27    char read_buffer[2000]; /*the line buffer for reading */
28    char *foo; /*the pointer to the current string token */
29    FILE *in_file; /* the input file */
30    char *in_name = NULL; /*the name of the input file */
31 +  char *out_prefix; // the output prefix
32 +  char current_flag; // used in parseing the flags
33  
34  
35 +
36 +  int done = 0; // multipurpose boolean
37 +  int have_prefix = 0; // prefix boolean
38 +  int calcRMSD = 0;
39 +
40 +  int calcGofR = 0;
41 +  char gofR1[30];
42 +  char gofR2[30];
43 +
44 +  int calcMuCorr = 0;
45 +  char muCorr[30];
46 +
47 +  int calcCosCorr = 0;
48 +  char cosCorr1[30];
49 +  char cosCorr2[30];
50 +
51    program_name = argv[0]; /*save the program name in case we need it*/
52    
53 <  for( i = 0; i < argc; i++){
53 >  for( i = 1; i < argc; i++){
54      
55      if(argv[i][0] =='-'){
56 +
57 +      // parse the option
58        
59 <      /* argv[i][1] is the actual option character */
59 >      if(argv[i][1] == '-' ){
60 >
61 >        // parse long word options
62 >        
63 >        if( !strcmp( argv[i], "--GofR" ) ){
64 >          calcGofR = 1;
65 >          i++;
66 >          strcpy( gofR1, argv[i] );
67 >          i++;
68 >          strcpy( gofR2, argv[i] );
69 >        }
70 >
71 >        else if( !strcmp( argv[i], "--MuCorr") ){
72 >          calcMuCorr = 1;
73 >          i++;
74 >          strcpy( muCorr, argv[i] );
75 >        }
76 >        
77 >        else if( !strcmp( argv[i], "--CosCorr" ) ){
78 >          calcCosCorr = 1;
79 >          i++;
80 >          strcpy( cosCorr1, argv[i] );
81 >          i++;
82 >          strcpy( cosCorr2, argv[i] );
83 >        }
84 >
85 >        else{
86 >          fprintf( stderr,
87 >                   "Invalid option \"%s\"\n", argv[i] );
88 >          usage();
89 >        }
90 >      }
91        
92 <      switch(argv[i][1]){
92 >      else{
93          
94 <        /* -f <name> => the xyz input file
95 <         *     [i+1] actually starts the name
96 <         */
94 >        // parse single character options
95 >        
96 >        done =0;
97 >        j = 1;
98 >        current_flag = argv[i][j];
99 >        while( (current_flag != '\0') && (!done) ){
100 >          
101 >          switch(current_flag){
102  
103 <      case 'f':
104 <        in_name = argv[i+1];
61 <        break;
103 >          case 'o':
104 >            // -o <prefix> => the output prefix.
105  
106 <      default:
107 <        (void)fprintf(stderr, "Bad option %s\n", argv[i]);
106 >            i++;
107 >            out_prefix = argv[i];
108 >            have_prefix = 1;
109 >            done = 1;
110 >            break;
111 >
112 >          case 'h':
113 >            // -h => give the usage
114 >            
115 >            usage();
116 >            break;
117 >        
118 >          case 'r':
119 >            // calculates the rmsd
120 >
121 >            calcRMSD = 1;
122 >            break;
123 >
124 >          case 'g':
125 >            // calculate all to all g(r)
126 >
127 >            calcGofR = 1;
128 >            strcpy( gofR1, "all" );
129 >            strcpy( gofR2, "all" );
130 >            break;
131 >
132 >          default:
133 >
134 >            fprintf( stderr, "about to print bad option\n" );
135 >
136 >            (void)fprintf(stderr, "Bad option \"-%s\"\n", current_flag);
137 >            usage();
138 >          }
139 >          j++;
140 >          current_flag = argv[i][j];
141 >        }
142 >      }
143 >    }
144 >
145 >    else{
146 >      
147 >      if( in_name != NULL ){
148 >        fprintf( stderr,
149 >                 "Error at \"%s\", program does not currently support\n"
150 >                 "more than one input file.\n"
151 >                 "\n",
152 >                 argv[i]);
153          usage();
154        }
155 +
156 +      in_name = argv[i];
157      }
158    }
159  
160    if(in_name == NULL){
161      usage();
162    }
163 +
164 +  if( !have_prefix ) out_prefix = in_name;
165    
166    printf( "Counting number of frames..." );
167    fflush( stdout );
# Line 88 | Line 180 | int main(argc, argv)
180      exit(8);
181    }
182  
183 <  // create the array of frames
183 >  // create and initialize the array of frames
184  
185    dumpArray = (struct xyz_frame*)calloc( nFrames,
186                                           sizeof( struct xyz_frame ) );
187 +  for( i=0; i<nFrames; i++ ){
188 +    dumpArray[i].nAtoms = 0;
189 +    dumpArray[i].time   = 0.0;
190 +    dumpArray[i].boxX   = 0.0;
191 +    dumpArray[i].boxY   = 0.0;
192 +    dumpArray[i].boxZ   = 0.0;
193 +    dumpArray[i].r      = NULL;
194 +    dumpArray[i].v      = NULL;
195 +    dumpArray[i].names  = NULL;
196 +  }
197  
198    // read the frames
199    
200    printf( "Reading the frames into the coordinate arrays..." );
201    fflush( stdout );
202  
203 +  isFirst = 1;
204    for(j =0; j<nFrames; j++ ){
205      
206      // read the number of atoms
# Line 110 | Line 213 | int main(argc, argv)
213  
214      dumpArray[j].r =
215        (struct coords *)calloc(n_atoms, sizeof(struct coords));
216 +    
217 +    if( isFirst ) {
218 +      dumpArray[0].names =
219 +        (atomID *)calloc( n_atoms, sizeof(atomID) );
220 +      isFirst = 0;
221 +    }
222  
223 +    if( calcMuCorr || calcCosCorr ){
224 +          dumpArray[j].v =
225 +            (struct vect *)calloc(n_atoms, sizeof(struct vect));
226 +          printf( " (Note: reading in vectors)... " );
227 +          fflush( stdout );
228 +    }
229 +
230      //read the time and the box sizes
231  
232      fgets(read_buffer, sizeof(read_buffer), in_file);
# Line 162 | Line 278 | int main(argc, argv)
278          exit(8);
279        }
280        
281 <      strcpy(dumpArray[j].r[i].name, foo); /*copy the atom name */
281 >      strcpy(dumpArray[0].names[i], foo); /*copy the atom name */
282  
283        foo = strtok(NULL, " ,;\t");
284        if(foo == NULL){
# Line 187 | Line 303 | int main(argc, argv)
303        }
304        
305        dumpArray[j].r[i].z = atof( foo );
306 <            
306 >
307 >      if( calcCosCorr || calcMuCorr ){
308 >        
309 >        foo = strtok(NULL, " ,;\t");
310 >        if(foo == NULL){
311 >                  
312 >          dumpArray[j].v[i].x = 0.0;
313 >          dumpArray[j].v[i].y = 0.0;
314 >          dumpArray[j].v[i].z = 0.0;
315 >        }
316 >        else{
317 >
318 >          dumpArray[j].v[i].x = atof( foo );
319 >          
320 >          foo = strtok(NULL, " ,;\t");
321 >          if(foo == NULL){
322 >            printf("error in reading vector y at line %d\n", lineNum);
323 >            exit(8);
324 >          }
325 >          
326 >          dumpArray[j].v[i].y = atof( foo );
327 >          
328 >          foo = strtok(NULL, " ,;\t");
329 >          if(foo == NULL){
330 >            printf("error in reading vector z at line %d\n", lineNum);
331 >            exit(8);
332 >          }
333 >          
334 >          dumpArray[j].v[i].z = atof( foo );
335 >        }
336 >      }
337 >      
338      }
339    }
340    
# Line 201 | Line 348 | int main(argc, argv)
348  
349    // do calculations here.
350  
351 +  if( calcGofR ){
352 +    
353 +    fprintf( stdout,
354 +             "Calculating the g(r) between atoms \"%s\" and \"%s\"...",
355 +             gofR1, gofR2 );
356 +    fflush( stdout );
357 +    
358 +    // gofr call
359 +    GofR( out_prefix, gofR1, gofR2, dumpArray, nFrames );
360 +    
361 +    fprintf( stdout,
362 +             " done.\n"
363 +             "\n");
364 +    fflush(stdout);
365 +  }
366  
367 <  
367 >  if( calcRMSD ){
368 >    
369 >    fprintf( stdout,
370 >             "Calculating the RMSD..." );
371 >    fflush( stdout );
372 >    
373 >    // RMSD call
374  
375 +    
376 +    fprintf( stdout,
377 +             " done.\n"
378 +             "\n");
379 +    fflush(stdout);
380 +  }
381  
382 +  if( calcMuCorr ){
383 +    
384 +    fprintf( stdout,
385 +             "Calculating the mu correlation for \"%s\"...",
386 +             muCorr);
387 +    fflush( stdout );
388 +    
389 +    // muCorr call
390  
391 +    
392 +    fprintf( stdout,
393 +             " done.\n"
394 +             "\n");
395 +    fflush(stdout);
396 +  }
397 +
398 +  if( calcCosCorr ){
399 +    
400 +    fprintf( stdout,
401 +             "Calculating the cos correlation between \"%s\" and \"%s\"...",
402 +             cosCorr1, cosCorr2 );
403 +    fflush( stdout );
404 +    
405 +    // cosCorr call
406 +
407 +    
408 +    fprintf( stdout,
409 +             " done.\n"
410 +             "\n");
411 +    fflush(stdout);
412 +  }
413    
414    return 0;
415    
# Line 218 | Line 422 | void usage(){
422   ***************************************************************************/
423  
424   void usage(){
425 <  (void)fprintf(stderr,
426 <                "The proper usage is: %s [options] -f <xyz_file>\n\n"
427 <                "Options:\n",
425 >  (void)fprintf(stdout,
426 >                "The proper usage is: %s [options] <xyz_file>\n"
427 >                "\n"
428 >                "Options:\n"
429 >                "\n"
430 >                "   short:\n"
431 >                "   ------\n"
432 >                "   -h              Display this message\n"
433 >                "   -o <prefix>     The output prefix\n"
434 >                "   -r              Calculate the RMSD\n"
435 >                "   -g              Calculate all to all g(r)\n"
436 >                
437 >                "\n"
438 >                "   long:\n"
439 >                "   -----\n"
440 >                "   --GofR <atom1> <atom2>    Calculates g(r) between atom1 and atom 2\n"
441 >                "                               -note: \"all\" will do all atoms\n"
442 >                "   --MuCorr <atom>           Calculate mu correlation of atom\n"
443 >                "   --CosCorr <atom1> <atom2> Calculate the cos correlation between atom1 and atom2\n"
444 >                
445 >                
446 >                "\n"
447 >                "\n",
448                  program_name);
449    exit(8);
450   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines