56{
57 TCLAP::CmdLine cmd(
58 "Converts a double or floating point cell data array of a vtk "
59 "unstructured grid into a int or double cell data array.\n\n"
60 "OpenGeoSys-6 software, version " +
62 ".\n"
63 "Copyright (c) 2012-2024, OpenGeoSys Community "
64 "(http://www.opengeosys.org)",
66
67 TCLAP::ValueArg<std::string> new_property_data_type_arg(
68 "t",
69 "new-property-data-type",
70 "the name of the data type as string (int or double)",
71 false,
72 "int",
73 "data type as string");
74 cmd.add(new_property_data_type_arg);
75
76 TCLAP::ValueArg<std::string> new_property_arg(
77 "n",
78 "new-property-name",
79 "the name of the new cell data array (PropertyVector) the values are "
80 "stored",
81 false,
82 "MaterialIDs",
83 "name of the new cell data array (PropertyVector) as string");
84 cmd.add(new_property_arg);
85
86 TCLAP::ValueArg<std::string> out_mesh_arg(
87 "o", "out-mesh", "output mesh file name", true, "", "file name");
88 cmd.add(out_mesh_arg);
89
90 TCLAP::ValueArg<std::string> property_arg(
91 "e",
92 "existing-property-name",
93 "the name of the existing cell data array (PropertyVector)",
94 true,
95 "",
96 "property name as string");
97 cmd.add(property_arg);
98
99 TCLAP::ValueArg<std::string> mesh_arg(
100 "i", "in-mesh", "input mesh file name", true, "", "file name");
101 cmd.add(mesh_arg);
102
103 cmd.parse(argc, argv);
104
106
107 std::unique_ptr<MeshLib::Mesh> mesh(
109
110 if (!mesh)
111 {
112 return -1;
113 }
114
115 bool success = false;
116 std::string err_msg = "Could not find cell data array '" +
117 property_arg.getValue() + "' in the mesh '" +
118 mesh_arg.getValue() + "'";
119
120 if (new_property_data_type_arg.getValue() == "int")
121 {
122 if (mesh->getProperties().existsPropertyVector<double>(
124 {
125 std::tie(success, err_msg) =
127 mesh->getProperties(),
128 property_arg.getValue(),
129 new_property_arg.getValue());
130 }
131
132 if (mesh->getProperties().existsPropertyVector<float>(
134 {
135 std::tie(success, err_msg) =
137 mesh->getProperties(),
138 property_arg.getValue(),
139 new_property_arg.getValue());
140 }
141 }
142 if (new_property_data_type_arg.getValue() == "double")
143 {
144 if (mesh->getProperties().existsPropertyVector<float>(
146 {
147 std::tie(success, err_msg) =
149 mesh->getProperties(),
150 property_arg.getValue(),
151 new_property_arg.getValue());
152 }
153 }
154
155 if (!success)
156 {
157 ERR(
"{:s}", err_msg);
158 return -1;
159 }
160
162
163 return EXIT_SUCCESS;
164}
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
std::pair< bool, std::string > castPropertyVectorToPropertyVector(MeshLib::Properties &properties, std::string const &property_vector_name_in, std::string const &property_vector_name_out)
GITINFOLIB_EXPORT const std::string ogs_version
MeshLib::Mesh * readMeshFromFile(const std::string &file_name, bool const compute_element_neighbors)
int writeMeshToFile(const MeshLib::Mesh &mesh, std::filesystem::path const &file_path, std::set< std::string > variable_output_names)