##// END OF EJS Templates
idem + maintien des declarations dans le .h
chust -
r20:aa66459dff7b TCH
parent child
Show More
@@ -1,183 +1,183
1 // In the frame of RPW LFR Sofware ICD Issue1 Rev8 (05/07/2013) => R2 FSW
1 // In the frame of RPW LFR Sofware ICD Issue1 Rev8 (05/07/2013) => R2 FSW
2 // version 1.0: 31/07/2013
2 // version 1.0: 31/07/2013
3 // version 1.1: 02/04/2014
3 // version 1.1: 02/04/2014
4 // version 1.2: 30/04/2014
4 // version 1.2: 30/04/2014
5 // version 1.3: 02/05/2014
5 // version 1.3: 02/05/2014
6 // version 1.4: 16/05/2014
6 // version 1.4: 16/05/2014
7 // version 1.5: 20/05/2014
7 // version 1.5: 20/05/2014
8 // version 1.6: 19/12/2014
8 // version 1.6: 19/12/2014
9 // version 1.7: 15/01/2015 (modifs de Paul + correction erreurs qui se compensaient (LSB <=> MSB + indices [0,2] <=> [1,3])
9 // version 1.7: 15/01/2015 (modifs de Paul + correction erreurs qui se compensaient (LSB <=> MSB + indices [0,2] <=> [1,3])
10 // version 1.8: 02/02/2015 (gestion des divisions par zΓ©ro)
10 // version 1.8: 02/02/2015 (gestion des divisions par zΓ©ro)
11 // In the frame of RPW LFR Sofware ICD Issue3 Rev6 (27/01/2015) => R3 FSW
11 // In the frame of RPW LFR Sofware ICD Issue3 Rev6 (27/01/2015) => R3 FSW
12 // version 2.0: 19/06/2015
12 // version 2.0: 19/06/2015
13 // version 2.1: 22/06/2015 (modifs de Paul)
13 // version 2.1: 22/06/2015 (modifs de Paul)
14 // version 2.2: 23/06/2015 (modifs de l'ordre de dΓ©claration/dΓ©finition de init_k_coefficients dans basic_parameters.c ...)
14 // version 2.2: 23/06/2015 (modifs de l'ordre de dΓ©claration/dΓ©finition de init_k_coefficients dans basic_parameters.c ... + maintien des declarations dans le .h)
15
15
16 #include <stdio.h>
16 #include <stdio.h>
17 #include <stdint.h>
17 #include <stdint.h>
18
18
19 #include "basic_parameters_params.h"
19 #include "basic_parameters_params.h"
20
20
21 void init_k_coefficients_f0(float *k_coefficients,
21 void init_k_coefficients_f0(float *k_coefficients,
22 unsigned char nb_binscompressed_matrix )
22 unsigned char nb_binscompressed_matrix )
23 {
23 {
24
24
25 uint8_t i; // 8 bits unsigned
25 uint8_t i; // 8 bits unsigned
26 for(i=0; i<nb_binscompressed_matrix; i++){
26 for(i=0; i<nb_binscompressed_matrix; i++){
27 k_coefficients[i*NB_K_COEFF_PER_BIN+K44_PE] = 1;
27 k_coefficients[i*NB_K_COEFF_PER_BIN+K44_PE] = 1;
28 k_coefficients[i*NB_K_COEFF_PER_BIN+K55_PE] = 1;
28 k_coefficients[i*NB_K_COEFF_PER_BIN+K55_PE] = 1;
29 k_coefficients[i*NB_K_COEFF_PER_BIN+K45_PE_RE] = 1;
29 k_coefficients[i*NB_K_COEFF_PER_BIN+K45_PE_RE] = 1;
30 k_coefficients[i*NB_K_COEFF_PER_BIN+K45_PE_IM] = 1;
30 k_coefficients[i*NB_K_COEFF_PER_BIN+K45_PE_IM] = 1;
31 k_coefficients[i*NB_K_COEFF_PER_BIN+K14_SX_RE] = 1;
31 k_coefficients[i*NB_K_COEFF_PER_BIN+K14_SX_RE] = 1;
32 k_coefficients[i*NB_K_COEFF_PER_BIN+K14_SX_IM] = 1;
32 k_coefficients[i*NB_K_COEFF_PER_BIN+K14_SX_IM] = 1;
33 k_coefficients[i*NB_K_COEFF_PER_BIN+K15_SX_RE] = 1;
33 k_coefficients[i*NB_K_COEFF_PER_BIN+K15_SX_RE] = 1;
34 k_coefficients[i*NB_K_COEFF_PER_BIN+K15_SX_IM] = 1;
34 k_coefficients[i*NB_K_COEFF_PER_BIN+K15_SX_IM] = 1;
35 k_coefficients[i*NB_K_COEFF_PER_BIN+K24_SX_RE] = 1;
35 k_coefficients[i*NB_K_COEFF_PER_BIN+K24_SX_RE] = 1;
36 k_coefficients[i*NB_K_COEFF_PER_BIN+K24_SX_IM] = 1;
36 k_coefficients[i*NB_K_COEFF_PER_BIN+K24_SX_IM] = 1;
37 k_coefficients[i*NB_K_COEFF_PER_BIN+K25_SX_RE] = 1;
37 k_coefficients[i*NB_K_COEFF_PER_BIN+K25_SX_RE] = 1;
38 k_coefficients[i*NB_K_COEFF_PER_BIN+K25_SX_IM] = 1;
38 k_coefficients[i*NB_K_COEFF_PER_BIN+K25_SX_IM] = 1;
39 k_coefficients[i*NB_K_COEFF_PER_BIN+K34_SX_RE] = 1;
39 k_coefficients[i*NB_K_COEFF_PER_BIN+K34_SX_RE] = 1;
40 k_coefficients[i*NB_K_COEFF_PER_BIN+K34_SX_IM] = 1;
40 k_coefficients[i*NB_K_COEFF_PER_BIN+K34_SX_IM] = 1;
41 k_coefficients[i*NB_K_COEFF_PER_BIN+K35_SX_RE] = 1;
41 k_coefficients[i*NB_K_COEFF_PER_BIN+K35_SX_RE] = 1;
42 k_coefficients[i*NB_K_COEFF_PER_BIN+K35_SX_IM] = 1;
42 k_coefficients[i*NB_K_COEFF_PER_BIN+K35_SX_IM] = 1;
43 k_coefficients[i*NB_K_COEFF_PER_BIN+K24_NY_RE] = 1;
43 k_coefficients[i*NB_K_COEFF_PER_BIN+K24_NY_RE] = 1;
44 k_coefficients[i*NB_K_COEFF_PER_BIN+K24_NY_IM] = 1;
44 k_coefficients[i*NB_K_COEFF_PER_BIN+K24_NY_IM] = 1;
45 k_coefficients[i*NB_K_COEFF_PER_BIN+K25_NY_RE] = 1;
45 k_coefficients[i*NB_K_COEFF_PER_BIN+K25_NY_RE] = 1;
46 k_coefficients[i*NB_K_COEFF_PER_BIN+K25_NY_IM] = 1;
46 k_coefficients[i*NB_K_COEFF_PER_BIN+K25_NY_IM] = 1;
47 k_coefficients[i*NB_K_COEFF_PER_BIN+K34_NY_RE] = 1;
47 k_coefficients[i*NB_K_COEFF_PER_BIN+K34_NY_RE] = 1;
48 k_coefficients[i*NB_K_COEFF_PER_BIN+K34_NY_IM] = 1;
48 k_coefficients[i*NB_K_COEFF_PER_BIN+K34_NY_IM] = 1;
49 k_coefficients[i*NB_K_COEFF_PER_BIN+K35_NY_RE] = 1;
49 k_coefficients[i*NB_K_COEFF_PER_BIN+K35_NY_RE] = 1;
50 k_coefficients[i*NB_K_COEFF_PER_BIN+K35_NY_IM] = 1;
50 k_coefficients[i*NB_K_COEFF_PER_BIN+K35_NY_IM] = 1;
51 k_coefficients[i*NB_K_COEFF_PER_BIN+K24_NZ_RE] = 1;
51 k_coefficients[i*NB_K_COEFF_PER_BIN+K24_NZ_RE] = 1;
52 k_coefficients[i*NB_K_COEFF_PER_BIN+K24_NZ_IM] = 1;
52 k_coefficients[i*NB_K_COEFF_PER_BIN+K24_NZ_IM] = 1;
53 k_coefficients[i*NB_K_COEFF_PER_BIN+K25_NZ_RE] = 1;
53 k_coefficients[i*NB_K_COEFF_PER_BIN+K25_NZ_RE] = 1;
54 k_coefficients[i*NB_K_COEFF_PER_BIN+K25_NZ_IM] = 1;
54 k_coefficients[i*NB_K_COEFF_PER_BIN+K25_NZ_IM] = 1;
55 k_coefficients[i*NB_K_COEFF_PER_BIN+K34_NZ_RE] = 1;
55 k_coefficients[i*NB_K_COEFF_PER_BIN+K34_NZ_RE] = 1;
56 k_coefficients[i*NB_K_COEFF_PER_BIN+K34_NZ_IM] = 1;
56 k_coefficients[i*NB_K_COEFF_PER_BIN+K34_NZ_IM] = 1;
57 k_coefficients[i*NB_K_COEFF_PER_BIN+K35_NZ_RE] = 1;
57 k_coefficients[i*NB_K_COEFF_PER_BIN+K35_NZ_RE] = 1;
58 k_coefficients[i*NB_K_COEFF_PER_BIN+K35_NZ_IM] = 1;
58 k_coefficients[i*NB_K_COEFF_PER_BIN+K35_NZ_IM] = 1;
59 }
59 }
60
60
61 }
61 }
62
62
63
63
64 void init_k_coefficients_f1(float *k_coefficients,
64 void init_k_coefficients_f1(float *k_coefficients,
65 unsigned char nb_binscompressed_matrix )
65 unsigned char nb_binscompressed_matrix )
66 {
66 {
67
67
68 uint8_t i; // 8 bits unsigned
68 uint8_t i; // 8 bits unsigned
69 for(i=0; i<nb_binscompressed_matrix; i++){
69 for(i=0; i<nb_binscompressed_matrix; i++){
70 k_coefficients[i*NB_K_COEFF_PER_BIN+K44_PE] = 1;
70 k_coefficients[i*NB_K_COEFF_PER_BIN+K44_PE] = 1;
71 k_coefficients[i*NB_K_COEFF_PER_BIN+K55_PE] = 1;
71 k_coefficients[i*NB_K_COEFF_PER_BIN+K55_PE] = 1;
72 k_coefficients[i*NB_K_COEFF_PER_BIN+K45_PE_RE] = 1;
72 k_coefficients[i*NB_K_COEFF_PER_BIN+K45_PE_RE] = 1;
73 k_coefficients[i*NB_K_COEFF_PER_BIN+K45_PE_IM] = 1;
73 k_coefficients[i*NB_K_COEFF_PER_BIN+K45_PE_IM] = 1;
74 k_coefficients[i*NB_K_COEFF_PER_BIN+K14_SX_RE] = 1;
74 k_coefficients[i*NB_K_COEFF_PER_BIN+K14_SX_RE] = 1;
75 k_coefficients[i*NB_K_COEFF_PER_BIN+K14_SX_IM] = 1;
75 k_coefficients[i*NB_K_COEFF_PER_BIN+K14_SX_IM] = 1;
76 k_coefficients[i*NB_K_COEFF_PER_BIN+K15_SX_RE] = 1;
76 k_coefficients[i*NB_K_COEFF_PER_BIN+K15_SX_RE] = 1;
77 k_coefficients[i*NB_K_COEFF_PER_BIN+K15_SX_IM] = 1;
77 k_coefficients[i*NB_K_COEFF_PER_BIN+K15_SX_IM] = 1;
78 k_coefficients[i*NB_K_COEFF_PER_BIN+K24_SX_RE] = 1;
78 k_coefficients[i*NB_K_COEFF_PER_BIN+K24_SX_RE] = 1;
79 k_coefficients[i*NB_K_COEFF_PER_BIN+K24_SX_IM] = 1;
79 k_coefficients[i*NB_K_COEFF_PER_BIN+K24_SX_IM] = 1;
80 k_coefficients[i*NB_K_COEFF_PER_BIN+K25_SX_RE] = 1;
80 k_coefficients[i*NB_K_COEFF_PER_BIN+K25_SX_RE] = 1;
81 k_coefficients[i*NB_K_COEFF_PER_BIN+K25_SX_IM] = 1;
81 k_coefficients[i*NB_K_COEFF_PER_BIN+K25_SX_IM] = 1;
82 k_coefficients[i*NB_K_COEFF_PER_BIN+K34_SX_RE] = 1;
82 k_coefficients[i*NB_K_COEFF_PER_BIN+K34_SX_RE] = 1;
83 k_coefficients[i*NB_K_COEFF_PER_BIN+K34_SX_IM] = 1;
83 k_coefficients[i*NB_K_COEFF_PER_BIN+K34_SX_IM] = 1;
84 k_coefficients[i*NB_K_COEFF_PER_BIN+K35_SX_RE] = 1;
84 k_coefficients[i*NB_K_COEFF_PER_BIN+K35_SX_RE] = 1;
85 k_coefficients[i*NB_K_COEFF_PER_BIN+K35_SX_IM] = 1;
85 k_coefficients[i*NB_K_COEFF_PER_BIN+K35_SX_IM] = 1;
86 k_coefficients[i*NB_K_COEFF_PER_BIN+K24_NY_RE] = 1;
86 k_coefficients[i*NB_K_COEFF_PER_BIN+K24_NY_RE] = 1;
87 k_coefficients[i*NB_K_COEFF_PER_BIN+K24_NY_IM] = 1;
87 k_coefficients[i*NB_K_COEFF_PER_BIN+K24_NY_IM] = 1;
88 k_coefficients[i*NB_K_COEFF_PER_BIN+K25_NY_RE] = 1;
88 k_coefficients[i*NB_K_COEFF_PER_BIN+K25_NY_RE] = 1;
89 k_coefficients[i*NB_K_COEFF_PER_BIN+K25_NY_IM] = 1;
89 k_coefficients[i*NB_K_COEFF_PER_BIN+K25_NY_IM] = 1;
90 k_coefficients[i*NB_K_COEFF_PER_BIN+K34_NY_RE] = 1;
90 k_coefficients[i*NB_K_COEFF_PER_BIN+K34_NY_RE] = 1;
91 k_coefficients[i*NB_K_COEFF_PER_BIN+K34_NY_IM] = 1;
91 k_coefficients[i*NB_K_COEFF_PER_BIN+K34_NY_IM] = 1;
92 k_coefficients[i*NB_K_COEFF_PER_BIN+K35_NY_RE] = 1;
92 k_coefficients[i*NB_K_COEFF_PER_BIN+K35_NY_RE] = 1;
93 k_coefficients[i*NB_K_COEFF_PER_BIN+K35_NY_IM] = 1;
93 k_coefficients[i*NB_K_COEFF_PER_BIN+K35_NY_IM] = 1;
94 k_coefficients[i*NB_K_COEFF_PER_BIN+K24_NZ_RE] = 1;
94 k_coefficients[i*NB_K_COEFF_PER_BIN+K24_NZ_RE] = 1;
95 k_coefficients[i*NB_K_COEFF_PER_BIN+K24_NZ_IM] = 1;
95 k_coefficients[i*NB_K_COEFF_PER_BIN+K24_NZ_IM] = 1;
96 k_coefficients[i*NB_K_COEFF_PER_BIN+K25_NZ_RE] = 1;
96 k_coefficients[i*NB_K_COEFF_PER_BIN+K25_NZ_RE] = 1;
97 k_coefficients[i*NB_K_COEFF_PER_BIN+K25_NZ_IM] = 1;
97 k_coefficients[i*NB_K_COEFF_PER_BIN+K25_NZ_IM] = 1;
98 k_coefficients[i*NB_K_COEFF_PER_BIN+K34_NZ_RE] = 1;
98 k_coefficients[i*NB_K_COEFF_PER_BIN+K34_NZ_RE] = 1;
99 k_coefficients[i*NB_K_COEFF_PER_BIN+K34_NZ_IM] = 1;
99 k_coefficients[i*NB_K_COEFF_PER_BIN+K34_NZ_IM] = 1;
100 k_coefficients[i*NB_K_COEFF_PER_BIN+K35_NZ_RE] = 1;
100 k_coefficients[i*NB_K_COEFF_PER_BIN+K35_NZ_RE] = 1;
101 k_coefficients[i*NB_K_COEFF_PER_BIN+K35_NZ_IM] = 1;
101 k_coefficients[i*NB_K_COEFF_PER_BIN+K35_NZ_IM] = 1;
102 }
102 }
103
103
104 }
104 }
105
105
106
106
107 void init_k_coefficients_f2(float *k_coefficients,
107 void init_k_coefficients_f2(float *k_coefficients,
108 unsigned char nb_binscompressed_matrix )
108 unsigned char nb_binscompressed_matrix )
109 {
109 {
110
110
111 uint8_t i; // 8 bits unsigned
111 uint8_t i; // 8 bits unsigned
112 for(i=0; i<nb_binscompressed_matrix; i++){
112 for(i=0; i<nb_binscompressed_matrix; i++){
113 k_coefficients[i*NB_K_COEFF_PER_BIN+K44_PE] = 1;
113 k_coefficients[i*NB_K_COEFF_PER_BIN+K44_PE] = 1;
114 k_coefficients[i*NB_K_COEFF_PER_BIN+K55_PE] = 1;
114 k_coefficients[i*NB_K_COEFF_PER_BIN+K55_PE] = 1;
115 k_coefficients[i*NB_K_COEFF_PER_BIN+K45_PE_RE] = 1;
115 k_coefficients[i*NB_K_COEFF_PER_BIN+K45_PE_RE] = 1;
116 k_coefficients[i*NB_K_COEFF_PER_BIN+K45_PE_IM] = 1;
116 k_coefficients[i*NB_K_COEFF_PER_BIN+K45_PE_IM] = 1;
117 k_coefficients[i*NB_K_COEFF_PER_BIN+K14_SX_RE] = 1;
117 k_coefficients[i*NB_K_COEFF_PER_BIN+K14_SX_RE] = 1;
118 k_coefficients[i*NB_K_COEFF_PER_BIN+K14_SX_IM] = 1;
118 k_coefficients[i*NB_K_COEFF_PER_BIN+K14_SX_IM] = 1;
119 k_coefficients[i*NB_K_COEFF_PER_BIN+K15_SX_RE] = 1;
119 k_coefficients[i*NB_K_COEFF_PER_BIN+K15_SX_RE] = 1;
120 k_coefficients[i*NB_K_COEFF_PER_BIN+K15_SX_IM] = 1;
120 k_coefficients[i*NB_K_COEFF_PER_BIN+K15_SX_IM] = 1;
121 k_coefficients[i*NB_K_COEFF_PER_BIN+K24_SX_RE] = 1;
121 k_coefficients[i*NB_K_COEFF_PER_BIN+K24_SX_RE] = 1;
122 k_coefficients[i*NB_K_COEFF_PER_BIN+K24_SX_IM] = 1;
122 k_coefficients[i*NB_K_COEFF_PER_BIN+K24_SX_IM] = 1;
123 k_coefficients[i*NB_K_COEFF_PER_BIN+K25_SX_RE] = 1;
123 k_coefficients[i*NB_K_COEFF_PER_BIN+K25_SX_RE] = 1;
124 k_coefficients[i*NB_K_COEFF_PER_BIN+K25_SX_IM] = 1;
124 k_coefficients[i*NB_K_COEFF_PER_BIN+K25_SX_IM] = 1;
125 k_coefficients[i*NB_K_COEFF_PER_BIN+K34_SX_RE] = 1;
125 k_coefficients[i*NB_K_COEFF_PER_BIN+K34_SX_RE] = 1;
126 k_coefficients[i*NB_K_COEFF_PER_BIN+K34_SX_IM] = 1;
126 k_coefficients[i*NB_K_COEFF_PER_BIN+K34_SX_IM] = 1;
127 k_coefficients[i*NB_K_COEFF_PER_BIN+K35_SX_RE] = 1;
127 k_coefficients[i*NB_K_COEFF_PER_BIN+K35_SX_RE] = 1;
128 k_coefficients[i*NB_K_COEFF_PER_BIN+K35_SX_IM] = 1;
128 k_coefficients[i*NB_K_COEFF_PER_BIN+K35_SX_IM] = 1;
129 k_coefficients[i*NB_K_COEFF_PER_BIN+K24_NY_RE] = 1;
129 k_coefficients[i*NB_K_COEFF_PER_BIN+K24_NY_RE] = 1;
130 k_coefficients[i*NB_K_COEFF_PER_BIN+K24_NY_IM] = 1;
130 k_coefficients[i*NB_K_COEFF_PER_BIN+K24_NY_IM] = 1;
131 k_coefficients[i*NB_K_COEFF_PER_BIN+K25_NY_RE] = 1;
131 k_coefficients[i*NB_K_COEFF_PER_BIN+K25_NY_RE] = 1;
132 k_coefficients[i*NB_K_COEFF_PER_BIN+K25_NY_IM] = 1;
132 k_coefficients[i*NB_K_COEFF_PER_BIN+K25_NY_IM] = 1;
133 k_coefficients[i*NB_K_COEFF_PER_BIN+K34_NY_RE] = 1;
133 k_coefficients[i*NB_K_COEFF_PER_BIN+K34_NY_RE] = 1;
134 k_coefficients[i*NB_K_COEFF_PER_BIN+K34_NY_IM] = 1;
134 k_coefficients[i*NB_K_COEFF_PER_BIN+K34_NY_IM] = 1;
135 k_coefficients[i*NB_K_COEFF_PER_BIN+K35_NY_RE] = 1;
135 k_coefficients[i*NB_K_COEFF_PER_BIN+K35_NY_RE] = 1;
136 k_coefficients[i*NB_K_COEFF_PER_BIN+K35_NY_IM] = 1;
136 k_coefficients[i*NB_K_COEFF_PER_BIN+K35_NY_IM] = 1;
137 k_coefficients[i*NB_K_COEFF_PER_BIN+K24_NZ_RE] = 1;
137 k_coefficients[i*NB_K_COEFF_PER_BIN+K24_NZ_RE] = 1;
138 k_coefficients[i*NB_K_COEFF_PER_BIN+K24_NZ_IM] = 1;
138 k_coefficients[i*NB_K_COEFF_PER_BIN+K24_NZ_IM] = 1;
139 k_coefficients[i*NB_K_COEFF_PER_BIN+K25_NZ_RE] = 1;
139 k_coefficients[i*NB_K_COEFF_PER_BIN+K25_NZ_RE] = 1;
140 k_coefficients[i*NB_K_COEFF_PER_BIN+K25_NZ_IM] = 1;
140 k_coefficients[i*NB_K_COEFF_PER_BIN+K25_NZ_IM] = 1;
141 k_coefficients[i*NB_K_COEFF_PER_BIN+K34_NZ_RE] = 1;
141 k_coefficients[i*NB_K_COEFF_PER_BIN+K34_NZ_RE] = 1;
142 k_coefficients[i*NB_K_COEFF_PER_BIN+K34_NZ_IM] = 1;
142 k_coefficients[i*NB_K_COEFF_PER_BIN+K34_NZ_IM] = 1;
143 k_coefficients[i*NB_K_COEFF_PER_BIN+K35_NZ_RE] = 1;
143 k_coefficients[i*NB_K_COEFF_PER_BIN+K35_NZ_RE] = 1;
144 k_coefficients[i*NB_K_COEFF_PER_BIN+K35_NZ_IM] = 1;
144 k_coefficients[i*NB_K_COEFF_PER_BIN+K35_NZ_IM] = 1;
145 }
145 }
146
146
147 }
147 }
148
148
149
149
150 void init_k_coefficients(float *k_coefficients,
150 void init_k_coefficients(float *k_coefficients,
151 unsigned char nb_binscompressed_matrix )
151 unsigned char nb_binscompressed_matrix )
152 {
152 {
153 switch (nb_binscompressed_matrix)
153 switch (nb_binscompressed_matrix)
154 {
154 {
155 case NB_BINS_COMPRESSED_MATRIX_f0:
155 case NB_BINS_COMPRESSED_MATRIX_f0:
156 #ifdef DEBUG_TCH
156 #ifdef DEBUG_TCH
157 printf("F0 data: initialization of the intercalibration k-coefficients\n");
157 printf("F0 data: initialization of the intercalibration k-coefficients\n");
158 #endif
158 #endif
159 init_k_coefficients_f0(k_coefficients, nb_binscompressed_matrix);
159 init_k_coefficients_f0(k_coefficients, nb_binscompressed_matrix);
160 break;
160 break;
161
161
162 case NB_BINS_COMPRESSED_MATRIX_f1:
162 case NB_BINS_COMPRESSED_MATRIX_f1:
163 #ifdef DEBUG_TCH
163 #ifdef DEBUG_TCH
164 printf("F1 data: initialization of the intercalibration k-coefficients\n");
164 printf("F1 data: initialization of the intercalibration k-coefficients\n");
165 #endif
165 #endif
166 init_k_coefficients_f1(k_coefficients, nb_binscompressed_matrix);
166 init_k_coefficients_f1(k_coefficients, nb_binscompressed_matrix);
167 break;
167 break;
168
168
169 case NB_BINS_COMPRESSED_MATRIX_f2:
169 case NB_BINS_COMPRESSED_MATRIX_f2:
170 #ifdef DEBUG_TCH
170 #ifdef DEBUG_TCH
171 printf("F2 data: initialization of the intercalibration k-coefficients\n");
171 printf("F2 data: initialization of the intercalibration k-coefficients\n");
172 #endif
172 #endif
173 init_k_coefficients_f2(k_coefficients, nb_binscompressed_matrix);
173 init_k_coefficients_f2(k_coefficients, nb_binscompressed_matrix);
174 break;
174 break;
175
175
176 default:
176 default:
177 #ifdef DEBUG_TCH
177 #ifdef DEBUG_TCH
178 printf("there is a problème !!?\n");
178 printf("there is a problème !!?\n");
179 #endif
179 #endif
180 break;
180 break;
181 }
181 }
182 }
182 }
183
183
@@ -1,955 +1,959
1 // In the frame of RPW LFR Sofware ICD Issue1 Rev8 (05/07/2013) => R2 FSW
1 // In the frame of RPW LFR Sofware ICD Issue1 Rev8 (05/07/2013) => R2 FSW
2 // version 1.0: 31/07/2013
2 // version 1.0: 31/07/2013
3 // version 1.1: 02/04/2014
3 // version 1.1: 02/04/2014
4 // version 1.2: 30/04/2014
4 // version 1.2: 30/04/2014
5 // version 1.3: 02/05/2014
5 // version 1.3: 02/05/2014
6 // version 1.4: 16/05/2014
6 // version 1.4: 16/05/2014
7 // version 1.5: 20/05/2014
7 // version 1.5: 20/05/2014
8 // version 1.6: 19/12/2014
8 // version 1.6: 19/12/2014
9 // version 1.7: 15/01/2015 (modifs de Paul + correction erreurs qui se compensaient (LSB <=> MSB + indices [0,2] <=> [1,3])
9 // version 1.7: 15/01/2015 (modifs de Paul + correction erreurs qui se compensaient (LSB <=> MSB + indices [0,2] <=> [1,3])
10 // version 1.8: 02/02/2015 (gestion des divisions par zΓ©ro)
10 // version 1.8: 02/02/2015 (gestion des divisions par zΓ©ro)
11 // In the frame of RPW LFR Sofware ICD Issue3 Rev6 (27/01/2015) => R3 FSW
11 // In the frame of RPW LFR Sofware ICD Issue3 Rev6 (27/01/2015) => R3 FSW
12 // version 2.0: 19/06/2015
12 // version 2.0: 19/06/2015
13 // version 2.1: 22/06/2015 (modifs de Paul)
13 // version 2.1: 22/06/2015 (modifs de Paul)
14 // version 2.2: 23/06/2015 (modifs de l'ordre de dΓ©claration/dΓ©finition de init_k_coefficients dans basic_parameters.c ...)
14 // version 2.2: 23/06/2015 (modifs de l'ordre de dΓ©claration/dΓ©finition de init_k_coefficients dans basic_parameters.c ... + maintien des declarations dans le .h)
15
15
16 #ifndef BASIC_PARAMETERS_H_INCLUDED
16 #ifndef BASIC_PARAMETERS_H_INCLUDED
17 #define BASIC_PARAMETERS_H_INCLUDED
17 #define BASIC_PARAMETERS_H_INCLUDED
18
18
19 #include <math.h>
19 #include <math.h>
20 #include <stdio.h>
20 #include <stdio.h>
21 #include <stdint.h>
21 #include <stdint.h>
22
22
23 #include "basic_parameters_params.h"
23 #include "basic_parameters_params.h"
24
24
25 static inline void BP1_set(float * compressed_spec_mat, float * k_coeff_intercalib, unsigned char nb_bins_compressed_spec_mat, unsigned char * lfr_bp1);
25 static inline void BP1_set(float * compressed_spec_mat, float * k_coeff_intercalib, unsigned char nb_bins_compressed_spec_mat, unsigned char * lfr_bp1);
26 static inline void BP2_set(float * compressed_spec_mat, unsigned char nb_bins_compressed_spec_mat, unsigned char * lfr_bp2);
26 static inline void BP2_set(float * compressed_spec_mat, unsigned char nb_bins_compressed_spec_mat, unsigned char * lfr_bp2);
27
27
28 void init_k_coefficients_f0( float *k_coeff_intercalib, unsigned char nb_binscompressed_matrix );
29 void init_k_coefficients_f1( float *k_coeff_intercalib, unsigned char nb_binscompressed_matrix );
30 void init_k_coefficients_f2( float *k_coeff_intercalib, unsigned char nb_binscompressed_matrix );
31
28 void init_k_coefficients( float *k_coeff_intercalib, unsigned char nb_binscompressed_matrix );
32 void init_k_coefficients( float *k_coeff_intercalib, unsigned char nb_binscompressed_matrix );
29
33
30 //***********************************
34 //***********************************
31 // STATIC INLINE FUNCTION DEFINITIONS
35 // STATIC INLINE FUNCTION DEFINITIONS
32
36
33 void BP1_set( float * compressed_spec_mat, float * k_coeff_intercalib, uint8_t nb_bins_compressed_spec_mat, uint8_t * lfr_bp1 ){
37 void BP1_set( float * compressed_spec_mat, float * k_coeff_intercalib, uint8_t nb_bins_compressed_spec_mat, uint8_t * lfr_bp1 ){
34 float PSDB; // 32-bit floating point
38 float PSDB; // 32-bit floating point
35 float PSDE;
39 float PSDE;
36 float tmp;
40 float tmp;
37 float NVEC_V0;
41 float NVEC_V0;
38 float NVEC_V1;
42 float NVEC_V1;
39 float NVEC_V2;
43 float NVEC_V2;
40 float aux;
44 float aux;
41 float tr_SB_SB;
45 float tr_SB_SB;
42 float e_cross_b_re;
46 float e_cross_b_re;
43 float e_cross_b_im;
47 float e_cross_b_im;
44 float n_cross_e_scal_b_re;
48 float n_cross_e_scal_b_re;
45 float n_cross_e_scal_b_im;
49 float n_cross_e_scal_b_im;
46 float ny;
50 float ny;
47 float nz;
51 float nz;
48 float bx_bx_star;
52 float bx_bx_star;
49 float vphi;
53 float vphi;
50 float significand;
54 float significand;
51 int exponent; // 32-bit signed integer
55 int exponent; // 32-bit signed integer
52 float alpha_M;
56 float alpha_M;
53
57
54 uint8_t nbitexp; // 8-bit unsigned integer
58 uint8_t nbitexp; // 8-bit unsigned integer
55 uint8_t nbitsig;
59 uint8_t nbitsig;
56 uint8_t tmp_uint8;
60 uint8_t tmp_uint8;
57 uint8_t *pt_uint8; // pointer on unsigned 8-bit integer
61 uint8_t *pt_uint8; // pointer on unsigned 8-bit integer
58 int8_t expmin; // 8-bit signed integer
62 int8_t expmin; // 8-bit signed integer
59 int8_t expmax;
63 int8_t expmax;
60 uint16_t rangesig; // 16-bit unsigned integer
64 uint16_t rangesig; // 16-bit unsigned integer
61 uint16_t psd;
65 uint16_t psd;
62 uint16_t exp;
66 uint16_t exp;
63 uint16_t tmp_uint16;
67 uint16_t tmp_uint16;
64 uint16_t i;
68 uint16_t i;
65
69
66 alpha_M = 45 * (3.1415927/180);
70 alpha_M = 45 * (3.1415927/180);
67
71
68 #ifdef DEBUG_TCH
72 #ifdef DEBUG_TCH
69 printf("BP1 : \n");
73 printf("BP1 : \n");
70 printf("Number of bins: %d\n", nb_bins_compressed_spec_mat);
74 printf("Number of bins: %d\n", nb_bins_compressed_spec_mat);
71 #endif
75 #endif
72
76
73 // initialization for managing the exponents of the floating point data:
77 // initialization for managing the exponents of the floating point data:
74 nbitexp = 6; // number of bits for the exponent
78 nbitexp = 6; // number of bits for the exponent
75 expmax = 32+5; // maximum value of the exponent
79 expmax = 32+5; // maximum value of the exponent
76 expmin = expmax - (1 << nbitexp) + 1; // accordingly the minimum exponent value
80 expmin = expmax - (1 << nbitexp) + 1; // accordingly the minimum exponent value
77 // for floating point data to be recorded on 16-bit words:
81 // for floating point data to be recorded on 16-bit words:
78 nbitsig = 16 - nbitexp; // number of bits for the significand
82 nbitsig = 16 - nbitexp; // number of bits for the significand
79 rangesig = (1 << nbitsig)-1; // == 2^nbitsig - 1
83 rangesig = (1 << nbitsig)-1; // == 2^nbitsig - 1
80
84
81 #ifdef DEBUG_TCH
85 #ifdef DEBUG_TCH
82 printf("nbitexp : %d, expmax : %d, expmin : %d\n", nbitexp, expmax, expmin);
86 printf("nbitexp : %d, expmax : %d, expmin : %d\n", nbitexp, expmax, expmin);
83 printf("nbitsig : %d, rangesig : %d\n", nbitsig, rangesig);
87 printf("nbitsig : %d, rangesig : %d\n", nbitsig, rangesig);
84 #endif
88 #endif
85
89
86 for(i=0; i<nb_bins_compressed_spec_mat; i++){
90 for(i=0; i<nb_bins_compressed_spec_mat; i++){
87 //==============================================
91 //==============================================
88 // BP1 PSDB == PA_LFR_SC_BP1_PB_F0 == 16 bits = 6 bits (exponent) + 10 bits (significand)
92 // BP1 PSDB == PA_LFR_SC_BP1_PB_F0 == 16 bits = 6 bits (exponent) + 10 bits (significand)
89 PSDB = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX] // S11
93 PSDB = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX] // S11
90 + compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+9] // S22
94 + compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+9] // S22
91 + compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+16]; // S33
95 + compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+16]; // S33
92
96
93 significand = frexpf(PSDB, &exponent); // 0.5 <= significand < 1
97 significand = frexpf(PSDB, &exponent); // 0.5 <= significand < 1
94 // PSDB = significand * 2^exponent
98 // PSDB = significand * 2^exponent
95
99
96 if (exponent < expmin) { // value should be >= 0.5 * 2^expmin
100 if (exponent < expmin) { // value should be >= 0.5 * 2^expmin
97 exponent = expmin;
101 exponent = expmin;
98 significand = 0.5; // min value that can be recorded
102 significand = 0.5; // min value that can be recorded
99 }
103 }
100 if (exponent > expmax) { // value should be < 0.5 * 2^(expmax+1)
104 if (exponent > expmax) { // value should be < 0.5 * 2^(expmax+1)
101 exponent = expmax;
105 exponent = expmax;
102 significand = 1.0; // max value that can be recorded
106 significand = 1.0; // max value that can be recorded
103 }
107 }
104 if (significand == 0) { // in that case exponent == 0 too
108 if (significand == 0) { // in that case exponent == 0 too
105 exponent = expmin;
109 exponent = expmin;
106 significand = 0.5; // min value that can be recorded
110 significand = 0.5; // min value that can be recorded
107 }
111 }
108
112
109 psd = (uint16_t) ((significand*2-1)*rangesig + 0.5); // Shift and cast into a 16-bit unsigned int with rounding
113 psd = (uint16_t) ((significand*2-1)*rangesig + 0.5); // Shift and cast into a 16-bit unsigned int with rounding
110 // where just the first nbitsig bits are used (0, ..., 2^nbitsig-1)
114 // where just the first nbitsig bits are used (0, ..., 2^nbitsig-1)
111 exp = (uint16_t) (exponent-expmin); // Shift and cast into a 16-bit unsigned int where just
115 exp = (uint16_t) (exponent-expmin); // Shift and cast into a 16-bit unsigned int where just
112 // the first nbitexp bits are used (0, ..., 2^nbitexp-1)
116 // the first nbitexp bits are used (0, ..., 2^nbitexp-1)
113 tmp_uint16 = psd | (exp << nbitsig); // Put the exponent bits (nbitexp) next to the
117 tmp_uint16 = psd | (exp << nbitsig); // Put the exponent bits (nbitexp) next to the
114 // left place of the significand bits (nbitsig),
118 // left place of the significand bits (nbitsig),
115 // making the 16-bit word to be recorded
119 // making the 16-bit word to be recorded
116 pt_uint8 = (uint8_t*) &tmp_uint16; // Affect an uint8_t pointer with the adress of tmp_uint16
120 pt_uint8 = (uint8_t*) &tmp_uint16; // Affect an uint8_t pointer with the adress of tmp_uint16
117 #ifdef MSB_FIRST_TCH
121 #ifdef MSB_FIRST_TCH
118 lfr_bp1[i*NB_BYTES_BP1+2] = pt_uint8[0]; // Record MSB of tmp_uint16
122 lfr_bp1[i*NB_BYTES_BP1+2] = pt_uint8[0]; // Record MSB of tmp_uint16
119 lfr_bp1[i*NB_BYTES_BP1+3] = pt_uint8[1]; // Record LSB of tmp_uint16
123 lfr_bp1[i*NB_BYTES_BP1+3] = pt_uint8[1]; // Record LSB of tmp_uint16
120 #endif
124 #endif
121 #ifdef LSB_FIRST_TCH
125 #ifdef LSB_FIRST_TCH
122 lfr_bp1[i*NB_BYTES_BP1+2] = pt_uint8[1]; // Record MSB of tmp_uint16
126 lfr_bp1[i*NB_BYTES_BP1+2] = pt_uint8[1]; // Record MSB of tmp_uint16
123 lfr_bp1[i*NB_BYTES_BP1+3] = pt_uint8[0]; // Record LSB of tmp_uint16
127 lfr_bp1[i*NB_BYTES_BP1+3] = pt_uint8[0]; // Record LSB of tmp_uint16
124 #endif
128 #endif
125 #ifdef DEBUG_TCH
129 #ifdef DEBUG_TCH
126 printf("\nBin number: %d\n", i);
130 printf("\nBin number: %d\n", i);
127 printf("PSDB : %16.8e\n",PSDB);
131 printf("PSDB : %16.8e\n",PSDB);
128 printf("significand : %16.8e\n",significand);
132 printf("significand : %16.8e\n",significand);
129 printf("exponent : %d\n" ,exponent);
133 printf("exponent : %d\n" ,exponent);
130 printf("psd for PSDB significand : %d\n",psd);
134 printf("psd for PSDB significand : %d\n",psd);
131 printf("exp for PSDB exponent : %d\n",exp);
135 printf("exp for PSDB exponent : %d\n",exp);
132 printf("pt_uint8[1] for PSDB exponent + significand: %.3d or %.2x\n",pt_uint8[1], pt_uint8[1]);
136 printf("pt_uint8[1] for PSDB exponent + significand: %.3d or %.2x\n",pt_uint8[1], pt_uint8[1]);
133 printf("pt_uint8[0] for PSDB significand: %.3d or %.2x\n",pt_uint8[0], pt_uint8[0]);
137 printf("pt_uint8[0] for PSDB significand: %.3d or %.2x\n",pt_uint8[0], pt_uint8[0]);
134 printf("lfr_bp1[i*NB_BYTES_BP1+2] : %.3d or %.2x\n",lfr_bp1[i*NB_BYTES_BP1+2], lfr_bp1[i*NB_BYTES_BP1+2]);
138 printf("lfr_bp1[i*NB_BYTES_BP1+2] : %.3d or %.2x\n",lfr_bp1[i*NB_BYTES_BP1+2], lfr_bp1[i*NB_BYTES_BP1+2]);
135 printf("lfr_bp1[i*NB_BYTES_BP1+3] : %.3d or %.2x\n",lfr_bp1[i*NB_BYTES_BP1+3], lfr_bp1[i*NB_BYTES_BP1+3]);
139 printf("lfr_bp1[i*NB_BYTES_BP1+3] : %.3d or %.2x\n",lfr_bp1[i*NB_BYTES_BP1+3], lfr_bp1[i*NB_BYTES_BP1+3]);
136 #endif
140 #endif
137 //==============================================
141 //==============================================
138 // BP1 PSDE == PA_LFR_SC_BP1_PE_F0 == 16 bits = 6 bits (exponent) + 10 bits (significand)
142 // BP1 PSDE == PA_LFR_SC_BP1_PE_F0 == 16 bits = 6 bits (exponent) + 10 bits (significand)
139 PSDE = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+21] * k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K44_PE] // S44
143 PSDE = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+21] * k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K44_PE] // S44
140 + compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+24] * k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K55_PE] // S55
144 + compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+24] * k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K55_PE] // S55
141 + compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+22] * k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K45_PE_RE] // S45 Re
145 + compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+22] * k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K45_PE_RE] // S45 Re
142 - compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+23] * k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K45_PE_IM]; // S45 Im
146 - compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+23] * k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K45_PE_IM]; // S45 Im
143
147
144 significand = frexpf(PSDE, &exponent); // 0.5 <= significand < 1
148 significand = frexpf(PSDE, &exponent); // 0.5 <= significand < 1
145 // PSDE = significand * 2^exponent
149 // PSDE = significand * 2^exponent
146
150
147 if (exponent < expmin) { // value should be >= 0.5 * 2^expmin
151 if (exponent < expmin) { // value should be >= 0.5 * 2^expmin
148 exponent = expmin;
152 exponent = expmin;
149 significand = 0.5; // min value that can be recorded
153 significand = 0.5; // min value that can be recorded
150 }
154 }
151 if (exponent > expmax) { // value should be < 0.5 * 2^(expmax+1)
155 if (exponent > expmax) { // value should be < 0.5 * 2^(expmax+1)
152 exponent = expmax;
156 exponent = expmax;
153 significand = 1.0; // max value that can be recorded
157 significand = 1.0; // max value that can be recorded
154 }
158 }
155 if (significand == 0) {// in that case exponent == 0 too
159 if (significand == 0) {// in that case exponent == 0 too
156 exponent = expmin;
160 exponent = expmin;
157 significand = 0.5; // min value that can be recorded
161 significand = 0.5; // min value that can be recorded
158 }
162 }
159
163
160 psd = (uint16_t) ((significand*2-1)*rangesig + 0.5); // Shift and cast into a 16-bit unsigned int with rounding
164 psd = (uint16_t) ((significand*2-1)*rangesig + 0.5); // Shift and cast into a 16-bit unsigned int with rounding
161 // where just the first nbitsig bits are used (0, ..., 2^nbitsig-1)
165 // where just the first nbitsig bits are used (0, ..., 2^nbitsig-1)
162 exp = (uint16_t) (exponent-expmin); // Shift and cast into a 16-bit unsigned int where just
166 exp = (uint16_t) (exponent-expmin); // Shift and cast into a 16-bit unsigned int where just
163 // the first nbitexp bits are used (0, ..., 2^nbitexp-1)
167 // the first nbitexp bits are used (0, ..., 2^nbitexp-1)
164 tmp_uint16 = psd | (exp << nbitsig); // Put the exponent bits (nbitexp) next to the
168 tmp_uint16 = psd | (exp << nbitsig); // Put the exponent bits (nbitexp) next to the
165 // left place of the significand bits (nbitsig),
169 // left place of the significand bits (nbitsig),
166 // making the 16-bit word to be recorded
170 // making the 16-bit word to be recorded
167 pt_uint8 = (uint8_t*) &tmp_uint16; // Affect an uint8_t pointer with the adress of tmp_uint16
171 pt_uint8 = (uint8_t*) &tmp_uint16; // Affect an uint8_t pointer with the adress of tmp_uint16
168 #ifdef MSB_FIRST_TCH
172 #ifdef MSB_FIRST_TCH
169 lfr_bp1[i*NB_BYTES_BP1+0] = pt_uint8[0]; // Record MSB of tmp_uint16
173 lfr_bp1[i*NB_BYTES_BP1+0] = pt_uint8[0]; // Record MSB of tmp_uint16
170 lfr_bp1[i*NB_BYTES_BP1+1] = pt_uint8[1]; // Record LSB of tmp_uint16
174 lfr_bp1[i*NB_BYTES_BP1+1] = pt_uint8[1]; // Record LSB of tmp_uint16
171 #endif
175 #endif
172 #ifdef LSB_FIRST_TCH
176 #ifdef LSB_FIRST_TCH
173 lfr_bp1[i*NB_BYTES_BP1+0] = pt_uint8[1]; // Record MSB of tmp_uint16
177 lfr_bp1[i*NB_BYTES_BP1+0] = pt_uint8[1]; // Record MSB of tmp_uint16
174 lfr_bp1[i*NB_BYTES_BP1+1] = pt_uint8[0]; // Record LSB of tmp_uint16
178 lfr_bp1[i*NB_BYTES_BP1+1] = pt_uint8[0]; // Record LSB of tmp_uint16
175 #endif
179 #endif
176 #ifdef DEBUG_TCH
180 #ifdef DEBUG_TCH
177 printf("PSDE : %16.8e\n",PSDE);
181 printf("PSDE : %16.8e\n",PSDE);
178 printf("significand : %16.8e\n",significand);
182 printf("significand : %16.8e\n",significand);
179 printf("exponent : %d\n" ,exponent);
183 printf("exponent : %d\n" ,exponent);
180 printf("psd for PSDE significand : %d\n",psd);
184 printf("psd for PSDE significand : %d\n",psd);
181 printf("exp for PSDE exponent : %d\n",exp);
185 printf("exp for PSDE exponent : %d\n",exp);
182 printf("pt_uint8[1] for PSDE exponent + significand: %.3d or %.2x\n",pt_uint8[1], pt_uint8[1]);
186 printf("pt_uint8[1] for PSDE exponent + significand: %.3d or %.2x\n",pt_uint8[1], pt_uint8[1]);
183 printf("pt_uint8[0] for PSDE significand: %.3d or %.2x\n",pt_uint8[0], pt_uint8[0]);
187 printf("pt_uint8[0] for PSDE significand: %.3d or %.2x\n",pt_uint8[0], pt_uint8[0]);
184 printf("lfr_bp1[i*NB_BYTES_BP1+0] : %.3d or %.2x\n",lfr_bp1[i*NB_BYTES_BP1+0], lfr_bp1[i*NB_BYTES_BP1+0]);
188 printf("lfr_bp1[i*NB_BYTES_BP1+0] : %.3d or %.2x\n",lfr_bp1[i*NB_BYTES_BP1+0], lfr_bp1[i*NB_BYTES_BP1+0]);
185 printf("lfr_bp1[i*NB_BYTES_BP1+1] : %.3d or %.2x\n",lfr_bp1[i*NB_BYTES_BP1+1], lfr_bp1[i*NB_BYTES_BP1+1]);
189 printf("lfr_bp1[i*NB_BYTES_BP1+1] : %.3d or %.2x\n",lfr_bp1[i*NB_BYTES_BP1+1], lfr_bp1[i*NB_BYTES_BP1+1]);
186 #endif
190 #endif
187 //==============================================================================
191 //==============================================================================
188 // BP1 normal wave vector == PA_LFR_SC_BP1_NVEC_V0_F0 == 8 bits
192 // BP1 normal wave vector == PA_LFR_SC_BP1_NVEC_V0_F0 == 8 bits
189 // == PA_LFR_SC_BP1_NVEC_V1_F0 == 8 bits
193 // == PA_LFR_SC_BP1_NVEC_V1_F0 == 8 bits
190 // == PA_LFR_SC_BP1_NVEC_V2_F0 == 1 sign bit
194 // == PA_LFR_SC_BP1_NVEC_V2_F0 == 1 sign bit
191 tmp = sqrt( compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+2] *compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+2] //Im S12
195 tmp = sqrt( compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+2] *compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+2] //Im S12
192 +compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+4] *compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+4] //Im S13
196 +compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+4] *compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+4] //Im S13
193 +compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+11]*compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+11] //Im S23
197 +compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+11]*compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+11] //Im S23
194 );
198 );
195 if (tmp != 0.) { // no division by 0.
199 if (tmp != 0.) { // no division by 0.
196 NVEC_V0 = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+11]/ tmp; // S23 Im => n1
200 NVEC_V0 = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+11]/ tmp; // S23 Im => n1
197 NVEC_V1 = -compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+4] / tmp; // S13 Im => n2
201 NVEC_V1 = -compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+4] / tmp; // S13 Im => n2
198 NVEC_V2 = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+2] / tmp; // S12 Im => n3
202 NVEC_V2 = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+2] / tmp; // S12 Im => n3
199 }
203 }
200 else
204 else
201 {
205 {
202 NVEC_V0 = 0.;
206 NVEC_V0 = 0.;
203 NVEC_V1 = 0.;
207 NVEC_V1 = 0.;
204 NVEC_V2 = 0.;
208 NVEC_V2 = 0.;
205 }
209 }
206 lfr_bp1[i*NB_BYTES_BP1+4] = (uint8_t) (NVEC_V0*127.5 + 128); // Shift and cast into a 8-bit uint8_t (0, ..., 255) with rounding
210 lfr_bp1[i*NB_BYTES_BP1+4] = (uint8_t) (NVEC_V0*127.5 + 128); // Shift and cast into a 8-bit uint8_t (0, ..., 255) with rounding
207 lfr_bp1[i*NB_BYTES_BP1+5] = (uint8_t) (NVEC_V1*127.5 + 128); // Shift and cast into a 8-bit uint8_t (0, ..., 255) with rounding
211 lfr_bp1[i*NB_BYTES_BP1+5] = (uint8_t) (NVEC_V1*127.5 + 128); // Shift and cast into a 8-bit uint8_t (0, ..., 255) with rounding
208 pt_uint8 = (uint8_t*) &NVEC_V2; // Affect an uint8_t pointer with the adress of NVEC_V2
212 pt_uint8 = (uint8_t*) &NVEC_V2; // Affect an uint8_t pointer with the adress of NVEC_V2
209 #ifdef LSB_FIRST_TCH
213 #ifdef LSB_FIRST_TCH
210 lfr_bp1[i*NB_BYTES_BP1+6] = pt_uint8[3] & 0x80; // Extract the sign bit of NVEC_V2 (32-bit float, sign bit in the 4th octet:PC convention)
214 lfr_bp1[i*NB_BYTES_BP1+6] = pt_uint8[3] & 0x80; // Extract the sign bit of NVEC_V2 (32-bit float, sign bit in the 4th octet:PC convention)
211 // Record it at the 8th bit position (from the right to the left) of lfr_bp1[i*NB_BYTES_BP1+6]
215 // Record it at the 8th bit position (from the right to the left) of lfr_bp1[i*NB_BYTES_BP1+6]
212 #endif
216 #endif
213 #ifdef MSB_FIRST_TCH
217 #ifdef MSB_FIRST_TCH
214 lfr_bp1[i*NB_BYTES_BP1+6] = pt_uint8[0] & 0x80; // Extract the sign bit of NVEC_V2 (32-bit float, sign bit in the 1th octet:SPARC convention)
218 lfr_bp1[i*NB_BYTES_BP1+6] = pt_uint8[0] & 0x80; // Extract the sign bit of NVEC_V2 (32-bit float, sign bit in the 1th octet:SPARC convention)
215 // Record it at the 8th bit position (from the right to the left) of lfr_bp1[i*NB_BYTES_BP1+6]
219 // Record it at the 8th bit position (from the right to the left) of lfr_bp1[i*NB_BYTES_BP1+6]
216 #endif
220 #endif
217 #ifdef DEBUG_TCH
221 #ifdef DEBUG_TCH
218 printf("NVEC_V0 : %16.8e\n",NVEC_V0);
222 printf("NVEC_V0 : %16.8e\n",NVEC_V0);
219 printf("NVEC_V1 : %16.8e\n",NVEC_V1);
223 printf("NVEC_V1 : %16.8e\n",NVEC_V1);
220 printf("NVEC_V2 : %16.8e\n",NVEC_V2);
224 printf("NVEC_V2 : %16.8e\n",NVEC_V2);
221 printf("lfr_bp1[i*NB_BYTES_BP1+4] for NVEC_V0 : %u\n",lfr_bp1[i*NB_BYTES_BP1+4]);
225 printf("lfr_bp1[i*NB_BYTES_BP1+4] for NVEC_V0 : %u\n",lfr_bp1[i*NB_BYTES_BP1+4]);
222 printf("lfr_bp1[i*NB_BYTES_BP1+5] for NVEC_V1 : %u\n",lfr_bp1[i*NB_BYTES_BP1+5]);
226 printf("lfr_bp1[i*NB_BYTES_BP1+5] for NVEC_V1 : %u\n",lfr_bp1[i*NB_BYTES_BP1+5]);
223 printf("lfr_bp1[i*NB_BYTES_BP1+6] for NVEC_V2 : %u\n",lfr_bp1[i*NB_BYTES_BP1+6]);
227 printf("lfr_bp1[i*NB_BYTES_BP1+6] for NVEC_V2 : %u\n",lfr_bp1[i*NB_BYTES_BP1+6]);
224 #endif
228 #endif
225 //=======================================================
229 //=======================================================
226 // BP1 ellipticity == PA_LFR_SC_BP1_ELLIP_F0 == 4 bits
230 // BP1 ellipticity == PA_LFR_SC_BP1_ELLIP_F0 == 4 bits
227 if (PSDB != 0.) { // no division by 0.
231 if (PSDB != 0.) { // no division by 0.
228 aux = 2*tmp / PSDB; // Compute the ellipticity
232 aux = 2*tmp / PSDB; // Compute the ellipticity
229 }
233 }
230 else
234 else
231 {
235 {
232 aux = 0.;
236 aux = 0.;
233 }
237 }
234 tmp_uint8 = (uint8_t) (aux*15 + 0.5); // Shift and cast into a 8-bit uint8_t with rounding
238 tmp_uint8 = (uint8_t) (aux*15 + 0.5); // Shift and cast into a 8-bit uint8_t with rounding
235 // where just the first 4 bits are used (0, ..., 15)
239 // where just the first 4 bits are used (0, ..., 15)
236 lfr_bp1[i*NB_BYTES_BP1+6] = lfr_bp1[i*NB_BYTES_BP1+6] | (tmp_uint8 << 3); // Put these 4 bits next to the right place
240 lfr_bp1[i*NB_BYTES_BP1+6] = lfr_bp1[i*NB_BYTES_BP1+6] | (tmp_uint8 << 3); // Put these 4 bits next to the right place
237 // of the sign bit of NVEC_V2 (recorded
241 // of the sign bit of NVEC_V2 (recorded
238 // previously in lfr_bp1[i*NB_BYTES_BP1+6])
242 // previously in lfr_bp1[i*NB_BYTES_BP1+6])
239 #ifdef DEBUG_TCH
243 #ifdef DEBUG_TCH
240 printf("ellipticity : %16.8e\n",aux);
244 printf("ellipticity : %16.8e\n",aux);
241 printf("tmp_uint8 for ellipticity : %u\n",tmp_uint8);
245 printf("tmp_uint8 for ellipticity : %u\n",tmp_uint8);
242 printf("lfr_bp1[i*NB_BYTES_BP1+6] for NVEC_V2 + ellipticity : %u\n",lfr_bp1[i*NB_BYTES_BP1+6]);
246 printf("lfr_bp1[i*NB_BYTES_BP1+6] for NVEC_V2 + ellipticity : %u\n",lfr_bp1[i*NB_BYTES_BP1+6]);
243 #endif
247 #endif
244 //==============================================================
248 //==============================================================
245 // BP1 degree of polarization == PA_LFR_SC_BP1_DOP_F0 == 3 bits
249 // BP1 degree of polarization == PA_LFR_SC_BP1_DOP_F0 == 3 bits
246 tr_SB_SB = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX] *compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX]
250 tr_SB_SB = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX] *compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX]
247 + compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+9] *compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+9]
251 + compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+9] *compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+9]
248 + compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+16] *compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+16]
252 + compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+16] *compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+16]
249 + 2 * compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+1] *compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+1]
253 + 2 * compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+1] *compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+1]
250 + 2 * compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+2] *compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+2]
254 + 2 * compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+2] *compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+2]
251 + 2 * compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+3] *compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+3]
255 + 2 * compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+3] *compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+3]
252 + 2 * compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+4] *compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+4]
256 + 2 * compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+4] *compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+4]
253 + 2 * compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+10]*compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+10]
257 + 2 * compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+10]*compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+10]
254 + 2 * compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+11]*compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+11];
258 + 2 * compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+11]*compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+11];
255 aux = PSDB*PSDB;
259 aux = PSDB*PSDB;
256 if (aux != 0.) { // no division by 0.
260 if (aux != 0.) { // no division by 0.
257 tmp = ( 3*tr_SB_SB - aux ) / ( 2 * aux ); // Compute the degree of polarisation
261 tmp = ( 3*tr_SB_SB - aux ) / ( 2 * aux ); // Compute the degree of polarisation
258 }
262 }
259 else
263 else
260 {
264 {
261 tmp = 0.;
265 tmp = 0.;
262 }
266 }
263 tmp_uint8 = (uint8_t) (tmp*7 + 0.5); // Shift and cast into a 8-bit uint8_t with rounding
267 tmp_uint8 = (uint8_t) (tmp*7 + 0.5); // Shift and cast into a 8-bit uint8_t with rounding
264 // where just the first 3 bits are used (0, ..., 7)
268 // where just the first 3 bits are used (0, ..., 7)
265 lfr_bp1[i*NB_BYTES_BP1+6] = lfr_bp1[i*NB_BYTES_BP1+6] | tmp_uint8; // Record these 3 bits at the 3 first bit positions
269 lfr_bp1[i*NB_BYTES_BP1+6] = lfr_bp1[i*NB_BYTES_BP1+6] | tmp_uint8; // Record these 3 bits at the 3 first bit positions
266 // (from the right to the left) of lfr_bp1[i*NB_BYTES_BP1+6]
270 // (from the right to the left) of lfr_bp1[i*NB_BYTES_BP1+6]
267 #ifdef DEBUG_TCH
271 #ifdef DEBUG_TCH
268 printf("DOP : %16.8e\n",tmp);
272 printf("DOP : %16.8e\n",tmp);
269 printf("tmp_uint8 for DOP : %u\n",tmp_uint8);
273 printf("tmp_uint8 for DOP : %u\n",tmp_uint8);
270 printf("lfr_bp1[i*NB_BYTES_BP1+6] for NVEC_V2 + ellipticity + DOP : %u\n",lfr_bp1[i*NB_BYTES_BP1+6]);
274 printf("lfr_bp1[i*NB_BYTES_BP1+6] for NVEC_V2 + ellipticity + DOP : %u\n",lfr_bp1[i*NB_BYTES_BP1+6]);
271 #endif
275 #endif
272 //=======================================================================================
276 //=======================================================================================
273 // BP1 X_SO-component of the Poynting flux == PA_LFR_SC_BP1_SX_F0 == 16 bits
277 // BP1 X_SO-component of the Poynting flux == PA_LFR_SC_BP1_SX_F0 == 16 bits
274 // = 1 sign bit + 1 argument bit (two sectors)
278 // = 1 sign bit + 1 argument bit (two sectors)
275 // + 6 bits (exponent) + 8 bits (significand)
279 // + 6 bits (exponent) + 8 bits (significand)
276 e_cross_b_re = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+17]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K34_SX_RE] //S34 Re
280 e_cross_b_re = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+17]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K34_SX_RE] //S34 Re
277 + compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+19]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K35_SX_RE] //S35 Re
281 + compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+19]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K35_SX_RE] //S35 Re
278 + compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+5] *k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K14_SX_RE] //S14 Re
282 + compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+5] *k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K14_SX_RE] //S14 Re
279 + compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+7] *k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K15_SX_RE] //S15 Re
283 + compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+7] *k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K15_SX_RE] //S15 Re
280 + compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+12]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K24_SX_RE] //S24 Re
284 + compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+12]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K24_SX_RE] //S24 Re
281 + compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+14]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K25_SX_RE] //S25 Re
285 + compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+14]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K25_SX_RE] //S25 Re
282 + compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+18]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K34_SX_IM] //S34 Im
286 + compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+18]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K34_SX_IM] //S34 Im
283 + compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+20]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K35_SX_IM] //S35 Im
287 + compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+20]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K35_SX_IM] //S35 Im
284 + compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+6] *k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K14_SX_IM] //S14 Im
288 + compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+6] *k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K14_SX_IM] //S14 Im
285 + compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+8] *k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K15_SX_IM] //S15 Im
289 + compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+8] *k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K15_SX_IM] //S15 Im
286 + compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+13]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K24_SX_IM] //S24 Im
290 + compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+13]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K24_SX_IM] //S24 Im
287 + compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+15]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K25_SX_IM]; //S25 Im
291 + compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+15]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K25_SX_IM]; //S25 Im
288 // Im(S_ji) = -Im(S_ij)
292 // Im(S_ji) = -Im(S_ij)
289 // k_ji = k_ij
293 // k_ji = k_ij
290 e_cross_b_im = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+17]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K34_SX_IM] //S34 Re
294 e_cross_b_im = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+17]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K34_SX_IM] //S34 Re
291 + compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+19]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K35_SX_IM] //S35 Re
295 + compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+19]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K35_SX_IM] //S35 Re
292 + compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+5] *k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K14_SX_IM] //S14 Re
296 + compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+5] *k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K14_SX_IM] //S14 Re
293 + compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+7] *k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K15_SX_IM] //S15 Re
297 + compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+7] *k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K15_SX_IM] //S15 Re
294 + compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+12]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K24_SX_IM] //S24 Re
298 + compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+12]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K24_SX_IM] //S24 Re
295 + compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+14]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K25_SX_IM] //S25 Re
299 + compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+14]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K25_SX_IM] //S25 Re
296 - compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+18]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K34_SX_RE] //S34 Im
300 - compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+18]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K34_SX_RE] //S34 Im
297 - compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+20]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K35_SX_RE] //S35 Im
301 - compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+20]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K35_SX_RE] //S35 Im
298 - compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+6] *k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K14_SX_RE] //S14 Im
302 - compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+6] *k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K14_SX_RE] //S14 Im
299 - compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+8] *k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K15_SX_RE] //S15 Im
303 - compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+8] *k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K15_SX_RE] //S15 Im
300 - compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+13]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K24_SX_RE] //S24 Im
304 - compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+13]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K24_SX_RE] //S24 Im
301 - compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+15]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K25_SX_RE]; //S25 Im
305 - compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+15]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K25_SX_RE]; //S25 Im
302 #ifdef DEBUG_TCH
306 #ifdef DEBUG_TCH
303 printf("ReaSX : %16.8e\n",e_cross_b_re);
307 printf("ReaSX : %16.8e\n",e_cross_b_re);
304 #endif
308 #endif
305 pt_uint8 = (uint8_t*) &e_cross_b_re; // Affect an uint8_t pointer with the adress of e_cross_b_re
309 pt_uint8 = (uint8_t*) &e_cross_b_re; // Affect an uint8_t pointer with the adress of e_cross_b_re
306 #ifdef LSB_FIRST_TCH
310 #ifdef LSB_FIRST_TCH
307 lfr_bp1[i*NB_BYTES_BP1+7] = lfr_bp1[i*NB_BYTES_BP1+7] | (pt_uint8[3] & 0x80); // Extract its sign bit (32-bit float, sign bit in the 4th octet:PC convention)
311 lfr_bp1[i*NB_BYTES_BP1+7] = lfr_bp1[i*NB_BYTES_BP1+7] | (pt_uint8[3] & 0x80); // Extract its sign bit (32-bit float, sign bit in the 4th octet:PC convention)
308 // Record it at the 8th bit position (from the right to the left)
312 // Record it at the 8th bit position (from the right to the left)
309 // of lfr_bp1[i*NB_BYTES_BP1+7]
313 // of lfr_bp1[i*NB_BYTES_BP1+7]
310 pt_uint8[3] = (pt_uint8[3] & 0x7f); // Make e_cross_b_re be positive in any case: |ReaSX|
314 pt_uint8[3] = (pt_uint8[3] & 0x7f); // Make e_cross_b_re be positive in any case: |ReaSX|
311 #endif
315 #endif
312 #ifdef MSB_FIRST_TCH
316 #ifdef MSB_FIRST_TCH
313 lfr_bp1[i*NB_BYTES_BP1+7] = lfr_bp1[i*NB_BYTES_BP1+7] | (pt_uint8[0] & 0x80); // Extract its sign bit (32-bit float, sign bit in the 1th octet:SPARC convention)
317 lfr_bp1[i*NB_BYTES_BP1+7] = lfr_bp1[i*NB_BYTES_BP1+7] | (pt_uint8[0] & 0x80); // Extract its sign bit (32-bit float, sign bit in the 1th octet:SPARC convention)
314 // Record it at the 8th bit position (from the right to the left)
318 // Record it at the 8th bit position (from the right to the left)
315 // of lfr_bp1[i*NB_BYTES_BP1+7]
319 // of lfr_bp1[i*NB_BYTES_BP1+7]
316 pt_uint8[0] = (pt_uint8[0] & 0x7f); // Make e_cross_b_re be positive in any case: |ReaSX|
320 pt_uint8[0] = (pt_uint8[0] & 0x7f); // Make e_cross_b_re be positive in any case: |ReaSX|
317 #endif
321 #endif
318 significand = frexpf(e_cross_b_re, &exponent); // 0.5 <= significand < 1
322 significand = frexpf(e_cross_b_re, &exponent); // 0.5 <= significand < 1
319 // ReaSX = significand * 2^exponent
323 // ReaSX = significand * 2^exponent
320 if (exponent < expmin) { // value should be >= 0.5 * 2^expmin
324 if (exponent < expmin) { // value should be >= 0.5 * 2^expmin
321 exponent = expmin;
325 exponent = expmin;
322 significand = 0.5; // min value that can be recorded
326 significand = 0.5; // min value that can be recorded
323 }
327 }
324 if (exponent > expmax) { // value should be < 0.5 * 2^(expmax+1)
328 if (exponent > expmax) { // value should be < 0.5 * 2^(expmax+1)
325 exponent = expmax;
329 exponent = expmax;
326 significand = 1.0; // max value that can be recorded
330 significand = 1.0; // max value that can be recorded
327 }
331 }
328 if (significand == 0) { // in that case exponent == 0 too
332 if (significand == 0) { // in that case exponent == 0 too
329 exponent = expmin;
333 exponent = expmin;
330 significand = 0.5; // min value that can be recorded
334 significand = 0.5; // min value that can be recorded
331 }
335 }
332
336
333 lfr_bp1[i*NB_BYTES_BP1+8] = (uint8_t) ((significand*2-1)*255 + 0.5); // Shift and cast into a 8-bit uint8_t with rounding
337 lfr_bp1[i*NB_BYTES_BP1+8] = (uint8_t) ((significand*2-1)*255 + 0.5); // Shift and cast into a 8-bit uint8_t with rounding
334 // where all bits are used (0, ..., 255)
338 // where all bits are used (0, ..., 255)
335 tmp_uint8 = (uint8_t) (exponent-expmin); // Shift and cast into a 8-bit uint8_t where
339 tmp_uint8 = (uint8_t) (exponent-expmin); // Shift and cast into a 8-bit uint8_t where
336 // just the first nbitexp bits are used (0, ..., 2^nbitexp-1)
340 // just the first nbitexp bits are used (0, ..., 2^nbitexp-1)
337 #ifdef DEBUG_TCH
341 #ifdef DEBUG_TCH
338 printf("|ReaSX| : %16.8e\n",e_cross_b_re);
342 printf("|ReaSX| : %16.8e\n",e_cross_b_re);
339 printf("significand : %16.8e\n",significand);
343 printf("significand : %16.8e\n",significand);
340 printf("exponent : %d\n" ,exponent);
344 printf("exponent : %d\n" ,exponent);
341 printf("tmp_uint8 for ReaSX exponent : %d\n",tmp_uint8);
345 printf("tmp_uint8 for ReaSX exponent : %d\n",tmp_uint8);
342 #endif
346 #endif
343 lfr_bp1[i*NB_BYTES_BP1+7] = lfr_bp1[i*NB_BYTES_BP1+7] | tmp_uint8; // Record these nbitexp bits in the nbitexp first bits
347 lfr_bp1[i*NB_BYTES_BP1+7] = lfr_bp1[i*NB_BYTES_BP1+7] | tmp_uint8; // Record these nbitexp bits in the nbitexp first bits
344 // (from the right to the left) of lfr_bp1[i*NB_BYTES_BP1+7]
348 // (from the right to the left) of lfr_bp1[i*NB_BYTES_BP1+7]
345 #ifdef DEBUG_TCH
349 #ifdef DEBUG_TCH
346 printf("lfr_bp1[i*NB_BYTES_BP1+7] for ReaSX sign + RealSX exponent : %u\n",lfr_bp1[i*NB_BYTES_BP1+7]);
350 printf("lfr_bp1[i*NB_BYTES_BP1+7] for ReaSX sign + RealSX exponent : %u\n",lfr_bp1[i*NB_BYTES_BP1+7]);
347 printf("lfr_bp1[i*NB_BYTES_BP1+8] for ReaSX significand : %u\n",lfr_bp1[i*NB_BYTES_BP1+8]);
351 printf("lfr_bp1[i*NB_BYTES_BP1+8] for ReaSX significand : %u\n",lfr_bp1[i*NB_BYTES_BP1+8]);
348 printf("ImaSX : %16.8e\n",e_cross_b_im);
352 printf("ImaSX : %16.8e\n",e_cross_b_im);
349 #endif
353 #endif
350 pt_uint8 = (uint8_t*) &e_cross_b_im; // Affect an uint8_t pointer with the adress of e_cross_b_im
354 pt_uint8 = (uint8_t*) &e_cross_b_im; // Affect an uint8_t pointer with the adress of e_cross_b_im
351 #ifdef LSB_FIRST_TCH
355 #ifdef LSB_FIRST_TCH
352 pt_uint8[3] = pt_uint8[3] & 0x7f; // Make e_cross_b_im be positive in any case: |ImaSX| (32-bit float, sign bit in the 4th octet:PC convention)
356 pt_uint8[3] = pt_uint8[3] & 0x7f; // Make e_cross_b_im be positive in any case: |ImaSX| (32-bit float, sign bit in the 4th octet:PC convention)
353 #endif
357 #endif
354 #ifdef MSB_FIRST_TCH
358 #ifdef MSB_FIRST_TCH
355 pt_uint8[0] = pt_uint8[0] & 0x7f; // Make e_cross_b_im be positive in any case: |ImaSX| (32-bit float, sign bit in the 1th octet:SPARC convention)
359 pt_uint8[0] = pt_uint8[0] & 0x7f; // Make e_cross_b_im be positive in any case: |ImaSX| (32-bit float, sign bit in the 1th octet:SPARC convention)
356 #endif
360 #endif
357 tmp_uint8 = (e_cross_b_im > e_cross_b_re) ? 0x40 : 0x00; // Determine the sector argument of SX. If |Im| > |Re| affect
361 tmp_uint8 = (e_cross_b_im > e_cross_b_re) ? 0x40 : 0x00; // Determine the sector argument of SX. If |Im| > |Re| affect
358 // an unsigned 8-bit char with 01000000; otherwise with null.
362 // an unsigned 8-bit char with 01000000; otherwise with null.
359 lfr_bp1[i*NB_BYTES_BP1+7] = lfr_bp1[i*NB_BYTES_BP1+7] | tmp_uint8; // Record it as a sign bit at the 7th bit position (from the right
363 lfr_bp1[i*NB_BYTES_BP1+7] = lfr_bp1[i*NB_BYTES_BP1+7] | tmp_uint8; // Record it as a sign bit at the 7th bit position (from the right
360 // to the left) of lfr_bp1[i*NB_BYTES_BP1+7], by simple logical addition.
364 // to the left) of lfr_bp1[i*NB_BYTES_BP1+7], by simple logical addition.
361 #ifdef DEBUG_TCH
365 #ifdef DEBUG_TCH
362 printf("|ImaSX| : %16.8e\n",e_cross_b_im);
366 printf("|ImaSX| : %16.8e\n",e_cross_b_im);
363 printf("ArgSX sign : %u\n",tmp_uint8);
367 printf("ArgSX sign : %u\n",tmp_uint8);
364 printf("lfr_bp1[i*NB_BYTES_BP1+7] for ReaSX & ArgSX signs + ReaSX exponent : %u\n",lfr_bp1[i*NB_BYTES_BP1+7]);
368 printf("lfr_bp1[i*NB_BYTES_BP1+7] for ReaSX & ArgSX signs + ReaSX exponent : %u\n",lfr_bp1[i*NB_BYTES_BP1+7]);
365 #endif
369 #endif
366 //======================================================================
370 //======================================================================
367 // BP1 phase velocity estimator == PA_LFR_SC_BP1_VPHI_F0 == 16 bits
371 // BP1 phase velocity estimator == PA_LFR_SC_BP1_VPHI_F0 == 16 bits
368 // = 1 sign bit + 1 argument bit (two sectors)
372 // = 1 sign bit + 1 argument bit (two sectors)
369 // + 6 bits (exponent) + 8 bits (significand)
373 // + 6 bits (exponent) + 8 bits (significand)
370 ny = sin(alpha_M)*NVEC_V1 + cos(alpha_M)*NVEC_V2;
374 ny = sin(alpha_M)*NVEC_V1 + cos(alpha_M)*NVEC_V2;
371 nz = NVEC_V0;
375 nz = NVEC_V0;
372 bx_bx_star = cos(alpha_M)*cos(alpha_M)*compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+9] // S22 Re
376 bx_bx_star = cos(alpha_M)*cos(alpha_M)*compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+9] // S22 Re
373 + sin(alpha_M)*sin(alpha_M)*compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+16] // S33 Re
377 + sin(alpha_M)*sin(alpha_M)*compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+16] // S33 Re
374 - 2*sin(alpha_M)*cos(alpha_M)*compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+10]; // S23 Re
378 - 2*sin(alpha_M)*cos(alpha_M)*compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+10]; // S23 Re
375
379
376 n_cross_e_scal_b_re = ny * (compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+12]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K24_NY_RE] //S24 Re
380 n_cross_e_scal_b_re = ny * (compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+12]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K24_NY_RE] //S24 Re
377 +compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+14]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K25_NY_RE] //S25 Re
381 +compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+14]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K25_NY_RE] //S25 Re
378 +compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+17]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K34_NY_RE] //S34 Re
382 +compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+17]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K34_NY_RE] //S34 Re
379 +compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+19]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K35_NY_RE] //S35 Re
383 +compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+19]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K35_NY_RE] //S35 Re
380 +compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+13]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K24_NY_IM] //S24 Im
384 +compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+13]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K24_NY_IM] //S24 Im
381 +compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+15]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K25_NY_IM] //S25 Im
385 +compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+15]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K25_NY_IM] //S25 Im
382 +compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+18]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K34_NY_IM] //S34 Im
386 +compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+18]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K34_NY_IM] //S34 Im
383 +compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+20]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K35_NY_IM]) //S35 Im
387 +compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+20]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K35_NY_IM]) //S35 Im
384 + nz * (compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+12]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K24_NZ_RE] //S24 Re
388 + nz * (compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+12]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K24_NZ_RE] //S24 Re
385 +compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+14]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K25_NZ_RE] //S25 Re
389 +compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+14]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K25_NZ_RE] //S25 Re
386 +compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+17]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K34_NZ_RE] //S34 Re
390 +compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+17]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K34_NZ_RE] //S34 Re
387 +compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+19]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K35_NZ_RE] //S35 Re
391 +compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+19]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K35_NZ_RE] //S35 Re
388 +compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+13]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K24_NZ_IM] //S24 Im
392 +compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+13]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K24_NZ_IM] //S24 Im
389 +compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+15]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K25_NZ_IM] //S25 Im
393 +compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+15]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K25_NZ_IM] //S25 Im
390 +compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+18]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K34_NZ_IM] //S34 Im
394 +compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+18]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K34_NZ_IM] //S34 Im
391 +compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+20]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K35_NZ_IM]);//S35 Im
395 +compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+20]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K35_NZ_IM]);//S35 Im
392 // Im(S_ji) = -Im(S_ij)
396 // Im(S_ji) = -Im(S_ij)
393 // k_ji = k_ij
397 // k_ji = k_ij
394 n_cross_e_scal_b_im = ny * (compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+12]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K24_NY_IM] //S24 Re
398 n_cross_e_scal_b_im = ny * (compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+12]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K24_NY_IM] //S24 Re
395 +compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+14]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K25_NY_IM] //S25 Re
399 +compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+14]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K25_NY_IM] //S25 Re
396 +compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+17]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K34_NY_IM] //S34 Re
400 +compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+17]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K34_NY_IM] //S34 Re
397 +compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+19]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K35_NY_IM] //S35 Re
401 +compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+19]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K35_NY_IM] //S35 Re
398 -compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+13]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K24_NY_RE] //S24 Im
402 -compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+13]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K24_NY_RE] //S24 Im
399 -compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+15]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K25_NY_RE] //S25 Im
403 -compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+15]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K25_NY_RE] //S25 Im
400 -compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+18]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K34_NY_RE] //S34 Im
404 -compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+18]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K34_NY_RE] //S34 Im
401 -compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+20]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K35_NY_RE]) //S35 Im
405 -compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+20]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K35_NY_RE]) //S35 Im
402 + nz * (compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+12]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K24_NZ_IM] //S24 Re
406 + nz * (compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+12]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K24_NZ_IM] //S24 Re
403 +compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+14]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K25_NZ_IM] //S25 Re
407 +compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+14]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K25_NZ_IM] //S25 Re
404 +compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+17]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K34_NZ_IM] //S34 Re
408 +compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+17]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K34_NZ_IM] //S34 Re
405 +compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+19]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K35_NZ_IM] //S35 Re
409 +compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+19]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K35_NZ_IM] //S35 Re
406 -compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+13]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K24_NZ_RE] //S24 Im
410 -compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+13]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K24_NZ_RE] //S24 Im
407 -compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+15]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K25_NZ_RE] //S25 Im
411 -compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+15]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K25_NZ_RE] //S25 Im
408 -compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+18]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K34_NZ_RE] //S34 Im
412 -compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+18]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K34_NZ_RE] //S34 Im
409 -compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+20]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K35_NZ_RE]);//S35 Im
413 -compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+20]*k_coeff_intercalib[i*NB_K_COEFF_PER_BIN+K35_NZ_RE]);//S35 Im
410 #ifdef DEBUG_TCH
414 #ifdef DEBUG_TCH
411 printf("n_cross_e_scal_b_re : %16.8e\n",n_cross_e_scal_b_re);
415 printf("n_cross_e_scal_b_re : %16.8e\n",n_cross_e_scal_b_re);
412 printf("n_cross_e_scal_b_im : %16.8e\n",n_cross_e_scal_b_im);
416 printf("n_cross_e_scal_b_im : %16.8e\n",n_cross_e_scal_b_im);
413 #endif
417 #endif
414 // vphi = n_cross_e_scal_b_re / bx_bx_star => sign(VPHI) = sign(n_cross_e_scal_b_re)
418 // vphi = n_cross_e_scal_b_re / bx_bx_star => sign(VPHI) = sign(n_cross_e_scal_b_re)
415 pt_uint8 = (uint8_t*) &n_cross_e_scal_b_re; // Affect an uint8_t pointer with the adress of n_cross_e_scal_b_re
419 pt_uint8 = (uint8_t*) &n_cross_e_scal_b_re; // Affect an uint8_t pointer with the adress of n_cross_e_scal_b_re
416 #ifdef LSB_FIRST_TCH
420 #ifdef LSB_FIRST_TCH
417 lfr_bp1[i*NB_BYTES_BP1+9] = lfr_bp1[i*NB_BYTES_BP1+9] | (pt_uint8[3] & 0x80); // Extract its sign bit (32-bit float, sign bit in the 4th octet:PC convention)
421 lfr_bp1[i*NB_BYTES_BP1+9] = lfr_bp1[i*NB_BYTES_BP1+9] | (pt_uint8[3] & 0x80); // Extract its sign bit (32-bit float, sign bit in the 4th octet:PC convention)
418 // Record it at the 8th bit position (from the right to the left)
422 // Record it at the 8th bit position (from the right to the left)
419 // of lfr_bp1[i*NB_BYTES_BP1+9]
423 // of lfr_bp1[i*NB_BYTES_BP1+9]
420 pt_uint8[3] = (pt_uint8[3] & 0x7f); // Make n_cross_e_scal_b_re be positive in any case: |n_cross_e_scal_b_re|
424 pt_uint8[3] = (pt_uint8[3] & 0x7f); // Make n_cross_e_scal_b_re be positive in any case: |n_cross_e_scal_b_re|
421 #endif
425 #endif
422 #ifdef MSB_FIRST_TCH
426 #ifdef MSB_FIRST_TCH
423 lfr_bp1[i*NB_BYTES_BP1+9] = lfr_bp1[i*NB_BYTES_BP1+9] | (pt_uint8[0] & 0x80); // Extract its sign bit (32-bit float, sign bit in the 1th octet:SPARC convention)
427 lfr_bp1[i*NB_BYTES_BP1+9] = lfr_bp1[i*NB_BYTES_BP1+9] | (pt_uint8[0] & 0x80); // Extract its sign bit (32-bit float, sign bit in the 1th octet:SPARC convention)
424 // Record it at the 8th bit position (from the right to the left)
428 // Record it at the 8th bit position (from the right to the left)
425 // of lfr_bp1[i*NB_BYTES_BP1+9]
429 // of lfr_bp1[i*NB_BYTES_BP1+9]
426 pt_uint8[0] = (pt_uint8[0] & 0x7f); // Make n_cross_e_scal_b_re be positive in any case: |n_cross_e_scal_b_re|
430 pt_uint8[0] = (pt_uint8[0] & 0x7f); // Make n_cross_e_scal_b_re be positive in any case: |n_cross_e_scal_b_re|
427 #endif
431 #endif
428 if (bx_bx_star != 0.) { // no division by 0.
432 if (bx_bx_star != 0.) { // no division by 0.
429 vphi = n_cross_e_scal_b_re / bx_bx_star; // Compute |VPHI|
433 vphi = n_cross_e_scal_b_re / bx_bx_star; // Compute |VPHI|
430 }
434 }
431 else
435 else
432 {
436 {
433 vphi = 1.e+20; // Put a huge value
437 vphi = 1.e+20; // Put a huge value
434 }
438 }
435 significand = frexpf(vphi, &exponent); // 0.5 <= significand < 1
439 significand = frexpf(vphi, &exponent); // 0.5 <= significand < 1
436 // vphi = significand * 2^exponent
440 // vphi = significand * 2^exponent
437 if (exponent < expmin) { // value should be >= 0.5 * 2^expmin
441 if (exponent < expmin) { // value should be >= 0.5 * 2^expmin
438 exponent = expmin;
442 exponent = expmin;
439 significand = 0.5; // min value that can be recorded
443 significand = 0.5; // min value that can be recorded
440 }
444 }
441 if (exponent > expmax) { // value should be < 0.5 * 2^(expmax+1)
445 if (exponent > expmax) { // value should be < 0.5 * 2^(expmax+1)
442 exponent = expmax;
446 exponent = expmax;
443 significand = 1.0; // max value that can be recorded
447 significand = 1.0; // max value that can be recorded
444 }
448 }
445 if (significand == 0) {// in that case exponent == 0 too
449 if (significand == 0) {// in that case exponent == 0 too
446 exponent = expmin;
450 exponent = expmin;
447 significand = 0.5; // min value that can be recorded
451 significand = 0.5; // min value that can be recorded
448 }
452 }
449
453
450 lfr_bp1[i*NB_BYTES_BP1+10] = (uint8_t) ((significand*2-1)*255 + 0.5); // Shift and cast into a 8-bit uint8_t with rounding
454 lfr_bp1[i*NB_BYTES_BP1+10] = (uint8_t) ((significand*2-1)*255 + 0.5); // Shift and cast into a 8-bit uint8_t with rounding
451 // where all the bits are used (0, ..., 255)
455 // where all the bits are used (0, ..., 255)
452 tmp_uint8 = (uint8_t) (exponent-expmin); // Shift and cast into a 8-bit uint8_t where
456 tmp_uint8 = (uint8_t) (exponent-expmin); // Shift and cast into a 8-bit uint8_t where
453 // just the first nbitexp bits are used (0, ..., 2^nbitexp-1)
457 // just the first nbitexp bits are used (0, ..., 2^nbitexp-1)
454 #ifdef DEBUG_TCH
458 #ifdef DEBUG_TCH
455 printf("|VPHI| : %16.8e\n",vphi);
459 printf("|VPHI| : %16.8e\n",vphi);
456 printf("significand : %16.8e\n",significand);
460 printf("significand : %16.8e\n",significand);
457 printf("exponent : %d\n" ,exponent);
461 printf("exponent : %d\n" ,exponent);
458 printf("tmp_uint8 for VPHI exponent : %d\n",tmp_uint8);
462 printf("tmp_uint8 for VPHI exponent : %d\n",tmp_uint8);
459 #endif
463 #endif
460 lfr_bp1[i*NB_BYTES_BP1+9] = lfr_bp1[i*NB_BYTES_BP1+9] | tmp_uint8; // Record these nbitexp bits in the nbitexp first bits
464 lfr_bp1[i*NB_BYTES_BP1+9] = lfr_bp1[i*NB_BYTES_BP1+9] | tmp_uint8; // Record these nbitexp bits in the nbitexp first bits
461 // (from the right to the left) of lfr_bp1[i*NB_BYTES_BP1+9]
465 // (from the right to the left) of lfr_bp1[i*NB_BYTES_BP1+9]
462 #ifdef DEBUG_TCH
466 #ifdef DEBUG_TCH
463 printf("lfr_bp1[i*NB_BYTES_BP1+9] for VPHI sign + VPHI exponent : %u\n",lfr_bp1[i*NB_BYTES_BP1+9]);
467 printf("lfr_bp1[i*NB_BYTES_BP1+9] for VPHI sign + VPHI exponent : %u\n",lfr_bp1[i*NB_BYTES_BP1+9]);
464 printf("lfr_bp1[i*NB_BYTES_BP1+10] for VPHI significand : %u\n",lfr_bp1[i*NB_BYTES_BP1+10]);
468 printf("lfr_bp1[i*NB_BYTES_BP1+10] for VPHI significand : %u\n",lfr_bp1[i*NB_BYTES_BP1+10]);
465 #endif
469 #endif
466 pt_uint8 = (uint8_t*) &n_cross_e_scal_b_im; // Affect an uint8_t pointer with the adress of n_cross_e_scal_b_im
470 pt_uint8 = (uint8_t*) &n_cross_e_scal_b_im; // Affect an uint8_t pointer with the adress of n_cross_e_scal_b_im
467 #ifdef LSB_FIRST_TCH
471 #ifdef LSB_FIRST_TCH
468 pt_uint8[3] = pt_uint8[3] & 0x7f; // Make n_cross_e_scal_b_im be positive in any case: |ImaNEBX| (32-bit float, sign bit in the 4th octet:PC convention)
472 pt_uint8[3] = pt_uint8[3] & 0x7f; // Make n_cross_e_scal_b_im be positive in any case: |ImaNEBX| (32-bit float, sign bit in the 4th octet:PC convention)
469 #endif
473 #endif
470 #ifdef MSB_FIRST_TCH
474 #ifdef MSB_FIRST_TCH
471 pt_uint8[0] = pt_uint8[0] & 0x7f; // Make n_cross_e_scal_b_im be positive in any case: |ImaNEBX| (32-bit float, sign bit in the 1th octet:SPARC convention)
475 pt_uint8[0] = pt_uint8[0] & 0x7f; // Make n_cross_e_scal_b_im be positive in any case: |ImaNEBX| (32-bit float, sign bit in the 1th octet:SPARC convention)
472 #endif
476 #endif
473 tmp_uint8 = (n_cross_e_scal_b_im > n_cross_e_scal_b_re) ? 0x40 : 0x00; // Determine the sector argument of NEBX. If |Im| > |Re| affect
477 tmp_uint8 = (n_cross_e_scal_b_im > n_cross_e_scal_b_re) ? 0x40 : 0x00; // Determine the sector argument of NEBX. If |Im| > |Re| affect
474 // an unsigned 8-bit char with 01000000; otherwise with null.
478 // an unsigned 8-bit char with 01000000; otherwise with null.
475 lfr_bp1[i*NB_BYTES_BP1+9] = lfr_bp1[i*NB_BYTES_BP1+9] | tmp_uint8; // Record it as a sign bit at the 7th bit position (from the right
479 lfr_bp1[i*NB_BYTES_BP1+9] = lfr_bp1[i*NB_BYTES_BP1+9] | tmp_uint8; // Record it as a sign bit at the 7th bit position (from the right
476 // to the left) of lfr_bp1[i*NB_BYTES_BP1+9], by simple logical addition.
480 // to the left) of lfr_bp1[i*NB_BYTES_BP1+9], by simple logical addition.
477 #ifdef DEBUG_TCH
481 #ifdef DEBUG_TCH
478 printf("|n_cross_e_scal_b_im| : %16.8e\n",n_cross_e_scal_b_im);
482 printf("|n_cross_e_scal_b_im| : %16.8e\n",n_cross_e_scal_b_im);
479 printf("|n_cross_e_scal_b_im|/bx_bx_star : %16.8e\n",n_cross_e_scal_b_im/bx_bx_star);
483 printf("|n_cross_e_scal_b_im|/bx_bx_star : %16.8e\n",n_cross_e_scal_b_im/bx_bx_star);
480 printf("ArgNEBX sign : %u\n",tmp_uint8);
484 printf("ArgNEBX sign : %u\n",tmp_uint8);
481 printf("lfr_bp1[i*NB_BYTES_BP1+9] for VPHI & ArgNEBX signs + VPHI exponent : %u\n",lfr_bp1[i*NB_BYTES_BP1+9]);
485 printf("lfr_bp1[i*NB_BYTES_BP1+9] for VPHI & ArgNEBX signs + VPHI exponent : %u\n",lfr_bp1[i*NB_BYTES_BP1+9]);
482 #endif
486 #endif
483 }
487 }
484 }
488 }
485
489
486 void BP2_set( float * compressed_spec_mat, uint8_t nb_bins_compressed_spec_mat, uint8_t * lfr_bp2 )
490 void BP2_set( float * compressed_spec_mat, uint8_t nb_bins_compressed_spec_mat, uint8_t * lfr_bp2 )
487 {
491 {
488 float cross_re; // 32-bit floating point
492 float cross_re; // 32-bit floating point
489 float cross_im;
493 float cross_im;
490 float aux;
494 float aux;
491 float significand;
495 float significand;
492 int exponent; // 32-bit signed integer
496 int exponent; // 32-bit signed integer
493 uint8_t nbitexp; // 8-bit unsigned integer
497 uint8_t nbitexp; // 8-bit unsigned integer
494 uint8_t nbitsig;
498 uint8_t nbitsig;
495 uint8_t *pt_uint8; // pointer on unsigned 8-bit integer
499 uint8_t *pt_uint8; // pointer on unsigned 8-bit integer
496 int8_t expmin; // 8-bit signed integer
500 int8_t expmin; // 8-bit signed integer
497 int8_t expmax;
501 int8_t expmax;
498 uint16_t rangesig; // 16-bit unsigned integer
502 uint16_t rangesig; // 16-bit unsigned integer
499 uint16_t autocor;
503 uint16_t autocor;
500 uint16_t exp;
504 uint16_t exp;
501 uint16_t tmp_uint16;
505 uint16_t tmp_uint16;
502 uint16_t i;
506 uint16_t i;
503
507
504 #ifdef DEBUG_TCH
508 #ifdef DEBUG_TCH
505 printf("BP2 : \n");
509 printf("BP2 : \n");
506 printf("Number of bins: %d\n", nb_bins_compressed_spec_mat);
510 printf("Number of bins: %d\n", nb_bins_compressed_spec_mat);
507 #endif
511 #endif
508
512
509 // For floating point data to be recorded on 16-bit words :
513 // For floating point data to be recorded on 16-bit words :
510 nbitexp = 6; // number of bits for the exponent
514 nbitexp = 6; // number of bits for the exponent
511 nbitsig = 16 - nbitexp; // number of bits for the significand
515 nbitsig = 16 - nbitexp; // number of bits for the significand
512 rangesig = (1 << nbitsig)-1; // == 2^nbitsig - 1
516 rangesig = (1 << nbitsig)-1; // == 2^nbitsig - 1
513 expmax = 32 + 5;
517 expmax = 32 + 5;
514 expmin = expmax - (1 << nbitexp) + 1;
518 expmin = expmax - (1 << nbitexp) + 1;
515
519
516 #ifdef DEBUG_TCH
520 #ifdef DEBUG_TCH
517
521
518 printf("nbitexp : %d, expmax : %d, expmin : %d\n", nbitexp, expmax, expmin);
522 printf("nbitexp : %d, expmax : %d, expmin : %d\n", nbitexp, expmax, expmin);
519 printf("nbitsig : %d, rangesig : %d\n", nbitsig, rangesig);
523 printf("nbitsig : %d, rangesig : %d\n", nbitsig, rangesig);
520 #endif
524 #endif
521
525
522 for(i = 0; i<nb_bins_compressed_spec_mat; i++){
526 for(i = 0; i<nb_bins_compressed_spec_mat; i++){
523 //==============================================
527 //==============================================
524 // BP2 normalized cross correlations == PA_LFR_SC_BP2_CROSS_F0 == 10 * (8+8) bits
528 // BP2 normalized cross correlations == PA_LFR_SC_BP2_CROSS_F0 == 10 * (8+8) bits
525 // == PA_LFR_SC_BP2_CROSS_RE_0_F0 == 8 bits
529 // == PA_LFR_SC_BP2_CROSS_RE_0_F0 == 8 bits
526 // == PA_LFR_SC_BP2_CROSS_IM_0_F0 == 8 bits
530 // == PA_LFR_SC_BP2_CROSS_IM_0_F0 == 8 bits
527 // == PA_LFR_SC_BP2_CROSS_RE_1_F0 == 8 bits
531 // == PA_LFR_SC_BP2_CROSS_RE_1_F0 == 8 bits
528 // == PA_LFR_SC_BP2_CROSS_IM_1_F0 == 8 bits
532 // == PA_LFR_SC_BP2_CROSS_IM_1_F0 == 8 bits
529 // == PA_LFR_SC_BP2_CROSS_RE_2_F0 == 8 bits
533 // == PA_LFR_SC_BP2_CROSS_RE_2_F0 == 8 bits
530 // == PA_LFR_SC_BP2_CROSS_IM_2_F0 == 8 bits
534 // == PA_LFR_SC_BP2_CROSS_IM_2_F0 == 8 bits
531 // == PA_LFR_SC_BP2_CROSS_RE_3_F0 == 8 bits
535 // == PA_LFR_SC_BP2_CROSS_RE_3_F0 == 8 bits
532 // == PA_LFR_SC_BP2_CROSS_IM_3_F0 == 8 bits
536 // == PA_LFR_SC_BP2_CROSS_IM_3_F0 == 8 bits
533 // == PA_LFR_SC_BP2_CROSS_RE_4_F0 == 8 bits
537 // == PA_LFR_SC_BP2_CROSS_RE_4_F0 == 8 bits
534 // == PA_LFR_SC_BP2_CROSS_IM_4_F0 == 8 bits
538 // == PA_LFR_SC_BP2_CROSS_IM_4_F0 == 8 bits
535 // == PA_LFR_SC_BP2_CROSS_RE_5_F0 == 8 bits
539 // == PA_LFR_SC_BP2_CROSS_RE_5_F0 == 8 bits
536 // == PA_LFR_SC_BP2_CROSS_IM_5_F0 == 8 bits
540 // == PA_LFR_SC_BP2_CROSS_IM_5_F0 == 8 bits
537 // == PA_LFR_SC_BP2_CROSS_RE_6_F0 == 8 bits
541 // == PA_LFR_SC_BP2_CROSS_RE_6_F0 == 8 bits
538 // == PA_LFR_SC_BP2_CROSS_IM_6_F0 == 8 bits
542 // == PA_LFR_SC_BP2_CROSS_IM_6_F0 == 8 bits
539 // == PA_LFR_SC_BP2_CROSS_RE_7_F0 == 8 bits
543 // == PA_LFR_SC_BP2_CROSS_RE_7_F0 == 8 bits
540 // == PA_LFR_SC_BP2_CROSS_IM_7_F0 == 8 bits
544 // == PA_LFR_SC_BP2_CROSS_IM_7_F0 == 8 bits
541 // == PA_LFR_SC_BP2_CROSS_RE_8_F0 == 8 bits
545 // == PA_LFR_SC_BP2_CROSS_RE_8_F0 == 8 bits
542 // == PA_LFR_SC_BP2_CROSS_IM_8_F0 == 8 bits
546 // == PA_LFR_SC_BP2_CROSS_IM_8_F0 == 8 bits
543 // == PA_LFR_SC_BP2_CROSS_RE_9_F0 == 8 bits
547 // == PA_LFR_SC_BP2_CROSS_RE_9_F0 == 8 bits
544 // == PA_LFR_SC_BP2_CROSS_IM_9_F0 == 8 bits
548 // == PA_LFR_SC_BP2_CROSS_IM_9_F0 == 8 bits
545 // S12
549 // S12
546 aux = sqrt(compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX]*compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+9]);
550 aux = sqrt(compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX]*compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+9]);
547 if (aux != 0.) { // no division by 0.
551 if (aux != 0.) { // no division by 0.
548 cross_re = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+1] / aux;
552 cross_re = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+1] / aux;
549 cross_im = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+2] / aux;
553 cross_im = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+2] / aux;
550 }
554 }
551 else
555 else
552 {
556 {
553 cross_re = 0.;
557 cross_re = 0.;
554 cross_im = 0.;
558 cross_im = 0.;
555 }
559 }
556 lfr_bp2[i*NB_BYTES_BP2+10] = (uint8_t) (cross_re*127.5 + 128); // Shift and cast into a 8-bit uint8_t (0, ..., 255) with rounding
560 lfr_bp2[i*NB_BYTES_BP2+10] = (uint8_t) (cross_re*127.5 + 128); // Shift and cast into a 8-bit uint8_t (0, ..., 255) with rounding
557 lfr_bp2[i*NB_BYTES_BP2+20] = (uint8_t) (cross_im*127.5 + 128); // Shift and cast into a 8-bit uint8_t (0, ..., 255) with rounding
561 lfr_bp2[i*NB_BYTES_BP2+20] = (uint8_t) (cross_im*127.5 + 128); // Shift and cast into a 8-bit uint8_t (0, ..., 255) with rounding
558 #ifdef DEBUG_TCH
562 #ifdef DEBUG_TCH
559 printf("\nBin number: %d\n", i);
563 printf("\nBin number: %d\n", i);
560 printf("lfr_bp2[i*NB_BYTES_BP2+10] for cross12_re (%16.8e) : %.3u\n",cross_re, lfr_bp2[i*NB_BYTES_BP2+10]);
564 printf("lfr_bp2[i*NB_BYTES_BP2+10] for cross12_re (%16.8e) : %.3u\n",cross_re, lfr_bp2[i*NB_BYTES_BP2+10]);
561 printf("lfr_bp2[i*NB_BYTES_BP2+20] for cross12_im (%16.8e) : %.3u\n",cross_im, lfr_bp2[i*NB_BYTES_BP2+20]);
565 printf("lfr_bp2[i*NB_BYTES_BP2+20] for cross12_im (%16.8e) : %.3u\n",cross_im, lfr_bp2[i*NB_BYTES_BP2+20]);
562 #endif
566 #endif
563 // S13
567 // S13
564 aux = sqrt(compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX]*compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+16]);
568 aux = sqrt(compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX]*compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+16]);
565 if (aux != 0.) { // no division by 0.
569 if (aux != 0.) { // no division by 0.
566 cross_re = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+3] / aux;
570 cross_re = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+3] / aux;
567 cross_im = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+4] / aux;
571 cross_im = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+4] / aux;
568 }
572 }
569 else
573 else
570 {
574 {
571 cross_re = 0.;
575 cross_re = 0.;
572 cross_im = 0.;
576 cross_im = 0.;
573 }
577 }
574 lfr_bp2[i*NB_BYTES_BP2+11] = (uint8_t) (cross_re*127.5 + 128); // Shift and cast into a 8-bit uint8_t (0, ..., 255) with rounding
578 lfr_bp2[i*NB_BYTES_BP2+11] = (uint8_t) (cross_re*127.5 + 128); // Shift and cast into a 8-bit uint8_t (0, ..., 255) with rounding
575 lfr_bp2[i*NB_BYTES_BP2+21] = (uint8_t) (cross_im*127.5 + 128); // Shift and cast into a 8-bit uint8_t (0, ..., 255) with rounding
579 lfr_bp2[i*NB_BYTES_BP2+21] = (uint8_t) (cross_im*127.5 + 128); // Shift and cast into a 8-bit uint8_t (0, ..., 255) with rounding
576 #ifdef DEBUG_TCH
580 #ifdef DEBUG_TCH
577 printf("lfr_bp2[i*NB_BYTES_BP2+11] for cross13_re (%16.8e) : %.3u\n",cross_re, lfr_bp2[i*NB_BYTES_BP2+11]);
581 printf("lfr_bp2[i*NB_BYTES_BP2+11] for cross13_re (%16.8e) : %.3u\n",cross_re, lfr_bp2[i*NB_BYTES_BP2+11]);
578 printf("lfr_bp2[i*NB_BYTES_BP2+21] for cross13_im (%16.8e) : %.3u\n",cross_im, lfr_bp2[i*NB_BYTES_BP2+21]);
582 printf("lfr_bp2[i*NB_BYTES_BP2+21] for cross13_im (%16.8e) : %.3u\n",cross_im, lfr_bp2[i*NB_BYTES_BP2+21]);
579 #endif
583 #endif
580 // S14
584 // S14
581 aux = sqrt(compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX]*compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+21]);
585 aux = sqrt(compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX]*compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+21]);
582 if (aux != 0.) { // no division by 0.
586 if (aux != 0.) { // no division by 0.
583 cross_re = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+5] / aux;
587 cross_re = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+5] / aux;
584 cross_im = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+6] / aux;
588 cross_im = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+6] / aux;
585 }
589 }
586 else
590 else
587 {
591 {
588 cross_re = 0.;
592 cross_re = 0.;
589 cross_im = 0.;
593 cross_im = 0.;
590 }
594 }
591 lfr_bp2[i*NB_BYTES_BP2+12] = (uint8_t) (cross_re*127.5 + 128); // Shift and cast into a 8-bit uint8_t (0, ..., 255) with rounding
595 lfr_bp2[i*NB_BYTES_BP2+12] = (uint8_t) (cross_re*127.5 + 128); // Shift and cast into a 8-bit uint8_t (0, ..., 255) with rounding
592 lfr_bp2[i*NB_BYTES_BP2+22] = (uint8_t) (cross_im*127.5 + 128); // Shift and cast into a 8-bit uint8_t (0, ..., 255) with rounding
596 lfr_bp2[i*NB_BYTES_BP2+22] = (uint8_t) (cross_im*127.5 + 128); // Shift and cast into a 8-bit uint8_t (0, ..., 255) with rounding
593 #ifdef DEBUG_TCH
597 #ifdef DEBUG_TCH
594 printf("lfr_bp2[i*NB_BYTES_BP2+12] for cross14_re (%16.8e) : %.3u\n",cross_re, lfr_bp2[i*NB_BYTES_BP2+12]);
598 printf("lfr_bp2[i*NB_BYTES_BP2+12] for cross14_re (%16.8e) : %.3u\n",cross_re, lfr_bp2[i*NB_BYTES_BP2+12]);
595 printf("lfr_bp2[i*NB_BYTES_BP2+22] for cross14_im (%16.8e) : %.3u\n",cross_im, lfr_bp2[i*NB_BYTES_BP2+22]);
599 printf("lfr_bp2[i*NB_BYTES_BP2+22] for cross14_im (%16.8e) : %.3u\n",cross_im, lfr_bp2[i*NB_BYTES_BP2+22]);
596 #endif
600 #endif
597 // S15
601 // S15
598 aux = sqrt(compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX]*compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+24]);
602 aux = sqrt(compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX]*compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+24]);
599 if (aux != 0.) { // no division by 0.
603 if (aux != 0.) { // no division by 0.
600 cross_re = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+7] / aux;
604 cross_re = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+7] / aux;
601 cross_im = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+8] / aux;
605 cross_im = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+8] / aux;
602 }
606 }
603 else
607 else
604 {
608 {
605 cross_re = 0.;
609 cross_re = 0.;
606 cross_im = 0.;
610 cross_im = 0.;
607 }
611 }
608 lfr_bp2[i*NB_BYTES_BP2+13] = (uint8_t) (cross_re*127.5 + 128); // Shift and cast into a 8-bit uint8_t (0, ..., 255) with rounding
612 lfr_bp2[i*NB_BYTES_BP2+13] = (uint8_t) (cross_re*127.5 + 128); // Shift and cast into a 8-bit uint8_t (0, ..., 255) with rounding
609 lfr_bp2[i*NB_BYTES_BP2+23] = (uint8_t) (cross_im*127.5 + 128); // Shift and cast into a 8-bit uint8_t (0, ..., 255) with rounding
613 lfr_bp2[i*NB_BYTES_BP2+23] = (uint8_t) (cross_im*127.5 + 128); // Shift and cast into a 8-bit uint8_t (0, ..., 255) with rounding
610 #ifdef DEBUG_TCH
614 #ifdef DEBUG_TCH
611 printf("lfr_bp2[i*NB_BYTES_BP2+13] for cross15_re (%16.8e) : %.3u\n",cross_re, lfr_bp2[i*NB_BYTES_BP2+13]);
615 printf("lfr_bp2[i*NB_BYTES_BP2+13] for cross15_re (%16.8e) : %.3u\n",cross_re, lfr_bp2[i*NB_BYTES_BP2+13]);
612 printf("lfr_bp2[i*NB_BYTES_BP2+23] for cross15_im (%16.8e) : %.3u\n",cross_im, lfr_bp2[i*NB_BYTES_BP2+23]);
616 printf("lfr_bp2[i*NB_BYTES_BP2+23] for cross15_im (%16.8e) : %.3u\n",cross_im, lfr_bp2[i*NB_BYTES_BP2+23]);
613 #endif
617 #endif
614 // S23
618 // S23
615 aux = sqrt(compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+9]*compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+16]);
619 aux = sqrt(compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+9]*compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+16]);
616 if (aux != 0.) { // no division by 0.
620 if (aux != 0.) { // no division by 0.
617 cross_re = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+10] / aux;
621 cross_re = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+10] / aux;
618 cross_im = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+11] / aux;
622 cross_im = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+11] / aux;
619 }
623 }
620 else
624 else
621 {
625 {
622 cross_re = 0.;
626 cross_re = 0.;
623 cross_im = 0.;
627 cross_im = 0.;
624 }
628 }
625 lfr_bp2[i*NB_BYTES_BP2+14] = (uint8_t) (cross_re*127.5 + 128); // Shift and cast into a 8-bit uint8_t (0, ..., 255) with rounding
629 lfr_bp2[i*NB_BYTES_BP2+14] = (uint8_t) (cross_re*127.5 + 128); // Shift and cast into a 8-bit uint8_t (0, ..., 255) with rounding
626 lfr_bp2[i*NB_BYTES_BP2+24] = (uint8_t) (cross_im*127.5 + 128); // Shift and cast into a 8-bit uint8_t (0, ..., 255) with rounding
630 lfr_bp2[i*NB_BYTES_BP2+24] = (uint8_t) (cross_im*127.5 + 128); // Shift and cast into a 8-bit uint8_t (0, ..., 255) with rounding
627 #ifdef DEBUG_TCH
631 #ifdef DEBUG_TCH
628 printf("lfr_bp2[i*NB_BYTES_BP2+14] for cross23_re (%16.8e) : %.3u\n",cross_re, lfr_bp2[i*NB_BYTES_BP2+14]);
632 printf("lfr_bp2[i*NB_BYTES_BP2+14] for cross23_re (%16.8e) : %.3u\n",cross_re, lfr_bp2[i*NB_BYTES_BP2+14]);
629 printf("lfr_bp2[i*NB_BYTES_BP2+24] for cross23_im (%16.8e) : %.3u\n",cross_im, lfr_bp2[i*NB_BYTES_BP2+24]);
633 printf("lfr_bp2[i*NB_BYTES_BP2+24] for cross23_im (%16.8e) : %.3u\n",cross_im, lfr_bp2[i*NB_BYTES_BP2+24]);
630 #endif
634 #endif
631 // S24
635 // S24
632 aux = sqrt(compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+9]*compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+21]);
636 aux = sqrt(compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+9]*compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+21]);
633 if (aux != 0.) { // no division by 0.
637 if (aux != 0.) { // no division by 0.
634 cross_re = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+12] / aux;
638 cross_re = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+12] / aux;
635 cross_im = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+13] / aux;
639 cross_im = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+13] / aux;
636 }
640 }
637 else
641 else
638 {
642 {
639 cross_re = 0.;
643 cross_re = 0.;
640 cross_im = 0.;
644 cross_im = 0.;
641 }
645 }
642 lfr_bp2[i*NB_BYTES_BP2+15] = (uint8_t) (cross_re*127.5 + 128); // Shift and cast into a 8-bit uint8_t (0, ..., 255) with rounding
646 lfr_bp2[i*NB_BYTES_BP2+15] = (uint8_t) (cross_re*127.5 + 128); // Shift and cast into a 8-bit uint8_t (0, ..., 255) with rounding
643 lfr_bp2[i*NB_BYTES_BP2+25] = (uint8_t) (cross_im*127.5 + 128); // Shift and cast into a 8-bit uint8_t (0, ..., 255) with rounding
647 lfr_bp2[i*NB_BYTES_BP2+25] = (uint8_t) (cross_im*127.5 + 128); // Shift and cast into a 8-bit uint8_t (0, ..., 255) with rounding
644 #ifdef DEBUG_TCH
648 #ifdef DEBUG_TCH
645 printf("lfr_bp2[i*NB_BYTES_BP2+15] for cross24_re (%16.8e) : %.3u\n",cross_re, lfr_bp2[i*NB_BYTES_BP2+15]);
649 printf("lfr_bp2[i*NB_BYTES_BP2+15] for cross24_re (%16.8e) : %.3u\n",cross_re, lfr_bp2[i*NB_BYTES_BP2+15]);
646 printf("lfr_bp2[i*NB_BYTES_BP2+25] for cross24_im (%16.8e) : %.3u\n",cross_im, lfr_bp2[i*NB_BYTES_BP2+25]);
650 printf("lfr_bp2[i*NB_BYTES_BP2+25] for cross24_im (%16.8e) : %.3u\n",cross_im, lfr_bp2[i*NB_BYTES_BP2+25]);
647 #endif
651 #endif
648 // S25
652 // S25
649 aux = sqrt(compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+9]*compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+24]);
653 aux = sqrt(compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+9]*compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+24]);
650 if (aux != 0.) { // no division by 0.
654 if (aux != 0.) { // no division by 0.
651 cross_re = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+14] / aux;
655 cross_re = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+14] / aux;
652 cross_im = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+15] / aux;
656 cross_im = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+15] / aux;
653 }
657 }
654 else
658 else
655 {
659 {
656 cross_re = 0.;
660 cross_re = 0.;
657 cross_im = 0.;
661 cross_im = 0.;
658 }
662 }
659 lfr_bp2[i*NB_BYTES_BP2+16] = (uint8_t) (cross_re*127.5 + 128); // Shift and cast into a 8-bit uint8_t (0, ..., 255) with rounding
663 lfr_bp2[i*NB_BYTES_BP2+16] = (uint8_t) (cross_re*127.5 + 128); // Shift and cast into a 8-bit uint8_t (0, ..., 255) with rounding
660 lfr_bp2[i*NB_BYTES_BP2+26] = (uint8_t) (cross_im*127.5 + 128); // Shift and cast into a 8-bit uint8_t (0, ..., 255) with rounding
664 lfr_bp2[i*NB_BYTES_BP2+26] = (uint8_t) (cross_im*127.5 + 128); // Shift and cast into a 8-bit uint8_t (0, ..., 255) with rounding
661 #ifdef DEBUG_TCH
665 #ifdef DEBUG_TCH
662 printf("lfr_bp2[i*NB_BYTES_BP2+16] for cross25_re (%16.8e) : %.3u\n",cross_re, lfr_bp2[i*NB_BYTES_BP2+16]);
666 printf("lfr_bp2[i*NB_BYTES_BP2+16] for cross25_re (%16.8e) : %.3u\n",cross_re, lfr_bp2[i*NB_BYTES_BP2+16]);
663 printf("lfr_bp2[i*NB_BYTES_BP2+26] for cross25_im (%16.8e) : %.3u\n",cross_im, lfr_bp2[i*NB_BYTES_BP2+26]);
667 printf("lfr_bp2[i*NB_BYTES_BP2+26] for cross25_im (%16.8e) : %.3u\n",cross_im, lfr_bp2[i*NB_BYTES_BP2+26]);
664 #endif
668 #endif
665 // S34
669 // S34
666 aux = sqrt(compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+16]*compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+21]);
670 aux = sqrt(compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+16]*compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+21]);
667 if (aux != 0.) { // no division by 0.
671 if (aux != 0.) { // no division by 0.
668 cross_re = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+17] / aux;
672 cross_re = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+17] / aux;
669 cross_im = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+18] / aux;
673 cross_im = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+18] / aux;
670 }
674 }
671 else
675 else
672 {
676 {
673 cross_re = 0.;
677 cross_re = 0.;
674 cross_im = 0.;
678 cross_im = 0.;
675 }
679 }
676 lfr_bp2[i*NB_BYTES_BP2+17] = (uint8_t) (cross_re*127.5 + 128); // Shift and cast into a 8-bit uint8_t (0, ..., 255) with rounding
680 lfr_bp2[i*NB_BYTES_BP2+17] = (uint8_t) (cross_re*127.5 + 128); // Shift and cast into a 8-bit uint8_t (0, ..., 255) with rounding
677 lfr_bp2[i*NB_BYTES_BP2+27] = (uint8_t) (cross_im*127.5 + 128); // Shift and cast into a 8-bit uint8_t (0, ..., 255) with rounding
681 lfr_bp2[i*NB_BYTES_BP2+27] = (uint8_t) (cross_im*127.5 + 128); // Shift and cast into a 8-bit uint8_t (0, ..., 255) with rounding
678 #ifdef DEBUG_TCH
682 #ifdef DEBUG_TCH
679 printf("lfr_bp2[i*NB_BYTES_BP2+17] for cross34_re (%16.8e) : %.3u\n",cross_re, lfr_bp2[i*NB_BYTES_BP2+17]);
683 printf("lfr_bp2[i*NB_BYTES_BP2+17] for cross34_re (%16.8e) : %.3u\n",cross_re, lfr_bp2[i*NB_BYTES_BP2+17]);
680 printf("lfr_bp2[i*NB_BYTES_BP2+27] for cross34_im (%16.8e) : %.3u\n",cross_im, lfr_bp2[i*NB_BYTES_BP2+27]);
684 printf("lfr_bp2[i*NB_BYTES_BP2+27] for cross34_im (%16.8e) : %.3u\n",cross_im, lfr_bp2[i*NB_BYTES_BP2+27]);
681 #endif
685 #endif
682 // S35
686 // S35
683 aux = sqrt(compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+16]*compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+24]);
687 aux = sqrt(compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+16]*compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+24]);
684 if (aux != 0.) { // no division by 0.
688 if (aux != 0.) { // no division by 0.
685 cross_re = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+19] / aux;
689 cross_re = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+19] / aux;
686 cross_im = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+20] / aux;
690 cross_im = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+20] / aux;
687 }
691 }
688 else
692 else
689 {
693 {
690 cross_re = 0.;
694 cross_re = 0.;
691 cross_im = 0.;
695 cross_im = 0.;
692 }
696 }
693 lfr_bp2[i*NB_BYTES_BP2+18] = (uint8_t) (cross_re*127.5 + 128); // Shift and cast into a 8-bit uint8_t (0, ..., 255) with rounding
697 lfr_bp2[i*NB_BYTES_BP2+18] = (uint8_t) (cross_re*127.5 + 128); // Shift and cast into a 8-bit uint8_t (0, ..., 255) with rounding
694 lfr_bp2[i*NB_BYTES_BP2+28] = (uint8_t) (cross_im*127.5 + 128); // Shift and cast into a 8-bit uint8_t (0, ..., 255) with rounding
698 lfr_bp2[i*NB_BYTES_BP2+28] = (uint8_t) (cross_im*127.5 + 128); // Shift and cast into a 8-bit uint8_t (0, ..., 255) with rounding
695 #ifdef DEBUG_TCH
699 #ifdef DEBUG_TCH
696 printf("lfr_bp2[i*NB_BYTES_BP2+18] for cross35_re (%16.8e) : %.3u\n",cross_re, lfr_bp2[i*NB_BYTES_BP2+18]);
700 printf("lfr_bp2[i*NB_BYTES_BP2+18] for cross35_re (%16.8e) : %.3u\n",cross_re, lfr_bp2[i*NB_BYTES_BP2+18]);
697 printf("lfr_bp2[i*NB_BYTES_BP2+28] for cross35_im (%16.8e) : %.3u\n",cross_im, lfr_bp2[i*NB_BYTES_BP2+28]);
701 printf("lfr_bp2[i*NB_BYTES_BP2+28] for cross35_im (%16.8e) : %.3u\n",cross_im, lfr_bp2[i*NB_BYTES_BP2+28]);
698 #endif
702 #endif
699 // S45
703 // S45
700 aux = sqrt(compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+21]*compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+24]);
704 aux = sqrt(compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+21]*compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+24]);
701 if (aux != 0.) { // no division by 0.
705 if (aux != 0.) { // no division by 0.
702 cross_re = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+22] / aux;
706 cross_re = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+22] / aux;
703 cross_im = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+23] / aux;
707 cross_im = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+23] / aux;
704 }
708 }
705 else
709 else
706 {
710 {
707 cross_re = 0.;
711 cross_re = 0.;
708 cross_im = 0.;
712 cross_im = 0.;
709 }
713 }
710 lfr_bp2[i*NB_BYTES_BP2+19] = (uint8_t) (cross_re*127.5 + 128); // Shift and cast into a 8-bit uint8_t (0, ..., 255) with rounding
714 lfr_bp2[i*NB_BYTES_BP2+19] = (uint8_t) (cross_re*127.5 + 128); // Shift and cast into a 8-bit uint8_t (0, ..., 255) with rounding
711 lfr_bp2[i*NB_BYTES_BP2+29] = (uint8_t) (cross_im*127.5 + 128); // Shift and cast into a 8-bit uint8_t (0, ..., 255) with rounding
715 lfr_bp2[i*NB_BYTES_BP2+29] = (uint8_t) (cross_im*127.5 + 128); // Shift and cast into a 8-bit uint8_t (0, ..., 255) with rounding
712 #ifdef DEBUG_TCH
716 #ifdef DEBUG_TCH
713 printf("lfr_bp2[i*NB_BYTES_BP2+19] for cross45_re (%16.8e) : %.3u\n",cross_re, lfr_bp2[i*NB_BYTES_BP2+19]);
717 printf("lfr_bp2[i*NB_BYTES_BP2+19] for cross45_re (%16.8e) : %.3u\n",cross_re, lfr_bp2[i*NB_BYTES_BP2+19]);
714 printf("lfr_bp2[i*NB_BYTES_BP2+29] for cross45_im (%16.8e) : %.3u\n",cross_im, lfr_bp2[i*NB_BYTES_BP2+29]);
718 printf("lfr_bp2[i*NB_BYTES_BP2+29] for cross45_im (%16.8e) : %.3u\n",cross_im, lfr_bp2[i*NB_BYTES_BP2+29]);
715 #endif
719 #endif
716 //==============================================
720 //==============================================
717 // BP2 auto correlations == PA_LFR_SC_BP2_AUTO_F0 == 5*16 bits = 5*[6 bits (exponent) + 10 bits (significand)]
721 // BP2 auto correlations == PA_LFR_SC_BP2_AUTO_F0 == 5*16 bits = 5*[6 bits (exponent) + 10 bits (significand)]
718 // == PA_LFR_SC_BP2_AUTO_A0_F0 == 16 bits
722 // == PA_LFR_SC_BP2_AUTO_A0_F0 == 16 bits
719 // == PA_LFR_SC_BP2_AUTO_A1_F0 == 16 bits
723 // == PA_LFR_SC_BP2_AUTO_A1_F0 == 16 bits
720 // == PA_LFR_SC_BP2_AUTO_A2_F0 == 16 bits
724 // == PA_LFR_SC_BP2_AUTO_A2_F0 == 16 bits
721 // == PA_LFR_SC_BP2_AUTO_A3_F0 == 16 bits
725 // == PA_LFR_SC_BP2_AUTO_A3_F0 == 16 bits
722 // == PA_LFR_SC_BP2_AUTO_A4_F0 == 16 bits
726 // == PA_LFR_SC_BP2_AUTO_A4_F0 == 16 bits
723 // S11
727 // S11
724 significand = frexpf(compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX], &exponent); // 0.5 <= significand < 1
728 significand = frexpf(compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX], &exponent); // 0.5 <= significand < 1
725 // S11 = significand * 2^exponent
729 // S11 = significand * 2^exponent
726 #ifdef DEBUG_TCH
730 #ifdef DEBUG_TCH
727 printf("S11 : %16.8e\n",compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX]);
731 printf("S11 : %16.8e\n",compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX]);
728 printf("significand : %16.8e\n",significand);
732 printf("significand : %16.8e\n",significand);
729 printf("exponent : %d\n" ,exponent);
733 printf("exponent : %d\n" ,exponent);
730 #endif
734 #endif
731 if (exponent < expmin) { // value should be >= 0.5 * 2^expmin
735 if (exponent < expmin) { // value should be >= 0.5 * 2^expmin
732 exponent = expmin;
736 exponent = expmin;
733 significand = 0.5; // min value that can be recorded
737 significand = 0.5; // min value that can be recorded
734 }
738 }
735 if (exponent > expmax) { // value should be < 0.5 * 2^(expmax+1)
739 if (exponent > expmax) { // value should be < 0.5 * 2^(expmax+1)
736 exponent = expmax;
740 exponent = expmax;
737 significand = 1.0; // max value that can be recorded
741 significand = 1.0; // max value that can be recorded
738 }
742 }
739 if (significand == 0) { // in that case exponent == 0 too
743 if (significand == 0) { // in that case exponent == 0 too
740 exponent = expmin;
744 exponent = expmin;
741 significand = 0.5; // min value that can be recorded
745 significand = 0.5; // min value that can be recorded
742 }
746 }
743
747
744 autocor = (uint16_t) ((significand*2-1)*rangesig + 0.5); // Shift and cast into a 16-bit unsigned int with rounding
748 autocor = (uint16_t) ((significand*2-1)*rangesig + 0.5); // Shift and cast into a 16-bit unsigned int with rounding
745 // where just the first nbitsig bits are used (0, ..., 2^nbitsig-1)
749 // where just the first nbitsig bits are used (0, ..., 2^nbitsig-1)
746 exp = (uint16_t) (exponent-expmin); // Shift and cast into a 16-bit unsigned int where just
750 exp = (uint16_t) (exponent-expmin); // Shift and cast into a 16-bit unsigned int where just
747 // the first nbitexp bits are used (0, ..., 2^nbitexp-1)
751 // the first nbitexp bits are used (0, ..., 2^nbitexp-1)
748 tmp_uint16 = autocor | (exp << nbitsig); // Put the exponent bits (nbitexp) next to the
752 tmp_uint16 = autocor | (exp << nbitsig); // Put the exponent bits (nbitexp) next to the
749 // left place of the significand bits (nbitsig),
753 // left place of the significand bits (nbitsig),
750 // making the 16-bit word to be recorded
754 // making the 16-bit word to be recorded
751 pt_uint8 = (uint8_t*) &tmp_uint16; // Affect an uint8_t pointer with the adress of tmp_uint16
755 pt_uint8 = (uint8_t*) &tmp_uint16; // Affect an uint8_t pointer with the adress of tmp_uint16
752 #ifdef MSB_FIRST_TCH
756 #ifdef MSB_FIRST_TCH
753 lfr_bp2[i*NB_BYTES_BP2+0] = pt_uint8[0]; // Record MSB of tmp_uint16
757 lfr_bp2[i*NB_BYTES_BP2+0] = pt_uint8[0]; // Record MSB of tmp_uint16
754 lfr_bp2[i*NB_BYTES_BP2+1] = pt_uint8[1]; // Record LSB of tmp_uint16
758 lfr_bp2[i*NB_BYTES_BP2+1] = pt_uint8[1]; // Record LSB of tmp_uint16
755 #endif
759 #endif
756 #ifdef LSB_FIRST_TCH
760 #ifdef LSB_FIRST_TCH
757 lfr_bp2[i*NB_BYTES_BP2+0] = pt_uint8[1]; // Record MSB of tmp_uint16
761 lfr_bp2[i*NB_BYTES_BP2+0] = pt_uint8[1]; // Record MSB of tmp_uint16
758 lfr_bp2[i*NB_BYTES_BP2+1] = pt_uint8[0]; // Record LSB of tmp_uint16
762 lfr_bp2[i*NB_BYTES_BP2+1] = pt_uint8[0]; // Record LSB of tmp_uint16
759 #endif
763 #endif
760 #ifdef DEBUG_TCH
764 #ifdef DEBUG_TCH
761 printf("autocor for S11 significand : %u\n",autocor);
765 printf("autocor for S11 significand : %u\n",autocor);
762 printf("exp for S11 exponent : %u\n",exp);
766 printf("exp for S11 exponent : %u\n",exp);
763 printf("pt_uint8[1] for S11 exponent + significand : %.3d or %2x\n",pt_uint8[1], pt_uint8[1]);
767 printf("pt_uint8[1] for S11 exponent + significand : %.3d or %2x\n",pt_uint8[1], pt_uint8[1]);
764 printf("pt_uint8[0] for S11 significand : %.3d or %2x\n",pt_uint8[0], pt_uint8[0]);
768 printf("pt_uint8[0] for S11 significand : %.3d or %2x\n",pt_uint8[0], pt_uint8[0]);
765 printf("lfr_bp2[i*NB_BYTES_BP2+0] : %3u or %2x\n",lfr_bp2[i*NB_BYTES_BP2+0], lfr_bp2[i*NB_BYTES_BP2+0]);
769 printf("lfr_bp2[i*NB_BYTES_BP2+0] : %3u or %2x\n",lfr_bp2[i*NB_BYTES_BP2+0], lfr_bp2[i*NB_BYTES_BP2+0]);
766 printf("lfr_bp2[i*NB_BYTES_BP2+1] : %3u or %2x\n",lfr_bp2[i*NB_BYTES_BP2+1], lfr_bp2[i*NB_BYTES_BP2+1]);
770 printf("lfr_bp2[i*NB_BYTES_BP2+1] : %3u or %2x\n",lfr_bp2[i*NB_BYTES_BP2+1], lfr_bp2[i*NB_BYTES_BP2+1]);
767 #endif
771 #endif
768 // S22
772 // S22
769 significand = frexpf(compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+9], &exponent); // 0.5 <= significand < 1
773 significand = frexpf(compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+9], &exponent); // 0.5 <= significand < 1
770 // S22 = significand * 2^exponent
774 // S22 = significand * 2^exponent
771 #ifdef DEBUG_TCH
775 #ifdef DEBUG_TCH
772 printf("S22 : %16.8e\n",compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+9]);
776 printf("S22 : %16.8e\n",compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+9]);
773 printf("significand : %16.8e\n",significand);
777 printf("significand : %16.8e\n",significand);
774 printf("exponent : %d\n" ,exponent);
778 printf("exponent : %d\n" ,exponent);
775 #endif
779 #endif
776 if (exponent < expmin) { // value should be >= 0.5 * 2^expmin
780 if (exponent < expmin) { // value should be >= 0.5 * 2^expmin
777 exponent = expmin;
781 exponent = expmin;
778 significand = 0.5; // min value that can be recorded
782 significand = 0.5; // min value that can be recorded
779 }
783 }
780 if (exponent > expmax) { // value should be < 0.5 * 2^(expmax+1)
784 if (exponent > expmax) { // value should be < 0.5 * 2^(expmax+1)
781 exponent = expmax;
785 exponent = expmax;
782 significand = 1.0; // max value that can be recorded
786 significand = 1.0; // max value that can be recorded
783 }
787 }
784 if (significand == 0) { // in that case exponent == 0 too
788 if (significand == 0) { // in that case exponent == 0 too
785 exponent = expmin;
789 exponent = expmin;
786 significand = 0.5; // min value that can be recorded
790 significand = 0.5; // min value that can be recorded
787 }
791 }
788
792
789 autocor = (uint16_t) ((significand*2-1)*rangesig + 0.5); // Shift and cast into a 16-bit unsigned int with rounding
793 autocor = (uint16_t) ((significand*2-1)*rangesig + 0.5); // Shift and cast into a 16-bit unsigned int with rounding
790 // where just the first nbitsig bits are used (0, ..., 2^nbitsig-1)
794 // where just the first nbitsig bits are used (0, ..., 2^nbitsig-1)
791 exp = (uint16_t) (exponent-expmin); // Shift and cast into a 16-bit unsigned int where just
795 exp = (uint16_t) (exponent-expmin); // Shift and cast into a 16-bit unsigned int where just
792 // the first nbitexp bits are used (0, ..., 2^nbitexp-1)
796 // the first nbitexp bits are used (0, ..., 2^nbitexp-1)
793 tmp_uint16 = autocor | (exp << nbitsig); // Put the exponent bits (nbitexp) next to the
797 tmp_uint16 = autocor | (exp << nbitsig); // Put the exponent bits (nbitexp) next to the
794 // left place of the significand bits (nbitsig),
798 // left place of the significand bits (nbitsig),
795 // making the 16-bit word to be recorded
799 // making the 16-bit word to be recorded
796 pt_uint8 = (uint8_t*) &tmp_uint16; // Affect an uint8_t pointer with the adress of tmp_uint16
800 pt_uint8 = (uint8_t*) &tmp_uint16; // Affect an uint8_t pointer with the adress of tmp_uint16
797 #ifdef MSB_FIRST_TCH
801 #ifdef MSB_FIRST_TCH
798 lfr_bp2[i*NB_BYTES_BP2+2] = pt_uint8[0]; // Record MSB of tmp_uint16
802 lfr_bp2[i*NB_BYTES_BP2+2] = pt_uint8[0]; // Record MSB of tmp_uint16
799 lfr_bp2[i*NB_BYTES_BP2+3] = pt_uint8[1]; // Record LSB of tmp_uint16
803 lfr_bp2[i*NB_BYTES_BP2+3] = pt_uint8[1]; // Record LSB of tmp_uint16
800 #endif
804 #endif
801 #ifdef LSB_FIRST_TCH
805 #ifdef LSB_FIRST_TCH
802 lfr_bp2[i*NB_BYTES_BP2+2] = pt_uint8[1]; // Record MSB of tmp_uint16
806 lfr_bp2[i*NB_BYTES_BP2+2] = pt_uint8[1]; // Record MSB of tmp_uint16
803 lfr_bp2[i*NB_BYTES_BP2+3] = pt_uint8[0]; // Record LSB of tmp_uint16
807 lfr_bp2[i*NB_BYTES_BP2+3] = pt_uint8[0]; // Record LSB of tmp_uint16
804 #endif
808 #endif
805 #ifdef DEBUG_TCH
809 #ifdef DEBUG_TCH
806 printf("autocor for S22 significand : %u\n",autocor);
810 printf("autocor for S22 significand : %u\n",autocor);
807 printf("exp for S11 exponent : %u\n",exp);
811 printf("exp for S11 exponent : %u\n",exp);
808 printf("pt_uint8[1] for S22 exponent + significand : %.3d or %2x\n",pt_uint8[1], pt_uint8[1]);
812 printf("pt_uint8[1] for S22 exponent + significand : %.3d or %2x\n",pt_uint8[1], pt_uint8[1]);
809 printf("pt_uint8[0] for S22 significand : %.3d or %2x\n",pt_uint8[0], pt_uint8[0]);
813 printf("pt_uint8[0] for S22 significand : %.3d or %2x\n",pt_uint8[0], pt_uint8[0]);
810 printf("lfr_bp2[i*NB_BYTES_BP2+2] : %3u or %2x\n",lfr_bp2[i*NB_BYTES_BP2+2], lfr_bp2[i*NB_BYTES_BP2+2]);
814 printf("lfr_bp2[i*NB_BYTES_BP2+2] : %3u or %2x\n",lfr_bp2[i*NB_BYTES_BP2+2], lfr_bp2[i*NB_BYTES_BP2+2]);
811 printf("lfr_bp2[i*NB_BYTES_BP2+3] : %3u or %2x\n",lfr_bp2[i*NB_BYTES_BP2+3], lfr_bp2[i*NB_BYTES_BP2+3]);
815 printf("lfr_bp2[i*NB_BYTES_BP2+3] : %3u or %2x\n",lfr_bp2[i*NB_BYTES_BP2+3], lfr_bp2[i*NB_BYTES_BP2+3]);
812 #endif
816 #endif
813 // S33
817 // S33
814 significand = frexpf(compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+16], &exponent); // 0.5 <= significand < 1
818 significand = frexpf(compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+16], &exponent); // 0.5 <= significand < 1
815 // S33 = significand * 2^exponent
819 // S33 = significand * 2^exponent
816 #ifdef DEBUG_TCH
820 #ifdef DEBUG_TCH
817 printf("S33 : %16.8e\n",compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+16]);
821 printf("S33 : %16.8e\n",compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+16]);
818 printf("significand : %16.8e\n",significand);
822 printf("significand : %16.8e\n",significand);
819 printf("exponent : %d\n" ,exponent);
823 printf("exponent : %d\n" ,exponent);
820 #endif
824 #endif
821 if (exponent < expmin) { // value should be >= 0.5 * 2^expmin
825 if (exponent < expmin) { // value should be >= 0.5 * 2^expmin
822 exponent = expmin;
826 exponent = expmin;
823 significand = 0.5; // min value that can be recorded
827 significand = 0.5; // min value that can be recorded
824 }
828 }
825 if (exponent > expmax) { // value should be < 0.5 * 2^(expmax+1)
829 if (exponent > expmax) { // value should be < 0.5 * 2^(expmax+1)
826 exponent = expmax;
830 exponent = expmax;
827 significand = 1.0; // max value that can be recorded
831 significand = 1.0; // max value that can be recorded
828 }
832 }
829 if (significand == 0) { // in that case exponent == 0 too
833 if (significand == 0) { // in that case exponent == 0 too
830 exponent = expmin;
834 exponent = expmin;
831 significand = 0.5; // min value that can be recorded
835 significand = 0.5; // min value that can be recorded
832 }
836 }
833
837
834 autocor = (uint16_t) ((significand*2-1)*rangesig + 0.5); // Shift and cast into a 16-bit unsigned int with rounding
838 autocor = (uint16_t) ((significand*2-1)*rangesig + 0.5); // Shift and cast into a 16-bit unsigned int with rounding
835 // where just the first nbitsig bits are used (0, ..., 2^nbitsig-1)
839 // where just the first nbitsig bits are used (0, ..., 2^nbitsig-1)
836 exp = (uint16_t) (exponent-expmin); // Shift and cast into a 16-bit unsigned int where just
840 exp = (uint16_t) (exponent-expmin); // Shift and cast into a 16-bit unsigned int where just
837 // the first nbitexp bits are used (0, ..., 2^nbitexp-1)
841 // the first nbitexp bits are used (0, ..., 2^nbitexp-1)
838 tmp_uint16 = autocor | (exp << nbitsig); // Put the exponent bits (nbitexp) next to the
842 tmp_uint16 = autocor | (exp << nbitsig); // Put the exponent bits (nbitexp) next to the
839 // left place of the significand bits (nbitsig),
843 // left place of the significand bits (nbitsig),
840 // making the 16-bit word to be recorded
844 // making the 16-bit word to be recorded
841 pt_uint8 = (uint8_t*) &tmp_uint16; // Affect an uint8_t pointer with the adress of tmp_uint16
845 pt_uint8 = (uint8_t*) &tmp_uint16; // Affect an uint8_t pointer with the adress of tmp_uint16
842 #ifdef MSB_FIRST_TCH
846 #ifdef MSB_FIRST_TCH
843 lfr_bp2[i*NB_BYTES_BP2+4] = pt_uint8[0]; // Record MSB of tmp_uint16
847 lfr_bp2[i*NB_BYTES_BP2+4] = pt_uint8[0]; // Record MSB of tmp_uint16
844 lfr_bp2[i*NB_BYTES_BP2+5] = pt_uint8[1]; // Record LSB of tmp_uint16
848 lfr_bp2[i*NB_BYTES_BP2+5] = pt_uint8[1]; // Record LSB of tmp_uint16
845 #endif
849 #endif
846 #ifdef LSB_FIRST_TCH
850 #ifdef LSB_FIRST_TCH
847 lfr_bp2[i*NB_BYTES_BP2+4] = pt_uint8[1]; // Record MSB of tmp_uint16
851 lfr_bp2[i*NB_BYTES_BP2+4] = pt_uint8[1]; // Record MSB of tmp_uint16
848 lfr_bp2[i*NB_BYTES_BP2+5] = pt_uint8[0]; // Record LSB of tmp_uint16
852 lfr_bp2[i*NB_BYTES_BP2+5] = pt_uint8[0]; // Record LSB of tmp_uint16
849 #endif
853 #endif
850 #ifdef DEBUG_TCH
854 #ifdef DEBUG_TCH
851 printf("autocor for S33 significand : %u\n",autocor);
855 printf("autocor for S33 significand : %u\n",autocor);
852 printf("exp for S33 exponent : %u\n",exp);
856 printf("exp for S33 exponent : %u\n",exp);
853 printf("pt_uint8[1] for S33 exponent + significand : %.3d or %2x\n",pt_uint8[1], pt_uint8[1]);
857 printf("pt_uint8[1] for S33 exponent + significand : %.3d or %2x\n",pt_uint8[1], pt_uint8[1]);
854 printf("pt_uint8[0] for S33 significand : %.3d or %2x\n",pt_uint8[0], pt_uint8[0]);
858 printf("pt_uint8[0] for S33 significand : %.3d or %2x\n",pt_uint8[0], pt_uint8[0]);
855 printf("lfr_bp2[i*NB_BYTES_BP2+4] : %3u or %2x\n",lfr_bp2[i*NB_BYTES_BP2+4], lfr_bp2[i*NB_BYTES_BP2+4]);
859 printf("lfr_bp2[i*NB_BYTES_BP2+4] : %3u or %2x\n",lfr_bp2[i*NB_BYTES_BP2+4], lfr_bp2[i*NB_BYTES_BP2+4]);
856 printf("lfr_bp2[i*NB_BYTES_BP2+5] : %3u or %2x\n",lfr_bp2[i*NB_BYTES_BP2+5], lfr_bp2[i*NB_BYTES_BP2+5]);
860 printf("lfr_bp2[i*NB_BYTES_BP2+5] : %3u or %2x\n",lfr_bp2[i*NB_BYTES_BP2+5], lfr_bp2[i*NB_BYTES_BP2+5]);
857 #endif
861 #endif
858 // S44
862 // S44
859 significand = frexpf(compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+21], &exponent); // 0.5 <= significand < 1
863 significand = frexpf(compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+21], &exponent); // 0.5 <= significand < 1
860 // S44 = significand * 2^exponent
864 // S44 = significand * 2^exponent
861 #ifdef DEBUG_TCH
865 #ifdef DEBUG_TCH
862 printf("S44 : %16.8e\n",compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+21]);
866 printf("S44 : %16.8e\n",compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+21]);
863 printf("significand : %16.8e\n",significand);
867 printf("significand : %16.8e\n",significand);
864 printf("exponent : %d\n" ,exponent);
868 printf("exponent : %d\n" ,exponent);
865 #endif
869 #endif
866
870
867 if (exponent < expmin) { // value should be >= 0.5 * 2^expmin
871 if (exponent < expmin) { // value should be >= 0.5 * 2^expmin
868 exponent = expmin;
872 exponent = expmin;
869 significand = 0.5; // min value that can be recorded
873 significand = 0.5; // min value that can be recorded
870 }
874 }
871 if (exponent > expmax) { // value should be < 0.5 * 2^(expmax+1)
875 if (exponent > expmax) { // value should be < 0.5 * 2^(expmax+1)
872 exponent = expmax;
876 exponent = expmax;
873 significand = 1.0; // max value that can be recorded
877 significand = 1.0; // max value that can be recorded
874 }
878 }
875 if (significand == 0) { // in that case exponent == 0 too
879 if (significand == 0) { // in that case exponent == 0 too
876 exponent = expmin;
880 exponent = expmin;
877 significand = 0.5; // min value that can be recorded
881 significand = 0.5; // min value that can be recorded
878 }
882 }
879
883
880 autocor = (uint16_t) ((significand*2-1)*rangesig + 0.5); // Shift and cast into a 16-bit unsigned int with rounding
884 autocor = (uint16_t) ((significand*2-1)*rangesig + 0.5); // Shift and cast into a 16-bit unsigned int with rounding
881 // where just the first nbitsig bits are used (0, ..., 2^nbitsig-1)
885 // where just the first nbitsig bits are used (0, ..., 2^nbitsig-1)
882 exp = (uint16_t) (exponent-expmin); // Shift and cast into a 16-bit unsigned int where just
886 exp = (uint16_t) (exponent-expmin); // Shift and cast into a 16-bit unsigned int where just
883 // the first nbitexp bits are used (0, ..., 2^nbitexp-1)
887 // the first nbitexp bits are used (0, ..., 2^nbitexp-1)
884 tmp_uint16 = autocor | (exp << nbitsig); // Put the exponent bits (nbitexp) next to the
888 tmp_uint16 = autocor | (exp << nbitsig); // Put the exponent bits (nbitexp) next to the
885 // left place of the significand bits (nbitsig),
889 // left place of the significand bits (nbitsig),
886 // making the 16-bit word to be recorded
890 // making the 16-bit word to be recorded
887 pt_uint8 = (uint8_t*) &tmp_uint16; // Affect an uint8_t pointer with the adress of tmp_uint16
891 pt_uint8 = (uint8_t*) &tmp_uint16; // Affect an uint8_t pointer with the adress of tmp_uint16
888 #ifdef MSB_FIRST_TCH
892 #ifdef MSB_FIRST_TCH
889 lfr_bp2[i*NB_BYTES_BP2+6] = pt_uint8[0]; // Record MSB of tmp_uint16
893 lfr_bp2[i*NB_BYTES_BP2+6] = pt_uint8[0]; // Record MSB of tmp_uint16
890 lfr_bp2[i*NB_BYTES_BP2+7] = pt_uint8[1]; // Record LSB of tmp_uint16
894 lfr_bp2[i*NB_BYTES_BP2+7] = pt_uint8[1]; // Record LSB of tmp_uint16
891 #endif
895 #endif
892 #ifdef LSB_FIRST_TCH
896 #ifdef LSB_FIRST_TCH
893 lfr_bp2[i*NB_BYTES_BP2+6] = pt_uint8[1]; // Record MSB of tmp_uint16
897 lfr_bp2[i*NB_BYTES_BP2+6] = pt_uint8[1]; // Record MSB of tmp_uint16
894 lfr_bp2[i*NB_BYTES_BP2+7] = pt_uint8[0]; // Record LSB of tmp_uint16
898 lfr_bp2[i*NB_BYTES_BP2+7] = pt_uint8[0]; // Record LSB of tmp_uint16
895 #endif
899 #endif
896 #ifdef DEBUG_TCH
900 #ifdef DEBUG_TCH
897 printf("autocor for S44 significand : %u\n",autocor);
901 printf("autocor for S44 significand : %u\n",autocor);
898 printf("exp for S44 exponent : %u\n",exp);
902 printf("exp for S44 exponent : %u\n",exp);
899 printf("pt_uint8[1] for S44 exponent + significand : %.3d or %2x\n",pt_uint8[1], pt_uint8[1]);
903 printf("pt_uint8[1] for S44 exponent + significand : %.3d or %2x\n",pt_uint8[1], pt_uint8[1]);
900 printf("pt_uint8[0] for S44 significand : %.3d or %2x\n",pt_uint8[0], pt_uint8[0]);
904 printf("pt_uint8[0] for S44 significand : %.3d or %2x\n",pt_uint8[0], pt_uint8[0]);
901 printf("lfr_bp2[i*NB_BYTES_BP2+6] : %3u or %2x\n",lfr_bp2[i*NB_BYTES_BP2+6], lfr_bp2[i*NB_BYTES_BP2+6]);
905 printf("lfr_bp2[i*NB_BYTES_BP2+6] : %3u or %2x\n",lfr_bp2[i*NB_BYTES_BP2+6], lfr_bp2[i*NB_BYTES_BP2+6]);
902 printf("lfr_bp2[i*NB_BYTES_BP2+7] : %3u or %2x\n",lfr_bp2[i*NB_BYTES_BP2+7], lfr_bp2[i*NB_BYTES_BP2+7]);
906 printf("lfr_bp2[i*NB_BYTES_BP2+7] : %3u or %2x\n",lfr_bp2[i*NB_BYTES_BP2+7], lfr_bp2[i*NB_BYTES_BP2+7]);
903 #endif
907 #endif
904 // S55
908 // S55
905 significand = frexpf(compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+24], &exponent); // 0.5 <= significand < 1
909 significand = frexpf(compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+24], &exponent); // 0.5 <= significand < 1
906 // S55 = significand * 2^exponent
910 // S55 = significand * 2^exponent
907 #ifdef DEBUG_TCH
911 #ifdef DEBUG_TCH
908 printf("S55 : %16.8e\n",compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+24]);
912 printf("S55 : %16.8e\n",compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+24]);
909 printf("significand : %16.8e\n",significand);
913 printf("significand : %16.8e\n",significand);
910 printf("exponent : %d\n" ,exponent);
914 printf("exponent : %d\n" ,exponent);
911 #endif
915 #endif
912 if (exponent < expmin) { // value should be >= 0.5 * 2^expmin
916 if (exponent < expmin) { // value should be >= 0.5 * 2^expmin
913 exponent = expmin;
917 exponent = expmin;
914 significand = 0.5; // min value that can be recorded
918 significand = 0.5; // min value that can be recorded
915 }
919 }
916 if (exponent > expmax) { // value should be < 0.5 * 2^(expmax+1)
920 if (exponent > expmax) { // value should be < 0.5 * 2^(expmax+1)
917 exponent = expmax;
921 exponent = expmax;
918 significand = 1.0; // max value that can be recorded
922 significand = 1.0; // max value that can be recorded
919 }
923 }
920 if (significand == 0) { // in that case exponent == 0 too
924 if (significand == 0) { // in that case exponent == 0 too
921 exponent = expmin;
925 exponent = expmin;
922 significand = 0.5; // min value that can be recorded
926 significand = 0.5; // min value that can be recorded
923 }
927 }
924
928
925 autocor = (uint16_t) ((significand*2-1)*rangesig + 0.5); // Shift and cast into a 16-bit unsigned int with rounding
929 autocor = (uint16_t) ((significand*2-1)*rangesig + 0.5); // Shift and cast into a 16-bit unsigned int with rounding
926 // where just the first nbitsig bits are used (0, ..., 2^nbitsig-1)
930 // where just the first nbitsig bits are used (0, ..., 2^nbitsig-1)
927 exp = (uint16_t) (exponent-expmin); // Shift and cast into a 16-bit unsigned int where just
931 exp = (uint16_t) (exponent-expmin); // Shift and cast into a 16-bit unsigned int where just
928 // the first nbitexp bits are used (0, ..., 2^nbitexp-1)
932 // the first nbitexp bits are used (0, ..., 2^nbitexp-1)
929 tmp_uint16 = autocor | (exp << nbitsig); // Put the exponent bits (nbitexp) next to the
933 tmp_uint16 = autocor | (exp << nbitsig); // Put the exponent bits (nbitexp) next to the
930 // left place of the significand bits (nbitsig),
934 // left place of the significand bits (nbitsig),
931 // making the 16-bit word to be recorded
935 // making the 16-bit word to be recorded
932 pt_uint8 = (uint8_t*) &tmp_uint16; // Affect an uint8_t pointer with the adress of tmp_uint16
936 pt_uint8 = (uint8_t*) &tmp_uint16; // Affect an uint8_t pointer with the adress of tmp_uint16
933 #ifdef MSB_FIRST_TCH
937 #ifdef MSB_FIRST_TCH
934 lfr_bp2[i*NB_BYTES_BP2+8] = pt_uint8[0]; // Record MSB of tmp_uint16
938 lfr_bp2[i*NB_BYTES_BP2+8] = pt_uint8[0]; // Record MSB of tmp_uint16
935 lfr_bp2[i*NB_BYTES_BP2+9] = pt_uint8[1]; // Record LSB of tmp_uint16
939 lfr_bp2[i*NB_BYTES_BP2+9] = pt_uint8[1]; // Record LSB of tmp_uint16
936 //printf("MSB:\n");
940 //printf("MSB:\n");
937 #endif
941 #endif
938 #ifdef LSB_FIRST_TCH
942 #ifdef LSB_FIRST_TCH
939 lfr_bp2[i*NB_BYTES_BP2+8] = pt_uint8[1]; // Record MSB of tmp_uint16
943 lfr_bp2[i*NB_BYTES_BP2+8] = pt_uint8[1]; // Record MSB of tmp_uint16
940 lfr_bp2[i*NB_BYTES_BP2+9] = pt_uint8[0]; // Record LSB of tmp_uint16
944 lfr_bp2[i*NB_BYTES_BP2+9] = pt_uint8[0]; // Record LSB of tmp_uint16
941 //printf("LSB:\n");
945 //printf("LSB:\n");
942 #endif
946 #endif
943 #ifdef DEBUG_TCH
947 #ifdef DEBUG_TCH
944 printf("autocor for S55 significand : %u\n",autocor);
948 printf("autocor for S55 significand : %u\n",autocor);
945 printf("exp for S55 exponent : %u\n",exp);
949 printf("exp for S55 exponent : %u\n",exp);
946 printf("pt_uint8[1] for S55 exponent + significand : %.3d or %2x\n",pt_uint8[1], pt_uint8[1]);
950 printf("pt_uint8[1] for S55 exponent + significand : %.3d or %2x\n",pt_uint8[1], pt_uint8[1]);
947 printf("pt_uint8[0] for S55 significand : %.3d or %2x\n",pt_uint8[0], pt_uint8[0]);
951 printf("pt_uint8[0] for S55 significand : %.3d or %2x\n",pt_uint8[0], pt_uint8[0]);
948 printf("lfr_bp2[i*NB_BYTES_BP2+8] : %3u or %2x\n",lfr_bp2[i*NB_BYTES_BP2+8], lfr_bp2[i*NB_BYTES_BP2+8]);
952 printf("lfr_bp2[i*NB_BYTES_BP2+8] : %3u or %2x\n",lfr_bp2[i*NB_BYTES_BP2+8], lfr_bp2[i*NB_BYTES_BP2+8]);
949 printf("lfr_bp2[i*NB_BYTES_BP2+9] : %3u or %2x\n",lfr_bp2[i*NB_BYTES_BP2+9], lfr_bp2[i*NB_BYTES_BP2+9]);
953 printf("lfr_bp2[i*NB_BYTES_BP2+9] : %3u or %2x\n",lfr_bp2[i*NB_BYTES_BP2+9], lfr_bp2[i*NB_BYTES_BP2+9]);
950 #endif
954 #endif
951 }
955 }
952 }
956 }
953
957
954
958
955 #endif // BASIC_PARAMETERS_H_INCLUDED
959 #endif // BASIC_PARAMETERS_H_INCLUDED
@@ -1,65 +1,65
1 // In the frame of RPW LFR Sofware ICD Issue1 Rev8 (05/07/2013) => R2 FSW
1 // In the frame of RPW LFR Sofware ICD Issue1 Rev8 (05/07/2013) => R2 FSW
2 // version 1.4: 16/05/2014
2 // version 1.4: 16/05/2014
3 // version 1.5: 20/05/2014
3 // version 1.5: 20/05/2014
4 // version 1.6: 19/12/2014
4 // version 1.6: 19/12/2014
5 // version 1.7: 15/01/2015 (modifs de Paul + correction erreurs qui se compensaient (LSB <=> MSB + indices [0,2] <=> [1,3])
5 // version 1.7: 15/01/2015 (modifs de Paul + correction erreurs qui se compensaient (LSB <=> MSB + indices [0,2] <=> [1,3])
6 // version 1.8: 02/02/2015 (gestion des divisions par zΓ©ro)
6 // version 1.8: 02/02/2015 (gestion des divisions par zΓ©ro)
7 // In the frame of RPW LFR Sofware ICD Issue3 Rev6 (27/01/2015) => R3 FSW
7 // In the frame of RPW LFR Sofware ICD Issue3 Rev6 (27/01/2015) => R3 FSW
8 // version 2.0: 19/06/2015
8 // version 2.0: 19/06/2015
9 // version 2.1: 22/06/2015 (modifs de Paul)
9 // version 2.1: 22/06/2015 (modifs de Paul)
10 // version 2.2: 23/06/2015 (modifs de l'ordre de dΓ©claration/dΓ©finition de init_k_coefficients dans basic_parameters.c ...)
10 // version 2.2: 23/06/2015 (modifs de l'ordre de dΓ©claration/dΓ©finition de init_k_coefficients dans basic_parameters.c ... + maintien des declarations dans le .h)
11
11
12 #ifndef BASIC_PARAMETERS_PARAMS_H
12 #ifndef BASIC_PARAMETERS_PARAMS_H
13 #define BASIC_PARAMETERS_PARAMS_H
13 #define BASIC_PARAMETERS_PARAMS_H
14
14
15 #define NB_VALUES_PER_SPECTRAL_MATRIX 25
15 #define NB_VALUES_PER_SPECTRAL_MATRIX 25
16
16
17 #define NB_BINS_COMPRESSED_MATRIX_f0 11
17 #define NB_BINS_COMPRESSED_MATRIX_f0 11
18 #define NB_BINS_COMPRESSED_MATRIX_f1 13
18 #define NB_BINS_COMPRESSED_MATRIX_f1 13
19 #define NB_BINS_COMPRESSED_MATRIX_f2 12
19 #define NB_BINS_COMPRESSED_MATRIX_f2 12
20
20
21 #define NB_BYTES_BP1 11
21 #define NB_BYTES_BP1 11
22 #define NB_BYTES_BP2 30
22 #define NB_BYTES_BP2 30
23
23
24 //********************************************
24 //********************************************
25 // K-COEFFICIENTS FOR ONBOARD INTERCALIBRATION
25 // K-COEFFICIENTS FOR ONBOARD INTERCALIBRATION
26
26
27 #define NB_K_COEFF_PER_BIN 32
27 #define NB_K_COEFF_PER_BIN 32
28
28
29 #define K44_PE 0
29 #define K44_PE 0
30 #define K55_PE 1
30 #define K55_PE 1
31 #define K45_PE_RE 2
31 #define K45_PE_RE 2
32 #define K45_PE_IM 3
32 #define K45_PE_IM 3
33
33
34 #define K14_SX_RE 4
34 #define K14_SX_RE 4
35 #define K14_SX_IM 5
35 #define K14_SX_IM 5
36 #define K15_SX_RE 6
36 #define K15_SX_RE 6
37 #define K15_SX_IM 7
37 #define K15_SX_IM 7
38 #define K24_SX_RE 8
38 #define K24_SX_RE 8
39 #define K24_SX_IM 9
39 #define K24_SX_IM 9
40 #define K25_SX_RE 10
40 #define K25_SX_RE 10
41 #define K25_SX_IM 11
41 #define K25_SX_IM 11
42 #define K34_SX_RE 12
42 #define K34_SX_RE 12
43 #define K34_SX_IM 13
43 #define K34_SX_IM 13
44 #define K35_SX_RE 14
44 #define K35_SX_RE 14
45 #define K35_SX_IM 15
45 #define K35_SX_IM 15
46
46
47 #define K24_NY_RE 16
47 #define K24_NY_RE 16
48 #define K24_NY_IM 17
48 #define K24_NY_IM 17
49 #define K25_NY_RE 18
49 #define K25_NY_RE 18
50 #define K25_NY_IM 19
50 #define K25_NY_IM 19
51 #define K34_NY_RE 20
51 #define K34_NY_RE 20
52 #define K34_NY_IM 21
52 #define K34_NY_IM 21
53 #define K35_NY_RE 22
53 #define K35_NY_RE 22
54 #define K35_NY_IM 23
54 #define K35_NY_IM 23
55
55
56 #define K24_NZ_RE 24
56 #define K24_NZ_RE 24
57 #define K24_NZ_IM 25
57 #define K24_NZ_IM 25
58 #define K25_NZ_RE 26
58 #define K25_NZ_RE 26
59 #define K25_NZ_IM 27
59 #define K25_NZ_IM 27
60 #define K34_NZ_RE 28
60 #define K34_NZ_RE 28
61 #define K34_NZ_IM 29
61 #define K34_NZ_IM 29
62 #define K35_NZ_RE 30
62 #define K35_NZ_RE 30
63 #define K35_NZ_IM 31
63 #define K35_NZ_IM 31
64
64
65 #endif // BASIC_PARAMETERS_PARAMS_H
65 #endif // BASIC_PARAMETERS_PARAMS_H
@@ -1,27 +1,27
1 // In the frame of RPW LFR Sofware ICD Issue1 Rev8 (05/07/2013) => R2 FSW
1 // In the frame of RPW LFR Sofware ICD Issue1 Rev8 (05/07/2013) => R2 FSW
2 // version 1.6: 19/12/2014
2 // version 1.6: 19/12/2014
3 // version 1.7: 15/01/2015 (modifs de Paul + correction erreurs qui se compensaient (LSB <=> MSB + indices [0,2] <=> [1,3])
3 // version 1.7: 15/01/2015 (modifs de Paul + correction erreurs qui se compensaient (LSB <=> MSB + indices [0,2] <=> [1,3])
4 // version 1.8: 02/02/2015 (gestion des divisions par zΓ©ro)
4 // version 1.8: 02/02/2015 (gestion des divisions par zΓ©ro)
5 // In the frame of RPW LFR Sofware ICD Issue3 Rev6 (27/01/2015) => R3 FSW
5 // In the frame of RPW LFR Sofware ICD Issue3 Rev6 (27/01/2015) => R3 FSW
6 // version 2.0: 19/06/2015
6 // version 2.0: 19/06/2015
7 // version 2.1: 22/06/2015 (modifs de Paul)
7 // version 2.1: 22/06/2015 (modifs de Paul)
8 // version 2.2: 23/06/2015 (modifs de l'ordre de dΓ©claration/dΓ©finition de init_k_coefficients dans basic_parameters.c ...)
8 // version 2.2: 23/06/2015 (modifs de l'ordre de dΓ©claration/dΓ©finition de init_k_coefficients dans basic_parameters.c ... + maintien des declarations dans le .h)
9
9
10
10
11 #ifndef BASIC_PARAMETERS_UTILITIES_H
11 #ifndef BASIC_PARAMETERS_UTILITIES_H
12 #define BASIC_PARAMETERS_UTILITIES_H
12 #define BASIC_PARAMETERS_UTILITIES_H
13
13
14 #include <stdio.h>
14 #include <stdio.h>
15 #include <malloc.h>
15 #include <malloc.h>
16
16
17 #include "basic_parameters_params.h"
17 #include "basic_parameters_params.h"
18
18
19 float compressed_spectral_matrix_f0[NB_BINS_COMPRESSED_MATRIX_f0 * NB_VALUES_PER_SPECTRAL_MATRIX];
19 float compressed_spectral_matrix_f0[NB_BINS_COMPRESSED_MATRIX_f0 * NB_VALUES_PER_SPECTRAL_MATRIX];
20 float k_coefficients_f0[NB_BINS_COMPRESSED_MATRIX_f0 * NB_K_COEFF_PER_BIN];
20 float k_coefficients_f0[NB_BINS_COMPRESSED_MATRIX_f0 * NB_K_COEFF_PER_BIN];
21 float k_coefficients_f1[NB_BINS_COMPRESSED_MATRIX_f1 * NB_K_COEFF_PER_BIN];
21 float k_coefficients_f1[NB_BINS_COMPRESSED_MATRIX_f1 * NB_K_COEFF_PER_BIN];
22 float k_coefficients_f2[NB_BINS_COMPRESSED_MATRIX_f2 * NB_K_COEFF_PER_BIN];
22 float k_coefficients_f2[NB_BINS_COMPRESSED_MATRIX_f2 * NB_K_COEFF_PER_BIN];
23
23
24 unsigned char LFR_BP1_f0[NB_BINS_COMPRESSED_MATRIX_f0*NB_BYTES_BP1];
24 unsigned char LFR_BP1_f0[NB_BINS_COMPRESSED_MATRIX_f0*NB_BYTES_BP1];
25 unsigned char LFR_BP2_f0[NB_BINS_COMPRESSED_MATRIX_f0*NB_BYTES_BP2];
25 unsigned char LFR_BP2_f0[NB_BINS_COMPRESSED_MATRIX_f0*NB_BYTES_BP2];
26
26
27 #endif // BASIC_PARAMETERS_UTILITIES_H
27 #endif // BASIC_PARAMETERS_UTILITIES_H
@@ -1,77 +1,77
1 // In the frame of RPW LFR Sofware ICD Issue1 Rev8 (05/07/2013) => R2 FSW
1 // In the frame of RPW LFR Sofware ICD Issue1 Rev8 (05/07/2013) => R2 FSW
2 // version 1.0: 31/07/2013
2 // version 1.0: 31/07/2013
3 // version 1.1: 02/04/2014
3 // version 1.1: 02/04/2014
4 // version 1.2: 30/04/2014
4 // version 1.2: 30/04/2014
5 // version 1.3: 02/05/2014
5 // version 1.3: 02/05/2014
6 // version 1.4: 16/05/2014
6 // version 1.4: 16/05/2014
7 // version 1.5: 20/05/2014
7 // version 1.5: 20/05/2014
8 // version 1.6: 19/12/2014
8 // version 1.6: 19/12/2014
9 // version 1.7: 15/01/2015 (modifs de Paul + correction erreurs qui se compensaient (LSB <=> MSB + indices [0,2] <=> [1,3])
9 // version 1.7: 15/01/2015 (modifs de Paul + correction erreurs qui se compensaient (LSB <=> MSB + indices [0,2] <=> [1,3])
10 // version 1.8: 02/02/2015 (gestion des divisions par zΓ©ro)
10 // version 1.8: 02/02/2015 (gestion des divisions par zΓ©ro)
11 // In the frame of RPW LFR Sofware ICD Issue3 Rev6 (27/01/2015) => R3 FSW
11 // In the frame of RPW LFR Sofware ICD Issue3 Rev6 (27/01/2015) => R3 FSW
12 // version 2.0: 19/06/2015
12 // version 2.0: 19/06/2015
13 // version 2.1: 22/06/2015 (modifs de Paul)
13 // version 2.1: 22/06/2015 (modifs de Paul)
14 // version 2.2: 23/06/2015 (modifs de l'ordre de dΓ©claration/dΓ©finition de init_k_coefficients dans basic_parameters.c ...)
14 // version 2.2: 23/06/2015 (modifs de l'ordre de dΓ©claration/dΓ©finition de init_k_coefficients dans basic_parameters.c ... + maintien des declarations dans le .h)
15
15
16
16
17 #include "basic_parameters_utilities.h"
17 #include "basic_parameters_utilities.h"
18
18
19 int lecture_file_sm(const char *fileName)
19 int lecture_file_sm(const char *fileName)
20 {
20 {
21 int i;
21 int i;
22
22
23 FILE *infile;
23 FILE *infile;
24 infile = fopen(fileName, "rb"); // open explicitely a binary file !!! ...
24 infile = fopen(fileName, "rb"); // open explicitely a binary file !!! ...
25 if(infile == NULL) {
25 if(infile == NULL) {
26 printf("Hello I cannot open the file! \n");
26 printf("Hello I cannot open the file! \n");
27 return 0;
27 return 0;
28 }
28 }
29 (void) fread(compressed_spectral_matrix_f0, sizeof(compressed_spectral_matrix_f0), 1, infile);
29 (void) fread(compressed_spectral_matrix_f0, sizeof(compressed_spectral_matrix_f0), 1, infile);
30 (void) fclose(infile);
30 (void) fclose(infile);
31
31
32 printf("Compressed_spectral_matrix_f0 : \n");
32 printf("Compressed_spectral_matrix_f0 : \n");
33 printf("Number of bins: %d\n", NB_BINS_COMPRESSED_MATRIX_f0);
33 printf("Number of bins: %d\n", NB_BINS_COMPRESSED_MATRIX_f0);
34 printf("Number of values per spectral matrix: %d\n", NB_VALUES_PER_SPECTRAL_MATRIX);
34 printf("Number of values per spectral matrix: %d\n", NB_VALUES_PER_SPECTRAL_MATRIX);
35 printf("Size of compressed_spectral_matrix_f0 : %lu\n", sizeof(compressed_spectral_matrix_f0));
35 printf("Size of compressed_spectral_matrix_f0 : %lu\n", sizeof(compressed_spectral_matrix_f0));
36
36
37 for(i=0; i<NB_BINS_COMPRESSED_MATRIX_f0; i++){
37 for(i=0; i<NB_BINS_COMPRESSED_MATRIX_f0; i++){
38
38
39 printf("\nBin number: %d\n", i);
39 printf("\nBin number: %d\n", i);
40
40
41 printf("Element %.2d (S11) (%.2d & --) => Re:%16.8e Im:%16.8e\n", 1, 0,
41 printf("Element %.2d (S11) (%.2d & --) => Re:%16.8e Im:%16.8e\n", 1, 0,
42 compressed_spectral_matrix_f0[i*NB_VALUES_PER_SPECTRAL_MATRIX+0], 0.);
42 compressed_spectral_matrix_f0[i*NB_VALUES_PER_SPECTRAL_MATRIX+0], 0.);
43 printf("Element %.2d (S12) (%.2d & %.2d) => Re:%16.8e Im:%16.8e\n", 2, 1, 2,
43 printf("Element %.2d (S12) (%.2d & %.2d) => Re:%16.8e Im:%16.8e\n", 2, 1, 2,
44 compressed_spectral_matrix_f0[i*NB_VALUES_PER_SPECTRAL_MATRIX+1], compressed_spectral_matrix_f0[i*NB_VALUES_PER_SPECTRAL_MATRIX+2]);
44 compressed_spectral_matrix_f0[i*NB_VALUES_PER_SPECTRAL_MATRIX+1], compressed_spectral_matrix_f0[i*NB_VALUES_PER_SPECTRAL_MATRIX+2]);
45 printf("Element %.2d (S13) (%.2d & %.2d) => Re:%16.8e Im:%16.8e\n", 3, 3, 4,
45 printf("Element %.2d (S13) (%.2d & %.2d) => Re:%16.8e Im:%16.8e\n", 3, 3, 4,
46 compressed_spectral_matrix_f0[i*NB_VALUES_PER_SPECTRAL_MATRIX+3], compressed_spectral_matrix_f0[i*NB_VALUES_PER_SPECTRAL_MATRIX+4]);
46 compressed_spectral_matrix_f0[i*NB_VALUES_PER_SPECTRAL_MATRIX+3], compressed_spectral_matrix_f0[i*NB_VALUES_PER_SPECTRAL_MATRIX+4]);
47 printf("Element %.2d (S14) (%.2d & %.2d) => Re:%16.8e Im:%16.8e\n", 4, 5, 6,
47 printf("Element %.2d (S14) (%.2d & %.2d) => Re:%16.8e Im:%16.8e\n", 4, 5, 6,
48 compressed_spectral_matrix_f0[i*NB_VALUES_PER_SPECTRAL_MATRIX+5], compressed_spectral_matrix_f0[i*NB_VALUES_PER_SPECTRAL_MATRIX+6]);
48 compressed_spectral_matrix_f0[i*NB_VALUES_PER_SPECTRAL_MATRIX+5], compressed_spectral_matrix_f0[i*NB_VALUES_PER_SPECTRAL_MATRIX+6]);
49 printf("Element %.2d (S15) (%.2d & %.2d) => Re:%16.8e Im:%16.8e\n", 5, 7, 8,
49 printf("Element %.2d (S15) (%.2d & %.2d) => Re:%16.8e Im:%16.8e\n", 5, 7, 8,
50 compressed_spectral_matrix_f0[i*NB_VALUES_PER_SPECTRAL_MATRIX+7], compressed_spectral_matrix_f0[i*NB_VALUES_PER_SPECTRAL_MATRIX+8]);
50 compressed_spectral_matrix_f0[i*NB_VALUES_PER_SPECTRAL_MATRIX+7], compressed_spectral_matrix_f0[i*NB_VALUES_PER_SPECTRAL_MATRIX+8]);
51 printf("Element %.2d (S22) (%.2d & --) => Re:%16.8e Im:%16.8e\n", 6, 9,
51 printf("Element %.2d (S22) (%.2d & --) => Re:%16.8e Im:%16.8e\n", 6, 9,
52 compressed_spectral_matrix_f0[i*NB_VALUES_PER_SPECTRAL_MATRIX+9], 0.);
52 compressed_spectral_matrix_f0[i*NB_VALUES_PER_SPECTRAL_MATRIX+9], 0.);
53 printf("Element %.2d (S23) (%.2d & %.2d) => Re:%16.8e Im:%16.8e\n", 7, 10, 11,
53 printf("Element %.2d (S23) (%.2d & %.2d) => Re:%16.8e Im:%16.8e\n", 7, 10, 11,
54 compressed_spectral_matrix_f0[i*NB_VALUES_PER_SPECTRAL_MATRIX+10], compressed_spectral_matrix_f0[i*NB_VALUES_PER_SPECTRAL_MATRIX+11]);
54 compressed_spectral_matrix_f0[i*NB_VALUES_PER_SPECTRAL_MATRIX+10], compressed_spectral_matrix_f0[i*NB_VALUES_PER_SPECTRAL_MATRIX+11]);
55 printf("Element %.2d (S24) (%.2d & %.2d) => Re:%16.8e Im:%16.8e\n", 8, 12, 13,
55 printf("Element %.2d (S24) (%.2d & %.2d) => Re:%16.8e Im:%16.8e\n", 8, 12, 13,
56 compressed_spectral_matrix_f0[i*NB_VALUES_PER_SPECTRAL_MATRIX+12], compressed_spectral_matrix_f0[i*NB_VALUES_PER_SPECTRAL_MATRIX+13]);
56 compressed_spectral_matrix_f0[i*NB_VALUES_PER_SPECTRAL_MATRIX+12], compressed_spectral_matrix_f0[i*NB_VALUES_PER_SPECTRAL_MATRIX+13]);
57 printf("Element %.2d (S25) (%.2d & %.2d) => Re:%16.8e Im:%16.8e\n", 9, 14, 15,
57 printf("Element %.2d (S25) (%.2d & %.2d) => Re:%16.8e Im:%16.8e\n", 9, 14, 15,
58 compressed_spectral_matrix_f0[i*NB_VALUES_PER_SPECTRAL_MATRIX+14], compressed_spectral_matrix_f0[i*NB_VALUES_PER_SPECTRAL_MATRIX+15]);
58 compressed_spectral_matrix_f0[i*NB_VALUES_PER_SPECTRAL_MATRIX+14], compressed_spectral_matrix_f0[i*NB_VALUES_PER_SPECTRAL_MATRIX+15]);
59 printf("Element %.2d (S33) (%.2d & --) => Re:%16.8e Im:%16.8e\n", 10, 16,
59 printf("Element %.2d (S33) (%.2d & --) => Re:%16.8e Im:%16.8e\n", 10, 16,
60 compressed_spectral_matrix_f0[i*NB_VALUES_PER_SPECTRAL_MATRIX+16], 0.);
60 compressed_spectral_matrix_f0[i*NB_VALUES_PER_SPECTRAL_MATRIX+16], 0.);
61 printf("Element %.2d (S34) (%.2d & %.2d) => Re:%16.8e Im:%16.8e\n", 11, 17, 18,
61 printf("Element %.2d (S34) (%.2d & %.2d) => Re:%16.8e Im:%16.8e\n", 11, 17, 18,
62 compressed_spectral_matrix_f0[i*NB_VALUES_PER_SPECTRAL_MATRIX+17], compressed_spectral_matrix_f0[i*NB_VALUES_PER_SPECTRAL_MATRIX+18]);
62 compressed_spectral_matrix_f0[i*NB_VALUES_PER_SPECTRAL_MATRIX+17], compressed_spectral_matrix_f0[i*NB_VALUES_PER_SPECTRAL_MATRIX+18]);
63 printf("Element %.2d (S35) (%.2d & %.2d) => Re:%16.8e Im:%16.8e\n", 12, 19, 20,
63 printf("Element %.2d (S35) (%.2d & %.2d) => Re:%16.8e Im:%16.8e\n", 12, 19, 20,
64 compressed_spectral_matrix_f0[i*NB_VALUES_PER_SPECTRAL_MATRIX+19], compressed_spectral_matrix_f0[i*NB_VALUES_PER_SPECTRAL_MATRIX+20]);
64 compressed_spectral_matrix_f0[i*NB_VALUES_PER_SPECTRAL_MATRIX+19], compressed_spectral_matrix_f0[i*NB_VALUES_PER_SPECTRAL_MATRIX+20]);
65 printf("Element %.2d (S44) (%.2d & --) => Re:%16.8e Im:%16.8e\n", 13, 21,
65 printf("Element %.2d (S44) (%.2d & --) => Re:%16.8e Im:%16.8e\n", 13, 21,
66 compressed_spectral_matrix_f0[i*NB_VALUES_PER_SPECTRAL_MATRIX+21], 0.);
66 compressed_spectral_matrix_f0[i*NB_VALUES_PER_SPECTRAL_MATRIX+21], 0.);
67 printf("Element %.2d (S45) (%.2d & %.2d) => Re:%16.8e Im:%16.8e\n", 14, 22, 23,
67 printf("Element %.2d (S45) (%.2d & %.2d) => Re:%16.8e Im:%16.8e\n", 14, 22, 23,
68 compressed_spectral_matrix_f0[i*NB_VALUES_PER_SPECTRAL_MATRIX+22], compressed_spectral_matrix_f0[i*NB_VALUES_PER_SPECTRAL_MATRIX+23]);
68 compressed_spectral_matrix_f0[i*NB_VALUES_PER_SPECTRAL_MATRIX+22], compressed_spectral_matrix_f0[i*NB_VALUES_PER_SPECTRAL_MATRIX+23]);
69 printf("Element %.2d (S55) (%.2d & --) => Re:%16.8e Im:%16.8e\n", 15, 24,
69 printf("Element %.2d (S55) (%.2d & --) => Re:%16.8e Im:%16.8e\n", 15, 24,
70 compressed_spectral_matrix_f0[i*NB_VALUES_PER_SPECTRAL_MATRIX+24], 0.);
70 compressed_spectral_matrix_f0[i*NB_VALUES_PER_SPECTRAL_MATRIX+24], 0.);
71
71
72 }
72 }
73 return 0;
73 return 0;
74 }
74 }
75
75
76
76
77
77
@@ -1,22 +1,22
1 // In the frame of RPW LFR Sofware ICD Issue1 Rev8 (05/07/2013) => R2 FSW
1 // In the frame of RPW LFR Sofware ICD Issue1 Rev8 (05/07/2013) => R2 FSW
2 // version 1.0: 31/07/2013
2 // version 1.0: 31/07/2013
3 // version 1.1: 02/04/2014
3 // version 1.1: 02/04/2014
4 // version 1.2: 30/04/2014
4 // version 1.2: 30/04/2014
5 // version 1.3: 02/05/2014
5 // version 1.3: 02/05/2014
6 // version 1.4: 16/05/2014
6 // version 1.4: 16/05/2014
7 // version 1.5: 20/05/2014
7 // version 1.5: 20/05/2014
8 // version 1.6: 19/12/2014
8 // version 1.6: 19/12/2014
9 // version 1.7: 15/01/2015 (modifs de Paul + correction erreurs qui se compensaient (LSB <=> MSB + indices [0,2] <=> [1,3])
9 // version 1.7: 15/01/2015 (modifs de Paul + correction erreurs qui se compensaient (LSB <=> MSB + indices [0,2] <=> [1,3])
10 // version 1.8: 02/02/2015 (gestion des divisions par zΓ©ro)
10 // version 1.8: 02/02/2015 (gestion des divisions par zΓ©ro)
11 // In the frame of RPW LFR Sofware ICD Issue3 Rev6 (27/01/2015) => R3 FSW
11 // In the frame of RPW LFR Sofware ICD Issue3 Rev6 (27/01/2015) => R3 FSW
12 // version 2.0: 19/06/2015
12 // version 2.0: 19/06/2015
13 // version 2.1: 22/06/2015 (modifs de Paul)
13 // version 2.1: 22/06/2015 (modifs de Paul)
14 // version 2.2: 23/06/2015 (modifs de l'ordre de dΓ©claration/dΓ©finition de init_k_coefficients dans basic_parameters.c ...)
14 // version 2.2: 23/06/2015 (modifs de l'ordre de dΓ©claration/dΓ©finition de init_k_coefficients dans basic_parameters.c ... + maintien des declarations dans le .h)
15
15
16
16
17 #ifndef FILE_UTILITIES_H
17 #ifndef FILE_UTILITIES_H
18 #define FILE_UTILITIES_H
18 #define FILE_UTILITIES_H
19
19
20 int lecture_file_sm(const char *fileName);
20 int lecture_file_sm(const char *fileName);
21
21
22 #endif // FILE_UTILITIES_H
22 #endif // FILE_UTILITIES_H
@@ -1,73 +1,73
1 // In the frame of RPW LFR Sofware ICD Issue1 Rev8 (05/07/2013) => R2 FSW
1 // In the frame of RPW LFR Sofware ICD Issue1 Rev8 (05/07/2013) => R2 FSW
2 // version 1.O: 31/07/2013
2 // version 1.O: 31/07/2013
3 // version 1.1: 02/04/2014
3 // version 1.1: 02/04/2014
4 // version 1.2: 30/04/2014
4 // version 1.2: 30/04/2014
5 // version 1.3: 02/05/2014
5 // version 1.3: 02/05/2014
6 // version 1.4: 16/05/2014
6 // version 1.4: 16/05/2014
7 // version 1.5: 20/05/2014
7 // version 1.5: 20/05/2014
8 // version 1.6: 19/12/2014
8 // version 1.6: 19/12/2014
9 // version 1.7: 15/01/2015 (modifs de Paul + correction erreurs qui se compensaient (LSB <=> MSB + indices [0,2] <=> [1,3])
9 // version 1.7: 15/01/2015 (modifs de Paul + correction erreurs qui se compensaient (LSB <=> MSB + indices [0,2] <=> [1,3])
10 // version 1.8: 02/02/2015 (gestion des divisions par zΓ©ro)
10 // version 1.8: 02/02/2015 (gestion des divisions par zΓ©ro)
11 // In the frame of RPW LFR Sofware ICD Issue3 Rev6 (27/01/2015) => R3 FSW
11 // In the frame of RPW LFR Sofware ICD Issue3 Rev6 (27/01/2015) => R3 FSW
12 // version 2.0: 19/06/2015
12 // version 2.0: 19/06/2015
13 // version 2.1: 22/06/2015 (modifs de Paul)
13 // version 2.1: 22/06/2015 (modifs de Paul)
14 // version 2.2: 23/06/2015 (modifs de l'ordre de dΓ©claration/dΓ©finition de init_k_coefficients dans basic_parameters.c ...)
14 // version 2.2: 23/06/2015 (modifs de l'ordre de dΓ©claration/dΓ©finition de init_k_coefficients dans basic_parameters.c ... + maintien des declarations dans le .h)
15
15
16 #include <stdio.h>
16 #include <stdio.h>
17
17
18 #include "file_utilities.h"
18 #include "file_utilities.h"
19 #include "basic_parameters_utilities.h"
19 #include "basic_parameters_utilities.h"
20 #include "basic_parameters.h"
20 #include "basic_parameters.h"
21
21
22 int main(void)
22 int main(void)
23 {
23 {
24 const char *filename;
24 const char *filename;
25 printf("Hello World!\n\n");
25 printf("Hello World!\n\n");
26
26
27 #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
27 #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
28 //LSB FIRST
28 //LSB FIRST
29 printf("The multi-byte quantities are laid out in a LSB FIRST (little endian) fashion \n\n");
29 printf("The multi-byte quantities are laid out in a LSB FIRST (little endian) fashion \n\n");
30 #endif
30 #endif
31
31
32 #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
32 #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
33 //MSB FIRST
33 //MSB FIRST
34 printf("The multi-byte quantities are laid out in a MSB FIRST (big endian) fashion\n\n");
34 printf("The multi-byte quantities are laid out in a MSB FIRST (big endian) fashion\n\n");
35 #endif
35 #endif
36
36
37 filename="/WIN/Users/chust/DD CHUST/Missions/Solar Orbiter/LFR/Prog C/tests bp Paul/tests7/sm_test2_R3.dat";
37 filename="/WIN/Users/chust/DD CHUST/Missions/Solar Orbiter/LFR/Prog C/tests bp Paul/tests7/sm_test2_R3.dat";
38 lecture_file_sm(filename);
38 lecture_file_sm(filename);
39
39
40 printf("\n");
40 printf("\n");
41
41
42 init_k_coefficients(k_coefficients_f0, NB_BINS_COMPRESSED_MATRIX_f0);
42 init_k_coefficients(k_coefficients_f0, NB_BINS_COMPRESSED_MATRIX_f0);
43 init_k_coefficients(k_coefficients_f1, NB_BINS_COMPRESSED_MATRIX_f1);
43 init_k_coefficients(k_coefficients_f1, NB_BINS_COMPRESSED_MATRIX_f1);
44 init_k_coefficients(k_coefficients_f2, NB_BINS_COMPRESSED_MATRIX_f2);
44 init_k_coefficients(k_coefficients_f2, NB_BINS_COMPRESSED_MATRIX_f2);
45
45
46 printf("\n\n");
46 printf("\n\n");
47
47
48 BP1_set(compressed_spectral_matrix_f0, k_coefficients_f0, NB_BINS_COMPRESSED_MATRIX_f0, LFR_BP1_f0);
48 BP1_set(compressed_spectral_matrix_f0, k_coefficients_f0, NB_BINS_COMPRESSED_MATRIX_f0, LFR_BP1_f0);
49
49
50 printf("\n");
50 printf("\n");
51
51
52 BP2_set(compressed_spectral_matrix_f0, NB_BINS_COMPRESSED_MATRIX_f0, LFR_BP2_f0);
52 BP2_set(compressed_spectral_matrix_f0, NB_BINS_COMPRESSED_MATRIX_f0, LFR_BP2_f0);
53
53
54 return 0;
54 return 0;
55 }
55 }
56
56
57
57
58
58
59
59
60
60
61
61
62
62
63
63
64
64
65
65
66
66
67
67
68
68
69
69
70
70
71
71
72
72
73
73
General Comments 0
You need to be logged in to leave comments. Login now