diff options
-rw-r--r-- | MANIFEST | 1 | ||||
-rw-r--r-- | src/H5D.c | 109 | ||||
-rw-r--r-- | src/H5P.c | 61 | ||||
-rw-r--r-- | src/H5Pprivate.h | 93 | ||||
-rw-r--r-- | src/Makefile.in | 3 |
5 files changed, 184 insertions, 83 deletions
@@ -90,6 +90,7 @@ ./src/H5P.c ./src/H5Pprivate.h ./src/H5Ppublic.h +./src/H5Psimp.c ./src/H5private.h ./src/H5public.h ./src/H5T.c @@ -824,14 +824,12 @@ H5D_read(H5D_t *dataset, const H5T_t *mem_type, const H5P_t *mem_space, void *buf/*out*/) { size_t nelmts, src_size, dst_size; - size_t offset[H5O_LAYOUT_NDIMS]; - size_t size[H5O_LAYOUT_NDIMS]; - size_t zero[H5O_LAYOUT_NDIMS]; - intn i; herr_t ret_value = FAIL; - uint8 *conv_buf = NULL; /*data type conv buffer */ - H5T_conv_t conv_func = NULL; /*conversion function */ + uint8 *tconv_buf = NULL; /*data type conv buffer */ + H5T_conv_t tconv_func = NULL; /*conversion function */ hid_t src_id = -1, dst_id = -1;/*temporary type atoms */ + const H5P_conv_t *sconv_func = NULL; /*space conversion funcs*/ + H5P_number_t numbering; /*element numbering info*/ FUNC_ENTER(H5D_read, FAIL); @@ -840,13 +838,8 @@ H5D_read(H5D_t *dataset, const H5T_t *mem_type, const H5P_t *mem_space, assert(mem_type); assert(xfer_parms); assert(buf); - - if ((mem_space && H5P_cmp(mem_space, dataset->space)) || - (file_space && H5P_cmp(file_space, dataset->space))) { - HGOTO_ERROR(H5E_DATASET, H5E_UNSUPPORTED, FAIL, - "space conversion not supported yet"); - } - assert (!mem_space || H5P_SIMPLE==mem_space->type); + if (!file_space) file_space = dataset->space; + if (!mem_space) mem_space = file_space; /* * Convert data types to atoms because the conversion functions are @@ -859,6 +852,27 @@ H5D_read(H5D_t *dataset, const H5T_t *mem_type, const H5P_t *mem_space, } /* + * Locate the type conversion function, data space conversion, and set up + * the element numbering information. + */ + if (NULL == (tconv_func = H5T_find(dataset->type, mem_type))) { + HGOTO_ERROR(H5E_DATASET, H5E_UNSUPPORTED, FAIL, + "unable to convert between src and dest data types"); + } + if (NULL==(sconv_func=H5P_find (file_space, mem_space))) { + HGOTO_ERROR (H5E_DATASET, H5E_UNSUPPORTED, FAIL, + "unable to convert between src and dest data spaces"); + } + if (sconv_func->init && + (sconv_func->init)(&(dataset->layout), mem_space, file_space, + &numbering/*out*/)<=0) { + HGOTO_ERROR (H5E_DATASET, H5E_CANTINIT, FAIL, + "unable to initialize element numbering information"); + } else { + HDmemset (&numbering, 0, sizeof numbering); + } + + /* * Compute the size of the request and allocate scratch buffers. */ #ifndef LATER @@ -869,62 +883,43 @@ H5D_read(H5D_t *dataset, const H5T_t *mem_type, const H5P_t *mem_space, nelmts = H5P_get_npoints(dataset->space); src_size = nelmts * H5T_get_size(dataset->type); dst_size = nelmts * H5T_get_size(mem_type); - conv_buf = H5MM_xmalloc(MAX(src_size, dst_size)); + tconv_buf = H5MM_xmalloc(MAX(src_size, dst_size)); #endif /* - * Locate the type conversion function. - */ - if (NULL == (conv_func = H5T_find(dataset->type, mem_type))) { - HGOTO_ERROR(H5E_DATASET, H5E_UNSUPPORTED, FAIL, - "unable to convert between src and dest data types"); - } - - /* * Gather the data from disk into the data type conversion buffer. */ -#ifndef LATER - /* - * Note: We only support complete reads currently. That is, the - * hyperslab must begin at zero in memory and on disk and the - * size of the hyperslab must be the same as the array on disk. - */ - for (i = 0; i < dataset->layout.ndims; i++) { - zero[i] = 0; - offset[i] = 0; - } - i = H5P_get_dims (dataset->space, size); - assert (i+1==dataset->layout.ndims); - size[i] = H5T_get_size (dataset->type); -#endif - if (H5F_arr_read(dataset->ent.file, &(dataset->layout), size, offset, - zero, size, conv_buf) < 0) { - HGOTO_ERROR(H5E_IO, H5E_READERROR, FAIL, "read failed"); + if ((sconv_func->fgath)(dataset->ent.file, &(dataset->layout), + H5T_get_size (dataset->type), file_space, + &numbering, 0, nelmts, + tconv_buf/*out*/)<0) { + HGOTO_ERROR(H5E_IO, H5E_READERROR, FAIL, "gather failed"); } /* * Perform data type conversion. */ - if ((conv_func) (src_id, dst_id, nelmts, conv_buf, NULL) < 0) { + if ((tconv_func) (src_id, dst_id, nelmts, tconv_buf, NULL) < 0) { HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "data type conversion failed"); } /* - * Copy conversion buffer into destination. + * Scatter the data into memory. */ - HDmemcpy(buf, conv_buf, dst_size); - + if ((sconv_func->mscat)(tconv_buf, H5T_get_size (mem_type), mem_space, + &numbering, 0, nelmts, buf/*out*/)<0) { + HGOTO_ERROR (H5E_IO, H5E_WRITEERROR, FAIL, "scatter failed"); + } ret_value = SUCCEED; + done: - if (src_id >= 0) - H5A_dec_ref(src_id); - if (dst_id >= 0) - H5A_dec_ref(dst_id); - conv_buf = H5MM_xfree(conv_buf); + if (src_id >= 0) H5A_dec_ref(src_id); + if (dst_id >= 0) H5A_dec_ref(dst_id); + tconv_buf = H5MM_xfree(tconv_buf); FUNC_LEAVE(ret_value); } - + /*------------------------------------------------------------------------- * Function: H5D_write * @@ -953,8 +948,8 @@ H5D_write(H5D_t *dataset, const H5T_t *mem_type, const H5P_t *mem_space, size_t zero[H5O_LAYOUT_NDIMS]; intn i; herr_t ret_value = FAIL; - uint8 *conv_buf = NULL; /*data type conversion buffer */ - H5T_conv_t conv_func = NULL; /*data type conversion function */ + uint8 *tconv_buf = NULL; /*data type conversion buffer */ + H5T_conv_t tconv_func = NULL; /*data type conversion function */ hid_t src_id = -1, dst_id = -1; /*temporary type atoms */ FUNC_ENTER(H5D_write, FAIL); @@ -997,13 +992,13 @@ H5D_write(H5D_t *dataset, const H5T_t *mem_type, const H5P_t *mem_space, nelmts = H5P_get_npoints(dataset->space); src_size = nelmts * H5T_get_size(mem_type); dst_size = nelmts * H5T_get_size(dataset->type); - conv_buf = H5MM_xmalloc(MAX(src_size, dst_size)); + tconv_buf = H5MM_xmalloc(MAX(src_size, dst_size)); #endif /* * Locate the type conversion function. */ - if (NULL == (conv_func = H5T_find(mem_type, dataset->type))) { + if (NULL == (tconv_func = H5T_find(mem_type, dataset->type))) { HGOTO_ERROR(H5E_DATASET, H5E_UNSUPPORTED, FAIL, "unable to convert between src and dest data types"); } @@ -1011,12 +1006,12 @@ H5D_write(H5D_t *dataset, const H5T_t *mem_type, const H5P_t *mem_space, /* * Gather data into the data type conversion buffer. */ - HDmemcpy(conv_buf, buf, src_size); + HDmemcpy(tconv_buf, buf, src_size); /* * Perform data type conversion. */ - if ((conv_func) (src_id, dst_id, nelmts, conv_buf, NULL) < 0) { + if ((tconv_func) (src_id, dst_id, nelmts, tconv_buf, NULL) < 0) { HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "data type conversion failed"); } @@ -1039,7 +1034,7 @@ H5D_write(H5D_t *dataset, const H5T_t *mem_type, const H5P_t *mem_space, size[i] = H5T_get_size (dataset->type); #endif if (H5F_arr_write(dataset->ent.file, &(dataset->layout), size, offset, - zero, size, conv_buf) < 0) { + zero, size, tconv_buf) < 0) { HGOTO_ERROR(H5E_IO, H5E_WRITEERROR, FAIL, "write failed"); } ret_value = SUCCEED; @@ -1047,6 +1042,6 @@ H5D_write(H5D_t *dataset, const H5T_t *mem_type, const H5P_t *mem_space, done: if (src_id >= 0) H5A_dec_ref(src_id); if (dst_id >= 0) H5A_dec_ref(dst_id); - conv_buf = H5MM_xfree(conv_buf); + tconv_buf = H5MM_xfree(tconv_buf); FUNC_LEAVE(ret_value); } @@ -23,11 +23,11 @@ static char RcsId[] = "@(#)$Revision$"; #include <H5Oprivate.h> /*object headers */ #include <H5Pprivate.h> /* Data-space functions */ -#define PABLO_MASK H5P_mask /* Interface initialization */ -static intn interface_initialize_g = FALSE; +#define PABLO_MASK H5P_mask #define INTERFACE_INIT H5P_init_interface +static intn interface_initialize_g = FALSE; static herr_t H5P_init_interface(void); static void H5P_term_interface(void); @@ -892,3 +892,60 @@ H5Pset_space(hid_t sid, intn rank, const size_t *dims) /* Normal function cleanup */ FUNC_LEAVE(ret_value); } + +/*------------------------------------------------------------------------- + * Function: H5P_find + * + * Purpose: Given source and destination data spaces (SRC and DST) this + * function locates the data space conversion functions and + * initializes CONV to point to them. + * + * Return: Success: Pointer to a data space conversion callback + * list. + * + * Failure: NULL + * + * Programmer: Robb Matzke + * Wednesday, January 21, 1998 + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +const H5P_conv_t * +H5P_find (const H5P_t *src, const H5P_t *dst) +{ + static H5P_conv_t _conv; + static const H5P_conv_t *conv = NULL; + + FUNC_ENTER (H5P_find, NULL); + + /* Check args */ + assert (src && H5P_SIMPLE==src->type); + assert (dst && H5P_SIMPLE==dst->type); + + /* + * We can't do conversion if the source and destination select a + * different number of data points. + */ + if (H5P_get_npoints (src) != H5P_get_npoints (dst)) { + HRETURN_ERROR (H5E_DATASPACE, H5E_BADRANGE, NULL, + "src and dest data spaces are different sizes"); + } + + /* + * Initialize pointers. This will eventually be a table lookup based + * on the source and destination data spaces, similar to H5T_find(), but + * for now we only support simple data spaces. + */ + if (!conv) { + _conv.init = H5P_simp_init; + _conv.fgath = H5P_simp_fgath; + _conv.mscat = H5P_simp_mscat; + _conv.mgath = H5P_simp_mgath; + _conv.fscat = H5P_simp_fscat; + conv = &_conv; + } + + FUNC_LEAVE (conv); +} diff --git a/src/H5Pprivate.h b/src/H5Pprivate.h index 3a2f804..e5dca7e 100644 --- a/src/H5Pprivate.h +++ b/src/H5Pprivate.h @@ -10,51 +10,98 @@ * * ****************************************************************************/ -/* $Id$ */ - /* * This file contains private information about the H5P module */ - #ifndef _H5Pprivate_H #define _H5Pprivate_H + #include <H5Ppublic.h> /* Private headers needed by this file */ #include <H5private.h> -#include <H5Gprivate.h> /*for H5G_entry_t */ +#include <H5Gprivate.h> /*for H5G_entry_t */ +#include <H5Oprivate.h> + +#define H5P_RESERVED_ATOMS 2 /* Flags to indicate special dataspace features are active */ #define H5P_VALID_MAX 0x01 #define H5P_VALID_PERM 0x02 typedef struct H5P_simple_t { - intn rank; /*number of dimensions */ - intn dim_flags; /*dimension flags */ - size_t *size; /*dimension sizes */ - size_t *max; /*maximum dimension sizes */ - intn *perm; /*dimension permutations */ + intn rank; /*number of dimensions */ + intn dim_flags; /*dimension flags */ + size_t *size; /*dimension sizes */ + size_t *max; /*maximum dimension sizes */ + intn *perm; /*dimension permutations */ } H5P_simple_t; typedef struct { - H5P_class_t type; /*type of dimensionality object */ + H5P_class_t type; /*type of dimensionality object */ union { - H5P_simple_t simple; /*simple dimensionality information */ + H5P_simple_t simple; /*simple dimensionality information */ } u; } H5P_t; -#define H5P_RESERVED_ATOMS 2 +/* + * This structure contains information about how the elements of a data space + * are numbered. + */ +typedef struct H5P_number_t { + int _place_holder; /*remove this field!*/ +} H5P_number_t; + +/* + * Callbacks for data space conversion. + */ +typedef struct H5P_tconv_t { + /* Initialize element numbering information */ + size_t (*init)(const struct H5O_layout_t *layout, const H5P_t *mem_space, + const H5P_t *file_space, H5P_number_t *numbering/*out*/); + + /* Gather elements from disk to type conversion buffer */ + size_t (*fgath)(H5F_t *f, const struct H5O_layout_t *layout, + size_t elmt_size, const H5P_t *file_space, + const H5P_number_t *numbering, intn start, intn nelmts, + void *tconv_buf/*out*/); + + /* Scatter elements from type conversion buffer to application buffer */ + herr_t (*mscat)(const void *tconv_buf, size_t elmt_size, + const H5P_t *mem_space, const H5P_number_t *numbering, + intn start, intn nelmts, void *buf/*out*/); + + /* Gather elements from app buffer to type conversion buffer */ + size_t (*mgath)(void /*fill out later*/); + + /* Scatter elements from type conversion buffer to disk */ + herr_t (*fscat)(void /*fill out later*/); +} H5P_conv_t; + +H5P_t *H5P_copy (const H5P_t *src); +herr_t H5P_close (H5P_t *ds); +size_t H5P_get_npoints (const H5P_t *ds); +intn H5P_get_ndims (const H5P_t *ds); +intn H5P_get_dims (const H5P_t *ds, size_t dims[]/*out*/); +herr_t H5P_modify (H5F_t *f, H5G_entry_t *ent, const H5P_t *space); +H5P_t *H5P_read (H5F_t *f, H5G_entry_t *ent); +intn H5P_cmp (const H5P_t *ds1, const H5P_t *ds2); +hbool_t H5P_is_simple (const H5P_t *sdim); +uintn H5P_nelem (const H5P_t *space); +const H5P_conv_t *H5P_find (const H5P_t *src, const H5P_t *dst); -H5P_t *H5P_copy(const H5P_t *src); -herr_t H5P_close(H5P_t *ds); -size_t H5P_get_npoints(const H5P_t *ds); -intn H5P_get_ndims(const H5P_t *ds); -intn H5P_get_dims(const H5P_t *ds, size_t dims[] /*out */ ); -herr_t H5P_modify(H5F_t *f, H5G_entry_t *ent, const H5P_t *space); -H5P_t *H5P_read(H5F_t *f, H5G_entry_t *ent); -intn H5P_cmp(const H5P_t *ds1, const H5P_t *ds2); - -hbool_t H5P_is_simple(const H5P_t *sdim); -uintn H5P_nelem(const H5P_t *space); +/* Conversion functions for simple data spaces */ +size_t H5P_simp_init (const struct H5O_layout_t *layout, + const H5P_t *mem_space, const H5P_t *file_space, + H5P_number_t *numbering/*out*/); +size_t H5P_simp_fgath (H5F_t *f, const struct H5O_layout_t *layout, + size_t elmt_size, const H5P_t *file_space, + const H5P_number_t *numbering, intn start, intn nelmts, + void *tconv_buf/*out*/); +herr_t H5P_simp_mscat (const void *tconv_buf, size_t elmt_size, + const H5P_t *mem_space, const H5P_number_t *numbering, + intn start, intn nelmts, void *buf/*out*/); +size_t H5P_simp_mgath (void); +herr_t H5P_simp_fscat (void); #endif diff --git a/src/Makefile.in b/src/Makefile.in index 7bb2f81..912a901 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -18,7 +18,8 @@ LIB_SRC=H5.c H5A.c H5AC.c H5B.c H5C.c H5D.c H5E.c H5F.c H5Farray.c H5Fcore.c \ H5Ffamily.c H5Fistore.c H5Flow.c H5Fsec2.c H5Fsplit.c H5Fstdio.c \ H5G.c H5Gent.c H5Gnode.c H5Gstab.c H5H.c H5M.c H5MF.c H5MM.c H5O.c \ H5Ocont.c H5Odtype.c H5Oefl.c H5Olayout.c H5Oname.c H5Onull.c \ - H5Osdspace.c H5Ostab.c H5P.c H5T.c H5Tconv.c H5Tinit.c H5V.c + H5Osdspace.c H5Ostab.c H5P.c H5Psimp.c H5T.c H5Tconv.c H5Tinit.c \ + H5V.c LIB_OBJ=$(LIB_SRC:.c=.o) |