Index: XMLIO_V2/dev/common/src/xmlio/output/nc4_data_output.cpp
===================================================================
--- XMLIO_V2/dev/common/src/xmlio/output/nc4_data_output.cpp	(revision 278)
+++ XMLIO_V2/dev/common/src/xmlio/output/nc4_data_output.cpp	(revision 286)
@@ -29,27 +29,18 @@
 
       CNc4DataOutput::CNc4DataOutput
-         (const StdString & filename, bool exist, bool multigroup, MPI_Comm comm_server)
+         (const StdString & filename, bool exist, MPI_Comm comm_server,bool multifile)
             : SuperClass()
-            , SuperClassWriter(filename, exist, &comm_server)
+            , SuperClassWriter(filename, exist, &comm_server,multifile)
             , comm_server(comm_server)
             , filename(filename)
       {
          StdString timeid = StdString("time_counter");
-         SuperClass::type = (multigroup) ? MULTI_GROUP : ONE_FILE;
+
+         SuperClass::type = (multifile) ? MULTI_FILE : ONE_FILE;
+         
          if (!exist)
             SuperClassWriter::addDimension(timeid);
       }
 
-      CNc4DataOutput::CNc4DataOutput
-         (const StdString & filename, bool exist, bool multigroup, comm::MPIComm comm_server, bool)
-            : SuperClass()
-            , SuperClassWriter(filename, exist, &comm_server, true)
-            , filename(filename)
-      {
-         StdString timeid = StdString("time_counter");
-         SuperClass::type = (multigroup) ? MULTI_GROUP : ONE_FILE;
-         if (!exist)
-            SuperClassWriter::addDimension(timeid);
-      }
 
       CNc4DataOutput::~CNc4DataOutput(void)
@@ -70,5 +61,5 @@
          domain->checkAttributes();
          
-         if (domain->isEmpty()) return;
+//         if (domain->isEmpty()) return;
 
          std::vector<StdString> dim0, dim1;
@@ -90,25 +81,28 @@
          bool isCurvilinear = (domain->lonvalue.getValue()->size() == ssize);
 
-         if (comm::CMPIManager::GetCommSize(CXIOSManager::Comm_Server) > 1)
-         {
-            SuperClassWriter::addDimension(lonid, domain->zoom_ni.getValue());
-            SuperClassWriter::addDimension(latid, domain->zoom_nj.getValue());
-         }
-
-         if (isCurvilinear)
-         {
-            dim0.push_back(latid_loc); dim0.push_back(lonid_loc);
-            lonid = StdString("nav_lon_").append(domid);
-            latid = StdString("nav_lat_").append(domid);
-         }
-         else
-         {
-            dim0.push_back(latid_loc);
-            dim1.push_back(lonid_loc);
-         }
          switch (SuperClass::type)
          {
             case (MULTI_FILE) :
             {
+               if (domain->isEmpty()) return;
+               
+               if (comm::CMPIManager::GetCommSize(CXIOSManager::Comm_Server) > 1)
+               {
+                 SuperClassWriter::addDimension(lonid, domain->zoom_ni.getValue());
+                 SuperClassWriter::addDimension(latid, domain->zoom_nj.getValue());
+               }
+
+               if (isCurvilinear)
+               {
+                 dim0.push_back(latid_loc); dim0.push_back(lonid_loc);
+                 lonid = StdString("nav_lon_").append(domid);
+                 latid = StdString("nav_lat_").append(domid);
+               }
+               else
+               {
+                 dim0.push_back(latid_loc);
+                 dim1.push_back(lonid_loc);
+               }
+
                SuperClassWriter::addDimension(lonid_loc, domain->zoom_ni_loc.getValue());
                SuperClassWriter::addDimension(latid_loc, domain->zoom_nj_loc.getValue());
@@ -133,7 +127,7 @@
                }
                this->writeAxisAttributes
-                  (latid, "X", "longitude", "Longitude", "degrees_east", domid);
+                  (lonid, "X", "longitude", "Longitude", "degrees_east", domid);
                this->writeAxisAttributes
-                  (lonid, "Y", "latitude", "Latitude", "degrees_north", domid);
+                  (latid, "Y", "latitude", "Latitude", "degrees_north", domid);
 
                dim0.clear();
@@ -164,4 +158,51 @@
                break;
             }
+            case (ONE_FILE) :
+            {
+               SuperClassWriter::addDimension(lonid, domain->zoom_ni.getValue());
+               SuperClassWriter::addDimension(latid, domain->zoom_nj.getValue());
+
+               
+               if (isCurvilinear)
+               {
+                  dim0.push_back(latid); dim0.push_back(lonid);
+                  lonid = StdString("nav_lon_").append(domid);
+                  latid = StdString("nav_lat_").append(domid);
+                  SuperClassWriter::addVariable(latid, NC_FLOAT, dim0);
+                  SuperClassWriter::addVariable(lonid, NC_FLOAT, dim0);
+               }
+               else
+               {
+                  dim0.push_back(latid);
+                  dim1.push_back(lonid);
+                  SuperClassWriter::addVariable(latid, NC_FLOAT, dim0);
+                  SuperClassWriter::addVariable(lonid, NC_FLOAT, dim1);
+               }
+               this->writeAxisAttributes
+                  (latid, "X", "longitude", "Longitude", "degrees_east", domid);
+               this->writeAxisAttributes
+                  (lonid, "Y", "latitude", "Latitude", "degrees_north", domid);
+
+
+               SuperClassWriter::definition_end();
+               std::vector<StdSize> start(2) ; 
+               std::vector<StdSize> count(2) ;
+               if (domain->isEmpty())
+               {
+                 start[0]=0 ; start [1]=0 ; 
+                 count[0]=0 ; count[1]=0 ; 
+               }
+               else
+               {
+                 start[1]=domain->zoom_ibegin_loc.getValue()+domain->ibegin.getValue()-1-domain->zoom_ibegin.getValue() ; start [0]=domain->zoom_jbegin_loc.getValue()+domain->jbegin.getValue()-1-domain->zoom_jbegin.getValue() ; 
+                 count[1]=domain->zoom_ni_loc.getValue() ; count[0]=domain->zoom_nj_loc.getValue() ; 
+               }
+               
+               SuperClassWriter::writeData(domain->latvalue.getValue(), latid, true, 0,&start,&count);
+               SuperClassWriter::writeData(domain->lonvalue.getValue(), lonid, true, 0,&start,&count);
+               SuperClassWriter::definition_start();
+
+               break;
+            }           
             default :
                ERROR("CNc4DataOutput::writeDomain(domain)",
@@ -183,9 +224,10 @@
          SuperClassWriter::addDimension(axisid, axis->size.getValue());
          dims.push_back(axisid);
-
+         
          switch (SuperClass::type)
          {
+            case (MULTI_FILE ) :
+            {}
             case (ONE_FILE) :
-            case (MULTI_FILE) :
             {
                SuperClassWriter::addVariable(axisid, NC_FLOAT, dims);
@@ -228,6 +270,7 @@
          boost::shared_ptr<CDomain> domain =
             CObjectFactory::GetObject<CDomain>(grid->domain_ref.getValue());
-            
-         if (domain->isEmpty()) return;
+           
+         if (domain->isEmpty()) 
+           if (SuperClass::type==MULTI_FILE) return ;
 
          StdString timeid    = StdString("time_counter");
@@ -291,62 +334,10 @@
                dims.push_back(latid_loc);
                dims.push_back(lonid_loc);
-               SuperClassWriter::addVariable(fieldid, type, dims);
-
-               if (!field->standard_name.isEmpty())
-                  SuperClassWriter::addAttribute
-                     ("standard_name",  field->standard_name.getValue(), &fieldid);
-
-               if (!field->long_name.isEmpty())
-                  SuperClassWriter::addAttribute
-                     ("long_name", field->long_name.getValue(), &fieldid);
-
-               if (!field->unit.isEmpty())
-                  SuperClassWriter::addAttribute
-                     ("units", field->unit.getValue(), &fieldid);
-                     
-               SuperClassWriter::addAttribute
-                     ("online_operation", field->operation.getValue(), &fieldid);
-                     
-               if (wtime)
-               {
-                  SuperClassWriter::addAttribute
-                        ("interval_operation", field->freq_op.getValue(), &fieldid);
-                  SuperClassWriter::addAttribute
-                        ("interval_write", field->getRelFile()->output_freq.getValue(), &fieldid);
-               }
-               
-               if (!field->default_value.isEmpty())
-               {
-                  double default_value = field->default_value.getValue();
-                  float fdefault_value = (float)default_value;
-                  if (type == NC_DOUBLE)
-                     SuperClassWriter::setDefaultValue(fieldid, &default_value);
-                  else
-                     SuperClassWriter::setDefaultValue(fieldid, &fdefault_value);
-               }
-               else
-               {
-                  double * default_value = NULL;
-                  SuperClassWriter::setDefaultValue(fieldid, default_value);
-               }             
-
-               {  // Ecriture des coordonnÃ©es
-               
-                  StdString coordstr; //boost::algorithm::join(coodinates, " ")
-                  std::vector<StdString>::iterator 
-                     itc = coodinates.begin(), endc = coodinates.end();
-                  
-                  for (; itc!= endc; itc++)
-                  {
-                     StdString & coord = *itc;
-                     if (itc+1 != endc)
-                           coordstr.append(coord).append(" ");
-                     else  coordstr.append(coord);
-                  }
-
-                  SuperClassWriter::addAttribute("coordinates", coordstr, &fieldid);
-
-               }
-
+               break ;
+            }
+            case (ONE_FILE) :
+            {
+               dims.push_back(latid);
+               dims.push_back(lonid);
                break;
             }
@@ -356,4 +347,63 @@
                      << " not implemented yet !");
          }
+          
+         SuperClassWriter::addVariable(fieldid, type, dims);
+         
+         if (!field->standard_name.isEmpty())
+            SuperClassWriter::addAttribute
+               ("standard_name",  field->standard_name.getValue(), &fieldid);
+
+         if (!field->long_name.isEmpty())
+            SuperClassWriter::addAttribute
+               ("long_name", field->long_name.getValue(), &fieldid);
+
+         if (!field->unit.isEmpty())
+            SuperClassWriter::addAttribute
+               ("units", field->unit.getValue(), &fieldid);
+               
+         SuperClassWriter::addAttribute
+               ("online_operation", field->operation.getValue(), &fieldid);
+               
+         if (wtime)
+         {
+            SuperClassWriter::addAttribute
+                  ("interval_operation", field->freq_op.getValue(), &fieldid);
+            SuperClassWriter::addAttribute
+                  ("interval_write", field->getRelFile()->output_freq.getValue(), &fieldid);
+         }
+         
+         if (!field->default_value.isEmpty())
+         {
+            double default_value = field->default_value.getValue();
+            float fdefault_value = (float)default_value;
+            if (type == NC_DOUBLE)
+               SuperClassWriter::setDefaultValue(fieldid, &default_value);
+            else
+               SuperClassWriter::setDefaultValue(fieldid, &fdefault_value);
+         }
+         else
+         {
+            double * default_value = NULL;
+            SuperClassWriter::setDefaultValue(fieldid, default_value);
+         }             
+
+         {  // Ecriture des coordonnÃ©es
+         
+            StdString coordstr; //boost::algorithm::join(coodinates, " ")
+            std::vector<StdString>::iterator 
+               itc = coodinates.begin(), endc = coodinates.end();
+            
+            for (; itc!= endc; itc++)
+            {
+               StdString & coord = *itc;
+               if (itc+1 != endc)
+                     coordstr.append(coord).append(" ");
+               else  coordstr.append(coord);
+            }
+
+            SuperClassWriter::addAttribute("coordinates", coordstr, &fieldid);
+
+         }
+
       }
 
@@ -373,4 +423,10 @@
       }
 
+      void CNc4DataOutput::closeFile_ (void)
+      {
+         std::cout<<"--> Close file "<<filename<<std::endl ;
+         SuperClassWriter::close() ;
+      }
+
       //---------------------------------------------------------------
 
@@ -395,4 +451,10 @@
          boost::shared_ptr<CGrid> grid =
             CObjectFactory::GetObject<CGrid>(field->grid_ref.getValue());
+         boost::shared_ptr<CDomain> domain =
+            CObjectFactory::GetObject<CDomain>(grid->domain_ref.getValue());
+         
+         if(SuperClass::type==MULTI_FILE) if (domain->isEmpty()) return;
+
+
          StdString fieldid   = (!field->name.isEmpty())
                              ? field->name.getValue() 
@@ -412,8 +474,35 @@
          if (grid->hasAxis()) // 3D
          {
+            boost::shared_ptr<CAxis> axis = CObjectFactory::GetObject<CAxis>(grid->axis_ref.getValue());
             ARRAY(double, 3) field_data3D (new CArray<double,3>(grid->getLocalShape()/*, boost::c_storage_order()*/));            
             grid->outputField(field_data, field_data3D);
-            SuperClassWriter::writeData(field_data3D, fieldid, true, field->getNStep()-1);
-            SuperClassWriter::writeData(time_data, oss.str(), true, field->getNStep()-1);
+            switch (SuperClass::type)
+           {
+              case (MULTI_FILE) :
+              {
+                 SuperClassWriter::writeData(field_data3D, fieldid, true, field->getNStep()-1);
+                 SuperClassWriter::writeData(time_data, oss.str(), true, field->getNStep()-1);
+                 break ;
+              }
+              case (ONE_FILE) :
+              {
+                 std::vector<StdSize> start(3) ; 
+                 std::vector<StdSize> count(3) ;
+                 if (domain->isEmpty())
+                 {
+                   start[0]=0 ; start[1]=0 ; start[2]=0 ;
+                   count[0]=0 ; count[1]=0 ; start[2]=0 ;
+                 }
+                 else
+                 {
+//                 start[2]=domain->zoom_ibegin_loc.getValue()-domain->zoom_ibegin.getValue() ; start [1]=domain->zoom_jbegin_loc.getValue()-domain->zoom_jbegin.getValue() ; start[0]=0 ;
+                   start[2]=domain->zoom_ibegin_loc.getValue()+domain->ibegin.getValue()-1-domain->zoom_ibegin.getValue() ; start [1]=domain->zoom_jbegin_loc.getValue()+domain->jbegin.getValue()-1-domain->zoom_jbegin.getValue() ; start[0]=0 ; 
+                   count[2]=domain->zoom_ni_loc.getValue() ; count[1]=domain->zoom_nj_loc.getValue() ; count[0] = axis->size.getValue();
+                 }
+                 SuperClassWriter::writeData(field_data3D, fieldid, true, field->getNStep()-1,&start,&count );
+                 SuperClassWriter::writeData(time_data, oss.str(), true, field->getNStep()-1 );
+                 break;
+              }
+            }
             
          }
@@ -422,6 +511,32 @@
             ARRAY(double, 2) field_data2D (new CArray<double, 2>(grid->getLocalShape()/*, boost::c_storage_order()*/));
             grid->outputField(field_data,  field_data2D);
-            SuperClassWriter::writeData(field_data2D, fieldid, true, field->getNStep()-1);
-            SuperClassWriter::writeData(time_data, oss.str(), true, field->getNStep()-1);
+            switch (SuperClass::type)
+            {
+              case (MULTI_FILE) :
+              {
+                SuperClassWriter::writeData(field_data2D, fieldid, true, field->getNStep()-1);
+                SuperClassWriter::writeData(time_data, oss.str(), true, field->getNStep()-1);
+                break;
+              }
+              case (ONE_FILE) :
+              {
+                 std::vector<StdSize> start(2) ; 
+                 std::vector<StdSize> count(2) ;
+                 if (domain->isEmpty())
+                 {
+                   start[0]=0 ; start[1]=0 ;
+                   count[0]=0 ; count[1]=0 ;
+                 }
+                 else
+                 {
+                   start[1]=domain->zoom_ibegin_loc.getValue()+domain->ibegin.getValue()-1-domain->zoom_ibegin.getValue() ; start [0]=domain->zoom_jbegin_loc.getValue()+domain->jbegin.getValue()-1-domain->zoom_jbegin.getValue() ; 
+                   count[1]=domain->zoom_ni_loc.getValue() ; count[0]=domain->zoom_nj_loc.getValue() ; 
+                 }
+                 SuperClassWriter::writeData(field_data2D, fieldid, true, field->getNStep()-1,&start,&count);
+                 SuperClassWriter::writeData(time_data, oss.str(), true, field->getNStep()-1);
+                 break;
+              
+              }
+            }
          }
       }
Index: XMLIO_V2/dev/common/src/xmlio/output/nc4_data_output.hpp
===================================================================
--- XMLIO_V2/dev/common/src/xmlio/output/nc4_data_output.hpp	(revision 278)
+++ XMLIO_V2/dev/common/src/xmlio/output/nc4_data_output.hpp	(revision 286)
@@ -27,7 +27,5 @@
                (const StdString & filename, bool exist);
             CNc4DataOutput
-               (const StdString & filename, bool exist, bool multigroup, MPI_Comm comm_server);
-            CNc4DataOutput
-               (const StdString & filename, bool exist, bool multigroup, comm::MPIComm comm_server, bool);
+               (const StdString & filename, bool exist, MPI_Comm comm_server, bool multifile);
 
             CNc4DataOutput(const CNc4DataOutput & dataoutput);       // Not implemented.
@@ -48,4 +46,5 @@
             virtual void writeFieldData_ (const boost::shared_ptr<tree::CField>    field);
             virtual void writeFile_      (const boost::shared_ptr<tree::CFile>     file);
+            virtual void closeFile_      (void);
             virtual void writeTimeAxis_  (const boost::shared_ptr<tree::CField>    field,
                                           const boost::shared_ptr<date::CCalendar> cal);
Index: XMLIO_V2/dev/common/src/xmlio/output/onetcdf4.cpp
===================================================================
--- XMLIO_V2/dev/common/src/xmlio/output/onetcdf4.cpp	(revision 278)
+++ XMLIO_V2/dev/common/src/xmlio/output/onetcdf4.cpp	(revision 286)
@@ -1,4 +1,5 @@
 #include "onetcdf4.hpp"
 #include "group_template_impl.hpp"
+#include "mpi_manager.hpp"
 
 namespace xmlioserver
@@ -9,33 +10,18 @@
 
       CONetCDF4::CONetCDF4
-         (const StdString & filename, bool exist, const MPI_Comm * comm)
+         (const StdString & filename, bool exist, const MPI_Comm * comm, bool multifile)
             : path()
       {
-         this->wmpi = (comm != NULL);
-         this->initialize(filename, exist, comm);
-      }
-      
-      //---------------------------------------------------------------
-      
-      CONetCDF4::CONetCDF4
-         (const StdString & filename, bool exist, const comm::MPIComm * comm, bool)
-         : path()
-      {
-         this->wmpi = (comm != NULL);
-         MPI_Comm * null_comm = NULL;
-         if (comm == NULL)
-            this->initialize(filename, exist, null_comm);
-         else
-         {
-            MPI_Comm comm_c = MPI_Comm_f2c(*comm);
-            this->initialize(filename, exist, &comm_c);
-         }
-      }
-      
-      //---------------------------------------------------------------
-      
+         this->wmpi = (comm != NULL) && !multifile;
+         this->initialize(filename, exist, comm,multifile);
+      }
+      
+      //---------------------------------------------------------------
+      
+      
+
       CONetCDF4::~CONetCDF4(void)
       {
-         CheckError(nc_close(this->ncidp));
+//         CheckError(nc_close(this->ncidp));
       }
 
@@ -43,5 +29,5 @@
 
       void CONetCDF4::initialize
-         (const StdString & filename, bool exist, const MPI_Comm * comm)
+         (const StdString & filename, bool exist, const MPI_Comm * comm, bool multifile)
       {
          if (!exist)
@@ -49,6 +35,6 @@
             if (comm != NULL)
             {
-               CheckError(nc_create_par
-                  (filename.c_str(), NC_NETCDF4|NC_MPIIO, *comm, MPI_INFO_NULL, &this->ncidp));
+               if (!multifile) CheckError(nc_create_par(filename.c_str(), NC_NETCDF4|NC_MPIIO, *comm, MPI_INFO_NULL, &this->ncidp));
+               else CheckError(nc_create(filename.c_str(), NC_NETCDF4, &this->ncidp));
             }
             else CheckError(nc_create(filename.c_str(), NC_NETCDF4, &this->ncidp));
@@ -57,8 +43,15 @@
          {
             if (comm != NULL)
-               CheckError(nc_open_par
-                  (filename.c_str(), NC_NETCDF4|NC_MPIIO, *comm, MPI_INFO_NULL, &this->ncidp));
+            {
+               if (!multifile) CheckError(nc_open_par(filename.c_str(), NC_NETCDF4|NC_MPIIO, *comm, MPI_INFO_NULL, &this->ncidp));
+               else CheckError(nc_open(filename.c_str(), NC_NETCDF4, &this->ncidp));
+            }
             else  CheckError(nc_open(filename.c_str(), NC_NETCDF4, &this->ncidp));
          }
+      }
+      
+      void CONetCDF4::close()
+      {
+        CheckError(nc_close(this->ncidp));
       }
       
@@ -262,4 +255,5 @@
             dimids.push_back(this->getDimension(dimid));
          }
+         std::cout<<"--> Var "<<name.c_str()<<std::endl ;
          CheckError(nc_def_var (grpid, name.c_str(), type, dimids.size(), &(dimids[0]), &retvalue));
          return (retvalue);
@@ -352,5 +346,8 @@
          }
          
-         
+//         if (iddims.begin()->compare(this->getUnlimitedDimensionName()) == 0)
+//         {
+//            if (array_size==0) scount[0]=0 ;
+//         }         
 //         for (StdSize u = 0; u < sstart.size(); u++)
 //            std::cout << "(" << sstart[u] << "," << scount[u]  << ")" ;
@@ -366,4 +363,5 @@
       {
          CheckError(nc_put_vara_double(grpid, varid, &(sstart[0]), &(scount[0]), data));
+//         sync() ;
       }
       
@@ -376,4 +374,5 @@
       {
           CheckError(nc_put_vara_int(grpid, varid, &(sstart[0]), &(scount[0]), data));
+//          sync() ;
       }
       
@@ -386,4 +385,5 @@
       {
           CheckError(nc_put_vara_float(grpid, varid, &(sstart[0]), &(scount[0]), data));
+//          sync() ;
       }
 
@@ -410,4 +410,10 @@
       }
 
+      void CONetCDF4::sync(void)
+      {
+        
+         comm::CMPIManager::Barrier(comm::CMPIManager::GetCommServer());
+         CheckError(nc_sync(this->ncidp)) ;
+      } 
       ///--------------------------------------------------------------
    } // namespace io
Index: XMLIO_V2/dev/common/src/xmlio/output/onetcdf4.hpp
===================================================================
--- XMLIO_V2/dev/common/src/xmlio/output/onetcdf4.hpp	(revision 278)
+++ XMLIO_V2/dev/common/src/xmlio/output/onetcdf4.hpp	(revision 286)
@@ -35,6 +35,5 @@
 
             /// Constructeurs ///
-            CONetCDF4(const StdString & filename, bool exist, const MPI_Comm * comm = NULL);
-            CONetCDF4(const StdString & filename, bool exist, const comm::MPIComm * comm, bool);
+            CONetCDF4(const StdString & filename, bool exist, const MPI_Comm * comm = NULL, bool multifile=true);
 
             CONetCDF4(const CONetCDF4 & onetcdf4);       // Not implemented.
@@ -43,5 +42,7 @@
 
             /// Initialisation ///
-            void initialize(const StdString & filename, bool exist, const MPI_Comm * comm);
+            void initialize(const StdString & filename, bool exist, const MPI_Comm * comm, bool multifile);
+            void close(void) ;
+            void sync(void) ;
             void definition_start(void);
             void definition_end(void);
