upgrading copyright year from 2015 to 2016
[hkl.git] / hkl / hkl-detector.c
blob2459b47e0b5f1d0ce0081b048d01ff80184a7e29
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 <stdio.h> // for fprintf, NULL, FILE
23 #include <stdlib.h> // for free
24 #include "hkl-detector-private.h" // for _HklDetector
25 #include "hkl-geometry-private.h" // for HklHolder, _HklGeometry, etc
26 #include "hkl-macros-private.h" // for HKL_MALLOC
27 #include "hkl-source-private.h" // for HklSource
28 #include "hkl-vector-private.h" // for hkl_vector_init, etc
29 #include "hkl.h" // for HklDetector, HklGeometry, etc
30 #include "hkl/ccan/darray/darray.h" // for darray_item
32 /**
33 * hkl_detector_new: (skip)
35 * Create a new default #HklDetector
37 * Returns:
38 **/
39 HklDetector *hkl_detector_new(void)
41 HklDetector *self = NULL;
43 self = HKL_MALLOC(HklDetector);
45 self->idx = 1;
46 self->holder = NULL;
48 return self;
51 /**
52 * hkl_detector_new_copy: (skip)
53 * @src: the detector to copy
55 * the copy constructor
57 * Returns:
58 **/
59 HklDetector *hkl_detector_new_copy(const HklDetector *src)
61 HklDetector *self;
63 self = HKL_MALLOC(HklDetector);
65 *self = *src;
67 return self;
70 /**
71 * hkl_detector_free: (skip)
72 * @self:
74 * destructor
75 **/
76 void hkl_detector_free(HklDetector *self)
78 free(self);
81 /**
82 * hkl_detector_attach_to_holder: (skip)
83 * @self:
84 * @holder:
86 * attach the #HklDetector to an #HklHolder
87 **/
88 void hkl_detector_attach_to_holder(HklDetector *self, HklHolder const *holder)
90 self->holder = holder;
93 /**
94 * hkl_detector_compute_kf: (skip)
95 * @self:
96 * @g: (in): the diffractometer #HklGeometry use to compute kf.
97 * @kf: (out caller-allocates): the #HklVector fill with the kf coordinates.
99 * Compute the kf vector of the #HklDetector
101 * Returns: HKL_SUCCESS if everythongs goes fine. HKL_FAIL otherwise.
103 int hkl_detector_compute_kf(HklDetector const *self, HklGeometry *g,
104 HklVector *kf)
106 HklHolder *holder;
108 hkl_geometry_update(g);
110 holder = darray_item(g->holders, self->idx);
111 if (holder) {
112 hkl_vector_init(kf, HKL_TAU / g->source.wave_length, 0, 0);
113 hkl_vector_rotated_quaternion(kf, &holder->q);
114 return TRUE;
115 } else
116 return FALSE;
120 * hkl_detector_fprintf: (skip)
121 * @f:
122 * @self:
124 * print to a FILE the detector members
126 void hkl_detector_fprintf(FILE *f, const HklDetector *self)
128 fprintf(f, "detector->idx: %d\n", self->idx);
129 fprintf(f, "detector->holder: %p\n", self->holder);