source: XIOS/dev/dev_ym/XIOS_COUPLING/src/filter/model_to_client_source_filter.cpp @ 2010

Last change on this file since 2010 was 1930, checked in by ymipsl, 4 years ago

Big update on on going work related to data distribution and transfer between clients and servers.
Revisite of the source and store filter using "connectors".

YM

  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 2.5 KB
Line 
1#include "model_to_client_source_filter.hpp"
2#include "grid.hpp"
3#include "exception.hpp"
4#include "calendar_util.hpp"
5#include <limits>
6
7namespace xios
8{
9  CModelToClientSourceFilter::CModelToClientSourceFilter(CGarbageCollector& gc, CGrid* grid, bool hasMissingValue, double defaultValue)
10    : COutputPin(gc)
11    , grid_(grid)
12    , hasMissingValue_(hasMissingValue), defaultValue_(defaultValue)
13  {
14    if (!grid)
15      ERROR("CSourceFilter::CSourceFilter(CGrid* grid)",
16            "Impossible to construct a source filter without providing a grid.");
17  }
18
19  template <int N>
20  void CModelToClientSourceFilter::streamData(CDate date, const CArray<double, N>& data)
21  {
22    CDataPacketPtr packet(new CDataPacket);
23    packet->date = date;
24    packet->timestamp = date;
25    packet->status = CDataPacket::NO_ERROR;
26   
27    auto connector = grid_->getModelToWorkflowConnector() ;
28
29    if (connector->getSrcSize() != data.numElements())
30      ERROR("void CModelToClientSourceFilter::streamData(CDate date, const CArray<double, N>& data)",
31            << "[ Awaiting data of size = " <<connector->getSrcSize() << ", "
32            << "Received data size = "      << data.numElements() << " ] "
33            << "The data array does not have the right size! "
34            << "grid = " << grid_->getId())
35    const double nanValue = std::numeric_limits<double>::quiet_NaN();
36    packet->data.resize(connector->getDstSize()) ;
37    connector->transfer(data, packet->data, nanValue) ;
38
39    if (hasMissingValue_)
40    {
41        const double nanValue = std::numeric_limits<double>::quiet_NaN();
42        const size_t nbData = packet->data.numElements();
43        for (size_t idx = 0; idx < nbData; ++idx)
44          if (defaultValue_ == packet->data(idx))   packet->data(idx) = nanValue;
45    }
46   
47    onOutputReady(packet);
48  }
49
50  template void CModelToClientSourceFilter::streamData<1>(CDate date, const CArray<double, 1>& data);
51  template void CModelToClientSourceFilter::streamData<2>(CDate date, const CArray<double, 2>& data);
52  template void CModelToClientSourceFilter::streamData<3>(CDate date, const CArray<double, 3>& data);
53  template void CModelToClientSourceFilter::streamData<4>(CDate date, const CArray<double, 4>& data);
54  template void CModelToClientSourceFilter::streamData<5>(CDate date, const CArray<double, 5>& data);
55  template void CModelToClientSourceFilter::streamData<6>(CDate date, const CArray<double, 6>& data);
56  template void CModelToClientSourceFilter::streamData<7>(CDate date, const CArray<double, 7>& data);
57
58} // namespace xios
Note: See TracBrowser for help on using the repository browser.