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

Last change on this file since 1018 was 1018, checked in by mhnguyen, 4 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 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    for (int idx = 0; idx < nbLocalIndex; ++idx)
42    {
43      currentlocalIndex = localIndex[idx].first;
44      if (!NumTraits<double>::isnan(*(dataInput + idx)))
45      {
46        if (flagInitial[currentlocalIndex])
47        {
48          dataOut(currentlocalIndex) = *(dataInput + idx);
49          flagInitial[currentlocalIndex] = false;
50        }
51        else
52        {
53          dataOut(currentlocalIndex) = std::min(*(dataInput + idx), dataOut(currentlocalIndex));
54        }
55      }
56    }
57  }
58  else
59  {
60    int nbLocalIndex = localIndex.size();
61    int currentlocalIndex = 0;
62    for (int idx = 0; idx < nbLocalIndex; ++idx)
63    {
64      currentlocalIndex = localIndex[idx].first;
65      if (flagInitial[currentlocalIndex])
66      {
67        dataOut(currentlocalIndex) = *(dataInput + idx);
68        flagInitial[currentlocalIndex] = false;
69      }
70      else
71      {
72        dataOut(currentlocalIndex) = std::min(*(dataInput + idx), dataOut(currentlocalIndex));
73      }
74    }
75  }
76}
77
78}
Note: See TracBrowser for help on using the repository browser.