def write(filename, mesh, add_global_ids=True):
import h5py<EOL>f = h5py.File(filename, "<STR_LIT:w>")<EOL>tstt = f.create_group("<STR_LIT>")<EOL>global_id = <NUM_LIT:1><EOL>nodes = tstt.create_group("<STR_LIT>")<EOL>coords = nodes.create_dataset("<STR_LIT>", data=mesh.points)<EOL>coords.attrs.create("<STR_LIT>", global_id)<EOL>global_id += len(mesh.points)<EOL>tstt_tags = tstt.create_group("<STR_LIT>")<EOL>pd = mesh.point_data.copy()<EOL>if "<STR_LIT>" not in pd and add_global_ids:<EOL><INDENT>pd["<STR_LIT>"] = numpy.arange(<NUM_LIT:1>, len(mesh.points) + <NUM_LIT:1>)<EOL><DEDENT>if pd:<EOL><INDENT>tags = nodes.create_group("<STR_LIT>")<EOL><DEDENT>for key, data in pd.items():<EOL><INDENT>if len(data.shape) == <NUM_LIT:1>:<EOL><INDENT>dtype = data.dtype<EOL>tags.create_dataset(key, data=data)<EOL><DEDENT>else:<EOL><INDENT>n, k = data.shape<EOL>dtype = numpy.dtype((data.dtype, (k,)))<EOL>dset = tags.create_dataset(key, (n,), dtype=dtype)<EOL>dset[:] = data<EOL><DEDENT>g = tstt_tags.create_group(key)<EOL>g["<STR_LIT:type>"] = dtype<EOL>g.attrs["<STR_LIT:class>"] = <NUM_LIT:2><EOL><DEDENT>elements = tstt.create_group("<STR_LIT>")<EOL>elem_dt = h5py.special_dtype(<EOL>enum=(<EOL>"<STR_LIT:i>",<EOL>{<EOL>"<STR_LIT>": <NUM_LIT:1>,<EOL>"<STR_LIT>": <NUM_LIT:2>,<EOL>"<STR_LIT>": <NUM_LIT:3>,<EOL>"<STR_LIT>": <NUM_LIT:4>,<EOL>"<STR_LIT>": <NUM_LIT:5>,<EOL>"<STR_LIT>": <NUM_LIT:6>,<EOL>"<STR_LIT>": <NUM_LIT:7>,<EOL>"<STR_LIT>": <NUM_LIT:8>,<EOL>"<STR_LIT>": <NUM_LIT:9>,<EOL>"<STR_LIT>": <NUM_LIT:10>,<EOL>},<EOL>)<EOL>)<EOL>tstt["<STR_LIT>"] = elem_dt<EOL>tstt.create_dataset(<EOL>"<STR_LIT>",<EOL>data=[<EOL>__name__.encode("<STR_LIT:utf-8>"),<EOL>__about__.__version__.encode("<STR_LIT:utf-8>"),<EOL>str(datetime.now()).encode("<STR_LIT:utf-8>"),<EOL>],<EOL>)<EOL>meshio_to_h5m_type = {<EOL>"<STR_LIT>": {"<STR_LIT:name>": "<STR_LIT>", "<STR_LIT:type>": <NUM_LIT:1>},<EOL>"<STR_LIT>": {"<STR_LIT:name>": "<STR_LIT>", "<STR_LIT:type>": <NUM_LIT:2>},<EOL>"<STR_LIT>": {"<STR_LIT:name>": "<STR_LIT>", "<STR_LIT:type>": <NUM_LIT:5>},<EOL>}<EOL>for key, data in mesh.cells.items():<EOL><INDENT>if key not in meshio_to_h5m_type:<EOL><INDENT>logging.warning("<STR_LIT>", key)<EOL>continue<EOL><DEDENT>this_type = meshio_to_h5m_type[key]<EOL>elem_group = elements.create_group(this_type["<STR_LIT:name>"])<EOL>elem_group.attrs.create("<STR_LIT>", this_type["<STR_LIT:type>"], dtype=elem_dt)<EOL>conn = elem_group.create_dataset("<STR_LIT>", data=(data + <NUM_LIT:1>))<EOL>conn.attrs.create("<STR_LIT>", global_id)<EOL>global_id += len(data)<EOL><DEDENT>if mesh.cell_data:<EOL><INDENT>tags = elem_group.create_group("<STR_LIT>")<EOL>for key, value in mesh.cell_data.items():<EOL><INDENT>tags.create_dataset(key, data=value)<EOL><DEDENT><DEDENT>sets = tstt.create_group("<STR_LIT>")<EOL>sets.create_group("<STR_LIT>")<EOL>tstt.attrs.create("<STR_LIT>", global_id, dtype="<STR_LIT>")<EOL>return<EOL>
Writes H5M files, cf.
    https://trac.mcs.anl.gov/projects/ITAPS/wiki/MOAB/h5m.