Index: /XIOS/trunk/src/data_output.cpp
===================================================================
--- /XIOS/trunk/src/data_output.cpp	(revision 320)
+++ /XIOS/trunk/src/data_output.cpp	(revision 321)
@@ -42,4 +42,9 @@
       {
          this->writeFile_(file);
+      }
+ 
+      void CDataOutput::syncFile(void)
+      {
+         this->syncFile_();
       }
 
Index: /XIOS/trunk/src/data_output.hpp
===================================================================
--- /XIOS/trunk/src/data_output.hpp	(revision 320)
+++ /XIOS/trunk/src/data_output.hpp	(revision 321)
@@ -25,4 +25,5 @@
             /// Ecriture ///
             void writeFile     (const boost::shared_ptr<tree::CFile>  file);
+            void syncFile     (void);
             void closeFile     (void);
             void writeField    (const boost::shared_ptr<tree::CField> field);
@@ -45,4 +46,5 @@
             virtual void writeFile_       (const boost::shared_ptr<tree::CFile>     file)   = 0;
             virtual void closeFile_       (void)                                            = 0;
+            virtual void syncFile_       (void)                                            = 0;
             virtual void writeField_      (const boost::shared_ptr<tree::CField>    field)  = 0;
             virtual void writeFieldData_  (const boost::shared_ptr<tree::CField>    field)  = 0;
Index: /XIOS/trunk/src/date.cpp
===================================================================
--- /XIOS/trunk/src/date.cpp	(revision 320)
+++ /XIOS/trunk/src/date.cpp	(revision 321)
@@ -194,4 +194,18 @@
       //----------------------------------------------------------------
       
+      StdString CDate::getStryyyymmdd(void) const
+      { 
+         std::streamsize s ; 
+         char c ;
+
+         ostringstream oss ;
+
+         s = oss.width (4);  c = oss.fill ('0') ; oss << year ;
+         s = oss.width (2);  c = oss.fill ('0') ; oss << month;
+         s = oss.width (2);  c = oss.fill ('0') ; oss << day ;
+
+         return oss.str();
+      }
+      
        StdString CDate::toString(void) const
       { 
Index: /XIOS/trunk/src/date.hpp
===================================================================
--- /XIOS/trunk/src/date.hpp	(revision 320)
+++ /XIOS/trunk/src/date.hpp	(revision 321)
@@ -57,4 +57,5 @@
             /// Autres ///
             StdString toString(void) const;
+            StdString getStryyyymmdd(void) const;
 
          public : /* static */
Index: /XIOS/trunk/src/node/context.cpp
===================================================================
--- /XIOS/trunk/src/node/context.cpp	(revision 320)
+++ /XIOS/trunk/src/node/context.cpp	(revision 321)
@@ -544,30 +544,5 @@
       for (it=enabledFiles.begin(); it != enabledFiles.end(); it++)
       {
-/*         shared_ptr<CFile> file = *it;
-         StdString filename = (!file->name.isEmpty()) ?   file->name.getValue() : file->getId();
-         StdOStringStream oss;
-         if (! output_dir.isEmpty()) oss << output_dir.getValue();
-         oss << filename;
-         if (!file->name_suffix.isEmpty()) oss << file->name_suffix.getValue();
-
-         bool multifile=true ;
-         if (!file->type.isEmpty())
-         {
-           StdString str=file->type.getValue() ; 
-           if (str.compare("one_file")==0) multifile=false ;
-           else if (str.compare("multi_file")==0) multifile=true ;
-           else ERROR("void Context::createDataOutput(void)",
-                      "incorrect file <type> attribut : must be <multi_file> or <one_file>, "
-                      <<"having : <"<<str<<">") ;
-         } 
-         if (multifile) 
-         {
-            if (server->intraCommSize > 1) oss << "_" << server->intraCommRank;
-         }
-         oss << ".nc";
-
-         shared_ptr<io::CDataOutput> dout(new T(oss.str(), false,server->intraComm,multifile));
-*/
-         (*it)->createHeader();
+         (*it)->initFile();
       }
    } 
Index: /XIOS/trunk/src/node/field.cpp
===================================================================
--- /XIOS/trunk/src/node/field.cpp	(revision 320)
+++ /XIOS/trunk/src/node/field.cpp	(revision 321)
@@ -176,5 +176,4 @@
       }
       
-      this->incrementNStep();
       *last_Write_srv = writeDate;
       writeField() ;
@@ -184,6 +183,10 @@
   void CField::writeField(void)
   {
-    if (! grid->domain->isEmpty() || getRelFile()->type.getValue()=="one_file") 
+    if (! grid->domain->isEmpty() || getRelFile()->type.getValue()=="one_file")
+    {
+      getRelFile()->checkFile();
+      this->incrementNStep();
       getRelFile()->getDataOutput()->writeFieldData(CObjectFactory::GetObject<CField>(this));
+    }
   }
    //----------------------------------------------------------------
@@ -222,4 +225,9 @@
    {
       this->nstep++;
+   }
+ 
+   void CField::resetNStep(void)
+   {
+      this->nstep=0;
    }
 
Index: /XIOS/trunk/src/node/field.hpp
===================================================================
--- /XIOS/trunk/src/node/field.hpp	(revision 320)
+++ /XIOS/trunk/src/node/field.hpp	(revision 321)
@@ -88,4 +88,5 @@
          void setRelFile(const boost::shared_ptr<CFile> _file);
          void incrementNStep(void);
+         void resetNStep() ;
 
          template <StdSize N> bool updateData(const ARRAY(double, N)   data);
Index: /XIOS/trunk/src/node/file.cpp
===================================================================
--- /XIOS/trunk/src/node/file.cpp	(revision 320)
+++ /XIOS/trunk/src/node/file.cpp	(revision 321)
@@ -141,11 +141,66 @@
       return false ;
     }
-      
+    
+   void CFile::initFile(void)
+   {
+      shared_ptr<CContext> context=CObjectFactory::GetObject<CContext>(CObjectFactory::GetCurrentContextId()) ;
+      date::CDate& currentDate=context->calendar->getCurrentDate() ;
+      
+      if (! sync_freq.isEmpty()) syncFreq = date::CDuration::FromString(sync_freq.getValue());
+      if (! split_freq.isEmpty()) splitFreq = date::CDuration::FromString(split_freq.getValue());
+      if (! output_freq.isEmpty()) outputFreq = date::CDuration::FromString(output_freq.getValue());
+      lastSync=new date::CDate(currentDate) ;
+      lastSplit=new date::CDate(currentDate) ;
+      isOpen=false ;
+    }
+    
+    void CFile::checkFile(void)
+    {
+      if (!isOpen) createHeader() ;
+      checkSync() ;
+      checkSplit() ;
+    }
+      
+     
+   bool CFile::checkSync(void)
+   {
+     shared_ptr<CContext> context=CObjectFactory::GetObject<CContext>(CObjectFactory::GetCurrentContextId()) ;
+     date::CDate& currentDate=context->calendar->getCurrentDate() ;
+     if (! sync_freq.isEmpty())
+     {
+       if (*lastSync+syncFreq < currentDate)
+       {
+         *lastSync=currentDate ;
+         data_out->syncFile() ;
+         return true ;
+        }
+      }
+      return false ;
+    }
+    
+    
+    bool CFile::checkSplit(void)
+    {
+      shared_ptr<CContext> context=CObjectFactory::GetObject<CContext>(CObjectFactory::GetCurrentContextId()) ;
+      date::CDate& currentDate=context->calendar->getCurrentDate() ;
+      if (! split_freq.isEmpty())
+      {
+        if (*lastSplit+splitFreq < currentDate)
+        {
+          *lastSplit=currentDate-outputFreq ;
+        
+          std::vector<boost::shared_ptr<CField> >::iterator it, end = this->enabledFields.end();
+          for (it = this->enabledFields.begin() ;it != end; it++)  (*it)->resetNStep() ;
+          createHeader() ;
+          return true ;
+        }
+      }
+      return false ;
+    }
+    
    void CFile::createHeader(void)
    {
       shared_ptr<CContext> context=CObjectFactory::GetObject<CContext>(CObjectFactory::GetCurrentContextId()) ;
-
-      if (! sync_freq.isEmpty()) syncFreq = date::CDuration::FromString(sync_freq.getValue());
-      lastSync=new date::CDate(context->calendar->getCurrentDate()) ;
+      date::CDate& currentDate=context->calendar->getCurrentDate() ;
       
       std::vector<boost::shared_ptr<CField> >::iterator it, end = this->enabledFields.end();
@@ -168,5 +223,6 @@
          oss << filename;
          if (!name_suffix.isEmpty()) oss << name_suffix.getValue();
-
+//         if (!split_freq.isEmpty()) oss<<"-["<<currentDate.toString()<<"]" ;
+         if (!split_freq.isEmpty()) oss<<"_"<<lastSplit->getStryyyymmdd()<<"-"<< (*lastSplit+(splitFreq-1*date::Second)).getStryyyymmdd();
          bool multifile=true ;
          if (!type.isEmpty())
@@ -187,5 +243,8 @@
          oss << ".nc";
 
+         if (isOpen) data_out->closeFile() ;
+         
          data_out=shared_ptr<io::CDataOutput>(new io::CNc4DataOutput(oss.str(), false,server->intraComm,multifile));
+         isOpen=true ;
 
          data_out->writeFile(CObjectFactory::GetObject<CFile>(this));
@@ -208,7 +267,11 @@
    void CFile::close(void)
    {
+     delete lastSync ;
+     delete lastSplit ;
      if (!AllDomainEmpty ||  type.getValue()=="one_file")
-       this->data_out->closeFile();
-     delete lastSync ;
+       if (isOpen) 
+       {
+         this->data_out->closeFile();
+       }
    }
    //----------------------------------------------------------------
Index: /XIOS/trunk/src/node/file.hpp
===================================================================
--- /XIOS/trunk/src/node/file.hpp	(revision 320)
+++ /XIOS/trunk/src/node/file.hpp	(revision 321)
@@ -104,7 +104,15 @@
          static bool dispatchEvent(CEventServer& event) ;
          bool isSyncTime(void) ;
+         bool checkSplit(void) ;
+         bool checkSync(void) ;
+         void checkFile(void) ;
+         void initFile(void) ;
          date::CDate* lastSync ;
+         date::CDate* lastSplit ;
          date::CDuration syncFreq ;
+         date::CDuration splitFreq ;
+         date::CDuration outputFreq ;
          int nbDomain ;
+         bool isOpen ;
       private :
 
Index: /XIOS/trunk/src/output/nc4_data_output.cpp
===================================================================
--- /XIOS/trunk/src/output/nc4_data_output.cpp	(revision 320)
+++ /XIOS/trunk/src/output/nc4_data_output.cpp	(revision 321)
@@ -433,4 +433,9 @@
          else singleDomain=false ;
       }
+ 
+      void CNc4DataOutput::syncFile_ (void)
+      {
+         SuperClassWriter::sync() ;
+      }
 
       void CNc4DataOutput::closeFile_ (void)
@@ -460,5 +465,5 @@
       {
          shared_ptr<CContext> context=CObjectFactory::GetObject<CContext>(CObjectFactory::GetCurrentContextId()) ;
-          if (field->getRelFile()->isSyncTime()) SuperClassWriter::sync() ;
+//          if (field->getRelFile()->isSyncTime()) SuperClassWriter::sync() ;
 
          boost::shared_ptr<CGrid> grid = field->grid ;
Index: /XIOS/trunk/src/output/nc4_data_output.hpp
===================================================================
--- /XIOS/trunk/src/output/nc4_data_output.hpp	(revision 320)
+++ /XIOS/trunk/src/output/nc4_data_output.hpp	(revision 321)
@@ -47,4 +47,5 @@
             virtual void writeFile_      (const boost::shared_ptr<tree::CFile>     file);
             virtual void closeFile_      (void);
+            virtual void syncFile_      (void);
             virtual void writeTimeAxis_  (const boost::shared_ptr<tree::CField>    field,
                                           const boost::shared_ptr<date::CCalendar> cal);
