void *
_saf_convert(hid_t srctype, /* Source datatype; type of SRCBUF value. */
const void *srcbuf, /* Source datum to be converted to a new type. */
hid_t dsttype, /* Destination datatype; type of DSTBUF value. */
void *dstbuf /* Optional destination buffer. If not supplied then a buffer is allocated. */
)
{
SAF_ENTER(_saf_convert, NULL);
static char tmp[128];
size_t srcsize = H5Tget_size(srctype);
size_t dstsize = H5Tget_size(dsttype);
if (!srcsize || !dstsize)
SAF_ERROR(NULL, _saf_errmsg("unable to get size of source or destination datatype"));
assert(srcsize<=sizeof(tmp) && dstsize<=sizeof(tmp));
memcpy(tmp, srcbuf, srcsize);
if (H5Tconvert(srctype, dsttype, 1, tmp, NULL, H5P_DEFAULT)<0)
SAF_ERROR(NULL, _saf_errmsg("datatype conversion failed"));
if (!dstbuf && NULL==(dstbuf=malloc(dstsize)))
SAF_ERROR(NULL, _saf_errmsg("unable to allocate return value"));
memcpy(dstbuf, tmp, dstsize);
SAF_LEAVE(dstbuf);
}