source: XIOS/trunk/src/transformation/Functions/min_reduction.cpp @ 1043

Last change on this file since 1043 was 1043, checked in by ymipsl, 4 years ago

Undefined value after spatial domain reduction will apear as missing value.

YM

File size: 2.0 KB
Line 
1/*!
2   \file min.cpp
3   \author Ha NGUYEN
4   \since 27 June 2016
5   \date 9 Jan 2017
6
7   \brief min reduction
8 */
9#include "min_reduction.hpp"
10#include "utils.hpp"
11
12namespace xios {
13
14CMinReductionAlgorithm::CMinReductionAlgorithm()
15  : CReductionAlgorithm()
16{
17}
18
19CReductionAlgorithm* CMinReductionAlgorithm::create()
20{
21  return (new CMinReductionAlgorithm());
22}
23
24bool CMinReductionAlgorithm::registerTrans()
25{
26  return registerOperation(TRANS_REDUCE_MIN, CMinReductionAlgorithm::create);
27}
28
29void CMinReductionAlgorithm::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
37  if (hasMissingValue)
38  {
39    int nbLocalIndex = localIndex.size();
40    int currentlocalIndex = 0;
41    dataOut=std::numeric_limits<double>::quiet_NaN();
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) = std::min(*(dataInput + idx), dataOut(currentlocalIndex));
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) = std::min(*(dataInput + idx), dataOut(currentlocalIndex));
74      }
75    }
76  }
77}
78
79}
Note: See TracBrowser for help on using the repository browser.