37 #include <boost/algorithm/string.hpp>
38 #include <boost/program_options.hpp>
46 namespace po = boost::program_options;
48 int main(
int argc,
char* argv[])
50 po::options_description desc(
"Available options");
52 (
"help,h",
"Produce this help message.")
53 (
"modules-list,l",
"Print the list of available modules.")
54 (
"modules-opt,p", po::value<string>(),
55 "Print options for a module.")
56 (
"module,m", po::value<vector<string> >(),
57 "Specify modules which are to be used.")
58 (
"verbose,v",
"Enable verbose mode.");
60 po::options_description hidden(
"Hidden options");
62 (
"input-file", po::value<vector<string> >(),
"Input filename");
64 po::options_description cmdline_options;
65 cmdline_options.add(hidden).add(desc);
67 po::options_description visible(
"Allowed options");
70 po::positional_options_description p;
71 p.add(
"input-file", -1);
77 po::store(po::command_line_parser(argc, argv).
78 options(cmdline_options).positional(p).run(), vm);
81 catch (
const std::exception& e)
83 cerr << e.what() << endl;
89 if (vm.count(
"modules-list"))
95 if (vm.count(
"modules-opt"))
98 boost::split(tmp1, vm[
"modules-opt"].as<string>(), boost::is_any_of(
":"));
100 if (tmp1.size() != 2)
102 cerr <<
"ERROR: To specify a module, use one of in, out or proc "
103 <<
"together with the filename; for example in:vtk." << endl;
107 if (tmp1[0] !=
"in" && tmp1[0] !=
"out" && tmp1[0] !=
"proc")
109 cerr <<
"ERROR: Invalid module type " << tmp1[0] << endl;
119 else if (tmp1[0] ==
"out")
123 else if (tmp1[0] ==
"proc")
131 cerr <<
"Options for module " << tmp1[1] <<
":" << endl;
136 if (vm.count(
"help") || vm.count(
"input-file") != 1) {
137 cerr <<
"Usage: NekMesh [options] inputfile.ext1 outputfile.ext2"
143 vector<string> inout = vm[
"input-file"].as<vector<string> >();
145 if (inout.size() < 2)
147 cerr <<
"ERROR: You must specify an input and output file." << endl;
162 vector<ModuleSharedPtr> modules;
163 vector<string> modcmds;
165 if (vm.count(
"verbose"))
167 mesh->m_verbose =
true;
170 if (vm.count(
"module"))
172 modcmds = vm[
"module"].as<vector<string> >();
176 modcmds.insert (modcmds.begin(), inout[0]);
177 modcmds.push_back(inout[1]);
179 for (
int i = 0; i < modcmds.size(); ++i)
186 boost::split(tmp1, modcmds[i], boost::is_any_of(
":"));
188 if (i == 0 || i == modcmds.size() - 1)
199 if (tmp1.size() == 1)
201 int dot = tmp1[0].find_last_of(
'.') + 1;
202 string ext = tmp1[0].substr(dot, tmp1[0].length() - dot);
204 tmp1.push_back(
string(i == 0 ?
"infile=" :
"outfile=")+tmp1[0]);
208 module.second = tmp1[1];
209 tmp1.push_back(
string(i == 0 ?
"infile=" :
"outfile=")+tmp1[0]);
216 module.second = tmp1[0];
221 modules.push_back(mod);
224 for (
int j = offset; j < tmp1.size(); ++j)
227 boost::split(tmp2, tmp1[j], boost::is_any_of(
"="));
229 if (tmp2.size() == 1)
231 mod->RegisterConfig(tmp2[0],
"1");
233 else if (tmp2.size() == 2)
235 mod->RegisterConfig(tmp2[0], tmp2[1]);
239 cerr <<
"ERROR: Invalid module configuration: format is "
240 <<
"either :arg or :arg=val" << endl;
250 for (
int i = 0; i < modules.size(); ++i)
252 modules[i]->Process();
void PrintAvailableClasses(std::ostream &pOut=std::cout)
Prints the available classes to stdout.
pair< ModuleType, string > ModuleKey
tBaseSharedPtr CreateInstance(tKey idKey BOOST_PP_COMMA_IF(MAX_PARAM) BOOST_PP_ENUM_BINARY_PARAMS(MAX_PARAM, tParam, x))
Create an instance of the class referred to by idKey.
boost::shared_ptr< Module > ModuleSharedPtr
int main(int argc, char *argv[])
boost::shared_ptr< Mesh > MeshSharedPtr
Shared pointer to a mesh.
ModuleFactory & GetModuleFactory()