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>
25 #include <hkl/hkl-source.h>
29 * @self: the #Hklsource to copy
36 HklSource
*hkl_source_dup(const HklSource
*self
)
38 HklSource
*dup
= HKL_MALLOC(HklSource
);
47 * @self: the #Hklsource to delete
52 void hkl_source_free(HklSource
*self
)
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
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
)) {
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
);
88 * hkl_source_cmp: (skip)
89 * @self: 1st #Hklsource
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
,
104 * hkl_source_compute_ki: (skip)
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)
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)
136 void hkl_source_fprintf(FILE *f
, HklSource
const *self
)
138 fprintf(f
, "%f", self
->wave_length
);
139 hkl_vector_fprintf(f
, &self
->direction
);