Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/meshio/vtk/_vtk_42.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ def read_buffer(f):
f.readline()

data_type = f.readline().decode().strip().upper()
if "Created by Gmsh" in data_type:
# Gmesh vtk files have one extra header line to skip before data_type
data_type = f.readline().decode().strip().upper()
if data_type not in ["ASCII", "BINARY"]:
raise ReadError(f"Unknown VTK data type '{data_type}'.")
info.is_ascii = data_type == "ASCII"
Expand Down Expand Up @@ -430,7 +433,7 @@ def _read_scalar_field(f, num_data, split, is_ascii):
dtype = dtype.newbyteorder(">")
data = np.fromfile(f, count=num_data * num_comp, dtype=dtype)
line = f.readline().decode()
if line != "\n":
if line not in ["\n", ""]: # special case: Gmsh vtk files use "" not "\n"
raise ReadError()

data = data.reshape(-1, num_comp)
Expand Down
5 changes: 4 additions & 1 deletion src/meshio/vtk/_vtk_51.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ def read_buffer(f):
f.readline()

data_type = f.readline().decode().strip().upper()
if "Created by Gmsh" in data_type:
# Gmesh vtk files have one extra header line to skip before data_type
data_type = f.readline().decode().strip().upper()
if data_type not in ["ASCII", "BINARY"]:
raise ReadError(f"Unknown VTK data type '{data_type}'.")
info.is_ascii = data_type == "ASCII"
Expand Down Expand Up @@ -402,7 +405,7 @@ def _read_scalar_field(f, num_data, split, is_ascii):
dtype = dtype.newbyteorder(">")
data = np.fromfile(f, count=num_data * num_comp, dtype=dtype)
line = f.readline().decode()
if line != "\n":
if line not in ["\n", ""]: # special case: Gmsh vtk files use "" not "\n"
raise ReadError()

data = data.reshape(-1, num_comp)
Expand Down