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

Last change on this file since 1076 was 1076, checked in by mhnguyen, 5 years ago

Correcting behavior of detecting_missing_value:

  • Missing value detection is activated only when detecting_missing_value = true

and a default_value is defined.

  • By default, undefined value by the computation of vertical (horizontal) interpolation will be NaN (not a number).

They are only converted to default_value if missing value detection is activated

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                                   bool ignoreMissingValue)
34{
35  if (ignoreMissingValue)
36  {
37    int nbLocalIndex = localIndex.size();
38    int currentlocalIndex = 0;
39
40    dataOut=std::numeric_limits<double>::quiet_NaN();
41 
42    for (int idx = 0; idx < nbLocalIndex; ++idx)
43    {
44      currentlocalIndex = localIndex[idx].first;   
45      if (!NumTraits<double>::isnan(*(dataInput + idx)))
46      {   
47        if (flagInitial[currentlocalIndex])
48        {
49          dataOut(currentlocalIndex) = *(dataInput + idx);
50          flagInitial[currentlocalIndex] = false;
51        }
52        else
53        {
54          dataOut(currentlocalIndex) += *(dataInput + idx);
55        }
56      }
57    }   
58  }
59  else
60  {
61    int nbLocalIndex = localIndex.size();
62    int currentlocalIndex = 0;   
63    for (int idx = 0; idx < nbLocalIndex; ++idx)
64    {
65      currentlocalIndex = localIndex[idx].first;     
66      if (flagInitial[currentlocalIndex])
67      {
68        dataOut(currentlocalIndex) = *(dataInput + idx);
69        flagInitial[currentlocalIndex] = false;
70      }
71      else
72      {
73        dataOut(currentlocalIndex) += *(dataInput + idx);
74      }
75    }
76  }
77}
78
79}
Note: See TracBrowser for help on using the repository browser.