# | Line 1 | Line 1 | |
---|---|---|
1 | #include <stdlib.h> | |
2 | #include <stdio.h> | |
3 | + | #include <string.h> |
4 | ||
5 | < | int main(int argc, char *argv[] ){ |
5 | > | #include "frameCount.h" |
6 | ||
6 | – | FILE *in_file; |
7 | – | int nFrames = 0; |
8 | – | int i, j, k; |
9 | – | int lineNum = 0; |
10 | – | char readBuffer[1000]; |
11 | – | |
7 | ||
8 | < | if( argc != 2 ){ |
9 | < | printf( "I need a dump file to read.\n" ); |
10 | < | exit(8); |
11 | < | } |
12 | < | |
13 | < | in_file = fopen( argv[1], "r" ); |
14 | < | if( in_file == NULL ){ |
15 | < | printf( "Error opening \"%s\"\n", argv[1] ); |
16 | < | exit(8); |
17 | < | } |
23 | < | |
24 | < | if( feof( in_file ) ){ |
25 | < | printf( "File ended unexpectedly at line %d\n", lineNum ); |
26 | < | exit(8); |
27 | < | } |
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 | < | fgets( readBuffer, sizeof( readBuffer ), in_file ); |
20 | < | lineNum++; |
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 | < | while( !feof( in_file ) ){ |
35 | < | |
36 | < | i = atoi(readBuffer); |
34 | > | while( !feof( in_file ) ){ |
35 | > | |
36 | > | i = atoi(readBuffer); |
37 | ||
38 | < | if( feof( in_file ) ){ |
39 | < | printf( "File ended unexpectedly at line %d, in frame%d\n", lineNum, nFrames+1 ); |
40 | < | exit(8); |
41 | < | } |
42 | < | fgets( readBuffer, sizeof( readBuffer ), in_file ); |
43 | < | lineNum++; |
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 | < | for(j=0; j<i; j++){ |
47 | < | |
48 | < | if( feof( in_file ) ){ |
49 | < | printf( "File ended unexpectedly at line %d, with atom %d, in frame %d\n", |
50 | < | lineNum, j, nFrames+1 ); |
51 | < | exit(8); |
52 | < | } |
53 | < | fgets( readBuffer, sizeof( readBuffer ), in_file ); |
54 | < | lineNum++; |
55 | < | } |
56 | < | |
57 | < | nFrames++; |
58 | < | |
59 | < | fgets( readBuffer, sizeof( readBuffer ), in_file ); |
60 | < | lineNum++; |
61 | < | } |
62 | < | |
63 | < | printf( "file \"%s\" has %d frames.\n", argv[1], nFrames ); |
64 | < | |
65 | < | fclose( in_file ); |
66 | < | |
67 | < | return 0; |
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 | } |
– | Removed lines |
+ | Added lines |
< | Changed lines |
> | Changed lines |