diff options
Diffstat (limited to 'hl/src/H5DO.c')
-rw-r--r-- | hl/src/H5DO.c | 227 |
1 files changed, 42 insertions, 185 deletions
diff --git a/hl/src/H5DO.c b/hl/src/H5DO.c index 99cf2f7..20d5a4a 100644 --- a/hl/src/H5DO.c +++ b/hl/src/H5DO.c @@ -22,163 +22,20 @@ /* public LT prototypes */ #include "H5DOpublic.h" - /*------------------------------------------------------------------------- - * Function: H5DOwrite_chunk - * - * Purpose: Writes an entire chunk to the file directly. - * - * Return: Non-negative on success/Negative on failure - * - * Programmer: Raymond Lu - * 30 July 2012 + * Function: H5DOappend() * - *------------------------------------------------------------------------- - */ -herr_t -H5DOwrite_chunk(hid_t dset_id, hid_t dxpl_id, uint32_t filters, const hsize_t *offset, - size_t data_size, const void *buf) -{ - hbool_t created_dxpl = FALSE; /* Whether we created a DXPL */ - hbool_t do_direct_write = TRUE; /* Flag for direct writes */ - uint32_t data_size_32; /* Chunk data size (limited to 32-bits currently) */ - herr_t ret_value = FAIL; /* Return value */ - - /* Check arguments */ - if(dset_id < 0) - goto done; - if(!buf) - goto done; - if(!offset) - goto done; - if(!data_size) - goto done; - data_size_32 = (uint32_t)data_size; - if(data_size != (size_t)data_size_32) - goto done; - - /* If the user passed in a default DXPL, create one to pass to H5Dwrite() */ - if(H5P_DEFAULT == dxpl_id) { - if((dxpl_id = H5Pcreate(H5P_DATASET_XFER)) < 0) - goto done; - created_dxpl = TRUE; - } /* end if */ - - /* Set direct write parameters */ - if(H5Pset(dxpl_id, H5D_XFER_DIRECT_CHUNK_WRITE_FLAG_NAME, &do_direct_write) < 0) - goto done; - if(H5Pset(dxpl_id, H5D_XFER_DIRECT_CHUNK_WRITE_FILTERS_NAME, &filters) < 0) - goto done; - if(H5Pset(dxpl_id, H5D_XFER_DIRECT_CHUNK_WRITE_OFFSET_NAME, &offset) < 0) - goto done; - if(H5Pset(dxpl_id, H5D_XFER_DIRECT_CHUNK_WRITE_DATASIZE_NAME, &data_size_32) < 0) - goto done; - - /* Write chunk */ - if(H5Dwrite(dset_id, 0, H5S_ALL, H5S_ALL, dxpl_id, buf) < 0) - goto done; - - /* Indicate success */ - ret_value = SUCCEED; - -done: - if(created_dxpl) { - if(H5Pclose(dxpl_id) < 0) - ret_value = FAIL; - } /* end if */ - else { - /* Reset the direct write flag on user DXPL */ - do_direct_write = FALSE; - if(H5Pset(dxpl_id, H5D_XFER_DIRECT_CHUNK_WRITE_FLAG_NAME, &do_direct_write) < 0) - ret_value = FAIL; - } - - return ret_value; -} /* end H5DOwrite_chunk() */ - - -/*------------------------------------------------------------------------- - * Function: H5DOread_chunk + * Purpose: To append elements to a dataset. * - * Purpose: Reads an entire chunk from the file directly. + * axis: the dataset dimension (zero-based) for the append + * extension: the # of elements to append for the axis-th dimension + * memtype: the datatype + * buf: buffer with data for the append * * Return: Non-negative on success/Negative on failure * - * Programmer: Matthew Strong (GE Healthcare) - * 14 February 2016 - * - *--------------------------------------------------------------------------- - */ -herr_t -H5DOread_chunk(hid_t dset_id, hid_t dxpl_id, const hsize_t *offset, uint32_t *filters, - void *buf) -{ - hbool_t created_dxpl = FALSE; /* Whether we created a DXPL */ - hbool_t do_direct_read = TRUE; /* Flag for direct writes */ - herr_t ret_value = FAIL; /* Return value */ - - /* Check arguments */ - if(dset_id < 0) - goto done; - if(!buf) - goto done; - if(!offset) - goto done; - if(!filters) - goto done; - - /* If the user passed in a default DXPL, create one to pass to H5Dwrite() */ - if(H5P_DEFAULT == dxpl_id) { - if((dxpl_id = H5Pcreate(H5P_DATASET_XFER)) < 0) - goto done; - created_dxpl = TRUE; - } /* end if */ - - /* Set direct write parameters */ - if(H5Pset(dxpl_id, H5D_XFER_DIRECT_CHUNK_READ_FLAG_NAME, &do_direct_read) < 0) - goto done; - if(H5Pset(dxpl_id, H5D_XFER_DIRECT_CHUNK_READ_OFFSET_NAME, &offset) < 0) - goto done; - - /* Read chunk */ - if(H5Dread(dset_id, 0, H5S_ALL, H5S_ALL, dxpl_id, buf) < 0) - goto done; - /* Get the filter mask */ - if(H5Pget(dxpl_id, H5D_XFER_DIRECT_CHUNK_READ_FILTERS_NAME, filters) < 0) - goto done; - - /* Indicate success */ - ret_value = SUCCEED; - -done: - if(created_dxpl) { - if(H5Pclose(dxpl_id) < 0) - ret_value = FAIL; - } /* end if */ - else { - /* Reset the direct read flag on user DXPL */ - do_direct_read = FALSE; - if(H5Pset(dxpl_id, H5D_XFER_DIRECT_CHUNK_READ_FLAG_NAME, &do_direct_read) < 0) - ret_value = FAIL; - } - - return ret_value; -} /* end H5DOread_chunk() */ - - -/*------------------------------------------------------------------------- - * Function: H5DOappend() - * - * Purpose: To append elements to a dataset. - * axis: the dataset dimension (zero-based) for the append - * extension: the # of elements to append for the axis-th dimension - * memtype: the datatype - * buf: buffer with data for the append - * - * Return: Non-negative on success/Negative on failure - * - * Programmer: Vailin Choi; Jan 2014 + * Programmer: Vailin Choi; Jan 2014 * * Note: * This routine is copied from the fast forward feature branch: features/hdf5_ff @@ -227,7 +84,7 @@ H5DOappend(hid_t dset_id, hid_t dxpl_id, unsigned axis, size_t extension, /* check arguments */ if(H5I_DATASET != H5Iget_type(dset_id)) - goto done; + goto done; /* If the user passed in a default DXPL, create one to pass to H5Dwrite() */ if(H5P_DEFAULT == dxpl_id) { @@ -236,35 +93,35 @@ H5DOappend(hid_t dset_id, hid_t dxpl_id, unsigned axis, size_t extension, created_dxpl = TRUE; } /* end if */ else if(TRUE != H5Pisa_class(dxpl_id, H5P_DATASET_XFER)) - goto done; + goto done; /* Get the dataspace of the dataset */ if(FAIL == (space_id = H5Dget_space(dset_id))) - goto done; + goto done; /* Get the rank of this dataspace */ if((sndims = H5Sget_simple_extent_ndims(space_id)) < 0) - goto done; + goto done; ndims = (unsigned)sndims; /* Verify correct axis */ if(axis >= ndims) - goto done; + goto done; /* Get the dimensions sizes of the dataspace */ if(H5Sget_simple_extent_dims(space_id, size, NULL) < 0) - goto done; + goto done; /* Adjust the dimension size of the requested dimension, but first record the old dimension size */ old_size = size[axis]; size[axis] += extension; if(size[axis] < old_size) - goto done; + goto done; /* Set the extent of the dataset to the new dimension */ if(H5Dset_extent(dset_id, size) < 0) - goto done; + goto done; /* Get the new dataspace of the dataset */ if(FAIL == (new_space_id = H5Dget_space(dset_id))) @@ -282,51 +139,51 @@ H5DOappend(hid_t dset_id, hid_t dxpl_id, unsigned axis, size_t extension, } /* end if */ } /* end for */ if(FAIL == H5Sselect_hyperslab(new_space_id, H5S_SELECT_SET, start, stride, count, block)) - goto done; + goto done; /* The # of elemnts in the new extended dataspace */ if((snelmts = H5Sget_select_npoints(new_space_id)) < 0) - goto done; + goto done; nelmts = (hsize_t)snelmts; /* create a memory space */ if(FAIL == (mem_space_id = H5Screate_simple(1, &nelmts, NULL))) - goto done; + goto done; /* Write the data */ if(H5Dwrite(dset_id, memtype, mem_space_id, new_space_id, dxpl_id, buf) < 0) - goto done; + goto done; /* Obtain the dataset's access property list */ if((dapl = H5Dget_access_plist(dset_id)) < 0) - goto done; + goto done; /* Allocate the boundary array */ boundary = (hsize_t *)HDmalloc(ndims * sizeof(hsize_t)); /* Retrieve the append flush property */ if(H5Pget_append_flush(dapl, ndims, boundary, &append_cb, &udata) < 0) - goto done; + goto done; /* No boundary for this axis */ if(boundary[axis] != 0) { - /* Determine whether a boundary is hit or not */ - for(k = start[axis]; k < size[axis]; k++) - if(!((k + 1) % boundary[axis])) { - hit = TRUE; - break; - } - - if(hit) { /* Hit the boundary */ - /* Invoke callback if there is one */ - if(append_cb && append_cb(dset_id, size, udata) < 0) - goto done; - - /* Do a dataset flush */ - if(H5Dflush(dset_id) < 0) - goto done; - } /* end if */ + /* Determine whether a boundary is hit or not */ + for(k = start[axis]; k < size[axis]; k++) + if(!((k + 1) % boundary[axis])) { + hit = TRUE; + break; + } + + if(hit) { /* Hit the boundary */ + /* Invoke callback if there is one */ + if(append_cb && append_cb(dset_id, size, udata) < 0) + goto done; + + /* Do a dataset flush */ + if(H5Dflush(dset_id) < 0) + goto done; + } /* end if */ } /* end if */ /* Indicate success */ @@ -341,22 +198,22 @@ done: /* Close old dataspace */ if(space_id != FAIL && H5Sclose(space_id) < 0) - ret_value = FAIL; + ret_value = FAIL; /* Close new dataspace */ if(new_space_id != FAIL && H5Sclose(new_space_id) < 0) - ret_value = FAIL; + ret_value = FAIL; /* Close memory dataspace */ if(mem_space_id != FAIL && H5Sclose(mem_space_id) < 0) - ret_value = FAIL; + ret_value = FAIL; /* Close the dataset access property list */ if(dapl != FAIL && H5Pclose(dapl) < 0) - ret_value = FAIL; + ret_value = FAIL; if(boundary) - HDfree(boundary); + HDfree(boundary); return ret_value; } /* H5DOappend() */ |