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 82 by mmeineke, Fri Aug 16 04:05:45 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 +  int startFrame = 0;
52 +  int haveStartFrame = 0;
53 +  int endFrame = 0;
54 +  int haveEndFrame = 0;
55 +
56    program_name = argv[0]; /*save the program name in case we need it*/
57    
58 <  for( i = 0; i < argc; i++){
58 >  for( i = 1; i < argc; i++){
59      
60      if(argv[i][0] =='-'){
61 +
62 +      // parse the option
63        
64 <      /* argv[i][1] is the actual option character */
64 >      if(argv[i][1] == '-' ){
65 >
66 >        // parse long word options
67 >        
68 >        if( !strcmp( argv[i], "--GofR" ) ){
69 >          calcGofR = 1;
70 >          i++;
71 >          strcpy( gofR1, argv[i] );
72 >          i++;
73 >          strcpy( gofR2, argv[i] );
74 >        }
75 >
76 >        else if( !strcmp( argv[i], "--MuCorr") ){
77 >          calcMuCorr = 1;
78 >          i++;
79 >          strcpy( muCorr, argv[i] );
80 >        }
81 >        
82 >        else if( !strcmp( argv[i], "--startFrame" ) ){
83 >          haveStartFrame = 1;
84 >          i++;
85 >          startFrame = atoi(argv[i]);
86 >        }
87 >
88 >        else if( !strcmp( argv[i], "--endFrame" ) ){
89 >          haveEndFrame = 1;
90 >          i++;
91 >          endFrame = atoi(argv[i]);
92 >        }
93 >
94 >        else{
95 >          fprintf( stderr,
96 >                   "Invalid option \"%s\"\n", argv[i] );
97 >          usage();
98 >        }
99 >      }
100        
101 <      switch(argv[i][1]){
101 >      else{
102          
103 <        /* -f <name> => the xyz input file
104 <         *     [i+1] actually starts the name
105 <         */
103 >        // parse single character options
104 >        
105 >        done =0;
106 >        j = 1;
107 >        current_flag = argv[i][j];
108 >        while( (current_flag != '\0') && (!done) ){
109 >          
110 >          switch(current_flag){
111  
112 <      case 'f':
113 <        in_name = argv[i+1];
61 <        break;
112 >          case 'o':
113 >            // -o <prefix> => the output prefix.
114  
115 <      default:
116 <        (void)fprintf(stderr, "Bad option %s\n", argv[i]);
115 >            i++;
116 >            out_prefix = argv[i];
117 >            have_prefix = 1;
118 >            done = 1;
119 >            break;
120 >
121 >          case 'h':
122 >            // -h => give the usage
123 >            
124 >            usage();
125 >            break;
126 >        
127 >          case 'r':
128 >            // calculates the rmsd
129 >
130 >            calcRMSD = 1;
131 >            break;
132 >
133 >          case 'g':
134 >            // calculate all to all g(r)
135 >
136 >            calcGofR = 1;
137 >            strcpy( gofR1, "all" );
138 >            strcpy( gofR2, "all" );
139 >            break;
140 >
141 >          default:
142 >
143 >            fprintf( stderr, "about to print bad option\n" );
144 >
145 >            (void)fprintf(stderr, "Bad option \"-%s\"\n", current_flag);
146 >            usage();
147 >          }
148 >          j++;
149 >          current_flag = argv[i][j];
150 >        }
151 >      }
152 >    }
153 >
154 >    else{
155 >      
156 >      if( in_name != NULL ){
157 >        fprintf( stderr,
158 >                 "Error at \"%s\", program does not currently support\n"
159 >                 "more than one input file.\n"
160 >                 "\n",
161 >                 argv[i]);
162          usage();
163        }
164 +
165 +      in_name = argv[i];
166      }
167    }
168  
169    if(in_name == NULL){
170      usage();
171    }
172 +
173 +  if( !have_prefix ) out_prefix = in_name;
174    
175    printf( "Counting number of frames..." );
176    fflush( stdout );
177    
178    nFrames = frameCount( in_name );
179 +  if( !haveEndFrame ) endFrame = nFrames;
180  
181    printf( "done.\n"
182            "nframes = %d\n"
# Line 88 | Line 190 | int main(argc, argv)
190      exit(8);
191    }
192  
193 <  // create the array of frames
193 >  // create and initialize the array of frames
194  
195    dumpArray = (struct xyz_frame*)calloc( nFrames,
196                                           sizeof( struct xyz_frame ) );
197 +  for( i=0; i<nFrames; i++ ){
198 +    dumpArray[i].nAtoms = 0;
199 +    dumpArray[i].time   = 0.0;
200 +    dumpArray[i].boxX   = 0.0;
201 +    dumpArray[i].boxY   = 0.0;
202 +    dumpArray[i].boxZ   = 0.0;
203 +    dumpArray[i].r      = NULL;
204 +    dumpArray[i].v      = NULL;
205 +    dumpArray[i].names  = NULL;
206 +  }
207  
208    // read the frames
209    
210    printf( "Reading the frames into the coordinate arrays..." );
211    fflush( stdout );
212  
213 +  isFirst = 1;
214    for(j =0; j<nFrames; j++ ){
215      
216      // read the number of atoms
# Line 110 | Line 223 | int main(argc, argv)
223  
224      dumpArray[j].r =
225        (struct coords *)calloc(n_atoms, sizeof(struct coords));
226 +    
227 +    if( isFirst ) {
228 +      dumpArray[0].names =
229 +        (atomID *)calloc( n_atoms, sizeof(atomID) );
230 +      isFirst = 0;
231 +    }
232  
233 +    if( calcMuCorr || calcCosCorr ){
234 +          dumpArray[j].v =
235 +            (struct vect *)calloc(n_atoms, sizeof(struct vect));
236 +    }
237 +
238      //read the time and the box sizes
239  
240      fgets(read_buffer, sizeof(read_buffer), in_file);
# Line 162 | Line 286 | int main(argc, argv)
286          exit(8);
287        }
288        
289 <      strcpy(dumpArray[j].r[i].name, foo); /*copy the atom name */
289 >      strcpy(dumpArray[0].names[i], foo); /*copy the atom name */
290  
291        foo = strtok(NULL, " ,;\t");
292        if(foo == NULL){
# Line 187 | Line 311 | int main(argc, argv)
311        }
312        
313        dumpArray[j].r[i].z = atof( foo );
314 <            
314 >
315 >      if( calcCosCorr || calcMuCorr ){
316 >        
317 >        foo = strtok(NULL, " ,;\t");
318 >        if(foo == NULL){
319 >                  
320 >          dumpArray[j].v[i].x = 0.0;
321 >          dumpArray[j].v[i].y = 0.0;
322 >          dumpArray[j].v[i].z = 0.0;
323 >        }
324 >        else{
325 >
326 >          dumpArray[j].v[i].x = atof( foo );
327 >          
328 >          foo = strtok(NULL, " ,;\t");
329 >          if(foo == NULL){
330 >            printf("error in reading vector y at line %d\n", lineNum);
331 >            exit(8);
332 >          }
333 >          
334 >          dumpArray[j].v[i].y = atof( foo );
335 >          
336 >          foo = strtok(NULL, " ,;\t");
337 >          if(foo == NULL){
338 >            printf("error in reading vector z at line %d\n", lineNum);
339 >            exit(8);
340 >          }
341 >          
342 >          dumpArray[j].v[i].z = atof( foo );
343 >        }
344 >      }
345 >      
346      }
347    }
348    
# Line 201 | Line 356 | int main(argc, argv)
356  
357    // do calculations here.
358  
359 +  if( calcGofR ){
360 +    
361 +    fprintf( stdout,
362 +             "Calculating the g(r) between atoms \"%s\" and \"%s\"...",
363 +             gofR1, gofR2 );
364 +    fflush( stdout );
365 +    
366 +    // gofr call
367 +    GofR( out_prefix, gofR1, gofR2, dumpArray, nFrames, startFrame, endFrame );
368 +    
369 +    fprintf( stdout,
370 +             " done.\n"
371 +             "\n");
372 +    fflush(stdout);
373 +  }
374  
375 <  
375 >  if( calcRMSD ){
376 >    
377 >    fprintf( stdout,
378 >             "Calculating the RMSD..." );
379 >    fflush( stdout );
380 >    
381 >    // RMSD call
382  
383 +    
384 +    fprintf( stdout,
385 +             " done.\n"
386 +             "\n");
387 +    fflush(stdout);
388 +  }
389  
390 +  if( calcMuCorr ){
391 +    
392 +    fprintf( stdout,
393 +             "Calculating the mu correlation for \"%s\"...",
394 +             muCorr);
395 +    fflush( stdout );
396 +    
397 +    // muCorr call
398  
399 +    
400 +    fprintf( stdout,
401 +             " done.\n"
402 +             "\n");
403 +    fflush(stdout);
404 +  }
405 +
406 +  if( calcCosCorr ){
407 +    
408 +    fprintf( stdout,
409 +             "Calculating the cos correlation between \"%s\" and \"%s\"...",
410 +             cosCorr1, cosCorr2 );
411 +    fflush( stdout );
412 +    
413 +    cosCorr( out_prefix, cosCorr1, cosCorr2, dumpArray, nFrames, startFrame,
414 +             endFrame );
415 +    
416 +    fprintf( stdout,
417 +             " done.\n"
418 +             "\n");
419 +    fflush(stdout);
420 +  }
421    
422    return 0;
423    
424   }
425  
426  
427 + void map( double *x, double *y, double *z,
428 +          double boxX, double boxY, double boxZ ){
429 +  
430 +  *x -= boxX * copysign(1.0,*x) * floor( fabs( *x/boxX ) + 0.5  );
431 +  *y -= boxY * copysign(1.0,*y) * floor( fabs( *y/boxY ) + 0.5  );
432 +  *z -= boxZ * copysign(1.0,*z) * floor( fabs( *z/boxZ ) + 0.5  );
433  
434 + }
435 +
436 +
437   /***************************************************************************
438   * prints out the usage for the command line arguments, then exits.
439   ***************************************************************************/
440  
441   void usage(){
442 <  (void)fprintf(stderr,
443 <                "The proper usage is: %s [options] -f <xyz_file>\n\n"
444 <                "Options:\n",
442 >  (void)fprintf(stdout,
443 >                "The proper usage is: %s [options] <xyz_file>\n"
444 >                "\n"
445 >                "Options:\n"
446 >                "\n"
447 >                "   short:\n"
448 >                "   ------\n"
449 >                "   -h              Display this message\n"
450 >                "   -o <prefix>     The output prefix\n"
451 >                "   -r              Calculate the RMSD\n"
452 >                "   -g              Calculate all to all g(r)\n"
453 >                
454 >                "\n"
455 >                "   long:\n"
456 >                "   -----\n"
457 >                "   --GofR <atom1> <atom2>    Calculates g(r) between atom1 and atom 2\n"
458 >                "                               -note: \"all\" will do all atoms\n"
459 >                "   --MuCorr <atom>           Calculate mu correlation of atom\n"
460 >                "   --CosCorr <atom1> <atom2> Calculate the cos correlation between atom1 and atom2\n"
461 >                "  --startFrame <frame#>      Specifies a frame to start correlating\n"
462 >                "  --endFrame <frame#>        Specifies a frame to stop correlating.\n"
463 >                
464 >                "\n"
465 >                "\n",
466                  program_name);
467    exit(8);
468   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines