Index: /branches/nemo_v3_3_beta/DOC/TexFiles/Chapters/Chap_MISC.tex
===================================================================
--- /branches/nemo_v3_3_beta/DOC/TexFiles/Chapters/Chap_MISC.tex	(revision 2363)
+++ /branches/nemo_v3_3_beta/DOC/TexFiles/Chapters/Chap_MISC.tex	(revision 2364)
@@ -508,5 +508,5 @@
 %       Standard Model Output 
 % -------------------------------------------------------------------------------------------------------------
-\subsection{Model Output (default or \key{iomput} or \key{dimgout})}
+\subsection{Model Output (default or \key{iomput} or \key{dimgout} or \key{netcdf4})}
 \label{MISC_iom}
 
@@ -536,8 +536,125 @@
 an IEEE output format.
 
+Since version 3.3, support for NetCDF4 chunking and (loss-less) compression has
+been included.  These options build on the standard NetCDF output and allow
+the user control over the size of the chunks via namelist settings. Chunking
+and compression can lead to significant reductions in file sizes for a small
+runtime overhead. For a fuller discussion on chunking and other performance
+issues the reader is referred to the NetCDF4 documentation:
+http://www.unidata.ucar.edu/software/netcdf/docs/netcdf.html\#Chunking
+
+The new features are only available when the code has been linked with a
+NetCDF4 library (version 4.1 onwards, recommended) which has been built
+with HDF5 support (version 1.8.4 onwards, recommended). Datasets created
+with chunking and compression are not backwards compatible with NetCDF3
+"classic" format but most analysis codes can be relinked simply with the
+new libraries and will then read both NetCDF3 and NetCDF4 files. NEMO
+executables linked with NetCDF4 libraries can be made to produce NetCDF3
+files by setting the \np{ln\_nc4zip} logical to false in the \np{namnc4} 
+namelist:
+
+%------------------------------------------namnc4----------------------------------------------------
+\namdisplay{namnc4}
+%-------------------------------------------------------------------------------------------------------------
+
+If \key{netcdf4} has not been defined, these namelist parameters are not read. 
+In this case, \np{ln\_nc4zip} is set false and dummy routines for a few
+NetCDF4-specific functions are defined. These functions will not be used but
+need to be included so that compilation is possible with NetCDF3 libraries.
+
+When using NetCDF4 libraries, \key{netcdf4} should be defined even if the
+intention is to create only NetCDF3-compatible files. This is necessary to
+avoid duplication between the dummy routines and the actual routines present
+in the library. Most compilers will fail at compile time when faced with
+such duplication. Thus when linking with NetCDF4 libraries the user must
+define \key{netcdf4} and control the type of NetCDF file produced via the
+namelist parameter.
+
+Chunking and compression is applied only to 4D fields and there is no
+advantage in chunking across more than one time dimension since previously
+written chunks would have to be read back and decompressed before being
+added to. Therefore, user control over chunk sizes is provided only for the
+three space dimensions. The user sets an approximate number of chunks along
+each spatial axis. The actual size of the chunks will depend on global domain
+size for mono-processors or, more likely, the local processor domain size for
+distributed processing. The derived values are subject to practical minimum
+values (to avoid wastefully small chunk sizes) and cannot be greater than the
+domain size in any dimension. The algorithm used is:
+
+\begin{alltt}  {{\tiny 
+\begin{verbatim}
+     ichunksz(1) = MIN( idomain_size,MAX( (idomain_size-1)/nn_nchunks_i + 1 ,16 ) )
+     ichunksz(2) = MIN( jdomain_size,MAX( (jdomain_size-1)/nn_nchunks_j + 1 ,16 ) )
+     ichunksz(3) = MIN( kdomain_size,MAX( (kdomain_size-1)/nn_nchunks_k + 1 , 1 ) )
+     ichunksz(4) = 1
+\end{verbatim}
+}}\end{alltt} 
+
+\noindent As an example, setting:
+\vspace{-20pt}
+\begin{alltt}  {{\tiny
+\begin{verbatim}
+     nn_nchunks_i=4, nn_nchunks_j=4 and nn_nchunks_k=31
+\end{verbatim}
+}}\end{alltt} \vspace{-10pt}
+
+\noindent for a standard ORCA2\_LIM configuration gives chunksizes of {\small\tt 46x38x1}
+respectively in the mono-processor case (i.e. global domain of {\small\tt 182x149x31}).
+An illustration of the potential space savings that NetCDF4 chunking and compression
+provides is given in table \ref{Tab_NC4} which compares the results of two short
+runs of the ORCA2\_LIM reference configuration with a 4x2 mpi partitioning. Note
+the variation in the compression ratio achieved which reflects chiefly the dry to wet 
+volume ratio of each processing region.
+
+\begin{table} 
+\begin{tabular}{lrrr}
+Filename & NetCDF3 & NetCDF4 & Reduction\\
+         &filesize & filesize & \% \\
+         &(KB)     & (KB)     & \\
+ORCA2\_restart\_0000.nc & 16420 & 8860 & 47\%\\
+ORCA2\_restart\_0001.nc & 16064 & 11456 & 29\%\\
+ORCA2\_restart\_0002.nc & 16064 & 9744 & 40\%\\
+ORCA2\_restart\_0003.nc & 16420 & 9404 & 43\%\\
+ORCA2\_restart\_0004.nc & 16200 & 5844 & 64\%\\
+ORCA2\_restart\_0005.nc & 15848 & 8172 & 49\%\\
+ORCA2\_restart\_0006.nc & 15848 & 8012 & 50\%\\
+ORCA2\_restart\_0007.nc & 16200 & 5148 & 69\%\\
+ORCA2\_2d\_grid\_T\_0000.nc & 2200 & 1504 & 32\%\\
+ORCA2\_2d\_grid\_T\_0001.nc & 2200 & 1748 & 21\%\\
+ORCA2\_2d\_grid\_T\_0002.nc & 2200 & 1592 & 28\%\\
+ORCA2\_2d\_grid\_T\_0003.nc & 2200 & 1540 & 30\%\\
+ORCA2\_2d\_grid\_T\_0004.nc & 2200 & 1204 & 46\%\\
+ORCA2\_2d\_grid\_T\_0005.nc & 2200 & 1444 & 35\%\\
+ORCA2\_2d\_grid\_T\_0006.nc & 2200 & 1428 & 36\%\\
+ORCA2\_2d\_grid\_T\_0007.nc & 2200 & 1148 & 48\%\\
+             ...            &  ... &  ... & ..  \\
+ORCA2\_2d\_grid\_W\_0000.nc & 4416 & 2240 & 50\%\\
+ORCA2\_2d\_grid\_W\_0001.nc & 4416 & 2924 & 34\%\\
+ORCA2\_2d\_grid\_W\_0002.nc & 4416 & 2512 & 44\%\\
+ORCA2\_2d\_grid\_W\_0003.nc & 4416 & 2368 & 47\%\\
+ORCA2\_2d\_grid\_W\_0004.nc & 4416 & 1432 & 68\%\\
+ORCA2\_2d\_grid\_W\_0005.nc & 4416 & 1972 & 56\%\\
+ORCA2\_2d\_grid\_W\_0006.nc & 4416 & 2028 & 55\%\\
+ORCA2\_2d\_grid\_W\_0007.nc & 4416 & 1368 & 70\%\\
+\end{tabular}
+\caption{\label{Tab_NC4} Filesize comparison between NetCDF3 and NetCDF4 
+with chunking and compression}
+\end{table}
+
 Since version 3.2, an I/O server has been added which provides more
 flexibility in the choice of the fields to be output as well as how the 
 writing work is distributed over the processors in massively parallel
-computing. It is activated when \key{iomput} is defined.
+computing. It is activated when \key{iomput} is defined. 
+
+When \key{iomput} is activated with \key{netcdf4} chunking and
+compression parameters for fields produced via \np{iom\_put} calls are
+set via an equivalent and identically named namelist to \np{namnc4} in
+\np{xmlio\_server.def}. Typically this namelist serves the mean files
+whilst the \np{ namnc4} in the main namelist file continues to serve the
+restart files. This duplication is unfortunate but appropriate since, if
+using io\_servers, the domain sizes of the individual files produced by the
+io\_server processes may be different to those produced by the invidual
+processing regions and different chunking choices may be desired.
+{ 
 
 % -------------------------------------------------------------------------------------------------------------
Index: /branches/nemo_v3_3_beta/DOC/TexFiles/Namelist/namnc4
===================================================================
--- /branches/nemo_v3_3_beta/DOC/TexFiles/Namelist/namnc4	(revision 2364)
+++ /branches/nemo_v3_3_beta/DOC/TexFiles/Namelist/namnc4	(revision 2364)
@@ -0,0 +1,15 @@
+!!======================================================================
+!!   namnc4            netcdf4 chunking and compression settings
+!!======================================================================
+!-----------------------------------------------------------------------
+&namnc4         !  netcdf4 chunking and compression settings          ("key_netcdf4")
+                !  (benign if "key_netcdf4" is not used)
+!-----------------------------------------------------------------------
+   nn_nchunks_i   =   4       !  number of chunks in i-dimension
+   nn_nchunks_j   =   4       !  number of chunks in j-dimension
+   nn_nchunks_k   =   31      !  number of chunks in k-dimension
+                              !  setting nn_nchunks_k = jpk will give a chunk size of 1 in the vertical which
+                              !  is optimal for postprocessing which works exclusively with horizontal slabs
+   ln_nc4zip      =   .TRUE.  !  (T) use netcdf4 chunking and compression
+                              !  (F) ignore chunking information and produce netcdf3-compatible files
+/
Index: /branches/nemo_v3_3_beta/NEMOGCM/ARCH/arch-ALTIX_NAUTILUS4.fcm
===================================================================
--- /branches/nemo_v3_3_beta/NEMOGCM/ARCH/arch-ALTIX_NAUTILUS4.fcm	(revision 2364)
+++ /branches/nemo_v3_3_beta/NEMOGCM/ARCH/arch-ALTIX_NAUTILUS4.fcm	(revision 2364)
@@ -0,0 +1,38 @@
+# ifort compiler options for NOCS ALTIX cluster nautilus using NetCDF4 libraries
+# NCDF_HOME   root directory containing lib and include subdirectories for netcdf4
+# HDF5_HOME   root directory containing lib and include subdirectories for HDF5
+# NCDF_INC    netcdf include file
+# NCDF_LIB    netcdf library
+# FC          Fortran compiler command
+# FCFLAGS     Fortran compiler flags
+# FFLAGS      Fortran 77 compiler flags
+# LD          linker
+# LDFLAGS     linker flags, e.g. -L<lib dir> if you have libraries in a
+# FPPFLAGS    pre-processing flags
+# AR          assembler
+# ARFLAGS     assembler flags
+# MK          make
+# USER_INC    additional include files for the compiler,  e.g. -I<include dir>
+# USER_LIB    additional libraries to pass to the linker, e.g. -l<library>
+
+
+%NCDF_HOME           /noc/users/jeff/packages/netcdf4/netcdf-4.1.1/x86_64/intel10.1
+%HDF5_HOME           /noc/users/jeff/packages/hdf5/hdf5-1.8.4-patch1/x86_64/intel10.1
+%NCDF_INC            -I%NCDF_HOME/include -I%HDF5_HOME/include
+# Note use of -Bstatic because the library root directories are not accessible to the back-end compute nodes
+%NCDF_LIB            -L%HDF5_HOME/lib -L%NCDF_HOME/lib -Bstatic -lnetcdf -lhdf5_fortran -lhdf5_hl -lhdf5 -Bdynamic -lz
+%FC                  mpif90
+%FCFLAGS             -r8 -O3 -xT -ip -vec-report0
+%FFLAGS              -r8 -O3 -xT -ip -vec-report0
+%LD                  mpif90
+%FPPFLAGS            -P -C -traditional
+%LDFLAGS
+%AR                  ar 
+%ARFLAGS             -r
+%MK                  gmake
+%USER_INC            %NCDF_INC
+%USER_LIB            %NCDF_LIB
+
+# - if debugging use these flags
+#FCFLAGS             -g -traceback -r8 -O0 -xT -ip -vec-report0
+#FFLAGS              -g -traceback -r8 -O0 -xT -ip -vec-report0
Index: /branches/nemo_v3_3_beta/NEMOGCM/CONFIG/GYRE/EXP00/namelist
===================================================================
--- /branches/nemo_v3_3_beta/NEMOGCM/CONFIG/GYRE/EXP00/namelist	(revision 2363)
+++ /branches/nemo_v3_3_beta/NEMOGCM/CONFIG/GYRE/EXP00/namelist	(revision 2364)
@@ -42,4 +42,19 @@
    cn_ocerst_in  = "restart"   !  suffix of ocean restart name (input)
    cn_ocerst_out = "restart"   !  suffix of ocean restart name (output)
+/
+!!======================================================================
+!!   namnc4            netcdf4 chunking and compression settings
+!!======================================================================
+!-----------------------------------------------------------------------
+&namnc4         !  netcdf4 chunking and compression settings     ("key_netcdf4")
+                !  (ignored if "key_netcdf4" is not used)
+!-----------------------------------------------------------------------
+   nn_nchunks_i   =   4       !  number of chunks in i-dimension
+   nn_nchunks_j   =   4       !  number of chunks in j-dimension
+   nn_nchunks_k   =   31      !  number of chunks in k-dimension
+                              !  setting nn_nchunks_k = jpk will give a chunk size of 1 in the vertical which
+                              !  is optimal for postprocessing which works exclusively with horizontal slabs
+   ln_nc4zip      =   .TRUE.  !  (T) use netcdf4 chunking and compression
+                              !  (F) ignore chunking information and produce netcdf3-compatible files
 /
 !!======================================================================
Index: /branches/nemo_v3_3_beta/NEMOGCM/CONFIG/GYRE/EXP00/xmlio_server.def
===================================================================
--- /branches/nemo_v3_3_beta/NEMOGCM/CONFIG/GYRE/EXP00/xmlio_server.def	(revision 2363)
+++ /branches/nemo_v3_3_beta/NEMOGCM/CONFIG/GYRE/EXP00/xmlio_server.def	(revision 2364)
@@ -17,4 +17,19 @@
   global_mpi_buffer_size = 512
 /  
+
+!!======================================================================
+!!   namnc4            netcdf4 chunking and compression settings
+!!======================================================================
+!-----------------------------------------------------------------------
+&namnc4         !  netcdf4 chunking and compression settings
+                !  (benign if "key_netcdf4" is not used)
+!-----------------------------------------------------------------------
+   nn_nchunks_i   =   4       !  number of chunks in i-dimension
+   nn_nchunks_j   =   4       !  number of chunks in j-dimension
+   nn_nchunks_k   =   31      !  number of chunks in k-dimension
+                              !  setting nn_nchunks_k = jpk will give a chunk size of 1 in the vertical which
+                              !  is optimal for postprocessing which works exclusively with horizontal slabs
+   ln_nc4zip      =   .TRUE.  !  (T) use netcdf4 chunking and compression
+                              !  (F) ignore chunking information and produce netcdf3-compatible files  
+/
   
-  
Index: /branches/nemo_v3_3_beta/NEMOGCM/CONFIG/GYRE_LOBSTER/EXP00/namelist
===================================================================
--- /branches/nemo_v3_3_beta/NEMOGCM/CONFIG/GYRE_LOBSTER/EXP00/namelist	(revision 2363)
+++ /branches/nemo_v3_3_beta/NEMOGCM/CONFIG/GYRE_LOBSTER/EXP00/namelist	(revision 2364)
@@ -42,4 +42,19 @@
    cn_ocerst_in  = "restart"   !  suffix of ocean restart name (input)
    cn_ocerst_out = "restart"   !  suffix of ocean restart name (output)
+/
+!!======================================================================
+!!   namnc4            netcdf4 chunking and compression settings
+!!======================================================================
+!-----------------------------------------------------------------------
+&namnc4         !  netcdf4 chunking and compression settings     ("key_netcdf4")
+                !  (ignored if "key_netcdf4" is not used)
+!-----------------------------------------------------------------------
+   nn_nchunks_i   =   4       !  number of chunks in i-dimension
+   nn_nchunks_j   =   4       !  number of chunks in j-dimension
+   nn_nchunks_k   =   31      !  number of chunks in k-dimension
+                              !  setting nn_nchunks_k = jpk will give a chunk size of 1 in the vertical which
+                              !  is optimal for postprocessing which works exclusively with horizontal slabs
+   ln_nc4zip      =   .TRUE.  !  (T) use netcdf4 chunking and compression
+                              !  (F) ignore chunking information and produce netcdf3-compatible files
 /
 !!======================================================================
Index: /branches/nemo_v3_3_beta/NEMOGCM/CONFIG/GYRE_LOBSTER/EXP00/xmlio_server.def
===================================================================
--- /branches/nemo_v3_3_beta/NEMOGCM/CONFIG/GYRE_LOBSTER/EXP00/xmlio_server.def	(revision 2363)
+++ /branches/nemo_v3_3_beta/NEMOGCM/CONFIG/GYRE_LOBSTER/EXP00/xmlio_server.def	(revision 2364)
@@ -17,4 +17,19 @@
   global_mpi_buffer_size = 512
 /  
+
+!!======================================================================
+!!   namnc4            netcdf4 chunking and compression settings
+!!======================================================================
+!-----------------------------------------------------------------------
+&namnc4         !  netcdf4 chunking and compression settings
+                !  (benign if "key_netcdf4" is not used)
+!-----------------------------------------------------------------------
+   nn_nchunks_i   =   4       !  number of chunks in i-dimension
+   nn_nchunks_j   =   4       !  number of chunks in j-dimension
+   nn_nchunks_k   =   31      !  number of chunks in k-dimension
+                              !  setting nn_nchunks_k = jpk will give a chunk size of 1 in the vertical which
+                              !  is optimal for postprocessing which works exclusively with horizontal slabs
+   ln_nc4zip      =   .TRUE.  !  (T) use netcdf4 chunking and compression
+                              !  (F) ignore chunking information and produce netcdf3-compatible files  
+/
   
-  
Index: /branches/nemo_v3_3_beta/NEMOGCM/CONFIG/ORCA2_LIM/EXP00/1_namelist
===================================================================
--- /branches/nemo_v3_3_beta/NEMOGCM/CONFIG/ORCA2_LIM/EXP00/1_namelist	(revision 2363)
+++ /branches/nemo_v3_3_beta/NEMOGCM/CONFIG/ORCA2_LIM/EXP00/1_namelist	(revision 2364)
@@ -42,4 +42,19 @@
    cn_ocerst_in  = "restart"   !  suffix of ocean restart name (input)
    cn_ocerst_out = "restart"   !  suffix of ocean restart name (output)
+/
+!!======================================================================
+!!   namnc4            netcdf4 chunking and compression settings
+!!======================================================================
+!-----------------------------------------------------------------------
+&namnc4         !  netcdf4 chunking and compression settings     ("key_netcdf4")
+                !  (ignored if "key_netcdf4" is not used)
+!-----------------------------------------------------------------------
+   nn_nchunks_i   =   4       !  number of chunks in i-dimension
+   nn_nchunks_j   =   4       !  number of chunks in j-dimension
+   nn_nchunks_k   =   31      !  number of chunks in k-dimension
+                              !  setting nn_nchunks_k = jpk will give a chunk size of 1 in the vertical which
+                              !  is optimal for postprocessing which works exclusively with horizontal slabs
+   ln_nc4zip      =   .TRUE.  !  (T) use netcdf4 chunking and compression
+                              !  (F) ignore chunking information and produce netcdf3-compatible files
 /
 !!======================================================================
Index: /branches/nemo_v3_3_beta/NEMOGCM/CONFIG/ORCA2_LIM/EXP00/namelist
===================================================================
--- /branches/nemo_v3_3_beta/NEMOGCM/CONFIG/ORCA2_LIM/EXP00/namelist	(revision 2363)
+++ /branches/nemo_v3_3_beta/NEMOGCM/CONFIG/ORCA2_LIM/EXP00/namelist	(revision 2364)
@@ -42,4 +42,19 @@
    cn_ocerst_in  = "restart"   !  suffix of ocean restart name (input)
    cn_ocerst_out = "restart"   !  suffix of ocean restart name (output)
+/
+!!======================================================================
+!!   namnc4            netcdf4 chunking and compression settings
+!!======================================================================
+!-----------------------------------------------------------------------
+&namnc4         !  netcdf4 chunking and compression settings     ("key_netcdf4")
+                !  (ignored if "key_netcdf4" is not used)
+!-----------------------------------------------------------------------
+   nn_nchunks_i   =   4       !  number of chunks in i-dimension
+   nn_nchunks_j   =   4       !  number of chunks in j-dimension
+   nn_nchunks_k   =   31      !  number of chunks in k-dimension
+                              !  setting nn_nchunks_k = jpk will give a chunk size of 1 in the vertical which
+                              !  is optimal for postprocessing which works exclusively with horizontal slabs
+   ln_nc4zip      =   .TRUE.  !  (T) use netcdf4 chunking and compression
+                              !  (F) ignore chunking information and produce netcdf3-compatible files
 /
 !!======================================================================
Index: /branches/nemo_v3_3_beta/NEMOGCM/CONFIG/ORCA2_LIM/EXP00/xmlio_server.def
===================================================================
--- /branches/nemo_v3_3_beta/NEMOGCM/CONFIG/ORCA2_LIM/EXP00/xmlio_server.def	(revision 2363)
+++ /branches/nemo_v3_3_beta/NEMOGCM/CONFIG/ORCA2_LIM/EXP00/xmlio_server.def	(revision 2364)
@@ -17,4 +17,19 @@
   global_mpi_buffer_size = 512
 /  
+
+!!======================================================================
+!!   namnc4            netcdf4 chunking and compression settings
+!!======================================================================
+!-----------------------------------------------------------------------
+&namnc4         !  netcdf4 chunking and compression settings
+                !  (benign if "key_netcdf4" is not used)
+!-----------------------------------------------------------------------
+   nn_nchunks_i   =   4       !  number of chunks in i-dimension
+   nn_nchunks_j   =   4       !  number of chunks in j-dimension
+   nn_nchunks_k   =   31      !  number of chunks in k-dimension
+                              !  setting nn_nchunks_k = jpk will give a chunk size of 1 in the vertical which
+                              !  is optimal for postprocessing which works exclusively with horizontal slabs
+   ln_nc4zip      =   .TRUE.  !  (T) use netcdf4 chunking and compression
+                              !  (F) ignore chunking information and produce netcdf3-compatible files  
+/
   
-  
Index: /branches/nemo_v3_3_beta/NEMOGCM/CONFIG/ORCA2_LIM/cpp_ORCA2_LIM.fcm
===================================================================
--- /branches/nemo_v3_3_beta/NEMOGCM/CONFIG/ORCA2_LIM/cpp_ORCA2_LIM.fcm	(revision 2363)
+++ /branches/nemo_v3_3_beta/NEMOGCM/CONFIG/ORCA2_LIM/cpp_ORCA2_LIM.fcm	(revision 2364)
@@ -1,1 +1,1 @@
- bld::tool::fppkeys key_trabbl key_vectopt_loop key_orca_r2 key_lim2 key_dynspg_flt key_diaeiv key_ldfslp key_traldf_c2d key_traldf_eiv key_dynldf_c3d key_dtatem key_dtasal key_tradmp key_zdftke key_zdfddm key_iomput key_nproci=1 key_nprocj=1
+ bld::tool::fppkeys key_trabbl key_vectopt_loop key_orca_r2 key_lim2 key_dynspg_flt key_diaeiv key_ldfslp key_traldf_c2d key_traldf_eiv key_dynldf_c3d key_dtatem key_dtasal key_tradmp key_zdftke key_zdfddm  key_nproci=4 key_nprocj=2   key_netcdf4 key_mpp_mpi 
Index: /branches/nemo_v3_3_beta/NEMOGCM/CONFIG/ORCA2_LIM_PISCES/EXP00/namelist
===================================================================
--- /branches/nemo_v3_3_beta/NEMOGCM/CONFIG/ORCA2_LIM_PISCES/EXP00/namelist	(revision 2363)
+++ /branches/nemo_v3_3_beta/NEMOGCM/CONFIG/ORCA2_LIM_PISCES/EXP00/namelist	(revision 2364)
@@ -42,4 +42,19 @@
    cn_ocerst_in  = "restart"   !  suffix of ocean restart name (input)
    cn_ocerst_out = "restart"   !  suffix of ocean restart name (output)
+/
+!!======================================================================
+!!   namnc4            netcdf4 chunking and compression settings
+!!======================================================================
+!-----------------------------------------------------------------------
+&namnc4         !  netcdf4 chunking and compression settings     ("key_netcdf4")
+                !  (ignored if "key_netcdf4" is not used)
+!-----------------------------------------------------------------------
+   nn_nchunks_i   =   4       !  number of chunks in i-dimension
+   nn_nchunks_j   =   4       !  number of chunks in j-dimension
+   nn_nchunks_k   =   31      !  number of chunks in k-dimension
+                              !  setting nn_nchunks_k = jpk will give a chunk size of 1 in the vertical which
+                              !  is optimal for postprocessing which works exclusively with horizontal slabs
+   ln_nc4zip      =   .TRUE.  !  (T) use netcdf4 chunking and compression
+                              !  (F) ignore chunking information and produce netcdf3-compatible files
 /
 !!======================================================================
Index: /branches/nemo_v3_3_beta/NEMOGCM/CONFIG/ORCA2_LIM_PISCES/EXP00/xmlio_server.def
===================================================================
--- /branches/nemo_v3_3_beta/NEMOGCM/CONFIG/ORCA2_LIM_PISCES/EXP00/xmlio_server.def	(revision 2363)
+++ /branches/nemo_v3_3_beta/NEMOGCM/CONFIG/ORCA2_LIM_PISCES/EXP00/xmlio_server.def	(revision 2364)
@@ -17,4 +17,19 @@
   global_mpi_buffer_size = 512
 /  
+
+!!======================================================================
+!!   namnc4            netcdf4 chunking and compression settings
+!!======================================================================
+!-----------------------------------------------------------------------
+&namnc4         !  netcdf4 chunking and compression settings
+                !  (benign if "key_netcdf4" is not used)
+!-----------------------------------------------------------------------
+   nn_nchunks_i   =   4       !  number of chunks in i-dimension
+   nn_nchunks_j   =   4       !  number of chunks in j-dimension
+   nn_nchunks_k   =   31      !  number of chunks in k-dimension
+                              !  setting nn_nchunks_k = jpk will give a chunk size of 1 in the vertical which
+                              !  is optimal for postprocessing which works exclusively with horizontal slabs
+   ln_nc4zip      =   .TRUE.  !  (T) use netcdf4 chunking and compression
+                              !  (F) ignore chunking information and produce netcdf3-compatible files  
+/
   
-  
Index: /branches/nemo_v3_3_beta/NEMOGCM/CONFIG/ORCA2_OFF_PISCES/EXP00/namelist
===================================================================
--- /branches/nemo_v3_3_beta/NEMOGCM/CONFIG/ORCA2_OFF_PISCES/EXP00/namelist	(revision 2363)
+++ /branches/nemo_v3_3_beta/NEMOGCM/CONFIG/ORCA2_OFF_PISCES/EXP00/namelist	(revision 2364)
@@ -42,4 +42,19 @@
    cn_ocerst_in  = "restart"   !  suffix of ocean restart name (input)
    cn_ocerst_out = "restart"   !  suffix of ocean restart name (output)
+/
+!!======================================================================
+!!   namnc4            netcdf4 chunking and compression settings
+!!======================================================================
+!-----------------------------------------------------------------------
+&namnc4         !  netcdf4 chunking and compression settings     ("key_netcdf4")
+                !  (ignored if "key_netcdf4" is not used)
+!-----------------------------------------------------------------------
+   nn_nchunks_i   =   4       !  number of chunks in i-dimension
+   nn_nchunks_j   =   4       !  number of chunks in j-dimension
+   nn_nchunks_k   =   31      !  number of chunks in k-dimension
+                              !  setting nn_nchunks_k = jpk will give a chunk size of 1 in the vertical which
+                              !  is optimal for postprocessing which works exclusively with horizontal slabs
+   ln_nc4zip      =   .TRUE.  !  (T) use netcdf4 chunking and compression
+                              !  (F) ignore chunking information and produce netcdf3-compatible files
 /
 !!======================================================================
Index: /branches/nemo_v3_3_beta/NEMOGCM/CONFIG/ORCA2_OFF_PISCES/EXP00/xmlio_server.def
===================================================================
--- /branches/nemo_v3_3_beta/NEMOGCM/CONFIG/ORCA2_OFF_PISCES/EXP00/xmlio_server.def	(revision 2363)
+++ /branches/nemo_v3_3_beta/NEMOGCM/CONFIG/ORCA2_OFF_PISCES/EXP00/xmlio_server.def	(revision 2364)
@@ -17,2 +17,19 @@
   global_mpi_buffer_size = 512
 /  
+
+!!======================================================================
+!!   namnc4            netcdf4 chunking and compression settings
+!!======================================================================
+!-----------------------------------------------------------------------
+&namnc4         !  netcdf4 chunking and compression settings
+                !  (benign if "key_netcdf4" is not used)
+!-----------------------------------------------------------------------
+   nn_nchunks_i   =   4       !  number of chunks in i-dimension
+   nn_nchunks_j   =   4       !  number of chunks in j-dimension
+   nn_nchunks_k   =   31      !  number of chunks in k-dimension
+                              !  setting nn_nchunks_k = jpk will give a chunk size of 1 in the vertical which
+                              !  is optimal for postprocessing which works exclusively with horizontal slabs
+   ln_nc4zip      =   .TRUE.  !  (T) use netcdf4 chunking and compression
+                              !  (F) ignore chunking information and produce netcdf3-compatible files  
+/
+  
Index: /branches/nemo_v3_3_beta/NEMOGCM/CONFIG/POMME/EXP00/namelist
===================================================================
--- /branches/nemo_v3_3_beta/NEMOGCM/CONFIG/POMME/EXP00/namelist	(revision 2363)
+++ /branches/nemo_v3_3_beta/NEMOGCM/CONFIG/POMME/EXP00/namelist	(revision 2364)
@@ -42,4 +42,19 @@
    cn_ocerst_in  = "restart"   !  suffix of ocean restart name (input)
    cn_ocerst_out = "restart"   !  suffix of ocean restart name (output)
+/
+!!======================================================================
+!!   namnc4            netcdf4 chunking and compression settings
+!!======================================================================
+!-----------------------------------------------------------------------
+&namnc4         !  netcdf4 chunking and compression settings     ("key_netcdf4")
+                !  (ignored if "key_netcdf4" is not used)
+!-----------------------------------------------------------------------
+   nn_nchunks_i   =   4       !  number of chunks in i-dimension
+   nn_nchunks_j   =   4       !  number of chunks in j-dimension
+   nn_nchunks_k   =   31      !  number of chunks in k-dimension
+                              !  setting nn_nchunks_k = jpk will give a chunk size of 1 in the vertical which
+                              !  is optimal for postprocessing which works exclusively with horizontal slabs
+   ln_nc4zip      =   .TRUE.  !  (T) use netcdf4 chunking and compression
+                              !  (F) ignore chunking information and produce netcdf3-compatible files
 /
 !!======================================================================
Index: /branches/nemo_v3_3_beta/NEMOGCM/CONFIG/POMME/EXP00/xmlio_server.def
===================================================================
--- /branches/nemo_v3_3_beta/NEMOGCM/CONFIG/POMME/EXP00/xmlio_server.def	(revision 2363)
+++ /branches/nemo_v3_3_beta/NEMOGCM/CONFIG/POMME/EXP00/xmlio_server.def	(revision 2364)
@@ -17,4 +17,19 @@
   global_mpi_buffer_size = 512
 /  
+
+!!======================================================================
+!!   namnc4            netcdf4 chunking and compression settings
+!!======================================================================
+!-----------------------------------------------------------------------
+&namnc4         !  netcdf4 chunking and compression settings
+                !  (benign if "key_netcdf4" is not used)
+!-----------------------------------------------------------------------
+   nn_nchunks_i   =   4       !  number of chunks in i-dimension
+   nn_nchunks_j   =   4       !  number of chunks in j-dimension
+   nn_nchunks_k   =   31      !  number of chunks in k-dimension
+                              !  setting nn_nchunks_k = jpk will give a chunk size of 1 in the vertical which
+                              !  is optimal for postprocessing which works exclusively with horizontal slabs
+   ln_nc4zip      =   .TRUE.  !  (T) use netcdf4 chunking and compression
+                              !  (F) ignore chunking information and produce netcdf3-compatible files  
+/
   
-  
Index: /branches/nemo_v3_3_beta/NEMOGCM/EXTERNAL/IOIPSL/src/histcom.f90
===================================================================
--- /branches/nemo_v3_3_beta/NEMOGCM/EXTERNAL/IOIPSL/src/histcom.f90	(revision 2363)
+++ /branches/nemo_v3_3_beta/NEMOGCM/EXTERNAL/IOIPSL/src/histcom.f90	(revision 2364)
@@ -7,4 +7,5 @@
 !-
   USE netcdf
+  USE nc4dummy ! needed to allow compilation with netcdf3 libraries
 !-
   USE stringop, ONLY : nocomma,cmpblank,findpos,find_str,strlowercase
@@ -35,4 +36,13 @@
 !- to describe the grid, just two vectors.
 !---------------------------------------------------------------------
+!-
+  TYPE, PUBLIC :: snc4_ctl    !: netcdf4 chunking control structure 
+                              !: (optional on histbeg and histend calls)
+     SEQUENCE
+     INTEGER :: ni
+     INTEGER :: nj
+     INTEGER :: nk
+     LOGICAL :: luse
+  END TYPE snc4_ctl
 !-
   INTERFACE histbeg
@@ -163,5 +173,5 @@
  & (pfilename,pim,plon,pjm,plat,       &
  &  par_orix,par_szx,par_oriy,par_szy, &
- &  pitau0,pdate0,pdeltat,phoriid,idf,domain_id,mode)
+ &  pitau0,pdate0,pdeltat,phoriid,idf,domain_id,mode,snc4chunks)
 !---------------------------------------------------------------------
 !- histbeg for 1D regular horizontal coordinates (see histb_all)
@@ -179,4 +189,5 @@
   INTEGER,INTENT(IN),OPTIONAL :: domain_id
   CHARACTER(LEN=*),OPTIONAL,INTENT(IN) :: mode
+  TYPE(snc4_ctl), OPTIONAL,INTENT(IN) :: snc4chunks
 !---------------------------------------------------------------------
   CALL histb_all &
@@ -184,5 +195,5 @@
  &  x_1d=plon,y_1d=plat, &
  &  k_orx=par_orix,k_szx=par_szx,k_ory=par_oriy,k_szy=par_szy, &
- &  domain_id=domain_id,mode=mode)
+ &  domain_id=domain_id,mode=mode,snc4chunks=snc4chunks)
 !-------------------------
 END SUBROUTINE histb_reg1d
@@ -191,5 +202,5 @@
  & (pfilename,pim,plon,pjm,plat,       &
  &  par_orix,par_szx,par_oriy,par_szy, &
- &  pitau0,pdate0,pdeltat,phoriid,idf,domain_id,mode)
+ &  pitau0,pdate0,pdeltat,phoriid,idf,domain_id,mode,snc4chunks)
 !---------------------------------------------------------------------
 !- histbeg for 2D regular horizontal coordinates (see histb_all)
@@ -206,4 +217,5 @@
   INTEGER,INTENT(IN),OPTIONAL :: domain_id
   CHARACTER(LEN=*),OPTIONAL,INTENT(IN) :: mode
+  TYPE(snc4_ctl), OPTIONAL,INTENT(IN) :: snc4chunks
 !---------------------------------------------------------------------
   CALL histb_all &
@@ -211,5 +223,5 @@
  &  x_2d=plon,y_2d=plat, &
  &  k_orx=par_orix,k_szx=par_szx,k_ory=par_oriy,k_szy=par_szy,    &
- &  domain_id=domain_id,mode=mode)
+ &  domain_id=domain_id,mode=mode,snc4chunks=snc4chunks)
 !-------------------------
 END SUBROUTINE histb_reg2d
@@ -217,5 +229,5 @@
 SUBROUTINE histb_irreg &
  &  (pfilename,pim,plon,plon_bounds,plat,plat_bounds, &
- &   pitau0,pdate0,pdeltat,phoriid,idf,domain_id,mode)
+ &   pitau0,pdate0,pdeltat,phoriid,idf,domain_id,mode,snc4chunks)
 !---------------------------------------------------------------------
 !- histbeg for irregular horizontal coordinates (see histb_all)
@@ -232,9 +244,10 @@
   INTEGER,INTENT(IN),OPTIONAL :: domain_id
   CHARACTER(LEN=*),OPTIONAL,INTENT(IN) :: mode
+  TYPE(snc4_ctl), OPTIONAL,INTENT(IN) :: snc4chunks
 !---------------------------------------------------------------------
   CALL histb_all &
  & (3,pfilename,pim,pim,pitau0,pdate0,pdeltat,phoriid,idf,  &
  &  x_1d=plon,y_1d=plat,x_bnds=plon_bounds,y_bnds=plat_bounds, &
- &  domain_id=domain_id,mode=mode)
+ &  domain_id=domain_id,mode=mode,snc4chunks=snc4chunks)
 !-------------------------
 END SUBROUTINE histb_irreg
@@ -243,5 +256,5 @@
  & (k_typ,nc_name,pim,pjm,pitau0,pdate0,pdeltat,phoriid,idf, &
  &  x_1d,y_1d,x_2d,y_2d,k_orx,k_szx,k_ory,k_szy, &
- &  x_bnds,y_bnds,domain_id,mode)
+ &  x_bnds,y_bnds,domain_id,mode,snc4chunks)
 !---------------------------------------------------------------------
 !- General interface for horizontal grids.
@@ -305,4 +318,9 @@
 !-              Keywords "NETCDF4" and "CLASSIC" are reserved
 !-              for future use.
+!-
+!- snc4chunks    : Structure containing chunk partitioning parameters
+!-              for 4-D variables and a logical switch to toggle
+!-              between netcdf3 o/p (false) and netcdf4 chunked
+!-              and compressed o/p (true)
 !---------------------------------------------------------------------
   IMPLICIT NONE
@@ -320,4 +338,5 @@
   INTEGER,INTENT(IN),OPTIONAL :: domain_id
   CHARACTER(LEN=*),OPTIONAL,INTENT(IN) :: mode
+  TYPE(snc4_ctl), OPTIONAL,INTENT(IN) :: snc4chunks
 !-
   INTEGER :: nfid,iret,m_c
@@ -406,4 +425,8 @@
   ELSE
     m_c = IOR(NF90_CLOBBER,NF90_64BIT_OFFSET)
+  ENDIF
+!-
+  IF (PRESENT(snc4chunks)) THEN
+    IF (snc4chunks%luse) m_c = NF90_HDF5  ! will conflict if compiling with netcdf4 libraries without "key_netcdf4"
   ENDIF
 !-
@@ -1347,5 +1370,5 @@
 END SUBROUTINE histdef
 !===
-SUBROUTINE histend (idf)
+SUBROUTINE histend (idf, snc4chunks)
 !---------------------------------------------------------------------
 !- This subroutine end the decalaration of variables and sets the
@@ -1362,4 +1385,5 @@
 !-
   INTEGER,INTENT(IN) :: idf
+  TYPE(snc4_ctl), OPTIONAL,INTENT(IN) :: snc4chunks
 !-
   INTEGER :: nfid,nvid,iret,ndim,iv,itx,ziv,itax,dim_cnt
@@ -1378,4 +1402,15 @@
   LOGICAL :: l_b
   LOGICAL :: l_dbg
+  INTEGER, DIMENSION(4) :: ichunksz    ! NETCDF4 chunk sizes
+  INTEGER :: ichunkalg, ishuffle,&
+             ideflate, ideflate_level
+  LOGICAL :: lchunk = .FALSE.   ! logical switch to activate chunking when appropriate
+!-
+  ! NetCDF4 chunking and compression parameters
+  ichunkalg = 0
+  ishuffle = 1
+  ideflate = 1
+  ideflate_level = 1
+  !
 !---------------------------------------------------------------------
   CALL ipsldbg (old_status=l_dbg)
@@ -1517,4 +1552,23 @@
  &             W_F(idf)%W_V(iv)%v_typ,dims(1:ABS(ndim)),nvid)
 !-
+      IF( ndim == 4 ) THEN
+        IF( PRESENT( snc4chunks ) ) THEN
+          IF( snc4chunks%luse ) THEN
+           ichunksz = 1
+           iret = NF90_INQUIRE_DIMENSION( nfid, W_F(idf)%xid, len = ichunksz(1) )
+           iret = NF90_INQUIRE_DIMENSION( nfid, W_F(idf)%yid, len = ichunksz(2) )
+           IF ( ziv .NE. -99 ) &
+              iret = NF90_INQUIRE_DIMENSION( nfid, W_F(idf)%zax_ids(ziv), len = ichunksz(3) )
+           ichunksz(1) = MIN(ichunksz(1), MAX((ichunksz(1)-1)/snc4chunks%ni + 1,16))
+           ichunksz(2) = MIN(ichunksz(2), MAX((ichunksz(2)-1)/snc4chunks%nj + 1,16))
+           ichunksz(3) = MIN(ichunksz(3), MAX((ichunksz(3)-1)/snc4chunks%nk + 1, 1))
+           ! Always use a chunk size of 1 for the unlimited dimension
+           iret = NF90_DEF_VAR_CHUNKING(nfid, nvid, ichunkalg, ichunksz) ! will conflict if compiling with netcdf4 libraries without "key_netcdf4"
+
+           iret = NF90_DEF_VAR_DEFLATE(nfid, nvid, ishuffle, ideflate, ideflate_level) ! will conflict if compiling with netcdf4 libraries without "key_netcdf4"
+
+          ENDIF
+        ENDIF
+      ENDIF
       W_F(idf)%W_V(iv)%ncvid = nvid
 !-
Index: /branches/nemo_v3_3_beta/NEMOGCM/EXTERNAL/IOIPSL/src/nc4dummy.F90
===================================================================
--- /branches/nemo_v3_3_beta/NEMOGCM/EXTERNAL/IOIPSL/src/nc4dummy.F90	(revision 2364)
+++ /branches/nemo_v3_3_beta/NEMOGCM/EXTERNAL/IOIPSL/src/nc4dummy.F90	(revision 2364)
@@ -0,0 +1,45 @@
+MODULE nc4dummy
+!-
+!-
+! This software is governed by the CeCILL license
+! See IOIPSL/IOIPSL_License_CeCILL.txt
+!---------------------------------------------------------------------
+#if ! defined key_netcdf4
+      !!--------------------------------------------------------------------
+      !! NOT 'key_netcdf4' Defines dummy routines for netcdf4
+      !!                   calls when compiling without netcdf4 libraries
+      !!--------------------------------------------------------------------
+     INTEGER, PUBLIC :: NF90_HDF5
+CONTAINS
+!===
+   INTEGER FUNCTION NF90_DEF_VAR_CHUNKING(idum1, idum2, idum3, iarr1)
+      !!--------------------------------------------------------------------
+      !!                   ***  SUBROUTINE NF90_DEF_VAR_CHUNKING  ***
+      !!
+      !! ** Purpose :   Dummy NetCDF4 routine to enable compiling with NetCDF3 libraries
+      !!--------------------------------------------------------------------
+      INTEGER,               INTENT(in) :: idum1, idum2, idum3
+      INTEGER, DIMENSION(4), INTENT(in) :: iarr1
+      IF(lwp) WRITE(numout,*) 'Warning: Attempt to chunk output variable without NetCDF4 support'
+      NF90_DEF_VAR_CHUNKING = -1
+   END FUNCTION NF90_DEF_VAR_CHUNKING
+
+   INTEGER FUNCTION NF90_DEF_VAR_DEFLATE(idum1, idum2, idum3, idum4, idum5)
+      !!--------------------------------------------------------------------
+      !!                   ***  SUBROUTINE NF90_DEF_VAR_DEFLATE  ***
+      !!
+      !! ** Purpose :   Dummy NetCDF4 routine to enable compiling with NetCDF3 libraries
+      !!--------------------------------------------------------------------
+      INTEGER,               INTENT(in) :: idum1, idum2, idum3, idum4, idum5
+      IF(lwp) WRITE(numout,*) 'Warning: Attempt to compress output variable without NetCDF4 support'
+      NF90_DEF_VAR_DEFLATE = -1
+   END FUNCTION NF90_DEF_VAR_DEFLATE
+#else
+      !!--------------------------------------------------------------------
+      !! 'key_netcdf4' Dummy module (usually defines dummy routines for netcdf4
+      !!               calls when compiling without netcdf4 libraries
+      !!--------------------------------------------------------------------
+#endif
+
+!------------------
+END MODULE nc4dummy
Index: /branches/nemo_v3_3_beta/NEMOGCM/EXTERNAL/XMLIO_SERVER/src/IOSERVER/mod_interface_ioipsl.f90
===================================================================
--- /branches/nemo_v3_3_beta/NEMOGCM/EXTERNAL/XMLIO_SERVER/src/IOSERVER/mod_interface_ioipsl.f90	(revision 2363)
+++ /branches/nemo_v3_3_beta/NEMOGCM/EXTERNAL/XMLIO_SERVER/src/IOSERVER/mod_interface_ioipsl.f90	(revision 2364)
@@ -38,4 +38,5 @@
   USE ioipsl
   USE xmlio
+  USE mod_ioserver_namelist
   IMPLICIT NONE
     INTEGER,INTENT(IN)  :: nb_server
@@ -85,5 +86,5 @@
                      pt_zoom%ibegin_loc, pt_zoom%ni_loc,pt_zoom%jbegin_loc,pt_zoom%nj_loc,         &
                      initial_timestep, initial_date, timestep_value,                               &
-                     ioipsl_hori_id, ioipsl_file_id)
+                     ioipsl_hori_id, ioipsl_file_id, snc4chunks=snc4ioset)
          ELSE                                              
 
@@ -92,5 +93,5 @@
                      pt_zoom%ibegin_loc, pt_zoom%ni_loc,pt_zoom%jbegin_loc,pt_zoom%nj_loc,          &
                      initial_timestep, initial_date, timestep_value,                                &
-                     ioipsl_hori_id, ioipsl_file_id,domain_id=ioipsl_domain_id)                                              
+                     ioipsl_hori_id, ioipsl_file_id,domain_id=ioipsl_domain_id, snc4chunks=snc4ioset)                                              
        
          ENDIF
@@ -139,5 +140,5 @@
           ENDIF
         ENDDO
-        CALL histend(ioipsl_file_id)
+        CALL histend(ioipsl_file_id, snc4chunks=snc4ioset)
       ENDIF
       CALL sorted_list__delete(axis_id)
Index: /branches/nemo_v3_3_beta/NEMOGCM/EXTERNAL/XMLIO_SERVER/src/IOSERVER/mod_ioserver_namelist.f90
===================================================================
--- /branches/nemo_v3_3_beta/NEMOGCM/EXTERNAL/XMLIO_SERVER/src/IOSERVER/mod_ioserver_namelist.f90	(revision 2363)
+++ /branches/nemo_v3_3_beta/NEMOGCM/EXTERNAL/XMLIO_SERVER/src/IOSERVER/mod_ioserver_namelist.f90	(revision 2364)
@@ -11,4 +11,16 @@
 
   INTEGER,PARAMETER,PRIVATE :: starting_unit=356
+  TYPE, PUBLIC :: snc4_ctl    !: netcdf4 chunking control structure
+                              !: (optional on histbeg and histend calls)
+     SEQUENCE
+     INTEGER :: ni
+     INTEGER :: nj
+     INTEGER :: nk
+     LOGICAL :: luse
+  END TYPE snc4_ctl
+  TYPE(snc4_ctl), SAVE :: snc4ioset
+  INTEGER :: nn_nchunks_i, nn_nchunks_j, nn_nchunks_k
+  LOGICAL :: ln_nc4zip=.false.
+  NAMELIST /namnc4/ nn_nchunks_i, nn_nchunks_j, nn_nchunks_k, ln_nc4zip
   
 CONTAINS
@@ -22,4 +34,5 @@
     server_id='unknown'
     global_mpi_buffer_size=512
+    snc4ioset%luse = .false.
     
   END SUBROUTINE set_default_namelist
@@ -46,6 +59,13 @@
       READ(unit,nml=coupling_param)
       READ(unit,nml=mpi_param)
-      global_mpi_buffer_size=global_mpi_buffer_size*1024*128  
+      READ(unit,nml=namnc4,ERR=666,END=666)
+ 666  global_mpi_buffer_size=global_mpi_buffer_size*1024*128  
       CLOSE(unit)
+      IF (ln_nc4zip) THEN
+        snc4ioset%ni  = nn_nchunks_i
+        snc4ioset%nj  = nn_nchunks_j
+        snc4ioset%nk  = nn_nchunks_k
+        snc4ioset%luse = ln_nc4zip
+      ENDIF
     ELSE
       PRINT *,'WARNING : mod_ioserver::read_namelist : file xmlio_server.def is absent', &
Index: /branches/nemo_v3_3_beta/NEMOGCM/NEMO/C1D_SRC/diawri_c1d.F90
===================================================================
--- /branches/nemo_v3_3_beta/NEMOGCM/NEMO/C1D_SRC/diawri_c1d.F90	(revision 2363)
+++ /branches/nemo_v3_3_beta/NEMOGCM/NEMO/C1D_SRC/diawri_c1d.F90	(revision 2364)
@@ -142,5 +142,5 @@
          CALL histbeg( clhstnam, jpi, glamt, jpj, gphit,           &  ! Horizontal grid: glamt and gphit
             &          iimi, iima-iimi+1, ijmi, ijma-ijmi+1,       &
-            &          nit000-1, zjulian, zdt, nh_T, nid_T, domain_id=nidom )
+            &          nit000-1, zjulian, zdt, nh_T, nid_T, domain_id=nidom, snc4chunks=snc4set )
          CALL histvert( nid_T, "deptht", "Vertical T levels",      &  ! Vertical grid: gdept
             &           "m", ipk, gdept_0, nz_T, "down" )
@@ -243,5 +243,5 @@
          ENDIF
 
-         CALL histend( nid_T )
+         CALL histend( nid_T, snc4set )
 
          IF(lwp) WRITE(numout,*)
Index: /branches/nemo_v3_3_beta/NEMOGCM/NEMO/LIM_SRC_2/limwri_2.F90
===================================================================
--- /branches/nemo_v3_3_beta/NEMOGCM/NEMO/LIM_SRC_2/limwri_2.F90	(revision 2363)
+++ /branches/nemo_v3_3_beta/NEMOGCM/NEMO/LIM_SRC_2/limwri_2.F90	(revision 2364)
@@ -112,5 +112,5 @@
          CALL dia_nam ( clhstnam, nwrite, 'icemod' )
          CALL histbeg ( clhstnam, jpi, glamt, jpj, gphit,    &
-            &           1, jpi, 1, jpj, niter, zjulian, rdt_ice, nhorid, nice , domain_id=nidom)
+            &           1, jpi, 1, jpj, niter, zjulian, rdt_ice, nhorid, nice , domain_id=nidom, snc4chunks=snc4set)
          CALL histvert( nice, "deptht", "Vertical T levels", "m", 1, zdept, ndepid, "down")
          CALL wheneq  ( jpij , tmask(:,:,1), 1, 1., ndex51, ndim)
@@ -120,5 +120,5 @@
                &                                  , nhorid, 1, 1, 1, -99, 32, clop, zsto, zout )
          END DO
-         CALL histend( nice )
+         CALL histend( nice, snc4set )
          !
       ENDIF
@@ -305,5 +305,5 @@
       CALL histdef( kid, "isnowpre", "Snow precipitation"      , "kg/m2/s", jpi, jpj, kh_i, 1, 1, 1, -99, 32, "inst(x)", rdt, rdt ) 
 
-      CALL histend( kid )   ! end of the file definition
+      CALL histend( kid, snc4set )   ! end of the file definition
 
       CALL histwrite( kid, "isnowthi", kt, hsnif          , jpi*jpj, (/1/) )   
Index: /branches/nemo_v3_3_beta/NEMOGCM/NEMO/LIM_SRC_3/limwri.F90
===================================================================
--- /branches/nemo_v3_3_beta/NEMOGCM/NEMO/LIM_SRC_3/limwri.F90	(revision 2363)
+++ /branches/nemo_v3_3_beta/NEMOGCM/NEMO/LIM_SRC_3/limwri.F90	(revision 2364)
@@ -146,5 +146,5 @@
          CALL dia_nam ( clhstnam, nwrite, 'icemod' )
          CALL histbeg ( clhstnam, jpi, glamt, jpj, gphit, 1, jpi, 1, jpj, niter, zjulian, rdt_ice,   &
-            &           nhorid, nice, domain_id=nidom )
+            &           nhorid, nice, domain_id=nidom, snc4chunks=snc4set )
          CALL histvert( nice, "deptht", "Vertical T levels", "m", 1, zdept, ndepid, "down")
          CALL wheneq  ( jpij , tmask(:,:,1), 1, 1., ndex51, ndim)
@@ -160,5 +160,5 @@
          END DO
 
-         CALL histend(nice)
+         CALL histend(nice, snc4set)
 
          !-----------------
@@ -175,5 +175,5 @@
             niter, zjulian, rdt_ice,   & ! time
             nhorida,                   & ! ? linked with horizontal ...
-            nicea , domain_id=nidom)                  ! file 
+            nicea , domain_id=nidom, snc4chunks=snc4set)                  ! file 
          CALL histvert( nicea, "icethi", "L levels",               &
             "m", ipl , hi_mean , nz )
@@ -195,5 +195,5 @@
          CALL histdef( nicea, "iice_etd", "Brine volume distr. "               , "%"    ,   &  
             jpi, jpj, nhorida, jpl, 1, jpl, nz, 15, clop, zsto, zout )
-         CALL histend(nicea)
+         CALL histend(nicea, snc4set)
       ENDIF
 
Index: /branches/nemo_v3_3_beta/NEMOGCM/NEMO/OPA_SRC/DIA/diaptr.F90
===================================================================
--- /branches/nemo_v3_3_beta/NEMOGCM/NEMO/OPA_SRC/DIA/diaptr.F90	(revision 2363)
+++ /branches/nemo_v3_3_beta/NEMOGCM/NEMO/OPA_SRC/DIA/diaptr.F90	(revision 2364)
@@ -728,5 +728,5 @@
             ! Horizontal grid : zphi()
             CALL histbeg(clhstnam, 1, zfoo, jpj, zphi,   &
-               1, 1, 1, jpj, niter, zjulian, zdt*nf_ptr, nhoridz, numptr, domain_id=nidom_ptr)
+               1, 1, 1, jpj, niter, zjulian, zdt*nf_ptr, nhoridz, numptr, domain_id=nidom_ptr, snc4chunks=snc4set)
             ! Vertical grids : gdept_0, gdepw_0
             CALL histvert( numptr, "deptht", "Vertical T levels",   &
@@ -880,5 +880,5 @@
             ENDIF
 
-            CALL histend( numptr )
+            CALL histend( numptr, snc4set )
 
          END IF
Index: /branches/nemo_v3_3_beta/NEMOGCM/NEMO/OPA_SRC/DIA/diawri.F90
===================================================================
--- /branches/nemo_v3_3_beta/NEMOGCM/NEMO/OPA_SRC/DIA/diawri.F90	(revision 2363)
+++ /branches/nemo_v3_3_beta/NEMOGCM/NEMO/OPA_SRC/DIA/diawri.F90	(revision 2364)
@@ -273,5 +273,5 @@
          CALL histbeg( clhstnam, jpi, glamt, jpj, gphit,           &  ! Horizontal grid: glamt and gphit
             &          iimi, iima-iimi+1, ijmi, ijma-ijmi+1,       &
-            &          nit000-1, zjulian, zdt, nh_T, nid_T, domain_id=nidom )
+            &          nit000-1, zjulian, zdt, nh_T, nid_T, domain_id=nidom, snc4chunks=snc4set )
          CALL histvert( nid_T, "deptht", "Vertical T levels",      &  ! Vertical grid: gdept
             &           "m", ipk, gdept_0, nz_T, "down" )
@@ -286,5 +286,5 @@
          CALL histbeg( clhstnam, jpi, glamu, jpj, gphiu,           &  ! Horizontal grid: glamu and gphiu
             &          iimi, iima-iimi+1, ijmi, ijma-ijmi+1,       &
-            &          nit000-1, zjulian, zdt, nh_U, nid_U, domain_id=nidom )
+            &          nit000-1, zjulian, zdt, nh_U, nid_U, domain_id=nidom, snc4chunks=snc4set )
          CALL histvert( nid_U, "depthu", "Vertical U levels",      &  ! Vertical grid: gdept
             &           "m", ipk, gdept_0, nz_U, "down" )
@@ -299,5 +299,5 @@
          CALL histbeg( clhstnam, jpi, glamv, jpj, gphiv,           &  ! Horizontal grid: glamv and gphiv
             &          iimi, iima-iimi+1, ijmi, ijma-ijmi+1,       &
-            &          nit000-1, zjulian, zdt, nh_V, nid_V, domain_id=nidom )
+            &          nit000-1, zjulian, zdt, nh_V, nid_V, domain_id=nidom, snc4chunks=snc4set )
          CALL histvert( nid_V, "depthv", "Vertical V levels",      &  ! Vertical grid : gdept
             &          "m", ipk, gdept_0, nz_V, "down" )
@@ -312,5 +312,5 @@
          CALL histbeg( clhstnam, jpi, glamt, jpj, gphit,           &  ! Horizontal grid: glamt and gphit
             &          iimi, iima-iimi+1, ijmi, ijma-ijmi+1,       &
-            &          nit000-1, zjulian, zdt, nh_W, nid_W, domain_id=nidom )
+            &          nit000-1, zjulian, zdt, nh_W, nid_W, domain_id=nidom, snc4chunks=snc4set )
          CALL histvert( nid_W, "depthw", "Vertical W levels",      &  ! Vertical grid: gdepw
             &          "m", ipk, gdepw_0, nz_W, "down" )
@@ -404,5 +404,5 @@
 #endif 
 
-         CALL histend( nid_T )
+         CALL histend( nid_T, snc4chunks=snc4set )
 
          !                                                                                      !!! nid_U : 3D
@@ -417,5 +417,5 @@
             &          jpi, jpj, nh_U, 1  , 1, 1  , - 99, 32, clop, zsto, zout )
 
-         CALL histend( nid_U )
+         CALL histend( nid_U, snc4chunks=snc4set )
 
          !                                                                                      !!! nid_V : 3D
@@ -430,5 +430,5 @@
             &          jpi, jpj, nh_V, 1  , 1, 1  , - 99, 32, clop, zsto, zout )
 
-         CALL histend( nid_V )
+         CALL histend( nid_V, snc4chunks=snc4set )
 
          !                                                                                      !!! nid_W : 3D
@@ -458,5 +458,5 @@
 #endif
 
-         CALL histend( nid_W )
+         CALL histend( nid_W, snc4chunks=snc4set )
 
          IF(lwp) WRITE(numout,*)
@@ -624,5 +624,5 @@
       zjulian = zjulian - adatrj   !   set calendar origin to the beginning of the experiment
       CALL histbeg( clname, jpi, glamt, jpj, gphit,   &
-          1, jpi, 1, jpj, nit000-1, zjulian, zdt, nh_i, id_i, domain_id=nidom )          ! Horizontal grid : glamt and gphit
+          1, jpi, 1, jpj, nit000-1, zjulian, zdt, nh_i, id_i, domain_id=nidom, snc4chunks=snc4set ) ! Horizontal grid : glamt and gphit
       CALL histvert( id_i, "deptht", "Vertical T levels",   &    ! Vertical grid : gdept
           "m", jpk, gdept_0, nz_i, "down")
@@ -658,5 +658,5 @@
       CALL lim_wri_state_2( kt, id_i, nh_i )
 #else
-      CALL histend( id_i )
+      CALL histend( id_i, snc4chunks=snc4set )
 #endif
 
Index: /branches/nemo_v3_3_beta/NEMOGCM/NEMO/OPA_SRC/DOM/domain.F90
===================================================================
--- /branches/nemo_v3_3_beta/NEMOGCM/NEMO/OPA_SRC/DOM/domain.F90	(revision 2363)
+++ /branches/nemo_v3_3_beta/NEMOGCM/NEMO/OPA_SRC/DOM/domain.F90	(revision 2364)
@@ -106,4 +106,5 @@
       !!              - namdom namelist
       !!              - namcla namelist
+      !!              - namnc4 namelist   ! "key_netcdf4" only
       !!----------------------------------------------------------------------
       USE ioipsl
@@ -115,4 +116,7 @@
          &             rn_rdtmax, rn_rdth     , nn_baro     , nn_closea
       NAMELIST/namcla/ nn_cla
+#if defined key_netcdf4
+      NAMELIST/namnc4/ nn_nchunks_i, nn_nchunks_j, nn_nchunks_k, ln_nc4zip
+#endif
       !!----------------------------------------------------------------------
 
@@ -232,4 +236,30 @@
       IF( lk_mpp_rep .AND. n_cla /= 0 )   CALL ctl_stop( ' Reproductibility tests (nbit_cmp=1) require n_cla = 0' )
       !
+
+#if defined key_netcdf4
+
+      REWIND( numnam )              ! Namelist namnc4 : netcdf4 chunking parameters
+      READ  ( numnam, namnc4 )
+      IF(lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) '   Namelist namnc4 - Netcdf4 chunking parameters'
+         WRITE(numout,*) '      number of chunks in i-dimension      nn_nchunks_i   = ', nn_nchunks_i
+         WRITE(numout,*) '      number of chunks in j-dimension      nn_nchunks_j   = ', nn_nchunks_j
+         WRITE(numout,*) '      number of chunks in k-dimension      nn_nchunks_k   = ', nn_nchunks_k
+         WRITE(numout,*) '      apply netcdf4/hdf5 chunking & compression ln_nc4zip = ', ln_nc4zip
+      ENDIF
+
+      ! Put the netcdf4 settings into a simple structure (snc4set, defined in in_out_manager module)
+      ! Note the chunk size in the unlimited (time) dimension will be fixed at 1
+      snc4set%ni   = nn_nchunks_i
+      snc4set%nj   = nn_nchunks_j
+      snc4set%nk   = nn_nchunks_k
+      snc4set%luse = ln_nc4zip
+
+#else
+
+      snc4set%luse = .FALSE.
+ 
+#endif
    END SUBROUTINE dom_nam
 
Index: /branches/nemo_v3_3_beta/NEMOGCM/NEMO/OPA_SRC/IOM/in_out_manager.F90
===================================================================
--- /branches/nemo_v3_3_beta/NEMOGCM/NEMO/OPA_SRC/IOM/in_out_manager.F90	(revision 2363)
+++ /branches/nemo_v3_3_beta/NEMOGCM/NEMO/OPA_SRC/IOM/in_out_manager.F90	(revision 2364)
@@ -45,4 +45,33 @@
    LOGICAL            ::   ln_clobber    = .FALSE.     !: clobber (overwrite) an existing file
    INTEGER            ::   nn_chunksz    = 0           !: chunksize (bytes) for NetCDF file (working only with iom_nf90 routines)
+#if defined key_netcdf4
+   !!----------------------------------------------------------------------
+   !!                   namnc4 namelist parameters
+   !!----------------------------------------------------------------------
+                                                       !: =========================================================================
+                                                       !: The following four values determine the partitioning of the output fields
+                                                       !: into netcdf4 chunks. They are unrelated to the nn_chunk_sz setting which is
+                                                       !: for runtime optimisation. The individual netcdf4 chunks can be optionally 
+                                                       !: gzipped (recommended) leading to significant reductions in I/O volumes 
+   INTEGER            ::   nn_nchunks_i  = 1           !: number of chunks required in the i-dimension (only with iom_nf90 routines and key_netcdf4)
+   INTEGER            ::   nn_nchunks_j  = 1           !: number of chunks required in the j-dimension (only with iom_nf90 routines and key_netcdf4)
+   INTEGER            ::   nn_nchunks_k  = 1           !: number of chunks required in the k-dimension (only with iom_nf90 routines and key_netcdf4)
+   INTEGER            ::   nn_nchunks_t  = 1           !: number of chunks required in the t-dimension (only with iom_nf90 routines and key_netcdf4)
+   LOGICAL            ::   ln_nc4zip     = .TRUE.      !: netcdf4 usage. (T): chunk and compress output datasets using the HDF5 sublayers of netcdf4
+                                                       !:                (F): ignore chunking request and use the netcdf4 library to produce netcdf3-compatible files 
+#endif
+
+!$AGRIF_DO_NOT_TREAT
+   TYPE, PUBLIC :: snc4_ctl                            !: netcdf4 chunking control structure (always needed for decision making)
+      SEQUENCE
+      INTEGER :: ni
+      INTEGER :: nj
+      INTEGER :: nk
+      LOGICAL :: luse
+   END TYPE snc4_ctl
+
+   TYPE(snc4_ctl) :: snc4set                          !: netcdf4 chunking control structure (always needed for decision making)
+!$AGRIF_END_DO_NOT_TREAT
+
 
    !! conversion of DOCTOR norm namelist name into model name
Index: /branches/nemo_v3_3_beta/NEMOGCM/NEMO/OPA_SRC/IOM/iom_nf90.F90
===================================================================
--- /branches/nemo_v3_3_beta/NEMOGCM/NEMO/OPA_SRC/IOM/iom_nf90.F90	(revision 2363)
+++ /branches/nemo_v3_3_beta/NEMOGCM/NEMO/OPA_SRC/IOM/iom_nf90.F90	(revision 2364)
@@ -39,4 +39,13 @@
       MODULE PROCEDURE iom_nf90_rp0123d
    END INTERFACE
+
+#if ! defined key_netcdf4
+   !!--------------------------------------------------------------------
+   !! NOT 'key_netcdf4' Defines dummy routines for netcdf4
+   !!                   calls when compiling without netcdf4 libraries
+   !!--------------------------------------------------------------------
+   PUBLIC NF90_DEF_VAR_CHUNKING, NF90_DEF_VAR_DEFLATE ! contained below
+   INTEGER :: NF90_HDF5
+#endif
    !!----------------------------------------------------------------------
    !! NEMO/OPA 3.3 , NEMO Consortium (2010)
@@ -67,5 +76,5 @@
       INTEGER            ::   jl               ! loop variable
       INTEGER            ::   ichunk           ! temporary storage of nn_chunksz
-      INTEGER            ::   imode            ! creation mode flag: NF90_CLOBBER or NF90_NOCLOBBER
+      INTEGER            ::   imode            ! creation mode flag: NF90_CLOBBER or NF90_NOCLOBBER or NF90_HDF5
       LOGICAL            ::   llclobber        ! local definition of ln_clobber
       !---------------------------------------------------------------------
@@ -82,5 +91,9 @@
          IF( ldwrt ) THEN  ! ... in write mode
             IF(lwp) WRITE(numout,*) TRIM(clinfo)//' open existing file: '//TRIM(cdname)//' in WRITE mode'
-            CALL iom_nf90_check(NF90_OPEN( TRIM(cdname), NF90_WRITE  , if90id, chunksize = ichunk ), clinfo)
+            IF( snc4set%luse ) THEN
+               CALL iom_nf90_check(NF90_OPEN( TRIM(cdname), NF90_WRITE  , if90id ), clinfo)
+            ELSE
+               CALL iom_nf90_check(NF90_OPEN( TRIM(cdname), NF90_WRITE  , if90id, chunksize = ichunk ), clinfo)
+            ENDIF
             CALL iom_nf90_check(NF90_SET_FILL( if90id, NF90_NOFILL, idmy                          ), clinfo)
          ELSE              ! ... in read mode
@@ -101,5 +114,13 @@
             ELSE                   ;   imode = IOR( NF90_64BIT_OFFSET, NF90_NOCLOBBER ) 
             ENDIF
-            CALL iom_nf90_check(NF90_CREATE( TRIM(cdname), imode, if90id, chunksize = ichunk ), clinfo)
+            IF( snc4set%luse ) THEN
+               IF(lwp) WRITE(numout,*) TRIM(clinfo)//' creating file: '//TRIM(cdname)//' in hdf5 (netcdf4) mode'
+               IF( llclobber ) THEN   ;   imode = IOR(NF90_HDF5, NF90_CLOBBER)
+               ELSE                   ;   imode = IOR(NF90_HDF5, NF90_NOCLOBBER)
+               ENDIF
+               CALL iom_nf90_check(NF90_CREATE( TRIM(cdname), imode, if90id ), clinfo)
+            ELSE
+               CALL iom_nf90_check(NF90_CREATE( TRIM(cdname), imode, if90id, chunksize = ichunk ), clinfo)
+            ENDIF
             CALL iom_nf90_check(NF90_SET_FILL( if90id, NF90_NOFILL, idmy                     ), clinfo)
             ! define dimensions
@@ -378,4 +399,11 @@
       INTEGER               :: idmy                 ! dummy variable
       INTEGER               :: itype                ! variable type
+      INTEGER, DIMENSION(4) :: ichunksz             ! NetCDF4 chunk sizes. Will be computed using
+                                                    ! nn_nchunks_[i,j,k,t] namelist parameters
+      INTEGER               :: ichunkalg, ishuffle,&
+                               ideflate, ideflate_level
+                                                    ! NetCDF4 internally fixed parameters
+      LOGICAL               :: lchunk               ! logical switch to activate chunking and compression
+                                                    ! when appropriate (currently chunking is applied to 4d fields only)
       !---------------------------------------------------------------------
       !
@@ -408,4 +436,11 @@
       ! ===============
       IF( kvid <= 0 ) THEN
+         !
+         ! NetCDF4 chunking and compression fixed settings
+         ichunkalg = 0
+         ishuffle = 1
+         ideflate = 1
+         ideflate_level = 1
+         !
          idvar = iom_file(kiomid)%nvars + 1
          ! are we in define mode?
@@ -438,4 +473,6 @@
                  &                            iom_file(kiomid)%nvid(idvar) ), clinfo)
          ENDIF
+         lchunk = .false.
+         IF( snc4set%luse .AND. idims.eq.4 ) lchunk = .true.
          ! update informations structure related the new variable we want to add...
          iom_file(kiomid)%nvars         = idvar
@@ -449,5 +486,18 @@
          DO jd = 1, idims
             CALL iom_nf90_check(NF90_INQUIRE_DIMENSION( if90id, idimid(jd), len = iom_file(kiomid)%dimsz(jd,idvar) ), clinfo)
+            IF ( lchunk ) ichunksz(jd) = iom_file(kiomid)%dimsz(jd,idvar)
          END DO
+         IF ( lchunk ) THEN
+            ! Calculate chunk sizes by partitioning each dimension as requested in namnc4 namelist
+            ! Disallow very small chunk sizes and prevent chunk sizes larger than each individual dimension
+            ichunksz(1) = MIN( ichunksz(1),MAX( (ichunksz(1)-1)/snc4set%ni + 1 ,16 ) ) ! Suggested default nc4set%ni=4
+            ichunksz(2) = MIN( ichunksz(2),MAX( (ichunksz(2)-1)/snc4set%nj + 1 ,16 ) ) ! Suggested default nc4set%nj=2
+            ichunksz(3) = MIN( ichunksz(3),MAX( (ichunksz(3)-1)/snc4set%nk + 1 , 1 ) ) ! Suggested default nc4set%nk=6
+            ichunksz(4) = 1                                                            ! Do not allow chunks to span the
+                                                                                       ! unlimited dimension
+            CALL iom_nf90_check(NF90_DEF_VAR_CHUNKING(if90id, idvar, ichunkalg, ichunksz), clinfo)
+            CALL iom_nf90_check(NF90_DEF_VAR_DEFLATE(if90id, idvar, ishuffle, ideflate, ideflate_level), clinfo)
+            IF(lwp) WRITE(numout,*) TRIM(clinfo)//' chunked ok. Chunks sizes: ', ichunksz
+         ENDIF
          IF(lwp) WRITE(numout,*) TRIM(clinfo)//' defined ok'
       ELSE
@@ -529,4 +579,34 @@
    END SUBROUTINE iom_nf90_check
 
+#if ! defined key_netcdf4
+
+      !!--------------------------------------------------------------------
+      !! NOT 'key_netcdf4' Defines dummy routines for netcdf4
+      !!                   calls when compiling without netcdf4 libraries
+      !!--------------------------------------------------------------------
+
+   INTEGER FUNCTION NF90_DEF_VAR_CHUNKING(idum1, idum2, idum3, iarr1)
+      !!--------------------------------------------------------------------
+      !!                   ***  SUBROUTINE NF90_DEF_VAR_CHUNKING  ***
+      !!
+      !! ** Purpose :   Dummy NetCDF4 routine to enable compiling with NetCDF3 libraries
+      !!--------------------------------------------------------------------
+      INTEGER,               INTENT(in) :: idum1, idum2, idum3
+      INTEGER, DIMENSION(4), INTENT(in) :: iarr1
+      IF(lwp) WRITE(numout,*) 'Warning: Attempt to chunk output variable without NetCDF4 support'
+      NF90_DEF_VAR_CHUNKING = -1
+   END FUNCTION NF90_DEF_VAR_CHUNKING
+
+   INTEGER FUNCTION NF90_DEF_VAR_DEFLATE(idum1, idum2, idum3, idum4, idum5)
+      !!--------------------------------------------------------------------
+      !!                   ***  SUBROUTINE NF90_DEF_VAR_DEFLATE  ***
+      !!
+      !! ** Purpose :   Dummy NetCDF4 routine to enable compiling with NetCDF3 libraries
+      !!--------------------------------------------------------------------
+      INTEGER,               INTENT(in) :: idum1, idum2, idum3, idum4, idum5
+      IF(lwp) WRITE(numout,*) 'Warning: Attempt to compress output variable without NetCDF4 support'
+      NF90_DEF_VAR_DEFLATE = -1
+   END FUNCTION NF90_DEF_VAR_DEFLATE
+#endif
 
    !!======================================================================
Index: /branches/nemo_v3_3_beta/NEMOGCM/NEMO/OPA_SRC/IOM/restart.F90
===================================================================
--- /branches/nemo_v3_3_beta/NEMOGCM/NEMO/OPA_SRC/IOM/restart.F90	(revision 2363)
+++ /branches/nemo_v3_3_beta/NEMOGCM/NEMO/OPA_SRC/IOM/restart.F90	(revision 2364)
@@ -95,4 +95,5 @@
             CASE DEFAULT         ;   WRITE(numout,*) '             open ocean restart NetCDF file: '//clname
             END SELECT
+            IF ( snc4set%luse )      WRITE(numout,*) '             opened for NetCDF4 chunking and compression'
             IF( kt == nitrst - 1 ) THEN   ;   WRITE(numout,*) '             kt = nitrst - 1 = ', kt
             ELSE                          ;   WRITE(numout,*) '             kt = '             , kt
@@ -178,4 +179,5 @@
          CASE ( jprstdimg )   ;   WRITE(numout,*) 'rst_read : read oce binary restart file'
          END SELECT
+         IF ( snc4set%luse )      WRITE(numout,*) 'rst_read : configured with NetCDF4 support'
          WRITE(numout,*) '~~~~~~~~'
       ENDIF
Index: /branches/nemo_v3_3_beta/NEMOGCM/NEMO/OPA_SRC/TRD/trdmld.F90
===================================================================
--- /branches/nemo_v3_3_beta/NEMOGCM/NEMO/OPA_SRC/TRD/trdmld.F90	(revision 2363)
+++ /branches/nemo_v3_3_beta/NEMOGCM/NEMO/OPA_SRC/TRD/trdmld.F90	(revision 2364)
@@ -873,5 +873,5 @@
       IF(lwp) WRITE(numout,*) ' Name of NETCDF file ', clhstnam
       CALL histbeg( clhstnam, jpi, glamt, jpj, gphit,                                            &
-      &             1, jpi, 1, jpj, nit000-1, zjulian, rdt, nh_t, nidtrd, domain_id=nidom )
+      &             1, jpi, 1, jpj, nit000-1, zjulian, rdt, nh_t, nidtrd, domain_id=nidom, snc4chunks=snc4set )
 
       !-- Define the ML depth variable
@@ -925,5 +925,5 @@
 
       !-- Leave IOIPSL/NetCDF define mode
-      CALL histend( nidtrd )
+      CALL histend( nidtrd, snc4set )
 
 #endif        /* key_dimgout */
Index: /branches/nemo_v3_3_beta/NEMOGCM/NEMO/OPA_SRC/TRD/trdvor.F90
===================================================================
--- /branches/nemo_v3_3_beta/NEMOGCM/NEMO/OPA_SRC/TRD/trdvor.F90	(revision 2363)
+++ /branches/nemo_v3_3_beta/NEMOGCM/NEMO/OPA_SRC/TRD/trdvor.F90	(revision 2364)
@@ -568,5 +568,5 @@
       IF(lwp) WRITE(numout,*) ' Name of NETCDF file ', clhstnam
       CALL histbeg( clhstnam, jpi, glamf, jpj, gphif,1, jpi,   &  ! Horizontal grid : glamt and gphit
-         &          1, jpj, nit000-1, zjulian, rdt, nh_t, nidvor, domain_id=nidom )
+         &          1, jpj, nit000-1, zjulian, rdt, nh_t, nidvor, domain_id=nidom, snc4chunks=snc4set )
       CALL wheneq( jpi*jpj, fmask, 1, 1., ndexvor1, ndimvor1 )    ! surface
 
@@ -598,5 +598,5 @@
       CALL histdef( nidvor, "sovorgap", cvort//"gap", "s-2",             & ! gap between 1st and 2 nd mbre
          &          jpi,jpj,nh_t,1,1,1,-99,32,clop,zsto,zout)
-      CALL histend( nidvor )
+      CALL histend( nidvor, snc4set )
 
       IF( idebug /= 0 ) THEN
Index: /branches/nemo_v3_3_beta/NEMOGCM/NEMO/TOP_SRC/SED/sedwri.F90
===================================================================
--- /branches/nemo_v3_3_beta/NEMOGCM/NEMO/TOP_SRC/SED/sedwri.F90	(revision 2363)
+++ /branches/nemo_v3_3_beta/NEMOGCM/NEMO/TOP_SRC/SED/sedwri.F90	(revision 2364)
@@ -186,5 +186,5 @@
          CALL histbeg ( clhstnam, jpi, glamt, jpj, gphit,     &
             &             iimi, iima-iimi+1, ijmi, ijma-ijmi+1,         &
-            &             nitsed000-1, zjulian, zdt,  nhorised, nised , domain_id=nidom )
+            &             nitsed000-1, zjulian, zdt,  nhorised, nised , domain_id=nidom, snc4chunks=snc4set )
          CALL histvert( nised,'deptht','Vertic.sed.T levels','m',ipk, profsed, ndepsed, 'down' )
          CALL wheneq  ( jpi*jpj*ipk, tmasksed, 1, 1., ndext52, ndimt52 )
@@ -223,5 +223,5 @@
 
 
-         CALL histend( nised )
+         CALL histend( nised, snc4set )
 
          WRITE(numsed,*)
Index: /branches/nemo_v3_3_beta/NEMOGCM/NEMO/TOP_SRC/TRP/trdmld_trc.F90
===================================================================
--- /branches/nemo_v3_3_beta/NEMOGCM/NEMO/TOP_SRC/TRP/trdmld_trc.F90	(revision 2363)
+++ /branches/nemo_v3_3_beta/NEMOGCM/NEMO/TOP_SRC/TRP/trdmld_trc.F90	(revision 2364)
@@ -1304,5 +1304,5 @@
             CALL dia_nam( clhstnam, nn_trd_trc, csuff )
             CALL histbeg( clhstnam, jpi, glamt, jpj, gphit,                                            &
-               &        1, jpi, 1, jpj, nit000, zjulian, rdt, nh_t(jn), nidtrd(jn), domain_id=nidom )
+               &        1, jpi, 1, jpj, nit000, zjulian, rdt, nh_t(jn), nidtrd(jn), domain_id=nidom, snc4chunks=snc4set )
       
             !-- Define the ML depth variable
@@ -1317,5 +1317,5 @@
           CALL dia_nam( clhstnam, nn_trd_trc, 'trdbio' )
           CALL histbeg( clhstnam, jpi, glamt, jpj, gphit,                                            &
-             &             1, jpi, 1, jpj, nit000, zjulian, rdt, nh_tb, nidtrdbio, domain_id=nidom )
+             &             1, jpi, 1, jpj, nit000, zjulian, rdt, nh_tb, nidtrdbio, domain_id=nidom, snc4chunks=snc4set )
 #endif
 
@@ -1368,10 +1368,10 @@
       !-- Leave IOIPSL/NetCDF define mode
       DO jn = 1, jptra
-         IF( ln_trdtrc(jn) )  CALL histend( nidtrd(jn) )
+         IF( ln_trdtrc(jn) )  CALL histend( nidtrd(jn), snc4set )
       END DO
 
 #if defined key_lobster
       !-- Leave IOIPSL/NetCDF define mode
-      CALL histend( nidtrdbio )
+      CALL histend( nidtrdbio, snc4set )
 
       IF(lwp) WRITE(numout,*)
Index: /branches/nemo_v3_3_beta/NEMOGCM/NEMO/TOP_SRC/trcdia.F90
===================================================================
--- /branches/nemo_v3_3_beta/NEMOGCM/NEMO/TOP_SRC/trcdia.F90	(revision 2363)
+++ /branches/nemo_v3_3_beta/NEMOGCM/NEMO/TOP_SRC/trcdia.F90	(revision 2364)
@@ -176,5 +176,5 @@
          CALL histbeg( clhstnam, jpi, glamt, jpj, gphit,     &
             &          iimi, iima-iimi+1, ijmi, ijma-ijmi+1,         & 
-            &          iiter, zjulian, zdt, nhorit5, nit5 , domain_id=nidom)
+            &          iiter, zjulian, zdt, nhorit5, nit5 , domain_id=nidom, snc4chunks=snc4set)
 
          ! Vertical grid for tracer : gdept
@@ -197,5 +197,5 @@
 
          ! end netcdf files header
-         CALL histend( nit5 )
+         CALL histend( nit5, snc4set )
          IF(lwp) WRITE(numout,*)
          IF(lwp) WRITE(numout,*) 'End of NetCDF Initialization in trcdit_wr'
@@ -303,5 +303,5 @@
          CALL histbeg( clhstnam, jpi, glamt, jpj, gphit,             &
             &          iimi, iima-iimi+1, ijmi, ijma-ijmi+1,         &
-            &          iiter, zjulian, zdt, nhoritd, nitd , domain_id=nidom )
+            &          iiter, zjulian, zdt, nhoritd, nitd , domain_id=nidom, snc4chunks=snc4set )
 
          ! Vertical grid for 2d and 3d arrays
@@ -332,5 +332,5 @@
 
          ! CLOSE netcdf Files
-         CALL histend( nitd )
+         CALL histend( nitd, snc4set )
 
          IF(lwp) WRITE(numout,*)
@@ -449,5 +449,5 @@
          CALL histbeg( clhstnam, jpi, glamt, jpj, gphit,      &
             &    iimi, iima-iimi+1, ijmi, ijma-ijmi+1,          &
-            &    iiter, zjulian, zdt, nhoritb, nitb , domain_id=nidom )
+            &    iiter, zjulian, zdt, nhoritb, nitb , domain_id=nidom, snc4chunks=snc4set )
          ! Vertical grid for biological trends
          CALL histvert(nitb, 'deptht', 'Vertical T levels', 'm', ipk, gdept_0, ndepitb)
@@ -464,5 +464,5 @@
 
          ! CLOSE netcdf Files
-          CALL histend( nitb )
+          CALL histend( nitb, snc4set )
 
          IF(lwp) WRITE(numout,*)
