##// END OF EJS Templates
version 1.1 qui prends en compte les modifs de Paul (cependant question des short int à faire encore ...)
chust -
r5:4f3902999c69 default
parent child
Show More
1 NO CONTENT: new file 100755, binary diff hidden
NO CONTENT: new file 100755, binary diff hidden
@@ -0,0 +1,11
1 # --------------------------------------------------------
2 # MISSION NAME : LFR/RPW/SO
3 # DATA NAME : test matrix
4 # NB_TOTAL_VALUES : 25
5 # NB_COMPONENTS : 25
6 # FORMAT : (25(e16.8))
7 # UNIT : floating
8 # --------------------------------------------------------
9 # BEGIN DATA
10 1.02217712e+06 -8.58216250e+04 -3.22199043e+04 1.01597820e+05 8.10333875e+05 1.19030141e+05 -8.69636688e+05 5.01504031e+05 -1.01948547e+05 1.35475020e+04 -3.67825469e+04 -1.10950273e+05 2.10715000e+04 4.49727383e+04 -4.37282031e+04 3.83337695e+03 1.05317175e+06 -4.04155312e+05 -1.32987891e+05 1.49277250e+05 -4.39122625e+05 9.46006250e+05 2.64386625e+05 3.71843125e+05 3.39770000e+05
11 # END DATA
@@ -0,0 +1,18
1 TEMPLATE = app
2 CONFIG += console
3 CONFIG -= app_bundle
4 CONFIG -= qt
5
6 DEFINES += DEBUG_TCH
7 #DEFINES += MSB_FIRST_TCH # SPARC convention
8 DEFINES += LSB_FIRST_TCH # PC convention
9
10 SOURCES += main.c \
11 basic_parameters.c \
12 file_utilities.c
13
14 HEADERS += \
15 basic_parameters.h \
16 file_utilities.h
17
18
@@ -1,5 +1,6
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: 31/07/2013
2 // version 1.0: 31/07/2013
3 // version 1.1: 02/04/2014
3
4
4 #include "basic_parameters.h"
5 #include "basic_parameters.h"
5 #include <math.h>
6 #include <math.h>
@@ -88,7 +89,7 void init_k_f0( void )
88
89
89 float alpha_M = 45 * (3.1415927/180);
90 float alpha_M = 45 * (3.1415927/180);
90
91
91 void BP1_set( float * compressed_spec_mat, unsigned char nb_bins_compressed_spec_mat, unsigned char * LFR_BP1 ){
92 void BP1_set( float * compressed_spec_mat, unsigned char nb_bins_compressed_spec_mat, unsigned char * lfr_bp1 ){
92 int i, exponent;
93 int i, exponent;
93 float PSDB;
94 float PSDB;
94 float PSDE;
95 float PSDE;
@@ -110,8 +111,8 void BP1_set( float * compressed_spec_ma
110 signed char nbitexp;
111 signed char nbitexp;
111 signed char nbitsig;
112 signed char nbitsig;
112 signed char expmin;
113 signed char expmin;
113 signed char expmax; // 8 bits
114 signed char expmax; // 8 bits
114 short int rangesig; // 16 bits
115 short int rangesig; // 16 bits
115 unsigned short int psd;
116 unsigned short int psd;
116 unsigned short int tmp_u_short_int; // 16 bits
117 unsigned short int tmp_u_short_int; // 16 bits
117 unsigned short int *pt_u_short_int; // pointer on unsigned 16-bit words
118 unsigned short int *pt_u_short_int; // pointer on unsigned 16-bit words
@@ -121,8 +122,8 void BP1_set( float * compressed_spec_ma
121 init_k_f0();
122 init_k_f0();
122
123
123 #ifdef DEBUG_TCH
124 #ifdef DEBUG_TCH
125 printf("BP1 : \n");
124 printf("Number of bins: %d\n", nb_bins_compressed_spec_mat);
126 printf("Number of bins: %d\n", nb_bins_compressed_spec_mat);
125 printf("BP1 : \n");
126 #endif
127 #endif
127
128
128 // initialization for managing the exponents of the floating point data:
129 // initialization for managing the exponents of the floating point data:
@@ -141,9 +142,9 void BP1_set( float * compressed_spec_ma
141 for(i=0; i<nb_bins_compressed_spec_mat; i++){
142 for(i=0; i<nb_bins_compressed_spec_mat; i++){
142 //==============================================
143 //==============================================
143 // BP1 PSDB == PA_LFR_SC_BP1_PB_F0 == 12 bits = 5 bits (exponent) + 7 bits (significand)
144 // BP1 PSDB == PA_LFR_SC_BP1_PB_F0 == 12 bits = 5 bits (exponent) + 7 bits (significand)
144 PSDB = compressed_spec_mat[i*30] // S11
145 PSDB = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX] // S11
145 + compressed_spec_mat[i*30+9] // S22
146 + compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+9] // S22
146 + compressed_spec_mat[i*30+16]; // S33
147 + compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+16]; // S33
147
148
148 significand = frexpf(PSDB/3, &exponent); // 0.5 <= significand < 1
149 significand = frexpf(PSDB/3, &exponent); // 0.5 <= significand < 1
149 // PSDB/3 = significand * 2^exponent
150 // PSDB/3 = significand * 2^exponent
@@ -166,27 +167,28 void BP1_set( float * compressed_spec_ma
166 // where just the first nbitsig bits are used (0, ..., 2^nbitsig-1)
167 // where just the first nbitsig bits are used (0, ..., 2^nbitsig-1)
167 tmp_u_short_int = (unsigned short int) (exponent-expmin); // Shift and cast into a 16-bit unsigned int
168 tmp_u_short_int = (unsigned short int) (exponent-expmin); // Shift and cast into a 16-bit unsigned int
168 // where just the first nbitexp bits are used (0, ..., 2^nbitexp-1)
169 // where just the first nbitexp bits are used (0, ..., 2^nbitexp-1)
169 pt_u_short_int = (unsigned short int*) &LFR_BP1[i*9+2]; // Affect an unsigned short int pointer with the
170 pt_u_short_int = (unsigned short int*) &lfr_bp1[i*NB_BYTES_BP1+2]; // Affect an unsigned short int pointer with the
170 // adress where the 16-bit word result will be stored
171 // adress where the 16-bit word result will be stored
171 *pt_u_short_int = psd | (tmp_u_short_int << nbitsig); // Put the exponent bits (nbitexp) next to the
172 *pt_u_short_int = psd | (tmp_u_short_int << nbitsig); // Put the exponent bits (nbitexp) next to the
172 // left place of the significand bits (nbitsig), making
173 // left place of the significand bits (nbitsig), making
173 // the 16-bit word to be recorded, and record it using the pointer
174 // the 16-bit word to be recorded, and record it using the pointer
174 #ifdef DEBUG_TCH
175 #ifdef DEBUG_TCH
176 printf("\nBin number: %d\n", i);
175 printf("PSDB / 3 : %16.8e\n",PSDB/3);
177 printf("PSDB / 3 : %16.8e\n",PSDB/3);
176 printf("significand : %16.8e\n",significand);
178 printf("significand : %16.8e\n",significand);
177 printf("exponent : %d\n" ,exponent);
179 printf("exponent : %d\n" ,exponent);
178 printf("psd for PSDB significand : %d\n",psd);
180 printf("psd for PSDB significand : %d\n",psd);
179 printf("tmp_u_short_int for PSDB exponent : %d\n",tmp_u_short_int);
181 printf("tmp_u_short_int for PSDB exponent : %d\n",tmp_u_short_int);
180 printf("*pt_u_short_int for PSDB exponent + significand: %.3d or %.4x\n",*pt_u_short_int, *pt_u_short_int);
182 printf("*pt_u_short_int for PSDB exponent + significand: %.3d or %.4x\n",*pt_u_short_int, *pt_u_short_int);
181 printf("LFR_BP1[i*9+3] : %.3d or %.2x\n",LFR_BP1[i*9+3], LFR_BP1[i*9+3]);
183 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]);
182 printf("LFR_BP1[i*9+2] : %.3d or %.2x\n",LFR_BP1[i*9+2], LFR_BP1[i*9+2]);
184 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]);
183 #endif
185 #endif
184 //==============================================
186 //==============================================
185 // BP1 PSDE == PA_LFR_SC_BP1_PE_F0 == 12 bits = 5 bits (exponent) + 7 bits (significand)
187 // BP1 PSDE == PA_LFR_SC_BP1_PE_F0 == 12 bits = 5 bits (exponent) + 7 bits (significand)
186 PSDE = compressed_spec_mat[i*30+21] * k_f0[i][K44_PE] // S44
188 PSDE = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+21] * k_f0[i][K44_PE] // S44
187 + compressed_spec_mat[i*30+24] * k_f0[i][K55_PE] // S55
189 + compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+24] * k_f0[i][K55_PE] // S55
188 + compressed_spec_mat[i*30+22] * k_f0[i][K45_PE_RE] // S45 Re
190 + compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+22] * k_f0[i][K45_PE_RE] // S45 Re
189 - compressed_spec_mat[i*30+23] * k_f0[i][K45_PE_IM]; // S45 Im
191 - compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+23] * k_f0[i][K45_PE_IM]; // S45 Im
190
192
191 significand = frexpf(PSDE/2, &exponent); // 0.5 <= significand < 1
193 significand = frexpf(PSDE/2, &exponent); // 0.5 <= significand < 1
192 // PSDE/2 = significand * 2^exponent
194 // PSDE/2 = significand * 2^exponent
@@ -210,7 +212,7 void BP1_set( float * compressed_spec_ma
210 // where just the first nbitsig bits are used (0, ..., 2^nbitsig-1)
212 // where just the first nbitsig bits are used (0, ..., 2^nbitsig-1)
211 tmp_u_short_int = (unsigned short int) (exponent-expmin); // Shift and cast into a 16-bit unsigned int
213 tmp_u_short_int = (unsigned short int) (exponent-expmin); // Shift and cast into a 16-bit unsigned int
212 // where just the first nbitexp bits are used (0, ..., 2^nbitexp-1)
214 // where just the first nbitexp bits are used (0, ..., 2^nbitexp-1)
213 pt_u_short_int = (unsigned short int*) &LFR_BP1[i*9+0]; // Affect an unsigned short int pointer with the
215 pt_u_short_int = (unsigned short int*) &lfr_bp1[i*NB_BYTES_BP1+0]; // Affect an unsigned short int pointer with the
214 // adress where the 16-bit word result will be stored
216 // adress where the 16-bit word result will be stored
215 *pt_u_short_int = psd | (tmp_u_short_int << nbitsig); // Put the exponent bits (nbitexp) next to the
217 *pt_u_short_int = psd | (tmp_u_short_int << nbitsig); // Put the exponent bits (nbitexp) next to the
216 // left place of the significand bits (nbitsig), making
218 // left place of the significand bits (nbitsig), making
@@ -222,39 +224,39 void BP1_set( float * compressed_spec_ma
222 printf("psd for PSDE significand : %d\n",psd);
224 printf("psd for PSDE significand : %d\n",psd);
223 printf("tmp_u_short_int for PSDE exponent : %d\n",tmp_u_short_int);
225 printf("tmp_u_short_int for PSDE exponent : %d\n",tmp_u_short_int);
224 printf("*pt_u_short_int for PSDE exponent + significand: %.3d or %.4x\n",*pt_u_short_int, *pt_u_short_int);
226 printf("*pt_u_short_int for PSDE exponent + significand: %.3d or %.4x\n",*pt_u_short_int, *pt_u_short_int);
225 printf("LFR_BP1[i*9+1] : %.3d or %.2x\n",LFR_BP1[i*9+1], LFR_BP1[i*9+1]);
227 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]);
226 printf("LFR_BP1[i*9+0] : %.3d or %.2x\n",LFR_BP1[i*9+0], LFR_BP1[i*9+0]);
228 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]);
227 #endif
229 #endif
228 //==============================================================================
230 //==============================================================================
229 // BP1 normal wave vector == PA_LFR_SC_BP1_NVEC_V0_F0 == 8 bits
231 // BP1 normal wave vector == PA_LFR_SC_BP1_NVEC_V0_F0 == 8 bits
230 // == PA_LFR_SC_BP1_NVEC_V1_F0 == 8 bits
232 // == PA_LFR_SC_BP1_NVEC_V1_F0 == 8 bits
231 // == PA_LFR_SC_BP1_NVEC_V2_F0 == 1 sign bit
233 // == PA_LFR_SC_BP1_NVEC_V2_F0 == 1 sign bit
232 tmp = sqrt( compressed_spec_mat[i*30+2] *compressed_spec_mat[i*30+2] //Im S12
234 tmp = sqrt( compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+2] *compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+2] //Im S12
233 +compressed_spec_mat[i*30+4] *compressed_spec_mat[i*30+4] //Im S13
235 +compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+4] *compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+4] //Im S13
234 +compressed_spec_mat[i*30+11]*compressed_spec_mat[i*30+11] //Im S23
236 +compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+11]*compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+11] //Im S23
235 );
237 );
236 NVEC_V0 = compressed_spec_mat[i*30+11]/ tmp; // S23 Im => n1
238 NVEC_V0 = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+11]/ tmp; // S23 Im => n1
237 NVEC_V1 = -compressed_spec_mat[i*30+4] / tmp; // S13 Im => n2
239 NVEC_V1 = -compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+4] / tmp; // S13 Im => n2
238 NVEC_V2 = compressed_spec_mat[i*30+2] / tmp; // S12 Im => n3
240 NVEC_V2 = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+2] / tmp; // S12 Im => n3
239
241
240 LFR_BP1[i*9+4] = (unsigned char) (NVEC_V0*127.5 + 128); // shift and cast into a 8-bit unsigned char (0, ..., 255) with rounding
242 lfr_bp1[i*NB_BYTES_BP1+4] = (unsigned char) (NVEC_V0*127.5 + 128); // shift and cast into a 8-bit unsigned char (0, ..., 255) with rounding
241 LFR_BP1[i*9+5] = (unsigned char) (NVEC_V1*127.5 + 128); // shift and cast into a 8-bit unsigned char (0, ..., 255) with rounding
243 lfr_bp1[i*NB_BYTES_BP1+5] = (unsigned char) (NVEC_V1*127.5 + 128); // shift and cast into a 8-bit unsigned char (0, ..., 255) with rounding
242 pt_u_char = (unsigned char*) &NVEC_V2; // affect an unsigned char pointer with the adress of NVEC_V2
244 pt_u_char = (unsigned char*) &NVEC_V2; // affect an unsigned char pointer with the adress of NVEC_V2
243 #ifdef LSB_FIRST_TCH
245 #ifdef LSB_FIRST_TCH
244 LFR_BP1[i*9+6] = pt_u_char[3] & 0x80; // extract the sign bit of NVEC_V2 (32-bit float, sign bit in the 4th octet:PC convention)
246 lfr_bp1[i*NB_BYTES_BP1+6] = pt_u_char[3] & 0x80; // extract the sign bit of NVEC_V2 (32-bit float, sign bit in the 4th octet:PC convention)
245 // record it at the 8th bit position (from the right to the left) of LFR_BP1[i*9+6]
247 // record it at the 8th bit position (from the right to the left) of lfr_bp1[i*NB_BYTES_BP1+6]
246 #endif
248 #endif
247 #ifdef MSB_FIRST_TCH
249 #ifdef MSB_FIRST_TCH
248 LFR_BP1[i*9+6] = pt_u_char[0] & 0x80; // extract the sign bit of NVEC_V2 (32-bit float, sign bit in the 0th octet:SPARC convention)
250 lfr_bp1[i*NB_BYTES_BP1+6] = pt_u_char[0] & 0x80; // extract the sign bit of NVEC_V2 (32-bit float, sign bit in the 0th octet:SPARC convention)
249 // record it at the 8th bit position (from the right to the left) of LFR_BP1[i*9+6]
251 // record it at the 8th bit position (from the right to the left) of lfr_bp1[i*NB_BYTES_BP1+6]
250 #endif
252 #endif
251 #ifdef DEBUG_TCH
253 #ifdef DEBUG_TCH
252 printf("NVEC_V0 : %16.8e\n",NVEC_V0);
254 printf("NVEC_V0 : %16.8e\n",NVEC_V0);
253 printf("NVEC_V1 : %16.8e\n",NVEC_V1);
255 printf("NVEC_V1 : %16.8e\n",NVEC_V1);
254 printf("NVEC_V2 : %16.8e\n",NVEC_V2);
256 printf("NVEC_V2 : %16.8e\n",NVEC_V2);
255 printf("LFR_BP1[i*9+4] for NVEC_V0 : %u\n",LFR_BP1[i*9+4]);
257 printf("lfr_bp1[i*NB_BYTES_BP1+4] for NVEC_V0 : %u\n",lfr_bp1[i*NB_BYTES_BP1+4]);
256 printf("LFR_BP1[i*9+5] for NVEC_V1 : %u\n",LFR_BP1[i*9+5]);
258 printf("lfr_bp1[i*NB_BYTES_BP1+5] for NVEC_V1 : %u\n",lfr_bp1[i*NB_BYTES_BP1+5]);
257 printf("LFR_BP1[i*9+6] for NVEC_V2 : %u\n",LFR_BP1[i*9+6]);
259 printf("lfr_bp1[i*NB_BYTES_BP1+6] for NVEC_V2 : %u\n",lfr_bp1[i*NB_BYTES_BP1+6]);
258 #endif
260 #endif
259 //=======================================================
261 //=======================================================
260 // BP1 ellipticity == PA_LFR_SC_BP1_ELLIP_F0 == 4 bits
262 // BP1 ellipticity == PA_LFR_SC_BP1_ELLIP_F0 == 4 bits
@@ -262,81 +264,81 void BP1_set( float * compressed_spec_ma
262
264
263 tmp_u_char = (unsigned char) (aux*15 + 0.5); // shift and cast into a 8-bit unsigned char with rounding
265 tmp_u_char = (unsigned char) (aux*15 + 0.5); // shift and cast into a 8-bit unsigned char with rounding
264 // where just the first 4 bits are used (0, ..., 15)
266 // where just the first 4 bits are used (0, ..., 15)
265 LFR_BP1[i*9+6] = LFR_BP1[i*9+6] | (tmp_u_char << 3); // put these 4 bits next to the right place
267 lfr_bp1[i*NB_BYTES_BP1+6] = lfr_bp1[i*NB_BYTES_BP1+6] | (tmp_u_char << 3); // put these 4 bits next to the right place
266 // of the sign bit of NVEC_V2 (recorded
268 // of the sign bit of NVEC_V2 (recorded
267 // previously in LFR_BP1[i*9+6])
269 // previously in lfr_bp1[i*NB_BYTES_BP1+6])
268 #ifdef DEBUG_TCH
270 #ifdef DEBUG_TCH
269 printf("ellipticity : %16.8e\n",aux);
271 printf("ellipticity : %16.8e\n",aux);
270 printf("tmp_u_char for ellipticity : %u\n",tmp_u_char);
272 printf("tmp_u_char for ellipticity : %u\n",tmp_u_char);
271 printf("LFR_BP1[i*9+6] for NVEC_V2 + ellipticity : %u\n",LFR_BP1[i*9+6]);
273 printf("lfr_bp1[i*NB_BYTES_BP1+6] for NVEC_V2 + ellipticity : %u\n",lfr_bp1[i*NB_BYTES_BP1+6]);
272 #endif
274 #endif
273 //==============================================================
275 //==============================================================
274 // BP1 degree of polarization == PA_LFR_SC_BP1_DOP_F0 == 3 bits
276 // BP1 degree of polarization == PA_LFR_SC_BP1_DOP_F0 == 3 bits
275 tr_SB_SB = compressed_spec_mat[i*30] *compressed_spec_mat[i*30]
277 tr_SB_SB = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX] *compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX]
276 + compressed_spec_mat[i*30+9] *compressed_spec_mat[i*30+9]
278 + compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+9] *compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+9]
277 + compressed_spec_mat[i*30+16] *compressed_spec_mat[i*30+16]
279 + compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+16] *compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+16]
278 + 2 * compressed_spec_mat[i*30+1] *compressed_spec_mat[i*30+1]
280 + 2 * compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+1] *compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+1]
279 + 2 * compressed_spec_mat[i*30+2] *compressed_spec_mat[i*30+2]
281 + 2 * compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+2] *compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+2]
280 + 2 * compressed_spec_mat[i*30+3] *compressed_spec_mat[i*30+3]
282 + 2 * compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+3] *compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+3]
281 + 2 * compressed_spec_mat[i*30+4] *compressed_spec_mat[i*30+4]
283 + 2 * compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+4] *compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+4]
282 + 2 * compressed_spec_mat[i*30+10]*compressed_spec_mat[i*30+10]
284 + 2 * compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+10]*compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+10]
283 + 2 * compressed_spec_mat[i*30+11]*compressed_spec_mat[i*30+11];
285 + 2 * compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+11]*compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+11];
284 aux = PSDB*PSDB;
286 aux = PSDB*PSDB;
285 tmp = ( 3*tr_SB_SB - aux ) / ( 2 * aux ); // compute the degree of polarisation
287 tmp = ( 3*tr_SB_SB - aux ) / ( 2 * aux ); // compute the degree of polarisation
286
288
287 tmp_u_char = (unsigned char) (tmp*7 + 0.5);// shift and cast into a 8-bit unsigned char with rounding
289 tmp_u_char = (unsigned char) (tmp*7 + 0.5);// shift and cast into a 8-bit unsigned char with rounding
288 // where just the first 3 bits are used (0, ..., 7)
290 // where just the first 3 bits are used (0, ..., 7)
289 LFR_BP1[i*9+6] = LFR_BP1[i*9+6] | tmp_u_char; // record these 3 bits at the 3 first bit positions
291 lfr_bp1[i*NB_BYTES_BP1+6] = lfr_bp1[i*NB_BYTES_BP1+6] | tmp_u_char; // record these 3 bits at the 3 first bit positions
290 // (from the right to the left) of LFR_BP1[i*9+6]
292 // (from the right to the left) of lfr_bp1[i*NB_BYTES_BP1+6]
291 #ifdef DEBUG_TCH
293 #ifdef DEBUG_TCH
292 printf("DOP : %16.8e\n",tmp);
294 printf("DOP : %16.8e\n",tmp);
293 printf("tmp_u_char for DOP : %u\n",tmp_u_char);
295 printf("tmp_u_char for DOP : %u\n",tmp_u_char);
294 printf("LFR_BP1[i*9+6] for NVEC_V2 + ellipticity + DOP : %u\n",LFR_BP1[i*9+6]);
296 printf("lfr_bp1[i*NB_BYTES_BP1+6] for NVEC_V2 + ellipticity + DOP : %u\n",lfr_bp1[i*NB_BYTES_BP1+6]);
295 #endif
297 #endif
296 //=======================================================================================
298 //=======================================================================================
297 // BP1 X_SO-component of the Poynting flux == PA_LFR_SC_BP1_SX_F0 == 8 (+ 2) bits
299 // BP1 X_SO-component of the Poynting flux == PA_LFR_SC_BP1_SX_F0 == 8 (+ 2) bits
298 // = 5 bits (exponent) + 3 bits (significand)
300 // = 5 bits (exponent) + 3 bits (significand)
299 // + 1 sign bit + 1 argument bit (two sectors)
301 // + 1 sign bit + 1 argument bit (two sectors)
300 e_cross_b_re = compressed_spec_mat[i*30+17]*k_f0[i][K34_SX_RE] //S34 Re
302 e_cross_b_re = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+17]*k_f0[i][K34_SX_RE] //S34 Re
301 + compressed_spec_mat[i*30+19]*k_f0[i][K35_SX_RE] //S35 Re
303 + compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+19]*k_f0[i][K35_SX_RE] //S35 Re
302 + compressed_spec_mat[i*30+5] *k_f0[i][K14_SX_RE] //S14 Re
304 + compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+5] *k_f0[i][K14_SX_RE] //S14 Re
303 + compressed_spec_mat[i*30+7] *k_f0[i][K15_SX_RE] //S15 Re
305 + compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+7] *k_f0[i][K15_SX_RE] //S15 Re
304 + compressed_spec_mat[i*30+12]*k_f0[i][K24_SX_RE] //S24 Re
306 + compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+12]*k_f0[i][K24_SX_RE] //S24 Re
305 + compressed_spec_mat[i*30+14]*k_f0[i][K25_SX_RE] //S25 Re
307 + compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+14]*k_f0[i][K25_SX_RE] //S25 Re
306 + compressed_spec_mat[i*30+18]*k_f0[i][K34_SX_IM] //S34 Im
308 + compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+18]*k_f0[i][K34_SX_IM] //S34 Im
307 + compressed_spec_mat[i*30+20]*k_f0[i][K35_SX_IM] //S35 Im
309 + compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+20]*k_f0[i][K35_SX_IM] //S35 Im
308 + compressed_spec_mat[i*30+6] *k_f0[i][K14_SX_IM] //S14 Im
310 + compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+6] *k_f0[i][K14_SX_IM] //S14 Im
309 + compressed_spec_mat[i*30+8] *k_f0[i][K15_SX_IM] //S15 Im
311 + compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+8] *k_f0[i][K15_SX_IM] //S15 Im
310 + compressed_spec_mat[i*30+13]*k_f0[i][K24_SX_IM] //S24 Im
312 + compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+13]*k_f0[i][K24_SX_IM] //S24 Im
311 + compressed_spec_mat[i*30+15]*k_f0[i][K25_SX_IM]; //S25 Im
313 + compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+15]*k_f0[i][K25_SX_IM]; //S25 Im
312 // Im(S_ji) = -Im(S_ij)
314 // Im(S_ji) = -Im(S_ij)
313 // k_ji = k_ij
315 // k_ji = k_ij
314 e_cross_b_im = compressed_spec_mat[i*30+17]*k_f0[i][K34_SX_IM] //S34 Re
316 e_cross_b_im = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+17]*k_f0[i][K34_SX_IM] //S34 Re
315 + compressed_spec_mat[i*30+19]*k_f0[i][K35_SX_IM] //S35 Re
317 + compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+19]*k_f0[i][K35_SX_IM] //S35 Re
316 + compressed_spec_mat[i*30+5] *k_f0[i][K14_SX_IM] //S14 Re
318 + compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+5] *k_f0[i][K14_SX_IM] //S14 Re
317 + compressed_spec_mat[i*30+7] *k_f0[i][K15_SX_IM] //S15 Re
319 + compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+7] *k_f0[i][K15_SX_IM] //S15 Re
318 + compressed_spec_mat[i*30+12]*k_f0[i][K24_SX_IM] //S24 Re
320 + compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+12]*k_f0[i][K24_SX_IM] //S24 Re
319 + compressed_spec_mat[i*30+14]*k_f0[i][K25_SX_IM] //S25 Re
321 + compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+14]*k_f0[i][K25_SX_IM] //S25 Re
320 - compressed_spec_mat[i*30+18]*k_f0[i][K34_SX_RE] //S34 Im
322 - compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+18]*k_f0[i][K34_SX_RE] //S34 Im
321 - compressed_spec_mat[i*30+20]*k_f0[i][K35_SX_RE] //S35 Im
323 - compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+20]*k_f0[i][K35_SX_RE] //S35 Im
322 - compressed_spec_mat[i*30+6] *k_f0[i][K14_SX_RE] //S14 Im
324 - compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+6] *k_f0[i][K14_SX_RE] //S14 Im
323 - compressed_spec_mat[i*30+8] *k_f0[i][K15_SX_RE] //S15 Im
325 - compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+8] *k_f0[i][K15_SX_RE] //S15 Im
324 - compressed_spec_mat[i*30+13]*k_f0[i][K24_SX_RE] //S24 Im
326 - compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+13]*k_f0[i][K24_SX_RE] //S24 Im
325 - compressed_spec_mat[i*30+15]*k_f0[i][K25_SX_RE]; //S25 Im
327 - compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+15]*k_f0[i][K25_SX_RE]; //S25 Im
326 #ifdef DEBUG_TCH
328 #ifdef DEBUG_TCH
327 printf("ReaSX / 2 : %16.8e\n",e_cross_b_re/2);
329 printf("ReaSX / 2 : %16.8e\n",e_cross_b_re/2);
328 #endif
330 #endif
329 pt_u_char = (unsigned char*) &e_cross_b_re; // Affect an unsigned char pointer with the adress of e_cross_b_re
331 pt_u_char = (unsigned char*) &e_cross_b_re; // Affect an unsigned char pointer with the adress of e_cross_b_re
330 #ifdef LSB_FIRST_TCH
332 #ifdef LSB_FIRST_TCH
331 LFR_BP1[i*9+1] = LFR_BP1[i*9+1] | (pt_u_char[3] & 0x80); // Extract its sign bit (32-bit float, sign bit in the 4th octet:PC convention)
333 lfr_bp1[i*NB_BYTES_BP1+1] = lfr_bp1[i*NB_BYTES_BP1+1] | (pt_u_char[3] & 0x80); // Extract its sign bit (32-bit float, sign bit in the 4th octet:PC convention)
332 // Record it at the 8th bit position (from the right to the left)
334 // Record it at the 8th bit position (from the right to the left)
333 // of LFR_BP1[i*9+1]
335 // of lfr_bp1[i*NB_BYTES_BP1+1]
334 pt_u_char[3] = (pt_u_char[3] & 0x7f); // Make e_cross_b_re be positive in any case: |ReaSX|
336 pt_u_char[3] = (pt_u_char[3] & 0x7f); // Make e_cross_b_re be positive in any case: |ReaSX|
335 #endif
337 #endif
336 #ifdef MSB_FIRST_TCH
338 #ifdef MSB_FIRST_TCH
337 LFR_BP1[i*9+1] = LFR_BP1[i*9+1] | (pt_u_char[0] & 0x80); // Extract its sign bit (32-bit float, sign bit in the 0th octet:SPARC convention)
339 lfr_bp1[i*NB_BYTES_BP1+1] = lfr_bp1[i*NB_BYTES_BP1+1] | (pt_u_char[0] & 0x80); // Extract its sign bit (32-bit float, sign bit in the 0th octet:SPARC convention)
338 // Record it at the 8th bit position (from the right to the left)
340 // Record it at the 8th bit position (from the right to the left)
339 // of LFR_BP1[i*9+1]
341 // of lfr_bp1[i*NB_BYTES_BP1+1]
340 pt_u_char[0] = (pt_u_char[0] & 0x7f); // Make e_cross_b_re be positive in any case: |ReaSX|
342 pt_u_char[0] = (pt_u_char[0] & 0x7f); // Make e_cross_b_re be positive in any case: |ReaSX|
341 #endif
343 #endif
342 significand = frexpf(e_cross_b_re/2, &exponent);// 0.5 <= significand < 1
344 significand = frexpf(e_cross_b_re/2, &exponent);// 0.5 <= significand < 1
@@ -357,7 +359,7 void BP1_set( float * compressed_spec_ma
357 significand = 0.5; // min value that can be recorded
359 significand = 0.5; // min value that can be recorded
358 }
360 }
359
361
360 LFR_BP1[i*9+7] = (unsigned char) ((significand*2-1)*7 + 0.5); // Shift and cast into a 8-bit unsigned char with rounding
362 lfr_bp1[i*NB_BYTES_BP1+7] = (unsigned char) ((significand*2-1)*7 + 0.5); // Shift and cast into a 8-bit unsigned char with rounding
361 // where just the first 3 bits are used (0, ..., 7)
363 // where just the first 3 bits are used (0, ..., 7)
362 tmp_u_char = (unsigned char) (exponent-expmin); // Shift and cast into a 8-bit unsigned char where
364 tmp_u_char = (unsigned char) (exponent-expmin); // Shift and cast into a 8-bit unsigned char where
363 // just the first 5 bits are used (0, ..., 2^5-1)
365 // just the first 5 bits are used (0, ..., 2^5-1)
@@ -365,14 +367,14 void BP1_set( float * compressed_spec_ma
365 printf("|ReaSX| / 2 : %16.8e\n",e_cross_b_re/2);
367 printf("|ReaSX| / 2 : %16.8e\n",e_cross_b_re/2);
366 printf("significand : %16.8e\n",significand);
368 printf("significand : %16.8e\n",significand);
367 printf("exponent : %d\n" ,exponent);
369 printf("exponent : %d\n" ,exponent);
368 printf("LFR_BP1[i*9+7] for ReaSX significand : %u\n",LFR_BP1[i*9+7]);
370 printf("lfr_bp1[i*NB_BYTES_BP1+7] for ReaSX significand : %u\n",lfr_bp1[i*NB_BYTES_BP1+7]);
369 printf("tmp_u_char for ReaSX exponent : %d\n",tmp_u_char);
371 printf("tmp_u_char for ReaSX exponent : %d\n",tmp_u_char);
370 #endif
372 #endif
371 LFR_BP1[i*9+7] = LFR_BP1[i*9+7] | (tmp_u_char << 3); // shift these 5 bits to the left before logical addition
373 lfr_bp1[i*NB_BYTES_BP1+7] = lfr_bp1[i*NB_BYTES_BP1+7] | (tmp_u_char << 3); // shift these 5 bits to the left before logical addition
372 // with LFR_BP1[i*9+7]
374 // with lfr_bp1[i*NB_BYTES_BP1+7]
373 #ifdef DEBUG_TCH
375 #ifdef DEBUG_TCH
374 printf("LFR_BP1[i*9+7] for ReaSX exponent + significand : %u\n",LFR_BP1[i*9+7]);
376 printf("lfr_bp1[i*NB_BYTES_BP1+7] for ReaSX exponent + significand : %u\n",lfr_bp1[i*NB_BYTES_BP1+7]);
375 printf("LFR_BP1[i*9+1] for ReaSX sign + PSDE 'exponent' : %u\n",LFR_BP1[i*9+1]);
377 printf("lfr_bp1[i*NB_BYTES_BP1+1] for ReaSX sign + PSDE 'exponent' : %u\n",lfr_bp1[i*NB_BYTES_BP1+1]);
376 printf("ImaSX / 2 : %16.8e\n",e_cross_b_im/2);
378 printf("ImaSX / 2 : %16.8e\n",e_cross_b_im/2);
377 #endif
379 #endif
378 pt_u_char = (unsigned char*) &e_cross_b_im; // Affect an unsigned char pointer with the adress of e_cross_b_im
380 pt_u_char = (unsigned char*) &e_cross_b_im; // Affect an unsigned char pointer with the adress of e_cross_b_im
@@ -384,12 +386,12 void BP1_set( float * compressed_spec_ma
384 #endif
386 #endif
385 tmp_u_char = (e_cross_b_im > e_cross_b_re) ? 0x40 : 0x00; // Determine the sector argument of SX. If |Im| > |Re| affect
387 tmp_u_char = (e_cross_b_im > e_cross_b_re) ? 0x40 : 0x00; // Determine the sector argument of SX. If |Im| > |Re| affect
386 // an unsigned 8-bit char with 01000000; otherwise with null.
388 // an unsigned 8-bit char with 01000000; otherwise with null.
387 LFR_BP1[i*9+1] = LFR_BP1[i*9+1] | tmp_u_char; // Record it as a sign bit at the 7th bit position (from the right
389 lfr_bp1[i*NB_BYTES_BP1+1] = lfr_bp1[i*NB_BYTES_BP1+1] | tmp_u_char; // Record it as a sign bit at the 7th bit position (from the right
388 // to the left) of LFR_BP1[i*9+1], by simple logical addition.
390 // to the left) of lfr_bp1[i*NB_BYTES_BP1+1], by simple logical addition.
389 #ifdef DEBUG_TCH
391 #ifdef DEBUG_TCH
390 printf("|ImaSX| / 2 : %16.8e\n",e_cross_b_im/2);
392 printf("|ImaSX| / 2 : %16.8e\n",e_cross_b_im/2);
391 printf("ArgSX sign : %u\n",tmp_u_char);
393 printf("ArgSX sign : %u\n",tmp_u_char);
392 printf("LFR_BP1[i*9+1] for ReaSX & ArgSX signs + PSDE 'exponent' : %u\n",LFR_BP1[i*9+1]);
394 printf("lfr_bp1[i*NB_BYTES_BP1+1] for ReaSX & ArgSX signs + PSDE 'exponent' : %u\n",lfr_bp1[i*NB_BYTES_BP1+1]);
393 #endif
395 #endif
394 //======================================================================
396 //======================================================================
395 // BP1 phase velocity estimator == PA_LFR_SC_BP1_VPHI_F0 == 8 (+ 2) bits
397 // BP1 phase velocity estimator == PA_LFR_SC_BP1_VPHI_F0 == 8 (+ 2) bits
@@ -397,44 +399,44 void BP1_set( float * compressed_spec_ma
397 // + 1 sign bit + 1 argument bit (two sectors)
399 // + 1 sign bit + 1 argument bit (two sectors)
398 ny = sin(alpha_M)*NVEC_V1 + cos(alpha_M)*NVEC_V2;
400 ny = sin(alpha_M)*NVEC_V1 + cos(alpha_M)*NVEC_V2;
399 nz = NVEC_V0;
401 nz = NVEC_V0;
400 bx_bx_star = cos(alpha_M)*cos(alpha_M)*compressed_spec_mat[i*30+9] // S22 Re
402 bx_bx_star = cos(alpha_M)*cos(alpha_M)*compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+9] // S22 Re
401 + sin(alpha_M)*sin(alpha_M)*compressed_spec_mat[i*30+16] // S33 Re
403 + sin(alpha_M)*sin(alpha_M)*compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+16] // S33 Re
402 - 2*sin(alpha_M)*cos(alpha_M)*compressed_spec_mat[i*30+10]; // S23 Re
404 - 2*sin(alpha_M)*cos(alpha_M)*compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+10]; // S23 Re
403
405
404 n_cross_e_scal_b_re = ny * (compressed_spec_mat[i*30+12]*k_f0[i][K24_NY_RE] //S24 Re
406 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
405 +compressed_spec_mat[i*30+14]*k_f0[i][K25_NY_RE] //S25 Re
407 +compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+14]*k_f0[i][K25_NY_RE] //S25 Re
406 +compressed_spec_mat[i*30+17]*k_f0[i][K34_NY_RE] //S34 Re
408 +compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+17]*k_f0[i][K34_NY_RE] //S34 Re
407 +compressed_spec_mat[i*30+19]*k_f0[i][K35_NY_RE] //S35 Re
409 +compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+19]*k_f0[i][K35_NY_RE] //S35 Re
408 +compressed_spec_mat[i*30+13]*k_f0[i][K24_NY_IM] //S24 Im
410 +compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+13]*k_f0[i][K24_NY_IM] //S24 Im
409 +compressed_spec_mat[i*30+15]*k_f0[i][K25_NY_IM] //S25 Im
411 +compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+15]*k_f0[i][K25_NY_IM] //S25 Im
410 +compressed_spec_mat[i*30+18]*k_f0[i][K34_NY_IM] //S34 Im
412 +compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+18]*k_f0[i][K34_NY_IM] //S34 Im
411 +compressed_spec_mat[i*30+20]*k_f0[i][K35_NY_IM]) //S35 Im
413 +compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+20]*k_f0[i][K35_NY_IM]) //S35 Im
412 + nz * (compressed_spec_mat[i*30+12]*k_f0[i][K24_NZ_RE] //S24 Re
414 + nz * (compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+12]*k_f0[i][K24_NZ_RE] //S24 Re
413 +compressed_spec_mat[i*30+14]*k_f0[i][K25_NZ_RE] //S25 Re
415 +compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+14]*k_f0[i][K25_NZ_RE] //S25 Re
414 +compressed_spec_mat[i*30+17]*k_f0[i][K34_NZ_RE] //S34 Re
416 +compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+17]*k_f0[i][K34_NZ_RE] //S34 Re
415 +compressed_spec_mat[i*30+19]*k_f0[i][K35_NZ_RE] //S35 Re
417 +compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+19]*k_f0[i][K35_NZ_RE] //S35 Re
416 +compressed_spec_mat[i*30+13]*k_f0[i][K24_NZ_IM] //S24 Im
418 +compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+13]*k_f0[i][K24_NZ_IM] //S24 Im
417 +compressed_spec_mat[i*30+15]*k_f0[i][K25_NZ_IM] //S25 Im
419 +compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+15]*k_f0[i][K25_NZ_IM] //S25 Im
418 +compressed_spec_mat[i*30+18]*k_f0[i][K34_NZ_IM] //S34 Im
420 +compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+18]*k_f0[i][K34_NZ_IM] //S34 Im
419 +compressed_spec_mat[i*30+20]*k_f0[i][K35_NZ_IM]);//S35 Im
421 +compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+20]*k_f0[i][K35_NZ_IM]);//S35 Im
420 // Im(S_ji) = -Im(S_ij)
422 // Im(S_ji) = -Im(S_ij)
421 // k_ji = k_ij
423 // k_ji = k_ij
422 n_cross_e_scal_b_im = ny * (compressed_spec_mat[i*30+12]*k_f0[i][K24_NY_IM] //S24 Re
424 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
423 +compressed_spec_mat[i*30+14]*k_f0[i][K25_NY_IM] //S25 Re
425 +compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+14]*k_f0[i][K25_NY_IM] //S25 Re
424 +compressed_spec_mat[i*30+17]*k_f0[i][K34_NY_IM] //S34 Re
426 +compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+17]*k_f0[i][K34_NY_IM] //S34 Re
425 +compressed_spec_mat[i*30+19]*k_f0[i][K35_NY_IM] //S35 Re
427 +compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+19]*k_f0[i][K35_NY_IM] //S35 Re
426 -compressed_spec_mat[i*30+13]*k_f0[i][K24_NY_RE] //S24 Im
428 -compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+13]*k_f0[i][K24_NY_RE] //S24 Im
427 -compressed_spec_mat[i*30+15]*k_f0[i][K25_NY_RE] //S25 Im
429 -compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+15]*k_f0[i][K25_NY_RE] //S25 Im
428 -compressed_spec_mat[i*30+18]*k_f0[i][K34_NY_RE] //S34 Im
430 -compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+18]*k_f0[i][K34_NY_RE] //S34 Im
429 -compressed_spec_mat[i*30+20]*k_f0[i][K35_NY_RE]) //S35 Im
431 -compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+20]*k_f0[i][K35_NY_RE]) //S35 Im
430 + nz * (compressed_spec_mat[i*30+12]*k_f0[i][K24_NZ_IM] //S24 Re
432 + nz * (compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+12]*k_f0[i][K24_NZ_IM] //S24 Re
431 +compressed_spec_mat[i*30+14]*k_f0[i][K25_NZ_IM] //S25 Re
433 +compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+14]*k_f0[i][K25_NZ_IM] //S25 Re
432 +compressed_spec_mat[i*30+17]*k_f0[i][K34_NZ_IM] //S34 Re
434 +compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+17]*k_f0[i][K34_NZ_IM] //S34 Re
433 +compressed_spec_mat[i*30+19]*k_f0[i][K35_NZ_IM] //S35 Re
435 +compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+19]*k_f0[i][K35_NZ_IM] //S35 Re
434 -compressed_spec_mat[i*30+13]*k_f0[i][K24_NZ_RE] //S24 Im
436 -compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+13]*k_f0[i][K24_NZ_RE] //S24 Im
435 -compressed_spec_mat[i*30+15]*k_f0[i][K25_NZ_RE] //S25 Im
437 -compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+15]*k_f0[i][K25_NZ_RE] //S25 Im
436 -compressed_spec_mat[i*30+18]*k_f0[i][K34_NZ_RE] //S34 Im
438 -compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+18]*k_f0[i][K34_NZ_RE] //S34 Im
437 -compressed_spec_mat[i*30+20]*k_f0[i][K35_NZ_RE]);//S35 Im
439 -compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+20]*k_f0[i][K35_NZ_RE]);//S35 Im
438 #ifdef DEBUG_TCH
440 #ifdef DEBUG_TCH
439 printf("n_cross_e_scal_b_re : %16.8e\n",n_cross_e_scal_b_re);
441 printf("n_cross_e_scal_b_re : %16.8e\n",n_cross_e_scal_b_re);
440 printf("n_cross_e_scal_b_im : %16.8e\n",n_cross_e_scal_b_im);
442 printf("n_cross_e_scal_b_im : %16.8e\n",n_cross_e_scal_b_im);
@@ -442,15 +444,15 void BP1_set( float * compressed_spec_ma
442 // vphi = n_cross_e_scal_b_re / bx_bx_star => sign(VPHI) = sign(n_cross_e_scal_b_re)
444 // vphi = n_cross_e_scal_b_re / bx_bx_star => sign(VPHI) = sign(n_cross_e_scal_b_re)
443 pt_u_char = (unsigned char*) &n_cross_e_scal_b_re; // Affect an unsigned char pointer with the adress of n_cross_e_scal_b_re
445 pt_u_char = (unsigned char*) &n_cross_e_scal_b_re; // Affect an unsigned char pointer with the adress of n_cross_e_scal_b_re
444 #ifdef LSB_FIRST_TCH
446 #ifdef LSB_FIRST_TCH
445 LFR_BP1[i*9+3] = LFR_BP1[i*9+3] | (pt_u_char[3] & 0x80); // Extract its sign bit (32-bit float, sign bit in the 4th octet:PC convention)
447 lfr_bp1[i*NB_BYTES_BP1+3] = lfr_bp1[i*NB_BYTES_BP1+3] | (pt_u_char[3] & 0x80); // Extract its sign bit (32-bit float, sign bit in the 4th octet:PC convention)
446 // Record it at the 8th bit position (from the right to the left)
448 // Record it at the 8th bit position (from the right to the left)
447 // of LFR_BP1[i*9+3]
449 // of lfr_bp1[i*NB_BYTES_BP1+3]
448 pt_u_char[3] = (pt_u_char[3] & 0x7f); // Make n_cross_e_scal_b_re be positive in any case: |n_cross_e_scal_b_re|
450 pt_u_char[3] = (pt_u_char[3] & 0x7f); // Make n_cross_e_scal_b_re be positive in any case: |n_cross_e_scal_b_re|
449 #endif
451 #endif
450 #ifdef MSB_FIRST_TCH
452 #ifdef MSB_FIRST_TCH
451 LFR_BP1[i*9+3] = LFR_BP1[i*9+3] | (pt_u_char[0] & 0x80); // Extract its sign bit (32-bit float, sign bit in the 0th octet:SPARC convention)
453 lfr_bp1[i*NB_BYTES_BP1+3] = lfr_bp1[i*NB_BYTES_BP1+3] | (pt_u_char[0] & 0x80); // Extract its sign bit (32-bit float, sign bit in the 0th octet:SPARC convention)
452 // Record it at the 8th bit position (from the right to the left)
454 // Record it at the 8th bit position (from the right to the left)
453 // of LFR_BP1[i*9+3]
455 // of lfr_bp1[i*NB_BYTES_BP1+3]
454 pt_u_char[0] = (pt_u_char[0] & 0x7f); // Make n_cross_e_scal_b_re be positive in any case: |n_cross_e_scal_b_re|
456 pt_u_char[0] = (pt_u_char[0] & 0x7f); // Make n_cross_e_scal_b_re be positive in any case: |n_cross_e_scal_b_re|
455 #endif
457 #endif
456 vphi = n_cross_e_scal_b_re / bx_bx_star; // Compute |VPHI|
458 vphi = n_cross_e_scal_b_re / bx_bx_star; // Compute |VPHI|
@@ -477,19 +479,19 void BP1_set( float * compressed_spec_ma
477 printf("significand : %16.8e\n",significand);
479 printf("significand : %16.8e\n",significand);
478 printf("exponent : %d\n" ,exponent);
480 printf("exponent : %d\n" ,exponent);
479 #endif
481 #endif
480 LFR_BP1[i*9+8] = (unsigned char) ((significand*2-1)*7 + 0.5); // Shift and cast into a 8-bit unsigned char with rounding
482 lfr_bp1[i*NB_BYTES_BP1+8] = (unsigned char) ((significand*2-1)*7 + 0.5); // Shift and cast into a 8-bit unsigned char with rounding
481 // where just the first 3 bits are used (0, ..., 7)
483 // where just the first 3 bits are used (0, ..., 7)
482 tmp_u_char = (unsigned char) (exponent-expmin); // Shift and cast into a 8-bit unsigned char where
484 tmp_u_char = (unsigned char) (exponent-expmin); // Shift and cast into a 8-bit unsigned char where
483 // just the first 5 bits are used (0, ..., 2^5-1)
485 // just the first 5 bits are used (0, ..., 2^5-1)
484 #ifdef DEBUG_TCH
486 #ifdef DEBUG_TCH
485 printf("LFR_BP1[i*9+8] for VPHI significand : %u\n",LFR_BP1[i*9+8]);
487 printf("lfr_bp1[i*NB_BYTES_BP1+8] for VPHI significand : %u\n",lfr_bp1[i*NB_BYTES_BP1+8]);
486 printf("tmp_u_char for VPHI exponent : %d\n",tmp_u_char);
488 printf("tmp_u_char for VPHI exponent : %d\n",tmp_u_char);
487 #endif
489 #endif
488 LFR_BP1[i*9+8] = LFR_BP1[i*9+8] | (tmp_u_char << 3); // shift these 5 bits to the left before logical addition
490 lfr_bp1[i*NB_BYTES_BP1+8] = lfr_bp1[i*NB_BYTES_BP1+8] | (tmp_u_char << 3); // shift these 5 bits to the left before logical addition
489 // with LFR_BP1[i*9+8]
491 // with lfr_bp1[i*NB_BYTES_BP1+8]
490 #ifdef DEBUG_TCH
492 #ifdef DEBUG_TCH
491 printf("LFR_BP1[i*9+8] for VPHI exponent + significand : %u\n",LFR_BP1[i*9+8]);
493 printf("lfr_bp1[i*NB_BYTES_BP1+8] for VPHI exponent + significand : %u\n",lfr_bp1[i*NB_BYTES_BP1+8]);
492 printf("LFR_BP1[i*9+3] for VPHI sign + PSDB 'exponent' : %u\n",LFR_BP1[i*9+3]);
494 printf("lfr_bp1[i*NB_BYTES_BP1+3] for VPHI sign + PSDB 'exponent' : %u\n",lfr_bp1[i*NB_BYTES_BP1+3]);
493 #endif
495 #endif
494 pt_u_char = (unsigned char*) &n_cross_e_scal_b_im; // Affect an unsigned char pointer with the adress of n_cross_e_scal_b_im
496 pt_u_char = (unsigned char*) &n_cross_e_scal_b_im; // Affect an unsigned char pointer with the adress of n_cross_e_scal_b_im
495 #ifdef LSB_FIRST_TCH
497 #ifdef LSB_FIRST_TCH
@@ -500,18 +502,18 void BP1_set( float * compressed_spec_ma
500 #endif
502 #endif
501 tmp_u_char = (n_cross_e_scal_b_im > n_cross_e_scal_b_re) ? 0x40 : 0x00; // Determine the sector argument of SX. If |Im| > |Re| affect
503 tmp_u_char = (n_cross_e_scal_b_im > n_cross_e_scal_b_re) ? 0x40 : 0x00; // Determine the sector argument of SX. If |Im| > |Re| affect
502 // an unsigned 8-bit char with 01000000; otherwise with null.
504 // an unsigned 8-bit char with 01000000; otherwise with null.
503 LFR_BP1[i*9+3] = LFR_BP1[i*9+3] | tmp_u_char; // Record it as a sign bit at the 7th bit position (from the right
505 lfr_bp1[i*NB_BYTES_BP1+3] = lfr_bp1[i*NB_BYTES_BP1+3] | tmp_u_char; // Record it as a sign bit at the 7th bit position (from the right
504 // to the left) of LFR_BP1[i*9+3], by simple logical addition.
506 // to the left) of lfr_bp1[i*NB_BYTES_BP1+3], by simple logical addition.
505 #ifdef DEBUG_TCH
507 #ifdef DEBUG_TCH
506 printf("|n_cross_e_scal_b_im| : %16.8e\n",n_cross_e_scal_b_im);
508 printf("|n_cross_e_scal_b_im| : %16.8e\n",n_cross_e_scal_b_im);
507 printf("|n_cross_e_scal_b_im|/bx_bx_star/2: %16.8e\n",n_cross_e_scal_b_im/bx_bx_star/2);
509 printf("|n_cross_e_scal_b_im|/bx_bx_star/2: %16.8e\n",n_cross_e_scal_b_im/bx_bx_star/2);
508 printf("ArgNEBX sign : %u\n",tmp_u_char);
510 printf("ArgNEBX sign : %u\n",tmp_u_char);
509 printf("LFR_BP1[i*9+3] for VPHI & ArgNEBX signs + PSDB 'exponent' : %u\n",LFR_BP1[i*9+3]);
511 printf("lfr_bp1[i*NB_BYTES_BP1+3] for VPHI & ArgNEBX signs + PSDB 'exponent' : %u\n",lfr_bp1[i*NB_BYTES_BP1+3]);
510 #endif
512 #endif
511 }
513 }
512 }
514 }
513
515
514 void BP2_set( float * compressed_spec_mat, unsigned char nb_bins_compressed_spec_mat, unsigned char * LFR_BP2 )
516 void BP2_set( float * compressed_spec_mat, unsigned char nb_bins_compressed_spec_mat, unsigned char * lfr_bp2 )
515 {
517 {
516 int i, exponent;
518 int i, exponent;
517 float aux, significand, cross_re, cross_im;
519 float aux, significand, cross_re, cross_im;
@@ -521,8 +523,8 void BP2_set( float * compressed_spec_ma
521 unsigned short int *pt_u_short_int; // pointer on unsigned 16-bit words
523 unsigned short int *pt_u_short_int; // pointer on unsigned 16-bit words
522
524
523 #ifdef DEBUG_TCH
525 #ifdef DEBUG_TCH
526 printf("BP2 : \n");
524 printf("Number of bins: %d\n", nb_bins_compressed_spec_mat);
527 printf("Number of bins: %d\n", nb_bins_compressed_spec_mat);
525 printf("BP2 : \n");
526 #endif
528 #endif
527
529
528 // For floating point data to be recorded on 16-bit words :
530 // For floating point data to be recorded on 16-bit words :
@@ -561,104 +563,105 void BP2_set( float * compressed_spec_ma
561 // == PA_LFR_SC_BP2_CROSS_RE_9_F0 == 8 bits
563 // == PA_LFR_SC_BP2_CROSS_RE_9_F0 == 8 bits
562 // == PA_LFR_SC_BP2_CROSS_IM_9_F0 == 8 bits
564 // == PA_LFR_SC_BP2_CROSS_IM_9_F0 == 8 bits
563 // S12
565 // S12
564 aux = sqrt(compressed_spec_mat[i*30]*compressed_spec_mat[i*30+9]);
566 aux = sqrt(compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX]*compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+9]);
565 cross_re = compressed_spec_mat[i*30+1] / aux;
567 cross_re = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+1] / aux;
566 cross_im = compressed_spec_mat[i*30+2] / aux;
568 cross_im = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+2] / aux;
567 LFR_BP2[i*30+10] = (unsigned char) (cross_re*127.5 + 128); // shift and cast into a 8-bit unsigned char (0, ..., 255) with rounding
569 lfr_bp2[i*NB_BYTES_BP2+10] = (unsigned char) (cross_re*127.5 + 128); // shift and cast into a 8-bit unsigned char (0, ..., 255) with rounding
568 LFR_BP2[i*30+20] = (unsigned char) (cross_im*127.5 + 128); // shift and cast into a 8-bit unsigned char (0, ..., 255) with rounding
570 lfr_bp2[i*NB_BYTES_BP2+20] = (unsigned char) (cross_im*127.5 + 128); // shift and cast into a 8-bit unsigned char (0, ..., 255) with rounding
569 #ifdef DEBUG_TCH
571 #ifdef DEBUG_TCH
570 printf("LFR_BP2[i*30+10] for cross12_re (%16.8e) : %.3u\n",cross_re, LFR_BP2[i*30+10]);
572 printf("\nBin number: %d\n", i);
571 printf("LFR_BP2[i*30+20] for cross12_im (%16.8e) : %.3u\n",cross_im, LFR_BP2[i*30+20]);
573 printf("lfr_bp2[i*NB_BYTES_BP2+10] for cross12_re (%16.8e) : %.3u\n",cross_re, lfr_bp2[i*NB_BYTES_BP2+10]);
574 printf("lfr_bp2[i*NB_BYTES_BP2+20] for cross12_im (%16.8e) : %.3u\n",cross_im, lfr_bp2[i*NB_BYTES_BP2+20]);
572 #endif
575 #endif
573 // S13
576 // S13
574 aux = sqrt(compressed_spec_mat[i*30]*compressed_spec_mat[i*30+16]);
577 aux = sqrt(compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX]*compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+16]);
575 cross_re = compressed_spec_mat[i*30+3] / aux;
578 cross_re = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+3] / aux;
576 cross_im = compressed_spec_mat[i*30+4] / aux;
579 cross_im = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+4] / aux;
577 LFR_BP2[i*30+11] = (unsigned char) (cross_re*127.5 + 128); // shift and cast into a 8-bit unsigned char (0, ..., 255) with rounding
580 lfr_bp2[i*NB_BYTES_BP2+11] = (unsigned char) (cross_re*127.5 + 128); // shift and cast into a 8-bit unsigned char (0, ..., 255) with rounding
578 LFR_BP2[i*30+21] = (unsigned char) (cross_im*127.5 + 128); // shift and cast into a 8-bit unsigned char (0, ..., 255) with rounding
581 lfr_bp2[i*NB_BYTES_BP2+21] = (unsigned char) (cross_im*127.5 + 128); // shift and cast into a 8-bit unsigned char (0, ..., 255) with rounding
579 #ifdef DEBUG_TCH
582 #ifdef DEBUG_TCH
580 printf("LFR_BP2[i*30+11] for cross13_re (%16.8e) : %.3u\n",cross_re, LFR_BP2[i*30+11]);
583 printf("lfr_bp2[i*NB_BYTES_BP2+11] for cross13_re (%16.8e) : %.3u\n",cross_re, lfr_bp2[i*NB_BYTES_BP2+11]);
581 printf("LFR_BP2[i*30+21] for cross13_im (%16.8e) : %.3u\n",cross_im, LFR_BP2[i*30+21]);
584 printf("lfr_bp2[i*NB_BYTES_BP2+21] for cross13_im (%16.8e) : %.3u\n",cross_im, lfr_bp2[i*NB_BYTES_BP2+21]);
582 #endif
585 #endif
583 // S14
586 // S14
584 aux = sqrt(compressed_spec_mat[i*30]*compressed_spec_mat[i*30+21]);
587 aux = sqrt(compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX]*compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+21]);
585 cross_re = compressed_spec_mat[i*30+5] / aux;
588 cross_re = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+5] / aux;
586 cross_im = compressed_spec_mat[i*30+6] / aux;
589 cross_im = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+6] / aux;
587 LFR_BP2[i*30+12] = (unsigned char) (cross_re*127.5 + 128); // shift and cast into a 8-bit unsigned char (0, ..., 255) with rounding
590 lfr_bp2[i*NB_BYTES_BP2+12] = (unsigned char) (cross_re*127.5 + 128); // shift and cast into a 8-bit unsigned char (0, ..., 255) with rounding
588 LFR_BP2[i*30+22] = (unsigned char) (cross_im*127.5 + 128); // shift and cast into a 8-bit unsigned char (0, ..., 255) with rounding
591 lfr_bp2[i*NB_BYTES_BP2+22] = (unsigned char) (cross_im*127.5 + 128); // shift and cast into a 8-bit unsigned char (0, ..., 255) with rounding
589 #ifdef DEBUG_TCH
592 #ifdef DEBUG_TCH
590 printf("LFR_BP2[i*30+12] for cross14_re (%16.8e) : %.3u\n",cross_re, LFR_BP2[i*30+12]);
593 printf("lfr_bp2[i*NB_BYTES_BP2+12] for cross14_re (%16.8e) : %.3u\n",cross_re, lfr_bp2[i*NB_BYTES_BP2+12]);
591 printf("LFR_BP2[i*30+22] for cross14_im (%16.8e) : %.3u\n",cross_im, LFR_BP2[i*30+22]);
594 printf("lfr_bp2[i*NB_BYTES_BP2+22] for cross14_im (%16.8e) : %.3u\n",cross_im, lfr_bp2[i*NB_BYTES_BP2+22]);
592 #endif
595 #endif
593 // S15
596 // S15
594 aux = sqrt(compressed_spec_mat[i*30]*compressed_spec_mat[i*30+24]);
597 aux = sqrt(compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX]*compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+24]);
595 cross_re = compressed_spec_mat[i*30+7] / aux;
598 cross_re = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+7] / aux;
596 cross_im = compressed_spec_mat[i*30+8] / aux;
599 cross_im = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+8] / aux;
597 LFR_BP2[i*30+13] = (unsigned char) (cross_re*127.5 + 128); // shift and cast into a 8-bit unsigned char (0, ..., 255) with rounding
600 lfr_bp2[i*NB_BYTES_BP2+13] = (unsigned char) (cross_re*127.5 + 128); // shift and cast into a 8-bit unsigned char (0, ..., 255) with rounding
598 LFR_BP2[i*30+23] = (unsigned char) (cross_im*127.5 + 128); // shift and cast into a 8-bit unsigned char (0, ..., 255) with rounding
601 lfr_bp2[i*NB_BYTES_BP2+23] = (unsigned char) (cross_im*127.5 + 128); // shift and cast into a 8-bit unsigned char (0, ..., 255) with rounding
599 #ifdef DEBUG_TCH
602 #ifdef DEBUG_TCH
600 printf("LFR_BP2[i*30+13] for cross15_re (%16.8e) : %.3u\n",cross_re, LFR_BP2[i*30+13]);
603 printf("lfr_bp2[i*NB_BYTES_BP2+13] for cross15_re (%16.8e) : %.3u\n",cross_re, lfr_bp2[i*NB_BYTES_BP2+13]);
601 printf("LFR_BP2[i*30+23] for cross15_im (%16.8e) : %.3u\n",cross_im, LFR_BP2[i*30+23]);
604 printf("lfr_bp2[i*NB_BYTES_BP2+23] for cross15_im (%16.8e) : %.3u\n",cross_im, lfr_bp2[i*NB_BYTES_BP2+23]);
602 #endif
605 #endif
603 // S23
606 // S23
604 aux = sqrt(compressed_spec_mat[i*30+9]*compressed_spec_mat[i*30+16]);
607 aux = sqrt(compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+9]*compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+16]);
605 cross_re = compressed_spec_mat[i*30+10] / aux;
608 cross_re = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+10] / aux;
606 cross_im = compressed_spec_mat[i*30+11] / aux;
609 cross_im = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+11] / aux;
607 LFR_BP2[i*30+14] = (unsigned char) (cross_re*127.5 + 128); // shift and cast into a 8-bit unsigned char (0, ..., 255) with rounding
610 lfr_bp2[i*NB_BYTES_BP2+14] = (unsigned char) (cross_re*127.5 + 128); // shift and cast into a 8-bit unsigned char (0, ..., 255) with rounding
608 LFR_BP2[i*30+24] = (unsigned char) (cross_im*127.5 + 128); // shift and cast into a 8-bit unsigned char (0, ..., 255) with rounding
611 lfr_bp2[i*NB_BYTES_BP2+24] = (unsigned char) (cross_im*127.5 + 128); // shift and cast into a 8-bit unsigned char (0, ..., 255) with rounding
609 #ifdef DEBUG_TCH
612 #ifdef DEBUG_TCH
610 printf("LFR_BP2[i*30+14] for cross23_re (%16.8e) : %.3u\n",cross_re, LFR_BP2[i*30+14]);
613 printf("lfr_bp2[i*NB_BYTES_BP2+14] for cross23_re (%16.8e) : %.3u\n",cross_re, lfr_bp2[i*NB_BYTES_BP2+14]);
611 printf("LFR_BP2[i*30+24] for cross23_im (%16.8e) : %.3u\n",cross_im, LFR_BP2[i*30+24]);
614 printf("lfr_bp2[i*NB_BYTES_BP2+24] for cross23_im (%16.8e) : %.3u\n",cross_im, lfr_bp2[i*NB_BYTES_BP2+24]);
612 #endif
615 #endif
613 // S24
616 // S24
614 aux = sqrt(compressed_spec_mat[i*30+9]*compressed_spec_mat[i*30+21]);
617 aux = sqrt(compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+9]*compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+21]);
615 cross_re = compressed_spec_mat[i*30+12] / aux;
618 cross_re = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+12] / aux;
616 cross_im = compressed_spec_mat[i*30+13] / aux;
619 cross_im = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+13] / aux;
617 LFR_BP2[i*30+15] = (unsigned char) (cross_re*127.5 + 128); // shift and cast into a 8-bit unsigned char (0, ..., 255) with rounding
620 lfr_bp2[i*NB_BYTES_BP2+15] = (unsigned char) (cross_re*127.5 + 128); // shift and cast into a 8-bit unsigned char (0, ..., 255) with rounding
618 LFR_BP2[i*30+25] = (unsigned char) (cross_im*127.5 + 128); // shift and cast into a 8-bit unsigned char (0, ..., 255) with rounding
621 lfr_bp2[i*NB_BYTES_BP2+25] = (unsigned char) (cross_im*127.5 + 128); // shift and cast into a 8-bit unsigned char (0, ..., 255) with rounding
619 #ifdef DEBUG_TCH
622 #ifdef DEBUG_TCH
620 printf("LFR_BP2[i*30+15] for cross24_re (%16.8e) : %.3u\n",cross_re, LFR_BP2[i*30+15]);
623 printf("lfr_bp2[i*NB_BYTES_BP2+15] for cross24_re (%16.8e) : %.3u\n",cross_re, lfr_bp2[i*NB_BYTES_BP2+15]);
621 printf("LFR_BP2[i*30+25] for cross24_im (%16.8e) : %.3u\n",cross_im, LFR_BP2[i*30+25]);
624 printf("lfr_bp2[i*NB_BYTES_BP2+25] for cross24_im (%16.8e) : %.3u\n",cross_im, lfr_bp2[i*NB_BYTES_BP2+25]);
622 #endif
625 #endif
623 // S25
626 // S25
624 aux = sqrt(compressed_spec_mat[i*30+9]*compressed_spec_mat[i*30+24]);
627 aux = sqrt(compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+9]*compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+24]);
625 cross_re = compressed_spec_mat[i*30+14] / aux;
628 cross_re = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+14] / aux;
626 cross_im = compressed_spec_mat[i*30+15] / aux;
629 cross_im = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+15] / aux;
627 LFR_BP2[i*30+16] = (unsigned char) (cross_re*127.5 + 128); // shift and cast into a 8-bit unsigned char (0, ..., 255) with rounding
630 lfr_bp2[i*NB_BYTES_BP2+16] = (unsigned char) (cross_re*127.5 + 128); // shift and cast into a 8-bit unsigned char (0, ..., 255) with rounding
628 LFR_BP2[i*30+26] = (unsigned char) (cross_im*127.5 + 128); // shift and cast into a 8-bit unsigned char (0, ..., 255) with rounding
631 lfr_bp2[i*NB_BYTES_BP2+26] = (unsigned char) (cross_im*127.5 + 128); // shift and cast into a 8-bit unsigned char (0, ..., 255) with rounding
629 #ifdef DEBUG_TCH
632 #ifdef DEBUG_TCH
630 printf("LFR_BP2[i*30+16] for cross25_re (%16.8e) : %.3u\n",cross_re, LFR_BP2[i*30+16]);
633 printf("lfr_bp2[i*NB_BYTES_BP2+16] for cross25_re (%16.8e) : %.3u\n",cross_re, lfr_bp2[i*NB_BYTES_BP2+16]);
631 printf("LFR_BP2[i*30+26] for cross25_im (%16.8e) : %.3u\n",cross_im, LFR_BP2[i*30+26]);
634 printf("lfr_bp2[i*NB_BYTES_BP2+26] for cross25_im (%16.8e) : %.3u\n",cross_im, lfr_bp2[i*NB_BYTES_BP2+26]);
632 #endif
635 #endif
633 // S34
636 // S34
634 aux = sqrt(compressed_spec_mat[i*30+16]*compressed_spec_mat[i*30+21]);
637 aux = sqrt(compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+16]*compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+21]);
635 cross_re = compressed_spec_mat[i*30+17] / aux;
638 cross_re = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+17] / aux;
636 cross_im = compressed_spec_mat[i*30+18] / aux;
639 cross_im = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+18] / aux;
637 LFR_BP2[i*30+17] = (unsigned char) (cross_re*127.5 + 128); // shift and cast into a 8-bit unsigned char (0, ..., 255) with rounding
640 lfr_bp2[i*NB_BYTES_BP2+17] = (unsigned char) (cross_re*127.5 + 128); // shift and cast into a 8-bit unsigned char (0, ..., 255) with rounding
638 LFR_BP2[i*30+27] = (unsigned char) (cross_im*127.5 + 128); // shift and cast into a 8-bit unsigned char (0, ..., 255) with rounding
641 lfr_bp2[i*NB_BYTES_BP2+27] = (unsigned char) (cross_im*127.5 + 128); // shift and cast into a 8-bit unsigned char (0, ..., 255) with rounding
639 #ifdef DEBUG_TCH
642 #ifdef DEBUG_TCH
640 printf("LFR_BP2[i*30+17] for cross34_re (%16.8e) : %.3u\n",cross_re, LFR_BP2[i*30+17]);
643 printf("lfr_bp2[i*NB_BYTES_BP2+17] for cross34_re (%16.8e) : %.3u\n",cross_re, lfr_bp2[i*NB_BYTES_BP2+17]);
641 printf("LFR_BP2[i*30+27] for cross34_im (%16.8e) : %.3u\n",cross_im, LFR_BP2[i*30+27]);
644 printf("lfr_bp2[i*NB_BYTES_BP2+27] for cross34_im (%16.8e) : %.3u\n",cross_im, lfr_bp2[i*NB_BYTES_BP2+27]);
642 #endif
645 #endif
643 // S35
646 // S35
644 aux = sqrt(compressed_spec_mat[i*30+16]*compressed_spec_mat[i*30+24]);
647 aux = sqrt(compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+16]*compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+24]);
645 cross_re = compressed_spec_mat[i*30+19] / aux;
648 cross_re = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+19] / aux;
646 cross_im = compressed_spec_mat[i*30+20] / aux;
649 cross_im = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+20] / aux;
647 LFR_BP2[i*30+18] = (unsigned char) (cross_re*127.5 + 128); // shift and cast into a 8-bit unsigned char (0, ..., 255) with rounding
650 lfr_bp2[i*NB_BYTES_BP2+18] = (unsigned char) (cross_re*127.5 + 128); // shift and cast into a 8-bit unsigned char (0, ..., 255) with rounding
648 LFR_BP2[i*30+28] = (unsigned char) (cross_im*127.5 + 128); // shift and cast into a 8-bit unsigned char (0, ..., 255) with rounding
651 lfr_bp2[i*NB_BYTES_BP2+28] = (unsigned char) (cross_im*127.5 + 128); // shift and cast into a 8-bit unsigned char (0, ..., 255) with rounding
649 #ifdef DEBUG_TCH
652 #ifdef DEBUG_TCH
650 printf("LFR_BP2[i*30+18] for cross35_re (%16.8e) : %.3u\n",cross_re, LFR_BP2[i*30+18]);
653 printf("lfr_bp2[i*NB_BYTES_BP2+18] for cross35_re (%16.8e) : %.3u\n",cross_re, lfr_bp2[i*NB_BYTES_BP2+18]);
651 printf("LFR_BP2[i*30+28] for cross35_im (%16.8e) : %.3u\n",cross_im, LFR_BP2[i*30+28]);
654 printf("lfr_bp2[i*NB_BYTES_BP2+28] for cross35_im (%16.8e) : %.3u\n",cross_im, lfr_bp2[i*NB_BYTES_BP2+28]);
652 #endif
655 #endif
653 // S45
656 // S45
654 aux = sqrt(compressed_spec_mat[i*30+21]*compressed_spec_mat[i*30+24]);
657 aux = sqrt(compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+21]*compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+24]);
655 cross_re = compressed_spec_mat[i*30+22] / aux;
658 cross_re = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+22] / aux;
656 cross_im = compressed_spec_mat[i*30+23] / aux;
659 cross_im = compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX+23] / aux;
657 LFR_BP2[i*30+19] = (unsigned char) (cross_re*127.5 + 128); // shift and cast into a 8-bit unsigned char (0, ..., 255) with rounding
660 lfr_bp2[i*NB_BYTES_BP2+19] = (unsigned char) (cross_re*127.5 + 128); // shift and cast into a 8-bit unsigned char (0, ..., 255) with rounding
658 LFR_BP2[i*30+29] = (unsigned char) (cross_im*127.5 + 128); // shift and cast into a 8-bit unsigned char (0, ..., 255) with rounding
661 lfr_bp2[i*NB_BYTES_BP2+29] = (unsigned char) (cross_im*127.5 + 128); // shift and cast into a 8-bit unsigned char (0, ..., 255) with rounding
659 #ifdef DEBUG_TCH
662 #ifdef DEBUG_TCH
660 printf("LFR_BP2[i*30+19] for cross45_re (%16.8e) : %.3u\n",cross_re, LFR_BP2[i*30+19]);
663 printf("lfr_bp2[i*NB_BYTES_BP2+19] for cross45_re (%16.8e) : %.3u\n",cross_re, lfr_bp2[i*NB_BYTES_BP2+19]);
661 printf("LFR_BP2[i*30+29] for cross45_im (%16.8e) : %.3u\n",cross_im, LFR_BP2[i*30+29]);
664 printf("lfr_bp2[i*NB_BYTES_BP2+29] for cross45_im (%16.8e) : %.3u\n",cross_im, lfr_bp2[i*NB_BYTES_BP2+29]);
662 #endif
665 #endif
663 //==============================================
666 //==============================================
664 // BP2 auto correlations == PA_LFR_SC_BP2_AUTO_F0 == 5*16 bits = 5*[6 bits (exponent) + 10 bits (significand)]
667 // BP2 auto correlations == PA_LFR_SC_BP2_AUTO_F0 == 5*16 bits = 5*[6 bits (exponent) + 10 bits (significand)]
@@ -668,10 +671,10 void BP2_set( float * compressed_spec_ma
668 // == PA_LFR_SC_BP2_AUTO_A3_F0 == 16 bits
671 // == PA_LFR_SC_BP2_AUTO_A3_F0 == 16 bits
669 // == PA_LFR_SC_BP2_AUTO_A4_F0 == 16 bits
672 // == PA_LFR_SC_BP2_AUTO_A4_F0 == 16 bits
670 // S11
673 // S11
671 significand = frexpf(compressed_spec_mat[i*30], &exponent); // 0.5 <= significand < 1
674 significand = frexpf(compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX], &exponent); // 0.5 <= significand < 1
672 // S11 = significand * 2^exponent
675 // S11 = significand * 2^exponent
673 #ifdef DEBUG_TCH
676 #ifdef DEBUG_TCH
674 printf("S11 : %16.8e\n",compressed_spec_mat[i*30]);
677 printf("S11 : %16.8e\n",compressed_spec_mat[i*NB_VALUES_PER_SPECTRAL_MATRIX]);
675 printf("significand : %16.8e\n",significand);
678 printf("significand : %16.8e\n",significand);
676 printf("exponent : %d\n" ,exponent);
679 printf("exponent : %d\n" ,exponent);
677 #endif
680 #endif
@@ -692,7 +695,7 void BP2_set( float * compressed_spec_ma
692 // where just the first nbitsig bits are used (0, ..., 2^nbitsig-1)
695 // where just the first nbitsig bits are used (0, ..., 2^nbitsig-1)
693 tmp_u_short_int = (unsigned short int) (exponent-expmin); // Shift and cast into a 16-bit unsigned int
696 tmp_u_short_int = (unsigned short int) (exponent-expmin); // Shift and cast into a 16-bit unsigned int
694 // where just the first nbitexp bits are used (0, ..., 2^nbitexp-1)
697 // where just the first nbitexp bits are used (0, ..., 2^nbitexp-1)
695 pt_u_short_int = (unsigned short int*) &LFR_BP2[i*30+0]; // Affect an unsigned short int pointer with the