summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlbert Cheng <acheng@hdfgroup.org>2000-03-06 23:02:37 (GMT)
committerAlbert Cheng <acheng@hdfgroup.org>2000-03-06 23:02:37 (GMT)
commit4d42626054b717b11e51582ce1db3a7735e1edee (patch)
treea5adf966f95887a57ef8b2d382d7da22116f44e9
parent99a30e1e601a7968715458d557a4030fb548f57c (diff)
downloadhdf5-4d42626054b717b11e51582ce1db3a7735e1edee.zip
hdf5-4d42626054b717b11e51582ce1db3a7735e1edee.tar.gz
hdf5-4d42626054b717b11e51582ce1db3a7735e1edee.tar.bz2
[svn-r2000] Purpose:
Bug fix. Description: Failed on T3E in which int32 is typedef to a short (4 bytes) but the converter just used H5T_NATIVE_INT for conversion of a STD_INT32. Int in a T3E is actually 64bit big. Solution: Recoded the h5type to h4type matching algorithm by making sure the size of the H4 type used is equal to the size of the H5 native type. Remark: current implementation is not efficient--it does all the sizes checking repeatedly. Should have done the type mapping once at the beginning as initialization. Old code are still retain via the macro NEWWAY. Need to verify the correctness of the converter in more platforms before finalized on the code. Platforms tested: Baldric (Solaris 2.6), arabica (Solaris 2.7) T3E
-rw-r--r--tools/h5toh4.c173
1 files changed, 171 insertions, 2 deletions
diff --git a/tools/h5toh4.c b/tools/h5toh4.c
index 19974d9..8e6b591 100644
--- a/tools/h5toh4.c
+++ b/tools/h5toh4.c
@@ -15,6 +15,7 @@
#include <errno.h>
#include <string.h>
#include <fcntl.h>
+#include <sys/stat.h>
#include <h5toh4.h>
extern void PrintOptions_h5toh4(void);
@@ -649,6 +650,15 @@ int32 order_array[512];
case H5T_INTEGER:
case H5T_FLOAT:
sd_id = op_data->sd_id;
+#define NEWWAY
+#ifdef NEWWAY
+ if (FAIL==h5atomic_type_to_h4type(type, &mem_type, &typesize, &h4_type)){
+ fprintf(stderr, "Error: Problems translating h5 type to h4 type\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset", __FILE__, __LINE__);
+ status = FAIL;
+ break;
+ }
+#else
if ((h4_type = h5type_to_h4type(type)) == FAIL ) {
fprintf(stderr, "Error: Problems translating h5 type to h4 type\n");
DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset", __FILE__, __LINE__);
@@ -667,6 +677,7 @@ int32 order_array[512];
status = FAIL;
break;
}
+#endif
if ((buffer = HDmalloc(n_values*typesize)) == NULL) {
fprintf(stderr, "Error: Problems with HDmalloc of memory space\n");
DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset", __FILE__, __LINE__);
@@ -748,6 +759,14 @@ int32 order_array[512];
DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset", __FILE__, __LINE__);
break;
}
+#ifdef NEWWAY
+ if (FAIL==h5atomic_type_to_h4type(fieldtype, &mem_type, &typesize, &h4_type)){
+ fprintf(stderr, "Error: Problems translating h5 type to h4 type\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset", __FILE__, __LINE__);
+ status = FAIL;
+ break;
+ }
+#else
if ((h4_type = h5type_to_h4type(fieldtype)) < 0 ) {
fprintf(stderr, "Error: Problems translating h5 type to h4 type\n");
DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset", __FILE__, __LINE__);
@@ -764,6 +783,7 @@ int32 order_array[512];
status = FAIL;
break;
}
+#endif
order = 1;
if (ndimf > 0) {
order *= dimf[permf[0]];
@@ -1027,6 +1047,14 @@ H5T_str_t strpad;
return status;
}
+#ifdef NEWWAY
+ if (FAIL==h5atomic_type_to_h4type(type, &mem_type, &typesize, &h4_type)){
+ fprintf(stderr, "Error: Problems translating h5 type to h4 type\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset", __FILE__, __LINE__);
+ status = FAIL;
+ break;
+ }
+#else
if ((h4_type = h5type_to_h4type(type)) == FAIL ) {
fprintf(stderr, "Error: Problems translating h5 type to h4 type\n");
DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_attr", __FILE__, __LINE__);
@@ -1047,6 +1075,7 @@ H5T_str_t strpad;
status = FAIL;
return status;
}
+#endif
if ((attr_values = HDmalloc(n_values*typesize)) == NULL) {
fprintf(stderr, "Error: Problems with HDmalloc of memory space\n");
@@ -2024,6 +2053,146 @@ H5T_str_t strpad;
}
+/*-------------------------------------------------------------------------
+ * Function: h5atomic_type_to_h4type
+ *
+ * Purpose: Match an H5 atomic type to an appropriate H4 type.
+ * Assign an appropirate H5 memory type that matches the H4 type.
+ * Return the H5 memory type, H4 type and sizeof H4 via pointers.
+ *
+ * Return: SUCCEED on suceed, FAIL on failure.
+ * When fail, pointer values of h5memtype, h5memsize and h4_type
+ * may have changed and are undefined.
+ *
+ * Programmer: Albert Cheng, March 2000
+ *
+ * Modifications:
+ *
+ *-----------------------------------------------------------------------*/
+herr_t h5atomic_type_to_h4type(const hid_t h5type, hid_t* h5memtype, size_t* h5memsize, int32* h4type)
+{
+ H5T_class_t class;
+ size_t h5typesize, h4typesize;
+ H5T_sign_t sign;
+ hid_t mem_datatype = FAIL;
+
+ if ((class = H5Tget_class(h5type)) < 0 ) {
+ fprintf(stderr,"Error: problem with getting type class\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "h5atomic_type_to_h4type", __FILE__, __LINE__);
+ return FAIL;
+ }
+
+ switch(class){
+ case H5T_INTEGER:
+ if ((h5typesize = H5Tget_size(h5type)) == 0 ) {
+ fprintf(stderr,"Error: problem with getting type size\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "h5atomic_type_to_h4type", __FILE__, __LINE__);
+ return FAIL;
+ }
+ if ((sign = H5Tget_sign(h5type)) == H5T_SGN_ERROR) {
+ fprintf(stderr,"Error: problem with getting type sign\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "h5atomic_type_to_h4type", __FILE__, __LINE__);
+ return FAIL;
+ }
+ /* deduce the proper HDF4 integer type to use according to the size of the HDF5 type. */
+ /* Current HDF4 types can be 8, 16, 32 bits (1, 2, 4 bytes). */
+ switch(h5typesize){
+ case 1:
+ *h4type = (sign == H5T_SGN_2 ? DFNT_INT8 : DFNT_UINT8);
+ h4typesize = sizeof(int8);
+ if (h4typesize == H5Tget_size(H5T_NATIVE_CHAR)){
+ mem_datatype = (sign == H5T_SGN_2 ? H5T_NATIVE_SCHAR : H5T_NATIVE_UCHAR);
+ }else if (h4typesize == H5Tget_size(H5T_NATIVE_SHORT)){
+ mem_datatype = (sign == H5T_SGN_2 ? H5T_NATIVE_SHORT : H5T_NATIVE_USHORT);
+ }else if (h4typesize == H5Tget_size(H5T_NATIVE_INT)){
+ mem_datatype = (sign == H5T_SGN_2 ? H5T_NATIVE_INT : H5T_NATIVE_UINT);
+ }else if (h4typesize == H5Tget_size(H5T_NATIVE_LONG)){
+ mem_datatype = (sign == H5T_SGN_2 ? H5T_NATIVE_LONG : H5T_NATIVE_ULONG);
+ }else
+ return(FAIL);
+ break;
+ case 2:
+ *h4type = (sign == H5T_SGN_2 ? DFNT_INT16 : DFNT_UINT16);
+ h4typesize = sizeof(int16);
+ if (h4typesize == H5Tget_size(H5T_NATIVE_CHAR)){
+ mem_datatype = (sign == H5T_SGN_2 ? H5T_NATIVE_SCHAR : H5T_NATIVE_UCHAR);
+ }else if (h4typesize == H5Tget_size(H5T_NATIVE_SHORT)){
+ mem_datatype = (sign == H5T_SGN_2 ? H5T_NATIVE_SHORT : H5T_NATIVE_USHORT);
+ }else if (h4typesize == H5Tget_size(H5T_NATIVE_INT)){
+ mem_datatype = (sign == H5T_SGN_2 ? H5T_NATIVE_INT : H5T_NATIVE_UINT);
+ }else if (h4typesize == H5Tget_size(H5T_NATIVE_LONG)){
+ mem_datatype = (sign == H5T_SGN_2 ? H5T_NATIVE_LONG : H5T_NATIVE_ULONG);
+ }else
+ return(FAIL);
+ break;
+ case 4:
+ *h4type = (sign == H5T_SGN_2 ? DFNT_INT32 : DFNT_UINT32);
+ h4typesize = sizeof(int32);
+ if (h4typesize == H5Tget_size(H5T_NATIVE_CHAR)){
+ mem_datatype = (sign == H5T_SGN_2 ? H5T_NATIVE_SCHAR : H5T_NATIVE_UCHAR);
+ }else if (h4typesize == H5Tget_size(H5T_NATIVE_SHORT)){
+ mem_datatype = (sign == H5T_SGN_2 ? H5T_NATIVE_SHORT : H5T_NATIVE_USHORT);
+ }else if (h4typesize == H5Tget_size(H5T_NATIVE_INT)){
+ mem_datatype = (sign == H5T_SGN_2 ? H5T_NATIVE_INT : H5T_NATIVE_UINT);
+ }else if (h4typesize == H5Tget_size(H5T_NATIVE_LONG)){
+ mem_datatype = (sign == H5T_SGN_2 ? H5T_NATIVE_LONG : H5T_NATIVE_ULONG);
+ }else
+ return(FAIL);
+ break;
+ default:
+ fprintf(stderr,"Error: unmatchable integer type\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "h5atomic_type_to_h4type", __FILE__, __LINE__);
+ return FAIL;
+ }
+ break;
+ /* end of case H5T_INTEGER */
+
+ case H5T_FLOAT:
+ if ((h5typesize = H5Tget_size(h5type)) == 0 ) {
+ fprintf(stderr,"Error: problem with getting type size\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "h5atomic_type_to_h4type", __FILE__, __LINE__);
+ return FAIL;
+ }
+ /* deduce the proper HDF4 floating point type to use according to the size of the HDF5 type. */
+ /* Current HDF4 types can be 32 or 64 bits (4 or 8 bytes). */
+ switch(h5typesize){
+ case 4:
+ *h4type = DFNT_FLOAT32;
+ h4typesize = sizeof(float32);
+ if (h4typesize == H5Tget_size(H5T_NATIVE_FLOAT)){
+ mem_datatype = H5T_NATIVE_FLOAT;
+ }else if (h4typesize == H5Tget_size(H5T_NATIVE_DOUBLE)){
+ mem_datatype = H5T_NATIVE_DOUBLE;
+ }else
+ return(FAIL);
+ break;
+ case 8:
+ *h4type = DFNT_FLOAT64;
+ h4typesize = sizeof(float64);
+ if (h4typesize == H5Tget_size(H5T_NATIVE_FLOAT)){
+ mem_datatype = H5T_NATIVE_FLOAT;
+ }else if (h4typesize == H5Tget_size(H5T_NATIVE_DOUBLE)){
+ mem_datatype = H5T_NATIVE_DOUBLE;
+ }else
+ return(FAIL);
+ break;
+ default:
+ fprintf(stderr,"Error: unmatchable H5 float type\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "h5atomic_type_to_h4type", __FILE__, __LINE__);
+ return FAIL;
+ }
+ break;
+ /* end of case H5T_FLOAT */
+
+ default:
+ return FAIL;
+ }
+
+ *h5memsize = h4typesize;
+ *h5memtype = mem_datatype;
+ return(SUCCEED);
+}
+#ifndef NEWWAY
/*****************************************************************************
Routine: h5type_to_h4type(h5type)
@@ -2171,7 +2340,7 @@ hid_t h4type_to_memtype(int32 h4_datatype)
case DFNT_INT32:
case DFNT_NINT32:
case DFNT_LINT32:
- mem_datatype = H5T_NATIVE_INT; break;
+ mem_datatype = H5T_NATIVE_INT; break;
case DFNT_UINT32:
case DFNT_NUINT32:
case DFNT_LUINT32:
@@ -2211,6 +2380,7 @@ hid_t h4type_to_memtype(int32 h4_datatype)
return mem_datatype;
}
+#endif
/*****************************************************************************
@@ -2273,7 +2443,6 @@ int test_dir(char *path)
}
return S_ISDIR(buf_ptr->st_mode);
-
}
/*****************************************************************************