From 5561307913af68f655ba83c31d3760a0e5892de4 Mon Sep 17 00:00:00 2001 From: Mark Olesen <Mark.Olesen@esi-group.com> Date: Tue, 12 Jun 2018 14:11:23 +0200 Subject: [PATCH] ENH: improve robustness of ensight surface reader (issue #868) - improve handling of model: ... line - simplify parsing of xxx element: ... lines --- .../readers/ensight/ensightSurfaceReader.C | 48 +++++++++++-------- .../readers/ensight/ensightSurfaceReader.H | 4 +- 2 files changed, 29 insertions(+), 23 deletions(-) diff --git a/src/sampling/sampledSurface/readers/ensight/ensightSurfaceReader.C b/src/sampling/sampledSurface/readers/ensight/ensightSurfaceReader.C index a8a18998117..11701aa55a7 100644 --- a/src/sampling/sampledSurface/readers/ensight/ensightSurfaceReader.C +++ b/src/sampling/sampledSurface/readers/ensight/ensightSurfaceReader.C @@ -24,6 +24,7 @@ License \*---------------------------------------------------------------------------*/ #include "ensightSurfaceReader.H" +#include "stringOps.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // @@ -158,15 +159,21 @@ void Foam::ensightSurfaceReader::readCase(IFstream& is) debugSection("GEOMETRY", is); readLine(is, buffer); - readFromLine(2, buffer, meshFileName_); // model: 1 xxx.0000.mesh + + // GEOMETRY with any of these + // model: 1 xxx.0000.mesh + // model: xxx.0000.mesh + // model: data/directory/geometry + // + // - use the last entry + meshFileName_ = stringOps::splitSpace(buffer).last().str(); debugSection("VARIABLE", is); // Read the field description DynamicList<word> fieldNames(10); DynamicList<string> fieldFileNames(10); - word fieldName; - string fieldFileName; + while (is.good()) { readLine(is, buffer); @@ -176,31 +183,30 @@ void Foam::ensightSurfaceReader::readCase(IFstream& is) break; } - IStringStream iss(buffer); + // Read the field name and associated file name. Eg, + // scalar per element: 1 p data/********/p - // Read the field name, e.g. p U etc - readFromLine(4, iss, fieldName); - fieldNames.append(fieldName); + const auto parsed = stringOps::splitSpace(buffer); - // Field file name may contain /'s e.g. - // surfaceName.****.fieldName - // This is not parser friendly - simply take remainder of buffer - label iPos = iss.stdStream().tellg(); - fieldFileName = buffer.substr(iPos); - size_t p0 = fieldFileName.find_first_not_of(' '); - if (p0 == string::npos) + if (buffer.find(':') == string::npos || parsed.size() < 4) { WarningInFunction - << "Error reading field file name. " - << "Current buffer: " << buffer - << endl; + << "Error reading field file name. Current buffer: " + << buffer << endl; + continue; } - else + else if (debug) { - size_t p1 = fieldFileName.find_last_not_of(' '); - fieldFileName = fieldFileName.substr(p0, p1 - p0 + 1); + Info<<"variable line: " << parsed.size(); + for (const auto& s : parsed) + { + Info<<" " << s.str(); + } + Info<<nl; } - fieldFileNames.append(fieldFileName); + + fieldNames.append(parsed[parsed.size()-2].str()); + fieldFileNames.append(parsed.last().str()); } fieldNames_.transfer(fieldNames); fieldFileNames_.transfer(fieldFileNames); diff --git a/src/sampling/sampledSurface/readers/ensight/ensightSurfaceReader.H b/src/sampling/sampledSurface/readers/ensight/ensightSurfaceReader.H index a5452c5c337..1a71e741502 100644 --- a/src/sampling/sampledSurface/readers/ensight/ensightSurfaceReader.H +++ b/src/sampling/sampledSurface/readers/ensight/ensightSurfaceReader.H @@ -63,8 +63,8 @@ protected: //- Base directory fileName baseDir_; - //- Name of mesh file - word meshFileName_; + //- Name of mesh file, including any subdirectory + fileName meshFileName_; //- Field names List<word> fieldNames_; -- GitLab