source: XIOS/trunk/src/node/field_impl.hpp @ 459

Last change on this file since 459 was 459, checked in by ymipsl, 10 years ago

Add new parsing expression functionnalities
(modified files)

YM

File size: 4.4 KB
Line 
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"
10#include "array_new.hpp"
11
12
13namespace xios {
14
15  template <int N>
16  void CField::setData(const CArray<double, N>& _data)
17  {
18    if (hasInstantData) 
19    {
20      grid->inputField(_data, instantData); 
21      for(list< pair<CField *,int> >::iterator it=fieldDependency.begin(); it!=fieldDependency.end(); ++it)  it->first->setSlot(it->second) ;
22    }
23   
24    if (!hasExpression)
25    {
26      const std::vector<CField*>& refField=getAllReference();
27      std::vector<CField*>::const_iterator  it = refField.begin(), end = refField.end();
28     
29      for (; it != end; it++) (*it)->setData(_data) ;
30      if (hasOutputFile) updateData(_data) ;
31    }
32     
33  }
34
35
36   template <int N>
37   bool CField::updateData(const CArray<double, N>& _data)
38   {       
39      CContext* context=CContext::getCurrent();
40      const CDate & currDate = context->getCalendar()->getCurrentDate();
41      const CDate opeDate      = *last_operation + freq_operation;
42      const CDate writeDate    = *last_Write     + freq_write;       
43      bool doOperation, doWrite; 
44
45   
46      info(50) << "CField::updateData " << currDate <<  " : send data to " << this->getBaseFieldId() << std::endl;
47      info(50) << "Next operation "  << opeDate<<std::endl;
48
49      doOperation = (opeDate <= currDate) ;
50      if (isOnceOperation)
51        if (isFirstOperation) doOperation=true ;
52        else doOperation=false ;
53
54      if (doOperation)
55      {
56         if (this->data.numElements() != this->grid->storeIndex_client.numElements())
57         {
58            this->data.resize(this->grid->storeIndex_client.numElements());
59         }
60           
61         CArray<double,1> input(data.numElements()) ;
62         this->grid->inputField(_data, input);         
63         (*this->foperation)(input);
64         
65         *last_operation = currDate;
66         info(50) << "(*last_operation = currDate) : " << *last_operation << " = " << currDate << std::endl; 
67      }
68
69      doWrite = (writeDate < (currDate + freq_operation)) ;
70      if (isOnceOperation)
71      { 
72        if(isFirstOperation) 
73        {
74          doWrite=true ;
75          isFirstOperation=false ;
76        }
77        else doWrite=false ;
78      }
79     
80      if (doWrite)
81      {
82         this->foperation->final();
83         *last_Write = writeDate;
84         info(50) << "(*last_Write = currDate) : " << *last_Write << " = " << currDate << std::endl;
85         CTimer::get("XIOS Send Data").resume() ;
86         sendUpdateData() ;
87         CTimer::get("XIOS Send Data").suspend() ;
88         return (true);       
89      }
90
91      return (false);
92   }
93   
94   bool CField::updateDataFromExpression(const CArray<double, 1>& _data)
95   {       
96      CContext* context=CContext::getCurrent();
97      const CDate & currDate = context->getCalendar()->getCurrentDate();
98      const CDate opeDate      = *last_operation + freq_operation;
99      const CDate writeDate    = *last_Write     + freq_write;       
100      bool doOperation, doWrite; 
101
102   
103      info(50) << "CField::updateData " << currDate <<  " : send data to " << this->getBaseFieldId() << std::endl;
104      info(50) << "Next operation "  << opeDate<<std::endl;
105
106      doOperation = (opeDate <= currDate) ;
107      if (isOnceOperation)
108        if (isFirstOperation) doOperation=true ;
109        else doOperation=false ;
110
111      if (doOperation)
112      {
113         if (this->data.numElements() != this->grid->storeIndex_client.numElements())
114         {
115            this->data.resize(this->grid->storeIndex_client.numElements());
116         }
117           
118        (*this->foperation)(_data);
119         
120         *last_operation = currDate;
121         info(50) << "(*last_operation = currDate) : " << *last_operation << " = " << currDate << std::endl; 
122      }
123
124      doWrite = (writeDate < (currDate + freq_operation)) ;
125      if (isOnceOperation)
126      { 
127        if(isFirstOperation) 
128        {
129          doWrite=true ;
130          isFirstOperation=false ;
131        }
132        else doWrite=false ;
133      }
134     
135      if (doWrite)
136      {
137         this->foperation->final();
138         *last_Write = writeDate;
139         info(50) << "(*last_Write = currDate) : " << *last_Write << " = " << currDate  << std::endl;
140         CTimer::get("XIOS Send Data").resume() ;
141         sendUpdateData() ;
142         CTimer::get("XIOS Send Data").suspend() ;
143         return (true);       
144      }
145
146      return (false);
147   }
148
149} // namespace xios
150
151#endif
Note: See TracBrowser for help on using the repository browser.