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