BUG: eof errors in the STARCD, VTK file reader (#1059)

- previously simply read files until the input stream went bad and no
  more lines could be read.  With the more stringent checking of
  values read (commit 0ce7e364a4) this approach causes problems.

  Use the underlying tokenizer instead to decide about termination.
This commit is contained in:
Mark Olesen
2018-11-03 15:46:37 +01:00
parent 1f9533ed5c
commit fd54070c3a
14 changed files with 402 additions and 457 deletions

View File

@ -38,32 +38,30 @@ namespace Foam
void Foam::ensightSurfaceReader::skip(const label n, Istream& is) const
{
label i = 0;
token t;
token tok;
while (is.good() && (i < n))
{
is >> t;
i++;
is >> tok;
++i;
if (debug)
{
Info<< "Skipping token " << t << endl;
}
DebugInfo
<< "Skipping token " << tok << nl;
}
if (i != n)
{
WarningInFunction
<< "Requested to skip " << n << "tokens, but stream exited after "
<< i << " tokens. Last token read: " << t
<< endl;
<< i << " tokens. Last token read: " << tok
<< nl;
}
}
void Foam::ensightSurfaceReader::readLine(IFstream& is, string& buffer) const
{
buffer = "";
while (is.good() && buffer == "")
buffer.clear();
while (is.good() && buffer.empty())
{
is.getLine(buffer);
}
@ -76,7 +74,7 @@ void Foam::ensightSurfaceReader::debugSection
IFstream& is
) const
{
string actual = "";
string actual;
readLine(is, actual);
if (expected != actual)
@ -87,10 +85,8 @@ void Foam::ensightSurfaceReader::debugSection
<< exit(FatalIOError);
}
if (debug)
{
Info<< "Read section header: " << expected << endl;
}
DebugInfo
<< "Read section header: " << expected << nl;
}
@ -103,45 +99,42 @@ void Foam::ensightSurfaceReader::readGeometryHeader(ensightReadFile& is) const
// Ensight Geometry File
is.read(buffer);
if (debug) Info<< "buffer: " << buffer << endl;
DebugInfo<< "buffer: " << buffer << nl;
// Description - 1
is.read(buffer);
if (debug) Info<< "buffer: " << buffer << endl;
DebugInfo<< "buffer: " << buffer << nl;
// Node info
is.read(buffer);
if (debug) Info<< "buffer: " << buffer << endl;
DebugInfo<< "buffer: " << buffer << nl;
// Element info
is.read(buffer);
if (debug) Info<< "buffer: " << buffer << endl;
DebugInfo<< "buffer: " << buffer << nl;
// Part
is.read(buffer);
if (debug) Info<< "buffer: " << buffer << endl;
DebugInfo<< "buffer: " << buffer << nl;
// Part number
label ibuffer;
is.read(ibuffer);
if (debug) Info<< "ibuffer: " << ibuffer << endl;
DebugInfo<< "ibuffer: " << ibuffer << nl;
// Description - 2
is.read(buffer);
if (debug) Info<< "buffer: " << buffer << endl;
DebugInfo<< "buffer: " << buffer << nl;
// Coordinates
is.read(buffer);
if (debug) Info<< "buffer: " << buffer << endl;
DebugInfo<< "buffer: " << buffer << nl;
}
void Foam::ensightSurfaceReader::readCase(IFstream& is)
{
if (debug)
{
InfoInFunction<< endl;
}
DebugInFunction<< nl;
if (!is.good())
{
@ -211,11 +204,9 @@ void Foam::ensightSurfaceReader::readCase(IFstream& is)
fieldNames_.transfer(fieldNames);
fieldFileNames_.transfer(fieldFileNames);
if (debug)
{
Info<< "fieldNames: " << fieldNames_ << nl
<< "fieldFileNames: " << fieldFileNames_ << endl;
}
DebugInfo
<< "fieldNames: " << fieldNames_ << nl
<< "fieldFileNames: " << fieldFileNames_ << nl;
// Start reading time information
readLine(is, buffer); // time set: <int>
@ -227,12 +218,10 @@ void Foam::ensightSurfaceReader::readCase(IFstream& is)
readLine(is, buffer);
readFromLine(2, buffer, timeIncrement_); // filename increment: <int>
if (debug)
{
Info<< "nTimeSteps: " << nTimeSteps_ << nl
<< "timeStartIndex: " << timeStartIndex_ << nl
<< "timeIncrement: " << timeIncrement_ << endl;
}
DebugInfo
<< "nTimeSteps: " << nTimeSteps_ << nl
<< "timeStartIndex: " << timeStartIndex_ << nl
<< "timeIncrement: " << timeIncrement_ << nl;
// Read the time values
readLine(is, buffer); // time values:
@ -274,10 +263,7 @@ Foam::ensightSurfaceReader::ensightSurfaceReader(const fileName& fName)
const Foam::meshedSurface& Foam::ensightSurfaceReader::geometry()
{
if (debug)
{
InfoInFunction<< endl;
}
DebugInFunction<< nl;
if (!surfPtr_.valid())
{
@ -337,20 +323,16 @@ const Foam::meshedSurface& Foam::ensightSurfaceReader::geometry()
ensightReadFile is(baseDir_/meshFileName_, streamFormat_);
if (debug)
{
Info<< "File: " << is.name() << endl;
}
DebugInfo
<< "File: " << is.name() << nl;
readGeometryHeader(is);
label nPoints;
is.read(nPoints);
if (debug)
{
Info<< "nPoints: " << nPoints << endl;
}
DebugInfo
<< "nPoints: " << nPoints << nl;
pointField points(nPoints);
{
@ -381,16 +363,14 @@ const Foam::meshedSurface& Foam::ensightSurfaceReader::geometry()
break;
}
if (debug)
{
Info<< "faceType: " << faceType << endl;
}
DebugInfo
<< "faceType: " << faceType << endl;
if (faceType == "tria3")
{
is.read(nFace);
label np = 3;
const label np = 3;
for (label faceI = 0; faceI < nFace; ++faceI)
{
face f(np);
@ -406,7 +386,7 @@ const Foam::meshedSurface& Foam::ensightSurfaceReader::geometry()
{
is.read(nFace);
label np = 4;
const label np = 4;
for (label faceI = 0; faceI < nFace; ++faceI)
{
face f(np);
@ -455,20 +435,16 @@ const Foam::meshedSurface& Foam::ensightSurfaceReader::geometry()
schema_.transfer(schema);
if (debug)
{
Info<< "read nFaces: " << faces.size() << nl
<< "file schema: " << schema_ << endl;
}
DebugInfo
<< "read nFaces: " << faces.size() << nl
<< "file schema: " << schema_ << nl;
// Convert from 1-based Ensight addressing to 0-based OF addressing
forAll(faces, faceI)
for (face& f : faces)
{
face& f = faces[faceI];
forAll(f, fpI)
for (label& pointi : f)
{
f[fpI]--;
--pointi;
}
}