source: XIOS/dev/branch_yushan_merged/src/functor/average.cpp @ 1131

Last change on this file since 1131 was 1018, checked in by mhnguyen, 7 years ago

Improving missing-value processing
If detect_missing_value is activated, then all missing value will be converted to
NaN (Not-a-number) in input of data flow then they will be reconverted to missing value on output

+) Update SourceFilter?, TemporalFilter? and SpatialTransformFilter? with new processing
+) Update all transformations with new processing

Test
+) On Curie
+) Work

  • Property copyright set to
    Software name : XIOS (Xml I/O Server)
    http://forge.ipsl.jussieu.fr/ioserver
    Creation date : January 2009
    Licence : CeCCIL version2
    see license file in root directory : Licence_CeCILL_V2-en.txt
    or http://www.cecill.info/licences/Licence_CeCILL_V2-en.html
    Holder : CEA/LSCE (Laboratoire des Sciences du CLimat et de l'Environnement)
    CNRS/IPSL (Institut Pierre Simon Laplace)
    Project Manager : Yann Meurdesoif
    yann.meurdesoif@cea.fr
File size: 2.4 KB
Line 
1#include "average.hpp"
2#include "array_new.hpp"
3#include "utils.hpp"
4
5namespace xios
6{
7   namespace func
8   {
9      /// ////////////////////// Définitions ////////////////////// ///
10
11      CAverage::CAverage(CArray<double,1>& doutput)
12         : SuperClass(StdString("average"), doutput)
13      { /* Ne rien faire de plus */ }
14
15      CAverage::CAverage(CArray<double,1>& doutput, double missingValue)
16         : SuperClass(StdString("average"), doutput, missingValue)
17      { /* Ne rien faire de plus */ }
18
19      CAverage::~CAverage(void)
20      { /* Ne rien faire de plus */ }
21
22      //---------------------------------------------------------------
23
24      void CAverage::apply(const CArray<double,1>& _dinput,
25                                 CArray<double,1>& _doutput)
26      {
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() ;
44            for (i=0; i<n; ++i,++nc,++in) 
45              if (!NumTraits<double>::isnan(*in)) (*nc) ++;
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) 
57              if (!NumTraits<double>::isnan(*in)) 
58              {
59                if (*nc != 0) (*out)  += *in;
60                else *out = *in ;
61                (*nc) ++;
62              } 
63          }
64          else _doutput+=_dinput ;
65        }
66     
67      }
68     
69      void CAverage::final(void)
70      {
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; 
85        this->nbcall = 0; 
86
87      }
88   } // namespace func
89} // namespace xios
Note: See TracBrowser for help on using the repository browser.