Skip to content

Commit

Permalink
IOSS: refactor the exodus match function
Browse files Browse the repository at this point in the history
  • Loading branch information
gsjaardema committed Sep 18, 2023
1 parent 7b1dcc2 commit 0f56703
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 15 deletions.
13 changes: 4 additions & 9 deletions packages/seacas/libraries/ioss/src/exodus/Ioex_Utils.C
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
#include <tokenize.h>

namespace {
size_t match(const char *name1, const char *name2)
size_t match(const std::string &name1, const std::string &name2)
{
size_t l1 = std::strlen(name1);
size_t l2 = std::strlen(name2);
size_t len = l1 < l2 ? l1 : l2;
size_t l1 = name1.size();
size_t l2 = name2.size();
size_t len = std::min(l1, l2);
for (size_t i = 0; i < len; i++) {
if (name1[i] != name2[i]) {
while (i > 0 && (isdigit(name1[i - 1]) != 0) && (isdigit(name2[i - 1]) != 0)) {
Expand All @@ -35,11 +35,6 @@ namespace {
return len;
}

size_t match(const std::string &name1, const std::string &name2)
{
return match(name1.c_str(), name2.c_str());
}

template <typename INT>
void internal_write_coordinate_frames(int exoid, const Ioss::CoordinateFrameContainer &frames,
INT /*dummy*/)
Expand Down
12 changes: 6 additions & 6 deletions packages/seacas/libraries/ioss/src/exonull/Ioexnl_Utils.C
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
#include <tokenize.h>

namespace {
size_t match(const char *name1, const char *name2)
size_t match(const std::string &name1, const std::string &name2)
{
size_t l1 = std::strlen(name1);
size_t l2 = std::strlen(name2);
size_t len = l1 < l2 ? l1 : l2;
size_t l1 = name1.size();
size_t l2 = name2.size();
size_t len = std::min(l1, l2);
for (size_t i = 0; i < len; i++) {
if (name1[i] != name2[i]) {
while (i > 0 && (isdigit(name1[i - 1]) != 0) && (isdigit(name2[i - 1]) != 0)) {
Expand Down Expand Up @@ -384,14 +384,14 @@ namespace Ioexnl {
// VECTOR_3D). If found, it returns the name.
//

static const std::string &displace = "displacement";
static const std::string displace = "displacement";

size_t max_span = 0;
for (const auto &name : fields) {
std::string lc_name(name);

Ioss::Utils::fixup_name(lc_name);
size_t span = match(lc_name.c_str(), displace.c_str());
size_t span = match(lc_name, displace);
if (span > max_span) {
const Ioss::VariableType *var_type = block->get_field(name).transformed_storage();
int comp_count = var_type->component_count();
Expand Down

0 comments on commit 0f56703

Please sign in to comment.