##// 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,10 +1,12
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
@@ -46,7 +48,7 float k_f0[NB_BINS_COMPRESSED_MATRIX_f0]
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;
@@ -89,9 +91,9 void init_k_f0( void )
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;
@@ -108,16 +110,17 void BP1_set( float * compressed_spec_ma
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
@@ -131,7 +134,7 void BP1_set( float * compressed_spec_ma
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
@@ -163,23 +166,31 void BP1_set( float * compressed_spec_ma
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
@@ -208,22 +219,31 void BP1_set( float * compressed_spec_ma
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
@@ -239,15 +259,15 void BP1_set( float * compressed_spec_ma
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
@@ -262,14 +282,14 void BP1_set( float * compressed_spec_ma
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 //==============================================================
@@ -286,13 +306,13 void BP1_set( float * compressed_spec_ma
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 //=======================================================================================
@@ -328,18 +348,18 void BP1_set( float * compressed_spec_ma
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
@@ -359,38 +379,38 void BP1_set( float * compressed_spec_ma
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 //======================================================================
@@ -442,18 +462,18 void BP1_set( float * compressed_spec_ma
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
@@ -479,48 +499,48 void BP1_set( float * compressed_spec_ma
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");
@@ -566,8 +586,8 void BP2_set( float * compressed_spec_ma
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]);
@@ -577,8 +597,8 void BP2_set( float * compressed_spec_ma
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]);
@@ -587,8 +607,8 void BP2_set( float * compressed_spec_ma
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]);
@@ -597,8 +617,8 void BP2_set( float * compressed_spec_ma
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]);
@@ -607,8 +627,8 void BP2_set( float * compressed_spec_ma
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]);
@@ -617,8 +637,8 void BP2_set( float * compressed_spec_ma
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]);
@@ -627,8 +647,8 void BP2_set( float * compressed_spec_ma
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]);
@@ -637,8 +657,8 void BP2_set( float * compressed_spec_ma
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]);
@@ -647,8 +667,8 void BP2_set( float * compressed_spec_ma
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]);
@@ -657,8 +677,8 void BP2_set( float * compressed_spec_ma
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]);
@@ -691,18 +711,18 void BP2_set( float * compressed_spec_ma
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]);
@@ -728,18 +748,18 void BP2_set( float * compressed_spec_ma
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]);
@@ -765,18 +785,18 void BP2_set( float * compressed_spec_ma
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]);
@@ -803,18 +823,18 void BP2_set( float * compressed_spec_ma
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]);
@@ -840,18 +860,18 void BP2_set( float * compressed_spec_ma
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]);
@@ -1,6 +1,7
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
@@ -1,6 +1,7
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
@@ -1,6 +1,7
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
@@ -1,5 +1,7
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>
@@ -15,8 +17,17 int main(void)
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);
General Comments 0
You need to be logged in to leave comments. Login now