Changeset 459 for XIOS/trunk/src/node
- Timestamp:
- 01/16/14 14:28:23 (10 years ago)
- Location:
- XIOS/trunk/src/node
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
XIOS/trunk/src/node/context.cpp
r445 r459 175 175 } 176 176 177 //---------------------------------------------------------------- 178 /* 179 void CContext::toBinary(StdOStream & os) const 180 { 181 SuperClass::toBinary(os); 182 183 #define DECLARE_NODE(Name_, name_) \ 184 { \ 185 ENodeType renum = C##Name_##Definition::GetType(); \ 186 bool val = C##Name_##Definition::has(C##Name_##Definition::GetDefName()); \ 187 os.write (reinterpret_cast<const char*>(&renum), sizeof(ENodeType)); \ 188 os.write (reinterpret_cast<const char*>(&val), sizeof(bool)); \ 189 if (val) C##Name_##Definition::get(C##Name_##Definition::GetDefName())->toBinary(os); \ 190 } 191 #define DECLARE_NODE_PAR(Name_, name_) 192 #include "node_type.conf" 193 } 194 */ 195 //---------------------------------------------------------------- 196 /* 197 void CContext::fromBinary(StdIStream & is) 198 { 199 SuperClass::fromBinary(is); 200 #define DECLARE_NODE(Name_, name_) \ 201 { \ 202 bool val = false; \ 203 ENodeType renum = Unknown; \ 204 is.read (reinterpret_cast<char*>(&renum), sizeof(ENodeType)); \ 205 is.read (reinterpret_cast<char*>(&val), sizeof(bool)); \ 206 if (renum != C##Name_##Definition::GetType()) \ 207 ERROR("CContext::fromBinary(StdIStream & is)", \ 208 << "[ renum = " << renum << "] Bad type !"); \ 209 if (val) C##Name_##Definition::create(C##Name_##Definition::GetDefName()) -> fromBinary(is); \ 210 } 211 #define DECLARE_NODE_PAR(Name_, name_) 212 #include "node_type.conf" 213 214 } 215 */ 216 177 217 178 //---------------------------------------------------------------- 218 179 … … 337 298 this->findEnabledFiles(); 338 299 300 301 this->processEnabledFiles() ; 302 303 /* 339 304 //Recherche des champs à sortir (enable à true + niveau de sortie correct) 340 305 // pour chaque fichier précédemment listé. … … 347 312 this->solveAllOperation(); 348 313 314 // Traitement des expressions. 315 this->solveAllExpression(); 316 */ 349 317 // Nettoyage de l'arborescence 350 318 CleanTree(); … … 357 325 (void)this->enabledFiles[i]->getEnabledFields(); 358 326 } 327 328 void CContext::processEnabledFiles(void) 329 { 330 for (unsigned int i = 0; i < this->enabledFiles.size(); i++) 331 this->enabledFiles[i]->processEnabledFile(); 332 } 333 359 334 360 335 void CContext::solveAllGridRef(void) … … 370 345 } 371 346 347 void CContext::solveAllExpression(void) 348 { 349 for (unsigned int i = 0; i < this->enabledFiles.size(); i++) 350 this->enabledFiles[i]->solveEFExpression(); 351 } 352 372 353 void CContext::solveAllInheritance(bool apply) 373 354 { -
XIOS/trunk/src/node/context.hpp
r445 r459 110 110 void closeDefinition(void) ; 111 111 void findAllEnabledFields(void); 112 void processEnabledFiles(void) ; 112 113 void solveAllGridRef(void); 113 114 void solveAllOperation(void); 115 void solveAllExpression(void); 114 116 void solveAllInheritance(bool apply=true) ; 115 117 void findEnabledFiles(void); -
XIOS/trunk/src/node/field.cpp
r449 r459 11 11 #include "type.hpp" 12 12 #include "context_client.hpp" 13 #include <set> 13 14 14 15 namespace xios{ … … 23 24 , nstep(0) 24 25 , last_Write(), last_operation() 25 , foperation() 26 , foperation(), hasInstantData(false), hasExpression(false) 27 , active(false) , hasOutputFile(false), slotUpdateDate(NULL) 28 , processed(false) 26 29 { /* Ne rien faire de plus */ } 27 30 … … 33 36 , nstep(0) 34 37 , last_Write(), last_operation() 35 , foperation() 38 , foperation(), hasExpression(false) 39 , active(false), hasOutputFile(false), slotUpdateDate(NULL) 40 , processed(false) 36 41 { /* Ne rien faire de plus */ } 37 42 … … 41 46 // this->file.reset() ; 42 47 this->foperation.reset() ; 48 if (hasExpression) delete expression ; 49 if (slotUpdateDate!=NULL) delete slotUpdateDate ; 50 43 51 } 44 52 … … 199 207 void CField::setRelFile(CFile* _file) 200 208 { 201 this->file = _file; 209 this->file = _file; 210 hasOutputFile=true ; 202 211 } 203 212 … … 327 336 //---------------------------------------------------------------- 328 337 338 void CField::processEnabledField(void) 339 { 340 if (!processed) 341 { 342 processed=true ; 343 solveRefInheritance(true) ; 344 solveOperation() ; 345 solveGridReference() ; 346 347 if (hasDirectFieldReference()) baseRefObject->processEnabledField() ; 348 buildExpression(); 349 active=true; 350 } 351 } 352 329 353 void CField::solveRefInheritance(bool apply) 330 354 { … … 333 357 CField * refer_ptr = this; 334 358 335 this->baseRefObject = CField::get(this); 359 if (this->hasDirectFieldReference()) baseRefObject = getDirectFieldReference(); 360 else baseRefObject = CField::get(this); 336 361 337 362 while (refer_ptr->hasDirectFieldReference()) … … 349 374 SuperClassAttribute::setAttributes(refer_ptr, apply); 350 375 sset.insert(refer_ptr); 351 baseRefObject = refer_sptr;376 //ym baseRefObject = refer_sptr; 352 377 //ym refObject.push_back(refer_sptr); 353 378 } 379 380 if (hasDirectFieldReference()) baseRefObject->addReference(this) ; 354 381 } 355 382 … … 359 386 { 360 387 using namespace func; 361 362 StdString id = this->getBaseFieldReference()->getId(); 388 389 if (!hasOutputFile) return ; 390 391 StdString id ; 392 if (hasId()) id=getId(); 393 else if (!name.isEmpty()) id=name ; 394 else if (hasDirectFieldReference()) id=baseRefObject->getId() ; 395 363 396 CContext* context = CContext::getCurrent(); 364 397 365 398 if (freq_op.isEmpty()) freq_op=string("1ts") ; 366 399 367 if (operation.isEmpty() || this->file->output_freq.isEmpty())400 if (operation.isEmpty() ) 368 401 { 369 402 ERROR("CField::solveOperation(void)", … … 548 581 549 582 grid->solveReference() ; 583 550 584 } 551 585 … … 598 632 ///------------------------------------------------------------------- 599 633 634 void CField::parse(xml::CXMLNode & node) 635 { 636 SuperClass::parse(node); 637 node.getContent(this->content) ; 638 } 639 640 CArray<double,1>* CField::getInstantData(void) 641 { 642 if (!hasInstantData) 643 { 644 instantData.resize(grid->storeIndex_client.numElements()) ; 645 hasInstantData=true ; 646 } 647 return &instantData ; 648 } 649 650 void CField::addReference(CField* field) 651 { 652 refObject.push_back(field) ; 653 } 654 655 void CField::addDependency(CField* field, int slotId) 656 { 657 fieldDependency.push_back(pair<CField*,int>(field,slotId)) ; 658 } 659 660 void CField::buildExpression(void) 661 { 662 if (content.size() > 0) 663 { 664 CSimpleNodeExpr* simpleExpr=parseExpr(content+'\0') ; 665 expression=CFieldNode::newNode(simpleExpr) ; 666 delete simpleExpr ; 667 set<string> fieldIds ; 668 expression->getFieldIds(fieldIds) ; 669 for (set<string>::iterator it=fieldIds.begin() ; it!=fieldIds.end();++it) if (*it!="this") CField::get(*it)->processEnabledField() ; 670 671 expression->reduce(this) ; 672 673 slots.resize(fieldIds.size()) ; 674 resetSlots() ; 675 int slotId=0 ; 676 set<CField*> fields ; 677 expression->getFields(fields) ; 678 for (set<CField*>::iterator it=fields.begin() ; it!=fields.end();++it,++slotId) (*it)->addDependency(this,slotId) ; 679 hasExpression=true; 680 } 681 } 682 683 void CField::resetSlots(void) 684 { 685 for(vector<bool>::iterator it=slots.begin();it!=slots.end();++it) *it=false ; 686 } 687 688 bool CField::slotsFull(void) 689 { 690 bool ret=true ; 691 for(vector<bool>::iterator it=slots.begin();it!=slots.end();++it) ret &= *it; 692 return ret ; 693 } 694 695 696 void CField::setSlot(int slotId) 697 { 698 CContext* context = CContext::getCurrent() ; 699 const CDate & currDate = context->getCalendar()->getCurrentDate(); 700 if (slotUpdateDate==NULL || currDate!=*slotUpdateDate) 701 { 702 resetSlots() ; 703 if (slotUpdateDate==NULL) slotUpdateDate=new CDate(currDate) ; 704 else *slotUpdateDate=currDate ; 705 } 706 slots[slotId]=true ; 707 if (slotsFull()) 708 { 709 CArray<double,1> expr(expression->compute()) ; 710 711 if (hasInstantData) 712 { 713 instantData=expr ; 714 for(list< pair<CField *,int> >::iterator it=fieldDependency.begin(); it!=fieldDependency.end(); ++it) 715 if (it->first!=this) it->first->setSlot(it->second) ; 716 } 717 718 if (hasOutputFile) updateDataFromExpression(expr) ; 719 720 } 721 } 722 600 723 } // namespace xios -
XIOS/trunk/src/node/field.hpp
r445 r459 13 13 #include "array_new.hpp" 14 14 #include "attribute_array.hpp" 15 #include "expr_node.hpp" 15 16 //#include "context.hpp" 16 17 … … 65 66 CField* getDirectFieldReference(void) const; 66 67 CField* getBaseFieldReference(void) const; 68 void addReference(CField* field) ; 67 69 const std::vector<CField*> & getAllReference(void) const; 68 70 … … 92 94 93 95 template <int N> bool updateData(const CArray<double, N>& data); 96 bool updateDataFromExpression(const CArray<double, 1>& data); 94 97 95 98 bool updateDataServer … … 102 105 bool hasDirectFieldReference(void) const; 103 106 bool isActive(void) const; 107 bool active ; 108 bool hasOutputFile ; 104 109 105 110 /// Traitements /// 111 void processEnabledField(void) ; 106 112 void solveRefInheritance(bool apply); 107 113 void solveGridReference(void); … … 127 133 void outputField(CArray<double,3>& fieldOut) ; 128 134 void outputField(CArray<double,2>& fieldOut) ; 129 135 void parse(xml::CXMLNode & node) ; 136 CArray<double,1>* getInstantData(void) ; 130 137 public : 131 138 … … 148 155 149 156 CArray<double, 1> data; 157 CArray<double, 1> instantData; 158 bool hasInstantData ; 150 159 map<int, CArray<double,1>* > data_srv ; 151 160 bool isOnceOperation ; 152 161 bool isFirstOperation ; 162 string content ; 163 164 list< pair<CField *,int> > fieldDependency ; 165 void buildExpression(void) ; 166 void addDependency(CField* field, int slotId) ; 167 void resetSlots(void) ; 168 vector<bool> slots ; 169 CDate* slotUpdateDate ; 170 CFieldNode * expression ; 171 bool hasExpression ; 172 bool slotsFull(void) ; 173 void setSlot(int slotId); 174 bool processed ; 153 175 154 176 }; // class CField -
XIOS/trunk/src/node/field_impl.hpp
r436 r459 13 13 namespace xios { 14 14 15 16 17 18 const std::vector<CField*>& refField=getAllReference();19 std::vector<CField*>::const_iterator it = refField.begin(), end = refField.end();20 21 for (; it != end; it++) (*it)->updateData(_data) ;15 template <int N> 16 void CField::setData(const CArray<double, N>& _data) 17 { 18 if (hasInstantData) 19 { 20 grid->inputField(_data, instantData); 21 for(list< pair<CField *,int> >::iterator it=fieldDependency.begin(); it!=fieldDependency.end(); ++it) it->first->setSlot(it->second) ; 22 22 } 23 23 24 if (!hasExpression) 25 { 26 const std::vector<CField*>& refField=getAllReference(); 27 std::vector<CField*>::const_iterator it = refField.begin(), end = refField.end(); 28 29 for (; it != end; it++) (*it)->setData(_data) ; 30 if (hasOutputFile) updateData(_data) ; 31 } 32 33 } 34 35 24 36 template <int N> 25 37 bool CField::updateData(const CArray<double, N>& _data) 26 38 { 27 39 CContext* context=CContext::getCurrent(); 28 40 const CDate & currDate = context->getCalendar()->getCurrentDate(); 29 41 const CDate opeDate = *last_operation + freq_operation; 30 const CDate writeDate = *last_Write + freq_write; 42 const CDate writeDate = *last_Write + freq_write; 31 43 bool doOperation, doWrite; 32 33 44 34 45 35 46 info(50) << "CField::updateData " << currDate << " : send data to " << this->getBaseFieldId() << std::endl; 36 47 info(50) << "Next operation " << opeDate<<std::endl; 37 48 38 49 doOperation = (opeDate <= currDate) ; 39 50 if (isOnceOperation) 40 51 if (isFirstOperation) doOperation=true ; 41 52 else doOperation=false ; 42 53 43 54 if (doOperation) 44 55 { … … 55 66 info(50) << "(*last_operation = currDate) : " << *last_operation << " = " << currDate << std::endl; 56 67 } 68 69 doWrite = (writeDate < (currDate + freq_operation)) ; 70 if (isOnceOperation) 71 { 72 if(isFirstOperation) 73 { 74 doWrite=true ; 75 isFirstOperation=false ; 76 } 77 else doWrite=false ; 78 } 57 79 58 80 if (doWrite) 81 { 82 this->foperation->final(); 83 *last_Write = writeDate; 84 info(50) << "(*last_Write = currDate) : " << *last_Write << " = " << currDate << std::endl; 85 CTimer::get("XIOS Send Data").resume() ; 86 sendUpdateData() ; 87 CTimer::get("XIOS Send Data").suspend() ; 88 return (true); 89 } 90 91 return (false); 92 } 93 94 bool CField::updateDataFromExpression(const CArray<double, 1>& _data) 95 { 96 CContext* context=CContext::getCurrent(); 97 const CDate & currDate = context->getCalendar()->getCurrentDate(); 98 const CDate opeDate = *last_operation + freq_operation; 99 const CDate writeDate = *last_Write + freq_write; 100 bool doOperation, doWrite; 101 102 103 info(50) << "CField::updateData " << currDate << " : send data to " << this->getBaseFieldId() << std::endl; 104 info(50) << "Next operation " << opeDate<<std::endl; 105 106 doOperation = (opeDate <= currDate) ; 107 if (isOnceOperation) 108 if (isFirstOperation) doOperation=true ; 109 else doOperation=false ; 110 111 if (doOperation) 112 { 113 if (this->data.numElements() != this->grid->storeIndex_client.numElements()) 114 { 115 this->data.resize(this->grid->storeIndex_client.numElements()); 116 } 117 118 (*this->foperation)(_data); 119 120 *last_operation = currDate; 121 info(50) << "(*last_operation = currDate) : " << *last_operation << " = " << currDate << std::endl; 122 } 123 59 124 doWrite = (writeDate < (currDate + freq_operation)) ; 60 125 if (isOnceOperation) -
XIOS/trunk/src/node/file.cpp
r451 r459 102 102 newEnabledFields.push_back(*it) ; 103 103 // Le champ est finalement actif, on y ajoute sa propre reference. 104 (*it)->refObject.push_back(*it);104 // (*it)->refObject.push_back(*it); 105 105 // Le champ est finalement actif, on y ajoute la référence au champ de base. 106 106 (*it)->setRelFile(CFile::get(this)); 107 (*it)->baseRefObject->refObject.push_back(*it);107 // (*it)->baseRefObject->refObject.push_back(*it); 108 108 // A faire, ajouter les references intermediaires... 109 109 } … … 366 366 //---------------------------------------------------------------- 367 367 368 void CFile::processEnabledFile(void) 369 { 370 if (output_freq.isEmpty()) ERROR("void CFile::processEnabledFile(void)", 371 <<"File attribute <<output_freq>> is undefined"); 372 solveFieldRefInheritance(true) ; 373 getEnabledFields() ; 374 processEnabledFields() ; 375 } 376 377 void CFile::processEnabledFields(void) 378 { 379 for (unsigned int i = 0; i < this->enabledFields.size(); i++) 380 { 381 this->enabledFields[i]->processEnabledField() ; 382 } 383 } 384 368 385 void CFile::solveFieldRefInheritance(bool apply) 369 386 { … … 389 406 this->enabledFields[i]->solveOperation(); 390 407 } 391 392 //--------------------------------------------------------------- 393 /* 394 void CFile::toBinary (StdOStream & os) const 395 { 396 ENodeType genum = CFileGroup::GetType(); 397 bool hasVFG = (this->getVirtualFieldGroup() != NULL); 398 SuperClass::toBinary(os); 399 400 os.write (reinterpret_cast<const char*>(&genum) , sizeof(ENodeType)); 401 os.write (reinterpret_cast<const char*>(&hasVFG) , sizeof(bool)); 402 403 if (hasVFG)this->getVirtualFieldGroup()->toBinary(os); 404 405 } 406 407 //---------------------------------------------------------------- 408 409 void CFile::fromBinary(StdIStream & is) 410 { 411 ENodeType renum = Unknown; 412 bool hasVFG = false; 413 SuperClass::fromBinary(is); 414 415 is.read (reinterpret_cast<char*>(&renum), sizeof(ENodeType)); 416 is.read (reinterpret_cast<char*>(&hasVFG), sizeof(bool)); 417 418 if (renum != CFileGroup::GetType()) 419 ERROR("CFile::fromBinary(StdIStream & is)", 420 << "[ renum = " << renum << "] Bad type !"); 421 422 // this->setVirtualFieldGroup(this->getId()); 423 if (hasVFG)this->getVirtualFieldGroup()->fromBinary(is); 424 425 } 426 */ 408 409 void CFile::solveEFExpression(void) 410 { 411 for (unsigned int i = 0; i < this->enabledFields.size(); i++) 412 this->enabledFields[i]->buildExpression(); 413 } 414 427 415 428 416 CField* CFile::addField(const string& id) -
XIOS/trunk/src/node/file.hpp
r445 r459 68 68 void setVirtualFieldGroup(CFieldGroup* newVFieldGroup); 69 69 void setVirtualFieldGroup(void); 70 70 void processEnabledFile(void) ; 71 void processEnabledFields(void) ; 71 72 void createHeader(void); 72 73 void close(void) ; … … 77 78 void solveEFGridRef(void); 78 79 void solveEFOperation(void); 80 void solveEFExpression(void); 79 81 80 82 /// Destructeur /// -
XIOS/trunk/src/node/variable.hpp
r369 r459 5 5 #include "xmlioserver_spl.hpp" 6 6 #include "declare_group.hpp" 7 8 #include " data_output.hpp"7 #include "group_template.hpp" 8 #include "array_new.hpp" 9 9 10 10 namespace xios
Note: See TracChangeset
for help on using the changeset viewer.