Skip to content

Commit

Permalink
Merge pull request #937 from nschloe/vtk-fix2
Browse files Browse the repository at this point in the history
VTK fix
  • Loading branch information
nschloe authored Sep 30, 2020
2 parents 7b74eda + 752dc17 commit b6cb618
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
6 changes: 4 additions & 2 deletions meshio/vtk/_vtk.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,16 +470,17 @@ def _read_scalar_field(f, num_data, split, is_ascii):
raise ReadError()

if is_ascii:
data = numpy.fromfile(f, count=num_data, sep=" ", dtype=dtype)
data = numpy.fromfile(f, count=num_data * num_comp, sep=" ", dtype=dtype)
else:
# Binary data is big endian, see
# <https://www.vtk.org/Wiki/VTK/Writing_VTK_files_using_python#.22legacy.22>.
dtype = dtype.newbyteorder(">")
data = numpy.fromfile(f, count=num_data, dtype=dtype)
data = numpy.fromfile(f, count=num_data * num_comp, dtype=dtype)
line = f.readline().decode("utf-8")
if line != "\n":
raise ReadError()

data = data.reshape(-1, num_comp)
return {data_name: data}


Expand All @@ -488,6 +489,7 @@ def _read_field(f, num_data, split, shape, is_ascii):
data_type = split[2].lower()

dtype = numpy.dtype(vtk_to_numpy_dtype_name[data_type])
# prod()
# <https://stackoverflow.com/q/2104782/353337>
k = reduce((lambda x, y: x * y), shape)

Expand Down
9 changes: 8 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = meshio
version = 4.2.1
version = 4.2.2
author = Nico Schlömer et al.
author_email = [email protected]
description = I/O for many mesh formats
Expand All @@ -24,6 +24,13 @@ classifiers =
Programming Language :: Python :: 3.8
Topic :: Scientific/Engineering
Topic :: Utilities
keywords =
mesh
file formats
scientific
engineering
fem
finite elements

[options]
packages = find:
Expand Down
3 changes: 3 additions & 0 deletions test/meshes/vtk/gh-935.vtk
Git LFS file not shown
1 change: 1 addition & 0 deletions test/test_vtk.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ def test_reference_file(filename, ref_sum, ref_num_cells, binary):
("04_rectilinear.vtk", "quad", 27, 40),
("05_rectilinear.vtk", "quad", 27, 40),
("06_unstructured.vtk", "hexahedron", 12, 42),
("gh-935.vtk", "triangle", 2, 6),
],
)
def test_structured(filename, ref_cells, ref_num_cells, ref_num_pnt):
Expand Down

0 comments on commit b6cb618

Please sign in to comment.