Skip to content

Commit

Permalink
Merge pull request #12147 from KratosMultiphysics/med/trim-whitespace
Browse files Browse the repository at this point in the history
[MedApp] Trim Whitespace in Group Names
  • Loading branch information
matekelemen authored Aug 26, 2024
2 parents 85aa661 + e6c89d8 commit d204c95
Showing 1 changed file with 3 additions and 10 deletions.
13 changes: 3 additions & 10 deletions applications/MedApplication/custom_io/med_model_part_io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "utilities/builtin_timer.h"
#include "utilities/parallel_utilities.h"
#include "utilities/variable_utils.h"
#include "utilities/string_utilities.h"

namespace Kratos {

Expand Down Expand Up @@ -67,13 +68,6 @@ void CheckMEDErrorCode(const int ierr, const std::string& MEDCallName)
KRATOS_ERROR_IF(ierr < 0) << MEDCallName << " failed with error code " << ierr << "." << std::endl;
}

// The names in the MED-file often have trailing null-chars, which need to be removed
// this can otherwise make debugging very tricky
void RemoveTrailingNullChars(std::string& rInput)
{
rInput.erase(std::find(rInput.begin(), rInput.end(), '\0'), rInput.end());
}

template<typename T>
void CheckConnectivitiesSize(
const std::size_t ExpectedSize,
Expand Down Expand Up @@ -329,8 +323,7 @@ auto GetGroupsByFamily(
std::vector<std::string> group_names(num_groups);
// split the goup names
for (int i = 0; i < num_groups; i++) {
group_names[i] = c_group_names.substr(i * MED_LNAME_SIZE, MED_LNAME_SIZE);
RemoveTrailingNullChars(group_names[i]);
group_names[i] = StringUtilities::Trim(c_group_names.substr(i * MED_LNAME_SIZE, MED_LNAME_SIZE), /*RemoveNullChar=*/true);
}

groups_by_family[family_number] = std::move(group_names);
Expand Down Expand Up @@ -424,7 +417,7 @@ class MedModelPartIO::MedFileHandler
axis_unit.data());
CheckMEDErrorCode(err, "MEDmeshInfo");

RemoveTrailingNullChars(mMeshName);
mMeshName = StringUtilities::Trim(mMeshName, /*RemoveNullChar=*/true);
mDimension = space_dim;
}

Expand Down

0 comments on commit d204c95

Please sign in to comment.