| 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, 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 |
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); |
| 39 |
|
| 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(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 |
} |