create an HklPseudoAxisEngineModeInfo for the Automatic modes.
[hkl.git] / hkl / hkl-unit.c
blob900ad707dd446e30a62323f3fb0eadd8d84886b1
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-2011 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 <math.h>
23 #include <gsl/gsl_nan.h>
24 #include <gsl/gsl_sys.h> /* gsl_nan()! */
25 #include <hkl/hkl-unit.h>
27 /**
28 * hkl_unit_dup: (skip)
29 * @self:
31 * copy an #Hklunit
33 * Returns: the copied #HklUnit (memory must be release with
34 * hkl_unit_free)
35 **/
36 HklUnit* hkl_unit_dup(const HklUnit *self)
38 if (!self)
39 return NULL;
41 HklUnit *dup = HKL_MALLOC(HklUnit);
42 *dup = *self;
44 return dup;
47 /**
48 * hkl_unit_free: (skip)
49 * @self:
51 * release the memory of an #HklUnit
52 **/
53 void hkl_unit_free(HklUnit *self)
55 if (self)
56 free(self);
59 /**
60 * hkl_unit_compatible: check if two units are compatible.
61 * @self: the first @HklUnit
62 * @unit: the second @HklUnit to check
64 * Returns: HKL_TRUE or HKL_FALSE
65 **/
66 int hkl_unit_compatible(const HklUnit *self, const HklUnit *unit)
68 int res = HKL_TRUE;
69 if (self && unit){
70 switch(self->type){
71 case HKL_UNIT_ANGLE_DEG:
72 switch(unit->type){
73 case HKL_UNIT_ANGLE_DEG:
74 case HKL_UNIT_ANGLE_RAD:
75 break;
76 default:
77 res = HKL_FALSE;
78 break;
80 break;
81 case HKL_UNIT_ANGLE_RAD:
82 switch(unit->type){
83 case HKL_UNIT_ANGLE_DEG:
84 case HKL_UNIT_ANGLE_RAD:
85 break;
86 default:
87 res = HKL_FALSE;
88 break;
90 break;
91 case HKL_UNIT_LENGTH_NM:
92 switch(unit->type){
93 case HKL_UNIT_LENGTH_NM:
94 break;
95 default:
96 res = HKL_FALSE;
97 break;
101 return res;
105 * hkl_unit_factor:
106 * @self:
107 * @unit:
109 * compute the factor to convert from one @Hklunit to another one.
110 * @self * factor = @unit
112 * Returns: the factor of the conversion.
114 double hkl_unit_factor(const HklUnit *self, const HklUnit *unit)
116 double factor = 1.;
118 if (self && unit){
119 switch(self->type){
120 case HKL_UNIT_ANGLE_DEG:
121 switch(unit->type){
122 case HKL_UNIT_ANGLE_DEG:
123 break;
124 case HKL_UNIT_ANGLE_RAD:
125 factor = HKL_DEGTORAD;
126 break;
127 default:
128 factor = GSL_NAN;
129 break;
131 break;
132 case HKL_UNIT_ANGLE_RAD:
133 switch(unit->type){
134 case HKL_UNIT_ANGLE_DEG:
135 factor = HKL_RADTODEG;
136 break;
137 case HKL_UNIT_ANGLE_RAD:
138 break;
139 default:
140 factor = GSL_NAN;
141 break;
143 break;
144 case HKL_UNIT_LENGTH_NM:
145 switch(unit->type){
146 case HKL_UNIT_LENGTH_NM:
147 break;
148 default:
149 factor = GSL_NAN;
150 break;
154 return factor;