Ignore:
Timestamp:
01/30/14 15:55:42 (10 years ago)
Author:
ymipsl
Message:

Enhancement : using new field attribute "detect_missing_value=true" adn defining a default value, the temporal operator (average, minimum, maximum, accumulate ...) detect missing value in the field and don't take them into account to perform the operation.

YM

File:
1 edited

Legend:

Unmodified
Added
Removed
  • XIOS/trunk/src/functor/average.cpp

    r380 r470  
    1212      { /* Ne rien faire de plus */ } 
    1313 
     14      CAverage::CAverage(CArray<double,1>& doutput, double missingValue) 
     15         : SuperClass(StdString("average"), doutput, missingValue) 
     16      { /* Ne rien faire de plus */ } 
     17 
    1418      CAverage::~CAverage(void) 
    1519      { /* Ne rien faire de plus */ } 
     
    2024                                 CArray<double,1>& _doutput) 
    2125      { 
    22 /* 
    23          const double * it1  = _dinput->data(), 
    24                       * end1 = _dinput->data() + _dinput->num_elements();  
    25                double * it   = _doutput->data(); 
    26          if (this->nbcall == 1) 
    27               for (; it1 != end1; it1++, it++) *it  = *it1; 
    28          else for (; it1 != end1; it1++, it++) *it += *it1;                
    29 */ 
    30         if (this->nbcall == 1) _doutput=_dinput ; 
    31         else _doutput+=_dinput ; 
     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        } 
    3265       
    3366      } 
     
    3568      void CAverage::final(void) 
    3669      { 
    37 /*          double * it1  = this->getDataOutput()->data(), 
    38                  * end1 = this->getDataOutput()->data() + this->getDataOutput()->num_elements(); 
    39           for (; it1 != end1; it1++) *it1 /= this->nbcall; 
    40           this->nbcall = 0;                                                    
    41 */ 
    42         doutput/=this->nbcall;  
     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;  
    4384        this->nbcall = 0;  
     85 
    4486      } 
    4587   } // namespace func 
Note: See TracChangeset for help on using the changeset viewer.