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