source: XIOS/trunk/src/filter/file_writer_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: 1.0 KB
Line 
1#include "file_writer_filter.hpp"
2#include "exception.hpp"
3#include "field.hpp"
4#include "utils.hpp"
5
6namespace xios
7{
8  CFileWriterFilter::CFileWriterFilter(CGarbageCollector& gc, CField* field)
9    : CInputPin(gc, 1)
10    , field(field)
11  {
12    if (!field)
13      ERROR("CFileWriterFilter::CFileWriterFilter(CField* field)",
14            "The field cannot be null.");
15  }
16
17  void CFileWriterFilter::onInputReady(std::vector<CDataPacketPtr> data)
18  {
19    bool ignoreMissingValue = (!field->detect_missing_value.isEmpty() && 
20                               !field->default_value.isEmpty() && 
21                               field->detect_missing_value == true);
22    if (ignoreMissingValue)
23    {
24      double missingValue = field->default_value;
25      size_t nbData = data[0]->data.numElements();
26      for (size_t idx = 0; idx < nbData; ++idx)
27      {
28        if (NumTraits<double>::isnan(data[0]->data(idx)))
29          data[0]->data(idx) = missingValue;
30      }
31    }   
32
33    field->sendUpdateData(data[0]->data);
34  }
35} // namespace xios
Note: See TracBrowser for help on using the repository browser.