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>
46 using namespace Nektar::NekMesh;
48 namespace po = boost::program_options;
49 namespace ip = boost::asio::ip;
51 int 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::options_description visible(
"Allowed options");
80 po::positional_options_description
p;
81 p.add(
"input-file", -1);
87 po::store(po::command_line_parser(argc, argv)
88 .options(cmdline_options)
94 catch (
const std::exception &e)
96 cerr << e.what() << endl;
103 if (std::getenv(
"NEKTAR_DISABLE_BACKUPS") !=
nullptr)
105 vm.insert(std::make_pair(
"forceoutput", po::variable_value()));
109 auto logOutput = std::make_shared<StreamOutput>(std::cout);
110 Logger
log(logOutput, vm.count(
"verbose") ? VERBOSE : INFO);
113 if (vm.count(
"modules-list"))
119 if (vm.count(
"modules-opt"))
122 boost::split(tmp1, vm[
"modules-opt"].as<string>(),
123 boost::is_any_of(
":"));
125 if (tmp1.size() != 2)
127 cerr <<
"ERROR: To specify a module, use one of in, out or proc "
128 <<
"together with the filename; for example in:vtk." << endl;
132 if (tmp1[0] !=
"in" && tmp1[0] !=
"out" && tmp1[0] !=
"proc")
134 cerr <<
"ERROR: Invalid module type " << tmp1[0] << endl;
144 else if (tmp1[0] ==
"out")
148 else if (tmp1[0] ==
"proc")
153 MeshSharedPtr m = std::shared_ptr<Mesh>(
new Mesh());
156 cerr <<
"Options for module " << tmp1[1] <<
":" << endl;
162 if (vm.count(
"help") || vm.count(
"input-file") != 1)
164 cerr <<
"Usage: NekMesh [options] inputfile.ext1 outputfile.ext2"
170 vector<string> inout = vm[
"input-file"].as<vector<string>>();
172 if (inout.size() < 2)
174 cerr <<
"ERROR: You must specify an input and output file." << endl;
188 MeshSharedPtr mesh = std::shared_ptr<Mesh>(
new Mesh());
192 for (
int i = 1; i < argc; i++)
194 ss << argv[i] <<
" ";
196 mesh->m_metadata[
"NekMeshCommandLine"] = ss.str();
198 vector<ModuleSharedPtr> modules;
199 vector<string> modcmds;
201 if (vm.count(
"module"))
203 modcmds = vm[
"module"].as<vector<string>>();
206 bool forceOutput = vm.count(
"forceoutput");
209 modcmds.insert(modcmds.begin(), inout[0]);
210 modcmds.push_back(inout[1]);
213 size_t maxModName = 0;
215 for (
int i = 0; i < modcmds.size(); ++i)
222 boost::split(tmp1, modcmds[i], boost::is_any_of(
":"));
224 if (i == 0 || i == modcmds.size() - 1)
235 if (tmp1.size() == 1)
237 int dot = tmp1[0].find_last_of(
'.') + 1;
238 string ext = tmp1[0].substr(dot, tmp1[0].length() - dot);
242 string tmp = tmp1[0].substr(0, tmp1[0].length() - 3);
243 dot = tmp.find_last_of(
'.') + 1;
244 ext = tmp.substr(dot, tmp.length() - dot);
248 tmp1.push_back(
string(i == 0 ?
"infile=" :
"outfile=") +
253 module.second = tmp1[1];
254 tmp1.push_back(
string(i == 0 ?
"infile=" :
"outfile=") +
262 module.second = tmp1[0];
268 modules.push_back(mod);
271 for (
int j = offset; j < tmp1.size(); ++j)
274 boost::split(tmp2, tmp1[j], boost::is_any_of(
"="));
276 if (tmp2.size() == 1)
278 mod->RegisterConfig(tmp2[0]);
280 else if (tmp2.size() == 2)
282 mod->RegisterConfig(tmp2[0], tmp2[1]);
286 cerr <<
"ERROR: Invalid module configuration: format is "
287 <<
"either :arg or :arg=val" << endl;
292 if (i == modcmds.size() - 1 && forceOutput)
294 mod->RegisterConfig(
"forceoutput",
"true");
301 std::string modName = mod->GetModuleName();
302 maxModName = std::max(maxModName, modName.length());
305 log.SetPrefixLen(maxModName);
308 for (
int i = 0; i < modules.size(); ++i)
314 modules[i]->GetLogger().SetPrefixLen(maxModName);
315 modules[i]->Process();
317 catch (NekMeshError &e)
323 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)