summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@hdfgroup.org>1998-07-22 22:11:22 (GMT)
committerQuincey Koziol <koziol@hdfgroup.org>1998-07-22 22:11:22 (GMT)
commitb970dce3ec059f86206b275d55fde2b8b6e5fd33 (patch)
treeae810bf2af451559ced99a17269ec06f8db4dbce /src
parent29a029d7e7c95be8ded8fb4e0989e3711ab7e3dc (diff)
downloadhdf5-b970dce3ec059f86206b275d55fde2b8b6e5fd33.zip
hdf5-b970dce3ec059f86206b275d55fde2b8b6e5fd33.tar.gz
hdf5-b970dce3ec059f86206b275d55fde2b8b6e5fd33.tar.bz2
[svn-r530] Added code so H5Scopy copies selections properly.
Diffstat (limited to 'src')
-rw-r--r--src/H5Shyper.c156
-rw-r--r--src/H5Spoint.c79
-rw-r--r--src/H5Sprivate.h3
-rw-r--r--src/H5Sselect.c41
-rw-r--r--src/H5public.h2
5 files changed, 280 insertions, 1 deletions
diff --git a/src/H5Shyper.c b/src/H5Shyper.c
index bd69f91..7a646aa 100644
--- a/src/H5Shyper.c
+++ b/src/H5Shyper.c
@@ -1760,3 +1760,159 @@ H5S_hyper_sel_iter_release (H5S_sel_iter_t *sel_iter)
FUNC_LEAVE (SUCCEED);
} /* H5S_hyper_sel_iter_release() */
+
+/*-------------------------------------------------------------------------
+ * Function: H5S_hyper_compare_bounds
+ *
+ * Purpose: Compares two bounds for equality
+ *
+ * Return: an integer less than, equal to, or greater than zero if the first
+ * region is considered to be respectively less than, equal to, or
+ * greater than the second
+ *
+ * Programmer: Quincey Koziol
+ * Friday, July 17, 1998
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+int
+H5S_hyper_compare_bounds (const void *r1, const void *r2)
+{
+ if(((const H5S_hyper_bound_t *)r1)->bound<((const H5S_hyper_bound_t *)r2)->bound)
+ return(-1);
+ else
+ if(((const H5S_hyper_bound_t *)r1)->bound>((const H5S_hyper_bound_t *)r2)->bound)
+ return(1);
+ else
+ return(0);
+} /* end H5S_hyper_compare_bounds */
+
+/*--------------------------------------------------------------------------
+ NAME
+ H5S_hyper_copy
+ PURPOSE
+ Copy a selection from one dataspace to another
+ USAGE
+ herr_t H5S_hyper_copy(dst, src)
+ H5S_t *dst; OUT: Pointer to the destination dataspace
+ H5S_t *src; IN: Pointer to the source dataspace
+ RETURNS
+ SUCCEED/FAIL
+ DESCRIPTION
+ Copies all the hyperslab selection information from the source
+ dataspace to the destination dataspace.
+ GLOBAL VARIABLES
+ COMMENTS, BUGS, ASSUMPTIONS
+ EXAMPLES
+ REVISION LOG
+--------------------------------------------------------------------------*/
+herr_t
+H5S_hyper_copy (H5S_t *dst, const H5S_t *src)
+{
+ H5S_hyper_list_t *new_hyper; /* New hyperslab selection */
+ H5S_hyper_node_t *curr, *new, *new_head; /* Hyperslab information nodes */
+ intn i; /* Counters */
+ size_t u; /* Counters */
+ herr_t ret_value=SUCCEED; /* return value */
+
+ FUNC_ENTER (H5S_hyper_copy, FAIL);
+
+ assert(src);
+ assert(dst);
+
+#ifdef QAK
+ printf("%s: check 3.0\n", FUNC);
+#endif /* QAK */
+ /* Create the new hyperslab information node */
+ if((new_hyper = H5MM_malloc(sizeof(H5S_hyper_list_t)))==NULL)
+ HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL,
+ "can't allocate point node");
+
+ /* Copy the basic hyperslab selection information */
+ *new_hyper=*(src->select.sel_info.hyper_lst);
+
+ /* Attach the hyperslab information to the destination dataspace */
+ dst->select.sel_info.hyper_lst=new_hyper;
+
+#ifdef QAK
+ printf("%s: check 4.0\n", FUNC);
+#endif /* QAK */
+ /* Allocate space for the low & high bound arrays */
+ if((new_hyper->lo_bounds = H5MM_malloc(sizeof(H5S_hyper_bound_t *)*src->extent.u.simple.rank))==NULL)
+ HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL,
+ "can't allocate point node");
+ if((new_hyper->hi_bounds = H5MM_malloc(sizeof(H5S_hyper_bound_t *)*src->extent.u.simple.rank))==NULL)
+ HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL,
+ "can't allocate point node");
+ for(i=0; i<src->extent.u.simple.rank; i++) {
+ if((new_hyper->lo_bounds[i] = H5MM_malloc(sizeof(H5S_hyper_bound_t)*src->select.sel_info.hyper_lst->count))==NULL)
+ HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL,
+ "can't allocate point node");
+ if((new_hyper->hi_bounds[i] = H5MM_malloc(sizeof(H5S_hyper_bound_t)*src->select.sel_info.hyper_lst->count))==NULL)
+ HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL,
+ "can't allocate point node");
+ } /* end for */
+
+#ifdef QAK
+ printf("%s: check 5.0\n", FUNC);
+#endif /* QAK */
+ /* Copy the hyperslab selection nodes, adding them to the lo & hi bound arrays also */
+ curr=src->select.sel_info.hyper_lst->head;
+ new_head=NULL;
+ u=0;
+ while(curr!=NULL) {
+#ifdef QAK
+ printf("%s: check 5.1\n", FUNC);
+#endif /* QAK */
+ /* Create each point */
+ if((new = H5MM_malloc(sizeof(H5S_hyper_node_t)))==NULL)
+ HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL,
+ "can't allocate point node");
+ if((new->start = H5MM_malloc(src->extent.u.simple.rank*sizeof(hssize_t)))==NULL)
+ HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL,
+ "can't allocate coordinate information");
+ if((new->end = H5MM_malloc(src->extent.u.simple.rank*sizeof(hssize_t)))==NULL)
+ HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL,
+ "can't allocate coordinate information");
+ HDmemcpy(new->start,curr->start,(src->extent.u.simple.rank*sizeof(hssize_t)));
+ HDmemcpy(new->end,curr->end,(src->extent.u.simple.rank*sizeof(hssize_t)));
+ new->next=NULL;
+
+ /* Insert into low & high bound arrays */
+ for(i=0; i<src->extent.u.simple.rank; i++) {
+ new_hyper->lo_bounds[i][u].bound=new->start[i];
+ new_hyper->lo_bounds[i][u].node=new;
+ new_hyper->hi_bounds[i][u].bound=new->end[i];
+ new_hyper->hi_bounds[i][u].node=new;
+ } /* end for */
+ u++; /* Increment the location of the next node in the boundary arrays */
+
+ /* Keep the order the same when copying */
+ if(new_head==NULL)
+ new_head=new_hyper->head=new;
+ else {
+ new_head->next=new;
+ new_head=new;
+ } /* end else */
+
+ curr=curr->next;
+ } /* end while */
+#ifdef QAK
+ printf("%s: check 6.0\n", FUNC);
+#endif /* QAK */
+
+ /* Sort the boundary arrays */
+ for(i=0; i<src->extent.u.simple.rank; i++) {
+ qsort(new_hyper->lo_bounds[i],new_hyper->count,sizeof(H5S_hyper_bound_t),H5S_hyper_compare_bounds);
+ qsort(new_hyper->hi_bounds[i],new_hyper->count,sizeof(H5S_hyper_bound_t),H5S_hyper_compare_bounds);
+ } /* end for */
+#ifdef QAK
+ printf("%s: check 7.0\n", FUNC);
+#endif /* QAK */
+
+done:
+ FUNC_LEAVE (ret_value);
+} /* end H5S_hyper_copy() */
+
diff --git a/src/H5Spoint.c b/src/H5Spoint.c
index a291d8a..91141a4 100644
--- a/src/H5Spoint.c
+++ b/src/H5Spoint.c
@@ -639,4 +639,83 @@ H5S_hyper_npoints (const H5S_t *space)
FUNC_LEAVE (space->select.num_elem);
} /* H5S_hyper_npoints() */
+
+/*--------------------------------------------------------------------------
+ NAME
+ H5S_point_copy
+ PURPOSE
+ Copy a selection from one dataspace to another
+ USAGE
+ herr_t H5S_point_copy(dst, src)
+ H5S_t *dst; OUT: Pointer to the destination dataspace
+ H5S_t *src; IN: Pointer to the source dataspace
+ RETURNS
+ SUCCEED/FAIL
+ DESCRIPTION
+ Copies all the point selection information from the source
+ dataspace to the destination dataspace.
+ GLOBAL VARIABLES
+ COMMENTS, BUGS, ASSUMPTIONS
+ EXAMPLES
+ REVISION LOG
+--------------------------------------------------------------------------*/
+herr_t
+H5S_point_copy (H5S_t *dst, const H5S_t *src)
+{
+ H5S_pnt_node_t *curr, *new, *new_head; /* Point information nodes */
+ herr_t ret_value=SUCCEED; /* return value */
+
+ FUNC_ENTER (H5S_point_copy, FAIL);
+
+ assert(src);
+ assert(dst);
+
+#ifdef QAK
+ printf("%s: check 1.0\n",FUNC);
+#endif /* QAK */
+ /* Allocate room for the head of the point list */
+ if((dst->select.sel_info.pnt_lst=H5MM_malloc(sizeof(H5S_pnt_list_t)))==NULL)
+ HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL,
+ "can't allocate point node");
+
+ curr=src->select.sel_info.pnt_lst->head;
+ new_head=NULL;
+ while(curr!=NULL) {
+ /* Create each point */
+ if((new=H5MM_malloc(sizeof(H5S_pnt_node_t)))==NULL)
+ HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL,
+ "can't allocate point node");
+ if((new->pnt = H5MM_malloc(src->extent.u.simple.rank*sizeof(hssize_t)))==NULL)
+ HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL,
+ "can't allocate coordinate information");
+ HDmemcpy(new->pnt,curr->pnt,(src->extent.u.simple.rank*sizeof(hssize_t)));
+ new->next=NULL;
+
+#ifdef QAK
+ printf("%s: check 5.0\n",FUNC);
+ {
+ intn i;
+ for(i=0; i<src->extent.u.simple.rank; i++)
+ printf("%s: check 5.1, new->pnt[%d]=%d\n",FUNC,i,(int)new->pnt[i]);
+ }
+#endif /* QAK */
+
+ /* Keep the order the same when copying */
+ if(new_head==NULL)
+ new_head=dst->select.sel_info.pnt_lst->head=new;
+ else {
+ new_head->next=new;
+ new_head=new;
+ } /* end else */
+
+ curr=curr->next;
+ } /* end while */
+#ifdef QAK
+ printf("%s: check 10.0 src->select.sel_info.pnt_lst=%p, dst->select.sel_info.pnt_lst=%p\n",FUNC,src->select.sel_info.pnt_lst,dst->select.sel_info.pnt_lst);
+ printf("%s: check 10.0 src->select.sel_info.pnt_lst->head=%p, dst->select.sel_info.pnt_lst->head=%p\n",FUNC,src->select.sel_info.pnt_lst->head,dst->select.sel_info.pnt_lst->head);
+#endif /* QAK */
+
+done:
+ FUNC_LEAVE (ret_value);
+} /* end H5S_point_copy() */
diff --git a/src/H5Sprivate.h b/src/H5Sprivate.h
index e5aeabc..eb1897f 100644
--- a/src/H5Sprivate.h
+++ b/src/H5Sprivate.h
@@ -286,6 +286,7 @@ herr_t H5S_point_mscat (const void *_tconv_buf, size_t elmt_size,
herr_t H5S_point_add (H5S_t *space, size_t num_elemn, const hssize_t **coord);
herr_t H5S_point_release (H5S_t *space);
hsize_t H5S_point_npoints (const H5S_t *space);
+herr_t H5S_point_copy (H5S_t *dst, const H5S_t *src);
/* "All" select functions */
herr_t H5S_all_init (const struct H5O_layout_t *layout,
@@ -337,5 +338,7 @@ herr_t H5S_hyper_release (H5S_t *space);
herr_t H5S_hyper_sel_iter_release (H5S_sel_iter_t *sel_iter);
hsize_t H5S_hyper_npoints (const H5S_t *space);
int H5S_hyper_compare_regions (const void *r1, const void *r2);
+int H5S_hyper_compare_bounds (const void *r1, const void *r2);
+herr_t H5S_hyper_copy (H5S_t *dst, const H5S_t *src);
#endif
diff --git a/src/H5Sselect.c b/src/H5Sselect.c
index af3dbcd..062b2a1 100644
--- a/src/H5Sselect.c
+++ b/src/H5Sselect.c
@@ -93,14 +93,55 @@ H5S_select_term(void)
herr_t
H5S_select_copy (H5S_t *dst, const H5S_t *src)
{
+ herr_t ret_value=SUCCEED; /* return value */
+
FUNC_ENTER (H5S_select_copy, FAIL);
/* Check args */
assert(dst);
assert(src);
+ /* Copy regular fields */
+ dst->select=src->select;
+
+/* Need to copy offset and order information still */
/* Perform correct type of copy based on the type of selection */
+ switch (src->extent.type) {
+ case H5S_SCALAR:
+ /*nothing needed */
+ break;
+
+ case H5S_SIMPLE:
+ /* Deep copy extra stuff */
+ switch(src->select.type) {
+ case H5S_SEL_NONE:
+ case H5S_SEL_ALL:
+ /*nothing needed */
+ break;
+
+ case H5S_SEL_POINTS:
+ ret_value=H5S_point_copy(dst,src);
+ break;
+
+ case H5S_SEL_HYPERSLABS:
+ ret_value=H5S_hyper_copy(dst,src);
+ break;
+
+ default:
+ assert("unknown selection type" && 0);
+ break;
+ } /* end switch */
+ break;
+
+ case H5S_COMPLEX:
+ /*void */
+ break;
+
+ default:
+ assert("unknown data space type" && 0);
+ break;
+ }
FUNC_LEAVE (SUCCEED);
} /* H5S_select_copy() */
diff --git a/src/H5public.h b/src/H5public.h
index 104ed28..641c6de 100644
--- a/src/H5public.h
+++ b/src/H5public.h
@@ -27,7 +27,7 @@
/* Version numbers */
#define H5_VERS_MAJOR 1 /* For major interface/format changes */
#define H5_VERS_MINOR 0 /* For minor interface/format changes */
-#define H5_VERS_RELEASE 25 /* For tweaks, bug-fixes, or development */
+#define H5_VERS_RELEASE 28 /* For tweaks, bug-fixes, or development */
#define H5check() H5vers_check(H5_VERS_MAJOR,H5_VERS_MINOR, \
H5_VERS_RELEASE)