source: XIOS/dev/branch_openmp/src/functor/average.cpp @ 1482

Last change on this file since 1482 was 1482, checked in by yushan, 6 years ago

Branch EP merged with Dev_cmip6 @r1481

  • 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
RevLine 
[219]1#include "average.hpp"
[369]2#include "array_new.hpp"
[1018]3#include "utils.hpp"
[219]4
[335]5namespace 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) 
[1482]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) 
[1482]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
Note: See TracBrowser for help on using the repository browser.