Ignore:
Timestamp:
02/24/15 09:50:14 (9 years ago)
Author:
rlacroix
Message:

Fix incorrect output values when using a field_ref or the @ operator on a field computed from an operation.

The computed values were never transmitted from the source field to the destination field.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • XIOS/trunk/src/node/field.cpp

    r551 r562  
    2626      , foperation(), hasInstantData(false), hasExpression(false) 
    2727      , active(false) , hasOutputFile(false),hasFieldOut(false), slotUpdateDate(NULL) 
    28       , processed(false), domAxisIds_("",""), areAllReferenceSolved(false), areAllExpressionBuilt(false) 
    29       { setVirtualVariableGroup() ; } 
    30  
    31    CField::CField(const StdString & id) 
     28      , processed(false), domAxisIds_("", ""), areAllReferenceSolved(false), areAllExpressionBuilt(false) 
     29      { setVirtualVariableGroup(); } 
     30 
     31   CField::CField(const StdString& id) 
    3232      : CObjectTemplate<CField>(id), CFieldAttributes() 
    3333      , refObject(), baseRefObject() 
     
    3838      , foperation(), hasInstantData(false), hasExpression(false) 
    3939      , active(false), hasOutputFile(false), hasFieldOut(false), slotUpdateDate(NULL) 
    40       , processed(false), domAxisIds_("",""), areAllReferenceSolved(false), areAllExpressionBuilt(false) 
    41    { setVirtualVariableGroup() ; } 
     40      , processed(false), domAxisIds_("", ""), areAllReferenceSolved(false), areAllExpressionBuilt(false) 
     41   { setVirtualVariableGroup(); } 
    4242 
    4343   CField::~CField(void) 
    4444   { 
    45 //      this->grid.reset() ; 
    46 //      this->file.reset() ; 
    47       this->foperation.reset() ; 
    48       if (hasExpression) delete expression ; 
    49       if (slotUpdateDate!=NULL) delete slotUpdateDate ; 
     45//      this->grid.reset(); 
     46//      this->file.reset(); 
     47      this->foperation.reset(); 
     48      if (hasExpression) delete expression; 
     49      if (slotUpdateDate != NULL) delete slotUpdateDate; 
    5050 
    5151   } 
     
    6666   CVariableGroup* CField::getVirtualVariableGroup(void) const 
    6767   { 
    68       return (this->vVariableGroup); 
     68      return this->vVariableGroup; 
    6969   } 
    7070 
     
    7272   std::vector<CVariable*> CField::getAllVariables(void) const 
    7373   { 
    74       return (this->vVariableGroup->getAllChildren()); 
    75    } 
    76  
    77    void CField::solveDescInheritance(bool apply, const CAttributeMap * const parent) 
    78    { 
    79       SuperClassAttribute::setAttributes(parent,apply); 
     74      return this->vVariableGroup->getAllChildren(); 
     75   } 
     76 
     77   void CField::solveDescInheritance(bool apply, const CAttributeMap* const parent) 
     78   { 
     79      SuperClassAttribute::setAttributes(parent, apply); 
    8080      this->getVirtualVariableGroup()->solveDescInheritance(apply, NULL); 
    8181   } 
     
    8484 
    8585   bool CField::updateDataServer 
    86       (const CDate & currDate, 
     86      (const CDate& currDate, 
    8787       const std::deque< CArray<double, 1>* > storedClient) 
    8888   { 
     
    9494         if (this->data.numElements() != this->grid->storeIndex[0]->numElements()) 
    9595         { 
    96             this->data.resize(this->grid->storeIndex[0] ->numElements()); 
     96            this->data.resize(this->grid->storeIndex[0]->numElements()); 
    9797         } 
    98          CArray<double,1> input(data.numElements()) ; 
     98         CArray<double,1> input(data.numElements()); 
    9999         this->grid->inputFieldServer(storedClient, input); 
    100100         (*this->foperation)(input); 
     
    106106         this->incrementNStep(); 
    107107         *last_Write = writeDate; 
    108          return (true); 
    109       } 
    110       return (false); 
     108         return true; 
     109      } 
     110      return false; 
    111111   } 
    112112 
     
    114114  { 
    115115 
    116     if (SuperClass::dispatchEvent(event)) return true ; 
     116    if (SuperClass::dispatchEvent(event)) return true; 
    117117    else 
    118118    { 
     
    120120      { 
    121121        case EVENT_ID_UPDATE_DATA : 
    122           recvUpdateData(event) ; 
    123           return true ; 
    124           break ; 
     122          recvUpdateData(event); 
     123          return true; 
     124          break; 
    125125 
    126126            case EVENT_ID_ADD_VARIABLE : 
    127              recvAddVariable(event) ; 
    128              return true ; 
    129              break ; 
     127             recvAddVariable(event); 
     128             return true; 
     129             break; 
    130130 
    131131           case EVENT_ID_ADD_VARIABLE_GROUP : 
    132              recvAddVariableGroup(event) ; 
    133              return true ; 
    134              break ; 
     132             recvAddVariableGroup(event); 
     133             return true; 
     134             break; 
    135135 
    136136        default : 
    137           ERROR("bool CField::dispatchEvent(CEventServer& event)",<<"Unknown Event") ; 
    138           return false ; 
     137          ERROR("bool CField::dispatchEvent(CEventServer& event)", << "Unknown Event"); 
     138          return false; 
    139139      } 
    140140    } 
     
    143143  void CField::sendUpdateData(void) 
    144144  { 
    145     CContext* context = CContext::getCurrent() ; 
    146     CContextClient* client=context->client ; 
    147  
    148     CEventClient event(getType(),EVENT_ID_UPDATE_DATA) ; 
    149  
    150     map<int,CArray<int, 1>* >::iterator it ; 
    151     list<shared_ptr<CMessage> > list_msg ; 
    152     list< CArray<double,1>* > list_data ; 
    153  
    154      for(it=grid->storeIndex_toSrv.begin();it!=grid->storeIndex_toSrv.end();it++) 
    155     { 
    156       int rank=(*it).first ; 
    157       CArray<int,1>& index = *(it->second) ; 
    158       CArray<double,1> data_tmp(index.numElements()) ; 
    159       for(int n=0;n<data_tmp.numElements();n++) data_tmp(n)=data(index(n)) ; 
    160       list_msg.push_back(shared_ptr<CMessage>(new CMessage)) ; 
    161       list_data.push_back(new CArray<double,1>(data_tmp)) ; 
    162       *list_msg.back()<<getId()<<*list_data.back() ; 
    163       event.push(rank,grid->nbSenders[rank],*list_msg.back()) ; 
    164     } 
    165     client->sendEvent(event) ; 
    166  
    167     for(list< CArray<double,1>* >::iterator it=list_data.begin();it!=list_data.end();it++) delete *it ; 
     145    CContext* context = CContext::getCurrent(); 
     146    CContextClient* client = context->client; 
     147 
     148    CEventClient event(getType(),EVENT_ID_UPDATE_DATA); 
     149 
     150    map<int,CArray<int, 1>* >::iterator it; 
     151    list<shared_ptr<CMessage> > list_msg; 
     152    list< CArray<double,1>* > list_data; 
     153 
     154     for (it = grid->storeIndex_toSrv.begin(); it != grid->storeIndex_toSrv.end(); it++) 
     155    { 
     156      int rank = (*it).first; 
     157      CArray<int,1>& index = *(it->second); 
     158      CArray<double,1> data_tmp(index.numElements()); 
     159      for (int n = 0; n < data_tmp.numElements(); n++) data_tmp(n) = data(index(n)); 
     160      list_msg.push_back(shared_ptr<CMessage>(new CMessage)); 
     161      list_data.push_back(new CArray<double,1>(data_tmp)); 
     162      *list_msg.back() << getId() << *list_data.back(); 
     163      event.push(rank,grid->nbSenders[rank],*list_msg.back()); 
     164    } 
     165    client->sendEvent(event); 
     166 
     167    for (list< CArray<double,1>* >::iterator it = list_data.begin(); it != list_data.end(); it++) delete *it; 
    168168  } 
    169169 
    170170  void CField::recvUpdateData(CEventServer& event) 
    171171  { 
    172     vector<int> ranks ; 
    173     vector<CBufferIn*> buffers ; 
    174  
    175     list<CEventServer::SSubEvent>::iterator it ; 
    176     string fieldId ; 
    177  
    178     for (it=event.subEvents.begin();it!=event.subEvents.end();++it) 
    179     { 
    180       int rank=it->rank; 
    181       CBufferIn* buffer=it->buffer; 
    182       *buffer>>fieldId ; 
    183       ranks.push_back(rank) ; 
    184       buffers.push_back(buffer) ; 
    185     } 
    186     get(fieldId)->recvUpdateData(ranks,buffers) ; 
     172    vector<int> ranks; 
     173    vector<CBufferIn*> buffers; 
     174 
     175    list<CEventServer::SSubEvent>::iterator it; 
     176    string fieldId; 
     177 
     178    for (it = event.subEvents.begin(); it != event.subEvents.end(); ++it) 
     179    { 
     180      int rank = it->rank; 
     181      CBufferIn* buffer = it->buffer; 
     182      *buffer >> fieldId; 
     183      ranks.push_back(rank); 
     184      buffers.push_back(buffer); 
     185    } 
     186    get(fieldId)->recvUpdateData(ranks,buffers); 
    187187  } 
    188188 
     
    192192    if (data_srv.empty()) 
    193193    { 
    194 //      for(map<int, CArray<int, 1>* >::iterator it=grid->out_i_fromClient.begin();it!=grid->out_i_fromClient.end();it++) 
    195       for(map<int, CArray<size_t, 1>* >::iterator it=grid->outIndexFromClient.begin();it!=grid->outIndexFromClient.end();++it) 
    196       { 
    197         int rank=it->first ; 
    198         CArray<double,1> data_tmp(it->second->numElements()) ; 
    199         data_srv.insert( pair<int, CArray<double,1>* >(rank, new CArray<double,1>(data_tmp) ) ) ; 
    200         foperation_srv.insert(pair<int,boost::shared_ptr<func::CFunctor> >(rank,boost::shared_ptr<func::CFunctor>(new func::CInstant(*data_srv[rank])))) ; 
    201       } 
    202     } 
    203  
    204     CContext* context = CContext::getCurrent() ; 
    205     const CDate & currDate = context->getCalendar()->getCurrentDate(); 
     194//      for (map<int, CArray<int, 1>* >::iterator it = grid->out_i_fromClient.begin(); it != grid->out_i_fromClient.end(); it++) 
     195      for (map<int, CArray<size_t, 1>* >::iterator it = grid->outIndexFromClient.begin(); it != grid->outIndexFromClient.end(); ++it) 
     196      { 
     197        int rank = it->first; 
     198        CArray<double,1> data_tmp(it->second->numElements()); 
     199        data_srv.insert( pair<int, CArray<double,1>* >(rank, new CArray<double,1>(data_tmp))); 
     200        foperation_srv.insert(pair<int,boost::shared_ptr<func::CFunctor> >(rank,boost::shared_ptr<func::CFunctor>(new func::CInstant(*data_srv[rank])))); 
     201      } 
     202    } 
     203 
     204    CContext* context = CContext::getCurrent(); 
     205    const CDate& currDate = context->getCalendar()->getCurrentDate(); 
    206206    const CDate opeDate      = *last_operation_srv + freq_operation_srv; 
    207207    const CDate writeDate    = *last_Write_srv     + freq_write_srv; 
    208208 
    209  
    210  
    211209    if (opeDate <= currDate) 
    212210    { 
    213       for(int n=0;n<ranks.size();n++) 
    214       { 
    215         CArray<double,1> data_tmp ; 
    216         *buffers[n]>>data_tmp ; 
    217         (*foperation_srv[ranks[n]])(data_tmp) ; 
     211      for (int n = 0; n < ranks.size(); n++) 
     212      { 
     213        CArray<double,1> data_tmp; 
     214        *buffers[n] >> data_tmp; 
     215        (*foperation_srv[ranks[n]])(data_tmp); 
    218216      } 
    219217      *last_operation_srv = currDate; 
     
    222220    if (writeDate < (currDate + freq_operation_srv)) 
    223221    { 
    224       for(int n=0;n<ranks.size();n++) 
     222      for (int n = 0; n < ranks.size(); n++) 
    225223      { 
    226224        this->foperation_srv[ranks[n]]->final(); 
     
    228226 
    229227      *last_Write_srv = writeDate; 
    230       writeField() ; 
    231       *lastlast_Write_srv=*last_Write_srv; 
     228      writeField(); 
     229      *lastlast_Write_srv = *last_Write_srv; 
    232230    } 
    233231  } 
     
    235233  void CField::writeField(void) 
    236234  { 
    237     if (! getRelFile()->allDomainEmpty ) 
    238       if (! grid->domain->isEmpty() || getRelFile()->type == CFile::type_attr::one_file) 
     235    if (!getRelFile()->allDomainEmpty) 
     236      if (!grid->domain->isEmpty() || getRelFile()->type == CFile::type_attr::one_file) 
    239237      { 
    240238        getRelFile()->checkFile(); 
     
    243241      } 
    244242  } 
     243 
    245244   //---------------------------------------------------------------- 
    246245 
     
    248247   { 
    249248      this->file = _file; 
    250       hasOutputFile=true ; 
    251    } 
    252  
    253    //---------------------------------------------------------------- 
    254  
    255    StdString CField::GetName(void)   { return (StdString("field")); } 
    256    StdString CField::GetDefName(void){ return (CField::GetName()); } 
    257    ENodeType CField::GetType(void)   { return (eField); } 
     249      hasOutputFile = true; 
     250   } 
     251 
     252   //---------------------------------------------------------------- 
     253 
     254   StdString CField::GetName(void)    { return StdString("field"); } 
     255   StdString CField::GetDefName(void) { return CField::GetName(); } 
     256   ENodeType CField::GetType(void)    { return eField; } 
    258257 
    259258   //---------------------------------------------------------------- 
     
    261260   CGrid* CField::getRelGrid(void) const 
    262261   { 
    263       return (this->grid); 
     262      return this->grid; 
    264263   } 
    265264 
     
    268267   CFile* CField::getRelFile(void) const 
    269268   { 
    270       return (this->file); 
     269      return this->file; 
    271270   } 
    272271 
    273272   StdSize CField::getNStep(void) const 
    274273   { 
    275       return (this->nstep); 
     274      return this->nstep; 
    276275   } 
    277276 
     
    283282   void CField::resetNStep(void) 
    284283   { 
    285       this->nstep=0; 
    286    } 
    287  
    288    //---------------------------------------------------------------- 
    289  
    290    const CDuration & CField::getFreqOperation(void) const 
    291    { 
    292       return (this->freq_operation); 
    293    } 
    294  
    295    //---------------------------------------------------------------- 
    296    const CDuration & CField::getFreqWrite(void) const 
    297    { 
    298       return (this->freq_write); 
     284      this->nstep = 0; 
     285   } 
     286 
     287   //---------------------------------------------------------------- 
     288 
     289   const CDuration& CField::getFreqOperation(void) const 
     290   { 
     291      return this->freq_operation; 
     292   } 
     293 
     294   //---------------------------------------------------------------- 
     295 
     296   const CDuration& CField::getFreqWrite(void) const 
     297   { 
     298      return this->freq_write; 
    299299   } 
    300300 
     
    303303   boost::shared_ptr<func::CFunctor> CField::getFieldOperation(void) const 
    304304   { 
    305       return (this->foperation); 
    306    } 
    307  
     305      return this->foperation; 
     306   } 
    308307 
    309308   bool CField::isActive(void) const 
    310309   { 
    311       return (!this->refObject.empty()); 
    312    } 
     310      return !this->refObject.empty(); 
     311   } 
     312 
    313313   //---------------------------------------------------------------- 
    314314 
     
    338338//      if (!processed) 
    339339//      { 
    340 //        processed=true ; 
    341 //        solveRefInheritance(true) ; 
    342 //        solveBaseReference() ; 
    343 //        solveOperation() ; 
    344 //        solveGridReference() ; 
    345 // 
    346 //        if (hasDirectFieldReference()) baseRefObject->processEnabledField() ; 
     340//        processed = true; 
     341//        solveRefInheritance(true); 
     342//        solveBaseReference(); 
     343//        solveOperation(); 
     344//        solveGridReference(); 
     345// 
     346//        if (hasDirectFieldReference()) baseRefObject->processEnabledField(); 
    347347//        buildExpression(); 
    348 //        active=true; 
     348//        active = true; 
    349349//      } 
    350350//    } 
     
    384384       if (hasDirectFieldReference()) baseRefObject->buildAllExpressionEnabledField(); 
    385385       buildExpression(); 
    386        active=true; 
     386       active = true; 
    387387     } 
    388388   } 
     
    394394      using namespace func; 
    395395 
    396       if (!hasOutputFile && !hasFieldOut) return ; 
    397  
    398       StdString id ; 
    399       if (hasId()) id=getId(); 
    400       else if (!name.isEmpty()) id=name ; 
    401       else if (hasDirectFieldReference()) id=baseRefObject->getId() ; 
     396      if (!hasOutputFile && !hasFieldOut) return; 
     397 
     398      StdString id; 
     399      if (hasId()) id = getId(); 
     400      else if (!name.isEmpty()) id = name; 
     401      else if (hasDirectFieldReference()) id = baseRefObject->getId(); 
    402402 
    403403      CContext* context = CContext::getCurrent(); 
     
    405405      if (freq_op.isEmpty()) freq_op.setValue(TimeStep); 
    406406 
    407       if (operation.isEmpty() ) 
     407      if (operation.isEmpty()) 
    408408      { 
    409409         ERROR("CField::solveOperation(void)", 
     
    455455         *this->last_operation   = *this->last_operation - toffset; 
    456456 
    457         if (operation.get()=="once") isOnceOperation=true ; 
    458         else isOnceOperation=false; 
    459         isFirstOperation=true; 
    460  
    461  
    462 #define DECLARE_FUNCTOR(MType, mtype)              \ 
    463    if  (operation.getValue().compare(#mtype) == 0) \ 
    464    {                                               \ 
    465       if (!detect_missing_value.isEmpty() && !default_value.isEmpty() && detect_missing_value==true) \ 
     457        if (operation.get() == "once") isOnceOperation = true; 
     458        else isOnceOperation = false; 
     459        isFirstOperation = true; 
     460 
     461#define DECLARE_FUNCTOR(MType, mtype) \ 
     462   if (operation.getValue().compare(#mtype) == 0) \ 
     463   { \ 
     464      if (!detect_missing_value.isEmpty() && !default_value.isEmpty() && detect_missing_value == true) \ 
    466465      { \ 
    467466        boost::shared_ptr<func::CFunctor> foperation_(new C##MType(this->data,default_value)); \ 
     
    471470      { \ 
    472471        boost::shared_ptr<func::CFunctor> foperation_(new C##MType(this->data)); \ 
    473         this->foperation = foperation_;  \ 
     472        this->foperation = foperation_; \ 
    474473      } \ 
    475       return;                                      \ 
     474      return; \ 
    476475   } 
    477476 
     
    482481               << "The operation is not defined !"); 
    483482//      } 
    484  
    485  
    486483   } 
    487484 
    488485   //---------------------------------------------------------------- 
    489486/* 
    490    void CField::fromBinary(StdIStream & is) 
     487   void CField::fromBinary(StdIStream& is) 
    491488   { 
    492489      SuperClass::fromBinary(is); 
     
    514511         if (CDomain::has(domain_ref.getValue())) 
    515512         { 
    516            domain = CDomain::get(domain_ref.getValue()) ; 
     513           domain = CDomain::get(domain_ref.getValue()); 
    517514           vecDom.push_back(domain); 
    518515         } 
     
    520517            ERROR("CField::solveGridReference(void)", 
    521518                  << "Reference to the domain \'" 
    522                   << domain_ref.getValue() << "\' is wrong") ; 
     519                  << domain_ref.getValue() << "\' is wrong"); 
    523520      } 
    524521 
     
    527524         if (CAxis::has(axis_ref.getValue())) 
    528525         { 
    529            axis = CAxis::get(axis_ref.getValue()) ; 
     526           axis = CAxis::get(axis_ref.getValue()); 
    530527           vecAxis.push_back(axis); 
    531528         } 
     
    533530            ERROR("CField::solveGridReference(void)", 
    534531                  << "Reference to the axis \'" 
    535                   << axis_ref.getValue() <<"\' is wrong") ; 
     532                  << axis_ref.getValue() <<"\' is wrong"); 
    536533      } 
    537534 
     
    540537         if (CGrid::has(grid_ref.getValue())) 
    541538         { 
    542            this->grid = CGrid::get(grid_ref.getValue()) ; 
     539           this->grid = CGrid::get(grid_ref.getValue()); 
    543540           domList = grid->getDomainList(); 
    544541           axisList = grid->getAxisList(); 
     
    550547      } 
    551548 
    552       if (grid_ref.isEmpty() &&  domain_ref.isEmpty() && axis_ref.isEmpty()) 
     549      if (grid_ref.isEmpty() && domain_ref.isEmpty() && axis_ref.isEmpty()) 
    553550      { 
    554551            ERROR("CField::solveGridReference(void)", 
     
    562559//     } 
    563560 
    564 //     CType<string> goodDomain ; 
    565 //     CType<string> goodAxis ; 
     561//     CType<string> goodDomain; 
     562//     CType<string> goodAxis; 
    566563//     if (!grid_ref.isEmpty()) 
    567564//     { 
    568 //       if (!grid->domain_ref.isEmpty()) goodDomain=grid->domain_ref ; 
    569 //       if (!grid->axis_ref.isEmpty()) goodAxis=grid->axis_ref ; 
     565//       if (!grid->domain_ref.isEmpty()) goodDomain = grid->domain_ref; 
     566//       if (!grid->axis_ref.isEmpty()) goodAxis = grid->axis_ref; 
    570567//     } 
    571 //     if (!domain_ref.isEmpty()) goodDomain=domain_ref ; 
    572 //     if (!axis_ref.isEmpty()) goodAxis=axis_ref ; 
     568//     if (!domain_ref.isEmpty()) goodDomain = domain_ref; 
     569//     if (!axis_ref.isEmpty()) goodAxis = axis_ref; 
    573570 
    574571//     CArray<std::string,1> domListTmp = grid->domainList.getValue(); 
     
    590587//     else 
    591588//     { 
    592 //       if (CDomain::has(goodDomain)) domain = CDomain::get(goodDomain) ; 
     589//       if (CDomain::has(goodDomain)) domain = CDomain::get(goodDomain); 
    593590//       else ERROR("CField::solveGridReference(void)",<< "Reference to the domain \'" 
    594 //                  <<goodDomain << "\' is wrong") ; 
    595 ////                  <<goodDomain.get() << "\' is wrong") ; 
     591//                  << goodDomain << "\' is wrong"); 
     592////                << goodDomain.get() << "\' is wrong"); 
    596593//     } 
    597594// 
     
    599596//     if (!goodAxis.empty()) 
    600597//     { 
    601 //       if (CAxis::has(goodAxis))  axis = CAxis::get(goodAxis) ; 
     598//       if (CAxis::has(goodAxis))  axis = CAxis::get(goodAxis); 
    602599//       else  ERROR("CField::solveGridReference(void)", << "Reference to the axis \'" 
    603 //                  << goodAxis <<"\' is wrong") ; 
    604 //                  << goodAxis.get() <<"\' is wrong") ; 
     600//                   << goodAxis <<"\' is wrong"); 
     601//                   << goodAxis.get() <<"\' is wrong"); 
    605602//     } 
    606603 
    607 //     bool nothingToDo=false ; 
     604//     bool nothingToDo = false; 
    608605// 
    609606//     if (!grid_ref.isEmpty()) 
    610607//     { 
    611608//       if (!grid->domain_ref.isEmpty() && goodDomain.get() == grid->domain_ref.get()) 
    612 //         if (goodAxis.isEmpty()) nothingToDo=true ; 
     609//         if (goodAxis.isEmpty()) nothingToDo = true; 
    613610//         else if (!grid->axis_ref.isEmpty()) 
    614 //                 if (grid->axis_ref.get()==goodAxis.get()) nothingToDo=true ; 
     611//                 if (grid->axis_ref.get() == goodAxis.get()) nothingToDo = true; 
    615612//     } 
    616613// 
     
    620617//       if (!goodAxis.isEmpty()) 
    621618//       { 
    622 //         this->grid = CGrid::createGrid(domain, axis) ; 
     619//         this->grid = CGrid::createGrid(domain, axis); 
    623620//         this->grid_ref.setValue(this->grid->getId()); 
    624621//       } 
    625622//       else 
    626623//       { 
    627 //         this->grid = CGrid::createGrid(domain) ; 
     624//         this->grid = CGrid::createGrid(domain); 
    628625//         this->grid_ref.setValue(this->grid->getId()); 
    629626//       } 
    630627//     } 
    631628 
    632 //     grid->solveReference() ; 
     629//     grid->solveReference(); 
    633630//     grid->solveDomainAxisRef(); 
    634631//     grid->checkMaskIndex(); 
     
    648645 
    649646   template <> 
    650       void CGroupTemplate<CField, CFieldGroup, CFieldAttributes>::solveRefInheritance(void) 
     647   void CGroupTemplate<CField, CFieldGroup, CFieldAttributes>::solveRefInheritance(void) 
    651648   { 
    652649      if (this->group_ref.isEmpty()) return; 
     
    662659 
    663660      std::vector<CField*> allChildren  = group->getAllChildren(); 
    664       std::vector<CField*>::iterator 
    665          it = allChildren.begin(), end = allChildren.end(); 
     661      std::vector<CField*>::iterator it = allChildren.begin(), end = allChildren.end(); 
    666662 
    667663      for (; it != end; it++) 
    668664      { 
    669665         CField* child = *it; 
    670          if (child->hasId()) owner->createChild()->field_ref.setValue(child->getId()) ; 
     666         if (child->hasId()) owner->createChild()->field_ref.setValue(child->getId()); 
    671667 
    672668      } 
     
    676672   { 
    677673     map<int, CArray<double,1>* >::iterator it; 
    678      for(it=data_srv.begin();it!=data_srv.end();it++) *it->second = (*it->second -addOffset) * 1./scaleFactor  ; 
     674     for (it = data_srv.begin(); it != data_srv.end(); it++) *it->second = (*it->second - addOffset) / scaleFactor; 
    679675   } 
    680676 
     
    682678   { 
    683679      map<int, CArray<double,1>* >::iterator it; 
    684       for(it=data_srv.begin();it!=data_srv.end();it++) 
    685       { 
    686         grid->outputField(it->first,*it->second, fieldOut.dataFirst()) ; 
    687       } 
    688  
    689 //         grid->outputField(it->first,*it->second, fieldOut.) ; 
    690  
     680      for (it = data_srv.begin(); it != data_srv.end(); it++) 
     681      { 
     682        grid->outputField(it->first,*it->second, fieldOut.dataFirst()); 
     683      } 
     684 
     685//         grid->outputField(it->first,*it->second, fieldOut.); 
    691686   } 
    692687 
     
    695690      map<int, CArray<double,1>* >::iterator it; 
    696691 
    697       for(it=data_srv.begin();it!=data_srv.end();it++) 
    698       { 
    699          grid->outputField(it->first,*it->second, fieldOut) ; 
     692      for (it = data_srv.begin(); it != data_srv.end(); it++) 
     693      { 
     694         grid->outputField(it->first, *it->second, fieldOut); 
    700695      } 
    701696   } 
     
    703698   ///------------------------------------------------------------------- 
    704699 
    705    void CField::parse(xml::CXMLNode & node) 
     700   void CField::parse(xml::CXMLNode& node) 
    706701   { 
    707702      SuperClass::parse(node); 
    708       if (! node.getContent(this->content)) 
     703      if (!node.getContent(this->content)) 
    709704      { 
    710705        if (node.goToChildElement()) 
     
    712707          do 
    713708          { 
    714             if (node.getElementName()=="variable" || node.getElementName()=="variable_group") this->getVirtualVariableGroup()->parseChild(node); 
    715           } while (node.goToNextElement()) ; 
     709            if (node.getElementName() == "variable" || node.getElementName() == "variable_group") this->getVirtualVariableGroup()->parseChild(node); 
     710          } while (node.goToNextElement()); 
    716711          node.goToParentElement(); 
    717712        } 
     
    723718    if (!hasInstantData) 
    724719    { 
    725       instantData.resize(grid->storeIndex_client.numElements()) ; 
    726       hasInstantData=true ; 
    727     } 
    728     return &instantData ; 
     720      instantData.resize(grid->storeIndex_client.numElements()); 
     721      hasInstantData = true; 
     722    } 
     723    return &instantData; 
    729724  } 
    730725 
    731726  void CField::addDependency(CField* field, int slotId) 
    732727  { 
    733     fieldDependency.push_back(pair<CField*,int>(field,slotId)) ; 
     728    fieldDependency.push_back(pair<CField*,int>(field,slotId)); 
    734729  } 
    735730 
     
    738733    if (content.size() > 0) 
    739734    { 
    740       CSimpleNodeExpr* simpleExpr=parseExpr(content+'\0') ; 
    741       expression=CFieldNode::newNode(simpleExpr) ; 
    742       delete simpleExpr ; 
    743       set<string> instantFieldIds ; 
    744       map<string,CField*> associatedInstantFieldIds ; 
    745       expression->getInstantFieldIds(instantFieldIds) ; 
    746       for (set<string>::iterator it=instantFieldIds.begin() ; it!=instantFieldIds.end();++it) 
    747       { 
    748         if (*it!="this") 
     735      CSimpleNodeExpr* simpleExpr = parseExpr(content+'\0'); 
     736      expression = CFieldNode::newNode(simpleExpr); 
     737      delete simpleExpr; 
     738      set<string> instantFieldIds; 
     739      map<string,CField*> associatedInstantFieldIds; 
     740      expression->getInstantFieldIds(instantFieldIds); 
     741      for (set<string>::iterator it = instantFieldIds.begin(); it != instantFieldIds.end(); ++it) 
     742      { 
     743        if (*it != "this") 
    749744        { 
    750745          if (CField::has(*it)) 
    751746          { 
    752             CField* field=CField::get(*it) ; 
    753 //            field->processEnabledField() ; 
     747            CField* field = CField::get(*it); 
     748//            field->processEnabledField(); 
    754749            field->buildAllExpressionEnabledField(); 
    755             associatedInstantFieldIds[*it]=field ; 
     750            associatedInstantFieldIds[*it] = field; 
    756751          } 
    757           else  ERROR("void CField::buildExpression(void)",<<" Field "<<*it<<" does not exist") ; 
     752          else  ERROR("void CField::buildExpression(void)", << " Field " << *it << " does not exist"); 
    758753        } 
    759754      } 
    760755 
    761       set<string> averageFieldIds ; 
    762       map<string,CField*> associatedAverageFieldIds ; 
    763  
    764       expression->getAverageFieldIds(averageFieldIds) ; 
    765       for (set<string>::iterator it=averageFieldIds.begin() ; it!=averageFieldIds.end();++it) 
     756      set<string> averageFieldIds; 
     757      map<string,CField*> associatedAverageFieldIds; 
     758 
     759      expression->getAverageFieldIds(averageFieldIds); 
     760      for (set<string>::iterator it = averageFieldIds.begin(); it != averageFieldIds.end(); ++it) 
    766761      { 
    767762        if (CField::has(*it)) 
    768763        { 
    769            CFieldGroup* root=CFieldGroup::get("field_definition") ; 
    770            CField* averageField=root->createChild() ; 
    771            CField* instantField=root->createChild() ; 
    772            averageField->field_ref=*it ; 
    773            averageField->hasFieldOut=true ; 
    774            averageField->fieldOut=instantField ; 
    775            instantField->freq_op=freq_op ; 
    776 //           averageField-> processEnabledField() ; 
     764           CFieldGroup* root = CFieldGroup::get("field_definition"); 
     765           CField* averageField = root->createChild(); 
     766           CField* instantField = root->createChild(); 
     767           averageField->field_ref = *it; 
     768           averageField->hasFieldOut = true; 
     769           averageField->fieldOut = instantField; 
     770           instantField->freq_op = freq_op; 
     771//           averageField-> processEnabledField(); 
    777772           averageField->buildAllExpressionEnabledField(); 
    778773           instantField->SuperClassAttribute::setAttributes(averageField, true); 
    779            instantField->field_ref.reset() ; 
    780            instantField->operation.reset() ; 
    781  
    782 //           instantField-> processEnabledField() ; 
     774           instantField->field_ref.reset(); 
     775           instantField->operation.reset(); 
     776 
     777//           instantField-> processEnabledField(); 
    783778           instantField->buildAllExpressionEnabledField(); 
    784            associatedAverageFieldIds[*it]=instantField  ; 
     779           associatedAverageFieldIds[*it] = instantField; 
    785780        } 
    786         else ERROR("void CField::buildExpression(void)",<<" Field "<<*it<<" does not exist") ; 
    787       } 
    788  
    789       expression->reduce(this,associatedInstantFieldIds,associatedAverageFieldIds) ; 
    790  
    791       slots.resize(instantFieldIds.size()+averageFieldIds.size()) ; 
    792       resetSlots() ; 
    793       int slotId=0 ; 
    794       set<CField*> fields ; 
    795       expression->getFields(fields) ; 
    796       for (set<CField*>::iterator it=fields.begin() ; it!=fields.end();++it,++slotId) (*it)->addDependency(this,slotId) ; 
    797       hasExpression=true; 
     781        else ERROR("void CField::buildExpression(void)", << " Field " << *it << " does not exist"); 
     782      } 
     783 
     784      expression->reduce(this,associatedInstantFieldIds,associatedAverageFieldIds); 
     785 
     786      slots.resize(instantFieldIds.size() + averageFieldIds.size()); 
     787      resetSlots(); 
     788      int slotId = 0; 
     789      set<CField*> fields; 
     790      expression->getFields(fields); 
     791      for (set<CField*>::iterator it = fields.begin(); it != fields.end(); ++it, ++slotId) (*it)->addDependency(this,slotId); 
     792      hasExpression = true; 
    798793    } 
    799794  } 
     
    801796  void CField::resetSlots(void) 
    802797  { 
    803     for(vector<bool>::iterator it=slots.begin();it!=slots.end();++it) *it=false ; 
     798    for (vector<bool>::iterator it = slots.begin(); it != slots.end(); ++it) *it = false; 
    804799  } 
    805800 
    806801  bool CField::slotsFull(void) 
    807802  { 
    808     bool ret=true ; 
    809     for(vector<bool>::iterator it=slots.begin();it!=slots.end();++it) ret &= *it; 
    810     return ret ; 
     803    bool ret = true; 
     804    for (vector<bool>::iterator it = slots.begin(); it != slots.end(); ++it) ret &= *it; 
     805    return ret; 
    811806  } 
    812  
    813807 
    814808  void CField::setSlot(int slotId) 
    815809  { 
    816     CContext* context = CContext::getCurrent() ; 
    817     const CDate & currDate = context->getCalendar()->getCurrentDate(); 
    818     if (slotUpdateDate==NULL || currDate!=*slotUpdateDate) 
    819     { 
    820       resetSlots() ; 
    821       if (slotUpdateDate==NULL) slotUpdateDate=new CDate(currDate) ; 
    822       else *slotUpdateDate=currDate ; 
    823     } 
    824     slots[slotId]=true ; 
     810    CContext* context = CContext::getCurrent(); 
     811    const CDate& currDate = context->getCalendar()->getCurrentDate(); 
     812    if (slotUpdateDate == NULL || currDate != *slotUpdateDate) 
     813    { 
     814      resetSlots(); 
     815      if (slotUpdateDate == NULL) slotUpdateDate = new CDate(currDate); 
     816      else *slotUpdateDate = currDate; 
     817    } 
     818    slots[slotId] = true; 
    825819    if (slotsFull()) 
    826820    { 
    827       CArray<double,1> expr(expression->compute()) ; 
     821      CArray<double,1> expr(expression->compute()); 
    828822 
    829823      if (hasInstantData) 
    830824      { 
    831         instantData=expr ; 
    832         for(list< pair<CField *,int> >::iterator it=fieldDependency.begin(); it!=fieldDependency.end(); ++it) 
    833           if (it->first!=this) it->first->setSlot(it->second) ; 
    834       } 
    835  
    836       if (hasOutputFile) updateDataFromExpression(expr) ; 
    837  
     825        instantData = expr; 
     826        for (list< pair<CField *,int> >::iterator it = fieldDependency.begin(); it != fieldDependency.end(); ++it) 
     827          if (it->first != this) it->first->setSlot(it->second); 
     828      } 
     829 
     830      if (hasOutputFile) updateDataFromExpression(expr); 
     831 
     832      const std::vector<CField*>& refField = getAllReference(); 
     833      for (std::vector<CField*>::const_iterator it = refField.begin(); it != refField.end(); it++) 
     834      { 
     835        if (!(*it)->hasExpression) 
     836          (*it)->setDataFromExpression(expr); 
     837      } 
    838838    } 
    839839  } 
     
    853853     } 
    854854 
    855      return (domAxisIds_); 
     855     return domAxisIds_; 
    856856   } 
    857857 
    858858   CVariable* CField::addVariable(const string& id) 
    859859   { 
    860      return vVariableGroup->createChild(id) ; 
     860     return vVariableGroup->createChild(id); 
    861861   } 
    862862 
    863863   CVariableGroup* CField::addVariableGroup(const string& id) 
    864864   { 
    865      return vVariableGroup->createChildGroup(id) ; 
    866    } 
    867  
     865     return vVariableGroup->createChildGroup(id); 
     866   } 
    868867 
    869868   void CField::sendAddAllVariables() 
     
    890889   void CField::sendAddVariable(const string& id) 
    891890   { 
    892     CContext* context=CContext::getCurrent() ; 
    893  
    894     if (! context->hasServer ) 
    895     { 
    896        CContextClient* client=context->client ; 
    897  
    898        CEventClient event(this->getType(),EVENT_ID_ADD_VARIABLE) ; 
     891    CContext* context = CContext::getCurrent(); 
     892 
     893    if (!context->hasServer) 
     894    { 
     895       CContextClient* client = context->client; 
     896 
     897       CEventClient event(this->getType(),EVENT_ID_ADD_VARIABLE); 
    899898       if (client->isServerLeader()) 
    900899       { 
    901          CMessage msg ; 
    902          msg<<this->getId() ; 
    903          msg<<id ; 
    904          event.push(client->getServerLeader(),1,msg) ; 
    905          client->sendEvent(event) ; 
     900         CMessage msg; 
     901         msg << this->getId(); 
     902         msg << id; 
     903         event.push(client->getServerLeader(),1,msg); 
     904         client->sendEvent(event); 
    906905       } 
    907        else client->sendEvent(event) ; 
    908     } 
    909  
    910    } 
    911  
     906       else client->sendEvent(event); 
     907    } 
     908   } 
    912909 
    913910   void CField::sendAddVariableGroup(const string& id) 
    914911   { 
    915     CContext* context=CContext::getCurrent() ; 
    916     if (! context->hasServer ) 
    917     { 
    918        CContextClient* client=context->client ; 
    919  
    920        CEventClient event(this->getType(),EVENT_ID_ADD_VARIABLE_GROUP) ; 
     912    CContext* context = CContext::getCurrent(); 
     913    if (!context->hasServer) 
     914    { 
     915       CContextClient* client = context->client; 
     916 
     917       CEventClient event(this->getType(),EVENT_ID_ADD_VARIABLE_GROUP); 
    921918       if (client->isServerLeader()) 
    922919       { 
    923          CMessage msg ; 
    924          msg<<this->getId() ; 
    925          msg<<id ; 
    926          event.push(client->getServerLeader(),1,msg) ; 
    927          client->sendEvent(event) ; 
     920         CMessage msg; 
     921         msg << this->getId(); 
     922         msg << id; 
     923         event.push(client->getServerLeader(),1,msg); 
     924         client->sendEvent(event); 
    928925       } 
    929        else client->sendEvent(event) ; 
    930     } 
    931  
     926       else client->sendEvent(event); 
     927    } 
    932928   } 
    933929 
     
    935931   { 
    936932 
    937       CBufferIn* buffer=event.subEvents.begin()->buffer; 
     933      CBufferIn* buffer = event.subEvents.begin()->buffer; 
    938934      string id; 
    939       *buffer>>id ; 
    940       get(id)->recvAddVariable(*buffer) ; 
    941    } 
    942  
     935      *buffer >> id; 
     936      get(id)->recvAddVariable(*buffer); 
     937   } 
    943938 
    944939   void CField::recvAddVariable(CBufferIn& buffer) 
    945940   { 
    946       string id ; 
    947       buffer>>id ; 
    948       addVariable(id) ; 
     941      string id; 
     942      buffer >> id; 
     943      addVariable(id); 
    949944   } 
    950945 
     
    952947   { 
    953948 
    954       CBufferIn* buffer=event.subEvents.begin()->buffer; 
     949      CBufferIn* buffer = event.subEvents.begin()->buffer; 
    955950      string id; 
    956       *buffer>>id ; 
    957       get(id)->recvAddVariableGroup(*buffer) ; 
    958    } 
    959  
     951      *buffer >> id; 
     952      get(id)->recvAddVariableGroup(*buffer); 
     953   } 
    960954 
    961955   void CField::recvAddVariableGroup(CBufferIn& buffer) 
    962956   { 
    963       string id ; 
    964       buffer>>id ; 
    965       addVariableGroup(id) ; 
     957      string id; 
     958      buffer >> id; 
     959      addVariableGroup(id); 
    966960   } 
    967961 
     
    970964//  void CField::addReference(CField* field) 
    971965//  { 
    972 //    refObject.push_back(field) ; 
     966//    refObject.push_back(field); 
    973967//  } 
    974968// 
     
    977971//   bool CField::hasDirectFieldReference(void) const 
    978972//   { 
    979 //     return (!this->field_ref.isEmpty()); 
     973//     return !this->field_ref.isEmpty(); 
    980974//   } 
    981975// 
    982976//   //---------------------------------------------------------------- 
    983977// 
    984 //   const StdString & CField::getBaseFieldId(void) const 
     978//   const StdString& CField::getBaseFieldId(void) const 
    985979//   { 
    986 //      return (this->getBaseFieldReference()->getId()); 
     980//      return this->getBaseFieldReference()->getId(); 
    987981//   } 
    988 // 
    989982// 
    990983//   //---------------------------------------------------------------- 
     
    996989//   { 
    997990//      if (this->field_ref.isEmpty()) 
    998 //         return (this->getBaseFieldReference()); 
    999 // 
    1000 //      if (! CField::has(this->field_ref.getValue())) 
     991//         return this->getBaseFieldReference(); 
     992// 
     993//      if (!CField::has(this->field_ref.getValue())) 
    1001994//         ERROR("CField::getDirectFieldReference(void)", 
    1002995//               << "[ ref_name = " << this->field_ref.getValue() << "]" 
    1003996//               << " invalid field name !"); 
    1004997// 
    1005 //      return (CField::get(this->field_ref.getValue())); 
     998//      return CField::get(this->field_ref.getValue()); 
    1006999//   } 
    10071000// 
     
    10101003//   CField* CField::getBaseFieldReference(void) const 
    10111004//   { 
    1012 //      return (baseRefObject); 
     1005//      return baseRefObject; 
    10131006//   } 
    10141007// 
     
    10171010//   const std::vector<CField*>& CField::getAllReference(void) const 
    10181011//   { 
    1019 //      return (refObject); 
     1012//      return refObject; 
    10201013//   } 
    1021 // 
    10221014// 
    10231015//   /*! 
     
    10331025//      std::set<CField *> sset; 
    10341026//      CField* refer_sptr; 
    1035 //      CField * refer_ptr = this; 
     1027//      CField* refer_ptr = this; 
    10361028// 
    10371029//      while (refer_ptr->hasDirectFieldReference()) 
     
    10671059//      std::set<CField *> sset; 
    10681060//      CField* refer_sptr; 
    1069 //      CField * refer_ptr = this; 
     1061//      CField* refer_ptr = this; 
    10701062// 
    10711063//      if (this->hasDirectFieldReference())  baseRefObject = getDirectFieldReference(); 
     
    10871079//      } 
    10881080// 
    1089 //      if (hasDirectFieldReference()) baseRefObject->addReference(this) ; 
     1081//      if (hasDirectFieldReference()) baseRefObject->addReference(this); 
    10901082//   } 
    1091 // 
    1092  
    10931083} // namespace xios 
Note: See TracChangeset for help on using the changeset viewer.