From 2c78145f74f5aab70fdd3f81106fca6a0dfc4b16 Mon Sep 17 00:00:00 2001 From: Raymond Lu Date: Thu, 7 Nov 2002 10:57:53 -0500 Subject: [svn-r6062] Purpose: New function. Description: H5Dget_offset returns the offset of a dataset's data relative to the beginning of a file. Platforms tested: arabica(simple function, one test should be enough.) Misc. update: RELEASE.txt --- release_docs/RELEASE.txt | 2 ++ src/H5D.c | 82 ++++++++++++++++++++++++++++++++++++++++++++++++ src/H5Dprivate.h | 1 + src/H5Dpublic.h | 1 + test/dsets.c | 16 ++++++++++ test/external.c | 4 +++ 6 files changed, 106 insertions(+) diff --git a/release_docs/RELEASE.txt b/release_docs/RELEASE.txt index 26231ae..df9db21 100644 --- a/release_docs/RELEASE.txt +++ b/release_docs/RELEASE.txt @@ -230,6 +230,8 @@ Documentation New Features ============ + * H5Dget_offset is added to return the offset of a dataset's data relative + to the beginning of the file. SLU - 2002/11/7 * Functions H5Tget_native_type and H5Tis_variable_str are added. The first one reconstructs a datatype based on native memory datatype. The second one checks if a datatype is variable string. SLU - 2002/11/6 diff --git a/src/H5D.c b/src/H5D.c index cb53178..89656a8 100644 --- a/src/H5D.c +++ b/src/H5D.c @@ -3689,6 +3689,88 @@ done: /*------------------------------------------------------------------------- + * Function: H5Dget_offset + * + * Purpose: Returns the address of dataset in file. + * + * Return: Success: the address of dataset + * + * Failure: Zero + * + * Programmer: Raymond Lu + * November 6, 2002 + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +haddr_t +H5Dget_offset(hid_t dset_id) +{ + H5D_t *dset=NULL; + haddr_t ret_value; /* Return value */ + + FUNC_ENTER_API(H5Dget_offset, 0); + H5TRACE1("h","i",dset_id); + + /* Check args */ + if (NULL==(dset=H5I_object_verify(dset_id, H5I_DATASET))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, 0, "not a dataset"); + + /* Set return value */ + ret_value = H5D_get_offset(dset); + +done: + FUNC_LEAVE(ret_value); +} + + +/*------------------------------------------------------------------------- + * Function: H5D_get_offset + * + * Purpose: Private function for H5D_get_offset. Returns the address + * of dataset in file. + * + * Return: Success: the address of dataset + * + * Failure: Zero + * + * Programmer: Raymond Lu + * November 6, 2002 + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +haddr_t +H5D_get_offset(H5D_t *dset) +{ + haddr_t ret_value; + + FUNC_ENTER_NOAPI(H5D_get_offset, HADDR_UNDEF); + + switch(dset->layout.type) { + case H5D_CHUNKED: + case H5D_COMPACT: + ret_value = HADDR_UNDEF; + break; + + case H5D_CONTIGUOUS: + /* If dataspace hasn't been allocated or dataset is stored in + * an external file, the value will be HADDR_UNDEF. */ + ret_value = dset->layout.addr; + break; + + default: + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, HADDR_UNDEF, "not a dataset type"); + } + +done: + FUNC_LEAVE(ret_value); +} + + +/*------------------------------------------------------------------------- * Function: H5Diterate * * Purpose: This routine iterates over all the elements selected in a memory diff --git a/src/H5Dprivate.h b/src/H5Dprivate.h index 3526e3c..d4a9f91 100644 --- a/src/H5Dprivate.h +++ b/src/H5Dprivate.h @@ -173,6 +173,7 @@ H5_DLL H5S_t *H5D_get_space(H5D_t *dset); H5_DLL H5D_t * H5D_open_oid(H5G_entry_t *ent); H5_DLL H5F_t * H5D_get_file(const H5D_t *dset); H5_DLL hsize_t H5D_get_storage_size(H5D_t *dset); +H5_DLL haddr_t H5D_get_offset(H5D_t *dset); H5_DLL void *H5D_vlen_get_buf_size_alloc(size_t size, void *info); H5_DLL herr_t H5D_vlen_get_buf_size(void *elem, hid_t type_id, hsize_t ndim, hssize_t *point, void *op_data); diff --git a/src/H5Dpublic.h b/src/H5Dpublic.h index 8bf09e1..3e969a3 100644 --- a/src/H5Dpublic.h +++ b/src/H5Dpublic.h @@ -80,6 +80,7 @@ H5_DLL herr_t H5Dget_space_status(hid_t dset_id, H5_DLL hid_t H5Dget_type (hid_t dset_id); H5_DLL hid_t H5Dget_create_plist (hid_t dset_id); H5_DLL hsize_t H5Dget_storage_size(hid_t dset_id); +H5_DLL haddr_t H5Dget_offset(hid_t dset_id); H5_DLL herr_t H5Dread (hid_t dset_id, hid_t mem_type_id, hid_t mem_space_id, hid_t file_space_id, hid_t plist_id, void *buf/*out*/); H5_DLL herr_t H5Dwrite (hid_t dset_id, hid_t mem_type_id, hid_t mem_space_id, diff --git a/test/dsets.c b/test/dsets.c index 11bad7f..3de7af3 100644 --- a/test/dsets.c +++ b/test/dsets.c @@ -155,6 +155,9 @@ test_create(hid_t file) if (dataset < 0) goto error; H5Pclose (create_parms); + /* Test dataset address. Should be undefined. */ + if(H5Dget_offset(dataset)!=HADDR_UNDEF) goto error; + /* * Close the chunked dataset. */ @@ -234,10 +237,16 @@ test_simple_io(hid_t file) if ((dataset = H5Dcreate(file, DSET_SIMPLE_IO_NAME, H5T_NATIVE_INT, space, H5P_DEFAULT))<0) goto error; + /* Test dataset address. Should be undefined. */ + if(H5Dget_offset(dataset)!=HADDR_UNDEF) goto error; + /* Write the data to the dataset */ if (H5Dwrite(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, xfer, points)<0) goto error; + /* Test dataset address. Should be valid. */ + if(H5Dget_offset(dataset)==HADDR_UNDEF) goto error; + /* Read the dataset back */ if (H5Dread(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, xfer, check)<0) goto error; @@ -327,9 +336,16 @@ test_compact_io(hid_t fapl) if((dataset = H5Dcreate(file, DSET_COMPACT_IO_NAME, H5T_NATIVE_INT, space, plist))<0) goto error; + + /* Test dataset address. Should be undefined. */ + if(H5Dget_offset(dataset)!=HADDR_UNDEF) goto error; + if(H5Dwrite(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, wbuf)<0) goto error; + /* Test dataset address. Should be undefined. */ + if(H5Dget_offset(dataset)!=HADDR_UNDEF) goto error; + /* Close file */ H5Sclose(space); H5Pclose(plist); diff --git a/test/external.c b/test/external.c index dfb11b1..f558fe0 100644 --- a/test/external.c +++ b/test/external.c @@ -109,6 +109,10 @@ test_1a(hid_t file) /* Read dataset creation information */ if ((dset = H5Dopen (file, "dset1"))<0) goto error; + + /* Test dataset address. Should be undefined. */ + if (H5Dget_offset(dset)!=HADDR_UNDEF) goto error; + if ((dcpl = H5Dget_create_plist (dset))<0) goto error; if ((n=H5Pget_external_count (dcpl))<0) goto error; if (1!=n) { -- cgit v0.12