From 753c767ce2c49bce1c01967fa4a5e5ecc9c5d1bc Mon Sep 17 00:00:00 2001 From: q-posev Date: Mon, 31 May 2021 16:42:11 +0200 Subject: [PATCH] first working prototype for string datasets [HDF5] --- src/templates_hdf5/templator_hdf5.org | 53 +++++++++++++++++---------- 1 file changed, 33 insertions(+), 20 deletions(-) diff --git a/src/templates_hdf5/templator_hdf5.org b/src/templates_hdf5/templator_hdf5.org index 160259f..cff65aa 100644 --- a/src/templates_hdf5/templator_hdf5.org +++ b/src/templates_hdf5/templator_hdf5.org @@ -428,32 +428,24 @@ trexio_hdf5_read_$group_dset$ (trexio_t* const file, $group_dset_dtype$* const $ const trexio_hdf5_t* f = (const trexio_hdf5_t*) file; herr_t status; - int rrank; - // get the rank of the dataset in a file - status = H5LTget_dataset_ndims (f->$group$_group, $GROUP_DSET$_NAME, &rrank); - - if (status < 0) return TREXIO_FAILURE; - - if (rrank != (int) rank) return TREXIO_INVALID_ARG_3; // open the dataset to get its dimensions hid_t dset_id = H5Dopen(f->$group$_group, $GROUP_DSET$_NAME, H5P_DEFAULT); if (dset_id <= 0) return TREXIO_INVALID_ID; + hid_t dspace = H5Dget_space(dset_id); + + int rrank; // allocate space for the dimensions to be read hsize_t* ddims = CALLOC( (int) rank, hsize_t); if (ddims == NULL) return TREXIO_FAILURE; - // read dimensions from the existing dataset - status = H5LDget_dset_dims(dset_id, ddims); + // get the rank of the dataset in a file + rrank = H5Sget_simple_extent_dims(dspace, ddims, NULL); - H5Dclose(dset_id); - if (status < 0) { - free(ddims); - return TREXIO_FAILURE; - } + if (rrank != (int) rank) return TREXIO_INVALID_ARG_3; - for (uint32_t i=0; i$group$_group, - $GROUP_DSET$_NAME, - $group_dset$); + hid_t memtype = H5Tcopy (H5T_C_S1); + status = H5Tset_size(memtype, H5T_VARIABLE); if (status < 0) return TREXIO_FAILURE; + char** rdata = CALLOC(dims[0], char*); + if (rdata == NULL) return TREXIO_ALLOCATION_FAILED; + + status = H5Dread(dset_id, memtype, H5S_ALL, H5S_ALL, H5P_DEFAULT, rdata); + if (status < 0) return TREXIO_FAILURE; + + // copy contents of temporary rdata buffer into the group_dset otherwise they are lost + // when calling H5Treclaim or H5Dvlen_reclaim + for (uint64_t i=0; i