[352] | 1 | |
---|
| 2 | #ifndef __FIELD_IMPL_HPP__ |
---|
| 3 | #define __FIELD_IMPL_HPP__ |
---|
| 4 | |
---|
| 5 | #include "xmlioserver_spl.hpp" |
---|
| 6 | #include "field.hpp" |
---|
| 7 | #include "context.hpp" |
---|
| 8 | #include "grid.hpp" |
---|
| 9 | #include "timer.hpp" |
---|
[369] | 10 | #include "array_new.hpp" |
---|
[352] | 11 | |
---|
[369] | 12 | |
---|
[352] | 13 | namespace xios { |
---|
| 14 | |
---|
[369] | 15 | template <int N> |
---|
| 16 | void CField::setData(const CArray<double, N>& _data) |
---|
[352] | 17 | { |
---|
| 18 | const std::vector<CField*>& refField=getAllReference(); |
---|
| 19 | std::vector<CField*>::const_iterator it = refField.begin(), end = refField.end(); |
---|
| 20 | |
---|
| 21 | for (; it != end; it++) (*it)->updateData(_data) ; |
---|
| 22 | } |
---|
| 23 | |
---|
[369] | 24 | template <int N> |
---|
| 25 | bool CField::updateData(const CArray<double, N>& _data) |
---|
[352] | 26 | { |
---|
| 27 | CContext* context=CContext::getCurrent(); |
---|
| 28 | const CDate & currDate = context->getCalendar()->getCurrentDate(); |
---|
| 29 | const CDate opeDate = *last_operation + freq_operation; |
---|
[436] | 30 | const CDate writeDate = *last_Write + freq_write; |
---|
| 31 | bool doOperation, doWrite; |
---|
| 32 | |
---|
[352] | 33 | |
---|
| 34 | |
---|
| 35 | info(50) << "CField::updateData " << currDate << " : send data to " << this->getBaseFieldId() << std::endl; |
---|
| 36 | info(50) << "Next operation " << opeDate<<std::endl; |
---|
[436] | 37 | |
---|
| 38 | doOperation = (opeDate <= currDate) ; |
---|
| 39 | if (isOnceOperation) |
---|
| 40 | if (isFirstOperation) doOperation=true ; |
---|
| 41 | else doOperation=false ; |
---|
| 42 | |
---|
| 43 | if (doOperation) |
---|
[352] | 44 | { |
---|
[369] | 45 | if (this->data.numElements() != this->grid->storeIndex_client.numElements()) |
---|
[352] | 46 | { |
---|
[369] | 47 | this->data.resize(this->grid->storeIndex_client.numElements()); |
---|
[352] | 48 | } |
---|
| 49 | |
---|
[369] | 50 | CArray<double,1> input(data.numElements()) ; |
---|
[352] | 51 | this->grid->inputField(_data, input); |
---|
| 52 | (*this->foperation)(input); |
---|
| 53 | |
---|
| 54 | *last_operation = currDate; |
---|
| 55 | info(50) << "(*last_operation = currDate) : " << *last_operation << " = " << currDate << std::endl; |
---|
| 56 | } |
---|
| 57 | |
---|
[436] | 58 | |
---|
| 59 | doWrite = (writeDate < (currDate + freq_operation)) ; |
---|
| 60 | if (isOnceOperation) |
---|
| 61 | { |
---|
| 62 | if(isFirstOperation) |
---|
| 63 | { |
---|
| 64 | doWrite=true ; |
---|
| 65 | isFirstOperation=false ; |
---|
| 66 | } |
---|
| 67 | else doWrite=false ; |
---|
| 68 | } |
---|
| 69 | |
---|
| 70 | if (doWrite) |
---|
[352] | 71 | { |
---|
| 72 | this->foperation->final(); |
---|
| 73 | *last_Write = writeDate; |
---|
| 74 | info(50) << "(*last_Write = currDate) : " << *last_Write << " = " << currDate << std::endl; |
---|
| 75 | CTimer::get("XIOS Send Data").resume() ; |
---|
| 76 | sendUpdateData() ; |
---|
| 77 | CTimer::get("XIOS Send Data").suspend() ; |
---|
| 78 | return (true); |
---|
| 79 | } |
---|
| 80 | |
---|
| 81 | return (false); |
---|
| 82 | } |
---|
| 83 | |
---|
| 84 | } // namespace xios |
---|
| 85 | |
---|
| 86 | #endif |
---|