Changeset 606 for XIOS/branchs


Ignore:
Timestamp:
06/03/15 15:06:25 (9 years ago)
Author:
rlacroix
Message:

Support NetCDF4 compression.

Only available for non-parallel output so either if only one server is used or if the multiple file mode is enabled).

Location:
XIOS/branchs/xios-1.0/src
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • XIOS/branchs/xios-1.0/src/config/field_attribute.conf

    r501 r606  
    2424DECLARE_ATTRIBUTE(double,    add_offset) 
    2525DECLARE_ATTRIBUTE(double,    scale_factor) 
     26 
     27DECLARE_ATTRIBUTE(int,       compression_level) 
  • XIOS/branchs/xios-1.0/src/config/file_attribute.conf

    r501 r606  
    1414DECLARE_ATTRIBUTE(StdString,      par_access) 
    1515 
    16 // DECLARE_ATTRIBUTE_DEF(bool, enabled, true) 
     16DECLARE_ATTRIBUTE(int,       compression_level) 
  • XIOS/branchs/xios-1.0/src/output/nc4_data_output.cpp

    r544 r606  
    736736              SuperClassWriter::setDefaultValue(fieldid, default_value); 
    737737           } 
     738 
     739           if (field->compression_level.isEmpty()) 
     740             field->compression_level = field->file->compression_level.isEmpty() ? 0 : field->file->compression_level; 
     741           if (field->compression_level < 0 || field->compression_level > 9) 
     742             ERROR("void CNc4DataOutput::writeField_(CField* field)", 
     743                   "Invalid compression level, the value should range between 0 and 9."); 
     744           SuperClassWriter::setCompressionLevel(fieldid, field->compression_level); 
    738745 
    739746           {  // Ecriture des coordonnées 
  • XIOS/branchs/xios-1.0/src/output/netCdfInterface.cpp

    r578 r606  
    525525 
    526526/*! 
     527This function sets the compression level to the specified variable 
     528\param [in] ncid Groud id (or file id) 
     529\param [in] varId Id of the variable 
     530\param [in] compressionLevel The compression level from 0 to 9 (0 disables the compression, 9 is the higher compression) 
     531\return Status code 
     532*/ 
     533int CNetCdfInterface::defVarDeflate(int ncid, int varId, int compressionLevel) 
     534{ 
     535  int status = nc_def_var_deflate(ncid, varId, false, (compressionLevel > 0), compressionLevel); 
     536  if (NC_NOERR != status) 
     537  { 
     538    StdString errormsg(nc_strerror(status)); 
     539    StdStringStream sstr; 
     540 
     541    sstr << "Error in calling function " << "nc_def_var_deflate(ncid, varId, false, (compressionLevel > 0), compressionLevel)" << std::endl; 
     542    sstr << errormsg << std::endl; 
     543    sstr << "Unable to set the compression level of the variable with id: " << varId 
     544         << " and compression level: " << compressionLevel << std::endl; 
     545    StdString e = sstr.str(); 
     546    throw CNetCdfException(e); 
     547  } 
     548 
     549  return status; 
     550} 
     551 
     552/*! 
    527553This function makes a request to netcdf with a ncid, to set the fill parameters for a variable, 
    528554given variable id and type of fill 
  • XIOS/branchs/xios-1.0/src/output/netCdfInterface.hpp

    r524 r606  
    9090    static int defVarChunking(int ncid, int varId, int storage, StdSize chunkSize[]); 
    9191 
     92    //! Define variable compression level 
     93    static int defVarDeflate(int ncid, int varId, int compressionLevel); 
     94 
    9295    //! Define variable fill parameters 
    9396    static int defVarFill(int ncid, int varId, int noFill, void* fillValue); 
  • XIOS/branchs/xios-1.0/src/output/onetcdf4.cpp

    r605 r606  
    288288      //--------------------------------------------------------------- 
    289289 
     290      void CONetCDF4::setCompressionLevel(const StdString& varname, int compressionLevel) 
     291      { 
     292         int grpid = this->getCurrentGroup(); 
     293         int varid = this->getVariable(varname); 
     294         CNetCdfInterface::defVarDeflate(grpid, varid, compressionLevel); 
     295      } 
     296 
     297      //--------------------------------------------------------------- 
     298 
    290299      template <> 
    291300         void CONetCDF4::addAttribute 
     
    414423         { 
    415424            sstart.push_back(record); 
    416             scount.push_back(1);  
     425            scount.push_back(1); 
    417426            if ((start == NULL) && 
    418427                (count == NULL)) i++; 
     
    421430 
    422431         for (;it != end; it++) 
    423          {  
     432         { 
    424433            if ((start != NULL) && (count != NULL)) 
    425434            { 
  • XIOS/branchs/xios-1.0/src/output/onetcdf4.hpp

    r501 r606  
    4646            int addVariable(const StdString & name, nc_type type, 
    4747                            const std::vector<StdString> & dim); 
    48                              
     48 
    4949      //---------------------------------------------------------------- 
    5050         public : 
    51           
     51 
    5252            template <class T> 
    5353               void setDefaultValue(const StdString & varname, const T * value = NULL); 
    54           
     54 
     55            void setCompressionLevel(const StdString& varname, int compressionLevel); 
     56 
    5557            template <class T>  void addAttribute (const StdString & name, const T & value, const StdString * varname = NULL); 
    5658 
     
    6264                              const std::vector<StdSize> * count = NULL); 
    6365 
    64             void writeData(const CArray<int, 2>& data, const StdString & name);      
     66            void writeData(const CArray<int, 2>& data, const StdString & name); 
    6567            void writeTimeAxisData(const CArray<double,1>& data, const StdString & name, 
    6668                                   bool collective, StdSize record, bool Isroot) ; 
     
    7072            /// Destructeur /// 
    7173            virtual ~CONetCDF4(void); 
    72              
     74 
    7375      //---------------------------------------------------------------- 
    74        
     76 
    7577         protected : 
    7678 
     
    9395 
    9496      //---------------------------------------------------------------- 
    95        
     97 
    9698         private : 
    97           
     99 
    98100            template <class T> 
    99101               void writeData_(int grpid, int varid, 
     
    118120 
    119121      ///--------------------------------------------------------------- 
    120             
     122 
    121123 
    122124 
Note: See TracChangeset for help on using the changeset viewer.