37 #include <boost/algorithm/string.hpp>
38 #include <boost/program_options.hpp>
43 using namespace Nektar::Utilities;
45 int main(
int argc,
char* argv[])
47 po::options_description desc(
"Available options");
50 "Produce this help message.")
52 "Print the list of available modules.")
53 (
"output-points,n", po::value<int>(),
54 "Output at n equipspaced points along the collapsed coordinates (for .dat, .vtk).")
56 "Write error of fields for regression checking")
57 (
"range,r", po::value<string>(),
58 "Define output range i.e. (-r xmin,xmax,ymin,ymax,zmin,zmax) "
59 "in which any vertex is contained.")
60 (
"nprocs", po::value<int>(),
61 "Used to define nprocs if running serial problem to mimic "
63 (
"onlyshape", po::value<string>(),
64 "Only use element with defined shape type i.e. -onlyshape "
66 (
"procid", po::value<int>(),
67 "Process as single procid of a partition of size nproc "
68 "(-nproc must be specified).")
69 (
"modules-opt,p", po::value<string>(),
70 "Print options for a module.")
71 (
"module,m", po::value<vector<string> >(),
72 "Specify modules which are to be used.")
73 (
"useSessionVariables",
74 "Use variables defined in session for output")
76 "Enable verbose mode.");
78 po::options_description hidden(
"Hidden options");
80 (
"input-file", po::value<vector<string> >(),
"Input filename");
82 po::options_description cmdline_options;
83 cmdline_options.add(hidden).add(desc);
85 po::options_description visible(
"Allowed options");
88 po::positional_options_description p;
89 p.add(
"input-file", -1);
95 po::store(po::command_line_parser(argc, argv).
96 options(cmdline_options).positional(p).run(), vm);
99 catch (
const std::exception& e)
101 cerr << e.what() << endl;
107 if (vm.count(
"modules-list"))
113 if (vm.count(
"modules-opt"))
116 boost::split(tmp1, vm[
"modules-opt"].as<string>(),
117 boost::is_any_of(
":"));
119 if (tmp1.size() != 2)
121 cerr <<
"ERROR: To specify a module, use one of in, out or proc "
122 <<
"together with the filename; for example in:vtk." << endl;
126 if (tmp1[0] !=
"in" && tmp1[0] !=
"out" && tmp1[0] !=
"proc")
128 cerr <<
"ERROR: Invalid module type " << tmp1[0] << endl;
138 else if (tmp1[0] ==
"out")
142 else if (tmp1[0] ==
"proc")
150 cerr <<
"Options for module " << tmp1[1] <<
":" << endl;
155 if (vm.count(
"help") || vm.count(
"input-file") != 1) {
156 cerr <<
"Usage: FieldConvert [options] inputfile.ext1 outputfile.ext2"
160 cout <<
"Example Usage: \n" << endl;
161 cout <<
"\t FieldConvert -m vorticity file.xml file.fld file_vort.fld "
163 cout <<
"(This will add vorticity to file file.fld and put it in a "
164 "new file file_vort.fld) " << endl;
166 cout <<
"\t FieldConvert file.xml file_vort.fld file_vort.dat " << endl;
167 cout <<
"(process file_vort.fld and make a tecplot output "
168 "file_vort.dat) " << endl;
174 "Must specify input(s) and/or output file.");
175 vector<string> inout = vm[
"input-file"].as<vector<string> >();
191 if(vm.count(
"procid"))
196 "Must specify --nprocs when using --procid option");
197 nprocs = vm[
"nprocs"].as<
int>();
198 rank = vm[
"procid"].as<
int>();
200 f->m_comm = boost::shared_ptr<FieldConvertComm>(
206 "ParallelMPI", argc, argv);
212 "Serial", argc, argv);
216 vector<ModuleSharedPtr> modules;
217 vector<string> modcmds;
219 if (vm.count(
"verbose"))
224 if (vm.count(
"module"))
226 modcmds = vm[
"module"].as<vector<string> >();
230 modcmds.insert(modcmds.begin(), inout.begin(), inout.end()-1);
231 modcmds.push_back(*(inout.end()-1));
232 int nInput = inout.size()-1;
236 for (
int i = 0; i < modcmds.size(); ++i)
243 boost::split(tmp1, modcmds[i], boost::is_any_of(
":"));
245 if (i < nInput || 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 tmp2 = tmp1[0].substr(0,dot-1);
264 dot = tmp2.find_last_of(
'.') + 1;
265 ext = tmp1[0].substr(dot,tmp1[0].length()-dot);
269 tmp1.push_back(
string(i < nInput ?
"infile=" :
"outfile=")
274 module.second = tmp1[1];
275 tmp1.push_back(
string(i < nInput ?
"infile=" :
"outfile=")
283 module.second = tmp1[0];
289 modules.push_back(mod);
293 inputModule = boost::dynamic_pointer_cast<
InputModule>(mod);
294 inputModule->
AddFile(module.second, tmp1[0]);
298 for (
int j = offset; j < tmp1.size(); ++j)
301 boost::split(tmp2, tmp1[j], boost::is_any_of(
"="));
303 if (tmp2.size() == 1)
305 mod->RegisterConfig(tmp2[0],
"1");
307 else if (tmp2.size() == 2)
309 mod->RegisterConfig(tmp2[0], tmp2[1]);
313 cerr <<
"ERROR: Invalid module configuration: format is "
314 <<
"either :arg or :arg=val" << endl;
324 bool RequiresEquiSpaced =
false;
325 for (
int i = 0; i < modules.size(); ++i)
327 if(modules[i]->GetRequireEquiSpaced())
329 RequiresEquiSpaced =
true;
332 if (RequiresEquiSpaced)
334 for (
int i = 0; i < modules.size(); ++i)
336 modules[i]->SetRequireEquiSpaced(
true);
340 for (
int i = 0; i < modules.size(); ++i)
342 modules[i]->Process(vm);