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 p equipspaced points (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 (
"procid", po::value<int>(),
64 "Process as single procid of a partition of size nproc "
65 "(-nproc must be specified).")
66 (
"modules-opt,p", po::value<string>(),
67 "Print options for a module.")
68 (
"module,m", po::value<vector<string> >(),
69 "Specify modules which are to be used.")
70 (
"useSessionVariables",
71 "Use variables defined in session for output")
73 "Enable verbose mode.");
75 po::options_description hidden(
"Hidden options");
77 (
"input-file", po::value<vector<string> >(),
"Input filename");
79 po::options_description cmdline_options;
80 cmdline_options.add(hidden).add(desc);
82 po::options_description visible(
"Allowed options");
85 po::positional_options_description p;
86 p.add(
"input-file", -1);
92 po::store(po::command_line_parser(argc, argv).
93 options(cmdline_options).positional(p).run(), vm);
96 catch (
const std::exception& e)
98 cerr << e.what() << endl;
104 if (vm.count(
"modules-list"))
110 if (vm.count(
"modules-opt"))
113 boost::split(tmp1, vm[
"modules-opt"].as<string>(),
114 boost::is_any_of(
":"));
116 if (tmp1.size() != 2)
118 cerr <<
"ERROR: To specify a module, use one of in, out or proc "
119 <<
"together with the filename; for example in:vtk." << endl;
123 if (tmp1[0] !=
"in" && tmp1[0] !=
"out" && tmp1[0] !=
"proc")
125 cerr <<
"ERROR: Invalid module type " << tmp1[0] << endl;
135 else if (tmp1[0] ==
"out")
139 else if (tmp1[0] ==
"proc")
147 cerr <<
"Options for module " << tmp1[1] <<
":" << endl;
152 if (vm.count(
"help") || vm.count(
"input-file") != 1) {
153 cerr <<
"Usage: FieldConvert [options] inputfile.ext1 outputfile.ext2"
157 cout <<
"Example Usage: \n" << endl;
158 cout <<
"\t FieldConvert -m vorticity file.xml file.fld file_vort.fld "
160 cout <<
"(This will add vorticity to file file.fld and put it in a "
161 "new file file_vort.fld) " << endl;
163 cout <<
"\t FieldConvert file.xml file_vort.fld file_vort.dat " << endl;
164 cout <<
"(process file_vort.fld and make a tecplot output "
165 "file_vort.dat) " << endl;
171 "Must specify input(s) and/or output file.");
172 vector<string> inout = vm[
"input-file"].as<vector<string> >();
188 if(vm.count(
"procid"))
193 "Must specify --nprocs when using --procid option");
194 nprocs = vm[
"nprocs"].as<
int>();
195 rank = vm[
"procid"].as<
int>();
197 f->m_comm = boost::shared_ptr<FieldConvertComm>(
203 "ParallelMPI", argc, argv);
209 "Serial", argc, argv);
213 vector<ModuleSharedPtr> modules;
214 vector<string> modcmds;
216 if (vm.count(
"verbose"))
221 if (vm.count(
"module"))
223 modcmds = vm[
"module"].as<vector<string> >();
227 modcmds.insert(modcmds.begin(), inout.begin(), inout.end()-1);
228 modcmds.push_back(*(inout.end()-1));
229 int nInput = inout.size()-1;
233 for (
int i = 0; i < modcmds.size(); ++i)
240 boost::split(tmp1, modcmds[i], boost::is_any_of(
":"));
242 if (i < nInput || i == modcmds.size() - 1)
253 if (tmp1.size() == 1)
255 int dot = tmp1[0].find_last_of(
'.') + 1;
256 string ext = tmp1[0].substr(dot, tmp1[0].length() - dot);
260 string tmp2 = tmp1[0].substr(0,dot-1);
261 dot = tmp2.find_last_of(
'.') + 1;
262 ext = tmp1[0].substr(dot,tmp1[0].length()-dot);
266 tmp1.push_back(
string(i < nInput ?
"infile=" :
"outfile=")
271 module.second = tmp1[1];
272 tmp1.push_back(
string(i < nInput ?
"infile=" :
"outfile=")
280 module.second = tmp1[0];
286 modules.push_back(mod);
290 inputModule = boost::dynamic_pointer_cast<
InputModule>(mod);
291 inputModule->
AddFile(module.second, tmp1[0]);
295 for (
int j = offset; j < tmp1.size(); ++j)
298 boost::split(tmp2, tmp1[j], boost::is_any_of(
"="));
300 if (tmp2.size() == 1)
302 mod->RegisterConfig(tmp2[0],
"1");
304 else if (tmp2.size() == 2)
306 mod->RegisterConfig(tmp2[0], tmp2[1]);
310 cerr <<
"ERROR: Invalid module configuration: format is "
311 <<
"either :arg or :arg=val" << endl;
321 bool RequiresEquiSpaced =
false;
322 for (
int i = 0; i < modules.size(); ++i)
324 if(modules[i]->GetRequireEquiSpaced())
326 RequiresEquiSpaced =
true;
329 if (RequiresEquiSpaced)
331 for (
int i = 0; i < modules.size(); ++i)
333 modules[i]->SetRequireEquiSpaced(
true);
337 for (
int i = 0; i < modules.size(); ++i)
339 modules[i]->Process(vm);