Writes a piece of data into an open HDF5 file.

    Low level function to store a Python type (`data`) into the
    specified Group.

    Parameters
    ----------
    f : h5py.File
        The open HDF5 file.
    grp : h5py.Group or h5py.File
        The Group to place the data in.
    name : str
        The name to write the data to.
    data : any
        The data to write.
    type_string : str or None
        The type string of the data, or ``None`` to deduce
        automatically.
    options : hdf5storage.core.Options
        The options to use when writing.

    Raises
    ------
    NotImplementedError
        If writing `data` is not supported.
    TypeNotMatlabCompatibleError
        If writing a type not compatible with MATLAB and
        `options.action_for_matlab_incompatible` is set to ``'error'``.

    See Also
    --------
    hdf5storage.write : Higher level version.
    read_data
    hdf5storage.Options

def write_data(f, grp, name, data, type_string, options):
    """ Writes a piece of data into an open HDF5 file.

    Low level function to store a Python type (`data`) into the
    specified Group.

    Parameters
    ----------
    f : h5py.File
        The open HDF5 file.
    grp : h5py.Group or h5py.File
        The Group to place the data in.
    name : str
        The name to write the data to.
    data : any
        The data to write.
    type_string : str or None
        The type string of the data, or ``None`` to deduce
        automatically.
    options : hdf5storage.core.Options
        The options to use when writing.

    Raises
    ------
    NotImplementedError
        If writing `data` is not supported.
    TypeNotMatlabCompatibleError
        If writing a type not compatible with MATLAB and
        `options.action_for_matlab_incompatible` is set to ``'error'``.

    See Also
    --------
    hdf5storage.write : Higher level version.
    read_data
    hdf5storage.Options

    """
    # Get the marshaller for type(data). The required modules should be
    # here and imported.
    tp = type(data)
    m, has_modules = \
        options.marshaller_collection.get_marshaller_for_type(tp)

    # If a marshaller was found and we have the required modules, use it
    # to write the data. Otherwise, return an error. If we get something
    # other than None back, then we must recurse through the
    # entries. Also, we must set the H5PATH attribute to be the path to
    # the containing group.

    if m is not None and has_modules:
        m.write(f, grp, name, data, type_string, options)
    else:
        raise NotImplementedError('Can''t write data type: '+str(tp))