--- branches/mmeineke/madProps/madProps.c 2002/07/19 01:37:38 38 +++ trunk/madProps/madProps.c 2002/08/16 04:05:45 82 @@ -3,23 +3,10 @@ #include #include + +#include "madProps.h" #include "frameCount.h" -struct coords{ - double x; - double y; - double z; - char name[30]; -}; - - -struct xyz_frame{ - int nAtoms; - double time; - double boxX, boxY, boxZ; - struct coords *r; -}; - char *program_name; /*the name of the program */ void usage(void); @@ -35,46 +22,161 @@ int main(argc, argv) int lineNum = 0; // keeps track of the line number int n_atoms; // the number of atoms int i,j; // loop counters + int isFirst; char read_buffer[2000]; /*the line buffer for reading */ char *foo; /*the pointer to the current string token */ FILE *in_file; /* the input file */ char *in_name = NULL; /*the name of the input file */ + char *out_prefix; // the output prefix + char current_flag; // used in parseing the flags + + int done = 0; // multipurpose boolean + int have_prefix = 0; // prefix boolean + int calcRMSD = 0; + + int calcGofR = 0; + char gofR1[30]; + char gofR2[30]; + + int calcMuCorr = 0; + char muCorr[30]; + + int calcCosCorr = 0; + char cosCorr1[30]; + char cosCorr2[30]; + + int startFrame = 0; + int haveStartFrame = 0; + int endFrame = 0; + int haveEndFrame = 0; + program_name = argv[0]; /*save the program name in case we need it*/ - for( i = 0; i < argc; i++){ + for( i = 1; i < argc; i++){ if(argv[i][0] =='-'){ + + // parse the option - /* argv[i][1] is the actual option character */ + if(argv[i][1] == '-' ){ + + // parse long word options + + if( !strcmp( argv[i], "--GofR" ) ){ + calcGofR = 1; + i++; + strcpy( gofR1, argv[i] ); + i++; + strcpy( gofR2, argv[i] ); + } + + else if( !strcmp( argv[i], "--MuCorr") ){ + calcMuCorr = 1; + i++; + strcpy( muCorr, argv[i] ); + } + + else if( !strcmp( argv[i], "--startFrame" ) ){ + haveStartFrame = 1; + i++; + startFrame = atoi(argv[i]); + } + + else if( !strcmp( argv[i], "--endFrame" ) ){ + haveEndFrame = 1; + i++; + endFrame = atoi(argv[i]); + } + + else{ + fprintf( stderr, + "Invalid option \"%s\"\n", argv[i] ); + usage(); + } + } - switch(argv[i][1]){ + else{ - /* -f => the xyz input file - * [i+1] actually starts the name - */ + // parse single character options + + done =0; + j = 1; + current_flag = argv[i][j]; + while( (current_flag != '\0') && (!done) ){ + + switch(current_flag){ - case 'f': - in_name = argv[i+1]; - break; + case 'o': + // -o => the output prefix. - default: - (void)fprintf(stderr, "Bad option %s\n", argv[i]); + i++; + out_prefix = argv[i]; + have_prefix = 1; + done = 1; + break; + + case 'h': + // -h => give the usage + + usage(); + break; + + case 'r': + // calculates the rmsd + + calcRMSD = 1; + break; + + case 'g': + // calculate all to all g(r) + + calcGofR = 1; + strcpy( gofR1, "all" ); + strcpy( gofR2, "all" ); + break; + + default: + + fprintf( stderr, "about to print bad option\n" ); + + (void)fprintf(stderr, "Bad option \"-%s\"\n", current_flag); + usage(); + } + j++; + current_flag = argv[i][j]; + } + } + } + + else{ + + if( in_name != NULL ){ + fprintf( stderr, + "Error at \"%s\", program does not currently support\n" + "more than one input file.\n" + "\n", + argv[i]); usage(); } + + in_name = argv[i]; } } if(in_name == NULL){ usage(); } + + if( !have_prefix ) out_prefix = in_name; printf( "Counting number of frames..." ); fflush( stdout ); nFrames = frameCount( in_name ); + if( !haveEndFrame ) endFrame = nFrames; printf( "done.\n" "nframes = %d\n" @@ -88,16 +190,27 @@ int main(argc, argv) exit(8); } - // create the array of frames + // create and initialize the array of frames dumpArray = (struct xyz_frame*)calloc( nFrames, sizeof( struct xyz_frame ) ); + for( i=0; i\n\n" - "Options:\n", + (void)fprintf(stdout, + "The proper usage is: %s [options] \n" + "\n" + "Options:\n" + "\n" + " short:\n" + " ------\n" + " -h Display this message\n" + " -o The output prefix\n" + " -r Calculate the RMSD\n" + " -g Calculate all to all g(r)\n" + + "\n" + " long:\n" + " -----\n" + " --GofR Calculates g(r) between atom1 and atom 2\n" + " -note: \"all\" will do all atoms\n" + " --MuCorr Calculate mu correlation of atom\n" + " --CosCorr Calculate the cos correlation between atom1 and atom2\n" + " --startFrame Specifies a frame to start correlating\n" + " --endFrame Specifies a frame to stop correlating.\n" + + "\n" + "\n", program_name); exit(8); }