ADIOS_SELECTION * adios_selection_intersect_pts_pts(const ADIOS_SELECTION_POINTS_STRUCT *pts1, const ADIOS_SELECTION_POINTS_STRUCT *pts2) { const int ndim = pts1->ndim; const uint64_t max_new_npts = pts1->npoints > pts2->npoints ? pts1->npoints : pts2->npoints; uint64_t *new_pts = malloc(max_new_npts * ndim * sizeof(uint64_t)); int k; uint64_t *new_pts_ptr = new_pts; uint64_t *pts1_ptr, *pts2_ptr; const uint64_t * const pts1_end_ptr = pts1->points + pts1->npoints * ndim; const uint64_t * const pts2_end_ptr = pts2->points + pts2->npoints * ndim; uint64_t new_npts = 0; assert(pts1->ndim == pts2->ndim); if (!new_pts) { adios_error(err_no_memory, "Cannot allocate memory for POINTS-POINTS selection intersection"); return NULL; } // Check every pair of points for equality; whenever a shared point is found, output // it into the new point list for (pts1_ptr = pts1->points; pts1_ptr < pts1_end_ptr; pts1_ptr += ndim) { for (pts2_ptr = pts2->points; pts2_ptr < pts2_end_ptr; pts2_ptr += ndim) { // Check each dimension component of the pair of points for equality for (k = 0; k < ndim; k++) if (pts1_ptr[k] != pts2_ptr[k]) break; // Check whether any component was unequal; if so, skip this pair; otherwise, // output the shared point if (k != ndim) { continue; } else { memcpy(new_pts_ptr, pts1_ptr, ndim * sizeof(uint64_t)); new_pts_ptr += ndim; new_npts++; } } } if (new_npts == 0) { free(new_pts); return NULL; } else { new_pts = (uint64_t*)realloc(new_pts, new_npts * sizeof(uint64_t)); return common_read_selection_points(ndim, new_npts, new_pts); } }
ADIOS_SELECTION * adios_selection_intersect_bb_pts(const ADIOS_SELECTION_BOUNDINGBOX_STRUCT *bb1, const ADIOS_SELECTION_POINTS_STRUCT *pts2) { const int ndim = bb1->ndim; const uint64_t max_new_npts = pts2->npoints; uint64_t *new_pts = malloc(max_new_npts * ndim * sizeof(uint64_t)); int j; uint64_t *new_pts_ptr = new_pts; uint64_t *pts2_ptr; const uint64_t * const pts2_end_ptr = pts2->points + pts2->npoints * ndim; uint64_t new_npts = 0; assert(bb1->ndim == pts2->ndim); if (!new_pts) { adios_error(err_no_memory, "Cannot allocate memory for BOUNDINGBOX-POINTS selection intersection"); return NULL; } // Check every pair of points for equality; whenever a shared point is found, output // it into the new point list for (pts2_ptr = pts2->points; pts2_ptr < pts2_end_ptr; pts2_ptr += ndim) { // Check each dimension component of the point for containment in the bounding box for (j = 0; j < ndim; j++) if (pts2_ptr[j] < bb1->start[j] || pts2_ptr[j] >= bb1->start[j] + bb1->count[j]) break; // Check whether any component was out of bounds; if so, skip this point; otherwise, // output the point if (j != ndim) { continue; } else { memcpy(new_pts_ptr, pts2_ptr, ndim * sizeof(uint64_t)); new_pts_ptr += ndim; new_npts++; } } if (new_npts == 0) { free(new_pts); return NULL; } else { new_pts = (uint64_t*)realloc(new_pts, new_npts * ndim * sizeof(uint64_t)); return common_read_selection_points(ndim, new_npts, new_pts); } }
ADIOS_SELECTION * adios_selection_points (int ndim, uint64_t npoints, const uint64_t *points) { return common_read_selection_points (ndim, npoints, points); }