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