[hkl] remove a bunch of warnings.
[hkl.git] / tests / tap / hkl-tap.c
blob039271c6ffc0a51e314a8f12492601a134439d76
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-2012 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 <stdarg.h>
24 #include "basic.h"
25 #include "hkl-tap.h"
26 #include "hkl/hkl-matrix-private.h"
27 #include "hkl/hkl-macros-private.h"
28 #include "hkl/hkl-pseudoaxis-private.h"
30 void is_quaternion(const HklQuaternion *wanted, const HklQuaternion *seen, const char *format, ...)
32 va_list args;
34 va_start(args, format);
35 fflush(stderr);
36 if(TRUE == hkl_quaternion_cmp(wanted, seen))
37 okv(1, format, args);
38 else{
39 printf("# wanted: %g %g %g %g\n",
40 wanted->data[0], wanted->data[1], wanted->data[2], wanted->data[3]);
41 printf("# seen: %g %g %g %g\n",
42 seen->data[0], seen->data[1], seen->data[2], wanted->data[3]);
43 okv(0, format, args);
47 void is_matrix(const HklMatrix *wanted, const HklMatrix *seen, const char *format, ...)
49 va_list args;
51 va_start(args, format);
52 fflush(stderr);
53 if(TRUE == hkl_matrix_cmp(wanted, seen))
54 okv(1, format, args);
55 else{
56 printf("# wanted: %g %g %g\n# : %g %g %g\n# : %g %g %g\n",
57 wanted->data[0][0], wanted->data[0][1], wanted->data[0][2],
58 wanted->data[1][0], wanted->data[1][1], wanted->data[1][2],
59 wanted->data[2][0], wanted->data[2][1], wanted->data[2][2]);
60 printf("# seen: %g %g %g\n# : %g %g %g\n# : %g %g %g\n",
61 seen->data[0][0], seen->data[0][1], seen->data[0][2],
62 seen->data[1][0], seen->data[1][1], seen->data[1][2],
63 seen->data[2][0], seen->data[2][1], seen->data[2][2]);
64 okv(0, format, args);
68 int check_pseudoaxes_v(HklEngine *engine, ...)
70 uint i;
71 va_list ap;
72 unsigned int len = hkl_engine_len(engine);
73 double values[len];
75 /* extract the variable part of the method */
76 va_start(ap, engine);
77 for(i=0; i<len; ++i)
78 values[i] = va_arg(ap, double);
79 va_end(ap);
81 return check_pseudoaxes(engine, values, len);
84 int check_pseudoaxes(HklEngine *engine,
85 double expected[], uint len)
87 int res = TRUE;
88 unsigned int i = 0;
89 double currents[len];
91 hkl_assert(hkl_engine_len(engine) == len);
93 if(hkl_engine_pseudo_axis_values_get(engine, currents, len, HKL_UNIT_DEFAULT, NULL)){
94 for(i=0; i<len; ++i){
95 res &= fabs(currents[i] - expected[i]) <= HKL_EPSILON;
96 if (!res){
97 fprintf(stderr, "current: %f, expected: %f, epsilon: %f\n",
98 currents[i], expected[i], HKL_EPSILON);
101 }else
102 res = FALSE;
104 return res;
108 * hkl_engine_set_values_v: (skip)
109 * @self: the Engine
110 * @values: the values to set
112 * set the values of the PseudoAxes with the given values. This method
113 * is only available for test as it is sort of brittle.
115 HklGeometryList *hkl_engine_set_values_v(HklEngine *self, ...)
117 uint i;
118 va_list ap;
119 unsigned int len = hkl_engine_len(self);
120 double values[len];
122 va_start(ap, self);
123 for(i=0; i<len; ++i)
124 values[i] = va_arg(ap, double);
126 va_end(ap);
127 return hkl_engine_pseudo_axis_values_set(self, values, len,
128 HKL_UNIT_DEFAULT, NULL);
132 * hkl_tap_engine_pseudo_axes_randomize: (skip)
133 * @self: the this ptr
135 * randomize all the parameters of the #HklEngine
137 void hkl_tap_engine_pseudo_axes_randomize(HklEngine *self,
138 double values[], size_t n_values,
139 HklUnitEnum unit_type)
141 size_t i;
143 for(i=0; i<n_values; ++i){
144 HklParameter *parameter = darray_item(self->pseudo_axes, i);
145 hkl_parameter_randomize(parameter);
146 values[i] = hkl_parameter_value_get(parameter, unit_type);
151 * hkl_tap_engine_parameters_randomize: (skip)
152 * @self: the this ptr
154 * randomize all the parameters of the #HklEngine
156 void hkl_tap_engine_parameters_randomize(HklEngine *self)
158 HklParameter **parameter;
160 darray_foreach(parameter, self->mode->parameters){
161 hkl_parameter_randomize(*parameter);