summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/H5Tnative.c68
-rw-r--r--test/ntypes.c32
2 files changed, 62 insertions, 38 deletions
diff --git a/src/H5Tnative.c b/src/H5Tnative.c
index a143496..3cd6789 100644
--- a/src/H5Tnative.c
+++ b/src/H5Tnative.c
@@ -527,29 +527,45 @@ H5T_get_native_integer(size_t size, H5T_sign_t sign, H5T_direction_t direction,
assert(size>0);
if(direction == H5T_DIR_DEFAULT || direction == H5T_DIR_ASCEND) {
- if(size==sizeof(char))
+ if(size<=sizeof(char))
match=H5T_NATIVE_INT_MATCH_CHAR;
- else if(size==sizeof(short))
+ else if(size<=sizeof(short))
match=H5T_NATIVE_INT_MATCH_SHORT;
- else if(size==sizeof(int))
+ else if(size<=sizeof(int))
match=H5T_NATIVE_INT_MATCH_INT;
- else if(size==sizeof(long))
+ else if(size<=sizeof(long))
match=H5T_NATIVE_INT_MATCH_LONG;
- else if(size==sizeof(long_long))
+ else if(size<=sizeof(long_long))
match=H5T_NATIVE_INT_MATCH_LLONG;
else /* If no native type matches the querried datatype, simply choose the type of biggest size. */
match=H5T_NATIVE_INT_MATCH_LLONG;
} else if(direction == H5T_DIR_DESCEND) {
- if(size==sizeof(long_long))
+ if(size>=sizeof(long_long))
match=H5T_NATIVE_INT_MATCH_LLONG;
- else if(size==sizeof(long))
- match=H5T_NATIVE_INT_MATCH_LONG;
- else if(size==sizeof(int))
- match=H5T_NATIVE_INT_MATCH_INT;
- else if(size==sizeof(short))
- match=H5T_NATIVE_INT_MATCH_SHORT;
- else if(size==sizeof(char))
- match=H5T_NATIVE_INT_MATCH_CHAR;
+ else if(size>=sizeof(long)) {
+ if(size==sizeof(long))
+ match=H5T_NATIVE_INT_MATCH_LONG;
+ else
+ match=H5T_NATIVE_INT_MATCH_LLONG;
+ }
+ else if(size>=sizeof(int)) {
+ if(size==sizeof(int))
+ match=H5T_NATIVE_INT_MATCH_INT;
+ else
+ match=H5T_NATIVE_INT_MATCH_LONG;
+ }
+ else if(size>=sizeof(short)) {
+ if(size==sizeof(short))
+ match=H5T_NATIVE_INT_MATCH_SHORT;
+ else
+ match=H5T_NATIVE_INT_MATCH_INT;
+ }
+ else if(size>=sizeof(char)) {
+ if(size==sizeof(char))
+ match=H5T_NATIVE_INT_MATCH_CHAR;
+ else
+ match=H5T_NATIVE_INT_MATCH_SHORT;
+ }
else /* If no native type matches the querried datatype, simple choose the type of smallest size. */
match=H5T_NATIVE_INT_MATCH_CHAR;
}
@@ -657,21 +673,29 @@ H5T_get_native_float(size_t size, H5T_direction_t direction, size_t *struct_alig
assert(size>0);
if(direction == H5T_DIR_DEFAULT || direction == H5T_DIR_ASCEND) {
- if(size==sizeof(float))
+ if(size<=sizeof(float))
match=H5T_NATIVE_FLOAT_MATCH_FLOAT;
- else if(size==sizeof(double))
+ else if(size<=sizeof(double))
match=H5T_NATIVE_FLOAT_MATCH_DOUBLE;
- else if(size==sizeof(long double))
+ else if(size<=sizeof(long double))
match=H5T_NATIVE_FLOAT_MATCH_LDOUBLE;
else /* If not match, return the biggest datatype */
match=H5T_NATIVE_FLOAT_MATCH_LDOUBLE;
} else {
- if(size==sizeof(long double))
+ if(size>=sizeof(long double))
match=H5T_NATIVE_FLOAT_MATCH_LDOUBLE;
- else if(size==sizeof(double))
- match=H5T_NATIVE_FLOAT_MATCH_DOUBLE;
- else if(size==sizeof(float))
- match=H5T_NATIVE_FLOAT_MATCH_FLOAT;
+ else if(size>=sizeof(double)) {
+ if(size==sizeof(double))
+ match=H5T_NATIVE_FLOAT_MATCH_DOUBLE;
+ else
+ match=H5T_NATIVE_FLOAT_MATCH_LDOUBLE;
+ }
+ else if(size>=sizeof(float)) {
+ if(size==sizeof(float))
+ match=H5T_NATIVE_FLOAT_MATCH_FLOAT;
+ else
+ match=H5T_NATIVE_FLOAT_MATCH_DOUBLE;
+ }
else
match=H5T_NATIVE_FLOAT_MATCH_FLOAT;
}
diff --git a/test/ntypes.c b/test/ntypes.c
index 0bc37df..4c877ee 100644
--- a/test/ntypes.c
+++ b/test/ntypes.c
@@ -114,7 +114,7 @@ test_atomic_dtype(hid_t file)
/* Verify the datatype retrieved and converted */
if(H5Tget_order(native_type) != H5Tget_order(H5T_NATIVE_INT))
TEST_ERROR;
- if(sizeof(int)!=H5Tget_size(native_type))
+ if(H5Tget_size(native_type) != H5Tget_size(H5T_STD_I32BE))
TEST_ERROR;
if(H5T_INTEGER!=H5Tget_class(native_type))
TEST_ERROR;
@@ -152,7 +152,7 @@ test_atomic_dtype(hid_t file)
/* Verify the datatype retrieved and converted */
if(H5Tget_order(native_type) != H5Tget_order(H5T_NATIVE_LLONG))
TEST_ERROR;
- if(sizeof(long_long)!=H5Tget_size(native_type))
+ if(H5Tget_size(native_type) != H5Tget_size(H5T_STD_I64LE))
TEST_ERROR;
if(H5T_INTEGER!=H5Tget_class(native_type))
TEST_ERROR;
@@ -173,7 +173,7 @@ test_atomic_dtype(hid_t file)
/* Verify the datatype retrieved and converted */
if(H5Tget_order(native_type) != H5Tget_order(H5T_NATIVE_CHAR))
TEST_ERROR;
- if(sizeof(char)!=H5Tget_size(native_type))
+ if(H5Tget_size(native_type) != H5Tget_size(H5T_NATIVE_CHAR))
TEST_ERROR;
if(H5T_INTEGER!=H5Tget_class(native_type))
TEST_ERROR;
@@ -194,7 +194,7 @@ test_atomic_dtype(hid_t file)
/* Verify the datatype retrieved and converted */
if(H5Tget_order(native_type) != H5Tget_order(H5T_NATIVE_FLOAT))
TEST_ERROR;
- if(sizeof(float)!=H5Tget_size(native_type))
+ if(H5Tget_size(native_type) != H5Tget_size(H5T_NATIVE_FLOAT))
TEST_ERROR;
if(H5T_FLOAT!=H5Tget_class(native_type))
TEST_ERROR;
@@ -215,7 +215,7 @@ test_atomic_dtype(hid_t file)
/* Verify the datatype retrieved and converted */
if(H5Tget_order(native_type) != H5Tget_order(H5T_NATIVE_DOUBLE))
TEST_ERROR;
- if(sizeof(double)!=H5Tget_size(native_type))
+ if(H5Tget_size(native_type) != H5Tget_size(H5T_IEEE_F64BE))
TEST_ERROR;
if(H5T_FLOAT!=H5Tget_class(native_type))
TEST_ERROR;
@@ -350,11 +350,6 @@ test_compound_dtype2(hid_t file)
/* Close dataset */
if(H5Dclose(dataset)<0) TEST_ERROR;
- /* Close temporary datatypes */
- if(H5Tclose(tid2)<0) TEST_ERROR;
- if(H5Tclose(tid)<0) TEST_ERROR;
- if(H5Tclose(tid_m2)<0) TEST_ERROR;
-
/* Close dataspace */
if(H5Sclose(space)<0) TEST_ERROR;
@@ -367,7 +362,7 @@ test_compound_dtype2(hid_t file)
if((native_type=H5Tget_native_type(dtype, H5T_DIR_DEFAULT))<0)
TEST_ERROR;
- if(sizeof(s1)!=H5Tget_size(native_type))
+ if(H5Tget_size(native_type) != H5Tget_size(tid_m))
TEST_ERROR;
if(!H5Tequal(native_type, tid_m))
TEST_ERROR;
@@ -392,6 +387,11 @@ test_compound_dtype2(hid_t file)
}
}
+ /* Close temporary datatypes */
+ if(H5Tclose(tid2)<0) TEST_ERROR;
+ if(H5Tclose(tid)<0) TEST_ERROR;
+ if(H5Tclose(tid_m2)<0) TEST_ERROR;
+
/* Close HDF5 objects */
H5Dclose(dataset);
H5Tclose(dtype);
@@ -493,9 +493,6 @@ test_compound_dtype(hid_t file)
/* Close dataset */
if(H5Dclose(dataset)<0) TEST_ERROR;
- /* Close datatype */
- if(H5Tclose(tid)<0) TEST_ERROR;
-
/* Close dataspace */
if(H5Sclose(space)<0) TEST_ERROR;
@@ -508,7 +505,7 @@ test_compound_dtype(hid_t file)
if((native_type=H5Tget_native_type(dtype, H5T_DIR_DEFAULT))<0)
TEST_ERROR;
- if(sizeof(s1)!=H5Tget_size(native_type))
+ if(H5Tget_size(native_type) != H5Tget_size(tid2))
TEST_ERROR;
if(!H5Tequal(native_type, tid2))
TEST_ERROR;
@@ -531,6 +528,9 @@ test_compound_dtype(hid_t file)
}
}
+ /* Close datatype */
+ if(H5Tclose(tid)<0) TEST_ERROR;
+
H5Dclose(dataset);
H5Tclose(dtype);
H5Tclose(native_type);
@@ -650,7 +650,7 @@ test_compound_dtype3(hid_t file)
if((native_type=H5Tget_native_type(dtype, H5T_DIR_DEFAULT))<0)
TEST_ERROR;
- if(sizeof(s1)!=H5Tget_size(native_type))
+ if(H5Tget_size(native_type) != H5Tget_size(tid_m))
TEST_ERROR;
if(!H5Tequal(native_type, tid_m))
TEST_ERROR;