Index: XIOS/trunk/src/io/nc4_data_output.cpp
===================================================================
--- XIOS/trunk/src/io/nc4_data_output.cpp	(revision 706)
+++ XIOS/trunk/src/io/nc4_data_output.cpp	(revision 707)
@@ -1393,34 +1393,43 @@
       void CNc4DataOutput::writeFieldData_ (CField*  field)
       {
-         CContext* context = CContext::getCurrent() ;
-//          if (field->getRelFile()->isSyncTime()) SuperClassWriter::sync() ;
-         CContextServer* server=context->server ;
-
-         CGrid* grid = field->grid ;
-
-         if (!grid->doGridHaveDataToWrite())
-          if (SuperClass::type==MULTI_FILE || !isCollective) return ;
-
-         StdString fieldid   = (!field->name.isEmpty())
-                             ? field->name.getValue()
-                             : field->getBaseFieldReference()->getId();
-
-         StdOStringStream oss;
-         string timeAxisId ;
-         if (field->getOperationTimeType() == func::CFunctor::instant)  timeAxisId="time_instant" ;
-         else if (field->getOperationTimeType() == func::CFunctor::centered)  timeAxisId="time_centered" ;
-
-         StdString timeBoundId("time_counter_bounds");
-
-         StdString timeAxisBoundId;
-         if (field->getOperationTimeType() == func::CFunctor::instant)  timeAxisBoundId="time_instant_bounds" ;
-         else if (field->getOperationTimeType() == func::CFunctor::centered)  timeAxisBoundId="time_centered_bounds" ;
-
-         CArray<double,1> time_data(1) ;
-         CArray<double,1> time_data_bound(2);
-         CArray<double,1> time_counter(1) ;
-         CArray<double,1> time_counter_bound(2);
-
-        bool wtime   = !(!field->operation.isEmpty() && (field->getOperationTimeType() == func::CFunctor::once));
+        CContext* context = CContext::getCurrent();
+        CContextServer* server = context->server;
+        CGrid* grid = field->grid;
+
+        if (!grid->doGridHaveDataToWrite())
+          if (SuperClass::type == MULTI_FILE || !isCollective) return;
+
+        StdString fieldid = !field->name.isEmpty()
+                          ? field->name.getValue()
+                          : field->getBaseFieldReference()->getId();
+
+        StdOStringStream oss;
+        string timeAxisId;
+        if (field->getOperationTimeType() == func::CFunctor::instant) timeAxisId = "time_instant";
+        else if (field->getOperationTimeType() == func::CFunctor::centered) timeAxisId = "time_centered";
+
+        StdString timeBoundId("time_counter_bounds");
+
+        StdString timeAxisBoundId;
+        if (field->getOperationTimeType() == func::CFunctor::instant) timeAxisBoundId = "time_instant_bounds";
+        else if (field->getOperationTimeType() == func::CFunctor::centered) timeAxisBoundId = "time_centered_bounds";
+
+        if (!field->wasWritten())
+        {
+          if (appendMode)
+          {
+            field->resetNStep(getRecordFromTime(field->last_Write_srv) + 1);
+          }
+
+          field->setWritten();
+        }
+
+
+        CArray<double,1> time_data(1);
+        CArray<double,1> time_data_bound(2);
+        CArray<double,1> time_counter(1);
+        CArray<double,1> time_counter_bound(2);
+
+        bool wtime = (field->getOperationTimeType() != func::CFunctor::once);
 
         if (wtime)
@@ -1461,15 +1470,13 @@
         }
 
-         bool isRoot ;
-         if (server->intraCommRank==0) isRoot=true ;
-         else isRoot=false ;
+         bool isRoot = (server->intraCommRank == 0);
 
          if (!field->scale_factor.isEmpty() || !field->add_offset.isEmpty())
          {
-           double scaleFactor=1. ;
-           double addOffset=0. ;
-           if (!field->scale_factor.isEmpty()) scaleFactor=field->scale_factor ;
-           if (!field->add_offset.isEmpty()) addOffset=field->add_offset ;
-           field->scaleFactorAddOffset(scaleFactor,addOffset) ;
+           double scaleFactor = 1.0;
+           double addOffset = 0.0;
+           if (!field->scale_factor.isEmpty()) scaleFactor = field->scale_factor;
+           if (!field->add_offset.isEmpty()) addOffset = field->add_offset;
+           field->scaleFactorAddOffset(scaleFactor, addOffset);
          }
 
@@ -1490,5 +1497,5 @@
              field->outputField(fieldData);
 
-           if (!field->prec.isEmpty() && field->prec==2) fieldData=round(fieldData) ;
+           if (!field->prec.isEmpty() && field->prec == 2) fieldData = round(fieldData);
 
            switch (SuperClass::type)
@@ -1508,5 +1515,5 @@
                    }
                  }
-                 break ;
+                 break;
               }
               case (ONE_FILE) :
@@ -1971,3 +1978,29 @@
       ///--------------------------------------------------------------
 
+      StdSize CNc4DataOutput::getRecordFromTime(Time time)
+      {
+        std::map<Time, StdSize>::const_iterator it = timeToRecordCache.find(time);
+        if (it == timeToRecordCache.end())
+        {
+          StdString timeAxisBoundsId("time_counter_bounds");
+          if (!SuperClassWriter::varExist(timeAxisBoundsId))
+            timeAxisBoundsId = "time_instant_bounds";
+
+          CArray<double,2> timeAxisBounds;
+          SuperClassWriter::getTimeAxisBounds(timeAxisBounds, timeAxisBoundsId, isCollective);
+
+          StdSize record = 0;
+          double dtime(time);
+          for (int n = timeAxisBounds.extent(1) - 1; n >= 0; n--)
+          {
+            if (timeAxisBounds(1, n) < dtime)
+            {
+              record = n + 1;
+              break;
+            }
+          }
+          it = timeToRecordCache.insert(std::make_pair(time, record)).first;
+        }
+        return it->second;
+      }
 } // namespace xios
Index: XIOS/trunk/src/io/nc4_data_output.hpp
===================================================================
--- XIOS/trunk/src/io/nc4_data_output.hpp	(revision 706)
+++ XIOS/trunk/src/io/nc4_data_output.hpp	(revision 707)
@@ -88,4 +88,6 @@
                                      const StdString & nav_model);
 
+            StdSize getRecordFromTime(Time time);
+
          private :
 
@@ -96,9 +98,10 @@
             MPI_Comm comm_file;
             const StdString filename;
+            std::map<Time, StdSize> timeToRecordCache;
+
             std::set<std::string> writtenDomains ; 
             std::set<std::string> writtenAxis ;
             bool isWrittenDomain(const std::string& domainName) { return this->writtenDomains.find(domainName) != this->writtenDomains.end(); }
             bool isWrittenAxis(const std::string& axisName) { return this->writtenAxis.find(axisName) != this->writtenAxis.end(); }
-
       }; // class CNc4DataOutput
 
Index: XIOS/trunk/src/io/onetcdf4.cpp
===================================================================
--- XIOS/trunk/src/io/onetcdf4.cpp	(revision 706)
+++ XIOS/trunk/src/io/onetcdf4.cpp	(revision 707)
@@ -17,5 +17,4 @@
         , wmpi(false)
         , useClassicFormat(useClassicFormat)
-        , recordOffset(0)
       {
          this->initialize(filename, append, useClassicFormat, comm,multifile);
@@ -23,5 +22,4 @@
 
       //---------------------------------------------------------------
-
 
       CONetCDF4::~CONetCDF4(void)
@@ -60,5 +58,4 @@
 
             this->appendMode = false;
-            this->recordOffset = 0;
          }
          else
@@ -71,11 +68,4 @@
 
             this->appendMode = true;
-            // Find out how many temporal records have been written already to the file we are opening
-            int ncUnlimitedDimId;
-            CNetCdfInterface::inqUnLimDim(this->ncidp, ncUnlimitedDimId);
-            if (ncUnlimitedDimId != -1)
-               CNetCdfInterface::inqDimLen(this->ncidp, ncUnlimitedDimId, this->recordOffset);
-            else
-               this->recordOffset = 0;
          }
 
@@ -224,4 +214,30 @@
 
          return retvalue;
+      }
+
+      //---------------------------------------------------------------
+
+      void CONetCDF4::getTimeAxisBounds(CArray<double,2>& timeAxisBounds, const StdString& name, bool collective)
+      {
+        int grpid = this->getCurrentGroup();
+        int varid = this->getVariable(name);
+
+        std::vector<StdSize> start(2), count(2);
+        start[0] = 0;
+        // Find out how many temporal records have been written already to the file we are opening
+        int ncUnlimitedDimId;
+        CNetCdfInterface::inqUnLimDim(this->ncidp, ncUnlimitedDimId);
+        CNetCdfInterface::inqDimLen(this->ncidp, ncUnlimitedDimId, count[0]);
+        start[1] = 0;
+        count[1] = 2;
+
+        timeAxisBounds.resize(count[1], count[0]);
+
+        if (this->wmpi && collective)
+          CNetCdfInterface::varParAccess(grpid, varid, NC_COLLECTIVE);
+        if (this->wmpi && !collective)
+          CNetCdfInterface::varParAccess(grpid, varid, NC_INDEPENDENT);
+
+        CNetCdfInterface::getVaraType(grpid, varid, &start[0], &count[0], timeAxisBounds.dataFirst());
       }
 
@@ -430,5 +446,5 @@
          if (iddims.begin()->compare(this->getUnlimitedDimensionName()) == 0)
          {
-            sstart.push_back(record + recordOffset);
+            sstart.push_back(record);
             scount.push_back(1);
             if ((start == NULL) &&
Index: XIOS/trunk/src/io/onetcdf4.hpp
===================================================================
--- XIOS/trunk/src/io/onetcdf4.hpp	(revision 706)
+++ XIOS/trunk/src/io/onetcdf4.hpp	(revision 707)
@@ -26,26 +26,26 @@
 
             /// Constructeurs ///
-            CONetCDF4(const StdString & filename, bool append, bool useClassicFormat = false,
-                      const MPI_Comm * comm = NULL, bool multifile = true);
+            CONetCDF4(const StdString& filename, bool append, bool useClassicFormat = false,
+                      const MPI_Comm* comm = NULL, bool multifile = true);
 
-            CONetCDF4(const CONetCDF4 & onetcdf4);       // Not implemented.
-            CONetCDF4(const CONetCDF4 * const onetcdf4); // Not implemented.
+            CONetCDF4(const CONetCDF4& onetcdf4);       // Not implemented.
+            CONetCDF4(const CONetCDF4* const onetcdf4); // Not implemented.
 
 
             /// Initialisation ///
-            void initialize(const StdString & filename, bool append, bool useClassicFormat,
-                            const MPI_Comm * comm, bool multifile);
-            void close(void) ;
-            void sync(void) ;
+            void initialize(const StdString& filename, bool append, bool useClassicFormat,
+                            const MPI_Comm* comm, bool multifile);
+            void close(void);
+            void sync(void);
             void definition_start(void);
             void definition_end(void);
 
             /// Mutateurs ///
-            void setCurrentPath(const CONetCDF4Path & path);
+            void setCurrentPath(const CONetCDF4Path& path);
 
-            int addGroup(const StdString & name);
+            int addGroup(const StdString& name);
             int addDimension(const StdString& name, const StdSize size = UNLIMITED_DIM);
-            int addVariable(const StdString & name, nc_type type,
-                            const std::vector<StdString> & dim);
+            int addVariable(const StdString& name, nc_type type,
+                            const std::vector<StdString>& dim);
 
       //----------------------------------------------------------------
@@ -53,22 +53,22 @@
 
             template <class T>
-               void setDefaultValue(const StdString & varname, const T * value = NULL);
+               void setDefaultValue(const StdString& varname, const T* value = NULL);
 
             void setCompressionLevel(const StdString& varname, int compressionLevel);
 
-            template <class T>  void addAttribute (const StdString & name, const T & value, const StdString * varname = NULL);
+            template <class T>  void addAttribute (const StdString& name, const T& value, const StdString* varname = NULL);
 
             /// Ecriture des donnÃ©es ///
             template <class T, int ndim>
-               void writeData(const CArray<T,ndim>& data, const StdString & name,
+               void writeData(const CArray<T,ndim>& data, const StdString& name,
                               bool collective, StdSize record,
-                              const std::vector<StdSize> * start = NULL,
-                              const std::vector<StdSize> * count = NULL);
+                              const std::vector<StdSize>* start = NULL,
+                              const std::vector<StdSize>* count = NULL);
 
-            void writeData(const CArray<int, 2>& data, const StdString & name);
-            void writeTimeAxisData(const CArray<double,1>& data, const StdString & name,
-                                   bool collective, StdSize record, bool Isroot) ;
+            void writeData(const CArray<int, 2>& data, const StdString& name);
+            void writeTimeAxisData(const CArray<double,1>& data, const StdString& name,
+                                   bool collective, StdSize record, bool Isroot);
             /// Accesseur ///
-            const CONetCDF4Path & getCurrentPath(void) const;
+            const CONetCDF4Path& getCurrentPath(void) const;
 
             /// Destructeur ///
@@ -86,13 +86,15 @@
             /// Accesseurs ///
             int getCurrentGroup(void);
-            int getGroup(const CONetCDF4Path & path);
-            int getVariable(const StdString & varname);
-            int getDimension(const StdString & dimname);
-            std::vector<StdSize>   getDimensions       (const StdString & varname);
-            std::vector<StdString> getDimensionsIdList (const StdString * varname);
+            int getGroup(const CONetCDF4Path& path);
+            int getVariable(const StdString& varname);
+            int getDimension(const StdString& dimname);
+            std::vector<StdSize>   getDimensions       (const StdString& varname);
+            std::vector<StdString> getDimensionsIdList (const StdString* varname);
             int       getUnlimitedDimension(void);
             StdString getUnlimitedDimensionName(void);
 
-            bool varExist(const StdString & varname);
+            void getTimeAxisBounds(CArray<double,2>& timeAxisBounds, const StdString& name, bool collective);
+
+            bool varExist(const StdString& varname);
 
             bool useClassicFormat; //!< If true, NetCDF4 will use the classic NetCDF3 format
@@ -101,15 +103,14 @@
 
          private :
+            template <class T>
+            void writeData_(int grpid, int varid,
+                            const std::vector<StdSize>& sstart,
+                            const std::vector<StdSize>& scount, T* data);
 
-            template <class T>
-               void writeData_(int grpid, int varid,
-                               const std::vector<StdSize> & sstart,
-                               const std::vector<StdSize> & scount, T * data);
-
-            void getWriteDataInfos(const StdString & name, StdSize record, StdSize & array_size,
-                                   std::vector<StdSize> & sstart,
-                                   std::vector<StdSize> & scount,
-                                   const std::vector<StdSize> * start,
-                                   const std::vector<StdSize> * count);
+            void getWriteDataInfos(const StdString& name, StdSize record, StdSize& array_size,
+                                   std::vector<StdSize>& sstart,
+                                   std::vector<StdSize>& scount,
+                                   const std::vector<StdSize>* start,
+                                   const std::vector<StdSize>* count);
 
             /// PropriÃ©tÃ©s privÃ©es ///
@@ -117,8 +118,5 @@
             int ncidp;
             bool wmpi;
-            /*! Number of records already written when opening an existing file.
-             *  always 0 when creating a new file */
-            size_t recordOffset;
-            map<int,size_t> timeAxis ;
+            map<int,size_t> timeAxis;
       }; // class CONetCDF4
 
Index: XIOS/trunk/src/node/field.cpp
===================================================================
--- XIOS/trunk/src/node/field.cpp	(revision 706)
+++ XIOS/trunk/src/node/field.cpp	(revision 707)
@@ -32,4 +32,5 @@
       , refObject(), baseRefObject()
       , grid(), file()
+      , written(false)
       , nstep(0), nstepMax(0)
       , hasOutputFile(false)
@@ -43,4 +44,5 @@
       , refObject(), baseRefObject()
       , grid(), file()
+      , written(false)
       , nstep(0), nstepMax(0)
       , hasOutputFile(false)
@@ -442,7 +444,7 @@
    }
 
-   void CField::resetNStep(void)
-   {
-      this->nstep = 0;
+   void CField::resetNStep(StdSize nstep /*= 0*/)
+   {
+      this->nstep = nstep;
    }
 
@@ -457,4 +459,16 @@
    {
       return !this->refObject.empty();
+   }
+
+   //----------------------------------------------------------------
+
+   bool CField::wasWritten() const
+   {
+     return written;
+   }
+
+   void CField::setWritten()
+   {
+     written = true;
    }
 
Index: XIOS/trunk/src/node/field.hpp
===================================================================
--- XIOS/trunk/src/node/field.hpp	(revision 706)
+++ XIOS/trunk/src/node/field.hpp	(revision 707)
@@ -56,5 +56,5 @@
          typedef CFieldAttributes SuperClassAttribute;
 
-      public :
+      public:
 
          typedef CFieldAttributes RelAttributes;
@@ -80,6 +80,5 @@
          func::CFunctor::ETimeType getOperationTimeType() const;
 
-      public :
-
+      public:
          StdSize getNStep(void) const;
 
@@ -91,12 +90,15 @@
          void setRelFile(CFile* _file);
          void incrementNStep(void);
-         void resetNStep();
+         void resetNStep(StdSize nstep = 0);
          void resetNStepMax();
 
          std::map<int, StdSize> getGridDataSize();
 
-       public :
+       public:
          bool isActive(void) const;
          bool hasOutputFile;
+
+         bool wasWritten() const;
+         void setWritten();
 
          bool getUseCompressedOutput() const;
@@ -170,5 +172,5 @@
         const std::pair<StdString, StdString>& getRefDomainAxisIds();
 
-      public :
+      public:
          /// PropriÃ©tÃ©s privÃ©es ///
          CVariableGroup* vVariableGroup;
@@ -179,4 +181,5 @@
          CDuration freq_operation_srv, freq_write_srv;
 
+         bool written; //<! Was the field written at least once
          StdSize nstep, nstepMax;
          bool isEOF;
