source: XIOS/dev/dev_olga/src/node/field.cpp @ 1144

Last change on this file since 1144 was 1144, checked in by mhnguyen, 7 years ago

Cleaning up some redundant codes

  • Property copyright set to
    Software name : XIOS (Xml I/O Server)
    http://forge.ipsl.jussieu.fr/ioserver
    Creation date : January 2009
    Licence : CeCCIL version2
    see license file in root directory : Licence_CeCILL_V2-en.txt
    or http://www.cecill.info/licences/Licence_CeCILL_V2-en.html
    Holder : CEA/LSCE (Laboratoire des Sciences du CLimat et de l'Environnement)
    CNRS/IPSL (Institut Pierre Simon Laplace)
    Project Manager : Yann Meurdesoif
    yann.meurdesoif@cea.fr
  • Property svn:executable set to *
File size: 46.7 KB
Line 
1#include "field.hpp"
2
3#include "attribute_template.hpp"
4#include "object_template.hpp"
5#include "group_template.hpp"
6
7#include "node_type.hpp"
8#include "calendar_util.hpp"
9#include "message.hpp"
10#include "xios_spl.hpp"
11#include "type.hpp"
12#include "timer.hpp"
13#include "context_client.hpp"
14#include "context_server.hpp"
15#include <set>
16#include "garbage_collector.hpp"
17#include "source_filter.hpp"
18#include "store_filter.hpp"
19#include "file_writer_filter.hpp"
20#include "pass_through_filter.hpp"
21#include "filter_expr_node.hpp"
22#include "lex_parser.hpp"
23#include "temporal_filter.hpp"
24#include "spatial_transform_filter.hpp"
25#include "file_server_writer_filter.hpp"
26
27namespace xios{
28
29   /// ////////////////////// Définitions ////////////////////// ///
30
31   CField::CField(void)
32      : CObjectTemplate<CField>(), CFieldAttributes()
33      , grid(), file()
34      , written(false)
35      , nstep(0), nstepMax(0)
36      , hasOutputFile(false)
37      , domAxisScalarIds_(vector<StdString>(3,""))
38      , areAllReferenceSolved(false), isReferenceSolved(false), isReferenceSolvedAndTransformed(false)
39      , useCompressedOutput(false)
40      , wasDataAlreadyReceivedFromServer(false)
41   { setVirtualVariableGroup(CVariableGroup::create(getId() + "_virtual_variable_group")); }
42
43   CField::CField(const StdString& id)
44      : CObjectTemplate<CField>(id), CFieldAttributes()
45      , grid(), file()
46      , written(false)
47      , nstep(0), nstepMax(0)
48      , hasOutputFile(false)
49      , domAxisScalarIds_(vector<StdString>(3,""))
50      , areAllReferenceSolved(false), isReferenceSolved(false), isReferenceSolvedAndTransformed(false)
51      , useCompressedOutput(false)
52      , wasDataAlreadyReceivedFromServer(false)
53   { setVirtualVariableGroup(CVariableGroup::create(getId() + "_virtual_variable_group")); }
54
55   CField::~CField(void)
56   {}
57
58  //----------------------------------------------------------------
59
60   void CField::setVirtualVariableGroup(CVariableGroup* newVVariableGroup)
61   {
62      this->vVariableGroup = newVVariableGroup;
63   }
64
65   CVariableGroup* CField::getVirtualVariableGroup(void) const
66   {
67      return this->vVariableGroup;
68   }
69
70   std::vector<CVariable*> CField::getAllVariables(void) const
71   {
72      return this->vVariableGroup->getAllChildren();
73   }
74
75   void CField::solveDescInheritance(bool apply, const CAttributeMap* const parent)
76   {
77      SuperClassAttribute::setAttributes(parent, apply);
78      this->getVirtualVariableGroup()->solveDescInheritance(apply, NULL);
79   }
80
81  //----------------------------------------------------------------
82
83  bool CField::dispatchEvent(CEventServer& event)
84  {
85    if (SuperClass::dispatchEvent(event)) return true;
86    else
87    {
88      switch(event.type)
89      {
90        case EVENT_ID_UPDATE_DATA :
91          recvUpdateData(event);
92          return true;
93          break;
94
95        case EVENT_ID_READ_DATA :
96          recvReadDataRequest(event);
97          return true;
98          break;
99
100        case EVENT_ID_READ_DATA_READY :
101          recvReadDataReady(event);
102          return true;
103          break;
104
105        case EVENT_ID_ADD_VARIABLE :
106          recvAddVariable(event);
107          return true;
108          break;
109
110        case EVENT_ID_ADD_VARIABLE_GROUP :
111          recvAddVariableGroup(event);
112          return true;
113          break;
114
115        default :
116          ERROR("bool CField::dispatchEvent(CEventServer& event)", << "Unknown Event");
117          return false;
118      }
119    }
120  }
121
122  void CField::sendUpdateData(const CArray<double,1>& data)
123  {
124    CTimer::get("XIOS Send Data").resume();
125
126    CContext* context = CContext::getCurrent();
127      CContextClient* client = (!context->hasServer) ? context->client : this->file->getContextClient();
128
129      CEventClient event(getType(), EVENT_ID_UPDATE_DATA);
130
131      map<int, CArray<int,1> >::iterator it;
132      list<CMessage> list_msg;
133      list<CArray<double,1> > list_data;
134
135      if (!grid->doGridHaveDataDistributed())
136      {
137         if (client->isServerLeader())
138         {
139            for (it = grid->storeIndex_toSrv.begin(); it != grid->storeIndex_toSrv.end(); it++)
140            {
141              int rank = it->first;
142              CArray<int,1>& index = it->second;
143
144              list_msg.push_back(CMessage());
145              list_data.push_back(CArray<double,1>(index.numElements()));
146
147              CArray<double,1>& data_tmp = list_data.back();
148              for (int n = 0; n < data_tmp.numElements(); n++) data_tmp(n) = data(index(n));
149
150              list_msg.back() << getId() << data_tmp;
151              event.push(rank, 1, list_msg.back());
152            }
153            client->sendEvent(event);
154         }
155         else client->sendEvent(event);
156      }
157      else
158      {
159        for (it = grid->storeIndex_toSrv.begin(); it != grid->storeIndex_toSrv.end(); it++)
160        {
161          int rank = it->first;
162          CArray<int,1>& index = it->second;
163
164          list_msg.push_back(CMessage());
165          list_data.push_back(CArray<double,1>(index.numElements()));
166
167          CArray<double,1>& data_tmp = list_data.back();
168          for (int n = 0; n < data_tmp.numElements(); n++) data_tmp(n) = data(index(n));
169
170          list_msg.back() << getId() << data_tmp;
171          event.push(rank, grid->nbSenders[0][rank], list_msg.back());
172        }
173        client->sendEvent(event);
174      }   
175
176    CTimer::get("XIOS Send Data").suspend();
177  }
178
179  void CField::recvUpdateData(CEventServer& event)
180  {
181    std::map<int,CBufferIn*> rankBuffers;
182
183    list<CEventServer::SSubEvent>::iterator it;
184    string fieldId;
185
186    for (it = event.subEvents.begin(); it != event.subEvents.end(); ++it)
187    {
188      int rank = it->rank;
189      CBufferIn* buffer = it->buffer;
190      *buffer >> fieldId;
191      rankBuffers[rank] = buffer;
192    }
193    get(fieldId)->recvUpdateData(rankBuffers);
194  }
195
196  void  CField::recvUpdateData(std::map<int,CBufferIn*>& rankBuffers)
197  {
198    CContext* context = CContext::getCurrent();
199
200    size_t sizeData = 0;
201    if (0 == recvDataSrv.numElements())
202    {           
203      CArray<int,1>& storeClient = grid->storeIndex_client;
204
205      // Gather all data from different clients     
206      recvDataSrv.resize(storeClient.numElements());
207      recvFoperationSrv = boost::shared_ptr<func::CFunctor>(new func::CInstant(recvDataSrv));
208    }
209
210    CArray<double,1> recv_data_tmp(recvDataSrv.numElements());   
211    const CDate& currDate = context->getCalendar()->getCurrentDate();
212    const CDate opeDate   = last_operation_srv +freq_op + freq_operation_srv - freq_op;
213
214    if (opeDate <= currDate)
215    {
216      for (map<int, CArray<size_t, 1> >::iterator it = grid->outLocalIndexStoreOnClient.begin(); it != grid->outLocalIndexStoreOnClient.end(); ++it)
217      {
218        CArray<double,1> tmp;
219        CArray<size_t,1>& indexTmp = it->second;
220        *(rankBuffers[it->first]) >> tmp;
221        for (int idx = 0; idx < indexTmp.numElements(); ++idx)
222        {
223          recv_data_tmp(indexTmp(idx)) = tmp(idx);
224        }     
225      }
226    }
227
228    this->setData(recv_data_tmp);
229  }
230
231  void CField::writeUpdateData(const CArray<double,1>& data)
232  {
233    CContext* context = CContext::getCurrent();
234
235    const CDate& currDate = context->getCalendar()->getCurrentDate();
236    const CDate opeDate      = last_operation_srv +freq_op + freq_operation_srv - freq_op;
237    const CDate writeDate    = last_Write_srv     + freq_write_srv;
238
239    if (opeDate <= currDate)
240    {
241      (*recvFoperationSrv)(data);
242      last_operation_srv = currDate;
243    }
244
245    if (writeDate < (currDate + freq_operation_srv))
246    {
247      recvFoperationSrv->final();
248      last_Write_srv = writeDate;
249      grid->computeWrittenIndex();
250      writeField();
251      lastlast_Write_srv = last_Write_srv;
252    }
253  }
254 
255//   void  CField::recvUpdateData(vector<int>& ranks, vector<CBufferIn*>& buffers)
256//   {
257//     CContext* context = CContext::getCurrent();
258
259//     if (data_srv.empty())
260//     {
261//       for (map<int, CArray<size_t, 1> >::iterator it = grid->outIndexFromClient.begin(); it != grid->outIndexFromClient.end(); ++it)
262//       {
263//         int rank = it->first;
264//         data_srv.insert(std::make_pair(rank, CArray<double,1>(it->second.numElements())));
265//         foperation_srv.insert(pair<int,boost::shared_ptr<func::CFunctor> >(rank,boost::shared_ptr<func::CFunctor>(new func::CInstant(data_srv[rank]))));
266//       }
267//     }
268
269//     const CDate& currDate = context->getCalendar()->getCurrentDate();
270//     const CDate opeDate      = last_operation_srv +freq_op + freq_operation_srv - freq_op;
271//     const CDate writeDate    = last_Write_srv     + freq_write_srv;
272
273//     if (opeDate <= currDate)
274//     {
275//       for (int n = 0; n < ranks.size(); n++)
276//       {
277//         CArray<double,1> data_tmp;
278//         *buffers[n] >> data_tmp;
279//         (*foperation_srv[ranks[n]])(data_tmp);
280//       }
281//       last_operation_srv = currDate;
282//     }
283
284//     if (writeDate < (currDate + freq_operation_srv))
285//     {
286//       for (int n = 0; n < ranks.size(); n++)
287//       {
288//         this->foperation_srv[ranks[n]]->final();
289//       }
290
291//       last_Write_srv = writeDate;
292//     }
293
294//     if (context->hasClient && context->hasServer)
295//     {
296//       size_t writtenSize;
297// //      if (field->getUseCompressedOutput())
298// //        writtenSize = grid->getNumberWrittenIndexes();
299// //      else
300//         writtenSize = grid->getWrittenDataSize();
301
302//       CArray<double,1> fieldData(writtenSize);
303// //      if (!field->default_value.isEmpty()) fieldData = field->default_value;
304
305// //      if (field->getUseCompressedOutput())
306// //        field->outputCompressedField(fieldData);
307// //      else
308//         this->outputField(fieldData);
309//       sendUpdateData(fieldData);
310//     }
311//     if (!context->hasClient && context->hasServer)
312//     {
313//       writeField();
314//     }
315
316//     lastlast_Write_srv = last_Write_srv;
317
318//   }
319
320  void CField::writeField(void)
321  {
322    if (!getRelFile()->allDomainEmpty)
323    {
324      if (grid->doGridHaveDataToWrite() || getRelFile()->type == CFile::type_attr::one_file)
325      {
326        getRelFile()->checkWriteFile();
327        this->incrementNStep();
328        getRelFile()->getDataOutput()->writeFieldData(CField::get(this));
329      }
330    }
331  }
332
333  void CField::sendReadDataRequest(const CDate& tsDataRequested)
334  {
335    CContext* context = CContext::getCurrent();
336    CContextClient* client = (!context->hasServer) ? context->client : this->file->getContextClient();
337
338
339    lastDataRequestedFromServer = tsDataRequested;
340
341    CEventClient event(getType(), EVENT_ID_READ_DATA);
342    if (client->isServerLeader())
343    {
344      CMessage msg;
345      msg << getId();
346      const std::list<int>& ranks = client->getRanksServerLeader();
347      for (std::list<int>::const_iterator itRank = ranks.begin(), itRankEnd = ranks.end(); itRank != itRankEnd; ++itRank)
348        event.push(*itRank, 1, msg);
349      client->sendEvent(event);
350    }
351    else client->sendEvent(event);
352  }
353
354  /*!
355  Send request new data read from file if need be, that is the current data is out-of-date.
356  \return true if and only if some data was requested
357  */
358  bool CField::sendReadDataRequestIfNeeded(void)
359  {
360    const CDate& currentDate = CContext::getCurrent()->getCalendar()->getCurrentDate();
361
362    bool dataRequested = false;
363    while (currentDate >= lastDataRequestedFromServer)
364    {
365      info(20) << "currentDate : " << currentDate << endl ;
366      info(20) << "lastDataRequestedFromServer : " << lastDataRequestedFromServer << endl ;
367      info(20) << "file->output_freq.getValue() : " << file->output_freq.getValue() << endl ;
368      info(20) << "lastDataRequestedFromServer + file->output_freq.getValue() : " << lastDataRequestedFromServer + file->output_freq << endl ;
369
370      sendReadDataRequest(lastDataRequestedFromServer + file->output_freq);
371
372      dataRequested = true;
373    }
374    return dataRequested;
375  }
376
377  void CField::recvReadDataRequest(CEventServer& event)
378  {
379    CBufferIn* buffer = event.subEvents.begin()->buffer;
380    StdString fieldId;
381    *buffer >> fieldId;
382    get(fieldId)->recvReadDataRequest();
383  }
384
385  void CField::recvReadDataRequest(void)
386  {
387    CContext* context = CContext::getCurrent();
388    CContextClient* client = context->client;   
389
390    CEventClient event(getType(), EVENT_ID_READ_DATA_READY);
391    std::list<CMessage> msgs;
392
393    bool hasData = readField();
394
395   
396    if (!grid->doGridHaveDataDistributed())
397    {
398       if (client->isServerLeader())
399       {
400          if (0 != recvDataSrv.numElements())
401          {           
402            const std::list<int>& ranks = client->getRanksServerLeader();
403            for (std::list<int>::const_iterator itRank = ranks.begin(), itRankEnd = ranks.end(); itRank != itRankEnd; ++itRank)
404            {
405              msgs.push_back(CMessage());
406              CMessage& msg = msgs.back();
407              msg << getId();
408              if (hasData)
409                msg << getNStep() - 1 << recvDataSrv;
410              else
411                msg << int(-1);
412              event.push(*itRank, 1, msg);
413            }
414          }
415
416          client->sendEvent(event);
417       }
418       else
419       {
420          client->sendEvent(event);
421       }
422    }
423    else
424    {
425      for (map<int, CArray<size_t, 1> >::iterator it = grid->outLocalIndexStoreOnClient.begin(); 
426                                                  it != grid->outLocalIndexStoreOnClient.end(); ++it)
427      {
428        CArray<size_t,1>& indexTmp = it->second;
429        CArray<double,1> tmp(indexTmp.numElements());
430        for (int idx = 0; idx < indexTmp.numElements(); ++idx)
431        {
432          tmp(idx) = recvDataSrv(indexTmp(idx));
433        } 
434
435        msgs.push_back(CMessage());
436        CMessage& msg = msgs.back();
437        msg << getId();
438        if (hasData)
439          msg << getNStep() - 1 << tmp;
440        else
441          msg << int(-1);
442        event.push(it->first, grid->nbReadSenders[0][it->first], msg);
443      }
444      client->sendEvent(event);
445    }
446  }
447
448  bool CField::readField(void)
449  {
450    grid->computeWrittenIndex();
451    if (!getRelFile()->allDomainEmpty)
452    {
453      if (grid->doGridHaveDataToWrite() || getRelFile()->type == CFile::type_attr::one_file)
454      {
455        if (0 == recvDataSrv.numElements())
456        {           
457          CArray<int,1>& storeClient = grid->storeIndex_client;         
458          recvDataSrv.resize(storeClient.numElements());         
459        }
460
461        getRelFile()->checkReadFile();
462        if (!nstepMax)
463        {
464          nstepMax = getRelFile()->getDataInput()->getFieldNbRecords(CField::get(this));
465        }
466
467        this->incrementNStep();
468
469        if (getNStep() > nstepMax && (getRelFile()->cyclic.isEmpty() || !getRelFile()->cyclic) )
470          return false;
471
472        getRelFile()->getDataInput()->readFieldData(CField::get(this));
473      }
474    }
475
476    return true;
477  }
478
479  void CField::recvReadDataReady(CEventServer& event)
480  {
481    string fieldId;
482    vector<int> ranks;
483    vector<CBufferIn*> buffers;
484
485    list<CEventServer::SSubEvent>::iterator it;
486    for (it = event.subEvents.begin(); it != event.subEvents.end(); ++it)
487    {
488      ranks.push_back(it->rank);
489      CBufferIn* buffer = it->buffer;
490      *buffer >> fieldId;
491      buffers.push_back(buffer);
492    }
493    get(fieldId)->recvReadDataReady(ranks, buffers);
494  }
495
496  void CField::recvReadDataReady(vector<int> ranks, vector<CBufferIn*> buffers)
497  {
498    CContext* context = CContext::getCurrent();
499    int record;
500    std::map<int, CArray<double,1> > data;
501
502    bool isEOF = false;
503
504    for (int i = 0; i < ranks.size(); i++)
505    {
506      int rank = ranks[i];
507      *buffers[i] >> record;
508      isEOF = (record == int(-1));
509
510      if (!isEOF)
511        *buffers[i] >> data[rank];
512      else
513        break;
514    }
515
516    if (wasDataAlreadyReceivedFromServer)
517      lastDataReceivedFromServer = lastDataReceivedFromServer + file->output_freq;
518    else
519    {
520      lastDataReceivedFromServer = context->getCalendar()->getInitDate();
521      wasDataAlreadyReceivedFromServer = true;
522    }
523
524    if (isEOF)
525      serverSourceFilter->signalEndOfStream(lastDataReceivedFromServer);
526    else
527      serverSourceFilter->streamDataFromServer(lastDataReceivedFromServer, data);
528  }
529
530   //----------------------------------------------------------------
531
532   void CField::setRelFile(CFile* _file)
533   {
534      this->file = _file;
535      hasOutputFile = true;
536   }
537
538   //----------------------------------------------------------------
539
540   StdString CField::GetName(void)    { return StdString("field"); }
541   StdString CField::GetDefName(void) { return CField::GetName(); }
542   ENodeType CField::GetType(void)    { return eField; }
543
544   //----------------------------------------------------------------
545
546   CGrid* CField::getRelGrid(void) const
547   {
548      return this->grid;
549   }
550
551   //----------------------------------------------------------------
552
553   CFile* CField::getRelFile(void) const
554   {
555      return this->file;
556   }
557
558   int CField::getNStep(void) const
559   {
560      return this->nstep;
561   }
562
563   func::CFunctor::ETimeType CField::getOperationTimeType() const
564   {
565     return operationTimeType;
566   }
567
568   //----------------------------------------------------------------
569
570   void CField::incrementNStep(void)
571   {
572      this->nstep++;
573   }
574
575   void CField::resetNStep(int nstep /*= 0*/)
576   {
577      this->nstep = nstep;
578   }
579
580   void CField::resetNStepMax(void)
581   {
582      this->nstepMax = 0;
583   }
584
585   //----------------------------------------------------------------
586
587   bool CField::isActive(void) const
588   {
589      return (instantDataFilter != NULL);
590   }
591
592   //----------------------------------------------------------------
593
594   bool CField::wasWritten() const
595   {
596     return written;
597   }
598
599   void CField::setWritten()
600   {
601     written = true;
602   }
603
604   //----------------------------------------------------------------
605
606   bool CField::getUseCompressedOutput() const
607   {
608     return useCompressedOutput;
609   }
610
611   void CField::setUseCompressedOutput()
612   {
613     useCompressedOutput = true;
614   }
615
616   //----------------------------------------------------------------
617
618   boost::shared_ptr<COutputPin> CField::getInstantDataFilter()
619   {
620     return instantDataFilter;
621   }
622
623   //----------------------------------------------------------------
624
625   /*!
626     Build up graph of grids which plays role of destination and source in grid transformation
627     This function should be called before \func solveGridReference()
628   */
629   void CField::buildGridTransformationGraph()
630   {
631     CContext* context = CContext::getCurrent();
632     if (context->hasClient && !context->hasServer)
633     {
634       if (grid && !grid->isTransformed() && hasDirectFieldReference() && grid != getDirectFieldReference()->grid)
635       {
636         grid->addTransGridSource(getDirectFieldReference()->grid);
637       }
638     }
639   }
640
641   /*!
642     Generate a new grid destination if there are more than one grid source pointing to a same grid destination
643   */
644   void CField::generateNewTransformationGridDest()
645   {
646     CContext* context = CContext::getCurrent();
647     if (context->hasClient && !context->hasServer)
648     {
649       std::map<CGrid*,std::pair<bool,StdString> >& gridSrcMap = grid->getTransGridSource();
650       if (1 < gridSrcMap.size())
651       {
652         // Search for grid source
653         CGrid* gridSrc = grid;
654         CField* currField = this;
655         std::vector<CField*> hieraField;
656
657         while (currField->hasDirectFieldReference() && (gridSrc == grid))
658         {
659           hieraField.push_back(currField);
660           CField* tmp = currField->getDirectFieldReference();
661           currField = tmp;
662           gridSrc = currField->grid;
663         }
664
665         if (gridSrcMap.end() != gridSrcMap.find(gridSrc))
666         {
667           CGrid* gridTmp;
668           std::pair<bool,StdString> newGridDest = gridSrcMap[gridSrc];
669           if (newGridDest.first)
670           {
671             StdString newIdGridDest = newGridDest.second;
672             if (!CGrid::has(newIdGridDest))
673             {
674                ERROR("CGrid* CGrid::generateNewTransformationGridDest()",
675                  << " Something wrong happened! Grid whose id " << newIdGridDest
676                  << "should exist ");
677             }
678             gridTmp = CGrid::get(newIdGridDest);
679           }
680           else
681           {
682             StdString newIdGridDest = CGrid::generateId(gridSrc, grid);
683             gridTmp = CGrid::cloneGrid(newIdGridDest, grid);
684
685             (gridSrcMap[gridSrc]).first = true;
686             (gridSrcMap[gridSrc]).second = newIdGridDest;
687           }
688
689           // Update all descendants
690           for (std::vector<CField*>::iterator it = hieraField.begin(); it != hieraField.end(); ++it)
691           {
692             (*it)->grid = gridTmp;
693             (*it)->updateRef((*it)->grid);
694           }
695         }
696       }
697     }
698   }
699
700   void CField::updateRef(CGrid* grid)
701   {
702     if (!grid_ref.isEmpty()) grid_ref.setValue(grid->getId());
703     else
704     {
705       std::vector<CAxis*> axisTmp = grid->getAxis();
706       std::vector<CDomain*> domainTmp = grid->getDomains();
707       if ((1<axisTmp.size()) || (1<domainTmp.size()))
708         ERROR("void CField::updateRef(CGrid* grid)",
709           << "More than one domain or axis is available for domain_ref/axis_ref of field " << this->getId());
710
711       if ((!domain_ref.isEmpty()) && (domainTmp.empty()))
712         ERROR("void CField::updateRef(CGrid* grid)",
713           << "Incoherent between available domain and domain_ref of field " << this->getId());
714       if ((!axis_ref.isEmpty()) && (axisTmp.empty()))
715         ERROR("void CField::updateRef(CGrid* grid)",
716           << "Incoherent between available axis and axis_ref of field " << this->getId());
717
718       if (!domain_ref.isEmpty()) domain_ref.setValue(domainTmp[0]->getId());
719       if (!axis_ref.isEmpty()) axis_ref.setValue(axisTmp[0]->getId());
720     }
721   }
722   
723   /*!
724     Solve reference of all enabled fields even the source fields .
725     In this step, we do transformations.
726   */
727   void CField::solveAllEnabledFieldsAndTransform()
728   {
729     CContext* context = CContext::getCurrent();
730     bool hasClient = context->hasClient;
731     bool hasServer = context->hasServer;
732
733     if (!isReferenceSolvedAndTransformed)
734     {
735        isReferenceSolvedAndTransformed = true;
736
737        if (hasClient && !hasServer)
738        {
739          solveRefInheritance(true);
740          if (hasDirectFieldReference()) getDirectFieldReference()->solveAllEnabledFieldsAndTransform();
741        }
742
743        if (hasServer)
744          solveServerOperation();
745
746        solveGridReference();
747
748        if (hasClient && !hasServer)
749       {
750         solveGenerateGrid();
751         buildGridTransformationGraph();
752       }
753
754       solveGridDomainAxisRef(false);
755
756       if (hasClient && !hasServer)
757       {
758         solveTransformedGrid();
759       }
760
761       solveGridDomainAxisRef(false);
762     }
763   }
764
765   void CField::checkGridOfEnabledFields()
766   {
767      solveCheckMaskIndex(false);
768   }
769
770   void CField::sendGridOfEnabledFields()
771   {
772      solveGridDomainAxisRef(true);
773      solveCheckMaskIndex(true);
774   }
775
776
777    void CField::solveOnlyReferenceEnabledField(bool doSending2Server)
778   {
779     CContext* context = CContext::getCurrent();
780     if (!isReferenceSolved)
781     {
782        isReferenceSolved = true;
783
784        if (context->hasClient && !context->hasServer)
785        {
786          solveRefInheritance(true);
787          if (hasDirectFieldReference()) getDirectFieldReference()->solveOnlyReferenceEnabledField(false);
788        }
789
790        if (context->hasServer)
791          solveServerOperation();
792
793        solveGridReference();
794
795        if (context->hasClient && !context->hasServer)
796       {
797         solveGenerateGrid();
798         buildGridTransformationGraph();
799       }
800     }
801   }
802     
803   void CField::solveAllReferenceEnabledField(bool doSending2Server)
804   {
805     CContext* context = CContext::getCurrent();
806     solveOnlyReferenceEnabledField(doSending2Server);
807
808     if (!areAllReferenceSolved)
809     {
810        areAllReferenceSolved = true;
811       
812        if (context->hasClient && !context->hasServer)
813        {
814          solveRefInheritance(true);
815          if (hasDirectFieldReference()) getDirectFieldReference()->solveAllReferenceEnabledField(false);
816        }
817       else if (context->hasServer)       
818          solveServerOperation();
819
820        solveGridReference();
821     }
822
823     solveGridDomainAxisRef(doSending2Server);
824
825     if (context->hasClient && !context->hasServer)
826     {
827       solveTransformedGrid();
828     }
829
830     solveCheckMaskIndex(doSending2Server);
831   }
832
833   std::map<int, StdSize> CField::getGridAttributesBufferSize()
834   {
835     return grid->getAttributesBufferSize();
836   }
837
838   std::vector<std::map<int, StdSize> > CField::getGridDataBufferSize()
839   {
840     return grid->getDataBufferSize(getId());
841   }
842
843   //----------------------------------------------------------------
844
845   void CField::solveServerOperation(void)
846   {
847      CContext* context = CContext::getCurrent();
848
849      if (!context->hasServer || !hasOutputFile) return;
850
851      if (freq_op.isEmpty())
852        freq_op.setValue(TimeStep);
853
854      if (freq_offset.isEmpty())
855        freq_offset.setValue(NoneDu);
856
857      freq_operation_srv = file->output_freq.getValue();
858      freq_write_srv     = file->output_freq.getValue();
859
860      lastlast_Write_srv = context->getCalendar()->getInitDate();
861      last_Write_srv     = context->getCalendar()->getInitDate();
862      last_operation_srv = context->getCalendar()->getInitDate();
863
864      const CDuration toffset = freq_operation_srv - freq_offset.getValue() - context->getCalendar()->getTimeStep();
865      last_operation_srv     = last_operation_srv - toffset;
866
867      if (operation.isEmpty())
868        ERROR("void CField::solveServerOperation(void)",
869              << "An operation must be defined for field \"" << getId() << "\".");
870
871      boost::shared_ptr<func::CFunctor> functor;
872      CArray<double, 1> dummyData;
873
874#define DECLARE_FUNCTOR(MType, mtype) \
875      if (operation.getValue().compare(#mtype) == 0) \
876      { \
877        functor.reset(new func::C##MType(dummyData)); \
878      }
879
880#include "functor_type.conf"
881
882      if (!functor)
883        ERROR("void CField::solveServerOperation(void)",
884              << "\"" << operation << "\" is not a valid operation.");
885
886      operationTimeType = functor->timeType();
887   }
888
889   //----------------------------------------------------------------
890
891   /*!
892    * Constructs the graph filter for the field, enabling or not the data output.
893    * This method should not be called more than once with enableOutput equal to true.
894    *
895    * \param gc the garbage collector to use when building the filter graph
896    * \param enableOutput must be true when the field data is to be
897    *                     read by the client or/and written to a file
898    */
899   void CField::buildFilterGraph(CGarbageCollector& gc, bool enableOutput)
900   {     
901    if (!isReferenceSolvedAndTransformed) solveAllEnabledFieldsAndTransform();
902     CContext* context = CContext::getCurrent();
903     bool hasWriterServer = context->hasServer && !context->hasClient;
904     bool hasIntermediateServer = context->hasServer && context->hasClient;
905
906     if (hasWriterServer)
907     {
908        if (!instantDataFilter)
909          instantDataFilter = clientSourceFilter = boost::shared_ptr<CSourceFilter>(new CSourceFilter(gc, grid));
910
911             // If the field data is to be read by the client or/and written to a file
912       if (enableOutput && !storeFilter && !fileWriterFilter)
913       {
914         if (file && (file->mode.isEmpty() || file->mode == CFile::mode_attr::write))
915         {
916           fileServerWriterFilter = boost::shared_ptr<CFileServerWriterFilter>(new CFileServerWriterFilter(gc, this));
917           instantDataFilter->connectOutput(fileServerWriterFilter, 0);
918         }
919       }
920     }
921     else if (hasIntermediateServer)
922     {
923       if (!instantDataFilter)
924         instantDataFilter = clientSourceFilter = boost::shared_ptr<CSourceFilter>(new CSourceFilter(gc, grid));
925
926             // If the field data is to be read by the client or/and written to a file
927       if (enableOutput && !storeFilter && !fileWriterFilter)
928       {
929         if (file && (file->mode.isEmpty() || file->mode == CFile::mode_attr::write))
930         {
931           fileWriterFilter = boost::shared_ptr<CFileWriterFilter>(new CFileWriterFilter(gc, this));
932           instantDataFilter->connectOutput(fileWriterFilter, 0);
933         }
934       }
935     }
936     else
937     {
938       // Start by building a filter which can provide the field's instant data
939       if (!instantDataFilter)
940       {
941         // Check if we have an expression to parse
942       if (hasExpression())
943         {
944         boost::scoped_ptr<IFilterExprNode> expr(parseExpr(getExpression() + '\0'));
945         boost::shared_ptr<COutputPin> filter = expr->reduce(gc, *this);
946
947         // Check if a spatial transformation is needed
948         if (!field_ref.isEmpty())
949         {
950           CGrid* gridRef = CField::get(field_ref)->grid;
951
952           if (grid && grid != gridRef && grid->hasTransform())
953           {
954             double defaultValue = !default_value.isEmpty() ? default_value : 0.0;
955             std::pair<boost::shared_ptr<CFilter>, boost::shared_ptr<CFilter> > filters = CSpatialTransformFilter::buildFilterGraph(gc, gridRef, grid, defaultValue);
956
957             filter->connectOutput(filters.first, 0);
958             filter = filters.second;
959           }
960         }
961
962         instantDataFilter = filter;
963         }
964         // Check if we have a reference on another field
965         else if (!field_ref.isEmpty())
966           instantDataFilter = getFieldReference(gc);
967         // Check if the data is to be read from a file
968         else if (file && !file->mode.isEmpty() && file->mode == CFile::mode_attr::read)
969         instantDataFilter = serverSourceFilter = boost::shared_ptr<CSourceFilter>(new CSourceFilter(gc, grid,
970                                                                                                     freq_offset.isEmpty() ? NoneDu : freq_offset,
971                                                                                                     true));
972         else // The data might be passed from the model
973         instantDataFilter = clientSourceFilter = boost::shared_ptr<CSourceFilter>(new CSourceFilter(gc, grid));
974       }
975
976       // If the field data is to be read by the client or/and written to a file
977       if (enableOutput && !storeFilter && !fileWriterFilter)
978       {
979         if (!read_access.isEmpty() && read_access)
980         {
981           storeFilter = boost::shared_ptr<CStoreFilter>(new CStoreFilter(gc, CContext::getCurrent(), grid));
982           instantDataFilter->connectOutput(storeFilter, 0);
983         }
984
985         if (file && (file->mode.isEmpty() || file->mode == CFile::mode_attr::write))
986         {
987           fileWriterFilter = boost::shared_ptr<CFileWriterFilter>(new CFileWriterFilter(gc, this));
988           getTemporalDataFilter(gc, file->output_freq)->connectOutput(fileWriterFilter, 0);
989         }
990       }
991     }
992   }
993
994
995   /*!
996    * Returns the filter needed to handle the field reference.
997    * This method should only be called when building the filter graph corresponding to the field.
998    *
999    * \param gc the garbage collector to use
1000    * \return the output pin corresponding to the field reference
1001    */
1002     boost::shared_ptr<COutputPin> CField::getFieldReference(CGarbageCollector& gc)
1003     {
1004       if (instantDataFilter || field_ref.isEmpty())
1005         ERROR("COutputPin* CField::getFieldReference(CGarbageCollector& gc)",
1006               "Impossible to get the field reference for a field which has already been parsed or which does not have a field_ref.");
1007
1008       CField* fieldRef = CField::get(field_ref);
1009       fieldRef->buildFilterGraph(gc, false);
1010
1011       std::pair<boost::shared_ptr<CFilter>, boost::shared_ptr<CFilter> > filters;
1012       // Check if a spatial transformation is needed
1013       if (grid && grid != fieldRef->grid && grid->hasTransform())
1014       {
1015         double defaultValue = !default_value.isEmpty() ? default_value : 0.0;
1016         filters = CSpatialTransformFilter::buildFilterGraph(gc, fieldRef->grid, grid, defaultValue);
1017       }
1018       else
1019         filters.first = filters.second = boost::shared_ptr<CFilter>(new CPassThroughFilter(gc));
1020
1021       fieldRef->getInstantDataFilter()->connectOutput(filters.first, 0);
1022
1023       return filters.second;
1024     }
1025
1026   /*!
1027    * Returns the filter needed to handle a self reference in the field's expression.
1028    * If the needed filter does not exist, it is created, otherwise it is reused.
1029    * This method should only be called when building the filter graph corresponding
1030    * to the field's expression.
1031    *
1032    * \param gc the garbage collector to use
1033    * \return the output pin corresponding to a self reference
1034    */
1035   boost::shared_ptr<COutputPin> CField::getSelfReference(CGarbageCollector& gc)
1036   {
1037     if (instantDataFilter || !hasExpression())
1038       ERROR("COutputPin* CField::getSelfReference(CGarbageCollector& gc)",
1039             "Impossible to add a self reference to a field which has already been parsed or which does not have an expression.");
1040
1041     if (!selfReferenceFilter)
1042     {
1043       if (file && !file->mode.isEmpty() && file->mode == CFile::mode_attr::read)
1044       {
1045         if (!serverSourceFilter)
1046           serverSourceFilter = boost::shared_ptr<CSourceFilter>(new CSourceFilter(gc, grid,
1047                                                                                   freq_offset.isEmpty() ? NoneDu : freq_offset,
1048                                                                                   true));
1049         selfReferenceFilter = serverSourceFilter;
1050       }
1051       else if (!field_ref.isEmpty())
1052       {
1053         CField* fieldRef = CField::get(field_ref);
1054         fieldRef->buildFilterGraph(gc, false);
1055         selfReferenceFilter = fieldRef->getInstantDataFilter();
1056       }
1057       else
1058       {
1059         if (!clientSourceFilter)
1060           clientSourceFilter = boost::shared_ptr<CSourceFilter>(new CSourceFilter(gc, grid));
1061
1062         selfReferenceFilter = clientSourceFilter;
1063       }
1064     }
1065
1066     return selfReferenceFilter;
1067   }
1068
1069   /*!
1070    * Returns the temporal filter corresponding to the field's temporal operation
1071    * for the specified operation frequency. The filter is created if it does not
1072    * exist, otherwise it is reused.
1073    *
1074    * \param gc the garbage collector to use
1075    * \param outFreq the operation frequency, i.e. the frequency at which the output data will be computed
1076    * \return the output pin corresponding to the requested temporal filter
1077    */
1078   boost::shared_ptr<COutputPin> CField::getTemporalDataFilter(CGarbageCollector& gc, CDuration outFreq)
1079   {
1080     std::map<CDuration, boost::shared_ptr<COutputPin> >::iterator it = temporalDataFilters.find(outFreq);
1081
1082     if (it == temporalDataFilters.end())
1083     {
1084       if (operation.isEmpty())
1085         ERROR("void CField::getTemporalDataFilter(CGarbageCollector& gc, CDuration outFreq)",
1086               << "An operation must be defined for field \"" << getId() << "\".");
1087
1088       if (freq_op.isEmpty())
1089         freq_op.setValue(TimeStep);
1090       if (freq_offset.isEmpty())
1091         freq_offset.setValue(NoneDu);
1092
1093       const bool ignoreMissingValue = (!detect_missing_value.isEmpty() && !default_value.isEmpty() && detect_missing_value == true);
1094
1095       boost::shared_ptr<CTemporalFilter> temporalFilter(new CTemporalFilter(gc, operation,
1096                                                                             CContext::getCurrent()->getCalendar()->getInitDate(),
1097                                                                             freq_op, freq_offset, outFreq,
1098                                                                             ignoreMissingValue, ignoreMissingValue ? default_value : 0.0));
1099       instantDataFilter->connectOutput(temporalFilter, 0);
1100
1101       it = temporalDataFilters.insert(std::make_pair(outFreq, temporalFilter)).first;
1102     }
1103
1104     return it->second;
1105   }
1106
1107   //----------------------------------------------------------------
1108/*
1109   void CField::fromBinary(StdIStream& is)
1110   {
1111      SuperClass::fromBinary(is);
1112#define CLEAR_ATT(name_)\
1113      SuperClassAttribute::operator[](#name_)->reset()
1114
1115         CLEAR_ATT(domain_ref);
1116         CLEAR_ATT(axis_ref);
1117#undef CLEAR_ATT
1118
1119   }
1120*/
1121   //----------------------------------------------------------------
1122
1123   void CField::solveGridReference(void)
1124   {
1125      if (grid_ref.isEmpty() && domain_ref.isEmpty() && axis_ref.isEmpty() && scalar_ref.isEmpty())
1126      {
1127        ERROR("CField::solveGridReference(void)",
1128              << "A grid must be defined for field '" << getFieldOutputName() << "' .");
1129      }
1130      else if (!grid_ref.isEmpty() && (!domain_ref.isEmpty() || !axis_ref.isEmpty() || !scalar_ref.isEmpty()))
1131      {
1132        ERROR("CField::solveGridReference(void)",
1133              << "Field '" << getFieldOutputName() << "' has both a grid and a domain/axis/scalar." << std::endl
1134              << "Please define either 'grid_ref' or 'domain_ref'/'axis_ref'/'scalar_ref'.");
1135      }
1136
1137      if (grid_ref.isEmpty())
1138      {
1139        std::vector<CDomain*> vecDom;
1140        std::vector<CAxis*> vecAxis;
1141        std::vector<CScalar*> vecScalar;
1142        std::vector<int> axisDomainOrderTmp;
1143       
1144        if (!domain_ref.isEmpty())
1145        {
1146          StdString tmp = domain_ref.getValue();
1147          if (CDomain::has(domain_ref))
1148          {
1149            vecDom.push_back(CDomain::get(domain_ref));
1150            axisDomainOrderTmp.push_back(2);
1151          }
1152          else
1153            ERROR("CField::solveGridReference(void)",
1154                  << "Invalid reference to domain '" << domain_ref.getValue() << "'.");
1155        }
1156
1157        if (!axis_ref.isEmpty())
1158        {
1159          if (CAxis::has(axis_ref))
1160          {
1161            vecAxis.push_back(CAxis::get(axis_ref));
1162            axisDomainOrderTmp.push_back(1);
1163          }
1164          else
1165            ERROR("CField::solveGridReference(void)",
1166                  << "Invalid reference to axis '" << axis_ref.getValue() << "'.");
1167        }
1168
1169        if (!scalar_ref.isEmpty())
1170        {
1171          if (CScalar::has(scalar_ref))
1172          {
1173            vecScalar.push_back(CScalar::get(scalar_ref));
1174            axisDomainOrderTmp.push_back(0);
1175          }
1176          else
1177            ERROR("CField::solveGridReference(void)",
1178                  << "Invalid reference to scalar '" << scalar_ref.getValue() << "'.");
1179        }
1180       
1181        CArray<int,1> axisDomainOrder(axisDomainOrderTmp.size());
1182        for (int idx = 0; idx < axisDomainOrderTmp.size(); ++idx)
1183        {
1184          axisDomainOrder(idx) = axisDomainOrderTmp[idx];
1185        }
1186
1187        // Warning: the gridId shouldn't be set as the grid_ref since it could be inherited
1188        StdString gridId = CGrid::generateId(vecDom, vecAxis, vecScalar,axisDomainOrder);
1189        if (CGrid::has(gridId))
1190          this->grid = CGrid::get(gridId);
1191        else
1192          this->grid = CGrid::createGrid(gridId, vecDom, vecAxis, vecScalar,axisDomainOrder);
1193      }
1194      else
1195      {
1196        if (CGrid::has(grid_ref))
1197          this->grid = CGrid::get(grid_ref);
1198        else
1199          ERROR("CField::solveGridReference(void)",
1200                << "Invalid reference to grid '" << grid_ref.getValue() << "'.");
1201      }
1202   }
1203
1204   void CField::solveGridDomainAxisRef(bool checkAtt)
1205   {
1206     grid->solveDomainAxisRef(checkAtt);
1207   }
1208
1209   void CField::solveCheckMaskIndex(bool doSendingIndex)
1210   {
1211     grid->checkMaskIndex(doSendingIndex);
1212   }
1213
1214   void CField::solveTransformedGrid()
1215   {
1216     if (grid && !grid->isTransformed() && hasDirectFieldReference() && grid != getDirectFieldReference()->grid)
1217     {
1218       std::vector<CGrid*> grids;
1219       // Source grid
1220       grids.push_back(getDirectFieldReference()->grid);
1221       // Intermediate grids
1222       if (!grid_path.isEmpty())
1223       {
1224         std::string gridId;
1225         size_t start = 0, end;
1226
1227         do
1228         {
1229           end = grid_path.getValue().find(',', start);
1230           if (end != std::string::npos)
1231           {
1232             gridId = grid_path.getValue().substr(start, end - start);
1233             start = end + 1;
1234           }
1235           else
1236             gridId = grid_path.getValue().substr(start);
1237
1238           if (!CGrid::has(gridId))
1239             ERROR("void CField::solveTransformedGrid()",
1240                   << "Invalid grid_path, the grid '" << gridId << "' does not exist.");
1241
1242           grids.push_back(CGrid::get(gridId));
1243         }
1244         while (end != std::string::npos);
1245       }
1246       // Destination grid
1247       grids.push_back(grid);
1248
1249       for (size_t i = 0, count = grids.size() - 1; i < count; ++i)
1250       {
1251         CGrid *gridSrc  = grids[i];
1252         CGrid *gridDest = grids[i + 1];
1253         if (!gridDest->isTransformed())
1254           gridDest->transformGrid(gridSrc);
1255       }
1256     }
1257     else if (grid && grid->hasTransform() && !grid->isTransformed())
1258     {
1259       // Temporarily deactivate the self-transformation of grid
1260       //grid->transformGrid(grid);
1261     }
1262   }
1263
1264   void CField::solveGenerateGrid()
1265   {
1266     if (grid && !grid->isTransformed() && hasDirectFieldReference() && grid != getDirectFieldReference()->grid)
1267       grid->completeGrid(getDirectFieldReference()->grid);
1268     else
1269       grid->completeGrid();
1270   }
1271
1272   void CField::solveGridDomainAxisBaseRef()
1273   {
1274     grid->solveDomainAxisRef(false);
1275     grid->solveDomainAxisBaseRef();
1276   }
1277
1278   ///-------------------------------------------------------------------
1279
1280   template <>
1281   void CGroupTemplate<CField, CFieldGroup, CFieldAttributes>::solveRefInheritance(void)
1282   {
1283      if (this->group_ref.isEmpty()) return;
1284      StdString gref = this->group_ref.getValue();
1285
1286      if (!CFieldGroup::has(gref))
1287         ERROR("CGroupTemplate<CField, CFieldGroup, CFieldAttributes>::solveRefInheritance(void)",
1288               << "[ gref = " << gref << "]"
1289               << " invalid group name !");
1290
1291      CFieldGroup* group = CFieldGroup::get(gref);
1292      CFieldGroup* owner = CFieldGroup::get(boost::polymorphic_downcast<CFieldGroup*>(this));
1293
1294      std::vector<CField*> allChildren  = group->getAllChildren();
1295      std::vector<CField*>::iterator it = allChildren.begin(), end = allChildren.end();
1296
1297      for (; it != end; it++)
1298      {
1299         CField* child = *it;
1300         if (child->hasId()) owner->createChild()->field_ref.setValue(child->getId());
1301
1302      }
1303   }
1304
1305   void CField::scaleFactorAddOffset(double scaleFactor, double addOffset)
1306   {
1307     recvDataSrv = (recvDataSrv - addOffset) / scaleFactor;
1308   }
1309
1310   void CField::invertScaleFactorAddOffset(double scaleFactor, double addOffset)
1311   {
1312     recvDataSrv = recvDataSrv * scaleFactor + addOffset;
1313   }
1314
1315   void CField::outputField(CArray<double,1>& fieldOut)
1316   { 
1317      CArray<size_t,1>& outIndexClient = grid->localIndexToWriteOnClient;
1318      CArray<size_t,1>& outIndexServer = grid->localIndexToWriteOnServer;
1319      for (size_t idx = 0; idx < outIndexServer.numElements(); ++idx)
1320      {
1321        fieldOut(outIndexServer(idx)) = recvDataSrv(outIndexClient(idx));
1322      }
1323   }
1324
1325   void CField::inputField(CArray<double,1>& fieldIn)
1326   {
1327      CArray<size_t,1>& outIndexClient = grid->localIndexToWriteOnClient;
1328      CArray<size_t,1>& outIndexServer = grid->localIndexToWriteOnServer;
1329      for (size_t idx = 0; idx < outIndexServer.numElements(); ++idx)
1330      {
1331        recvDataSrv(outIndexClient(idx)) = fieldIn(outIndexServer(idx));
1332      }
1333
1334   }
1335
1336   void CField::outputCompressedField(CArray<double,1>& fieldOut)
1337   {
1338      CArray<size_t,1>& outIndexClient = grid->localIndexToWriteOnClient;
1339      CArray<size_t,1>& outIndexServer = grid->localIndexToWriteOnServer;
1340      for (size_t idx = 0; idx < outIndexServer.numElements(); ++idx)
1341      {
1342        fieldOut((idx)) = recvDataSrv(outIndexClient(idx));
1343      }
1344   }
1345
1346   ///-------------------------------------------------------------------
1347
1348   void CField::parse(xml::CXMLNode& node)
1349   {
1350      SuperClass::parse(node);
1351      if (!node.getContent(this->content))
1352      {
1353        if (node.goToChildElement())
1354        {
1355          do
1356          {
1357            if (node.getElementName() == "variable" || node.getElementName() == "variable_group") this->getVirtualVariableGroup()->parseChild(node);
1358          } while (node.goToNextElement());
1359          node.goToParentElement();
1360        }
1361      }
1362    }
1363
1364   /*!
1365     This function retrieves Id of corresponding domain_ref and axis_ref (if any)
1366   of a field. In some cases, only domain exists but axis doesn't
1367   \return pair of Domain and Axis id
1368   */
1369   const std::vector<StdString>& CField::getRefDomainAxisIds()
1370   {
1371     CGrid* cgPtr = getRelGrid();
1372     if (NULL != cgPtr)
1373     {
1374       std::vector<StdString>::iterator it;
1375       if (!domain_ref.isEmpty())
1376       {
1377         std::vector<StdString> domainList = cgPtr->getDomainList();
1378         it = std::find(domainList.begin(), domainList.end(), domain_ref.getValue());
1379         if (domainList.end() != it) domAxisScalarIds_[0] = *it;
1380       }
1381
1382       if (!axis_ref.isEmpty())
1383       {
1384         std::vector<StdString> axisList = cgPtr->getAxisList();
1385         it = std::find(axisList.begin(), axisList.end(), axis_ref.getValue());
1386         if (axisList.end() != it) domAxisScalarIds_[1] = *it;
1387       }
1388
1389       if (!scalar_ref.isEmpty())
1390       {
1391         std::vector<StdString> scalarList = cgPtr->getScalarList();
1392         it = std::find(scalarList.begin(), scalarList.end(), scalar_ref.getValue());
1393         if (scalarList.end() != it) domAxisScalarIds_[2] = *it;
1394       }
1395     }
1396     return (domAxisScalarIds_);
1397   }
1398
1399   CVariable* CField::addVariable(const string& id)
1400   {
1401     return vVariableGroup->createChild(id);
1402   }
1403
1404   CVariableGroup* CField::addVariableGroup(const string& id)
1405   {
1406     return vVariableGroup->createChildGroup(id);
1407   }
1408
1409   void CField::sendAddAllVariables(CContextClient* client)
1410   {
1411     std::vector<CVariable*> allVar = getAllVariables();
1412     std::vector<CVariable*>::const_iterator it = allVar.begin();
1413     std::vector<CVariable*>::const_iterator itE = allVar.end();
1414
1415     for (; it != itE; ++it)
1416     {
1417       this->sendAddVariable((*it)->getId(), client);
1418       (*it)->sendAllAttributesToServer(client);
1419       (*it)->sendValue(client);
1420     }
1421   }
1422
1423   void CField::sendAddVariable(const string& id, CContextClient* client)
1424   {
1425      sendAddItem(id, (int)EVENT_ID_ADD_VARIABLE, client);
1426   }
1427
1428   void CField::sendAddVariableGroup(const string& id, CContextClient* client)
1429   {
1430      sendAddItem(id, (int)EVENT_ID_ADD_VARIABLE_GROUP, client);
1431   }
1432
1433   void CField::recvAddVariable(CEventServer& event)
1434   {
1435
1436      CBufferIn* buffer = event.subEvents.begin()->buffer;
1437      string id;
1438      *buffer >> id;
1439      get(id)->recvAddVariable(*buffer);
1440   }
1441
1442   void CField::recvAddVariable(CBufferIn& buffer)
1443   {
1444      string id;
1445      buffer >> id;
1446      addVariable(id);
1447   }
1448
1449   void CField::recvAddVariableGroup(CEventServer& event)
1450   {
1451
1452      CBufferIn* buffer = event.subEvents.begin()->buffer;
1453      string id;
1454      *buffer >> id;
1455      get(id)->recvAddVariableGroup(*buffer);
1456   }
1457
1458   void CField::recvAddVariableGroup(CBufferIn& buffer)
1459   {
1460      string id;
1461      buffer >> id;
1462      addVariableGroup(id);
1463   }
1464
1465   /*!
1466    * Returns string arithmetic expression associated to the field.
1467    * \return if content is defined return content string, otherwise, if "expr" attribute is defined, return expr string.
1468    */
1469   const string& CField::getExpression(void)
1470   {
1471     if (!expr.isEmpty() && content.empty())
1472     {
1473       content = expr;
1474       expr.reset();
1475     }
1476
1477     return content;
1478   }
1479
1480   bool CField::hasExpression(void) const
1481   {
1482     return (!expr.isEmpty() || !content.empty());
1483   }
1484
1485
1486   DEFINE_REF_FUNC(Field,field)
1487} // namespace xios
Note: See TracBrowser for help on using the repository browser.