19#define YAC_RAD (0.01745329251994329576923690768489)
21static void utest_check_point_selection(
24 size_t num_points,
size_t * ref_selected_points,
25 size_t ref_num_selected_points);
26static void utest_check_compare(
33 int comm_rank, comm_size;
34 MPI_Comm_rank(MPI_COMM_WORLD, &comm_rank);
35 MPI_Comm_size(MPI_COMM_WORLD, &comm_size);
37 YAC_ASSERT(comm_size == 1,
"ERROR wrong number of processes (has to be 1)")
39 enum {NLON = 36, NLAT = 19};
41 malloc(NLON * NLAT *
sizeof(*point_coords));
42 for (
int i = 0, k = 0;
i < NLAT; ++
i)
43 for (
int j = 0; j < NLON; ++j, ++k)
44 LLtoXYZ_deg((
double)(10 * j), (
double)(-90 + 10 * i), point_coords[k]);
52 for (
size_t i = 0;
i <
NUM_POINTS; ++
i) point_indices[i] = i;
53 enum {REF_NUM_SELECTED_POINTS = 0};
54 size_t * ref_selected_points = NULL;
56 utest_check_point_selection(
58 point_indices,
NUM_POINTS, ref_selected_points, REF_NUM_SELECTED_POINTS);
75 for (
size_t i = 0, k = 0;
i < 3; ++
i)
76 for (
size_t j = 0; j < NLAT; ++j, ++k)
77 point_indices[k] = i * 10 + j * NLON;
78 enum {REF_NUM_SELECTED_POINTS = 6};
79 size_t ref_selected_points[REF_NUM_SELECTED_POINTS] =
80 {(NLAT - 2) * NLON + 0 * 10, (NLAT - 1) * NLON + 0 * 10,
81 (NLAT - 2) * NLON + 1 * 10, (NLAT - 1) * NLON + 1 * 10,
82 (NLAT - 2) * NLON + 2 * 10, (NLAT - 1) * NLON + 2 * 10};
84 utest_check_point_selection(
86 point_indices,
NUM_POINTS, ref_selected_points, REF_NUM_SELECTED_POINTS);
102 NUM_POINT_SELECTIONS =
103 sizeof(point_selections)/
sizeof(point_selections[0])
106 for (
size_t i = 0;
i < NUM_POINT_SELECTIONS; ++
i) {
107 for (
size_t j = i + 1; j < NUM_POINT_SELECTIONS; ++j)
108 utest_check_compare(point_selections[i], point_selections[j]);
122 size_t const * a_ = a, * b_ = b;
124 return (*a_ > *b_) - (*b_ > *a_);
127static void utest_check_point_selection_(
130 size_t num_points,
size_t * ref_sorted_points,
131 size_t * ref_sorted_selected_points,
size_t ref_num_selected_points) {
133 size_t * point_indices_copy =
134 malloc(
num_points *
sizeof(*point_indices_copy));
136 point_indices_copy, point_indices,
num_points *
sizeof(*point_indices));
138 malloc(
num_points *
sizeof(*selected_point_coords));
141 selected_point_coords[i], point_coords[point_indices[i]],
142 sizeof(*selected_point_coords));
144 size_t num_selected_points;
147 point_selection, selected_point_coords, point_indices_copy,
num_points,
148 &num_selected_points);
150 if (num_selected_points == ref_num_selected_points) {
155 point_indices_copy +
num_points - num_selected_points,
156 num_selected_points,
sizeof(*point_indices_copy),
compare_size_t);
157 for (
size_t i = 0, j =
num_points - num_selected_points;
158 i < num_selected_points; ++
i, ++j)
159 if (point_indices_copy[j] != ref_sorted_selected_points[i])
160 PUT_ERR(
"error in selected point within original point list");
164 point_indices_copy,
num_points,
sizeof(*point_indices_copy),
167 if (point_indices_copy[i] != ref_sorted_points[i])
168 PUT_ERR(
"error in original point list");
171 PUT_ERR(
"wrong number of selected points");
174 free(selected_point_coords);
175 free(point_indices_copy);
178static void utest_check_point_selection(
181 size_t num_points,
size_t * ref_selected_points,
182 size_t ref_num_selected_points) {
184 size_t * sorted_point_indices =
185 malloc(
num_points *
sizeof(*sorted_point_indices));
187 sorted_point_indices, point_indices,
num_points *
sizeof(*point_indices));
189 sorted_point_indices,
num_points,
sizeof(*sorted_point_indices),
192 ref_selected_points, ref_num_selected_points,
sizeof(*ref_selected_points),
196 utest_check_point_selection_(
197 point_selection, point_coords, point_indices,
num_points,
198 sorted_point_indices, ref_selected_points, ref_num_selected_points);
204 utest_check_point_selection_(
205 point_selection_copy, point_coords, point_indices,
num_points,
206 sorted_point_indices, ref_selected_points, ref_num_selected_points);
213 void * pack_buffer = malloc(pack_size);
216 point_selection, pack_buffer, (
int)pack_size, &position, MPI_COMM_WORLD);
220 pack_buffer, (
int)pack_size, &position, MPI_COMM_WORLD);
222 utest_check_point_selection_(
223 point_selection_copy, point_coords, point_indices,
num_points,
224 sorted_point_indices, ref_selected_points, ref_num_selected_points);
228 free(sorted_point_indices);
231static void utest_check_compare(
235 PUT_ERR(
"error in yac_point_selection_compare (a != a)")
#define YAC_ASSERT(exp, msg)
static void LLtoXYZ_deg(double lon, double lat, double p_out[])
int yac_point_selection_compare(struct yac_point_selection const *a, struct yac_point_selection const *b)
struct yac_point_selection * yac_point_selection_bnd_circle_new(double center_lon, double center_lat, double inc_angle)
struct yac_point_selection * yac_point_selection_unpack(void const *buffer, int buffer_size, int *position, MPI_Comm comm)
struct yac_point_selection * yac_point_selection_copy(struct yac_point_selection const *point_select)
void yac_point_selection_apply(struct yac_point_selection const *point_select, yac_coordinate_pointer point_coords, size_t *point_indices, size_t num_points, size_t *num_selected_points)
void yac_point_selection_pack(struct yac_point_selection const *point_select, void *buffer, int buffer_size, int *position, MPI_Comm comm)
size_t yac_point_selection_get_pack_size(struct yac_point_selection const *point_select, MPI_Comm comm)
void yac_point_selection_delete(struct yac_point_selection *point_select)
static int compare_size_t(const void *a, const void *b)
double const (* yac_const_coordinate_pointer)[3]
double(* yac_coordinate_pointer)[3]