ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE/props/frameCount.c
Revision: 656
Committed: Tue Jul 29 16:32:37 2003 UTC (21 years, 9 months ago) by mmeineke
Content type: text/plain
File size: 1480 byte(s)
Log Message:
working on the props code

File Contents

# User Rev Content
1 mmeineke 656 #include <stdlib.h>
2     #include <stdio.h>
3     #include <string.h>
4    
5     #include "frameCount.h"
6    
7    
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     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);
37    
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     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     }