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
RevLine 
[888]1/*!
2   \file min.cpp
3   \author Ha NGUYEN
4   \since 27 June 2016
[1018]5   \date 9 Jan 2017
[888]6
7   \brief min reduction
8 */
[979]9#include "min_reduction.hpp"
[1018]10#include "utils.hpp"
[888]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,
[1018]32                                   std::vector<bool>& flagInitial,
33                                   const double& defaultValue)
[888]34{
[1018]35  bool hasMissingValue = NumTraits<double>::isnan(defaultValue);
36
37  if (hasMissingValue)
[888]38  {
[1018]39    int nbLocalIndex = localIndex.size();
40    int currentlocalIndex = 0;
41    for (int idx = 0; idx < nbLocalIndex; ++idx)
[888]42    {
[1018]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      }
[888]56    }
[1018]57  }
58  else
59  {
60    int nbLocalIndex = localIndex.size();
61    int currentlocalIndex = 0;
62    for (int idx = 0; idx < nbLocalIndex; ++idx)
[888]63    {
[1018]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      }
[888]74    }
75  }
76}
77
78}
Note: See TracBrowser for help on using the repository browser.