source: XIOS/trunk/src/transformation/Functions/sum_reduction.cpp @ 1018

Last change on this file since 1018 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

File size: 1.9 KB
Line 
1/*!
2   \file sum.cpp
3   \author Ha NGUYEN
4   \since 27 June 2016
5   \date 9 Jan 2017
6
7   \brief sum reduction
8 */
9#include "sum_reduction.hpp"
10#include "utils.hpp"
11
12namespace xios {
13
14CSumReductionAlgorithm::CSumReductionAlgorithm()
15  : CReductionAlgorithm()
16{
17}
18
19CReductionAlgorithm* CSumReductionAlgorithm::create()
20{
21  return (new CSumReductionAlgorithm());
22}
23
24bool CSumReductionAlgorithm::registerTrans()
25{
26  return registerOperation(TRANS_REDUCE_SUM, CSumReductionAlgorithm::create);
27}
28
29void CSumReductionAlgorithm::apply(const std::vector<std::pair<int,double> >& localIndex,
30                                   const double* dataInput,
31                                   CArray<double,1>& dataOut,
32                                   std::vector<bool>& flagInitial,
33                                   const double& defaultValue)
34{
35  bool hasMissingValue = NumTraits<double>::isnan(defaultValue);
36  if (hasMissingValue)
37  {
38    int nbLocalIndex = localIndex.size();
39    int currentlocalIndex = 0;   
40    for (int idx = 0; idx < nbLocalIndex; ++idx)
41    {
42      currentlocalIndex = localIndex[idx].first;   
43      if (!NumTraits<double>::isnan(*(dataInput + idx)))
44      {   
45        if (flagInitial[currentlocalIndex])
46        {
47          dataOut(currentlocalIndex) = *(dataInput + idx);
48          flagInitial[currentlocalIndex] = false;
49        }
50        else
51        {
52          dataOut(currentlocalIndex) += *(dataInput + idx);
53        }
54      }
55    }   
56  }
57  else
58  {
59    int nbLocalIndex = localIndex.size();
60    int currentlocalIndex = 0;   
61    for (int idx = 0; idx < nbLocalIndex; ++idx)
62    {
63      currentlocalIndex = localIndex[idx].first;     
64      if (flagInitial[currentlocalIndex])
65      {
66        dataOut(currentlocalIndex) = *(dataInput + idx);
67        flagInitial[currentlocalIndex] = false;
68      }
69      else
70      {
71        dataOut(currentlocalIndex) += *(dataInput + idx);
72      }
73    }
74  }
75}
76
77}
Note: See TracBrowser for help on using the repository browser.