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");
54 po::options_description dep(
"Deprecated options");
58 (
"help,h",
"Produce this help message.")
59 (
"force-output,f",
"Force the output to be written without any checks")
60 (
"modules-list,l",
"Print the list of available modules.")
61 (
"modules-opt,p", po::value<string>(),
62 "Print options for a module.")
63 (
"module,m", po::value<vector<string> >(),
64 "Specify modules which are to be used.")
65 (
"verbose,v",
"Enable verbose output.");
68 po::options_description hidden(
"Hidden options");
72 (
"input-file", po::value<vector<string> >(),
"Input filename");
77 std::map<std::string, std::string> deprecated = {
78 {
"forceoutput",
"force-output"}};
80 for (
auto &
d : deprecated)
82 std::string
description =
"Deprecated: use --" +
d.second;
86 po::options_description cmdline_options;
87 cmdline_options.add(hidden).add(desc).add(dep);
89 po::positional_options_description
p;
90 p.add(
"input-file", -1);
96 po::store(po::command_line_parser(argc, argv)
97 .options(cmdline_options)
103 catch (
const std::exception &e)
105 cerr << e.what() << endl;
112 if (std::getenv(
"NEKTAR_DISABLE_BACKUPS") !=
nullptr)
114 vm.insert(std::make_pair(
"force-output", po::variable_value()));
118 auto logOutput = std::make_shared<StreamOutput>(std::cout);
119 Logger
log(logOutput, vm.count(
"verbose") ? VERBOSE : INFO);
122 for (
auto &
d : deprecated)
124 if (vm.count(
d.first))
126 log(WARNING) <<
"--" <<
d.first <<
" deprecated: use --" <<
d.second
128 vm.emplace(
d.second, po::variable_value(vm[
d.first]));
133 if (vm.count(
"modules-list"))
139 if (vm.count(
"modules-opt"))
142 boost::split(tmp1, vm[
"modules-opt"].as<string>(),
143 boost::is_any_of(
":"));
145 if (tmp1.size() != 2)
147 cerr <<
"ERROR: To specify a module, use one of in, out or proc "
148 <<
"together with the filename; for example in:vtk." << endl;
152 if (tmp1[0] !=
"in" && tmp1[0] !=
"out" && tmp1[0] !=
"proc")
154 cerr <<
"ERROR: Invalid module type (in, out, or proc): " << tmp1[0]
165 else if (tmp1[0] ==
"out")
169 else if (tmp1[0] ==
"proc")
174 MeshSharedPtr m = std::shared_ptr<Mesh>(
new Mesh());
177 cerr <<
"Options for module " << tmp1[1] <<
":" << endl;
183 if (vm.count(
"help") || vm.count(
"input-file") != 1)
185 cerr <<
"Usage: NekMesh [options] inputfile.ext1 outputfile.ext2"
191 vector<string> inout = vm[
"input-file"].as<vector<string>>();
193 if (inout.size() != 2)
195 cerr <<
"ERROR: You must specify an input and output file." << endl;
209 MeshSharedPtr mesh = std::shared_ptr<Mesh>(
new Mesh());
213 for (
int i = 1; i < argc; i++)
215 ss << argv[i] <<
" ";
217 mesh->m_metadata[
"NekMeshCommandLine"] = ss.str();
219 vector<ModuleSharedPtr> modules;
220 vector<string> modcmds;
222 if (vm.count(
"module"))
224 modcmds = vm[
"module"].as<vector<string>>();
227 bool forceOutput = vm.count(
"force-output");
230 modcmds.insert(modcmds.begin(), inout[0]);
231 modcmds.push_back(inout[1]);
234 size_t maxModName = 0;
236 for (
int i = 0; i < modcmds.size(); ++i)
243 boost::split(tmp1, modcmds[i], boost::is_any_of(
":"));
245 if (i == 0 || i == modcmds.size() - 1)
256 if (tmp1.size() == 1)
258 int dot = tmp1[0].find_last_of(
'.') + 1;
259 string ext = tmp1[0].substr(dot, tmp1[0].length() - dot);
263 string tmp = tmp1[0].substr(0, tmp1[0].length() - 3);
264 dot = tmp.find_last_of(
'.') + 1;
265 ext = tmp.substr(dot, tmp.length() - dot);
269 tmp1.push_back(
string(i == 0 ?
"infile=" :
"outfile=") +
274 module.second = tmp1[1];
275 tmp1.push_back(
string(i == 0 ?
"infile=" :
"outfile=") +
283 module.second = tmp1[0];
289 modules.push_back(mod);
292 for (
int j = offset; j < tmp1.size(); ++j)
295 boost::split(tmp2, tmp1[j], boost::is_any_of(
"="));
297 if (tmp2.size() == 1)
299 mod->RegisterConfig(tmp2[0]);
301 else if (tmp2.size() == 2)
303 mod->RegisterConfig(tmp2[0], tmp2[1]);
307 cerr <<
"ERROR: Invalid module configuration: format is "
308 <<
"either :arg or :arg=val" << endl;
313 if (i == modcmds.size() - 1 && forceOutput)
315 mod->RegisterConfig(
"forceoutput",
"true");
322 std::string modName = mod->GetModuleName();
323 maxModName = std::max(maxModName, modName.length());
326 log.SetPrefixLen(maxModName);
329 for (
int i = 0; i < modules.size(); ++i)
335 modules[i]->GetLogger().SetPrefixLen(maxModName);
336 modules[i]->Process();
338 catch (NekMeshError &e)
344 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.
def description(self, force=False, cellml=False)
std::pair< ModuleType, std::string > ModuleKey
std::shared_ptr< Module > ModuleSharedPtr
ModuleFactory & GetModuleFactory()
std::vector< double > d(NPUPPER *NPUPPER)
scalarT< T > log(scalarT< T > in)