Rework the unit part of the hkl library
[hkl.git] / tests / hkl-pseudoaxis-k4cv-t.c
blobef3305583b5ef62ab168c6de6bef66d3ed10a143
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-2014 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>
22 #include "hkl.h"
23 #include <tap/basic.h>
24 #include <tap/hkl-tap.h>
26 static void degenerated(void)
28 int res = TRUE;
29 HklEngineList *engines;
30 HklEngine *engine;
31 const darray_string *modes;
32 const char **mode;
33 const HklFactory *factory;
34 HklGeometry *geometry;
35 const HklGeometryList *geometries;
36 HklDetector *detector;
37 HklSample *sample;
38 static double hkl[] = {0, 1, 0};
40 factory = hkl_factory_get_by_name("K4CV", NULL);
41 geometry = hkl_factory_create_new_geometry(factory);
42 sample = hkl_sample_new("test");
44 detector = hkl_detector_factory_new(HKL_DETECTOR_TYPE_0D);
45 hkl_detector_idx_set(detector, 1);
47 engines = hkl_factory_create_new_engine_list(factory);
48 hkl_engine_list_init(engines, geometry, detector, sample);
49 geometries = hkl_engine_list_geometries_get(engines);
51 engine = hkl_engine_list_engine_get_by_name(engines, "hkl", NULL);
52 modes = hkl_engine_modes_names_get(engine);
54 darray_foreach(mode, *modes) {
55 const darray_string *parameters;
57 hkl_engine_select_mode(engine, *mode, NULL);
58 parameters = hkl_engine_parameters_names_get(engine);
59 if(darray_size(*parameters)){
60 const char *pname = darray_item(*parameters, 0);
61 HklParameter *p = hkl_parameter_new_copy(hkl_engine_parameter_get(engine,
62 pname, NULL));
63 hkl_parameter_value_set(p, 1, HKL_UNIT_DEFAULT, NULL);
64 hkl_engine_parameter_set(engine, pname, p, NULL);
65 hkl_parameter_free(p);
68 /* studdy this degenerated case */
69 hkl_engine_pseudo_axes_values_set(engine,
70 hkl, ARRAY_SIZE(hkl), HKL_UNIT_DEFAULT, NULL);
71 if (hkl_engine_set(engine, NULL)){
72 const HklGeometryListItem *item;
74 HKL_GEOMETRY_LIST_FOREACH(item, geometries){
75 static double null[] = {0, 0, 0};
77 hkl_engine_pseudo_axes_values_set(engine,
78 null, ARRAY_SIZE(null), HKL_UNIT_DEFAULT,
79 NULL);
80 hkl_geometry_set(geometry,
81 hkl_geometry_list_item_geometry_get(item));
82 hkl_engine_get(engine, NULL);
83 res &= check_pseudoaxes(engine, hkl, 3);
88 ok(res == TRUE, "degenerated");
90 hkl_engine_list_free(engines);
91 hkl_detector_free(detector);
92 hkl_sample_free(sample);
93 hkl_geometry_free(geometry);
96 static void eulerians(void)
98 int res = TRUE;
99 HklEngineList *engines;
100 HklEngine *engine;
101 const darray_string *modes;
102 const char **mode;
103 const HklFactory *factory;
104 HklGeometry *geometry;
105 const HklGeometryList *geometries;
106 HklDetector *detector;
107 HklSample *sample;
108 static double eulerians[] = {0., 90 * HKL_DEGTORAD, 0.};
110 factory = hkl_factory_get_by_name("K4CV", NULL);
111 geometry = hkl_factory_create_new_geometry(factory);
112 sample = hkl_sample_new("test");
114 detector = hkl_detector_factory_new(HKL_DETECTOR_TYPE_0D);
115 hkl_detector_idx_set(detector, 1);
117 engines = hkl_factory_create_new_engine_list(factory);
118 hkl_engine_list_init(engines, geometry, detector, sample);
119 geometries = hkl_engine_list_geometries_get(engines);
121 engine = hkl_engine_list_engine_get_by_name(engines, "eulerians", NULL);
122 modes = hkl_engine_modes_names_get(engine);
124 darray_foreach(mode, *modes){
125 const darray_string *parameters;
127 hkl_engine_select_mode(engine, *mode, NULL);
128 parameters = hkl_engine_parameters_names_get(engine);
129 if(darray_size(*parameters)){
130 const char *pname = darray_item(*parameters, 0);
131 HklParameter *p = hkl_parameter_new_copy(hkl_engine_parameter_get(engine,
132 pname, NULL));
133 hkl_parameter_value_set(p, 1, HKL_UNIT_DEFAULT, NULL);
134 hkl_engine_parameter_set(engine, pname, p, NULL);
135 hkl_parameter_free(p);
138 /* studdy this degenerated case */
139 hkl_engine_pseudo_axes_values_set(engine,
140 eulerians, ARRAY_SIZE(eulerians),
141 HKL_UNIT_DEFAULT, NULL);
142 if (hkl_engine_set(engine, NULL)) {
143 const HklGeometryListItem *item;
145 /* first solution = -180, -90, 180 */
146 item = hkl_geometry_list_items_first_get(geometries);
147 hkl_geometry_set(geometry,
148 hkl_geometry_list_item_geometry_get(item));
149 hkl_engine_get(engine, NULL);
150 res &= check_pseudoaxes_v(engine, -180. * HKL_DEGTORAD, -90 * HKL_DEGTORAD, 180. * HKL_DEGTORAD);
152 /* second solution = 0, 90, 0 */
153 item = hkl_geometry_list_items_next_get(geometries,item);
154 hkl_geometry_set(geometry,
155 hkl_geometry_list_item_geometry_get(item));
156 hkl_engine_get(engine, NULL);
157 res &= check_pseudoaxes_v(engine, 0., 90 * HKL_DEGTORAD, 0.);
159 /* no more solution */
160 res &= hkl_geometry_list_items_next_get(geometries, item) == NULL;
164 ok(res == TRUE, "eulerians");
166 hkl_engine_list_free(engines);
167 hkl_detector_free(detector);
168 hkl_sample_free(sample);
169 hkl_geometry_free(geometry);
172 static void q(void)
174 int res = TRUE;
175 HklEngineList *engines;
176 HklEngine *engine;
177 const darray_string *modes;
178 const char **mode;
179 const HklFactory *factory;
180 HklGeometry *geometry;
181 const HklGeometryList *geometries;
182 HklDetector *detector;
183 HklSample *sample;
185 factory = hkl_factory_get_by_name("K4CV", NULL);
186 geometry = hkl_factory_create_new_geometry(factory);
187 sample = hkl_sample_new("test");
189 detector = hkl_detector_factory_new(HKL_DETECTOR_TYPE_0D);
190 hkl_detector_idx_set(detector, 1);
192 engines = hkl_factory_create_new_engine_list(factory);
193 hkl_engine_list_init(engines, geometry, detector, sample);
194 geometries = hkl_engine_list_geometries_get(engines);
196 engine = hkl_engine_list_engine_get_by_name(engines, "q", NULL);
197 modes = hkl_engine_modes_names_get(engine);
199 /* the init part */
200 hkl_geometry_set_values_v(geometry, HKL_UNIT_USER, NULL, 30., 0., 0., 60.);
201 hkl_engine_initialize(engine, NULL);
203 darray_foreach(mode, *modes){
204 double q;
206 hkl_engine_select_mode(engine, *mode, NULL);
207 for(q=-1.; q<1.; q += 0.1){
208 hkl_engine_set_values_v(engine, q, NULL);
209 if(hkl_engine_set(engine, NULL)){
210 const HklGeometryListItem *item;
212 HKL_GEOMETRY_LIST_FOREACH(item, geometries){
213 hkl_engine_set_values_v(engine, 0.);
214 hkl_geometry_set(geometry,
215 hkl_geometry_list_item_geometry_get(item));
216 hkl_engine_get(engine, NULL);
217 res &= check_pseudoaxes_v(engine, q);
223 ok(res == TRUE, "q");
225 hkl_engine_list_free(engines);
226 hkl_detector_free(detector);
227 hkl_sample_free(sample);
228 hkl_geometry_free(geometry);
231 int main(int argc, char** argv)
233 plan(3);
235 degenerated();
236 eulerians();
237 q();
239 return 0;