diff --git a/src/sampling/sampledSurface/readers/ensight/ensightSurfaceReader.C b/src/sampling/sampledSurface/readers/ensight/ensightSurfaceReader.C index a8a18998117601a743119b7a4eff46f1ed30c539..11701aa55a7ba3e222163d5c923b49db99f55bcd 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 a5452c5c337cdc044d699b6854ccb302058b6862..1a71e7415026cb1f2d8e6438de398ddd1a731ba8 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_;