Index: XIOS/trunk/src/output/nc4_data_output.cpp
===================================================================
--- XIOS/trunk/src/output/nc4_data_output.cpp	(revision 488)
+++ XIOS/trunk/src/output/nc4_data_output.cpp	(revision 498)
@@ -10,4 +10,6 @@
 #include "context.hpp"
 #include "context_server.hpp"
+#include "netCdfException.hpp"
+#include "exception.hpp"
 
 namespace xios
@@ -105,209 +107,222 @@
 */
 
-         switch (SuperClass::type)
-         {
-            case (MULTI_FILE) :
-            {
-//               if (domain->isEmpty()) return;
-
-               if (server->intraCommSize > 1)
-               {
-//                 SuperClassWriter::addDimension(lonid, domain->zoom_ni.getValue());
-//                 SuperClassWriter::addDimension(latid, domain->zoom_nj.getValue());
-               }
-
-               switch (domain->type)
-               {
-                 case CDomain::type_attr::curvilinear :
-                   dim0.push_back(dimYid); dim0.push_back(dimXid);
-                   lonid = StdString("nav_lon").append(appendDomid);
-                   latid = StdString("nav_lat").append(appendDomid);
-                   break ;
-                 case CDomain::type_attr::regular :
-                   lonid = StdString("lon").append(appendDomid);
-                   latid = StdString("lat").append(appendDomid);
-                   dim0.push_back(dimYid);
-                   dim1.push_back(dimXid);
-                   break;
-                 case CDomain::type_attr::unstructured :
-                   lonid = StdString("lon").append(appendDomid);
-                   latid = StdString("lat").append(appendDomid);
-                   bounds_lonid=string("bounds_lon").append(appendDomid);
-                   bounds_latid=string("bounds_lat").append(appendDomid);
-                   dim0.push_back(dimXid);
-                   break;
-               }
-
-               if (domain->type == CDomain::type_attr::unstructured)
-               {
-                 SuperClassWriter::addDimension(dimXid, domain->nj_glo);
-               }
-               else
-               {
-                 SuperClassWriter::addDimension(dimXid, domain->zoom_ni_srv);
-                 SuperClassWriter::addDimension(dimYid, domain->zoom_nj_srv);
-               }
-
-               if (server->intraCommSize > 1)
-               {
-                  if (domain->type != CDomain::type_attr::unstructured)
-                  {
-                    this->writeLocalAttributes(domain->zoom_ibegin_srv,
-                                               domain->zoom_ni_srv,
-                                               domain->zoom_jbegin_srv,
-                                               domain->zoom_nj_srv,
-                                               appendDomid);
-
-                    if (singleDomain) this->writeLocalAttributes_IOIPSL(domain->zoom_ibegin_srv,
-                                               domain->zoom_ni_srv,
-                                               domain->zoom_jbegin_srv,
-                                               domain->zoom_nj_srv,
-                                               domain->ni_glo,domain->nj_glo,
-                                               server->intraCommRank,server->intraCommSize);
-                 }
-               }
-
-               switch (domain->type)
-               {
-                 case CDomain::type_attr::curvilinear :
-                   SuperClassWriter::addVariable(latid, NC_FLOAT, dim0);
-                   SuperClassWriter::addVariable(lonid, NC_FLOAT, dim0);
-                   break ;
-                  case CDomain::type_attr::regular :
-                    SuperClassWriter::addVariable(latid, NC_FLOAT, dim0);
-                    SuperClassWriter::addVariable(lonid, NC_FLOAT, dim1);
-                    break ;
-                  case CDomain::type_attr::unstructured :
-                    SuperClassWriter::addVariable(latid, NC_FLOAT, dim0);
-                    SuperClassWriter::addVariable(lonid, NC_FLOAT, dim0);
-               }
-
-               this->writeAxisAttributes(lonid, "X", "longitude", "Longitude", "degrees_east", domid);
-               this->writeAxisAttributes(latid, "Y", "latitude", "Latitude", "degrees_north", domid);
-
-               dim0.clear();
-               if (domain->type != CDomain::type_attr::unstructured) dim0.push_back(dimYid);
-               dim0.push_back(dimXid);
-
-
-// supress mask               if (server->intraCommSize > 1)
-// supress mask               {
-// supress mask                  SuperClassWriter::addVariable(maskid, NC_INT, dim0);
-// supress mask
-// supress mask                  this->writeMaskAttributes(maskid,
-// supress mask                     domain->data_dim.getValue()/*,
-// supress mask                     domain->data_ni.getValue(),
-// supress mask                     domain->data_nj.getValue(),
-// supress mask                     domain->data_ibegin.getValue(),
-// supress mask                     domain->data_jbegin.getValue()*/);
-// supress mask               }
-
-               //SuperClassWriter::setDefaultValue(maskid, &dvm);
-
-               SuperClassWriter::definition_end();
-
-               switch (domain->type)
-               {
-                 case CDomain::type_attr::curvilinear :
-                   SuperClassWriter::writeData(domain->latvalue_srv, latid, isCollective, 0);
-                   SuperClassWriter::writeData(domain->lonvalue_srv, lonid, isCollective, 0);
-                   break;
-                 case CDomain::type_attr::regular :
-                   CArray<double,1> lat = domain->latvalue_srv(Range(fromStart,toEnd,domain->zoom_ni_srv)) ;
-                   SuperClassWriter::writeData(CArray<double,1>(lat.copy()), latid, isCollective, 0);
-                   CArray<double,1> lon=domain->lonvalue_srv(Range(0,domain->zoom_ni_srv-1)) ;
-                   SuperClassWriter::writeData(CArray<double,1>(lon.copy()), lonid, isCollective, 0);
-                   break;
-               }
-               SuperClassWriter::definition_start();
-
-               break;
-            }
-            case (ONE_FILE) :
-            {
-               SuperClassWriter::addDimension(dimXid, domain->zoom_ni.getValue());
-               SuperClassWriter::addDimension(dimYid, domain->zoom_nj.getValue());
-
-
-               switch (domain->type)
-               {
-                 case CDomain::type_attr::curvilinear :
-                   dim0.push_back(dimYid); dim0.push_back(dimXid);
-                   lonid = StdString("nav_lon").append(appendDomid);
-                   latid = StdString("nav_lat").append(appendDomid);
-                   SuperClassWriter::addVariable(latid, NC_FLOAT, dim0);
-                   SuperClassWriter::addVariable(lonid, NC_FLOAT, dim0);
-                   break;
-
-                 case CDomain::type_attr::regular :
-                   dim0.push_back(dimYid);
-                   dim1.push_back(dimXid);
-                   lonid = StdString("lon").append(appendDomid);
-                   latid = StdString("lat").append(appendDomid);
-                   SuperClassWriter::addVariable(latid, NC_FLOAT, dim0);
-                   SuperClassWriter::addVariable(lonid, NC_FLOAT, dim1);
-                   break;
-               }
-               this->writeAxisAttributes
-                  (lonid, "X", "longitude", "Longitude", "degrees_east", domid);
-               this->writeAxisAttributes
-                  (latid, "Y", "latitude", "Latitude", "degrees_north", domid);
-
-
-               SuperClassWriter::definition_end();
-               switch (domain->type)
-               {
-                 case CDomain::type_attr::curvilinear :
-                 {
-                   std::vector<StdSize> start(2) ;
-                   std::vector<StdSize> count(2) ;
-                   if (domain->isEmpty())
+         try
+         {
+           switch (SuperClass::type)
+           {
+              case (MULTI_FILE) :
+              {
+  //               if (domain->isEmpty()) return;
+
+                 if (server->intraCommSize > 1)
+                 {
+  //                 SuperClassWriter::addDimension(lonid, domain->zoom_ni.getValue());
+  //                 SuperClassWriter::addDimension(latid, domain->zoom_nj.getValue());
+                 }
+
+                 switch (domain->type)
+                 {
+                   case CDomain::type_attr::curvilinear :
+                     dim0.push_back(dimYid); dim0.push_back(dimXid);
+                     lonid = StdString("nav_lon").append(appendDomid);
+                     latid = StdString("nav_lat").append(appendDomid);
+                     break ;
+                   case CDomain::type_attr::regular :
+                     lonid = StdString("lon").append(appendDomid);
+                     latid = StdString("lat").append(appendDomid);
+                     dim0.push_back(dimYid);
+                     dim1.push_back(dimXid);
+                     break;
+                   case CDomain::type_attr::unstructured :
+                     lonid = StdString("lon").append(appendDomid);
+                     latid = StdString("lat").append(appendDomid);
+                     bounds_lonid=string("bounds_lon").append(appendDomid);
+                     bounds_latid=string("bounds_lat").append(appendDomid);
+                     dim0.push_back(dimXid);
+                     break;
+                 }
+
+                 if (domain->type == CDomain::type_attr::unstructured)
+                 {
+                   SuperClassWriter::addDimension(dimXid, domain->nj_glo);
+                 }
+                 else
+                 {
+                   SuperClassWriter::addDimension(dimXid, domain->zoom_ni_srv);
+                   SuperClassWriter::addDimension(dimYid, domain->zoom_nj_srv);
+                 }
+
+                 if (server->intraCommSize > 1)
+                 {
+                    if (domain->type != CDomain::type_attr::unstructured)
+                    {
+                      this->writeLocalAttributes(domain->zoom_ibegin_srv,
+                                                 domain->zoom_ni_srv,
+                                                 domain->zoom_jbegin_srv,
+                                                 domain->zoom_nj_srv,
+                                                 appendDomid);
+
+                      if (singleDomain) this->writeLocalAttributes_IOIPSL(domain->zoom_ibegin_srv,
+                                                 domain->zoom_ni_srv,
+                                                 domain->zoom_jbegin_srv,
+                                                 domain->zoom_nj_srv,
+                                                 domain->ni_glo,domain->nj_glo,
+                                                 server->intraCommRank,server->intraCommSize);
+                   }
+                 }
+
+                 switch (domain->type)
+                 {
+                   case CDomain::type_attr::curvilinear :
+                     SuperClassWriter::addVariable(latid, NC_FLOAT, dim0);
+                     SuperClassWriter::addVariable(lonid, NC_FLOAT, dim0);
+                     break ;
+                    case CDomain::type_attr::regular :
+                      SuperClassWriter::addVariable(latid, NC_FLOAT, dim0);
+                      SuperClassWriter::addVariable(lonid, NC_FLOAT, dim1);
+                      break ;
+                    case CDomain::type_attr::unstructured :
+                      SuperClassWriter::addVariable(latid, NC_FLOAT, dim0);
+                      SuperClassWriter::addVariable(lonid, NC_FLOAT, dim0);
+                 }
+
+                 this->writeAxisAttributes(lonid, "X", "longitude", "Longitude", "degrees_east", domid);
+                 this->writeAxisAttributes(latid, "Y", "latitude", "Latitude", "degrees_north", domid);
+
+                 dim0.clear();
+                 if (domain->type != CDomain::type_attr::unstructured) dim0.push_back(dimYid);
+                 dim0.push_back(dimXid);
+
+
+  // supress mask               if (server->intraCommSize > 1)
+  // supress mask               {
+  // supress mask                  SuperClassWriter::addVariable(maskid, NC_INT, dim0);
+  // supress mask
+  // supress mask                  this->writeMaskAttributes(maskid,
+  // supress mask                     domain->data_dim.getValue()/*,
+  // supress mask                     domain->data_ni.getValue(),
+  // supress mask                     domain->data_nj.getValue(),
+  // supress mask                     domain->data_ibegin.getValue(),
+  // supress mask                     domain->data_jbegin.getValue()*/);
+  // supress mask               }
+
+                 //SuperClassWriter::setDefaultValue(maskid, &dvm);
+
+                 SuperClassWriter::definition_end();
+
+                 switch (domain->type)
+                 {
+                   case CDomain::type_attr::curvilinear :
+                     SuperClassWriter::writeData(domain->latvalue_srv, latid, isCollective, 0);
+                     SuperClassWriter::writeData(domain->lonvalue_srv, lonid, isCollective, 0);
+                     break;
+                   case CDomain::type_attr::regular :
+                     CArray<double,1> lat = domain->latvalue_srv(Range(fromStart,toEnd,domain->zoom_ni_srv)) ;
+                     SuperClassWriter::writeData(CArray<double,1>(lat.copy()), latid, isCollective, 0);
+                     CArray<double,1> lon=domain->lonvalue_srv(Range(0,domain->zoom_ni_srv-1)) ;
+                     SuperClassWriter::writeData(CArray<double,1>(lon.copy()), lonid, isCollective, 0);
+                     break;
+                 }
+                 SuperClassWriter::definition_start();
+
+                 break;
+              }
+              case (ONE_FILE) :
+              {
+                 SuperClassWriter::addDimension(dimXid, domain->zoom_ni.getValue());
+                 SuperClassWriter::addDimension(dimYid, domain->zoom_nj.getValue());
+
+
+                 switch (domain->type)
+                 {
+                   case CDomain::type_attr::curvilinear :
+                     dim0.push_back(dimYid); dim0.push_back(dimXid);
+                     lonid = StdString("nav_lon").append(appendDomid);
+                     latid = StdString("nav_lat").append(appendDomid);
+                     SuperClassWriter::addVariable(latid, NC_FLOAT, dim0);
+                     SuperClassWriter::addVariable(lonid, NC_FLOAT, dim0);
+                     break;
+
+                   case CDomain::type_attr::regular :
+                     dim0.push_back(dimYid);
+                     dim1.push_back(dimXid);
+                     lonid = StdString("lon").append(appendDomid);
+                     latid = StdString("lat").append(appendDomid);
+                     SuperClassWriter::addVariable(latid, NC_FLOAT, dim0);
+                     SuperClassWriter::addVariable(lonid, NC_FLOAT, dim1);
+                     break;
+                 }
+                 this->writeAxisAttributes
+                    (lonid, "X", "longitude", "Longitude", "degrees_east", domid);
+                 this->writeAxisAttributes
+                    (latid, "Y", "latitude", "Latitude", "degrees_north", domid);
+
+
+                 SuperClassWriter::definition_end();
+                 switch (domain->type)
+                 {
+                   case CDomain::type_attr::curvilinear :
                    {
-                     start[0]=0 ; start [1]=0 ;
-                     count[0]=0 ; count[1]=0 ;
+                     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_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);
+                     break;
                    }
-                   else
+                   case CDomain::type_attr::regular :
                    {
-                     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 ;
+                     std::vector<StdSize> start(1) ;
+                     std::vector<StdSize> count(1) ;
+                     if (domain->isEmpty())
+                     {
+                       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 ;
+                       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 ;
+                       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);
+                     }
+                     break;
                    }
-
-                   SuperClassWriter::writeData(domain->latvalue_srv, latid, isCollective, 0,&start,&count);
-                   SuperClassWriter::writeData(domain->lonvalue_srv, lonid, isCollective, 0,&start,&count);
-                   break;
-                 }
-                 case CDomain::type_attr::regular :
-                 {
-                   std::vector<StdSize> start(1) ;
-                   std::vector<StdSize> count(1) ;
-                   if (domain->isEmpty())
-                   {
-                     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 ;
-                     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 ;
-                     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);
-                   }
-                   break;
-                 }
-               }
-               SuperClassWriter::definition_start();
-               break;
-            }
-            default :
-               ERROR("CNc4DataOutput::writeDomain(domain)",
-                     << "[ type = " << SuperClass::type << "]"
-                     << " not implemented yet !");
-         }
+                 }
+                 SuperClassWriter::definition_start();
+                 break;
+              }
+              default :
+                 ERROR("CNc4DataOutput::writeDomain(domain)",
+                       << "[ type = " << SuperClass::type << "]"
+                       << " not implemented yet !");
+           }
+         }
+         catch (CNetCdfException& e)
+         {
+           StdString msg("On writing the domain : ");
+           msg.append(domid); msg.append("\n");
+           msg.append("In the context : ");
+           msg.append(context->getId()); msg.append("\n");
+           msg.append(e.what());
+           ERROR("CNc4DataOutput::writeDomain_(CDomain* domain)", << msg);
+         }
+
          domain->addRelFile(this->filename);
       }
@@ -335,115 +350,127 @@
          string lonid,latid,bounds_lonid,bounds_latid ;
 
-         switch (SuperClass::type)
-         {
-            case (MULTI_FILE) :
-            {
-               lonid = StdString("lon").append(appendDomid);
-               latid = StdString("lat").append(appendDomid);
-               dim0.push_back(dimXid);
-
-               SuperClassWriter::addDimension(dimXid, domain->zoom_nj_srv);
-               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);
-               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)
-               {
+         try
+         {
+           switch (SuperClass::type)
+           {
+              case (MULTI_FILE) :
+              {
+                 lonid = StdString("lon").append(appendDomid);
+                 latid = StdString("lat").append(appendDomid);
                  dim0.push_back(dimXid);
-                 dim0.push_back(dimVertId);
-                 SuperClassWriter::addVariable(bounds_lonid, NC_FLOAT, dim0);
-                 SuperClassWriter::addVariable(bounds_latid, NC_FLOAT, dim0);
-               }
-
-               dim0.clear();
-               dim0.push_back(dimXid);
-
-               SuperClassWriter::definition_end();
-
-               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);
-               }
-               SuperClassWriter::definition_start();
-               break ;
-            }
-
-            case (ONE_FILE) :
-            {
-               lonid = StdString("lon").append(appendDomid);
-               latid = StdString("lat").append(appendDomid);
-               bounds_lonid = StdString("bounds_lon").append(appendDomid);
-               bounds_latid = StdString("bounds_lat").append(appendDomid);
-               dim0.push_back(dimXid);
-               SuperClassWriter::addDimension(dimXid, domain->nj_glo);
-               SuperClassWriter::addVariable(latid, NC_FLOAT, dim0);
-               SuperClassWriter::addVariable(lonid, NC_FLOAT, dim0);
-               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);
-               if (domain->hasBounds) SuperClassWriter::addAttribute("bounds",bounds_latid, &latid);
-               if (domain->hasBounds) SuperClassWriter::addDimension(dimVertId, domain->nvertex);
-               dim0.clear();
-
-               if (domain->hasBounds)
-               {
+
+                 SuperClassWriter::addDimension(dimXid, domain->zoom_nj_srv);
+                 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);
+                 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)
+                 {
+                   dim0.push_back(dimXid);
+                   dim0.push_back(dimVertId);
+                   SuperClassWriter::addVariable(bounds_lonid, NC_FLOAT, dim0);
+                   SuperClassWriter::addVariable(bounds_latid, NC_FLOAT, dim0);
+                 }
+
+                 dim0.clear();
                  dim0.push_back(dimXid);
-                 dim0.push_back(dimVertId);
-                 SuperClassWriter::addVariable(bounds_lonid, NC_FLOAT, dim0);
-                 SuperClassWriter::addVariable(bounds_latid, NC_FLOAT, dim0);
-               }
-
-               SuperClassWriter::definition_end();
-
-               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 ;
-                 countBounds[1]=domain->nvertex ;
-                 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 ;
-                 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)
-               {
-                 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 !");
+
+                 SuperClassWriter::definition_end();
+
+                 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);
+                 }
+                 SuperClassWriter::definition_start();
+                 break ;
+              }
+
+              case (ONE_FILE) :
+              {
+                 lonid = StdString("lon").append(appendDomid);
+                 latid = StdString("lat").append(appendDomid);
+                 bounds_lonid = StdString("bounds_lon").append(appendDomid);
+                 bounds_latid = StdString("bounds_lat").append(appendDomid);
+                 dim0.push_back(dimXid);
+                 SuperClassWriter::addDimension(dimXid, domain->nj_glo);
+                 SuperClassWriter::addVariable(latid, NC_FLOAT, dim0);
+                 SuperClassWriter::addVariable(lonid, NC_FLOAT, dim0);
+                 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);
+                 if (domain->hasBounds) SuperClassWriter::addAttribute("bounds",bounds_latid, &latid);
+                 if (domain->hasBounds) SuperClassWriter::addDimension(dimVertId, domain->nvertex);
+                 dim0.clear();
+
+                 if (domain->hasBounds)
+                 {
+                   dim0.push_back(dimXid);
+                   dim0.push_back(dimVertId);
+                   SuperClassWriter::addVariable(bounds_lonid, NC_FLOAT, dim0);
+                   SuperClassWriter::addVariable(bounds_latid, NC_FLOAT, dim0);
+                 }
+
+                 SuperClassWriter::definition_end();
+
+                 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 ;
+                   countBounds[1]=domain->nvertex ;
+                   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 ;
+                   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)
+                 {
+                   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 !");
+           }
+         }
+         catch (CNetCdfException& e)
+         {
+           StdString msg("On writing the domain : ");
+           msg.append(domid); msg.append("\n");
+           msg.append("In the context : ");
+           msg.append(context->getId()); msg.append("\n");
+           msg.append(e.what());
+           ERROR("CNc4DataOutput::writeUnstructuredDomain(CDomain* domain)", << msg);
          }
          domain->addRelFile(this->filename);
@@ -458,50 +485,64 @@
          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 !");
+         try
+         {
+           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 !");
+           }
+         }
+         catch (CNetCdfException& e)
+         {
+           StdString msg("On writing the axis : ");
+           msg.append(axisid); msg.append("\n");
+           msg.append("In the context : ");
+           CContext* context = CContext::getCurrent() ;
+           msg.append(context->getId()); msg.append("\n");
+           msg.append(e.what());
+           ERROR("CNc4DataOutput::writeAxis_(CAxis* axis)", << msg);
          }
          axis->addRelFile(this->filename);
@@ -510,6 +551,18 @@
      void CNc4DataOutput::writeTimeDimension_(void)
      {
-       SuperClassWriter::addDimension("time_counter");
-       SuperClassWriter::addDimension("time_bounds", 2);
+       try
+       {
+        SuperClassWriter::addDimension("time_counter");
+        SuperClassWriter::addDimension("time_bounds", 2);
+       }
+       catch (CNetCdfException& e)
+       {
+         StdString msg("On writing time dimension : time_couter, time_bounds \n");
+         msg.append("In the context : ");
+         CContext* context = CContext::getCurrent() ;
+         msg.append(context->getId()); msg.append("\n");
+         msg.append(e.what());
+         ERROR("CNc4DataOutput::writeTimeDimension_(void)", << msg);
+       }
      }
       //--------------------------------------------------------------
@@ -614,90 +667,101 @@
          dims.push_back(dimXid);
 
-         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);
-
-          if (!field->valid_min.isEmpty())
-            SuperClassWriter::addAttribute
-               ("valid_min", field->valid_min.getValue(), &fieldid);
-
-         if (!field->valid_max.isEmpty())
-            SuperClassWriter::addAttribute
-               ("valid_max", field->valid_max.getValue(), &fieldid);
-
-          if (!field->scale_factor.isEmpty())
-            SuperClassWriter::addAttribute
-               ("scale_factor", field->scale_factor.getValue(), &fieldid);
-
-           if (!field->add_offset.isEmpty())
-            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)
-         {
-            CDuration duration ;
-
-            duration=CDuration::FromString(field->freq_op) ;
-            duration.solveTimeStep(*(context->calendar));
-            SuperClassWriter::addAttribute("interval_operation", duration.toString(), &fieldid);
-
-            duration=CDuration::FromString(field->getRelFile()->output_freq) ;
-            duration.solveTimeStep(*(context->calendar));
-            SuperClassWriter::addAttribute("interval_write", duration.toString(), &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);
-
-         }
-
+         try
+         {
+           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);
+
+            if (!field->valid_min.isEmpty())
+              SuperClassWriter::addAttribute
+                 ("valid_min", field->valid_min.getValue(), &fieldid);
+
+           if (!field->valid_max.isEmpty())
+              SuperClassWriter::addAttribute
+                 ("valid_max", field->valid_max.getValue(), &fieldid);
+
+            if (!field->scale_factor.isEmpty())
+              SuperClassWriter::addAttribute
+                 ("scale_factor", field->scale_factor.getValue(), &fieldid);
+
+             if (!field->add_offset.isEmpty())
+              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)
+           {
+              CDuration duration ;
+
+              duration=CDuration::FromString(field->freq_op) ;
+              duration.solveTimeStep(*(context->calendar));
+              SuperClassWriter::addAttribute("interval_operation", duration.toString(), &fieldid);
+
+              duration=CDuration::FromString(field->getRelFile()->output_freq) ;
+              duration.solveTimeStep(*(context->calendar));
+              SuperClassWriter::addAttribute("interval_write", duration.toString(), &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);
+
+           }
+         }
+         catch (CNetCdfException& e)
+         {
+           StdString msg("On writing field : ");
+           msg.append(fieldid); msg.append("\n");
+           msg.append("In the context : ");
+           msg.append(context->getId()); msg.append("\n");
+           msg.append(e.what());
+           ERROR("CNc4DataOutput::writeField_(CField* field)", << msg);
+         }
       }
 
@@ -711,8 +775,21 @@
                                ? file->description.getValue()
                                : StdString("Created by xios");
-         this->writeFileAttributes(filename, description,
-                                   StdString ("CF-1.1"),
-                                   StdString("An IPSL model"),
-                                   this->getTimeStamp());
+         try
+         {
+           this->writeFileAttributes(filename, description,
+                                     StdString ("CF-1.1"),
+                                     StdString("An IPSL model"),
+                                     this->getTimeStamp());
+         }
+         catch (CNetCdfException& e)
+         {
+           StdString msg("On writing file : ");
+           msg.append(filename); msg.append("\n");
+           msg.append("In the context : ");
+           CContext* context = CContext::getCurrent() ;
+           msg.append(context->getId()); msg.append("\n");
+           msg.append(e.what());
+           ERROR("CNc4DataOutput::writeFile_ (CFile* file)", << msg);
+         }
          if (file->nbDomain==1) singleDomain=true ;
          else singleDomain=false ;
@@ -726,10 +803,23 @@
         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) ;
+        try
+        {
+          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) ;
+        }
+       catch (CNetCdfException& e)
+       {
+         StdString msg("On writing attributes of variable with name : ");
+         msg.append(name); msg.append("in the field "); msg.append(fieldId); msg.append("\n");
+         msg.append("In the context : ");
+         CContext* context = CContext::getCurrent() ;
+         msg.append(context->getId()); msg.append("\n");
+         msg.append(e.what());
+         ERROR("CNc4DataOutput::writeAttribute_ (CVariable* var, const string& fieldId)", << msg);
+       }
      }
 
@@ -740,21 +830,58 @@
         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>()) ;
+        try
+        {
+          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>()) ;
+        }
+       catch (CNetCdfException& e)
+       {
+         StdString msg("On writing attributes of variable with name : ");
+         msg.append(name); msg.append("\n");
+         msg.append("In the context : ");
+         CContext* context = CContext::getCurrent() ;
+         msg.append(context->getId()); msg.append("\n");
+         msg.append(e.what());
+         ERROR("CNc4DataOutput::writeAttribute_ (CVariable* var)", << msg);
+       }
      }
 
       void CNc4DataOutput::syncFile_ (void)
       {
-         SuperClassWriter::sync() ;
+        try
+        {
+          SuperClassWriter::sync() ;
+        }
+        catch (CNetCdfException& e)
+        {
+         StdString msg("On synchronizing the write among processes");
+         msg.append("In the context : ");
+         CContext* context = CContext::getCurrent() ;
+         msg.append(context->getId()); msg.append("\n");
+         msg.append(e.what());
+         ERROR("CNc4DataOutput::syncFile_ (void)", << msg);
+        }
       }
 
       void CNc4DataOutput::closeFile_ (void)
       {
-         SuperClassWriter::close() ;
+        try
+        {
+          SuperClassWriter::close() ;
+        }
+        catch (CNetCdfException& e)
+        {
+         StdString msg("On closing file");
+         msg.append("In the context : ");
+         CContext* context = CContext::getCurrent() ;
+         msg.append(context->getId()); msg.append("\n");
+         msg.append(e.what());
+         ERROR("CNc4DataOutput::syncFile_ (void)", << msg);
+        }
+
       }
 
@@ -842,103 +969,115 @@
          }
 
-         if (grid->hasAxis()) // 3D
-         {
-            CAxis* axis = grid->axis ;
-            CArray<double,3> field_data3D(domain->zoom_ni_srv,domain->zoom_nj_srv,axis->zoom_size) ;
-            if (!field->default_value.isEmpty()) field_data3D = field->default_value ;
-
-            field->outputField(field_data3D);
-
-            if (!field->prec.isEmpty() && field->prec==2) field_data3D=round(field_data3D) ;
-
-            switch (SuperClass::type)
+         try
+         {
+           if (grid->hasAxis()) // 3D
            {
-              case (MULTI_FILE) :
+              CAxis* axis = grid->axis ;
+              CArray<double,3> field_data3D(domain->zoom_ni_srv,domain->zoom_nj_srv,axis->zoom_size) ;
+              if (!field->default_value.isEmpty()) field_data3D = field->default_value ;
+
+              field->outputField(field_data3D);
+
+              if (!field->prec.isEmpty() && field->prec==2) field_data3D=round(field_data3D) ;
+
+              switch (SuperClass::type)
+             {
+                case (MULTI_FILE) :
+                {
+                   SuperClassWriter::writeData(field_data3D, fieldid, isCollective, field->getNStep()-1);
+                   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 ;
+                }
+                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_srv-domain->zoom_ibegin.getValue() ; start [1]=domain->zoom_jbegin_srv-domain->zoom_jbegin.getValue() ; start[0]=0 ;
+                     count[2]=domain->zoom_ni_srv ; count[1]=domain->zoom_nj_srv ; count[0] = axis->zoom_size.getValue();
+                   }
+                   SuperClassWriter::writeData(field_data3D, fieldid, isCollective, field->getNStep()-1,&start,&count );
+                   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
+           {
+              CArray<double,2> field_data2D(domain->zoom_ni_srv,domain->zoom_nj_srv) ;
+              if (!field->default_value.isEmpty()) field_data2D = field->default_value ;
+              field->outputField(field_data2D);
+              if (!field->prec.isEmpty() && field->prec==2) field_data2D=round(field_data2D) ;
+              switch (SuperClass::type)
               {
-                 SuperClassWriter::writeData(field_data3D, fieldid, isCollective, field->getNStep()-1);
-                 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 ;
+                case (MULTI_FILE) :
+                {
+                  SuperClassWriter::writeData(field_data2D, fieldid, isCollective, field->getNStep()-1);
+                  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;
+                }
+                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_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)
+                   {
+                     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;
+
+                }
               }
-              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_srv-domain->zoom_ibegin.getValue() ; start [1]=domain->zoom_jbegin_srv-domain->zoom_jbegin.getValue() ; start[0]=0 ;
-                   count[2]=domain->zoom_ni_srv ; count[1]=domain->zoom_nj_srv ; count[0] = axis->zoom_size.getValue();
-                 }
-                 SuperClassWriter::writeData(field_data3D, fieldid, isCollective, field->getNStep()-1,&start,&count );
-                 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
-         {
-            CArray<double,2> field_data2D(domain->zoom_ni_srv,domain->zoom_nj_srv) ;
-            if (!field->default_value.isEmpty()) field_data2D = field->default_value ;
-            field->outputField(field_data2D);
-            if (!field->prec.isEmpty() && field->prec==2) field_data2D=round(field_data2D) ;
-            switch (SuperClass::type)
-            {
-              case (MULTI_FILE) :
-              {
-                SuperClassWriter::writeData(field_data2D, fieldid, isCollective, field->getNStep()-1);
-                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;
-              }
-              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_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)
-                 {
-                   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;
-
-              }
-            }
+           }
+         }
+         catch (CNetCdfException& e)
+         {
+           StdString msg("On writing field data: ");
+           msg.append(fieldid); msg.append("\n");
+           msg.append("In the context : ");
+           msg.append(context->getId()); msg.append("\n");
+           msg.append(e.what());
+           ERROR("CNc4DataOutput::writeFieldData_ (CField*  field)", << msg);
          }
       }
@@ -973,57 +1112,70 @@
          }
 
-         // Adding time_instant or time_centered
-         std::vector<StdString> dims;
-         dims.push_back(timeid);
-         if (!SuperClassWriter::varExist(axisid))
-         {
-            SuperClassWriter::addVariable(axisid, NC_DOUBLE, dims);
-
-            CDate timeOrigin=cal->getTimeOrigin() ;
-            StdOStringStream oss2;
-//            oss2<<initDate.getYear()<<"-"<<initDate.getMonth()<<"-"<<initDate.getDay()<<" "
-//                <<initDate.getHour()<<"-"<<initDate.getMinute()<<"-"<<initDate.getSecond() ;
-            StdString strInitdate=oss2.str() ;
-            StdString strTimeOrigin=timeOrigin.toString() ;
-            this->writeTimeAxisAttributes
-               (axisid, cal->getType(),
-                StdString("seconds since ").append(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() ;
-         dims.push_back(timeid);
-         if (!SuperClassWriter::varExist(axisid))
-         {
-            SuperClassWriter::addVariable(axisid, NC_DOUBLE, dims);
-            SuperClassWriter::addAttribute("axis", string("T"), &axisid);
-            CDate timeOrigin=cal->getTimeOrigin() ;
-            StdString strTimeOrigin=timeOrigin.toString() ;
-
-            this->writeTimeAxisAttributes
-               (axisid, cal->getType(),
-                StdString("seconds since ").append(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);
+         try
+         {
+          // Adding time_instant or time_centered
+           std::vector<StdString> dims;
+           dims.push_back(timeid);
+           if (!SuperClassWriter::varExist(axisid))
+           {
+              SuperClassWriter::addVariable(axisid, NC_DOUBLE, dims);
+
+              CDate timeOrigin=cal->getTimeOrigin() ;
+              StdOStringStream oss2;
+  //            oss2<<initDate.getYear()<<"-"<<initDate.getMonth()<<"-"<<initDate.getDay()<<" "
+  //                <<initDate.getHour()<<"-"<<initDate.getMinute()<<"-"<<initDate.getSecond() ;
+              StdString strInitdate=oss2.str() ;
+              StdString strTimeOrigin=timeOrigin.toString() ;
+              this->writeTimeAxisAttributes
+                 (axisid, cal->getType(),
+                  StdString("seconds since ").append(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() ;
+           dims.push_back(timeid);
+           if (!SuperClassWriter::varExist(axisid))
+           {
+              SuperClassWriter::addVariable(axisid, NC_DOUBLE, dims);
+              SuperClassWriter::addAttribute("axis", string("T"), &axisid);
+              CDate timeOrigin=cal->getTimeOrigin() ;
+              StdString strTimeOrigin=timeOrigin.toString() ;
+
+              this->writeTimeAxisAttributes
+                 (axisid, cal->getType(),
+                  StdString("seconds since ").append(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);
+           }
+         }
+         catch (CNetCdfException& e)
+         {
+           StdString msg("On writing time axis data: ");
+           msg.append("In the context : ");
+           CContext* context = CContext::getCurrent() ;
+           msg.append(context->getId()); msg.append("\n");
+           msg.append(e.what());
+           ERROR("CNc4DataOutput::writeTimeAxis_ (CField*    field, \
+                  const boost::shared_ptr<CCalendar> cal)", << msg);
          }
       }
@@ -1040,11 +1192,30 @@
                                                    const StdString & title)
       {
-         SuperClassWriter::addAttribute("standard_name", standard_name, &axis_name);
-         SuperClassWriter::addAttribute("long_name",     long_name    , &axis_name);
-         SuperClassWriter::addAttribute("title",         title        , &axis_name);
-         SuperClassWriter::addAttribute("calendar",      calendar     , &axis_name);
-         SuperClassWriter::addAttribute("units",         units        , &axis_name);
-         SuperClassWriter::addAttribute("time_origin",   time_origin  , &axis_name);
-         SuperClassWriter::addAttribute("bounds",        time_bounds  , &axis_name);
+         try
+         {
+           SuperClassWriter::addAttribute("standard_name", standard_name, &axis_name);
+           SuperClassWriter::addAttribute("long_name",     long_name    , &axis_name);
+           SuperClassWriter::addAttribute("title",         title        , &axis_name);
+           SuperClassWriter::addAttribute("calendar",      calendar     , &axis_name);
+           SuperClassWriter::addAttribute("units",         units        , &axis_name);
+           SuperClassWriter::addAttribute("time_origin",   time_origin  , &axis_name);
+           SuperClassWriter::addAttribute("bounds",        time_bounds  , &axis_name);
+         }
+         catch (CNetCdfException& e)
+         {
+           StdString msg("On writing time axis Attribute: ");
+           msg.append("In the context : ");
+           CContext* context = CContext::getCurrent() ;
+           msg.append(context->getId()); msg.append("\n");
+           msg.append(e.what());
+           ERROR("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, \
+                                                   const StdString & title)", << msg);
+         }
       }
 
@@ -1058,9 +1229,26 @@
                                                const StdString & nav_model)
       {
-         SuperClassWriter::addAttribute("axis"         , axis         , &axis_name);
-         SuperClassWriter::addAttribute("standard_name", standard_name, &axis_name);
-         SuperClassWriter::addAttribute("long_name"    , long_name    , &axis_name);
-         SuperClassWriter::addAttribute("units"        , units        , &axis_name);
-         SuperClassWriter::addAttribute("nav_model"    , nav_model    , &axis_name);
+         try
+         {
+          SuperClassWriter::addAttribute("axis"         , axis         , &axis_name);
+          SuperClassWriter::addAttribute("standard_name", standard_name, &axis_name);
+          SuperClassWriter::addAttribute("long_name"    , long_name    , &axis_name);
+          SuperClassWriter::addAttribute("units"        , units        , &axis_name);
+          SuperClassWriter::addAttribute("nav_model"    , nav_model    , &axis_name);
+         }
+         catch (CNetCdfException& e)
+         {
+           StdString msg("On writing Axis Attribute: ");
+           msg.append("In the context : ");
+           CContext* context = CContext::getCurrent() ;
+           msg.append(context->getId()); msg.append("\n");
+           msg.append(e.what());
+           ERROR("CNc4DataOutput::writeAxisAttributes(const StdString & axis_name, \
+                                               const StdString & axis, \
+                                               const StdString & standard_name, \
+                                               const StdString & long_name, \
+                                               const StdString & units, \
+                                               const StdString & nav_model)", << msg);
+         }
       }
 
@@ -1070,8 +1258,22 @@
          (int ibegin, int ni, int jbegin, int nj, StdString domid)
       {
+        try
+        {
          SuperClassWriter::addAttribute(StdString("ibegin").append(domid), ibegin);
          SuperClassWriter::addAttribute(StdString("ni"    ).append(domid), ni);
          SuperClassWriter::addAttribute(StdString("jbegin").append(domid), jbegin);
          SuperClassWriter::addAttribute(StdString("nj"    ).append(domid), nj);
+        }
+        catch (CNetCdfException& e)
+        {
+           StdString msg("On writing Local Attributes: ");
+           msg.append("In the context : ");
+           CContext* context = CContext::getCurrent() ;
+           msg.append(context->getId()); msg.append("\n");
+           msg.append(e.what());
+           ERROR("CNc4DataOutput::writeLocalAttributes \
+                  (int ibegin, int ni, int jbegin, int nj, StdString domid)", << msg);
+        }
+
       }
 
@@ -1081,27 +1283,39 @@
          CArray<int,1> array(2) ;
 
-         SuperClassWriter::addAttribute("DOMAIN_number_total",size ) ;
-         SuperClassWriter::addAttribute("DOMAIN_number", rank) ;
-         array=1,2 ;
-         SuperClassWriter::addAttribute("DOMAIN_dimensions_ids",array) ;
-         array=ni_glo,nj_glo ;
-         SuperClassWriter::addAttribute("DOMAIN_size_global", array) ;
-         array=ni,nj ;
-         SuperClassWriter::addAttribute("DOMAIN_size_local", array) ;
-         array=ibegin,jbegin ;
-         SuperClassWriter::addAttribute("DOMAIN_position_first", array) ;
-         array=ibegin+ni-1,jbegin+nj-1 ;
-         SuperClassWriter::addAttribute("DOMAIN_position_last",array) ;
-         array=0,0 ;
-         SuperClassWriter::addAttribute("DOMAIN_halo_size_start", array) ;
-         SuperClassWriter::addAttribute("DOMAIN_halo_size_end", array);
-         SuperClassWriter::addAttribute("DOMAIN_type",string("box")) ;
-/*
-         SuperClassWriter::addAttribute("DOMAIN_DIM_N001",string("x")) ;
-         SuperClassWriter::addAttribute("DOMAIN_DIM_N002",string("y")) ;
-         SuperClassWriter::addAttribute("DOMAIN_DIM_N003",string("axis_A")) ;
-         SuperClassWriter::addAttribute("DOMAIN_DIM_N004",string("time_counter")) ;
-*/
-
+         try
+         {
+           SuperClassWriter::addAttribute("DOMAIN_number_total",size ) ;
+           SuperClassWriter::addAttribute("DOMAIN_number", rank) ;
+           array=1,2 ;
+           SuperClassWriter::addAttribute("DOMAIN_dimensions_ids",array) ;
+           array=ni_glo,nj_glo ;
+           SuperClassWriter::addAttribute("DOMAIN_size_global", array) ;
+           array=ni,nj ;
+           SuperClassWriter::addAttribute("DOMAIN_size_local", array) ;
+           array=ibegin,jbegin ;
+           SuperClassWriter::addAttribute("DOMAIN_position_first", array) ;
+           array=ibegin+ni-1,jbegin+nj-1 ;
+           SuperClassWriter::addAttribute("DOMAIN_position_last",array) ;
+           array=0,0 ;
+           SuperClassWriter::addAttribute("DOMAIN_halo_size_start", array) ;
+           SuperClassWriter::addAttribute("DOMAIN_halo_size_end", array);
+           SuperClassWriter::addAttribute("DOMAIN_type",string("box")) ;
+  /*
+           SuperClassWriter::addAttribute("DOMAIN_DIM_N001",string("x")) ;
+           SuperClassWriter::addAttribute("DOMAIN_DIM_N002",string("y")) ;
+           SuperClassWriter::addAttribute("DOMAIN_DIM_N003",string("axis_A")) ;
+           SuperClassWriter::addAttribute("DOMAIN_DIM_N004",string("time_counter")) ;
+  */
+         }
+         catch (CNetCdfException& e)
+         {
+           StdString msg("On writing Local Attributes IOI PSL \n");
+           msg.append("In the context : ");
+           CContext* context = CContext::getCurrent() ;
+           msg.append(context->getId()); msg.append("\n");
+           msg.append(e.what());
+           ERROR("CNc4DataOutput::writeLocalAttributes_IOIPSL \
+                  (int ibegin, int ni, int jbegin, int nj, int ni_glo, int nj_glo, int rank, int size)", << msg);
+         }
       }
       //---------------------------------------------------------------
@@ -1113,9 +1327,25 @@
                                                 const StdString & timeStamp)
       {
-         SuperClassWriter::addAttribute("name"       , name);
-         SuperClassWriter::addAttribute("description", description);
-         SuperClassWriter::addAttribute("conventions", conventions);
-         SuperClassWriter::addAttribute("production" , production);
-         SuperClassWriter::addAttribute("timeStamp"  , timeStamp);
+         try
+         {
+           SuperClassWriter::addAttribute("name"       , name);
+           SuperClassWriter::addAttribute("description", description);
+           SuperClassWriter::addAttribute("conventions", conventions);
+           SuperClassWriter::addAttribute("production" , production);
+           SuperClassWriter::addAttribute("timeStamp"  , timeStamp);
+         }
+         catch (CNetCdfException& e)
+         {
+           StdString msg("On writing File Attributes \n ");
+           msg.append("In the context : ");
+           CContext* context = CContext::getCurrent() ;
+           msg.append(context->getId()); msg.append("\n");
+           msg.append(e.what());
+           ERROR("CNc4DataOutput:: writeFileAttributes(const StdString & name, \
+                                                const StdString & description, \
+                                                const StdString & conventions, \
+                                                const StdString & production, \
+                                                const StdString & timeStamp)", << msg);
+         }
       }
 
@@ -1129,9 +1359,26 @@
                                                int data_jbegin)
       {
-         SuperClassWriter::addAttribute("data_dim"   , data_dim   , &mask_name);
-         SuperClassWriter::addAttribute("data_ni"    , data_ni    , &mask_name);
-         SuperClassWriter::addAttribute("data_nj"    , data_nj    , &mask_name);
-         SuperClassWriter::addAttribute("data_ibegin", data_ibegin, &mask_name);
-         SuperClassWriter::addAttribute("data_jbegin", data_jbegin, &mask_name);
+         try
+         {
+           SuperClassWriter::addAttribute("data_dim"   , data_dim   , &mask_name);
+           SuperClassWriter::addAttribute("data_ni"    , data_ni    , &mask_name);
+           SuperClassWriter::addAttribute("data_nj"    , data_nj    , &mask_name);
+           SuperClassWriter::addAttribute("data_ibegin", data_ibegin, &mask_name);
+           SuperClassWriter::addAttribute("data_jbegin", data_jbegin, &mask_name);
+         }
+         catch (CNetCdfException& e)
+         {
+           StdString msg("On writing Mask Attributes \n ");
+           msg.append("In the context : ");
+           CContext* context = CContext::getCurrent() ;
+           msg.append(context->getId()); msg.append("\n");
+           msg.append(e.what());
+           ERROR("CNc4DataOutput::writeMaskAttributes(const StdString & mask_name, \
+                                               int data_dim, \
+                                               int data_ni, \
+                                               int data_nj, \
+                                               int data_ibegin, \
+                                               int data_jbegin)", << msg);
+         }
       }
 
Index: XIOS/trunk/src/output/netCdfException.hpp
===================================================================
--- XIOS/trunk/src/output/netCdfException.hpp	(revision 498)
+++ XIOS/trunk/src/output/netCdfException.hpp	(revision 498)
@@ -0,0 +1,34 @@
+/*!
+   \file netCdfException.hpp
+   \author Ha NGUYEN
+   \date 08 Oct 2014
+   \since 07 Oct 2014
+
+   \brief Exception management.
+ */
+#ifndef __NETCDF_EXCEPTION_HPP__
+#define __NETCDF_EXCEPTION_HPP__
+
+#include <iostream>
+#include <exception>
+
+namespace xios
+{
+/*!
+\class CNetCdfException
+ This class manages exceptions risen by CNetCdfInterface
+*/
+class CNetCdfException : public virtual std::exception
+{
+public:
+  CNetCdfException(const std::string& ss) : exStr_(ss) {}
+  CNetCdfException(const CNetCdfException& netEx) : exStr_(netEx.exStr_) {}
+  ~CNetCdfException() throw() {}
+  const char* what() const throw() { return exStr_.c_str();}
+protected:
+  std::string exStr_;
+};
+
+}
+
+#endif // __NETCDF_EXCEPTION_HPP__
Index: XIOS/trunk/src/output/netCdfInterface.cpp
===================================================================
--- XIOS/trunk/src/output/netCdfInterface.cpp	(revision 498)
+++ XIOS/trunk/src/output/netCdfInterface.cpp	(revision 498)
@@ -0,0 +1,753 @@
+/*!
+   \file netCdfInterface.cpp
+   \author Ha NGUYEN
+   \date 08 Oct 2014
+   \since 03 Oct 2014
+
+   \brief Wrapper of netcdf functions.
+ */
+
+ #include "netCdfInterface.hpp"
+ #include "netCdfException.hpp"
+
+ namespace xios
+ {
+   /*!
+   This function creates a new netcdf file and return its id
+   \param [in] fileName Name of the file
+   \param [in] cMode create mode
+   \param [in/out] ncId id of the created file
+   \return Status code
+   */
+   int CNetCdfInterface::create(const StdString& fileName, int cMode, int& ncId)
+   {
+     int status = nc_create((fileName.c_str()), cMode, &ncId);
+     if (NC_NOERR != status)
+     {
+       StdString errormsg(nc_strerror(status));
+       StdStringStream sstr;
+       sstr << "Error in calling function : nc_create((fileName.c_str()), cMode, &ncId) " << std::endl
+            << errormsg << std::endl
+            << "Unable to create file, given its name : " << fileName
+            << "and its creation mode " << creationMode2String(cMode) << std::endl;
+       StdString e = sstr.str();
+       throw CNetCdfException(e);
+     }
+
+     return status;
+   }
+
+   /*!
+   This function creates a new netcdf file on parallel file system
+   \param [in] fileName Name of the file
+   \param [in] cMode create mode
+   \param [in] comm MPI communicator
+   \param [in] info MPI information
+   \param [in/out] ncId id of the created file
+   \return Status code
+   */
+   int CNetCdfInterface::createPar(const StdString& fileName, int cMode, MPI_Comm comm, MPI_Info info, int& ncId)
+   {
+     int status = ::nc_create_par((fileName.c_str()), cMode, comm, info, &ncId);
+     if (NC_NOERR != status)
+     {
+       StdString errormsg(nc_strerror(status));
+       StdStringStream sstr;
+       sstr << "Error in calling function : nc_create_par((fileName.c_str()), cMode, comm, info, &ncId) " << std::endl
+            << errormsg << std::endl
+            << "Unable to create file on parallel filesys, given its name : " << std::endl
+            << "and its creation mode " << creationMode2String(cMode) << std::endl;
+       StdString e = sstr.str();
+       throw CNetCdfException(e);
+     }
+
+     return status;
+   }
+
+   /*!
+   This function opens a netcdf file, given its name and open mode, return its id
+   \param [in] fileName Name of the file
+   \param [in] oMode open mode
+   \param [in/out] ncId id of the opening file
+   \return Status code
+   */
+   int CNetCdfInterface::open(const StdString& fileName, int oMode, int& ncId)
+   {
+     int status = nc_open((fileName.c_str()), oMode, &ncId);
+     if (NC_NOERR != status)
+     {
+       StdString errormsg(nc_strerror(status));
+       StdStringStream sstr;
+       sstr << "Error in calling function : nc_open((fileName.c_str()), oMode, &ncId) "<< std::endl
+            << errormsg << std::endl
+            << "Unable to open file, given its name : " << fileName
+            << "and its open mode " << openMode2String(oMode) << std::endl;
+       StdString e = sstr.str();
+       throw CNetCdfException(e);
+     }
+
+     return status;
+   }
+
+
+   /*!
+   This function opens a new netcdf file on parallel file system
+   \param [in] fileName Name of the file
+   \param [in] oMode open mode
+   \param [in] comm MPI communicator
+   \param [in] info MPI information
+   \param [in/out] ncId id of the opened file
+   \return Status code
+   */
+   int CNetCdfInterface::openPar(const StdString& fileName, int oMode, MPI_Comm comm, MPI_Info info, int& ncId)
+   {
+     int status = ::nc_open_par((fileName.c_str()), oMode, comm, info, &ncId);
+     if (NC_NOERR != status)
+     {
+       StdString errormsg(nc_strerror(status));
+       StdStringStream sstr;
+       sstr << "Error in calling function " << "nc_open_par((fileName.c_str()), oMode, comm, info, &ncId) " << std::endl
+            << errormsg << std::endl
+            << "Unable to open file on parallel filesys, given its name : " << fileName
+            << "and its open mode " << openMode2String(oMode) << std::endl;
+       StdString e = sstr.str();
+       throw CNetCdfException(e);
+     }
+
+     return status;
+   }
+
+   /*!
+   This function closes a netcdf file, given its id
+   \param [in] ncId id of the opening netcdf file
+   \return Status code
+   */
+   int CNetCdfInterface::close(int ncId)
+   {
+     int status = nc_close(ncId);
+     if (NC_NOERR != status)
+     {
+       StdString errormsg(nc_strerror(status));
+       StdStringStream sstr;
+       sstr << "Error in calling function " << "nc_close(ncId)" << std::endl
+            << errormsg << std::endl
+            << "Unable to close file, given its id : " << ncId << std::endl;
+       StdString e = sstr.str();
+       throw CNetCdfException(e);
+     }
+
+     return status;
+   }
+
+   /*!
+   This function put a netcdf file into define mode, given its id
+   \param [in] ncId id of the opening netcdf file to be put into define mode
+   \return Status code
+   */
+   int CNetCdfInterface::reDef(int ncId)
+   {
+     int status = nc_redef(ncId);
+     if (NC_NOERR != status)
+     {
+       StdString errormsg(nc_strerror(status));
+       StdStringStream sstr;
+       sstr << "Error in calling function " << "nc_redef(ncId)" << std::endl
+         << errormsg << std::endl
+         << "Unable to put this file into define mode given its id : " << ncId << std::endl;
+       StdString e = sstr.str();
+       throw CNetCdfException(e);
+     }
+
+     return status;
+   }
+
+   /*!
+   This function ends a netcdf file define mode, given its id
+   \param [in] ncId id of the opening netcdf file to be put into define mode
+   \return Status code
+   */
+   int CNetCdfInterface::endDef(int ncId)
+   {
+     int status = nc_enddef(ncId);
+     if (NC_NOERR != status)
+     {
+       StdString errormsg(nc_strerror(status));
+       StdStringStream sstr;
+
+       sstr << "Error in calling function " << "nc_enddef(ncId)" << std::endl
+            << errormsg << std::endl
+            << "Unable to end define mode of this file, given its id : " << ncId << std::endl;
+       StdString e = sstr.str();
+       throw CNetCdfException(e);
+     }
+
+     return status;
+   }
+
+   /*!
+   This function makes a request to netcdf with ncid and group name then return ncid of the named group
+   \param [in] ncid Groupd id (or File Id)
+   \param [in] grpName Name of the desired group (or file)
+   \param [in/out] grpId Group id if the group is found
+   \return Status code
+   */
+   int CNetCdfInterface::inqNcId(int ncid, const StdString& grpName, int& grpId)
+   {
+     int status = nc_inq_ncid(ncid, (grpName.c_str()), &grpId);
+     if (NC_NOERR != status)
+     {
+       StdString errormsg(nc_strerror(status));
+       StdStringStream sstr;
+
+       sstr << "Error in calling function " << "nc_inq_ncid(ncid, (grpName.c_str()), &grpId)" << std::endl
+            << errormsg << std::endl
+            << "Unable to get id of a group (File), given its name : " << grpName << std::endl;
+       StdString e = sstr.str();
+       throw CNetCdfException(e);
+     }
+
+     return status;
+   }
+
+
+   /*!
+   This function makes a request to netcdf with ncid and variable name then return ncid of the named variable
+   \param [in] ncid Groupd id (or File Id)
+   \param [in] varName Name of the desired variable
+   \param [in/out] varId Variable id if this variable is found
+   \return Status code
+   */
+   int CNetCdfInterface::inqVarId(int ncid,const StdString& varName, int& varId)
+   {
+     int status = nc_inq_varid(ncid, (varName.c_str()), &varId);
+     if (NC_NOERR != status)
+     {
+       StdString errormsg(nc_strerror(status));
+       StdStringStream sstr;
+
+       sstr << "Error in calling function : nc_inq_varid(ncid, (varName.c_str()), &varId)" << std::endl
+            << (errormsg) << std::endl
+            << "Unable to get id of variable with name : " << varName << std::endl;
+       StdString e = sstr.str();
+       throw CNetCdfException(e);
+     }
+
+     return status;
+   }
+
+  /*!
+   This function makes a request to netcdf with a netCdf dimension name then return ncid of the named dimension
+   \param [in] ncid Groupd id (or File Id)
+   \param [in] dimName Name of the desired dimension
+   \param [in/out] dimId Dimension id if this dimension is found
+   \return Status code
+   */
+   int CNetCdfInterface::inqDimId(int ncid,const StdString& dimName, int& dimId)
+   {
+     int status = nc_inq_dimid(ncid, (dimName.c_str()), &dimId);
+     if (NC_NOERR != status)
+     {
+       StdString errormsg(nc_strerror(status));
+       StdStringStream sstr;
+
+       sstr << "Error in calling function " << "nc_inq_dimid(ncid, (dimName.c_str()), &dimId)" << std::endl
+            << errormsg << std::endl
+            << "Unable to get id of dimension, given its name : " << dimName << std::endl;
+       StdString e = sstr.str();
+       throw CNetCdfException(e);
+     }
+
+     return status;
+   }
+
+  /*!
+   This function makes a request to netcdf with a netCdf dimension name then return ncid of the named dimension
+   \param [in] ncid Groupd id (or File Id)
+   \param [in/out] dimId Dimension id if this dimension is found
+   \return Status code
+   */
+   int CNetCdfInterface::inqUnLimDim(int ncid, int& dimId)
+   {
+     int status = nc_inq_unlimdim(ncid, &dimId);
+     if (NC_NOERR != status)
+     {
+       StdString errormsg(nc_strerror(status));
+       StdStringStream sstr;
+
+       sstr << "Error in calling function " << "nc_inq_dimid" << std::endl
+         << errormsg << std::endl
+         << "Unable to get id of unlimited dimension " << std::endl;
+       StdString e = sstr.str();
+       throw CNetCdfException(e);
+    }
+
+     return status;
+   }
+
+  /*!
+   This function makes a request to netcdf, returns name of a dimension, given its id
+   \param [in] ncid Groupd id (or File Id)
+   \param [in] dimId Id of desired dimension
+   \param [in/out] dimName Name of desired dimension
+   \return Status code
+   */
+   int CNetCdfInterface::inqDimName(int ncid, int dimId, StdString& dimName)
+   {
+     char fullNameIn[NC_MAX_NAME +1];
+     int status = nc_inq_dimname(ncid, dimId, fullNameIn);
+     if (NC_NOERR != status)
+     {
+       StdString errormsg(nc_strerror(status));
+       StdStringStream sstr;
+
+       sstr << "Error in calling function " << "nc_inq_dimname(ncid, dimId, fullNameIn)" << std::endl
+            << errormsg << std::endl
+            << "Unable to get dimension name from its id : " << dimId << std::endl;
+       StdString e = sstr.str();
+       throw CNetCdfException(e);
+     }
+     dimName = StdString(fullNameIn);
+     return status;
+   }
+
+  /*!
+   This function makes a request to netcdf, returns length of a dimension, given its id
+   \param [in] ncid Groupd id (or File Id)
+   \param [in] dimId Id of desired dimension
+   \param [in/out] dimLen Length of desired dimension
+   \return Status code
+   */
+   int CNetCdfInterface::inqDimLen(int ncid, int dimId, StdSize& dimLen)
+   {
+     int status = nc_inq_dimlen(ncid, dimId, &dimLen);
+     if (NC_NOERR != status)
+     {
+       StdString errormsg(nc_strerror(status));
+       StdStringStream sstr;
+
+       sstr << "Error in calling function " << "nc_inq_dimlen(ncid, dimId, &dimLen)" << std::endl
+            << errormsg << std::endl
+            << "Unable to get dimension length from its id: " << dimId << std::endl;
+       StdString e = sstr.str();
+       throw CNetCdfException(e);
+     }
+
+     return status;
+   }
+
+  /*!
+   This function makes a request to netcdf, returns number of dimensions of a variable, given its id
+   \param [in] ncid Groupd id (or File Id)
+   \param [in] varId Id of variable
+   \param [in/out] ndims number of dimension of the variable
+   \return Status code
+   */
+   int CNetCdfInterface::inqVarNDims(int ncid, int varId, int& nDims)
+   {
+     int status = nc_inq_varndims(ncid, varId, &nDims);
+     if (NC_NOERR != status)
+     {
+       StdString errormsg(nc_strerror(status));
+       StdStringStream sstr;
+
+       sstr << "Error in calling function " << "nc_inq_varndims(ncid, varId, &nDims)" << std::endl
+            << errormsg << std::endl
+            << "Unable to get the number of dimension of variable with Id : " << varId << std::endl;
+       StdString e = sstr.str();
+       throw CNetCdfException(e);
+     }
+
+     return status;
+   }
+
+  /*!
+   This function makes a request to netcdf, returns a list of dimension ID describing the shape of the variable, given its id
+   \param [in] ncid Groupd id (or File Id)
+   \param [in] varId Id of variable
+   \param [in/out] dimIds list of dimension of the variable
+   \return Status code
+   */
+   int CNetCdfInterface::inqVarDimId(int ncid, int varId, int* dimIds)
+   {
+     int status = nc_inq_vardimid(ncid, varId, dimIds);
+     if (NC_NOERR != status)
+     {
+       StdString errormsg(nc_strerror(status));
+       StdStringStream sstr;
+
+       sstr << "Error in calling function " << "nc_inq_vardimid(ncid, varId, dimIds)" << std::endl
+            << errormsg << std::endl
+            << "Unable to get list of dimension id of the variable with id " << varId << std::endl;
+       StdString e = sstr.str();
+       throw CNetCdfException(e);
+     }
+
+     return status;
+   }
+
+   /*!
+   This function makes a request to netcdf, to find all dimension in a group
+   \param [in] ncid Groupd id (or File Id)
+   \param [in/out] nDims number of list of dimension
+   \param [in/out] dimIds list of dimension in a group or any of its parent
+   \param [in] includeParents number of parents
+   \return Status code
+   */
+   int CNetCdfInterface::inqDimIds(int ncid, int& nDims, int* dimIds, int includeParents)
+   {
+     int status = nc_inq_dimids(ncid, &nDims, dimIds, includeParents);
+     if (NC_NOERR != status)
+     {
+       StdString errormsg(nc_strerror(status));
+       StdStringStream sstr;
+
+       sstr << "Error in calling function " << "nc_inq_dimids(ncid, &nDims, dimIds, includeParents)" << std::endl;
+       sstr << errormsg << std::endl;
+       sstr << "Unable to retrieve number of dimension in the group with id : " << ncid << std::endl;
+       sstr << "With number of Parents " << includeParents << std::endl;
+       StdString e = sstr.str();
+       throw CNetCdfException(e);
+     }
+
+     return status;
+   }
+
+   /*!
+   This function makes a request to netcdf with a id of a prent groupd and then return id of the created group, given its name
+   \param [in] parentNcid Id of parent groupd(or File Id)
+   \param [in] grpName Name of the desired group
+   \param [in/out] grpId Group id if this group is created sucessfully
+   \return Status code
+   */
+   int CNetCdfInterface::defGrp(int parentNcid, const StdString& grpName, int& grpId)
+   {
+     int status = nc_def_grp(parentNcid, (grpName.c_str()), &grpId);
+     if (NC_NOERR != status)
+     {
+       StdString errormsg(nc_strerror(status));
+       StdStringStream sstr;
+
+       sstr << "Error in calling function " << "nc_def_grp(parentNcid, (grpName.c_str()), &grpId)" << std::endl;
+       sstr << errormsg << std::endl;
+       sstr << "Unable to create group Id, given its name : " << grpName << std::endl;
+       StdString e = sstr.str();
+       throw CNetCdfException(e);
+     }
+
+     return status;
+   }
+
+   /*!
+   This function makes a request to netcdf, add a new dimension to an open netcdf in define mode
+   \param [in] ncid Id of groupd(or File Id)
+   \param [in] dimName Name of the desired dimension
+   \param [in/out] grpId Group id if this group is created sucessfully
+   \return Status code
+   */
+   int CNetCdfInterface::defDim(int ncid, const StdString& dimName, StdSize dimLen, int& dimId)
+   {
+     int status = nc_def_dim(ncid, (dimName.c_str()), dimLen, &dimId);
+     if (NC_NOERR != status)
+     {
+       StdString errormsg(nc_strerror(status));
+       StdStringStream sstr;
+
+       sstr << "Error in calling function " << "nc_def_dim(ncid, (dimName.c_str()), dimLen, &dimId)" << std::endl;
+       sstr << errormsg << std::endl;
+       sstr << "Unable to create dimension with name : " << dimName
+            << " and with length " << dimLen << std::endl;
+       StdString e = sstr.str();
+       throw CNetCdfException(e);
+     }
+
+     return status;
+   }
+
+   /*!
+   This function makes a request to netcdf with its id, to add a new variable to an open netCdf in define mode,
+   return a variable id, given its name, type, the number of dimensions and list of dimension id
+   \param [in] ncid Id of groupd(or File Id)
+   \param [in] varName Name of the desired dimension
+   \param [in] xtypes One of the set of predefined netCDF data types
+   \param [in] nDims Number of dimension for the variable
+   \param [in] dimIds List of ndims dimension ids corresponding to the variable dimensions
+   \param [in/out] varId Variable id if it is added sucessfully
+   \return Status code
+   */
+   int CNetCdfInterface::defVar(int ncid,const StdString& varName, nc_type xtype,
+                                int nDims, const int dimIds[], int& varId)
+   {
+     int status = nc_def_var(ncid, (varName.c_str()), xtype, nDims, dimIds, &varId);
+     if (NC_NOERR != status)
+     {
+       StdString errormsg(nc_strerror(status));
+       StdStringStream sstr;
+
+       sstr << "Error in calling function " << " nc_def_var(ncid, (varName.c_str()), xtype, nDims, dimIds, &varId)" << std::endl;
+       sstr << errormsg << std::endl;
+       sstr << "Unable to add a new variable with name : " << varName
+            << " with type " << xtype
+            << " and number of dimension " << nDims << std::endl;
+       StdString e = sstr.str();
+       throw CNetCdfException(e);
+     }
+
+     return status;
+   }
+
+   /*!
+   This function makes a request to netcdf with a ncid, to set the chunking size of a variable,
+   given variable id and type of storage
+   \param [in] ncid Id groupd(or File Id)
+   \param [in] varId Id of the variable
+   \param [in] storage Type of storage (It can be : NC_CONTIGUOUS, NC_CHUNKED)
+   \param [in/out] chunkSize array list of chunk sizes
+   \return Status code
+   */
+   int CNetCdfInterface::defVarChunking(int ncid, int varId, int storage, StdSize chunkSize[])
+   {
+     int status = nc_def_var_chunking(ncid, varId, storage, chunkSize);
+     if (NC_NOERR != status)
+     {
+       StdString errormsg(nc_strerror(status));
+       StdStringStream sstr;
+
+       sstr << "Error in calling function " << "nc_def_var_chunking(ncid, varId, storage, chunkSize)" << std::endl;
+       sstr << errormsg << std::endl;
+       sstr << "Unable to set chunk size of the variable with id : " << varId
+         << " and storage type " << storage << std::endl;
+       StdString e = sstr.str();
+       throw CNetCdfException(e);
+     }
+
+     return status;
+   }
+
+   /*!
+   This function makes a request to netcdf with a ncid, to set the fill parameters for a variable,
+   given variable id and type of fill
+   \param [in] ncid Id groupd(or File Id)
+   \param [in] varId Id of the variable
+   \param [in] noFill turn on/off nofill mode on a variable
+   \param [in/out] fillValue
+   \return Status code
+   */
+   int CNetCdfInterface::defVarFill(int ncid, int varId, int noFill, void* fillValue)
+   {
+     int status = nc_def_var_fill(ncid, varId, noFill, fillValue);
+     if (NC_NOERR != status)
+     {
+       StdString errormsg(nc_strerror(status));
+       StdStringStream sstr;
+
+       sstr << "Error in calling function " << "nc_def_var_fill(ncid, varId, noFill, fillValue)" << std::endl;
+       sstr << errormsg << std::endl;
+       sstr << "Unable to set fill parameters of the variable with id : " << varId
+         << " and fill option " << noFill << std::endl;
+       StdString e = sstr.str();
+       throw CNetCdfException(e);
+     }
+
+     return status;
+   }
+
+   /*!
+   This function makes a request to netcdf with a ncid, to change the way read/write operations are performed
+   collectively or independently on the variable.
+   \param [in] ncid Id groupd(or File Id)
+   \param [in] varId Id of the variable
+   \param [in] noFill turn on/off nofill mode on a variable
+   \param [in/out] fillValue
+   \return Status code
+   */
+   int CNetCdfInterface::varParAccess(int ncid, int varId, int access)
+   {
+     int status = nc_var_par_access(ncid, varId, access);
+     if (NC_NOERR != status)
+     {
+       StdString errormsg(nc_strerror(status));
+       StdStringStream sstr;
+
+       sstr << "Error in calling function " << "nc_var_par_access(ncid, varId, access)" << std::endl;
+       sstr << errormsg << std::endl;
+       sstr << "Unable to change read/write option of the variable with id : " << varId << std::endl;
+       StdString e = sstr.str();
+       throw CNetCdfException(e);
+     }
+
+     return status;
+   }
+
+   /*!
+   This function makes a synchronisation of the disk copy of a netCDF dataset.
+   \param [in] ncid Id groupd(or File Id)
+   \return Status code
+   */
+   int CNetCdfInterface::sync(int ncid)
+   {
+     int status = nc_sync(ncid);
+     if (NC_NOERR != status)
+     {
+       StdString errormsg(nc_strerror(status));
+       StdStringStream sstr;
+
+       sstr << "Error in calling function " << "nc_sync(ncid)" << std::endl;
+       sstr << errormsg << std::endl;
+       sstr << "Unable to make a synchronization of a netCDF file with id : " << ncid << std::endl;
+       StdString e = sstr.str();
+       throw CNetCdfException(e);
+     }
+
+     return status;
+   }
+
+   /*!
+   This function makes a request to netcdf with its id, to add or change a variable attribute or gloabl attribute,
+   given its name, type, number of values provided for attribute
+   \param [in] ncid Id of groupd(or File Id)
+   \param [in] varId Id of the variable
+   \param [in] attrName Name of the attribute
+   \param [in] xtypes One of the set of predefined netCDF data types
+   \param [in] numVal Number of values
+   \param [in] op Array of values provided for attribute
+   \return Status code
+   */
+   int CNetCdfInterface::putAtt(int ncid, int varId, const StdString& attrName, nc_type xtype,
+                                StdSize numVal, const void* op)
+   {
+     int status = nc_put_att(ncid, varId, (attrName.c_str()), xtype, numVal, op);
+     if (NC_NOERR != status)
+     {
+       StdString errormsg(nc_strerror(status));
+       StdStringStream sstr;
+
+       sstr << "Error in calling function " << "nc_put_att(ncid, varId, (attrName.c_str()), xtype, numVal, op)" << std::endl;
+       sstr << errormsg << std::endl;
+       sstr << "Unable to set attribute " << attrName << " for a variable with id : " << varId
+            << " with number of attribute  " << numVal
+            << " with type " << xtype << std::endl;
+       StdString e = sstr.str();
+       throw CNetCdfException(e);
+     }
+
+     return status;
+   }
+
+   // Some specilization of putAttributeType
+  template<>
+  int CNetCdfInterface::ncPutAttType(int ncid, int varid, const char* attrName,
+                                   StdSize numVal, const double* op)
+  {
+    return (nc_put_att_double(ncid, varid, attrName, NC_DOUBLE, numVal, op));
+  }
+
+  template<>
+  int CNetCdfInterface::ncPutAttType(int ncid, int varid, const char* attrName,
+                                     StdSize numVal, const float* op)
+  {
+    return (nc_put_att_float(ncid, varid, attrName, NC_FLOAT, numVal, op));
+  }
+
+  template<>
+  int CNetCdfInterface::ncPutAttType(int ncid, int varid, const char* attrName,
+                                     StdSize numVal, const int* op)
+  {
+    return (nc_put_att_int(ncid, varid, attrName, NC_INT, numVal, op));
+  }
+
+  template<>
+  int CNetCdfInterface::ncPutAttType(int ncid, int varid, const char* attrName,
+                                     StdSize numVal, const long* op)
+  {
+    return (nc_put_att_long(ncid, varid, attrName, NC_LONG, numVal, op));
+  }
+
+  template<>
+  int CNetCdfInterface::ncPutAttType(int ncid, int varid, const char* attrName,
+                                     StdSize numVal, const short* op)
+  {
+    return (nc_put_att_short(ncid, varid, attrName, NC_SHORT, numVal, op));
+  }
+
+
+  // Some specilization of putVariableType
+  template<>
+  int CNetCdfInterface::ncPutVaraType(int ncid, int varid, const StdSize* start, const StdSize* count, const double* op)
+  {
+    return (nc_put_vara_double(ncid, varid, start, count, op));
+  }
+
+  template<>
+  int CNetCdfInterface::ncPutVaraType(int ncid, int varid, const StdSize* start, const StdSize* count, const float* op)
+  {
+    return (nc_put_vara_float(ncid, varid, start, count, op));
+  }
+
+  template<>
+  int CNetCdfInterface::ncPutVaraType(int ncid, int varid, const StdSize* start, const StdSize* count, const int* op)
+  {
+    return (nc_put_vara_int(ncid, varid, start, count, op));
+  }
+
+   /*!
+   This function verifies an existence of a variable by using its name.
+   Be careful, althoug false means variable doens't exist, it could show that netCDF file doesn't either
+   \param [in] ncid Id of groupd(or File Id)
+   \param [in] attrName Name of the variable
+   \return Existence of variable
+   */
+  bool CNetCdfInterface::isVarExisted(int ncId, const StdString& varName)
+  {
+     int varId = 0;
+     return (NC_NOERR == (nc_inq_varid(ncId, varName.c_str(), &varId)));
+  }
+
+  StdString CNetCdfInterface::openMode2String(int oMode)
+  {
+    StdString modeMes;
+    switch (oMode)
+    {
+    case NC_NOWRITE:
+      modeMes = StdString("NC_NOWRITE : Opening netCDF file with read-only access with buffering and caching access");
+      break;
+    case NC_SHARE:
+      modeMes = StdString("NC_SHARE : Several processes can read the file concurrently");
+      break;
+    case NC_WRITE:
+      modeMes = StdString("NC_WRITE : NetCDF file is readable and writable");
+      break;
+    default:
+      modeMes = StdString("In the composed opening mode");
+      break;
+    return modeMes;
+    }
+  }
+
+  StdString CNetCdfInterface::creationMode2String(int cMode)
+  {
+    StdString modeMes;
+    switch (cMode)
+    {
+    case NC_NOCLOBBER:
+      modeMes = StdString("NC_NOCLOBBER : Not overwrite an exisiting netCDF file ");
+      break;
+    case NC_SHARE:
+      modeMes = StdString("NC_SHARE : Several processes can read from and write into the file concurrently");
+      break;
+    case NC_64BIT_OFFSET:
+      modeMes = StdString("NC_64BIT_OFFSET : NetCDF file is 64-bit offset");
+      break;
+    case NC_NETCDF4:
+      modeMes = StdString("NC_NETCDF4 : NetCDF file is HDF5/NetCDF-4");
+      break;
+    case NC_CLASSIC_MODEL:
+      modeMes = StdString("NC_CLASSIC_MODEL : NetCDF file is classical model");
+      break;
+    default:
+      modeMes = StdString("In the composed creation mode");
+      break;
+    return modeMes;
+    }
+  }
+
+ }
Index: XIOS/trunk/src/output/netCdfInterface.hpp
===================================================================
--- XIOS/trunk/src/output/netCdfInterface.hpp	(revision 498)
+++ XIOS/trunk/src/output/netCdfInterface.hpp	(revision 498)
@@ -0,0 +1,132 @@
+/*!
+   \file netCdfInterface.hpp
+   \author Ha NGUYEN
+   \date 08 Oct 2014
+   \since 03 Oct 2014
+
+   \brief Wrapper of netcdf functions.
+ */
+#ifndef __NETCDF_INTERFACE_HPP_
+#define __NETCDF_INTERFACE_HPP_
+
+#include "xmlioserver_spl.hpp"
+#include "mpi.hpp"
+#include "netcdf.hpp"
+
+namespace xios
+{
+  /*!
+  \class CNetCdfInterface
+   This class is  wrapper of some common used functions of netCdf in Xios
+  */
+  class CNetCdfInterface
+  {
+  public:
+    //! Create a netcdf file
+    static int create(const StdString& path, int cmode, int& ncId);
+
+    //! Create a netcdf file on a parallel file system
+    static int createPar(const StdString& path, int cmode, MPI_Comm comm, MPI_Info info, int& ncId);
+
+    //! Open a netcdf file
+    static int open(const StdString& path, int oMode, int& ncId);
+
+    //! Open a netcdf file
+    static int openPar(const StdString& path, int cmode, MPI_Comm comm, MPI_Info info, int& ncId);
+
+    //! Close a netcdf file
+    static int close(int ncId);
+
+    //! Put netcdf file into define mode
+    static int reDef(int ncId);
+
+    //! End define mode of a netcdf file
+    static int endDef(int ncId);
+
+    //! Query identity of a named group
+    static int inqNcId(int ncid, const StdString& grpName, int& grpId);
+
+    //! Query identity of a named variable
+    static int inqVarId(int ncid, const StdString& varName, int& varId);
+
+    //! Query identity of a named dimension
+    static int inqDimId(int ncid,const StdString& dimName, int& dimId);
+
+    //! Query identity of unlimited dimension
+    static int inqUnLimDim(int ncid, int& dimId);
+
+    //! Query name of a dimension with its id
+    static int inqDimName(int ncid, int dimId, StdString& dimName);
+
+    //! Query length of dimension with its id
+    static int inqDimLen(int ncid, int dimId, StdSize& dimLen);
+
+    //! Query number of dimension of a variable with its id
+    static int inqVarNDims(int ncid, int varId, int& nDims);
+
+    //! Query list of dimension of a variable with its id
+    static int inqVarDimId(int, int, int*);
+
+    //! Query dimensions of a group
+    static int inqDimIds(int ncid, int& nDims, int* dimIds, int includeParents);
+
+
+    //! Define a group
+    static int defGrp(int parentNcid,const StdString& grpName, int& grpId);
+
+    //! Define a dimension
+    static int defDim(int ncid,const StdString& dimName, StdSize dimLen, int& dimId);
+
+    //! Define a variable
+    static int defVar(int ncid,const StdString& varName, nc_type xtype,
+                      int nDims, const int dimIds[], int& varId);
+
+    //! Define variable chunking size
+    static int defVarChunking(int ncid, int varId, int storage, StdSize chunkSize[]);
+
+    //! Define variable fill parameters
+    static int defVarFill(int ncid, int varId, int noFill, void* fillValue);
+
+
+    //! Change access type of a variable
+    static int varParAccess(int ncid, int varid, int access);
+
+    //! Syn
+    static int sync(int ncId);
+
+    //! Put attribute into variable
+    static int putAtt(int ncid, int varid, const StdString& attrName, nc_type xtype,
+                      StdSize numVal, const void* op);
+
+
+    //! Put attribute into variable with specific type
+    template<typename T>
+    static int putAttType(int ncid, int varid, const StdString& attrName, StdSize numVal, const T* op);
+
+    //! Put value into a variable with a specific type
+    template<typename T>
+    static int putVaraType(int ncid, int varid, const StdSize* start, const StdSize* count, const T* op);
+
+  private:
+    template<typename T>
+    static int ncPutAttType(int ncid, int varid, const char* attrName, StdSize numVal, const T* op);
+
+    template<typename T>
+    static int ncPutVaraType(int ncid, int varid, const StdSize* start, const StdSize* count, const T* op);
+
+  private:
+    static StdString openMode2String(int oMode);
+
+    static StdString creationMode2String(int cMode);
+
+
+  public:
+    // Some functions dedude from several special cases
+    //! Query the existence of a variable
+    static bool isVarExisted(int ncId, const StdString& varName);
+
+  };
+}
+
+
+#endif // NETCDFINTERFACE_HPP_
Index: XIOS/trunk/src/output/netCdfInterface_decl.cpp
===================================================================
--- XIOS/trunk/src/output/netCdfInterface_decl.cpp	(revision 498)
+++ XIOS/trunk/src/output/netCdfInterface_decl.cpp	(revision 498)
@@ -0,0 +1,30 @@
+/*!
+   \file netCdfInterface_impl.hpp
+   \author Ha NGUYEN
+   \date 06 Oct 2014
+   \since 06 Oct 2014
+
+   \brief Implemention of some templated functions in netCdfInterface
+ */
+
+#include "netCdfInterface_impl.hpp"
+
+namespace xios
+{
+#define  macroPutAtt(type) \
+  template int CNetCdfInterface::putAttType(int ncid, int varid, const StdString& attrName, \
+                                            StdSize numVal, const type* op);
+
+  macroPutAtt(double);
+  macroPutAtt(float);
+  macroPutAtt(int);
+  macroPutAtt(long);
+  macroPutAtt(short);
+
+#define  macroPutVar(type) \
+ template int CNetCdfInterface::putVaraType(int ncid, int varId, const StdSize* start, \
+                                            const StdSize* count, const type* op);
+  macroPutVar(double);
+  macroPutVar(float);
+  macroPutVar(int);
+}
Index: XIOS/trunk/src/output/netCdfInterface_impl.hpp
===================================================================
--- XIOS/trunk/src/output/netCdfInterface_impl.hpp	(revision 498)
+++ XIOS/trunk/src/output/netCdfInterface_impl.hpp	(revision 498)
@@ -0,0 +1,77 @@
+/*!
+   \file netCdfInterface_impl.hpp
+   \author Ha NGUYEN
+   \date 08 Oct 2014
+   \since 06 Oct 2014
+
+   \brief Implemention of some templated functions in netCdfInterface
+ */
+
+#ifndef __NETCDF_INTERFACE_IMPL_HPP__
+#define __NETCDF_INTERFACE_IMPL_HPP__
+
+#include "netCdfInterface.hpp"
+#include "netCdfException.hpp"
+
+namespace xios
+{
+   /*!
+   This function makes a request to netcdf with its id, to add or change a variable attribute or gloabl attribute,
+   given its name, type, number of values provided for attribute
+   \param [in] ncid Id of groupd(or File Id)
+   \param [in] varId Id of the variable
+   \param [in] attrName Name of the attribute
+   \param [in] numVal Number of values
+   \param [in] op Array of values provided for attribute
+   \return Error code
+   */
+  template<typename T>
+  int CNetCdfInterface::putAttType(int ncid, int varId, const StdString& attrName,
+                                   StdSize numVal, const T* op)
+  {
+    int status = ncPutAttType(ncid, varId, attrName.c_str(), numVal, op);
+    if (NC_NOERR != status)
+     {
+       StdString errormsg(nc_strerror(status));
+       StdStringStream sstr;
+       sstr << "Error in calling function " << "ncPutAttType(ncid, varId, attrName.c_str(), numVal, op)" << std::endl;
+       sstr << errormsg << std::endl;
+       sstr << "Unable to set attribute " << attrName << " for a variable with id : " << varId
+         << " with number of attribute  " << numVal << std::endl;
+       StdString e = sstr.str();
+       throw CNetCdfException(e);
+     }
+
+     return status;
+  }
+
+   /*!
+   This function makes a request to netcdf with its id, to write variable values into netcdf file,
+   \param [in] ncid Id of groupd(or File Id)
+   \param [in] varId Id of the variable
+   \param [in] start Array specifying the index in the variable where the first data value will be written
+   \param [in] count Array specifying the edge lengths along each dimension of block data
+   \param [in] op Array of values provided for attribute
+   \return Error code
+   */
+  template<typename T>
+  int CNetCdfInterface::putVaraType(int ncid, int varId, const StdSize* start, const StdSize* count, const T* op)
+  {
+    int status = ncPutVaraType(ncid, varId, start, count, op);
+    if (NC_NOERR != status)
+     {
+       StdString errormsg(nc_strerror(status));
+       StdStringStream sstr;
+       sstr << "Error in calling function " << "ncPutVaraType(ncid, varId, start, count, op)" << std::endl;
+       sstr << errormsg << std::endl;
+       sstr << "Unable to write value of a variable with id : " << varId << std::endl;
+       StdString e = sstr.str();
+       throw CNetCdfException(e);
+     }
+
+     return status;
+  }
+
+}
+
+#endif // __NETCDF_INTERFACE_IMPL_HPP__
Index: XIOS/trunk/src/output/onetcdf4.cpp
===================================================================
--- XIOS/trunk/src/output/onetcdf4.cpp	(revision 488)
+++ XIOS/trunk/src/output/onetcdf4.cpp	(revision 498)
@@ -3,4 +3,6 @@
 #include "mpi.hpp"
 #include "netcdf.hpp"
+#include "netCdfInterface.hpp"
+#include "netCdfException.hpp"
 
 namespace xios
@@ -15,8 +17,7 @@
          this->initialize(filename, exist, comm,multifile);
       }
-      
-      //---------------------------------------------------------------
-      
-      
+
+      //---------------------------------------------------------------
+
 
       CONetCDF4::~CONetCDF4(void)
@@ -34,8 +35,8 @@
             if (comm != NULL)
             {
-               if (!multifile) CheckError(xios::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));
+               if (!multifile) (CNetCdfInterface::createPar(filename, NC_NETCDF4|NC_MPIIO, *comm, MPI_INFO_NULL, (this->ncidp)));
+               else (CNetCdfInterface::create(filename, NC_NETCDF4, this->ncidp));
             }
-            else CheckError(nc_create(filename.c_str(), NC_NETCDF4, &this->ncidp));
+            else (CNetCdfInterface::create(filename, NC_NETCDF4, this->ncidp));
          }
          else
@@ -43,55 +44,56 @@
             if (comm != NULL)
             {
-               if (!multifile) CheckError(xios::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));
+               if (!multifile) (CNetCdfInterface::openPar(filename, NC_NETCDF4|NC_MPIIO, *comm, MPI_INFO_NULL, this->ncidp));
+               else (CNetCdfInterface::open(filename, NC_NETCDF4, this->ncidp));
             }
-            else  CheckError(nc_open(filename.c_str(), NC_NETCDF4, &this->ncidp));
-         }
-      }
-      
+            else  (CNetCdfInterface::open(filename, NC_NETCDF4, this->ncidp));
+         }
+      }
+
       void CONetCDF4::close()
       {
-        CheckError(nc_close(this->ncidp));
-      }
-      
-      //---------------------------------------------------------------
-      
+        (CNetCdfInterface::close(this->ncidp));
+      }
+
+      //---------------------------------------------------------------
+
       void CONetCDF4::definition_start(void)
-      { 
-         CheckError(nc_redef(this->ncidp));
-      }
-      
-      //---------------------------------------------------------------
-      
+      {
+         (CNetCdfInterface::reDef(this->ncidp));
+      }
+
+      //---------------------------------------------------------------
+
       void CONetCDF4::definition_end(void)
-      { 
-         CheckError(nc_enddef(this->ncidp));
-      }
-      
-      //---------------------------------------------------------------
-      
-      void CONetCDF4::CheckError(int status)
-      {
-         if (status != NC_NOERR)
-         {
-            StdString errormsg (nc_strerror(status)); // fuite mÃ©moire ici ?
-            ERROR("CONetCDF4::CheckError(int status)",
-                  << "[ status = " << status << " ] " << errormsg);
-         }
-      }
-
-      //---------------------------------------------------------------
-      
+      {
+         (CNetCdfInterface::endDef(this->ncidp));
+      }
+
+      //---------------------------------------------------------------
+
+// Don't need it anymore?
+//      void CONetCDF4::CheckError(int status)
+//      {
+//         if (status != NC_NOERR)
+//         {
+//            StdString errormsg (nc_strerror(status)); // fuite mÃ©moire ici ?
+//            ERROR("CONetCDF4::CheckError(int status)",
+//                  << "[ status = " << status << " ] " << errormsg);
+//         }
+//      }
+
+      //---------------------------------------------------------------
+
       int CONetCDF4::getCurrentGroup(void)
       {
          return (this->getGroup(this->getCurrentPath()));
       }
-      
-      //---------------------------------------------------------------
-      
+
+      //---------------------------------------------------------------
+
       int CONetCDF4::getGroup(const CONetCDF4Path & path)
       {
          int retvalue = this->ncidp;
-         
+
          CONetCDF4Path::const_iterator
             it  = path.begin(), end = path.end();
@@ -100,54 +102,53 @@
          {
             const StdString & groupid = *it;
-            CheckError(nc_inq_ncid(retvalue, const_cast<char*>(groupid.c_str()), &retvalue));
+            (CNetCdfInterface::inqNcId(retvalue, groupid, retvalue));
          }
          return (retvalue);
       }
-      
-      //---------------------------------------------------------------
-      
+
+      //---------------------------------------------------------------
+
       int CONetCDF4::getVariable(const StdString & varname)
       {
          int varid = 0;
          int grpid = this->getCurrentGroup();
-         CheckError(nc_inq_varid (grpid, varname.c_str(), &varid));
+         (CNetCdfInterface::inqVarId(grpid, varname, varid));
          return (varid);
       }
-      
-      //---------------------------------------------------------------
-      
+
+      //---------------------------------------------------------------
+
       int CONetCDF4::getDimension(const StdString & dimname)
       {
          int dimid = 0;
          int grpid = this->getCurrentGroup();
-         CheckError(nc_inq_dimid (grpid, dimname.c_str(), &dimid));
+         (CNetCdfInterface::inqDimId(grpid, dimname, dimid));
          return (dimid);
       }
-      
-      //---------------------------------------------------------------
-      
+
+      //---------------------------------------------------------------
+
       int CONetCDF4::getUnlimitedDimension(void)
       {
          int dimid = 0;
          int grpid = this->getCurrentGroup();
-         CheckError(nc_inq_unlimdim (grpid, &dimid));
+         (CNetCdfInterface::inqUnLimDim(grpid, dimid));
          return (dimid);
       }
-      
+
       StdString CONetCDF4::getUnlimitedDimensionName(void)
       {
-         char full_name_in[NC_MAX_NAME +1];
          int grpid = this->getGroup(path);
          int dimid = this->getUnlimitedDimension();
-                              
+
          if (dimid == -1) return (std::string());
-            CheckError(nc_inq_dimname(grpid, dimid, full_name_in));
-                                          
-         StdString dimname(full_name_in);
+         StdString dimname;
+         (CNetCdfInterface::inqDimName(grpid, dimid, dimname));
+
          return (dimname);
       }
-      
-      //---------------------------------------------------------------
-      
+
+      //---------------------------------------------------------------
+
       std::vector<StdSize> CONetCDF4::getDimensions(const StdString & varname)
       {
@@ -158,11 +159,11 @@
          int nbdim = 0, *dimid = NULL;
 
-         CheckError(nc_inq_varndims(grpid, varid, &nbdim));
+         (CNetCdfInterface::inqVarNDims(grpid, varid, nbdim));
          dimid = new int[nbdim]();
-         CheckError(nc_inq_vardimid(grpid, varid, dimid));
+         (CNetCdfInterface::inqVarDimId(grpid, varid, dimid));
 
          for (int i = 0; i < nbdim; i++)
          {
-            CheckError(nc_inq_dimlen (grpid, dimid[i], &size));
+            (CNetCdfInterface::inqDimLen(grpid, dimid[i], size));
             if (size == NC_UNLIMITED)
                 size = UNLIMITED_DIM;
@@ -175,31 +176,31 @@
       std::vector<std::string> CONetCDF4::getDimensionsIdList (const std::string * _varname)
       {
-         char full_name_in[NC_MAX_NAME +1];
+         int nDimNull = 0;
          int nbdim = 0, *dimid = NULL;
          int grpid = this->getCurrentGroup();
          int varid = (_varname != NULL) ? this->getVariable(*_varname) : NC_GLOBAL;
          std::vector<std::string> retvalue;
-                                   
+
          if (_varname != NULL)
          {
-            CheckError(nc_inq_varndims(grpid, varid, &nbdim));
+            (CNetCdfInterface::inqVarNDims(grpid, varid, nbdim));
             dimid = new int[nbdim]();
-            CheckError(nc_inq_vardimid(grpid, varid, dimid));
+            (CNetCdfInterface::inqVarDimId(grpid, varid, dimid));
          }
          else
          {
-            CheckError(nc_inq_dimids(grpid, &nbdim, NULL, 1));
+            (CNetCdfInterface::inqDimIds(grpid, nbdim, NULL, 1));
             dimid = new int[nbdim]();
-            CheckError(nc_inq_dimids(grpid, NULL, dimid, 1));
-         }
-                                        
+            (CNetCdfInterface::inqDimIds(grpid, nDimNull, dimid, 1));
+         }
+
          for (int i = 0; i < nbdim; i++)
          {
-            CheckError(nc_inq_dimname(grpid, dimid[i], full_name_in));
-            std::string dimname(full_name_in);
+            std::string dimname;
+            (CNetCdfInterface::inqDimName(grpid, dimid[i], dimname));
             retvalue.push_back(dimname);
          }
          delete [] dimid;
-                                                                                                                                                      
+
          return (retvalue);
       }
@@ -220,10 +221,10 @@
          int retvalue = 0;
          int grpid = this->getCurrentGroup();
-         CheckError(nc_def_grp(grpid, const_cast<char*>(name.c_str()), &retvalue));
+         (CNetCdfInterface::defGrp(grpid, name, retvalue));
          return (retvalue);
       }
-      
-      //---------------------------------------------------------------
-      
+
+      //---------------------------------------------------------------
+
       int CONetCDF4::addDimension(const StdString& name, const StdSize size)
       {
@@ -231,12 +232,12 @@
          int grpid = this->getCurrentGroup();
          if (size != UNLIMITED_DIM)
-            CheckError(nc_def_dim (grpid, name.c_str(), size, &retvalue));
+            (CNetCdfInterface::defDim(grpid, name, size, retvalue));
          else
-            CheckError(nc_def_dim (grpid, name.c_str(), NC_UNLIMITED, &retvalue));
+            (CNetCdfInterface::defDim(grpid, name, NC_UNLIMITED, retvalue));
          return (retvalue);
       }
-      
-      //---------------------------------------------------------------
-      
+
+      //---------------------------------------------------------------
+
       int CONetCDF4::addVariable(const StdString & name, nc_type type,
                                   const std::vector<StdString> & dim)
@@ -248,7 +249,7 @@
          StdSize totalSize ;
          StdSize maxSize=1024*1024*256 ; // == 2GB/8 if output double
-         
-         int grpid = this->getCurrentGroup();
-         
+
+         int grpid = this->getCurrentGroup();
+
          std::vector<StdString>::const_iterator
             it  = dim.begin(), end = dim.end();
@@ -258,10 +259,10 @@
             const StdString & dimid = *it;
             dimids.push_back(this->getDimension(dimid));
-            CheckError(nc_inq_dimlen (grpid, this->getDimension(dimid), &size));
+            (CNetCdfInterface::inqDimLen(grpid, this->getDimension(dimid), size));
             if (size==NC_UNLIMITED) size=1 ;
             dimsizes.push_back(size) ;
          }
-         
-         CheckError(nc_def_var (grpid, name.c_str(), type, dimids.size(), &(dimids[0]), &varid));
+
+         (CNetCdfInterface::defVar(grpid, name, type, dimids.size(), &(dimids[0]), varid));
 
 // set chunksize : size of one record
@@ -274,6 +275,6 @@
          }
 
-         CheckError(nc_def_var_chunking (grpid, varid, NC_CHUNKED, &(dimsizes[0])));
-         CheckError(nc_def_var_fill(grpid, varid, true, NULL));
+         (CNetCdfInterface::defVarChunking(grpid, varid, NC_CHUNKED, &(dimsizes[0])));
+         (CNetCdfInterface::defVarFill(grpid, varid, true, NULL));
          return (varid);
       }
@@ -287,10 +288,10 @@
          int grpid = this->getCurrentGroup();
          int varid = (varname == NULL) ? NC_GLOBAL : this->getVariable(*varname);
-         CheckError(nc_put_att(grpid, varid, name.c_str(), NC_CHAR, value.size(), value.c_str()));
+         (CNetCdfInterface::putAtt(grpid, varid, name, NC_CHAR, value.size(), value.c_str()));
          //CheckError(nc_put_att_string(grpid, varid, name.c_str(), 1, &str));
       }
-      
-      //---------------------------------------------------------------
-      
+
+      //---------------------------------------------------------------
+
       template <>
          void CONetCDF4::addAttribute
@@ -299,5 +300,5 @@
          int grpid = this->getCurrentGroup();
          int varid = (varname == NULL) ? NC_GLOBAL : this->getVariable(*varname);
-         CheckError(nc_put_att_double(grpid, varid, name.c_str(), NC_DOUBLE,1, &value));
+         (CNetCdfInterface::putAttType(grpid, varid, name, 1, &value));
       }
 
@@ -308,8 +309,8 @@
          int grpid = this->getCurrentGroup();
          int varid = (varname == NULL) ? NC_GLOBAL : this->getVariable(*varname);
-         CheckError(nc_put_att_double(grpid, varid, name.c_str(), NC_DOUBLE,value.numElements(), value.dataFirst()));
-      }     
-      //---------------------------------------------------------------
-      
+         (CNetCdfInterface::putAttType(grpid, varid, name, value.numElements(), value.dataFirst()));
+      }
+      //---------------------------------------------------------------
+
       template <>
          void CONetCDF4::addAttribute
@@ -318,5 +319,5 @@
          int grpid = this->getCurrentGroup();
          int varid = (varname == NULL) ? NC_GLOBAL : this->getVariable(*varname);
-         CheckError(nc_put_att_float(grpid, varid, name.c_str(), NC_FLOAT, 1, &value));
+         (CNetCdfInterface::putAttType(grpid, varid, name, 1, &value));
       }
 
@@ -327,9 +328,9 @@
          int grpid = this->getCurrentGroup();
          int varid = (varname == NULL) ? NC_GLOBAL : this->getVariable(*varname);
-         CheckError(nc_put_att_float(grpid, varid, name.c_str(), NC_FLOAT,value.numElements(), value.dataFirst()));
-      }     
-      
-      //---------------------------------------------------------------
-      
+         (CNetCdfInterface::putAttType(grpid, varid, name, value.numElements(), value.dataFirst()));
+      }
+
+      //---------------------------------------------------------------
+
       template <>
          void CONetCDF4::addAttribute
@@ -338,5 +339,5 @@
          int grpid = this->getCurrentGroup();
          int varid = (varname == NULL) ? NC_GLOBAL : this->getVariable(*varname);
-         CheckError(nc_put_att_int(grpid, varid, name.c_str(), NC_INT,1, &value));
+         (CNetCdfInterface::putAttType(grpid, varid, name, 1, &value));
       }
 
@@ -347,9 +348,7 @@
          int grpid = this->getCurrentGroup();
          int varid = (varname == NULL) ? NC_GLOBAL : this->getVariable(*varname);
-         CheckError(nc_put_att_int(grpid, varid, name.c_str(), NC_INT,value.numElements(), value.dataFirst()));
-      }     
-      
-      
- 
+         (CNetCdfInterface::putAttType(grpid, varid, name, value.numElements(), value.dataFirst()));
+      }
+
       template <>
          void CONetCDF4::addAttribute
@@ -358,5 +357,5 @@
          int grpid = this->getCurrentGroup();
          int varid = (varname == NULL) ? NC_GLOBAL : this->getVariable(*varname);
-         CheckError(nc_put_att_short(grpid, varid, name.c_str(), NC_SHORT,1, &value));
+         (CNetCdfInterface::putAttType(grpid, varid, name, 1, &value));
       }
 
@@ -367,9 +366,9 @@
          int grpid = this->getCurrentGroup();
          int varid = (varname == NULL) ? NC_GLOBAL : this->getVariable(*varname);
-         CheckError(nc_put_att_short(grpid, varid, name.c_str(), NC_SHORT,value.numElements(), value.dataFirst()));
-      }     
-      
-      
-      
+         (CNetCdfInterface::putAttType(grpid, varid, name, value.numElements(), value.dataFirst()));
+      }
+
+
+
       template <>
          void CONetCDF4::addAttribute
@@ -378,5 +377,5 @@
          int grpid = this->getCurrentGroup();
          int varid = (varname == NULL) ? NC_GLOBAL : this->getVariable(*varname);
-         CheckError(nc_put_att_long(grpid, varid, name.c_str(), NC_LONG,1, &value));
+         (CNetCdfInterface::putAttType(grpid, varid, name, 1, &value));
       }
 
@@ -387,9 +386,9 @@
          int grpid = this->getCurrentGroup();
          int varid = (varname == NULL) ? NC_GLOBAL : this->getVariable(*varname);
-         CheckError(nc_put_att_long(grpid, varid, name.c_str(), NC_LONG, value.numElements(), value.dataFirst()));
-      } 
-      
-      
-      
+         (CNetCdfInterface::putAttType(grpid, varid, name, value.numElements(), value.dataFirst()));
+      }
+
+
+
                 //---------------------------------------------------------------
 
@@ -399,7 +398,7 @@
                                         const std::vector<StdSize> * start,
                                         const std::vector<StdSize> * count)
-      {   
+      {
          std::vector<std::size_t> sizes  = this->getDimensions(name);
-         std::vector<std::string> iddims = this->getDimensionsIdList (&name);   
+         std::vector<std::string> iddims = this->getDimensionsIdList (&name);
          std::vector<std::size_t>::const_iterator
             it  = sizes.begin(), end = sizes.end();
@@ -416,5 +415,5 @@
 
          for (;it != end; it++)
-         {      
+         { 
             if ((start != NULL) && (count != NULL))
             {
@@ -432,9 +431,9 @@
             }
          }
-         
-      }
-      
-                     
- 
+
+      }
+
+
+
       template <>
          void CONetCDF4::writeData_(int grpid, int varid,
@@ -442,10 +441,10 @@
                                     const std::vector<StdSize> & scount, const double * data)
       {
-         CheckError(nc_put_vara_double(grpid, varid, &(sstart[0]), &(scount[0]), data));
+         (CNetCdfInterface::putVaraType(grpid, varid, &(sstart[0]), &(scount[0]), data));
 //         sync() ;
       }
-      
-      //---------------------------------------------------------------
-      
+
+      //---------------------------------------------------------------
+
       template <>
          void CONetCDF4::writeData_(int grpid, int varid,
@@ -453,10 +452,10 @@
                                     const std::vector<StdSize> & scount, const int * data)
       {
-          CheckError(nc_put_vara_int(grpid, varid, &(sstart[0]), &(scount[0]), data));
+          (CNetCdfInterface::putVaraType(grpid, varid, &(sstart[0]), &(scount[0]), data));
 //          sync() ;
       }
-      
-      //---------------------------------------------------------------
-      
+
+      //---------------------------------------------------------------
+
       template <>
          void CONetCDF4::writeData_(int grpid, int varid,
@@ -464,5 +463,5 @@
                                     const std::vector<StdSize> & scount, const float * data)
       {
-          CheckError(nc_put_vara_float(grpid, varid, &(sstart[0]), &(scount[0]), data));
+          (CNetCdfInterface::putVaraType(grpid, varid, &(sstart[0]), &(scount[0]), data));
 //          sync() ;
       }
@@ -486,21 +485,21 @@
          int grpid = this->getCurrentGroup();
          int varid = this->getVariable(name);
-         
+
          map<int,size_t>::iterator it=timeAxis.find(varid) ;
          if (it==timeAxis.end()) timeAxis[varid]=record ;
-         else 
+         else
          {
            if (it->second >= record) return ;
            else it->second =record ;
          }
-         
+
          StdSize array_size = 1;
          std::vector<StdSize> sstart, scount;
-         
+
          if (this->wmpi && collective)
-         CheckError(nc_var_par_access(grpid, varid, NC_COLLECTIVE));
+         (CNetCdfInterface::varParAccess(grpid, varid, NC_COLLECTIVE));
          if (this->wmpi && !collective)
-         CheckError(nc_var_par_access(grpid, varid, NC_INDEPENDENT));
-         
+         (CNetCdfInterface::varParAccess(grpid, varid, NC_INDEPENDENT));
+
          this->getWriteDataInfos(name, record, array_size,  sstart, scount, NULL, NULL);
          if (using_netcdf_internal)  if (!isRoot) { sstart[0]=sstart[0]+1 ; scount[0]=0 ;}
@@ -509,16 +508,15 @@
 
       //---------------------------------------------------------------
-      
+
       bool CONetCDF4::varExist(const StdString & varname)
       {
-         int varid = 0;
-         int grpid = this->getCurrentGroup();
-         return (nc_inq_varid (grpid, varname.c_str(), &varid) == NC_NOERR);
+         int grpid = this->getCurrentGroup();
+         return (CNetCdfInterface::isVarExisted(grpid, varname));
       }
 
       void CONetCDF4::sync(void)
       {
-         CheckError(nc_sync(this->ncidp)) ;
-      } 
+         (CNetCdfInterface::sync(this->ncidp)) ;
+      }
       ///--------------------------------------------------------------
  } // namespace xios
Index: XIOS/trunk/src/output/onetcdf4_impl.hpp
===================================================================
--- XIOS/trunk/src/output/onetcdf4_impl.hpp	(revision 488)
+++ XIOS/trunk/src/output/onetcdf4_impl.hpp	(revision 498)
@@ -3,4 +3,5 @@
 
 #include "onetcdf4.hpp"
+#include "netCdfInterface.hpp"
 
 namespace xios
@@ -18,7 +19,7 @@
 
     if (this->wmpi && collective)
-    CheckError(nc_var_par_access(grpid, varid, NC_COLLECTIVE));
+    CNetCdfInterface::varParAccess(grpid, varid, NC_COLLECTIVE);
     if (this->wmpi && !collective)
-    CheckError(nc_var_par_access(grpid, varid, NC_INDEPENDENT));
+    CNetCdfInterface::varParAccess(grpid, varid, NC_INDEPENDENT);
 
     this->getWriteDataInfos
@@ -31,10 +32,10 @@
       << " ] Invalid input data !" );
     }
-         
+
     this->writeData_(grpid, varid, sstart, scount, data.dataFirst());
   }
-      
+
 //----------------------------------------------------------------
-           
+
   template <class T>
   void CONetCDF4::setDefaultValue(const StdString & varname, const T * value)
@@ -42,13 +43,13 @@
     int grpid = this->getCurrentGroup();
     int varid = this->getVariable(varname);
-         
+
     if (value != NULL)
     {
-      CheckError(nc_def_var_fill(grpid, varid, 0, (void*)value));
+      CNetCdfInterface::defVarFill(grpid, varid, 0, (void*)value);
       this->addAttribute(StdString("missing_value"), *value, &varname);
     }
-    else CheckError(nc_def_var_fill(grpid, varid, 1, NULL));         
+    else CNetCdfInterface::defVarFill(grpid, varid, 1, NULL);
   }
-     
+
   ///---------------------------------------------------------------
 
