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