diff options
-rw-r--r-- | release_docs/RELEASE.txt | 2 | ||||
-rw-r--r-- | src/H5Shyper.c | 10 | ||||
-rw-r--r-- | src/H5Spoint.c | 22 | ||||
-rw-r--r-- | test/tselect.c | 102 |
4 files changed, 90 insertions, 46 deletions
diff --git a/release_docs/RELEASE.txt b/release_docs/RELEASE.txt index c436711..a8e9af2 100644 --- a/release_docs/RELEASE.txt +++ b/release_docs/RELEASE.txt @@ -35,6 +35,8 @@ Bug Fixes since HDF5-1.4.2 Library ------- + * Fixed bug where selection offsets were not being used when iterating + through point and hyperslab selections with H5Diterate(). QAK - 2002/04/29 * Fixed bug where the data for several level deep nested compound & variable-length datatypes used for datasets were getting corrupted when written to the file. QAK - 2002/04/17 diff --git a/src/H5Shyper.c b/src/H5Shyper.c index b9652c0..98ffc35 100644 --- a/src/H5Shyper.c +++ b/src/H5Shyper.c @@ -5893,7 +5893,7 @@ H5S_hyper_select_iterate_mem_gen(H5S_hyper_iter_info_t *iter_info) off_arr[i]=iter->hyp.span[i]->low; /* Compute the sequential element offset */ - loc_off+=off_arr[i]*slab[i]; + loc_off+=(off_arr[i]+space->select.offset[i])*slab[i]; } /* end for */ /* Perform the I/O on the elements, based on the position of the iterator */ @@ -6008,7 +6008,7 @@ H5S_hyper_select_iterate_mem_gen(H5S_hyper_iter_info_t *iter_info) /* Reset the buffer offset */ for(i=0, loc_off=0; i<ndims; i++) - loc_off+=off_arr[i]*slab[i]; + loc_off+=(off_arr[i]+space->select.offset[i])*slab[i]; } /* end else */ } /* end while */ @@ -6102,12 +6102,12 @@ H5S_hyper_select_iterate_mem_opt(H5S_sel_iter_t UNUSED *iter, void *buf, hid_t t for(u=0; u<ndims; u++) { tmp_count[u]=diminfo[u].count; tmp_block[u]=diminfo[u].block; - offset[u]=diminfo[u].start; + offset[u]=(diminfo[u].start+space->select.offset[u]); } /* end for */ /* Initialize the starting location */ for(loc=buf,u=0; u<ndims; u++) - loc+=diminfo[u].start*slab[u]; + loc+=offset[u]*slab[u]; /* Go iterate over the hyperslabs */ while(user_ret==0) { @@ -6185,7 +6185,7 @@ H5S_hyper_select_iterate_mem_opt(H5S_sel_iter_t UNUSED *iter, void *buf, hid_t t /* Re-compute buffer location & offset array */ for(loc=buf,u=0; u<ndims; u++) { - temp_off=diminfo[u].start + temp_off=(diminfo[u].start+space->select.offset[u]) +diminfo[u].stride*(diminfo[u].count-tmp_count[u]) +(diminfo[u].block-tmp_block[u]); loc+=temp_off*slab[u]; diff --git a/src/H5Spoint.c b/src/H5Spoint.c index efe6df0..5f56ebb 100644 --- a/src/H5Spoint.c +++ b/src/H5Spoint.c @@ -1258,14 +1258,13 @@ H5S_point_select_iterate(void *buf, hid_t type_id, H5S_t *space, H5D_operator_t void *operator_data) { hsize_t mem_size[H5O_LAYOUT_NDIMS]; /* Dataspace size */ - hsize_t acc; /* Size accumulator */ + hssize_t mem_offset[H5O_LAYOUT_NDIMS]; /* Point offset */ hsize_t offset; /* Offset of region in buffer */ - hsize_t elmt_size; /* Size of datatype */ void *tmp_buf; /* Temporary location of the element in the buffer */ H5S_pnt_node_t *node; /* Point node */ unsigned rank; /* Dataspace rank */ H5T_t *dt; /* Datatype structure */ - int i; /* Index variable */ + unsigned u; /* Local index variable */ herr_t ret_value=0; /* return value */ FUNC_ENTER (H5S_point_select_iterate, 0); @@ -1284,21 +1283,24 @@ H5S_point_select_iterate(void *buf, hid_t type_id, H5S_t *space, H5D_operator_t /* Set the size of the datatype */ if (NULL==(dt=H5I_object(type_id))) HRETURN_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not an valid base datatype"); - mem_size[rank]=elmt_size=H5T_get_size(dt); + mem_size[rank]=H5T_get_size(dt); /* Iterate through the node, checking the bounds on each element */ node=space->select.sel_info.pnt_lst->head; while(node!=NULL && ret_value==0) { - /* Compute the offset of each selected point in the buffer */ - for(i=rank-1,acc=elmt_size,offset=0; i>=0; i--) { - offset+=(node->pnt[i]+space->select.offset[i])*acc; - acc*=mem_size[i]; - } /* end for */ + /* Set up the location of the point */ + HDmemcpy(mem_offset, node->pnt, rank*sizeof(hssize_t)); + mem_offset[rank]=0; + + /* Add in the selection offset */ + for(u=0; u<rank; u++) + mem_offset[u]+=space->select.offset[u]; /* Get the offset in the memory buffer */ + offset=H5V_array_offset(rank+1,mem_size,(const hssize_t *)mem_offset); tmp_buf=((char *)buf+offset); - ret_value=(*op)(tmp_buf,type_id,(hsize_t)rank,node->pnt,operator_data); + ret_value=(*op)(tmp_buf,type_id,(hsize_t)rank,mem_offset,operator_data); node=node->next; } /* end while */ diff --git a/test/tselect.c b/test/tselect.c index f439c96..4cb4495 100644 --- a/test/tselect.c +++ b/test/tselect.c @@ -79,6 +79,7 @@ #define SPACE7_RANK 2 #define SPACE7_DIM1 10 #define SPACE7_DIM2 10 +#define SPACE7_FILL 254 /* 4-D dataset with fixed dimensions */ #define SPACE8_NAME "Space8" @@ -115,7 +116,8 @@ herr_t test_select_hyper_iter1(void *elem,hid_t type_id, hsize_t ndim, hssize_t herr_t test_select_point_iter1(void *elem,hid_t type_id, hsize_t ndim, hssize_t *point, void *operator_data); herr_t test_select_all_iter1(void *elem,hid_t type_id, hsize_t ndim, hssize_t *point, void *operator_data); herr_t test_select_none_iter1(void *elem,hid_t type_id, hsize_t ndim, hssize_t *point, void *operator_data); -herr_t test_select_hyper_iter2(void *_elem, hid_t UNUSED type_id, hsize_t ndim, hssize_t *point, void *_operator_data); +herr_t test_select_hyper_iter2(void *_elem, hid_t type_id, hsize_t ndim, hssize_t *point, void *_operator_data); +herr_t test_select_hyper_iter3(void *elem,hid_t type_id, hsize_t ndim, hssize_t *point, void *operator_data); /**************************************************************** ** @@ -4412,6 +4414,24 @@ test_select_combine(void) /**************************************************************** ** +** test_select_hyper_iter3(): Iterator for checking hyperslab iteration +** +****************************************************************/ +herr_t +test_select_hyper_iter3(void *_elem,hid_t UNUSED type_id, hsize_t UNUSED ndim, hssize_t UNUSED *point, void *_operator_data) +{ + unsigned short *tbuf=(unsigned short *)_elem, /* temporary buffer pointer */ + *tbuf2=(unsigned short *)_operator_data; /* temporary buffer handle */ + + /* Simple check to make certain the values in the selected points match */ + if(*tbuf!=*tbuf2) + return(-1); + else + return(0); +} /* end test_select_hyper_iter3() */ + +/**************************************************************** +** ** test_select_fill_all(): Test basic H5S (dataspace) selection code. ** Tests filling "all" selections ** @@ -4445,17 +4465,13 @@ test_select_fill_all(void) /* Space defaults to "all" selection */ /* Set fill value */ - fill_value=254; + fill_value=SPACE7_FILL; /* Fill selection in memory */ ret=H5Dfill(&fill_value,H5T_NATIVE_INT,wbuf,H5T_NATIVE_USHORT,sid1); CHECK(ret, FAIL, "H5Dfill"); - /* Close dataspace */ - ret = H5Sclose(sid1); - CHECK(ret, FAIL, "H5Sclose"); - - /* Verify memory buffer */ + /* Verify memory buffer the hard way... */ for(i=0, tbuf=wbuf; i<SPACE7_DIM1; i++) for(j=0; j<SPACE7_DIM2; j++) if(*tbuf!=(unsigned short)fill_value) { @@ -4463,6 +4479,14 @@ test_select_fill_all(void) printf("Error! j=%d, i=%d, *tbuf=%x, fill_value=%x\n",j,i,(unsigned)*tbuf,(unsigned)fill_value); } /* end if */ + /* Iterate through selection, verifying correct data */ + ret = H5Diterate(wbuf,H5T_NATIVE_USHORT,sid1,test_select_hyper_iter3,&fill_value); + CHECK(ret, FAIL, "H5Diterate"); + + /* Close dataspace */ + ret = H5Sclose(sid1); + CHECK(ret, FAIL, "H5Sclose"); + /* Free memory buffers */ free(wbuf); } /* test_select_fill_all() */ @@ -4516,17 +4540,13 @@ test_select_fill_point(hssize_t *offset) CHECK(ret, FAIL, "H5Soffset_simple"); /* Set fill value */ - fill_value=254; + fill_value=SPACE7_FILL; /* Fill selection in memory */ ret=H5Dfill(&fill_value,H5T_NATIVE_INT,wbuf,H5T_NATIVE_USHORT,sid1); CHECK(ret, FAIL, "H5Dfill"); - /* Close dataspace */ - ret = H5Sclose(sid1); - CHECK(ret, FAIL, "H5Sclose"); - - /* Verify memory buffer */ + /* Verify memory buffer the hard way... */ for(i=0, tbuf=wbuf; i<SPACE7_DIM1; i++) for(j=0; j<SPACE7_DIM2; j++, tbuf++) { for(k=0; k<(int)num_points; k++) { @@ -4544,6 +4564,14 @@ test_select_fill_point(hssize_t *offset) } /* end if */ } /* end for */ + /* Fill selection in memory */ + ret=H5Dfill(&fill_value,H5T_NATIVE_INT,wbuf,H5T_NATIVE_USHORT,sid1); + CHECK(ret, FAIL, "H5Dfill"); + + /* Close dataspace */ + ret = H5Sclose(sid1); + CHECK(ret, FAIL, "H5Sclose"); + /* Free memory buffers */ free(wbuf); } /* test_select_fill_point() */ @@ -4599,17 +4627,13 @@ test_select_fill_hyper_simple(hssize_t *offset) CHECK(ret, FAIL, "H5Soffset_simple"); /* Set fill value */ - fill_value=254; + fill_value=SPACE7_FILL; /* Fill selection in memory */ ret=H5Dfill(&fill_value,H5T_NATIVE_INT,wbuf,H5T_NATIVE_USHORT,sid1); CHECK(ret, FAIL, "H5Dfill"); - /* Close dataspace */ - ret = H5Sclose(sid1); - CHECK(ret, FAIL, "H5Sclose"); - - /* Verify memory buffer */ + /* Verify memory buffer the hard way... */ for(i=0, tbuf=wbuf; i<SPACE7_DIM1; i++) for(j=0; j<SPACE7_DIM2; j++, tbuf++) { if((i>=(int)(start[0]+real_offset[0]) && i<(int)(start[0]+count[0]+real_offset[0])) @@ -4627,6 +4651,14 @@ test_select_fill_hyper_simple(hssize_t *offset) } /* end else */ } /* end for */ + /* Iterate through selection, verifying correct data */ + ret = H5Diterate(wbuf,H5T_NATIVE_USHORT,sid1,test_select_hyper_iter3,&fill_value); + CHECK(ret, FAIL, "H5Diterate"); + + /* Close dataspace */ + ret = H5Sclose(sid1); + CHECK(ret, FAIL, "H5Sclose"); + /* Free memory buffers */ free(wbuf); } /* test_select_fill_hyper_simple() */ @@ -4693,17 +4725,13 @@ test_select_fill_hyper_regular(hssize_t *offset) CHECK(ret, FAIL, "H5Soffset_simple"); /* Set fill value */ - fill_value=254; + fill_value=SPACE7_FILL; /* Fill selection in memory */ ret=H5Dfill(&fill_value,H5T_NATIVE_INT,wbuf,H5T_NATIVE_USHORT,sid1); CHECK(ret, FAIL, "H5Dfill"); - /* Close dataspace */ - ret = H5Sclose(sid1); - CHECK(ret, FAIL, "H5Sclose"); - - /* Verify memory buffer */ + /* Verify memory buffer the hard way... */ for(i=0, tbuf=wbuf; i<SPACE7_DIM1; i++) for(j=0; j<SPACE7_DIM2; j++, tbuf++) { for(k=0; k<(int)num_points; k++) { @@ -4721,7 +4749,14 @@ test_select_fill_hyper_regular(hssize_t *offset) } /* end if */ } /* end for */ + /* Iterate through selection, verifying correct data */ + ret = H5Diterate(wbuf,H5T_NATIVE_USHORT,sid1,test_select_hyper_iter3,&fill_value); + CHECK(ret, FAIL, "H5Diterate"); + /* Close dataspace */ + ret = H5Sclose(sid1); + CHECK(ret, FAIL, "H5Sclose"); + /* Free memory buffers */ free(wbuf); } /* test_select_fill_hyper_regular() */ @@ -4794,17 +4829,13 @@ test_select_fill_hyper_irregular(hssize_t *offset) CHECK(ret, FAIL, "H5Soffset_simple"); /* Set fill value */ - fill_value=254; + fill_value=SPACE7_FILL; /* Fill selection in memory */ ret=H5Dfill(&fill_value,H5T_NATIVE_INT,wbuf,H5T_NATIVE_USHORT,sid1); CHECK(ret, FAIL, "H5Dfill"); - /* Close dataspace */ - ret = H5Sclose(sid1); - CHECK(ret, FAIL, "H5Sclose"); - - /* Verify memory buffer */ + /* Verify memory buffer the hard way... */ for(i=0, tbuf=wbuf; i<SPACE7_DIM1; i++) for(j=0; j<SPACE7_DIM2; j++, tbuf++) { for(k=0; k<(int)num_points; k++) { @@ -4822,6 +4853,13 @@ test_select_fill_hyper_irregular(hssize_t *offset) } /* end if */ } /* end for */ + /* Iterate through selection, verifying correct data */ + ret = H5Diterate(wbuf,H5T_NATIVE_USHORT,sid1,test_select_hyper_iter3,&fill_value); + CHECK(ret, FAIL, "H5Diterate"); + + /* Close dataspace */ + ret = H5Sclose(sid1); + CHECK(ret, FAIL, "H5Sclose"); /* Free memory buffers */ free(wbuf); @@ -4937,6 +4975,7 @@ test_select(void) test_select_combine(); /* Test filling selections */ + /* (Also tests iterating through each selection */ test_select_fill_all(); test_select_fill_point(NULL); test_select_fill_point(offset); @@ -4946,6 +4985,7 @@ test_select(void) test_select_fill_hyper_regular(offset); test_select_fill_hyper_irregular(NULL); test_select_fill_hyper_irregular(offset); + } /* test_select() */ |