def write_gmsh(msh_fname=None, mesh_dict=None):
    """Write gmsh .msh file."""
    with open(msh_fname, 'w') as mfid:
        mfid.write('$MeshFormat\n')
        mfid.write('{}'.format(mesh_dict['mesh_format']))
        mfid.write('$EndMeshFormat\n')
        mfid.write('$Nodes\n')
        mfid.write('{0:d}\n'.format(mesh_dict['nodes'].shape[0]))
        for inode, node_row in enumerate(mesh_dict['nodes'].tolist()):
            mfid.write('{0:d} {1:f} {2:f} {3:f}\n'.format(inode + 1,
                node_row[0], node_row[1], node_row[2]))
        mfid.write('$EndNodes\n')
        mfid.write('$Elements\n')
        mfid.write('{0:d}\n'.format(mesh_dict['elements'].shape[0]))
        for ielem, (elem_row, info_row) in enumerate(zip(mesh_dict[
            'elements'].astype(str), mesh_dict['elem_info'].astype(str))):
            mfid.write('{0} {1} {2}\n'.format(ielem + 1, ' '.join(info_row),
                ' '.join(elem_row[:-1])))
        mfid.write('$EndElements\n')
