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