Line | Count | Source |
1 | | /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
2 | | * Copyright by The HDF Group. * |
3 | | * All rights reserved. * |
4 | | * * |
5 | | * This file is part of HDF5. The full HDF5 copyright notice, including * |
6 | | * terms governing use, modification, and redistribution, is contained in * |
7 | | * the LICENSE file, which can be found at the root of the source code * |
8 | | * distribution tree, or in https://www.hdfgroup.org/licenses. * |
9 | | * If you do not have access to either file, you may request a copy from * |
10 | | * help@hdfgroup.org. * |
11 | | * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ |
12 | | |
13 | | /* |
14 | | * Purpose: Point selection dataspace I/O functions. |
15 | | */ |
16 | | |
17 | | /****************/ |
18 | | /* Module Setup */ |
19 | | /****************/ |
20 | | |
21 | | #include "H5Smodule.h" /* This source code file is part of the H5S module */ |
22 | | |
23 | | /***********/ |
24 | | /* Headers */ |
25 | | /***********/ |
26 | | #include "H5private.h" /* Generic Functions */ |
27 | | #include "H5CXprivate.h" /* API Contexts */ |
28 | | #include "H5Eprivate.h" /* Error handling */ |
29 | | #include "H5FLprivate.h" /* Free Lists */ |
30 | | #include "H5Iprivate.h" /* ID Functions */ |
31 | | #include "H5MMprivate.h" /* Memory management */ |
32 | | #include "H5Spkg.h" /* Dataspace functions */ |
33 | | #include "H5VMprivate.h" /* Vector functions */ |
34 | | |
35 | | /****************/ |
36 | | /* Local Macros */ |
37 | | /****************/ |
38 | | |
39 | | /******************/ |
40 | | /* Local Typedefs */ |
41 | | /******************/ |
42 | | |
43 | | /* Define alias for hsize_t, for allocating H5S_pnt_node_t + point objects */ |
44 | | /* (Makes it easier to understand the alloc / free calls) */ |
45 | | typedef hsize_t hcoords_t; |
46 | | |
47 | | /********************/ |
48 | | /* Local Prototypes */ |
49 | | /********************/ |
50 | | static herr_t H5S__point_add(H5S_t *space, H5S_seloper_t op, size_t num_elem, const hsize_t *coord); |
51 | | static H5S_pnt_list_t *H5S__copy_pnt_list(const H5S_pnt_list_t *src, unsigned rank); |
52 | | static void H5S__free_pnt_list(H5S_pnt_list_t *pnt_lst); |
53 | | |
54 | | /* Selection callbacks */ |
55 | | static herr_t H5S__point_copy(H5S_t *dst, const H5S_t *src, bool share_selection); |
56 | | static herr_t H5S__point_release(H5S_t *space); |
57 | | static htri_t H5S__point_is_valid(const H5S_t *space); |
58 | | static hssize_t H5S__point_serial_size(H5S_t *space); |
59 | | static herr_t H5S__point_serialize(H5S_t *space, uint8_t **p); |
60 | | static herr_t H5S__point_deserialize(H5S_t **space, const uint8_t **p, const size_t p_size, bool skip); |
61 | | static herr_t H5S__point_bounds(const H5S_t *space, hsize_t *start, hsize_t *end); |
62 | | static herr_t H5S__point_offset(const H5S_t *space, hsize_t *off); |
63 | | static int H5S__point_unlim_dim(const H5S_t *space); |
64 | | static htri_t H5S__point_is_contiguous(const H5S_t *space); |
65 | | static htri_t H5S__point_is_single(const H5S_t *space); |
66 | | static htri_t H5S__point_is_regular(H5S_t *space); |
67 | | static htri_t H5S__point_shape_same(H5S_t *space1, H5S_t *space2); |
68 | | static htri_t H5S__point_intersect_block(H5S_t *space, const hsize_t *start, const hsize_t *end); |
69 | | static herr_t H5S__point_adjust_u(H5S_t *space, const hsize_t *offset); |
70 | | static herr_t H5S__point_adjust_s(H5S_t *space, const hssize_t *offset); |
71 | | static herr_t H5S__point_project_scalar(const H5S_t *space, hsize_t *offset); |
72 | | static herr_t H5S__point_project_simple(const H5S_t *space, H5S_t *new_space, hsize_t *offset); |
73 | | static herr_t H5S__point_iter_init(H5S_t *space, H5S_sel_iter_t *iter); |
74 | | static herr_t H5S__point_get_version_enc_size(const H5S_t *space, uint32_t *version, uint8_t *enc_size); |
75 | | |
76 | | /* Selection iteration callbacks */ |
77 | | static herr_t H5S__point_iter_coords(const H5S_sel_iter_t *iter, hsize_t *coords); |
78 | | static herr_t H5S__point_iter_block(const H5S_sel_iter_t *iter, hsize_t *start, hsize_t *end); |
79 | | static hsize_t H5S__point_iter_nelmts(const H5S_sel_iter_t *iter); |
80 | | static htri_t H5S__point_iter_has_next_block(const H5S_sel_iter_t *iter); |
81 | | static herr_t H5S__point_iter_next(H5S_sel_iter_t *sel_iter, size_t nelem); |
82 | | static herr_t H5S__point_iter_next_block(H5S_sel_iter_t *sel_iter); |
83 | | static herr_t H5S__point_iter_get_seq_list(H5S_sel_iter_t *iter, size_t maxseq, size_t maxbytes, size_t *nseq, |
84 | | size_t *nbytes, hsize_t *off, size_t *len); |
85 | | static herr_t H5S__point_iter_release(H5S_sel_iter_t *sel_iter); |
86 | | |
87 | | /*****************************/ |
88 | | /* Library Private Variables */ |
89 | | /*****************************/ |
90 | | |
91 | | /*********************/ |
92 | | /* Package Variables */ |
93 | | /*********************/ |
94 | | |
95 | | /* Selection properties for point selections */ |
96 | | const H5S_select_class_t H5S_sel_point[1] = {{ |
97 | | H5S_SEL_POINTS, |
98 | | |
99 | | /* Methods on selection */ |
100 | | H5S__point_copy, |
101 | | H5S__point_release, |
102 | | H5S__point_is_valid, |
103 | | H5S__point_serial_size, |
104 | | H5S__point_serialize, |
105 | | H5S__point_deserialize, |
106 | | H5S__point_bounds, |
107 | | H5S__point_offset, |
108 | | H5S__point_unlim_dim, |
109 | | NULL, |
110 | | H5S__point_is_contiguous, |
111 | | H5S__point_is_single, |
112 | | H5S__point_is_regular, |
113 | | H5S__point_shape_same, |
114 | | H5S__point_intersect_block, |
115 | | H5S__point_adjust_u, |
116 | | H5S__point_adjust_s, |
117 | | H5S__point_project_scalar, |
118 | | H5S__point_project_simple, |
119 | | H5S__point_iter_init, |
120 | | }}; |
121 | | |
122 | | /* Format version bounds for dataspace point selection */ |
123 | | static const unsigned H5O_sds_point_ver_bounds[] = { |
124 | | H5S_POINT_VERSION_1, /* H5F_LIBVER_EARLIEST */ |
125 | | H5S_POINT_VERSION_1, /* H5F_LIBVER_V18 */ |
126 | | H5S_POINT_VERSION_1, /* H5F_LIBVER_V110 */ |
127 | | H5S_POINT_VERSION_2, /* H5F_LIBVER_V112 */ |
128 | | H5S_POINT_VERSION_2, /* H5F_LIBVER_V114 */ |
129 | | H5S_POINT_VERSION_2, /* H5F_LIBVER_V200 */ |
130 | | H5S_POINT_VERSION_2 /* H5F_LIBVER_LATEST */ |
131 | | }; |
132 | | |
133 | | /*******************/ |
134 | | /* Local Variables */ |
135 | | /*******************/ |
136 | | |
137 | | /* Iteration properties for point selections */ |
138 | | static const H5S_sel_iter_class_t H5S_sel_iter_point[1] = {{ |
139 | | H5S_SEL_POINTS, |
140 | | |
141 | | /* Methods on selection iterator */ |
142 | | H5S__point_iter_coords, |
143 | | H5S__point_iter_block, |
144 | | H5S__point_iter_nelmts, |
145 | | H5S__point_iter_has_next_block, |
146 | | H5S__point_iter_next, |
147 | | H5S__point_iter_next_block, |
148 | | H5S__point_iter_get_seq_list, |
149 | | H5S__point_iter_release, |
150 | | }}; |
151 | | |
152 | | /* Declare a free list to manage the H5S_pnt_node_t + hcoords_t array struct */ |
153 | | H5FL_BARR_DEFINE_STATIC(H5S_pnt_node_t, hcoords_t, H5S_MAX_RANK); |
154 | | |
155 | | /* Declare a free list to manage the H5S_pnt_list_t struct */ |
156 | | H5FL_DEFINE_STATIC(H5S_pnt_list_t); |
157 | | |
158 | | /*------------------------------------------------------------------------- |
159 | | * Function: H5S__point_iter_init |
160 | | * |
161 | | * Purpose: Initializes iteration information for point selection. |
162 | | * |
163 | | * Return: Non-negative on success, negative on failure. |
164 | | * |
165 | | *------------------------------------------------------------------------- |
166 | | */ |
167 | | static herr_t |
168 | | H5S__point_iter_init(H5S_t *space, H5S_sel_iter_t *iter) |
169 | 679 | { |
170 | 679 | herr_t ret_value = SUCCEED; /* Return value */ |
171 | | |
172 | 679 | FUNC_ENTER_PACKAGE |
173 | | |
174 | | /* Check args */ |
175 | 679 | assert(space && H5S_SEL_POINTS == H5S_GET_SELECT_TYPE(space)); |
176 | 679 | assert(iter); |
177 | | |
178 | | /* If this iterator is created from an API call, by default we clone the |
179 | | * selection now, as the dataspace could be modified or go out of scope. |
180 | | * |
181 | | * However, if the H5S_SEL_ITER_SHARE_WITH_DATASPACE flag is given, |
182 | | * the selection is shared between the selection iterator and the |
183 | | * dataspace. In this case, the application _must_not_ modify or |
184 | | * close the dataspace that the iterator is operating on, or undefined |
185 | | * behavior will occur. |
186 | | */ |
187 | 679 | if ((iter->flags & H5S_SEL_ITER_API_CALL) && !(iter->flags & H5S_SEL_ITER_SHARE_WITH_DATASPACE)) { |
188 | | /* Copy the point list */ |
189 | 0 | if (NULL == |
190 | 0 | (iter->u.pnt.pnt_lst = H5S__copy_pnt_list(space->select.sel_info.pnt_lst, space->extent.rank))) |
191 | 0 | HGOTO_ERROR(H5E_DATASPACE, H5E_CANTCOPY, FAIL, "can't copy point list"); |
192 | 0 | } /* end if */ |
193 | 679 | else |
194 | | /* OK to share point list for internal iterations */ |
195 | 679 | iter->u.pnt.pnt_lst = space->select.sel_info.pnt_lst; |
196 | | |
197 | | /* Start at the head of the list of points */ |
198 | 679 | iter->u.pnt.curr = iter->u.pnt.pnt_lst->head; |
199 | | |
200 | | /* Initialize type of selection iterator */ |
201 | 679 | iter->type = H5S_sel_iter_point; |
202 | | |
203 | 679 | done: |
204 | 679 | FUNC_LEAVE_NOAPI(ret_value) |
205 | 679 | } /* end H5S__point_iter_init() */ |
206 | | |
207 | | /*------------------------------------------------------------------------- |
208 | | * Function: H5S__point_iter_coords |
209 | | * |
210 | | * Purpose: Retrieve the current coordinates of iterator for current |
211 | | * selection |
212 | | * |
213 | | * Return: Non-negative on success, negative on failure |
214 | | * |
215 | | *------------------------------------------------------------------------- |
216 | | */ |
217 | | static herr_t |
218 | | H5S__point_iter_coords(const H5S_sel_iter_t *iter, hsize_t *coords) |
219 | 0 | { |
220 | 0 | FUNC_ENTER_PACKAGE_NOERR |
221 | | |
222 | | /* Check args */ |
223 | 0 | assert(iter); |
224 | 0 | assert(coords); |
225 | | |
226 | | /* Copy the offset of the current point */ |
227 | 0 | H5MM_memcpy(coords, iter->u.pnt.curr->pnt, sizeof(hsize_t) * iter->rank); |
228 | |
|
229 | 0 | FUNC_LEAVE_NOAPI(SUCCEED) |
230 | 0 | } /* end H5S__point_iter_coords() */ |
231 | | |
232 | | /*------------------------------------------------------------------------- |
233 | | * Function: H5S__point_iter_block |
234 | | * |
235 | | * Purpose: Retrieve the current block of iterator for current |
236 | | * selection |
237 | | * |
238 | | * Return: Non-negative on success, negative on failure |
239 | | * |
240 | | *------------------------------------------------------------------------- |
241 | | */ |
242 | | static herr_t |
243 | | H5S__point_iter_block(const H5S_sel_iter_t *iter, hsize_t *start, hsize_t *end) |
244 | 43 | { |
245 | 43 | FUNC_ENTER_PACKAGE_NOERR |
246 | | |
247 | | /* Check args */ |
248 | 43 | assert(iter); |
249 | 43 | assert(start); |
250 | 43 | assert(end); |
251 | | |
252 | | /* Copy the current point as a block */ |
253 | 43 | H5MM_memcpy(start, iter->u.pnt.curr->pnt, sizeof(hsize_t) * iter->rank); |
254 | 43 | H5MM_memcpy(end, iter->u.pnt.curr->pnt, sizeof(hsize_t) * iter->rank); |
255 | | |
256 | 43 | FUNC_LEAVE_NOAPI(SUCCEED) |
257 | 43 | } /* end H5S__point_iter_block() */ |
258 | | |
259 | | /*------------------------------------------------------------------------- |
260 | | * Function: H5S__point_iter_nelmts |
261 | | * |
262 | | * Purpose: Return number of elements left to process in iterator |
263 | | * |
264 | | * Return: Non-negative number of elements on success, zero on failure |
265 | | * |
266 | | *------------------------------------------------------------------------- |
267 | | */ |
268 | | static hsize_t |
269 | | H5S__point_iter_nelmts(const H5S_sel_iter_t *iter) |
270 | 0 | { |
271 | 0 | FUNC_ENTER_PACKAGE_NOERR |
272 | | |
273 | | /* Check args */ |
274 | 0 | assert(iter); |
275 | |
|
276 | 0 | FUNC_LEAVE_NOAPI(iter->elmt_left) |
277 | 0 | } /* end H5S__point_iter_nelmts() */ |
278 | | |
279 | | /*-------------------------------------------------------------------------- |
280 | | NAME |
281 | | H5S__point_iter_has_next_block |
282 | | PURPOSE |
283 | | Check if there is another block left in the current iterator |
284 | | USAGE |
285 | | htri_t H5S__point_iter_has_next_block(iter) |
286 | | const H5S_sel_iter_t *iter; IN: Pointer to selection iterator |
287 | | RETURNS |
288 | | Non-negative (true/false) on success/Negative on failure |
289 | | DESCRIPTION |
290 | | Check if there is another block available in the selection iterator. |
291 | | GLOBAL VARIABLES |
292 | | COMMENTS, BUGS, ASSUMPTIONS |
293 | | EXAMPLES |
294 | | REVISION LOG |
295 | | --------------------------------------------------------------------------*/ |
296 | | static htri_t |
297 | | H5S__point_iter_has_next_block(const H5S_sel_iter_t *iter) |
298 | 0 | { |
299 | 0 | htri_t ret_value = true; /* Return value */ |
300 | |
|
301 | 0 | FUNC_ENTER_PACKAGE_NOERR |
302 | | |
303 | | /* Check args */ |
304 | 0 | assert(iter); |
305 | | |
306 | | /* Check if there is another point in the list */ |
307 | 0 | if (iter->u.pnt.curr->next == NULL) |
308 | 0 | HGOTO_DONE(false); |
309 | | |
310 | 0 | done: |
311 | 0 | FUNC_LEAVE_NOAPI(ret_value) |
312 | 0 | } /* end H5S__point_iter_has_next_block() */ |
313 | | |
314 | | /*-------------------------------------------------------------------------- |
315 | | NAME |
316 | | H5S__point_iter_next |
317 | | PURPOSE |
318 | | Increment selection iterator |
319 | | USAGE |
320 | | herr_t H5S__point_iter_next(iter, nelem) |
321 | | H5S_sel_iter_t *iter; IN: Pointer to selection iterator |
322 | | size_t nelem; IN: Number of elements to advance by |
323 | | RETURNS |
324 | | Non-negative on success/Negative on failure |
325 | | DESCRIPTION |
326 | | Advance selection iterator to the NELEM'th next element in the selection. |
327 | | GLOBAL VARIABLES |
328 | | COMMENTS, BUGS, ASSUMPTIONS |
329 | | EXAMPLES |
330 | | REVISION LOG |
331 | | --------------------------------------------------------------------------*/ |
332 | | static herr_t |
333 | | H5S__point_iter_next(H5S_sel_iter_t *iter, size_t nelem) |
334 | 0 | { |
335 | 0 | FUNC_ENTER_PACKAGE_NOERR |
336 | | |
337 | | /* Check args */ |
338 | 0 | assert(iter); |
339 | 0 | assert(nelem > 0); |
340 | | |
341 | | /* Increment the iterator */ |
342 | 0 | while (nelem > 0) { |
343 | 0 | iter->u.pnt.curr = iter->u.pnt.curr->next; |
344 | 0 | nelem--; |
345 | 0 | } /* end while */ |
346 | |
|
347 | 0 | FUNC_LEAVE_NOAPI(SUCCEED) |
348 | 0 | } /* end H5S__point_iter_next() */ |
349 | | |
350 | | /*-------------------------------------------------------------------------- |
351 | | NAME |
352 | | H5S__point_iter_next_block |
353 | | PURPOSE |
354 | | Increment selection iterator to next block |
355 | | USAGE |
356 | | herr_t H5S__point_iter_next_block(iter) |
357 | | H5S_sel_iter_t *iter; IN: Pointer to selection iterator |
358 | | RETURNS |
359 | | Non-negative on success/Negative on failure |
360 | | DESCRIPTION |
361 | | Advance selection iterator to the next block in the selection. |
362 | | GLOBAL VARIABLES |
363 | | COMMENTS, BUGS, ASSUMPTIONS |
364 | | EXAMPLES |
365 | | REVISION LOG |
366 | | --------------------------------------------------------------------------*/ |
367 | | static herr_t |
368 | | H5S__point_iter_next_block(H5S_sel_iter_t *iter) |
369 | 0 | { |
370 | 0 | FUNC_ENTER_PACKAGE_NOERR |
371 | | |
372 | | /* Check args */ |
373 | 0 | assert(iter); |
374 | | |
375 | | /* Increment the iterator */ |
376 | 0 | iter->u.pnt.curr = iter->u.pnt.curr->next; |
377 | |
|
378 | 0 | FUNC_LEAVE_NOAPI(SUCCEED) |
379 | 0 | } /* end H5S__point_iter_next_block() */ |
380 | | |
381 | | /*-------------------------------------------------------------------------- |
382 | | NAME |
383 | | H5S__point_iter_get_seq_list |
384 | | PURPOSE |
385 | | Create a list of offsets & lengths for a selection |
386 | | USAGE |
387 | | herr_t H5S__point_iter_get_seq_list(iter,maxseq,maxelem,nseq,nelem,off,len) |
388 | | H5S_sel_iter_t *iter; IN/OUT: Selection iterator describing last |
389 | | position of interest in selection. |
390 | | size_t maxseq; IN: Maximum number of sequences to generate |
391 | | size_t maxelem; IN: Maximum number of elements to include in the |
392 | | generated sequences |
393 | | size_t *nseq; OUT: Actual number of sequences generated |
394 | | size_t *nelem; OUT: Actual number of elements in sequences generated |
395 | | hsize_t *off; OUT: Array of offsets (in bytes) |
396 | | size_t *len; OUT: Array of lengths (in bytes) |
397 | | RETURNS |
398 | | Non-negative on success/Negative on failure. |
399 | | DESCRIPTION |
400 | | Use the selection in the dataspace to generate a list of byte offsets and |
401 | | lengths for the region(s) selected. Start/Restart from the position in the |
402 | | ITER parameter. The number of sequences generated is limited by the MAXSEQ |
403 | | parameter and the number of sequences actually generated is stored in the |
404 | | NSEQ parameter. |
405 | | GLOBAL VARIABLES |
406 | | COMMENTS, BUGS, ASSUMPTIONS |
407 | | EXAMPLES |
408 | | REVISION LOG |
409 | | --------------------------------------------------------------------------*/ |
410 | | static herr_t |
411 | | H5S__point_iter_get_seq_list(H5S_sel_iter_t *iter, size_t maxseq, size_t maxelem, size_t *nseq, size_t *nelem, |
412 | | hsize_t *off, size_t *len) |
413 | 636 | { |
414 | 636 | size_t io_left; /* The number of bytes left in the selection */ |
415 | 636 | size_t start_io_left; /* The initial number of bytes left in the selection */ |
416 | 636 | H5S_pnt_node_t *node; /* Point node */ |
417 | 636 | unsigned ndims; /* Dimensionality of dataspace*/ |
418 | 636 | hsize_t acc; /* Coordinate accumulator */ |
419 | 636 | hsize_t loc; /* Coordinate offset */ |
420 | 636 | size_t curr_seq; /* Current sequence being operated on */ |
421 | 636 | int i; /* Local index variable */ |
422 | 636 | herr_t ret_value = SUCCEED; /* return value */ |
423 | | |
424 | 636 | FUNC_ENTER_PACKAGE_NOERR |
425 | | |
426 | | /* Check args */ |
427 | 636 | assert(iter); |
428 | 636 | assert(maxseq > 0); |
429 | 636 | assert(maxelem > 0); |
430 | 636 | assert(nseq); |
431 | 636 | assert(nelem); |
432 | 636 | assert(off); |
433 | 636 | assert(len); |
434 | | |
435 | | /* Choose the minimum number of bytes to sequence through */ |
436 | 636 | H5_CHECK_OVERFLOW(iter->elmt_left, hsize_t, size_t); |
437 | 636 | start_io_left = io_left = (size_t)MIN(iter->elmt_left, maxelem); |
438 | | |
439 | | /* Get the dataspace's rank */ |
440 | 636 | ndims = iter->rank; |
441 | | |
442 | | /* Walk through the points in the selection, starting at the current */ |
443 | | /* location in the iterator */ |
444 | 636 | node = iter->u.pnt.curr; |
445 | 636 | curr_seq = 0; |
446 | 8.42k | while (NULL != node) { |
447 | | /* Compute the offset of each selected point in the buffer */ |
448 | 25.2k | for (i = (int)(ndims - 1), acc = iter->elmt_size, loc = 0; i >= 0; i--) { |
449 | 16.7k | loc += (hsize_t)((hssize_t)node->pnt[i] + iter->sel_off[i]) * acc; |
450 | 16.7k | acc *= iter->dims[i]; |
451 | 16.7k | } /* end for */ |
452 | | |
453 | | /* Check if this is a later point in the selection */ |
454 | 8.42k | if (curr_seq > 0) { |
455 | | /* If a sorted sequence is requested, make certain we don't go backwards in the offset */ |
456 | 7.78k | if ((iter->flags & H5S_SEL_ITER_GET_SEQ_LIST_SORTED) && loc < off[curr_seq - 1]) |
457 | 0 | break; |
458 | | |
459 | | /* Check if this point extends the previous sequence */ |
460 | | /* (Unlikely, but possible) */ |
461 | 7.78k | if (loc == (off[curr_seq - 1] + len[curr_seq - 1])) { |
462 | | /* Extend the previous sequence */ |
463 | 5.82k | len[curr_seq - 1] += iter->elmt_size; |
464 | 5.82k | } /* end if */ |
465 | 1.95k | else { |
466 | | /* Add a new sequence */ |
467 | 1.95k | off[curr_seq] = loc; |
468 | 1.95k | len[curr_seq] = iter->elmt_size; |
469 | | |
470 | | /* Increment sequence count */ |
471 | 1.95k | curr_seq++; |
472 | 1.95k | } /* end else */ |
473 | 7.78k | } /* end if */ |
474 | 636 | else { |
475 | | /* Add a new sequence */ |
476 | 636 | off[curr_seq] = loc; |
477 | 636 | len[curr_seq] = iter->elmt_size; |
478 | | |
479 | | /* Increment sequence count */ |
480 | 636 | curr_seq++; |
481 | 636 | } /* end else */ |
482 | | |
483 | | /* Decrement number of elements left to process */ |
484 | 8.42k | io_left--; |
485 | | |
486 | | /* Move the iterator */ |
487 | 8.42k | iter->u.pnt.curr = node->next; |
488 | 8.42k | iter->elmt_left--; |
489 | | |
490 | | /* Check if we're finished with all sequences */ |
491 | 8.42k | if (curr_seq == maxseq) |
492 | 0 | break; |
493 | | |
494 | | /* Check if we're finished with all the elements available */ |
495 | 8.42k | if (io_left == 0) |
496 | 636 | break; |
497 | | |
498 | | /* Advance to the next point */ |
499 | 7.78k | node = node->next; |
500 | 7.78k | } /* end while */ |
501 | | |
502 | | /* Set the number of sequences generated */ |
503 | 636 | *nseq = curr_seq; |
504 | | |
505 | | /* Set the number of elements used */ |
506 | 636 | *nelem = start_io_left - io_left; |
507 | | |
508 | 636 | FUNC_LEAVE_NOAPI(ret_value) |
509 | 636 | } /* end H5S__point_iter_get_seq_list() */ |
510 | | |
511 | | /*-------------------------------------------------------------------------- |
512 | | NAME |
513 | | H5S__point_iter_release |
514 | | PURPOSE |
515 | | Release point selection iterator information for a dataspace |
516 | | USAGE |
517 | | herr_t H5S__point_iter_release(iter) |
518 | | H5S_sel_iter_t *iter; IN: Pointer to selection iterator |
519 | | RETURNS |
520 | | Non-negative on success/Negative on failure |
521 | | DESCRIPTION |
522 | | Releases all information for a dataspace point selection iterator |
523 | | GLOBAL VARIABLES |
524 | | COMMENTS, BUGS, ASSUMPTIONS |
525 | | EXAMPLES |
526 | | REVISION LOG |
527 | | --------------------------------------------------------------------------*/ |
528 | | static herr_t |
529 | | H5S__point_iter_release(H5S_sel_iter_t *iter) |
530 | 679 | { |
531 | 679 | FUNC_ENTER_PACKAGE_NOERR |
532 | | |
533 | | /* Check args */ |
534 | 679 | assert(iter); |
535 | | |
536 | | /* If this iterator copied the point list, we must free it */ |
537 | 679 | if ((iter->flags & H5S_SEL_ITER_API_CALL) && !(iter->flags & H5S_SEL_ITER_SHARE_WITH_DATASPACE)) |
538 | 0 | H5S__free_pnt_list(iter->u.pnt.pnt_lst); |
539 | | |
540 | 679 | FUNC_LEAVE_NOAPI(SUCCEED) |
541 | 679 | } /* end H5S__point_iter_release() */ |
542 | | |
543 | | /*-------------------------------------------------------------------------- |
544 | | NAME |
545 | | H5S__point_add |
546 | | PURPOSE |
547 | | Add a series of elements to a point selection |
548 | | USAGE |
549 | | herr_t H5S__point_add(space, num_elem, coord) |
550 | | H5S_t *space; IN: Dataspace of selection to modify |
551 | | size_t num_elem; IN: Number of elements in COORD array. |
552 | | const hsize_t *coord[]; IN: The location of each element selected |
553 | | RETURNS |
554 | | Non-negative on success/Negative on failure |
555 | | DESCRIPTION |
556 | | This function adds elements to the current point selection for a dataspace |
557 | | GLOBAL VARIABLES |
558 | | COMMENTS, BUGS, ASSUMPTIONS |
559 | | EXAMPLES |
560 | | REVISION LOG |
561 | | --------------------------------------------------------------------------*/ |
562 | | static herr_t |
563 | | H5S__point_add(H5S_t *space, H5S_seloper_t op, size_t num_elem, const hsize_t *coord) |
564 | 687 | { |
565 | 687 | H5S_pnt_node_t *top = NULL, *curr = NULL, *new_node = NULL; /* Point selection nodes */ |
566 | 687 | unsigned u; /* Counter */ |
567 | 687 | herr_t ret_value = SUCCEED; /* Return value */ |
568 | | |
569 | 687 | FUNC_ENTER_PACKAGE |
570 | | |
571 | | /* Sanity checks */ |
572 | 687 | assert(space); |
573 | 687 | assert(num_elem > 0); |
574 | 687 | assert(coord); |
575 | 687 | assert(op == H5S_SELECT_SET || op == H5S_SELECT_APPEND || op == H5S_SELECT_PREPEND); |
576 | | |
577 | 9.17k | for (u = 0; u < num_elem; u++) { |
578 | 8.48k | unsigned dim; /* Counter for dimensions */ |
579 | | |
580 | | /* The following allocation relies on the size of an hcoords_t being |
581 | | * the same as an 'H5S_pnt_node_t *', so fail now if that's not true |
582 | | */ |
583 | 8.48k | HDcompile_assert(sizeof(hcoords_t) >= sizeof(H5S_pnt_node_t *)); |
584 | | |
585 | | /* Allocate space for the new node */ |
586 | | /* Note: allocating "rank + 1" to allow for 'next' pointer */ |
587 | 8.48k | if (NULL == (new_node = (H5S_pnt_node_t *)H5FL_ARR_MALLOC(hcoords_t, space->extent.rank + 1))) |
588 | 0 | HGOTO_ERROR(H5E_DATASPACE, H5E_CANTALLOC, FAIL, "can't allocate point node"); |
589 | | |
590 | | /* Initialize fields in node */ |
591 | 8.48k | new_node->next = NULL; |
592 | | |
593 | | /* Copy over the coordinates */ |
594 | 8.48k | H5MM_memcpy(new_node->pnt, coord + (u * space->extent.rank), (space->extent.rank * sizeof(hsize_t))); |
595 | | |
596 | | /* Link into list */ |
597 | 8.48k | if (top == NULL) |
598 | 687 | top = new_node; |
599 | 7.79k | else |
600 | 7.79k | curr->next = new_node; |
601 | 8.48k | curr = new_node; |
602 | | |
603 | | /* Update bound box */ |
604 | | /* (Note: when op is H5S_SELECT_SET, the bound box has been reset |
605 | | * inside H5S_select_elements, the only caller of this function. |
606 | | * So the following bound box update procedure works correctly |
607 | | * for the SET operation) |
608 | | */ |
609 | 25.3k | for (dim = 0; dim < space->extent.rank; dim++) { |
610 | 16.9k | space->select.sel_info.pnt_lst->low_bounds[dim] = |
611 | 16.9k | MIN(space->select.sel_info.pnt_lst->low_bounds[dim], curr->pnt[dim]); |
612 | 16.9k | space->select.sel_info.pnt_lst->high_bounds[dim] = |
613 | 16.9k | MAX(space->select.sel_info.pnt_lst->high_bounds[dim], curr->pnt[dim]); |
614 | 16.9k | } /* end for */ |
615 | 8.48k | } /* end for */ |
616 | 687 | new_node = NULL; |
617 | | |
618 | | /* Insert the list of points selected in the proper place */ |
619 | 687 | if (op == H5S_SELECT_SET || op == H5S_SELECT_PREPEND) { |
620 | | /* Append current list, if there is one */ |
621 | 687 | if (NULL != space->select.sel_info.pnt_lst->head) |
622 | 0 | curr->next = space->select.sel_info.pnt_lst->head; |
623 | | |
624 | | /* Put new list in point selection */ |
625 | 687 | space->select.sel_info.pnt_lst->head = top; |
626 | | |
627 | | /* Change the tail pointer if tail has not been set */ |
628 | 687 | if (NULL == space->select.sel_info.pnt_lst->tail) |
629 | 687 | space->select.sel_info.pnt_lst->tail = curr; |
630 | 687 | } /* end if */ |
631 | 0 | else { /* op==H5S_SELECT_APPEND */ |
632 | 0 | H5S_pnt_node_t *tmp_node; /* Temporary point selection node */ |
633 | |
|
634 | 0 | tmp_node = space->select.sel_info.pnt_lst->head; |
635 | 0 | if (tmp_node != NULL) { |
636 | 0 | assert(space->select.sel_info.pnt_lst->tail); |
637 | 0 | space->select.sel_info.pnt_lst->tail->next = top; |
638 | 0 | } /* end if */ |
639 | 0 | else |
640 | 0 | space->select.sel_info.pnt_lst->head = top; |
641 | 0 | space->select.sel_info.pnt_lst->tail = curr; |
642 | 0 | } /* end else */ |
643 | | |
644 | | /* Set the number of elements in the new selection */ |
645 | 687 | if (op == H5S_SELECT_SET) |
646 | 687 | space->select.num_elem = num_elem; |
647 | 0 | else |
648 | 0 | space->select.num_elem += num_elem; |
649 | | |
650 | 687 | done: |
651 | 687 | if (ret_value < 0) { |
652 | | /* Release possibly partially initialized new node */ |
653 | 0 | if (new_node) |
654 | 0 | new_node = (H5S_pnt_node_t *)H5FL_ARR_FREE(hcoords_t, new_node); |
655 | | |
656 | | /* Release possible linked list of nodes */ |
657 | 0 | while (top) { |
658 | 0 | curr = top->next; |
659 | 0 | top = (H5S_pnt_node_t *)H5FL_ARR_FREE(hcoords_t, top); |
660 | 0 | top = curr; |
661 | 0 | } /* end while */ |
662 | 0 | } /* end if */ |
663 | | |
664 | 687 | FUNC_LEAVE_NOAPI(ret_value) |
665 | 687 | } /* end H5S__point_add() */ |
666 | | |
667 | | /*-------------------------------------------------------------------------- |
668 | | NAME |
669 | | H5S__point_release |
670 | | PURPOSE |
671 | | Release point selection information for a dataspace |
672 | | USAGE |
673 | | herr_t H5S__point_release(space) |
674 | | H5S_t *space; IN: Pointer to dataspace |
675 | | RETURNS |
676 | | Non-negative on success/Negative on failure |
677 | | DESCRIPTION |
678 | | Releases all point selection information for a dataspace |
679 | | GLOBAL VARIABLES |
680 | | COMMENTS, BUGS, ASSUMPTIONS |
681 | | EXAMPLES |
682 | | REVISION LOG |
683 | | --------------------------------------------------------------------------*/ |
684 | | static herr_t |
685 | | H5S__point_release(H5S_t *space) |
686 | 957 | { |
687 | 957 | FUNC_ENTER_PACKAGE_NOERR |
688 | | |
689 | | /* Check args */ |
690 | 957 | assert(space); |
691 | | |
692 | | /* Free the point list */ |
693 | 957 | H5S__free_pnt_list(space->select.sel_info.pnt_lst); |
694 | | |
695 | | /* Reset the point list header */ |
696 | 957 | space->select.sel_info.pnt_lst = NULL; |
697 | | |
698 | | /* Reset the number of elements in the selection */ |
699 | 957 | space->select.num_elem = 0; |
700 | | |
701 | 957 | FUNC_LEAVE_NOAPI(SUCCEED) |
702 | 957 | } /* end H5S__point_release() */ |
703 | | |
704 | | /*-------------------------------------------------------------------------- |
705 | | NAME |
706 | | H5S_select_elements |
707 | | PURPOSE |
708 | | Specify a series of elements in the dataspace to select |
709 | | USAGE |
710 | | herr_t H5S_select_elements(dsid, op, num_elem, coord) |
711 | | hid_t dsid; IN: Dataspace ID of selection to modify |
712 | | H5S_seloper_t op; IN: Operation to perform on current selection |
713 | | size_t num_elem; IN: Number of elements in COORD array. |
714 | | const hsize_t *coord; IN: The location of each element selected |
715 | | RETURNS |
716 | | Non-negative on success/Negative on failure |
717 | | DESCRIPTION |
718 | | This function selects array elements to be included in the selection for |
719 | | the dataspace. The COORD array is a 2-D array of size <dataspace rank> |
720 | | by NUM_ELEM (ie. a list of coordinates in the dataspace). The order of |
721 | | the element coordinates in the COORD array specifies the order that the |
722 | | array elements are iterated through when I/O is performed. Duplicate |
723 | | coordinates are not checked for. The selection operator, OP, determines |
724 | | how the new selection is to be combined with the existing selection for |
725 | | the dataspace. |
726 | | GLOBAL VARIABLES |
727 | | COMMENTS, BUGS, ASSUMPTIONS |
728 | | EXAMPLES |
729 | | REVISION LOG |
730 | | --------------------------------------------------------------------------*/ |
731 | | herr_t |
732 | | H5S_select_elements(H5S_t *space, H5S_seloper_t op, size_t num_elem, const hsize_t *coord) |
733 | 687 | { |
734 | 687 | herr_t ret_value = SUCCEED; /* Return value */ |
735 | | |
736 | 687 | FUNC_ENTER_NOAPI(FAIL) |
737 | | |
738 | | /* Check args */ |
739 | 687 | assert(space); |
740 | 687 | assert(num_elem); |
741 | 687 | assert(coord); |
742 | 687 | assert(op == H5S_SELECT_SET || op == H5S_SELECT_APPEND || op == H5S_SELECT_PREPEND); |
743 | | |
744 | | /* If we are setting a new selection, remove current selection first */ |
745 | 687 | if (op == H5S_SELECT_SET || H5S_GET_SELECT_TYPE(space) != H5S_SEL_POINTS) |
746 | 687 | if (H5S_SELECT_RELEASE(space) < 0) |
747 | 0 | HGOTO_ERROR(H5E_DATASPACE, H5E_CANTDELETE, FAIL, "can't release point selection"); |
748 | | |
749 | | /* Allocate space for the point selection information if necessary */ |
750 | 687 | if (H5S_GET_SELECT_TYPE(space) != H5S_SEL_POINTS || space->select.sel_info.pnt_lst == NULL) { |
751 | 687 | hsize_t tmp = HSIZET_MAX; |
752 | | |
753 | 687 | if (NULL == (space->select.sel_info.pnt_lst = H5FL_CALLOC(H5S_pnt_list_t))) |
754 | 0 | HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "can't allocate element information"); |
755 | | |
756 | | /* Set the bound box to the default value */ |
757 | 687 | H5VM_array_fill(space->select.sel_info.pnt_lst->low_bounds, &tmp, sizeof(hsize_t), |
758 | 687 | space->extent.rank); |
759 | 687 | memset(space->select.sel_info.pnt_lst->high_bounds, 0, sizeof(hsize_t) * space->extent.rank); |
760 | 687 | } |
761 | | |
762 | | /* Add points to selection */ |
763 | 687 | if (H5S__point_add(space, op, num_elem, coord) < 0) |
764 | 0 | HGOTO_ERROR(H5E_DATASPACE, H5E_CANTINSERT, FAIL, "can't insert elements"); |
765 | | |
766 | | /* Set selection type */ |
767 | 687 | space->select.type = H5S_sel_point; |
768 | | |
769 | 687 | done: |
770 | 687 | FUNC_LEAVE_NOAPI(ret_value) |
771 | 687 | } /* end H5S_select_elements() */ |
772 | | |
773 | | /*-------------------------------------------------------------------------- |
774 | | NAME |
775 | | H5S__copy_pnt_list |
776 | | PURPOSE |
777 | | Copy a point selection list |
778 | | USAGE |
779 | | H5S_pnt_list_t *H5S__copy_pnt_list(src) |
780 | | const H5S_pnt_list_t *src; IN: Pointer to the source point list |
781 | | unsigned rank; IN: # of dimensions for points |
782 | | RETURNS |
783 | | Non-NULL pointer to new point list on success / NULL on failure |
784 | | DESCRIPTION |
785 | | Copies point selection information from the source point list to newly |
786 | | created point list. |
787 | | GLOBAL VARIABLES |
788 | | COMMENTS, BUGS, ASSUMPTIONS |
789 | | EXAMPLES |
790 | | REVISION LOG |
791 | | --------------------------------------------------------------------------*/ |
792 | | static H5S_pnt_list_t * |
793 | | H5S__copy_pnt_list(const H5S_pnt_list_t *src, unsigned rank) |
794 | 270 | { |
795 | 270 | H5S_pnt_list_t *dst = NULL; /* New point list */ |
796 | 270 | H5S_pnt_node_t *curr, *new_tail; /* Point information nodes */ |
797 | 270 | H5S_pnt_list_t *ret_value = NULL; /* Return value */ |
798 | | |
799 | 270 | FUNC_ENTER_PACKAGE |
800 | | |
801 | | /* Sanity checks */ |
802 | 270 | assert(src); |
803 | 270 | assert(rank > 0); |
804 | | |
805 | | /* Allocate room for the head of the point list */ |
806 | 270 | if (NULL == (dst = H5FL_CALLOC(H5S_pnt_list_t))) |
807 | 0 | HGOTO_ERROR(H5E_DATASPACE, H5E_CANTALLOC, NULL, "can't allocate point list node"); |
808 | | |
809 | 270 | curr = src->head; |
810 | 270 | new_tail = NULL; |
811 | 4.41k | while (curr) { |
812 | 4.14k | H5S_pnt_node_t *new_node; /* New point information node */ |
813 | | |
814 | | /* The following allocation relies on the size of an hcoords_t being |
815 | | * the same as an 'H5S_pnt_node_t *', so fail now if that's not true |
816 | | */ |
817 | 4.14k | HDcompile_assert(sizeof(hcoords_t) >= sizeof(H5S_pnt_node_t *)); |
818 | | |
819 | | /* Create new point */ |
820 | | /* Note: allocating "rank + 1" to allow for 'next' pointer */ |
821 | 4.14k | if (NULL == (new_node = (H5S_pnt_node_t *)H5FL_ARR_MALLOC(hcoords_t, rank + 1))) |
822 | 0 | HGOTO_ERROR(H5E_DATASPACE, H5E_CANTALLOC, NULL, "can't allocate point node"); |
823 | 4.14k | new_node->next = NULL; |
824 | | |
825 | | /* Copy over the point's coordinates */ |
826 | 4.14k | H5MM_memcpy(new_node->pnt, curr->pnt, (rank * sizeof(hsize_t))); |
827 | | |
828 | | /* Keep the order the same when copying */ |
829 | 4.14k | if (NULL == new_tail) |
830 | 270 | new_tail = dst->head = new_node; |
831 | 3.87k | else { |
832 | 3.87k | new_tail->next = new_node; |
833 | 3.87k | new_tail = new_node; |
834 | 3.87k | } /* end else */ |
835 | | |
836 | 4.14k | curr = curr->next; |
837 | 4.14k | } /* end while */ |
838 | 270 | dst->tail = new_tail; |
839 | | |
840 | | /* Copy the selection bounds */ |
841 | 270 | H5MM_memcpy(dst->high_bounds, src->high_bounds, (rank * sizeof(hsize_t))); |
842 | 270 | H5MM_memcpy(dst->low_bounds, src->low_bounds, (rank * sizeof(hsize_t))); |
843 | | |
844 | | /* Clear cached iteration point */ |
845 | 270 | dst->last_idx = 0; |
846 | 270 | dst->last_idx_pnt = NULL; |
847 | | |
848 | | /* Set return value */ |
849 | 270 | ret_value = dst; |
850 | | |
851 | 270 | done: |
852 | 270 | if (NULL == ret_value && dst) |
853 | 0 | H5S__free_pnt_list(dst); |
854 | | |
855 | 270 | FUNC_LEAVE_NOAPI(ret_value) |
856 | 270 | } /* end H5S__copy_pnt_list() */ |
857 | | |
858 | | /*-------------------------------------------------------------------------- |
859 | | NAME |
860 | | H5S__free_pnt_list |
861 | | PURPOSE |
862 | | Free a point selection list |
863 | | USAGE |
864 | | void H5S__free_pnt_list(pnt_lst) |
865 | | H5S_pnt_list_t *pnt_lst; IN: Pointer to the point list to free |
866 | | RETURNS |
867 | | None |
868 | | DESCRIPTION |
869 | | Frees point selection information from the point list |
870 | | GLOBAL VARIABLES |
871 | | COMMENTS, BUGS, ASSUMPTIONS |
872 | | EXAMPLES |
873 | | REVISION LOG |
874 | | --------------------------------------------------------------------------*/ |
875 | | static void |
876 | | H5S__free_pnt_list(H5S_pnt_list_t *pnt_lst) |
877 | 957 | { |
878 | 957 | H5S_pnt_node_t *curr; /* Point information nodes */ |
879 | | |
880 | 957 | FUNC_ENTER_PACKAGE_NOERR |
881 | | |
882 | | /* Sanity checks */ |
883 | 957 | assert(pnt_lst); |
884 | | |
885 | | /* Traverse the list, freeing all memory */ |
886 | 957 | curr = pnt_lst->head; |
887 | 13.5k | while (curr) { |
888 | 12.6k | H5S_pnt_node_t *tmp_node = curr; |
889 | | |
890 | 12.6k | curr = curr->next; |
891 | 12.6k | tmp_node = (H5S_pnt_node_t *)H5FL_ARR_FREE(hcoords_t, tmp_node); |
892 | 12.6k | } /* end while */ |
893 | | |
894 | 957 | H5FL_FREE(H5S_pnt_list_t, pnt_lst); |
895 | | |
896 | 957 | FUNC_LEAVE_NOAPI_VOID |
897 | 957 | } /* end H5S__free_pnt_list() */ |
898 | | |
899 | | /*-------------------------------------------------------------------------- |
900 | | NAME |
901 | | H5S__point_copy |
902 | | PURPOSE |
903 | | Copy a selection from one dataspace to another |
904 | | USAGE |
905 | | herr_t H5S__point_copy(dst, src, share_selection) |
906 | | H5S_t *dst; OUT: Pointer to the destination dataspace |
907 | | H5S_t *src; IN: Pointer to the source dataspace |
908 | | bool share_selection; IN: Whether to share the selection between the dataspaces |
909 | | RETURNS |
910 | | Non-negative on success/Negative on failure |
911 | | DESCRIPTION |
912 | | Copies all the point selection information from the source |
913 | | dataspace to the destination dataspace. |
914 | | GLOBAL VARIABLES |
915 | | COMMENTS, BUGS, ASSUMPTIONS |
916 | | EXAMPLES |
917 | | REVISION LOG |
918 | | --------------------------------------------------------------------------*/ |
919 | | static herr_t |
920 | | H5S__point_copy(H5S_t *dst, const H5S_t *src, bool H5_ATTR_UNUSED share_selection) |
921 | 270 | { |
922 | 270 | herr_t ret_value = SUCCEED; /* Return value */ |
923 | | |
924 | 270 | FUNC_ENTER_PACKAGE |
925 | | |
926 | | /* Sanity checks */ |
927 | 270 | assert(src); |
928 | 270 | assert(dst); |
929 | | |
930 | | /* Allocate room for the head of the point list */ |
931 | 270 | if (NULL == |
932 | 270 | (dst->select.sel_info.pnt_lst = H5S__copy_pnt_list(src->select.sel_info.pnt_lst, src->extent.rank))) |
933 | 0 | HGOTO_ERROR(H5E_DATASPACE, H5E_CANTCOPY, FAIL, "can't copy point list"); |
934 | | |
935 | 270 | done: |
936 | 270 | FUNC_LEAVE_NOAPI(ret_value) |
937 | 270 | } /* end H5S__point_copy() */ |
938 | | |
939 | | /*-------------------------------------------------------------------------- |
940 | | NAME |
941 | | H5S__point_is_valid |
942 | | PURPOSE |
943 | | Check whether the selection fits within the extent, with the current |
944 | | offset defined. |
945 | | USAGE |
946 | | htri_t H5S__point_is_valid(space); |
947 | | const H5S_t *space; IN: Dataspace pointer to query |
948 | | RETURNS |
949 | | true if the selection fits within the extent, false if it does not and |
950 | | Negative on an error. |
951 | | DESCRIPTION |
952 | | Determines if the current selection at the current offset fits within the |
953 | | extent for the dataspace. |
954 | | GLOBAL VARIABLES |
955 | | COMMENTS, BUGS, ASSUMPTIONS |
956 | | EXAMPLES |
957 | | REVISION LOG |
958 | | --------------------------------------------------------------------------*/ |
959 | | static htri_t |
960 | | H5S__point_is_valid(const H5S_t *space) |
961 | 686 | { |
962 | 686 | unsigned u; /* Counter */ |
963 | 686 | htri_t ret_value = true; /* Return value */ |
964 | | |
965 | 686 | FUNC_ENTER_PACKAGE_NOERR |
966 | | |
967 | 686 | assert(space); |
968 | | |
969 | | /* Check each dimension */ |
970 | 2.05k | for (u = 0; u < space->extent.rank; u++) { |
971 | | /* Bounds check the selected point + offset against the extent */ |
972 | 1.37k | if ((space->select.sel_info.pnt_lst->high_bounds[u] + (hsize_t)space->select.offset[u]) > |
973 | 1.37k | space->extent.size[u]) |
974 | 0 | HGOTO_DONE(false); |
975 | 1.37k | if (((hssize_t)space->select.sel_info.pnt_lst->low_bounds[u] + space->select.offset[u]) < 0) |
976 | 0 | HGOTO_DONE(false); |
977 | 1.37k | } /* end for */ |
978 | | |
979 | 686 | done: |
980 | 686 | FUNC_LEAVE_NOAPI(ret_value) |
981 | 686 | } /* end H5S__point_is_valid() */ |
982 | | |
983 | | /*-------------------------------------------------------------------------- |
984 | | NAME |
985 | | H5Sget_select_elem_npoints |
986 | | PURPOSE |
987 | | Get the number of points in current element selection |
988 | | USAGE |
989 | | hssize_t H5Sget_select_elem_npoints(dsid) |
990 | | hid_t dsid; IN: Dataspace ID of selection to query |
991 | | RETURNS |
992 | | The number of element points in selection on success, negative on failure |
993 | | DESCRIPTION |
994 | | Returns the number of element points in current selection for dataspace. |
995 | | GLOBAL VARIABLES |
996 | | COMMENTS, BUGS, ASSUMPTIONS |
997 | | EXAMPLES |
998 | | REVISION LOG |
999 | | --------------------------------------------------------------------------*/ |
1000 | | hssize_t |
1001 | | H5Sget_select_elem_npoints(hid_t spaceid) |
1002 | 0 | { |
1003 | 0 | H5S_t *space; /* Dataspace to modify selection of */ |
1004 | 0 | hssize_t ret_value; /* return value */ |
1005 | |
|
1006 | 0 | FUNC_ENTER_API(FAIL) |
1007 | | |
1008 | | /* Check args */ |
1009 | 0 | if (NULL == (space = (H5S_t *)H5I_object_verify(spaceid, H5I_DATASPACE))) |
1010 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a dataspace"); |
1011 | 0 | if (H5S_GET_SELECT_TYPE(space) != H5S_SEL_POINTS) |
1012 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not an element selection"); |
1013 | | |
1014 | 0 | ret_value = (hssize_t)H5S_GET_SELECT_NPOINTS(space); |
1015 | |
|
1016 | 0 | done: |
1017 | 0 | FUNC_LEAVE_API(ret_value) |
1018 | 0 | } /* end H5Sget_select_elem_npoints() */ |
1019 | | |
1020 | | /*-------------------------------------------------------------------------- |
1021 | | NAME |
1022 | | H5S__point_get_version_enc_size |
1023 | | PURPOSE |
1024 | | Determine the version and the size (2, 4 or 8 bytes) to encode point selection info |
1025 | | USAGE |
1026 | | hssize_t H5S__point_get_version_enc_size(space, version, enc_size) |
1027 | | const H5S_t *space: IN: Dataspace ID of selection to query |
1028 | | uint32_t *version: OUT: The version to use for encoding |
1029 | | uint8_t *enc_size: OUT: The size to use for encoding |
1030 | | RETURNS |
1031 | | The version and the size to encode point selection info |
1032 | | DESCRIPTION |
1033 | | Determine the version to use for encoding points selection info based |
1034 | | on the following: |
1035 | | (1) the low/high bounds setting in fapl |
1036 | | (2) whether the number of points or selection high bounds exceeds H5S_UINT32_MAX or not |
1037 | | |
1038 | | Determine the encoded size based on version: |
1039 | | --For version 2, the encoded size of point selection info is determined |
1040 | | by the maximum size for: |
1041 | | (a) storing the number of points |
1042 | | (b) storing the selection high bounds |
1043 | | |
1044 | | GLOBAL VARIABLES |
1045 | | COMMENTS, BUGS, ASSUMPTIONS |
1046 | | EXAMPLES |
1047 | | REVISION LOG |
1048 | | --------------------------------------------------------------------------*/ |
1049 | | static herr_t |
1050 | | H5S__point_get_version_enc_size(const H5S_t *space, uint32_t *version, uint8_t *enc_size) |
1051 | 0 | { |
1052 | 0 | bool count_up_version = false; /* Whether number of points exceed H5S_UINT32_MAX */ |
1053 | 0 | bool bound_up_version = false; /* Whether high bounds exceed H5S_UINT32_MAX */ |
1054 | 0 | H5F_libver_t low_bound; /* The 'low' bound of library format versions */ |
1055 | 0 | H5F_libver_t high_bound; /* The 'high' bound of library format versions */ |
1056 | 0 | uint32_t tmp_version; /* Local temporary version */ |
1057 | 0 | hsize_t bounds_start[H5S_MAX_RANK]; /* Starting coordinate of bounding box */ |
1058 | 0 | hsize_t bounds_end[H5S_MAX_RANK]; /* Opposite coordinate of bounding box */ |
1059 | 0 | hsize_t max_size = 0; /* Maximum selection size */ |
1060 | 0 | unsigned u; /* Local index variable */ |
1061 | 0 | herr_t ret_value = SUCCEED; /* Return value */ |
1062 | |
|
1063 | 0 | FUNC_ENTER_PACKAGE |
1064 | | |
1065 | | /* Get bounding box for the selection */ |
1066 | 0 | memset(bounds_end, 0, sizeof(bounds_end)); |
1067 | 0 | if (H5S__point_bounds(space, bounds_start, bounds_end) < 0) |
1068 | 0 | HGOTO_ERROR(H5E_DATASPACE, H5E_CANTGET, FAIL, "can't get selection bounds"); |
1069 | | |
1070 | | /* Determine whether number of points or high bounds exceeds (2^32 - 1) */ |
1071 | 0 | if (space->select.num_elem > H5S_UINT32_MAX) |
1072 | 0 | count_up_version = true; |
1073 | 0 | else |
1074 | 0 | for (u = 0; u < space->extent.rank; u++) |
1075 | 0 | if (bounds_end[u] > H5S_UINT32_MAX) { |
1076 | 0 | bound_up_version = true; |
1077 | 0 | break; |
1078 | 0 | } /* end if */ |
1079 | | |
1080 | | /* If exceed (2^32 -1) */ |
1081 | 0 | if (count_up_version || bound_up_version) |
1082 | 0 | tmp_version = H5S_POINT_VERSION_2; |
1083 | 0 | else |
1084 | 0 | tmp_version = H5S_POINT_VERSION_1; |
1085 | | |
1086 | | /* Get the file's low/high bounds */ |
1087 | 0 | if (H5CX_get_libver_bounds(&low_bound, &high_bound) < 0) |
1088 | 0 | HGOTO_ERROR(H5E_DATASET, H5E_CANTGET, FAIL, "can't get low/high bounds from API context"); |
1089 | | |
1090 | | /* Upgrade to the version indicated by the file's low bound if higher */ |
1091 | 0 | tmp_version = MAX(tmp_version, H5O_sds_point_ver_bounds[low_bound]); |
1092 | | |
1093 | | /* Version bounds check */ |
1094 | 0 | if (tmp_version > H5O_sds_point_ver_bounds[high_bound]) { |
1095 | 0 | if (count_up_version) |
1096 | 0 | HGOTO_ERROR(H5E_DATASPACE, H5E_BADVALUE, FAIL, |
1097 | 0 | "The number of points in point selection exceeds 2^32"); |
1098 | 0 | else if (bound_up_version) |
1099 | 0 | HGOTO_ERROR(H5E_DATASPACE, H5E_BADVALUE, FAIL, |
1100 | 0 | "The end of bounding box in point selection exceeds 2^32"); |
1101 | 0 | else |
1102 | 0 | HGOTO_ERROR(H5E_DATASPACE, H5E_BADRANGE, FAIL, "Dataspace point selection version out of bounds"); |
1103 | 0 | } /* end if */ |
1104 | | |
1105 | | /* Set the version to return */ |
1106 | 0 | *version = tmp_version; |
1107 | | |
1108 | | /* Get the encoded size use based on version */ |
1109 | 0 | switch (tmp_version) { |
1110 | 0 | case H5S_POINT_VERSION_1: |
1111 | 0 | *enc_size = H5S_SELECT_INFO_ENC_SIZE_4; |
1112 | 0 | break; |
1113 | | |
1114 | 0 | case H5S_POINT_VERSION_2: |
1115 | | /* Find max for num_elem and bounds_end[] */ |
1116 | 0 | max_size = space->select.num_elem; |
1117 | 0 | for (u = 0; u < space->extent.rank; u++) |
1118 | 0 | if (bounds_end[u] > max_size) |
1119 | 0 | max_size = bounds_end[u]; |
1120 | | |
1121 | | /* Determine the encoding size */ |
1122 | 0 | if (max_size > H5S_UINT32_MAX) |
1123 | 0 | *enc_size = H5S_SELECT_INFO_ENC_SIZE_8; |
1124 | 0 | else if (max_size > H5S_UINT16_MAX) |
1125 | 0 | *enc_size = H5S_SELECT_INFO_ENC_SIZE_4; |
1126 | 0 | else |
1127 | 0 | *enc_size = H5S_SELECT_INFO_ENC_SIZE_2; |
1128 | 0 | break; |
1129 | | |
1130 | 0 | default: |
1131 | 0 | HGOTO_ERROR(H5E_DATASPACE, H5E_UNSUPPORTED, FAIL, "unknown point info size"); |
1132 | 0 | break; |
1133 | 0 | } /* end switch */ |
1134 | | |
1135 | 0 | done: |
1136 | 0 | FUNC_LEAVE_NOAPI(ret_value) |
1137 | 0 | } /* H5S__point_get_version_enc_size() */ |
1138 | | |
1139 | | /*-------------------------------------------------------------------------- |
1140 | | NAME |
1141 | | H5S__point_serial_size |
1142 | | PURPOSE |
1143 | | Determine the number of bytes needed to store the serialized point selection |
1144 | | information. |
1145 | | USAGE |
1146 | | hssize_t H5S__point_serial_size(space) |
1147 | | const H5S_t *space; IN: Dataspace pointer to query |
1148 | | RETURNS |
1149 | | The number of bytes required on success, negative on an error. |
1150 | | DESCRIPTION |
1151 | | Determines the number of bytes required to serialize the current point |
1152 | | selection information for storage on disk. |
1153 | | GLOBAL VARIABLES |
1154 | | COMMENTS, BUGS, ASSUMPTIONS |
1155 | | EXAMPLES |
1156 | | REVISION LOG |
1157 | | --------------------------------------------------------------------------*/ |
1158 | | static hssize_t |
1159 | | H5S__point_serial_size(H5S_t *space) |
1160 | 0 | { |
1161 | 0 | uint32_t version; /* Version number */ |
1162 | 0 | uint8_t enc_size; /* Encoded size of point selection info */ |
1163 | 0 | hssize_t ret_value = -1; /* Return value */ |
1164 | |
|
1165 | 0 | FUNC_ENTER_PACKAGE |
1166 | |
|
1167 | 0 | assert(space); |
1168 | | |
1169 | | /* Determine the version and encoded size for point selection */ |
1170 | 0 | if (H5S__point_get_version_enc_size(space, &version, &enc_size) < 0) |
1171 | 0 | HGOTO_ERROR(H5E_DATASPACE, H5E_CANTGET, FAIL, "can't determine version and enc_size"); |
1172 | | |
1173 | | /* Basic number of bytes required to serialize point selection: */ |
1174 | 0 | if (version >= H5S_POINT_VERSION_2) |
1175 | | /* |
1176 | | * <type (4 bytes)> + <version (4 bytes)> + |
1177 | | * <size of point info (1 byte)> + rank (4 bytes)> |
1178 | | */ |
1179 | 0 | ret_value = 13; |
1180 | 0 | else |
1181 | | /* |
1182 | | * <type (4 bytes)> + <version (4 bytes)> + <padding (4 bytes)> + |
1183 | | * <length (4 bytes)> + <rank (4 bytes)> |
1184 | | */ |
1185 | 0 | ret_value = 20; |
1186 | | |
1187 | | /* <num points (depend on enc_size)> */ |
1188 | 0 | ret_value += enc_size; |
1189 | | |
1190 | | /* Count points in selection */ |
1191 | 0 | ret_value += (hssize_t)(enc_size * space->extent.rank * space->select.num_elem); |
1192 | |
|
1193 | 0 | done: |
1194 | 0 | FUNC_LEAVE_NOAPI(ret_value) |
1195 | 0 | } /* end H5S__point_serial_size() */ |
1196 | | |
1197 | | /*-------------------------------------------------------------------------- |
1198 | | NAME |
1199 | | H5S__point_serialize |
1200 | | PURPOSE |
1201 | | Serialize the current selection into a user-provided buffer. |
1202 | | USAGE |
1203 | | herr_t H5S__point_serialize(space, p) |
1204 | | H5S_t *space; IN: Dataspace with selection to serialize |
1205 | | uint8_t **p; OUT: Pointer to buffer to put serialized |
1206 | | selection. Will be advanced to end of |
1207 | | serialized selection. |
1208 | | RETURNS |
1209 | | Non-negative on success/Negative on failure |
1210 | | DESCRIPTION |
1211 | | Serializes the current element selection into a buffer. (Primarily for |
1212 | | storing on disk). |
1213 | | GLOBAL VARIABLES |
1214 | | COMMENTS, BUGS, ASSUMPTIONS |
1215 | | EXAMPLES |
1216 | | REVISION LOG |
1217 | | --------------------------------------------------------------------------*/ |
1218 | | static herr_t |
1219 | | H5S__point_serialize(H5S_t *space, uint8_t **p) |
1220 | 0 | { |
1221 | 0 | H5S_pnt_node_t *curr; /* Point information nodes */ |
1222 | 0 | uint8_t *pp; /* Local pointer for encoding */ |
1223 | 0 | uint8_t *lenp = NULL; /* pointer to length location for later storage */ |
1224 | 0 | uint32_t len = 0; /* number of bytes used */ |
1225 | 0 | unsigned u; /* local counting variable */ |
1226 | 0 | uint32_t version; /* Version number */ |
1227 | 0 | uint8_t enc_size; /* Encoded size of point selection info */ |
1228 | 0 | herr_t ret_value = SUCCEED; /* Return value */ |
1229 | |
|
1230 | 0 | FUNC_ENTER_PACKAGE |
1231 | | |
1232 | | /* Check args */ |
1233 | 0 | assert(space); |
1234 | 0 | assert(p); |
1235 | 0 | pp = (*p); |
1236 | 0 | assert(pp); |
1237 | | |
1238 | | /* Determine the version and encoded size for point selection info */ |
1239 | 0 | if (H5S__point_get_version_enc_size(space, &version, &enc_size) < 0) |
1240 | 0 | HGOTO_ERROR(H5E_DATASPACE, H5E_CANTGET, FAIL, "can't determine version and enc_size"); |
1241 | | |
1242 | | /* Store the preamble information */ |
1243 | 0 | UINT32ENCODE(pp, (uint32_t)H5S_GET_SELECT_TYPE(space)); /* Store the type of selection */ |
1244 | |
|
1245 | 0 | UINT32ENCODE(pp, version); /* Store the version number */ |
1246 | 0 | if (version >= 2) { |
1247 | 0 | *(pp)++ = enc_size; /* Store size of point info */ |
1248 | 0 | } |
1249 | 0 | else { |
1250 | 0 | assert(version == H5S_POINT_VERSION_1); |
1251 | 0 | UINT32ENCODE(pp, (uint32_t)0); /* Store the un-used padding */ |
1252 | 0 | lenp = pp; /* Keep the pointer to the length location for later */ |
1253 | 0 | pp += 4; /* Skip over space for length */ |
1254 | 0 | len += 8; /* Add in advance # of bytes for num of dimensions and num elements */ |
1255 | 0 | } |
1256 | | |
1257 | | /* Encode number of dimensions */ |
1258 | 0 | UINT32ENCODE(pp, (uint32_t)space->extent.rank); |
1259 | |
|
1260 | 0 | switch (enc_size) { |
1261 | 0 | case H5S_SELECT_INFO_ENC_SIZE_2: |
1262 | 0 | assert(version == H5S_POINT_VERSION_2); |
1263 | | |
1264 | | /* Encode number of elements */ |
1265 | 0 | UINT16ENCODE(pp, (uint16_t)space->select.num_elem); |
1266 | | |
1267 | | /* Encode each point in selection */ |
1268 | 0 | curr = space->select.sel_info.pnt_lst->head; |
1269 | 0 | while (curr != NULL) { |
1270 | | /* Encode each point */ |
1271 | 0 | for (u = 0; u < space->extent.rank; u++) |
1272 | 0 | UINT16ENCODE(pp, (uint16_t)curr->pnt[u]); |
1273 | 0 | curr = curr->next; |
1274 | 0 | } /* end while */ |
1275 | 0 | break; |
1276 | | |
1277 | 0 | case H5S_SELECT_INFO_ENC_SIZE_4: |
1278 | 0 | assert(version == H5S_POINT_VERSION_1 || version == H5S_POINT_VERSION_2); |
1279 | | |
1280 | | /* Encode number of elements */ |
1281 | 0 | UINT32ENCODE(pp, (uint32_t)space->select.num_elem); |
1282 | | |
1283 | | /* Encode each point in selection */ |
1284 | 0 | curr = space->select.sel_info.pnt_lst->head; |
1285 | 0 | while (curr != NULL) { |
1286 | | /* Encode each point */ |
1287 | 0 | for (u = 0; u < space->extent.rank; u++) |
1288 | 0 | UINT32ENCODE(pp, (uint32_t)curr->pnt[u]); |
1289 | 0 | curr = curr->next; |
1290 | 0 | } /* end while */ |
1291 | | |
1292 | | /* Add 4 bytes times the rank for each element selected */ |
1293 | 0 | if (version == H5S_POINT_VERSION_1) |
1294 | 0 | len += (uint32_t)space->select.num_elem * 4 * space->extent.rank; |
1295 | 0 | break; |
1296 | | |
1297 | 0 | case H5S_SELECT_INFO_ENC_SIZE_8: |
1298 | 0 | assert(version == H5S_POINT_VERSION_2); |
1299 | | |
1300 | | /* Encode number of elements */ |
1301 | 0 | UINT64ENCODE(pp, space->select.num_elem); |
1302 | | |
1303 | | /* Encode each point in selection */ |
1304 | 0 | curr = space->select.sel_info.pnt_lst->head; |
1305 | 0 | while (curr != NULL) { |
1306 | | /* Encode each point */ |
1307 | 0 | for (u = 0; u < space->extent.rank; u++) |
1308 | 0 | UINT64ENCODE(pp, curr->pnt[u]); |
1309 | 0 | curr = curr->next; |
1310 | 0 | } /* end while */ |
1311 | 0 | break; |
1312 | | |
1313 | 0 | default: |
1314 | 0 | HGOTO_ERROR(H5E_DATASPACE, H5E_UNSUPPORTED, FAIL, "unknown point info size"); |
1315 | 0 | break; |
1316 | |
|
1317 | 0 | } /* end switch */ |
1318 | | |
1319 | 0 | if (version == H5S_POINT_VERSION_1) |
1320 | 0 | UINT32ENCODE(lenp, (uint32_t)len); /* Store the length of the extra information */ |
1321 | | |
1322 | | /* Update encoding pointer */ |
1323 | 0 | *p = pp; |
1324 | |
|
1325 | 0 | done: |
1326 | 0 | FUNC_LEAVE_NOAPI(ret_value) |
1327 | 0 | } /* H5S__point_serialize() */ |
1328 | | |
1329 | | /*-------------------------------------------------------------------------- |
1330 | | NAME |
1331 | | H5S__point_deserialize |
1332 | | PURPOSE |
1333 | | Deserialize the current selection from a user-provided buffer. |
1334 | | USAGE |
1335 | | herr_t H5S__point_deserialize(space, p) |
1336 | | H5S_t **space; IN/OUT: Dataspace pointer to place |
1337 | | selection into |
1338 | | uint8 **p; OUT: Pointer to buffer holding serialized |
1339 | | selection. Will be advanced to end of |
1340 | | serialized selection. |
1341 | | RETURNS |
1342 | | Non-negative on success/Negative on failure |
1343 | | DESCRIPTION |
1344 | | Deserializes the current selection into a buffer. (Primarily for retrieving |
1345 | | from disk). |
1346 | | GLOBAL VARIABLES |
1347 | | COMMENTS, BUGS, ASSUMPTIONS |
1348 | | EXAMPLES |
1349 | | REVISION LOG |
1350 | | --------------------------------------------------------------------------*/ |
1351 | | static herr_t |
1352 | | H5S__point_deserialize(H5S_t **space, const uint8_t **p, const size_t p_size, bool skip) |
1353 | 0 | { |
1354 | 0 | H5S_t *tmp_space = NULL; /* Pointer to actual dataspace to use, |
1355 | | either *space or a newly allocated one */ |
1356 | 0 | hsize_t dims[H5S_MAX_RANK]; /* Dimension sizes */ |
1357 | 0 | uint32_t version; /* Version number */ |
1358 | 0 | uint8_t enc_size = 0; /* Encoded size of selection info */ |
1359 | 0 | hsize_t *coord = NULL, *tcoord; /* Pointer to array of elements */ |
1360 | 0 | const uint8_t *pp; /* Local pointer for decoding */ |
1361 | 0 | uint64_t num_elem = 0; /* Number of elements in selection */ |
1362 | 0 | unsigned rank; /* Rank of points */ |
1363 | 0 | unsigned i, j; /* local counting variables */ |
1364 | 0 | size_t enc_type_size; |
1365 | 0 | size_t coordinate_buffer_requirement; |
1366 | 0 | herr_t ret_value = SUCCEED; /* Return value */ |
1367 | 0 | const uint8_t *p_end; |
1368 | |
|
1369 | 0 | FUNC_ENTER_PACKAGE |
1370 | | |
1371 | | /* Check args */ |
1372 | 0 | assert(p); |
1373 | 0 | pp = (*p); |
1374 | 0 | assert(pp); |
1375 | |
|
1376 | 0 | if (skip) |
1377 | 0 | p_end = *p; |
1378 | 0 | else if (p_size == 0) |
1379 | 0 | HGOTO_ERROR(H5E_DATASPACE, H5E_OVERFLOW, FAIL, "empty point selection buffer"); |
1380 | 0 | else |
1381 | 0 | p_end = *p + p_size - 1; /* Pointer to last valid byte in buffer */ |
1382 | | |
1383 | | /* As part of the efforts to push all selection-type specific coding |
1384 | | to the callbacks, the coding for the allocation of a null dataspace |
1385 | | is moved from H5S_select_deserialize() in H5Sselect.c to here. |
1386 | | This is needed for decoding virtual layout in H5O__layout_decode() */ |
1387 | | /* Allocate space if not provided */ |
1388 | 0 | if (!*space) { |
1389 | 0 | if (NULL == (tmp_space = H5S_create(H5S_SIMPLE))) |
1390 | 0 | HGOTO_ERROR(H5E_DATASPACE, H5E_CANTCREATE, FAIL, "can't create dataspace"); |
1391 | 0 | } /* end if */ |
1392 | 0 | else |
1393 | 0 | tmp_space = *space; |
1394 | | |
1395 | | /* Decode version */ |
1396 | 0 | if (H5_IS_KNOWN_BUFFER_OVERFLOW(skip, pp, sizeof(uint32_t), p_end)) |
1397 | 0 | HGOTO_ERROR(H5E_DATASPACE, H5E_OVERFLOW, FAIL, "buffer overflow while decoding selection version"); |
1398 | 0 | UINT32DECODE(pp, version); |
1399 | |
|
1400 | 0 | if (version < H5S_POINT_VERSION_1 || version > H5S_POINT_VERSION_LATEST) |
1401 | 0 | HGOTO_ERROR(H5E_DATASPACE, H5E_BADVALUE, FAIL, "bad version number for point selection"); |
1402 | | |
1403 | 0 | if (version >= (uint32_t)H5S_POINT_VERSION_2) { |
1404 | | /* Decode size of point info */ |
1405 | 0 | if (H5_IS_KNOWN_BUFFER_OVERFLOW(skip, pp, 1, p_end)) |
1406 | 0 | HGOTO_ERROR(H5E_DATASPACE, H5E_OVERFLOW, FAIL, "buffer overflow while decoding point info"); |
1407 | 0 | enc_size = *(pp)++; |
1408 | 0 | } |
1409 | 0 | else { |
1410 | | /* Skip over the remainder of the header */ |
1411 | 0 | if (H5_IS_KNOWN_BUFFER_OVERFLOW(skip, pp, 8, p_end)) |
1412 | 0 | HGOTO_ERROR(H5E_DATASPACE, H5E_OVERFLOW, FAIL, |
1413 | 0 | "buffer overflow while decoding selection headers"); |
1414 | 0 | pp += 8; |
1415 | 0 | enc_size = H5S_SELECT_INFO_ENC_SIZE_4; |
1416 | 0 | } |
1417 | | |
1418 | | /* Check encoded size */ |
1419 | 0 | if (enc_size & ~H5S_SELECT_INFO_ENC_SIZE_BITS) |
1420 | 0 | HGOTO_ERROR(H5E_DATASPACE, H5E_CANTLOAD, FAIL, "unknown size of point/offset info for selection"); |
1421 | | |
1422 | | /* Decode the rank of the point selection */ |
1423 | 0 | if (H5_IS_KNOWN_BUFFER_OVERFLOW(skip, pp, sizeof(uint32_t), p_end)) |
1424 | 0 | HGOTO_ERROR(H5E_DATASPACE, H5E_OVERFLOW, FAIL, "buffer overflow while decoding selection rank"); |
1425 | 0 | UINT32DECODE(pp, rank); |
1426 | 0 | if (0 == rank || rank > H5S_MAX_RANK) |
1427 | 0 | HGOTO_ERROR(H5E_DATASPACE, H5E_BADVALUE, FAIL, "invalid rank (%u) for serialized point selection", |
1428 | 0 | rank); |
1429 | | |
1430 | 0 | if (!*space) { |
1431 | | /* Patch the rank of the allocated dataspace */ |
1432 | 0 | (void)memset(dims, 0, (size_t)rank * sizeof(dims[0])); |
1433 | 0 | if (H5S_set_extent_simple(tmp_space, rank, dims, NULL) < 0) |
1434 | 0 | HGOTO_ERROR(H5E_DATASPACE, H5E_CANTINIT, FAIL, "can't set dimensions"); |
1435 | 0 | } /* end if */ |
1436 | 0 | else |
1437 | | /* Verify the rank of the provided dataspace */ |
1438 | 0 | if (rank != tmp_space->extent.rank) |
1439 | 0 | HGOTO_ERROR(H5E_DATASPACE, H5E_BADRANGE, FAIL, |
1440 | 0 | "rank of serialized selection does not match dataspace"); |
1441 | | |
1442 | | /* decode the number of points */ |
1443 | 0 | switch (enc_size) { |
1444 | 0 | case H5S_SELECT_INFO_ENC_SIZE_2: |
1445 | 0 | if (H5_IS_KNOWN_BUFFER_OVERFLOW(skip, pp, sizeof(uint16_t), p_end)) |
1446 | 0 | HGOTO_ERROR(H5E_DATASPACE, H5E_OVERFLOW, FAIL, |
1447 | 0 | "buffer overflow while decoding number of points"); |
1448 | | |
1449 | 0 | UINT16DECODE(pp, num_elem); |
1450 | 0 | break; |
1451 | 0 | case H5S_SELECT_INFO_ENC_SIZE_4: |
1452 | 0 | if (H5_IS_KNOWN_BUFFER_OVERFLOW(skip, pp, sizeof(uint32_t), p_end)) |
1453 | 0 | HGOTO_ERROR(H5E_DATASPACE, H5E_OVERFLOW, FAIL, |
1454 | 0 | "buffer overflow while decoding number of points"); |
1455 | | |
1456 | 0 | UINT32DECODE(pp, num_elem); |
1457 | 0 | break; |
1458 | 0 | case H5S_SELECT_INFO_ENC_SIZE_8: |
1459 | 0 | if (H5_IS_KNOWN_BUFFER_OVERFLOW(skip, pp, sizeof(uint64_t), p_end)) |
1460 | 0 | HGOTO_ERROR(H5E_DATASPACE, H5E_OVERFLOW, FAIL, |
1461 | 0 | "buffer overflow while decoding number of points"); |
1462 | | |
1463 | 0 | UINT64DECODE(pp, num_elem); |
1464 | 0 | break; |
1465 | 0 | default: |
1466 | 0 | HGOTO_ERROR(H5E_DATASPACE, H5E_UNSUPPORTED, FAIL, "unknown point info size"); |
1467 | 0 | break; |
1468 | 0 | } /* end switch */ |
1469 | | |
1470 | | /* Determine necessary size of buffer for coordinates */ |
1471 | 0 | enc_type_size = 0; |
1472 | |
|
1473 | 0 | switch (enc_size) { |
1474 | 0 | case H5S_SELECT_INFO_ENC_SIZE_2: |
1475 | 0 | enc_type_size = sizeof(uint16_t); |
1476 | 0 | break; |
1477 | 0 | case H5S_SELECT_INFO_ENC_SIZE_4: |
1478 | 0 | enc_type_size = sizeof(uint32_t); |
1479 | 0 | break; |
1480 | 0 | case H5S_SELECT_INFO_ENC_SIZE_8: |
1481 | 0 | enc_type_size = sizeof(uint64_t); |
1482 | 0 | break; |
1483 | 0 | default: |
1484 | 0 | HGOTO_ERROR(H5E_DATASPACE, H5E_UNSUPPORTED, FAIL, "unknown point info size"); |
1485 | 0 | break; |
1486 | 0 | } |
1487 | | |
1488 | 0 | coordinate_buffer_requirement = num_elem * rank * enc_type_size; |
1489 | | |
1490 | | /* Check for overflow during multiplication */ |
1491 | 0 | if (num_elem != (coordinate_buffer_requirement / (rank * enc_type_size))) |
1492 | 0 | HGOTO_ERROR(H5E_DATASPACE, H5E_OVERFLOW, FAIL, "size of point selection buffer overflowed"); |
1493 | | |
1494 | | /* Check for possible buffer overrun */ |
1495 | 0 | if (H5_IS_KNOWN_BUFFER_OVERFLOW(skip, pp, coordinate_buffer_requirement, p_end)) |
1496 | 0 | HGOTO_ERROR(H5E_DATASPACE, H5E_OVERFLOW, FAIL, |
1497 | 0 | "buffer overflow while decoding selection coordinates"); |
1498 | | |
1499 | | /* Allocate space for the coordinates */ |
1500 | 0 | if (NULL == (coord = (hsize_t *)H5MM_malloc(num_elem * rank * sizeof(hsize_t)))) |
1501 | 0 | HGOTO_ERROR(H5E_DATASPACE, H5E_CANTALLOC, FAIL, "can't allocate coordinate information"); |
1502 | | |
1503 | | /* Retrieve the coordinates from the buffer */ |
1504 | 0 | for (tcoord = coord, i = 0; i < num_elem; i++) |
1505 | 0 | for (j = 0; j < (unsigned)rank; j++, tcoord++) |
1506 | 0 | switch (enc_size) { |
1507 | 0 | case H5S_SELECT_INFO_ENC_SIZE_2: |
1508 | 0 | UINT16DECODE(pp, *tcoord); |
1509 | 0 | break; |
1510 | 0 | case H5S_SELECT_INFO_ENC_SIZE_4: |
1511 | 0 | UINT32DECODE(pp, *tcoord); |
1512 | 0 | break; |
1513 | 0 | case H5S_SELECT_INFO_ENC_SIZE_8: |
1514 | 0 | UINT64DECODE(pp, *tcoord); |
1515 | 0 | break; |
1516 | 0 | default: |
1517 | 0 | HGOTO_ERROR(H5E_DATASPACE, H5E_UNSUPPORTED, FAIL, "unknown point info size"); |
1518 | 0 | break; |
1519 | 0 | } /* end switch */ |
1520 | | |
1521 | | /* Select points */ |
1522 | 0 | if (H5S_select_elements(tmp_space, H5S_SELECT_SET, num_elem, (const hsize_t *)coord) < 0) |
1523 | 0 | HGOTO_ERROR(H5E_DATASPACE, H5E_CANTDELETE, FAIL, "can't change selection"); |
1524 | | |
1525 | | /* Update decoding pointer */ |
1526 | 0 | *p = pp; |
1527 | | |
1528 | | /* Return space to the caller if allocated */ |
1529 | 0 | if (!*space) |
1530 | 0 | *space = tmp_space; |
1531 | |
|
1532 | 0 | done: |
1533 | | /* Free temporary space if not passed to caller (only happens on error) */ |
1534 | 0 | if (!*space && tmp_space) |
1535 | 0 | if (H5S_close(tmp_space) < 0) |
1536 | 0 | HDONE_ERROR(H5E_DATASPACE, H5E_CANTFREE, FAIL, "can't close dataspace"); |
1537 | | |
1538 | | /* Free the coordinate array if necessary */ |
1539 | 0 | if (coord != NULL) |
1540 | 0 | H5MM_xfree(coord); |
1541 | |
|
1542 | 0 | FUNC_LEAVE_NOAPI(ret_value) |
1543 | 0 | } /* end H5S__point_deserialize() */ |
1544 | | |
1545 | | /*-------------------------------------------------------------------------- |
1546 | | NAME |
1547 | | H5S__get_select_elem_pointlist |
1548 | | PURPOSE |
1549 | | Get the list of element points currently selected |
1550 | | USAGE |
1551 | | herr_t H5S__get_select_elem_pointlist(space, hsize_t *buf) |
1552 | | const H5S_t *space; IN: Dataspace pointer of selection to query |
1553 | | hsize_t startpoint; IN: Element point to start with |
1554 | | hsize_t numpoints; IN: Number of element points to get |
1555 | | hsize_t *buf; OUT: List of element points selected |
1556 | | RETURNS |
1557 | | Non-negative on success, negative on failure |
1558 | | DESCRIPTION |
1559 | | Puts a list of the element points into the user's buffer. The points |
1560 | | start with the 'startpoint'th block in the list of points and put |
1561 | | 'numpoints' number of points into the user's buffer (or until the end of |
1562 | | the list of points, whichever happen first) |
1563 | | The point coordinates have the same dimensionality (rank) as the |
1564 | | dataspace they are located within. The list of points is formatted as |
1565 | | follows: <coordinate> followed by the next coordinate, etc. until all the |
1566 | | point information in the selection have been put into the user's buffer. |
1567 | | The points are returned in the order they will be iterated through |
1568 | | when a selection is read/written from/to disk. |
1569 | | GLOBAL VARIABLES |
1570 | | COMMENTS, BUGS, ASSUMPTIONS |
1571 | | EXAMPLES |
1572 | | REVISION LOG |
1573 | | --------------------------------------------------------------------------*/ |
1574 | | static herr_t |
1575 | | H5S__get_select_elem_pointlist(const H5S_t *space, hsize_t startpoint, hsize_t numpoints, hsize_t *buf) |
1576 | 0 | { |
1577 | 0 | const hsize_t endpoint = startpoint + numpoints; /* Index of last point in iteration */ |
1578 | 0 | H5S_pnt_node_t *node; /* Point node */ |
1579 | 0 | unsigned rank; /* Dataspace rank */ |
1580 | |
|
1581 | 0 | FUNC_ENTER_PACKAGE_NOERR |
1582 | |
|
1583 | 0 | assert(space); |
1584 | 0 | assert(buf); |
1585 | | |
1586 | | /* Get the dataspace extent rank */ |
1587 | 0 | rank = space->extent.rank; |
1588 | | |
1589 | | /* Check for cached point at the correct index */ |
1590 | 0 | if (space->select.sel_info.pnt_lst->last_idx_pnt && |
1591 | 0 | startpoint == space->select.sel_info.pnt_lst->last_idx) |
1592 | 0 | node = space->select.sel_info.pnt_lst->last_idx_pnt; |
1593 | 0 | else { |
1594 | | /* Get the head of the point list */ |
1595 | 0 | node = space->select.sel_info.pnt_lst->head; |
1596 | | |
1597 | | /* Iterate to the first point to return */ |
1598 | 0 | while (node != NULL && startpoint > 0) { |
1599 | 0 | startpoint--; |
1600 | 0 | node = node->next; |
1601 | 0 | } /* end while */ |
1602 | 0 | } /* end else */ |
1603 | | |
1604 | | /* Iterate through the node, copying each point's information */ |
1605 | 0 | while (node != NULL && numpoints > 0) { |
1606 | 0 | H5MM_memcpy(buf, node->pnt, sizeof(hsize_t) * rank); |
1607 | 0 | buf += rank; |
1608 | 0 | numpoints--; |
1609 | 0 | node = node->next; |
1610 | 0 | } /* end while */ |
1611 | | |
1612 | | /* Cached next point in iteration */ |
1613 | 0 | space->select.sel_info.pnt_lst->last_idx = endpoint; |
1614 | 0 | space->select.sel_info.pnt_lst->last_idx_pnt = node; |
1615 | |
|
1616 | 0 | FUNC_LEAVE_NOAPI(SUCCEED) |
1617 | 0 | } /* end H5S__get_select_elem_pointlist() */ |
1618 | | |
1619 | | /*-------------------------------------------------------------------------- |
1620 | | NAME |
1621 | | H5Sget_select_elem_pointlist |
1622 | | PURPOSE |
1623 | | Get the list of element points currently selected |
1624 | | USAGE |
1625 | | herr_t H5Sget_select_elem_pointlist(dsid, hsize_t *buf) |
1626 | | hid_t dsid; IN: Dataspace ID of selection to query |
1627 | | hsize_t startpoint; IN: Element point to start with |
1628 | | hsize_t numpoints; IN: Number of element points to get |
1629 | | hsize_t buf[]; OUT: List of element points selected |
1630 | | RETURNS |
1631 | | Non-negative on success, negative on failure |
1632 | | DESCRIPTION |
1633 | | Puts a list of the element points into the user's buffer. The points |
1634 | | start with the 'startpoint'th block in the list of points and put |
1635 | | 'numpoints' number of points into the user's buffer (or until the end of |
1636 | | the list of points, whichever happen first) |
1637 | | The point coordinates have the same dimensionality (rank) as the |
1638 | | dataspace they are located within. The list of points is formatted as |
1639 | | follows: <coordinate> followed by the next coordinate, etc. until all the |
1640 | | point information in the selection have been put into the user's buffer. |
1641 | | The points are returned in the order they will be iterated through |
1642 | | when a selection is read/written from/to disk. |
1643 | | GLOBAL VARIABLES |
1644 | | COMMENTS, BUGS, ASSUMPTIONS |
1645 | | EXAMPLES |
1646 | | REVISION LOG |
1647 | | --------------------------------------------------------------------------*/ |
1648 | | herr_t |
1649 | | H5Sget_select_elem_pointlist(hid_t spaceid, hsize_t startpoint, hsize_t numpoints, |
1650 | | hsize_t buf[/*numpoints*/] /*out*/) |
1651 | 0 | { |
1652 | 0 | H5S_t *space; /* Dataspace to modify selection of */ |
1653 | 0 | herr_t ret_value; /* return value */ |
1654 | |
|
1655 | 0 | FUNC_ENTER_API(FAIL) |
1656 | | |
1657 | | /* Check args */ |
1658 | 0 | if (NULL == buf) |
1659 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "invalid pointer"); |
1660 | 0 | if (NULL == (space = (H5S_t *)H5I_object_verify(spaceid, H5I_DATASPACE))) |
1661 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a dataspace"); |
1662 | 0 | if (H5S_GET_SELECT_TYPE(space) != H5S_SEL_POINTS) |
1663 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a point selection"); |
1664 | | |
1665 | 0 | ret_value = H5S__get_select_elem_pointlist(space, startpoint, numpoints, buf); |
1666 | |
|
1667 | 0 | done: |
1668 | 0 | FUNC_LEAVE_API(ret_value) |
1669 | 0 | } /* end H5Sget_select_elem_pointlist() */ |
1670 | | |
1671 | | /*-------------------------------------------------------------------------- |
1672 | | NAME |
1673 | | H5S__point_bounds |
1674 | | PURPOSE |
1675 | | Gets the bounding box containing the selection. |
1676 | | USAGE |
1677 | | herr_t H5S__point_bounds(space, start, end) |
1678 | | H5S_t *space; IN: Dataspace pointer of selection to query |
1679 | | hsize_t *start; OUT: Starting coordinate of bounding box |
1680 | | hsize_t *end; OUT: Opposite coordinate of bounding box |
1681 | | RETURNS |
1682 | | Non-negative on success, negative on failure |
1683 | | DESCRIPTION |
1684 | | Retrieves the bounding box containing the current selection and places |
1685 | | it into the user's buffers. The start and end buffers must be large |
1686 | | enough to hold the dataspace rank number of coordinates. The bounding box |
1687 | | exactly contains the selection, ie. if a 2-D element selection is currently |
1688 | | defined with the following points: (4,5), (6,8) (10,7), the bounding box |
1689 | | with be (4, 5), (10, 8). |
1690 | | The bounding box calculations _does_ include the current offset of the |
1691 | | selection within the dataspace extent. |
1692 | | GLOBAL VARIABLES |
1693 | | COMMENTS, BUGS, ASSUMPTIONS |
1694 | | EXAMPLES |
1695 | | REVISION LOG |
1696 | | --------------------------------------------------------------------------*/ |
1697 | | static herr_t |
1698 | | H5S__point_bounds(const H5S_t *space, hsize_t *start, hsize_t *end) |
1699 | 686 | { |
1700 | 686 | unsigned u; /* Local index variable */ |
1701 | 686 | herr_t ret_value = SUCCEED; /* Return value */ |
1702 | | |
1703 | 686 | FUNC_ENTER_PACKAGE |
1704 | | |
1705 | | /* Sanity check */ |
1706 | 686 | assert(space); |
1707 | 686 | assert(start); |
1708 | 686 | assert(end); |
1709 | | |
1710 | | /* Loop over dimensions */ |
1711 | 2.05k | for (u = 0; u < space->extent.rank; u++) { |
1712 | | /* Sanity check */ |
1713 | 1.37k | assert(space->select.sel_info.pnt_lst->low_bounds[u] <= |
1714 | 1.37k | space->select.sel_info.pnt_lst->high_bounds[u]); |
1715 | | |
1716 | | /* Check for offset moving selection negative */ |
1717 | 1.37k | if (((hssize_t)space->select.sel_info.pnt_lst->low_bounds[u] + space->select.offset[u]) < 0) |
1718 | 0 | HGOTO_ERROR(H5E_DATASPACE, H5E_BADRANGE, FAIL, "offset moves selection out of bounds"); |
1719 | | |
1720 | | /* Set the low & high bounds in this dimension */ |
1721 | 1.37k | start[u] = |
1722 | 1.37k | (hsize_t)((hssize_t)space->select.sel_info.pnt_lst->low_bounds[u] + space->select.offset[u]); |
1723 | 1.37k | end[u] = |
1724 | 1.37k | (hsize_t)((hssize_t)space->select.sel_info.pnt_lst->high_bounds[u] + space->select.offset[u]); |
1725 | 1.37k | } /* end for */ |
1726 | | |
1727 | 686 | done: |
1728 | 686 | FUNC_LEAVE_NOAPI(ret_value) |
1729 | 686 | } /* end H5S__point_bounds() */ |
1730 | | |
1731 | | /*-------------------------------------------------------------------------- |
1732 | | NAME |
1733 | | H5S__point_offset |
1734 | | PURPOSE |
1735 | | Gets the linear offset of the first element for the selection. |
1736 | | USAGE |
1737 | | herr_t H5S__point_offset(space, offset) |
1738 | | const H5S_t *space; IN: Dataspace pointer of selection to query |
1739 | | hsize_t *offset; OUT: Linear offset of first element in selection |
1740 | | RETURNS |
1741 | | Non-negative on success, negative on failure |
1742 | | DESCRIPTION |
1743 | | Retrieves the linear offset (in "units" of elements) of the first element |
1744 | | selected within the dataspace. |
1745 | | GLOBAL VARIABLES |
1746 | | COMMENTS, BUGS, ASSUMPTIONS |
1747 | | Calling this function on a "none" selection returns fail. |
1748 | | EXAMPLES |
1749 | | REVISION LOG |
1750 | | --------------------------------------------------------------------------*/ |
1751 | | static herr_t |
1752 | | H5S__point_offset(const H5S_t *space, hsize_t *offset) |
1753 | 50 | { |
1754 | 50 | const hsize_t *pnt; /* Pointer to a selected point's coordinates */ |
1755 | 50 | const hssize_t *sel_offset; /* Pointer to the selection's offset */ |
1756 | 50 | const hsize_t *dim_size; /* Pointer to a dataspace's extent */ |
1757 | 50 | hsize_t accum; /* Accumulator for dimension sizes */ |
1758 | 50 | int i; /* index variable */ |
1759 | 50 | herr_t ret_value = SUCCEED; /* Return value */ |
1760 | | |
1761 | 50 | FUNC_ENTER_PACKAGE |
1762 | | |
1763 | 50 | assert(space); |
1764 | 50 | assert(offset); |
1765 | | |
1766 | | /* Start at linear offset 0 */ |
1767 | 50 | *offset = 0; |
1768 | | |
1769 | | /* Set up pointers to arrays of values */ |
1770 | 50 | pnt = space->select.sel_info.pnt_lst->head->pnt; |
1771 | 50 | sel_offset = space->select.offset; |
1772 | 50 | dim_size = space->extent.size; |
1773 | | |
1774 | | /* Loop through coordinates, calculating the linear offset */ |
1775 | 50 | accum = 1; |
1776 | 150 | for (i = (int)space->extent.rank - 1; i >= 0; i--) { |
1777 | 100 | hssize_t pnt_offset = (hssize_t)pnt[i] + sel_offset[i]; /* Point's offset in this dimension */ |
1778 | | |
1779 | | /* Check for offset moving selection out of the dataspace */ |
1780 | 100 | if (pnt_offset < 0 || (hsize_t)pnt_offset >= dim_size[i]) |
1781 | 0 | HGOTO_ERROR(H5E_DATASPACE, H5E_BADRANGE, FAIL, "offset moves selection out of bounds"); |
1782 | | |
1783 | | /* Add the point's offset in this dimension to the total linear offset */ |
1784 | 100 | *offset += (hsize_t)pnt_offset * accum; |
1785 | | |
1786 | | /* Increase the accumulator */ |
1787 | 100 | accum *= dim_size[i]; |
1788 | 100 | } /* end for */ |
1789 | | |
1790 | 50 | done: |
1791 | 50 | FUNC_LEAVE_NOAPI(ret_value) |
1792 | 50 | } /* end H5S__point_offset() */ |
1793 | | |
1794 | | /*-------------------------------------------------------------------------- |
1795 | | NAME |
1796 | | H5S__point_unlim_dim |
1797 | | PURPOSE |
1798 | | Return unlimited dimension of selection, or -1 if none |
1799 | | USAGE |
1800 | | int H5S__point_unlim_dim(space) |
1801 | | H5S_t *space; IN: Dataspace pointer to check |
1802 | | RETURNS |
1803 | | Unlimited dimension of selection, or -1 if none (never fails). |
1804 | | DESCRIPTION |
1805 | | Returns the index of the unlimited dimension in this selection, or -1 |
1806 | | if the selection has no unlimited dimension. Currently point |
1807 | | selections cannot have an unlimited dimension, so this function always |
1808 | | returns -1. |
1809 | | GLOBAL VARIABLES |
1810 | | COMMENTS, BUGS, ASSUMPTIONS |
1811 | | EXAMPLES |
1812 | | REVISION LOG |
1813 | | --------------------------------------------------------------------------*/ |
1814 | | static int |
1815 | | H5S__point_unlim_dim(const H5S_t H5_ATTR_UNUSED *space) |
1816 | 0 | { |
1817 | 0 | FUNC_ENTER_PACKAGE_NOERR |
1818 | |
|
1819 | 0 | FUNC_LEAVE_NOAPI(-1) |
1820 | 0 | } /* end H5S__point_unlim_dim() */ |
1821 | | |
1822 | | /*-------------------------------------------------------------------------- |
1823 | | NAME |
1824 | | H5S__point_is_contiguous |
1825 | | PURPOSE |
1826 | | Check if a point selection is contiguous within the dataspace extent. |
1827 | | USAGE |
1828 | | htri_t H5S__point_is_contiguous(space) |
1829 | | H5S_t *space; IN: Dataspace pointer to check |
1830 | | RETURNS |
1831 | | true/false/FAIL |
1832 | | DESCRIPTION |
1833 | | Checks to see if the current selection in the dataspace is contiguous. |
1834 | | This is primarily used for reading the entire selection in one swoop. |
1835 | | This code currently doesn't properly check for contiguousness when there is |
1836 | | more than one point, as that would take a lot of extra coding that we |
1837 | | don't need now. |
1838 | | GLOBAL VARIABLES |
1839 | | COMMENTS, BUGS, ASSUMPTIONS |
1840 | | EXAMPLES |
1841 | | REVISION LOG |
1842 | | --------------------------------------------------------------------------*/ |
1843 | | static htri_t |
1844 | | H5S__point_is_contiguous(const H5S_t *space) |
1845 | 0 | { |
1846 | 0 | htri_t ret_value = FAIL; /* Return value */ |
1847 | |
|
1848 | 0 | FUNC_ENTER_PACKAGE_NOERR |
1849 | |
|
1850 | 0 | assert(space); |
1851 | | |
1852 | | /* One point is definitely contiguous */ |
1853 | 0 | if (space->select.num_elem == 1) |
1854 | 0 | ret_value = true; |
1855 | 0 | else /* More than one point might be contiguous, but it's complex to check and we don't need it right now |
1856 | | */ |
1857 | 0 | ret_value = false; |
1858 | |
|
1859 | 0 | FUNC_LEAVE_NOAPI(ret_value) |
1860 | 0 | } /* end H5S__point_is_contiguous() */ |
1861 | | |
1862 | | /*-------------------------------------------------------------------------- |
1863 | | NAME |
1864 | | H5S__point_is_single |
1865 | | PURPOSE |
1866 | | Check if a point selection is single within the dataspace extent. |
1867 | | USAGE |
1868 | | htri_t H5S__point_is_single(space) |
1869 | | H5S_t *space; IN: Dataspace pointer to check |
1870 | | RETURNS |
1871 | | true/false/FAIL |
1872 | | DESCRIPTION |
1873 | | Checks to see if the current selection in the dataspace is a single block. |
1874 | | This is primarily used for reading the entire selection in one swoop. |
1875 | | GLOBAL VARIABLES |
1876 | | COMMENTS, BUGS, ASSUMPTIONS |
1877 | | EXAMPLES |
1878 | | REVISION LOG |
1879 | | --------------------------------------------------------------------------*/ |
1880 | | static htri_t |
1881 | | H5S__point_is_single(const H5S_t *space) |
1882 | 160 | { |
1883 | 160 | htri_t ret_value = FAIL; /* Return value */ |
1884 | | |
1885 | 160 | FUNC_ENTER_PACKAGE_NOERR |
1886 | | |
1887 | 160 | assert(space); |
1888 | | |
1889 | | /* One point is definitely 'single' :-) */ |
1890 | 160 | if (space->select.num_elem == 1) |
1891 | 117 | ret_value = true; |
1892 | 43 | else |
1893 | 43 | ret_value = false; |
1894 | | |
1895 | 160 | FUNC_LEAVE_NOAPI(ret_value) |
1896 | 160 | } /* end H5S__point_is_single() */ |
1897 | | |
1898 | | /*-------------------------------------------------------------------------- |
1899 | | NAME |
1900 | | H5S__point_is_regular |
1901 | | PURPOSE |
1902 | | Check if a point selection is "regular" |
1903 | | USAGE |
1904 | | htri_t H5S__point_is_regular(space) |
1905 | | H5S_t *space; IN: Dataspace pointer to check |
1906 | | RETURNS |
1907 | | true/false/FAIL |
1908 | | DESCRIPTION |
1909 | | Checks to see if the current selection in a dataspace is the a regular |
1910 | | pattern. |
1911 | | This is primarily used for reading the entire selection in one swoop. |
1912 | | GLOBAL VARIABLES |
1913 | | COMMENTS, BUGS, ASSUMPTIONS |
1914 | | Doesn't check for points selected to be next to one another in a regular |
1915 | | pattern yet. |
1916 | | EXAMPLES |
1917 | | REVISION LOG |
1918 | | --------------------------------------------------------------------------*/ |
1919 | | static htri_t |
1920 | | H5S__point_is_regular(H5S_t *space) |
1921 | 0 | { |
1922 | 0 | htri_t ret_value = FAIL; /* Return value */ |
1923 | |
|
1924 | 0 | FUNC_ENTER_PACKAGE_NOERR |
1925 | | |
1926 | | /* Check args */ |
1927 | 0 | assert(space); |
1928 | | |
1929 | | /* Only simple check for regular points for now... */ |
1930 | 0 | if (space->select.num_elem == 1) |
1931 | 0 | ret_value = true; |
1932 | 0 | else |
1933 | 0 | ret_value = false; |
1934 | |
|
1935 | 0 | FUNC_LEAVE_NOAPI(ret_value) |
1936 | 0 | } /* end H5S__point_is_regular() */ |
1937 | | |
1938 | | /*-------------------------------------------------------------------------- |
1939 | | NAME |
1940 | | H5S__point_shape_same |
1941 | | PURPOSE |
1942 | | Check if a two "point" selections are the same shape |
1943 | | USAGE |
1944 | | htri_t H5S__point_shape_same(space1, space2) |
1945 | | H5S_t *space1; IN: First dataspace to check |
1946 | | H5S_t *space2; IN: Second dataspace to check |
1947 | | RETURNS |
1948 | | true / false / FAIL |
1949 | | DESCRIPTION |
1950 | | Checks to see if the current selection in each dataspace are the same |
1951 | | shape. |
1952 | | GLOBAL VARIABLES |
1953 | | COMMENTS, BUGS, ASSUMPTIONS |
1954 | | EXAMPLES |
1955 | | REVISION LOG |
1956 | | --------------------------------------------------------------------------*/ |
1957 | | static htri_t |
1958 | | H5S__point_shape_same(H5S_t *space1, H5S_t *space2) |
1959 | 0 | { |
1960 | 0 | H5S_pnt_node_t *pnt1, *pnt2; /* Point information nodes */ |
1961 | 0 | hssize_t offset[H5S_MAX_RANK]; /* Offset between the selections */ |
1962 | 0 | unsigned space1_rank; /* Number of dimensions of first dataspace */ |
1963 | 0 | unsigned space2_rank; /* Number of dimensions of second dataspace */ |
1964 | 0 | int space1_dim; /* Current dimension in first dataspace */ |
1965 | 0 | int space2_dim; /* Current dimension in second dataspace */ |
1966 | 0 | htri_t ret_value = true; /* Return value */ |
1967 | |
|
1968 | 0 | FUNC_ENTER_PACKAGE_NOERR |
1969 | | |
1970 | | /* Check args */ |
1971 | 0 | assert(space1); |
1972 | 0 | assert(space2); |
1973 | | |
1974 | | /* Get dataspace ranks */ |
1975 | 0 | space1_rank = space1->extent.rank; |
1976 | 0 | space2_rank = space2->extent.rank; |
1977 | | |
1978 | | /* Sanity check */ |
1979 | 0 | assert(space1_rank >= space2_rank); |
1980 | 0 | assert(space2_rank > 0); |
1981 | | |
1982 | | /* Initialize dimensions */ |
1983 | 0 | space1_dim = (int)space1_rank - 1; |
1984 | 0 | space2_dim = (int)space2_rank - 1; |
1985 | | |
1986 | | /* Look at first point in each selection to compute the offset for common |
1987 | | * dimensions. |
1988 | | */ |
1989 | 0 | pnt1 = space1->select.sel_info.pnt_lst->head; |
1990 | 0 | pnt2 = space2->select.sel_info.pnt_lst->head; |
1991 | 0 | while (space2_dim >= 0) { |
1992 | | /* Set the relative locations of the selections */ |
1993 | 0 | offset[space1_dim] = (hssize_t)pnt2->pnt[space2_dim] - (hssize_t)pnt1->pnt[space1_dim]; |
1994 | |
|
1995 | 0 | space1_dim--; |
1996 | 0 | space2_dim--; |
1997 | 0 | } /* end while */ |
1998 | | |
1999 | | /* For dimensions that appear only in space1: */ |
2000 | 0 | while (space1_dim >= 0) { |
2001 | | /* Set the absolute offset of the remaining dimensions */ |
2002 | 0 | offset[space1_dim] = (hssize_t)pnt1->pnt[space1_dim]; |
2003 | |
|
2004 | 0 | space1_dim--; |
2005 | 0 | } /* end while */ |
2006 | | |
2007 | | /* Advance to next point */ |
2008 | 0 | pnt1 = pnt1->next; |
2009 | 0 | pnt2 = pnt2->next; |
2010 | | |
2011 | | /* Loop over remaining points */ |
2012 | 0 | while (pnt1 && pnt2) { |
2013 | | /* Initialize dimensions */ |
2014 | 0 | space1_dim = (int)space1_rank - 1; |
2015 | 0 | space2_dim = (int)space2_rank - 1; |
2016 | | |
2017 | | /* Compare locations in common dimensions, including relative offset */ |
2018 | 0 | while (space2_dim >= 0) { |
2019 | 0 | if ((hsize_t)((hssize_t)pnt1->pnt[space1_dim] + offset[space1_dim]) != pnt2->pnt[space2_dim]) |
2020 | 0 | HGOTO_DONE(false); |
2021 | | |
2022 | 0 | space1_dim--; |
2023 | 0 | space2_dim--; |
2024 | 0 | } /* end while */ |
2025 | | |
2026 | | /* For dimensions that appear only in space1: */ |
2027 | 0 | while (space1_dim >= 0) { |
2028 | | /* Compare the absolute offset in the remaining dimensions */ |
2029 | 0 | if ((hssize_t)pnt1->pnt[space1_dim] != offset[space1_dim]) |
2030 | 0 | HGOTO_DONE(false); |
2031 | | |
2032 | 0 | space1_dim--; |
2033 | 0 | } /* end while */ |
2034 | | |
2035 | | /* Advance to next point */ |
2036 | 0 | pnt1 = pnt1->next; |
2037 | 0 | pnt2 = pnt2->next; |
2038 | 0 | } /* end while */ |
2039 | | |
2040 | 0 | done: |
2041 | 0 | FUNC_LEAVE_NOAPI(ret_value) |
2042 | 0 | } /* end H5S__point_shape_same() */ |
2043 | | |
2044 | | /*-------------------------------------------------------------------------- |
2045 | | NAME |
2046 | | H5S__point_intersect_block |
2047 | | PURPOSE |
2048 | | Detect intersections of selection with block |
2049 | | USAGE |
2050 | | htri_t H5S__point_intersect_block(space, start, end) |
2051 | | H5S_t *space; IN: Dataspace with selection to use |
2052 | | const hsize_t *start; IN: Starting coordinate for block |
2053 | | const hsize_t *end; IN: Ending coordinate for block |
2054 | | RETURNS |
2055 | | Non-negative true / false on success, negative on failure |
2056 | | DESCRIPTION |
2057 | | Quickly detect intersections with a block |
2058 | | GLOBAL VARIABLES |
2059 | | COMMENTS, BUGS, ASSUMPTIONS |
2060 | | EXAMPLES |
2061 | | REVISION LOG |
2062 | | --------------------------------------------------------------------------*/ |
2063 | | htri_t |
2064 | | H5S__point_intersect_block(H5S_t *space, const hsize_t *start, const hsize_t *end) |
2065 | 0 | { |
2066 | 0 | H5S_pnt_node_t *pnt; /* Point information node */ |
2067 | 0 | htri_t ret_value = false; /* Return value */ |
2068 | |
|
2069 | 0 | FUNC_ENTER_PACKAGE_NOERR |
2070 | | |
2071 | | /* Sanity check */ |
2072 | 0 | assert(space); |
2073 | 0 | assert(H5S_SEL_POINTS == H5S_GET_SELECT_TYPE(space)); |
2074 | 0 | assert(start); |
2075 | 0 | assert(end); |
2076 | | |
2077 | | /* Loop over points */ |
2078 | 0 | pnt = space->select.sel_info.pnt_lst->head; |
2079 | 0 | while (pnt) { |
2080 | 0 | unsigned u; /* Local index variable */ |
2081 | | |
2082 | | /* Verify that the point is within the block */ |
2083 | 0 | for (u = 0; u < space->extent.rank; u++) |
2084 | 0 | if (pnt->pnt[u] < start[u] || pnt->pnt[u] > end[u]) |
2085 | 0 | break; |
2086 | | |
2087 | | /* Check if point was within block for all dimensions */ |
2088 | 0 | if (u == space->extent.rank) |
2089 | 0 | HGOTO_DONE(true); |
2090 | | |
2091 | | /* Advance to next point */ |
2092 | 0 | pnt = pnt->next; |
2093 | 0 | } /* end while */ |
2094 | | |
2095 | 0 | done: |
2096 | 0 | FUNC_LEAVE_NOAPI(ret_value) |
2097 | 0 | } /* end H5S__point_intersect_block() */ |
2098 | | |
2099 | | /*-------------------------------------------------------------------------- |
2100 | | NAME |
2101 | | H5S__point_adjust_u |
2102 | | PURPOSE |
2103 | | Adjust a "point" selection by subtracting an offset |
2104 | | USAGE |
2105 | | herr_t H5S__point_adjust_u(space, offset) |
2106 | | H5S_t *space; IN/OUT: Pointer to dataspace to adjust |
2107 | | const hsize_t *offset; IN: Offset to subtract |
2108 | | RETURNS |
2109 | | Non-negative on success, negative on failure |
2110 | | DESCRIPTION |
2111 | | Moves a point selection by subtracting an offset from it. |
2112 | | GLOBAL VARIABLES |
2113 | | COMMENTS, BUGS, ASSUMPTIONS |
2114 | | EXAMPLES |
2115 | | REVISION LOG |
2116 | | --------------------------------------------------------------------------*/ |
2117 | | static herr_t |
2118 | | H5S__point_adjust_u(H5S_t *space, const hsize_t *offset) |
2119 | 0 | { |
2120 | 0 | bool non_zero_offset = false; /* Whether any offset is non-zero */ |
2121 | 0 | H5S_pnt_node_t *node; /* Point node */ |
2122 | 0 | unsigned rank; /* Dataspace rank */ |
2123 | 0 | unsigned u; /* Local index variable */ |
2124 | |
|
2125 | 0 | FUNC_ENTER_PACKAGE_NOERR |
2126 | |
|
2127 | 0 | assert(space); |
2128 | 0 | assert(offset); |
2129 | | |
2130 | | /* Check for an all-zero offset vector */ |
2131 | 0 | for (u = 0; u < space->extent.rank; u++) |
2132 | 0 | if (0 != offset[u]) { |
2133 | 0 | non_zero_offset = true; |
2134 | 0 | break; |
2135 | 0 | } |
2136 | | |
2137 | | /* Only perform operation if the offset is non-zero */ |
2138 | 0 | if (non_zero_offset) { |
2139 | | /* Iterate through the nodes, checking the bounds on each element */ |
2140 | 0 | node = space->select.sel_info.pnt_lst->head; |
2141 | 0 | rank = space->extent.rank; |
2142 | 0 | while (node) { |
2143 | | /* Adjust each coordinate for point node */ |
2144 | 0 | for (u = 0; u < rank; u++) { |
2145 | | /* Check for offset moving selection negative */ |
2146 | 0 | assert(node->pnt[u] >= offset[u]); |
2147 | | |
2148 | | /* Adjust node's coordinate location */ |
2149 | 0 | node->pnt[u] -= offset[u]; |
2150 | 0 | } /* end for */ |
2151 | | |
2152 | | /* Advance to next point node in selection */ |
2153 | 0 | node = node->next; |
2154 | 0 | } /* end while */ |
2155 | | |
2156 | | /* update the bound box of the selection */ |
2157 | 0 | for (u = 0; u < rank; u++) { |
2158 | 0 | space->select.sel_info.pnt_lst->low_bounds[u] -= offset[u]; |
2159 | 0 | space->select.sel_info.pnt_lst->high_bounds[u] -= offset[u]; |
2160 | 0 | } /* end for */ |
2161 | 0 | } /* end if */ |
2162 | |
|
2163 | 0 | FUNC_LEAVE_NOAPI(SUCCEED) |
2164 | 0 | } /* end H5S__point_adjust_u() */ |
2165 | | |
2166 | | /*-------------------------------------------------------------------------- |
2167 | | NAME |
2168 | | H5S__point_adjust_s |
2169 | | PURPOSE |
2170 | | Adjust a "point" selection by subtracting an offset |
2171 | | USAGE |
2172 | | herr_t H5S__point_adjust_u(space, offset) |
2173 | | H5S_t *space; IN/OUT: Pointer to dataspace to adjust |
2174 | | const hssize_t *offset; IN: Offset to subtract |
2175 | | RETURNS |
2176 | | Non-negative on success, negative on failure |
2177 | | DESCRIPTION |
2178 | | Moves a point selection by subtracting an offset from it. |
2179 | | GLOBAL VARIABLES |
2180 | | COMMENTS, BUGS, ASSUMPTIONS |
2181 | | EXAMPLES |
2182 | | REVISION LOG |
2183 | | --------------------------------------------------------------------------*/ |
2184 | | static herr_t |
2185 | | H5S__point_adjust_s(H5S_t *space, const hssize_t *offset) |
2186 | 0 | { |
2187 | 0 | bool non_zero_offset = false; /* Whether any offset is non-zero */ |
2188 | 0 | H5S_pnt_node_t *node; /* Point node */ |
2189 | 0 | unsigned rank; /* Dataspace rank */ |
2190 | 0 | unsigned u; /* Local index variable */ |
2191 | |
|
2192 | 0 | FUNC_ENTER_PACKAGE_NOERR |
2193 | |
|
2194 | 0 | assert(space); |
2195 | 0 | assert(offset); |
2196 | | |
2197 | | /* Check for an all-zero offset vector */ |
2198 | 0 | for (u = 0; u < space->extent.rank; u++) |
2199 | 0 | if (0 != offset[u]) { |
2200 | 0 | non_zero_offset = true; |
2201 | 0 | break; |
2202 | 0 | } /* end if */ |
2203 | | |
2204 | | /* Only perform operation if the offset is non-zero */ |
2205 | 0 | if (non_zero_offset) { |
2206 | | /* Iterate through the nodes, checking the bounds on each element */ |
2207 | 0 | node = space->select.sel_info.pnt_lst->head; |
2208 | 0 | rank = space->extent.rank; |
2209 | 0 | while (node) { |
2210 | | /* Adjust each coordinate for point node */ |
2211 | 0 | for (u = 0; u < rank; u++) { |
2212 | | /* Check for offset moving selection negative */ |
2213 | 0 | assert((hssize_t)node->pnt[u] >= offset[u]); |
2214 | | |
2215 | | /* Adjust node's coordinate location */ |
2216 | 0 | node->pnt[u] = (hsize_t)((hssize_t)node->pnt[u] - offset[u]); |
2217 | 0 | } /* end for */ |
2218 | | |
2219 | | /* Advance to next point node in selection */ |
2220 | 0 | node = node->next; |
2221 | 0 | } /* end while */ |
2222 | | |
2223 | | /* update the bound box of the selection */ |
2224 | 0 | for (u = 0; u < rank; u++) { |
2225 | 0 | assert((hssize_t)space->select.sel_info.pnt_lst->low_bounds[u] >= offset[u]); |
2226 | 0 | space->select.sel_info.pnt_lst->low_bounds[u] = |
2227 | 0 | (hsize_t)((hssize_t)space->select.sel_info.pnt_lst->low_bounds[u] - offset[u]); |
2228 | 0 | space->select.sel_info.pnt_lst->high_bounds[u] = |
2229 | 0 | (hsize_t)((hssize_t)space->select.sel_info.pnt_lst->high_bounds[u] - offset[u]); |
2230 | 0 | } /* end for */ |
2231 | 0 | } /* end if */ |
2232 | |
|
2233 | 0 | FUNC_LEAVE_NOAPI(SUCCEED) |
2234 | 0 | } /* end H5S__point_adjust_s() */ |
2235 | | |
2236 | | /*------------------------------------------------------------------------- |
2237 | | * Function: H5S__point_project_scalar |
2238 | | * |
2239 | | * Purpose: Projects a single element point selection into a scalar |
2240 | | * dataspace |
2241 | | * |
2242 | | * Return: Non-negative on success, negative on failure. |
2243 | | * |
2244 | | *------------------------------------------------------------------------- |
2245 | | */ |
2246 | | static herr_t |
2247 | | H5S__point_project_scalar(const H5S_t *space, hsize_t *offset) |
2248 | 0 | { |
2249 | 0 | const H5S_pnt_node_t *node; /* Point node */ |
2250 | 0 | herr_t ret_value = SUCCEED; /* Return value */ |
2251 | |
|
2252 | 0 | FUNC_ENTER_PACKAGE |
2253 | | |
2254 | | /* Check args */ |
2255 | 0 | assert(space && H5S_SEL_POINTS == H5S_GET_SELECT_TYPE(space)); |
2256 | 0 | assert(offset); |
2257 | | |
2258 | | /* Get the head of the point list */ |
2259 | 0 | node = space->select.sel_info.pnt_lst->head; |
2260 | | |
2261 | | /* Check for more than one point selected */ |
2262 | 0 | if (node->next) |
2263 | 0 | HGOTO_ERROR(H5E_DATASPACE, H5E_BADRANGE, FAIL, |
2264 | 0 | "point selection of one element has more than one node!"); |
2265 | | |
2266 | | /* Calculate offset of selection in projected buffer */ |
2267 | 0 | *offset = H5VM_array_offset(space->extent.rank, space->extent.size, node->pnt); |
2268 | |
|
2269 | 0 | done: |
2270 | 0 | FUNC_LEAVE_NOAPI(ret_value) |
2271 | 0 | } /* end H5S__point_project_scalar() */ |
2272 | | |
2273 | | /*------------------------------------------------------------------------- |
2274 | | * Function: H5S__point_project_simple |
2275 | | * |
2276 | | * Purpose: Projects a point selection onto/into a simple dataspace |
2277 | | * of a different rank |
2278 | | * |
2279 | | * Return: Non-negative on success, negative on failure. |
2280 | | * |
2281 | | *------------------------------------------------------------------------- |
2282 | | */ |
2283 | | static herr_t |
2284 | | H5S__point_project_simple(const H5S_t *base_space, H5S_t *new_space, hsize_t *offset) |
2285 | 0 | { |
2286 | 0 | const H5S_pnt_node_t *base_node; /* Point node in base space */ |
2287 | 0 | H5S_pnt_node_t *new_node; /* Point node in new space */ |
2288 | 0 | H5S_pnt_node_t *prev_node; /* Previous point node in new space */ |
2289 | 0 | unsigned rank_diff; /* Difference in ranks between spaces */ |
2290 | 0 | unsigned u; /* Local index variable */ |
2291 | 0 | herr_t ret_value = SUCCEED; /* Return value */ |
2292 | |
|
2293 | 0 | FUNC_ENTER_PACKAGE |
2294 | | |
2295 | | /* Check args */ |
2296 | 0 | assert(base_space && H5S_SEL_POINTS == H5S_GET_SELECT_TYPE(base_space)); |
2297 | 0 | assert(new_space); |
2298 | 0 | assert(offset); |
2299 | | |
2300 | | /* We are setting a new selection, remove any current selection in new dataspace */ |
2301 | 0 | if (H5S_SELECT_RELEASE(new_space) < 0) |
2302 | 0 | HGOTO_ERROR(H5E_DATASPACE, H5E_CANTDELETE, FAIL, "can't release selection"); |
2303 | | |
2304 | | /* Allocate room for the head of the point list */ |
2305 | 0 | if (NULL == (new_space->select.sel_info.pnt_lst = H5FL_CALLOC(H5S_pnt_list_t))) |
2306 | 0 | HGOTO_ERROR(H5E_DATASPACE, H5E_CANTALLOC, FAIL, "can't allocate point list node"); |
2307 | | |
2308 | | /* Check if the new space's rank is < or > base space's rank */ |
2309 | 0 | if (new_space->extent.rank < base_space->extent.rank) { |
2310 | 0 | hsize_t block[H5S_MAX_RANK]; /* Block selected in base dataspace */ |
2311 | | |
2312 | | /* Compute the difference in ranks */ |
2313 | 0 | rank_diff = base_space->extent.rank - new_space->extent.rank; |
2314 | | |
2315 | | /* Calculate offset of selection in projected buffer */ |
2316 | 0 | memset(block, 0, sizeof(block)); |
2317 | 0 | H5MM_memcpy(block, base_space->select.sel_info.pnt_lst->head->pnt, sizeof(hsize_t) * rank_diff); |
2318 | 0 | *offset = H5VM_array_offset(base_space->extent.rank, base_space->extent.size, block); |
2319 | | |
2320 | | /* Iterate through base space's point nodes, copying the point information */ |
2321 | 0 | base_node = base_space->select.sel_info.pnt_lst->head; |
2322 | 0 | prev_node = NULL; |
2323 | 0 | while (base_node) { |
2324 | | /* The following allocation relies on the size of an hcoords_t being |
2325 | | * the same as an 'H5S_pnt_node_t *', so fail now if that's not true |
2326 | | */ |
2327 | 0 | HDcompile_assert(sizeof(hcoords_t) >= sizeof(H5S_pnt_node_t *)); |
2328 | | |
2329 | | /* Create new point */ |
2330 | | /* Note: allocating "rank + 1" to allow for 'next' pointer */ |
2331 | 0 | if (NULL == (new_node = (H5S_pnt_node_t *)H5FL_ARR_MALLOC(hcoords_t, new_space->extent.rank + 1))) |
2332 | 0 | HGOTO_ERROR(H5E_DATASPACE, H5E_CANTALLOC, FAIL, "can't allocate point node"); |
2333 | 0 | new_node->next = NULL; |
2334 | | |
2335 | | /* Copy over the point's coordinates */ |
2336 | 0 | H5MM_memcpy(new_node->pnt, &base_node->pnt[rank_diff], |
2337 | 0 | (new_space->extent.rank * sizeof(hsize_t))); |
2338 | | |
2339 | | /* Keep the order the same when copying */ |
2340 | 0 | if (NULL == prev_node) |
2341 | 0 | prev_node = new_space->select.sel_info.pnt_lst->head = new_node; |
2342 | 0 | else { |
2343 | 0 | prev_node->next = new_node; |
2344 | 0 | prev_node = new_node; |
2345 | 0 | } /* end else */ |
2346 | | |
2347 | | /* Advance to next node */ |
2348 | 0 | base_node = base_node->next; |
2349 | 0 | } /* end while */ |
2350 | | |
2351 | | /* Update the bounding box */ |
2352 | 0 | for (u = 0; u < new_space->extent.rank; u++) { |
2353 | 0 | new_space->select.sel_info.pnt_lst->low_bounds[u] = |
2354 | 0 | base_space->select.sel_info.pnt_lst->low_bounds[u + rank_diff]; |
2355 | 0 | new_space->select.sel_info.pnt_lst->high_bounds[u] = |
2356 | 0 | base_space->select.sel_info.pnt_lst->high_bounds[u + rank_diff]; |
2357 | 0 | } /* end for */ |
2358 | 0 | } /* end if */ |
2359 | 0 | else { |
2360 | 0 | assert(new_space->extent.rank > base_space->extent.rank); |
2361 | | |
2362 | | /* Compute the difference in ranks */ |
2363 | 0 | rank_diff = new_space->extent.rank - base_space->extent.rank; |
2364 | | |
2365 | | /* The offset is zero when projected into higher dimensions */ |
2366 | 0 | *offset = 0; |
2367 | | |
2368 | | /* Iterate through base space's point nodes, copying the point information */ |
2369 | 0 | base_node = base_space->select.sel_info.pnt_lst->head; |
2370 | 0 | prev_node = NULL; |
2371 | 0 | while (base_node) { |
2372 | | /* The following allocation relies on the size of an hcoords_t being |
2373 | | * the same as an 'H5S_pnt_node_t *', so fail now if that's not true |
2374 | | */ |
2375 | 0 | HDcompile_assert(sizeof(hcoords_t) >= sizeof(H5S_pnt_node_t *)); |
2376 | | |
2377 | | /* Create new point */ |
2378 | | /* Note: allocating "rank + 1" to allow for 'next' pointer */ |
2379 | 0 | if (NULL == (new_node = (H5S_pnt_node_t *)H5FL_ARR_MALLOC(hcoords_t, new_space->extent.rank + 1))) |
2380 | 0 | HGOTO_ERROR(H5E_DATASPACE, H5E_CANTALLOC, FAIL, "can't allocate point node"); |
2381 | 0 | new_node->next = NULL; |
2382 | | |
2383 | | /* Copy over the point's coordinates */ |
2384 | 0 | memset(new_node->pnt, 0, sizeof(hsize_t) * rank_diff); |
2385 | 0 | H5MM_memcpy(&new_node->pnt[rank_diff], base_node->pnt, |
2386 | 0 | (base_space->extent.rank * sizeof(hsize_t))); |
2387 | | |
2388 | | /* Keep the order the same when copying */ |
2389 | 0 | if (NULL == prev_node) |
2390 | 0 | prev_node = new_space->select.sel_info.pnt_lst->head = new_node; |
2391 | 0 | else { |
2392 | 0 | prev_node->next = new_node; |
2393 | 0 | prev_node = new_node; |
2394 | 0 | } /* end else */ |
2395 | | |
2396 | | /* Advance to next node */ |
2397 | 0 | base_node = base_node->next; |
2398 | 0 | } /* end while */ |
2399 | | |
2400 | | /* Update the bounding box */ |
2401 | 0 | for (u = 0; u < rank_diff; u++) { |
2402 | 0 | new_space->select.sel_info.pnt_lst->low_bounds[u] = 0; |
2403 | 0 | new_space->select.sel_info.pnt_lst->high_bounds[u] = 0; |
2404 | 0 | } /* end for */ |
2405 | 0 | for (; u < new_space->extent.rank; u++) { |
2406 | 0 | new_space->select.sel_info.pnt_lst->low_bounds[u] = |
2407 | 0 | base_space->select.sel_info.pnt_lst->low_bounds[u - rank_diff]; |
2408 | 0 | new_space->select.sel_info.pnt_lst->high_bounds[u] = |
2409 | 0 | base_space->select.sel_info.pnt_lst->high_bounds[u - rank_diff]; |
2410 | 0 | } /* end for */ |
2411 | 0 | } /* end else */ |
2412 | | |
2413 | | /* Clear cached iteration point */ |
2414 | 0 | new_space->select.sel_info.pnt_lst->last_idx = 0; |
2415 | 0 | new_space->select.sel_info.pnt_lst->last_idx_pnt = NULL; |
2416 | | |
2417 | | /* Number of elements selected will be the same */ |
2418 | 0 | new_space->select.num_elem = base_space->select.num_elem; |
2419 | | |
2420 | | /* Set selection type */ |
2421 | 0 | new_space->select.type = H5S_sel_point; |
2422 | |
|
2423 | 0 | done: |
2424 | 0 | FUNC_LEAVE_NOAPI(ret_value) |
2425 | 0 | } /* end H5S__point_project_simple() */ |
2426 | | |
2427 | | /*-------------------------------------------------------------------------- |
2428 | | NAME |
2429 | | H5Sselect_elements |
2430 | | PURPOSE |
2431 | | Specify a series of elements in the dataspace to select |
2432 | | USAGE |
2433 | | herr_t H5Sselect_elements(dsid, op, num_elem, coord) |
2434 | | hid_t dsid; IN: Dataspace ID of selection to modify |
2435 | | H5S_seloper_t op; IN: Operation to perform on current selection |
2436 | | size_t num_elem; IN: Number of elements in COORD array. |
2437 | | const hsize_t *coord; IN: The location of each element selected |
2438 | | RETURNS |
2439 | | Non-negative on success/Negative on failure |
2440 | | DESCRIPTION |
2441 | | This function selects array elements to be included in the selection for |
2442 | | the dataspace. The COORD array is a 2-D array of size <dataspace rank> |
2443 | | by NUM_ELEM (ie. a list of coordinates in the dataspace). The order of |
2444 | | the element coordinates in the COORD array specifies the order that the |
2445 | | array elements are iterated through when I/O is performed. Duplicate |
2446 | | coordinates are not checked for. The selection operator, OP, determines |
2447 | | how the new selection is to be combined with the existing selection for |
2448 | | the dataspace. Currently, only H5S_SELECT_SET is supported, which replaces |
2449 | | the existing selection with the one defined in this call. When operators |
2450 | | other than H5S_SELECT_SET are used to combine a new selection with an |
2451 | | existing selection, the selection ordering is reset to 'C' array ordering. |
2452 | | GLOBAL VARIABLES |
2453 | | COMMENTS, BUGS, ASSUMPTIONS |
2454 | | EXAMPLES |
2455 | | REVISION LOG |
2456 | | --------------------------------------------------------------------------*/ |
2457 | | herr_t |
2458 | | H5Sselect_elements(hid_t spaceid, H5S_seloper_t op, size_t num_elem, const hsize_t *coord) |
2459 | 687 | { |
2460 | 687 | H5S_t *space; /* Dataspace to modify selection of */ |
2461 | 687 | herr_t ret_value; /* Return value */ |
2462 | | |
2463 | 1.37k | FUNC_ENTER_API(FAIL) |
2464 | | |
2465 | | /* Check args */ |
2466 | 1.37k | if (NULL == (space = (H5S_t *)H5I_object_verify(spaceid, H5I_DATASPACE))) |
2467 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a dataspace"); |
2468 | 687 | if (H5S_SCALAR == H5S_GET_EXTENT_TYPE(space)) |
2469 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "point doesn't support H5S_SCALAR space"); |
2470 | 687 | if (H5S_NULL == H5S_GET_EXTENT_TYPE(space)) |
2471 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "point doesn't support H5S_NULL space"); |
2472 | 687 | if (coord == NULL || num_elem == 0) |
2473 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "elements not specified"); |
2474 | 687 | if (!(op == H5S_SELECT_SET || op == H5S_SELECT_APPEND || op == H5S_SELECT_PREPEND)) |
2475 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_UNSUPPORTED, FAIL, "unsupported operation attempted"); |
2476 | | |
2477 | | /* Call the real element selection routine */ |
2478 | 687 | if ((ret_value = H5S_select_elements(space, op, num_elem, coord)) < 0) |
2479 | 0 | HGOTO_ERROR(H5E_DATASPACE, H5E_CANTDELETE, FAIL, "can't select elements"); |
2480 | | |
2481 | 687 | done: |
2482 | | FUNC_LEAVE_API(ret_value) |
2483 | 687 | } /* end H5Sselect_elements() */ |