22{
23 TCLAP::CmdLine cmd(
24 "Reads Gocad ascii files (*.ts, *.pl, *.mx) and writes TSurf- and PLine"
25 "data into one or more VTU unstructured grids.\n\n"
26 "OpenGeoSys-6 software, version " +
28 ".\n"
29 "Copyright (c) 2012-2026, OpenGeoSys Community "
30 "(http://www.opengeosys.org)",
32
33 TCLAP::SwitchArg write_binary_arg(
34 "b", "write-binary",
35 "if set, OGS-Meshes will be written in binary format");
36 cmd.add(write_binary_arg);
37
38 TCLAP::SwitchArg export_surfaces_arg(
39 "s", "surfaces-only",
40 "if set, only TSurf datasets will be parsed from the input file");
41 cmd.add(export_surfaces_arg);
42
43 TCLAP::SwitchArg export_lines_arg(
44 "", "lines-only",
45 "if set, only PLine datasets will be parsed from the input file");
46 cmd.add(export_lines_arg);
47
48 TCLAP::ValueArg<std::string> output_arg(
49 "o", "output-dir", "Output directory", true, "", "OUTPUT_PATH");
50 cmd.add(output_arg);
51
52 TCLAP::ValueArg<std::string> input_arg(
53 "i", "input-file",
54 "Input (.ts | .pl | .mx). Gocad triangular surfaces file"
55 "Provide a file with unix file "
56 "endings under unix. Use dos2unix to convert. ",
57 true, "", "INPUT_FILE");
59 cmd.add(log_level_arg);
60 cmd.add(input_arg);
61
62 cmd.parse(argc, argv);
63
66
67 if (export_lines_arg.isSet() && export_surfaces_arg.isSet())
68 {
69 ERR(
"Both the 'lines-only'-flag and 'surfaces-only'-flag are set. Only "
70 "one is allowed at a time.");
71 return 2;
72 }
73
74 std::string const file_name(input_arg.getValue());
75
77 if (export_lines_arg.isSet())
78 {
80 }
81 if (export_surfaces_arg.isSet())
82 {
84 }
85 std::vector<std::unique_ptr<MeshLib::Mesh>> meshes;
87 {
88 ERR(
"Error reading file.");
89 return 1;
90 }
91 INFO(
"{:d} meshes found.", meshes.size());
92 std::string const dir = output_arg.getValue();
93 bool const write_binary = write_binary_arg.getValue();
94 std::string
const delim =
getDelim(dir);
95 for (auto& mesh : meshes)
96 {
97 if (mesh == nullptr)
98 {
99 continue;
100 }
101 INFO(
"Writing mesh \"{:s}\"", mesh->getName());
102 int data_mode = (write_binary) ? 2 : 0;
103 bool compressed = (write_binary);
105 vtu.writeToFile(dir + delim + mesh->getName() + ".vtu");
106 }
107 return 0;
108}
std::string getDelim(std::string const &str)
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
Reads and writes VtkXMLUnstructuredGrid-files (vtu) to and from OGS data structures....
TCLAP::ValueArg< std::string > makeLogLevelArg()
void initOGSLogger(std::string const &log_level)
bool readFile(std::string const &file_name, std::vector< std::unique_ptr< MeshLib::Mesh > > &meshes, DataType const export_type)
Reads the specified file and writes data into internal mesh vector.
GITINFOLIB_EXPORT const std::string ogs_version