53 po::options_description desc(
"Available options");
55 (
"help,h",
"Produce this help message.")
56 (
"modules-list,l",
"Print the list of available modules.")
57 (
"modules-opt,p", po::value<string>(),
58 "Print options for a module.")
59 (
"module,m", po::value<vector<string> >(),
60 "Specify modules which are to be used.")
61 (
"verbose,v",
"Enable verbose output.");
63 po::options_description hidden(
"Hidden options");
65 (
"input-file", po::value<vector<string> >(),
"Input filename");
67 po::options_description cmdline_options;
68 cmdline_options.add(hidden).add(desc);
70 po::options_description visible(
"Allowed options");
73 po::positional_options_description
p;
74 p.add(
"input-file", -1);
80 po::store(po::command_line_parser(argc, argv).
81 options(cmdline_options).positional(
p).
run(), vm);
84 catch (
const std::exception& e)
86 cerr << e.what() << endl;
92 auto logOutput = std::make_shared<StreamOutput>(std::cout);
93 Logger
log(logOutput, vm.count(
"verbose") ? VERBOSE : INFO);
96 if (vm.count(
"modules-list"))
102 if (vm.count(
"modules-opt"))
105 boost::split(tmp1, vm[
"modules-opt"].as<string>(), boost::is_any_of(
":"));
107 if (tmp1.size() != 2)
109 cerr <<
"ERROR: To specify a module, use one of in, out or proc "
110 <<
"together with the filename; for example in:vtk." << endl;
114 if (tmp1[0] !=
"in" && tmp1[0] !=
"out" && tmp1[0] !=
"proc")
116 cerr <<
"ERROR: Invalid module type " << tmp1[0] << endl;
126 else if (tmp1[0] ==
"out")
130 else if (tmp1[0] ==
"proc")
135 MeshSharedPtr m = std::shared_ptr<Mesh>(
new Mesh());
138 cerr <<
"Options for module " << tmp1[1] <<
":" << endl;
144 if (vm.count(
"help") || vm.count(
"input-file") != 1) {
145 cerr <<
"Usage: NekMesh [options] inputfile.ext1 outputfile.ext2"
151 vector<string> inout = vm[
"input-file"].as<vector<string> >();
153 if (inout.size() < 2)
155 cerr <<
"ERROR: You must specify an input and output file." << endl;
169 MeshSharedPtr mesh = std::shared_ptr<Mesh>(
new Mesh());
173 for(
int i = 1; i < argc; i++)
175 ss << argv[i] <<
" ";
177 mesh->m_metadata[
"NekMeshCommandLine"] = ss.str();
179 vector<ModuleSharedPtr> modules;
180 vector<string> modcmds;
182 if (vm.count(
"module"))
184 modcmds = vm[
"module"].as<vector<string> >();
188 modcmds.insert (modcmds.begin(), inout[0]);
189 modcmds.push_back(inout[1]);
192 size_t maxModName = 0;
194 for (
int i = 0; i < modcmds.size(); ++i)
201 boost::split(tmp1, modcmds[i], boost::is_any_of(
":"));
203 if (i == 0 || i == modcmds.size() - 1)
214 if (tmp1.size() == 1)
216 int dot = tmp1[0].find_last_of(
'.') + 1;
217 string ext = tmp1[0].substr(dot, tmp1[0].length() - dot);
221 string tmp = tmp1[0].substr(0, tmp1[0].length() - 3);
222 dot = tmp.find_last_of(
'.') + 1;
223 ext = tmp.substr(dot, tmp.length() - dot);
227 tmp1.push_back(
string(i == 0 ?
"infile=" :
"outfile=")+tmp1[0]);
231 module.second = tmp1[1];
232 tmp1.push_back(
string(i == 0 ?
"infile=" :
"outfile=")+tmp1[0]);
239 module.second = tmp1[0];
245 modules.push_back(mod);
248 for (
int j = offset; j < tmp1.size(); ++j)
251 boost::split(tmp2, tmp1[j], boost::is_any_of(
"="));
253 if (tmp2.size() == 1)
255 mod->RegisterConfig(tmp2[0]);
257 else if (tmp2.size() == 2)
259 mod->RegisterConfig(tmp2[0], tmp2[1]);
263 cerr <<
"ERROR: Invalid module configuration: format is "
264 <<
"either :arg or :arg=val" << endl;
273 std::string modName = mod->GetModuleName();
274 maxModName = std::max(maxModName, modName.length());
277 log.SetPrefixLen(maxModName);
280 for (
int i = 0; i < modules.size(); ++i)
286 modules[i]->GetLogger().SetPrefixLen(maxModName);
287 modules[i]->Process();
289 catch (NekMeshError &e)
295 log.SetPrefix(modules[i]->GetModuleName());
296 log(VERBOSE) <<
" - Elapsed time: "
tBaseSharedPtr CreateInstance(tKey idKey, tParam... args)
Create an instance of the class referred to by idKey.
void PrintAvailableClasses(std::ostream &pOut=std::cout)
Prints the available classes to stdout.
NekDouble TimePerTest(unsigned int n)
Returns amount of seconds per iteration in a test with n iterations.
std::pair< ModuleType, std::string > ModuleKey
std::shared_ptr< Module > ModuleSharedPtr
ModuleFactory & GetModuleFactory()
scalarT< T > log(scalarT< T > in)