1 |
+ |
#define _FILE_OFFSET_BITS 64 |
2 |
+ |
|
3 |
|
#include <stdlib.h> |
4 |
|
#include <stdio.h> |
5 |
+ |
#include <string.h> |
6 |
|
|
7 |
|
#include "frameCount.h" |
8 |
|
|
9 |
|
|
10 |
< |
int frameCount( char* in_name ){ |
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 |
< |
FILE *in_file; |
22 |
< |
int nFrames = 0; |
23 |
< |
int i, j, k; |
24 |
< |
int lineNum = 0; |
25 |
< |
char readBuffer[2000]; |
26 |
< |
|
27 |
< |
in_file = fopen( in_name, "r" ); |
28 |
< |
if( in_file == NULL ){ |
29 |
< |
printf( "Error opening \"%s\"\n", in_name ); |
30 |
< |
exit(8); |
31 |
< |
} |
32 |
< |
|
33 |
< |
if( feof( in_file ) ){ |
34 |
< |
printf( "File ended unexpectedly at line %d\n", lineNum ); |
23 |
< |
exit(8); |
24 |
< |
} |
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 |
< |
fgets( readBuffer, sizeof( readBuffer ), in_file ); |
37 |
< |
lineNum++; |
36 |
> |
while( !feof( in_file ) ){ |
37 |
> |
|
38 |
> |
i = atoi(readBuffer); |
39 |
|
|
40 |
< |
while( !feof( in_file ) ){ |
41 |
< |
|
42 |
< |
i = atoi(readBuffer); |
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 |
< |
if( feof( in_file ) ){ |
49 |
< |
printf( "File ended unexpectedly at line %d, in frame%d\n", lineNum, nFrames+1 ); |
50 |
< |
exit(8); |
51 |
< |
} |
52 |
< |
fgets( readBuffer, sizeof( readBuffer ), in_file ); |
53 |
< |
lineNum++; |
54 |
< |
|
55 |
< |
for(j=0; j<i; j++){ |
56 |
< |
|
57 |
< |
if( feof( in_file ) ){ |
58 |
< |
printf( "File ended unexpectedly at line %d, with atom %d, in frame %d\n", |
59 |
< |
lineNum, j, nFrames+1 ); |
60 |
< |
exit(8); |
61 |
< |
} |
62 |
< |
fgets( readBuffer, sizeof( readBuffer ), in_file ); |
63 |
< |
lineNum++; |
64 |
< |
} |
65 |
< |
|
66 |
< |
nFrames++; |
67 |
< |
|
68 |
< |
fgets( readBuffer, sizeof( readBuffer ), in_file ); |
69 |
< |
lineNum++; |
70 |
< |
} |
71 |
< |
|
72 |
< |
fclose( in_file ); |
73 |
< |
|
74 |
< |
return nFrames; |
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 |
|
} |