summaryrefslogtreecommitdiffstats
path: root/src/H5Tconv.c
diff options
context:
space:
mode:
authorRaymond Lu <songyulu@hdfgroup.org>2012-10-17 18:38:38 (GMT)
committerRaymond Lu <songyulu@hdfgroup.org>2012-10-17 18:38:38 (GMT)
commit1c45b31cc674a38e32a87a168d50249a6875f821 (patch)
tree8586b6f08af5bb2807f1657092c608735649c89d /src/H5Tconv.c
parent33504deb83ded74816f659887405aecef07718bf (diff)
downloadhdf5-1c45b31cc674a38e32a87a168d50249a6875f821.zip
hdf5-1c45b31cc674a38e32a87a168d50249a6875f821.tar.gz
hdf5-1c45b31cc674a38e32a87a168d50249a6875f821.tar.bz2
[svn-r22914] I checked in the conversion function H5T__conv_enum_numeric (numeric type means integer or floating number) and the C test for it. This is the work for Chicago.
Tested on jam, koala, and ostrich.
Diffstat (limited to 'src/H5Tconv.c')
-rw-r--r--src/H5Tconv.c83
1 files changed, 83 insertions, 0 deletions
diff --git a/src/H5Tconv.c b/src/H5Tconv.c
index 983922f..b0827f8 100644
--- a/src/H5Tconv.c
+++ b/src/H5Tconv.c
@@ -2889,6 +2889,89 @@ done:
/*-------------------------------------------------------------------------
+ * Function: H5T__conv_enum_numeric
+ *
+ * Purpose: Converts enumerated data to a numeric type (integer or
+ * floating-point number). This function is registered into
+ * the conversion table twice in H5T_init_interface in H5T.c.
+ * Once for enum-integer conversion. Once for enum-float conversion.
+ *
+ * Return: Success: Non-negative
+ *
+ * Failure: negative
+ *
+ * Programmer: Raymond Lu
+ * 12 October 2012
+ *-------------------------------------------------------------------------
+ */
+herr_t
+H5T__conv_enum_numeric(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts,
+ size_t buf_stride, size_t UNUSED bkg_stride, void *_buf,
+ void UNUSED *bkg, hid_t UNUSED dxpl_id)
+{
+ H5T_t *src = NULL, *dst = NULL; /*src and dst datatypes */
+ H5T_t *src_parent = NULL; /*parent type for src */
+ hid_t src_parent_id = -1; /*ID for parent of the source */
+ H5T_path_t *tpath; /* Conversion information */
+ herr_t ret_value = SUCCEED; /* Return value */
+
+ FUNC_ENTER_PACKAGE
+
+ switch(cdata->command) {
+ case H5T_CONV_INIT:
+ /*
+ * Determine if this conversion function applies to the conversion
+ * path SRC_ID->DST_ID. If not, return failure.
+ */
+ if(NULL == (src = (H5T_t *)H5I_object(src_id)) || NULL == (dst = (H5T_t *)H5I_object(dst_id)))
+ HGOTO_ERROR(H5E_DATATYPE, H5E_BADTYPE, FAIL, "not a datatype")
+ if(H5T_ENUM != src->shared->type)
+ HGOTO_ERROR(H5E_DATATYPE, H5E_BADTYPE, FAIL, "source type is not a H5T_ENUM datatype")
+ if(H5T_INTEGER != dst->shared->type && H5T_FLOAT != dst->shared->type)
+ HGOTO_ERROR(H5E_DATATYPE, H5E_BADTYPE, FAIL, "destination is not an integer type")
+
+ cdata->need_bkg = H5T_BKG_NO;
+ break;
+
+ case H5T_CONV_FREE:
+ break;
+
+ case H5T_CONV_CONV:
+ if(NULL == (src = (H5T_t *)H5I_object(src_id)) || NULL == (dst = (H5T_t *)H5I_object(dst_id)))
+ HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a datatype")
+
+ src_parent = src->shared->parent;
+ if(H5T_INTEGER != src_parent->shared->type)
+ HGOTO_ERROR(H5E_DATATYPE, H5E_BADTYPE, FAIL, "the base type of the source enum is not an integer type")
+
+ if(NULL == (tpath = H5T_path_find(src_parent, dst, NULL, NULL, dxpl_id, FALSE))) {
+ HGOTO_ERROR(H5E_DATASET, H5E_UNSUPPORTED, FAIL, "unable to convert between src and dest datatype")
+ } else if (!H5T_path_noop(tpath)) {
+ if((src_parent_id = H5I_register(H5I_DATATYPE, H5T_copy(src_parent, H5T_COPY_ALL), FALSE)) < 0)
+ HGOTO_ERROR(H5E_DATASET, H5E_CANTREGISTER, FAIL, "unable to register types for conversion")
+ }
+
+ /* Convert the data */
+ if(H5T_convert(tpath, src_parent_id, dst_id, nelmts, buf_stride, bkg_stride, _buf, bkg, dxpl_id) < 0)
+ HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "datatype conversion failed")
+
+ /* Release the temporary datatype IDs used */
+ if(src_parent_id >= 0)
+ H5I_dec_ref(src_parent_id);
+
+ break;
+
+ default:
+ /* Some other command we don't know about yet.*/
+ HGOTO_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, "unknown conversion command")
+ } /* end switch */
+
+done:
+ FUNC_LEAVE_NOAPI(ret_value)
+} /* end H5T__conv_enum_numeric() */
+
+
+/*-------------------------------------------------------------------------
* Function: H5T__conv_vlen
*
* Purpose: Converts between VL datatypes in memory and on disk.