Changeset 2280


Ignore:
Timestamp:
01/07/22 12:17:18 (2 years ago)
Author:
ymipsl
Message:

Improve file reading reading

  • add_offset and scaling_factor attributes are set when present in reading file
  • Add new attribute for axis to scale axis_value when read from file : convert_from_factor
  • fix bugs when time dimension in reading file is not unlimited

YM

Location:
XIOS/trunk/src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • XIOS/trunk/src/config/axis_attribute.conf

    r1493 r2280  
    66 
    77DECLARE_ATTRIBUTE(StdString, unit) 
     8DECLARE_ATTRIBUTE(double, convert_from_factor) 
    89DECLARE_ATTRIBUTE(StdString, formula) 
    910DECLARE_ATTRIBUTE(StdString, formula_term) 
  • XIOS/trunk/src/io/inetcdf4.cpp

    r1639 r2280  
    2828 
    2929    this->timeCounterName = timeCounterName; 
     30 
    3031    if (!CNetCdfInterface::isDimExisted(this->ncidp, this->timeCounterName)) this->timeCounterName=this->getUnlimitedDimensionName() ; 
    3132 
     
    8788    CNetCdfInterface::inqAtt(grpid, varid, attname, retvalue.first, retvalue.second); 
    8889    return retvalue; 
     90  } 
     91 
     92   
     93  bool CINetCDF4::hasUnlimitedDimension(const CVarPath* const path) 
     94  { 
     95    int dimid = 0; 
     96    int grpid = this->getGroup(path); 
     97    CNetCdfInterface::inqUnLimDim(grpid, dimid); 
     98    if (dimid==-1) return false ; 
     99    else return true ; 
    89100  } 
    90101 
     
    174185  } 
    175186 
    176   StdSize CINetCDF4::getNbOfTimestep(const CVarPath* const path) 
    177   { 
    178     return this->getDimensions(NULL, path)[this->getUnlimitedDimensionName(path)]; 
    179   } 
    180  
    181187  std::set<StdString> CINetCDF4::getBoundVariables(const CVarPath* const path) 
    182188  { 
     
    337343    return false; 
    338344  } 
     345 
     346  template <class T> 
     347  bool CINetCDF4::hasAttribute(const StdString& name, const StdString* const var, const CVarPath* const path) 
     348  { 
     349    std::list<StdString> atts = this->getAttributes(var, path); 
     350    std::list<StdString>::const_iterator it = atts.begin(), end = atts.end(); 
     351    for (; it != end; it++) 
     352    { 
     353      const StdString& attname = *it; 
     354      if (attname.compare(0, name.size(), name) == 0) 
     355      {  
     356        std::pair<nc_type , StdSize> attinfos = this->getAttribute(name, var, path); 
     357        std::vector<T> retvalue(attinfos.second); 
     358        nc_type type = CNetCdfInterface::getNcType<T>(); 
     359        if (attinfos.first == type) return true; 
     360        else return false ; 
     361      } 
     362    } 
     363    return false; 
     364  } 
     365   
     366  template bool  CINetCDF4::hasAttribute<double>(const StdString& name, const StdString* const var, const CVarPath* const path); 
     367  template bool  CINetCDF4::hasAttribute<float>(const StdString& name, const StdString* const var, const CVarPath* const path); 
     368  template bool  CINetCDF4::hasAttribute<int>(const StdString& name, const StdString* const var, const CVarPath* const path); 
     369  template bool  CINetCDF4::hasAttribute<char>(const StdString& name, const StdString* const var, const CVarPath* const path); 
     370   
    339371 
    340372  bool CINetCDF4::hasVariable(const StdString& name, 
  • XIOS/trunk/src/io/inetcdf4.hpp

    r1639 r2280  
    4040 
    4141      /// Getters /// 
    42       StdSize getNbOfTimestep(const CVarPath* const path = NULL); 
    4342 
    4443      StdString getUnlimitedDimensionName(const CVarPath* const path = NULL); 
     
    112111      /// Tests /// 
    113112      bool hasMissingValue(const StdString& name, const CVarPath* const path = NULL); 
    114  
     113      bool hasAttribute(const StdString& name, const StdString* const var  = NULL, const CVarPath* const path = NULL); 
     114       
     115      template <class T> 
    115116      bool hasAttribute(const StdString& name, const StdString* const var  = NULL, const CVarPath* const path = NULL); 
    116117 
     
    144145      int getDimension(const StdString& dimname, const CVarPath* const path = NULL); 
    145146      int getUnlimitedDimension(const CVarPath* const path = NULL); 
     147      bool hasUnlimitedDimension(const CVarPath* const path = NULL); 
     148 
    146149      int getAttributeId(const StdString& name, 
    147150                         const StdString* const var = NULL, 
  • XIOS/trunk/src/io/nc4_data_input.cpp

    r1639 r2280  
    3535    if (SuperClassWriter::isTemporal(fieldId)) 
    3636    { 
    37 //      return SuperClassWriter::getDimensions(&fieldId)[SuperClassWriter::getUnlimitedDimensionName()]; 
    3837      return SuperClassWriter::getDimensions(&fieldId)[SuperClassWriter::getTimeCounterName()]; 
    3938    } 
     
    159158    if (SuperClassWriter::isTemporal(fieldId)) 
    160159    { 
    161       dimSizeMap.erase(SuperClassWriter::getUnlimitedDimensionName()); 
     160      dimSizeMap.erase(SuperClassWriter::getTimeCounterName()); 
    162161      dimList.pop_front() ;  // assume time dimension is first 
    163162    } 
     
    195194        listDimSize.push_front(*dimSizeMap.find(*it)); 
    196195    } 
     196     
     197    // read specific field attribute 
     198    if (field->add_offset.isEmpty()) 
     199    { 
     200      if (SuperClassWriter::hasAttribute<float>("add_offset",&fieldId))  
     201        field->add_offset =  SuperClassWriter::getAttributeValue<float>("add_offset",&fieldId)[0] ; 
     202      else if (SuperClassWriter::hasAttribute<double>("add_offset",&fieldId)) 
     203        field->add_offset =  SuperClassWriter::getAttributeValue<double>("add_offset",&fieldId)[0] ; 
     204    } 
     205 
     206    if (field->scale_factor.isEmpty()) 
     207    { 
     208      if (SuperClassWriter::hasAttribute<float>("scale_factor",&fieldId))  
     209        field->scale_factor =  SuperClassWriter::getAttributeValue<float>("scale_factor",&fieldId)[0] ; 
     210      else if (SuperClassWriter::hasAttribute<double>("scale_factor",&fieldId)) 
     211        field->scale_factor =  SuperClassWriter::getAttributeValue<double>("scale_factor",&fieldId)[0] ; 
     212    } 
    197213 
    198214    // Now process domain and axis 
     
    579595        if (!axis->n.isEmpty()) n = axis->n.getValue(); 
    580596        axis->value.resize(n); 
    581         for (int i = 0; i < n; ++i) axis->value(i) = readAxisValue(begin + i); 
     597        double convertFromFactor=1.0 ; 
     598        if (!axis->convert_from_factor.isEmpty()) convertFromFactor = axis->convert_from_factor ; 
     599        for (int i = 0; i < n; ++i) axis->value(i) = readAxisValue(begin + i)*convertFromFactor; 
    582600      } 
    583601    } 
Note: See TracChangeset for help on using the changeset viewer.