summaryrefslogtreecommitdiffstats
path: root/src/H5Tconv.c
diff options
context:
space:
mode:
authorRobb Matzke <matzke@llnl.gov>1998-01-29 19:36:16 (GMT)
committerRobb Matzke <matzke@llnl.gov>1998-01-29 19:36:16 (GMT)
commit28e23330df9b9d35c1c13e1f983f66b4a98afe36 (patch)
tree99483b64cdc89e319b68d57c2ad99da250712529 /src/H5Tconv.c
parent5761b90f63b5f3d69e914cfbe7a4619cce9bfc4b (diff)
downloadhdf5-28e23330df9b9d35c1c13e1f983f66b4a98afe36.zip
hdf5-28e23330df9b9d35c1c13e1f983f66b4a98afe36.tar.gz
hdf5-28e23330df9b9d35c1c13e1f983f66b4a98afe36.tar.bz2
[svn-r197] Changes since 19980129
---------------------- ./config/freebds2.2.1 ./config/irix64 ./config/linux Added -DH5T_DEBUG to the debugging flags. Also changed `true' to `:' for the Irix64 ranlib program. This turns on printing of data type conversion statistics when the program exits. ./html/Datatypes.html Fixed documentation for data conversion functions and updated examples. ./src/H5D.c The I/O pipeline updates data type conversion statistics. ./src/H5T.c ./src/H5Tconv.c ./src/H5Tpkg.h ./src/H5Tpublic.h Cleaned up data type conversion registration interface.
Diffstat (limited to 'src/H5Tconv.c')
-rw-r--r--src/H5Tconv.c310
1 files changed, 187 insertions, 123 deletions
diff --git a/src/H5Tconv.c b/src/H5Tconv.c
index c30f8d7..0368fcb 100644
--- a/src/H5Tconv.c
+++ b/src/H5Tconv.c
@@ -49,6 +49,31 @@ H5T_conv_noop(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts,
void *buf, void *background)
{
FUNC_ENTER(H5T_conv_noop, FAIL);
+
+ switch (cdata->command) {
+ case H5T_CONV_INIT:
+ /* Nothing to initialize */
+ break;
+
+ case H5T_CONV_CONV:
+ /* Nothing to convert */
+ break;
+
+ case H5T_CONV_FREE:
+ /* Nothing to free */
+#ifdef H5T_DEBUG
+ if (cdata->ncalls>0) {
+ fprintf (stderr, "HDF5-DIAG: H5T_conv_noop statistics...\n");
+ fprintf (stderr, " Number of calls: %lu\n", cdata->ncalls);
+ fprintf (stderr, " Data points converted: %lu\n", cdata->nelmts);
+ }
+#endif
+
+ default:
+ HRETURN_ERROR (H5E_DATATYPE, H5E_UNSUPPORTED, FAIL,
+ "unknown conversion command");
+ }
+
FUNC_LEAVE(SUCCEED);
}
@@ -83,16 +108,15 @@ H5T_conv_order(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts,
FUNC_ENTER(H5T_conv_order, FAIL);
- /* Check args */
- if (H5_DATATYPE != H5A_group(src_id) ||
- NULL == (src = H5A_object(src_id)) ||
- H5_DATATYPE != H5A_group(dst_id) ||
- NULL == (dst = H5A_object(dst_id))) {
- HRETURN_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a data type");
- }
-
- if (!buf) {
+ switch (cdata->command) {
+ case H5T_CONV_INIT:
/* Capability query */
+ if (H5_DATATYPE != H5A_group(src_id) ||
+ NULL == (src = H5A_object(src_id)) ||
+ H5_DATATYPE != H5A_group(dst_id) ||
+ NULL == (dst = H5A_object(dst_id))) {
+ HRETURN_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a data type");
+ }
if (src->size != dst->size ||
0 != src->u.atomic.offset ||
0 != dst->u.atomic.offset ||
@@ -126,17 +150,40 @@ H5T_conv_order(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts,
HRETURN_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL,
"conversion not supported");
}
- HRETURN(SUCCEED);
- }
-
- /* The conversion */
- md = src->size / 2;
- for (i = 0; i < nelmts; i++, buf += src->size) {
- for (j = 0; j < md; j++) {
- tmp = buf[j];
- buf[j] = buf[src->size - (j + 1)];
- buf[src->size - (j + 1)] = tmp;
- }
+ break;
+
+ case H5T_CONV_CONV:
+ /* The conversion */
+ if (H5_DATATYPE != H5A_group(src_id) ||
+ NULL == (src = H5A_object(src_id)) ||
+ H5_DATATYPE != H5A_group(dst_id) ||
+ NULL == (dst = H5A_object(dst_id))) {
+ HRETURN_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a data type");
+ }
+ md = src->size / 2;
+ for (i = 0; i < nelmts; i++, buf += src->size) {
+ for (j = 0; j < md; j++) {
+ tmp = buf[j];
+ buf[j] = buf[src->size - (j + 1)];
+ buf[src->size - (j + 1)] = tmp;
+ }
+ }
+ break;
+
+ case H5T_CONV_FREE:
+ /* Free private data */
+#ifdef H5T_DEBUG
+ if (cdata->ncalls>0) {
+ fprintf (stderr, "HDF5-DIAG: H5T_conv_order statistics...\n");
+ fprintf (stderr, " Number of calls: %lu\n", cdata->ncalls);
+ fprintf (stderr, " Data points converted: %lu\n", cdata->nelmts);
+ }
+#endif
+ break;
+
+ default:
+ HRETURN_ERROR (H5E_DATATYPE, H5E_UNSUPPORTED, FAIL,
+ "unknown conversion command");
}
FUNC_LEAVE(SUCCEED);
@@ -306,12 +353,12 @@ H5T_conv_struct(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts,
size_t offset; /*byte offset wrt struct */
size_t src_delta, dst_delta; /*source & destination stride */
intn elmtno, i; /*counters */
- herr_t ret_value = FAIL;
H5T_conv_struct_t *priv = (H5T_conv_struct_t *)(cdata->priv);
FUNC_ENTER (H5T_conv_struct, FAIL);
- if (!buf && H5T_CONV_INIT==nelmts) {
+ switch (cdata->command) {
+ case H5T_CONV_INIT:
/*
* First, determine if this conversion function applies to the
* conversion path SRC_ID-->DST_ID. If not, return failure;
@@ -349,129 +396,146 @@ H5T_conv_struct(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts,
HRETURN_ERROR (H5E_DATATYPE, H5E_CANTINIT, FAIL,
"unable to initialize conversion data");
}
- HRETURN (SUCCEED);
-
- } else if (!buf && H5T_CONV_FREE==nelmts) {
+ break;
+
+ case H5T_CONV_FREE:
/*
* Free the private conversion data.
*/
+#ifdef H5T_DEBUG
+ if (cdata->ncalls>0) {
+ fprintf (stderr, "HDF5-DIAG: H5T_conv_struct statistics...\n");
+ fprintf (stderr, " Number of calls: %lu\n", cdata->ncalls);
+ fprintf (stderr, " Data points converted: %lu\n", cdata->nelmts);
+ }
+#endif
H5MM_xfree (priv->src2dst);
H5MM_xfree (priv->src_memb_id);
H5MM_xfree (priv->dst_memb_id);
H5MM_xfree (priv->memb_conv);
cdata->priv = priv = H5MM_xfree (priv);
- HRETURN (SUCCEED);
-
- } else if (!buf) {
- /* Some other command we don't know about yet.*/
- HRETURN_ERROR (H5E_DATATYPE, H5E_UNSUPPORTED, FAIL,
- "unknown conversion command");
- }
-
-
- /* Check args */
- if (H5_DATATYPE != H5A_group(src_id) ||
- NULL == (src = H5A_object(src_id)) ||
- H5_DATATYPE != H5A_group(dst_id) ||
- NULL == (dst = H5A_object(dst_id))) {
- HRETURN_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a data type");
- }
- assert (priv);
- assert (bkg && cdata->need_bkg>=H5T_BKG_TEMP);
+ break;
- if (cdata->recalc &&
- H5T_conv_struct_init (src, dst, cdata)<0) {
- HRETURN_ERROR (H5E_DATATYPE, H5E_CANTINIT, FAIL,
- "unable to initialize conversion data");
- }
-
-
- /*
- * Insure that members are sorted.
- */
- H5T_sort_by_offset (src);
- H5T_sort_by_offset (dst);
- src2dst = priv->src2dst;
+ case H5T_CONV_CONV:
+ /*
+ * Conversion.
+ */
+ if (H5_DATATYPE != H5A_group(src_id) ||
+ NULL == (src = H5A_object(src_id)) ||
+ H5_DATATYPE != H5A_group(dst_id) ||
+ NULL == (dst = H5A_object(dst_id))) {
+ HRETURN_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a data type");
+ }
+ assert (priv);
+ assert (bkg && cdata->need_bkg>=H5T_BKG_TEMP);
- /*
- * Direction of conversion.
- */
- if (dst->size <= src->size) {
- src_delta = src->size;
- dst_delta = dst->size;
- } else {
- src_delta = -(src->size);
- dst_delta = -(dst->size);
- buf += (nelmts-1) * src->size;
- bkg += (nelmts-1) * dst->size;
- }
+ if (cdata->recalc &&
+ H5T_conv_struct_init (src, dst, cdata)<0) {
+ HRETURN_ERROR (H5E_DATATYPE, H5E_CANTINIT, FAIL,
+ "unable to initialize conversion data");
+ }
- for (elmtno=0; elmtno<nelmts; elmtno++) {
/*
- * For each source member which will be present in the destination,
- * convert the member to the destination type unless it is larger than
- * the source type. Then move the member to the left-most unoccupied
- * position in the buffer. This makes the data point as small as
- * possible with all the free space on the right side.
+ * Insure that members are sorted.
*/
- for (i=0, offset=0; i<src->u.compnd.nmembs; i++) {
- if (src2dst[i]<0) continue;
- src_memb = src->u.compnd.memb + i;
- dst_memb = dst->u.compnd.memb + src2dst[i];
-
- if (dst_memb->type.size <= src_memb->type.size) {
- H5T_conv_t tconv_func = priv->memb_conv[src2dst[i]];
- H5T_cdata_t *memb_cdata = priv->memb_cdata[src2dst[i]];
- (tconv_func)(priv->src_memb_id[src2dst[i]],
- priv->dst_memb_id[src2dst[i]], memb_cdata, 1,
- buf + src_memb->offset, bkg + dst_memb->offset);
-
- HDmemmove (buf + offset, buf + src_memb->offset,
- dst_memb->type.size);
- offset += dst_memb->type.size;
- } else {
- HDmemmove (buf + offset, buf + src_memb->offset,
- src_memb->type.size);
- offset += src_memb->type.size;
- }
- }
+ H5T_sort_by_offset (src);
+ H5T_sort_by_offset (dst);
+ src2dst = priv->src2dst;
/*
- * For each source member which will be present in the destination,
- * convert the member to the destination type if it is larger than the
- * source type (that is, has not been converted yet). Then copy the
- * member to the destination offset in the background buffer.
+ * Direction of conversion.
*/
- for (i=src->u.compnd.nmembs-1; i>=0; --i) {
- if (src2dst[i]<0) continue;
- src_memb = src->u.compnd.memb + i;
- dst_memb = dst->u.compnd.memb + src2dst[i];
- offset -= dst_memb->type.size;
-
- if (dst_memb->type.size > src_memb->type.size) {
- H5T_conv_t tconv_func = priv->memb_conv[src2dst[i]];
- H5T_cdata_t *memb_cdata = priv->memb_cdata[src2dst[i]];
- (tconv_func)(priv->src_memb_id[src2dst[i]],
- priv->dst_memb_id[src2dst[i]], memb_cdata, 1,
- buf + offset, bkg + dst_memb->offset);
+ if (dst->size <= src->size) {
+ src_delta = src->size;
+ dst_delta = dst->size;
+ } else {
+ src_delta = -(src->size);
+ dst_delta = -(dst->size);
+ buf += (nelmts-1) * src->size;
+ bkg += (nelmts-1) * dst->size;
+ }
+
+ for (elmtno=0; elmtno<nelmts; elmtno++) {
+ /*
+ * For each source member which will be present in the
+ * destination, convert the member to the destination type unless
+ * it is larger than the source type. Then move the member to the
+ * left-most unoccupied position in the buffer. This makes the
+ * data point as small as possible with all the free space on the
+ * right side.
+ */
+ for (i=0, offset=0; i<src->u.compnd.nmembs; i++) {
+ if (src2dst[i]<0) continue;
+ src_memb = src->u.compnd.memb + i;
+ dst_memb = dst->u.compnd.memb + src2dst[i];
+
+ if (dst_memb->type.size <= src_memb->type.size) {
+ H5T_conv_t tconv_func = priv->memb_conv[src2dst[i]];
+ H5T_cdata_t *memb_cdata = priv->memb_cdata[src2dst[i]];
+ memb_cdata->command = H5T_CONV_CONV;
+ (tconv_func)(priv->src_memb_id[src2dst[i]],
+ priv->dst_memb_id[src2dst[i]],
+ memb_cdata,
+ 1,
+ buf + src_memb->offset,
+ bkg + dst_memb->offset);
+
+ HDmemmove (buf + offset, buf + src_memb->offset,
+ dst_memb->type.size);
+ offset += dst_memb->type.size;
+ } else {
+ HDmemmove (buf + offset, buf + src_memb->offset,
+ src_memb->type.size);
+ offset += src_memb->type.size;
+ }
}
- HDmemmove (bkg+dst_memb->offset, buf+offset, dst_memb->type.size);
+
+ /*
+ * For each source member which will be present in the
+ * destination, convert the member to the destination type if it
+ * is larger than the source type (that is, has not been converted
+ * yet). Then copy the member to the destination offset in the
+ * background buffer.
+ */
+ for (i=src->u.compnd.nmembs-1; i>=0; --i) {
+ if (src2dst[i]<0) continue;
+ src_memb = src->u.compnd.memb + i;
+ dst_memb = dst->u.compnd.memb + src2dst[i];
+ offset -= dst_memb->type.size;
+
+ if (dst_memb->type.size > src_memb->type.size) {
+ H5T_conv_t tconv_func = priv->memb_conv[src2dst[i]];
+ H5T_cdata_t *memb_cdata = priv->memb_cdata[src2dst[i]];
+ memb_cdata->command = H5T_CONV_CONV;
+ (tconv_func)(priv->src_memb_id[src2dst[i]],
+ priv->dst_memb_id[src2dst[i]], memb_cdata, 1,
+ buf + offset, bkg + dst_memb->offset);
+ }
+ HDmemmove (bkg+dst_memb->offset, buf+offset,
+ dst_memb->type.size);
+ }
+ assert (0==offset);
+
+ /*
+ * Update buf and background.
+ */
+ buf += src_delta;
+ bkg += dst_delta;
}
- assert (0==offset);
/*
- * Update buf and background.
+ * Copy the background buffer back into the in-place conversion
+ * buffer.
*/
- buf += src_delta;
- bkg += dst_delta;
+ HDmemcpy (_buf, _bkg, nelmts*dst->size);
+ break;
+
+ default:
+ /* Some other command we don't know about yet.*/
+ HRETURN_ERROR (H5E_DATATYPE, H5E_UNSUPPORTED, FAIL,
+ "unknown conversion command");
}
- /*
- * Copy the background buffer back into the in-place conversion buffer.
- */
- HDmemcpy (_buf, _bkg, nelmts*dst->size);
- ret_value = SUCCEED;
-
- FUNC_LEAVE (ret_value);
+ FUNC_LEAVE (SUCCEED);
}