Changeset 1000 for XIOS/trunk/src


Ignore:
Timestamp:
11/22/16 16:31:11 (7 years ago)
Author:
rlacroix
Message:

Fix handling of arithmetic expression for fields without a field_ref after r998.

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

Legend:

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

    r998 r1000  
    768768   { 
    769769     if (!areAllReferenceSolved) solveAllReferenceEnabledField(false); 
     770 
    770771     // Start by building a filter which can provide the field's instant data 
    771772     if (!instantDataFilter) 
    772773     { 
    773         boost::shared_ptr<COutputPin> arithmDataFilter; 
    774     
    775774       // Check if we have an expression to parse 
    776        if (hasExpression() || !field_ref.isEmpty()) 
    777        { 
    778          if (hasExpression()) 
     775       if (hasExpression()) 
     776       { 
     777         boost::scoped_ptr<IFilterExprNode> expr(parseExpr(getExpression() + '\0')); 
     778         boost::shared_ptr<COutputPin> filter = expr->reduce(gc, *this); 
     779 
     780         // Check if a spatial transformation is needed 
     781         if (!field_ref.isEmpty()) 
    779782         { 
    780            boost::scoped_ptr<IFilterExprNode> expr(parseExpr(getExpression() + '\0')); 
    781            arithmDataFilter = expr->reduce(gc, *this); 
     783           CGrid* gridRef = CField::get(field_ref)->grid; 
     784 
     785           if (grid && grid != gridRef && grid->hasTransform()) 
     786           { 
     787             double defaultValue = !default_value.isEmpty() ? default_value : 0.0; 
     788             std::pair<boost::shared_ptr<CFilter>, boost::shared_ptr<CFilter> > filters = CSpatialTransformFilter::buildFilterGraph(gc, gridRef, grid, defaultValue); 
     789 
     790             filter->connectOutput(filters.first, 0); 
     791             filter = filters.second; 
     792           } 
    782793         } 
    783          // Check if we have a reference on another field 
    784          if (!field_ref.isEmpty()) instantDataFilter = getFieldReference(gc,arithmDataFilter); 
    785        }   
     794 
     795         instantDataFilter = filter; 
     796       } 
     797       // Check if we have a reference on another field 
     798       else if (!field_ref.isEmpty()) 
     799         instantDataFilter = getFieldReference(gc); 
    786800       // Check if the data is to be read from a file 
    787801       else if (file && !file->mode.isEmpty() && file->mode == CFile::mode_attr::read) 
     
    816830    * \return the output pin corresponding to the field reference 
    817831    */ 
    818    boost::shared_ptr<COutputPin> CField::getFieldReference(CGarbageCollector& gc, boost::shared_ptr<COutputPin> OutputPin) 
     832   boost::shared_ptr<COutputPin> CField::getFieldReference(CGarbageCollector& gc) 
    819833   { 
    820834     if (instantDataFilter || field_ref.isEmpty()) 
     
    823837 
    824838     CField* fieldRef = CField::get(field_ref); 
    825      if (!OutputPin) fieldRef->buildFilterGraph(gc, false); 
     839     fieldRef->buildFilterGraph(gc, false); 
    826840 
    827841     std::pair<boost::shared_ptr<CFilter>, boost::shared_ptr<CFilter> > filters; 
     
    829843     if (grid && grid != fieldRef->grid && grid->hasTransform()) 
    830844     { 
    831        double defaultValue = 0.0; 
    832        if (!default_value.isEmpty()) defaultValue = this->default_value; 
     845       double defaultValue = !default_value.isEmpty() ? default_value : 0.0; 
    833846       filters = CSpatialTransformFilter::buildFilterGraph(gc, fieldRef->grid, grid, defaultValue); 
    834847     } 
    835  
    836848     else 
    837849       filters.first = filters.second = boost::shared_ptr<CFilter>(new CPassThroughFilter(gc)); 
    838850 
    839      if (!OutputPin)   fieldRef->getInstantDataFilter()->connectOutput(filters.first, 0); 
    840      else OutputPin->connectOutput(filters.first, 0); 
     851     fieldRef->getInstantDataFilter()->connectOutput(filters.first, 0); 
    841852 
    842853     return filters.second; 
     
    854865   boost::shared_ptr<COutputPin> CField::getSelfReference(CGarbageCollector& gc) 
    855866   { 
    856      if (instantDataFilter || ! hasExpression()) 
     867     if (instantDataFilter || !hasExpression()) 
    857868       ERROR("COutputPin* CField::getSelfReference(CGarbageCollector& gc)", 
    858869             "Impossible to add a self reference to a field which has already been parsed or which does not have an expression."); 
     
    926937  /*! 
    927938    * Returns the temporal filter corresponding to the field's temporal operation 
    928     * for the specified operation frequency. The filter is created if it does not 
    929     * exist, otherwise it is reused. 
     939    * for the specified operation frequency. 
    930940    * 
    931941    * \param gc the garbage collector to use 
     
    936946   boost::shared_ptr<COutputPin> CField::getSelfTemporalDataFilter(CGarbageCollector& gc, CDuration outFreq) 
    937947   { 
    938       
    939948     if (instantDataFilter || !hasExpression()) 
    940949       ERROR("COutputPin* CField::getSelfTemporalDataFilter(CGarbageCollector& gc)", 
     
    968977     } 
    969978  } 
    970  
    971  
    972 /* 
    973    boost::shared_ptr<COutputPin> CField::getSelfTemporalDataFilter(CGarbageCollector& gc, CDuration outFreq) 
    974    { 
    975  
    976        if (file && !file->mode.isEmpty() && file->mode == CFile::mode_attr::read) 
    977        { 
    978          if (!serverSourceFilter) 
    979            serverSourceFilter = boost::shared_ptr<CSourceFilter>(new CSourceFilter(grid, 
    980                                                                                    freq_offset.isEmpty() ? NoneDu : freq_offset)); 
    981  
    982          selfReferenceFilter = serverSourceFilter; 
    983        } 
    984        else if (!field_ref.isEmpty()) 
    985        {    
    986           CField* fieldRef = CField::get(field_ref); 
    987           fieldRef->buildFilterGraph(gc, false); 
    988           return fieldRef->getTemporalDataFilter(CGarbageCollector& gc, CDuration outFreq) ; 
    989        } 
    990    
    991     } 
    992  
    993 */ 
    994979 
    995980   //---------------------------------------------------------------- 
     
    14251410    * \return if content is defined return content string, otherwise, if "expr" attribute is defined, return expr string. 
    14261411    */ 
    1427    string CField::getExpression(void) 
    1428    { 
    1429      if (! expr.isEmpty() && content.empty()) 
    1430      { 
    1431        content=expr ; 
    1432        expr.reset() ; 
    1433      } 
     1412   const string& CField::getExpression(void) 
     1413   { 
     1414     if (!expr.isEmpty() && content.empty()) 
     1415     { 
     1416       content = expr; 
     1417       expr.reset(); 
     1418     } 
     1419 
    14341420     return content; 
    14351421   } 
    1436     
    1437    bool CField::hasExpression(void) 
    1438    { 
    1439      if (! expr.isEmpty()) return true ; 
    1440      if (!content.empty()) return true ; 
    1441      return false; 
    1442    }    
     1422 
     1423   bool CField::hasExpression(void) const 
     1424   { 
     1425     return (!expr.isEmpty() || !content.empty()); 
     1426   } 
     1427 
    14431428   DEFINE_REF_FUNC(Field,field) 
    14441429} // namespace xios 
  • XIOS/trunk/src/node/field.hpp

    r998 r1000  
    121121 
    122122         void buildFilterGraph(CGarbageCollector& gc, bool enableOutput); 
    123          boost::shared_ptr<COutputPin> getFieldReference(CGarbageCollector& gc, boost::shared_ptr<COutputPin> OutputPin = boost::shared_ptr<COutputPin>()); 
     123         boost::shared_ptr<COutputPin> getFieldReference(CGarbageCollector& gc); 
    124124         boost::shared_ptr<COutputPin> getSelfReference(CGarbageCollector& gc); 
    125125         boost::shared_ptr<COutputPin> getTemporalDataFilter(CGarbageCollector& gc, CDuration outFreq); 
     
    178178 
    179179        const std::vector<StdString>& getRefDomainAxisIds(); 
    180         string getExpression(void) ; 
    181         bool hasExpression(void) ; 
     180 
     181        const string& getExpression(void); 
     182        bool hasExpression(void) const; 
    182183 
    183184      public: 
Note: See TracChangeset for help on using the changeset viewer.