source: XIOS/trunk/src/filter/source_filter.cpp @ 827

Last change on this file since 827 was 756, checked in by rlacroix, 9 years ago

Support freq_offset for fields in files in read mode.

In theory the first record of a file being read is available at timestep 0, this allows to delay the availability of the data to a later timestep.

Use a temporary solution for now until this can be properly integrated in a temporal filter.

File size: 2.4 KB
RevLine 
[638]1#include "source_filter.hpp"
2#include "grid.hpp"
3#include "exception.hpp"
[756]4#include "calendar_util.hpp"
[638]5
6namespace xios
7{
[756]8  CSourceFilter::CSourceFilter(CGrid* grid, const CDuration offset /*= NoneDu*/)
[638]9    : grid(grid)
[756]10    , offset(offset)
[638]11  {
12    if (!grid)
13      ERROR("CSourceFilter::CSourceFilter(CGrid* grid)",
14            "Impossible to construct a source filter without providing a grid.");
15  }
16
17  template <int N>
[643]18  void CSourceFilter::streamData(CDate date, const CArray<double, N>& data)
[638]19  {
[756]20    date = date + offset; // this is a temporary solution, it should be part of a proper temporal filter
21
[638]22    CDataPacketPtr packet(new CDataPacket);
[643]23    packet->date = date;
24    packet->timestamp = date;
[638]25    packet->status = CDataPacket::NO_ERROR;
26
27    packet->data.resize(grid->storeIndex_client.numElements());
28    grid->inputField(data, packet->data);
29
30    deliverOuput(packet);
31  }
32
[643]33  template void CSourceFilter::streamData<1>(CDate date, const CArray<double, 1>& data);
34  template void CSourceFilter::streamData<2>(CDate date, const CArray<double, 2>& data);
35  template void CSourceFilter::streamData<3>(CDate date, const CArray<double, 3>& data);
[638]36
[643]37  void CSourceFilter::streamDataFromServer(CDate date, const std::map<int, CArray<double, 1> >& data)
[638]38  {
[756]39    date = date + offset; // this is a temporary solution, it should be part of a proper temporal filter
40
[638]41    CDataPacketPtr packet(new CDataPacket);
[643]42    packet->date = date;
43    packet->timestamp = date;
[638]44    packet->status = CDataPacket::NO_ERROR;
45
46    if (data.size() != grid->storeIndex_toSrv.size())
[643]47      ERROR("CSourceFilter::streamDataFromServer(CDate date, const std::map<int, CArray<double, 1> >& data)",
[638]48            << "Incoherent data received from servers,"
49            << " expected " << grid->storeIndex_toSrv.size() << " chunks but " << data.size() << " were given.");
50
51    packet->data.resize(grid->storeIndex_client.numElements());
52    std::map<int, CArray<double, 1> >::const_iterator it, itEnd = data.end();
53    for (it = data.begin(); it != itEnd; it++)
54    {
[650]55      CArray<int,1>& index = grid->storeIndex_toSrv[it->first];
[638]56
57      for (int n = 0; n < index.numElements(); n++)
58        packet->data(index(n)) = it->second(n);
59    }
60
61    deliverOuput(packet);
62  }
63
[643]64  void CSourceFilter::signalEndOfStream(CDate date)
[638]65  {
66    CDataPacketPtr packet(new CDataPacket);
[643]67    packet->date = date;
68    packet->timestamp = date;
[638]69    packet->status = CDataPacket::END_OF_STREAM;
70    deliverOuput(packet);
71  }
72} // namespace xios
Note: See TracBrowser for help on using the repository browser.