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

Last change on this file since 1154 was 1154, checked in by mhnguyen, 4 years ago

Correcting a bug: activating detect_missing_value on field source doesn't work correctly

+) If all source data corresponding to a destination data are NaN, this destination data
will turn to be NaN even its default value is zero

Test
+) On Curie
+) Work

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