source: XIOS/trunk/src/functor/average.cpp @ 501

Last change on this file since 501 was 501, checked in by ymipsl, 9 years ago

Add licence copyright to all file ond directory src using the command :
svn propset -R copyright -F header_licence src

XIOS is now officialy under CeCILL licence

YM

  • 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.3 KB
Line 
1#include "average.hpp"
2#include "array_new.hpp"
3
4namespace xios
5{
6   namespace func
7   {
8      /// ////////////////////// Définitions ////////////////////// ///
9
10      CAverage::CAverage(CArray<double,1>& doutput)
11         : SuperClass(StdString("average"), doutput)
12      { /* Ne rien faire de plus */ }
13
14      CAverage::CAverage(CArray<double,1>& doutput, double missingValue)
15         : SuperClass(StdString("average"), doutput, missingValue)
16      { /* Ne rien faire de plus */ }
17
18      CAverage::~CAverage(void)
19      { /* Ne rien faire de plus */ }
20
21      //---------------------------------------------------------------
22
23      void CAverage::apply(const CArray<double,1>& _dinput,
24                                 CArray<double,1>& _doutput)
25      {
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() ;
43            for (i=0; i<n; ++i,++nc) 
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        }
65     
66      }
67     
68      void CAverage::final(void)
69      {
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; 
84        this->nbcall = 0; 
85
86      }
87   } // namespace func
88} // namespace xmlioserver
Note: See TracBrowser for help on using the repository browser.