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

Comparing trunk/frameCount/src/frameCount.c (file contents):
Revision 35 by mmeineke, Fri Jul 19 00:01:59 2002 UTC vs.
Revision 1086 by mmeineke, Fri Mar 5 17:21:20 2004 UTC

# Line 1 | Line 1
1 + #define _FILE_OFFSET_BITS 64
2 +
3   #include <stdlib.h>
4   #include <stdio.h>
5 + #include <string.h>
6  
7 < int main(int argc, char *argv[] ){
7 > #include "frameCount.h"
8  
6        FILE *in_file;
7        int nFrames = 0;
8        int i, j, k;
9        int lineNum = 0;
10        char readBuffer[1000];
11        
9  
10 <        if( argc != 2 ){
11 <                printf( "I need a dump file to read.\n" );
12 <                exit(8);
13 <        }
14 <        
15 <        in_file = fopen( argv[1], "r" );
16 <        if( in_file == NULL ){
17 <                printf( "Error opening \"%s\"\n", argv[1] );
18 <                exit(8);
19 <        }
23 <        
24 <        if( feof( in_file ) ){
25 <                printf( "File ended unexpectedly at line %d\n", lineNum );
26 <                exit(8);
27 <        }
10 > int frameCount( char* in_name, int outTime ){
11 >  
12 >  FILE *in_file;
13 >  int nFrames = 0;
14 >  double time;
15 >  int i, j, k;
16 >  int lineNum = 0;
17 >  char readBuffer[2000];
18 >  char* foo;
19 >  
20  
21 <        fgets( readBuffer, sizeof( readBuffer ), in_file );
22 <        lineNum++;
21 >  in_file = fopen( in_name, "r" );
22 >  if( in_file == NULL ){
23 >    printf( "Error opening \"%s\"\n", in_name );
24 >    exit(8);
25 >  }
26 >  
27 >  fgets( readBuffer, sizeof( readBuffer ), in_file );
28 >  lineNum++;
29 >  if( feof( in_file ) ){
30 >    printf( "File ended unexpectedly at line %d\n", lineNum );
31 >    exit(8);
32 >  }
33 >  
34 >  if(outTime) printf("# frame Num\tTime\n" );
35  
36 <        while( !feof( in_file ) ){
37 <                        
38 <                i = atoi(readBuffer);
36 >  while( !feof( in_file ) ){
37 >    
38 >    i = atoi(readBuffer);
39  
40 <                if( feof( in_file ) ){
41 <                        printf( "File ended unexpectedly at line %d, in frame%d\n", lineNum, nFrames+1 );
42 <                        exit(8);
43 <                }
44 <                fgets( readBuffer, sizeof( readBuffer ), in_file );
45 <                lineNum++;
40 >    fgets( readBuffer, sizeof( readBuffer ), in_file );
41 >    lineNum++;    
42 >    if( feof( in_file ) ){
43 >      printf( "File ended unexpectedly at line %d, in frame%d\n",
44 >              lineNum, nFrames+1 );
45 >      exit(8);
46 >    }
47  
48 <                for(j=0; j<i; j++){
49 <                        
50 <                        if( feof( in_file ) ){
51 <                                printf( "File ended unexpectedly at line %d, with atom %d, in frame %d\n",
52 <                                                lineNum, j, nFrames+1 );
53 <                                exit(8);
54 <                        }
55 <                        fgets( readBuffer, sizeof( readBuffer ), in_file );
56 <                        lineNum++;
57 <                }
58 <
59 <                nFrames++;
60 <                
61 <                fgets( readBuffer, sizeof( readBuffer ), in_file );
62 <                lineNum++;
63 <        }
64 <
65 <        printf( "file \"%s\" has %d frames.\n", argv[1], nFrames );
66 <        
67 <        fclose( in_file );
68 <        
69 <        return 0;
48 >    if(outTime){
49 >      foo = strtok( readBuffer, " ,;\t" );
50 >      time = atof( foo );
51 >    }
52 >    
53 >    for(j=0; j<i; j++){
54 >      
55 >      fgets( readBuffer, sizeof( readBuffer ), in_file );
56 >      lineNum++;    
57 >      if( feof( in_file ) ){
58 >        printf( "File ended unexpectedly at line %d,"
59 >                " with atom %d, in frame %d\n", lineNum, j, nFrames+1 );
60 >        exit(8);
61 >      }
62 >      
63 >    }
64 >    
65 >    nFrames++;
66 >    if( outTime ){
67 >      printf("%d\t%f\n", nFrames, time );
68 >    }
69 >    
70 >    fgets( readBuffer, sizeof( readBuffer ), in_file );
71 >    lineNum++;
72 >  }
73 >  
74 >  fclose( in_file );
75 >  
76 >  return nFrames;
77   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines