Index: XIOS/dev/branch_yushan/src/io/nc4_data_output.cpp
===================================================================
--- XIOS/dev/branch_yushan/src/io/nc4_data_output.cpp	(revision 1036)
+++ XIOS/dev/branch_yushan/src/io/nc4_data_output.cpp	(revision 1037)
@@ -21,5 +21,5 @@
             , filename(filename)
       {
-        SuperClass::type = MULTI_FILE;
+    SuperClass::type = MULTI_FILE;
       }
 
@@ -33,5 +33,5 @@
             , isCollective(isCollective)
       {
-        SuperClass::type = (multifile) ? MULTI_FILE : ONE_FILE;
+    SuperClass::type = (multifile) ? MULTI_FILE : ONE_FILE;
       }
 
@@ -1458,126 +1458,126 @@
       void CNc4DataOutput::writeField_(CField* field)
       {
-        CContext* context = CContext::getCurrent() ;
-        CContextServer* server=context->server ;
-
-        std::vector<StdString> dims, coodinates;
-        CGrid* grid = field->grid;
-        if (!grid->doGridHaveDataToWrite())
+         CContext* context = CContext::getCurrent() ;
+         CContextServer* server=context->server ;
+
+         std::vector<StdString> dims, coodinates;
+         CGrid* grid = field->grid;
+         if (!grid->doGridHaveDataToWrite())
           if (SuperClass::type==MULTI_FILE) return ;
 
-        CArray<int,1> axisDomainOrder = grid->axis_domain_order;
-        int numElement = axisDomainOrder.numElements(), idxDomain = 0, idxAxis = 0, idxScalar = 0;
-        std::vector<StdString> domainList = grid->getDomainList();
-        std::vector<StdString> axisList   = grid->getAxisList();
-        std::vector<StdString> scalarList = grid->getScalarList();        
-
-        StdString timeid  = getTimeCounterName();
-        StdString dimXid,dimYid;
-        std::deque<StdString> dimIdList, dimCoordList;
-        bool hasArea = false;
-        StdString cellMeasures = "area:";
-        bool compressedOutput = !field->indexed_output.isEmpty() && field->indexed_output;
-
-        for (int i = 0; i < numElement; ++i)
-        {
-          if (2 == axisDomainOrder(i))
-          {
-            CDomain* domain = CDomain::get(domainList[idxDomain]);
-            StdString domId = domain->getDomainOutputName();
-            StdString appendDomId  = singleDomain ? "" : "_" + domId ;
-
-            if (compressedOutput && domain->isCompressible() && domain->type != CDomain::type_attr::unstructured)
+         CArray<int,1> axisDomainOrder = grid->axis_domain_order;
+         int numElement = axisDomainOrder.numElements(), idxDomain = 0, idxAxis = 0, idxScalar = 0;
+         std::vector<StdString> domainList = grid->getDomainList();
+         std::vector<StdString> axisList   = grid->getAxisList();
+         std::vector<StdString> scalarList = grid->getScalarList();
+
+         StdString timeid  = getTimeCounterName();
+         StdString dimXid,dimYid;
+         std::deque<StdString> dimIdList, dimCoordList;
+         bool hasArea = false;
+         StdString cellMeasures = "area:";
+         bool compressedOutput = !field->indexed_output.isEmpty() && field->indexed_output;
+
+         for (int i = 0; i < numElement; ++i)
+         {
+           if (2 == axisDomainOrder(i))
+           {
+             CDomain* domain = CDomain::get(domainList[idxDomain]);
+             StdString domId = domain->getDomainOutputName();
+             StdString appendDomId  = singleDomain ? "" : "_" + domId ;
+
+             if (compressedOutput && domain->isCompressible() && domain->type != CDomain::type_attr::unstructured)
+             {
+               dimIdList.push_back(domId + "_points");
+               field->setUseCompressedOutput();
+             }
+
+             switch (domain->type)
+             {
+               case CDomain::type_attr::curvilinear:
+                 if (!compressedOutput || !domain->isCompressible())
+                 {
+                   dimXid     = StdString("x").append(appendDomId);
+                   dimIdList.push_back(dimXid);
+                   dimYid     = StdString("y").append(appendDomId);
+                   dimIdList.push_back(dimYid);
+                 }
+                 dimCoordList.push_back(StdString("nav_lon").append(appendDomId));
+                 dimCoordList.push_back(StdString("nav_lat").append(appendDomId));
+                 break ;
+               case CDomain::type_attr::rectilinear:
+                 if (!compressedOutput || !domain->isCompressible())
+                 {
+                   dimXid     = StdString("lon").append(appendDomId);
+                   dimIdList.push_back(dimXid);
+                   dimYid     = StdString("lat").append(appendDomId);
+                   dimIdList.push_back(dimYid);
+                 }
+                 break ;
+               case CDomain::type_attr::unstructured:
+               {
+           if (SuperClassWriter::useCFConvention)
+           {
+            dimXid     = StdString("cell").append(appendDomId);
+            dimIdList.push_back(dimXid);
+            dimCoordList.push_back(StdString("lon").append(appendDomId));
+            dimCoordList.push_back(StdString("lat").append(appendDomId));
+          }
+           else
+           {
+            StdString domainName = domain->name;
+            if (domain->nvertex == 1)
             {
-              dimIdList.push_back(domId + "_points");
-              field->setUseCompressedOutput();
+              dimXid     = "n" + domainName + "_node";
+              dimIdList.push_back(dimXid);
+              dimCoordList.push_back(StdString(domainName + "_node_x"));
+              dimCoordList.push_back(StdString(domainName + "_node_y"));
             }
-
-            switch (domain->type)
+            else if (domain->nvertex == 2)
             {
-              case CDomain::type_attr::curvilinear:
-                if (!compressedOutput || !domain->isCompressible())
-                {
-                  dimXid     = StdString("x").append(appendDomId);
-                  dimIdList.push_back(dimXid);
-                  dimYid     = StdString("y").append(appendDomId);
-                  dimIdList.push_back(dimYid);
-                }
-                dimCoordList.push_back(StdString("nav_lon").append(appendDomId));
-                dimCoordList.push_back(StdString("nav_lat").append(appendDomId));
-              break ;
-              case CDomain::type_attr::rectilinear:
-                if (!compressedOutput || !domain->isCompressible())
-                {
-                  dimXid     = StdString("lon").append(appendDomId);
-                  dimIdList.push_back(dimXid);
-                  dimYid     = StdString("lat").append(appendDomId);
-                  dimIdList.push_back(dimYid);
-                }
-              break ;
-              case CDomain::type_attr::unstructured:
-              {
-                if (SuperClassWriter::useCFConvention)
-                {
-                  dimXid     = StdString("cell").append(appendDomId);
-                  dimIdList.push_back(dimXid);
-                  dimCoordList.push_back(StdString("lon").append(appendDomId));
-                  dimCoordList.push_back(StdString("lat").append(appendDomId));
-                }
-                else
-                {
-                  StdString domainName = domain->name;
-                  if (domain->nvertex == 1)
-                  {
-                    dimXid     = "n" + domainName + "_node";
-                    dimIdList.push_back(dimXid);
-                    dimCoordList.push_back(StdString(domainName + "_node_x"));
-                    dimCoordList.push_back(StdString(domainName + "_node_y"));
-                  }
-                  else if (domain->nvertex == 2)
-                  {
-                    dimXid     = "n" + domainName + "_edge";
-                    dimIdList.push_back(dimXid);
-                    dimCoordList.push_back(StdString(domainName + "_edge_x"));
-                    dimCoordList.push_back(StdString(domainName + "_edge_y"));
-                  }
-                  else
-                  {
-                    dimXid     = "n" + domainName + "_face";
-                    dimIdList.push_back(dimXid);
-                    dimCoordList.push_back(StdString(domainName + "_face_x"));
-                    dimCoordList.push_back(StdString(domainName + "_face_y"));
-                  }
-                }  // ugrid convention
-              }  // case unstructured domain
-            }
-
-            if (domain->hasArea)
-            {
-              hasArea = true;
-              cellMeasures += " area" + appendDomId;
-            }
-            ++idxDomain;
-          }
-          else if (1 == axisDomainOrder(i))
-          {
-            CAxis* axis = CAxis::get(axisList[idxAxis]);
-            StdString axisId = axis->getAxisOutputName();
-
-            if (compressedOutput && axis->isCompressible())
-            {
-              dimIdList.push_back(axisId + "_points");
-              field->setUseCompressedOutput();
+              dimXid     = "n" + domainName + "_edge";
+              dimIdList.push_back(dimXid);
+              dimCoordList.push_back(StdString(domainName + "_edge_x"));
+              dimCoordList.push_back(StdString(domainName + "_edge_y"));
             }
             else
-              dimIdList.push_back(axisId);
-
-            dimCoordList.push_back(axisId);
-            ++idxAxis;
-          }
-          else // scalar
-          {
+            {
+              dimXid     = "n" + domainName + "_face";
+              dimIdList.push_back(dimXid);
+              dimCoordList.push_back(StdString(domainName + "_face_x"));
+              dimCoordList.push_back(StdString(domainName + "_face_y"));
+            }
+          }  // ugrid convention
+        }  // case unstructured domain
+             }
+
+             if (domain->hasArea)
+             {
+               hasArea = true;
+               cellMeasures += " area" + appendDomId;
+             }
+             ++idxDomain;
+           }
+           else if (1 == axisDomainOrder(i))
+           {
+             CAxis* axis = CAxis::get(axisList[idxAxis]);
+             StdString axisId = axis->getAxisOutputName();
+
+             if (compressedOutput && axis->isCompressible())
+             {
+               dimIdList.push_back(axisId + "_points");
+               field->setUseCompressedOutput();
+             }
+             else
+               dimIdList.push_back(axisId);
+
+             dimCoordList.push_back(axisId);
+             ++idxAxis;
+           }
+           else // scalar
+           {
              /* Do nothing here */
-          }
-        }
+           }
+         }
 
 /*
@@ -1589,51 +1589,51 @@
                              : latid;
 */
-        StdString fieldid = field->getFieldOutputName();
-
-        nc_type type ;
-        if (field->prec.isEmpty()) type =  NC_FLOAT ;
-        else
-        {
-          if (field->prec==2) type = NC_SHORT ;
-          else if (field->prec==4)  type =  NC_FLOAT ;
-          else if (field->prec==8)   type =  NC_DOUBLE ;
-        }
-
-        bool wtime   = !(!field->operation.isEmpty() && field->getOperationTimeType() == func::CFunctor::once);
-
-        if (wtime)
-        {
-
-          //StdOStringStream oss;
-          // oss << "time_" << field->operation.getValue()
-          //     << "_" << field->getRelFile()->output_freq.getValue();
+         StdString fieldid = field->getFieldOutputName();
+
+         nc_type type ;
+         if (field->prec.isEmpty()) type =  NC_FLOAT ;
+         else
+         {
+           if (field->prec==2) type = NC_SHORT ;
+           else if (field->prec==4)  type =  NC_FLOAT ;
+           else if (field->prec==8)   type =  NC_DOUBLE ;
+         }
+
+         bool wtime   = !(!field->operation.isEmpty() && field->getOperationTimeType() == func::CFunctor::once);
+
+         if (wtime)
+         {
+
+            //StdOStringStream oss;
+           // oss << "time_" << field->operation.getValue()
+           //     << "_" << field->getRelFile()->output_freq.getValue();
           //oss
-          if (field->getOperationTimeType() == func::CFunctor::instant) coodinates.push_back(string("time_instant"));
-          else if (field->getOperationTimeType() == func::CFunctor::centered) coodinates.push_back(string("time_centered"));
-          dims.push_back(timeid);
-        }
-
-        if (compressedOutput && grid->isCompressible())
-        {
-          dims.push_back(grid->getId() + "_points");
-          field->setUseCompressedOutput();
-        }
-        else
-        {
-          while (!dimIdList.empty())
-          {
-            dims.push_back(dimIdList.back());
-            dimIdList.pop_back();
-          }
-        }
-
-        while (!dimCoordList.empty())
-        {
-          coodinates.push_back(dimCoordList.back());
-          dimCoordList.pop_back();
-        }
-
-        try
-        {
+            if (field->getOperationTimeType() == func::CFunctor::instant) coodinates.push_back(string("time_instant"));
+            else if (field->getOperationTimeType() == func::CFunctor::centered) coodinates.push_back(string("time_centered"));
+            dims.push_back(timeid);
+         }
+
+         if (compressedOutput && grid->isCompressible())
+         {
+           dims.push_back(grid->getId() + "_points");
+           field->setUseCompressedOutput();
+         }
+         else
+         {
+           while (!dimIdList.empty())
+           {
+             dims.push_back(dimIdList.back());
+             dimIdList.pop_back();
+           }
+         }
+
+         while (!dimCoordList.empty())
+         {
+           coodinates.push_back(dimCoordList.back());
+           dimCoordList.pop_back();
+         }
+
+         try
+         {
            SuperClassWriter::addVariable(fieldid, type, dims);
 
@@ -1650,25 +1650,5 @@
                  ("units", field->unit.getValue(), &fieldid);
 
-           // Ugrid field attributes "mesh" and "location"
-           if (!SuperClassWriter::useCFConvention)
-           {
-            if (!domainList.empty())
-            {
-              CDomain* domain = CDomain::get(domainList[0]); // Suppose that we have only domain
-              StdString mesh = domain->name;
-              SuperClassWriter::addAttribute("mesh", mesh, &fieldid);
-              StdString location;
-              if (domain->nvertex == 1)
-                location = "node";
-              else if (domain->nvertex == 2)
-                location = "edge";
-              else if (domain->nvertex > 2)
-                location = "face";
-              SuperClassWriter::addAttribute("location", location, &fieldid);
-            }
-
-           }
-
-           if (!field->valid_min.isEmpty())
+            if (!field->valid_min.isEmpty())
               SuperClassWriter::addAttribute
                  ("valid_min", field->valid_min.getValue(), &fieldid);
@@ -1694,35 +1674,4 @@
            vector<CVariable*> listVars = field->getAllVariables() ;
            for (vector<CVariable*>::iterator it = listVars.begin() ;it != listVars.end(); it++) writeAttribute_(*it, fieldid) ;
-
-           bool alreadyAddCellMethod = false;
-           StdString cellMethodsPrefix(""), cellMethodsSuffix("");
-           if (!field->cell_methods.isEmpty())
-           {
-              StdString cellMethodString = field->cell_methods;
-              if (field->cell_methods_mode.isEmpty() ||
-                 (CField::cell_methods_mode_attr::overwrite == field->cell_methods_mode))
-              {
-                SuperClassWriter::addAttribute("cell_methods", cellMethodString, &fieldid);
-                alreadyAddCellMethod = true;
-              }
-              else
-              {
-                switch (field->cell_methods_mode)
-                {
-                  case (CField::cell_methods_mode_attr::prefix):
-                    cellMethodsPrefix = cellMethodString;
-                    cellMethodsPrefix += " ";
-                    break;
-                  case (CField::cell_methods_mode_attr::suffix):
-                    cellMethodsSuffix = " ";
-                    cellMethodsSuffix += cellMethodString;
-                    break;
-                  case (CField::cell_methods_mode_attr::none):
-                    break;
-                  default:
-                    break;
-                }
-              }
-           }
 
 
@@ -1738,5 +1687,5 @@
               SuperClassWriter::addAttribute("interval_write", freqOut.toStringUDUnits(), &fieldid);
 
-              StdString cellMethods(cellMethodsPrefix + "time: ");
+              StdString cellMethods = "time: ";
               if (field->operation.getValue() == "instant") cellMethods += "point";
               else if (field->operation.getValue() == "average") cellMethods += "mean";
@@ -1745,7 +1694,5 @@
               if (freqOp.resolve(*context->calendar) != freqOut.resolve(*context->calendar))
                 cellMethods += " (interval: " + freqOpStr + ")";
-              cellMethods += cellMethodsSuffix;
-              if (!alreadyAddCellMethod)
-                SuperClassWriter::addAttribute("cell_methods", cellMethods, &fieldid);
+              SuperClassWriter::addAttribute("cell_methods", cellMethods, &fieldid);
            }
 
@@ -1813,5 +1760,5 @@
        if (SuperClassWriter::useCFConvention)
              this->writeFileAttributes(filename, description,
-                                       StdString("CF-1.6"),
+                                       StdString("CF-1.5"),
                                        StdString("An IPSL model"),
                                        this->getTimeStamp());
@@ -1981,6 +1928,5 @@
         if (!field->wasWritten())
         {
-          if (appendMode && field->file->record_offset.isEmpty() && 
-              field->getOperationTimeType() != func::CFunctor::once)
+          if (appendMode && field->file->record_offset.isEmpty())
           {
             field->resetNStep(getRecordFromTime(field->last_Write_srv) + 1);
@@ -2015,12 +1961,6 @@
             time_data_bound(1) = lastWrite;
           }
-          
-          if (field->file->time_counter.isEmpty())
-            if (field->hasTimeInstant && !field->hasTimeCentered)
-              time_counter(0) = lastWrite;
-            else 
-              time_counter(0) = (lastWrite + lastLastWrite) / 2;
-
-          else if (field->file->time_counter == CFile::time_counter_attr::instant)
+
+          if (field->file->time_counter == CFile::time_counter_attr::instant)
             time_counter(0) = lastWrite;
           else if (field->file->time_counter == CFile::time_counter_attr::centered)
@@ -2030,13 +1970,5 @@
 
 
-          if (field->file->time_counter.isEmpty())
-            if (field->hasTimeInstant && !field->hasTimeCentered)
-              time_counter_bound(0) = time_counter_bound(1) = lastWrite;
-            else 
-            {
-              time_counter_bound(0) = lastLastWrite;
-              time_counter_bound(1) = lastWrite;
-            }          
-          else if (field->file->time_counter == CFile::time_counter_attr::instant)
+          if (field->file->time_counter == CFile::time_counter_attr::instant)
             time_counter_bound(0) = time_counter_bound(1) = lastWrite;
           else if (field->file->time_counter == CFile::time_counter_attr::centered)
@@ -2087,10 +2019,8 @@
                    SuperClassWriter::writeData(time_data, timeAxisId, isCollective, field->getNStep() - 1);
                    SuperClassWriter::writeData(time_data_bound, timeAxisBoundId, isCollective, field->getNStep() - 1);
-                   if (field->file->time_counter.isEmpty() ||  
-                      (field->file->time_counter != CFile::time_counter_attr::none))
+                   if (field->file->time_counter != CFile::time_counter_attr::none)
                    {
                      SuperClassWriter::writeData(time_counter, getTimeCounterName(), isCollective, field->getNStep() - 1);
-                     if (field->file->time_counter.isEmpty() || 
-                        (field->file->time_counter != CFile::time_counter_attr::record))
+                     if (field->file->time_counter != CFile::time_counter_attr::record)
                        SuperClassWriter::writeData(time_counter_bound, timeBoundId, isCollective, field->getNStep() - 1);
                    }
@@ -2225,10 +2155,8 @@
                    SuperClassWriter::writeTimeAxisData(time_data, timeAxisId, isCollective, field->getNStep() - 1, isRoot);
                    SuperClassWriter::writeTimeAxisData(time_data_bound, timeAxisBoundId, isCollective, field->getNStep() - 1, isRoot);
-                   if (field->file->time_counter.isEmpty() || 
-                      (field->file->time_counter != CFile::time_counter_attr::none))
+                   if (field->file->time_counter != CFile::time_counter_attr::none)
                    {
                      SuperClassWriter::writeTimeAxisData(time_counter, getTimeCounterName(), isCollective, field->getNStep() - 1, isRoot);
-                     if (field->file->time_counter.isEmpty() ||  
-                        (field->file->time_counter != CFile::time_counter_attr::record))
+                     if (field->file->time_counter != CFile::time_counter_attr::record)
                        SuperClassWriter::writeTimeAxisData(time_counter_bound, timeBoundId, isCollective, field->getNStep() - 1, isRoot);
                    }
@@ -2271,16 +2199,10 @@
          StdString timeid(getTimeCounterName());
          StdString timeBoundId("axis_nbounds");
- 
+
          if (field->getOperationTimeType() == func::CFunctor::instant)
          {
             axisid = "time_instant";
             axisBoundId = "time_instant_bounds";
-            field->hasTimeInstant = true;                   
-         }
-
-         if (field->getOperationTimeType() == func::CFunctor::centered)
-         {
-            field->hasTimeCentered = true;            
-         }          
+         }
 
          try
@@ -2314,6 +2236,5 @@
            }
 
-           if (field->file->time_counter.isEmpty() ||  
-              (field->file->time_counter != CFile::time_counter_attr::none))
+           if (field->file->time_counter != CFile::time_counter_attr::none)
            {
              // Adding time_counter
@@ -2327,6 +2248,5 @@
                 SuperClassWriter::addAttribute("axis", string("T"), &axisid);
 
-                if (field->file->time_counter.isEmpty() || 
-                   (field->file->time_counter != CFile::time_counter_attr::record))
+                if (field->file->time_counter != CFile::time_counter_attr::record)
                 {
                   CDate timeOrigin = cal->getTimeOrigin();
@@ -2340,6 +2260,5 @@
 
              // Adding time_counter_bound dimension
-             if (field->file->time_counter.isEmpty() ||  
-                (field->file->time_counter != CFile::time_counter_attr::record))
+             if (field->file->time_counter != CFile::time_counter_attr::record)
              {
                 if (!SuperClassWriter::varExist(axisBoundId))
@@ -2516,5 +2435,5 @@
            SuperClassWriter::addAttribute("title"      , description);
            SuperClassWriter::addAttribute("Conventions", conventions);
-           // SuperClassWriter::addAttribute("production" , production);
+           SuperClassWriter::addAttribute("production" , production);
            SuperClassWriter::addAttribute("timeStamp"  , timeStamp);
          }
