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 36 by mmeineke, Fri Jul 19 00:48:45 2002 UTC vs.
Revision 84 by mmeineke, Fri Aug 16 16:45:29 2002 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines