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-2015 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", NULL
);
38 geometry
= hkl_factory_create_new_geometry(factory
);
39 sample
= hkl_sample_new("test");
41 detector
= hkl_detector_factory_new(HKL_DETECTOR_TYPE_0D
);
43 engines
= hkl_factory_create_new_engine_list(factory
);
44 hkl_engine_list_init(engines
, geometry
, detector
, sample
);
46 engine
= hkl_engine_list_engine_get_by_name(engines
, "hkl", NULL
);
48 /* geometry -> pseudo */
49 hkl_geometry_set_values_v(geometry
, HKL_UNIT_USER
, NULL
, 30., 0., 0., 60.);
50 res
&= DIAG(check_pseudoaxes_v(engine
, 0., 1., 0.));
52 hkl_geometry_set_values_v(geometry
, HKL_UNIT_USER
, NULL
, 30., 0., 90., 60.);
53 res
&= DIAG(check_pseudoaxes_v(engine
, 1., 0., 0.));
55 hkl_geometry_set_values_v(geometry
, HKL_UNIT_USER
, NULL
, 30., 0., -90., 60.);
56 res
&= DIAG(check_pseudoaxes_v(engine
, -1., 0., 0.));
58 hkl_geometry_set_values_v(geometry
, HKL_UNIT_USER
, NULL
, 30., 0., 180., 60.);
59 res
&= DIAG(check_pseudoaxes_v(engine
, 0., -1., 0.));
61 hkl_geometry_set_values_v(geometry
, HKL_UNIT_USER
, NULL
, 45., 0., 135., 90.);
62 res
&= DIAG(check_pseudoaxes_v(engine
, 1., -1., 0.));
64 ok(res
== TRUE
, "getter");
66 hkl_engine_list_free(engines
);
67 hkl_detector_free(detector
);
68 hkl_sample_free(sample
);
69 hkl_geometry_free(geometry
);
72 static void degenerated(void)
75 HklEngineList
*engines
;
78 const darray_string
*modes
;
79 const HklFactory
*factory
;
80 HklGeometry
*geometry
;
81 HklDetector
*detector
;
84 factory
= hkl_factory_get_by_name("E4CH", NULL
);
85 geometry
= hkl_factory_create_new_geometry(factory
);
86 sample
= hkl_sample_new("test");
88 detector
= hkl_detector_factory_new(HKL_DETECTOR_TYPE_0D
);
90 engines
= hkl_factory_create_new_engine_list(factory
);
91 hkl_engine_list_init(engines
, geometry
, detector
, sample
);
93 engine
= hkl_engine_list_engine_get_by_name(engines
, "hkl", NULL
);
94 modes
= hkl_engine_modes_names_get(engine
);
96 darray_foreach(mode
, *modes
){
97 static double values
[] = {0, 0, 1};
98 const darray_string
*parameters
;
99 HklGeometryList
*geometries
;
102 hkl_engine_current_mode_set(engine
, *mode
, NULL
);
103 parameters
= hkl_engine_parameters_names_get(engine
);
104 n_params
= darray_size(*parameters
);
106 double params
[n_params
];
108 hkl_engine_parameters_values_get(engine
, params
, n_params
, HKL_UNIT_DEFAULT
);
110 hkl_engine_parameters_values_set(engine
, params
, n_params
, HKL_UNIT_DEFAULT
, NULL
);
113 /* studdy this degenerated case */
114 geometries
= hkl_engine_pseudo_axis_values_set(engine
, values
, ARRAY_SIZE(values
),
115 HKL_UNIT_DEFAULT
, NULL
);
117 const HklGeometryListItem
*item
;
119 HKL_GEOMETRY_LIST_FOREACH(item
, geometries
){
120 hkl_geometry_set(geometry
,
121 hkl_geometry_list_item_geometry_get(item
));
122 res
&= DIAG(check_pseudoaxes(engine
, values
, 3));
124 hkl_geometry_list_free(geometries
);
128 ok(res
== TRUE
, "degenerated");
130 hkl_engine_list_free(engines
);
131 hkl_detector_free(detector
);
132 hkl_sample_free(sample
);
133 hkl_geometry_free(geometry
);
136 static void psi_getter(void)
139 HklEngineList
*engines
;
141 const HklFactory
*factory
;
142 HklGeometry
*geometry
;
143 HklDetector
*detector
;
147 factory
= hkl_factory_get_by_name("E4CH", NULL
);
148 geometry
= hkl_factory_create_new_geometry(factory
);
149 sample
= hkl_sample_new("test");
151 detector
= hkl_detector_factory_new(HKL_DETECTOR_TYPE_0D
);
153 engines
= hkl_factory_create_new_engine_list(factory
);
154 hkl_engine_list_init(engines
, geometry
, detector
, sample
);
156 engine
= hkl_engine_list_engine_get_by_name(engines
, "psi", NULL
);
158 /* the getter part */
159 hkl_geometry_set_values_v(geometry
, HKL_UNIT_USER
, NULL
, 30., 0., 0., 60.);
160 hkl_engine_initialized_set(engine
, TRUE
, NULL
);
162 hkl
[0] = 1, hkl
[1] = 0, hkl
[2] = 0;
163 hkl_engine_parameters_values_set(engine
, hkl
, ARRAY_SIZE(hkl
),
164 HKL_UNIT_DEFAULT
, NULL
);
165 res
&= DIAG(check_pseudoaxes_v(engine
, 0.));
167 /* here Q and <h, k, l>_ref are colinear must FAIL */
168 hkl
[0] = 0, hkl
[1] = 1, hkl
[2] = 0;
169 hkl_engine_parameters_values_set(engine
, hkl
, ARRAY_SIZE(hkl
),
170 HKL_UNIT_DEFAULT
, NULL
);
171 res
&= DIAG(!check_pseudoaxes_v(engine
, 0.));
173 hkl
[0] = -1, hkl
[1] = 0, hkl
[2] = 0;
174 hkl_engine_parameters_values_set(engine
, hkl
, ARRAY_SIZE(hkl
),
175 HKL_UNIT_DEFAULT
, NULL
);
176 res
&= DIAG(check_pseudoaxes_v(engine
, 180. * HKL_DEGTORAD
));
178 hkl
[0] = 0, hkl
[1] = 0, hkl
[2] = -1;
179 hkl_engine_parameters_values_set(engine
, hkl
, ARRAY_SIZE(hkl
),
180 HKL_UNIT_DEFAULT
, NULL
);
181 res
&= DIAG(check_pseudoaxes_v(engine
, 90. * HKL_DEGTORAD
));
183 /* Q and <h, k, l>_ref are colinear so must FAIL */
184 hkl
[0] = 0, hkl
[1] = -1, hkl
[2] = 0;
185 hkl_engine_parameters_values_set(engine
, hkl
, ARRAY_SIZE(hkl
),
186 HKL_UNIT_DEFAULT
, NULL
);
187 res
&= DIAG(!check_pseudoaxes_v(engine
, 0.));
189 ok(res
== TRUE
, "psi getter");
191 hkl_engine_list_free(engines
);
192 hkl_detector_free(detector
);
193 hkl_sample_free(sample
);
194 hkl_geometry_free(geometry
);
197 static void psi_setter(void)
200 HklEngineList
*engines
;
202 const darray_string
*modes
;
204 const HklFactory
*factory
;
205 HklGeometry
*geometry
;
206 HklDetector
*detector
;
208 static double hkl
[] = {1, 0, 0};
210 factory
= hkl_factory_get_by_name("E4CH", NULL
);
211 geometry
= hkl_factory_create_new_geometry(factory
);
212 sample
= hkl_sample_new("test");
214 detector
= hkl_detector_factory_new(HKL_DETECTOR_TYPE_0D
);
216 engines
= hkl_factory_create_new_engine_list(factory
);
217 hkl_engine_list_init(engines
, geometry
, detector
, sample
);
219 engine
= hkl_engine_list_engine_get_by_name(engines
, "psi", NULL
);
220 modes
= hkl_engine_modes_names_get(engine
);
223 hkl_geometry_set_values_v(geometry
, HKL_UNIT_USER
, NULL
, 30., 0., 0., 60.);
224 hkl_engine_parameters_values_set(engine
, hkl
, ARRAY_SIZE(hkl
),
225 HKL_UNIT_DEFAULT
, NULL
);
226 hkl_engine_initialized_set(engine
, TRUE
, NULL
);
228 darray_foreach(mode
, *modes
){
231 hkl_engine_current_mode_set(engine
, *mode
, NULL
);
232 for(psi
=-180 * HKL_DEGTORAD
;psi
<180 * HKL_DEGTORAD
;psi
+= HKL_DEGTORAD
){
233 HklGeometryList
*geometries
;
235 geometries
= hkl_engine_pseudo_axis_values_set(engine
, &psi
, 1,
236 HKL_UNIT_DEFAULT
, NULL
);
238 const HklGeometryListItem
*item
;
240 HKL_GEOMETRY_LIST_FOREACH(item
, geometries
){
241 hkl_geometry_set(geometry
,
242 hkl_geometry_list_item_geometry_get(item
));
243 res
&= DIAG(check_pseudoaxes_v(engine
, psi
));
245 hkl_geometry_list_free(geometries
);
250 ok(res
== TRUE
, "psi setter");
252 hkl_engine_list_free(engines
);
253 hkl_detector_free(detector
);
254 hkl_sample_free(sample
);
255 hkl_geometry_free(geometry
);
262 HklEngineList
*engines
;
264 const darray_string
*modes
;
266 const HklFactory
*factory
;
267 HklGeometry
*geometry
;
268 HklDetector
*detector
;
271 factory
= hkl_factory_get_by_name("E4CH", NULL
);
272 geometry
= hkl_factory_create_new_geometry(factory
);
273 sample
= hkl_sample_new("test");
275 detector
= hkl_detector_factory_new(HKL_DETECTOR_TYPE_0D
);
277 engines
= hkl_factory_create_new_engine_list(factory
);
278 hkl_engine_list_init(engines
, geometry
, detector
, sample
);
280 engine
= hkl_engine_list_engine_get_by_name(engines
, "q", NULL
);
281 modes
= hkl_engine_modes_names_get(engine
);
284 hkl_geometry_set_values_v(geometry
, HKL_UNIT_USER
, NULL
, 30., 0., 0., 60.);
285 hkl_engine_initialized_set(engine
, TRUE
, NULL
);
287 darray_foreach(mode
, *modes
){
290 hkl_engine_current_mode_set(engine
, *mode
, NULL
);
291 for(q
=-1.; q
<1.; q
+= 0.1){
292 HklGeometryList
*geometries
;
294 geometries
= hkl_engine_pseudo_axis_values_set(engine
, &q
, 1,
295 HKL_UNIT_DEFAULT
, NULL
);
298 const HklGeometryListItem
*item
;
300 HKL_GEOMETRY_LIST_FOREACH(item
, geometries
){
301 hkl_geometry_set(geometry
,
302 hkl_geometry_list_item_geometry_get(item
));
303 res
&= DIAG(check_pseudoaxes(engine
, &q
, 1));
305 hkl_geometry_list_free(geometries
);
310 ok(res
== TRUE
, "q");
312 hkl_engine_list_free(engines
);
313 hkl_detector_free(detector
);
314 hkl_sample_free(sample
);
315 hkl_geometry_free(geometry
);
318 static void hkl_psi_constant_horizontal(void)
321 HklEngineList
*engines
;
323 const HklFactory
*factory
;
324 HklGeometry
*geometry
;
325 HklGeometryList
*geometries
;
326 HklDetector
*detector
;
328 static double hkl
[] = {1, 0, 1};
329 static double hkl2
[] = {1, 1, 0};
331 factory
= hkl_factory_get_by_name("E4CH", NULL
);
332 geometry
= hkl_factory_create_new_geometry(factory
);
333 sample
= hkl_sample_new("test");
335 detector
= hkl_detector_factory_new(HKL_DETECTOR_TYPE_0D
);
337 engines
= hkl_factory_create_new_engine_list(factory
);
338 hkl_engine_list_init(engines
, geometry
, detector
, sample
);
340 engine
= hkl_engine_list_engine_get_by_name(engines
, "hkl", NULL
);
342 hkl_engine_current_mode_set(engine
, "psi_constant", NULL
);
345 hkl_geometry_set_values_v(geometry
, HKL_UNIT_USER
, NULL
, 30., 0., 0., 60.);
346 hkl_engine_parameters_values_set(engine
, hkl2
, ARRAY_SIZE(hkl2
),
347 HKL_UNIT_DEFAULT
, NULL
);
348 hkl_engine_initialized_set(engine
, TRUE
, NULL
);
350 geometries
= hkl_engine_pseudo_axis_values_set(engine
,
351 hkl
, ARRAY_SIZE(hkl
),
352 HKL_UNIT_DEFAULT
, NULL
);
354 const HklGeometryListItem
*item
;
356 HKL_GEOMETRY_LIST_FOREACH(item
, geometries
){
357 hkl_geometry_set(geometry
,
358 hkl_geometry_list_item_geometry_get(item
));
359 res
&= DIAG(check_pseudoaxes(engine
, hkl
, ARRAY_SIZE(hkl
)));
361 hkl_geometry_list_free(geometries
);
364 ok(res
== TRUE
, "psi constant horizontal");
366 hkl_engine_list_free(engines
);
367 hkl_detector_free(detector
);
368 hkl_sample_free(sample
);
369 hkl_geometry_free(geometry
);
372 int main(int argc
, char** argv
)
381 hkl_psi_constant_horizontal();