##// END OF EJS Templates

Compare Commits r7:ccd69f4e7a60...r9:19349b3a5e90

Target:

Source:

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