Index: XIOS/trunk/src/output/nc4_data_output.cpp
===================================================================
--- XIOS/trunk/src/output/nc4_data_output.cpp	(revision 472)
+++ XIOS/trunk/src/output/nc4_data_output.cpp	(revision 488)
@@ -37,5 +37,5 @@
 
          SuperClass::type = (multifile) ? MULTI_FILE : ONE_FILE;
-         
+
  //        if (!exist)
 //            SuperClassWriter::addDimension(timeid);
@@ -62,12 +62,12 @@
            return ;
          }
-         
+
          CContext* context = CContext::getCurrent() ;
          CContextServer* server=context->server ;
-         
+
          if (domain->IsWritten(this->filename)) return;
          domain->checkAttributes();
-         
-         if (domain->isEmpty()) 
+
+         if (domain->isEmpty())
            if (SuperClass::type==MULTI_FILE) return ;
 
@@ -79,5 +79,5 @@
 
          StdString dimXid, dimYid ;
-         
+
          switch (domain->type)
          {
@@ -93,6 +93,6 @@
              dimXid     = StdString("cell").append(appendDomid);
              break;
-         }            
-         
+         }
+
          string lonid,latid,bounds_lonid,bounds_latid ;
 /*
@@ -110,5 +110,5 @@
             {
 //               if (domain->isEmpty()) return;
-               
+
                if (server->intraCommSize > 1)
                {
@@ -138,5 +138,5 @@
                    break;
                }
-                
+
                if (domain->type == CDomain::type_attr::unstructured)
                {
@@ -148,5 +148,5 @@
                  SuperClassWriter::addDimension(dimYid, domain->zoom_nj_srv);
                }
-               
+
                if (server->intraCommSize > 1)
                {
@@ -158,5 +158,5 @@
                                                domain->zoom_nj_srv,
                                                appendDomid);
-                  
+
                     if (singleDomain) this->writeLocalAttributes_IOIPSL(domain->zoom_ibegin_srv,
                                                domain->zoom_ni_srv,
@@ -167,5 +167,5 @@
                  }
                }
-               
+
                switch (domain->type)
                {
@@ -182,5 +182,5 @@
                     SuperClassWriter::addVariable(lonid, NC_FLOAT, dim0);
                }
-               
+
                this->writeAxisAttributes(lonid, "X", "longitude", "Longitude", "degrees_east", domid);
                this->writeAxisAttributes(latid, "Y", "latitude", "Latitude", "degrees_north", domid);
@@ -202,5 +202,5 @@
 // supress mask                     domain->data_jbegin.getValue()*/);
 // supress mask               }
-                  
+
                //SuperClassWriter::setDefaultValue(maskid, &dvm);
 
@@ -212,5 +212,5 @@
                    SuperClassWriter::writeData(domain->latvalue_srv, latid, isCollective, 0);
                    SuperClassWriter::writeData(domain->lonvalue_srv, lonid, isCollective, 0);
-                   break; 
+                   break;
                  case CDomain::type_attr::regular :
                    CArray<double,1> lat = domain->latvalue_srv(Range(fromStart,toEnd,domain->zoom_ni_srv)) ;
@@ -229,5 +229,5 @@
                SuperClassWriter::addDimension(dimYid, domain->zoom_nj.getValue());
 
-               
+
                switch (domain->type)
                {
@@ -260,17 +260,17 @@
                  case CDomain::type_attr::curvilinear :
                  {
-                   std::vector<StdSize> start(2) ; 
+                   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 ; 
+                     start[0]=0 ; start [1]=0 ;
+                     count[0]=0 ; count[1]=0 ;
                    }
                    else
                    {
-                     start[1]=domain->zoom_ibegin_srv-domain->zoom_ibegin.getValue() ; start [0]=domain->zoom_jbegin_srv-domain->zoom_jbegin.getValue() ; 
-                     count[1]=domain->zoom_ni_srv ; count[0]=domain->zoom_nj_srv ; 
+                     start[1]=domain->zoom_ibegin_srv-domain->zoom_ibegin.getValue() ; start [0]=domain->zoom_jbegin_srv-domain->zoom_jbegin.getValue() ;
+                     count[1]=domain->zoom_ni_srv ; count[0]=domain->zoom_nj_srv ;
                    }
-                 
+
                    SuperClassWriter::writeData(domain->latvalue_srv, latid, isCollective, 0,&start,&count);
                    SuperClassWriter::writeData(domain->lonvalue_srv, lonid, isCollective, 0,&start,&count);
@@ -279,21 +279,21 @@
                  case CDomain::type_attr::regular :
                  {
-                   std::vector<StdSize> start(1) ; 
+                   std::vector<StdSize> start(1) ;
                    std::vector<StdSize> count(1) ;
                    if (domain->isEmpty())
                    {
-                     start[0]=0 ;  
-                     count[0]=0 ;  
+                     start[0]=0 ;
+                     count[0]=0 ;
                      SuperClassWriter::writeData(domain->latvalue_srv, latid, isCollective, 0,&start,&count);
                      SuperClassWriter::writeData(domain->lonvalue_srv, lonid, isCollective, 0,&start,&count);                 }
                    else
                    {
-                     start[0]=domain->zoom_jbegin_srv-domain->zoom_jbegin.getValue() ; 
-                     count[0]=domain->zoom_nj_srv ; 
+                     start[0]=domain->zoom_jbegin_srv-domain->zoom_jbegin.getValue() ;
+                     count[0]=domain->zoom_nj_srv ;
                      CArray<double,1> lat = domain->latvalue_srv(Range(fromStart,toEnd,domain->zoom_ni_srv)) ;
                      SuperClassWriter::writeData(CArray<double,1>(lat.copy()), latid, isCollective, 0,&start,&count);
 
-                     start[0]=domain->zoom_ibegin_srv-domain->zoom_ibegin.getValue() ; 
-                     count[0]=domain->zoom_ni_srv ; 
+                     start[0]=domain->zoom_ibegin_srv-domain->zoom_ibegin.getValue() ;
+                     count[0]=domain->zoom_ni_srv ;
                      CArray<double,1> lon=domain->lonvalue_srv(Range(0,domain->zoom_ni_srv-1)) ;
                      SuperClassWriter::writeData(CArray<double,1>(lon.copy()), lonid, isCollective, 0,&start,&count);
@@ -304,5 +304,5 @@
                SuperClassWriter::definition_start();
                break;
-            }           
+            }
             default :
                ERROR("CNc4DataOutput::writeDomain(domain)",
@@ -317,9 +317,9 @@
          CContext* context = CContext::getCurrent() ;
          CContextServer* server=context->server ;
-         
+
          if (domain->IsWritten(this->filename)) return;
          domain->checkAttributes();
-         
-         if (domain->isEmpty()) 
+
+         if (domain->isEmpty())
            if (SuperClass::type==MULTI_FILE) return ;
 
@@ -332,5 +332,5 @@
          StdString dimXid = StdString("cell").append(appendDomid);
          StdString dimVertId = StdString("nvertex").append(appendDomid);
-        
+
          string lonid,latid,bounds_lonid,bounds_latid ;
 
@@ -346,9 +346,9 @@
                SuperClassWriter::addVariable(latid, NC_FLOAT, dim0);
                SuperClassWriter::addVariable(lonid, NC_FLOAT, dim0);
-               
+
                bounds_lonid = StdString("bounds_lon").append(appendDomid);
                bounds_latid = StdString("bounds_lat").append(appendDomid);
-              
-               
+
+
                this->writeAxisAttributes(lonid, "X", "longitude", "Longitude", "degrees_east", domid);
                if (domain->hasBounds) SuperClassWriter::addAttribute("bounds",bounds_lonid, &lonid);
@@ -358,5 +358,5 @@
                dim0.clear();
                if (domain->hasBounds)
-               { 
+               {
                  dim0.push_back(dimXid);
                  dim0.push_back(dimVertId);
@@ -364,5 +364,5 @@
                  SuperClassWriter::addVariable(bounds_latid, NC_FLOAT, dim0);
                }
-               
+
                dim0.clear();
                dim0.push_back(dimXid);
@@ -372,7 +372,7 @@
                SuperClassWriter::writeData(domain->latvalue_srv, latid, isCollective, 0);
                SuperClassWriter::writeData(domain->lonvalue_srv, lonid, isCollective, 0);
-               
+
                if (domain->hasBounds)
-               { 
+               {
                  SuperClassWriter::writeData(domain->bounds_lon_srv, bounds_lonid, isCollective, 0);
                  SuperClassWriter::writeData(domain->bounds_lat_srv, bounds_latid, isCollective, 0);
@@ -394,10 +394,10 @@
                this->writeAxisAttributes(lonid, "X", "longitude", "Longitude", "degrees_east", domid);
                if (domain->hasBounds) SuperClassWriter::addAttribute("bounds",bounds_lonid, &lonid);
-               this->writeAxisAttributes(latid, "Y", "latitude", "Latitude", "degrees_north", domid);                                           
+               this->writeAxisAttributes(latid, "Y", "latitude", "Latitude", "degrees_north", domid);
                if (domain->hasBounds) SuperClassWriter::addAttribute("bounds",bounds_latid, &latid);
                if (domain->hasBounds) SuperClassWriter::addDimension(dimVertId, domain->nvertex);
                dim0.clear();
-               
-               if (domain->hasBounds) 
+
+               if (domain->hasBounds)
                {
                  dim0.push_back(dimXid);
@@ -406,94 +406,36 @@
                  SuperClassWriter::addVariable(bounds_latid, NC_FLOAT, dim0);
                }
-               
+
                SuperClassWriter::definition_end();
-               
-               std::vector<StdSize> start(1), startBounds(2) ; 
+
+               std::vector<StdSize> start(1), startBounds(2) ;
                std::vector<StdSize> count(1), countBounds(2) ;
                if (domain->isEmpty())
                {
-                 start[0]=0 ;  
-                 count[0]=0 ;  
-                 startBounds[1]=0 ;  
+                 start[0]=0 ;
+                 count[0]=0 ;
+                 startBounds[1]=0 ;
                  countBounds[1]=domain->nvertex ;
-                 startBounds[0]=0 ;  
-                 countBounds[0]=0 ;  
+                 startBounds[0]=0 ;
+                 countBounds[0]=0 ;
                }
                else
                {
-                 start[0]=domain->zoom_jbegin_srv-domain->zoom_jbegin ; 
-                 count[0]=domain->zoom_nj_srv ; 
-                 startBounds[0]=domain->zoom_jbegin_srv-domain->zoom_jbegin ; 
-                 startBounds[1]=0 ;  
-                 countBounds[0]=domain->zoom_nj_srv ;   
+                 start[0]=domain->zoom_jbegin_srv-domain->zoom_jbegin ;
+                 count[0]=domain->zoom_nj_srv ;
+                 startBounds[0]=domain->zoom_jbegin_srv-domain->zoom_jbegin ;
+                 startBounds[1]=0 ;
+                 countBounds[0]=domain->zoom_nj_srv ;
                  countBounds[1]=domain->nvertex ;
                }
                SuperClassWriter::writeData(domain->latvalue_srv, latid, isCollective, 0,&start,&count);
                SuperClassWriter::writeData(domain->lonvalue_srv, lonid, isCollective, 0,&start,&count);
-               if (domain->hasBounds) 
+               if (domain->hasBounds)
                {
                  SuperClassWriter::writeData(domain->bounds_lon_srv, bounds_lonid, isCollective, 0,&startBounds,&countBounds);
                  SuperClassWriter::writeData(domain->bounds_lat_srv, bounds_latid, isCollective, 0,&startBounds,&countBounds);
                }
- 
-               
-               SuperClassWriter::definition_start();
-
-               break;
-            }           
-            default :
-               ERROR("CNc4DataOutput::writeDomain(domain)",
-                     << "[ type = " << SuperClass::type << "]"
-                     << " not implemented yet !");
-         }
-         domain->addRelFile(this->filename);
-      }
-      //--------------------------------------------------------------
-
-      void CNc4DataOutput::writeAxis_(CAxis* axis)
-      {
-         if (axis->IsWritten(this->filename)) return;
-         axis->checkAttributes();
-         StdSize zoom_size=axis->zoom_size.getValue() ;
-         StdSize zoom_begin=axis->zoom_begin.getValue()-1 ;
-         
-         std::vector<StdString> dims;
-         StdString axisid = (!axis->name.isEmpty())
-                           ? axis->name.getValue() : axis->getId();
-         SuperClassWriter::addDimension(axisid, zoom_size);
-         dims.push_back(axisid);
-         
-         switch (SuperClass::type)
-         {
-            case (MULTI_FILE ) :
-            {}
-            case (ONE_FILE) :
-            {
-               SuperClassWriter::addVariable(axisid, NC_FLOAT, dims);
-
-               SuperClassWriter::addAttribute("axis", StdString("Z"), &axisid);
-
-               if (!axis->standard_name.isEmpty())
-                  SuperClassWriter::addAttribute
-                     ("standard_name",  axis->standard_name.getValue(), &axisid);
-
-               if (!axis->long_name.isEmpty())
-                  SuperClassWriter::addAttribute
-                     ("long_name", axis->long_name.getValue(), &axisid);
-
-               if (!axis->unit.isEmpty())
-                  SuperClassWriter::addAttribute
-                     ("units", axis->unit.getValue(), &axisid);
-
-              if (!axis->positive.isEmpty())
-                if (axis->positive==CAxis::positive_attr::up) SuperClassWriter::addAttribute("positive", string("up"), &axisid);
-                else   SuperClassWriter::addAttribute("positive", string("down"), &axisid);
-
-               SuperClassWriter::definition_end();
-               
-               CArray<double,1> axis_value(zoom_size) ;
-               for(StdSize i = 0 ; i < zoom_size ; i++) axis_value(i)=axis->value(i+zoom_begin) ;
-               SuperClassWriter::writeData(axis_value, axisid, isCollective, 0);
-               
+
+
                SuperClassWriter::definition_start();
 
@@ -505,10 +447,69 @@
                      << " not implemented yet !");
          }
+         domain->addRelFile(this->filename);
+      }
+      //--------------------------------------------------------------
+
+      void CNc4DataOutput::writeAxis_(CAxis* axis)
+      {
+         if (axis->IsWritten(this->filename)) return;
+         axis->checkAttributes();
+         StdSize zoom_size=axis->zoom_size.getValue() ;
+         StdSize zoom_begin=axis->zoom_begin.getValue()-1 ;
+
+         std::vector<StdString> dims;
+         StdString axisid = (!axis->name.isEmpty())
+                           ? axis->name.getValue() : axis->getId();
+         SuperClassWriter::addDimension(axisid, zoom_size);
+         dims.push_back(axisid);
+
+         switch (SuperClass::type)
+         {
+            case (MULTI_FILE ) :
+            {}
+            case (ONE_FILE) :
+            {
+               SuperClassWriter::addVariable(axisid, NC_FLOAT, dims);
+
+               SuperClassWriter::addAttribute("axis", StdString("Z"), &axisid);
+
+               if (!axis->standard_name.isEmpty())
+                  SuperClassWriter::addAttribute
+                     ("standard_name",  axis->standard_name.getValue(), &axisid);
+
+               if (!axis->long_name.isEmpty())
+                  SuperClassWriter::addAttribute
+                     ("long_name", axis->long_name.getValue(), &axisid);
+
+               if (!axis->unit.isEmpty())
+                  SuperClassWriter::addAttribute
+                     ("units", axis->unit.getValue(), &axisid);
+
+              if (!axis->positive.isEmpty())
+                if (axis->positive==CAxis::positive_attr::up) SuperClassWriter::addAttribute("positive", string("up"), &axisid);
+                else   SuperClassWriter::addAttribute("positive", string("down"), &axisid);
+
+               SuperClassWriter::definition_end();
+
+               CArray<double,1> axis_value(zoom_size) ;
+               for(StdSize i = 0 ; i < zoom_size ; i++) axis_value(i)=axis->value(i+zoom_begin) ;
+               SuperClassWriter::writeData(axis_value, axisid, isCollective, 0);
+
+               SuperClassWriter::definition_start();
+
+               break;
+            }
+            default :
+               ERROR("CNc4DataOutput::writeDomain(domain)",
+                     << "[ type = " << SuperClass::type << "]"
+                     << " not implemented yet !");
+         }
          axis->addRelFile(this->filename);
      }
-     
+
      void CNc4DataOutput::writeTimeDimension_(void)
      {
        SuperClassWriter::addDimension("time_counter");
+       SuperClassWriter::addDimension("time_bounds", 2);
      }
       //--------------------------------------------------------------
@@ -522,6 +523,6 @@
          CGrid* grid = field->grid;
          CDomain* domain = grid->domain;
-           
-         if (domain->isEmpty()) 
+
+         if (domain->isEmpty())
            if (SuperClass::type==MULTI_FILE) return ;
 
@@ -530,10 +531,10 @@
                              ? domain->name.getValue() : domain->getId();
          StdString appendDomid  = (singleDomain) ? "" : "_"+domid ;
- 
-//         bool isCurvilinear = domain->isCurvilinear ; 
+
+//         bool isCurvilinear = domain->isCurvilinear ;
 //         bool isCurvilinear = (domain->type == CDomain::type_attr::curvilinear) ;
-         
+
          StdString dimXid,dimYid ;
-        
+
          switch (domain->type)
          {
@@ -550,6 +551,6 @@
              break ;
         }
-         
-/* 
+
+/*
          StdString lonid_loc = (server->intraCommSize > 1)
                              ? StdString("lon").append(appendDomid).append("_local")
@@ -564,6 +565,6 @@
 //         unsigned int ssize = domain->zoom_ni_loc.getValue() * domain->zoom_nj_loc.getValue();
 //         bool isCurvilinear = (domain->lonvalue.getValue()->size() == ssize);
-//          bool isCurvilinear = domain->isCurvilinear ; 
-          
+//          bool isCurvilinear = domain->isCurvilinear ;
+
          nc_type type ;
          if (field->prec.isEmpty()) type =  NC_FLOAT ;
@@ -572,16 +573,16 @@
            if (field->prec==2) type = NC_SHORT ;
            else if (field->prec==4)  type =  NC_FLOAT ;
-           else if (field->prec==8)   type =  NC_DOUBLE ; 
-         }
-                     
+           else if (field->prec==8)   type =  NC_DOUBLE ;
+         }
+
          bool wtime   = !(!field->operation.isEmpty() && field->foperation->timeType() == func::CFunctor::once);
-                         
+
          if (wtime)
          {
-            
+
             //StdOStringStream oss;
            // oss << "time_" << field->operation.getValue()
            //     << "_" << field->getRelFile()->output_freq.getValue();
-          //oss 
+          //oss
             if (field->foperation->timeType() == func::CFunctor::instant) coodinates.push_back(string("time_instant"));
             else if (field->foperation->timeType() == func::CFunctor::centered) coodinates.push_back(string("time_centered"));
@@ -603,6 +604,6 @@
              coodinates.push_back(StdString("nav_lat").append(appendDomid));
              break;
-           case CDomain::type_attr::regular :             
-           case CDomain::type_attr::unstructured :   
+           case CDomain::type_attr::regular :
+           case CDomain::type_attr::unstructured :
             coodinates.push_back(StdString("lon").append(appendDomid));
             coodinates.push_back(StdString("lat").append(appendDomid));
@@ -612,7 +613,7 @@
          if ( domain->type == CDomain::type_attr::curvilinear || domain->type == CDomain::type_attr::regular)dims.push_back(dimYid);
          dims.push_back(dimXid);
-          
+
          SuperClassWriter::addVariable(fieldid, type, dims);
-         
+
          if (!field->standard_name.isEmpty())
             SuperClassWriter::addAttribute
@@ -642,15 +643,15 @@
             SuperClassWriter::addAttribute
                ("add_offset", field->add_offset.getValue(), &fieldid);
-                                            
+
          SuperClassWriter::addAttribute
                ("online_operation", field->operation.getValue(), &fieldid);
 
         // write child variables as attributes
-        
-        
+
+
          vector<CVariable*> listVars = field->getAllVariables() ;
          for (vector<CVariable*>::iterator it = listVars.begin() ;it != listVars.end(); it++) writeAttribute_(*it, fieldid) ;
 
-               
+
          if (wtime)
          {
@@ -665,5 +666,5 @@
             SuperClassWriter::addAttribute("interval_write", duration.toString(), &fieldid);
          }
-         
+
          if (!field->default_value.isEmpty())
          {
@@ -679,12 +680,12 @@
             double * default_value = NULL;
             SuperClassWriter::setDefaultValue(fieldid, default_value);
-         }             
+         }
 
          {  // Ecriture des coordonnÃ©es
-         
+
             StdString coordstr; //boost::algorithm::join(coodinates, " ")
-            std::vector<StdString>::iterator 
+            std::vector<StdString>::iterator
                itc = coodinates.begin(), endc = coodinates.end();
-            
+
             for (; itc!= endc; itc++)
             {
@@ -717,5 +718,5 @@
          else singleDomain=false ;
       }
- 
+
       void CNc4DataOutput::writeAttribute_ (CVariable* var, const string& fieldId)
       {
@@ -724,13 +725,13 @@
         else if (var->hasId()) name=var->getId() ;
         else return ;
-        
-        if (var->getVarType()==CVariable::t_int) addAttribute(name,var->getData<int>(),&fieldId) ; 
-        else if (var->getVarType()==CVariable::t_short_int) addAttribute(name,var->getData<short int>(),&fieldId) ; 
-        else if (var->getVarType()==CVariable::t_long_int) addAttribute(name,var->getData<long int>(),&fieldId) ; 
-        else if (var->getVarType()==CVariable::t_float) addAttribute(name,var->getData<float>(),&fieldId) ; 
-        else if (var->getVarType()==CVariable::t_double) addAttribute(name,var->getData<double>(),&fieldId) ; 
-        else addAttribute(name,var->getData<string>(),&fieldId) ; 
+
+        if (var->getVarType()==CVariable::t_int) addAttribute(name,var->getData<int>(),&fieldId) ;
+        else if (var->getVarType()==CVariable::t_short_int) addAttribute(name,var->getData<short int>(),&fieldId) ;
+        else if (var->getVarType()==CVariable::t_long_int) addAttribute(name,var->getData<long int>(),&fieldId) ;
+        else if (var->getVarType()==CVariable::t_float) addAttribute(name,var->getData<float>(),&fieldId) ;
+        else if (var->getVarType()==CVariable::t_double) addAttribute(name,var->getData<double>(),&fieldId) ;
+        else addAttribute(name,var->getData<string>(),&fieldId) ;
      }
- 
+
      void CNc4DataOutput::writeAttribute_ (CVariable* var)
      {
@@ -739,13 +740,13 @@
         else if (var->hasId()) name=var->getId() ;
         else return ;
-        
-        if (var->getVarType()==CVariable::t_int) addAttribute(name,var->getData<int>()) ; 
-        else if (var->getVarType()==CVariable::t_short_int) addAttribute(name,var->getData<short int>()) ; 
-        else if (var->getVarType()==CVariable::t_long_int) addAttribute(name,var->getData<long int>()) ; 
-        else if (var->getVarType()==CVariable::t_float) addAttribute(name,var->getData<float>()) ; 
-        else if (var->getVarType()==CVariable::t_double) addAttribute(name,var->getData<double>()) ; 
-        else addAttribute(name,var->getData<string>()) ; 
-     }     
- 
+
+        if (var->getVarType()==CVariable::t_int) addAttribute(name,var->getData<int>()) ;
+        else if (var->getVarType()==CVariable::t_short_int) addAttribute(name,var->getData<short int>()) ;
+        else if (var->getVarType()==CVariable::t_long_int) addAttribute(name,var->getData<long int>()) ;
+        else if (var->getVarType()==CVariable::t_float) addAttribute(name,var->getData<float>()) ;
+        else if (var->getVarType()==CVariable::t_double) addAttribute(name,var->getData<double>()) ;
+        else addAttribute(name,var->getData<string>()) ;
+     }
+
       void CNc4DataOutput::syncFile_ (void)
       {
@@ -773,7 +774,7 @@
          return (StdString(buffer));
       }
-      
+
       //---------------------------------------------------------------
-      
+
       void CNc4DataOutput::writeFieldData_ (CField*  field)
       {
@@ -784,12 +785,12 @@
          CGrid* grid = field->grid ;
          CDomain* domain = grid->domain ;
-         
+
          if(SuperClass::type==MULTI_FILE || !isCollective) if (domain->isEmpty()) return;
 
 
-         StdString fieldid   = (!field->name.isEmpty()) 
-                             ? field->name.getValue() 
+         StdString fieldid   = (!field->name.isEmpty())
+                             ? field->name.getValue()
                              : field->getBaseFieldReference()->getId();
-                             
+
          StdOStringStream oss;
          string timeAxisId ;
@@ -797,24 +798,39 @@
          else if (field->foperation->timeType() == func::CFunctor::centered)  timeAxisId="time_centered" ;
 
-             
+         StdString timeBoundId("time_counter_bounds");
+
+         StdString timeAxisBoundId;
+         if (field->foperation->timeType() == func::CFunctor::instant)  timeAxisBoundId="time_instant_bounds" ;
+         else if (field->foperation->timeType() == func::CFunctor::centered)  timeAxisBoundId="time_centered_bounds" ;
+
          CArray<double,1> time_data(1) ;
          CArray<double,1> time_counter(1) ;
-                
+         CArray<double,1> time_counter_bound(2);
+         CArray<double,1> time_data_bound(2);
+
         bool wtime   = !(!field->operation.isEmpty() && (field->foperation->timeType() == func::CFunctor::once));
-                                 
+
         if (wtime)
         {
           time_counter(0)= (Time(*field->last_Write_srv)+Time(*field->lastlast_Write_srv))/2 -Time(context->calendar->getTimeOrigin());
-          if (field->foperation->timeType() == func::CFunctor::instant) 
+          if (field->foperation->timeType() == func::CFunctor::instant)
             time_data(0) = Time(*field->last_Write_srv)-Time(context->calendar->getTimeOrigin());
           else if (field->foperation->timeType() == func::CFunctor::centered) time_data(0) = time_counter(0);
-          
-         }
-         
-         
+
+          time_counter_bound(0) = Time(*field->lastlast_Write_srv) - Time(context->calendar->getTimeOrigin());
+          time_counter_bound(1) = Time(*field->last_Write_srv) - Time(context->calendar->getTimeOrigin());
+          if (field->foperation->timeType() == func::CFunctor::instant)
+            time_data_bound(0) = time_data_bound(1) = Time(*field->last_Write_srv)-Time(context->calendar->getTimeOrigin());
+          else if (field->foperation->timeType() == func::CFunctor::centered)
+          {
+            time_data_bound(0) = time_counter_bound(0);
+            time_data_bound(1) = time_counter_bound(1);
+          }
+         }
+
          bool isRoot ;
          if (server->intraCommRank==0) isRoot=true ;
          else isRoot=false ;
-          
+
          if (!field->scale_factor.isEmpty() || !field->add_offset.isEmpty())
          {
@@ -825,5 +841,5 @@
            field->scaleFactorAddOffset(scaleFactor,addOffset) ;
          }
-            
+
          if (grid->hasAxis()) // 3D
          {
@@ -841,8 +857,10 @@
               {
                  SuperClassWriter::writeData(field_data3D, fieldid, isCollective, field->getNStep()-1);
-                 if (wtime) 
+                 if (wtime)
                  {
                    SuperClassWriter::writeData(time_data, timeAxisId, isCollective, field->getNStep()-1);
                    SuperClassWriter::writeData(time_counter, string("time_counter"), isCollective, field->getNStep()-1);
+                   SuperClassWriter::writeData(time_counter_bound, timeBoundId, isCollective, field->getNStep()-1);
+                   SuperClassWriter::writeData(time_data_bound, timeAxisBoundId, isCollective, field->getNStep()-1);
                  }
                  break ;
@@ -850,5 +868,5 @@
               case (ONE_FILE) :
               {
-                 std::vector<StdSize> start(3) ; 
+                 std::vector<StdSize> start(3) ;
                  std::vector<StdSize> count(3) ;
                  if (domain->isEmpty())
@@ -864,13 +882,15 @@
                  }
                  SuperClassWriter::writeData(field_data3D, fieldid, isCollective, field->getNStep()-1,&start,&count );
-                 if (wtime) 
+                 if (wtime)
                  {
                    SuperClassWriter::writeTimeAxisData(time_data, timeAxisId, isCollective, field->getNStep()-1,isRoot );
                    SuperClassWriter::writeTimeAxisData(time_counter, string("time_counter"), isCollective, field->getNStep()-1,isRoot );
+                   SuperClassWriter::writeTimeAxisData(time_counter_bound, timeBoundId, isCollective, field->getNStep()-1, isRoot );
+                   SuperClassWriter::writeTimeAxisData(time_data_bound, timeAxisBoundId, isCollective, field->getNStep()-1, isRoot);
                  }
                  break;
               }
             }
-            
+
          }
          else // 2D
@@ -885,8 +905,10 @@
               {
                 SuperClassWriter::writeData(field_data2D, fieldid, isCollective, field->getNStep()-1);
-                if (wtime) 
+                if (wtime)
                 {
                   SuperClassWriter::writeData(time_data, timeAxisId, isCollective, field->getNStep()-1);
                   SuperClassWriter::writeData(time_counter, string("time_counter"), isCollective, field->getNStep()-1);
+                  SuperClassWriter::writeData(time_counter_bound, timeBoundId, isCollective, field->getNStep()-1);
+                  SuperClassWriter::writeData(time_data_bound, timeAxisBoundId, isCollective, field->getNStep()-1);
                 }
                 break;
@@ -894,5 +916,5 @@
               case (ONE_FILE) :
               {
-                 std::vector<StdSize> start(2) ; 
+                 std::vector<StdSize> start(2) ;
                  std::vector<StdSize> count(2) ;
                  if (domain->isEmpty())
@@ -903,16 +925,18 @@
                  else
                  {
-                   start[1]=domain->zoom_ibegin_srv-domain->zoom_ibegin.getValue() ; start[0]=domain->zoom_jbegin_srv-domain->zoom_jbegin.getValue() ; 
+                   start[1]=domain->zoom_ibegin_srv-domain->zoom_ibegin.getValue() ; start[0]=domain->zoom_jbegin_srv-domain->zoom_jbegin.getValue() ;
                    count[1]=domain->zoom_ni_srv ; count[0]=domain->zoom_nj_srv ;
                  }
 
                  SuperClassWriter::writeData(field_data2D, fieldid, isCollective, field->getNStep()-1,&start,&count);
-                 if (wtime) 
+                 if (wtime)
                  {
                    SuperClassWriter::writeTimeAxisData(time_data, timeAxisId, isCollective, field->getNStep()-1,isRoot);
                    SuperClassWriter::writeTimeAxisData(time_counter, string("time_counter"), isCollective, field->getNStep()-1,isRoot);
-                 }                   
-                 break; 
-              
+                   SuperClassWriter::writeTimeAxisData(time_counter_bound, timeBoundId, isCollective, field->getNStep()-1, isRoot);
+                   SuperClassWriter::writeTimeAxisData(time_data_bound, timeAxisBoundId, isCollective, field->getNStep()-1, isRoot);
+                 }
+                 break;
+
               }
             }
@@ -927,40 +951,58 @@
       {
          StdOStringStream oss;
-         
+
 //         if (field->operation.getValue().compare("once") == 0) return ;
          if (field->foperation->timeType() == func::CFunctor::once) return ;
-                                
+
 //         oss << "time_" << field->operation.getValue()
 //             << "_" << field->getRelFile()->output_freq.getValue();
-         
-         string  axisid ;   
-         if (field->foperation->timeType() == func::CFunctor::centered) axisid="time_centered" ;
-         else if (field->foperation->timeType() == func::CFunctor::instant) axisid="time_instant" ;
-         
+
+//         StdString axisid = oss.str();
+//         if (field->foperation->timeType() == func::CFunctor::centered) axisid="time_centered" ;
+//         else if (field->foperation->timeType() == func::CFunctor::instant) axisid="time_instant" ;
+
+         StdString axisid("time_centered") ;
+         StdString axisBoundId("time_centered_bounds");
+         StdString timeid("time_counter");
+         StdString timeBoundId("time_bounds");
+
+         if (field->foperation->timeType() == func::CFunctor::instant)
+         {
+            axisid = "time_instant";
+            axisBoundId = "time_instant_bounds";
+         }
+
+         // Adding time_instant or time_centered
          std::vector<StdString> dims;
-//         StdString axisid = oss.str();
-         StdString timeid = StdString("time_counter");
-
          dims.push_back(timeid);
          if (!SuperClassWriter::varExist(axisid))
          {
             SuperClassWriter::addVariable(axisid, NC_DOUBLE, dims);
-            
+
             CDate timeOrigin=cal->getTimeOrigin() ;
-//            StdOStringStream oss2;
+            StdOStringStream oss2;
 //            oss2<<initDate.getYear()<<"-"<<initDate.getMonth()<<"-"<<initDate.getDay()<<" "
 //                <<initDate.getHour()<<"-"<<initDate.getMinute()<<"-"<<initDate.getSecond() ;
-//            StdString strInitdate=oss2.str() ;
+            StdString strInitdate=oss2.str() ;
             StdString strTimeOrigin=timeOrigin.toString() ;
             this->writeTimeAxisAttributes
                (axisid, cal->getType(),
                 StdString("seconds since ").append(strTimeOrigin),
-                strTimeOrigin);
-         }
-
+                strTimeOrigin, axisBoundId);
+         }
+
+         // Adding time_instant_bounds or time_centered_bounds variables
+         if (!SuperClassWriter::varExist(axisBoundId))
+         {
+            dims.clear() ;
+            dims.push_back(timeid);
+            dims.push_back(timeBoundId);
+            SuperClassWriter::addVariable(axisBoundId, NC_DOUBLE, dims);
+         }
+
+         // Adding time_counter
+         axisid = "time_counter" ;
+         axisBoundId = "time_counter_bounds" ;
          dims.clear() ;
-         axisid = "time_counter" ;
-         timeid = "time_counter" ;
-
          dims.push_back(timeid);
          if (!SuperClassWriter::varExist(axisid))
@@ -970,19 +1012,28 @@
             CDate timeOrigin=cal->getTimeOrigin() ;
             StdString strTimeOrigin=timeOrigin.toString() ;
+
             this->writeTimeAxisAttributes
                (axisid, cal->getType(),
                 StdString("seconds since ").append(strTimeOrigin),
-                strTimeOrigin);
-         }         
-         
-
+                strTimeOrigin, axisBoundId);
+         }
+
+         // Adding time_counter_bound dimension
+         if (!SuperClassWriter::varExist(axisBoundId))
+         {
+            dims.clear();
+            dims.push_back(timeid);
+            dims.push_back(timeBoundId);
+            SuperClassWriter::addVariable(axisBoundId, NC_DOUBLE, dims);
+         }
       }
 
       //---------------------------------------------------------------
-      
+
       void CNc4DataOutput::writeTimeAxisAttributes(const StdString & axis_name,
                                                    const StdString & calendar,
                                                    const StdString & units,
                                                    const StdString & time_origin,
+                                                   const StdString & time_bounds,
                                                    const StdString & standard_name,
                                                    const StdString & long_name,
@@ -995,6 +1046,7 @@
          SuperClassWriter::addAttribute("units",         units        , &axis_name);
          SuperClassWriter::addAttribute("time_origin",   time_origin  , &axis_name);
-      }
-      
+         SuperClassWriter::addAttribute("bounds",        time_bounds  , &axis_name);
+      }
+
       //---------------------------------------------------------------
 
@@ -1014,5 +1066,5 @@
 
       //---------------------------------------------------------------
-      
+
       void CNc4DataOutput::writeLocalAttributes
          (int ibegin, int ni, int jbegin, int nj, StdString domid)
