def add_data(self, data, metadata=None):
        subdata = np.atleast_2d(data)
        if subdata.shape[1] != self.grid.nr_of_elements:
            if subdata.shape[0] == self.grid.nr_of_elements:
                subdata = subdata.T
            else:
                raise Exception(
                    'Number of values does not match the number of ' +
                    'elements in the grid'
                )
        K = subdata.shape[0]
        if metadata is not None:
            if K > 1:
                if(not isinstance(metadata, (list, tuple)) or
                   len(metadata) != K):
                    raise Exception('metadata does not fit the provided data')
            else:
                metadata = [metadata, ]
        if metadata is None:
            metadata = [None for i in range(0, K)]
        return_ids = []
        for dataset, meta in zip(subdata, metadata):
            cid = self._get_next_index()
            self.parsets[cid] = dataset
            self.metadata[cid] = meta
            return_ids.append(cid)
        if len(return_ids) == 1:
            return return_ids[0]
        else:
            return return_ids