37#include <boost/algorithm/string.hpp>
38#include <boost/asio/ip/host_name.hpp>
39#include <boost/format.hpp>
40#include <boost/program_options.hpp>
43#include <NekMesh/Module/Module.h>
46using namespace Nektar::NekMesh;
48namespace po = boost::program_options;
49namespace ip = boost::asio::ip;
51int main(
int argc,
char *argv[])
53 po::options_description desc(
"Available options");
57 (
"help,h",
"Produce this help message.")
58 (
"forceoutput,f",
"Force the output to be written without any checks")
59 (
"modules-list,l",
"Print the list of available modules.")
60 (
"modules-opt,p", po::value<string>(),
61 "Print options for a module.")
62 (
"module,m", po::value<vector<string> >(),
63 "Specify modules which are to be used.")
64 (
"verbose,v",
"Enable verbose output.");
67 po::options_description hidden(
"Hidden options");
71 (
"input-file", po::value<vector<string> >(),
"Input filename");
74 po::options_description cmdline_options;
75 cmdline_options.add(hidden).add(desc);
77 po::positional_options_description
p;
78 p.add(
"input-file", -1);
84 po::store(po::command_line_parser(argc, argv)
85 .options(cmdline_options)
91 catch (
const std::exception &e)
93 cerr << e.what() << endl;
100 if (std::getenv(
"NEKTAR_DISABLE_BACKUPS") !=
nullptr)
102 vm.insert(std::make_pair(
"forceoutput", po::variable_value()));
106 auto logOutput = std::make_shared<StreamOutput>(std::cout);
107 Logger
log(logOutput, vm.count(
"verbose") ? VERBOSE : INFO);
110 if (vm.count(
"modules-list"))
116 if (vm.count(
"modules-opt"))
119 boost::split(tmp1, vm[
"modules-opt"].as<string>(),
120 boost::is_any_of(
":"));
122 if (tmp1.size() != 2)
124 cerr <<
"ERROR: To specify a module, use one of in, out or proc "
125 <<
"together with the filename; for example in:vtk." << endl;
129 if (tmp1[0] !=
"in" && tmp1[0] !=
"out" && tmp1[0] !=
"proc")
131 cerr <<
"ERROR: Invalid module type (in, out, or proc): " << tmp1[0]
142 else if (tmp1[0] ==
"out")
146 else if (tmp1[0] ==
"proc")
151 MeshSharedPtr m = std::shared_ptr<Mesh>(
new Mesh());
154 cerr <<
"Options for module " << tmp1[1] <<
":" << endl;
160 if (vm.count(
"help") || vm.count(
"input-file") != 1)
162 cerr <<
"Usage: NekMesh [options] inputfile.ext1 outputfile.ext2"
168 vector<string> inout = vm[
"input-file"].as<vector<string>>();
170 if (inout.size() != 2)
172 cerr <<
"ERROR: You must specify an input and output file." << endl;
186 MeshSharedPtr mesh = std::shared_ptr<Mesh>(
new Mesh());
190 for (
int i = 1; i < argc; i++)
192 ss << argv[i] <<
" ";
194 mesh->m_metadata[
"NekMeshCommandLine"] = ss.str();
196 vector<ModuleSharedPtr> modules;
197 vector<string> modcmds;
199 if (vm.count(
"module"))
201 modcmds = vm[
"module"].as<vector<string>>();
204 bool forceOutput = vm.count(
"forceoutput");
207 modcmds.insert(modcmds.begin(), inout[0]);
208 modcmds.push_back(inout[1]);
211 size_t maxModName = 0;
213 for (
int i = 0; i < modcmds.size(); ++i)
220 boost::split(tmp1, modcmds[i], boost::is_any_of(
":"));
222 if (i == 0 || i == modcmds.size() - 1)
233 if (tmp1.size() == 1)
235 int dot = tmp1[0].find_last_of(
'.') + 1;
236 string ext = tmp1[0].substr(dot, tmp1[0].length() - dot);
240 string tmp = tmp1[0].substr(0, tmp1[0].length() - 3);
241 dot = tmp.find_last_of(
'.') + 1;
242 ext = tmp.substr(dot, tmp.length() - dot);
246 tmp1.push_back(
string(i == 0 ?
"infile=" :
"outfile=") +
251 module.second = tmp1[1];
252 tmp1.push_back(
string(i == 0 ?
"infile=" :
"outfile=") +
260 module.second = tmp1[0];
266 modules.push_back(mod);
269 for (
int j = offset; j < tmp1.size(); ++j)
272 boost::split(tmp2, tmp1[j], boost::is_any_of(
"="));
274 if (tmp2.size() == 1)
276 mod->RegisterConfig(tmp2[0]);
278 else if (tmp2.size() == 2)
280 mod->RegisterConfig(tmp2[0], tmp2[1]);
284 cerr <<
"ERROR: Invalid module configuration: format is "
285 <<
"either :arg or :arg=val" << endl;
290 if (i == modcmds.size() - 1 && forceOutput)
292 mod->RegisterConfig(
"forceoutput",
"true");
299 std::string modName = mod->GetModuleName();
300 maxModName = std::max(maxModName, modName.length());
303 log.SetPrefixLen(maxModName);
306 for (
int i = 0; i < modules.size(); ++i)
312 modules[i]->GetLogger().SetPrefixLen(maxModName);
313 modules[i]->Process();
315 catch (NekMeshError &e)
321 log.SetPrefix(modules[i]->GetModuleName());
int main(int argc, char *argv[])
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)