source: XIOS/trunk/src/filter/store_filter.cpp @ 988

Last change on this file since 988 was 932, checked in by mhnguyen, 8 years ago

Adding Fortran interface for high-dimension grid (up to 7)

+) Add check mask for high-dimension grid
+) Add Fortran interface for send_field, recv_field

Test
+) On Curie
+) Work

File size: 2.8 KB
Line 
1#include "store_filter.hpp"
2#include "context.hpp"
3#include "grid.hpp"
4#include "timer.hpp"
5
6namespace xios
7{
8  CStoreFilter::CStoreFilter(CGarbageCollector& gc, CContext* context, CGrid* grid)
9    : CInputPin(gc, 1)
10    , context(context)
11    , grid(grid)
12  {
13    if (!context)
14      ERROR("CStoreFilter::CStoreFilter(CContext* context, CGrid* grid)",
15            "Impossible to construct a store filter without providing a context.");
16    if (!grid)
17      ERROR("CStoreFilter::CStoreFilter(CContext* context, CGrid* grid)",
18            "Impossible to construct a store filter without providing a grid.");
19  }
20
21  CConstDataPacketPtr CStoreFilter::getPacket(Time timestamp)
22  {
23    CTimer timer("CStoreFilter::getPacket");
24    CConstDataPacketPtr packet;
25    const double timeout = 10; // 10 seconds timeout
26
27    do
28    {
29      timer.resume();
30
31      std::map<Time, CDataPacketPtr>::const_iterator it = packets.find(timestamp);
32      if (it != packets.end())
33        packet = it->second;
34      else // if the packet is not available yet, check if it can be received
35        context->checkBuffersAndListen();
36
37      timer.suspend();
38    } while (!packet && timer.getCumulatedTime() < timeout);
39
40    if (!packet)
41      ERROR("CConstDataPacketPtr CStoreFilter::getPacket(Time timestamp) const",
42            << "Impossible to get the packet with timestamp = " << timestamp);
43
44    return packet;
45  }
46
47  template <int N>
48  CDataPacket::StatusCode CStoreFilter::getData(Time timestamp, CArray<double, N>& data)
49  {
50    CConstDataPacketPtr packet = getPacket(timestamp);
51
52    if (packet->status == CDataPacket::NO_ERROR)
53      grid->outputField(packet->data, data);
54
55    return packet->status;
56  }
57
58  template CDataPacket::StatusCode CStoreFilter::getData<1>(Time timestamp, CArray<double, 1>& data);
59  template CDataPacket::StatusCode CStoreFilter::getData<2>(Time timestamp, CArray<double, 2>& data);
60  template CDataPacket::StatusCode CStoreFilter::getData<3>(Time timestamp, CArray<double, 3>& data);
61  template CDataPacket::StatusCode CStoreFilter::getData<4>(Time timestamp, CArray<double, 4>& data);
62  template CDataPacket::StatusCode CStoreFilter::getData<5>(Time timestamp, CArray<double, 5>& data);
63  template CDataPacket::StatusCode CStoreFilter::getData<6>(Time timestamp, CArray<double, 6>& data);
64  template CDataPacket::StatusCode CStoreFilter::getData<7>(Time timestamp, CArray<double, 7>& data);
65
66  void CStoreFilter::onInputReady(std::vector<CDataPacketPtr> data)
67  {
68    packets.insert(std::make_pair(data[0]->timestamp, data[0]));
69    // The packet is always destroyed by the garbage collector
70    // so we register but never unregister
71    gc.registerFilter(this, data[0]->timestamp);
72  }
73
74  void CStoreFilter::invalidate(Time timestamp)
75  {
76    CInputPin::invalidate(timestamp);
77    packets.erase(packets.begin(), packets.lower_bound(timestamp));
78  }
79} // namespace xios
Note: See TracBrowser for help on using the repository browser.