def save_replace_dataset(hf, address, data, maxshape, dtype):
    """Saves or replaces a dataset in a hdf5 file. The dataset must be resizable (see the HDF5 manual).

    Parameters
    ----------
    hf : :obj:`h5py.File`
        hdf5 file (already opened with writing permission)
    address : :obj:`str`
        address of the dataset to be written/replaced
    data : array
        data to be saved
    maxshape : array or None
        maximum size of the array
    dtype : array
        data type

    """
    if address in hf:
        chunk = hf[address]
        chunk.resize(data.shape)
        chunk[...] = data
    else:
        hf.create_dataset(address, data=data, maxshape=maxshape, dtype=dtype)
