Changeset 606


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
Files:
14 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 
  • XIOS/trunk/src/config/field_attribute.conf

    r593 r606  
    2525DECLARE_ATTRIBUTE(double,    add_offset) 
    2626DECLARE_ATTRIBUTE(double,    scale_factor) 
     27 
     28DECLARE_ATTRIBUTE(int,       compression_level) 
  • XIOS/trunk/src/config/file_attribute.conf

    r598 r606  
    1717DECLARE_ENUM2(mode, read, write) 
    1818 
    19 // DECLARE_ATTRIBUTE_DEF(bool, enabled, true) 
     19DECLARE_ATTRIBUTE(int,       compression_level) 
  • XIOS/trunk/src/output/nc4_data_output.cpp

    r586 r606  
    756756              SuperClassWriter::setDefaultValue(fieldid, (double*)NULL); 
    757757 
     758            if (field->compression_level.isEmpty()) 
     759              field->compression_level = field->file->compression_level.isEmpty() ? 0 : field->file->compression_level; 
     760            if (field->compression_level < 0 || field->compression_level > 9) 
     761              ERROR("void CNc4DataOutput::writeField_(CField* field)", 
     762                    "Invalid compression level, the value should range between 0 and 9."); 
     763            SuperClassWriter::setCompressionLevel(fieldid, field->compression_level); 
     764 
    758765           {  // Ecriture des coordonnées 
    759766 
  • XIOS/trunk/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/*! 
    527553Set or unset the fill mode for a NetCDF file specified by its file id. 
    528554\param [in] ncid File id 
  • XIOS/trunk/src/output/netCdfInterface.hpp

    r591 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    //! Set or unset the fill mode 
    9396    static int setFill(int ncid, bool fill); 
  • XIOS/trunk/src/output/onetcdf4.cpp

    r605 r606  
    8484         // This is done per variable for the NetCDF4 format. 
    8585         if (useClassicFormat) 
    86             CNetCdfInterface::setFill(this->ncidp, false);     
     86            CNetCdfInterface::setFill(this->ncidp, false); 
    8787      } 
    8888 
     
    277277 
    278278      int CONetCDF4::addVariable(const StdString & name, nc_type type, 
    279                                   const std::vector<StdString> & dim) 
     279                                 const std::vector<StdString> & dim) 
    280280      { 
    281281         int varid = 0; 
    282282         std::vector<int> dimids; 
    283          std::vector<StdSize> dimsizes ; 
    284          StdSize size ; 
    285          StdSize totalSize ; 
    286          StdSize maxSize=1024*1024*256 ; // == 2GB/8 if output double 
    287  
    288          int grpid = this->getCurrentGroup(); 
    289  
    290          std::vector<StdString>::const_iterator 
    291             it  = dim.begin(), end = dim.end(); 
    292  
    293          for (;it != end; it++) 
     283         std::vector<StdSize> dimsizes; 
     284         StdSize size; 
     285         StdSize totalSize; 
     286         StdSize maxSize = 1024 * 1024 * 256; // == 2GB/8 if output double 
     287 
     288         int grpid = this->getCurrentGroup(); 
     289 
     290         std::vector<StdString>::const_iterator it = dim.begin(), end = dim.end(); 
     291 
     292         for (; it != end; it++) 
    294293         { 
    295294            const StdString & dimid = *it; 
    296295            dimids.push_back(this->getDimension(dimid)); 
    297             (CNetCdfInterface::inqDimLen(grpid, this->getDimension(dimid), size)); 
    298             if (size==NC_UNLIMITED) size=1 ; 
    299             dimsizes.push_back(size) ; 
    300          } 
    301  
    302          CNetCdfInterface::defVar(grpid, name, type, dimids.size(), &(dimids[0]), varid); 
     296            CNetCdfInterface::inqDimLen(grpid, this->getDimension(dimid), size); 
     297            if (size == NC_UNLIMITED) size = 1; 
     298            dimsizes.push_back(size); 
     299         } 
     300 
     301         CNetCdfInterface::defVar(grpid, name, type, dimids.size(), &dimids[0], varid); 
    303302 
    304303         // The classic NetCDF format does not support chunking nor fill parameters 
     
    318317         } 
    319318 
    320          return (varid); 
     319         return varid; 
     320      } 
     321 
     322      //--------------------------------------------------------------- 
     323 
     324      void CONetCDF4::setCompressionLevel(const StdString& varname, int compressionLevel) 
     325      { 
     326         int grpid = this->getCurrentGroup(); 
     327         int varid = this->getVariable(varname); 
     328         CNetCdfInterface::defVarDeflate(grpid, varid, compressionLevel); 
    321329      } 
    322330 
     
    449457         { 
    450458            sstart.push_back(record + recordOffset); 
    451             scount.push_back(1);  
     459            scount.push_back(1); 
    452460            if ((start == NULL) && 
    453461                (count == NULL)) i++; 
     
    456464 
    457465         for (;it != end; it++) 
    458          {  
     466         { 
    459467            if ((start != NULL) && (count != NULL)) 
    460468            { 
  • XIOS/trunk/src/output/onetcdf4.hpp

    r599 r606  
    4848            int addVariable(const StdString & name, nc_type type, 
    4949                            const std::vector<StdString> & dim); 
    50                              
     50 
    5151      //---------------------------------------------------------------- 
    5252         public : 
    53           
     53 
    5454            template <class T> 
    5555               void setDefaultValue(const StdString & varname, const T * value = NULL); 
    56           
     56 
     57            void setCompressionLevel(const StdString& varname, int compressionLevel); 
     58 
    5759            template <class T>  void addAttribute (const StdString & name, const T & value, const StdString * varname = NULL); 
    5860 
     
    6466                              const std::vector<StdSize> * count = NULL); 
    6567 
    66             void writeData(const CArray<int, 2>& data, const StdString & name);      
     68            void writeData(const CArray<int, 2>& data, const StdString & name); 
    6769            void writeTimeAxisData(const CArray<double,1>& data, const StdString & name, 
    6870                                   bool collective, StdSize record, bool Isroot) ; 
     
    7274            /// Destructeur /// 
    7375            virtual ~CONetCDF4(void); 
    74              
     76 
    7577      //---------------------------------------------------------------- 
    76        
     78 
    7779         protected : 
    7880 
     
    9799 
    98100      //---------------------------------------------------------------- 
    99        
     101 
    100102         private : 
    101           
     103 
    102104            template <class T> 
    103105               void writeData_(int grpid, int varid, 
     
    125127 
    126128      ///--------------------------------------------------------------- 
    127             
     129 
    128130 
    129131 
Note: See TracChangeset for help on using the changeset viewer.