Options parseOptions(int _argc, char * _argv[], Options defaults) { /****************************************** * Pass the array of argument and the name of * a configuration file to the ArgumentParser * object. Then ask for the value of the argument * and collect error and warnings. * * This function returns a Options structure * defined at the head of this file ******************************************/ Options opt; /****************************************** * Set the allowed and required options: * * Example of configuartion file: * ******************************************/ vector<string> required; vector<string> allowed; opt.required.push_back("pdbFile"); opt.required.push_back("segment"); opt.required.push_back("proteinId"); opt.required.push_back("topFile"); opt.required.push_back("parFile"); opt.required.push_back("solvFile"); opt.required.push_back("hBondFile"); opt.allowed.push_back("configfile"); //OptionParser OP(_argc, _argv); OptionParser OP; OP.setShortOptionEquivalent(opt.equivalent); OP.readArgv(_argc, _argv); OP.setDefaultArguments(opt.defaultArgs); // a pdb file value can be given as a default argument without the --pdbfile option OP.setRequired(opt.required); OP.setAllowed(opt.allowed); OP.autoExtendOptions(); // if you give option "solvat" it will be autocompleted to "solvationfile" if (OP.countOptions() == 0) { usage(); exit(0); } opt.configfile = OP.getString("configfile"); if (opt.configfile != "") { OP.readFile(opt.configfile); if (OP.fail()) { opt.errorFlag = true; opt.errorMessages += "Cannot read configuration file " + opt.configfile + "\n"; exit(1); } } /***************************************** * VERSION AND HELP * * --version or -v arguments print the version number * --help prints the usage and help *****************************************/ opt.version = OP.getBool("version"); //if (OP.fail()) { // opt.version = OP.getBool("v"); //} if (opt.version) { version(); exit(0); } opt.help = OP.getBool("help"); if (OP.fail()) { opt.help = OP.getBool("h"); } if (opt.help) { help(defaults); exit(0); } /***************************************** * CHECK THE GIVEN OPTIONS *****************************************/ if (!OP.checkOptions()) { opt.errorFlag = true; opt.OPerrors = OP.getErrors(); return opt; } opt.errorFlag = false; opt.warningFlag = false; opt.errorMessages = ""; opt.warningMessages = ""; /***************************************** * CHECK THE GIVEN OPTIONS *****************************************/ opt.pdbFile = OP.getString("pdbFile"); if (OP.fail()) { opt.errorMessages += "pdbFile not specified\n"; opt.errorFlag = true; } opt.segment = OP.getMultiString("segment"); if (OP.fail()) { opt.errorMessages += "segment not specified\n"; opt.errorFlag = true; } opt.proteinId = OP.getString("proteinId"); if (OP.fail()) { opt.errorMessages += "proteinId not specified\n"; opt.errorFlag = true; } opt.topFile = OP.getString("topFile"); if (OP.fail()) { opt.errorMessages += "topFile not specified\n"; opt.errorFlag = true; } opt.parFile = OP.getString("parFile"); if (OP.fail()) { opt.errorMessages += "parFile not specified\n"; opt.errorFlag = true; } opt.solvFile = OP.getString("solvFile"); if (OP.fail()) { opt.errorMessages += "solvFile not specified\n"; opt.errorFlag = true; } opt.hBondFile = OP.getString("hBondFile"); if (OP.fail()) { opt.errorMessages += "hBondFile not specified\n"; opt.errorFlag = true; } // return the Options structure return opt; }