c++ interface append data to an existing file


#1

Hello,
I am trying to append data to an existing file using c++ interface, but the documentation is not clear on how to extend the data space.

int main(){
	H5File file = H5File("myfile.h5", H5F_ACC_RDWR);
	DataSet dataset = file.openDataSet( "data" );
	DataSpace dataspace = dataset.getSpace();
	int rank = dataspace.getSimpleExtentNdims();

    hsize_t dims_out[rank];
    int ndims = dataspace.getSimpleExtentDims( dims_out, NULL);

	DSetCreatPropList cparms = dataset.getCreatePlist();


	/*
     * Check if dataset is chunked.
     */
    hsize_t chunk_dims[2];
    int     rank_chunk;

    std::cout << cparms.getLayout() <<"; "<< H5D_CONTIGUOUS << std::endl;
    if( H5D_CHUNKED != cparms.getLayout() )
    {
    	std::cout<<"enabling chunking"<<std::endl;
        /*
         * Get chunking information: rank and dimensions
         */
    	hsize_t      chunk_dims[2] ={4, 5};
    	cparms.setChunk( 2, chunk_dims );

    }

    std::cout << cparms.getLayout() <<"; "<< H5D_CHUNKED << std::endl;

the ode above works, but if I try to call a dataset.extend() the library throws an exception and the code fails.
I know I am supposed to extend the data space, select a new hyper slab an write the new data in it, but how can I do it?

Thanks for your help


#2

Hello,

Please make sure that the call dataset.extend() meets the criteria listed here: https://portal.hdfgroup.org/display/HDF5/H5D_SET_EXTENT

Binh-Minh