source: XIOS/dev/branch_yushan_merged/src/transformation/Functions/max_reduction.cpp @ 1205

Last change on this file since 1205 was 1205, checked in by yushan, 7 years ago

branch merged with trunk @1200

File size: 2.0 KB
RevLine 
[888]1/*!
2   \file max.cpp
3   \author Ha NGUYEN
4   \since 27 June 2016
5   \date 27 June 2016
6
7   \brief max reduction
8 */
[979]9#include "max_reduction.hpp"
[1018]10#include "utils.hpp"
[888]11
12namespace xios {
13
14CMaxReductionAlgorithm::CMaxReductionAlgorithm()
15  : CReductionAlgorithm()
16{
17}
18
19CReductionAlgorithm* CMaxReductionAlgorithm::create()
20{
21  return (new CMaxReductionAlgorithm());
22}
23
24bool CMaxReductionAlgorithm::registerTrans()
25{
26  return registerOperation(TRANS_REDUCE_MAX, CMaxReductionAlgorithm::create);
27}
28
29void CMaxReductionAlgorithm::apply(const std::vector<std::pair<int,double> >& localIndex,
30                                   const double* dataInput,
31                                   CArray<double,1>& dataOut,
[1018]32                                   std::vector<bool>& flagInitial,
[1076]33                                   bool ignoreMissingValue)
34{ 
35  if (ignoreMissingValue)
[888]36  {
[1018]37    int nbLocalIndex = localIndex.size();
[1205]38    int currentlocalIndex = 0;   
[1018]39    for (int idx = 0; idx < nbLocalIndex; ++idx)
[888]40    {
[1018]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::max(*(dataInput + idx), dataOut(currentlocalIndex));
52        }
53      }
[1205]54      else
55      {
56        if (flagInitial[currentlocalIndex]) 
57          dataOut(currentlocalIndex) = std::numeric_limits<double>::quiet_NaN();
58      }
[888]59    }
[1018]60  }
61  else
62  {
63    int nbLocalIndex = localIndex.size();
64    int currentlocalIndex = 0;   
65    for (int idx = 0; idx < nbLocalIndex; ++idx)
[888]66    {
[1018]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::max(*(dataInput + idx), dataOut(currentlocalIndex));
76      }
[888]77    }
78  }
79}
80
81}
Note: See TracBrowser for help on using the repository browser.