Skip to content

Allow for one or more blank lines between sections in Tecplot ascii .dat file

Thibault Lestang requested to merge i84_handle_blank_lines_inputstartec into master

Issue addressed

The NekMesh Tecplot (ascii .dat) converter errors out if the input file contains one or more blank lines between two sections. For instance with

# star_test_tecplot.dat
...
 4 4 4 4 4 4 4 4 4 4
 4 4 4 4 4 4 4 4 4 4

# face nodes
 1 2 3 4 1 5 5 1 3 7
$ NekMesh star_test_tecplot.dat star_test_tecplot.xml 
[InputStarTec] ERROR: Failed to find 'face nodes' section, check your file format is correct.

This was raised a while ago by issue #84.

The error lies within the Tecplot converter's ReadZone method. It consists of a series of getline calls that seem to expect the various sections of the file to be contiguous with each other, without one of more blank lines. It looks like there already is some sort of safeguarding in place - that could be meant to allow for flexibility in the way the file is organized:

// In function InputTec::ReadZone

// Read Node count per face
getline(m_mshFile, line);
if (line.find("node count per face") == string::npos)
{
    if (line.find("face nodes") == string::npos)
    {
        getline(m_mshFile, line);
    }
}
	
vector<int> Nodes_per_face;
if (line.find("node count per face") != string::npos)
{
	   # Read the file ...

But I'm no too sure what the above is meant to do.

Proposed solution

The reader could jump to the next non empty line and test it for the name of a section, instead of calling getline a fixed number of times. This way we allow for an arbitrary number of blank lines between sections.

Implementation

I introduced a new function ReadNextNonEmptyLine

static void ReadNextNonEmptyLine(io::filtering_istream &mshFile, string &line);

and replaced most of the getline calls and line.find() based checks by calls to ReadNextNonEmptyLine.

I had to include boost/iostreams/filtering_stream.hpp, which make me think that maybe this function should be a method of InputModule?

The InputTec::ReadZone function defines a stringstream s. I'm not sure what it is used for, but it is not used before reading the Zone header. I removed apprently unneeded calls to s.clear() and s.str(line).

Tests

This adds a blank line before the "face nodes" section of the test data peralign_bl_cube.dat.

Notes

Pease add any other information that could be useful for reviewers.

Checklist

  • Modified/added functions or classes have up to date docstrings
  • User guide/documentation is updated.
  • Changelog is updated.
  • Changes are tested.
  • Newly added files are correctly formatted.
Edited by James Slaughter

Merge request reports