* add the liststore to contain all the diffractometers
[hkl.git] / hkl / hkl-pseudoaxis-e4cv-hkl.c
blobecdaad0e7c76cfaf3697f4a2757573f2475fc020
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-2010 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 * Maria-Teresa Nunez-Pardo-de-Verra <tnunez@mail.desy.de>
22 * Jens Krüger <Jens.Krueger@frm2.tum.de>
24 #include <gsl/gsl_math.h>
25 #include <gsl/gsl_vector.h>
27 #include <hkl/hkl-pseudoaxis-e4cv.h>
28 #include <hkl/hkl-pseudoaxis-common-hkl.h>
30 /*******/
31 /* hkl */
32 /*******/
34 static int bissector_func(const gsl_vector *x, void *params, gsl_vector *f)
36 double omega, tth;
37 double const *x_data = gsl_vector_const_ptr(x, 0);
38 double *f_data = gsl_vector_ptr(f, 0);
40 RUBh_minus_Q(x_data, params, f_data);
42 omega = x_data[0];
43 tth = x_data[3];
45 f_data[3] = tth - 2 * fmod(omega,M_PI);
47 return GSL_SUCCESS;
50 HklPseudoAxisEngine *hkl_pseudo_axis_engine_e4cv_hkl_new(void)
52 HklPseudoAxisEngine *self;
53 HklPseudoAxisEngineMode *mode;
55 self = hkl_pseudo_axis_engine_hkl_new();
57 /* hkl get/set bissector */
58 mode = hkl_pseudo_axis_engine_mode_new(
59 "bissector",
60 NULL,
61 hkl_pseudo_axis_engine_mode_get_hkl_real,
62 hkl_pseudo_axis_engine_mode_set_real,
63 1, bissector_func,
64 (size_t)0,
65 (size_t)4, "omega", "chi", "phi", "tth");
66 hkl_pseudo_axis_engine_add_mode(self, mode);
68 /* constant_omega */
69 mode = hkl_pseudo_axis_engine_mode_new(
70 "constant_omega",
71 NULL,
72 hkl_pseudo_axis_engine_mode_get_hkl_real,
73 hkl_pseudo_axis_engine_mode_set_real,
74 1, RUBh_minus_Q_func,
75 (size_t)0,
76 (size_t)3, "chi", "phi", "tth");
77 hkl_pseudo_axis_engine_add_mode(self, mode);
79 /* constant_chi */
80 mode = hkl_pseudo_axis_engine_mode_new(
81 "constant_chi",
82 NULL,
83 hkl_pseudo_axis_engine_mode_get_hkl_real,
84 hkl_pseudo_axis_engine_mode_set_real,
85 1, RUBh_minus_Q_func,
86 (size_t)0,
87 (size_t)3, "omega", "phi", "tth");
88 hkl_pseudo_axis_engine_add_mode(self, mode);
90 /* constant_phi */
91 mode = hkl_pseudo_axis_engine_mode_new(
92 "constant_phi",
93 NULL,
94 hkl_pseudo_axis_engine_mode_get_hkl_real,
95 hkl_pseudo_axis_engine_mode_set_real,
96 1, RUBh_minus_Q_func,
97 (size_t)0,
98 (size_t)3, "omega", "chi", "tth");
99 hkl_pseudo_axis_engine_add_mode(self, mode);
101 /* double_diffraction */
102 HklParameter h2;
103 HklParameter k2;
104 HklParameter l2;
106 hkl_parameter_init(&h2, "h2", -1, 1, 1, HKL_TRUE, HKL_TRUE, NULL, NULL);
107 hkl_parameter_init(&k2, "k2", -1, 1, 1, HKL_TRUE, HKL_TRUE, NULL, NULL);
108 hkl_parameter_init(&l2, "l2", -1, 1, 1, HKL_TRUE, HKL_TRUE, NULL, NULL);
110 mode = hkl_pseudo_axis_engine_mode_new(
111 "double_diffraction",
112 NULL,
113 hkl_pseudo_axis_engine_mode_get_hkl_real,
114 hkl_pseudo_axis_engine_mode_set_real,
115 1, double_diffraction_func,
116 (size_t)3, h2, k2, l2,
117 (size_t)4, "omega", "chi", "phi", "tth");
118 hkl_pseudo_axis_engine_add_mode(self, mode);
120 /* psi_constant */
121 HklParameter psi;
123 hkl_parameter_init(&h2, "h2", -1, 1, 1, HKL_TRUE, HKL_TRUE, NULL, NULL);
124 hkl_parameter_init(&k2, "k2", -1, 0, 1, HKL_TRUE, HKL_TRUE, NULL, NULL);
125 hkl_parameter_init(&l2, "l2", -1, 0, 1, HKL_TRUE, HKL_TRUE, NULL, NULL);
126 hkl_parameter_init(&psi, "psi", -M_PI, 0, M_PI, HKL_TRUE, HKL_TRUE,
127 &hkl_unit_angle_rad, &hkl_unit_angle_deg);
129 mode = hkl_pseudo_axis_engine_mode_new(
130 "psi_constant",
131 hkl_pseudo_axis_engine_mode_init_psi_constant_vertical_real,
132 hkl_pseudo_axis_engine_mode_get_hkl_real,
133 hkl_pseudo_axis_engine_mode_set_real,
134 1, psi_constant_vertical_func,
135 (size_t)4, h2, k2, l2, psi,
136 (size_t)4, "omega", "chi", "phi", "tth");
137 hkl_pseudo_axis_engine_add_mode(self, mode);
139 hkl_pseudo_axis_engine_select_mode(self, 0);
141 return self;