Index: /XIOS/branchs/xios-1.0/src/config/field_attribute.conf
===================================================================
--- /XIOS/branchs/xios-1.0/src/config/field_attribute.conf	(revision 605)
+++ /XIOS/branchs/xios-1.0/src/config/field_attribute.conf	(revision 606)
@@ -24,2 +24,4 @@
 DECLARE_ATTRIBUTE(double,    add_offset)
 DECLARE_ATTRIBUTE(double,    scale_factor)
+
+DECLARE_ATTRIBUTE(int,       compression_level)
Index: /XIOS/branchs/xios-1.0/src/config/file_attribute.conf
===================================================================
--- /XIOS/branchs/xios-1.0/src/config/file_attribute.conf	(revision 605)
+++ /XIOS/branchs/xios-1.0/src/config/file_attribute.conf	(revision 606)
@@ -14,3 +14,3 @@
 DECLARE_ATTRIBUTE(StdString,      par_access)
 
-// DECLARE_ATTRIBUTE_DEF(bool, enabled, true)
+DECLARE_ATTRIBUTE(int,       compression_level)
Index: /XIOS/branchs/xios-1.0/src/output/nc4_data_output.cpp
===================================================================
--- /XIOS/branchs/xios-1.0/src/output/nc4_data_output.cpp	(revision 605)
+++ /XIOS/branchs/xios-1.0/src/output/nc4_data_output.cpp	(revision 606)
@@ -736,4 +736,11 @@
               SuperClassWriter::setDefaultValue(fieldid, default_value);
            }
+
+           if (field->compression_level.isEmpty())
+             field->compression_level = field->file->compression_level.isEmpty() ? 0 : field->file->compression_level;
+           if (field->compression_level < 0 || field->compression_level > 9)
+             ERROR("void CNc4DataOutput::writeField_(CField* field)",
+                   "Invalid compression level, the value should range between 0 and 9.");
+           SuperClassWriter::setCompressionLevel(fieldid, field->compression_level);
 
            {  // Ecriture des coordonnÃ©es
Index: /XIOS/branchs/xios-1.0/src/output/netCdfInterface.cpp
===================================================================
--- /XIOS/branchs/xios-1.0/src/output/netCdfInterface.cpp	(revision 605)
+++ /XIOS/branchs/xios-1.0/src/output/netCdfInterface.cpp	(revision 606)
@@ -525,4 +525,30 @@
 
 /*!
+This function sets the compression level to the specified variable
+\param [in] ncid Groud id (or file id)
+\param [in] varId Id of the variable
+\param [in] compressionLevel The compression level from 0 to 9 (0 disables the compression, 9 is the higher compression)
+\return Status code
+*/
+int CNetCdfInterface::defVarDeflate(int ncid, int varId, int compressionLevel)
+{
+  int status = nc_def_var_deflate(ncid, varId, false, (compressionLevel > 0), compressionLevel);
+  if (NC_NOERR != status)
+  {
+    StdString errormsg(nc_strerror(status));
+    StdStringStream sstr;
+
+    sstr << "Error in calling function " << "nc_def_var_deflate(ncid, varId, false, (compressionLevel > 0), compressionLevel)" << std::endl;
+    sstr << errormsg << std::endl;
+    sstr << "Unable to set the compression level of the variable with id: " << varId
+         << " and compression level: " << compressionLevel << std::endl;
+    StdString e = sstr.str();
+    throw CNetCdfException(e);
+  }
+
+  return status;
+}
+
+/*!
 This function makes a request to netcdf with a ncid, to set the fill parameters for a variable,
 given variable id and type of fill
Index: /XIOS/branchs/xios-1.0/src/output/netCdfInterface.hpp
===================================================================
--- /XIOS/branchs/xios-1.0/src/output/netCdfInterface.hpp	(revision 605)
+++ /XIOS/branchs/xios-1.0/src/output/netCdfInterface.hpp	(revision 606)
@@ -90,4 +90,7 @@
     static int defVarChunking(int ncid, int varId, int storage, StdSize chunkSize[]);
 
+    //! Define variable compression level
+    static int defVarDeflate(int ncid, int varId, int compressionLevel);
+
     //! Define variable fill parameters
     static int defVarFill(int ncid, int varId, int noFill, void* fillValue);
Index: /XIOS/branchs/xios-1.0/src/output/onetcdf4.cpp
===================================================================
--- /XIOS/branchs/xios-1.0/src/output/onetcdf4.cpp	(revision 605)
+++ /XIOS/branchs/xios-1.0/src/output/onetcdf4.cpp	(revision 606)
@@ -288,4 +288,13 @@
       //---------------------------------------------------------------
 
+      void CONetCDF4::setCompressionLevel(const StdString& varname, int compressionLevel)
+      {
+         int grpid = this->getCurrentGroup();
+         int varid = this->getVariable(varname);
+         CNetCdfInterface::defVarDeflate(grpid, varid, compressionLevel);
+      }
+
+      //---------------------------------------------------------------
+
       template <>
          void CONetCDF4::addAttribute
@@ -414,5 +423,5 @@
          {
             sstart.push_back(record);
-            scount.push_back(1); 
+            scount.push_back(1);
             if ((start == NULL) &&
                 (count == NULL)) i++;
@@ -421,5 +430,5 @@
 
          for (;it != end; it++)
-         { 
+         {
             if ((start != NULL) && (count != NULL))
             {
Index: /XIOS/branchs/xios-1.0/src/output/onetcdf4.hpp
===================================================================
--- /XIOS/branchs/xios-1.0/src/output/onetcdf4.hpp	(revision 605)
+++ /XIOS/branchs/xios-1.0/src/output/onetcdf4.hpp	(revision 606)
@@ -46,11 +46,13 @@
             int addVariable(const StdString & name, nc_type type,
                             const std::vector<StdString> & dim);
-                            
+
       //----------------------------------------------------------------
          public :
-         
+
             template <class T>
                void setDefaultValue(const StdString & varname, const T * value = NULL);
-         
+
+            void setCompressionLevel(const StdString& varname, int compressionLevel);
+
             template <class T>  void addAttribute (const StdString & name, const T & value, const StdString * varname = NULL);
 
@@ -62,5 +64,5 @@
                               const std::vector<StdSize> * count = NULL);
 
-            void writeData(const CArray<int, 2>& data, const StdString & name);     
+            void writeData(const CArray<int, 2>& data, const StdString & name);
             void writeTimeAxisData(const CArray<double,1>& data, const StdString & name,
                                    bool collective, StdSize record, bool Isroot) ;
@@ -70,7 +72,7 @@
             /// Destructeur ///
             virtual ~CONetCDF4(void);
-            
+
       //----------------------------------------------------------------
-      
+
          protected :
 
@@ -93,7 +95,7 @@
 
       //----------------------------------------------------------------
-      
+
          private :
-         
+
             template <class T>
                void writeData_(int grpid, int varid,
@@ -118,5 +120,5 @@
 
       ///---------------------------------------------------------------
-           
+
 
 
Index: /XIOS/trunk/src/config/field_attribute.conf
===================================================================
--- /XIOS/trunk/src/config/field_attribute.conf	(revision 605)
+++ /XIOS/trunk/src/config/field_attribute.conf	(revision 606)
@@ -25,2 +25,4 @@
 DECLARE_ATTRIBUTE(double,    add_offset)
 DECLARE_ATTRIBUTE(double,    scale_factor)
+
+DECLARE_ATTRIBUTE(int,       compression_level)
Index: /XIOS/trunk/src/config/file_attribute.conf
===================================================================
--- /XIOS/trunk/src/config/file_attribute.conf	(revision 605)
+++ /XIOS/trunk/src/config/file_attribute.conf	(revision 606)
@@ -17,3 +17,3 @@
 DECLARE_ENUM2(mode, read, write)
 
-// DECLARE_ATTRIBUTE_DEF(bool, enabled, true)
+DECLARE_ATTRIBUTE(int,       compression_level)
Index: /XIOS/trunk/src/output/nc4_data_output.cpp
===================================================================
--- /XIOS/trunk/src/output/nc4_data_output.cpp	(revision 605)
+++ /XIOS/trunk/src/output/nc4_data_output.cpp	(revision 606)
@@ -756,4 +756,11 @@
               SuperClassWriter::setDefaultValue(fieldid, (double*)NULL);
 
+            if (field->compression_level.isEmpty())
+              field->compression_level = field->file->compression_level.isEmpty() ? 0 : field->file->compression_level;
+            if (field->compression_level < 0 || field->compression_level > 9)
+              ERROR("void CNc4DataOutput::writeField_(CField* field)",
+                    "Invalid compression level, the value should range between 0 and 9.");
+            SuperClassWriter::setCompressionLevel(fieldid, field->compression_level);
+
            {  // Ecriture des coordonnÃ©es
 
Index: /XIOS/trunk/src/output/netCdfInterface.cpp
===================================================================
--- /XIOS/trunk/src/output/netCdfInterface.cpp	(revision 605)
+++ /XIOS/trunk/src/output/netCdfInterface.cpp	(revision 606)
@@ -525,4 +525,30 @@
 
 /*!
+This function sets the compression level to the specified variable
+\param [in] ncid Groud id (or file id)
+\param [in] varId Id of the variable
+\param [in] compressionLevel The compression level from 0 to 9 (0 disables the compression, 9 is the higher compression)
+\return Status code
+*/
+int CNetCdfInterface::defVarDeflate(int ncid, int varId, int compressionLevel)
+{
+  int status = nc_def_var_deflate(ncid, varId, false, (compressionLevel > 0), compressionLevel);
+  if (NC_NOERR != status)
+  {
+    StdString errormsg(nc_strerror(status));
+    StdStringStream sstr;
+
+    sstr << "Error in calling function " << "nc_def_var_deflate(ncid, varId, false, (compressionLevel > 0), compressionLevel)" << std::endl;
+    sstr << errormsg << std::endl;
+    sstr << "Unable to set the compression level of the variable with id: " << varId
+         << " and compression level: " << compressionLevel << std::endl;
+    StdString e = sstr.str();
+    throw CNetCdfException(e);
+  }
+
+  return status;
+}
+
+/*!
 Set or unset the fill mode for a NetCDF file specified by its file id.
 \param [in] ncid File id
Index: /XIOS/trunk/src/output/netCdfInterface.hpp
===================================================================
--- /XIOS/trunk/src/output/netCdfInterface.hpp	(revision 605)
+++ /XIOS/trunk/src/output/netCdfInterface.hpp	(revision 606)
@@ -90,4 +90,7 @@
     static int defVarChunking(int ncid, int varId, int storage, StdSize chunkSize[]);
 
+    //! Define variable compression level
+    static int defVarDeflate(int ncid, int varId, int compressionLevel);
+
     //! Set or unset the fill mode
     static int setFill(int ncid, bool fill);
Index: /XIOS/trunk/src/output/onetcdf4.cpp
===================================================================
--- /XIOS/trunk/src/output/onetcdf4.cpp	(revision 605)
+++ /XIOS/trunk/src/output/onetcdf4.cpp	(revision 606)
@@ -84,5 +84,5 @@
          // This is done per variable for the NetCDF4 format.
          if (useClassicFormat)
-            CNetCdfInterface::setFill(this->ncidp, false);    
+            CNetCdfInterface::setFill(this->ncidp, false);
       }
 
@@ -277,28 +277,27 @@
 
       int CONetCDF4::addVariable(const StdString & name, nc_type type,
-                                  const std::vector<StdString> & dim)
+                                 const std::vector<StdString> & dim)
       {
          int varid = 0;
          std::vector<int> dimids;
-         std::vector<StdSize> dimsizes ;
-         StdSize size ;
-         StdSize totalSize ;
-         StdSize maxSize=1024*1024*256 ; // == 2GB/8 if output double
-
-         int grpid = this->getCurrentGroup();
-
-         std::vector<StdString>::const_iterator
-            it  = dim.begin(), end = dim.end();
-
-         for (;it != end; it++)
+         std::vector<StdSize> dimsizes;
+         StdSize size;
+         StdSize totalSize;
+         StdSize maxSize = 1024 * 1024 * 256; // == 2GB/8 if output double
+
+         int grpid = this->getCurrentGroup();
+
+         std::vector<StdString>::const_iterator it = dim.begin(), end = dim.end();
+
+         for (; it != end; it++)
          {
             const StdString & dimid = *it;
             dimids.push_back(this->getDimension(dimid));
-            (CNetCdfInterface::inqDimLen(grpid, this->getDimension(dimid), size));
-            if (size==NC_UNLIMITED) size=1 ;
-            dimsizes.push_back(size) ;
-         }
-
-         CNetCdfInterface::defVar(grpid, name, type, dimids.size(), &(dimids[0]), varid);
+            CNetCdfInterface::inqDimLen(grpid, this->getDimension(dimid), size);
+            if (size == NC_UNLIMITED) size = 1;
+            dimsizes.push_back(size);
+         }
+
+         CNetCdfInterface::defVar(grpid, name, type, dimids.size(), &dimids[0], varid);
 
          // The classic NetCDF format does not support chunking nor fill parameters
@@ -318,5 +317,14 @@
          }
 
-         return (varid);
+         return varid;
+      }
+
+      //---------------------------------------------------------------
+
+      void CONetCDF4::setCompressionLevel(const StdString& varname, int compressionLevel)
+      {
+         int grpid = this->getCurrentGroup();
+         int varid = this->getVariable(varname);
+         CNetCdfInterface::defVarDeflate(grpid, varid, compressionLevel);
       }
 
@@ -449,5 +457,5 @@
          {
             sstart.push_back(record + recordOffset);
-            scount.push_back(1); 
+            scount.push_back(1);
             if ((start == NULL) &&
                 (count == NULL)) i++;
@@ -456,5 +464,5 @@
 
          for (;it != end; it++)
-         { 
+         {
             if ((start != NULL) && (count != NULL))
             {
Index: /XIOS/trunk/src/output/onetcdf4.hpp
===================================================================
--- /XIOS/trunk/src/output/onetcdf4.hpp	(revision 605)
+++ /XIOS/trunk/src/output/onetcdf4.hpp	(revision 606)
@@ -48,11 +48,13 @@
             int addVariable(const StdString & name, nc_type type,
                             const std::vector<StdString> & dim);
-                            
+
       //----------------------------------------------------------------
          public :
-         
+
             template <class T>
                void setDefaultValue(const StdString & varname, const T * value = NULL);
-         
+
+            void setCompressionLevel(const StdString& varname, int compressionLevel);
+
             template <class T>  void addAttribute (const StdString & name, const T & value, const StdString * varname = NULL);
 
@@ -64,5 +66,5 @@
                               const std::vector<StdSize> * count = NULL);
 
-            void writeData(const CArray<int, 2>& data, const StdString & name);     
+            void writeData(const CArray<int, 2>& data, const StdString & name);
             void writeTimeAxisData(const CArray<double,1>& data, const StdString & name,
                                    bool collective, StdSize record, bool Isroot) ;
@@ -72,7 +74,7 @@
             /// Destructeur ///
             virtual ~CONetCDF4(void);
-            
+
       //----------------------------------------------------------------
-      
+
          protected :
 
@@ -97,7 +99,7 @@
 
       //----------------------------------------------------------------
-      
+
          private :
-         
+
             template <class T>
                void writeData_(int grpid, int varid,
@@ -125,5 +127,5 @@
 
       ///---------------------------------------------------------------
-           
+
 
 
