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 #include <gsl/gsl_nan.h> // for GSL_NAN
23 #include <gsl/gsl_sys.h> // for gsl_isnan
24 #include <stdlib.h> // for free, NULL
25 #include "hkl-macros-private.h" // for HKL_MALLOC
26 #include "hkl-unit-private.h" // for HklUnit, etc
27 #include "hkl.h" // for FALSE, HKL_DEGTORAD, etc
30 * hkl_unit_dup: (skip)
35 * Returns: the copied #HklUnit (memory must be release with
38 HklUnit
* hkl_unit_dup(const HklUnit
*self
)
43 HklUnit
*dup
= HKL_MALLOC(HklUnit
);
50 * hkl_unit_free: (skip)
53 * release the memory of an #HklUnit
55 void hkl_unit_free(HklUnit
*self
)
62 * hkl_unit_compatible: (skip)
63 * @self: the first @HklUnit
64 * @unit: the second @HklUnit to check
66 * check if two units are compatible.
68 * Returns: TRUE or FALSE
70 int hkl_unit_compatible(const HklUnit
*self
, const HklUnit
*unit
)
75 case HKL_UNIT_ANGLE_DEG
:
77 case HKL_UNIT_ANGLE_DEG
:
78 case HKL_UNIT_ANGLE_RAD
:
79 case HKL_UNIT_ANGLE_MRAD
:
86 case HKL_UNIT_ANGLE_RAD
:
88 case HKL_UNIT_ANGLE_DEG
:
89 case HKL_UNIT_ANGLE_RAD
:
90 case HKL_UNIT_ANGLE_MRAD
:
97 case HKL_UNIT_LENGTH_NM
:
99 case HKL_UNIT_LENGTH_NM
:
106 case HKL_UNIT_ANGLE_MRAD
:
108 case HKL_UNIT_ANGLE_DEG
:
109 case HKL_UNIT_ANGLE_RAD
:
110 case HKL_UNIT_ANGLE_MRAD
:
127 * compute the factor to convert from one @Hklunit to another one.
128 * @self * factor = @unit
130 * Returns: the factor of the conversion.
132 double hkl_unit_factor(const HklUnit
*self
, const HklUnit
*unit
)
138 case HKL_UNIT_ANGLE_DEG
:
140 case HKL_UNIT_ANGLE_DEG
:
142 case HKL_UNIT_ANGLE_RAD
:
143 factor
= HKL_DEGTORAD
;
145 case HKL_UNIT_ANGLE_MRAD
:
146 factor
= HKL_DEGTORAD
* 1e3
;
153 case HKL_UNIT_ANGLE_RAD
:
155 case HKL_UNIT_ANGLE_DEG
:
156 factor
= HKL_RADTODEG
;
158 case HKL_UNIT_ANGLE_RAD
:
160 case HKL_UNIT_ANGLE_MRAD
:
168 case HKL_UNIT_LENGTH_NM
:
170 case HKL_UNIT_LENGTH_NM
:
177 case HKL_UNIT_ANGLE_MRAD
:
179 case HKL_UNIT_ANGLE_DEG
:
180 factor
= 1e-3 * HKL_RADTODEG
;
182 case HKL_UNIT_ANGLE_RAD
:
185 case HKL_UNIT_ANGLE_MRAD
: