Index: XIOS/trunk/src/output/onetcdf4.cpp
===================================================================
--- XIOS/trunk/src/output/onetcdf4.cpp	(revision 472)
+++ 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
