33#include <cr2res_dfs.h>
34#include <cr2res_pol.h>
36#define CR2RES_DETECTOR_SIZE 2048
43static void test_cr2res_pol_demod_stokes(
void);
44static void test_cr2res_pol_demod_stokes_different_wavelengths(
void);
45static void test_cr2res_pol_demod_stokes_zeros(
void);
71static void test_cr2res_pol_demod_stokes(){
73 cpl_vector ** wl = cpl_malloc(n *
sizeof(cpl_vector*));
74 cpl_vector ** intens = cpl_malloc(n *
sizeof(cpl_vector*));
75 cpl_vector ** errors = cpl_malloc(n *
sizeof(cpl_vector*));
78 double error = 1. / sqrt(8);
83 cpl_bivector * spec = cpl_bivector_new(CR2RES_DETECTOR_SIZE);
84 for (cpl_size i = 0; i < CR2RES_DETECTOR_SIZE; i++)
86 cpl_vector_set(cpl_bivector_get_x(spec), i, 1);
87 cpl_vector_set(cpl_bivector_get_y(spec), i, 1);
94 double step = (wmax - wmin) / CR2RES_DETECTOR_SIZE;
95 for (
int i = 0; i < n; i++){
96 wl[i] = cpl_vector_new(CR2RES_DETECTOR_SIZE);
97 for (
int j = 0; j < CR2RES_DETECTOR_SIZE; j++){
98 cpl_vector_set(wl[i], j, wmin + j * step);
103 for (
int i = 0; i < n; i++)
105 intens[i] = cpl_bivector_get_x(spec);
106 errors[i] = cpl_bivector_get_y(spec);
112 for (cpl_size i = 0; i < CR2RES_DETECTOR_SIZE; i++)
114 cpl_test_abs(value, cpl_vector_get(cpl_bivector_get_x(pol), i),
116 cpl_test_abs(error, cpl_vector_get(cpl_bivector_get_y(pol), i),
121 for (
int i = 0; i < n; i++){
122 cpl_vector_delete(wl[i]);
124 cpl_bivector_delete(pol);
125 cpl_bivector_delete(spec);
132static void test_cr2res_pol_demod_stokes_different_wavelengths(){
134 cpl_vector ** wl = cpl_malloc(n *
sizeof(cpl_vector*));
135 cpl_vector ** intens = cpl_malloc(n *
sizeof(cpl_vector*));
136 cpl_vector ** errors = cpl_malloc(n *
sizeof(cpl_vector*));
139 double error = 1. / sqrt(8);
146 cpl_bivector * spec = cpl_bivector_new(CR2RES_DETECTOR_SIZE);
147 for (i = 0; i < CR2RES_DETECTOR_SIZE; i++)
149 cpl_vector_set(cpl_bivector_get_x(spec), i, 1);
150 cpl_vector_set(cpl_bivector_get_y(spec), i, 1);
157 double step = (wmax - wmin) / CR2RES_DETECTOR_SIZE;
158 double diff_between_spectra = 20;
159 for (i = 0; i < n; i++){
160 wl[i] = cpl_vector_new(CR2RES_DETECTOR_SIZE);
161 for (j = 0; j < CR2RES_DETECTOR_SIZE; j++){
162 cpl_vector_set(wl[i], j, wmin + j * step + i * diff_between_spectra);
168 for (i = 0; i < n; i++)
170 intens[i] = cpl_bivector_get_x(spec);
171 errors[i] = cpl_bivector_get_y(spec);
180 cpl_size xmax = 1760;
184 for (; i < xmin; i++){
185 cpl_test(isnan(cpl_vector_get(cpl_bivector_get_x(pol), i)));
186 cpl_test(isnan(cpl_vector_get(cpl_bivector_get_y(pol), i)));
189 for (; i < xmax + 1; i++)
191 cpl_test_abs(value, cpl_vector_get(cpl_bivector_get_x(pol), i),
193 cpl_test_abs(error, cpl_vector_get(cpl_bivector_get_y(pol), i),
197 for (; i < CR2RES_DETECTOR_SIZE; i++){
198 cpl_test(isnan(cpl_vector_get(cpl_bivector_get_x(pol), i)));
199 cpl_test(isnan(cpl_vector_get(cpl_bivector_get_y(pol), i)));
203 for (j = 0; j < n; j++){
204 cpl_vector_delete(wl[j]);
206 cpl_bivector_delete(pol);
207 cpl_bivector_delete(spec);
213static void test_cr2res_pol_demod_stokes_zeros(){
215 cpl_vector ** wl = cpl_malloc(n *
sizeof(cpl_vector*));
216 cpl_vector ** intens = cpl_malloc(n *
sizeof(cpl_vector*));
217 cpl_vector ** errors = cpl_malloc(n *
sizeof(cpl_vector*));
223 cpl_bivector * spec = cpl_bivector_new(CR2RES_DETECTOR_SIZE);
224 for (cpl_size i = 0; i < CR2RES_DETECTOR_SIZE; i++)
226 cpl_vector_set(cpl_bivector_get_x(spec), i, 0);
227 cpl_vector_set(cpl_bivector_get_y(spec), i, 0);
234 double step = (wmax - wmin) / CR2RES_DETECTOR_SIZE;
235 for (
int i = 0; i < n; i++){
236 wl[i] = cpl_vector_new(CR2RES_DETECTOR_SIZE);
237 for (
int j = 0; j < CR2RES_DETECTOR_SIZE; j++){
238 cpl_vector_set(wl[i], j, wmin + j * step);
243 for (
int i = 0; i < n; i++)
245 intens[i] = cpl_bivector_get_x(spec);
246 errors[i] = cpl_bivector_get_y(spec);
252 for (cpl_size i = 0; i < CR2RES_DETECTOR_SIZE; i++)
254 cpl_test(isnan(cpl_vector_get(cpl_bivector_get_x(pol), i)));
255 cpl_test(isnan(cpl_vector_get(cpl_bivector_get_y(pol), i)));
259 for (
int i = 0; i < n; i++){
260 cpl_vector_delete(wl[i]);
262 cpl_bivector_delete(pol);
263 cpl_bivector_delete(spec);
276 cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_DEBUG);
278 test_cr2res_pol_demod_stokes();
279 test_cr2res_pol_demod_stokes_different_wavelengths();
280 test_cr2res_pol_demod_stokes_zeros();
282 return cpl_test_end(0);
int main(void)
Run the Unit tests.
cpl_bivector * cr2res_pol_demod_stokes(cpl_vector **intens, cpl_vector **wl, cpl_vector **errors, int n)
Demodulate extracted spectra into Stokes parameter.