source: XIOS/trunk/src/filter/temporal_filter.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: 2.4 KB
Line 
1#include "temporal_filter.hpp"
2#include "functor_type.hpp"
3#include "calendar_util.hpp"
4
5namespace xios
6{
7  CTemporalFilter::CTemporalFilter(CGarbageCollector& gc, const std::string& opId,
8                                   const CDate& initDate, const CDuration samplingFreq, const CDuration samplingOffset, const CDuration opFreq,
9                                   bool ignoreMissingValue /*= false*/, double missingValue /*= 0.0*/)
10    : CFilter(gc, 1, this)
11    , samplingFreq(samplingFreq)
12    , opFreq(opFreq)
13    , nextSamplingDate(initDate + samplingOffset + initDate.getRelCalendar().getTimeStep())
14    , nextOperationDate(initDate + opFreq)
15    , isFirstOperation(true)
16  {
17    double defaultValue = ignoreMissingValue ? std::numeric_limits<double>::quiet_NaN() : missingValue;
18   
19#define DECLARE_FUNCTOR(MType, mtype) \
20    if (opId.compare(#mtype) == 0) \
21    { \
22      if (ignoreMissingValue) \
23      { \
24        functor.reset(new func::C##MType(tmpData, defaultValue)); \
25      } \
26      else \
27      { \
28        functor.reset(new func::C##MType(tmpData)); \
29      } \
30    }
31
32#include "functor_type.conf"
33
34    if (!functor)
35      ERROR("CTemporalFilter::CTemporalFilter(CGarbageCollector& gc, const std::string& opId, ...)",
36            << "\"" << opId << "\" is not a valid operation.");
37
38    isOnceOperation = (functor->timeType() == func::CFunctor::once);
39  }
40
41  CDataPacketPtr CTemporalFilter::apply(std::vector<CDataPacketPtr> data)
42  {
43    CDataPacketPtr packet;
44
45    if (data[0]->status != CDataPacket::END_OF_STREAM)
46    {
47      const bool usePacket = isOnceOperation ? isFirstOperation : (data[0]->date >= nextSamplingDate);
48      if (usePacket)
49      {
50        if (!tmpData.numElements())
51          tmpData.resize(data[0]->data.numElements());
52
53        (*functor)(data[0]->data);
54
55        nextSamplingDate = nextSamplingDate + samplingFreq;
56      }
57
58      const bool outputResult = isOnceOperation ? isFirstOperation : (data[0]->date + samplingFreq > nextOperationDate);
59      if (outputResult)
60      {
61        functor->final();
62
63        packet = CDataPacketPtr(new CDataPacket);
64        packet->date = data[0]->date;
65        packet->timestamp = data[0]->timestamp;
66        packet->status = data[0]->status;
67        packet->data.resize(tmpData.numElements());
68        packet->data = tmpData;
69
70        isFirstOperation = false;
71        nextOperationDate = nextOperationDate + samplingFreq + opFreq - samplingFreq;
72      }
73    }
74
75    return packet;
76  }
77} // namespace xios
Note: See TracBrowser for help on using the repository browser.