#include #include #include #include #include int main( int argc, char * argv[] ) { FILE * rawFile; FILE * outFile; int i=1, index=0; char * oneLine=NULL; float ftime=0, fRate=0,timeArr[14]; /* index from 0 to 13*/ double doubleVal=0.0; double dVar=0.0, average=0.0; if ( argc != 3 ) { fprintf(stderr, "usage: %s inputfile outputfile \n", argv[0] ); exit( EXIT_FAILURE ); } if( (rawFile = fopen( argv[1], "r" )) < 0 ) { fprintf(stderr, "Error opening %s \n", argv[1] ); exit( EXIT_FAILURE ); } if( (outFile = fopen( argv[2], "w" )) < 0 ) { fprintf(stderr, "Error opening %s \n", argv[2] ); exit( EXIT_FAILURE ); } /* initialize the timeArr*/ for( i=0; i<14; i++) timeArr[i] = 0; /* allocate memory for oneLine */ oneLine = malloc( 1024 ); while ( (oneLine = fgets( oneLine, 1024, rawFile )) != NULL ) { if ( strstr( oneLine, "blastclient" ) ) continue; if ( strstr( oneLine, "Elapsed" ) ) { /* get elapse time in the array */ index++; sscanf( oneLine, "Elapsed: %f", &ftime ); //printf("time is: %f\n", ftime );/* for debugging purpose */ timeArr[ index ] = ftime; if ( index == 10 ) { /* this is the last elapse data, put the arry in the file */ /* calculate the average time and the throughput */ /* BE SURE TO USE DOUBLE TYPE WHEN YOU DO CALCULATION :w*/ average=0.0; for( i=1; i<=10; i++) { doubleVal = (double) timeArr[i]; average += doubleVal/10; fprintf( outFile, " %f", timeArr[i] ); } /* average timeArr[11]*/ //(double)timeArr[11] = (double) timeArr[11]/10; timeArr[11] = (float) average; fprintf( outFile, " %f", timeArr[11] ); printf( "average: %f\n", timeArr[11] ); /* average devication timeArr[12]*/ dVar =0.0; for( i=1; i<=10; i++ ) { //timeArr[12] += (timeArr[i]-timeArr[11])*(timeArr[i]-timeArr[11]); doubleVal = (double) (timeArr[i]-timeArr[11]); doubleVal = doubleVal*doubleVal; dVar += doubleVal/10; } dVar = sqrt( dVar ); timeArr[12] = (float) dVar; fprintf( outFile, " %f", timeArr[12] ); printf( "Var: %f\n", timeArr[12] ); /* throughput = 1526*100000/timeArr[11] */ timeArr[13] = 1526*100000/timeArr[11]; fprintf( outFile, " %f\n", timeArr[13] ); }/* end of index=10*/ continue; } if ( strstr( oneLine, "Dublin" ) ) { /* get router dropping rate*/ sscanf( oneLine, "Dublin packet drop rate is set to: %f", &fRate); index = 0; timeArr[0] = fRate; /* put dropping rate at the first column of the file*/ fprintf( outFile, " %f", timeArr[0] ); } }/* end of while */ return 0; }/* end of main */