-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
KISS-111, add api for writing double variables with mesh locations #7
Changes from 1 commit
70cfed9
db2894c
7fbad41
ba9e9d3
6ea5eed
d0917b8
8048b3a
6cacc4f
f0187ac
13965ae
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -163,6 +163,20 @@ namespace ugridapi | |
return it->second; | ||
} | ||
|
||
static auto get_coordinate_variable_string(int file_id, int topology_id, int topology_type, std::string const& var_name) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
{ | ||
auto topology = get_topology(file_id, topology_id, topology_type); | ||
|
||
auto coordinates_vector_variables = topology->get_topology_attribute_variable(var_name); | ||
std::string result; | ||
for (auto i = 0; i < coordinates_vector_variables.size() - 1; ++i) | ||
{ | ||
result += coordinates_vector_variables[i].getName() + " "; | ||
} | ||
result += coordinates_vector_variables.back().getName(); | ||
return result; | ||
} | ||
|
||
UGRID_API int ug_error_get(const char*& error_message) | ||
{ | ||
error_message = exceptionMessage; | ||
|
@@ -296,6 +310,56 @@ namespace ugridapi | |
return exit_code; | ||
} | ||
|
||
UGRID_API int ug_topology_define_double_variable_on_location(int file_id, int topology_id, int topology_type, int mesh_location, char const* variable_name) | ||
{ | ||
int exit_code = Success; | ||
try | ||
{ | ||
if (ugrid_states.count(file_id) == 0) | ||
{ | ||
throw std::invalid_argument("UGrid: The selected file_id does not exist."); | ||
} | ||
|
||
const auto name = ugrid::char_array_to_string(variable_name, ugrid::name_long_length); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This variable |
||
|
||
// Get the variable | ||
auto const local_variable_name = ugrid::char_array_to_string(variable_name, ugrid::name_long_length); | ||
|
||
auto variable = ugrid_states[file_id].m_ncFile->addVar(local_variable_name, netCDF::NcType::nc_DOUBLE); | ||
|
||
auto topology = get_topology(file_id, topology_id, topology_type); | ||
|
||
auto const mesh = topology->get_name(); | ||
|
||
const auto mesh_location_enum = static_cast<MeshLocations>(mesh_location); | ||
auto location = std::string(); | ||
auto coordinates = std::string(); | ||
if (mesh_location_enum == MeshLocations::Faces) | ||
{ | ||
location = "faces"; | ||
coordinates = get_coordinate_variable_string(file_id, topology_id, Mesh2dTopology, "face_coordinates"); | ||
} | ||
if (mesh_location_enum == MeshLocations::Nodes) | ||
{ | ||
coordinates = get_coordinate_variable_string(file_id, topology_id, Mesh2dTopology, "node_coordinates"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need a: |
||
} | ||
if (mesh_location_enum == MeshLocations::Edges) | ||
{ | ||
location = "edges"; | ||
coordinates = get_coordinate_variable_string(file_id, topology_id, Mesh2dTopology, "edge_coordinates"); | ||
} | ||
|
||
variable.putAtt("mesh", netCDF::NcType::nc_CHAR, mesh.size(), mesh.c_str()); | ||
variable.putAtt("location", netCDF::NcType::nc_CHAR, location.size(), location.c_str()); | ||
variable.putAtt("coordinates", netCDF::NcType::nc_CHAR, coordinates.size(), coordinates.c_str()); | ||
} | ||
catch (...) | ||
{ | ||
exit_code = HandleExceptions(std::current_exception()); | ||
} | ||
return exit_code; | ||
} | ||
|
||
UGRID_API int ug_variable_count_attributes(int file_id, char const* variable_name, int& attributes_count) | ||
{ | ||
int exit_code = Success; | ||
|
@@ -1032,4 +1096,20 @@ namespace ugridapi | |
return exit_code; | ||
} | ||
|
||
UGRID_API int ug_get_edges_location_type(int& type) | ||
{ | ||
type = static_cast<int>(MeshLocations::Edges); | ||
return Success; | ||
} | ||
UGRID_API int ug_get_nodes_location_type(int& type) | ||
{ | ||
type = static_cast<int>(MeshLocations::Nodes); | ||
return Success; | ||
} | ||
UGRID_API int ug_get_faces_location_type(int& type) | ||
{ | ||
type = static_cast<int>(MeshLocations::Faces); | ||
return Success; | ||
} | ||
|
||
} // namespace ugridapi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you need Doxygen documentation here?