41 keys.
addFlag(
"--help/-h",
false,
"print this help");
52 plumed_massert(
keywords.
exists(key),
"keyword " + key +
" has not been registered");
53 plumed_massert(
keywords.
style(key,
"flag"),
"keyword " + key +
" has not been registered as a flag");
56 else if(
inputData[key]==
"false") t=
false;
61 plumed_massert(
inputdata!=
unset,
"You have not specified where your tool reads its input. "
62 "If it is from the command line (like driver) add inputdata=commandline to the "
63 "tools constructor. If it reads everything from an input file (like simplemd) "
64 "add inputdata=ifile to the tools constructor");
72 std::string prefix(
""),
a(
""), thiskey;
77 if(
keywords.
style(thiskey,
"flag") )
inputData.insert(std::pair<std::string,std::string>(thiskey,
"false"));
82 for(
int i=1;i<argc;i++){
84 if(
a.length()==0)
continue;
85 if(
a==
"-h" ||
a==
"--help"){
92 if(
a==thiskey ){ found=
true;
inputData[thiskey]=
"true"; }
95 prefix=thiskey+
"="; found=
true;
96 inputData.insert(std::pair<std::string,std::string>(thiskey,
""));
97 }
else if(
a.find(thiskey+
"=")==0){
98 a.erase(0,
a.find(
"=")+1); prefix=
""; found=
true;
100 inputData.insert(std::pair<std::string,std::string>(thiskey,
a));
108 fprintf(stderr,
"ERROR in input for command line tool %s : %s option is unknown \n\n",
name.c_str(),
a.c_str() );
109 fprintf(out,
"Usage: %s < inputFile \n",
name.c_str() );
110 fprintf(out,
"inputFile should contain one directive per line. The directives should come from amongst the following\n\n");
121 fprintf(out,
"Usage: %s [options] \n\n",
name.c_str() );
129 std::string def, thiskey;
135 plumed_assert( def.length()>0 );
136 inputData.insert(std::pair<std::string,std::string>(thiskey,def));
138 fprintf(out,
"ERROR : argument %s is compulsory. Use --help option for help\n",thiskey.c_str() );
151 for(
int i=1;i<argc;i++){
153 if(a.length()==0)
continue;
154 if(a==
"-h" || a==
"--help"){
155 fprintf(out,
"Usage: %s < inputFile \n",
name.c_str() );
156 fprintf(out,
"inputFile should contain one directive per line. The directives should come from amongst the following\n\n");
164 mystdin=fopen(argv[1],
"r");
166 fprintf(stderr,
"ERROR: cannot open file %s\n\n",argv[1]);
167 fprintf(out,
"Usage: %s < inputFile \n",
name.c_str() );
168 fprintf(out,
"inputFile should contain one directive per line. The directives should come from amongst the following\n\n");
174 char buffer[256]; std::string line; line.resize(256);
175 while(fgets(buffer,256,mystdin)){
177 for(
int i=0;i<line.length();++i)
if(line[i]==
'#' || line[i]==
'\n') line.erase(i);
179 if(line.length()==0)
continue;
180 sscanf(line.c_str(),
"%255s",buffer);
181 std::string keyword=buffer;
bool found=
false;
184 if(thiskey==keyword){
186 std::size_t keypos=line.find_first_of(keyword)+keyword.length();
187 inputData.insert(std::pair<std::string,std::string>(thiskey,line.substr(keypos)));
192 fprintf(stderr,
"ERROR in input for command line tool %s : unknown keyword %s found in input file\n\n",
name.c_str(),keyword.c_str());
193 fprintf(out,
"Usage: %s < inputFile \n",
name.c_str() );
194 fprintf(out,
"inputFile should contain one directive per line. The directives should come from amongst the following\n\n");
196 if(mystdin) fclose(mystdin);
201 if(argc==2) fclose(mystdin);
207 fprintf(stderr,
"ERROR : in input for command line tool %s : %s\n",
name.c_str(),msg.c_str());
bool getDefaultValue(std::string key, std::string &def) const
Get the value of the default for the keyword named key.
This class holds the keywords and their documentation.
std::string get(const unsigned k) const
Get the ith keyword.
void print(Log &log) const
Print the documentation to the log file (used by PLMD::Action::error)
bool style(const std::string &k, const std::string &t) const
Check if the keyword with name k has style t.
bool exists(const std::string &k) const
Check if there is a keyword with name k.
void addFlag(const std::string &k, const bool def, const std::string &d)
Add a falg with name k that is by default on if def is true and off if def is false. d should provide a description of the flag.
unsigned size() const
Return the number of defined keywords.