mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-28 22:26:08 -04:00
fix reading 2D string vector from attribute in hdf5
This commit is contained in:
parent
950c684e6c
commit
59046be677
1 changed files with 4 additions and 8 deletions
|
|
@ -204,23 +204,19 @@ read_attribute(hid_t obj_id, const char* name, std::vector<std::string>& vec)
|
|||
|
||||
// Allocate a C char array to get strings
|
||||
auto n = attribute_typesize(obj_id, name);
|
||||
char** buffer = new char*[m];
|
||||
for (int i = 0; i < m; i++) {
|
||||
buffer[i] = new char[n];
|
||||
}
|
||||
char* buffer = new char[m*n];
|
||||
|
||||
// Read char data in attribute
|
||||
read_attr_string(obj_id, name, n, buffer[0]);
|
||||
read_attr_string(obj_id, name, n, buffer);
|
||||
|
||||
for (int i = 0; i < m; ++i) {
|
||||
// Determine proper length of string -- strlen doesn't work because
|
||||
// buffer[i] might not have any null characters
|
||||
std::size_t k = 0;
|
||||
for (; k < n; ++k) if (buffer[i][k] == '\0') break;
|
||||
for (; k < n; ++k) if (buffer[i*n + k] == '\0') break;
|
||||
|
||||
// Create string based on (char*, size_t) constructor
|
||||
vec.emplace_back(&buffer[i][0], k);
|
||||
delete[] buffer[i];
|
||||
vec.emplace_back(&buffer[i*n], k);
|
||||
}
|
||||
delete[] buffer;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue