diff options
author | Scot Breitenfeld <brtnfld@hdfgroup.org> | 2009-07-15 15:38:38 (GMT) |
---|---|---|
committer | Scot Breitenfeld <brtnfld@hdfgroup.org> | 2009-07-15 15:38:38 (GMT) |
commit | 8f7c95a7900771c1c9b49c482b9bd9b37b5482e6 (patch) | |
tree | 3c61e3b665138d1eb3267704d31aec0cc25e82d9 /hl/test | |
parent | cc3b1531c5b6b774dfb84aaa484d3f9979c3627b (diff) | |
download | hdf5-8f7c95a7900771c1c9b49c482b9bd9b37b5482e6.zip hdf5-8f7c95a7900771c1c9b49c482b9bd9b37b5482e6.tar.gz hdf5-8f7c95a7900771c1c9b49c482b9bd9b37b5482e6.tar.bz2 |
[svn-r17188] Description:
Fixed the implementation of H5LRcreate_regref_to_all so that it does as specified in RFC.
Tested (smirom: icc, gcc, pgcc), (linew)
Diffstat (limited to 'hl/test')
-rw-r--r-- | hl/test/test_regref_hyper.c | 221 |
1 files changed, 141 insertions, 80 deletions
diff --git a/hl/test/test_regref_hyper.c b/hl/test/test_regref_hyper.c index 18b61f3..94ba5c7 100644 --- a/hl/test/test_regref_hyper.c +++ b/hl/test/test_regref_hyper.c @@ -26,94 +26,143 @@ #define dsetnamev "DS2" #define dsetnamer "R1" -static size_t start_counter; /* starting index counter for placing data into 1D array, used by H5LRcreate_regref_to_all */ +/* used by H5Lvisit_by_name */ +static size_t _regref_to_all_start; /* starting index counter for placing data into 1D array, used by H5LRcreate_regref_to_all */ +static H5R_type_t _regref_type; /* type of data to create region references for */ + /************************************************************ Operator function: - (1) Sums the number of elements in each region reference - if operator_data is NULL. - (2) Reads the data from the region references into a - 1D array (operator_data). + (1) Compares the number of elements in the region references + to that of the dataset (operator_data). ************************************************************/ -static herr_t op_func (hid_t loc_id, const char *name, const H5O_info_t *info, - int *operator_data) + +static herr_t +op_func (hid_t loc_id, const char *name, const H5O_info_t *info, void *operator_data) { herr_t status; - hid_t dtype_id, dtype, native_type, space_id,space_id_ref; - int rank, ndim; - hsize_t *dims; - hsize_t i; - int j; - hdset_reg_ref_t *ref_out; - size_t size_loc; - int *data_loc; - /* - * Check if the current object is a region reference. - */ - size_loc = 0; - if(info->type == H5O_TYPE_DATASET) { - dtype_id = H5Dopen2(loc_id, name, H5P_DEFAULT); - if(dtype_id < 0) goto out; - dtype = H5Dget_type(dtype_id); - if(dtype < 0) goto out; - native_type = H5Tget_native_type(dtype, H5T_DIR_DEFAULT); - if(native_type < 0) goto out; - /* check if object is a region reference */ - if(H5Tget_class(native_type) == H5T_REFERENCE){ - - space_id = H5Dget_space(dtype_id); - if(space_id < 0) goto out; - rank = H5Sget_simple_extent_ndims(space_id); - if(rank < 0) goto out; - - dims = (hsize_t *)malloc (sizeof (hsize_t) * rank); - if(dims == NULL) goto out; - - ndim = H5Sget_simple_extent_dims(space_id, dims, NULL); - if(ndim < 0) goto out; - - ref_out = (hdset_reg_ref_t*)malloc (sizeof (hdset_reg_ref_t) * dims[0]); - if(ref_out == NULL) goto out; - - /* loop through the region references */ - for (i=0; i<ndim; i++){ - status = H5Dread(dtype_id, H5T_STD_REF_DSETREG, H5S_ALL, H5S_ALL, - H5P_DEFAULT, ref_out); - if(status != 0) goto out; - } - size_loc = 0; - for (i=0; i<dims[0]; i++){ - - space_id_ref = H5Rget_region(dtype_id, H5R_DATASET_REGION, ref_out[i]); - size_loc = (size_t)H5Sget_select_npoints(space_id_ref); - data_loc = (int*)malloc (sizeof (int) * size_loc); - status = H5LRread_region(dtype_id, ref_out[i], H5T_NATIVE_INT, &size_loc, data_loc); - if(status != 0) goto out; - - for (j=start_counter;j<size_loc;j++){ - if(operator_data[j+start_counter]!=data_loc[j]) goto out; + hid_t dtype_id=-1, sid=-1; + hid_t dtype_id2; + hid_t sid2; + hssize_t npoints, npoints_ref; + hsize_t coord[1][1]; + hdset_reg_ref_t reg_out[1]; + hobj_ref_t obj_out[1]; + hid_t dataspace_id_reg; + hsize_t dims[1]; /* array of the size of source dimension, reading into 1D array */ + hid_t mem_space = -1; + hsize_t dims_out[1]; + ssize_t i; + char buf[100];; + char name2[100]; + if(_regref_type == H5R_DATASET_REGION) { + + if(info->type == H5O_TYPE_DATASET) { + + /* Open the dataset for a given path */ + if( ( dtype_id = H5Dopen2(loc_id, name, H5P_DEFAULT) ) < 0) goto out; + + /* Get the dataspace of the dataset */ + if( ( sid = H5Dget_space(dtype_id) ) < 0) goto out; + + /* Select the entire extent of the dataspace */ + if( H5Sselect_all( sid ) < 0 ) goto out; + + npoints = H5Sget_simple_extent_npoints(sid); + + if(H5Dclose(dtype_id) != 0) goto out; + dtype_id = -1; + if(H5Sclose(sid) != 0) goto out; + sid = -1; + + /* Open the dataset for a given path */ + if( ( dtype_id2 = H5Dopen2(loc_id, "/RegRef", H5P_DEFAULT) ) < 0) goto out; + + /* Get the dataspace of the dataset */ + if( ( sid2 = H5Dget_space(dtype_id2) ) < 0) goto out; + + /* get the extent of the region reference array */ + if( (H5Sget_simple_extent_dims(sid2, dims_out, NULL ) )<1) goto out; + /* only inquire the region references that were created (i.e. not /RegRef itself) */ + if( _regref_to_all_start < dims_out[0] ) { + coord[0][0] = _regref_to_all_start; + status = H5Sselect_elements(sid2, H5S_SELECT_SET, 1, &coord[0][0] ); + if(status !=0) goto out; + + /* read the region reference */ + dims[0] = 1; + mem_space = H5Screate_simple (1, dims, NULL); + status = H5Dread(dtype_id2, H5T_STD_REF_DSETREG, mem_space, sid2, H5P_DEFAULT, reg_out); + if(status !=0) goto out; + + dataspace_id_reg = H5Rget_region( dtype_id2, H5R_DATASET_REGION, reg_out ); + + npoints_ref = H5Sget_simple_extent_npoints(dataspace_id_reg); + + if((int)npoints != (int)npoints_ref) { + printf(" ERROR: incorrect number of elements referenced for region references\n"); + goto out; } - start_counter += size_loc; + + H5Dclose(dtype_id2); + H5Sclose(sid2); + + _regref_to_all_start += 1; } - free(dims); - free(ref_out); - } - status = H5Dclose(dtype_id); - if(status != 0) goto out; - status = H5Tclose(native_type); - if(status != 0) goto out; + } /* if dataset */ + } else if(_regref_type == H5R_OBJECT) { + + /* Open the dataset for a given path */ + if( ( dtype_id2 = H5Dopen2(loc_id, "/ObjRef", H5P_DEFAULT) ) < 0) goto out; + + /* Get the dataspace of the dataset */ + if( ( sid2 = H5Dget_space(dtype_id2) ) < 0) goto out; + + /* get the extent of the region reference array */ + if( (H5Sget_simple_extent_dims(sid2, dims_out, NULL ) )<1) goto out; + /* only enquire the objects references that were created (i.e. not /ObjRef itself) */ + if( _regref_to_all_start < dims_out[0] && !(HDstrcmp(name, "ObjRef")==0) ) { + coord[0][0] = _regref_to_all_start; + status = H5Sselect_elements(sid2, H5S_SELECT_SET, 1, &coord[0][0] ); + if(status !=0) goto out; + + /* read the region reference */ + + dims[0] = 1; + mem_space = H5Screate_simple (1, dims, NULL); + status = H5Dread(dtype_id2, H5T_STD_REF_OBJ, mem_space, sid2, H5P_DEFAULT, obj_out); + if(status !=0) goto out; + + *buf = '\0'; + i = H5Rget_name(dtype_id2, H5R_OBJECT, &obj_out[0], (char*)buf, sizeof(buf)); + + sprintf(name2, "/%s", name); + + if(!((HDstrcmp(buf, name2) == 0) )) goto out; + _regref_to_all_start += 1; + + } /* if object */ + H5Dclose(dtype_id2); + H5Sclose(sid2); } return 0; -out: + + out: + if(dtype_id > 0) + H5Dclose(dtype_id); + if(sid > 0) + H5Sclose(sid); + return -2; } + static herr_t op_func_L (hid_t loc_id, const char *name, const H5L_info_t *info, - int *operator_data) + void *operator_data) { herr_t status; H5O_info_t infobuf; @@ -148,7 +197,6 @@ static int test_regref_hyper( void ) hsize_t dims3D[3] = {9,8,6}; herr_t status; hdset_reg_ref_t ref[4]; - int data_read_1D[37]; int data[9][8], data_read_2D[9][8]; int data1D[9]; int data3D[9][8][6]; @@ -684,7 +732,7 @@ static int test_regref_hyper( void ) status = H5LRcreate_region_references(file_id, num_elem, - path, + (const char **)path, block_coord_6, ref6); if(status < 0) goto out; @@ -731,21 +779,34 @@ static int test_regref_hyper( void ) *------------------------------------------------------------------------- */ - TESTING("H5LRcreate_regref_to_all"); - start_counter = 0; - status = H5LRcreate_regref_to_all(file_id, "/", - "/Group_2D/DS2c", H5_INDEX_NAME, H5_ITER_INC); + TESTING("H5LRcreate_regref_to_all Region Reference Datatset"); + status = H5LRcreate_regref_to_all(file_id, "/","/RegRef", H5_INDEX_NAME, H5_ITER_INC, H5R_DATASET_REGION); if(status < 0) goto out; - status = H5LTread_dataset(file_id,"/Group_2D/DS2c",H5T_NATIVE_INT,data_read_1D); + /* check results */ + _regref_to_all_start=0; + _regref_type = H5R_DATASET_REGION; - if(status<0) goto out; + status = H5Lvisit_by_name(file_id, "/", H5_INDEX_NAME, H5_ITER_INC, op_func_L, NULL, H5P_DEFAULT ); - status = H5Lvisit_by_name(file_id, "/", H5_INDEX_NAME, H5_ITER_INC, op_func_L, data_read_1D, H5P_DEFAULT ); + if(status < 0) goto out; + + PASSED(); + + TESTING("H5LRcreate_regref_to_all Region Reference Object"); + status = H5LRcreate_regref_to_all(file_id, "/","/ObjRef", H5_INDEX_NAME, H5_ITER_INC, H5R_OBJECT); + + if(status < 0) goto out; + + /* check results */ + _regref_to_all_start=0; + _regref_type = H5R_OBJECT; + + status = H5Lvisit_by_name(file_id, "/", H5_INDEX_NAME, H5_ITER_INC, op_func_L, NULL, H5P_DEFAULT ); + if(status < 0) goto out; PASSED(); - return 0; out: |