diff options
author | Robb Matzke <matzke@llnl.gov> | 1998-08-28 15:24:12 (GMT) |
---|---|---|
committer | Robb Matzke <matzke@llnl.gov> | 1998-08-28 15:24:12 (GMT) |
commit | 1b1be9918c1a654225f2040619f0b26ae83028fb (patch) | |
tree | db8bfa193965145aea917d4f06f122238324555d /src/H5R.c | |
parent | 69ed3c270a64d5c60544126b34431d1a7e9a7c8c (diff) | |
download | hdf5-1b1be9918c1a654225f2040619f0b26ae83028fb.zip hdf5-1b1be9918c1a654225f2040619f0b26ae83028fb.tar.gz hdf5-1b1be9918c1a654225f2040619f0b26ae83028fb.tar.bz2 |
[svn-r627] Changes since 19980827
----------------------
./src/H5G.c
Fixed a link count on groups. Groups were always created with
a link count of zero instead of one.
./src/H5Gpublic.h
Added H5G_NTYPES so applications can easily declare arrays
which are indexed by object type.
./src/H5O.c
Calling `H5O_link(&ent,0)' will succeed when the file is open
for read only because it's the only way to get the object's
current link count.
./tools/h5ls.c
Can take non-group object names on the command line (and
multiple objects). Reorganized to be more extendible. The
link count is displayed for `-v'.
./src/H5F.c
Dumping of cache statistics is controlled by only the
HDF5_DEBUG environment variable and not the H5F_ACC_DEBUG flag
for H5Fopen() and H5Fcreate() since this makes it similar to
the other debugging options.
./src/H5R.c
./test/ragged.c
./test/Makefile.in
Tests pass but still a little work left to be done.
Diffstat (limited to 'src/H5R.c')
-rw-r--r-- | src/H5R.c | 128 |
1 files changed, 115 insertions, 13 deletions
@@ -738,7 +738,7 @@ H5R_write(H5R_t *ra, hssize_t start_row, hsize_t nrows, H5T_t *type, for (i=0; i<nrows; i++) { if (size[i]>raw_cur_size[1]) { H5R_fix_overflow(ra, type, meta+i, size[i]-raw_cur_size[1], - (uint8*)(buf[i])+raw_cur_size[1]); + (uint8*)(buf[i])+raw_cur_size[1]*type_size); } meta[i].nelmts = size[i]; } @@ -997,15 +997,18 @@ H5R_read(H5R_t *ra, hssize_t start_row, hsize_t nrows, H5T_t *type, H5S_t *mm_space=NULL; /*meta memory data space */ H5S_t *rf_space=NULL; /*raw data file space */ H5S_t *rm_space=NULL; /*raw data memory space */ + H5S_t *of_space=NULL; /*overflow data file space */ + H5S_t *om_space=NULL; /*overflow data memory space */ hsize_t meta_cur_size; /*current meta data nelmts */ hsize_t meta_read_size; /*amount of meta data to read */ hsize_t raw_cur_size[2]; /*raw data current size */ - hsize_t raw_read_size; /*amount of raw data to read */ + hsize_t raw_read_size[2]; /*amount of raw data to read */ hssize_t hs_offset[2]; /*hyperslab offset */ hsize_t hs_size[2]; /*hyperslab size */ uint8 *raw_buf=NULL; /*raw buffer */ size_t type_size; /*size of the TYPE argument */ - hsize_t i; + void **buf_out=NULL; /*output BUF values */ + hsize_t i; /*counter */ FUNC_ENTER(H5R_read, FAIL); @@ -1017,6 +1020,16 @@ H5R_read(H5R_t *ra, hssize_t start_row, hsize_t nrows, H5T_t *type, if (0==nrows) HRETURN(SUCCEED); type_size = H5T_get_size(type); + /* + * Malloc `buf_out' to hold the output values for `buf'. We have to do + * this because if we return failure we want `buf' to have the original + * values. + */ + if (NULL==(buf_out=H5MM_calloc(nrows*sizeof(void*)))) { + HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, + "memory allocation failed for BUF output values"); + } + /* Read from the raw dataset */ if (NULL==(rf_space=H5D_get_space(ra->raw)) || H5S_extent_dims(rf_space, raw_cur_size, NULL)<0) { @@ -1024,17 +1037,33 @@ H5R_read(H5R_t *ra, hssize_t start_row, hsize_t nrows, H5T_t *type, "unable to determine current raw data extents"); } if ((hsize_t)start_row>=raw_cur_size[0]) { - raw_read_size = 0; + raw_read_size[0] = 0; + raw_read_size[1] = raw_cur_size[1]; } else { - raw_read_size = MIN(nrows, raw_cur_size[0]-(hsize_t)start_row); + raw_read_size[0] = MIN(nrows, raw_cur_size[0]-(hsize_t)start_row); + raw_read_size[1] = raw_cur_size[1]; } - + hs_offset[0] = start_row; + hs_offset[1] = 0; + if (NULL==(rm_space=H5S_create(H5S_SIMPLE)) || + H5S_set_extent_simple(rm_space, 2, raw_read_size, NULL)<0 || + H5S_select_hyperslab(rf_space, H5S_SELECT_SET, hs_offset, NULL, + raw_read_size, NULL)<0) { + HGOTO_ERROR(H5E_RAGGED, H5E_CANTINIT, FAIL, + "unable to set raw dataset selection"); + } + if (NULL==(raw_buf=H5MM_malloc(nrows*raw_read_size[1]*type_size))) { + HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, + "memory allocation failed for raw dataset"); + } + if (H5D_read(ra->raw, type, rm_space, rf_space, &H5D_xfer_dflt, + raw_buf)<0) { + HGOTO_ERROR(H5E_RAGGED, H5E_READERROR, FAIL, + "unable to read raw dataset"); + } + HDmemset(raw_buf+raw_read_size[0]*raw_read_size[1]*type_size, 0, + (nrows-raw_read_size[0])*raw_read_size[1]*type_size); - - - - - /* Get the meta data */ if (NULL==(meta=H5MM_malloc(nrows*sizeof(H5R_meta_t)))) { HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, @@ -1065,11 +1094,84 @@ H5R_read(H5R_t *ra, hssize_t start_row, hsize_t nrows, H5T_t *type, HDmemset(meta+meta_read_size, 0, (nrows-meta_read_size)*sizeof(H5R_meta_t)); + /* Copy data into output buffers */ + for (i=0; i<nrows; i++) { + /* + * If the caller didn't supply a buffer then allocate a buffer large + * enough to hold the entire row. Ignore the input value for the + * size and request the entire row. + */ + if (NULL==(buf_out[i]=buf[i])) { + if (meta[i].nelmts>0 && + NULL==(buf_out[i]=H5MM_malloc(meta[i].nelmts*type_size))) { + HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, + "memory allocation failed for result"); + } + size[i] = meta[i].nelmts; + } else { + size[i] = MIN(size[i], meta[i].nelmts); + } + if (0==size[i]) continue; + + /* Copy the part of the row from the raw dataset */ + HDmemcpy(buf_out[i], raw_buf+i*raw_read_size[1]*type_size, + MIN(size[i], raw_read_size[1])*type_size); + + /* Copy the part of the row from the overflow dataset */ + if (size[i]>raw_read_size[1]) { + if (!of_space && NULL==(of_space=H5D_get_space(ra->over))) { + HGOTO_ERROR(H5E_RAGGED, H5E_CANTINIT, FAIL, + "unable to get overflow extents"); + } + hs_size[0] = size[i]-raw_read_size[1]; + if (NULL==(om_space=H5S_create(H5S_SIMPLE)) || + H5S_set_extent_simple(om_space, 1, size+i, NULL)<0 || + H5S_select_hyperslab(om_space, H5S_SELECT_SET, + (hssize_t*)(raw_read_size+1), NULL, + hs_size, NULL)<0 || + H5S_select_hyperslab(of_space, H5S_SELECT_SET, + &(meta[i].offset), NULL, hs_size, + NULL)<0) { + HGOTO_ERROR(H5E_RAGGED, H5E_CANTINIT, FAIL, + "unable to set overflow selection"); + } + if (H5D_read(ra->over, type, om_space, of_space, &H5D_xfer_dflt, + buf_out[i])<0) { + HGOTO_ERROR(H5E_RAGGED, H5E_CANTINIT, FAIL, + "unable to read overflow dataset"); + } + if (H5S_close(om_space)<0) { + om_space = NULL; + HGOTO_ERROR(H5E_RAGGED, H5E_CANTINIT, FAIL, + "unable to close overflow memory space"); + } + om_space = NULL; + } + + /* Actual row size */ + size[i] = meta[i].nelmts; + } - HGOTO_ERROR(H5E_RAGGED, H5E_UNSUPPORTED, FAIL, - "not implemented yet"); + /* Copy output buffers into BUF argument */ + for (i=0; i<nrows; i++) buf[i] = buf_out[i]; + ret_value = SUCCEED; done: + if (rf_space) H5S_close(rf_space); + if (rm_space) H5S_close(rm_space); + if (mf_space) H5S_close(mf_space); + if (mm_space) H5S_close(mm_space); + if (of_space) H5S_close(of_space); + if (om_space) H5S_close(om_space); + H5MM_xfree(meta); + H5MM_xfree(raw_buf); + if (buf_out) { + for (i=0; i<nrows; i++) { + if (!buf[i]) H5MM_xfree(buf_out[i]); + } + H5MM_xfree(buf_out); + } + FUNC_LEAVE(ret_value); } |