def read(filename):
<EOL>cells = {}<EOL>meshio_to_permas_type = {<EOL>"<STR_LIT>": (<NUM_LIT:1>, "<STR_LIT>"),<EOL>"<STR_LIT>": (<NUM_LIT:2>, "<STR_LIT>"),<EOL>"<STR_LIT>": (<NUM_LIT:3>, "<STR_LIT>"),<EOL>"<STR_LIT>": (<NUM_LIT:4>, "<STR_LIT>"),<EOL>"<STR_LIT>": (<NUM_LIT:4>, "<STR_LIT>"),<EOL>"<STR_LIT>": (<NUM_LIT:8>, "<STR_LIT>"),<EOL>"<STR_LIT>": (<NUM_LIT:6>, "<STR_LIT>"),<EOL>"<STR_LIT>": (<NUM_LIT:5>, "<STR_LIT>"),<EOL>}<EOL>opener = gzip.open if filename.endswith("<STR_LIT>") else open<EOL>with opener(filename, "<STR_LIT:rb>") as f:<EOL><INDENT>while True:<EOL><INDENT>line = f.readline().decode("<STR_LIT:utf-8>")<EOL>if not line or re.search("<STR_LIT>", line):<EOL><INDENT>break<EOL><DEDENT>for meshio_type, permas_ele in meshio_to_permas_type.items():<EOL><INDENT>num_nodes = permas_ele[<NUM_LIT:0>]<EOL>permas_type = permas_ele[<NUM_LIT:1>]<EOL>if re.search("<STR_LIT>".format(permas_type), line):<EOL><INDENT>while True:<EOL><INDENT>line = f.readline().decode("<STR_LIT:utf-8>")<EOL>if not line or line.startswith("<STR_LIT:!>"):<EOL><INDENT>break<EOL><DEDENT>data = numpy.array(line.split(), dtype=int)<EOL>if meshio_type in cells:<EOL><INDENT>cells[meshio_type].append(data[-num_nodes:])<EOL><DEDENT>else:<EOL><INDENT>cells[meshio_type] = [data[-num_nodes:]]<EOL><DEDENT><DEDENT><DEDENT><DEDENT>if re.search("<STR_LIT>", line):<EOL><INDENT>points = []<EOL>while True:<EOL><INDENT>line = f.readline().decode("<STR_LIT:utf-8>")<EOL>if not line or line.startswith("<STR_LIT:!>"):<EOL><INDENT>break<EOL><DEDENT>for r in numpy.array(line.split(), dtype=float)[<NUM_LIT:1>:]:<EOL><INDENT>points.append(r)<EOL><DEDENT><DEDENT><DEDENT><DEDENT><DEDENT>points = numpy.array(points)<EOL>points = numpy.reshape(points, newshape=(len(points) // <NUM_LIT:3>, <NUM_LIT:3>))<EOL>for key in cells:<EOL><INDENT>cells[key] = numpy.array(cells[key], dtype=int) - <NUM_LIT:1><EOL><DEDENT>return Mesh(points, cells)<EOL>
Reads a (compressed) PERMAS dato or post file.