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