--- trunk/tcProps/tcProps.c 2004/02/17 19:23:44 1057 +++ trunk/tcProps/tcProps.c 2004/02/18 21:20:51 1058 @@ -7,8 +7,15 @@ #include "params.h" #include "tcProps.h" #include "readWrite.h" +#include "scdCorr.h" +#define VERSION_MAJOR 0 +#define VERSION_MINOR 1 + +char *programName; /*the name of the program */ +void usage(void); + int main( int argC, char *argV[] ){ // list of 'a priori' constants @@ -25,6 +32,18 @@ int main( int argC, char *argV[] ){ int i,j,k; char* inName; int nFrames; + + char* outPrefix; // the output prefix + char currentFlag; // used in parsing the flags + int done = 0; // multipurpose boolean + int havePrefix; // boolean for the output prefix + char* conversionCheck; + int conversionError; + int optionError; + char* pair1; + char* pair2; + int scdCorr; + double startTime; // system initialization @@ -33,7 +52,291 @@ int main( int argC, char *argV[] ){ nFrames = 0; frameTimes = NULL; + outPrefix = NULL; + inName = NULL; + + conversionError = 0; + optionError = 0; + havePrefix = 0; + scdCorr = 0; + startTime = 0.0; + + // parse the command line + + programName = argV[0]; /*save the program name in case we need it*/ + + for( i = 1; i < argC; i++){ + + if(argV[i][0] =='-'){ + + // parse the option + + if(argV[i][1] == '-' ){ + + // parse long word options + + if( !strcmp( argV[i], "--gofr" ) ){ + + i++; + if( i>=argC ){ + fprintf( stderr, + "\n" + "not enough arguments for --gofr\n"); + usage(); + exit(0); + } + pair1 = argV[i]; + + i++; + if( i>=argC ){ + fprintf( stderr, + "\n" + "not enough arguments for --gofr\n"); + usage(); + exit(0); + } + pair2 = argV[i]; + + } + + else if( !strcmp( argV[i], "--gofrTheta" ) ){ + + i++; + if( i>=argC ){ + fprintf( stderr, + "\n" + "not enough arguments for --gofrTheta\n"); + usage(); + exit(0); + } + pair1 = argV[i]; + + i++; + if( i>=argC ){ + fprintf( stderr, + "\n" + "not enough arguments for --gofrTheta\n"); + usage(); + exit(0); + } + pair2 = argV[i]; + + } + + else if( !strcmp( argV[i], "--gofrOmega" ) ){ + + i++; + if( i>=argC ){ + fprintf( stderr, + "\n" + "not enough arguments for --gofrOmega\n"); + usage(); + exit(0); + } + pair1 = argV[i]; + + i++; + if( i>=argC ){ + fprintf( stderr, + "\n" + "not enough arguments for --gofrOmega\n"); + usage(); + exit(0); + } + pair2 = argV[i]; + + } + + else if( !strcmp( argV[i], "--version") ){ + + printf("\n" + "tcProps version %d.%d\n" + "\n", + VERSION_MAJOR, VERSION_MINOR ); + exit(0); + + } + + else if( !strcmp( argV[i], "--help") ){ + + usage(); + exit(0); + } + + // anything else is an error + + else{ + fprintf( stderr, + "Invalid option \"%s\"\n", argV[i] ); + usage(); + exit(0); + } + } + + else{ + + // parse single character options + + done =0; + j = 1; + currentFlag = argV[i][j]; + while( (currentFlag != '\0') && (!done) ){ + + switch(currentFlag){ + + case 'o': + // -o => the output prefix. + + j++; + currentFlag = argV[i][j]; + + if( currentFlag != '\0' ) optionError = 1; + + if( optionError ){ + fprintf( stderr, + "\n" + "The -o flag should end an option sequence.\n" + " example: -r *NOT* -or \n" ); + usage(); + exit(0); + } + + i++; + if( i>=argC ){ + fprintf( stderr, + "\n" + "not enough arguments for -o\n"); + usage(); + exit(0); + } + + outPrefix = argV[i]; + if( outPrefix[0] == '-' ) optionError = 1; + + if( optionError ){ + fprintf( stderr, + "\n" + "\"%s\" is not a valid out prefix/name.\n" + "Out prefix/name should not begin with a dash.\n", + outPrefix ); + usage(); + exit(0); + } + + havePrefix = 1; + done = 1; + break; + + case 'l': + // -l set to the maxLength + + haveMaxLength = true; + j++; + currentFlag = argV[i][j]; + + if( currentFlag != '\0' ) optionError = 1; + + if( optionError ){ + fprintf( stderr, + "\n" + "The -l flag should end an option sequence.\n" + " example: -sl *NOT* -ls \n" ); + usage(); + exit(0); + } + + i++; + if( i>=argC ){ + fprintf( stderr, + "\n" + "not enough arguments for -l\n"); + usage(); + exit(0); + } + + maxLength = atof( argV[i] ); + + done = 1; + + break; + + case 't': + // -t set to the startTime + + j++; + currentFlag = argV[i][j]; + + if( currentFlag != '\0' ) optionError = 1; + + if( optionError ){ + fprintf( stderr, + "\n" + "The -t flag should end an option sequence.\n" + " example: -st *NOT* -ts \n" ); + usage(); + exit(0); + } + + i++; + if( i>=argC ){ + fprintf( stderr, + "\n" + "not enough arguments for -t\n"); + usage(); + exit(0); + } + + startTime = atof( argV[i] ); + done = 1; + break; + + case 's': + // -s turn on separate output files + + scdCorr = 1; + break; + + + default: + + sprintf(painCave.errMsg, + "\n" + "Bad option \"-%c\"\n", currentFlag); + usage(); + exit(0); + } + j++; + currentFlag = argV[i][j]; + } + } + } + + else{ + + if( inName != NULL ){ + fprintf( stderr, + "Error at \"%s\", program does not currently support\n" + "more than one input dump file.\n" + "\n", + argV[i]); + usage(); + exit(0); + } + + inName = argV[i]; + + } + } + + if( inName == NULL ){ + fprintf( stderr, + "Error, dump file is needed to run.\n" ); + usage(); + exit(0); + } + + // initialize the arrays for(i=0;i\n" + "\n" + "Options:\n" + "\n" + " short:\n" + " ------\n" + " -o The output prefix\n" + " -t