upgrading copyright year from 2015 to 2016
[hkl.git] / hkl / hkl-unit.c
blobb3a04bcd5824b468f93cff6d140a2a72cfcf9bf5
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-2016 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
29 /**
30 * hkl_unit_dup: (skip)
31 * @self:
33 * copy an #Hklunit
35 * Returns: the copied #HklUnit (memory must be release with
36 * hkl_unit_free)
37 **/
38 HklUnit* hkl_unit_dup(const HklUnit *self)
40 if (!self)
41 return NULL;
43 HklUnit *dup = HKL_MALLOC(HklUnit);
44 *dup = *self;
46 return dup;
49 /**
50 * hkl_unit_free: (skip)
51 * @self:
53 * release the memory of an #HklUnit
54 **/
55 void hkl_unit_free(HklUnit *self)
57 if (self)
58 free(self);
61 /**
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
69 **/
70 int hkl_unit_compatible(const HklUnit *self, const HklUnit *unit)
72 int res = TRUE;
73 if (self && unit){
74 switch(self->type){
75 case HKL_UNIT_ANGLE_DEG:
76 switch(unit->type){
77 case HKL_UNIT_ANGLE_DEG:
78 case HKL_UNIT_ANGLE_RAD:
79 break;
80 default:
81 res = FALSE;
82 break;
84 break;
85 case HKL_UNIT_ANGLE_RAD:
86 switch(unit->type){
87 case HKL_UNIT_ANGLE_DEG:
88 case HKL_UNIT_ANGLE_RAD:
89 break;
90 default:
91 res = FALSE;
92 break;
94 break;
95 case HKL_UNIT_LENGTH_NM:
96 switch(unit->type){
97 case HKL_UNIT_LENGTH_NM:
98 break;
99 default:
100 res = FALSE;
101 break;
105 return res;
109 * hkl_unit_factor:
110 * @self:
111 * @unit:
113 * compute the factor to convert from one @Hklunit to another one.
114 * @self * factor = @unit
116 * Returns: the factor of the conversion.
118 double hkl_unit_factor(const HklUnit *self, const HklUnit *unit)
120 double factor = 1.;
122 if (self && unit){
123 switch(self->type){
124 case HKL_UNIT_ANGLE_DEG:
125 switch(unit->type){
126 case HKL_UNIT_ANGLE_DEG:
127 break;
128 case HKL_UNIT_ANGLE_RAD:
129 factor = HKL_DEGTORAD;
130 break;
131 default:
132 factor = GSL_NAN;
133 break;
135 break;
136 case HKL_UNIT_ANGLE_RAD:
137 switch(unit->type){
138 case HKL_UNIT_ANGLE_DEG:
139 factor = HKL_RADTODEG;
140 break;
141 case HKL_UNIT_ANGLE_RAD:
142 break;
143 default:
144 factor = GSL_NAN;
145 break;
147 break;
148 case HKL_UNIT_LENGTH_NM:
149 switch(unit->type){
150 case HKL_UNIT_LENGTH_NM:
151 break;
152 default:
153 factor = GSL_NAN;
154 break;
158 return factor;