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