1 /* This file is part of the hkl library.
3 * The hkl library is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 3 of the License, or
6 * (at your option) any later version.
8 * The hkl library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with the hkl library. If not, see <http://www.gnu.org/licenses/>.
16 * Copyright (C) 2003-2013 Synchrotron SOLEIL
17 * L'Orme des Merisiers Saint-Aubin
18 * BP 48 91192 GIF-sur-YVETTE CEDEX
20 * Authors: Picca Frédéric-Emmanuel <picca@synchrotron-soleil.fr>
21 * Jens Krüger <jens.krueger@frm.tum.de>
24 #include <tap/basic.h>
25 #include <tap/hkl-tap.h>
27 static void getter(void)
30 HklEngineList
*engines
;
32 const HklFactory
*factory
;
33 HklGeometry
*geometry
;
34 HklDetector
*detector
;
37 factory
= hkl_factory_get_by_name("E4CH");
38 geometry
= hkl_factory_create_new_geometry(factory
);
39 sample
= hkl_sample_new("test");
41 detector
= hkl_detector_factory_new(HKL_DETECTOR_TYPE_0D
);
42 hkl_detector_idx_set(detector
, 1);
44 engines
= hkl_factory_create_new_engine_list(factory
);
45 hkl_engine_list_init(engines
, geometry
, detector
, sample
);
47 engine
= hkl_engine_list_engine_get_by_name(engines
, "hkl");
49 /* geometry -> pseudo */
50 hkl_geometry_set_values_unit_v(geometry
, 30., 0., 0., 60.);
51 hkl_engine_get(engine
, NULL
);
52 res
&= check_pseudoaxes_v(engine
, 0., 1., 0.);
54 hkl_geometry_set_values_unit_v(geometry
, 30., 0., 90., 60.);
55 hkl_engine_get(engine
, NULL
);
56 res
&= check_pseudoaxes_v(engine
, 1., 0., 0.);
58 hkl_geometry_set_values_unit_v(geometry
, 30., 0., -90., 60.);
59 hkl_engine_get(engine
, NULL
);
60 res
&= check_pseudoaxes_v(engine
, -1., 0., 0.);
62 hkl_geometry_set_values_unit_v(geometry
, 30., 0., 180., 60.);
63 hkl_engine_get(engine
, NULL
);
64 res
&= check_pseudoaxes_v(engine
, 0., -1., 0.);
66 hkl_geometry_set_values_unit_v(geometry
, 45., 0., 135., 90.);
67 hkl_engine_get(engine
, NULL
);
68 res
&= check_pseudoaxes_v(engine
, 1., -1., 0.);
70 ok(res
== HKL_TRUE
, "getter");
72 hkl_engine_list_free(engines
);
73 hkl_detector_free(detector
);
74 hkl_sample_free(sample
);
75 hkl_geometry_free(geometry
);
78 static void degenerated(void)
81 HklEngineList
*engines
;
85 const HklFactory
*factory
;
86 HklGeometry
*geometry
;
87 const HklGeometryList
*geometries
;
88 HklDetector
*detector
;
90 HklParameterList
*pseudo_axes
;
92 factory
= hkl_factory_get_by_name("E4CH");
93 geometry
= hkl_factory_create_new_geometry(factory
);
94 sample
= hkl_sample_new("test");
96 detector
= hkl_detector_factory_new(HKL_DETECTOR_TYPE_0D
);
97 hkl_detector_idx_set(detector
, 1);
99 engines
= hkl_factory_create_new_engine_list(factory
);
100 hkl_engine_list_init(engines
, geometry
, detector
, sample
);
101 geometries
= hkl_engine_list_geometries_get(engines
);
103 engine
= hkl_engine_list_engine_get_by_name(engines
, "hkl");
104 modes
= hkl_engine_modes_get(engine
);
105 pseudo_axes
= hkl_engine_pseudo_axes_get(engine
);
107 darray_foreach(mode
, *modes
){
108 static double values
[] = {0, 0, 1};
109 darray_parameter
*parameters
;
111 hkl_engine_select_mode(engine
, *mode
);
112 parameters
= hkl_mode_parameters_get(*mode
);
113 if (darray_size(*parameters
))
114 hkl_parameter_value_set(darray_item(*parameters
, 0), 0, NULL
);
116 /* studdy this degenerated case */
117 hkl_parameter_list_values_set(pseudo_axes
, values
, 3, NULL
);
118 if(hkl_engine_set(engine
, NULL
)){
119 const HklGeometryListItem
*item
;
121 HKL_GEOMETRY_LIST_FOREACH(item
, geometries
){
122 static double null
[] = {0, 0, 0};
124 hkl_parameter_list_values_set(pseudo_axes
, null
, 3, NULL
);
125 hkl_geometry_set(geometry
,
126 hkl_geometry_list_item_geometry_get(item
));
127 hkl_engine_get(engine
, NULL
);
128 res
&= check_pseudoaxes(engine
, values
, 3);
133 ok(res
== HKL_TRUE
, "degenerated");
135 hkl_engine_list_free(engines
);
136 hkl_detector_free(detector
);
137 hkl_sample_free(sample
);
138 hkl_geometry_free(geometry
);
141 static void psi_getter(void)
144 HklEngineList
*engines
;
146 const HklFactory
*factory
;
147 HklGeometry
*geometry
;
148 HklDetector
*detector
;
152 HklParameterList
*parameters
;
154 factory
= hkl_factory_get_by_name("E4CH");
155 geometry
= hkl_factory_create_new_geometry(factory
);
156 sample
= hkl_sample_new("test");
158 detector
= hkl_detector_factory_new(HKL_DETECTOR_TYPE_0D
);
159 hkl_detector_idx_set(detector
, 1);
161 engines
= hkl_factory_create_new_engine_list(factory
);
162 hkl_engine_list_init(engines
, geometry
, detector
, sample
);
164 engine
= hkl_engine_list_engine_get_by_name(engines
, "psi");
165 mode
= hkl_engine_mode_get(engine
);
166 parameters
= hkl_mode_parameters_get(mode
);
168 /* the getter part */
169 hkl_geometry_set_values_unit_v(geometry
, 30., 0., 0., 60.);
170 hkl_engine_initialize(engine
, NULL
);
172 hkl
[0] = 1, hkl
[1] = 0, hkl
[2] = 0;
173 hkl_parameter_list_values_set(parameters
,
174 hkl
, ARRAY_SIZE(hkl
), NULL
);
175 res
&= hkl_engine_get(engine
, NULL
);
176 res
&= check_pseudoaxes_v(engine
, 0.);
178 /* here Q and <h, k, l>_ref are colinear must FAIL */
179 hkl
[0] = 0, hkl
[1] = 1, hkl
[2] = 0;
180 hkl_parameter_list_values_set(parameters
,
181 hkl
, ARRAY_SIZE(hkl
), NULL
);
182 res
&= !hkl_engine_get(engine
, NULL
);
184 hkl
[0] = -1, hkl
[1] = 0, hkl
[2] = 0;
185 hkl_parameter_list_values_set(parameters
,
186 hkl
, ARRAY_SIZE(hkl
), NULL
);
187 res
&= hkl_engine_get(engine
, NULL
);
188 res
&= check_pseudoaxes_v(engine
, 180. * HKL_DEGTORAD
);
190 hkl
[0] = 0, hkl
[1] = 0, hkl
[2] = -1;
191 hkl_parameter_list_values_set(parameters
,
192 hkl
, ARRAY_SIZE(hkl
), NULL
);
193 res
&= hkl_engine_get(engine
, NULL
);
194 res
&= check_pseudoaxes_v(engine
, 90. * HKL_DEGTORAD
);
196 /* Q and <h, k, l>_ref are colinear so must FAIL */
197 hkl
[0] = 0, hkl
[1] = -1, hkl
[2] = 0;
198 hkl_parameter_list_values_set(parameters
,
199 hkl
, ARRAY_SIZE(hkl
), NULL
);
200 res
&= !hkl_engine_get(engine
, NULL
);
202 ok(res
== HKL_TRUE
, "psi getter");
204 hkl_engine_list_free(engines
);
205 hkl_detector_free(detector
);
206 hkl_sample_free(sample
);
207 hkl_geometry_free(geometry
);
210 static void psi_setter(void)
213 HklEngineList
*engines
;
217 const HklFactory
*factory
;
218 HklGeometry
*geometry
;
219 const HklGeometryList
*geometries
;
220 HklDetector
*detector
;
222 static double hkl
[] = {1, 0, 0};
223 HklParameterList
*pseudo_axes
;
225 factory
= hkl_factory_get_by_name("E4CH");
226 geometry
= hkl_factory_create_new_geometry(factory
);
227 sample
= hkl_sample_new("test");
229 detector
= hkl_detector_factory_new(HKL_DETECTOR_TYPE_0D
);
230 hkl_detector_idx_set(detector
, 1);
232 engines
= hkl_factory_create_new_engine_list(factory
);
233 hkl_engine_list_init(engines
, geometry
, detector
, sample
);
234 geometries
= hkl_engine_list_geometries_get(engines
);
236 engine
= hkl_engine_list_engine_get_by_name(engines
, "psi");
237 modes
= hkl_engine_modes_get(engine
);
238 pseudo_axes
= hkl_engine_pseudo_axes_get(engine
);
241 hkl_geometry_set_values_unit_v(geometry
, 30., 0., 0., 60.);
242 hkl_parameter_list_values_set(hkl_mode_parameters_get(hkl_engine_mode_get(engine
)),
243 hkl
, ARRAY_SIZE(hkl
), NULL
);
244 hkl_engine_initialize(engine
, NULL
);
246 darray_foreach(mode
, *modes
){
249 hkl_engine_select_mode(engine
, *mode
);
250 for(psi
=-180 * HKL_DEGTORAD
;psi
<180 * HKL_DEGTORAD
;psi
+= HKL_DEGTORAD
){
251 hkl_parameter_list_values_set(pseudo_axes
, &psi
, 1, NULL
);
252 if(hkl_engine_set(engine
, NULL
)){
253 const HklGeometryListItem
*item
;
255 HKL_GEOMETRY_LIST_FOREACH(item
, geometries
){
256 static double null
[] = {0};
258 hkl_parameter_list_values_set(pseudo_axes
,
259 null
, ARRAY_SIZE(null
),
261 hkl_geometry_set(geometry
,
262 hkl_geometry_list_item_geometry_get(item
));
263 hkl_engine_get(engine
, NULL
);
264 res
&= check_pseudoaxes_v(engine
, psi
);
270 ok(res
== HKL_TRUE
, "psi setter");
272 hkl_engine_list_free(engines
);
273 hkl_detector_free(detector
);
274 hkl_sample_free(sample
);
275 hkl_geometry_free(geometry
);
282 HklEngineList
*engines
;
286 const HklFactory
*factory
;
287 HklGeometry
*geometry
;
288 const HklGeometryList
*geometries
;
289 HklDetector
*detector
;
291 HklParameterList
*pseudo_axes
;
293 factory
= hkl_factory_get_by_name("E4CH");
294 geometry
= hkl_factory_create_new_geometry(factory
);
295 sample
= hkl_sample_new("test");
297 detector
= hkl_detector_factory_new(HKL_DETECTOR_TYPE_0D
);
298 hkl_detector_idx_set(detector
, 1);
300 engines
= hkl_factory_create_new_engine_list(factory
);
301 hkl_engine_list_init(engines
, geometry
, detector
, sample
);
302 geometries
= hkl_engine_list_geometries_get(engines
);
304 engine
= hkl_engine_list_engine_get_by_name(engines
, "q");
305 modes
= hkl_engine_modes_get(engine
);
306 pseudo_axes
= hkl_engine_pseudo_axes_get(engine
);
309 hkl_geometry_set_values_unit_v(geometry
, 30., 0., 0., 60.);
310 hkl_engine_initialize(engine
, NULL
);
312 darray_foreach(mode
, *modes
){
315 hkl_engine_select_mode(engine
, *mode
);
316 for(q
=-1.; q
<1.; q
+= 0.1){
317 hkl_parameter_list_values_set(pseudo_axes
, &q
, 1, NULL
);
319 if(hkl_engine_set(engine
, NULL
)){
320 const HklGeometryListItem
*item
;
322 HKL_GEOMETRY_LIST_FOREACH(item
, geometries
){
323 static double null
[] = {0};
324 hkl_parameter_list_values_set(pseudo_axes
,
325 null
, ARRAY_SIZE(null
),
328 hkl_geometry_set(geometry
,
329 hkl_geometry_list_item_geometry_get(item
));
330 hkl_engine_get(engine
, NULL
);
331 res
&= check_pseudoaxes(engine
, &q
, 1);
337 ok(res
== HKL_TRUE
, "q");
339 hkl_engine_list_free(engines
);
340 hkl_detector_free(detector
);
341 hkl_sample_free(sample
);
342 hkl_geometry_free(geometry
);
345 static void hkl_psi_constant_horizontal(void)
348 HklEngineList
*engines
;
351 const HklFactory
*factory
;
352 HklGeometry
*geometry
;
353 const HklGeometryList
*geometries
;
354 HklDetector
*detector
;
356 static double hkl
[] = {1, 0, 1};
357 static double hkl2
[] = {1, 1, 0};
358 HklParameterList
*pseudo_axes
;
360 factory
= hkl_factory_get_by_name("E4CH");
361 geometry
= hkl_factory_create_new_geometry(factory
);
362 sample
= hkl_sample_new("test");
364 detector
= hkl_detector_factory_new(HKL_DETECTOR_TYPE_0D
);
365 hkl_detector_idx_set(detector
, 1);
367 engines
= hkl_factory_create_new_engine_list(factory
);
368 hkl_engine_list_init(engines
, geometry
, detector
, sample
);
369 geometries
= hkl_engine_list_geometries_get(engines
);
371 engine
= hkl_engine_list_engine_get_by_name(engines
, "hkl");
372 mode
= hkl_engine_mode_get(engine
);
373 pseudo_axes
= hkl_engine_pseudo_axes_get(engine
);
375 hkl_engine_select_mode_by_name(engine
,
379 hkl_geometry_set_values_unit_v(geometry
, 30., 0., 0., 60.);
380 hkl_parameter_list_values_set(hkl_mode_parameters_get(mode
),
381 hkl2
, ARRAY_SIZE(hkl2
), NULL
);
382 hkl_engine_initialize(engine
, NULL
);
384 hkl_parameter_list_values_set(pseudo_axes
,
385 hkl
, ARRAY_SIZE(hkl
), NULL
);
386 if(hkl_engine_set(engine
, NULL
)){
387 const HklGeometryListItem
*item
;
389 HKL_GEOMETRY_LIST_FOREACH(item
, geometries
){
390 static double null
[] = {0, 0, 0};
392 hkl_parameter_list_values_set(pseudo_axes
,
393 null
, ARRAY_SIZE(null
),
395 hkl_geometry_set(geometry
,
396 hkl_geometry_list_item_geometry_get(item
));
397 hkl_engine_get(engine
, NULL
);
398 res
&= check_pseudoaxes(engine
, hkl
, ARRAY_SIZE(hkl
));
402 ok(res
== HKL_TRUE
, "psi constant horizontal");
404 hkl_engine_list_free(engines
);
405 hkl_detector_free(detector
);
406 hkl_sample_free(sample
);
407 hkl_geometry_free(geometry
);
410 int main(int argc
, char** argv
)
419 hkl_psi_constant_horizontal();