diff options
author | Vailin Choi <vchoi@hdfgroup.org> | 2013-04-18 18:23:51 (GMT) |
---|---|---|
committer | Vailin Choi <vchoi@hdfgroup.org> | 2013-04-18 18:23:51 (GMT) |
commit | 6ee0e05fb94445551840fcb80b9b1c254c736799 (patch) | |
tree | 0acf68cdc69dae2ff0e2a72b36e4efb6f8fbfd06 /src/H5Tconv.c | |
parent | 94f89911545edce6fc9ebde2c83357cbda0bbd70 (diff) | |
download | hdf5-6ee0e05fb94445551840fcb80b9b1c254c736799.zip hdf5-6ee0e05fb94445551840fcb80b9b1c254c736799.tar.gz hdf5-6ee0e05fb94445551840fcb80b9b1c254c736799.tar.bz2 |
[svn-r23599] Bring revisions 22802 : 23085 from trunk to revise_chunks.
h5committested.
Diffstat (limited to 'src/H5Tconv.c')
-rw-r--r-- | src/H5Tconv.c | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/src/H5Tconv.c b/src/H5Tconv.c index 983922f..5ecf864 100644 --- a/src/H5Tconv.c +++ b/src/H5Tconv.c @@ -2889,6 +2889,86 @@ 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, *dst; /*src and dst datatypes */ + H5T_t *src_parent; /*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(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") + } + break; + + default: + /* Some other command we don't know about yet.*/ + HGOTO_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, "unknown conversion command") + } /* end switch */ + +done: + /* Release the temporary datatype IDs used */ + if(src_parent_id >= 0) + H5I_dec_ref(src_parent_id); + + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5T__conv_enum_numeric() */ + + +/*------------------------------------------------------------------------- * Function: H5T__conv_vlen * * Purpose: Converts between VL datatypes in memory and on disk. |