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

Comparing trunk/dumpCat/dumpCat.c (file contents):
Revision 48 by mmeineke, Wed Jul 24 16:51:43 2002 UTC vs.
Revision 681 by mmeineke, Tue Aug 12 16:08:05 2003 UTC

# Line 3 | Line 3
3   #include <string.h>
4   #include <unistd.h>
5  
6 + #define MAX_FILES 1000
7 + #define STR_BUFFER 2000
8  
9   void usage( void );
10  
# Line 14 | Line 16 | int main( int argc, char* argv[] ){
16    double realTime, currentTime, lastTime;
17    double boxX, boxY, boxZ;
18    char* foo;
19 <  char* in_name;
20 <  char* out_name;
21 <  char readBuffer[2000];
19 >  char* in_name[MAX_FILES];
20 >  char readBuffer[STR_BUFFER];
21 >  char writeBuffer[STR_BUFFER];
22    int i,j,k;
23    int lineNum;
24  
25 +  int current_flag;
26 +  int done;
27 +  
28 +  char* out_name;
29 +  int have_out = 0;
30 +
31 +  int timeMod = 1;
32 +
33 +  int nFiles;
34 +  int index;
35 +  
36 +  int printMe = 0;
37 +  int skipFirst = 0;
38 +
39    FILE *in_file;
40    FILE *out_file;
41    
42    program_name = argv[0];
43 +
44 +  nFiles = 0;
45 +  for( i = 1; i < argc; i++){
46 +    
47 +    if(argv[i][0] =='-'){
48 +
49 +      // parse the option
50 +      
51 +      if(argv[i][1] == '-' ){
52 +
53 +        // parse long word options
54 +        
55 +        fprintf( stderr,
56 +                 "Invalid option \"%s\"\n", argv[i] );
57 +        usage();
58 +        
59 +      }
60 +      
61 +      else{
62 +        
63 +        // parse single character options
64 +        
65 +        done = 0;
66 +        j = 1;
67 +        current_flag = argv[i][j];
68 +        while( (current_flag != '\0') && (!done) ){
69 +          
70 +          switch(current_flag){
71 +
72 +          case 'o':
73 +            // -o <outFile> => the output file.
74 +
75 +            i++;
76 +            out_name = argv[i];
77 +            have_out = 1;
78 +            done = 1;
79 +            break;
80 +
81 +          case 't':
82 +            // -t <#> => the time increment
83 +
84 +            i++;
85 +            timeMod = atoi( argv[i] );
86 +            done = 1;
87 +            break;
88 +
89 +          case 'h':
90 +            // -h => display help
91 +            
92 +            usage();
93 +            break;
94 +        
95 +          case 's':
96 +            // -b => skip first frame
97 +
98 +            skipFirst = 1;
99 +            break;
100 +
101 +          default:
102 +
103 +            (void)fprintf(stderr, "Bad option \"-%c\"\n", current_flag);
104 +            usage();
105 +          }
106 +          j++;
107 +          current_flag = argv[i][j];
108 +        }
109 +      }
110 +    }
111 +
112 +    else{
113 +      
114 +      nFiles++;
115 +      if( nFiles >= MAX_FILES ){
116 +        printf( "Error, MAX_FILES, %d, exceeded at %s\n", MAX_FILES, argv[i] );
117 +        exit(0);
118 +      }
119 +      
120 +      in_name[(nFiles-1)] = argv[i];
121 +    }
122 +  }
123    
124 <  out_name = argv[1];
29 <  
30 <  if( !access( out_name, F_OK ) ){
124 >  if( !have_out ){
125      
126 <    in_file = fopen( out_name, "r" );
126 >    in_file = fopen( in_name[0], "r" );
127      lineNum =0;
128      if( in_file == NULL ){
129        printf( "Error opening \"%s\"\n", out_name );
# Line 76 | Line 170 | int main( int argc, char* argv[] ){
170      
171      fclose( in_file );
172  
173 <    out_file = fopen( out_name, "a" );
173 >    out_file = fopen( in_name[0], "a" );
174    }
175    
176    else{
# Line 84 | Line 178 | int main( int argc, char* argv[] ){
178      out_file = fopen( out_name, "w" );
179      lastTime = 0.0;
180      
181 <    in_name = argv[2];
88 <
89 <    in_file = fopen( in_name, "r" );
181 >    in_file = fopen( in_name[0], "r" );
182      lineNum = 0;
183      if( in_file == NULL ){
184 <      printf( "Error opening \"%s\"\n", in_name );
184 >      printf( "Error opening \"%s\"\n", in_name[0] );
185        exit(8);
186      }
187  
188      fgets( readBuffer, sizeof( readBuffer ), in_file );
189      lineNum++;
190      if( feof( in_file ) ){
191 <      printf( "File %s ended unexpectedly at line %d\n", in_name, lineNum );
191 >      printf( "File %s ended unexpectedly at line %d\n", in_name[0], lineNum );
192        exit(8);
193      }
194 <    
195 <    fprintf( out_file, "%s", readBuffer );
104 <
105 <    i = atoi(readBuffer);
106 <    
107 <    fgets(readBuffer, sizeof(readBuffer), in_file);
108 <    lineNum++;
109 <    if( feof( in_file ) ){
110 <      printf( "File %s ended unexpectedly at line %d\n", in_name, lineNum );
111 <      exit(8);
112 <    }
113 <    
114 <    fprintf( out_file, "%s", readBuffer );
115 <
116 <    for(j=0; j<i; j++){
194 >      
195 >    while( !feof( in_file ) ){
196        
197 <      fgets( readBuffer, sizeof( readBuffer ), in_file );
198 <      lineNum++;    
197 >      
198 >      i = atoi(readBuffer);
199 >      
200 >      fgets(readBuffer, sizeof(readBuffer), in_file);
201 >      lineNum++;
202        if( feof( in_file ) ){
203 <        printf( "File %s ended unexpectedly at line %d,"
204 <                " with atom %d\n", in_name, lineNum, j);
203 >        printf( "File %s ended unexpectedly at line %d\n", in_name[0],
204 >                lineNum );
205          exit(8);
206        }
207 <
208 <      fprintf( out_file, "%s", readBuffer );
209 <    }
207 >      
208 >      for(j=0; j<STR_BUFFER; j++) writeBuffer[j] = readBuffer[j];
209 >      
210 >
211 >      foo = strtok(readBuffer, " ,;\t");
212 >      if(foo == NULL){
213 >        printf("error in reading time at line %d in %s\n", lineNum,
214 >               in_name[0]);
215 >        exit(8);
216 >      }
217 >    
218 >      j = strlen( foo );
219 >      currentTime = atof( foo );
220 >      realTime = currentTime + lastTime;
221 >      
222 >      printMe = !( ((int)realTime) % timeMod );
223 >      
224 >      if( printMe ){
225 >        fprintf( out_file,
226 >                 "%d\n"
227 >                 "%d%s\n",
228 >                 i, realTime, &(writeBuffer[j]) );      
229 >      }
230 >      
231 >      for(j=0; j<i; j++){
232 >        
233 >        fgets( readBuffer, sizeof( readBuffer ), in_file );
234 >        lineNum++;    
235 >        if( feof( in_file ) ){
236 >          printf( "File %s ended unexpectedly at line %d,"
237 >                  " with atom %d\n", in_name[0], lineNum, j);
238 >          exit(8);
239 >        }
240 >        
241 >        if(printMe) fprintf( out_file, "%s", readBuffer );
242  
243 +      }
244 +          
245 +      fgets( readBuffer, sizeof( readBuffer ), in_file );
246 +      lineNum++;
247 +    }
248 +    
249 +    lastTime = realTime;
250      fclose( in_file );
251    }
252  
253 <  for( k=2; k<argc; k++ ){
253 >  for( k=1; k<nFiles; k++ ){
254  
255 <    in_name = argv[k];
135 <
136 <    in_file = fopen( in_name, "r" );
255 >    in_file = fopen( in_name[k], "r" );
256      lineNum = 0;
257      if( in_file == NULL ){
258 <      printf( "Error opening \"%s\"\n", in_name );
258 >      printf( "Error opening \"%s\"\n", in_name[k] );
259        exit(8);
260      }
261      
262      
263 <    // skip the zero frame
263 >    // if this is a time = 0.0 frame then don't write it.
264  
265 <    fgets( readBuffer, sizeof( readBuffer ), in_file );
147 <    lineNum++;
148 <    if( feof( in_file ) ){
149 <      printf( "File %s ended unexpectedly at line %d\n", in_name, lineNum );
150 <      exit(8);
151 <    }
152 <    
153 <    i = atoi(readBuffer);
154 <    
155 <    fgets(readBuffer, sizeof(readBuffer), in_file);
156 <    lineNum++;
157 <    if( feof( in_file ) ){
158 <      printf( "File %s ended unexpectedly at line %d\n", in_name, lineNum );
159 <      exit(8);
160 <    }
161 <    
162 <    for(j=0; j<i; j++){
163 <      
265 >    if( skipFirst ){
266        fgets( readBuffer, sizeof( readBuffer ), in_file );
267 <      lineNum++;    
267 >      lineNum++;
268        if( feof( in_file ) ){
269 <        printf( "File %s ended unexpectedly at line %d,"
270 <                " with atom %d\n", in_name, lineNum, j);
269 >        printf( "File %s ended unexpectedly at line %d\n", in_name[k],
270 >                lineNum );
271          exit(8);
272        }
273 +      
274 +      i = atoi(readBuffer);
275 +      
276 +      fgets(readBuffer, sizeof(readBuffer), in_file);
277 +      lineNum++;
278 +      if( feof( in_file ) ){
279 +        printf( "File %s ended unexpectedly at line %d\n", in_name[k],
280 +                lineNum );
281 +        exit(8);
282 +      }
283 +      
284 +      for(j=0; j<i; j++){
285 +        
286 +        fgets( readBuffer, sizeof( readBuffer ), in_file );
287 +        lineNum++;    
288 +        if( feof( in_file ) ){
289 +          printf( "File %s ended unexpectedly at line %d,"
290 +                  " with atom %d\n", in_name[k], lineNum, j);
291 +          exit(8);
292 +        }
293 +      }
294      }
295 <    
295 >
296      // now start reading and writing
297  
298      fgets( readBuffer, sizeof( readBuffer ), in_file );
# Line 181 | Line 304 | int main( int argc, char* argv[] ){
304      
305      while( !feof( in_file ) ){
306        
184      fprintf( out_file, "%s", readBuffer );
185      
307        i = atoi(readBuffer);
308        
309        fgets(readBuffer, sizeof(readBuffer), in_file);
310        lineNum++;
311        if( feof( in_file ) ){
312 <        printf( "File %s ended unexpectedly at line %d\n", in_name, lineNum );
312 >        printf( "File %s ended unexpectedly at line %d\n", in_name[k],
313 >                lineNum );
314          exit(8);
315        }
316        
317 +      for(j=0; j<STR_BUFFER; j++) writeBuffer[j] = readBuffer[j];
318  
319        foo = strtok(readBuffer, " ,;\t");
320        if(foo == NULL){
321 <        printf("error in reading time at line %d in %s\n", lineNum, in_name);
321 >        printf("error in reading time at line %d in %s\n", lineNum,
322 >               in_name[k]);
323          exit(8);
324        }
325 <    
325 >
326 >      j = strlen( foo );
327        currentTime = atof( foo );
328        realTime = currentTime + lastTime;
329        
330 <
206 <      foo = strtok(NULL, " ,;\t");
207 <      if(foo == NULL){
208 <        printf("error in reading boxX at line %d in %s\n", lineNum, in_name);
209 <        exit(8);
210 <      }
211 <    
212 <      boxX = atof( foo );
213 <
214 <      foo = strtok(NULL, " ,;\t");
215 <      if(foo == NULL){
216 <        printf("error in reading boxY at line %d in %s\n", lineNum, in_name);
217 <        exit(8);
218 <      }
330 >      printMe = !( ((int)realTime) % timeMod );
331        
332 <      boxY = atof( foo );
333 <    
334 <      foo = strtok(NULL, " ,;\t");
335 <      if(foo == NULL){
336 <        printf("error in reading boxZ at line %d in %s\n", lineNum, in_name);
225 <        exit(8);
332 >      if( printMe ){
333 >        fprintf( out_file,
334 >                 "%d\n"
335 >                 "%d%s\n",
336 >                 i, realTime, &(writeBuffer[j]) );      
337        }
338        
228      boxZ = atof( foo );
229
230      fprintf( out_file, "%lf\t%lf\t%lf\t%lf\n",
231               realTime, boxX, boxY, boxZ );
232      
339        for(j=0; j<i; j++){
340          
341          fgets( readBuffer, sizeof( readBuffer ), in_file );
342          lineNum++;    
343          if( feof( in_file ) ){
344            printf( "File %s ended unexpectedly at line %d,"
345 <                  " with atom %d\n", in_name, lineNum, j);
345 >                  " with atom %d\n", in_name[k], lineNum, j);
346            exit(8);
347          }
348          
349 <        fprintf( out_file, "%s", readBuffer );
349 >        if(printMe) fprintf( out_file, "%s", readBuffer );
350  
351        }
352            
# Line 256 | Line 362 | int main( int argc, char* argv[] ){
362    
363    return 0;
364   }
365 +
366 +
367 + /***************************************************************************
368 + * prints out the usage for the command line arguments, then exits.
369 + ***************************************************************************/
370 +
371 + void usage(){
372 +  (void)fprintf(stderr,
373 +                "The proper usage is: %s [options] dumpFile1 dumpFile2...\n"
374 +                "\n"
375 +                "Options:\n"
376 +                "\n"
377 +                "   -o <outFile>  the output file\n"
378 +                "                     *default is to append to first file.\n"
379 +                "   -t <#>        only print out time steps that are\n"
380 +                "                      increments of <#>\n"
381 +                "   -s            skip the first frame (t = 0.0 )\n"
382 +                "\n"
383 +                "   -h            display this message\n"
384 +                "\n",
385 +                program_name);
386 +  exit(8);
387 + }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines