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