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 46 by mmeineke, Tue Jul 23 20:10:49 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 +    }
227 +
228      //read the time and the box sizes
229  
230      fgets(read_buffer, sizeof(read_buffer), in_file);
# Line 162 | Line 276 | int main(argc, argv)
276          exit(8);
277        }
278        
279 <      strcpy(dumpArray[j].r[i].name, foo); /*copy the atom name */
279 >      strcpy(dumpArray[0].names[i], foo); /*copy the atom name */
280  
281        foo = strtok(NULL, " ,;\t");
282        if(foo == NULL){
# Line 187 | Line 301 | int main(argc, argv)
301        }
302        
303        dumpArray[j].r[i].z = atof( foo );
304 <            
304 >
305 >      if( calcCosCorr || calcMuCorr ){
306 >        
307 >        foo = strtok(NULL, " ,;\t");
308 >        if(foo == NULL){
309 >                  
310 >          dumpArray[j].v[i].x = 0.0;
311 >          dumpArray[j].v[i].y = 0.0;
312 >          dumpArray[j].v[i].z = 0.0;
313 >        }
314 >        else{
315 >
316 >          dumpArray[j].v[i].x = atof( foo );
317 >          
318 >          foo = strtok(NULL, " ,;\t");
319 >          if(foo == NULL){
320 >            printf("error in reading vector y at line %d\n", lineNum);
321 >            exit(8);
322 >          }
323 >          
324 >          dumpArray[j].v[i].y = atof( foo );
325 >          
326 >          foo = strtok(NULL, " ,;\t");
327 >          if(foo == NULL){
328 >            printf("error in reading vector z at line %d\n", lineNum);
329 >            exit(8);
330 >          }
331 >          
332 >          dumpArray[j].v[i].z = atof( foo );
333 >        }
334 >      }
335 >      
336      }
337    }
338    
# Line 201 | Line 346 | int main(argc, argv)
346  
347    // do calculations here.
348  
349 +  if( calcGofR ){
350 +    
351 +    fprintf( stdout,
352 +             "Calculating the g(r) between atoms \"%s\" and \"%s\"...",
353 +             gofR1, gofR2 );
354 +    fflush( stdout );
355 +    
356 +    // gofr call
357 +    GofR( out_prefix, gofR1, gofR2, dumpArray, nFrames );
358 +    
359 +    fprintf( stdout,
360 +             " done.\n"
361 +             "\n");
362 +    fflush(stdout);
363 +  }
364  
365 <  
365 >  if( calcRMSD ){
366 >    
367 >    fprintf( stdout,
368 >             "Calculating the RMSD..." );
369 >    fflush( stdout );
370 >    
371 >    // RMSD call
372  
373 +    
374 +    fprintf( stdout,
375 +             " done.\n"
376 +             "\n");
377 +    fflush(stdout);
378 +  }
379  
380 +  if( calcMuCorr ){
381 +    
382 +    fprintf( stdout,
383 +             "Calculating the mu correlation for \"%s\"...",
384 +             muCorr);
385 +    fflush( stdout );
386 +    
387 +    // muCorr call
388  
389 +    
390 +    fprintf( stdout,
391 +             " done.\n"
392 +             "\n");
393 +    fflush(stdout);
394 +  }
395 +
396 +  if( calcCosCorr ){
397 +    
398 +    fprintf( stdout,
399 +             "Calculating the cos correlation between \"%s\" and \"%s\"...",
400 +             cosCorr1, cosCorr2 );
401 +    fflush( stdout );
402 +    
403 +    cosCorr( out_prefix, cosCorr1, cosCorr2, dumpArray, nFrames );
404 +    
405 +    fprintf( stdout,
406 +             " done.\n"
407 +             "\n");
408 +    fflush(stdout);
409 +  }
410    
411    return 0;
412    
413   }
414  
415  
416 + void map( double *x, double *y, double *z,
417 +          double boxX, double boxY, double boxZ ){
418 +  
419 +  *x -= boxX * copysign(1.0,*x) * floor( fabs( *x/boxX ) + 0.5  );
420 +  *y -= boxY * copysign(1.0,*y) * floor( fabs( *y/boxY ) + 0.5  );
421 +  *z -= boxZ * copysign(1.0,*z) * floor( fabs( *z/boxZ ) + 0.5  );
422  
423 + }
424 +
425 +
426   /***************************************************************************
427   * prints out the usage for the command line arguments, then exits.
428   ***************************************************************************/
429  
430   void usage(){
431 <  (void)fprintf(stderr,
432 <                "The proper usage is: %s [options] -f <xyz_file>\n\n"
433 <                "Options:\n",
431 >  (void)fprintf(stdout,
432 >                "The proper usage is: %s [options] <xyz_file>\n"
433 >                "\n"
434 >                "Options:\n"
435 >                "\n"
436 >                "   short:\n"
437 >                "   ------\n"
438 >                "   -h              Display this message\n"
439 >                "   -o <prefix>     The output prefix\n"
440 >                "   -r              Calculate the RMSD\n"
441 >                "   -g              Calculate all to all g(r)\n"
442 >                
443 >                "\n"
444 >                "   long:\n"
445 >                "   -----\n"
446 >                "   --GofR <atom1> <atom2>    Calculates g(r) between atom1 and atom 2\n"
447 >                "                               -note: \"all\" will do all atoms\n"
448 >                "   --MuCorr <atom>           Calculate mu correlation of atom\n"
449 >                "   --CosCorr <atom1> <atom2> Calculate the cos correlation between atom1 and atom2\n"
450 >                
451 >                
452 >                "\n"
453 >                "\n",
454                  program_name);
455    exit(8);
456   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines