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