GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: src/../LFR_basic-parameters/basic_parameters.h Lines: 328 358 91.6 %
Date: 2018-11-13 11:16:07 Branches: 75 90 83.3 %

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