std::string Runner::check_and_get_inputfile(int argc, char* argv[], GetPot & command_line) { if( argc < 2 ) { std::stringstream error_msg; error_msg << "ERROR: Found only 1 command line argument, but was expecting an inputfile name!" << std::endl << " Please specify the name of the input file on the command line as the first" << std::endl << " command line argument or using the '--input <filename>' option." << std::endl; libmesh_error_msg(error_msg.str()); } std::string inputfile_name; if( command_line.search("--input") ) inputfile_name = command_line.next(std::string("DIE!")); else inputfile_name = argv[1]; std::ifstream i(inputfile_name.c_str()); if (!i) { std::string error_msg = "Error: Could not read from input file "+inputfile_name+"!\n"; libmesh_error_msg(error_msg); } return inputfile_name; }
T assert_argument (GetPot &cl, const std::string &argname, const char *progname, const T& defaultarg) { if(!cl.search(argname)) { libMesh::err << ("No " + argname + " argument found!") << std::endl; usage_error(progname); } return cl.next(defaultarg); }
void get_input_params(GetPot& field_parser, libmesh_assemble_input_params& input_params) { // Set mesh files if (field_parser.search(1, "Mesh")) { input_params.mesh_file = field_parser.next( input_params.mesh_file); } else { homemade_error_msg("Missing the system mesh file!"); } // Set constant parameters if ( field_parser.search(1, "PhysicalParameters") ) { input_params.physical_params_file = field_parser.next(input_params.physical_params_file); } else { homemade_error_msg("Missing the physical parameters file!"); } // Set weight function std::string sys_type; if ( field_parser.search(1, "SystemType") ) { sys_type = field_parser.next(sys_type); if(sys_type == "Macro" || sys_type == "MACRO" || sys_type == "macro") input_params.system_type = WeightFunctionSystemType::MACRO; else if(sys_type == "Micro" || sys_type == "MICRO" || sys_type == "micro") input_params.system_type = WeightFunctionSystemType::MICRO; else if(sys_type == "NoWeight" || sys_type == "NOWEIGHT" || sys_type == "noweight") { input_params.system_type = WeightFunctionSystemType::NO_WEIGHT; std::cout << " >> Warning: Will not use the weight parameters!" << std::endl; } else homemade_error_msg("Invalid system type (must be either Macro, Micro or NoWeight)!"); } else { homemade_error_msg("Missing the system type (must be either Macro, Micro or NoWeight)!"); } if ( field_parser.search(1, "MeshWeight") ) { input_params.mesh_weight_file = field_parser.next(input_params.mesh_weight_file); } else { homemade_error_msg("Missing the weight mesh file!"); } if( field_parser.search(1, "WeightIndexes") ) { input_params.weight_domain_idx_file = field_parser.next(input_params.weight_domain_idx_file); } else { homemade_error_msg("Missing the weight value file!"); } // Output if (field_parser.search(2, "--output", "OutputBase")) { input_params.output_base = field_parser.next( input_params.output_base); } else { input_params.output_base = "test_system"; } if (field_parser.search(1, "ExportRBVectors")) { input_params.bCalculateRBVectors = true; } else { input_params.bCalculateRBVectors = false; } };
void Server::parseConfig(GetPot &config) { // this variable is needed for setting up the partial loading part when the features // are loaded for the very first time at fire start up string partialLoadingString="empty"; if(config.search(2,"-F","--filter")) { string unparsed = config.follow("empty",2,"-F","--filter"); if (parseFilter(unparsed.c_str())) { retriever_.setFilterApply(true); DBG(10) << "Using filter " << unparsed << " for retrieval" << endl; } else { retriever_.setFilterApply(false); retriever_.clearFilter(); DBG(10) << "Error in filter String " << unparsed << endl; DBG(10) << "Aborting filtering and using normal retrieval settings" << endl; } } if(config.search(2,"-q","--queryCombiner")) { retriever_.setQueryCombiner(config.follow("adding:POS=1.0:NEG=0.833",2,"-q","--queryCombiner")); } if(config.search("--reRanker")) { retriever_.setReranking(config.follow("cluster:CONS=100:RR=20:CLUSTERS=5","--reRanker")); } if(config.search(2,"-U","--defdontload")) { partialLoadingString="default"; retriever_.setPartialLoadingApply(true); } if(config.search(2,"-u","--dontload")) { string unparsed=config.follow("empty",2,"-u","--dontload"); if(unparsed!="empty") { // the parsing is not possible here, because the amount of different features // is not known yet // but a sanity check is possible const char* str = unparsed.c_str(); bool errformat = false; // note it is not checked if there are two or more : present in a row while(*str != '\0' && !errformat) { if(!isdigit(*str) && *str!=':') { errformat=true; DBG(10) << "Error in format string " << unparsed << " following -u/--dontload option" << endl; DBG(10) << "format string must start with a digit; aborting partial feature loading" << endl; } str++; } if(!errformat && retriever_.setPartialLoadingApply(true)) { partialLoadingString=unparsed; } else { ERR << "-u/--dontload was used without -F/--filter option or there are illegal characters in the format string" << endl; ERR << "ignoring -u/--dontload option, loading all features" << endl; } } else { retriever_.setPartialLoadingApply(false); ERR << "Error after -u/--dontload option: No featureindexsequence given" << endl; //DBG(10) << "Aborting partial loading for filtered retrieval and loading all features" << endl; } } if(config.search(2,"-f","--filelist")) { string filelistname=config.follow("list.txt",2,"-f","--filelist"); string result=retriever_.filelist(filelistname,partialLoadingString); if(result=="filelist FAILURE") { ERR << "Error in filelist. Please correct it and start again." << endl; exit(1); } DBG(10) << result << endl; } if(config.search(2,"-R","--relevancefile")) { relevanceFile_=config.follow("",2,"-R","--relevancefile"); } retriever_.setScoring("linear"); log_=LogFile(config.follow("",2,"-l","--logfile")); if(config.search(2,"-D","--defaultdists")) { for(uint i=0;i<retriever_.numberOfSuffices();++i) { retriever_.dist(i,distanceMaker_.getDefaultDistance(retriever_.featureType(i))); retriever_.weight(i,1.0); DBG(10) << "default dist[" << i << "]=" << retriever_.dist(i)->name() << endl; } } config.init_multiple_occurrence(); // can have multiple distances while(config.search(2,"-d","--dist")) { uint idx=config.follow(0,2,"-d","--dist"); string distname=config.next("basedist"); // default distance measure (dummy!) retriever_.weight(idx,1.0); // set default weight for configured distances retriever_.dist(idx,distanceMaker_.makeDistance(distname)); DBG(10) << "dist[" << idx << "]=" << retriever_.dist(idx)->name() << endl; } config.init_multiple_occurrence(); // can have multiple weights while(config.search(2,"-w","--weight")) { uint idx=config.follow(0,2,"-w","--weight"); double w=config.next(1.0); retriever_.weight(idx,w); DBG(10) << "weight[" << idx << "]=" << w << endl; } retriever_.setScoring(config.follow("linear",2,"-C","--scoring")); if(config.search(2,"-I","--interactor")) { retriever_.setInteractor(config.follow("",2,"-I","--interactor")); } config.enable_loop(); // enable returning to the beginning of command line (was disabled for multiplicity before) if(config.search(2,"-S","--startAfterInit")) { startAfterInit_=config.follow("echo \"No program defined\"",2,"-S","--startAfterInit"); } if(config.search(2,"-P","--proxy")) { proxyhost_=config.follow("localhost",2,"-P","--proxy"); proxyport_=config.next(12963); DBG(10) << "Will notify proxy at " << proxyhost_ << ":"<<proxyport_ << " about my existence." << endl; } if(config.search(2,"-r","--results")) { retriever_.results(config.follow(9,2,"-r","--results")); DBG(10) << "results=" << retriever_.results() << endl; } if(config.search(2,"-l","--log")) { logfile_=config.follow("log.txt",2,"-l","--log"); DBG(10) << "logfile="<< logfile_ << endl; } if(config.search(2,"-s","--server")) { port_=config.follow(12961,2,"-s","--server"); DBG(10) << "port="<< port_ << endl; } if(config.search(2,"-B","--batch")) { batchfile_=config.follow("batch",2,"-B","--batch"); DBG(10) << "batchfile="<< batchfile_ << endl; } if(config.search("--cache")) { retriever_.setCache(config.follow("cache.sqlite3.db","--cache")); } if(config.search(2,"-e","--expansion")) { retriever_.extensions(config.follow(2,2,"-e","--expansion")); DBG(10) << "expansions=" << config.follow(2,2,"-e","--expansion") << endl; } if(config.search(2,"-p","--password")) { password_=config.follow("",2,"-p","--password"); DBG(10) << "password necessary for changing settings: " << password_ << endl; } if(config.search(2,"-t","--type2bin")) { t2bpath=config.follow("",2,"-t","--type2bin"); DBG(10) << "type2bin-file has been reset to: " << t2bpath << endl; } }