summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRaymond Lu <songyulu@hdfgroup.org>2002-11-06 21:08:45 (GMT)
committerRaymond Lu <songyulu@hdfgroup.org>2002-11-06 21:08:45 (GMT)
commita9dea215ed696c1523fec79b4175b571600dca77 (patch)
tree0f004dc441cf2b95ecc1312a3bad61c0a556b768
parent28874d54c4a7ebb953d7a92814090eb97b306251 (diff)
downloadhdf5-a9dea215ed696c1523fec79b4175b571600dca77.zip
hdf5-a9dea215ed696c1523fec79b4175b571600dca77.tar.gz
hdf5-a9dea215ed696c1523fec79b4175b571600dca77.tar.bz2
[svn-r6060]
Purpose: Add new functions Description: add H5Tget_native_type and H5Tis_variable_str. Platforms tested: arabica, eirene, modi4 Misc. update: MANIFEST and release_docs/RELEASE updated.
-rw-r--r--MANIFEST1
-rw-r--r--release_docs/RELEASE.txt3
-rw-r--r--src/H5T.c1039
-rw-r--r--src/H5Tpkg.h16
-rw-r--r--src/H5Tprivate.h16
-rw-r--r--src/H5Tpublic.h9
-rw-r--r--src/H5detect.c61
-rw-r--r--test/Makefile.in11
-rw-r--r--test/ntypes.c1390
-rw-r--r--test/tvlstr.c6
10 files changed, 2518 insertions, 34 deletions
diff --git a/MANIFEST b/MANIFEST
index 287a742..ffaacf4 100644
--- a/MANIFEST
+++ b/MANIFEST
@@ -945,6 +945,7 @@
./test/links.c
./test/mount.c
./test/mtime.c
+./test/ntypes.c
./test/ohdr.c
./test/space_overflow.c _DO_NOT_DISTRIBUTE_
./test/gen_old_array.c _DO_NOT_DISTRIBUTE_
diff --git a/release_docs/RELEASE.txt b/release_docs/RELEASE.txt
index 3e3df14..26231ae 100644
--- a/release_docs/RELEASE.txt
+++ b/release_docs/RELEASE.txt
@@ -230,6 +230,9 @@ Documentation
New Features
============
+ * 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
* Added environment variable "HDF5_DISABLE_VERSION_CHECK", which disables
the version checking between the header files and the library linked into
an application if set to '1'. This should be used with caution, mis-
diff --git a/src/H5T.c b/src/H5T.c
index 3cfe306..427b86e 100644
--- a/src/H5T.c
+++ b/src/H5T.c
@@ -131,6 +131,26 @@ hid_t H5T_NATIVE_UINT_FAST64_g = FAIL;
/*
* Alignment constraints for native types. These are initialized at run time
+ * in H5Tinit.c. These alignments are mainly for offsets in HDF5 compound
+ * datatype or C structures, which are different from the alignments for memory
+ * address below this group of variables.
+ */
+size_t H5T_NATIVE_SCHAR_COMP_ALIGN_g = 0;
+size_t H5T_NATIVE_UCHAR_COMP_ALIGN_g = 0;
+size_t H5T_NATIVE_SHORT_COMP_ALIGN_g = 0;
+size_t H5T_NATIVE_USHORT_COMP_ALIGN_g = 0;
+size_t H5T_NATIVE_INT_COMP_ALIGN_g = 0;
+size_t H5T_NATIVE_UINT_COMP_ALIGN_g = 0;
+size_t H5T_NATIVE_LONG_COMP_ALIGN_g = 0;
+size_t H5T_NATIVE_ULONG_COMP_ALIGN_g = 0;
+size_t H5T_NATIVE_LLONG_COMP_ALIGN_g = 0;
+size_t H5T_NATIVE_ULLONG_COMP_ALIGN_g = 0;
+size_t H5T_NATIVE_FLOAT_COMP_ALIGN_g = 0;
+size_t H5T_NATIVE_DOUBLE_COMP_ALIGN_g = 0;
+size_t H5T_NATIVE_LDOUBLE_COMP_ALIGN_g = 0;
+
+/*
+ * Alignment constraints for native types. These are initialized at run time
* in H5Tinit.c
*/
size_t H5T_NATIVE_SCHAR_ALIGN_g = 0;
@@ -2549,6 +2569,631 @@ done:
/*-------------------------------------------------------------------------
+ * Function: H5Tis_variable_str
+ *
+ * Purpose: Check whether a datatype is a variable-length string
+ *
+ * Return: TRUE (1) or FALSE (0) on success/Negative on failure
+ *
+ * Programmer: Raymond Lu
+ * November 4, 2002
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+htri_t
+H5Tis_variable_str(hid_t dtype_id)
+{
+ H5T_t *dt = NULL;
+ htri_t ret_value; /* Return value */
+
+ FUNC_ENTER_API(H5Tis_variable_str, FAIL);
+ H5TRACE1("b","i",dtype_id);
+
+ /* Check args */
+ if (NULL == (dt = H5I_object_verify(dtype_id,H5I_DATATYPE)))
+ HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a data type");
+
+ /* Set return value */
+ ret_value=H5T_is_variable_str(dt);
+
+done:
+ FUNC_LEAVE(ret_value);
+}
+
+
+/*-------------------------------------------------------------------------
+ * Function: H5T_is_variable_str
+ *
+ * Purpose: Private function of H5Tis_variable_str.
+ * Check whether a datatype is a variable-length string
+ *
+ *
+ * Return: TRUE (1) or FALSE (0) on success/Negative on failure
+ *
+ * Programmer: Raymond Lu
+ * November 4, 2002
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+htri_t
+H5T_is_variable_str(H5T_t *dt)
+{
+ htri_t ret_value=FALSE; /* Return value */
+
+ FUNC_ENTER_NOAPI(H5T_is_variable_str, FAIL);
+
+ assert(dt);
+
+ if(H5T_VLEN == dt->type && H5T_VLEN_STRING == dt->u.vlen.type)
+ ret_value = TRUE;
+ else
+ ret_value = FALSE;
+
+done:
+ FUNC_LEAVE(ret_value);
+}
+
+
+/*-------------------------------------------------------------------------
+ * Function: H5Tget_native_type
+ *
+ * Purpose: High-level API to return the native type of a datatype.
+ * The native type is chosen by matching the size and class of
+ * querried datatype from the following native premitive
+ * datatypes:
+ * H5T_NATIVE_CHAR H5T_NATIVE_UCHAR
+ * H5T_NATIVE_SHORT H5T_NATIVE_USHORT
+ * H5T_NATIVE_INT H5T_NATIVE_UINT
+ * H5T_NATIVE_LONG H5T_NATIVE_ULONG
+ * H5T_NATIVE_LLONG H5T_NATIVE_ULLONG
+ *
+ * H5T_NATIVE_FLOAT
+ * H5T_NATIVE_DOUBLE
+ * H5T_NATIVE_LDOUBLE
+ *
+ * Compound, array, enum, and VL types all choose among these
+ * types for theire members. Time, Bifield, Opaque, Reference
+ * types are only copy out.
+ *
+ * Return: Success: Returns the native data type if successful.
+ *
+ * Failure: negative
+ *
+ * Programmer: Raymond Lu
+ * Oct 3, 2002
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+hid_t H5Tget_native_type(hid_t type_id, H5T_direction_t direction)
+{
+ H5T_t *dt=NULL, *new_dt=NULL;
+ H5T_class_t class;
+ size_t comp_size=0;
+ hid_t ret_value;
+
+ FUNC_ENTER_API(H5Tget_native_type, FAIL);
+ H5TRACE1("z","i",type_id);
+
+ /* check argument */
+ if(NULL==(dt=H5I_object_verify(type_id, H5I_DATATYPE)))
+ HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a data type");
+
+ if(direction!=H5T_DIR_DEFAULT && direction!=H5T_DIR_ASCEND
+ && direction!=H5T_DIR_DESCEND)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "not valid direction value");
+
+ if((new_dt = H5T_get_native_type(dt, direction, NULL, NULL, &comp_size))==NULL)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "cannot retrieve native type");
+
+ if((ret_value=H5I_register(H5I_DATATYPE, new_dt)) < 0)
+ HGOTO_ERROR(H5E_DATATYPE, H5E_CANTREGISTER, FAIL, "unable to register data type");
+
+done:
+ FUNC_LEAVE(ret_value);
+}
+
+
+/*-------------------------------------------------------------------------
+ * Function: H5T_get_native_type
+ *
+ * Purpose: Returns the native type of a datatype.
+ *
+ * Return: Success: Returns the native data type if successful.
+ *
+ * Failure: negative
+ *
+ * Programmer: Raymond Lu
+ * Oct 3, 2002
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+H5T_t* H5T_get_native_type(H5T_t *dtype, H5T_direction_t direction, size_t *struct_align, size_t *offset, size_t *comp_size)
+{
+ H5T_t *ret_value, *dt;
+ H5T_class_t class;
+ H5T_sign_t sign;
+ size_t size;
+ int nmemb;
+ int i;
+ H5T_t *memb_type, *base_type, *super_type, *new_type;
+ hid_t memb_id, base_id;
+ H5T_t **memb_list; /* List of compound member IDs */
+ size_t *memb_offset=NULL; /* List of member offsets in compound type, including member size and alignment */
+ size_t children_size=0; /* Total size of compound members */
+ size_t children_st_align=0; /* The max alignment among compound members. This'll be the compound alignment */
+ char **comp_mname; /* List of member names in compound type */
+ char *memb_name;
+ void *memb_value;
+ int array_rank;
+ hsize_t *dims = NULL;
+ H5T_class_t child_class;
+
+ FUNC_ENTER_NOAPI(H5T_get_native_type, NULL);
+
+ assert(dtype);
+
+ if((class = H5T_get_class(dtype))<0)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "not a valid class");
+
+ if((size = H5T_get_size(dtype))==0)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "not a valid size");
+
+ switch(class) {
+ case H5T_INTEGER:
+ if((sign = H5T_get_sign(dtype))==H5T_SGN_ERROR)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "not a valid signess");
+
+ if((ret_value = H5T_get_native_integer(size, sign, direction, struct_align, offset, comp_size))==NULL)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "cannot retrieve integer type");
+
+ break;
+ case H5T_FLOAT:
+ if((ret_value = H5T_get_native_float(size, direction, struct_align, offset, comp_size))==NULL)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "cannot retrieve float type");
+
+ break;
+ case H5T_STRING:
+ if(H5T_is_variable_str(dtype)) {
+ if(NULL==(dt=H5I_object_verify(H5T_C_S1, H5I_DATATYPE)))
+ HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "not a data type");
+ if((ret_value=H5T_copy(dt, H5T_COPY_TRANSIENT))==NULL)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "cannot retrieve float type");
+ if(H5T_set_size(ret_value, H5T_VARIABLE)<0)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "cannot set size");
+ } else {
+ if(NULL==(dt=H5I_object_verify(H5T_NATIVE_UCHAR, H5I_DATATYPE)))
+ HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "not a data type");
+ if((ret_value=H5T_copy(dt, H5T_COPY_TRANSIENT))==NULL)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "cannot retrieve float type");
+ if(H5T_set_size(ret_value, size)<0)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "cannot set size");
+ }
+
+ break;
+ case H5T_TIME:
+ case H5T_BITFIELD:
+ case H5T_OPAQUE:
+ case H5T_REFERENCE:
+ if((ret_value=H5T_copy(dtype, H5T_COPY_TRANSIENT))==NULL)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "cannot retrieve float type");
+
+ break;
+ case H5T_COMPOUND:
+ if((nmemb = H5T_get_nmembers(dtype))<=0)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "compound data type doesn't have any member");
+
+ memb_list = (H5T_t**)HDmalloc(nmemb*sizeof(H5T_t*));
+ memb_offset = (size_t*)HDcalloc(nmemb, sizeof(size_t));
+ comp_mname = (char**)HDmalloc(nmemb*sizeof(char*));
+
+ /* Construct child compound type and retrieve a list of their IDs, offsets, total size, and alignment for compound type. */
+ for(i=0; i<nmemb; i++) {
+ if((memb_type = H5T_get_member_type(dtype, i))==NULL)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "member type retrieval failed");
+
+ if((comp_mname[i] = H5T_get_member_name(dtype, i))==NULL)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "member type retrieval failed");
+
+ if((memb_list[i] = H5T_get_native_type(memb_type, direction, &children_st_align, &(memb_offset[i]), &children_size))==NULL)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "member identifier retrieval failed");
+
+ if(H5T_close(memb_type)<0)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "cannot close datatype");
+ }
+
+ /* The alignment for whole compound type */
+ if(children_st_align && children_size % children_st_align) {
+ memb_offset[nmemb-1] += children_size % children_st_align;
+ children_size += children_size % children_st_align;
+ }
+
+ /* Construct new compound type based on native type */
+ if((new_type=H5T_create(H5T_COMPOUND, children_size))==NULL)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "cannot create a compound type");
+
+ /* Insert members for the new compound type */
+ for(i=0; i<nmemb; i++) {
+ if(H5T_insert(new_type, comp_mname[i], memb_offset[i], memb_list[i])<0)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "cannot insert member to compound datatype");
+ }
+
+ /* Update size, offset and compound alignment for parent. */
+ if(offset)
+ *offset = *comp_size;
+ if(struct_align && *struct_align < children_st_align)
+ *struct_align = children_st_align;
+ *comp_size += children_size;
+
+ /* Close member data type */
+ for(i=0; i<nmemb; i++) {
+ if(H5T_close(memb_list[i])<0)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "cannot close datatype");
+
+ /* Free member name list */
+ if(comp_mname[i])
+ HDfree(comp_mname[i]);
+ }
+
+ if(memb_list)
+ HDfree(memb_list);
+ if(memb_offset)
+ HDfree(memb_offset);
+ if(comp_mname)
+ HDfree(comp_mname);
+
+ ret_value = new_type;
+
+ break;
+ case H5T_ENUM:
+ /* Retrieve base type for enumarate type */
+ if((super_type=H5T_get_super(dtype))==NULL)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "unable to get base type for enumarate type");
+ if((base_type = H5T_get_native_type(super_type, direction, struct_align, offset, comp_size))==NULL)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "base native type retrieval failed");
+
+ /* Allocate room for the enum values */
+ memb_value = H5MM_malloc(H5T_get_size(super_type));
+ assert(memb_value);
+
+ /* Close super type */
+ if(H5T_close(super_type)<0)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "cannot close datatype");
+
+ /* Construct new enum type based on native type */
+ if((new_type=H5T_enum_create(base_type))==NULL)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "unable to create enum type");
+
+ /* Retrieve member info and insert members into new enum type */
+ if((nmemb = H5T_get_nmembers(dtype))<=0)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "enumarate data type doesn't have any member");
+ for(i=0; i<nmemb; i++) {
+ if((memb_name=H5T_get_member_name(dtype, i))==NULL)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "cannot get member name");
+ if(H5T_get_member_value(dtype, i, memb_value)<0)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "cannot get member value");
+ if(H5T_enum_insert(new_type, memb_name, memb_value)<0)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "cannot insert member");
+ if(memb_name)
+ HDfree(memb_name);
+ }
+ if(memb_value)
+ H5MM_xfree(memb_value);
+
+ /* Close base type */
+ if(H5T_close(base_type)<0)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "cannot close datatype");
+
+ ret_value = new_type;
+
+ break;
+ case H5T_ARRAY:
+ /* Retrieve dimension information for array data type */
+ if((array_rank=H5T_get_array_ndims(dtype))<=0)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "cannot get dimension rank");
+ if((dims = (hsize_t*)H5MM_malloc(array_rank*sizeof(hsize_t)))==NULL)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "cannot allocate memory");
+ if(H5T_get_array_dims(dtype, dims, NULL)<0)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "cannot get dimension size");
+
+ /* Retrieve base type for array type */
+ if((super_type=H5T_get_super(dtype))==NULL)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "unable to get parent type for enumarate type");
+ if((base_type = H5T_get_native_type(super_type, direction, struct_align, offset, comp_size))==NULL)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "parent native type retrieval failed");
+
+ /* Close super type */
+ if(H5T_close(super_type)<0)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "cannot close datatype");
+
+ /* Create a new array type based on native type */
+ if((new_type=H5T_array_create(base_type, array_rank, dims, NULL))==NULL)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "unable to create array type");
+
+ /* Close base type */
+ if(H5T_close(base_type)<0)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "cannot close datatype");
+ if(dims)
+ HDfree(dims);
+
+ ret_value = new_type;
+
+ break;
+ case H5T_VLEN:
+ /* Retrieve base type for array type */
+ if((super_type=H5T_get_super(dtype))==NULL)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "unable to get parent type for enumarate type");
+ if((base_type = H5T_get_native_type(super_type, direction, struct_align, offset, comp_size))==NULL)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "parent native type retrieval failed");
+
+ /* Close super type */
+ if(H5T_close(super_type)<0)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "cannot close datatype");
+
+ /* Create a new array type based on native type */
+ if((new_type=H5T_vlen_create(base_type))==NULL)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "unable to create VL type");
+
+ /* Close base type */
+ if(H5T_close(base_type)<0)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "cannot close datatype");
+
+ ret_value = new_type;
+
+ break;
+ default:
+ HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "data type doesn't match any native type");
+ }
+
+done:
+ FUNC_LEAVE(ret_value);
+}
+
+
+/*-------------------------------------------------------------------------
+ * Function: H5T_get_native_integer
+ *
+ * Purpose: Returns the native integer type of a datatype.
+ *
+ * Return: Success: Returns the native data type if successful.
+ *
+ * Failure: negative
+ *
+ * Programmer: Raymond Lu
+ * Oct 3, 2002
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+H5T_t* H5T_get_native_integer(size_t size, H5T_sign_t sign, H5T_direction_t direction, size_t *struct_align, size_t *offset, size_t *comp_size)
+{
+ H5T_t *dt=NULL, *ret_value=NULL;
+ hid_t tid;
+ size_t align=1;
+
+ FUNC_ENTER_NOAPI(H5T_get_native_integer, NULL);
+
+ if(direction == H5T_DIR_DEFAULT || direction == H5T_DIR_ASCEND) {
+ if(size==sizeof(char)) {
+ if(sign==H5T_SGN_2)
+ tid = H5T_NATIVE_SCHAR;
+ else
+ tid = H5T_NATIVE_UCHAR;
+
+ align = H5T_NATIVE_SCHAR_COMP_ALIGN_g;
+ }
+ else if(size==sizeof(short)) {
+ if(sign==H5T_SGN_2)
+ tid = H5T_NATIVE_SHORT;
+ else
+ tid = H5T_NATIVE_USHORT;
+
+ align = H5T_NATIVE_SHORT_COMP_ALIGN_g;
+ }
+ else if(size==sizeof(int)) {
+ if(sign==H5T_SGN_2)
+ tid = H5T_NATIVE_INT;
+ else
+ tid = H5T_NATIVE_UINT;
+
+ align = H5T_NATIVE_INT_COMP_ALIGN_g;
+ }
+ else if(size==sizeof(long)) {
+ if(sign==H5T_SGN_2)
+ tid = H5T_NATIVE_LONG;
+ else
+ tid = H5T_NATIVE_ULONG;
+
+ align = H5T_NATIVE_LONG_COMP_ALIGN_g;
+ }
+ else if(size==sizeof(long long)) {
+ if(sign==H5T_SGN_2)
+ tid = H5T_NATIVE_LLONG;
+ else
+ tid = H5T_NATIVE_ULLONG;
+
+ align = H5T_NATIVE_LLONG_COMP_ALIGN_g;
+ }
+ else { /* If no native type matches the querried datatype, simply choose the type of biggest size. */
+ if(sign==H5T_SGN_2)
+ tid = H5T_NATIVE_LLONG;
+ else
+ tid = H5T_NATIVE_ULLONG;
+
+ align = H5T_NATIVE_LLONG_COMP_ALIGN_g;
+ }
+ } else if(direction == H5T_DIR_DESCEND) {
+ if(size==sizeof(long long)) {
+ if(sign==H5T_SGN_2)
+ tid = H5T_NATIVE_LLONG;
+ else
+ tid = H5T_NATIVE_ULLONG;
+
+ align = H5T_NATIVE_LLONG_COMP_ALIGN_g;
+ }
+ else if(size==sizeof(long)) {
+ if(sign==H5T_SGN_2)
+ tid = H5T_NATIVE_LONG;
+ else
+ tid = H5T_NATIVE_ULONG;
+
+ align = H5T_NATIVE_LONG_COMP_ALIGN_g;
+ }
+ else if(size==sizeof(int)) {
+ if(sign==H5T_SGN_2)
+ tid = H5T_NATIVE_INT;
+ else
+ tid = H5T_NATIVE_UINT;
+
+ align = H5T_NATIVE_INT_COMP_ALIGN_g;
+ }
+ else if(size==sizeof(short)) {
+ if(sign==H5T_SGN_2)
+ tid = H5T_NATIVE_SHORT;
+ else
+ tid = H5T_NATIVE_SHORT;
+
+ align = H5T_NATIVE_SHORT_COMP_ALIGN_g;
+ }
+ if(size==sizeof(char)) {
+ if(sign==H5T_SGN_2)
+ tid = H5T_NATIVE_SCHAR;
+ else
+ tid = H5T_NATIVE_UCHAR;
+
+ align = H5T_NATIVE_SCHAR_COMP_ALIGN_g;
+ }
+ else { /* If no native type matches the querried datatype, simple choose the type of smallest size. */
+ if(sign==H5T_SGN_2)
+ tid = H5T_NATIVE_SCHAR;
+ else
+ tid = H5T_NATIVE_UCHAR;
+
+ align = H5T_NATIVE_SCHAR_COMP_ALIGN_g;
+ }
+ }
+
+ /* Create new native type */
+ if(NULL==(dt=H5I_object_verify(tid, H5I_DATATYPE)))
+ HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "not a data type");
+ if((ret_value=H5T_copy(dt, H5T_COPY_TRANSIENT))==NULL)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "cannot retrieve float type");
+
+ /* compute size and offset of compound type member. */
+ if(comp_size && offset) {
+ /* Add alignment value */
+ if(align && *comp_size%align) {
+ *offset = *comp_size + (align - *comp_size%align);
+ size = size + (align - *comp_size%align);
+ } else
+ *offset = *comp_size;
+
+ *comp_size += size;
+ }
+ /* Alignment for whole compound type */
+ if(struct_align && *struct_align<align)
+ *struct_align = align;
+
+done:
+ FUNC_LEAVE(ret_value);
+}
+
+
+/*-------------------------------------------------------------------------
+ * Function: H5T_get_native_float
+ *
+ * Purpose: Returns the native floatt type of a datatype.
+ *
+ * Return: Success: Returns the native data type if successful.
+ *
+ * Failure: negative
+ *
+ * Programmer: Raymond Lu
+ * Oct 3, 2002
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+H5T_t* H5T_get_native_float(size_t size, H5T_direction_t direction, size_t *struct_align, size_t *offset, size_t *comp_size)
+{
+ H5T_t *ret_value=NULL, *dt=NULL;
+ hid_t tid;
+ size_t align=1;
+
+ FUNC_ENTER_NOAPI(H5T_get_native_integer, NULL);
+
+ if(direction == H5T_DIR_DEFAULT || direction == H5T_DIR_ASCEND) {
+ if(size==sizeof(float)) {
+ tid = H5T_NATIVE_FLOAT;
+ align = H5T_NATIVE_FLOAT_COMP_ALIGN_g;
+ }
+ else if(size==sizeof(double)) {
+ tid = H5T_NATIVE_DOUBLE;
+ align = H5T_NATIVE_DOUBLE_COMP_ALIGN_g;
+ }
+ else if(size==sizeof(long double)) {
+ tid = H5T_NATIVE_LDOUBLE;
+ align = H5T_NATIVE_LDOUBLE_COMP_ALIGN_g;
+ }
+ else { /* If not match, return the biggest datatype */
+ tid = H5T_NATIVE_LDOUBLE;
+ align = H5T_NATIVE_LDOUBLE_COMP_ALIGN_g;
+ }
+ } else {
+ if(size==sizeof(long double)) {
+ tid = H5T_NATIVE_LDOUBLE;
+ align = H5T_NATIVE_LDOUBLE_COMP_ALIGN_g;
+ }
+ else if(size==sizeof(double)) {
+ tid = H5T_NATIVE_DOUBLE;
+ align = H5T_NATIVE_DOUBLE_COMP_ALIGN_g;
+ }
+ else if(size==sizeof(float)) {
+ tid = H5T_NATIVE_FLOAT;
+ align = H5T_NATIVE_FLOAT_COMP_ALIGN_g;
+ }
+ else {
+ tid = H5T_NATIVE_FLOAT;
+ align = H5T_NATIVE_FLOAT_COMP_ALIGN_g;
+ }
+ }
+
+ /* Create new native type */
+ if(NULL==(dt=H5I_object_verify(tid, H5I_DATATYPE)))
+ HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "not a data type");
+ if((ret_value=H5T_copy(dt, H5T_COPY_TRANSIENT))==NULL)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "cannot retrieve float type");
+
+ /* compute size and offset of compound type member. */
+ if(comp_size && offset) {
+ /* Add alignment value */
+ if(align && *comp_size % align) {
+ *offset = *comp_size + (align - *comp_size % align);
+ size = size + (align - *comp_size % align);
+ } else
+ *offset = *comp_size;
+
+ *comp_size += size;
+ }
+ /* Alignment for whole compound type */
+ if(struct_align && *struct_align < align)
+ *struct_align = align;
+
+done:
+ FUNC_LEAVE(ret_value);
+}
+
+
+/*-------------------------------------------------------------------------
* Function: H5Tget_size
*
* Purpose: Determines the total size of a data type in bytes.
@@ -3097,9 +3742,42 @@ H5Tget_sign(hid_t type_id)
/* Check args */
if (NULL == (dt = H5I_object_verify(type_id,H5I_DATATYPE)))
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, H5T_SGN_ERROR, "not an integer data type");
+
+ ret_value = H5T_get_sign(dt);
+
+done:
+ FUNC_LEAVE(ret_value);
+}
+
+
+/*-------------------------------------------------------------------------
+ * Function: H5T_get_sign
+ *
+ * Purpose: Private function for H5Tget_sign. Retrieves the sign type
+ * for an integer type.
+ *
+ * Return: Success: The sign type.
+ *
+ * Failure: H5T_SGN_ERROR (Negative)
+ *
+ * Programmer: Raymond Lu
+ * October 8, 2002
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+H5T_sign_t
+H5T_get_sign(H5T_t *dt)
+{
+ H5T_sign_t ret_value;
+
+ FUNC_ENTER_NOAPI(H5T_get_sign, H5T_SGN_ERROR);
+
+ /* Check args */
+ if (!dt)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, H5T_SGN_ERROR, "not a valid data type");
if (dt->parent)
- dt = dt->parent; /*defer to parent*/
- if (H5T_INTEGER!=dt->type)
HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, H5T_SGN_ERROR, "operation not defined for data type class");
/* Sign */
@@ -3109,6 +3787,7 @@ done:
FUNC_LEAVE(ret_value);
}
+
/*-------------------------------------------------------------------------
* Function: H5Tset_sign
@@ -3802,6 +4481,45 @@ H5Tget_nmembers(hid_t type_id)
if (NULL == (dt = H5I_object_verify(type_id,H5I_DATATYPE)))
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a data type");
+ if((ret_value = H5T_get_nmembers(dt))<0)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "cannot return member number");
+
+done:
+ FUNC_LEAVE(ret_value);
+}
+
+
+/*-------------------------------------------------------------------------
+ * Function: H5T_get_nmembers
+ *
+ * Purpose: Private function for H5Tget_nmembers. Determines how many
+ * members DTYPE has. The type must be either a compound data i
+ * type or an enumeration data type.
+ *
+ * Return: Success: Number of members defined in the data type.
+ *
+ * Failure: Negative
+ *
+ * Errors:
+ *
+ * Programmer: Raymond Lu
+ * October 8, 2002
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+int
+H5T_get_nmembers(const H5T_t *dt)
+{
+ int ret_value;
+
+ FUNC_ENTER_NOAPI(H5T_get_nmembers, FAIL);
+
+ /* check argument */
+ if (NULL == dt)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a valid data type");
+
if (H5T_COMPOUND==dt->type)
ret_value = dt->u.compnd.nmembs;
else if (H5T_ENUM==dt->type)
@@ -3847,6 +4565,40 @@ H5Tget_member_name(hid_t type_id, int membno)
if (NULL == (dt = H5I_object_verify(type_id,H5I_DATATYPE)))
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "not a data type");
+ if((ret_value = H5T_get_member_name(dt, membno))==NULL)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "unable to get member name");
+
+done:
+ FUNC_LEAVE(ret_value);
+}
+
+
+/*-------------------------------------------------------------------------
+ * Function: H5T_get_member_name
+ *
+ * Purpose: Private function for H5Tget_member_name. Returns the name
+ * of a member of a compound or enumeration data type. Members
+ * are stored in no particular order with numbers 0 through
+ * N-1 where N is the value returned by H5Tget_nmembers().
+ *
+ * Return: Success: Ptr to a string allocated with malloc(). The
+ * caller is responsible for freeing the string.
+ *
+ * Failure: NULL
+ *
+ * Programmer: Raymond Lu
+ * October 9, 2002
+ *
+ * Modifications:
+ *-------------------------------------------------------------------------
+ */
+char *
+H5T_get_member_name(H5T_t *dt, int membno)
+{
+ char *ret_value;
+
+ FUNC_ENTER_NOAPI(H5T_get_member_name, NULL);
+
switch (dt->type) {
case H5T_COMPOUND:
if (membno<0 || membno>=dt->u.compnd.nmembs)
@@ -3925,7 +4677,7 @@ H5Tget_member_index(hid_t type_id, const char *name)
done:
FUNC_LEAVE(ret_value);
}
-
+
/*-------------------------------------------------------------------------
* Function: H5Tget_member_offset
@@ -3963,6 +4715,48 @@ H5Tget_member_offset(hid_t type_id, int membno)
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, 0, "invalid member number");
/* Value */
+ ret_value = H5T_get_member_offset(dt, membno);
+
+done:
+ FUNC_LEAVE(ret_value);
+}
+
+
+/*-------------------------------------------------------------------------
+ * Function: H5T_get_member_offset
+ *
+ * Purpose: Private function for H5Tget_member_offset. Returns the byte
+ * offset of the beginning of a member with respect to the i
+ * beginning of the compound data type datum.
+ *
+ * Return: Success: Byte offset.
+ *
+ * Failure: Zero. Zero is a valid offset, but this
+ * function will fail only if a call to
+ * H5Tget_member_dims() fails with the same
+ * arguments.
+ *
+ * Programmer: Raymond Lu
+ * October 8, 2002
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+size_t
+H5T_get_member_offset(H5T_t *dt, int membno)
+{
+ size_t ret_value;
+
+ FUNC_ENTER_NOAPI(H5T_get_member_offset, 0);
+
+ /* Check args */
+ if (!dt)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, 0, "not a valid data type");
+ if (membno < 0 || membno >= dt->u.compnd.nmembs)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, 0, "invalid member number");
+
+ /* Value */
ret_value = dt->u.compnd.memb[membno].offset;
done:
@@ -4008,6 +4802,7 @@ done:
FUNC_LEAVE(ret_value);
} /* end H5Tget_member_class() */
+
/*-------------------------------------------------------------------------
* Function: H5Tget_member_type
@@ -4047,10 +4842,8 @@ H5Tget_member_type(hid_t type_id, int membno)
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a compound data type");
if (membno < 0 || membno >= dt->u.compnd.nmembs)
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "invalid member number");
-
- /* Copy data type into an atom */
- if (NULL == (memb_dt = H5T_copy(dt->u.compnd.memb[membno].type, H5T_COPY_REOPEN)))
- HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "unable to copy member data type");
+ if ((memb_dt=H5T_get_member_type(dt, membno))==NULL)
+ HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "unable to retrieve member type");
if ((ret_value = H5I_register(H5I_DATATYPE, memb_dt)) < 0)
HGOTO_ERROR(H5E_DATATYPE, H5E_CANTREGISTER, FAIL, "unable register data type atom");
@@ -4065,6 +4858,48 @@ done:
/*-------------------------------------------------------------------------
+ * Function: H5T_get_member_type
+ *
+ * Purpose: Private function for H5Tget_member_type. Returns the data
+ * type of the specified member.
+ *
+ * Return: Success: A copy of the member data type;
+ * modifying the returned data type does not
+ * modify the member type.
+ *
+ * Failure: NULL
+ *
+ * Programmer: Raymond Lu
+ * October 8, 2002
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+H5T_t *
+H5T_get_member_type(H5T_t *dt, int membno)
+{
+ H5T_t *ret_value = NULL;
+
+ FUNC_ENTER_NOAPI(H5T_get_member_type, NULL);
+
+ /* Check args */
+ if (!dt)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "data type doesn't exist");
+ if (membno < 0 || membno >= dt->u.compnd.nmembs)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, NULL, "invalid member number");
+
+ /* Copy data type into an atom */
+ if (NULL == (ret_value = H5T_copy(dt->u.compnd.memb[membno].type, H5T_COPY_REOPEN)))
+ HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, NULL, "unable to copy member data type");
+
+done:
+ FUNC_LEAVE(ret_value);
+}
+
+
+
+/*-------------------------------------------------------------------------
* Function: H5Tinsert
*
* Purpose: Adds another member to the compound data type PARENT_ID. The
@@ -4190,13 +5025,8 @@ H5Tenum_create(hid_t parent_id)
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not an integer data type");
/* Build new type */
- if (NULL==(dt = H5FL_ALLOC(H5T_t,1)))
- HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed");
- dt->type = H5T_ENUM;
- dt->parent = H5T_copy(parent, H5T_COPY_ALL);
- dt->size = dt->parent->size;
- dt->ent.header = HADDR_UNDEF;
-
+ if((dt=H5T_enum_create(parent))==NULL)
+ HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "cannot create enum type");
/* Atomize the type */
if ((ret_value=H5I_register(H5I_DATATYPE, dt))<0)
HGOTO_ERROR(H5E_DATATYPE, H5E_CANTREGISTER, FAIL, "unable to register data type atom");
@@ -4207,6 +5037,45 @@ done:
/*-------------------------------------------------------------------------
+ * Function: H5T_enum_create
+ *
+ * Purpose: Private function for H5Tenum_create. Create a new
+ * enumeration data type based on the specified
+ * TYPE, which must be an integer type.
+ *
+ * Return: Success: new enumeration data type
+ *
+ * Failure: NULL
+ *
+ * Programmer: Raymond Lu
+ * October 9, 2002
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+H5T_t *
+H5T_enum_create(H5T_t *parent)
+{
+ H5T_t *ret_value = NULL; /*new enumeration data type */
+
+ FUNC_ENTER_NOAPI(H5T_enum_create, NULL);
+
+ /* Build new type */
+ if (NULL==(ret_value = H5FL_ALLOC(H5T_t,1)))
+ HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed");
+ ret_value->type = H5T_ENUM;
+ ret_value->parent = H5T_copy(parent, H5T_COPY_ALL);
+ ret_value->size = ret_value->parent->size;
+ ret_value->ent.header = HADDR_UNDEF;
+
+done:
+ FUNC_LEAVE(ret_value);
+}
+
+
+
+/*-------------------------------------------------------------------------
* Function: H5Tenum_insert
*
* Purpose: Insert a new enumeration data type member into an enumeration
@@ -4283,10 +5152,8 @@ H5Tget_super(hid_t type)
if (NULL==(dt=H5I_object_verify(type,H5I_DATATYPE)))
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a data type");
- if (!dt->parent)
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "not a derived data type");
- if (NULL==(super=H5T_copy(dt->parent, H5T_COPY_ALL)))
- HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "unable to copy parent data type");
+ if((super=H5T_get_super(dt))==NULL)
+ HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "not a data type");
if ((ret_value=H5I_register(H5I_DATATYPE, super))<0)
HGOTO_ERROR(H5E_DATATYPE, H5E_CANTREGISTER, FAIL, "unable to register parent data type");
@@ -4301,6 +5168,41 @@ done:
/*-------------------------------------------------------------------------
+ * Function: H5T_get_super
+ *
+ * Purpose: Private function for H5Tget_super. Returns the type from
+ * which TYPE is derived. In the case of an enumeration type
+ * the return value is an integer type.
+ *
+ * Return: Success: Data type for base data type.
+ *
+ * Failure: NULL
+ *
+ * Programmer: Raymond Lu
+ * October 9, 2002
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+H5T_t *
+H5T_get_super(H5T_t *dt)
+{
+ H5T_t *ret_value=NULL;
+
+ FUNC_ENTER_NOAPI(H5T_get_super, NULL);
+
+ if (!dt->parent)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, NULL, "not a derived data type");
+ if (NULL==(ret_value=H5T_copy(dt->parent, H5T_COPY_ALL)))
+ HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, NULL, "unable to copy parent data type");
+
+done:
+ FUNC_LEAVE(ret_value);
+}
+
+
+/*-------------------------------------------------------------------------
* Function: H5Tget_member_value
*
* Purpose: Return the value for an enumeration data type member.
@@ -4335,12 +5237,45 @@ H5Tget_member_value(hid_t type, int membno, void *value/*out*/)
if (!value)
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "null value buffer");
+ if (H5T_get_member_value(dt, membno, value)<0)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "unable to get member value");
+done:
+ FUNC_LEAVE(ret_value);
+}
+
+
+/*-------------------------------------------------------------------------
+ * Function: H5T_get_member_value
+ *
+ * Purpose: Private function for H5T_get_member_value. Return the
+ * value for an enumeration data type member.
+ *
+ * Return: Success: non-negative with the member value copied
+ * into the memory pointed to by VALUE.
+ *
+ * Failure: negative, VALUE memory is undefined.
+ *
+ * Programmer: Raymond Lu
+ * October 9, 2002
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+herr_t
+H5T_get_member_value(H5T_t *dt, int membno, void *value/*out*/)
+{
+ herr_t ret_value=SUCCEED; /* Return value */
+
+ FUNC_ENTER_NOAPI(H5T_get_member_value, FAIL);
+
HDmemcpy(value, dt->u.enumer.value + membno*dt->size, dt->size);
done:
FUNC_LEAVE(ret_value);
}
+
/*-------------------------------------------------------------------------
* Function: H5Tenum_nameof
@@ -7782,7 +8717,7 @@ H5Tget_array_ndims(hid_t type_id)
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not an array datatype");
/* Retrieve the number of dimensions */
- ret_value=dt->u.array.ndims;
+ ret_value = H5T_get_array_ndims(dt);
done:
FUNC_LEAVE(ret_value);
@@ -7790,6 +8725,37 @@ done:
/*-------------------------------------------------------------------------
+ * Function: H5T_get_array_ndims
+ *
+ * Purpose: Private function for H5T_get_array_ndims. Query the number
+ * of dimensions for an array datatype.
+ *
+ * Return: Success: Number of dimensions of the array datatype
+ * Failure: Negative
+ *
+ * Programmer: Raymond Lu
+ * October 10, 2002
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+int
+H5T_get_array_ndims(H5T_t *dt)
+{
+ int ret_value; /* return value */
+
+ FUNC_ENTER_NOAPI(H5T_get_array_ndims, FAIL);
+
+ /* Retrieve the number of dimensions */
+ ret_value=dt->u.array.ndims;
+
+done:
+ FUNC_LEAVE(ret_value);
+} /* end H5T_get_array_ndims */
+
+
+/*-------------------------------------------------------------------------
* Function: H5Tget_array_dims
*
* Purpose: Query the sizes of dimensions for an array datatype.
@@ -7821,6 +8787,38 @@ H5Tget_array_dims(hid_t type_id, hsize_t dims[], int perm[])
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not an array datatype");
/* Retrieve the sizes of the dimensions */
+ if(H5T_get_array_dims(dt, dims, perm)<0)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "unable to get dimension sizes");
+done:
+ FUNC_LEAVE(ret_value);
+} /* end H5Tget_array_dims */
+
+
+/*-------------------------------------------------------------------------
+ * Function: H5T_get_array_dims
+ *
+ * Purpose: Private function for H5T_get_array_dims. Query the sizes
+ * of dimensions for an array datatype.
+ *
+ * Return: Success: Non-negative
+ * Failure: Negative
+ *
+ * Programmer: Raymond Lu
+ * October 10, 2002
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+herr_t
+H5T_get_array_dims(H5T_t *dt, hsize_t dims[], int perm[])
+{
+ herr_t ret_value = SUCCEED; /* return value */
+ int i; /* Local index variable */
+
+ FUNC_ENTER_NOAPI(H5T_get_array_dims, FAIL);
+
+ /* Retrieve the sizes of the dimensions */
if(dims)
for(i=0; i<dt->u.array.ndims; i++)
dims[i]=dt->u.array.dim[i];
@@ -7832,7 +8830,8 @@ H5Tget_array_dims(hid_t type_id, hsize_t dims[], int perm[])
done:
FUNC_LEAVE(ret_value);
-} /* end H5Tget_array_dims */
+} /* end H5T_get_array_dims */
+
/*-------------------------------------------------------------------------
diff --git a/src/H5Tpkg.h b/src/H5Tpkg.h
index 8356f78..0adc4e9 100644
--- a/src/H5Tpkg.h
+++ b/src/H5Tpkg.h
@@ -175,6 +175,22 @@ H5_DLLVAR H5T_overflow_t H5T_overflow_g;
* Alignment information for native types. A value of N indicates that the
* data must be aligned on an address ADDR such that 0 == ADDR mod N. When
* N=1 no alignment is required; N=0 implies that alignment constraints were
+ * not calculated. These alignment info is only for H5Tget_native_type.
+ * These values are used for structure alignment.
+ */
+H5_DLLVAR size_t H5T_NATIVE_SCHAR_COMP_ALIGN_g;
+H5_DLLVAR size_t H5T_NATIVE_SHORT_COMP_ALIGN_g;
+H5_DLLVAR size_t H5T_NATIVE_INT_COMP_ALIGN_g;
+H5_DLLVAR size_t H5T_NATIVE_LONG_COMP_ALIGN_g;
+H5_DLLVAR size_t H5T_NATIVE_LLONG_COMP_ALIGN_g;
+H5_DLLVAR size_t H5T_NATIVE_FLOAT_COMP_ALIGN_g;
+H5_DLLVAR size_t H5T_NATIVE_DOUBLE_COMP_ALIGN_g;
+H5_DLLVAR size_t H5T_NATIVE_LDOUBLE_COMP_ALIGN_g;
+
+/*
+ * Alignment information for native types. A value of N indicates that the
+ * data must be aligned on an address ADDR such that 0 == ADDR mod N. When
+ * N=1 no alignment is required; N=0 implies that alignment constraints were
* not calculated.
*/
H5_DLLVAR size_t H5T_NATIVE_SCHAR_ALIGN_g;
diff --git a/src/H5Tprivate.h b/src/H5Tprivate.h
index b4606cb..cd75f05 100644
--- a/src/H5Tprivate.h
+++ b/src/H5Tprivate.h
@@ -108,11 +108,25 @@ H5_DLL herr_t H5T_path_force_reinit(H5T_t *dt);
H5_DLL H5T_class_t H5T_get_class(const H5T_t *dt);
H5_DLL htri_t H5T_detect_class (const H5T_t *dt, H5T_class_t cls);
H5_DLL size_t H5T_get_size(const H5T_t *dt);
-H5_DLL int H5T_cmp(const H5T_t *dt1, const H5T_t *dt2);
+H5_DLL H5T_sign_t H5T_get_sign(H5T_t *dt);
+H5_DLL H5T_t *H5T_get_super(H5T_t *dt);
+H5_DLL char *H5T_get_member_name(H5T_t *dt, int membno);
+H5_DLL herr_t H5T_get_member_value(H5T_t *dt, int membno, void *value);
+H5_DLL H5T_t *H5T_get_member_type(H5T_t *dt, int membno);
+H5_DLL size_t H5T_get_member_offset(H5T_t *dt, int membno);
+H5_DLL int H5T_get_nmembers(const H5T_t *dt);
+H5_DLL htri_t H5T_is_variable_str(H5T_t *dt);
+H5_DLL H5T_t *H5T_get_native_type(H5T_t *dt, H5T_direction_t direction, size_t *struct_align, size_t *offset, size_t *comp_size);
+H5_DLL H5T_t *H5T_get_native_integer(size_t size, H5T_sign_t sign, H5T_direction_t direction, size_t *struct_align, size_t *offset, size_t *comp_size);
+H5_DLL H5T_t *H5T_get_native_float(size_t size, H5T_direction_t direction, size_t *struct_align, size_t *offset, size_t *comp_size);
+H5_DLL int H5T_cmp(const H5T_t *dt1, const H5T_t *dt2);
H5_DLL htri_t H5T_is_atomic(const H5T_t *dt);
H5_DLL herr_t H5T_insert(H5T_t *parent, const char *name, size_t offset,
const H5T_t *member);
+H5_DLL H5T_t *H5T_enum_create(H5T_t *parent);
H5_DLL herr_t H5T_enum_insert(H5T_t *dt, const char *name, void *value);
+H5_DLL int H5T_get_array_ndims(H5T_t *dt);
+H5_DLL herr_t H5T_get_array_dims(H5T_t *dt, hsize_t dims[], int perm[]);
H5_DLL herr_t H5T_pack(H5T_t *dt);
H5_DLL herr_t H5T_debug(const H5T_t *dt, FILE * stream);
H5_DLL H5G_entry_t *H5T_entof(H5T_t *dt);
diff --git a/src/H5Tpublic.h b/src/H5Tpublic.h
index 1d66054..2bfc7da 100644
--- a/src/H5Tpublic.h
+++ b/src/H5Tpublic.h
@@ -157,6 +157,13 @@ typedef enum H5T_pers_t {
H5T_PERS_SOFT = 1 /*soft conversion function */
} H5T_pers_t;
+/* The order to retrieve atomic native datatype */
+typedef enum H5T_direction_t {
+ H5T_DIR_DEFAULT = 0, /*default direction is inscendent */
+ H5T_DIR_ASCEND = 1, /*in inscendent order */
+ H5T_DIR_DESCEND = 2 /*in descendent order */
+} H5T_direction_t;
+
/* Variable Length Datatype struct in memory */
/* (This is only used for VL sequences, not VL strings, which are stored in char *'s) */
typedef struct {
@@ -513,6 +520,8 @@ H5_DLL hid_t H5Tget_member_type(hid_t type_id, int membno);
H5_DLL herr_t H5Tget_member_value(hid_t type_id, int membno,
void *value/*out*/);
H5_DLL H5T_cset_t H5Tget_cset(hid_t type_id);
+H5_DLL htri_t H5Tis_variable_str(hid_t type_id);
+H5_DLL hid_t H5Tget_native_type(hid_t type_id, H5T_direction_t direction);
/* Setting property values */
H5_DLL herr_t H5Tset_size(hid_t type_id, size_t size);
diff --git a/src/H5detect.c b/src/H5detect.c
index 0f29eb3..65118e3 100644
--- a/src/H5detect.c
+++ b/src/H5detect.c
@@ -48,6 +48,7 @@ typedef struct detected_t {
int epos, esize; /*information about exponent */
unsigned long bias; /*exponent bias for floating pt.*/
size_t align; /*required byte alignment */
+ size_t comp_align; /*alignment for structure */
} detected_t;
static void print_results(int nd, detected_t *d);
@@ -248,6 +249,16 @@ precision (detected_t *d)
precision (&(INFO)); \
}
+/* Detect alignment for C structure */
+#define COMP_ALIGNMENT(TYPE,COMP_ALIGN) { \
+ struct { \
+ char c; \
+ TYPE x; \
+ } s; \
+ \
+ COMP_ALIGN = (size_t)((char*)(&(s.x)) - (char*)(&s)); \
+}
+
#if defined(H5_HAVE_LONGJMP) && defined(H5_HAVE_SIGNAL)
#define ALIGNMENT(TYPE,ALIGN) { \
char *volatile _buf=NULL; \
@@ -492,6 +503,15 @@ H5TN_init_interface(void)\n\
d[i].varname);
printf(" H5T_NATIVE_%s_ALIGN_g = %lu;\n",
d[i].varname, (unsigned long)(d[i].align));
+
+ /* Variables for alignment of compound datatype */
+ if(!strcmp(d[i].varname, "SCHAR") || !strcmp(d[i].varname, "SHORT") ||
+ !strcmp(d[i].varname, "INT") || !strcmp(d[i].varname, "LONG") ||
+ !strcmp(d[i].varname, "LLONG") || !strcmp(d[i].varname, "FLOAT") ||
+ !strcmp(d[i].varname, "DOUBLE") || !strcmp(d[i].varname, "LDOUBLE")) {
+ printf(" H5T_NATIVE_%s_COMP_ALIGN_g = %lu;\n",
+ d[i].varname, (unsigned long)(d[i].comp_align));
+ }
}
printf("\
@@ -1012,13 +1032,24 @@ main(void)
print_header();
/* C89 integer types */
- DETECT_I(signed char, SCHAR, d[nd]); nd++;
+ DETECT_I(signed char, SCHAR, d[nd]);
+ COMP_ALIGNMENT(signed char, d[nd].comp_align); nd++;
+
DETECT_I(unsigned char, UCHAR, d[nd]); nd++;
- DETECT_I(short, SHORT, d[nd]); nd++;
+
+ DETECT_I(short, SHORT, d[nd]);
+ COMP_ALIGNMENT(short, d[nd].comp_align); nd++;
+
DETECT_I(unsigned short, USHORT, d[nd]); nd++;
- DETECT_I(int, INT, d[nd]); nd++;
+
+ DETECT_I(int, INT, d[nd]);
+ COMP_ALIGNMENT(int, d[nd].comp_align); nd++;
+
DETECT_I(unsigned int, UINT, d[nd]); nd++;
- DETECT_I(long, LONG, d[nd]); nd++;
+
+ DETECT_I(long, LONG, d[nd]);
+ COMP_ALIGNMENT(long, d[nd].comp_align); nd++;
+
DETECT_I(unsigned long, ULONG, d[nd]); nd++;
/*
@@ -1098,7 +1129,9 @@ main(void)
#endif
#if H5_SIZEOF_LONG_LONG>0
- DETECT_I(long_long, LLONG, d[nd]); nd++;
+ DETECT_I(long_long, LLONG, d[nd]);
+ COMP_ALIGNMENT(long long, d[nd].comp_align); nd++;
+
DETECT_I(unsigned long_long, ULLONG, d[nd]); nd++;
#else
/*
@@ -1106,12 +1139,17 @@ main(void)
* so we'll just make H5T_NATIVE_LLONG the same as H5T_NATIVE_LONG since
* `long long' is probably equivalent to `long' here anyway.
*/
- DETECT_I(long, LLONG, d[nd]); nd++;
+ DETECT_I(long, LLONG, d[nd]);
+ COMP_ALIGNMENT(long, d[nd].comp_align); nd++;
+
DETECT_I(unsigned long, ULLONG, d[nd]); nd++;
#endif
- DETECT_F(float, FLOAT, d[nd]); nd++;
- DETECT_F(double, DOUBLE, d[nd]); nd++;
+ DETECT_F(float, FLOAT, d[nd]);
+ COMP_ALIGNMENT(float, d[nd].comp_align); nd++;
+
+ DETECT_F(double, DOUBLE, d[nd]);
+ COMP_ALIGNMENT(double, d[nd].comp_align); nd++;
#if H5_SIZEOF_DOUBLE == H5_SIZEOF_LONG_DOUBLE
/*
@@ -1120,11 +1158,14 @@ main(void)
* some systems and `long double' is probably the same as `double' here
* anyway.
*/
- DETECT_F(double, LDOUBLE, d[nd]); nd++;
+ DETECT_F(double, LDOUBLE, d[nd]);
+ COMP_ALIGNMENT(double, d[nd].comp_align); nd++;
#else
- DETECT_F(long double, LDOUBLE, d[nd]); nd++;
+ DETECT_F(long double, LDOUBLE, d[nd]);
+ COMP_ALIGNMENT(long double, d[nd].comp_align); nd++;
#endif
print_results (nd, d);
+
return 0;
}
diff --git a/test/Makefile.in b/test/Makefile.in
index 330eb32..0ea2fa5 100644
--- a/test/Makefile.in
+++ b/test/Makefile.in
@@ -19,7 +19,8 @@ CPPFLAGS=-I. -I$(srcdir) -I../src -I$(top_srcdir)/src @CPPFLAGS@
TEST_PROGS=testhdf5 lheap ohdr stab gheap hyperslab istore bittests dtypes \
dsets cmpd_dset extend external links unlink big mtime fillval mount \
flush1 flush2 enum gass_write gass_read gass_append set_extent \
- srb_write srb_append srb_read ttsafe stream_test getname file_handle
+ srb_write srb_append srb_read ttsafe stream_test getname file_handle \
+ ntypes
TIMINGS=testmeta
@@ -52,6 +53,7 @@ MOSTLYCLEAN=cmpd_dset.h5 compact_dataset.h5 dataset.h5 extend.h5 istore.h5 \
set_extent_read.h5 set_extent_create.h5 getname.h5 getname1.h5 \
getname2.h5 getname3.h5 sec2_file.h5 family_file000[0-3][0-9].h5 \
multi_file-[rs].h5 core_file new_move_[ab].h5
+
CLEAN=$(TIMINGS)
## Source and object files for programs... The TEST_SRC list contains all the
@@ -67,7 +69,7 @@ TEST_SRC=big.c bittests.c cmpd_dset.c dsets.c dtypes.c extend.c \
tvlstr.c tmisc.c unlink.c enum.c ttsafe.c ttsafe_dcreate.c \
ttsafe_error.c ttsafe_cancel.c ttsafe_acreate.c gass_write.c \
gass_read.c gass_append.c srb_read.c srb_write.c srb_append.c \
- stream_test.c set_extent.c getname.c file_handle.c
+ stream_test.c set_extent.c getname.c file_handle.c ntypes.c
TEST_OBJ=$(TEST_SRC:.c=.lo)
@@ -194,6 +196,9 @@ getname: getname.lo
@$(LT_LINK_EXE) $(CFLAGS) -o $@ getname.lo $(LIB) $(LIBHDF5) $(LDFLAGS) $(LIBS)
file_handle: file_handle.lo
- @$(LT_LINK_EXE) $(CFLAGS) -o $@ file_handle.lo $(LIB) $(LIBHDF5) $(LDFLAGS)
+ @$(LT_LINK_EXE) $(CFLAGS) -o $@ file_handle.lo $(LIB) $(LIBHDF5) $(LDFLAGS) $(LIBS)
+
+ntypes: ntypes.lo
+ @$(LT_LINK_EXE) $(CFLAGS) -o $@ ntypes.lo $(LIB) $(LIBHDF5) $(LDFLAGS) $(LIBS)
@CONCLUDE@
diff --git a/test/ntypes.c b/test/ntypes.c
new file mode 100644
index 0000000..b4534fe
--- /dev/null
+++ b/test/ntypes.c
@@ -0,0 +1,1390 @@
+/*
+ * Copyright (C) 1997 NCSA
+ * All rights reserved.
+ *
+ * Programmer: Raymond Lu
+ * October 14, 2001
+ *
+ * Purpose: Tests the H5Tget_native_type function.
+ */
+
+#include "h5test.h"
+
+const char *FILENAME[] = {
+ "ntypes",
+ NULL
+};
+
+#define DSET_ATOMIC_NAME_1 "atomic_type_1"
+#define DSET_ATOMIC_NAME_2 "atomic_type_2"
+#define DSET_ATOMIC_NAME_3 "atomic_type_3"
+#define DSET_ATOMIC_NAME_4 "atomic_type_4"
+#define DSET_COMPOUND_NAME "compound_type"
+#define DSET_COMPOUND_NAME_2 "compound_type_2"
+#define DSET_ENUM_NAME "enum_type"
+#define DSET_ARRAY_NAME "array_type"
+#define DSET_VL_NAME "vl_type"
+#define DSET_VLSTR_NAME "vlstr_type"
+#define DSET_OPAQUE_NAME "opaque_type"
+#define DSET_BITFIELD_NAME "bitfield_type"
+
+#define SPACE1_DIM1 4
+#define SPACE1_RANK 1
+
+
+/*-------------------------------------------------------------------------
+ * Function: test_atomic_dtype
+ *
+ * Purpose: Test H5Tget_native_type for atomic datatype
+ *
+ * Return: Success: 0
+ *
+ * Failure: -1
+ *
+ * Programmer: Raymond Lu
+ * October 15, 2002
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+static herr_t
+test_atomic_dtype(hid_t file)
+{
+ hid_t dataset, space;
+ hid_t dtype, native_type;
+ int i, j, n;
+ hsize_t dims[2];
+ int points[100][200], check[100][200];
+
+ TESTING("atomic datatype");
+
+ /* Initialize the dataset */
+ for (i = n = 0; i < 100; i++) {
+ for (j = 0; j < 200; j++) {
+ points[i][j] = n++;
+ }
+ }
+
+ /* Create the data space */
+ dims[0] = 100;
+ dims[1] = 200;
+ if ((space = H5Screate_simple(2, dims, NULL))<0) goto error;
+
+ /*------------------- Test data values ------------------------*/
+ /* Create the dataset */
+ if ((dataset = H5Dcreate(file, DSET_ATOMIC_NAME_1, H5T_STD_I32BE, space,
+ H5P_DEFAULT))<0) goto error;
+
+ /* Write the data to the dataset */
+ if (H5Dwrite(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, points)<0)
+ goto error;
+
+ /* Close dataset */
+ if(H5Dclose(dataset)<0) goto error;
+
+ /* Open dataset again to check H5Tget_native_type */
+ if((dataset=H5Dopen(file, DSET_ATOMIC_NAME_1))<0) goto error;
+
+ if((dtype=H5Dget_type(dataset))<0) goto error;
+
+ if((native_type=H5Tget_native_type(dtype, H5T_DIR_DEFAULT))<0)
+ goto error;
+
+ /* Verify the datatype retrieved and converted */
+ if(H5Tget_order(native_type) != H5Tget_order(H5T_NATIVE_INT))
+ goto error;
+ if(sizeof(int)!=H5Tget_size(native_type))
+ goto error;
+ if(H5T_INTEGER!=H5Tget_class(native_type))
+ goto error;
+
+ /* Read the dataset back */
+ if (H5Dread(dataset, native_type, H5S_ALL, H5S_ALL, H5P_DEFAULT, check)<0)
+ goto error;
+
+ /* Check that the values read are the same as the values written */
+ for (i = 0; i < 100; i++) {
+ for (j = 0; j < 200; j++) {
+ if (points[i][j] != check[i][j]) {
+ H5_FAILED();
+ printf(" Read different values than written.\n");
+ printf(" At index %d,%d\n", i, j);
+ goto error;
+ }
+ }
+ }
+
+ H5Dclose(dataset);
+ H5Tclose(dtype);
+
+ /*------------------ Test different data types ----------------*/
+
+ /* Create the dataset of H5T_STD_I64LE */
+ if ((dataset = H5Dcreate(file, DSET_ATOMIC_NAME_2, H5T_STD_I64LE, space,
+ H5P_DEFAULT))<0) goto error;
+
+ if((dtype=H5Dget_type(dataset))<0) goto error;
+
+ if((native_type=H5Tget_native_type(dtype, H5T_DIR_DEFAULT))<0)
+ goto error;
+
+ /* Verify the datatype retrieved and converted */
+ if(H5Tget_order(native_type) != H5Tget_order(H5T_NATIVE_LLONG))
+ goto error;
+ if(sizeof(long long)!=H5Tget_size(native_type))
+ goto error;
+ if(H5T_INTEGER!=H5Tget_class(native_type))
+ goto error;
+
+ if(H5Dclose(dataset)<0) goto error;
+ if(H5Tclose(dtype)<0) goto error;
+
+
+ /* Create the dataset of H5T_STD_I8LE */
+ if ((dataset = H5Dcreate(file, DSET_ATOMIC_NAME_3, H5T_STD_I8LE, space,
+ H5P_DEFAULT))<0) goto error;
+
+ if((dtype=H5Dget_type(dataset))<0) goto error;
+
+ if((native_type=H5Tget_native_type(dtype, H5T_DIR_ASCEND))<0)
+ goto error;
+
+ /* Verify the datatype retrieved and converted */
+ if(H5Tget_order(native_type) != H5Tget_order(H5T_NATIVE_CHAR))
+ goto error;
+ if(sizeof(char)!=H5Tget_size(native_type))
+ goto error;
+ if(H5T_INTEGER!=H5Tget_class(native_type))
+ goto error;
+
+ if(H5Dclose(dataset)<0) goto error;
+ if(H5Tclose(dtype)<0) goto error;
+
+
+ /* Create the dataset of H5T_IEEE_F64BE */
+ if ((dataset = H5Dcreate(file, DSET_ATOMIC_NAME_4, H5T_IEEE_F32BE, space,
+ H5P_DEFAULT))<0) goto error;
+
+ if((dtype=H5Dget_type(dataset))<0) goto error;
+
+ if((native_type=H5Tget_native_type(dtype, H5T_DIR_DESCEND))<0)
+ goto error;
+
+ /* Verify the datatype retrieved and converted */
+ if(H5Tget_order(native_type) != H5Tget_order(H5T_NATIVE_FLOAT))
+ goto error;
+ if(sizeof(float)!=H5Tget_size(native_type))
+ goto error;
+ if(H5T_FLOAT!=H5Tget_class(native_type))
+ goto error;
+
+ if(H5Dclose(dataset)<0) goto error;
+ if(H5Tclose(dtype)<0) goto error;
+
+
+ /* Close dataspace */
+ if(H5Sclose(space)<0) goto error;
+
+ PASSED();
+ return 0;
+
+ error:
+ return -1;
+}
+
+
+/*-------------------------------------------------------------------------
+ * Function: test_compound_dtype_2
+ *
+ * Purpose: Test H5Tget_native_type for compound datatype
+ *
+ * Return: Success: 0
+ *
+ * Failure: -1
+ *
+ * Programmer: Raymond Lu
+ * October 15, 2002
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+static herr_t
+test_compound_dtype_2(hid_t file)
+{
+ typedef struct s2 {
+ short c2;
+ } s2;
+ typedef struct s1 {
+ char c;
+ int i;
+ s2 st;
+ unsigned long long l;
+ } s1;
+ hid_t dataset, space;
+ hid_t dtype, native_type, tid, tid2, tid_m, tid_m2;
+ int i, j, n;
+ hsize_t dims[2];
+ s1 points[100][200], check[100][200];
+
+ TESTING("compound_2 datatype");
+
+ /* Initialize the dataset */
+ for (i = n = 0; i < 100; i++) {
+ for (j = 0; j < 200; j++) {
+ (points[i][j]).c = 't';
+ (points[i][j]).i = n++;
+ (points[i][j]).st.c2 = i+j;
+ (points[i][j]).l = (i*10+j*100)*n;
+ }
+ }
+
+ /* Create the data space */
+ dims[0] = 100;
+ dims[1] = 200;
+ if ((space = H5Screate_simple(2, dims, NULL))<0) goto error;
+
+ /* Create compound datatype for disk storage */
+ if((tid2=H5Tcreate(H5T_COMPOUND, 2))<0) goto error;
+ if((tid=H5Tcreate(H5T_COMPOUND, 15))<0) goto error;
+
+ /* Insert and pack members */
+ if(H5Tinsert(tid2, "c2", 0, H5T_STD_I16BE)<0) goto error;
+
+ if(H5Tinsert(tid, "c", 0, H5T_NATIVE_CHAR)<0) goto error;
+ if(H5Tinsert(tid, "i", 1, H5T_STD_I32LE)<0) goto error;
+ if(H5Tinsert(tid, "st", 5, tid2)<0) goto error;
+ if(H5Tinsert(tid, "l", 7, H5T_STD_U64BE)<0) goto error;
+
+ /* Create the dataset */
+ if ((dataset = H5Dcreate(file, DSET_COMPOUND_NAME_2, tid, space,
+ H5P_DEFAULT))<0) goto error;
+
+ /* Create compound datatype for memory */
+ if((tid_m2=H5Tcreate(H5T_COMPOUND, sizeof(s2)))<0) goto error;
+ if((tid_m=H5Tcreate(H5T_COMPOUND, sizeof(s1)))<0) goto error;
+
+ /* Insert members */
+ if(H5Tinsert(tid_m2, "c2", HOFFSET(s2, c2), H5T_NATIVE_SHORT)<0) goto error;
+ if(H5Tinsert(tid_m, "c", HOFFSET(s1, c), H5T_NATIVE_CHAR)<0) goto error;
+ if(H5Tinsert(tid_m, "i", HOFFSET(s1, i), H5T_NATIVE_INT)<0) goto error;
+ if(H5Tinsert(tid_m, "st", HOFFSET(s1, st), tid_m2)<0) goto error;
+ if(H5Tinsert(tid_m, "l", HOFFSET(s1, l), H5T_NATIVE_ULLONG)<0) goto error;
+
+ /* Write the data to the dataset */
+ if (H5Dwrite(dataset, tid_m, H5S_ALL, H5S_ALL, H5P_DEFAULT, points)<0)
+ goto error;
+
+ /* Close dataset */
+ if(H5Dclose(dataset)<0) goto error;
+
+ /* Close datatype */
+ if(H5Tclose(tid2)<0) goto error;
+ if(H5Tclose(tid)<0) goto error;
+ if(H5Tclose(tid_m2)<0) goto error;
+
+ /* Close dataspace */
+ if(H5Sclose(space)<0) goto error;
+
+
+ /* Open dataset again to check H5Tget_native_type */
+ if((dataset=H5Dopen(file, DSET_COMPOUND_NAME_2))<0) goto error;
+
+ if((dtype=H5Dget_type(dataset))<0) goto error;
+
+ if((native_type=H5Tget_native_type(dtype, H5T_DIR_DEFAULT))<0)
+ goto error;
+
+ if(!H5Tequal(native_type, tid_m))
+ goto error;
+
+ /* Read the dataset back */
+ if (H5Dread(dataset, native_type, H5S_ALL, H5S_ALL, H5P_DEFAULT, check)<0)
+ goto error;
+
+ /* Check that the values read are the same as the values written */
+ for (i = 0; i < 100; i++) {
+ for (j = 0; j < 200; j++) {
+ if ((points[i][j]).c != (check[i][j]).c ||
+ (points[i][j]).i != (check[i][j]).i ||
+ (points[i][j]).st.c2 != (check[i][j]).st.c2 ||
+ (points[i][j]).l != (check[i][j]).l ) {
+ H5_FAILED();
+ printf(" Read different values than written.\n");
+ printf(" At index %d,%d\n", i, j);
+ goto error;
+ }
+ }
+ }
+
+ H5Dclose(dataset);
+ H5Tclose(dtype);
+ H5Tclose(native_type);
+ H5Tclose(tid_m);
+ PASSED();
+ return 0;
+
+ error:
+ return -1;
+}
+
+
+/*-------------------------------------------------------------------------
+ * Function: test_compound_dtype
+ *
+ * Purpose: Test H5Tget_native_type for compound datatype
+ *
+ * Return: Success: 0
+ *
+ * Failure: -1
+ *
+ * Programmer: Raymond Lu
+ * October 15, 2002
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+static herr_t
+test_compound_dtype(hid_t file)
+{
+ typedef struct {
+ char c;
+ unsigned int i;
+ long long l;
+ } s1;
+ hid_t dataset, space;
+ hid_t dtype, native_type, tid, tid2;
+ int i, j, n;
+ hsize_t dims[2];
+ s1 points[100][200], check[100][200];
+
+ TESTING("compound datatype");
+
+ /* Initialize the dataset */
+ for (i = n = 0; i < 100; i++) {
+ for (j = 0; j < 200; j++) {
+ (points[i][j]).c = 't';
+ (points[i][j]).i = n++;
+ (points[i][j]).l = (i*10+j*100)*n;
+ }
+ }
+
+ /* Create the data space */
+ dims[0] = 100;
+ dims[1] = 200;
+ if ((space = H5Screate_simple(2, dims, NULL))<0) goto error;
+
+ /* Create compound datatype for disk storage */
+ if((tid=H5Tcreate(H5T_COMPOUND, sizeof(s1)))<0) goto error;
+
+ /* Insert members */
+ if(H5Tinsert(tid, "c", 0, H5T_NATIVE_CHAR)<0) goto error;
+ if(H5Tinsert(tid, "i", 1, H5T_STD_U32LE)<0) goto error;
+ if(H5Tinsert(tid, "l", 5, H5T_STD_I64BE)<0) goto error;
+
+ /* Create the dataset */
+ if ((dataset = H5Dcreate(file, DSET_COMPOUND_NAME, tid, space,
+ H5P_DEFAULT))<0) goto error;
+
+ /* Create compound datatype for datatype in memory */
+ if((tid2=H5Tcreate(H5T_COMPOUND, sizeof(s1)))<0) goto error;
+ if(H5Tinsert(tid2, "c", HOFFSET(s1, c), H5T_NATIVE_CHAR)<0) goto error;
+ if(H5Tinsert(tid2, "i", HOFFSET(s1, i), H5T_NATIVE_UINT)<0) goto error;
+ if(H5Tinsert(tid2, "l", HOFFSET(s1, l), H5T_NATIVE_LLONG)<0) goto error;
+
+ /* Write the data to the dataset */
+ if (H5Dwrite(dataset, tid2, H5S_ALL, H5S_ALL, H5P_DEFAULT, points)<0)
+ goto error;
+
+ /* Close dataset */
+ if(H5Dclose(dataset)<0) goto error;
+
+ /* Close datatype */
+ if(H5Tclose(tid)<0) goto error;
+
+ /* Close dataspace */
+ if(H5Sclose(space)<0) goto error;
+
+
+ /* Open dataset again to check H5Tget_native_type */
+ if((dataset=H5Dopen(file, DSET_COMPOUND_NAME))<0) goto error;
+
+ if((dtype=H5Dget_type(dataset))<0) goto error;
+
+ if((native_type=H5Tget_native_type(dtype, H5T_DIR_DEFAULT))<0)
+ goto error;
+
+ if(!H5Tequal(native_type, tid2))
+ goto error;
+
+ /* Read the dataset back */
+ if (H5Dread(dataset, native_type, H5S_ALL, H5S_ALL, H5P_DEFAULT, check)<0)
+ goto error;
+
+ /* Check that the values read are the same as the values written */
+ for (i = 0; i < 100; i++) {
+ for (j = 0; j < 200; j++) {
+ if ((points[i][j]).c != (check[i][j]).c ||
+ (points[i][j]).i != (check[i][j]).i ||
+ (points[i][j]).l != (check[i][j]).l ) {
+ H5_FAILED();
+ printf(" Read different values than written.\n");
+ printf(" At index %d,%d\n", i, j);
+ goto error;
+ }
+ }
+ }
+
+ H5Dclose(dataset);
+ H5Tclose(dtype);
+ H5Tclose(native_type);
+ H5Tclose(tid2);
+ PASSED();
+ return 0;
+
+ error:
+ return -1;
+}
+
+
+/*-------------------------------------------------------------------------
+ * Function: test_enum_dtype
+ *
+ * Purpose: Test H5Tget_native_type for enumerate datatype
+ *
+ * Return: Success: 0
+ *
+ * Failure: -1
+ *
+ * Programmer: Raymond Lu
+ * October 15, 2002
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+static herr_t
+test_enum_dtype(hid_t file)
+{
+ hid_t dataset, space;
+ hid_t tid, tid_m, dtype, native_type;
+ int i, j, n;
+ hsize_t dims[2];
+ short points[100][200], check[100][200];
+ short colors[8];
+ char *mname[] = { "RED",
+ "GREEN",
+ "BLUE",
+ "YELLOW",
+ "PINK",
+ "PURPLE",
+ "ORANGE",
+ "WHITE" };
+
+ TESTING("enum datatype");
+
+ /* Initialize the dataset */
+ for (i = 0; i < 100; i++) {
+ for (j=0, n=0; j < 200; j++, n++)
+ points[i][j] = (i*10+j*100+n)%8;
+ }
+
+ /* Create the data space */
+ dims[0] = 100;
+ dims[1] = 200;
+ if ((space = H5Screate_simple(2, dims, NULL))<0) goto error;
+
+ /* Construct enum type based on native type */
+ if((tid=H5Tenum_create(H5T_STD_I16LE))<0) goto error;
+
+ for (i = 0; i < 8; i++) {
+ colors[i] = i;
+ if(H5Tenum_insert(tid, mname[i], &(colors[i]))<0) goto error;
+ }
+
+ /* Create the dataset */
+ if ((dataset = H5Dcreate(file, DSET_ENUM_NAME, tid, space,
+ H5P_DEFAULT))<0) goto error;
+
+ /* Construct enum type based on native type in memory */
+ if((tid_m=H5Tenum_create(H5T_NATIVE_SHORT))<0) goto error;
+
+ for (i = 0; i < 8; i++) {
+ colors[i] = i;
+ if(H5Tenum_insert(tid_m, mname[i], &(colors[i]))<0) goto error;
+ }
+
+ /* Write the data to the dataset */
+ if (H5Dwrite(dataset, tid_m, H5S_ALL, H5S_ALL, H5P_DEFAULT, points)<0)
+ goto error;
+
+ /* Close dataset */
+ if(H5Dclose(dataset)<0) goto error;
+
+ /* Close datatype */
+ if(H5Tclose(tid)<0) goto error;
+
+ /* Close dataspace */
+ if(H5Sclose(space)<0) goto error;
+
+ /* Open dataset again to check H5Tget_native_type */
+ if((dataset=H5Dopen(file, DSET_ENUM_NAME))<0) goto error;
+
+ if((dtype=H5Dget_type(dataset))<0) goto error;
+
+ if((native_type=H5Tget_native_type(dtype, H5T_DIR_DEFAULT))<0)
+ goto error;
+
+ if(!H5Tequal(native_type, tid_m))
+ goto error;
+
+ /* Read the dataset back */
+ if (H5Dread(dataset, native_type, H5S_ALL, H5S_ALL, H5P_DEFAULT, check)<0)
+ goto error;
+
+ /* Check that the values read are the same as the values written */
+ for (i = 0; i < 100; i++) {
+ for (j = 0; j < 200; j++) {
+ if (points[i][j] != check[i][j]) {
+ H5_FAILED();
+ printf(" Read different values than written.\n");
+ printf(" At index %d,%d\n", i, j);
+ goto error;
+ }
+ }
+ }
+
+ H5Dclose(dataset);
+ H5Tclose(dtype);
+ H5Tclose(native_type);
+ H5Tclose(tid_m);
+ PASSED();
+ return 0;
+
+ error:
+ return -1;
+}
+
+
+/*-------------------------------------------------------------------------
+ * Function: test_array_dtype
+ *
+ * Purpose: Test H5Tget_native_type for array datatype
+ *
+ * Return: Success: 0
+ *
+ * Failure: -1
+ *
+ * Programmer: Raymond Lu
+ * October 15, 2002
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+static herr_t
+test_array_dtype(hid_t file)
+{
+ typedef struct {
+ char c;
+ int i;
+ long long l;
+ } s1;
+ hid_t dataset, space, tmp_t;
+ hid_t dtype, native_type, tid, tid2, tid3, tid_m;
+ int i, j, k, n;
+ hsize_t space_dims[2], array_dims[1]={5};
+ s1 points[100][200][5], check[100][200][5];
+
+ TESTING("array datatype");
+
+ /* Initialize the dataset */
+ for (i = n = 0; i < 100; i++) {
+ for (j = 0; j < 200; j++) {
+ for(k = 0; k < 5; k++) {
+ (points[i][j][k]).c = 't';
+ (points[i][j][k]).i = n++;
+ (points[i][j][k]).l = (i*10+j*100)*n;
+ }
+ }
+ }
+
+ /* Create the data space */
+ space_dims[0] = 100;
+ space_dims[1] = 200;
+ if ((space = H5Screate_simple(2, space_dims, NULL))<0) goto error;
+
+ /* Create compound datatype for disk storage */
+ if((tid2=H5Tcreate(H5T_COMPOUND, 13))<0) goto error;
+
+ /* Insert members */
+ if(H5Tinsert(tid2, "c", 0, H5T_NATIVE_CHAR)<0) goto error;
+ if(H5Tinsert(tid2, "i", 1, H5T_STD_U32LE)<0) goto error;
+ if(H5Tinsert(tid2, "l", 5, H5T_STD_I64BE)<0) goto error;
+
+ /* Create array datatype for disk storage */
+ if((tid=H5Tarray_create(tid2, 1, array_dims, NULL))<0) goto error;
+
+ /* Create the dataset */
+ if ((dataset = H5Dcreate(file, DSET_ARRAY_NAME, tid, space,
+ H5P_DEFAULT))<0) goto error;
+
+ /* Create compound datatype for datatype in memory */
+ if((tid3=H5Tcreate(H5T_COMPOUND, sizeof(s1)))<0) goto error;
+ if(H5Tinsert(tid3, "c", HOFFSET(s1, c), H5T_NATIVE_CHAR)<0) goto error;
+ if(H5Tinsert(tid3, "i", HOFFSET(s1, i), H5T_NATIVE_UINT)<0) goto error;
+ if(H5Tinsert(tid3, "l", HOFFSET(s1, l), H5T_NATIVE_LLONG)<0) goto error;
+
+ /* Create array datatype for memory */
+ if((tid_m=H5Tarray_create(tid3, 1, array_dims, NULL))<0) goto error;
+
+ /* Write the data to the dataset */
+ if (H5Dwrite(dataset, tid_m, H5S_ALL, H5S_ALL, H5P_DEFAULT, points)<0)
+ goto error;
+
+ /* Close dataset */
+ if(H5Dclose(dataset)<0) goto error;
+
+ /* Close datatype */
+ if(H5Tclose(tid)<0) goto error;
+ if(H5Tclose(tid2)<0) goto error;
+
+ /* Close dataspace */
+ if(H5Sclose(space)<0) goto error;
+
+ /* Open dataset again to check H5Tget_native_type */
+ if((dataset=H5Dopen(file, DSET_ARRAY_NAME))<0) goto error;
+
+ if((dtype=H5Dget_type(dataset))<0) goto error;
+
+ if((native_type=H5Tget_native_type(dtype, H5T_DIR_DEFAULT))<0)
+ goto error;
+
+ if(!H5Tequal(tid_m, native_type)) goto error;
+
+ /* Read the dataset back */
+ if (H5Dread(dataset, native_type, H5S_ALL, H5S_ALL, H5P_DEFAULT, check)<0)
+ goto error;
+
+ /* Check that the values read are the same as the values written */
+ for (i = 0; i < 100; i++) {
+ for (j = 0; j < 200; j++) {
+ for (k = 0; k < 5; k++) {
+ if ((points[i][j][k]).c != (check[i][j][k]).c ||
+ (points[i][j][k]).i != (check[i][j][k]).i ||
+ (points[i][j][k]).l != (check[i][j][k]).l ) {
+ H5_FAILED();
+ printf(" Read different values than written.\n");
+ printf(" At index %d,%d\n", i, j);
+ goto error;
+ }
+ }
+ }
+ }
+
+ if(H5Dclose(dataset)) goto error;
+ if(H5Tclose(native_type)) goto error;
+ if(H5Tclose(dtype)) goto error;
+ if(H5Tclose(tid_m)<0) goto error;
+ if(H5Tclose(tid3)<0) goto error;
+ PASSED();
+ return 0;
+
+ error:
+ return -1;
+}
+
+
+/****************************************************************
+**
+** test_vl_alloc_custom(): Test VL datatype custom memory
+** allocation routines. This routine just uses malloc to
+** allocate the memory and increments the amount of memory
+** allocated.
+**
+****************************************************************/
+static void *test_vl_alloc_custom(size_t size, void *info)
+{
+ void *ret_value=NULL; /* Pointer to return */
+ size_t *mem_used=(size_t *)info; /* Get the pointer to the memory used */
+ size_t extra; /* Extra space needed */
+
+ /*
+ * This weird contortion is required on the DEC Alpha to keep the
+ * alignment correct - QAK
+ */
+ extra=MAX(sizeof(void *),sizeof(size_t));
+
+ if((ret_value=HDmalloc(extra+size))!=NULL) {
+ *(size_t *)ret_value=size;
+ *mem_used+=size;
+ } /* end if */
+ ret_value=((unsigned char *)ret_value)+extra;
+ return(ret_value);
+}
+
+
+/****************************************************************
+**
+** test_vl_free_custom(): Test VL datatype custom memory
+** allocation routines. This routine just uses free to
+** release the memory and decrements the amount of memory
+** allocated.
+**
+****************************************************************/
+static void test_vl_free_custom(void *_mem, void *info)
+{
+ unsigned char *mem;
+ size_t *mem_used=(size_t *)info; /* Get the pointer to the memory used */
+ size_t extra; /* Extra space needed */
+
+ /*
+ * This weird contortion is required on the DEC Alpha to keep the
+ * alignment correct - QAK
+ */
+ extra=MAX(sizeof(void *),sizeof(size_t));
+
+ if(_mem!=NULL) {
+ mem=((unsigned char *)_mem)-extra;
+ *mem_used-=*(size_t *)mem;
+ HDfree(mem);
+ } /* end if */
+}
+
+
+/*-------------------------------------------------------------------------
+ * Function: test_vl_dtype
+ *
+ * Purpose: Test H5Tget_native_type for variable length datatype
+ *
+ * Return: Success: 0
+ *
+ * Failure: -1
+ *
+ * Programmer: Raymond Lu
+ * October 15, 2002
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+static herr_t
+test_vl_dtype(hid_t file)
+{
+ hvl_t wdata[SPACE1_DIM1]; /* Information to write */
+ hvl_t rdata[SPACE1_DIM1]; /* Information read in */
+ hvl_t *t1, *t2; /* Temporary pointer to VL information */
+ hid_t xfer_pid; /* Dataset transfer property list ID */
+ hsize_t dims1[] = {SPACE1_DIM1};
+ size_t mem_used=0; /* Memory used during allocation */
+
+ hid_t dataset, space;
+ hid_t dtype, native_type, tid, tid2, tid_m, tid_m2;
+ int i, j, k;
+
+ TESTING("variable length datatype");
+
+ /* Allocate and initialize VL data to write */
+ for(i=0; i<SPACE1_DIM1; i++) {
+ wdata[i].p=malloc((i+1)*sizeof(hvl_t));
+ if(wdata[i].p==NULL) {
+ printf("Cannot allocate memory for VL data! i=%u\n",i);
+ H5_FAILED();
+ goto error;
+ } /* end if */
+ wdata[i].len=i+1;
+ for(t1=wdata[i].p,j=0; j<(i+1); j++, t1++) {
+ t1->p=malloc((j+1)*sizeof(unsigned int));
+ if(t1->p==NULL) {
+ printf("Cannot allocate memory for VL data! i=%u, j=%u\n",i,j);
+ H5_FAILED();
+ goto error;
+ } /* end if */
+ t1->len=j+1;
+ for(k=0; k<(j+1); k++)
+ ((unsigned int *)t1->p)[k]=i*100+j*10+k;
+ } /* end for */
+ } /* end for */
+
+ /* Create dataspace for datasets */
+ if((space = H5Screate_simple(SPACE1_RANK, dims1, NULL))<0) goto error;
+
+ /* Create the base VL type */
+ if((tid2 = H5Tvlen_create (H5T_STD_U32LE))<0) goto error;
+
+ /* Create a VL datatype for disk storage */
+ tid = H5Tvlen_create (tid2);
+
+ /* Create a dataset */
+ if((dataset=H5Dcreate(file, DSET_VL_NAME, tid, space, H5P_DEFAULT))<0)
+ goto error;
+
+ /* Create a base VL datatype for memory */
+ if((tid_m2 = H5Tvlen_create (H5T_NATIVE_UINT))<0) goto error;
+
+ /* Create a VL datatype for memory */
+ if((tid_m = H5Tvlen_create (tid_m2))<0) goto error;
+
+ /* Write dataset to disk */
+ if(H5Dwrite(dataset,tid_m,H5S_ALL,H5S_ALL,H5P_DEFAULT,wdata)<0) goto error;
+
+ /* Close Dataset */
+ if(H5Dclose(dataset)<0) goto error;
+
+ /* Close datatype */
+ if(H5Tclose(tid2)<0) goto error;
+ if(H5Tclose(tid)<0) goto error;
+
+ /* Open a dataset */
+ if((dataset=H5Dopen(file, DSET_VL_NAME))<0) goto error;
+
+ /* Get datatype for dataset */
+ if((dtype = H5Dget_type(dataset))<0) goto error;
+
+ if((native_type=H5Tget_native_type(dtype, H5T_DIR_DEFAULT))<0)
+ goto error;
+
+ if(!H5Tequal(native_type, tid_m))
+ goto error;
+
+ /* Change to the custom memory allocation routines for reading VL data */
+ if((xfer_pid=H5Pcreate(H5P_DATASET_XFER))<0) goto error;
+
+ if(H5Pset_vlen_mem_manager(xfer_pid,test_vl_alloc_custom,&mem_used,test_vl_free_custom,&mem_used)<0)
+ goto error;
+
+ /* Read dataset from disk */
+ if(H5Dread(dataset,native_type,H5S_ALL,H5S_ALL,xfer_pid,rdata)<0) goto error;
+
+ /* Compare data read in */
+ for(i=0; i<SPACE1_DIM1; i++) {
+ if(wdata[i].len!=rdata[i].len) {
+ H5_FAILED();
+ printf("VL data length don't match!, wdata[%d].len=%d, rdata[%d].len=%d\n",(int)i,(int)wdata[i].len,(int)i,(int)rdata[i].len);
+ goto error;
+ } /* end if */
+ for(t1=wdata[i].p, t2=rdata[i].p, j=0; j<rdata[i].len; j++, t1++, t2++) {
+ if(t1->len!=t2->len) {
+ H5_FAILED();
+ printf("VL data length don't match!, wdata[%d].len=%d, rdata[%d].len=%d\n",(int)i,(int)wdata[i].len,(int)i,(int)rdata[i].len);
+ goto error;
+ } /* end if */
+ for(k=0; k<t2->len; k++) {
+ if( ((unsigned int *)t1->p)[k] != ((unsigned int *)t2->p)[k] ) {
+ H5_FAILED();
+ printf("VL data length don't match!, wdata[%d].len=%d, rdata[%d].len=%d\n",(int)i,(int)wdata[i].len,(int)i,(int)rdata[i].len);
+ goto error;
+ }
+ } /* end for */
+ } /* end for */
+ } /* end for */
+
+ /* Reclaim the read VL data */
+ if(H5Dvlen_reclaim(native_type,space,xfer_pid,rdata)<0) goto error;
+
+ /* Reclaim the write VL data */
+ if(H5Dvlen_reclaim(native_type,space,H5P_DEFAULT,wdata)<0) goto error;
+
+ /* Close Dataset */
+ if(H5Dclose(dataset)<0) goto error;
+
+ /* Close datatype */
+ if(H5Tclose(native_type)<0) goto error;
+ if(H5Tclose(dtype)<0) goto error;
+ if(H5Tclose(tid_m)<0) goto error;
+ if(H5Tclose(tid_m2)<0) goto error;
+
+
+ /* Close disk dataspace */
+ if(H5Sclose(space)<0) goto error;
+
+ /* Close dataset transfer property list */
+ if(H5Pclose(xfer_pid)<0) goto error;
+
+ PASSED();
+ return 0;
+
+ error:
+ return -1;
+} /* end test_vl_type() */
+
+
+/*-------------------------------------------------------------------------
+ * Function: test_vlstr_dtype
+ *
+ * Purpose: Test H5Tget_native_type for variable length string datatype
+ *
+ * Return: Success: 0
+ *
+ * Failure: -1
+ *
+ * Programmer: Raymond Lu
+ * October 15, 2002
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+static herr_t
+test_vlstr_dtype(hid_t file)
+{
+ const char *wdata[SPACE1_DIM1]= {
+ "Four score and seven years ago our forefathers brought forth on this continent a new nation,",
+ "conceived in liberty and dedicated to the proposition that all men are created equal.",
+ "Now we are engaged in a great civil war,",
+ "testing whether that nation or any nation so conceived and so dedicated can long endure."
+ }; /* Information to write */
+ char *rdata[SPACE1_DIM1]; /* Information read in */
+ hid_t dataset; /* Dataset ID */
+ hid_t sid1; /* Dataspace ID */
+ hid_t tid1,dtype,native_type; /* Datatype ID */
+ hid_t xfer_pid; /* Dataset transfer property list ID */
+ hsize_t dims1[] = {SPACE1_DIM1};
+ hsize_t size; /* Number of bytes which will be used */
+ unsigned i; /* counting variable */
+ int str_used; /* String data in memory */
+ int mem_used=0; /* Memory used during allocation */
+ herr_t ret; /* Generic return value */
+
+ /* Output message about test being performed */
+ TESTING("variable length string datatype");
+
+ /* Create dataspace for datasets */
+ if((sid1 = H5Screate_simple(SPACE1_RANK, dims1, NULL))<0) goto error;
+
+ /* Create a datatype to refer to */
+ if((tid1 = H5Tcopy (H5T_C_S1))<0) goto error;
+
+ if(H5Tset_size (tid1,H5T_VARIABLE)<0) goto error;
+ if(H5T_STRING!=H5Tget_class(tid1) || !H5Tis_variable_str(tid1))
+ goto error;
+
+ /* Create a dataset */
+ if((dataset=H5Dcreate(file,DSET_VLSTR_NAME,tid1,sid1,H5P_DEFAULT))<0) goto error;
+
+ /* Write dataset to disk */
+ if(H5Dwrite(dataset,tid1,H5S_ALL,H5S_ALL,H5P_DEFAULT,wdata)<0) goto error;
+
+ /* Close Dataset */
+ if(H5Dclose(dataset)<0) goto error;
+
+ /* Open a dataset */
+ if((dataset=H5Dopen(file, DSET_VLSTR_NAME))<0) goto error;
+
+ /* Get datatype for dataset */
+ if((dtype = H5Dget_type(dataset))<0) goto error;
+
+ /* Construct native type */
+ if((native_type=H5Tget_native_type(dtype, H5T_DIR_DEFAULT))<0)
+ goto error;
+
+ /* Check if the data type is equal */
+ if(!H5Tequal(native_type, tid1))
+ goto error;
+
+ /* Read dataset from disk */
+ if(H5Dread(dataset,native_type,H5S_ALL,H5S_ALL,H5P_DEFAULT,rdata)<0) goto error;
+
+ /* Compare data read in */
+ for(i=0; i<SPACE1_DIM1; i++) {
+ if(strlen(wdata[i])!=strlen(rdata[i])) {
+ H5_FAILED();
+ printf("VL data length don't match!, strlen(wdata[%d])=%d, strlen(rdata[%d])=%d\n",(int)i,(int)strlen(wdata[i]),(int)i,(int)strlen(rdata[i]));
+ goto error;
+ } /* end if */
+ if( strcmp(wdata[i],rdata[i]) != 0 ) {
+ H5_FAILED();
+ printf("VL data values don't match!, wdata[%d]=%s, rdata[%d]=%s\n",(int)i,wdata[i],(int)i,rdata[i]);
+ goto error;
+ } /* end if */
+ } /* end for */
+
+ /* Close Dataset */
+ if(H5Dclose(dataset)<0) goto error;
+
+ /* Close datatype */
+ if(H5Tclose(tid1)<0) goto error;
+ if(H5Tclose(native_type)<0) goto error;
+
+ /* Close disk dataspace */
+ if(H5Sclose(sid1)<0) goto error;
+
+ /* Free memory for rdata */
+ for(i=0; i<SPACE1_DIM1; i++) {
+ HDfree(rdata[i]);
+ }
+
+ PASSED();
+ return 0;
+
+error:
+ return -1;
+} /* end test_vlstr_dtype() */
+
+
+/*-------------------------------------------------------------------------
+ * Function: test_refer_dtype
+ *
+ * Purpose: Test H5Tget_native_type for reference datatype
+ *
+ * Return: Success: 0
+ *
+ * Failure: -1
+ *
+ * Programmer: Raymond Lu
+ * October 15, 2002
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+static herr_t
+test_refer_dtype(hid_t file)
+{
+
+ /* Compound datatype */
+ typedef struct s1_t {
+ unsigned int a;
+ unsigned int b;
+ float c;
+ } s1_t;
+
+ hid_t dataset, /* Dataset ID */
+ dset2; /* Dereferenced dataset ID */
+ hid_t group; /* Group ID */
+ hid_t sid1; /* Dataspace ID */
+ hid_t tid1, dtype, native_type; /* Datatype ID */
+ hsize_t dims1[] = {1};
+ hobj_ref_t *wbuf, /* buffer to write to disk */
+ *rbuf; /* buffer read from disk */
+ int i; /* counting variables */
+
+ /* Output message about test being performed */
+ TESTING("reference datatype");
+
+ /* Allocate write & read buffers */
+ wbuf=HDmalloc(MAX(sizeof(unsigned),sizeof(hobj_ref_t)));
+ rbuf=HDmalloc(MAX(sizeof(unsigned),sizeof(hobj_ref_t)));
+
+ /* Create dataspace for datasets */
+ if((sid1 = H5Screate_simple(SPACE1_RANK, dims1, NULL))<0)
+ goto error;
+
+ /* Create a group */
+ if((group=H5Gcreate(file,"Group1",(size_t)-1))<0)
+ goto error;
+
+ /* Create a datatype to refer to */
+ if((tid1 = H5Tcreate (H5T_COMPOUND, sizeof(s1_t)))<0)
+ goto error;
+
+ /* Insert fields */
+ if(H5Tinsert (tid1, "a", HOFFSET(s1_t,a), H5T_NATIVE_INT)<0)
+ goto error;
+
+ if(H5Tinsert (tid1, "b", HOFFSET(s1_t,b), H5T_NATIVE_INT)<0)
+ goto error;
+
+ if(H5Tinsert (tid1, "c", HOFFSET(s1_t,c), H5T_NATIVE_FLOAT)<0)
+ goto error;
+
+ /* Save datatype for later */
+ if(H5Tcommit (group, "Datatype1", tid1)<0)
+ goto error;
+
+ /* Close datatype */
+ if(H5Tclose(tid1)<0)
+ goto error;
+
+ /* Close group */
+ if(H5Gclose(group)<0)
+ goto error;
+
+ /* Create a dataset */
+ if((dataset=H5Dcreate(file,"Dataset3",H5T_STD_REF_OBJ,sid1,H5P_DEFAULT))<0)
+ goto error;
+
+ /* Create reference to named datatype */
+ if(H5Rcreate(wbuf,file,"/Group1/Datatype1",H5R_OBJECT,-1)<0)
+ goto error;
+#ifdef H5_WANT_H5_V1_4_COMPAT
+ if(H5Rget_object_type(dataset,wbuf)!=H5G_TYPE)
+ goto error;
+#else /* H5_WANT_H5_V1_4_COMPAT */
+ if(H5Rget_obj_type(dataset,H5R_OBJECT,wbuf)!=H5G_TYPE)
+ goto error;
+#endif /* H5_WANT_H5_V1_4_COMPAT */
+
+ /* Write selection to disk */
+ if(H5Dwrite(dataset,H5T_STD_REF_OBJ,H5S_ALL,H5S_ALL,H5P_DEFAULT,wbuf)<0)
+ goto error;
+
+ /* Close disk dataspace */
+ if(H5Sclose(sid1)<0)
+ goto error;
+
+ /* Close Dataset */
+ if(H5Dclose(dataset)<0)
+ goto error;
+
+
+ /* Open the dataset */
+ if((dataset=H5Dopen(file,"/Dataset3"))<0)
+ goto error;
+
+ /* Get datatype for dataset */
+ if((dtype = H5Dget_type(dataset))<0)
+ goto error;
+
+ /* Construct native type */
+ if((native_type=H5Tget_native_type(dtype, H5T_DIR_DEFAULT))<0)
+ goto error;
+
+ /* Check if the data type is equal */
+ if(!H5Tequal(native_type, H5T_STD_REF_OBJ))
+ goto error;
+
+ /* Read selection from disk */
+ if(H5Dread(dataset,native_type,H5S_ALL,H5S_ALL,H5P_DEFAULT,rbuf)<0)
+ goto error;
+
+ /* Open datatype object */
+ if((tid1 = H5Rdereference(dataset,H5R_OBJECT,rbuf))<0)
+ goto error;
+
+ /* Verify correct datatype */
+ {
+ H5T_class_t tclass;
+
+ if(H5Tget_class(tid1)!=H5T_COMPOUND)
+ goto error;
+
+ if(H5Tget_nmembers(tid1)!=3)
+ goto error;
+ }
+
+ /* Close datatype */
+ if(H5Tclose(tid1)<0)
+ goto error;
+
+ /* Close Dataset */
+ if(H5Dclose(dataset)<0)
+ goto error;
+
+ /* Free memory buffers */
+ free(wbuf);
+ free(rbuf);
+
+ PASSED();
+ return 0;
+
+error:
+ return -1;
+} /* test_refer_dtype() */
+
+
+/*-------------------------------------------------------------------------
+ * Function: test_opaque_dtype
+ *
+ * Purpose: Test H5Tget_native_type for opaque datatype
+ *
+ * Return: Success: 0
+ *
+ * Failure: -1
+ *
+ * Programmer: Raymond Lu
+ * October 15, 2002
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+static herr_t
+test_opaque_dtype(hid_t file)
+{
+ hid_t grp=-1, type=-1, space=-1, dset=-1;
+ hid_t dataset, dtype, native_type;
+ int i, j, n;
+ hsize_t dims[2];
+ unsigned char wbuf[32], rbuf[32];
+ hsize_t nelmts;
+
+ TESTING("opaque datatype");
+
+ /* opaque_1 */
+ nelmts = sizeof(wbuf);
+ if ((type=H5Tcreate(H5T_OPAQUE, 1))<0 ||
+ H5Tset_tag(type, "testing 1-byte opaque type")<0 ||
+ (space=H5Screate_simple(1, &nelmts, NULL))<0 ||
+ (dset=H5Dcreate(file, DSET_OPAQUE_NAME, type, space, H5P_DEFAULT))<0)
+ goto error;
+ for (i=0; i<sizeof wbuf; i++) wbuf[i] = (unsigned char)0xff ^ (unsigned char)i;
+ if (H5Dwrite(dset, type, H5S_ALL, H5S_ALL, H5P_DEFAULT, wbuf)<0)
+ goto error;
+ if (H5Sclose(space)<0) goto error;
+ if (H5Dclose(dset)<0) goto error;
+
+
+ /* Open dataset again to check H5Tget_native_type */
+ if((dataset=H5Dopen(file, DSET_OPAQUE_NAME))<0) goto error;
+
+ if((dtype=H5Dget_type(dataset))<0) goto error;
+
+ if((native_type=H5Tget_native_type(dtype, H5T_DIR_DEFAULT))<0)
+ goto error;
+
+ if(!H5Tequal(native_type, type)) goto error;
+
+ if (H5Dread(dataset, native_type, H5S_ALL, H5S_ALL, H5P_DEFAULT, rbuf)<0)
+ goto error;
+
+ for(i=0; i<sizeof(rbuf); i++) {
+ if (rbuf[i] != wbuf[i]) {
+ H5_FAILED();
+ printf(" Read different values than written.\n");
+ printf(" At index %d\n", i);
+ goto error;
+ }
+ }
+
+ if (H5Tclose(type)<0) goto error;
+ if (H5Tclose(dtype)<0) goto error;
+ if (H5Tclose(native_type)<0) goto error;
+ if (H5Dclose(dataset)<0) goto error;
+
+ PASSED();
+ return 0;
+
+error:
+ return -1;
+} /* test_opaque_dtype */
+
+
+/*-------------------------------------------------------------------------
+ * Function: test_bitfield_dtype
+ *
+ * Purpose: Test H5Tget_native_type for bitfield datatype
+ *
+ * Return: Success: 0
+ *
+ * Failure: -1
+ *
+ * Programmer: Raymond Lu
+ * October 15, 2002
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+static herr_t
+test_bitfield_dtype(hid_t file)
+{
+ hid_t grp=-1, type=-1, space=-1, dset=-1;
+ hid_t dataset, dtype, native_type;
+ int i, j, n;
+ hsize_t dims[2];
+ unsigned char wbuf[32], rbuf[32];
+ hsize_t nelmts;
+
+ TESTING("bitfield datatype");
+
+ /* opaque_1 */
+ nelmts = sizeof(wbuf);
+ if ((type=H5Tcopy(H5T_STD_B8LE))<0 ||
+ (space=H5Screate_simple(1, &nelmts, NULL))<0 ||
+ (dset=H5Dcreate(file, DSET_BITFIELD_NAME, type, space, H5P_DEFAULT))<0)
+ goto error;
+ for (i=0; i<sizeof wbuf; i++) wbuf[i] = (unsigned char)0xff ^ (unsigned char)i;
+ if (H5Dwrite(dset, type, H5S_ALL, H5S_ALL, H5P_DEFAULT, wbuf)<0)
+ goto error;
+ if (H5Sclose(space)<0) goto error;
+ if (H5Dclose(dset)<0) goto error;
+
+
+ /* Open dataset again to check H5Tget_native_type */
+ if((dataset=H5Dopen(file, DSET_BITFIELD_NAME))<0) goto error;
+
+ if((dtype=H5Dget_type(dataset))<0) goto error;
+
+ if((native_type=H5Tget_native_type(dtype, H5T_DIR_DEFAULT))<0)
+ goto error;
+
+ if(!H5Tequal(native_type, type)) goto error;
+
+ if (H5Dread(dataset, native_type, H5S_ALL, H5S_ALL, H5P_DEFAULT, rbuf)<0)
+ goto error;
+
+ for(i=0; i<sizeof(rbuf); i++) {
+ if (rbuf[i] != wbuf[i]) {
+ H5_FAILED();
+ printf(" Read different values than written.\n");
+ printf(" At index %d\n", i);
+ goto error;
+ }
+ }
+
+ if (H5Tclose(type)<0) goto error;
+ if (H5Tclose(dtype)<0) goto error;
+ if (H5Tclose(native_type)<0) goto error;
+ if (H5Dclose(dataset)<0) goto error;
+
+ PASSED();
+ return 0;
+
+error:
+ return -1;
+} /* test_opaque_dtype */
+
+
+/*-------------------------------------------------------------------------
+ * Function: main
+ *
+ * Purpose: Test H5Tget_native_type for different datatype
+ *
+ * Programmer: Raymond Lu
+ * October 15, 2002
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+int
+main(void)
+{
+ hid_t file, fapl;
+ int nerrors=0;
+ char filename[1024];
+
+ h5_reset();
+ fapl = h5_fileaccess();
+
+ h5_fixname(FILENAME[0], fapl, filename, sizeof filename);
+ if ((file=H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl))<0) {
+ goto error;
+ }
+
+ nerrors += test_atomic_dtype(file)<0 ?1:0;
+ nerrors += test_compound_dtype(file)<0 ?1:0;
+ nerrors += test_compound_dtype_2(file)<0 ?1:0;
+ nerrors += test_enum_dtype(file)<0 ?1:0;
+ nerrors += test_array_dtype(file)<0 ?1:0;
+ nerrors += test_vl_dtype(file)<0 ?1:0;
+ nerrors += test_vlstr_dtype(file)<0 ?1:0;
+ nerrors += test_refer_dtype(file)<0 ?1:0;
+ nerrors += test_opaque_dtype(file)<0 ?1:0;
+ nerrors += test_bitfield_dtype(file)<0 ?1:0;
+
+ if (H5Fclose(file)<0) goto error;
+ if (nerrors) goto error;
+ printf("All native datatype tests passed.\n");
+ h5_cleanup(FILENAME, fapl);
+ return 0;
+
+ error:
+ nerrors = MAX(1, nerrors);
+ printf("***** %d DATASET TEST%s FAILED! *****\n",
+ nerrors, 1 == nerrors ? "" : "S");
+ return 1;
+}
diff --git a/test/tvlstr.c b/test/tvlstr.c
index 7ce7e18..9d31f2d 100644
--- a/test/tvlstr.c
+++ b/test/tvlstr.c
@@ -261,6 +261,12 @@ static void test_vlstring_type(void)
ret = H5Tset_size(tid_vlstr, H5T_VARIABLE);
CHECK(ret, FAIL, "H5Tset_size");
+ /* Check if datatype is VL string */
+ ret = H5Tget_class(tid_vlstr);
+ VERIFY(ret, H5T_STRING, "H5Tget_class");
+ ret = H5Tis_variable_str(tid_vlstr);
+ VERIFY(ret, TRUE, "H5Tis_variable_str");
+
/* Check default character set and padding */
cset = H5Tget_cset(tid_vlstr);
VERIFY(cset, H5T_CSET_ASCII, "H5Tget_cset");