Ignore:
Timestamp:
02/03/14 14:16:20 (10 years ago)
Author:
ymipsl
Message:

Enhancement : user defined global and field attribute can be output in the netcdfcf file.
A variable child element inclosed into a file element will be output as a global file attribute.
A variable child element inclosed into a field element will be output as a field attribute.

+ variable fortran interface added

YM

File:
1 edited

Legend:

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

    r459 r472  
    2424      : CObjectTemplate<CFile>(), CFileAttributes() 
    2525      , vFieldGroup(), data_out(), enabledFields(), fileComm(MPI_COMM_NULL) 
    26    { setVirtualFieldGroup() ;} 
     26   {  
     27     setVirtualFieldGroup() ; 
     28     setVirtualVariableGroup() ; 
     29   } 
    2730 
    2831   CFile::CFile(const StdString & id) 
    2932      : CObjectTemplate<CFile>(id), CFileAttributes() 
    3033      , vFieldGroup(), data_out(), enabledFields(), fileComm(MPI_COMM_NULL) 
    31    { setVirtualFieldGroup() ;} 
     34    {  
     35      setVirtualFieldGroup() ; 
     36      setVirtualVariableGroup() ; 
     37    } 
    3238 
    3339   CFile::~CFile(void) 
     
    5258   } 
    5359 
     60   CVariableGroup* CFile::getVirtualVariableGroup(void) const 
     61   { 
     62      return (this->vVariableGroup); 
     63   } 
     64 
    5465   std::vector<CField*> CFile::getAllFields(void) const 
    5566   { 
    5667      return (this->vFieldGroup->getAllChildren()); 
     68   } 
     69  
     70   std::vector<CVariable*> CFile::getAllVariables(void) const 
     71   { 
     72      return (this->vVariableGroup->getAllChildren()); 
    5773   } 
    5874 
     
    120136   } 
    121137 
     138   void CFile::setVirtualVariableGroup(CVariableGroup* newVVariableGroup) 
     139   {  
     140      this->vVariableGroup = newVVariableGroup;  
     141   } 
     142 
    122143   //---------------------------------------------------------------- 
    123144 
     
    125146   { 
    126147      this->setVirtualFieldGroup(CFieldGroup::create()); 
     148   } 
     149 
     150   void CFile::setVirtualVariableGroup(void) 
     151   { 
     152      this->setVirtualVariableGroup(CVariableGroup::create()); 
    127153   } 
    128154 
     
    313339         } 
    314340          
     341         vector<CVariable*> listVars = getAllVariables() ; 
     342         for (vector<CVariable*>::iterator it = listVars.begin() ;it != listVars.end(); it++) this-> data_out-> writeAttribute(*it) ; 
     343          
    315344         this->data_out->definition_end(); 
    316345      } 
     
    333362   { 
    334363      SuperClass::parse(node); 
    335       if (node.goToChildElement() & this->hasId()) 
    336       { // Si la définition du fichier intégre des champs et si le fichier est identifié. 
    337          node.goToParentElement(); 
    338 //         this->setVirtualFieldGroup(this->getId()); 
    339          this->getVirtualFieldGroup()->parse(node, false); 
    340       } 
     364       
     365      if (node.goToChildElement()) 
     366      { 
     367        do 
     368        { 
     369           if (node.getElementName()=="field" || node.getElementName()=="field_group") this->getVirtualFieldGroup()->parseChild(node); 
     370           else if (node.getElementName()=="variable" || node.getElementName()=="variable_group") this->getVirtualVariableGroup()->parseChild(node); 
     371        } while (node.goToNextElement()) ; 
     372        node.goToParentElement(); 
     373      } 
     374 
    341375   } 
    342376   //---------------------------------------------------------------- 
     
    361395   { 
    362396      SuperClassAttribute::setAttributes(parent,apply); 
    363       this->getVirtualFieldGroup()->solveDescInheritance(apply, NULL); 
     397      this->getVirtualFieldGroup()->solveDescInheritance(apply, NULL);  
     398      this->getVirtualVariableGroup()->solveDescInheritance(apply, NULL); 
    364399   } 
    365400 
     
    422457   { 
    423458     return vFieldGroup->createChildGroup(id) ; 
     459   } 
     460  
     461   CVariable* CFile::addVariable(const string& id) 
     462   { 
     463     return vVariableGroup->createChild(id) ; 
     464   } 
     465 
     466   CVariableGroup* CFile::addVariableGroup(const string& id) 
     467   { 
     468     return vVariableGroup->createChildGroup(id) ; 
    424469   } 
    425470    
     
    502547   } 
    503548    
     549 
     550 
     551 
     552 
     553 
     554 
     555 
     556 
     557 
     558 
     559   void CFile::sendAddVariable(const string& id) 
     560   { 
     561    CContext* context=CContext::getCurrent() ; 
     562     
     563    if (! context->hasServer ) 
     564    { 
     565       CContextClient* client=context->client ; 
     566 
     567       CEventClient event(this->getType(),EVENT_ID_ADD_VARIABLE) ;    
     568       if (client->isServerLeader()) 
     569       { 
     570         CMessage msg ; 
     571         msg<<this->getId() ; 
     572         msg<<id ; 
     573         event.push(client->getServerLeader(),1,msg) ; 
     574         client->sendEvent(event) ; 
     575       } 
     576       else client->sendEvent(event) ; 
     577    } 
     578       
     579   } 
     580    
     581   void CFile::sendAddVariableGroup(const string& id) 
     582   { 
     583    CContext* context=CContext::getCurrent() ; 
     584    if (! context->hasServer ) 
     585    { 
     586       CContextClient* client=context->client ; 
     587 
     588       CEventClient event(this->getType(),EVENT_ID_ADD_VARIABLE_GROUP) ;    
     589       if (client->isServerLeader()) 
     590       { 
     591         CMessage msg ; 
     592         msg<<this->getId() ; 
     593         msg<<id ; 
     594         event.push(client->getServerLeader(),1,msg) ; 
     595         client->sendEvent(event) ; 
     596       } 
     597       else client->sendEvent(event) ; 
     598    } 
     599       
     600   } 
     601    
     602   void CFile::recvAddVariable(CEventServer& event) 
     603   { 
     604       
     605      CBufferIn* buffer=event.subEvents.begin()->buffer; 
     606      string id; 
     607      *buffer>>id ; 
     608      get(id)->recvAddVariable(*buffer) ; 
     609   } 
     610    
     611    
     612   void CFile::recvAddVariable(CBufferIn& buffer) 
     613   { 
     614      string id ; 
     615      buffer>>id ; 
     616      addVariable(id) ; 
     617   } 
     618 
     619   void CFile::recvAddVariableGroup(CEventServer& event) 
     620   { 
     621       
     622      CBufferIn* buffer=event.subEvents.begin()->buffer; 
     623      string id; 
     624      *buffer>>id ; 
     625      get(id)->recvAddVariableGroup(*buffer) ; 
     626   } 
     627    
     628    
     629   void CFile::recvAddVariableGroup(CBufferIn& buffer) 
     630   { 
     631      string id ; 
     632      buffer>>id ; 
     633      addVariableGroup(id) ; 
     634   } 
     635 
     636 
     637 
     638 
    504639 
    505640   bool CFile::dispatchEvent(CEventServer& event) 
     
    519654             return true ; 
    520655             break ;        
     656  
     657            case EVENT_ID_ADD_VARIABLE : 
     658             recvAddVariable(event) ; 
     659             return true ; 
     660             break ; 
    521661          
     662           case EVENT_ID_ADD_VARIABLE_GROUP : 
     663             recvAddVariableGroup(event) ; 
     664             return true ; 
     665             break ;                
    522666           default : 
    523667              ERROR("bool CFile::dispatchEvent(CEventServer& event)", <<"Unknown Event") ; 
Note: See TracChangeset for help on using the changeset viewer.