37 #include <boost/algorithm/string.hpp> 40 #include <boost/program_options.hpp> 41 #include <boost/asio/ip/host_name.hpp> 42 #include <boost/format.hpp> 49 namespace po = boost::program_options;
50 namespace ip = boost::asio::ip;
52 int main(
int argc,
char* argv[])
54 po::options_description desc(
"Available options");
56 (
"help,h",
"Produce this help message.")
57 (
"modules-list,l",
"Print the list of available modules.")
58 (
"modules-opt,p", po::value<string>(),
59 "Print options for a module.")
60 (
"module,m", po::value<vector<string> >(),
61 "Specify modules which are to be used.")
62 (
"verbose,v",
"Enable verbose mode.");
64 po::options_description hidden(
"Hidden options");
66 (
"input-file", po::value<vector<string> >(),
"Input filename");
68 po::options_description cmdline_options;
69 cmdline_options.add(hidden).add(desc);
71 po::options_description visible(
"Allowed options");
74 po::positional_options_description
p;
75 p.add(
"input-file", -1);
81 po::store(po::command_line_parser(argc, argv).
82 options(cmdline_options).positional(p).
run(), vm);
85 catch (
const std::exception& e)
87 cerr << e.what() << endl;
93 if (vm.count(
"modules-list"))
99 if (vm.count(
"modules-opt"))
102 boost::split(tmp1, vm[
"modules-opt"].as<string>(), boost::is_any_of(
":"));
104 if (tmp1.size() != 2)
106 cerr <<
"ERROR: To specify a module, use one of in, out or proc " 107 <<
"together with the filename; for example in:vtk." << endl;
111 if (tmp1[0] !=
"in" && tmp1[0] !=
"out" && tmp1[0] !=
"proc")
113 cerr <<
"ERROR: Invalid module type " << tmp1[0] << endl;
123 else if (tmp1[0] ==
"out")
127 else if (tmp1[0] ==
"proc")
135 cerr <<
"Options for module " << tmp1[1] <<
":" << endl;
140 if (vm.count(
"help") || vm.count(
"input-file") != 1) {
141 cerr <<
"Usage: NekMesh [options] inputfile.ext1 outputfile.ext2" 147 vector<string> inout = vm[
"input-file"].as<vector<string> >();
149 if (inout.size() < 2)
151 cerr <<
"ERROR: You must specify an input and output file." << endl;
169 for(
int i = 1; i < argc; i++)
171 ss << argv[i] <<
" ";
173 mesh->m_metadata[
"NekMeshCommandLine"] = ss.str();
175 vector<ModuleSharedPtr> modules;
176 vector<string> modcmds;
178 if (vm.count(
"verbose"))
180 mesh->m_verbose =
true;
183 if (vm.count(
"module"))
185 modcmds = vm[
"module"].as<vector<string> >();
189 modcmds.insert (modcmds.begin(), inout[0]);
190 modcmds.push_back(inout[1]);
192 for (
int i = 0; i < modcmds.size(); ++i)
199 boost::split(tmp1, modcmds[i], boost::is_any_of(
":"));
201 if (i == 0 || i == modcmds.size() - 1)
212 if (tmp1.size() == 1)
214 int dot = tmp1[0].find_last_of(
'.') + 1;
215 string ext = tmp1[0].substr(dot, tmp1[0].length() - dot);
219 string tmp = tmp1[0].substr(0, tmp1[0].length() - 3);
220 dot = tmp.find_last_of(
'.') + 1;
221 ext = tmp.substr(dot, tmp.length() - dot);
225 tmp1.push_back(
string(i == 0 ?
"infile=" :
"outfile=")+tmp1[0]);
229 module.second = tmp1[1];
230 tmp1.push_back(
string(i == 0 ?
"infile=" :
"outfile=")+tmp1[0]);
237 module.second = tmp1[0];
242 modules.push_back(mod);
245 for (
int j = offset; j < tmp1.size(); ++j)
248 boost::split(tmp2, tmp1[j], boost::is_any_of(
"="));
250 if (tmp2.size() == 1)
252 mod->RegisterConfig(tmp2[0]);
254 else if (tmp2.size() == 2)
256 mod->RegisterConfig(tmp2[0], tmp2[1]);
260 cerr <<
"ERROR: Invalid module configuration: format is " 261 <<
"either :arg or :arg=val" << endl;
271 for (
int i = 0; i < modules.size(); ++i)
275 modules[i]->Process();
280 std::cout <<
"Module elapsed time: " << t.
TimePerTest(1) << std::endl;
NekDouble TimePerTest(unsigned int n)
Returns amount of seconds per iteration in a test with n iterations.
std::shared_ptr< Module > ModuleSharedPtr
void PrintAvailableClasses(std::ostream &pOut=std::cout)
Prints the available classes to stdout.
std::shared_ptr< Mesh > MeshSharedPtr
Shared pointer to a mesh.
tBaseSharedPtr CreateInstance(tKey idKey, tParam... args)
Create an instance of the class referred to by idKey.
std::pair< ModuleType, std::string > ModuleKey
int main(int argc, char *argv[])
std::pair< ModuleType, std::string > ModuleKey
ModuleFactory & GetModuleFactory()