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-2017 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 #ifndef __HKL_PSEUDOAXIS_AUTO_H__
23 #define __HKL_PSEUDOAXIS_AUTO_H__
25 #include <gsl/gsl_vector_double.h> // for gsl_vector
26 #include <stddef.h> // for NULL
27 #include <sys/types.h> // for uint
28 #include "hkl-detector-private.h" // for hkl_detector_new_copy
29 #include "hkl-geometry-private.h" // for hkl_geometry_new_copy
30 #include "hkl-macros-private.h" // for hkl_assert, etc
31 #include "hkl-pseudoaxis-private.h" // for HklModeOperations, etc
32 #include "hkl.h" // for HklMode, hkl_detector_free, etc
33 #include "hkl/ccan/container_of/container_of.h" // for container_of
34 #include "hkl/ccan/array_size/array_size.h" // ARRAY_SIZE
38 typedef struct _HklFunction HklFunction
;
39 typedef struct _HklModeAutoInfo HklModeAutoInfo
;
40 typedef struct _HklModeAutoWithInit HklModeAutoWithInit
;
49 int (* function
) (const gsl_vector
*x
, void *params
, gsl_vector
*f
);
52 typedef darray(const HklFunction
*) darray_function
;
54 struct _HklModeAutoInfo
{
55 const HklModeInfo info
;
56 darray_function functions
;
59 #define HKL_MODE_OPERATIONS_AUTO_DEFAULTS \
60 HKL_MODE_OPERATIONS_DEFAULTS, \
61 .set = hkl_mode_auto_set_real
63 #define CHECK_NAN(x, len) do{ \
64 for(uint i=0; i<len; ++i) \
69 #define HKL_MODE_AUTO_INFO(_name, _axes_r, _axes_w, _fn) .info={HKL_MODE_INFO(_name, _axes_r, _axes_w),}, .functions=DARRAY(_fn)
71 #define HKL_MODE_AUTO_INFO_WITH_PARAMS(_name, _axes_r, _axes_w, _fn, _parameters) .info={HKL_MODE_INFO_WITH_PARAMS(_name, _axes_r, _axes_w, _parameters)}, .functions=DARRAY(_fn)
73 extern HklMode
*hkl_mode_auto_new(const HklModeAutoInfo
*auto_info
,
74 const HklModeOperations
*ops
,
77 extern void hkl_mode_auto_init(HklMode
*self
,
78 const HklModeAutoInfo
*auto_info
,
79 const HklModeOperations
*ops
,
82 extern int hkl_mode_auto_set_real(HklMode
*self
,
84 HklGeometry
*geometry
,
85 HklDetector
*detector
,
89 /***********************/
90 /* HklModeAutoWithInit */
91 /***********************/
93 struct _HklModeAutoWithInit
{
95 HklGeometry
*geometry
;
96 HklDetector
*detector
;
100 #define HKL_MODE_AUTO_WITH_INIT_ERROR hkl_mode_auto_with_init_error_quark ()
102 static inline GQuark
hkl_mode_auto_with_init_error_quark (void)
104 return g_quark_from_static_string ("hkl-mode-auto-with-init-error-quark");
108 HKL_MODE_AUTO_WITH_INIT_ERROR_INIT
/* can not set the pseudo axis engine */
111 #define HKL_MODE_OPERATIONS_AUTO_WITH_INIT_DEFAULTS \
112 HKL_MODE_OPERATIONS_AUTO_DEFAULTS, \
113 .capabilities = HKL_ENGINE_CAPABILITIES_READABLE | HKL_ENGINE_CAPABILITIES_WRITABLE | HKL_ENGINE_CAPABILITIES_INITIALIZABLE, \
114 .free = hkl_mode_auto_with_init_free_real, \
115 .initialized_set = hkl_mode_auto_with_init_initialized_set_real
117 static NEEDED
void hkl_mode_auto_with_init_free_real(HklMode
*mode
)
119 HklModeAutoWithInit
*self
= container_of(mode
, HklModeAutoWithInit
, mode
);
122 hkl_geometry_free(self
->geometry
);
124 hkl_detector_free(self
->detector
);
126 hkl_sample_free(self
->sample
);
128 hkl_mode_free_real(mode
);
132 static NEEDED
int hkl_mode_auto_with_init_initialized_set_real(HklMode
*mode
,
134 HklGeometry
*geometry
,
135 HklDetector
*detector
,
140 HklModeAutoWithInit
*self
= container_of(mode
, HklModeAutoWithInit
, mode
);
142 hkl_error(error
== NULL
|| *error
== NULL
);
147 hkl_geometry_free(self
->geometry
);
148 self
->geometry
= hkl_geometry_new_copy(geometry
);
152 hkl_detector_free(self
->detector
);
153 self
->detector
= hkl_detector_new_copy(detector
);
157 hkl_sample_free(self
->sample
);
158 self
->sample
= hkl_sample_new_copy(sample
);
162 mode
->initialized
= initialized
;
167 extern HklMode
*hkl_mode_auto_with_init_new(const HklModeAutoInfo
*info
,
168 const HklModeOperations
*ops
,
173 #endif /* __HKL_PSEUDOAXIS_AUTO_H__ */