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

Comparing trunk/tcProps/tcProps.c (file contents):
Revision 1052 by mmeineke, Fri Feb 13 22:13:06 2004 UTC vs.
Revision 1060 by mmeineke, Thu Feb 19 21:10:06 2004 UTC

# Line 2 | Line 2
2  
3   #include <stdio.h>
4   #include <stdlib.h>
5 + #include <string.h>
6  
7  
8   #include "params.h"
9   #include "tcProps.h"
10   #include "readWrite.h"
11 + #include "scdCorr.h"
12 + #include "directorHead.h"
13  
14  
15 + #define VERSION_MAJOR 0
16 + #define VERSION_MINOR 1
17 +
18 + char *programName; /*the name of the program */
19 + void usage(void);
20 +
21   int main( int argC, char *argV[] ){
22  
23    // list of 'a priori' constants
24  
25 <  const int nLipAtoms = 19;
26 <  const int nBonds = 18;
27 <  const int nLipids = NLIPIDS;
28 <  const int nSSD = NSSD;
29 <  const int nAtoms = nLipAtoms * nLipids + nSSD;
25 >  const int nLipAtoms = NL_ATOMS;
26 >  const int nBonds    = NBONDS;
27 >  const int nLipids   = NLIPIDS;
28 >  const int nSSD      = NSSD;
29 >  const int nAtoms    = nLipAtoms * nLipids + nSSD;
30  
31    // different needed variables
32    
33    struct atomCoord atoms[nAtoms];
34    int i,j,k;
35 <  char* inName;
36 <  int nFrames;
35 >  
36 >  char* outPrefix; // the output prefix
37 >  char currentFlag; // used in parsing the flags
38 >  int done = 0; // multipurpose boolean
39 >  int havePrefix; // boolean for the output prefix  
40 >  int haveMaxLength;
41 >  char* conversionCheck;
42 >  int conversionError;
43 >  int optionError;
44 >  char* pair1;
45 >  char* pair2;
46 >  int scdCorr;
47 >  double startTime;
48 >  double maxLength;
49 >  int directorHead;
50  
51    // system initialization
52    
53    isScanned = 0;
54 +  fileOpen = 0;
55 +  nFrames = 0;
56 +  frameTimes = NULL;
57  
58 +  outPrefix = NULL;
59 +  inName = NULL;
60 +  
61 +  haveMaxLength = 0;
62 +  conversionError = 0;
63 +  optionError = 0;
64 +  havePrefix = 0;
65 +  scdCorr = 0;
66 +  startTime = 0.0;
67 +  directorHead = 0;
68 +  
69  
70 +  // parse the command line
71 +
72 +  programName = argV[0]; /*save the program name in case we need it*/
73 +
74 +  for( i = 1; i < argC; i++){
75 +    
76 +    if(argV[i][0] =='-'){
77 +
78 +      // parse the option
79 +      
80 +      if(argV[i][1] == '-' ){
81 +
82 +        // parse long word options
83 +        
84 +        if( !strcmp( argV[i], "--gofr" ) ){
85 +
86 +          i++;
87 +          if( i>=argC ){
88 +            fprintf( stderr,
89 +                     "\n"
90 +                     "not enough arguments for --gofr\n");
91 +            usage();
92 +            exit(0);
93 +          }      
94 +          pair1 = argV[i];
95 +
96 +          i++;
97 +          if( i>=argC ){
98 +            fprintf( stderr,
99 +                     "\n"
100 +                     "not enough arguments for --gofr\n");
101 +            usage();
102 +            exit(0);
103 +          }      
104 +          pair2 = argV[i];
105 +
106 +        }
107 +
108 +        else if( !strcmp( argV[i], "--gofrTheta" ) ){
109 +          
110 +          i++;
111 +          if( i>=argC ){
112 +            fprintf( stderr,
113 +                     "\n"
114 +                     "not enough arguments for --gofrTheta\n");
115 +            usage();
116 +            exit(0);
117 +          }      
118 +          pair1 = argV[i];
119 +
120 +          i++;
121 +          if( i>=argC ){
122 +            fprintf( stderr,
123 +                     "\n"
124 +                     "not enough arguments for --gofrTheta\n");
125 +            usage();
126 +            exit(0);
127 +          }      
128 +          pair2 = argV[i];
129 +
130 +        }
131 +
132 +        else if( !strcmp( argV[i], "--gofrOmega" ) ){
133 +          
134 +          i++;
135 +          if( i>=argC ){
136 +            fprintf( stderr,
137 +                     "\n"
138 +                     "not enough arguments for --gofrOmega\n");
139 +            usage();
140 +            exit(0);
141 +          }      
142 +          pair1 = argV[i];
143 +
144 +          i++;
145 +          if( i>=argC ){
146 +            fprintf( stderr,
147 +                     "\n"
148 +                     "not enough arguments for --gofrOmega\n");
149 +            usage();
150 +            exit(0);
151 +          }      
152 +          pair2 = argV[i];
153 +
154 +        }
155 +
156 +        else if( !strcmp( argV[i], "--version") ){
157 +          
158 +          printf("\n"
159 +                 "tcProps version %d.%d\n"
160 +                 "\n",
161 +                 VERSION_MAJOR, VERSION_MINOR );
162 +          exit(0);
163 +          
164 +        }
165 +
166 +        else if( !strcmp( argV[i], "--help") ){
167 +          
168 +          usage();
169 +          exit(0);
170 +        }
171 +        
172 +        // anything else is an error
173 +
174 +        else{
175 +          fprintf( stderr,
176 +                   "Invalid option \"%s\"\n", argV[i] );
177 +          usage();
178 +          exit(0);
179 +        }
180 +      }
181 +      
182 +      else{
183 +        
184 +        // parse single character options
185 +        
186 +        done =0;
187 +        j = 1;
188 +        currentFlag = argV[i][j];
189 +        while( (currentFlag != '\0') && (!done) ){
190 +          
191 +          switch(currentFlag){
192 +
193 +          case 'o':
194 +            // -o <prefix> => the output prefix.
195 +
196 +            j++;
197 +            currentFlag = argV[i][j];
198 +              
199 +            if( currentFlag != '\0' ) optionError = 1;
200 +            
201 +            if( optionError ){
202 +              fprintf( stderr,
203 +                       "\n"
204 +                       "The -o flag should end an option sequence.\n"
205 +                       "   example: -r <outname> *NOT* -or <outname>\n" );
206 +              usage();
207 +              exit(0);
208 +            }
209 +              
210 +            i++;
211 +            if( i>=argC ){
212 +              fprintf( stderr,
213 +                       "\n"
214 +                       "not enough arguments for -o\n");
215 +              usage();
216 +              exit(0);
217 +            }    
218 +            
219 +            outPrefix = argV[i];
220 +            if( outPrefix[0] == '-' ) optionError = 1;
221 +                
222 +            if( optionError ){
223 +              fprintf( stderr,
224 +                       "\n"
225 +                       "\"%s\" is not a valid out prefix/name.\n"
226 +                       "Out prefix/name should not begin with a dash.\n",
227 +                       outPrefix );
228 +              usage();
229 +              exit(0);
230 +            }
231 +            
232 +            havePrefix = 1;
233 +            done = 1;
234 +            break;
235 +
236 +          case 'l':
237 +            // -l <double>    set <double> to the maxLength
238 +
239 +            haveMaxLength = 1;
240 +            j++;
241 +            currentFlag = argV[i][j];
242 +              
243 +            if( currentFlag != '\0' ) optionError = 1;
244 +            
245 +            if( optionError ){
246 +              fprintf( stderr,
247 +                       "\n"
248 +                       "The -l flag should end an option sequence.\n"
249 +                       "   example: -sl <double> *NOT* -ls <double>\n" );
250 +              usage();
251 +              exit(0);
252 +            }
253 +
254 +            i++;
255 +            if( i>=argC ){
256 +              fprintf( stderr,
257 +                       "\n"
258 +                       "not enough arguments for -l\n");
259 +              usage();
260 +              exit(0);
261 +            }    
262 +
263 +            maxLength = atof( argV[i] );
264 +            
265 +            done = 1;
266 +
267 +            break;
268 +
269 +          case 't':
270 +            // -t <double>    set <double> to the startTime
271 +
272 +            j++;
273 +            currentFlag = argV[i][j];
274 +              
275 +            if( currentFlag != '\0' ) optionError = 1;
276 +            
277 +            if( optionError ){
278 +              fprintf( stderr,
279 +                       "\n"
280 +                       "The -t flag should end an option sequence.\n"
281 +                       "   example: -st <double> *NOT* -ts <double>\n" );
282 +              usage();
283 +              exit(0);
284 +            }
285 +
286 +            i++;
287 +            if( i>=argC ){
288 +              fprintf( stderr,
289 +                       "\n"
290 +                       "not enough arguments for -t\n");
291 +              usage();
292 +              exit(0);
293 +            }    
294 +
295 +            startTime = atof( argV[i] );
296 +            done = 1;
297 +            break;
298 +
299 +          case 's':
300 +            // -s turn on Scd corr
301 +
302 +            scdCorr = 1;
303 +            break;
304 +
305 +          case 'h':
306 +            // -h turn on director head
307 +
308 +            directorHead = 1;
309 +            break;
310 +
311 +
312 +          default:
313 +
314 +            fprintf( stderr,
315 +                    "\n"
316 +                    "Bad option \"-%c\"\n", currentFlag);
317 +            usage();
318 +            exit(0);
319 +          }
320 +          j++;
321 +          currentFlag = argV[i][j];
322 +        }
323 +      }
324 +    }
325 +
326 +    else{
327 +      
328 +      if( inName != NULL ){
329 +        fprintf( stderr,
330 +                 "Error at \"%s\", program does not currently support\n"
331 +                 "more than one input dump file.\n"
332 +                 "\n",
333 +                 argV[i]);
334 +        usage();
335 +        exit(0);
336 +      }
337 +      
338 +      inName = argV[i];
339 +      
340 +    }
341 +  }  
342 +  
343 +  if( inName == NULL ){
344 +    fprintf( stderr,
345 +             "Error, dump file is needed to run.\n" );
346 +    usage();
347 +    exit(0);
348 +  }
349 +
350 +  if( outPrefix == NULL )
351 +    outPrefix = inName;
352 +
353 +
354    // initialize the arrays
355  
356    for(i=0;i<nLipids;i++){
# Line 87 | Line 407 | int main( int argC, char *argV[] ){
407  
408    // read and set the frames
409    
410 <  nFrames = setFrames( inName );
410 >  openFile();
411 >
412 >  fprintf( stdout,
413 >           "\n"
414 >           "Counting the number of frames in \"%s\"...",
415 >           inName );
416 >  fflush(stdout);
417 >
418 >  setFrames();
419    
420 +  fprintf( stdout,
421 +           "done.\n"
422 +           "nFrames = %d.\n",
423 +           nFrames );
424 +  fflush(stdout);
425 +
426 +  if(scdCorr){
427 +
428 +    fprintf ( stdout,
429 +              "Calculating the Scd correlation\n" );
430 +    fflush( stdout );
431 +    
432 +    calcScdCorr( startTime, atoms, outPrefix );
433 +  }
434 +
435 +  if(directorHead){
436 +
437 +    fprintf ( stdout,
438 +              "Calculating the Head director\n" );
439 +    fflush( stdout );
440 +    
441 +    calcDirHeadCorr( startTime, atoms, outPrefix );
442 +  }
443 +  
444 +
445 +  closeFile();
446 +
447 + }
448 +
449 +
450 + /***************************************************************************
451 + * prints out the usage for the command line arguments, then exits.
452 + ***************************************************************************/
453 +
454 + void usage(){
455 +  (void)fprintf(stdout,
456 +                "\n"
457 +                "The proper usage is: %s [options] <input_file>\n"
458 +                "\n"
459 +                "Options:\n"
460 +                "\n"
461 +                "   short:\n"
462 +                "   ------\n"
463 +                "   -o <name>       The output prefix\n"
464 +                "   -t <time>       Set the start time for correlations\n"
465 +                "   -l <maxLength>  set the maximum value of r\n"
466 +                "                     *Defaults to 1/2 smallest length of first frame.\n"
467 +                "   -s              Calculate the Scd chain correlation.\n"
468 +                "\n"
469 +                "   long:\n"
470 +                "   -----\n"
471 +                "   --gofr <atom1> <atom2>         g(r) for atom1 and atom2\n"
472 +                "   --gofrTheta <atom1> <atom2>    g(r, theta) for atom1 and atom2\n"
473 +                "   --gofrOmega <atom1> <atom2>    g(r, omega) for atom1 and atom2\n"
474 +                "   --version                      displays the version number\n"
475 +                "   --help                         displays this help message.\n"
476 +                
477 +                "\n"
478 +                "\n",
479 +                programName);
480 + }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines