Changeset 2631


Ignore:
Timestamp:
05/29/24 19:16:58 (5 weeks ago)
Author:
ymipsl
Message:

Back port of XIOS2/trunk, rev.2280 :
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:
XIOS3/trunk/src
Files:
4 edited

Legend:

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

    r2479 r2631  
    66 
    77DECLARE_ATTRIBUTE(StdString, unit) 
     8DECLARE_ATTRIBUTE(double, convert_from_factor)  
    89DECLARE_ATTRIBUTE(StdString, formula) 
    910DECLARE_ATTRIBUTE(StdString, formula_term) 
  • XIOS3/trunk/src/io/inetcdf4.cpp

    r2629 r2631  
    8989  } 
    9090 
     91  bool CINetCDF4::hasUnlimitedDimension(const CVarPath* const path)  
     92  {  
     93    int dimid = 0;  
     94    int grpid = this->getGroup(path);  
     95    CNetCdfInterface::inqUnLimDim(grpid, dimid);  
     96    if (dimid==-1) return false ;  
     97    else return true ;  
     98  }  
     99   
    91100  int CINetCDF4::getUnlimitedDimension(const CVarPath* const path) 
    92101  { 
     
    174183  } 
    175184 
    176   StdSize CINetCDF4::getNbOfTimestep(const CVarPath* const path) 
    177   { 
    178     return this->getDimensions(NULL, path)[this->getUnlimitedDimensionName(path)]; 
    179   } 
    180  
    181185  std::set<StdString> CINetCDF4::getBoundVariables(const CVarPath* const path) 
    182186  { 
     
    337341    return false; 
    338342  } 
     343 
     344  
     345  template <class T>  
     346  bool CINetCDF4::hasAttribute(const StdString& name, const StdString* const var, const CVarPath* const path)  
     347  {  
     348    std::list<StdString> atts = this->getAttributes(var, path);  
     349    std::list<StdString>::const_iterator it = atts.begin(), end = atts.end();  
     350    for (; it != end; it++)  
     351    {  
     352      const StdString& attname = *it;  
     353      if (attname.compare(0, name.size(), name) == 0)  
     354      {   
     355        std::pair<nc_type , StdSize> attinfos = this->getAttribute(name, var, path);  
     356        std::vector<T> retvalue(attinfos.second);  
     357        nc_type type = CNetCdfInterface::getNcType<T>();  
     358        if (attinfos.first == type) return true;  
     359        else return false ;  
     360      }  
     361    }  
     362    return false;  
     363  }  
     364    
     365  template bool  CINetCDF4::hasAttribute<double>(const StdString& name, const StdString* const var, const CVarPath* const path);  
     366  template bool  CINetCDF4::hasAttribute<float>(const StdString& name, const StdString* const var, const CVarPath* const path);  
     367  template bool  CINetCDF4::hasAttribute<int>(const StdString& name, const StdString* const var, const CVarPath* const path);  
     368  template bool  CINetCDF4::hasAttribute<char>(const StdString& name, const StdString* const var, const CVarPath* const path);  
    339369 
    340370  bool CINetCDF4::hasVariable(const StdString& name, 
  • XIOS3/trunk/src/io/inetcdf4.hpp

    r1639 r2631  
    4040 
    4141      /// Getters /// 
    42       StdSize getNbOfTimestep(const CVarPath* const path = NULL); 
    4342 
    4443      StdString getUnlimitedDimensionName(const CVarPath* const path = NULL); 
     
    113112      bool hasMissingValue(const StdString& name, const CVarPath* const path = NULL); 
    114113 
     114      bool hasAttribute(const StdString& name, const StdString* const var  = NULL, const CVarPath* const path = NULL);  
     115         
     116      template <class T> 
    115117      bool hasAttribute(const StdString& name, const StdString* const var  = NULL, const CVarPath* const path = NULL); 
    116118 
     
    144146      int getDimension(const StdString& dimname, const CVarPath* const path = NULL); 
    145147      int getUnlimitedDimension(const CVarPath* const path = NULL); 
     148      bool hasUnlimitedDimension(const CVarPath* const path = NULL);  
    146149      int getAttributeId(const StdString& name, 
    147150                         const StdString* const var = NULL, 
  • XIOS3/trunk/src/io/nc4_data_input.cpp

    r2628 r2631  
    3636    if (SuperClassWriter::isTemporal(fieldId)) 
    3737    { 
    38 //      return SuperClassWriter::getDimensions(&fieldId)[SuperClassWriter::getUnlimitedDimensionName()]; 
    3938      return SuperClassWriter::getDimensions(&fieldId)[SuperClassWriter::getTimeCounterName()]; 
    4039    } 
     
    151150    if (SuperClassWriter::isTemporal(fieldId)) 
    152151    { 
    153       dimSizeMap.erase(SuperClassWriter::getUnlimitedDimensionName()); 
     152      dimSizeMap.erase(SuperClassWriter::getTimeCounterName());  
    154153      dimList.pop_front() ;  // assume time dimension is first 
    155154    } 
     
    187186        listDimSize.push_front(*dimSizeMap.find(*it)); 
    188187    } 
     188      
     189    // read specific field attribute  
     190    if (field->add_offset.isEmpty())  
     191    {  
     192      if (SuperClassWriter::hasAttribute<float>("add_offset",&fieldId))   
     193        field->add_offset =  SuperClassWriter::getAttributeValue<float>("add_offset",&fieldId)[0] ;  
     194      else if (SuperClassWriter::hasAttribute<double>("add_offset",&fieldId))  
     195        field->add_offset =  SuperClassWriter::getAttributeValue<double>("add_offset",&fieldId)[0] ;  
     196    }  
     197  
     198    if (field->scale_factor.isEmpty())  
     199    {  
     200      if (SuperClassWriter::hasAttribute<float>("scale_factor",&fieldId))   
     201        field->scale_factor =  SuperClassWriter::getAttributeValue<float>("scale_factor",&fieldId)[0] ;  
     202      else if (SuperClassWriter::hasAttribute<double>("scale_factor",&fieldId))  
     203        field->scale_factor =  SuperClassWriter::getAttributeValue<double>("scale_factor",&fieldId)[0] ;  
     204    }  
    189205 
    190206    // Now process domain and axis 
     
    571587        if (!axis->n.isEmpty()) n = axis->n.getValue(); 
    572588        axis->value.resize(n); 
    573         for (int i = 0; i < n; ++i) axis->value(i) = readAxisValue(begin + i); 
     589 
     590        double convertFromFactor=1.0 ;  
     591        if (!axis->convert_from_factor.isEmpty()) convertFromFactor = axis->convert_from_factor ;  
     592        for (int i = 0; i < n; ++i) axis->value(i) = readAxisValue(begin + i)*convertFromFactor;  
    574593      } 
    575594    } 
Note: See TracChangeset for help on using the changeset viewer.