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>
23 #include <tap/basic.h>
24 #include <tap/hkl-tap.h>
26 static void getter(void)
29 HklEngineList
*engines
;
31 const HklFactory
*factory
;
33 HklDetector
*detector
;
36 factory
= hkl_factory_get_by_name("E4CV");
37 geom
= hkl_factory_create_new_geometry(factory
);
38 sample
= hkl_sample_new("test");
40 detector
= hkl_detector_factory_new(HKL_DETECTOR_TYPE_0D
);
41 hkl_detector_idx_set(detector
, 1);
43 engines
= hkl_factory_create_new_engine_list(factory
);
44 hkl_engine_list_init(engines
, geom
, detector
, sample
);
46 engine
= hkl_engine_list_get_by_name(engines
, "hkl");
48 /* geometry -> pseudo */
49 hkl_geometry_set_values_unit_v(geom
, 30., 0., 0., 60.);
50 hkl_engine_get(engine
, NULL
);
51 res
&= check_pseudoaxes_v(engine
, 0., 0., 1.);
53 hkl_geometry_set_values_unit_v(geom
, 30., 0., 90., 60.);
54 hkl_engine_get(engine
, NULL
);
55 res
&= check_pseudoaxes_v(engine
, 1., 0., 0.);
57 hkl_geometry_set_values_unit_v(geom
, 30., 0., -90., 60.);
58 hkl_engine_get(engine
, NULL
);
59 res
&= check_pseudoaxes_v(engine
, -1., 0., 0.);
61 hkl_geometry_set_values_unit_v(geom
, 30., 0., 180., 60.);
62 hkl_engine_get(engine
, NULL
);
63 res
&= check_pseudoaxes_v(engine
, 0., 0., -1.);
65 hkl_geometry_set_values_unit_v(geom
, 45., 0., 135., 90.);
66 hkl_engine_get(engine
, NULL
);
67 res
&= check_pseudoaxes_v(engine
, 1., 0., -1.);
69 ok(res
== HKL_TRUE
, "getter");
71 hkl_engine_list_free(engines
);
72 hkl_detector_free(detector
);
73 hkl_sample_free(sample
);
74 hkl_geometry_free(geom
);
77 static void degenerated(void)
80 HklEngineList
*engines
;
84 const HklFactory
*factory
;
85 HklGeometry
*geometry
;
86 HklDetector
*detector
;
88 const HklGeometryList
*geometries
;
90 factory
= hkl_factory_get_by_name("E4CV");
91 geometry
= hkl_factory_create_new_geometry(factory
);
92 sample
= hkl_sample_new("test");
94 detector
= hkl_detector_factory_new(HKL_DETECTOR_TYPE_0D
);
95 hkl_detector_idx_set(detector
, 1);
97 engines
= hkl_factory_create_new_engine_list(factory
);
98 hkl_engine_list_init(engines
, geometry
, detector
, sample
);
99 geometries
= hkl_engine_list_geometries(engines
);
101 engine
= hkl_engine_list_get_by_name(engines
, "hkl");
102 modes
= hkl_engine_modes(engine
);
104 darray_foreach(mode
, *modes
){
105 static double values
[] = {0, 0, 1};
106 HklParameterList
*pseudo_axes
= hkl_engine_pseudo_axes(engine
);
107 darray_parameter
*parameters
= hkl_mode_parameters(*mode
);
109 hkl_engine_select_mode(engine
, *mode
);
110 if (darray_size(*parameters
))
111 hkl_parameter_value_set(darray_item(*parameters
, 0), 0, NULL
);
113 /* studdy this degenerated case */
114 hkl_parameter_list_values_set(pseudo_axes
, values
, 3, NULL
);
116 if(hkl_engine_set(engine
, NULL
)){
117 const darray_item
*items
= hkl_geometry_list_items_get(geometries
);
118 HklGeometryListItem
**item
;
120 darray_foreach(item
, *items
){
121 static double null
[] = {0, 0, 0};
123 hkl_parameter_list_values_set(pseudo_axes
, null
, 3, NULL
);
124 hkl_geometry_set(geometry
,
125 hkl_geometry_list_item_geometry_get(*item
));
126 hkl_engine_get(engine
, NULL
);
127 res
&= check_pseudoaxes(engine
, values
, 3);
132 ok(res
== HKL_TRUE
, "degenerated");
134 hkl_engine_list_free(engines
);
135 hkl_detector_free(detector
);
136 hkl_sample_free(sample
);
137 hkl_geometry_free(geometry
);
140 static void psi_getter(void)
143 HklEngineList
*engines
;
146 HklParameterList
*parameters
;
147 const HklFactory
*factory
;
149 HklDetector
*detector
;
153 factory
= hkl_factory_get_by_name("E4CV");
154 geom
= hkl_factory_create_new_geometry(factory
);
155 sample
= hkl_sample_new("test");
157 detector
= hkl_detector_factory_new(HKL_DETECTOR_TYPE_0D
);
158 hkl_detector_idx_set(detector
, 1);
160 engines
= hkl_factory_create_new_engine_list(factory
);
161 hkl_engine_list_init(engines
, geom
, detector
, sample
);
163 engine
= hkl_engine_list_get_by_name(engines
, "psi");
164 mode
= hkl_engine_mode(engine
);
165 parameters
= hkl_mode_parameters(mode
);
167 /* the getter part */
168 hkl_geometry_set_values_unit_v(geom
, 30., 0., 0., 60.);
169 hkl_engine_initialize(engine
, NULL
);
171 hkl
[0] = 1, hkl
[1] = 0, hkl
[2] = 0;
172 hkl_parameter_list_values_set(parameters
,
173 hkl
, ARRAY_SIZE(hkl
), NULL
);
174 res
&= hkl_engine_get(engine
, NULL
);
175 res
&= check_pseudoaxes_v(engine
, 0.);
177 hkl
[0] = 0, hkl
[1] = 1, hkl
[2] = 0;
178 hkl_parameter_list_values_set(parameters
,
179 hkl
, ARRAY_SIZE(hkl
), NULL
);
180 res
&= hkl_engine_get(engine
, NULL
);
181 res
&= check_pseudoaxes_v(engine
, 90. * HKL_DEGTORAD
);
183 /* here Q and <h, k, l>_ref are colinear must FAIL */
184 hkl
[0] = 0, hkl
[1] = 0, hkl
[2] = 1;
185 hkl_parameter_list_values_set(parameters
,
186 hkl
, ARRAY_SIZE(hkl
), NULL
);
187 res
&= !hkl_engine_get(engine
, NULL
);
189 hkl
[0] = -1, hkl
[1] = 0, hkl
[2] = 0;
190 hkl_parameter_list_values_set(parameters
,
191 hkl
, ARRAY_SIZE(hkl
), NULL
);
192 res
&= hkl_engine_get(engine
, NULL
);
193 res
&= check_pseudoaxes_v(engine
, 180. * HKL_DEGTORAD
);
195 hkl
[0] = 0, hkl
[1] = -1, hkl
[2] = 0;
196 hkl_parameter_list_values_set(parameters
,
197 hkl
, ARRAY_SIZE(hkl
), NULL
);
198 res
&= hkl_engine_get(engine
, NULL
);
199 res
&= check_pseudoaxes_v(engine
, -90. * HKL_DEGTORAD
);
201 /* Q and <h, k, l>_ref are colinear so must FAIL */
202 hkl
[0] = 0, hkl
[1] = 0, hkl
[2] = -1;
203 hkl_parameter_list_values_set(parameters
,
204 hkl
, ARRAY_SIZE(hkl
), NULL
);
205 res
&= !hkl_engine_get(engine
, NULL
);
207 ok(res
== HKL_TRUE
, "psi getter");
209 hkl_engine_list_free(engines
);
210 hkl_detector_free(detector
);
211 hkl_sample_free(sample
);
212 hkl_geometry_free(geom
);
215 static void psi_setter(void)
218 HklEngineList
*engines
;
220 HklParameterList
*pseudo_axes
;
223 HklParameterList
*parameters
;
224 const HklFactory
*factory
;
225 HklGeometry
*geometry
;
226 HklDetector
*detector
;
228 static double hkl
[] = {1, 0, 0};
229 const HklGeometryList
*geometries
;
231 factory
= hkl_factory_get_by_name("E4CV");
232 geometry
= hkl_factory_create_new_geometry(factory
);
233 sample
= hkl_sample_new("test");
235 detector
= hkl_detector_factory_new(HKL_DETECTOR_TYPE_0D
);
236 hkl_detector_idx_set(detector
, 1);
238 engines
= hkl_factory_create_new_engine_list(factory
);
239 hkl_engine_list_init(engines
, geometry
, detector
, sample
);
240 geometries
= hkl_engine_list_geometries(engines
);
242 engine
= hkl_engine_list_get_by_name(engines
, "psi");
243 pseudo_axes
= hkl_engine_pseudo_axes(engine
);
244 modes
= hkl_engine_modes(engine
);
245 parameters
= hkl_mode_parameters(hkl_engine_mode(engine
));
248 hkl_geometry_set_values_unit_v(geometry
, 30., 0., 0., 60.);
249 hkl_parameter_list_values_set(parameters
,
250 hkl
, ARRAY_SIZE(hkl
), NULL
);
251 hkl_engine_initialize(engine
, NULL
);
253 darray_foreach(mode
, *modes
){
256 hkl_engine_select_mode(engine
, *mode
);
257 for(psi
=-180 * HKL_DEGTORAD
;psi
<180 * HKL_DEGTORAD
;psi
+= HKL_DEGTORAD
){
258 hkl_parameter_list_values_set(pseudo_axes
, &psi
, 1, NULL
);
259 if(hkl_engine_set(engine
, NULL
)){
260 const darray_item
*items
= hkl_geometry_list_items_get(geometries
);
261 HklGeometryListItem
**item
;
263 darray_foreach(item
, *items
){
264 static double null
[] = {0};
266 hkl_parameter_list_values_set(pseudo_axes
, null
, 1, NULL
);
267 hkl_geometry_set(geometry
,
268 hkl_geometry_list_item_geometry_get(*item
));
269 hkl_engine_get(engine
, NULL
);
270 res
&= check_pseudoaxes_v(engine
, psi
);
276 ok(res
== HKL_TRUE
, "psi setter");
278 hkl_engine_list_free(engines
);
279 hkl_detector_free(detector
);
280 hkl_sample_free(sample
);
281 hkl_geometry_free(geometry
);
287 HklEngineList
*engines
;
291 const HklFactory
*factory
;
292 HklGeometry
*geometry
;
293 HklDetector
*detector
;
295 const HklGeometryList
*geometries
;
297 factory
= hkl_factory_get_by_name("E4CV");
298 geometry
= hkl_factory_create_new_geometry(factory
);
299 sample
= hkl_sample_new("test");
301 detector
= hkl_detector_factory_new(HKL_DETECTOR_TYPE_0D
);
302 hkl_detector_idx_set(detector
, 1);
304 engines
= hkl_factory_create_new_engine_list(factory
);
305 hkl_engine_list_init(engines
, geometry
, detector
, sample
);
306 geometries
= hkl_engine_list_geometries(engines
);
308 engine
= hkl_engine_list_get_by_name(engines
, "q");
309 modes
= hkl_engine_modes(engine
);
312 hkl_geometry_set_values_unit_v(geometry
, 30., 0., 0., 60.);
313 hkl_engine_initialize(engine
, NULL
);
315 darray_foreach(mode
, *modes
){
317 HklParameterList
*pseudo_axes
= hkl_engine_pseudo_axes(engine
);
319 hkl_engine_select_mode(engine
, *mode
);
320 for(q
=-1.; q
<1.; q
+= 0.1){
321 hkl_parameter_list_values_set(pseudo_axes
, &q
, 1, NULL
);
322 if(hkl_engine_set(engine
, NULL
)){
323 const darray_item
*items
= hkl_geometry_list_items_get(geometries
);
324 HklGeometryListItem
**item
;
326 darray_foreach(item
, *items
){
327 static double null
[] = {0};
329 hkl_parameter_list_values_set(pseudo_axes
, null
, 1, NULL
);
330 hkl_geometry_set(geometry
,
331 hkl_geometry_list_item_geometry_get(*item
));
332 hkl_engine_get(engine
, NULL
);
333 res
&= check_pseudoaxes(engine
, &q
, 1);
339 ok(res
== HKL_TRUE
, "q");
341 hkl_engine_list_free(engines
);
342 hkl_detector_free(detector
);
343 hkl_sample_free(sample
);
344 hkl_geometry_free(geometry
);
347 static void hkl_psi_constant_vertical(void)
350 HklEngineList
*engines
;
352 const HklFactory
*factory
;
353 HklGeometry
*geometry
;
354 const HklGeometryList
*geometries
;
355 HklDetector
*detector
;
357 static double hkl
[] = {1, 0, 1};
358 static double hkl2
[] = {1, 1, 0};
359 HklParameterList
*pseudo_axes
;
361 HklParameterList
*parameters
;
363 factory
= hkl_factory_get_by_name("E4CV");
364 geometry
= hkl_factory_create_new_geometry(factory
);
365 sample
= hkl_sample_new("test");
367 detector
= hkl_detector_factory_new(HKL_DETECTOR_TYPE_0D
);
368 hkl_detector_idx_set(detector
, 1);
370 engines
= hkl_factory_create_new_engine_list(factory
);
371 hkl_engine_list_init(engines
, geometry
, detector
, sample
);
372 geometries
= hkl_engine_list_geometries(engines
);
374 engine
= hkl_engine_list_get_by_name(engines
, "hkl");
375 pseudo_axes
= hkl_engine_pseudo_axes(engine
);
377 hkl_engine_select_mode_by_name(engine
,
380 mode
= hkl_engine_mode(engine
);
381 parameters
= hkl_mode_parameters(mode
);
384 hkl_geometry_set_values_unit_v(geometry
, 30., 0., 0., 60.);
385 hkl_parameter_list_values_set(parameters
,
386 hkl2
, ARRAY_SIZE(hkl2
), NULL
);
387 hkl_engine_initialize(engine
, NULL
);
389 hkl_parameter_list_values_set(pseudo_axes
,
390 hkl
, ARRAY_SIZE(hkl
), NULL
);
391 if(hkl_engine_set(engine
, NULL
)){
392 const darray_item
*items
= hkl_geometry_list_items_get(geometries
);
393 HklGeometryListItem
**item
;
395 darray_foreach(item
, *items
){
396 static double null
[] = {0, 0, 0};
398 hkl_parameter_list_values_set(pseudo_axes
,
399 null
, ARRAY_SIZE(null
),
401 hkl_geometry_set(geometry
,
402 hkl_geometry_list_item_geometry_get(*item
));
403 hkl_engine_get(engine
, NULL
);
404 res
&= check_pseudoaxes(engine
, hkl
, ARRAY_SIZE(hkl
));
408 ok(res
== HKL_TRUE
, "psi constant vertical");
410 hkl_engine_list_free(engines
);
411 hkl_detector_free(detector
);
412 hkl_sample_free(sample
);
413 hkl_geometry_free(geometry
);
416 int main(int argc
, char** argv
)
425 hkl_psi_constant_vertical();