summaryrefslogtreecommitdiffstats
path: root/src/H5Tnative.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/H5Tnative.c')
-rw-r--r--src/H5Tnative.c190
1 files changed, 118 insertions, 72 deletions
diff --git a/src/H5Tnative.c b/src/H5Tnative.c
index 75b5d03..8d8920b 100644
--- a/src/H5Tnative.c
+++ b/src/H5Tnative.c
@@ -38,6 +38,8 @@ static H5T_t *H5T_get_native_integer(size_t prec, H5T_sign_t sign, H5T_direction
size_t *struct_align, size_t *offset, size_t *comp_size);
static H5T_t *H5T_get_native_float(size_t size, H5T_direction_t direction,
size_t *struct_align, size_t *offset, size_t *comp_size);
+static H5T_t* H5T_get_native_bitfield(size_t prec, H5T_direction_t direction,
+ size_t *struct_align, size_t *offset, size_t *comp_size);
static herr_t H5T_cmp_offset(size_t *comp_size, size_t *offset, size_t elem_size,
size_t nelems, size_t align, size_t *struct_align);
@@ -108,7 +110,7 @@ H5Tget_native_type(hid_t type_id, H5T_direction_t direction)
H5TRACE2("i", "iTd", type_id, direction);
/* check argument */
- if(NULL==(dt=H5I_object_verify(type_id, H5I_DATATYPE)))
+ if(NULL==(dt=(H5T_t *)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
@@ -210,13 +212,19 @@ H5T_get_native_type(H5T_t *dtype, H5T_direction_t direction, size_t *struct_alig
}
break;
- /* These 2 types will be supported in the future. Simply return "not supported"
+ /* The time type will be supported in the future. Simply return "not supported"
* message for now.*/
case H5T_TIME:
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "time type is not supported yet")
case H5T_BITFIELD:
- HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "bit field type is not supported yet")
+ {
+ prec = dtype->shared->u.atomic.prec;
+
+ if((ret_value = H5T_get_native_bitfield(prec, direction, struct_align, offset, comp_size))==NULL)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "cannot retrieve integer for bitfield type")
+ }
+ break;
case H5T_OPAQUE:
if((ret_value=H5T_copy(dtype, H5T_COPY_TRANSIENT))==NULL)
@@ -237,7 +245,7 @@ H5T_get_native_type(H5T_t *dtype, H5T_direction_t direction, size_t *struct_alig
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "cannot retrieve float type")
/* Decide if the data type is object or dataset region reference. */
- if(NULL==(dt=H5I_object(H5T_STD_REF_OBJ_g)))
+ if(NULL==(dt=(H5T_t *)H5I_object(H5T_STD_REF_OBJ_g)))
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "not a data type")
not_equal = H5T_cmp(ret_value, dt, FALSE);
@@ -556,46 +564,19 @@ H5T_get_native_integer(size_t prec, H5T_sign_t sign, H5T_direction_t direction,
native_size = sizeof(long long);
}
} else if(direction == H5T_DIR_DESCEND) {
- if(prec>=H5Tget_precision(H5T_NATIVE_LLONG)) {
+ if(prec>H5Tget_precision(H5T_NATIVE_LONG)) {
match=H5T_NATIVE_INT_MATCH_LLONG;
native_size = sizeof(long long);
- } else if(prec>=H5Tget_precision(H5T_NATIVE_LONG)) {
- if(prec==H5Tget_precision(H5T_NATIVE_LONG)) {
- match=H5T_NATIVE_INT_MATCH_LONG;
- native_size = sizeof(long);
- } else {
- match=H5T_NATIVE_INT_MATCH_LLONG;
- native_size = sizeof(long long);
- }
- }
- else if(prec>=H5Tget_precision(H5T_NATIVE_INT)) {
- if(prec==H5Tget_precision(H5T_NATIVE_INT)) {
- match=H5T_NATIVE_INT_MATCH_INT;
- native_size = sizeof(int);
- } else {
- match=H5T_NATIVE_INT_MATCH_LONG;
- native_size = sizeof(long);
- }
- }
- else if(prec>=H5Tget_precision(H5T_NATIVE_SHORT)) {
- if(prec==H5Tget_precision(H5T_NATIVE_SHORT)) {
- match=H5T_NATIVE_INT_MATCH_SHORT;
- native_size = sizeof(short);
- } else {
- match=H5T_NATIVE_INT_MATCH_INT;
- native_size = sizeof(int);
- }
- }
- else if(prec>=H5Tget_precision(H5T_NATIVE_SCHAR)) {
- if(prec==H5Tget_precision(H5T_NATIVE_SCHAR)) {
- match=H5T_NATIVE_INT_MATCH_CHAR;
- native_size = sizeof(char);
- } else {
- match=H5T_NATIVE_INT_MATCH_SHORT;
- native_size = sizeof(short);
- }
- }
- else { /* If no native type matches the queried datatype, simply choose the type of smallest size. */
+ } else if(prec>H5Tget_precision(H5T_NATIVE_INT)) {
+ match=H5T_NATIVE_INT_MATCH_LONG;
+ native_size = sizeof(long);
+ } else if(prec>H5Tget_precision(H5T_NATIVE_SHORT)) {
+ match=H5T_NATIVE_INT_MATCH_INT;
+ native_size = sizeof(int);
+ } else if(prec>H5Tget_precision(H5T_NATIVE_SCHAR)) {
+ match=H5T_NATIVE_INT_MATCH_SHORT;
+ native_size = sizeof(short);
+ } else {
match=H5T_NATIVE_INT_MATCH_CHAR;
native_size = sizeof(char);
}
@@ -654,7 +635,7 @@ H5T_get_native_integer(size_t prec, H5T_sign_t sign, H5T_direction_t direction,
/* Create new native type */
assert(tid>=0);
- if(NULL==(dt=H5I_object(tid)))
+ if(NULL==(dt=(H5T_t *)H5I_object(tid)))
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "not a data type")
if((ret_value=H5T_copy(dt, H5T_COPY_TRANSIENT))==NULL)
@@ -733,46 +714,23 @@ H5T_get_native_float(size_t size, H5T_direction_t direction, size_t *struct_alig
}
} else {
#if H5_SIZEOF_LONG_DOUBLE !=0
- if(size>=sizeof(long double)) {
+ if(size>sizeof(double)) {
match=H5T_NATIVE_FLOAT_MATCH_LDOUBLE;
native_size = sizeof(long double);
}
- else if(size>=sizeof(double)) {
- if(size==sizeof(double)) {
- match=H5T_NATIVE_FLOAT_MATCH_DOUBLE;
- native_size = sizeof(double);
- } else {
- match=H5T_NATIVE_FLOAT_MATCH_LDOUBLE;
- native_size = sizeof(long double);
- }
- }
- else if(size>=sizeof(float)) {
- if(size==sizeof(float)) {
- match=H5T_NATIVE_FLOAT_MATCH_FLOAT;
- native_size = sizeof(float);
- } else {
- match=H5T_NATIVE_FLOAT_MATCH_DOUBLE;
- native_size = sizeof(double);
- }
+ else if(size>sizeof(float)) {
+ match=H5T_NATIVE_FLOAT_MATCH_DOUBLE;
+ native_size = sizeof(double);
}
else {
match=H5T_NATIVE_FLOAT_MATCH_FLOAT;
native_size = sizeof(float);
}
#else
- if(size>=sizeof(double)) {
+ if(size>sizeof(float)) {
match=H5T_NATIVE_FLOAT_MATCH_DOUBLE;
native_size = sizeof(double);
}
- else if(size>=sizeof(float)) {
- if(size==sizeof(float)) {
- match=H5T_NATIVE_FLOAT_MATCH_FLOAT;
- native_size = sizeof(float);
- } else {
- match=H5T_NATIVE_FLOAT_MATCH_DOUBLE;
- native_size = sizeof(double);
- }
- }
else {
match=H5T_NATIVE_FLOAT_MATCH_FLOAT;
native_size = sizeof(float);
@@ -805,7 +763,7 @@ H5T_get_native_float(size_t size, H5T_direction_t direction, size_t *struct_alig
/* Create new native type */
assert(tid>=0);
- if(NULL==(dt=H5I_object(tid)))
+ if(NULL==(dt=(H5T_t *)H5I_object(tid)))
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")
@@ -820,6 +778,94 @@ done:
/*-------------------------------------------------------------------------
+ * Function: H5T_get_native_bitfield
+ *
+ * Purpose: Returns the native bitfield type of a datatype. Bitfield
+ * is similar to unsigned integer.
+ *
+ * Return: Success: Returns the native data type if successful.
+ *
+ * Failure: negative
+ *
+ * Programmer: Raymond Lu
+ * 1 December 2009
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+static H5T_t*
+H5T_get_native_bitfield(size_t prec, H5T_direction_t direction, size_t *struct_align,
+ size_t *offset, size_t *comp_size)
+{
+ H5T_t *dt; /* Appropriate native datatype to copy */
+ hid_t tid=(-1); /* Datatype ID of appropriate native datatype */
+ size_t align=0; /* Alignment necessary for native datatype */
+ size_t native_size=0; /* Datatype size of the native type */
+ H5T_t *ret_value; /* Return value */
+
+ FUNC_ENTER_NOAPI(H5T_get_native_bitfield, NULL);
+
+ if(direction == H5T_DIR_DEFAULT || direction == H5T_DIR_ASCEND) {
+ if(prec<=H5Tget_precision(H5T_NATIVE_B8)) {
+ tid = H5T_NATIVE_B8;
+ native_size = 1;
+ align = H5T_NATIVE_UINT8_ALIGN_g;
+ } else if(prec<=H5Tget_precision(H5T_NATIVE_B16)) {
+ tid = H5T_NATIVE_B16;
+ native_size = 2;
+ align = H5T_NATIVE_UINT16_ALIGN_g;
+ } else if(prec<=H5Tget_precision(H5T_NATIVE_B32)) {
+ tid = H5T_NATIVE_B32;
+ native_size = 4;
+ align = H5T_NATIVE_UINT32_ALIGN_g;
+ } else if(prec<=H5Tget_precision(H5T_NATIVE_B64)) {
+ tid = H5T_NATIVE_B64;
+ native_size = 8;
+ align = H5T_NATIVE_UINT64_ALIGN_g;
+ } else { /* If no native type matches the querried datatype, simply choose the type of biggest size. */
+ tid = H5T_NATIVE_B64;
+ native_size = 8;
+ align = H5T_NATIVE_UINT64_ALIGN_g;
+ }
+ } else if(direction == H5T_DIR_DESCEND) {
+ if(prec>H5Tget_precision(H5T_NATIVE_B32)) {
+ tid = H5T_NATIVE_B64;
+ native_size = 8;
+ align = H5T_NATIVE_UINT64_ALIGN_g;
+ } else if(prec>H5Tget_precision(H5T_NATIVE_B16)) {
+ tid = H5T_NATIVE_B32;
+ native_size = 4;
+ align = H5T_NATIVE_UINT32_ALIGN_g;
+ } else if(prec>H5Tget_precision(H5T_NATIVE_B8)) {
+ tid = H5T_NATIVE_B16;
+ native_size = 2;
+ align = H5T_NATIVE_UINT16_ALIGN_g;
+ } else {
+ tid = H5T_NATIVE_B8;
+ native_size = 1;
+ align = H5T_NATIVE_UINT8_ALIGN_g;
+ }
+ }
+
+ /* Create new native type */
+ assert(tid>=0);
+ if(NULL==(dt=(H5T_t *)H5I_object(tid)))
+ 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 copy type")
+
+ /* compute size and offset of compound type member. */
+ if(H5T_cmp_offset(comp_size, offset, native_size, (size_t)1, align, struct_align)<0)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "cannot compute compound offset")
+
+done:
+ FUNC_LEAVE_NOAPI(ret_value)
+}
+
+
+/*-------------------------------------------------------------------------
* Function: H5T_cmp_offset
*
* Purpose: This function is only for convenience. It computes the