summaryrefslogtreecommitdiffstats
path: root/tools/lib/h5tools_type.c
diff options
context:
space:
mode:
authorPedro Vicente Nunes <pvn@hdfgroup.org>2006-07-28 15:00:29 (GMT)
committerPedro Vicente Nunes <pvn@hdfgroup.org>2006-07-28 15:00:29 (GMT)
commitc7384f49e030fb296629300ac6b2ce9981a05cfd (patch)
tree72b294fce82845ea3eeeacaee7de710643c5a209 /tools/lib/h5tools_type.c
parente55a2e7bd1c06ecea8b9f2ff4265dc02ebdc4dc3 (diff)
downloadhdf5-c7384f49e030fb296629300ac6b2ce9981a05cfd.zip
hdf5-c7384f49e030fb296629300ac6b2ce9981a05cfd.tar.gz
hdf5-c7384f49e030fb296629300ac6b2ce9981a05cfd.tar.bz2
[svn-r12513]
new feature h5dump binary output. use little and big endian type conversions
Diffstat (limited to 'tools/lib/h5tools_type.c')
-rw-r--r--tools/lib/h5tools_type.c167
1 files changed, 161 insertions, 6 deletions
diff --git a/tools/lib/h5tools_type.c b/tools/lib/h5tools_type.c
index 1ef2579..517b1bc 100644
--- a/tools/lib/h5tools_type.c
+++ b/tools/lib/h5tools_type.c
@@ -15,16 +15,16 @@
#include "h5tools.h"
/*-------------------------------------------------------------------------
- * Function: h5tools_get_native_type
+ * Function: h5tools_get_native_type
*
- * Purpose: Wrapper around H5Tget_native_type() to work around
- * Problems with bitfields.
+ * Purpose: Wrapper around H5Tget_native_type() to work around
+ * Problems with bitfields.
*
- * Return: Success: datatype ID
+ * Return: Success: datatype ID
*
- * Failure: FAIL
+ * Failure: FAIL
*
- * Programmer: Quincey Koziol
+ * Programmer: Quincey Koziol
* Tuesday, October 5, 2004
*
* Modifications:
@@ -46,3 +46,158 @@ h5tools_get_native_type(hid_t type)
return(p_type);
}
+
+/*-------------------------------------------------------------------------
+ * Function: h5tools_get_little_endian_type
+ *
+ * Purpose: Get a little endian type from a file type
+ *
+ * Return: Success: datatype ID
+ * Failure: FAIL
+ *
+ * Programmer: Pedro Vicente Nunes
+ * Tuesday, July 18, 2006
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+hid_t
+h5tools_get_little_endian_type(hid_t tid)
+{
+ hid_t p_type=-1;
+ H5T_class_t type_class;
+ size_t size;
+ H5T_sign_t sign;
+
+ type_class = H5Tget_class(tid);
+ size = H5Tget_size(tid);
+ sign = H5Tget_sign(tid);
+
+ switch( type_class )
+ {
+ case H5T_INTEGER:
+ {
+ if ( size == 1 && sign == H5T_SGN_2)
+ p_type=H5Tcopy(H5T_STD_I8LE);
+ else if ( size == 2 && sign == H5T_SGN_2)
+ p_type=H5Tcopy(H5T_STD_I16LE);
+ else if ( size == 4 && sign == H5T_SGN_2)
+ p_type=H5Tcopy(H5T_STD_I32LE);
+ else if ( size == 8 && sign == H5T_SGN_2)
+ p_type=H5Tcopy(H5T_STD_I64LE);
+ else if ( size == 1 && sign == H5T_SGN_NONE)
+ p_type=H5Tcopy(H5T_STD_U8LE);
+ else if ( size == 2 && sign == H5T_SGN_NONE)
+ p_type=H5Tcopy(H5T_STD_U16LE);
+ else if ( size == 4 && sign == H5T_SGN_NONE)
+ p_type=H5Tcopy(H5T_STD_U32LE);
+ else if ( size == 8 && sign == H5T_SGN_NONE)
+ p_type=H5Tcopy(H5T_STD_U64LE);
+ }
+ break;
+
+ case H5T_FLOAT:
+ if ( size == 4)
+ p_type=H5Tcopy(H5T_IEEE_F32LE);
+ else if ( size == 8)
+ p_type=H5Tcopy(H5T_IEEE_F64LE);
+ break;
+
+ case H5T_TIME:
+ case H5T_BITFIELD:
+ case H5T_OPAQUE:
+ case H5T_STRING:
+ case H5T_COMPOUND:
+ case H5T_REFERENCE:
+ case H5T_ENUM:
+ case H5T_VLEN:
+ case H5T_ARRAY:
+ break;
+
+ default:
+ break;
+
+ }
+
+ return(p_type);
+}
+
+
+/*-------------------------------------------------------------------------
+ * Function: h5tools_get_big_endian_type
+ *
+ * Purpose: Get a big endian type from a file type
+ *
+ * Return: Success: datatype ID
+ * Failure: FAIL
+ *
+ * Programmer: Pedro Vicente Nunes
+ * Tuesday, July 18, 2006
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+hid_t
+h5tools_get_big_endian_type(hid_t tid)
+{
+ hid_t p_type=-1;
+ H5T_class_t type_class;
+ size_t size;
+ H5T_sign_t sign;
+
+ type_class = H5Tget_class(tid);
+ size = H5Tget_size(tid);
+ sign = H5Tget_sign(tid);
+
+ switch( type_class )
+ {
+ case H5T_INTEGER:
+ {
+ if ( size == 1 && sign == H5T_SGN_2)
+ p_type=H5Tcopy(H5T_STD_I8BE);
+ else if ( size == 2 && sign == H5T_SGN_2)
+ p_type=H5Tcopy(H5T_STD_I16BE);
+ else if ( size == 4 && sign == H5T_SGN_2)
+ p_type=H5Tcopy(H5T_STD_I32BE);
+ else if ( size == 8 && sign == H5T_SGN_2)
+ p_type=H5Tcopy(H5T_STD_I64BE);
+ else if ( size == 1 && sign == H5T_SGN_NONE)
+ p_type=H5Tcopy(H5T_STD_U8BE);
+ else if ( size == 2 && sign == H5T_SGN_NONE)
+ p_type=H5Tcopy(H5T_STD_U16BE);
+ else if ( size == 4 && sign == H5T_SGN_NONE)
+ p_type=H5Tcopy(H5T_STD_U32BE);
+ else if ( size == 8 && sign == H5T_SGN_NONE)
+ p_type=H5Tcopy(H5T_STD_U64BE);
+ }
+ break;
+
+ case H5T_FLOAT:
+ if ( size == 4)
+ p_type=H5Tcopy(H5T_IEEE_F32BE);
+ else if ( size == 8)
+ p_type=H5Tcopy(H5T_IEEE_F64BE);
+ break;
+
+ case H5T_TIME:
+ case H5T_BITFIELD:
+ case H5T_OPAQUE:
+ case H5T_STRING:
+ case H5T_COMPOUND:
+ case H5T_REFERENCE:
+ case H5T_ENUM:
+ case H5T_VLEN:
+ case H5T_ARRAY:
+ break;
+
+ default:
+ break;
+
+ }
+
+
+ return(p_type);
+}
+