create an HklPseudoAxisEngineModeInfo for the Automatic modes.
[hkl.git] / hkl / hkl-source.c
blob08e5b84eaa22a3c07325f7c7a99f1a5d0bb62a0d
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>
22 #include <stdlib.h>
23 #include <math.h>
25 #include <hkl/hkl-source.h>
27 /**
28 * hkl_source_dup:
29 * @self: the #Hklsource to copy
31 * copy constructor
32 * TODO test
34 * Returns:
35 **/
36 HklSource *hkl_source_dup(const HklSource *self)
38 HklSource *dup = HKL_MALLOC(HklSource);
40 *dup = *self;
42 return dup;
45 /**
46 * hkl_source_free:
47 * @self: the #Hklsource to delete
49 * destructor
50 * TODO: test
51 **/
52 void hkl_source_free(HklSource *self)
54 if (self)
55 free(self);
58 /**
59 * hkl_source_init:
60 * @self: the #Hklsource to initialize
61 * @wave_length: the wave length to set
62 * @x: x coordinates of the ki vector
63 * @y: y coordinates of the ki vector
64 * @z: z coordinates of the ki vector
66 * initialize the #HklSource
68 * Returns: HKL_SUCCESS if everythongs goes fine, HKL_FAIL otherwise
69 **/
70 int hkl_source_init(HklSource *self,
71 double wave_length, double x, double y, double z)
73 if (wave_length > HKL_EPSILON &&
74 ( x > HKL_EPSILON || y > HKL_EPSILON || z > HKL_EPSILON)) {
75 double norm;
77 norm = sqrt(x*x + y*y + z*z);
79 self->wave_length = wave_length;
80 hkl_vector_init(&self->direction, x, y, z);
81 hkl_vector_div_double(&self->direction, norm);
82 return HKL_TRUE;
83 } else
84 return HKL_FALSE;
87 /**
88 * hkl_source_cmp: (skip)
89 * @self: 1st #Hklsource
90 * @s: 2nd #Hklsource
92 * compare two sources
94 * Returns:
95 **/
96 int hkl_source_cmp(HklSource const *self, HklSource const *s)
98 return ( (fabs(self->wave_length - s->wave_length) < HKL_EPSILON)
99 && hkl_vector_is_colinear(&self->direction,
100 &s->direction));
104 * hkl_source_compute_ki: (skip)
105 * @self:
106 * @ki: (out caller-allocates):
108 * compute the ki hkl_vector
110 void hkl_source_compute_ki(HklSource const *self, HklVector *ki)
112 *ki = self->direction;
113 hkl_vector_times_double(ki, HKL_TAU / self->wave_length);
117 * hkl_source_get_wavelength: (skip)
118 * @self:
120 * get the wave_length
122 * Returns: the wave_length
124 double hkl_source_get_wavelength(HklSource const *self)
126 return self->wave_length;
130 * hkl_source_fprintf: (skip)
131 * @f:
132 * @self:
134 * printf the source
136 void hkl_source_fprintf(FILE *f, HklSource const *self)
138 fprintf(f, "%f", self->wave_length);
139 hkl_vector_fprintf(f, &self->direction);