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>
25 #include <math.h> // for M_PI
26 #include <stddef.h> // for size_t
27 #include <stdio.h> // for FILE
28 #include <hkl/ccan/darray/darray.h> // for darray
30 /* Guard C code in headers, while including them from C++ */
32 # define HKL_BEGIN_DECLS extern "C" {
33 # define HKL_END_DECLS }
35 # define HKL_BEGIN_DECLS
36 # define HKL_END_DECLS
40 #if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1)
41 # define HKL_DEPRECATED __attribute__((__deprecated__))
42 #elif defined(_MSC_VER) && (_MSC_VER >= 1300)
43 # define HKL_DEPRECATED __declspec(deprecated)
45 # define HKL_DEPRECATED
48 #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)
49 # define HKL_DEPRECATED_FOR(f) __attribute__((__deprecated__("Use '" #f "' instead")))
50 #elif defined(_MSC_FULL_VER) && (_MSC_FULL_VER > 140050320)
51 # define HKL_DEPRECATED_FOR(f) __declspec(deprecated("is deprecated. Use '" #f "' instead"))
53 # define HKL_DEPRECATED_FOR(f) HKL_DEPRECATED
60 #define HKL_EPSILON 1e-6
61 #define HKL_DEGTORAD (M_PI/180.)
62 #define HKL_RADTODEG (180./M_PI)
65 #define HKL_TAU (2. * M_PI)
66 /* #define HKL_TAU 1 */
74 # define HKLAPI __attribute__ ((visibility("default")))
81 * @brief Used to export functions(by changing visibility).
86 #if (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3))
87 # define HKL_ARG_NONNULL(...) __attribute__ ((__nonnull__(__VA_ARGS__)))
89 # define HKL_ARG_NONNULL(...)
92 #define _darray(type) type *item; size_t size; size_t alloc
100 typedef struct _HklMatrix HklMatrix
;
102 HKLAPI HklMatrix
*hkl_matrix_new(void);
104 HKLAPI HklMatrix
*hkl_matrix_new_full(double m11
, double m12
, double m13
,
105 double m21
, double m22
, double m23
,
106 double m31
, double m32
, double m33
);
108 HKLAPI HklMatrix
*hkl_matrix_new_euler(double euler_x
, double euler_y
, double euler_z
);
110 HKLAPI
double hkl_matrix_get(const HklMatrix
*self
, unsigned int i
, unsigned int j
) HKL_ARG_NONNULL(1);
112 HKLAPI
void hkl_matrix_free(HklMatrix
*self
) HKL_ARG_NONNULL(1);
114 HKLAPI
void hkl_matrix_init(HklMatrix
*self
,
115 double m11
, double m12
, double m13
,
116 double m21
, double m22
, double m23
,
117 double m31
, double m32
, double m33
) HKL_ARG_NONNULL(1);
119 HKLAPI
int hkl_matrix_cmp(const HklMatrix
*self
, const HklMatrix
*m
) HKL_ARG_NONNULL(1, 2);
121 HKLAPI
void hkl_matrix_times_matrix(HklMatrix
*self
, const HklMatrix
*m
) HKL_ARG_NONNULL(1, 2);
127 typedef struct _HklError HklError
;
129 HKLAPI
const char *hkl_error_message_get(const HklError
*self
) HKL_ARG_NONNULL(1);
135 typedef struct _HklParameter HklParameter
;
139 HKLAPI HklParameter
*hkl_parameter_new_copy(const HklParameter
*self
) HKL_ARG_NONNULL(1);
141 HKLAPI
void hkl_parameter_free(HklParameter
*self
) HKL_ARG_NONNULL(1);
143 HKLAPI
const char *hkl_parameter_name_get(const HklParameter
*self
) HKL_ARG_NONNULL(1);
145 HKLAPI
double hkl_parameter_value_get(const HklParameter
*self
) HKL_ARG_NONNULL(1);
147 HKLAPI
int hkl_parameter_value_set(HklParameter
*self
, double value
,
148 HklError
**error
) HKL_ARG_NONNULL(1);
150 HKLAPI
double hkl_parameter_value_unit_get(const HklParameter
*self
) HKL_ARG_NONNULL(1);
152 HKLAPI
int hkl_parameter_value_unit_set(HklParameter
*self
, double value
,
153 HklError
**error
) HKL_ARG_NONNULL(1);
155 HKLAPI
void hkl_parameter_min_max_get(const HklParameter
*self
, double *min
, double *max
) HKL_ARG_NONNULL(1, 2, 3);
157 HKLAPI
void hkl_parameter_min_max_set(HklParameter
*self
, double min
, double max
) HKL_ARG_NONNULL(1);
159 HKLAPI
void hkl_parameter_min_max_unit_get(const HklParameter
*self
, double *min
, double *max
) HKL_ARG_NONNULL(1, 2, 3);
161 HKLAPI
void hkl_parameter_min_max_unit_set(HklParameter
*self
, double min
, double max
) HKL_ARG_NONNULL(1);
163 HKLAPI
int hkl_parameter_fit_get(const HklParameter
*self
) HKL_ARG_NONNULL(1);
165 HKLAPI
void hkl_parameter_fit_set(HklParameter
*self
, int fit
) HKL_ARG_NONNULL(1);
167 HKLAPI
void hkl_parameter_randomize(HklParameter
*self
) HKL_ARG_NONNULL(1);
173 typedef struct _HklDetector HklDetector
;
174 typedef enum _HklDetectorType
179 HKLAPI
void hkl_detector_free(HklDetector
*self
) HKL_ARG_NONNULL(1);
181 HKLAPI
void hkl_detector_idx_set(HklDetector
*self
, int idx
) HKL_ARG_NONNULL(1);
183 HKLAPI
void hkl_detector_fprintf(FILE *f
, const HklDetector
*self
) HKL_ARG_NONNULL(1, 2);
185 HKLAPI HklDetector
*hkl_detector_factory_new(HklDetectorType type
);
191 typedef struct _HklGeometry HklGeometry
;
192 typedef struct _HklGeometryList HklGeometryList
;
193 typedef struct _HklGeometryListItem HklGeometryListItem
;
197 HKLAPI
void hkl_geometry_free(HklGeometry
*self
) HKL_ARG_NONNULL(1);
199 HKLAPI
void hkl_geometry_set(HklGeometry
*self
, const HklGeometry
*src
) HKL_ARG_NONNULL(1, 2);
201 HKLAPI
const HklParameter
*hkl_geometry_axis_get(const HklGeometry
*self
, const char *name
) HKL_ARG_NONNULL(1, 2);
203 HKLAPI
void hkl_geometry_axis_set(HklGeometry
*self
, const HklParameter
*axis
) HKL_ARG_NONNULL(1, 2);
205 HKLAPI
const char *hkl_geometry_name_get(const HklGeometry
*self
) HKL_ARG_NONNULL(1);
207 HKLAPI
double hkl_geometry_wavelength_get(const HklGeometry
*self
) HKL_ARG_NONNULL(1);
209 HKLAPI
void hkl_geometry_wavelength_set(HklGeometry
*self
, double wavelength
) HKL_ARG_NONNULL(1);
211 HKLAPI
void hkl_geometry_randomize(HklGeometry
*self
) HKL_ARG_NONNULL(1);
213 HKLAPI
int hkl_geometry_set_values_unit_v(HklGeometry
*self
, ...) HKL_ARG_NONNULL(1);
215 HKLAPI
void hkl_geometry_fprintf(FILE *file
, const HklGeometry
*self
) HKL_ARG_NONNULL(1, 2);
217 /* HklGeometryList */
219 #define HKL_GEOMETRY_LIST_FOREACH(item, list) for((item)=hkl_geometry_list_items_first_get((list)); \
221 (item)=hkl_geometry_list_items_next_get((list), (item)))
223 HKLAPI
size_t hkl_geometry_list_n_items_get(const HklGeometryList
*self
) HKL_ARG_NONNULL(1);
225 HKLAPI
const HklGeometryListItem
*hkl_geometry_list_items_first_get(const HklGeometryList
*self
) HKL_ARG_NONNULL(1);
227 HKLAPI
const HklGeometryListItem
*hkl_geometry_list_items_next_get(const HklGeometryList
*self
,
228 const HklGeometryListItem
*item
) HKL_ARG_NONNULL(1, 2);
230 /* HklGeometryListItem */
232 HKLAPI
const HklGeometry
*hkl_geometry_list_item_geometry_get(const HklGeometryListItem
*self
) HKL_ARG_NONNULL(1);
238 typedef struct _HklLattice HklLattice
;
239 typedef struct _HklSample HklSample
;
240 typedef struct _HklSampleReflection HklSampleReflection
;
244 HKLAPI HklLattice
*hkl_lattice_new(double a
, double b
, double c
,
245 double alpha
, double beta
, double gamma
);
247 HKLAPI HklLattice
*hkl_lattice_new_copy(const HklLattice
*self
) HKL_ARG_NONNULL(1);
249 HKLAPI HklLattice
*hkl_lattice_new_default(void);
251 HKLAPI
void hkl_lattice_free(HklLattice
*self
) HKL_ARG_NONNULL(1);
253 HKLAPI
const HklParameter
*hkl_lattice_a_get(const HklLattice
*self
) HKL_ARG_NONNULL(1);
255 HKLAPI
void hkl_lattice_a_set(HklLattice
*self
, const HklParameter
*parameter
) HKL_ARG_NONNULL(1, 2);
257 HKLAPI
const HklParameter
*hkl_lattice_b_get(const HklLattice
*self
) HKL_ARG_NONNULL(1);
259 HKLAPI
void hkl_lattice_b_set(HklLattice
*self
, const HklParameter
*parameter
) HKL_ARG_NONNULL(1, 2);
261 HKLAPI
const HklParameter
*hkl_lattice_c_get(const HklLattice
*self
) HKL_ARG_NONNULL(1);
263 HKLAPI
void hkl_lattice_c_set(HklLattice
*self
, const HklParameter
*parameter
) HKL_ARG_NONNULL(1, 2);
265 HKLAPI
const HklParameter
*hkl_lattice_alpha_get(const HklLattice
*self
) HKL_ARG_NONNULL(1);
267 HKLAPI
void hkl_lattice_alpha_set(HklLattice
*self
, const HklParameter
*parameter
) HKL_ARG_NONNULL(1, 2);
269 HKLAPI
const HklParameter
*hkl_lattice_beta_get(const HklLattice
*self
) HKL_ARG_NONNULL(1);
271 HKLAPI
void hkl_lattice_beta_set(HklLattice
*self
, const HklParameter
*parameter
) HKL_ARG_NONNULL(1, 2);
273 HKLAPI
const HklParameter
*hkl_lattice_gamma_get(const HklLattice
*self
) HKL_ARG_NONNULL(1);
275 HKLAPI
void hkl_lattice_gamma_set(HklLattice
*self
, const HklParameter
*parameter
) HKL_ARG_NONNULL(1, 2);
277 HKLAPI
int hkl_lattice_set(HklLattice
*self
,
278 double a
, double b
, double c
,
279 double alpha
, double beta
, double gamma
) HKL_ARG_NONNULL(1);
281 HKLAPI
void hkl_lattice_get(const HklLattice
*self
,
282 double *a
, double *b
, double *c
,
283 double *alpha
, double *beta
, double *gamma
) HKL_ARG_NONNULL(1, 2, 3, 4, 5, 6, 7);
285 HKLAPI
int hkl_lattice_get_B(const HklLattice
*self
, HklMatrix
*B
) HKL_ARG_NONNULL(1, 2);
287 HKLAPI
int hkl_lattice_get_1_B(const HklLattice
*self
, HklMatrix
*B
) HKL_ARG_NONNULL(1, 2);
289 HKLAPI
int hkl_lattice_reciprocal(const HklLattice
*self
, HklLattice
*reciprocal
) HKL_ARG_NONNULL(1, 2);
293 HKLAPI HklSample
*hkl_sample_new(const char *name
) HKL_ARG_NONNULL(1);
295 HKLAPI HklSample
*hkl_sample_new_copy(const HklSample
*self
) HKL_ARG_NONNULL(1);
297 HKLAPI
void hkl_sample_free(HklSample
*self
) HKL_ARG_NONNULL(1);
299 HKLAPI
const char *hkl_sample_name_get(const HklSample
*self
) HKL_ARG_NONNULL(1);
301 HKLAPI
void hkl_sample_name_set(HklSample
*self
, const char *name
) HKL_ARG_NONNULL(1, 2);
303 HKLAPI
const HklLattice
*hkl_sample_lattice_get(HklSample
*self
) HKL_ARG_NONNULL(1);
305 HKLAPI
void hkl_sample_lattice_set(HklSample
*self
, const HklLattice
*lattice
) HKL_ARG_NONNULL(1, 2);
307 HKLAPI
const HklParameter
*hkl_sample_ux_get(const HklSample
*self
) HKL_ARG_NONNULL(1);
309 HKLAPI
void hkl_sample_ux_set(HklSample
*self
, const HklParameter
*ux
) HKL_ARG_NONNULL(1, 2);
311 HKLAPI
const HklParameter
*hkl_sample_uy_get(const HklSample
*self
) HKL_ARG_NONNULL(1);
313 HKLAPI
void hkl_sample_uy_set(HklSample
*self
, const HklParameter
*uy
) HKL_ARG_NONNULL(1, 2);
315 HKLAPI
const HklParameter
*hkl_sample_uz_get(const HklSample
*self
) HKL_ARG_NONNULL(1);
317 HKLAPI
void hkl_sample_uz_set(HklSample
*self
, const HklParameter
*uz
) HKL_ARG_NONNULL(1, 2);
319 HKLAPI
const HklMatrix
*hkl_sample_U_get(const HklSample
*self
) HKL_ARG_NONNULL(1);
321 HKLAPI
void hkl_sample_U_set(HklSample
*self
, const HklMatrix
*U
) HKL_ARG_NONNULL(1);
323 HKLAPI
const HklMatrix
*hkl_sample_UB_get(const HklSample
*self
) HKL_ARG_NONNULL(1);
325 HKLAPI
double hkl_sample_UB_set(HklSample
*self
, const HklMatrix
*UB
) HKL_ARG_NONNULL(1, 2);
327 HKLAPI HklSampleReflection
*hkl_sample_first_reflection_get(HklSample
*self
) HKL_ARG_NONNULL(1);
329 HKLAPI HklSampleReflection
*hkl_sample_next_reflection_get(HklSample
*self
,
330 HklSampleReflection
*reflection
) HKL_ARG_NONNULL(1, 2);
332 HKLAPI
void hkl_sample_del_reflection(HklSample
*self
,
333 HklSampleReflection
*reflection
) HKL_ARG_NONNULL(1, 2);
335 HKLAPI
void hkl_sample_add_reflection(HklSample
*self
,
336 HklSampleReflection
*reflection
) HKL_ARG_NONNULL(1, 2);
338 HKLAPI
int hkl_sample_compute_UB_busing_levy(HklSample
*self
,
339 const HklSampleReflection
*r1
,
340 const HklSampleReflection
*r2
) HKL_ARG_NONNULL(1, 2, 3);
342 HKLAPI
double hkl_sample_get_reflection_mesured_angle(const HklSample
*self
,
343 const HklSampleReflection
*r1
,
344 const HklSampleReflection
*r2
) HKL_ARG_NONNULL(1, 2, 3);
346 HKLAPI
double hkl_sample_get_reflection_theoretical_angle(const HklSample
*self
,
347 const HklSampleReflection
*r1
,
348 const HklSampleReflection
*r2
) HKL_ARG_NONNULL(1, 2, 3);
350 HKLAPI
double hkl_sample_affine(HklSample
*self
) HKL_ARG_NONNULL(1);
352 /* hklSampleReflection */
354 HKLAPI HklSampleReflection
*hkl_sample_reflection_new(const HklGeometry
*geometry
,
355 const HklDetector
*detector
,
356 double h
, double k
, double l
) HKL_ARG_NONNULL(1, 2);
358 HKLAPI
void hkl_sample_reflection_hkl_get(const HklSampleReflection
*self
,
359 double *h
, double *k
, double *l
) HKL_ARG_NONNULL(1, 2, 3, 4);
361 HKLAPI
void hkl_sample_reflection_hkl_set(HklSampleReflection
*self
,
362 double h
, double k
, double l
) HKL_ARG_NONNULL(1);
364 HKLAPI
int hkl_sample_reflection_flag_get(const HklSampleReflection
*self
) HKL_ARG_NONNULL(1);
366 HKLAPI
void hkl_sample_reflection_flag_set(HklSampleReflection
*self
, int flag
) HKL_ARG_NONNULL(1);
368 HKLAPI
const HklGeometry
*hkl_sample_reflection_geometry_get(HklSampleReflection
*self
) HKL_ARG_NONNULL(1);
370 HKLAPI
void hkl_sample_reflection_geometry_set(HklSampleReflection
*self
,
371 const HklGeometry
*geometry
) HKL_ARG_NONNULL(1, 2);
377 typedef struct _HklPseudoAxis HklPseudoAxis
;
378 typedef struct _HklEngine HklEngine
;
379 typedef struct _HklEngineList HklEngineList
;
381 typedef darray(const char *) darray_string
;
382 typedef darray(HklEngine
*) darray_engine
;
386 HKLAPI
const char *hkl_engine_name_get(const HklEngine
*self
) HKL_ARG_NONNULL(1);
388 HKLAPI
unsigned int hkl_engine_len(const HklEngine
*self
) HKL_ARG_NONNULL(1);
390 HKLAPI
const darray_string
*hkl_engine_pseudo_axes_names_get(HklEngine
*self
) HKL_ARG_NONNULL(1);
392 HKLAPI
void hkl_engine_pseudo_axes_values_get(HklEngine
*self
,
393 double values
[], size_t n_values
) HKL_ARG_NONNULL(1, 2);
395 HKLAPI
unsigned int hkl_engine_pseudo_axes_values_set(HklEngine
*self
,
396 double values
[], size_t n_values
,
397 HklError
**error
) HKL_ARG_NONNULL(1, 2);
399 HKLAPI
void hkl_engine_pseudo_axes_randomize(HklEngine
*self
) HKL_ARG_NONNULL(1);
401 HKLAPI
const HklParameter
*hkl_engine_pseudo_axis_get(const HklEngine
*self
,
402 const char *name
) HKL_ARG_NONNULL(1, 2);
404 HKLAPI
unsigned int hkl_engine_pseudo_axis_set(HklEngine
*self
,
405 const HklParameter
*parameter
,
406 HklError
**error
) HKL_ARG_NONNULL(1, 2);
408 HKLAPI
const darray_string
*hkl_engine_modes_get(const HklEngine
*self
) HKL_ARG_NONNULL(1);
410 HKLAPI
void hkl_engine_select_mode(HklEngine
*self
,
411 const char *name
) HKL_ARG_NONNULL(1, 2);
413 HKLAPI
const darray_string
*hkl_engine_parameters_get(const HklEngine
*self
) HKL_ARG_NONNULL(1);
415 HKLAPI
unsigned int hkl_engine_parameters_set(HklEngine
*self
,
416 double values
[], size_t n_values
,
417 HklError
**error
) HKL_ARG_NONNULL(1, 2);
419 HKLAPI
void hkl_engine_parameters_randomize(HklEngine
*self
) HKL_ARG_NONNULL(1);
421 HKLAPI
const HklParameter
*hkl_engine_parameter_get(const HklEngine
*self
,
422 const char *name
) HKL_ARG_NONNULL(1, 2);
424 HKLAPI
void hkl_engine_parameter_set(HklEngine
*self
,
425 const HklParameter
*parameter
) HKL_ARG_NONNULL(1, 2);
427 HKLAPI HklEngineList
*hkl_engine_engines_get(HklEngine
*self
) HKL_ARG_NONNULL(1);
429 HKLAPI
int hkl_engine_initialize(HklEngine
*self
, HklError
**error
) HKL_ARG_NONNULL(1);
431 HKLAPI
int hkl_engine_set(HklEngine
*self
, HklError
**error
) HKL_ARG_NONNULL(1);
433 HKLAPI
int hkl_engine_get(HklEngine
*self
, HklError
**error
) HKL_ARG_NONNULL(1);
435 HKLAPI
void hkl_engine_fprintf(FILE *f
, const HklEngine
*self
) HKL_ARG_NONNULL(1, 2);
439 HKLAPI
void hkl_engine_list_free(HklEngineList
*self
) HKL_ARG_NONNULL(1);
441 HKLAPI darray_engine
*hkl_engine_list_engines_get(HklEngineList
*self
) HKL_ARG_NONNULL(1);
443 HKLAPI HklGeometry
*hkl_engine_list_geometry_get(HklEngineList
*self
) HKL_ARG_NONNULL(1);
445 HKLAPI
void hkl_engine_list_geometry_set(HklEngineList
*self
, const HklGeometry
*geometry
) HKL_ARG_NONNULL(1, 2);
447 HKLAPI
const HklGeometryList
*hkl_engine_list_geometries_get(const HklEngineList
*self
) HKL_ARG_NONNULL(1);
449 HKLAPI
void hkl_engine_list_select_solution(HklEngineList
*self
,
450 const HklGeometryListItem
*item
) HKL_ARG_NONNULL(1);
452 HKLAPI HklEngine
*hkl_engine_list_engine_get_by_name(HklEngineList
*self
,
453 const char *name
) HKL_ARG_NONNULL(1, 2);
455 HKLAPI HklParameter
*hkl_engine_list_pseudo_axis_get_by_name(const HklEngineList
*self
,
456 const char *name
) HKL_ARG_NONNULL(1, 2);
458 HKLAPI
void hkl_engine_list_init(HklEngineList
*self
,
459 HklGeometry
*geometry
,
460 HklDetector
*detector
,
461 HklSample
*sample
) HKL_ARG_NONNULL(1, 2, 3, 4);
463 HKLAPI
int hkl_engine_list_get(HklEngineList
*self
) HKL_ARG_NONNULL(1);
465 HKLAPI
void hkl_engine_list_fprintf(FILE *f
,
466 const HklEngineList
*self
) HKL_ARG_NONNULL(1, 2);
472 typedef struct _HklFactory HklFactory
;
474 HKLAPI HklFactory
**hkl_factory_get_all(unsigned int *n
) HKL_ARG_NONNULL(1);
476 HKLAPI HklFactory
*hkl_factory_get_by_name(const char *name
) HKL_ARG_NONNULL(1);
478 HKLAPI
const char *hkl_factory_name(const HklFactory
*self
) HKL_ARG_NONNULL(1);
480 HKLAPI
const char **hkl_factory_axes_get(const HklFactory
*self
,
481 size_t *length
) HKL_ARG_NONNULL(1, 2);
483 HKLAPI HklGeometry
*hkl_factory_create_new_geometry(const HklFactory
*self
) HKL_ARG_NONNULL(1);
485 HKLAPI HklEngineList
*hkl_factory_create_new_engine_list(const HklFactory
*self
) HKL_ARG_NONNULL(1);