source: XIOS/dev/branch_openmp/src/transformation/Functions/max_reduction.cpp @ 1482

Last change on this file since 1482 was 1482, checked in by yushan, 6 years ago

Branch EP merged with Dev_cmip6 @r1481

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