Blame view

src/Parameters/DataTypeMath.hh 51.4 KB
fbe3c2bb   Benjamin Renard   First commit
1
2
3
4
5
6
7
8
9
10
/*
 * LogicalDataType.hh
 * @brief is a complement of ParamData.hh, contain mathematics function between ParamData element
 * @see paramData.hh
 *  Created on: Dec 21, 2012
 *      Author: f.casimir
 */

#ifndef LOGICALDATATYPE_HH_
#define LOGICALDATATYPE_HH_
f02d93eb   Hacene SI HADJ MOHAND   alfven ok
11
#define MU_0 1.25664e-06
3699433c   Hacene SI HADJ MOHAND   adding functions
12
#define RE 6.3712e+06
fbe3c2bb   Benjamin Renard   First commit
13
14
15

#include <vector>
#include <cmath>
c76233b2   Benjamin Renard   Check window time...
16
17
#include <boost/lexical_cast.hpp>

fbe3c2bb   Benjamin Renard   First commit
18
#include "ParamData.hh"
ab4d0b63   Elena.Budnik   AMDA_constants to...
19
#include "AMDA_constants.hh"
fbe3c2bb   Benjamin Renard   First commit
20

68af7c4e   Hacene SI HADJ MOHAND   nOk 7528
21
22
23
24
25
26
27
28
29
30
inline AMDA::Parameters::LogicalData castToLogicalData(int a) {
    if (isNAN(a)) {
        return AMDA::Parameters::LogicalData::NaN;
    }
    return (a >= 1) ? AMDA::Parameters::LogicalData::True : AMDA::Parameters::LogicalData::False;
}

inline AMDA::Parameters::LogicalData castToLogicalData(AMDA::Parameters::LogicalData a) {
    return a;
}
7578a549   Benjamin Renard   Add boolean suppo...
31

fbe3c2bb   Benjamin Renard   First commit
32
33
34
/**
 * @brief Operator And (&&) between LogicalData
 */
68af7c4e   Hacene SI HADJ MOHAND   nOk 7528
35
36
37
38
39
template<typename Type1, typename Type2>
inline AMDA::Parameters::LogicalData And(Type1 a, Type2 b) {
    AMDA::Parameters::LogicalData aa = castToLogicalData(a);
    AMDA::Parameters::LogicalData bb = castToLogicalData(b);
    AMDA::Parameters::LogicalData res = AMDA::Parameters::LogicalData::NaN;
384f25b6   Benjamin Renard   Implements operat...
40

68af7c4e   Hacene SI HADJ MOHAND   nOk 7528
41
42
43
    if (aa != AMDA::Parameters::LogicalData::NaN && bb != AMDA::Parameters::LogicalData::NaN) {
        res = ((aa == AMDA::Parameters::LogicalData::True) && (bb == AMDA::Parameters::LogicalData::True)) ? AMDA::Parameters::LogicalData::True : AMDA::Parameters::LogicalData::False;
    }
384f25b6   Benjamin Renard   Implements operat...
44

68af7c4e   Hacene SI HADJ MOHAND   nOk 7528
45
46
    return res;
}
384f25b6   Benjamin Renard   Implements operat...
47

68af7c4e   Hacene SI HADJ MOHAND   nOk 7528
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
/**
 * @brief Operator Or (||) between LogicalData
 */
template<typename Type1, typename Type2>
inline AMDA::Parameters::LogicalData Or(Type1 a, Type2 b) {
    AMDA::Parameters::LogicalData aa = castToLogicalData(a);
    AMDA::Parameters::LogicalData bb = castToLogicalData(b);
    AMDA::Parameters::LogicalData res = AMDA::Parameters::LogicalData::NaN;

    if (aa != AMDA::Parameters::LogicalData::NaN && bb != AMDA::Parameters::LogicalData::NaN) {
        res = ((aa == AMDA::Parameters::LogicalData::True) || (bb == AMDA::Parameters::LogicalData::True)) ? AMDA::Parameters::LogicalData::True : AMDA::Parameters::LogicalData::False;
    }

    return res;
}

/**
 * @brief Operator greater_than (>) between LogicalData
 */
template <typename Type1, typename Type2>
AMDA::Parameters::LogicalData greater_than(Type1 a, Type2 b) {
    AMDA::Parameters::LogicalData res = AMDA::Parameters::LogicalData::True;
    if (std::isfinite(a) && std::isfinite(b)) {
        res = (a > b) ? AMDA::Parameters::LogicalData::True : AMDA::Parameters::LogicalData::False;
    } else {
        res = AMDA::Parameters::LogicalData::NaN;
    }
    return res;
}

/**
 * @brief Operator greater_than (>) between table of LogicalData
 */
template<typename Type1, typename Type2>
std::vector<AMDA::Parameters::LogicalData> greater_than(std::vector<Type1> a,
        std::vector<Type2> b) {
    std::vector<AMDA::Parameters::LogicalData> r;
    if (a.size() != b.size()) {
        BOOST_THROW_EXCEPTION(
                AMDA::AMDA_exception() << AMDA::errno_code(AMDA_OPER_NOT_ALLOWED) << AMDA::ex_msg("Logical comparison between two vector of different size"));
    }

    for (unsigned int i = 0; i < a.size(); ++i) {
        r.push_back(greater_than(a[i], b[i]));
    }
    return r;
}

/**
 * @brief Operator lower_than (<) between table of LogicalData
 */
template <typename Type1, typename Type2>
AMDA::Parameters::LogicalData lower_than(Type1 a, Type2 b) {
    AMDA::Parameters::LogicalData res = AMDA::Parameters::LogicalData::True;
    if (std::isfinite(a) && std::isfinite(b)) {
        res = (a < b) ? AMDA::Parameters::LogicalData::True : AMDA::Parameters::LogicalData::False;
    } else {
        res = AMDA::Parameters::LogicalData::NaN;
    }
    return res;
}

/**
 * @brief Operator lower_than (<) between table of LogicalData
 */
template<typename Type1, typename Type2>
std::vector<AMDA::Parameters::LogicalData> lower_than(std::vector<Type1> a,
        std::vector<Type2> b) {
    std::vector<AMDA::Parameters::LogicalData> r;
    if (a.size() != b.size()) {
        BOOST_THROW_EXCEPTION(
                AMDA::AMDA_exception() << AMDA::errno_code(AMDA_OPER_NOT_ALLOWED) << AMDA::ex_msg("Logical comparison between two vector of different size"));
    }

    for (unsigned int i = 0; i < a.size(); ++i) {
        r.push_back(lower_than(a[i], b[i]));
    }
    return r;
}

/**
 * @brief Operator * between two scalars, one is LogicalData
 */
template <typename Type>
Type operator*(Type a, AMDA::Parameters::LogicalData b) {
    Type r;
    r << NotANumber();
    if (isNAN(a) || isNAN(b)) {
        return r;
    }
    r = a * (Type) b;
    return r;
}

template <typename Type>
Type operator*(AMDA::Parameters::LogicalData a, Type b) {
    return b * a;
}

/**
 * @brief Operator / between two scalars, one is LogicalData
 */
template <typename Type>
Type operator/(Type a, AMDA::Parameters::LogicalData b) {
    Type r;
    r << NotANumber();
    if (isNAN(a) || isNAN(b) || (b == AMDA::Parameters::LogicalData::False)) {
        return r;
    }
    r = a / (Type) b;
    return r;
}

template <typename Type>
Type operator/(AMDA::Parameters::LogicalData a, Type b) {
    Type r;
    r << NotANumber();
    if (isNAN(a) || isNAN(b) || (b == 0)) {
        return r;
    }
    r = (Type) a / b;
    return r;
}

/**
 * @brief Operator + between two scalars, one is LogicalData
 */
template <typename Type>
Type operator+(Type a, AMDA::Parameters::LogicalData b) {
    Type r;
    r << NotANumber();
    if (isNAN(a) || isNAN(b)) {
        return r;
    }
    r = a + (Type) b;
    return r;
}

template <typename Type>
Type operator+(AMDA::Parameters::LogicalData a, Type b) {
    return b + a;
}

/**
 * @brief Operator - between two scalars, one is LogicalData
 */
template <typename Type>
Type operator-(Type a, AMDA::Parameters::LogicalData b) {
    Type r;
    r << NotANumber();
    if (isNAN(a) || isNAN(b)) {
        return r;
    }
    r = a - (Type) b;
    return r;
}

template <typename Type>
Type operator-(AMDA::Parameters::LogicalData a, Type b) {
    Type r;
    r << NotANumber();
    if (isNAN(a) || isNAN(b)) {
        return r;
    }
    r = (Type) a - b;
    return r;
}

/**
 * @brief Operator addition between  two  vector
 * @details
 * 		r[0] = a[0] + b[0]
 * 		r[1] = a[1] + b[1]
 * 		r[2] = a[2] + b[2]
 * 	@return r
 */
template <typename Type1, typename Type2>
std::vector<Type1> operator+(std::vector<Type1> a, std::vector<Type2> b) {
    std::vector<Type1> r;
    if (a.size() != b.size()) {
        BOOST_THROW_EXCEPTION(AMDA::AMDA_exception() << AMDA::errno_code(AMDA_OPER_NOT_ALLOWED) << AMDA::ex_msg("Add two vector of different size"));
    }

    for (unsigned int i = 0; i < a.size(); ++i) {
        r.push_back((Type1) (a[i] + b[i]));
    }
    return r;
}

/**
 * @brief Operator subtraction between  two  vector
 * @details
 * 		r[0] = a[0] - b[0]
 * 		r[1] = a[1] - b[1]
 * 		r[2] = a[2] - b[2]
 * 	@return r
 */
template <typename Type1, typename Type2>
std::vector<Type1> operator-(std::vector<Type1> a, std::vector<Type2> b) {
    std::vector<Type1> r;
    if (a.size() != b.size()) {
        BOOST_THROW_EXCEPTION(AMDA::AMDA_exception() << AMDA::errno_code(AMDA_OPER_NOT_ALLOWED) << AMDA::ex_msg("Subtract two vector of different size"));
    }

    for (unsigned int i = 0; i < a.size(); ++i) {
        r.push_back(a[i] - b[i]);
    }
    return r;
}
22493b20   Benjamin Renard   Add dot product f...
257

68af7c4e   Hacene SI HADJ MOHAND   nOk 7528
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
/**
 * @brief Operator dot product between  two  vector
 * @details
 * 		r = a[0]*b[0] + a[1]*b[1] + a[2]+b[2]
 * 	@return the scalar r
 */
template <typename Type1, typename Type2>
Type1 operator*(std::vector<Type1> a, std::vector<Type2> b) {
    Type1 r = 0;
    if (a.size() != b.size()) {
        BOOST_THROW_EXCEPTION(AMDA::AMDA_exception() << AMDA::errno_code(AMDA_OPER_NOT_ALLOWED) << AMDA::ex_msg("Multiply two vector of different size"));
    }

    for (unsigned int i = 0; i < a.size(); ++i) {
        r += a[i] * b[i];
    }
    return r;
}

/**
 * @brief Function dot between two vectors can be used for dot product
 */
template <typename Type1, typename Type2>
Type1 dot(std::vector<Type1> a, std::vector<Type2> b) {
    return a*b;
}

template <typename Type>
677cc39b   Hacene SI HADJ MOHAND   removing plugin M...
286
Type magnitude(std::vector<Type> a) {
f2cf89d8   Hacene SI HADJ MOHAND   ok 7528
287
288
289
290
    Type mag = 0;
    for (unsigned int i = 0; i < a.size(); ++i)
        mag += a[i] * a[i];
    return std::sqrt(mag);
68af7c4e   Hacene SI HADJ MOHAND   nOk 7528
291
292
293
294
}

template <typename Type1, typename Type2>
Type1 angle(std::vector<Type1> a, std::vector<Type2> b) {
f2cf89d8   Hacene SI HADJ MOHAND   ok 7528
295
296
297
298
    if (magnitude(a) == 0 || magnitude(b) == 0) {
        BOOST_THROW_EXCEPTION(AMDA::AMDA_exception() << AMDA::errno_code(AMDA_OPER_NOT_ALLOWED) << AMDA::ex_msg("One of the two vectors is NULL"));
    }
    Type1 res;
f02d93eb   Hacene SI HADJ MOHAND   alfven ok
299
    if (dot(a, b) / magnitude(a) / magnitude(b) > 0.99999) {
f2cf89d8   Hacene SI HADJ MOHAND   ok 7528
300
        res = 0;
f02d93eb   Hacene SI HADJ MOHAND   alfven ok
301
302
    } else {
        res = std::acos(dot(a, b) / magnitude(a) / magnitude(b));
f2cf89d8   Hacene SI HADJ MOHAND   ok 7528
303
304
    }
    return res;
68af7c4e   Hacene SI HADJ MOHAND   nOk 7528
305
306
}

ed087564   Hacene SI HADJ MOHAND   function fairfiel...
307
308
309
310
/**
 * @brief alfvenVelocity : args magnetic field magnitude and density
 * @details
 * 
c7a19a54   Elena.Budnik   Valf in our units
311
312
 * standard : V (m/s) = mag (T) / std::sqrt(MU_0 * density ( kg/m^3))
 *  our : V (km/s) = K * mag (nT) / sqrt(density ( 1/cm^3)) assuming mass of proton
ed087564   Hacene SI HADJ MOHAND   function fairfiel...
313
 */
f02d93eb   Hacene SI HADJ MOHAND   alfven ok
314
315
template <typename Type1, typename Type2>
Type1 alfvenVelocity(Type1 density, Type2 mag) {
ed087564   Hacene SI HADJ MOHAND   function fairfiel...
316
    Type1 val;
f02d93eb   Hacene SI HADJ MOHAND   alfven ok
317
318
319
    if (density <= 0) {
        val << NotANumber();
    } else {
a88dbf1e   Hacene SI HADJ MOHAND   9719 ok
320
        val = 21.83 * mag / std::sqrt(density);
f02d93eb   Hacene SI HADJ MOHAND   alfven ok
321
    }
ed087564   Hacene SI HADJ MOHAND   function fairfiel...
322
323
324
325
326
327
328
    return val;
}

/**
 * @brief  FAIRFIELD 1970 model of neutral sheet position 
 * @details
 * z_sm-std::sqrt(pow(11.0, 2.0) - pow(11.0, 2.0) / pow(15.0, 2.0) * pow(y_sm, 2.0)) * std::sin(x_ss);
38bebd9c   Hacene SI HADJ MOHAND   lib Jupeter field...
329
 * where y_sm and z_sm  are the solar magnetospheric coordinates of the spacecraft and x_ss is geomagnetic latitude of the sun  (tilt angle) 
3ff34f08   Hacene SI HADJ MOHAND   fairfield70 et fa...
330

ed087564   Hacene SI HADJ MOHAND   function fairfiel...
331
332
333
334
template <typename Type1, typename Type2, typename Type3>
Type1 fairfield70(Type1  y_sm, Type2 z_sm,Type3 x_ss) {
    Type1 val = z_sm-std::sqrt(pow(11.0, 2.0) - pow(11.0, 2.0) / pow(15.0, 2.0) * pow(y_sm, 2.0)) * std::sin(x_ss);
    return val;
f02d93eb   Hacene SI HADJ MOHAND   alfven ok
335
}
3ff34f08   Hacene SI HADJ MOHAND   fairfield70 et fa...
336
 *  */
24effbb7   Elena.Budnik   Fairfield angle i...
337

3ff34f08   Hacene SI HADJ MOHAND   fairfield70 et fa...
338
/**
24effbb7   Elena.Budnik   Fairfield angle i...
339
 * @brief FAIRFIELD 1970 model of neutral sheet position : ..sqrt(11^2 - 11^2/15^2*y^2)... 
3ff34f08   Hacene SI HADJ MOHAND   fairfield70 et fa...
340
 * @param xyz_sm SM coordinates of the sat
24effbb7   Elena.Budnik   Fairfield angle i...
341
342
 * @param x_ss tilt Angle ( deg )
 * @return delta Z 
3ff34f08   Hacene SI HADJ MOHAND   fairfield70 et fa...
343
344
 */
template <typename Type1, typename Type2>
a88dbf1e   Hacene SI HADJ MOHAND   9719 ok
345
346
Type1 fairfield70(std::vector<Type1> xyz_sm, Type2 x_ss) {
    Type1 val = xyz_sm[2] - std::sqrt(121.0 - 0.537778 * pow(xyz_sm[1], 2.0)) * std::sin(x_ss * DEG2RAD);
3ff34f08   Hacene SI HADJ MOHAND   fairfield70 et fa...
347
348
349
350
351
352
353
    return val;
}

/**
 * @brief FAIRFIELD 1980 model of neutral sheet position  
 * @param xyz_sm SM coordinates of the sat
 * @param x_ss tilt Angle
24effbb7   Elena.Budnik   Fairfield angle i...
354
 * @return delta Z 
3ff34f08   Hacene SI HADJ MOHAND   fairfield70 et fa...
355
356
 */
template <typename Type1, typename Type2>
a88dbf1e   Hacene SI HADJ MOHAND   9719 ok
357
358
Type1 fairfield80(std::vector<Type1> xyz_sm, Type2 x_ss) {
    Type1 val = xyz_sm[2] - 10.5 * std::sqrt(1.0 - pow(xyz_sm[1], 2.0) / 289.0) * std::sin(x_ss * DEG2RAD);
3ff34f08   Hacene SI HADJ MOHAND   fairfield70 et fa...
359
360
    return val;
}
f02d93eb   Hacene SI HADJ MOHAND   alfven ok
361

68af7c4e   Hacene SI HADJ MOHAND   nOk 7528
362
/**
3699433c   Hacene SI HADJ MOHAND   adding functions
363
364
365
366
367
368
369
370
371
372
 * @brief  Perrault and Akasofu 1978 geomagnetic storms
 * @details
 *     u(t) = E_mag(t)*B_mag(t)/4pi(7RE sin²(theta_p(t)/2))²
 * where u(t) is total energy dissipation
 *            E_mag(t) The  magnitude of  the solar-wind electric field
 *            theta_p is a measure of the angle between the geomagnetic field vector and the IMF vector at the front of the 
 *            B_mag(t) The magnitude of the IMF magnetosphere in the equatorial plane. theta_p = pi/2 -theta where theta 
 *            denotes the latitudinal angle of the IMF vector measured from the solar equatorial plane.
 */
template <typename Type1, typename Type2, typename Type3>
a88dbf1e   Hacene SI HADJ MOHAND   9719 ok
373
374
Type1 perreault78(Type1 E_mag, Type2 B_mag, Type3 theta_p) {
    Type1 val = E_mag * B_mag / (4 * std::atan(1)*4) * std::pow((7 * RE * std::pow(sin(theta_p / 2), 2)), 2);
3699433c   Hacene SI HADJ MOHAND   adding functions
375
376
377
378
379
380
381
382
383
384
    return val;
}

/**
 * @brief  NEWELL et al 2007 solar wind-magnetosphere coupling function 
 * @details d_phi/d_t = mu^4/3*Bt^2/3*sin(theta/2)^8/3
 * where mu is rate IMF field lines approach the magnetopause
 *            B_mag interplanetary field magnitude,
 *            theta IMF clock angle arctan(By/Bz)
 */
1d171be3   Hacene SI HADJ MOHAND   newell
385
template <typename Type1, typename Type2>
a88dbf1e   Hacene SI HADJ MOHAND   9719 ok
386
387
388
389
390
Type1 newell2007(Type1 mu, std::vector<Type2> Bxyz) {
    Type2 B_mag = std::sqrt(Bxyz[0] * Bxyz[0] + Bxyz[1] * Bxyz[1] + Bxyz[2] * Bxyz[2]);
    Type2 theta = std::atan2(Bxyz[1] / Bxyz[2]);
    Type1 val = std::pow(mu, 4.0 / 3.0) * std::pow(B_mag, 2.0 / 3.0) * pow(std::sin(theta / 2), 8.0 / 3.0);
    return val;
3699433c   Hacene SI HADJ MOHAND   adding functions
391
392
393
}

/**
ed087564   Hacene SI HADJ MOHAND   function fairfiel...
394
395
396
397
398
399
400
 * @brief  Lopez 1990 model of magnetic latitude of the neutral sheet
 * @details
 *MLAT = -(0.14*Kp+0.69)*std::pow(phi, 1.0/3.0)*(0.065*R-0.16)*DTA;
 * where Kp is the 3-hour magnetic index, phi the magnetic local time in degrees (phi = 0° at midnight)
 * R is the radial distance in RE and DTA is the dipole tilt angle 
 */
template <typename Type1, typename Type2, typename Type3, typename Type4>
a88dbf1e   Hacene SI HADJ MOHAND   9719 ok
401
402
Type1 lopez90(Type1 Kp, Type2 phi, Type3 R, Type4 DTA) {
    Type1 val = -(0.14 * Kp + 0.69) * std::pow(phi, 0.3333)*(0.065 * R - 0.16) * DTA*DEG2RAD;
ed087564   Hacene SI HADJ MOHAND   function fairfiel...
403
404
405
    return val;
}

a88dbf1e   Hacene SI HADJ MOHAND   9719 ok
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
template <typename Type1, typename Type2>
Type1 pv_ionos_te(Type1 alt, Type2 sza) {

    Type1 te;
    if (alt > 3000 || alt < 150) {
        te << NotANumber();
        return te;
    } else {

        std::vector<double> pb;
        pb.resize(4);
        // 0 was added to fdsmodt in order to keep indexes as in fortran original source 
        const std::vector< double> fdsmodt{0,
            3.567296, 1.3836078e-02, 1.5086544e-02, 6.0729804e-03, 4.0306677e-03,
            -1.3217842e-02, 7.8089219e-03, -2775.023, -123.7310, 8.828382,
            -96.94563, 15.84634, 138.9812, -139.7511, -84.03277,
            0.2649297, -1.444215, 0.6347786, -2.192531, -0.5396207,
            0.6054179, 1.0569388e-04, -8.0908003e-06, 1.3877957e-05, -1.2327257e-05,
            -1.1256760e-05, 1.3830228e-05, -1.4350858e-05};
        double s = std::sin(sza);
        double c = std::cos(sza);
        double s2 = std::sin(2 * sza);
        double c2 = std::cos(2 * sza);
        double s3 = std::sin(3 * sza);
        double c3 = std::cos(3 * sza);
        for (int j = 1; j < 5; j++) {
            int k = 7 * j;
            pb[j - 1] = fdsmodt[k - 6] + fdsmodt[k - 5] * s + fdsmodt[k - 4] * c + fdsmodt[k - 3] * s2 + fdsmodt[k - 2] * c2 +
                    fdsmodt[k - 1] * s3 + fdsmodt[k] * c3;
        }
        te = (Type1) pb[0] + pb[1] / ((alt + pb[2])*(alt + pb[2])) + pb[3] * alt;
        return te;
    }
}

template <typename Type1, typename Type2>
Type1 pv_ionos_dn(Type1 alt, Type2 sza) {
ed087564   Hacene SI HADJ MOHAND   function fairfiel...
443

a88dbf1e   Hacene SI HADJ MOHAND   9719 ok
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
    Type1 dn;
    if (alt > 3000 || alt < 150) {
        dn << NotANumber();
        return dn;
    } else {
        std::vector<double> bp;
        bp.resize(4);
        // 0 was added to fdsmodde in order to keep indexes as in fortran original source 
        const std::vector<double> fdsmodde{0,
            5.334022, 252.5587, 120.4444, 9.1163822E-02, -6.195264,
            37.38898, 3.331818, 245.5529, 0.7587564, 0.1453792,
            -0.9461438, 127.1485, -0.3391595, 2.4936652E-02, 0.1879423,
            -5.3126566E-02, 2.9439656E-02, 1.654282, 415.7859, 2.6281483E-02,
            145.3951, 2.045347, 0.4421963, 3.036170, 9.1009791E-04,
            141.5824};
        double s2 = std::sin(sza) * std::sin(sza);
        double  szap = sza * (1. - fdsmodde[23] * s2 * std::exp(-fdsmodde[24] * s2 - fdsmodde[25]*(alt - fdsmodde[26])*(alt - fdsmodde[26])));
        double sinz = std::sin(fdsmodde[18] + szap);
        double s = fdsmodde[1] + fdsmodde[2] / (alt - fdsmodde[3])
                + sinz * fdsmodde[13]
                + fdsmodde[19] * std::exp(-fdsmodde[20]*((alt - fdsmodde[21])*(alt - fdsmodde[21])) - fdsmodde[22] * szap * szap);
        double o = fdsmodde[4] + fdsmodde[5] / (alt - fdsmodde[6]) + sinz * fdsmodde[14];
        double c = fdsmodde[7] + fdsmodde[8] / (alt - fdsmodde[9]) + sinz * fdsmodde[15];
        double m = fdsmodde[10] + fdsmodde[11] / (alt - fdsmodde[12]) + sinz * fdsmodde[16];
        double ss = s * cos(fdsmodde[17] + szap);
        double calc = (1.77245 * ss * erfc(-ss) + std::exp(-ss * ss) + o);
        if (calc <= 0)
            calc = 0.00001;
        dn = (Type1) c + m * log(calc);
        return dn;
    }
}
ed087564   Hacene SI HADJ MOHAND   function fairfiel...
476
477

/**
68af7c4e   Hacene SI HADJ MOHAND   nOk 7528
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
 * @brief Operator cross product between  two  vector
 * @details
 * 		r[0] = a[1]*b[2] - a[2]*b[1]
 * 		r[1] = a[2]*b[0] - a[0]*b[2]
 * 		r[2] = a[0]*b[1] - a[1]*b[0]
 * 	@return r
 */
template <typename Type1, typename Type2>
std::vector<Type1> operator ^(std::vector<Type1> a, std::vector<Type2> b) {
    std::vector<Type1> r;
    if (a.size() != b.size() || b.size() != 3) {
        BOOST_THROW_EXCEPTION(AMDA::AMDA_exception() << AMDA::errno_code(AMDA_OPER_NOT_ALLOWED) << AMDA::ex_msg("Vector product on two vector of different size"));
    }

    r.push_back(a[1] * b[2] - a[2] * b[1]);
    r.push_back(a[2] * b[0] - a[0] * b[2]);
    r.push_back(a[0] * b[1] - a[1] * b[0]);

    return r;
}

/**
 * @brief Function cross between two vectors can be used for cross product
 */
template <typename Type1, typename Type2>
std::vector<Type1> cross(std::vector<Type1> a, std::vector<Type2> b) {
    return a^b;
}

/**
 * @brief div each coordinate one to one
 * @details
 * 		r[0] = a[0] / b[0]
 * 		r[1] = a[1] / b[1]
 * 		r[2] = a[2] /  b[2]
 */
template <typename Type1, typename Type2>
std::vector<Type1> div(std::vector<Type1> a, std::vector<Type2> b) {
    std::vector<Type1> r;
    if (a.size() != b.size()) {
        BOOST_THROW_EXCEPTION(AMDA::AMDA_exception() << AMDA::errno_code(AMDA_OPER_NOT_ALLOWED) << AMDA::ex_msg("Vector div on two vector of different size"));

    }

    for (unsigned int i = 0; i < a.size(); ++i) {
        r.push_back(a[i] / b[i]);
    }

    return r;
}

//
//Idea but more complex: template <typename Type1, typename Type2>
//auto operator ^(std::vector<Type1> a, std::vector<Type2> b)  -> std::vector<decltype(Type1()*Type2())> {
//	std::vector<decltype(Type1()*Type2())> r;
fbe3c2bb   Benjamin Renard   First commit
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558


//	Idea but more complex: template <typename Type1, typename Type2>
//	double operator ^(Type1 a, Type2 b) {
//		return pow(a, b);
//	}
//	class Integer {
//		public:
//		Integer(int i) : _i(i) {};
//		int _i;
//	};
//
//	inline double operator ^(double a, Integer b) {
//		return pow(a, b._i);
//	}
//
//
//	class Double {
//		public:
//		Double(double i) : _i(i) {};
//		double _i;
//	};
//	inline double operator ^(double a, Double b) {
//		return pow(a, b._i);
//	}

68af7c4e   Hacene SI HADJ MOHAND   nOk 7528
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
// vector with scalar operation

/**
 * @brief Operator division between  a  vector and a scalar
 * @details all member of vector are divided by the scalar
 */
template <typename Type1, typename Type2>
std::vector<Type1> operator/(std::vector<Type1> a, Type2 b) {
    std::vector<Type1> r;
    for (typename std::vector<Type1>::iterator it = a.begin(); it != a.end(); ++it) {
        r.push_back((Type1) (*it / b));
    }
    return r;
}

/**
 * @brief Operator division between a scalar and a vector
 * @details apply the division on each vector component
 */
template <typename Type1, typename Type2>
std::vector<Type2> operator/(Type1 a, std::vector<Type2> b) {
    std::vector<Type2> r;
    for (typename std::vector<Type2>::iterator it = b.begin(); it != b.end(); ++it) {
        r.push_back((Type2) (a / *it));
    }
    return r;
}

/**
 * @brief Operator addition between  a  vector and a scalar
 * @details all member of vector are added with the scalar
 */
template <typename Type1, typename Type2>
std::vector<Type1> operator+(std::vector<Type1> a, Type2 b) {
    std::vector<Type1> r;
    for (typename std::vector<Type1>::iterator it = a.begin(); it != a.end(); ++it) {
        r.push_back((Type1) (*it + b));
    }
    return r;
}

/**
 * @brief Operator addition between a scalar and a  vector
 * @details all member of vector are added with the scalar
 */
template <typename Type1, typename Type2>
std::vector<Type2> operator+(Type1 a, std::vector<Type2> b) {
    std::vector<Type2> r;
    for (typename std::vector<Type2>::iterator it = b.begin(); it != b.end(); ++it) {
        r.push_back((Type2) (a + *it));
    }
    return r;
}

/**
 * @brief Operator subtraction  between a vector and a scalar
 * @details scalar is substracted to all vector components
 */
template <typename Type1, typename Type2>
std::vector<Type1> operator-(std::vector<Type1> a, Type2 b) {
    std::vector<Type1> r;
    for (typename std::vector<Type1>::iterator it = a.begin(); it != a.end(); ++it) {
        r.push_back((Type1) (*it - b));
    }
    return r;
}

/**
 * @brief Operator subtraction  between a scalar and a  vector
 * @details all member of vector are subtracted with the scalar
 */
template <typename Type1, typename Type2>
std::vector<Type2> operator-(Type1 a, std::vector<Type2> b) {
    std::vector<Type2> r;
    for (typename std::vector<Type2>::iterator it = b.begin(); it != b.end(); ++it) {
        r.push_back((Type2) (a - *it));
    }
    return r;
}

/**
 * @brief Operator product between a vector and a scalar
 * @details product applied in all member of vector
 */
template <typename Type1, typename Type2>
std::vector<Type1> operator*(std::vector<Type1> a, Type2 b) {
    std::vector<Type1> r;
    for (typename std::vector<Type1>::iterator it = a.begin(); it != a.end(); ++it) {
        r.push_back((Type1) ((*it) * b));
    }
    return r;
}

/**
 * @brief Operator product between a scalar and a vector
 * @details all member of vector are added by the scalar
 */
template <typename Type1, typename Type2>
std::vector<Type2> operator*(Type1 a, std::vector<Type2> b) {
    std::vector<Type2> r;
    for (typename std::vector<Type2>::iterator it = b.begin(); it != b.end(); ++it) {
        r.push_back((Type2) (a * (*it)));
    }
    return r;
}

/**
 * @return false if val is NaN or inf or -inf
 */
template <typename Type>
inline bool isFinite(Type val) {
    return std::isfinite(val);
}

inline bool isFinite(AMDA::Parameters::LogicalData val) {
    return !isNAN(val);
}

/**
 * @return false if elem of val is NaN or inf or -inf
 */
template <typename Type>
inline bool isFinite(std::vector<Type> val) {
    bool ret = false;
    auto it = val.begin();
    while (it != val.end() && !ret) {
        ret &= std::isfinite(*it);
        ++it;
    }
    return ret;
}

/**
 * @return false if elem of val is NaN or inf or -inf
 */
template <typename Type>
inline bool isFinite(const AMDA::Parameters::Tab2DData<Type>& val) {
    bool ret = false;
    for (int i = 0; i < val.getDim1Size(); ++i)
        for (int j = 0; j < val.getDim2Size(); ++j)
            ret &= std::isfinite(val[i][j]);
    return ret;
}

/**
 * @return the average of std::list
 */
template <typename Type>
inline Type average(std::list<Type> tab, int /*dim1*/, int /*dim2*/) {
    Type mean;
    if (tab.empty()) {
        mean << NotANumber();
    } else {
        mean << ElemNull();
        auto it = tab.begin();
        if (it != tab.end()) {
            unsigned int nbNan = 0;
            Type sum;
            sum << NotANumber();
            for (; it != tab.end(); ++it) {
                if (isFinite(*it) && !isNAN(*it)) {
                    if (isNAN(sum))
                        sum = *it;
                    else
                        sum = sum + *it;
                } else {
                    ++nbNan;
                }
            }
            if ((tab.size() - nbNan == 0) || isNAN(sum)) {
                mean << NotANumber();
            } else {
                mean = sum / (int) (tab.size() - nbNan);
            }
        } else {
            mean << NotANumber();
        }
    }
    return mean;
}

inline AMDA::Parameters::LogicalData average(std::list<AMDA::Parameters::LogicalData> /*tab*/, int /*dim1*/, int /*dim2*/) {
    AMDA::Parameters::LogicalData mean;
    mean << NotANumber();
    return mean;
}

template <typename Type>
inline AMDA::Parameters::Tab2DData<Type> average(std::list<AMDA::Parameters::Tab2DData<Type> > tab, int dim1, int dim2) {
    AMDA::Parameters::Tab2DData<Type> mean(dim1, dim2);
    AMDA::Parameters::Tab2DData<unsigned int > nbNan(dim1, dim2);
    AMDA::Parameters::Tab2DData<Type> sum(dim1, dim2);
    if (tab.empty()) {
        mean << NotANumber();
        return mean;
    }
    for (int index1 = 0; index1 < dim1; ++index1) {
        for (int index2 = 0; index2 < dim2; ++index2) {
            nbNan[index1][index2] = 0;
        }
    }
    sum << NotANumber();
    for (auto it = tab.begin(); it != tab.end(); ++it) {
        for (int index1 = 0; index1 < dim1; ++index1) {
            for (int index2 = 0; index2 < dim2; ++index2) {
                Type val = (*it)[index1][index2];
                if (std::isfinite(val) && !isNAN(val)) {
                    if (isNAN(sum[index1][index2]))
                        sum[index1][index2] = val;
                    else
                        sum[index1][index2] += val;
                } else {
                    ++(nbNan[index1][index2]);
                }
            }
        }
    }
    for (int index1 = 0; index1 < dim1; ++index1) {
        for (int index2 = 0; index2 < dim2; ++index2) {
            if (tab.size() - nbNan[index1][index2] == 0) {
                mean[index1][index2] << NotANumber();
            } else {
                mean[index1][index2] = sum[index1][index2] / (int) (tab.size() - nbNan[index1][index2]);
            }
8aa97375   Benjamin Renard   Add some missing ...
783
        }
68af7c4e   Hacene SI HADJ MOHAND   nOk 7528
784
785
786
787
    }

    return mean;
}
fbe3c2bb   Benjamin Renard   First commit
788

68af7c4e   Hacene SI HADJ MOHAND   nOk 7528
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
inline AMDA::Parameters::Tab2DData<AMDA::Parameters::LogicalData> average(std::list<AMDA::Parameters::Tab2DData<AMDA::Parameters::LogicalData>> /*tab*/, int dim1, int dim2) {
    AMDA::Parameters::Tab2DData<AMDA::Parameters::LogicalData> mean(dim1, dim2);
    mean << NotANumber();
    return mean;
}

/**
 * @return the average of std::list
 */
template <typename Type>
inline std::vector<Type> average(std::list<std::vector<Type> > tab, int dim1, int /*dim2*/) {
    std::vector<Type> mean;
    mean.resize(dim1);
    std::vector<unsigned int >nbNan;
    nbNan.resize(dim1);
    std::vector<Type> sum;
    sum.resize(dim1);
    if (tab.empty()) {
        mean << NotANumber();
        return mean;
    }
    for (unsigned int index = 0; index < tab.begin()->size(); ++index) {
        nbNan[index] = 0;
    }
    sum << NotANumber();
    for (auto it = tab.begin(); it != tab.end(); ++it) {
        for (unsigned int index = 0; index < it->size(); ++index) {
            Type val = it->at(index);
            if (std::isfinite(val) && !isNAN(val)) {
                if (isNAN(sum[index]))
                    sum[index] = val;
                else
                    sum[index] += val;
            } else {
                ++(nbNan[index]);
            }
        }
    }
    for (unsigned int index = 0; index < tab.begin()->size(); ++index) {
        if (tab.size() - nbNan[index] == 0) {
            mean[index] << NotANumber();
        } else {
            mean[index] = sum[index] / (int) (tab.size() - nbNan[index]);
7578a549   Benjamin Renard   Add boolean suppo...
832
        }
68af7c4e   Hacene SI HADJ MOHAND   nOk 7528
833
834
    }

7578a549   Benjamin Renard   Add boolean suppo...
835

68af7c4e   Hacene SI HADJ MOHAND   nOk 7528
836
837
    return mean;
}
fbe3c2bb   Benjamin Renard   First commit
838

68af7c4e   Hacene SI HADJ MOHAND   nOk 7528
839
840
841
842
843
844
inline std::vector<AMDA::Parameters::LogicalData> average(std::list<std::vector<AMDA::Parameters::LogicalData>> /*tab*/, int dim1, int /*dim2*/) {
    std::vector<AMDA::Parameters::LogicalData> mean;
    mean.resize(dim1);
    mean << NotANumber();
    return mean;
}
7578a549   Benjamin Renard   Add boolean suppo...
845

2f932bad   Benjamin Renard   Fix interpolation...
846
847
848
/**
 *
 */
68af7c4e   Hacene SI HADJ MOHAND   nOk 7528
849
850
851
852
853
854
855
856
857
template <typename Type>
inline Type interpolation(const Type& leftVal, const Type& rightVal, double coef, int /*dim1*/, int /*dim2*/) {
    Type val;
    val << NotANumber();
    if (isNAN(leftVal) || isNAN(rightVal) || coef < 0. || coef > 1.)
        return val;
    val = leftVal + (rightVal - leftVal) * coef;
    return val;
}
2f932bad   Benjamin Renard   Fix interpolation...
858

68af7c4e   Hacene SI HADJ MOHAND   nOk 7528
859
860
861
862
863
864
865
866
867
inline AMDA::Parameters::LogicalData interpolation(const AMDA::Parameters::LogicalData& leftVal, const AMDA::Parameters::LogicalData& rightVal, double /*coef*/, int /*dim1*/, int /*dim2*/) {
    AMDA::Parameters::LogicalData val;
    if (leftVal == rightVal) {
        val = leftVal;
    } else {
        val << NotANumber();
    }
    return val;
}
7578a549   Benjamin Renard   Add boolean suppo...
868

2f932bad   Benjamin Renard   Fix interpolation...
869
870
871
872
/**
 * 
 */

68af7c4e   Hacene SI HADJ MOHAND   nOk 7528
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
template <typename Type>
inline AMDA::Parameters::Tab2DData<Type> interpolation(const AMDA::Parameters::Tab2DData<Type>& leftVal, const AMDA::Parameters::Tab2DData<Type>& rightVal, double coef, int dim1, int dim2) {
    AMDA::Parameters::Tab2DData<Type> val(dim1, dim2);
    val << NotANumber();
    for (int index1 = 0; index1 < dim1; ++index1) {
        for (int index2 = 0; index2 < dim2; ++index2) {
            Type leftValComp = leftVal[index1][index2];
            Type rightValComp = rightVal[index1][index2];
            val[index1][index2] = interpolation(leftValComp, rightValComp, coef, 1, 1);
        }
    }
    return val;
}

template <typename Type>
inline std::vector<Type> interpolation(const std::vector<Type>& leftVal, const std::vector<Type>& rightVal, double coef, int dim1, int /*dim2*/) {
    std::vector<Type> val;
    val.resize(dim1);
    val << NotANumber();
    for (int index = 0; index < dim1; ++index) {
        Type leftValComp = leftVal[index];
        Type rightValComp = rightVal[index];
        val[index] = interpolation(leftValComp, rightValComp, coef, 1, 1);
    }
    return val;
}
fbe3c2bb   Benjamin Renard   First commit
899
900
901
902
903

/**
 * @brief Operator + between Tab2D and scalar
 */
template <typename Type1, typename Type2>
68af7c4e   Hacene SI HADJ MOHAND   nOk 7528
904
905
906
907
908
909
910
911
912
913
914
915
916
917
AMDA::Parameters::Tab2DData<Type1> operator+(const AMDA::Parameters::Tab2DData<Type1>& a, Type2 b) {
    AMDA::Parameters::Tab2DData<Type1> r(a);

    if (isNAN(b)) {
        r << NotANumber();
        return r;
    }

    for (int i = 0; i < r.getDim1Size(); ++i)
        for (int j = 0; j < r.getDim2Size(); ++j) {
            if (!isNAN(r[i][j]))
                r[i][j] += b;
        }
    return r;
fbe3c2bb   Benjamin Renard   First commit
918
919
920
}

template <typename Type1, typename Type2>
68af7c4e   Hacene SI HADJ MOHAND   nOk 7528
921
922
AMDA::Parameters::Tab2DData<Type2> operator+(Type1 a, const AMDA::Parameters::Tab2DData<Type2>& b) {
    return (b + a);
fbe3c2bb   Benjamin Renard   First commit
923
924
925
926
927
928
}

/**
 * @brief Operator - between Tab2D and scalar
 */
template <typename Type1, typename Type2>
68af7c4e   Hacene SI HADJ MOHAND   nOk 7528
929
930
AMDA::Parameters::Tab2DData<Type1> operator-(const AMDA::Parameters::Tab2DData<Type1>& a, Type2 b) {
    return (a + (-b));
fbe3c2bb   Benjamin Renard   First commit
931
932
933
}

template <typename Type1, typename Type2>
68af7c4e   Hacene SI HADJ MOHAND   nOk 7528
934
935
936
937
938
939
940
941
942
943
944
945
946
947
AMDA::Parameters::Tab2DData<Type2> operator-(Type1 a, const AMDA::Parameters::Tab2DData<Type2>& b) {
    AMDA::Parameters::Tab2DData<Type2> r(b);

    if (isNAN(a)) {
        r << NotANumber();
        return r;
    }

    for (int i = 0; i < r.getDim1Size(); ++i)
        for (int j = 0; j < r.getDim2Size(); ++j) {
            if (!isNAN(r[i][j]))
                r[i][j] = a - r[i][j];
        }
    return r;
fbe3c2bb   Benjamin Renard   First commit
948
949
950
951
952
953
}

/**
 * @brief Operator * between Tab2D and scalar
 */
template <typename Type1, typename Type2>
68af7c4e   Hacene SI HADJ MOHAND   nOk 7528
954
955
956
957
958
959
960
961
962
963
964
965
966
967
AMDA::Parameters::Tab2DData<Type1> operator*(const AMDA::Parameters::Tab2DData<Type1>& a, Type2 b) {
    AMDA::Parameters::Tab2DData<Type1> r(a);

    if (isNAN(b)) {
        r << NotANumber();
        return r;
    }

    for (int i = 0; i < r.getDim1Size(); ++i)
        for (int j = 0; j < r.getDim2Size(); ++j) {
            if (!isNAN(r[i][j]))
                r[i][j] *= b;
        }
    return r;
fbe3c2bb   Benjamin Renard   First commit
968
969
970
}

template <typename Type1, typename Type2>
68af7c4e   Hacene SI HADJ MOHAND   nOk 7528
971
972
AMDA::Parameters::Tab2DData<Type2> operator*(Type1 a, const AMDA::Parameters::Tab2DData<Type2>& b) {
    return (b * a);
fbe3c2bb   Benjamin Renard   First commit
973
974
975
976
977
978
}

/**
 * @brief Operator / between Tab2D and scalar
 */
template <typename Type1, typename Type2>
68af7c4e   Hacene SI HADJ MOHAND   nOk 7528
979
980
981
982
983
984
985
AMDA::Parameters::Tab2DData<Type1> operator/(const AMDA::Parameters::Tab2DData<Type1>& a, Type2 b) {
    if (b == 0) {
        AMDA::Parameters::Tab2DData<Type1> r(a);
        r << NotANumber();
        return r;
    }
    return (a * (1. / b));
fbe3c2bb   Benjamin Renard   First commit
986
987
988
}

template <typename Type1, typename Type2>
68af7c4e   Hacene SI HADJ MOHAND   nOk 7528
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
AMDA::Parameters::Tab2DData<Type2> operator/(Type1 a, const AMDA::Parameters::Tab2DData<Type2>& b) {
    AMDA::Parameters::Tab2DData<Type2> r(b);

    if (isNAN(a)) {
        r << NotANumber();
        return r;
    }

    for (int i = 0; i < r.getDim1Size(); ++i)
        for (int j = 0; j < r.getDim2Size(); ++j) {
            if (isNAN(r[i][j]) || (r[i][j] == 0))
                r[i][j] << NotANumber();
            else
                r[i][j] = a / r[i][j];
        }
    return r;
fbe3c2bb   Benjamin Renard   First commit
1005
1006
1007
1008
1009
1010
}

/*
 * @brief Function add between a Tab2D and a vector
 */
template <typename Type1, typename Type2>
68af7c4e   Hacene SI HADJ MOHAND   nOk 7528
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
AMDA::Parameters::Tab2DData<Type1> add(const AMDA::Parameters::Tab2DData<Type1>& a, std::vector<Type2> b, int mode) {
    AMDA::Parameters::Tab2DData<Type1> r(a);

    switch (mode) {
        case 1:
            if (r.getDim1Size() != b.size()) {
                BOOST_THROW_EXCEPTION(
                        AMDA::AMDA_exception() << AMDA::errno_code(AMDA_OPER_NOT_ALLOWED) << AMDA::ex_msg("Operation not allowed due to incompatibility in data dimensions"));
            }

            for (int i = 0; i < r.getDim1Size(); ++i)
                for (int j = 0; j < r.getDim2Size(); ++j) {
                    if (isNAN(r[i][j]) || isNAN(b[i]))
                        r[i][j] << NotANumber();
                    else
                        r[i][j] += b[i];
                }
            break;
        case 2:
            if (r.getDim2Size() != b.size()) {
                BOOST_THROW_EXCEPTION(
                        AMDA::AMDA_exception() << AMDA::errno_code(AMDA_OPER_NOT_ALLOWED) << AMDA::ex_msg("Operation not allowed due to incompatibility in data dimensions"));
            }

            for (int i = 0; i < r.getDim1Size(); ++i)
                for (int j = 0; j < r.getDim2Size(); ++j) {
                    if (isNAN(r[i][j]) || isNAN(b[j]))
                        r[i][j] << NotANumber();
                    else
                        r[i][j] += b[j];
                }
            break;
        default:
            BOOST_THROW_EXCEPTION(
                    AMDA::AMDA_exception() << AMDA::errno_code(AMDA_OPER_NOT_ALLOWED) << AMDA::ex_msg("Operation not allowed due a not implemented mode"));
    }
    return r;
fbe3c2bb   Benjamin Renard   First commit
1048
1049
1050
}

template <typename Type1, typename Type2>
68af7c4e   Hacene SI HADJ MOHAND   nOk 7528
1051
1052
AMDA::Parameters::Tab2DData<Type2> add(std::vector<Type1> a, const AMDA::Parameters::Tab2DData<Type2>& b, int mode) {
    return add(b, a, mode);
fbe3c2bb   Benjamin Renard   First commit
1053
1054
1055
1056
1057
1058
}

/**
 * @brief Operator + between Tab2D and vector
 */
template <typename Type1, typename Type2>
68af7c4e   Hacene SI HADJ MOHAND   nOk 7528
1059
1060
AMDA::Parameters::Tab2DData<Type1> operator+(const AMDA::Parameters::Tab2DData<Type1>& a, std::vector<Type2> b) {
    return add(a, b, 1);
fbe3c2bb   Benjamin Renard   First commit
1061
1062
1063
}

template <typename Type1, typename Type2>
68af7c4e   Hacene SI HADJ MOHAND   nOk 7528
1064
1065
AMDA::Parameters::Tab2DData<Type2> operator+(std::vector<Type1> a, const AMDA::Parameters::Tab2DData<Type2>& b) {
    return add(a, b, 1);
fbe3c2bb   Benjamin Renard   First commit
1066
1067
1068
1069
1070
1071
}

/**
 * @brief Function sub between Tab2D and vector
 */
template <typename Type1, typename Type2>
68af7c4e   Hacene SI HADJ MOHAND   nOk 7528
1072
1073
AMDA::Parameters::Tab2DData<Type1> sub(const AMDA::Parameters::Tab2DData<Type1>& a, std::vector<Type2> b, int mode) {
    return add(a, (-1) * b, mode);
fbe3c2bb   Benjamin Renard   First commit
1074
1075
1076
}

template <typename Type1, typename Type2>
68af7c4e   Hacene SI HADJ MOHAND   nOk 7528
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
AMDA::Parameters::Tab2DData<Type2> sub(std::vector<Type1> a, const AMDA::Parameters::Tab2DData<Type2>& b, int mode) {
    AMDA::Parameters::Tab2DData<Type2> r(b);

    switch (mode) {
        case 1:
            if (r.getDim1Size() != a.size()) {
                BOOST_THROW_EXCEPTION(
                        AMDA::AMDA_exception() << AMDA::errno_code(AMDA_OPER_NOT_ALLOWED) << AMDA::ex_msg("Operation not allowed due to incompatibility in data dimensions"));
            }

            for (int i = 0; i < r.getDim1Size(); ++i)
                for (int j = 0; j < r.getDim2Size(); ++j) {
                    if (isNAN(r[i][j]) || isNAN(a[i]))
                        r[i][j] << NotANumber();
                    else
                        r[i][j] = a[i] - r[i][j];
                }
            break;
        case 2:
            if (r.getDim2Size() != a.size()) {
                BOOST_THROW_EXCEPTION(
                        AMDA::AMDA_exception() << AMDA::errno_code(AMDA_OPER_NOT_ALLOWED) << AMDA::ex_msg("Operation not allowed due to incompatibility in data dimensions"));
            }

            for (int i = 0; i < r.getDim1Size(); ++i)
                for (int j = 0; j < r.getDim2Size(); ++j) {
                    if (isNAN(r[i][j]) || isNAN(a[j]))
                        r[i][j] << NotANumber();
                    else
                        r[i][j] = a[j] - r[i][j];
                }
            break;
        default:
            BOOST_THROW_EXCEPTION(
                    AMDA::AMDA_exception() << AMDA::errno_code(AMDA_OPER_NOT_ALLOWED) << AMDA::ex_msg("Operation not allowed due a not implemented mode"));
    }
    return r;
fbe3c2bb   Benjamin Renard   First commit
1114
1115
1116
1117
1118
1119
}

/**
 * @brief Operator - between Tab2D and vector
 */
template <typename Type1, typename Type2>
68af7c4e   Hacene SI HADJ MOHAND   nOk 7528
1120
1121
AMDA::Parameters::Tab2DData<Type1> operator-(const AMDA::Parameters::Tab2DData<Type1>& a, std::vector<Type2> b) {
    return sub(a, b, 1);
fbe3c2bb   Benjamin Renard   First commit
1122
1123
1124
}

template <typename Type1, typename Type2>
68af7c4e   Hacene SI HADJ MOHAND   nOk 7528
1125
1126
AMDA::Parameters::Tab2DData<Type2> operator-(std::vector<Type1> a, const AMDA::Parameters::Tab2DData<Type2>& b) {
    return sub(a, b, 1);
fbe3c2bb   Benjamin Renard   First commit
1127
1128
1129
1130
1131
1132
}

/**
 * @brief Function mult between Tab2D and vector
 */
template <typename Type1, typename Type2>
68af7c4e   Hacene SI HADJ MOHAND   nOk 7528
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
AMDA::Parameters::Tab2DData<Type1> mult(const AMDA::Parameters::Tab2DData<Type1>& a, std::vector<Type2> b, int mode) {
    AMDA::Parameters::Tab2DData<Type1> r(a);

    switch (mode) {
        case 1:
            if (r.getDim1Size() != b.size()) {
                BOOST_THROW_EXCEPTION(
                        AMDA::AMDA_exception() << AMDA::errno_code(AMDA_OPER_NOT_ALLOWED) << AMDA::ex_msg("Operation not allowed due to incompatibility in data dimensions"));
            }

            for (int i = 0; i < r.getDim1Size(); ++i)
                for (int j = 0; j < r.getDim2Size(); ++j) {
                    if (isNAN(r[i][j]) || isNAN(b[i]))
                        r[i][j] << NotANumber();
                    else
                        r[i][j] *= b[i];
                }
            break;
        case 2:
            if (r.getDim2Size() != b.size()) {
                BOOST_THROW_EXCEPTION(
                        AMDA::AMDA_exception() << AMDA::errno_code(AMDA_OPER_NOT_ALLOWED) << AMDA::ex_msg("Operation not allowed due to incompatibility in data dimensions"));
            }

            for (int i = 0; i < r.getDim1Size(); ++i)
                for (int j = 0; j < r.getDim2Size(); ++j) {
                    if (isNAN(r[i][j]) || isNAN(b[j]))
                        r[i][j] << NotANumber();
                    else
                        r[i][j] *= b[j];
                }
            break;
        default:
            BOOST_THROW_EXCEPTION(
                    AMDA::AMDA_exception() << AMDA::errno_code(AMDA_OPER_NOT_ALLOWED) << AMDA::ex_msg("Operation not allowed due a not implemented mode"));
    }
    return r;
fbe3c2bb   Benjamin Renard   First commit
1170
1171
1172
}

template <typename Type1, typename Type2>
68af7c4e   Hacene SI HADJ MOHAND   nOk 7528
1173
1174
AMDA::Parameters::Tab2DData<Type2> mult(std::vector<Type1> a, const AMDA::Parameters::Tab2DData<Type2>& b, int mode) {
    return mult(b, a, mode);
fbe3c2bb   Benjamin Renard   First commit
1175
1176
1177
1178
1179
1180
}

/**
 * @brief Operator * between Tab2D and vector
 */
template <typename Type1, typename Type2>
68af7c4e   Hacene SI HADJ MOHAND   nOk 7528
1181
1182
AMDA::Parameters::Tab2DData<Type1> operator*(const AMDA::Parameters::Tab2DData<Type1>& a, std::vector<Type2> b) {
    return mult(a, b, 1);
fbe3c2bb   Benjamin Renard   First commit
1183
1184
1185
}

template <typename Type1, typename Type2>
68af7c4e   Hacene SI HADJ MOHAND   nOk 7528
1186
1187
AMDA::Parameters::Tab2DData<Type2> operator*(std::vector<Type1> a, const AMDA::Parameters::Tab2DData<Type2>& b) {
    return mult(b, a, 1);
fbe3c2bb   Benjamin Renard   First commit
1188
1189
1190
1191
1192
1193
}

/**
 * @brief Function div between Tab2D and vector
 */
template <typename Type1, typename Type2>
68af7c4e   Hacene SI HADJ MOHAND   nOk 7528
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
AMDA::Parameters::Tab2DData<Type1> div(const AMDA::Parameters::Tab2DData<Type1>& a, std::vector<Type2> b, int mode) {
    AMDA::Parameters::Tab2DData<Type1> r(a);

    switch (mode) {
        case 1:
            if (r.getDim1Size() != b.size()) {
                BOOST_THROW_EXCEPTION(
                        AMDA::AMDA_exception() << AMDA::errno_code(AMDA_OPER_NOT_ALLOWED) << AMDA::ex_msg("Operation not allowed due to incompatibility in data dimensions"));
            }

            for (int i = 0; i < r.getDim1Size(); ++i)
                for (int j = 0; j < r.getDim2Size(); ++j) {
                    if (isNAN(r[i][j]) || isNAN(b[i]) || (b[i] == 0))
                        r[i][j] << NotANumber();
                    else
                        r[i][j] = r[i][j] / b[i];
                }
            break;
        case 2:
            if (r.getDim2Size() != b.size()) {
                BOOST_THROW_EXCEPTION(
                        AMDA::AMDA_exception() << AMDA::errno_code(AMDA_OPER_NOT_ALLOWED) << AMDA::ex_msg("Operation not allowed due to incompatibility in data dimensions"));
            }

            for (int i = 0; i < r.getDim1Size(); ++i)
                for (int j = 0; j < r.getDim2Size(); ++j) {
                    if (isNAN(r[i][j]) || isNAN(b[j]) || (b[j] == 0))
                        r[i][j] << NotANumber();
                    else
                        r[i][j] = r[i][j] / b[j];
                }
            break;
        default:
            BOOST_THROW_EXCEPTION(
                    AMDA::AMDA_exception() << AMDA::errno_code(AMDA_OPER_NOT_ALLOWED) << AMDA::ex_msg("Operation not allowed due a not implemented mode"));
    }
    return r;
fbe3c2bb   Benjamin Renard   First commit
1231
1232
1233
}

template <typename Type1, typename Type2>
68af7c4e   Hacene SI HADJ MOHAND   nOk 7528
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
AMDA::Parameters::Tab2DData<Type2> div(std::vector<Type1> a, const AMDA::Parameters::Tab2DData<Type2>& b, int mode) {
    AMDA::Parameters::Tab2DData<Type2> r(b);

    switch (mode) {
        case 1:
            if (r.getDim1Size() != a.size()) {
                BOOST_THROW_EXCEPTION(
                        AMDA::AMDA_exception() << AMDA::errno_code(AMDA_OPER_NOT_ALLOWED) << AMDA::ex_msg("Operation not allowed due to incompatibility in data dimensions"));
            }

            for (int i = 0; i < r.getDim1Size(); ++i)
                for (int j = 0; j < r.getDim2Size(); ++j) {
                    if (isNAN(r[i][j]) || isNAN(a[i]) || (r[i][j] == 0))
                        r[i][j] << NotANumber();
                    else
                        r[i][j] = a[i] / r[i][j];
                }
            break;
        case 2:
            if (r.getDim2Size() != a.size()) {
                BOOST_THROW_EXCEPTION(
                        AMDA::AMDA_exception() << AMDA::errno_code(AMDA_OPER_NOT_ALLOWED) << AMDA::ex_msg("Operation not allowed due to incompatibility in data dimensions"));
            }

            for (int i = 0; i < r.getDim1Size(); ++i)
                for (int j = 0; j < r.getDim2Size(); ++j) {
                    if (isNAN(r[i][j]) || isNAN(a[j]) || (r[i][j] == 0))
                        r[i][j] << NotANumber();
                    else
                        r[i][j] = a[j] / r[i][j];
                }
            break;
        default:
            BOOST_THROW_EXCEPTION(
                    AMDA::AMDA_exception() << AMDA::errno_code(AMDA_OPER_NOT_ALLOWED) << AMDA::ex_msg("Operation not allowed due a not implemented mode"));
    }
    return r;
fbe3c2bb   Benjamin Renard   First commit
1271
1272
1273
1274
1275
1276
}

/**
 * @brief Operator / between Tab2D and vector
 */
template <typename Type1, typename Type2>
68af7c4e   Hacene SI HADJ MOHAND   nOk 7528
1277
1278
AMDA::Parameters::Tab2DData<Type1> operator/(const AMDA::Parameters::Tab2DData<Type1>& a, std::vector<Type2> b) {
    return div(a, b, 1);
fbe3c2bb   Benjamin Renard   First commit
1279
1280
1281
}

template <typename Type1, typename Type2>
68af7c4e   Hacene SI HADJ MOHAND   nOk 7528
1282
1283
AMDA::Parameters::Tab2DData<Type2> operator/(std::vector<Type1> a, const AMDA::Parameters::Tab2DData<Type2>& b) {
    return div(b, a, 1);
fbe3c2bb   Benjamin Renard   First commit
1284
1285
1286
1287
1288
1289
}

/**
 * @brief Operator + between two Tab2D
 */
template <typename Type1, typename Type2>
68af7c4e   Hacene SI HADJ MOHAND   nOk 7528
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
AMDA::Parameters::Tab2DData<Type1> operator+(const AMDA::Parameters::Tab2DData<Type1>& a, const AMDA::Parameters::Tab2DData<Type2>& b) {
    if ((a.getDim1Size() != b.getDim1Size()) || (a.getDim2Size() != b.getDim2Size())) {
        BOOST_THROW_EXCEPTION(
                AMDA::AMDA_exception() << AMDA::errno_code(AMDA_OPER_NOT_ALLOWED) << AMDA::ex_msg("Operation not allowed due to incompatibility in data dimensions"));
    }

    AMDA::Parameters::Tab2DData<Type1> r(a);

    for (int i = 0; i < r.getDim1Size(); ++i)
        for (int j = 0; j < r.getDim2Size(); ++j) {
            if (isNAN(a[i][j]) || isNAN(b[i][j]))
                r[i][j] << NotANumber();
            else
                r[i][j] = a[i][j] + b[i][j];
        }
fbe3c2bb   Benjamin Renard   First commit
1305

68af7c4e   Hacene SI HADJ MOHAND   nOk 7528
1306
    return r;
fbe3c2bb   Benjamin Renard   First commit
1307
1308
1309
1310
1311
1312
}

/**
 * @brief Operator - between two Tab2D
 */
template <typename Type1, typename Type2>
68af7c4e   Hacene SI HADJ MOHAND   nOk 7528
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
AMDA::Parameters::Tab2DData<Type1> operator-(const AMDA::Parameters::Tab2DData<Type1>& a, const AMDA::Parameters::Tab2DData<Type2>& b) {
    if ((a.getDim1Size() != b.getDim1Size()) || (a.getDim2Size() != b.getDim2Size())) {
        BOOST_THROW_EXCEPTION(
                AMDA::AMDA_exception() << AMDA::errno_code(AMDA_OPER_NOT_ALLOWED) << AMDA::ex_msg("Operation not allowed due to incompatibility in data dimensions"));
    }

    AMDA::Parameters::Tab2DData<Type1> r(a);

    for (int i = 0; i < r.getDim1Size(); ++i)
        for (int j = 0; j < r.getDim2Size(); ++j) {
            if (isNAN(a[i][j]) || isNAN(b[i][j]))
                r[i][j] << NotANumber();
            else
                r[i][j] = a[i][j] - b[i][j];
        }
    return r;
fbe3c2bb   Benjamin Renard   First commit
1329
1330
1331
1332
1333
1334
}

/**
 * @brief Operator * between two Tab2D
 */
template <typename Type1, typename Type2>
68af7c4e   Hacene SI HADJ MOHAND   nOk 7528
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
AMDA::Parameters::Tab2DData<Type1> operator*(const AMDA::Parameters::Tab2DData<Type1>& a, const AMDA::Parameters::Tab2DData<Type2>& b) {
    if ((a.getDim1Size() != b.getDim1Size()) || (a.getDim2Size() != b.getDim2Size())) {
        BOOST_THROW_EXCEPTION(
                AMDA::AMDA_exception() << AMDA::errno_code(AMDA_OPER_NOT_ALLOWED) << AMDA::ex_msg("Operation not allowed due to incompatibility in data dimensions"));
    }

    AMDA::Parameters::Tab2DData<Type1> r(a);

    for (int i = 0; i < r.getDim1Size(); ++i)
        for (int j = 0; j < r.getDim2Size(); ++j) {
            if (isNAN(a[i][j]) || isNAN(b[i][j]))
                r[i][j] << NotANumber();
            else
                r[i][j] = a[i][j] * b[i][j];
        }
    return r;
fbe3c2bb   Benjamin Renard   First commit
1351
1352
1353
1354
1355
1356
}

/**
 * @brief Operator + between two Tab2D
 */
template <typename Type1, typename Type2>
68af7c4e   Hacene SI HADJ MOHAND   nOk 7528
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
AMDA::Parameters::Tab2DData<Type1> operator/(const AMDA::Parameters::Tab2DData<Type1>& a, const AMDA::Parameters::Tab2DData<Type2>& b) {
    if ((a.getDim1Size() != b.getDim1Size()) || (a.getDim2Size() != b.getDim2Size())) {
        BOOST_THROW_EXCEPTION(
                AMDA::AMDA_exception() << AMDA::errno_code(AMDA_OPER_NOT_ALLOWED) << AMDA::ex_msg("Operation not allowed due to incompatibility in data dimensions"));
    }

    AMDA::Parameters::Tab2DData<Type1> r(a);

    for (int i = 0; i < r.getDim1Size(); ++i)
        for (int j = 0; j < r.getDim2Size(); ++j) {
            if (isNAN(a[i][j]) || isNAN(b[i][j]) || (b[i][j] == 0))
                r[i][j] << NotANumber();
            else
                r[i][j] = a[i][j] / b[i][j];
        }
    return r;
fbe3c2bb   Benjamin Renard   First commit
1373
1374
1375
}

/**
351058d5   Elena.Budnik   total() for vector
1376
1377
1378
 * @brief Function total on all components of a vector => result is a scalar
 */
template <typename Type>
68af7c4e   Hacene SI HADJ MOHAND   nOk 7528
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
Type total(const std::vector<Type>& a) {
    Type sum;
    sum << NotANumber();

    for (int j = 0; j < a.size(); ++j) {
        if (isFinite(a[j])) {
            if (isNAN(sum))
                sum = a[j];
            else
                sum += a[j];
        }
    }
    return sum;
351058d5   Elena.Budnik   total() for vector
1392
1393
1394
}

/**
fbe3c2bb   Benjamin Renard   First commit
1395
1396
1397
 * @brief Function total on all components of a Tab2D => result is a scalar
 */
template <typename Type>
68af7c4e   Hacene SI HADJ MOHAND   nOk 7528
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
Type total(const AMDA::Parameters::Tab2DData<Type>& a) {
    Type sum;
    sum << NotANumber();

    for (int i = 0; i < a.getDim1Size(); ++i)
        for (int j = 0; j < a.getDim2Size(); ++j) {
            if (isFinite(a[i][j])) {
                if (isNAN(sum))
                    sum = a[i][j];
                else
                    sum += a[i][j];
            }
        }
    return sum;
fbe3c2bb   Benjamin Renard   First commit
1412
1413
1414
1415
1416
1417
1418
1419
}

/**
 * @brief Function total on lines or columns of a Tab2D => result is a vector
 * mode = 1 => sum on lines
 * mode = 2 => sum on columns
 */
template <typename Type>
68af7c4e   Hacene SI HADJ MOHAND   nOk 7528
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
std::vector<Type> total(const AMDA::Parameters::Tab2DData<Type>& a, int mode) {
    std::vector<Type> sum;

    switch (mode) {
        case 1:
            for (int j = 0; j < a.getDim2Size(); ++j) {
                Type elem;
                elem << NotANumber();
                for (int i = 0; i < a.getDim1Size(); ++i) {
                    if (isFinite(a[i][j])) {
                        if (isNAN(elem))
                            elem = a[i][j];
                        else
                            elem += a[i][j];
                    }
                }
                sum.push_back(elem);
            }
            break;
        case 2:
            for (int i = 0; i < a.getDim1Size(); ++i) {
                Type elem;
                elem << NotANumber();
                for (int j = 0; j < a.getDim2Size(); ++j) {
                    if (isFinite(a[i][j])) {
                        if (isNAN(elem))
                            elem = a[i][j];
                        else
                            elem += a[i][j];
                    }
                }
                sum.push_back(elem);
            }
            break;
        default:
            BOOST_THROW_EXCEPTION(
                    AMDA::AMDA_exception() << AMDA::errno_code(AMDA_OPER_NOT_ALLOWED) << AMDA::ex_msg("Operation not allowed due a not implemented mode"));
    }

    return sum;
fbe3c2bb   Benjamin Renard   First commit
1460
1461
}

66b49969   Benjamin Renard   Add a function to...
1462
// Reshape a Tab2D to a vector
a88dbf1e   Hacene SI HADJ MOHAND   9719 ok
1463

66b49969   Benjamin Renard   Add a function to...
1464
1465
1466
template <typename Type>
std::vector<Type> reshapeToVector(const AMDA::Parameters::Tab2DData<Type>& a) {
    std::vector<Type> v;
a88dbf1e   Hacene SI HADJ MOHAND   9719 ok
1467
    v.resize(a.getDim1Size() * a.getDim2Size());
66b49969   Benjamin Renard   Add a function to...
1468
1469
    for (int r = 0; r < a.getDim1Size(); ++r) {
        for (int c = 0; c < a.getDim2Size(); ++c) {
a88dbf1e   Hacene SI HADJ MOHAND   9719 ok
1470
            v[r * a.getDim2Size() + c] = a[r][c];
66b49969   Benjamin Renard   Add a function to...
1471
1472
1473
1474
1475
        }
    }

    return v;
}
a88dbf1e   Hacene SI HADJ MOHAND   9719 ok
1476

f6ac001d   Hacene SI HADJ MOHAND   adding newwell201...
1477
1478
1479
1480
1481
1482
1483
/*
 * Evaluation of SuperMAG auroral electrojet indices as indicators
 * of substorms and auroral power
 *  JOURNAL OF GEOPHYSICAL RESEARCH, VOL. 116, A12211, doi:10.1029/2011JA016779, 2011
 */
template <typename Type>
Type newell2011(Type a) {
a88dbf1e   Hacene SI HADJ MOHAND   9719 ok
1484
    return 0.048 * a + 0.241 * std::sqrt(a);
f6ac001d   Hacene SI HADJ MOHAND   adding newwell201...
1485
}
66b49969   Benjamin Renard   Add a function to...
1486

9e4ae650   Benjamin Renard   Fix operators amb...
1487
template <typename Type1, typename Type2>
68af7c4e   Hacene SI HADJ MOHAND   nOk 7528
1488
1489
1490
1491
std::vector<Type1> operator+(AMDA::Parameters::TabRow<Type1> a, AMDA::Parameters::TabRow<Type2> b) {
    std::vector<Type1> av(a);
    std::vector<Type1> bv(b);
    return av + bv;
9e4ae650   Benjamin Renard   Fix operators amb...
1492
1493
1494
}

template <typename Type1, typename Type2>
68af7c4e   Hacene SI HADJ MOHAND   nOk 7528
1495
1496
1497
std::vector<Type1> operator+(std::vector<Type1> a, AMDA::Parameters::TabRow<Type2> b) {
    std::vector<Type2> bv(b);
    return a + bv;
9e4ae650   Benjamin Renard   Fix operators amb...
1498
1499
1500
}

template <typename Type1, typename Type2>
68af7c4e   Hacene SI HADJ MOHAND   nOk 7528
1501
1502
1503
std::vector<Type1> operator+(AMDA::Parameters::TabRow<Type1> a, std::vector<Type2> b) {
    std::vector<Type1> av(a);
    return av + b;
9e4ae650   Benjamin Renard   Fix operators amb...
1504
1505
1506
}

template <typename Type1, typename Type2>
68af7c4e   Hacene SI HADJ MOHAND   nOk 7528
1507
1508
1509
1510
std::vector<Type1> operator*(AMDA::Parameters::TabRow<Type1> a, AMDA::Parameters::TabRow<Type2> b) {
    std::vector<Type1> av(a);
    std::vector<Type1> bv(b);
    return av*bv;
9e4ae650   Benjamin Renard   Fix operators amb...
1511
1512
1513
}

template <typename Type1, typename Type2>
68af7c4e   Hacene SI HADJ MOHAND   nOk 7528
1514
1515
1516
std::vector<Type1> operator*(std::vector<Type1> a, AMDA::Parameters::TabRow<Type2> b) {
    std::vector<Type2> bv(b);
    return a*bv;
9e4ae650   Benjamin Renard   Fix operators amb...
1517
1518
1519
}

template <typename Type1, typename Type2>
68af7c4e   Hacene SI HADJ MOHAND   nOk 7528
1520
1521
1522
std::vector<Type1> operator*(AMDA::Parameters::TabRow<Type1> a, std::vector<Type2> b) {
    std::vector<Type1> av(a);
    return av*b;
9e4ae650   Benjamin Renard   Fix operators amb...
1523
1524
1525
}

template <typename Type1, typename Type2>
68af7c4e   Hacene SI HADJ MOHAND   nOk 7528
1526
1527
1528
1529
std::vector<Type1> operator-(AMDA::Parameters::TabRow<Type1> a, AMDA::Parameters::TabRow<Type2> b) {
    std::vector<Type1> av(a);
    std::vector<Type1> bv(b);
    return av - bv;
9e4ae650   Benjamin Renard   Fix operators amb...
1530
1531
1532
}

template <typename Type1, typename Type2>
68af7c4e   Hacene SI HADJ MOHAND   nOk 7528
1533
1534
1535
std::vector<Type1> operator-(std::vector<Type1> a, AMDA::Parameters::TabRow<Type2> b) {
    std::vector<Type2> bv(b);
    return a - bv;
9e4ae650   Benjamin Renard   Fix operators amb...
1536
1537
1538
}

template <typename Type1, typename Type2>
68af7c4e   Hacene SI HADJ MOHAND   nOk 7528
1539
1540
1541
std::vector<Type1> operator-(AMDA::Parameters::TabRow<Type1> a, std::vector<Type2> b) {
    std::vector<Type1> av(a);
    return av - b;
9e4ae650   Benjamin Renard   Fix operators amb...
1542
1543
1544
}

template <typename Type1, typename Type2>
68af7c4e   Hacene SI HADJ MOHAND   nOk 7528
1545
1546
1547
1548
std::vector<Type1> operator/(AMDA::Parameters::TabRow<Type1> a, AMDA::Parameters::TabRow<Type2> b) {
    std::vector<Type1> av(a);
    std::vector<Type1> bv(b);
    return av / bv;
9e4ae650   Benjamin Renard   Fix operators amb...
1549
1550
1551
}

template <typename Type1, typename Type2>
68af7c4e   Hacene SI HADJ MOHAND   nOk 7528
1552
1553
1554
std::vector<Type1> operator/(std::vector<Type1> a, AMDA::Parameters::TabRow<Type2> b) {
    std::vector<Type2> bv(b);
    return a / bv;
9e4ae650   Benjamin Renard   Fix operators amb...
1555
1556
1557
}

template <typename Type1, typename Type2>
68af7c4e   Hacene SI HADJ MOHAND   nOk 7528
1558
1559
1560
std::vector<Type1> operator/(AMDA::Parameters::TabRow<Type1> a, std::vector<Type2> b) {
    std::vector<Type1> av(a);
    return av / b;
9e4ae650   Benjamin Renard   Fix operators amb...
1561
}
fbe3c2bb   Benjamin Renard   First commit
1562

c76233b2   Benjamin Renard   Check window time...
1563
template<typename Type>
a88dbf1e   Hacene SI HADJ MOHAND   9719 ok
1564
1565
1566
bool isValid(const std::string& num) {
    bool flag = true;
    try {
b7747945   Benjamin Renard   Fix some warning ...
1567
        boost::lexical_cast<Type>(num);
a88dbf1e   Hacene SI HADJ MOHAND   9719 ok
1568
1569
1570
1571
    } catch (boost::bad_lexical_cast &e) {
        flag = false;
    }
    return flag;
f5c74402   Hacene SI HADJ MOHAND   compilation ok
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
}

template <typename Type>
std::pair<Type, Type> operator-(std::pair<Type, Type> a, std::pair<Type, Type> b) {
    std::pair<Type, Type> c;
    c.first = a.first - b.firest;
    c.second = a.second - b.second;
    return c;
}

template <typename Type>
std::pair<Type, Type> operator+(std::pair<Type, Type> a, std::pair<Type, Type> b) {
    std::pair<Type, Type> c;
    c.first = a.first + b.firest;
    c.second = a.second + b.second;
    return c;
}

template <typename Type>
std::pair<Type, Type> operator*(std::pair<Type, Type> a, std::pair<Type, Type> b) {
    std::pair<Type, Type> c;
a88dbf1e   Hacene SI HADJ MOHAND   9719 ok
1593
1594
    c.first = a.first * b.firest;
    c.second = a.second * b.second;
f5c74402   Hacene SI HADJ MOHAND   compilation ok
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
    return c;
}

template <typename Type, typename Type2>
std::pair<Type, Type> operator/(std::pair<Type, Type> a, Type2 b) {
    std::pair<Type, Type> c;
    c.first = a.first / b;
    c.second = a.second / b;
    return c;
}
c76233b2   Benjamin Renard   Check window time...
1605

fbe3c2bb   Benjamin Renard   First commit
1606
#endif /* LOGICALDATATYPE_HH_ */