10#include <tclap/CmdLine.h>
32 std::string
const& val_name,
36 std::size_t start(line.find(val_name));
37 std::size_t end(std::string::npos);
40 ERR(
"Value not found.");
43 value = line.substr(start + 1, std::string::npos);
46 start = value.find(
"\"");
47 value = value.substr(start + 1, std::string::npos);
48 end = value.find(
"\"");
52 start = value.find_first_not_of(
" ");
53 value = value.substr(start + 1, std::string::npos);
55 end = value.find_first_of(
" ");
57 value = value.substr(0, end);
63std::string
getName(std::string
const& line)
70 auto start = line.find(
"ZONETYPE=");
71 if (start == std::string::npos)
74 "A required 'ZONETYPE=' substring is not available in the ZONE "
75 "description: '{:s}'.",
78 start += std::size(
"ZONETYPE=") - 1;
80 auto end = line.find(
',', start);
81 if (end == std::string::npos)
84 "Expected the 'ZONETYPE=type' to be followed by a comma in the "
85 "ZONE description '{:s}'. The zone type starts at position {:d}.",
90 ERR(
"ZONETYPE string is empty in ZONE description '{:s}'.", line);
92 return std::string_view(&line[start], end - start);
96std::pair<std::size_t, std::size_t>
getDimensions(std::string
const& line)
98 std::pair<std::size_t, std::size_t> dims;
99 std::stringstream start(
getValue(line,
"I=",
false));
101 std::stringstream end(
getValue(line,
"J=",
false));
109 std::size_t
const start = var.find_first_not_of(
"\"");
110 var = var.substr(start, std::string::npos);
111 std::size_t
const end = var.find_first_of(
"\"");
112 return var.substr(0, end);
118 std::string
const var_str(
"VARIABLES");
119 std::size_t start(line.find(var_str));
120 std::string all_vars =
121 line.substr(start + var_str.length(), std::string::npos);
122 start = all_vars.find(
"=");
123 all_vars = all_vars.substr(start + 1, std::string::npos);
126 std::vector<std::string> variables;
128 while (end != std::string::npos)
130 end = all_vars.find_first_of(
" ");
131 std::string var = all_vars.substr(0, end);
133 all_vars = all_vars.substr(end + 1, std::string::npos);
142 std::size_t
const& current,
143 std::size_t
const& total)
145 if (current != total)
147 ERR(
"Data rows found do not fit specified dimensions for section "
158 std::string
const& name,
159 std::size_t
const& current,
160 std::size_t
const& total)
172 std::vector<std::vector<double>>& scalars,
173 std::size_t& val_count)
176 scalars.reserve(n_scalars);
177 for (std::size_t i = 0; i < n_scalars; ++i)
179 scalars.emplace_back(0);
186 std::string
const& file_name,
187 std::size_t& write_count,
188 std::size_t& val_count,
189 std::size_t& val_total)
191 if (write_count == 0 || val_total != 0)
193 std::size_t
const delim_pos(file_name.find_last_of(
"."));
194 std::string
const base_name(file_name.substr(0, delim_pos + 1));
195 std::string
const extension(
196 file_name.substr(delim_pos, std::string::npos));
200 INFO(
"Writing section #{}", write_count);
202 out.open(base_name + std::to_string(write_count++) + extension);
208 std::size_t& write_count,
209 std::vector<std::string>
const& vec_names,
210 std::vector<std::vector<double>>
const& scalars,
211 std::pair<std::size_t, std::size_t>
const& dims)
214 for (std::size_t i = 0; i < vec_names.size(); ++i)
216 if (vec_names[i] ==
"x" || vec_names[i] ==
"X")
218 cellsize = scalars[i][1] - scalars[i][0];
225 ERR(
"Cell size not found. Aborting...");
231 origin, cellsize, -9999};
233 std::unique_ptr<MeshLib::Mesh> mesh(
240 for (std::size_t i = 1; i < vec_names.size(); ++i)
246 ERR(
"Error creating array '{:s}'.", vec_names[i]);
249 prop->reserve(scalars[i].size());
250 std::copy(scalars[i].cbegin(), scalars[i].cend(),
251 std::back_inserter(*prop));
254 std::size_t
const delim_pos(file_name.find_last_of(
"."));
255 std::string
const base_name(file_name.substr(0, delim_pos + 1));
256 std::string
const extension(file_name.substr(delim_pos, std::string::npos));
258 INFO(
"Writing section #{}", write_count);
260 vtu.
writeToFile(base_name + std::to_string(write_count++) + extension);
267 while (std::getline(in, line))
269 if ((line.find(
"TITLE") != std::string::npos) ||
270 (line.find(
"VARIABLES") != std::string::npos) ||
271 (line.find(
"ZONE") != std::string::npos))
279int splitFile(std::ifstream& in, std::string
const& file_name)
284 std::size_t val_count(0);
285 std::size_t val_total(0);
286 std::size_t write_count(0);
287 while (std::getline(in, line))
289 if (line.find(
"TITLE") != std::string::npos)
300 if (line.find(
"VARIABLES") != std::string::npos)
311 if (line.find(
"ZONE") != std::string::npos)
321 std::pair<std::size_t, std::size_t> dims =
getDimensions(line);
322 val_total = dims.first * dims.second;
334 INFO(
"Writing time step #{}", write_count);
336 INFO(
"Finished split.");
346 std::pair<std::size_t, std::size_t> dims(0, 0);
347 std::vector<std::string> var_names;
348 std::vector<std::vector<double>> scalars;
349 std::size_t val_count(0);
350 std::size_t val_total(0);
351 std::size_t write_count(0);
352 while (std::getline(in, line))
354 if (line.find(
"GEOMETRY") != std::string::npos)
363 if (line.find(
"TITLE") != std::string::npos)
377 if (line.find(
"VARIABLES") != std::string::npos)
393 if (line.find(
"ZONE") != std::string::npos)
406 if (
auto const zonetype =
getZonetype(line); zonetype !=
"ORDERED")
408 ERR(
"Given zonetype '{:s}' is not supported. Only 'ORDERED' "
409 "zonetype data can be converted.",
414 val_total = dims.first * dims.second;
420 std::stringstream iss(line);
422 std::size_t
const n_scalars(scalars.size());
425 if (i > n_scalars - 1)
427 ERR(
"Too much data for existing scalar arrays");
430 scalars[i++].push_back(x);
434 ERR(
"Not enough data for existing scalar arrays");
444 INFO(
"Finished conversion.");
459int main(
int argc,
char* argv[])
463 "OpenGeoSys-6 software, version " +
466 "Copyright (c) 2012-2024, OpenGeoSys Community "
467 "(http://www.opengeosys.org)",
469 TCLAP::SwitchArg split_arg(
"s",
"split",
470 "split time steps into separate files");
472 TCLAP::SwitchArg convert_arg(
"c",
"convert",
473 "convert TecPlot data into OGS meshes");
474 cmd.add(convert_arg);
475 TCLAP::ValueArg<std::string> output_arg(
476 "o",
"output-file",
"output mesh file",
false,
"",
"string");
478 TCLAP::ValueArg<std::string> input_arg(
479 "i",
"input-file",
"TecPlot input file",
true,
"",
"string");
481 cmd.parse(argc, argv);
484 MPI_Init(&argc, &argv);
487 if (!input_arg.isSet())
489 ERR(
"No input file given. Please specify TecPlot (*.plt) file");
496 if (convert_arg.getValue() && !output_arg.isSet())
498 ERR(
"No output file given. Please specify OGS mesh (*.vtu) file");
505 std::ifstream in(input_arg.getValue().c_str());
508 ERR(
"Could not open file {:s}.", input_arg.getValue());
515 if (!convert_arg.isSet() && !split_arg.isSet())
517 INFO(
"Nothing to do. Use -s to split or -c to convert.");
524 std::string
const filename =
525 (output_arg.isSet()) ? output_arg.getValue() : input_arg.getValue();
527 if (split_arg.getValue())
531 else if (convert_arg.getValue())
Definition of the Point class.
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
Definition of the Mesh class.
Implementation of the VtuInterface class.
Reads and writes VtkXMLUnstructuredGrid-files (vtu) to and from OGS data structures....
bool writeToFile(std::filesystem::path const &file_path)
Property manager on mesh items. Class Properties manages scalar, vector or matrix properties....
PropertyVector< T > * createNewPropertyVector(std::string_view name, MeshItemType mesh_item_type, std::size_t n_components=1)
void trim(std::string &str, char ch)
GITINFOLIB_EXPORT const std::string ogs_version