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