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