--- trunk/dumpCat/dumpCat.c 2002/07/24 16:51:43 48 +++ trunk/dumpCat/dumpCat.c 2002/09/06 21:47:13 105 @@ -3,6 +3,7 @@ #include #include +#define MAX_FILES 1000 void usage( void ); @@ -14,22 +15,113 @@ int main( int argc, char* argv[] ){ double realTime, currentTime, lastTime; double boxX, boxY, boxZ; char* foo; - char* in_name; - char* out_name; + char* in_name[MAX_FILES]; char readBuffer[2000]; int i,j,k; int lineNum; + int current_flag; + int done; + + char* out_name; + int have_out = 0; + + int timeMod = 1; + + int nFiles; + int index; + + int printMe = 0; + int skipFirst = 0; + FILE *in_file; FILE *out_file; program_name = argv[0]; + + nFiles = 0; + for( i = 1; i < argc; i++){ + + if(argv[i][0] =='-'){ + + // parse the option + + if(argv[i][1] == '-' ){ + + // parse long word options + + fprintf( stderr, + "Invalid option \"%s\"\n", argv[i] ); + usage(); + + } + + else{ + + // parse single character options + + done = 0; + j = 1; + current_flag = argv[i][j]; + while( (current_flag != '\0') && (!done) ){ + + switch(current_flag){ + + case 'o': + // -o => the output file. + + i++; + out_name = argv[i]; + have_out = 1; + done = 1; + break; + + case 't': + // -t <#> => the time increment + + i++; + timeMod = atoi( argv[i] ); + done = 1; + break; + + case 'h': + // -h => display help + + usage(); + break; + + case 's': + // -b => skip first frame + + skipFirst = 1; + break; + + default: + + (void)fprintf(stderr, "Bad option \"-%c\"\n", current_flag); + usage(); + } + j++; + current_flag = argv[i][j]; + } + } + } + + else{ + + nFiles++; + if( nFiles >= MAX_FILES ){ + printf( "Error, MAX_FILES, %d, exceeded at %s\n", MAX_FILES, argv[i] ); + exit(0); + } + + in_name[(nFiles-1)] = argv[i]; + } + } - out_name = argv[1]; - - if( !access( out_name, F_OK ) ){ + if( !have_out ){ - in_file = fopen( out_name, "r" ); + in_file = fopen( in_name[0], "r" ); lineNum =0; if( in_file == NULL ){ printf( "Error opening \"%s\"\n", out_name ); @@ -76,7 +168,7 @@ int main( int argc, char* argv[] ){ fclose( in_file ); - out_file = fopen( out_name, "a" ); + out_file = fopen( in_name[0], "a" ); } else{ @@ -84,92 +176,145 @@ int main( int argc, char* argv[] ){ out_file = fopen( out_name, "w" ); lastTime = 0.0; - in_name = argv[2]; - - in_file = fopen( in_name, "r" ); + in_file = fopen( in_name[0], "r" ); lineNum = 0; if( in_file == NULL ){ - printf( "Error opening \"%s\"\n", in_name ); + printf( "Error opening \"%s\"\n", in_name[0] ); exit(8); } fgets( readBuffer, sizeof( readBuffer ), in_file ); lineNum++; if( feof( in_file ) ){ - printf( "File %s ended unexpectedly at line %d\n", in_name, lineNum ); + printf( "File %s ended unexpectedly at line %d\n", in_name[0], lineNum ); exit(8); } + + while( !feof( in_file ) ){ + + + i = atoi(readBuffer); + + fgets(readBuffer, sizeof(readBuffer), in_file); + lineNum++; + if( feof( in_file ) ){ + printf( "File %s ended unexpectedly at line %d\n", in_name[0], + lineNum ); + exit(8); + } + + + foo = strtok(readBuffer, " ,;\t"); + if(foo == NULL){ + printf("error in reading time at line %d in %s\n", lineNum, + in_name[0]); + exit(8); + } - fprintf( out_file, "%s", readBuffer ); + currentTime = atof( foo ); + realTime = currentTime + lastTime; + - i = atoi(readBuffer); + foo = strtok(NULL, " ,;\t"); + if(foo == NULL){ + printf("error in reading boxX at line %d in %s\n", lineNum, + in_name[0]); + exit(8); + } - fgets(readBuffer, sizeof(readBuffer), in_file); - lineNum++; - if( feof( in_file ) ){ - printf( "File %s ended unexpectedly at line %d\n", in_name, lineNum ); - exit(8); - } - - fprintf( out_file, "%s", readBuffer ); + boxX = atof( foo ); - for(j=0; j the output file\n" + " *default is to append to first file.\n" + " -t <#> only print out time steps that are\n" + " increments of <#>\n" + " -s skip the first frame (t = 0.0 )\n" + "\n" + " -h display this message\n" + "\n", + program_name); + exit(8); +}