properly close permas file after reading
@@ -17,16 +17,11 @@ def read(filename):
'''
# The format is specified at
# <http://www.intes.de>.
- if filename.endswith('post.gz'):
- f = gzip.open(filename, 'r')
- elif filename.endswith('dato.gz'):
- f = gzip.open(filename, 'r')
- elif filename.endswith('dato'):
- f = open(filename, 'r')
- elif filename.endswith('post'):
- f = open(filename, 'r')
+ if filename.endswith('post.gz') or filename.endswith('dato.gz'):
+ opener = gzip.open
else:
- print('Unsupported file format')
+ assert filename.endswith('dato') or filename.endswith('post')
+ opener = open
cells = {}
meshio_to_permas_type = {
@@ -38,7 +33,7 @@ def read(filename):
'wedge': (6, 'PENTA6'),
'pyramid': (5, 'PYRA5')
}
-
+ with opener(filename, 'r') as f:
while True:
line = f.readline()
if not line or re.search('\\$END STRUCTURE', line):
@@ -66,6 +61,7 @@ def read(filename):
break
for r in numpy.array(line.split(), dtype=float)[1:]:
points.append(r)
+
points = numpy.array(points)
points = numpy.reshape(points, newshape=(len(points)//3, 3))
for key in cells:
