Changeset 459


Ignore:
Timestamp:
01/16/14 14:28:23 (10 years ago)
Author:
ymipsl
Message:

Add new parsing expression functionnalities
(modified files)

YM

Location:
XIOS/trunk/src/node
Files:
8 edited

Legend:

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

    r445 r459  
    175175   } 
    176176    
    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 
    217178   //---------------------------------------------------------------- 
    218179 
     
    337298      this->findEnabledFiles(); 
    338299 
     300         
     301      this->processEnabledFiles() ; 
     302 
     303/*         
    339304      //Recherche des champs à sortir (enable à true + niveau de sortie correct) 
    340305      // pour chaque fichier précédemment listé. 
     
    347312      this->solveAllOperation(); 
    348313 
     314      // Traitement des expressions. 
     315      this->solveAllExpression(); 
     316*/ 
    349317      // Nettoyage de l'arborescence 
    350318      CleanTree(); 
     
    357325     (void)this->enabledFiles[i]->getEnabledFields(); 
    358326   } 
     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   
    359334 
    360335   void CContext::solveAllGridRef(void) 
     
    370345   } 
    371346 
     347   void CContext::solveAllExpression(void) 
     348   { 
     349      for (unsigned int i = 0; i < this->enabledFiles.size(); i++) 
     350      this->enabledFiles[i]->solveEFExpression(); 
     351   } 
     352    
    372353   void CContext::solveAllInheritance(bool apply) 
    373354   { 
  • XIOS/trunk/src/node/context.hpp

    r445 r459  
    110110         void closeDefinition(void) ; 
    111111         void findAllEnabledFields(void); 
     112         void processEnabledFiles(void) ; 
    112113         void solveAllGridRef(void); 
    113114         void solveAllOperation(void); 
     115         void solveAllExpression(void); 
    114116         void solveAllInheritance(bool apply=true) ; 
    115117         void findEnabledFiles(void); 
  • XIOS/trunk/src/node/field.cpp

    r449 r459  
    1111#include "type.hpp" 
    1212#include "context_client.hpp" 
     13#include <set> 
    1314 
    1415namespace xios{ 
     
    2324      , nstep(0) 
    2425      , last_Write(), last_operation() 
    25       , foperation() 
     26      , foperation(), hasInstantData(false), hasExpression(false) 
     27      , active(false) , hasOutputFile(false), slotUpdateDate(NULL) 
     28      , processed(false) 
    2629      { /* Ne rien faire de plus */ } 
    2730 
     
    3336      , nstep(0) 
    3437      , last_Write(), last_operation() 
    35       , foperation() 
     38      , foperation(), hasExpression(false) 
     39      , active(false), hasOutputFile(false), slotUpdateDate(NULL) 
     40      , processed(false) 
    3641   { /* Ne rien faire de plus */ } 
    3742 
     
    4146//      this->file.reset() ; 
    4247      this->foperation.reset() ; 
     48      if (hasExpression) delete expression ; 
     49      if (slotUpdateDate!=NULL) delete slotUpdateDate ; 
     50         
    4351   } 
    4452 
     
    199207   void CField::setRelFile(CFile* _file) 
    200208   {  
    201       this->file = _file;  
     209      this->file = _file; 
     210      hasOutputFile=true ;  
    202211   } 
    203212 
     
    327336   //---------------------------------------------------------------- 
    328337 
     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     
    329353   void CField::solveRefInheritance(bool apply) 
    330354   { 
     
    333357      CField * refer_ptr = this; 
    334358       
    335       this->baseRefObject = CField::get(this); 
     359      if (this->hasDirectFieldReference())  baseRefObject = getDirectFieldReference(); 
     360      else  baseRefObject = CField::get(this); 
    336361       
    337362      while (refer_ptr->hasDirectFieldReference()) 
     
    349374         SuperClassAttribute::setAttributes(refer_ptr, apply); 
    350375         sset.insert(refer_ptr); 
    351          baseRefObject = refer_sptr; 
     376//ym         baseRefObject = refer_sptr; 
    352377//ym         refObject.push_back(refer_sptr); 
    353378      } 
     379       
     380      if (hasDirectFieldReference()) baseRefObject->addReference(this) ; 
    354381   } 
    355382 
     
    359386   { 
    360387      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       
    363396      CContext* context = CContext::getCurrent(); 
    364397       
    365398      if (freq_op.isEmpty()) freq_op=string("1ts") ; 
    366399       
    367       if (operation.isEmpty()  || this->file->output_freq.isEmpty()) 
     400      if (operation.isEmpty() ) 
    368401      { 
    369402         ERROR("CField::solveOperation(void)", 
     
    548581 
    549582     grid->solveReference() ; 
     583 
    550584   } 
    551585 
     
    598632   ///------------------------------------------------------------------- 
    599633 
     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   
    600723} // namespace xios 
  • XIOS/trunk/src/node/field.hpp

    r445 r459  
    1313#include "array_new.hpp" 
    1414#include "attribute_array.hpp" 
     15#include "expr_node.hpp" 
    1516//#include "context.hpp" 
    1617 
     
    6566         CField* getDirectFieldReference(void) const; 
    6667         CField* getBaseFieldReference(void)   const; 
     68         void addReference(CField* field) ; 
    6769         const std::vector<CField*> & getAllReference(void) const; 
    6870 
     
    9294 
    9395         template <int N> bool updateData(const CArray<double, N>&   data); 
     96         bool updateDataFromExpression(const CArray<double, 1>&   data); 
    9497          
    9598         bool updateDataServer 
     
    102105         bool hasDirectFieldReference(void) const; 
    103106         bool isActive(void) const; 
     107         bool active ; 
     108         bool hasOutputFile ; 
    104109 
    105110         /// Traitements /// 
     111         void processEnabledField(void) ; 
    106112         void solveRefInheritance(bool apply); 
    107113         void solveGridReference(void); 
     
    127133        void outputField(CArray<double,3>& fieldOut) ; 
    128134        void outputField(CArray<double,2>& fieldOut) ; 
    129          
     135        void parse(xml::CXMLNode & node) ; 
     136        CArray<double,1>* getInstantData(void)  ; 
    130137      public : 
    131138 
     
    148155          
    149156         CArray<double, 1> data; 
     157         CArray<double, 1> instantData; 
     158         bool hasInstantData ; 
    150159         map<int, CArray<double,1>* > data_srv ; 
    151160         bool isOnceOperation ; 
    152161         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 ; 
    153175 
    154176   }; // class CField 
  • XIOS/trunk/src/node/field_impl.hpp

    r436 r459  
    1313namespace xios { 
    1414 
    15    template <int N> 
    16    void CField::setData(const CArray<double, N>& _data) 
    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) ; 
    2222    } 
    2323     
     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 
    2436   template <int N> 
    25       bool CField::updateData(const CArray<double, N>& _data) 
     37   bool CField::updateData(const CArray<double, N>& _data) 
    2638   {         
    2739      CContext* context=CContext::getCurrent(); 
    2840      const CDate & currDate = context->getCalendar()->getCurrentDate(); 
    2941      const CDate opeDate      = *last_operation + freq_operation; 
    30       const CDate writeDate    = *last_Write     + freq_write; 
     42      const CDate writeDate    = *last_Write     + freq_write;        
    3143      bool doOperation, doWrite;  
    32           
    3344 
    3445    
    3546      info(50) << "CField::updateData " << currDate <<  " : send data to " << this->getBaseFieldId() << std::endl; 
    3647      info(50) << "Next operation "  << opeDate<<std::endl; 
    37        
     48 
    3849      doOperation = (opeDate <= currDate) ; 
    3950      if (isOnceOperation) 
    4051        if (isFirstOperation) doOperation=true ; 
    4152        else doOperation=false ; 
    42        
     53 
    4354      if (doOperation) 
    4455      { 
     
    5566         info(50) << "(*last_operation = currDate) : " << *last_operation << " = " << currDate << std::endl;  
    5667      } 
     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      } 
    5779       
    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 
    59124      doWrite = (writeDate < (currDate + freq_operation)) ; 
    60125      if (isOnceOperation) 
  • XIOS/trunk/src/node/file.cpp

    r451 r459  
    102102         newEnabledFields.push_back(*it) ; 
    103103         // Le champ est finalement actif, on y ajoute sa propre reference. 
    104          (*it)->refObject.push_back(*it); 
     104//         (*it)->refObject.push_back(*it); 
    105105         // Le champ est finalement actif, on y ajoute la référence au champ de base. 
    106106         (*it)->setRelFile(CFile::get(this)); 
    107          (*it)->baseRefObject->refObject.push_back(*it); 
     107//         (*it)->baseRefObject->refObject.push_back(*it); 
    108108         // A faire, ajouter les references intermediaires... 
    109109      } 
     
    366366   //---------------------------------------------------------------- 
    367367 
     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     
    368385   void CFile::solveFieldRefInheritance(bool apply) 
    369386   { 
     
    389406         this->enabledFields[i]->solveOperation(); 
    390407   } 
    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  
    427415 
    428416   CField* CFile::addField(const string& id) 
  • XIOS/trunk/src/node/file.hpp

    r445 r459  
    6868         void setVirtualFieldGroup(CFieldGroup* newVFieldGroup); 
    6969         void setVirtualFieldGroup(void); 
    70  
     70         void processEnabledFile(void) ; 
     71         void processEnabledFields(void) ; 
    7172         void createHeader(void); 
    7273         void close(void) ; 
     
    7778         void solveEFGridRef(void); 
    7879         void solveEFOperation(void); 
     80         void solveEFExpression(void); 
    7981 
    8082         /// Destructeur /// 
  • XIOS/trunk/src/node/variable.hpp

    r369 r459  
    55#include "xmlioserver_spl.hpp" 
    66#include "declare_group.hpp" 
    7  
    8 #include "data_output.hpp" 
     7#include "group_template.hpp" 
     8#include "array_new.hpp" 
    99 
    1010namespace xios 
Note: See TracChangeset for help on using the changeset viewer.