[219] | 1 | #include "average.hpp" |
---|
[369] | 2 | #include "array_new.hpp" |
---|
[1158] | 3 | #include "utils.hpp" |
---|
[219] | 4 | |
---|
[335] | 5 | namespace xios |
---|
[219] | 6 | { |
---|
| 7 | namespace func |
---|
| 8 | { |
---|
| 9 | /// ////////////////////// Définitions ////////////////////// /// |
---|
| 10 | |
---|
[369] | 11 | CAverage::CAverage(CArray<double,1>& doutput) |
---|
[219] | 12 | : SuperClass(StdString("average"), doutput) |
---|
[380] | 13 | { /* Ne rien faire de plus */ } |
---|
[219] | 14 | |
---|
[470] | 15 | CAverage::CAverage(CArray<double,1>& doutput, double missingValue) |
---|
| 16 | : SuperClass(StdString("average"), doutput, missingValue) |
---|
| 17 | { /* Ne rien faire de plus */ } |
---|
| 18 | |
---|
[219] | 19 | CAverage::~CAverage(void) |
---|
| 20 | { /* Ne rien faire de plus */ } |
---|
| 21 | |
---|
| 22 | //--------------------------------------------------------------- |
---|
| 23 | |
---|
[369] | 24 | void CAverage::apply(const CArray<double,1>& _dinput, |
---|
| 25 | CArray<double,1>& _doutput) |
---|
[219] | 26 | { |
---|
[470] | 27 | if (hasMissingValue) |
---|
| 28 | { |
---|
| 29 | if (nbcalls.numElements()==0) |
---|
| 30 | { |
---|
| 31 | nbcalls.resize(_dinput.numElements()) ; |
---|
| 32 | nbcalls=0 ; |
---|
| 33 | } |
---|
| 34 | } |
---|
| 35 | |
---|
| 36 | if (this->nbcall == 1) |
---|
| 37 | { |
---|
| 38 | _doutput=_dinput ; |
---|
| 39 | if (hasMissingValue) |
---|
| 40 | { |
---|
| 41 | int i, n =_dinput.numElements() ; |
---|
| 42 | const double * in=_dinput.dataFirst() ; |
---|
| 43 | int* nc=nbcalls.dataFirst() ; |
---|
[588] | 44 | for (i=0; i<n; ++i,++nc,++in) |
---|
[1474] | 45 | if (!NumTraits<double>::isNan(*in)) (*nc) ++; |
---|
[470] | 46 | } |
---|
| 47 | } |
---|
| 48 | else |
---|
| 49 | { |
---|
| 50 | if (hasMissingValue) |
---|
| 51 | { |
---|
| 52 | int i, n =_dinput.numElements() ; |
---|
| 53 | const double * in=_dinput.dataFirst() ; |
---|
| 54 | double* out=_doutput.dataFirst(); |
---|
| 55 | int* nc=nbcalls.dataFirst() ; |
---|
| 56 | for (i=0; i<n; ++i,++in,++out,++nc) |
---|
[1474] | 57 | if (!NumTraits<double>::isNan(*in)) |
---|
[470] | 58 | { |
---|
| 59 | if (*nc != 0) (*out) += *in; |
---|
| 60 | else *out = *in ; |
---|
| 61 | (*nc) ++; |
---|
| 62 | } |
---|
| 63 | } |
---|
| 64 | else _doutput+=_dinput ; |
---|
| 65 | } |
---|
[369] | 66 | |
---|
[219] | 67 | } |
---|
[266] | 68 | |
---|
| 69 | void CAverage::final(void) |
---|
| 70 | { |
---|
[470] | 71 | if (hasMissingValue) |
---|
| 72 | { |
---|
| 73 | int i, n = nbcalls.numElements() ; |
---|
| 74 | double* out= doutput.dataFirst(); |
---|
| 75 | int* nc=nbcalls.dataFirst() ; |
---|
| 76 | for (i=0; i<n; ++i, ++out,++nc) |
---|
| 77 | if (*nc!=0) |
---|
| 78 | { |
---|
| 79 | *out /= *nc; |
---|
| 80 | *nc = 0 ; |
---|
| 81 | } |
---|
| 82 | |
---|
| 83 | } |
---|
| 84 | else doutput/=this->nbcall; |
---|
[369] | 85 | this->nbcall = 0; |
---|
[470] | 86 | |
---|
[266] | 87 | } |
---|
[219] | 88 | } // namespace func |
---|
[591] | 89 | } // namespace xios |
---|