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