summaryrefslogtreecommitdiffstats
path: root/hl/src/H5LT.c
diff options
context:
space:
mode:
Diffstat (limited to 'hl/src/H5LT.c')
-rw-r--r--hl/src/H5LT.c468
1 files changed, 213 insertions, 255 deletions
diff --git a/hl/src/H5LT.c b/hl/src/H5LT.c
index 5e158a4..ae110cc 100644
--- a/hl/src/H5LT.c
+++ b/hl/src/H5LT.c
@@ -3012,25 +3012,22 @@ H5LTread_region(const char *file,
hid_t mem_type,
void *buf ) )
- herr_t status;
- hsize_t *dims1;
- hid_t file_id;
- hid_t dset_id;
- hid_t sid1;
- hid_t sid2;
- int ndim;
- int i;
- hsize_t *start, *count;
- hbool_t dims1_alloc = FALSE;
- hbool_t start_alloc = FALSE;
- hbool_t count_alloc = FALSE;
- hid_t current_stack_id = -1;
+ herr_t status; /* API return status */
+ hid_t file_id; /* file identifier for the open file */
+ hid_t dset_id; /* dataset identifier */
+ hid_t file_space_id; /* identifier of the dataset's dataspace in the file */
+ hid_t mem_space_id; /* identifier of the memory dataspace */
+ int ndim; /* the dimensionality of a dataspace */
+ hsize_t *dims; /* an array of the size of each dimension */
+ int i; /* counter */
+ hid_t current_stack_id = -1; /* current error stack id */
+ /* flags marking state of allocation */
+ hbool_t dims_alloc = FALSE;
/* Open the file */
file_id = H5Fopen(file, H5F_ACC_RDONLY, H5P_DEFAULT);
- if(file_id < 0) {
+ if(file_id < 0)
H5E_THROW(H5E_CANTOPENFILE, "H5LT: Failed to open file")
- }
/* Open the dataset for a given the path */
dset_id = H5Dopen2(file_id, path, H5P_DEFAULT);
@@ -3038,54 +3035,39 @@ H5LTread_region(const char *file,
H5E_THROW(H5E_CANTOPENOBJ, "H5LT: Failed to open dataset")
/* Get the dataspace of the dataset */
- sid1 = H5Dget_space(dset_id);
- if(sid1 < 0)
+ file_space_id = H5Dget_space(dset_id);
+ if(file_space_id < 0)
H5E_THROW(H5E_CANTOPENOBJ, "H5LT: Failed to open dataspace")
/* Find the rank of the dataspace */
- ndim = H5Sget_simple_extent_ndims(sid1);
+ ndim = H5Sget_simple_extent_ndims(file_space_id);
if(ndim < 0)
H5E_THROW(H5E_NOTFOUND, "H5LT: Failed to find extents of dataspace")
/* Allocate space for the dimension array */
- dims1 = (hsize_t *)malloc (sizeof (hsize_t) * ndim);
- if(dims1 == NULL)
+ dims = (hsize_t *)malloc (sizeof (hsize_t) * ndim);
+ if(dims == NULL)
H5E_THROW(H5E_CANTALLOC, "H5LT: Failed to allocate enough memory")
- dims1_alloc = TRUE;
+ dims_alloc = TRUE;
- /* find the dimensions of each data space from the block coordinates */
+ /* Find the dimensions of each data space from the block coordinates */
for (i=0; i<ndim; i++)
- dims1[i] = block_coord[i+ndim] - block_coord[i] + 1;
+ dims[i] = block_coord[i+ndim] - block_coord[i] + 1;
/* Create dataspace for reading buffer */
- sid2 = H5Screate_simple(ndim, dims1, NULL);
- if(sid2 < 0)
+ mem_space_id = H5Screate_simple(ndim, dims, NULL);
+ if(mem_space_id < 0)
H5E_THROW(H5E_CANTCREATE, "H5LT: Failed to create dataspace for retrieving elements")
-
/* Select (x , x , ..., x ) x (y , y , ..., y ) hyperslab for reading memory dataset */
/* 1 2 n 1 2 n */
- start = (hsize_t *)malloc (sizeof (hsize_t) * ndim);
- if(start == NULL)
- H5E_THROW(H5E_CANTALLOC, "H5LT: Failed to allocate enough memory")
- start_alloc = TRUE;
-
- count = (hsize_t *)malloc (sizeof (hsize_t) * ndim);
- if(count == NULL)
- H5E_THROW(H5E_CANTALLOC, "H5LT: Failed to allocate enough memory")
- count_alloc = TRUE;
-
- for (i=0; i<ndim; i++) {
- start[i] = block_coord[i];
- count[i] = dims1[i];
- }
-
- status = H5Sselect_hyperslab(sid1,H5S_SELECT_SET,start,NULL,count,NULL);
+ status = H5Sselect_hyperslab(file_space_id,H5S_SELECT_SET, block_coord, NULL, dims,NULL);
if(status < 0)
H5E_THROW(H5E_CANTSELECT, "H5LT: Failed to select hyperslab")
- status = H5Dread(dset_id, mem_type, sid2, sid1, H5P_DEFAULT, buf);
+ /* Read data from dataset into the buffer */
+ status = H5Dread(dset_id, mem_type, mem_space_id, file_space_id, H5P_DEFAULT, buf);
if(status < 0)
H5E_THROW(H5E_READERROR, "H5LT: Unable to retrieve elements")
@@ -3099,21 +3081,23 @@ H5LTread_region(const char *file,
H5E_THROW(H5E_CLOSEERROR, "H5LT: Failed to close dataset")
}
}
- /* Close the dataspaces */
- if(sid1 > 0) {
- status = H5Sclose(sid1);
- sid1 = -1;
+ /* Close the file space */
+ if(file_space_id > 0) {
+ status = H5Sclose(file_space_id);
+ file_space_id = -1;
if(status < 0) {
H5E_THROW(H5E_CLOSEERROR, "H5LR: Failed to close dataspace")
}
}
- if(sid2 > 0) {
- status = H5Sclose(sid2);
- sid2 = -1;
+ /* Close the memory space */
+ if(mem_space_id > 0) {
+ status = H5Sclose(mem_space_id);
+ mem_space_id = -1;
if(status < 0) {
H5E_THROW(H5E_CLOSEERROR, "H5LR: Failed to close dataspace")
}
}
+ /* Close the file */
if(file_id > 0) {
status = H5Fclose(file_id);
file_id = -1;
@@ -3122,35 +3106,30 @@ H5LTread_region(const char *file,
}
}
- free(dims1);
- dims1_alloc = FALSE;
- free(start);
- start_alloc = FALSE;
- free(count);
- count_alloc = FALSE;
+ /* deallocate arrays */
+ free(dims);
+ dims_alloc = FALSE;
- CATCH
+CATCH
- current_stack_id = H5Eget_current_stack();
+ current_stack_id = H5Eget_current_stack();
- if(dims1_alloc) free(dims1);
- if(start_alloc) free(start);
- if(count_alloc) free(count);
+ if(dims_alloc) free(dims);
- /* Close the dataspace */
- if(sid1 > 0)
- status = H5Sclose(sid1);
- if(sid2 > 0)
- status = H5Sclose(sid2);
+ /* Close the dataspaces */
+ if(file_space_id > 0)
+ status = H5Sclose(file_space_id);
+ if(mem_space_id > 0)
+ status = H5Sclose(mem_space_id);
- /* Close the dataset */
- if(dset_id > 0)
- status = H5Dclose(dset_id);
- /* Close the file */
- if(file_id > 0)
- status = H5Fclose(file_id);
+ /* Close the dataset */
+ if(dset_id > 0)
+ status = H5Dclose(dset_id);
+ /* Close the file */
+ if(file_id > 0)
+ status = H5Fclose(file_id);
- status = H5Eset_current_stack(current_stack_id);
+ status = H5Eset_current_stack(current_stack_id);
END_FUNC(PUB)
@@ -3175,44 +3154,44 @@ END_FUNC(PUB)
BEGIN_FUNC(PUB, ERR,
herr_t, SUCCEED, FAIL,
-H5LTcopy_region(const char *file_src,
+H5LTcopy_region(const char *file_src,
const char *path_src,
const hsize_t *block_coord_src,
const char *file_dest,
const char *path_dest,
const hsize_t *block_coord_dset) )
- herr_t status;
- hsize_t *dims1, *dims_src;
- hid_t sid1;
- hid_t sid2;
- hid_t fid_src, type_id, file_id;
- hid_t did_src, sid_src,dset_id;
- int ndim;
- void *buf;
- hsize_t numelem_src;
- int nrank_src;
- int i, j;
- hsize_t *start, *count;
- hid_t dtype;
+ herr_t status; /* API return status */
+ hsize_t *dims, *dims_src; /* array of the size of each destination, source dimension */
+ hid_t file_space_id; /* identifier of the dataset's dataspace in the file */
+ hid_t mem_space_id; /* identifier of the memory dataspace */
+ hid_t dset_id, type_id, file_id; /* Destination: dataset, dataspace, file ids */
+ hid_t did_src, sid_src, fid_src; /* Source: dataset, dataspace, file ids */
+ int ndim; /* the dimensionality of a dataspace */
+ void *buf; /* buffer to hold data */
+ hsize_t numelem_src; /* total number of elements in hyperslab */
+ int nrank_src; /* the dimensionality of the source dataspace */
+ int i, j; /* counters */
+ hsize_t *stride; /* hyperslab stride */
+ hid_t dtype; /* data type of source */
+ hid_t current_stack_id = -1; /* current error stack id */
+/* flags marking state of allocation */
hbool_t dims_src_alloc = FALSE;
- hbool_t dims1_alloc = FALSE;
- hbool_t buf_alloc = FALSE;
- hbool_t start_alloc = FALSE;
- hbool_t count_alloc = FALSE;
- hid_t current_stack_id = -1;
+ hbool_t dims_alloc = FALSE;
+ hbool_t buf_alloc = FALSE;
+ hbool_t stride_alloc = FALSE;
- /* Open the file */
+ /* Open the source file */
fid_src = H5Fopen(file_src, H5F_ACC_RDONLY, H5P_DEFAULT);
if(fid_src < 0)
H5E_THROW(H5E_CANTOPENFILE, "H5LT: Failed to open file")
- /* Open the dataset for a given the path */
+ /* Open the dataset for a given the source path */
did_src = H5Dopen2(fid_src, path_src, H5P_DEFAULT);
if(did_src < 0)
H5E_THROW(H5E_CANTOPENOBJ, "H5LT: Failed to open dataset for the given path")
- /* Get the dataspace of the dataset */
+ /* Get the source dataspace of the dataset */
sid_src = H5Dget_space(did_src);
if(sid_src < 0)
H5E_THROW(H5E_CANTOPENOBJ, "H5LT: Failed to open dataspace")
@@ -3228,60 +3207,45 @@ H5LTcopy_region(const char *file_src,
H5E_THROW(H5E_CANTALLOC, "H5LT: Failed to allocate enough memory")
dims_src_alloc = TRUE;
-/* bounds_coor = (hsize_t *)malloc (sizeof (hsize_t) * nrank * 2); */
-/* status = H5Sget_select_hyper_blocklist(sid_ref, 0, 1, bounds_coor); */
-
numelem_src = 1;
for (j=0; j<nrank_src; j++) {
dims_src[j] = block_coord_src[nrank_src + j] - block_coord_src[j] + 1;
numelem_src = dims_src[j]*numelem_src;
}
+ /* datatype of source dataspace */
dtype = H5Dget_type(did_src);
if(dtype < 0)
H5E_THROW(H5E_CANTGET, "H5LT: Failed to find the data type")
-
+ /* native datatype of source dataspace */
type_id = H5Tget_native_type(dtype , H5T_DIR_DEFAULT );
if(type_id < 0)
H5E_THROW(H5E_CANTGET, "H5LT: Failed to find the native data type")
-
+
buf = malloc(sizeof(type_id) * numelem_src);
if(buf == NULL)
H5E_THROW(H5E_CANTALLOC, "H5LT: Failed to allocate enough memory")
buf_alloc = TRUE;
/* Create dataspace for reading buffer */
- sid2 = H5Screate_simple(nrank_src, dims_src, NULL);
- if(sid2 < 0)
+ mem_space_id = H5Screate_simple(nrank_src, dims_src, NULL);
+ if(mem_space_id < 0)
H5E_THROW(H5E_CANTCREATE, "H5LT: Unable to create dataspace for retrieving elements")
/* Select (x , x , ..., x ) x (y , y , ..., y ) hyperslab for reading memory dataset */
/* 1 2 n 1 2 n */
- start = (hsize_t *)malloc (sizeof (hsize_t) * nrank_src);
- if(start == NULL)
- H5E_THROW(H5E_CANTALLOC, "H5LR: Failed to allocate enough memory")
- start_alloc = TRUE;
-
- count = (hsize_t *)malloc (sizeof (hsize_t) * nrank_src);
- if(count == NULL)
- H5E_THROW(H5E_CANTALLOC, "H5LR: Failed to allocate enough memory")
- count_alloc = TRUE;
-
- for (i=0; i<nrank_src; i++) {
- start[i] = block_coord_src[i];
- count[i] = dims_src[i];
- }
-
- status = H5Sselect_hyperslab(sid_src,H5S_SELECT_SET,start,NULL,count,NULL);
+ status = H5Sselect_hyperslab(sid_src,H5S_SELECT_SET,block_coord_src,NULL,dims_src,NULL);
if(status < 0)
H5E_THROW(H5E_CANTSELECT, "H5LT: Failed to select hyperslab")
- status = H5Dread(did_src, type_id, sid2, sid_src, H5P_DEFAULT, buf);
+
+ /* Read data from dataset into the buffer */
+ status = H5Dread(did_src, type_id, mem_space_id, sid_src, H5P_DEFAULT, buf);
if(status < 0)
H5E_THROW(H5E_READERROR, "H5LT: Unable to retrieve elements in hyperslab")
-
+ /* Close the dataset */
if(did_src > 0) {
status = H5Dclose(did_src);
did_src = -1;
@@ -3289,6 +3253,7 @@ H5LTcopy_region(const char *file_src,
H5E_THROW(H5E_CLOSEERROR, "H5LT: Failed to close dataset")
}
}
+ /* Close the dataspaces */
if(sid_src > 0) {
status = H5Sclose(sid_src);
sid_src = -1;
@@ -3296,13 +3261,14 @@ H5LTcopy_region(const char *file_src,
H5E_THROW(H5E_CLOSEERROR, "H5LT: Failed to close dataspace")
}
}
- if(sid2 > 0) {
- status = H5Sclose(sid2);
- sid2 = -1;
+ if(mem_space_id > 0) {
+ status = H5Sclose(mem_space_id);
+ mem_space_id = -1;
if(status < 0) {
H5E_THROW(H5E_CLOSEERROR, "H5LT: Failed to close dataspace")
}
}
+ /* Close the source file */
if(fid_src > 0) {
status = H5Fclose(fid_src);
fid_src = -1;
@@ -3311,13 +3277,9 @@ H5LTcopy_region(const char *file_src,
}
}
free(dims_src);
- free(start);
- free(count);
dims_src_alloc = FALSE;
- start_alloc = FALSE;
- count_alloc = FALSE;
-/* Open the file */
+/* Open the destination file */
file_id = H5Fopen(file_dest, H5F_ACC_RDWR, H5P_DEFAULT);
if(file_id < 0)
H5E_THROW(H5E_CANTOPENFILE, "H5LT: Failed to open file")
@@ -3328,142 +3290,133 @@ H5LTcopy_region(const char *file_src,
H5E_THROW(H5E_CANTOPENOBJ, "H5LT: Failed to open dataset")
/* Get the dataspace of the dataset */
- sid1 = H5Dget_space(dset_id);
- if(sid1 < 0)
+ file_space_id = H5Dget_space(dset_id);
+ if(file_space_id < 0)
H5E_THROW(H5E_CANTOPENOBJ, "H5LT: Failed to open dataspace for given path")
/* Find the rank of the dataspace */
- ndim = H5Sget_simple_extent_ndims(sid1);
+ ndim = H5Sget_simple_extent_ndims(file_space_id);
if(ndim < 0)
H5E_THROW(H5E_NOTFOUND, "H5LT: Failed to find extents of dataspace")
/* Allocate space for the dimension array */
- dims1 = (hsize_t *)malloc (sizeof (hsize_t) * ndim);
- if(dims1 == NULL)
+ dims = (hsize_t *)malloc (sizeof (hsize_t) * ndim);
+ if(dims == NULL)
H5E_THROW(H5E_CANTALLOC, "H5LT: Failed to allocate enough memory")
- dims1_alloc = TRUE;
+ dims_alloc = TRUE;
/* find the dimensions of each data space from the block coordinates */
for (i=0; i<ndim; i++)
- dims1[i] = block_coord_dset[i+ndim] - block_coord_dset[i] + 1;
+ dims[i] = block_coord_dset[i+ndim] - block_coord_dset[i] + 1;
/* Create dataspace for writing the buffer */
- sid2 = H5Screate_simple(ndim, dims1, NULL);
- if(sid2 < 0)
+ mem_space_id = H5Screate_simple(ndim, dims, NULL);
+ if(mem_space_id < 0)
H5E_THROW(H5E_CANTCREATE, "H5LT: Unable to create dataspace for retrieving elements")
/* Select (x , x , ..., x ) x (y , y , ..., y ) hyperslab for writing memory dataset */
/* 1 2 n 1 2 n */
- start = (hsize_t *)malloc (sizeof (hsize_t) * ndim);
- if(start == NULL)
- H5E_THROW(H5E_CANTALLOC, "H5LT: Failed to allocate enough memory")
- start_alloc = TRUE;
-
- count = (hsize_t *)malloc (sizeof (hsize_t) * ndim);
- if(count == NULL)
+ stride = (hsize_t *)malloc (sizeof (hsize_t) * ndim);
+ if(stride == NULL)
H5E_THROW(H5E_CANTALLOC, "H5LT: Failed to allocate enough memory")
- count_alloc = TRUE;
+ stride_alloc = TRUE;
- for (i=0; i<ndim; i++) {
- start[i] = block_coord_dset[i];
- count[i] = block_coord_dset[i + ndim] - start[i] + 1;
- }
+ for (i=0; i<ndim; i++)
+ stride[i] = block_coord_dset[i + ndim] - block_coord_dset[i] + 1;
- status = H5Sselect_hyperslab(sid1,H5S_SELECT_SET,start,NULL,count,NULL);
+ status = H5Sselect_hyperslab(file_space_id,H5S_SELECT_SET, block_coord_dset,NULL,stride,NULL);
if(status < 0)
H5E_THROW(H5E_CANTSELECT, "H5LT: Failed to select hyperslab")
- status = H5Dwrite(dset_id, type_id, sid2, sid1, H5P_DEFAULT, buf);
+ status = H5Dwrite(dset_id, type_id, mem_space_id, file_space_id, H5P_DEFAULT, buf);
if(status < 0)
H5E_THROW(H5E_CANTCREATE, "H5LT: Unable to create dataset")
-/* CLOSE THE DATA */
- /* Close the dataset */
- if(dset_id > 0) {
- status = H5Dclose(dset_id);
- dset_id = -1;
- if(status < 0) {
- H5E_THROW(H5E_CLOSEERROR, "H5LT: Failed to close dataset")
- }
- }
- /* Close the dataspace */
- if(sid1 > 0) {
- status = H5Sclose(sid1);
- sid1 = -1;
- if(status < 0) {
- H5E_THROW(H5E_CLOSEERROR, "H5LT: Failed to close dataspace")
- }
- }
-
- /* Close the dataspace */
- if(sid2 > 0) {
- status = H5Sclose(sid2);
- sid2 = -1;
- if(status < 0) {
- H5E_THROW(H5E_CLOSEERROR, "H5LT: Failed to close dataspace")
- }
- }
+ /* CLOSE THE DATA */
+
+ /* Close the dataset */
+ if(dset_id > 0) {
+ status = H5Dclose(dset_id);
+ dset_id = -1;
+ if(status < 0) {
+ H5E_THROW(H5E_CLOSEERROR, "H5LT: Failed to close dataset")
+ }
+ }
+ /* Close the dataspaces */
+ if(file_space_id > 0) {
+ status = H5Sclose(file_space_id);
+ file_space_id = -1;
+ if(status < 0) {
+ H5E_THROW(H5E_CLOSEERROR, "H5LT: Failed to close dataspace")
+ }
+ }
+ if(mem_space_id > 0) {
+ status = H5Sclose(mem_space_id);
+ mem_space_id = -1;
+ if(status < 0) {
+ H5E_THROW(H5E_CLOSEERROR, "H5LT: Failed to close dataspace")
+ }
+ }
+ /* Close datatypes */
if(type_id > 0) {
status = H5Tclose(type_id);
type_id = -1;
if(status < 0) {
H5E_THROW(H5E_CLOSEERROR, "H5LT: Failed to close datatype")
- }
+ }
}
if(dtype > 0) {
status = H5Tclose(dtype);
dtype = -1;
if(status < 0) {
H5E_THROW(H5E_CLOSEERROR, "H5LT: Failed to close datatype")
- }
+ }
}
+ /* Close the file */
if(file_id > 0) {
status = H5Fclose(file_id);
file_id = -1;
if(status < 0) {
H5E_THROW(H5E_CLOSEERROR, "H5LT: Failed to close dataset")
- }
+ }
}
- free(start);
- free(count);
+ free(stride);
free(buf);
- free(dims1);
+ free(dims);
- start_alloc = FALSE;
- count_alloc = FALSE;
+ stride_alloc = FALSE;
buf_alloc = FALSE;
- dims1_alloc = FALSE;
+ dims_alloc = FALSE;
- CATCH
+CATCH
- current_stack_id = H5Eget_current_stack();
+ current_stack_id = H5Eget_current_stack();
- if(dims1_alloc) free(dims1);
- if(buf_alloc) free(buf);
- if(start_alloc) free(start);
- if(count_alloc) free(count);
- if(dims_src_alloc) free(dims_src);
+ if(dims_alloc) free(dims);
+ if(buf_alloc) free(buf);
+ if(stride_alloc) free(stride);
+ if(dims_src_alloc) free(dims_src);
- /* Close the dataspace */
- if(sid1 > 0)
- status = H5Sclose(sid1);
- if(sid2 > 0)
- status = H5Sclose(sid2);
+ /* Close the dataspace */
+ if(file_space_id > 0)
+ status = H5Sclose(file_space_id);
+ if(mem_space_id > 0)
+ status = H5Sclose(mem_space_id);
- /* Close the dataset */
- if(dset_id > 0)
- status = H5Dclose(dset_id);
- /* Close the file */
- if(file_id > 0)
- status = H5Fclose(file_id);
- /* Close the datatypes */
- if(dtype > 0)
- status = H5Tclose(dtype);
- if(type_id > 0)
- status = H5Tclose(type_id);
-
- status = H5Eset_current_stack(current_stack_id);
+ /* Close the dataset */
+ if(dset_id > 0)
+ status = H5Dclose(dset_id);
+ /* Close the file */
+ if(file_id > 0)
+ status = H5Fclose(file_id);
+ /* Close the datatypes */
+ if(dtype > 0)
+ status = H5Tclose(dtype);
+ if(type_id > 0)
+ status = H5Tclose(type_id);
+
+ status = H5Eset_current_stack(current_stack_id);
END_FUNC(PUB)
@@ -3488,16 +3441,17 @@ END_FUNC(PUB)
BEGIN_FUNC(PUB, ERR,
herr_t, SUCCEED, FAIL,
H5LTread_bitfield_value(hid_t dset_id, int num_values, const unsigned *offset,
- const unsigned *lengths, hid_t *space, hid_t *dtype, int *buf) )
-
- herr_t status;
- H5S_sel_type sel_type;
- hid_t space_id = -1, mem_space = -1;
- hsize_t dims1[1];
- int i, j, icnt;
- unsigned char *buf2;
- hbool_t buf2_alloc = FALSE;
- hid_t current_stack_id = -1;
+ const unsigned *lengths, hid_t *space, int *buf) )
+
+ herr_t status; /* API return status */
+ H5S_sel_type sel_type; /* type selection */
+ hid_t space_id = -1, mem_space = -1; /* dataspace ids */
+ hsize_t dims[1]; /* array of the size of source dimension, reading into 1D array */
+ int i, j, icnt; /* counters */
+ unsigned char *buf_src; /* buffer to read data into from source */
+ hid_t dtype; /* data type of source */
+ hid_t current_stack_id = -1; /* current error stack id */
+ hbool_t buf_src_alloc = FALSE; /* flag marking state of allocation */
/* Determine the type of the dataspace selection */
space_id = H5Dget_space (dset_id);
@@ -3508,55 +3462,60 @@ H5LTread_bitfield_value(hid_t dset_id, int num_values, const unsigned *offset,
/* Get the number of elements */
if(sel_type==H5S_SEL_HYPERSLABS){
- dims1[0] = H5Sget_select_hyper_nblocks(space_id);
+ dims[0] = H5Sget_select_hyper_nblocks(space_id);
} else if(sel_type==H5S_SEL_POINTS){
- dims1[0] = H5Sget_select_npoints(space_id);
+ dims[0] = H5Sget_select_npoints(space_id);
} else if(sel_type==H5S_SEL_NONE){
- return ret_value;
+ goto catch_except;
} else if(sel_type==H5S_SEL_ALL){
- dims1[0] = H5Sget_select_npoints(space_id);
+ dims[0] = H5Sget_select_npoints(space_id);
} else
H5E_THROW(H5E_BADSELECT, "H5LT: Failed to find selection type")
/* Create a new simple dataspace in memory and open it for access */
- mem_space = H5Screate_simple (1, dims1, NULL);
+ mem_space = H5Screate_simple (1, dims, NULL);
if(mem_space < 0)
H5E_THROW(H5E_CANTCREATE, "H5LT: Unable to create dataspace for retrieving elements")
- buf2 = malloc(sizeof(unsigned char) * dims1[0]);
- if(buf2 == NULL){
+ buf_src = malloc(sizeof(unsigned char) * dims[0]);
+ if(buf_src == NULL)
H5E_THROW(H5E_CANTALLOC, "H5LT: Failed to allocate enough memory")
- }
- buf2_alloc = TRUE;
+ buf_src_alloc = TRUE;
+
+ dtype = H5Dget_type(dset_id);
+ if(dtype < 0)
+ H5E_THROW(H5E_CANTGET, "H5LT: Unable to determine datatype of dataset")
/* Read the region data from the file_space into the mem_space */
- status = H5Dread (dset_id, dtype, mem_space, space_id, H5P_DEFAULT, buf2);
+ status = H5Dread (dset_id, dtype, mem_space, space_id, H5P_DEFAULT, buf_src);
if(status < 0)
H5E_THROW(H5E_READERROR, "H5LT: Unable to read region data")
icnt = 0;
- for (i = 0; i<dims1[0]; i++)
+ for (i = 0; i< (int)dims[0]; i++)
for (j = 0; j<num_values; j++){
- buf[icnt] = (int*)((buf2[i] >> (offset[j]) ) & ((1 << lengths[j] ) - 1));
+ buf[icnt] = (int*)((buf_src[i] >> (offset[j]) ) & ((1 << lengths[j] ) - 1));
icnt += 1;
}
- /* Close the dataspace */
- if(space_id > 0) {
- status = H5Sclose(space_id);
- space_id = -1;
- if(status < 0) {
- H5E_THROW(H5E_CLOSEERROR, "H5LT: Failed to close dataspace")
+ /* Close the dataspace */
+ if(space_id > 0) {
+ status = H5Sclose(space_id);
+ space_id = -1;
+ if(status < 0) {
+ H5E_THROW(H5E_CLOSEERROR, "H5LT: Failed to close dataspace")
+ }
+ }
+
+ /* Close the datatype */
+ if(dtype > 0) {
+ status = H5Tclose(dtype);
+ dtype = -1;
+ if(status < 0) {
+ H5E_THROW(H5E_CLOSEERROR, "H5LT: Failed to close datatype")
}
- }
-
-/* if(sel_type > 0) { */
-/* status = H5Tclose(sel_type); */
-/* sel_type = -1; */
-/* if(status < 0) { */
-/* H5E_THROW(H5E_CLOSEERROR, "H5LT: Failed to close datatype") */
-/* } */
-/* } */
+ }
+ /* Close the memory space */
if(mem_space > 0) {
status = H5Sclose(mem_space);
mem_space = -1;
@@ -3565,23 +3524,22 @@ H5LTread_bitfield_value(hid_t dset_id, int num_values, const unsigned *offset,
}
}
- free(buf2);
- buf2_alloc = FALSE;
+ free(buf_src);
+ buf_src_alloc = FALSE;
CATCH
current_stack_id = H5Eget_current_stack();
- /* Close the dataspace */
+ /* Close */
if(mem_space > 0)
status = H5Sclose(mem_space);
if(space_id> 0)
status = H5Sclose(space_id);
- /* Close the datatypes */
-/* if(sel_type > 0) */
-/* status = H5Tclose(sel_type); */
+ if(dtype> 0)
+ status = H5Sclose(dtype);
- if(buf2_alloc) free(buf2);
+ if(buf_src_alloc) free(buf_src);
status = H5Eset_current_stack(current_stack_id);