Index: /XIOS/trunk/src/io/nc4_data_output.cpp
===================================================================
--- /XIOS/trunk/src/io/nc4_data_output.cpp	(revision 878)
+++ /XIOS/trunk/src/io/nc4_data_output.cpp	(revision 879)
@@ -21,5 +21,5 @@
             , filename(filename)
       {
-		SuperClass::type = MULTI_FILE;
+    SuperClass::type = MULTI_FILE;
       }
 
@@ -33,9 +33,9 @@
             , isCollective(isCollective)
       {
-		SuperClass::type = (multifile) ? MULTI_FILE : ONE_FILE;
+    SuperClass::type = (multifile) ? MULTI_FILE : ONE_FILE;
       }
 
       CNc4DataOutput::~CNc4DataOutput(void)
-	  { /* Ne rien faire de plus */ }
+    { /* Ne rien faire de plus */ }
 
       ///--------------------------------------------------------------
@@ -52,8 +52,8 @@
          if (domain->type == CDomain::type_attr::unstructured)
          {
-			 if (SuperClassWriter::useCFConvention)
-				writeUnstructuredDomain(domain) ;
-			else
-				writeUnstructuredDomainUgrid(domain) ;
+       if (SuperClassWriter::useCFConvention)
+        writeUnstructuredDomain(domain) ;
+      else
+        writeUnstructuredDomainUgrid(domain) ;
            return ;
          }
@@ -434,292 +434,292 @@
       }
 
-	  //--------------------------------------------------------------
-
-		void CNc4DataOutput::writeUnstructuredDomainUgrid(CDomain* domain)
-		{
-			CContext* context = CContext::getCurrent() ;
-			CContextServer* server=context->server ;
-
-			if (domain->IsWritten(this->filename)) return;
-			domain->checkAttributes();
-			if (domain->isEmpty())
-				if (SuperClass::type==MULTI_FILE) return ;
-
-			std::vector<StdString> dim0;
-			StdString domid = domain->getDomainOutputName();
-			StdString domainName = domain->name;
-
-			if (domain->mesh->isWritten(domainName)) domain->mesh = CMesh::getMesh;
-
-			domain->mesh->createMesh(domain->lonvalue_srv, domain->latvalue_srv, domain->bounds_lon_srv, domain->bounds_lat_srv);
-			//domain->mesh->createMeshEpsilon(domain->lonvalue_srv, domain->latvalue_srv, domain->bounds_lon_srv, domain->bounds_lat_srv);
-
-			StdString node_x = domainName + "_node_x";
-			StdString node_y = domainName + "_node_y";
-
-			StdString edge_x = domainName + "_edge_x";
-			StdString edge_y = domainName + "_edge_y";
-			StdString edge_nodes = domainName + "_edge_nodes";
-
-			StdString face_x = domainName + "_face_x";
-			StdString face_y = domainName + "_face_y";
-			StdString face_nodes = domainName + "_face_nodes";
-
-			StdString dimNode = "n" + domainName + "_node";
-			StdString dimEdge = "n" + domainName + "_edge";
-			StdString dimFace = "n" + domainName + "_face";
-			StdString dimVertex = "n" + domainName + "_vertex";
-			StdString dimTwo = "Two";
-
-			if (!SuperClassWriter::dimExist(dimTwo)) SuperClassWriter::addDimension(dimTwo, 2);
-			if (!isWrittenDomain(domid))
-			{
-				dim0.clear();
-				SuperClassWriter::addVariable(domainName, NC_INT, dim0);
-				SuperClassWriter::addAttribute("cf_role", StdString("mesh_topology"), &domainName);
-				SuperClassWriter::addAttribute("node_coordinates", node_x + " " + node_y, &domainName);
-			}
-
-			try
-			{
-				switch (SuperClass::type)
-				{
-					case (ONE_FILE) :
-					{
-						// Adding nodes
-						if (domain->nvertex == 1)
-						{
-							if (!SuperClassWriter::varExist(node_x) || !SuperClassWriter::varExist(node_y))
-							{
-								SuperClassWriter::addDimension(dimNode, domain->mesh->nbNodes);
-								dim0.clear();
-								dim0.push_back(dimNode);
-								SuperClassWriter::addVariable(node_x, NC_FLOAT, dim0);
-								SuperClassWriter::addAttribute("standard_name", StdString("longitude"), &node_x);
-								SuperClassWriter::addAttribute("longname_name", StdString("Longitude of mesh nodes."), &node_x);
-								SuperClassWriter::addAttribute("units", StdString("degrees_east"), &node_x);
-								SuperClassWriter::addVariable(node_y, NC_FLOAT, dim0);
-								SuperClassWriter::addAttribute("standard_name", StdString("latitude"), &node_y);
-								SuperClassWriter::addAttribute("longname_name", StdString("Latitude of mesh nodes."), &node_y);
-								SuperClassWriter::addAttribute("units", StdString("degrees_north"), &node_y);
-							}
-						} // domain->nvertex == 1
-
-						// Adding edges and nodes, if nodes have not been defined previously
-						if (domain->nvertex == 2)
-						{
-							// Nodes
-							if (!SuperClassWriter::varExist(node_x) || !SuperClassWriter::varExist(node_y))
-							{
-								SuperClassWriter::addDimension(dimNode, domain->mesh->nbNodes);
-								dim0.clear();
-								dim0.push_back(dimNode);
-								SuperClassWriter::addVariable(node_x, NC_FLOAT, dim0);
-								SuperClassWriter::addAttribute("standard_name", StdString("longitude"), &node_x);
-								SuperClassWriter::addAttribute("longname_name", StdString("Longitude of mesh nodes."), &node_x);
-								SuperClassWriter::addAttribute("units", StdString("degrees_east"), &node_x);
-								SuperClassWriter::addVariable(node_y, NC_FLOAT, dim0);
-								SuperClassWriter::addAttribute("standard_name", StdString("latitude"), &node_y);
-								SuperClassWriter::addAttribute("longname_name", StdString("Latitude of mesh nodes."), &node_y);
-								SuperClassWriter::addAttribute("units", StdString("degrees_north"), &node_y);
-							}
-							// Edges
-							if (!SuperClassWriter::varExist(edge_x) || !SuperClassWriter::varExist(edge_y))
-							{
-								SuperClassWriter::addAttribute("edge_node_connectivity", edge_nodes, &domainName);
-								SuperClassWriter::addAttribute("edge_coordinates", edge_x + " " + edge_y, &domainName);
-								SuperClassWriter::addDimension(dimEdge, domain->mesh->nbEdges);
-								dim0.clear();
-								dim0.push_back(dimEdge);
-								SuperClassWriter::addVariable(edge_x, NC_FLOAT, dim0);
-								SuperClassWriter::addAttribute("standard_name", StdString("longitude"), &edge_x);
-								SuperClassWriter::addAttribute("longname_name", StdString("Characteristic longitude of mesh edges."), &edge_x);
-								SuperClassWriter::addAttribute("units", StdString("degrees_east"), &edge_x);
-								SuperClassWriter::addVariable(edge_y, NC_FLOAT, dim0);
-								SuperClassWriter::addAttribute("standard_name", StdString("latitude"), &edge_y);
-								SuperClassWriter::addAttribute("longname_name", StdString("Characteristic latitude of mesh edges."), &edge_y);
-								SuperClassWriter::addAttribute("units", StdString("degrees_north"), &edge_y);
-								dim0.clear();
-								dim0.push_back(dimEdge);
-								dim0.push_back(dimTwo);
-								SuperClassWriter::addVariable(edge_nodes, NC_INT, dim0);
-								SuperClassWriter::addAttribute("cf_role", StdString("edge_node_connectivity"), &edge_nodes);
-								SuperClassWriter::addAttribute("long_name", StdString("Maps every edge/link to two nodes that it connects."), &edge_nodes);
-								SuperClassWriter::addAttribute("start_index", 0, &edge_nodes);
-							}
-						} // domain->nvertex == 2
-
-						// Adding faces, edges, and nodes, if edges and nodes have not been defined previously
-						if (domain->nvertex > 2)
-						{
-							// Nodes
-							if (!SuperClassWriter::varExist(node_x) || !SuperClassWriter::varExist(node_y))
-							{
-								SuperClassWriter::addDimension(dimNode, domain->mesh->nbNodes);
-								dim0.clear();
-								dim0.push_back(dimNode);
-								SuperClassWriter::addVariable(node_x, NC_FLOAT, dim0);
-								SuperClassWriter::addAttribute("standard_name", StdString("longitude"), &node_x);
-								SuperClassWriter::addAttribute("longname_name", StdString("Longitude of mesh nodes."), &node_x);
-								SuperClassWriter::addAttribute("units", StdString("degrees_east"), &node_x);
-								SuperClassWriter::addVariable(node_y, NC_FLOAT, dim0);
-								SuperClassWriter::addAttribute("standard_name", StdString("latitude"), &node_y);
-								SuperClassWriter::addAttribute("longname_name", StdString("Latitude of mesh nodes."), &node_y);
-								SuperClassWriter::addAttribute("units", StdString("degrees_north"), &node_y);
-							}
-							// Edges
-							if (!SuperClassWriter::varExist(edge_x) || !SuperClassWriter::varExist(edge_y))
-							{
-								SuperClassWriter::addAttribute("edge_coordinates", edge_x + " " + edge_y, &domainName);
-								SuperClassWriter::addAttribute("edge_node_connectivity", edge_nodes, &domainName);
-								SuperClassWriter::addDimension(dimEdge, domain->mesh->nbEdges);
-								dim0.clear();
-								dim0.push_back(dimEdge);
-								SuperClassWriter::addVariable(edge_x, NC_FLOAT, dim0);
-								SuperClassWriter::addAttribute("standard_name", StdString("longitude"), &edge_x);
-								SuperClassWriter::addAttribute("longname_name", StdString("Characteristic longitude of mesh edges."), &edge_x);
-								SuperClassWriter::addAttribute("units", StdString("degrees_east"), &edge_x);
-								SuperClassWriter::addVariable(edge_y, NC_FLOAT, dim0);
-								SuperClassWriter::addAttribute("standard_name", StdString("latitude"), &edge_y);
-								SuperClassWriter::addAttribute("longname_name", StdString("Characteristic latitude of mesh edges."), &edge_y);
-								SuperClassWriter::addAttribute("units", StdString("degrees_north"), &edge_y);
-								dim0.clear();
-								dim0.push_back(dimEdge);
-								dim0.push_back(dimTwo);
-								SuperClassWriter::addVariable(edge_nodes, NC_INT, dim0);
-								SuperClassWriter::addAttribute("cf_role", StdString("edge_node_connectivity"), &edge_nodes);
-								SuperClassWriter::addAttribute("long_name", StdString("Maps every edge/link to two nodes that it connects."), &edge_nodes);
-								SuperClassWriter::addAttribute("start_index", 0, &edge_nodes);
-							}
-							// Faces
-								SuperClassWriter::addAttribute("face_coordinates", face_x + " " + face_y, &domainName);
-								SuperClassWriter::addAttribute("face_node_connectivity", face_nodes, &domainName);
-								SuperClassWriter::addDimension(dimFace, domain->mesh->nbFaces);
-								SuperClassWriter::addDimension(dimVertex, domain->mesh->nvertex);
-								dim0.clear();
-								dim0.push_back(dimFace);
-								SuperClassWriter::addVariable(face_x, NC_FLOAT, dim0);
-								SuperClassWriter::addAttribute("standard_name", StdString("longitude"), &face_x);
-								SuperClassWriter::addAttribute("longname_name", StdString("Characteristic longitude of mesh faces."), &face_x);
-								SuperClassWriter::addAttribute("units", StdString("degrees_east"), &face_x);
-								SuperClassWriter::addVariable(face_y, NC_FLOAT, dim0);
-								SuperClassWriter::addAttribute("standard_name", StdString("latitude"), &face_y);
-								SuperClassWriter::addAttribute("longname_name", StdString("Characteristic latitude of mesh faces."), &face_y);
-								SuperClassWriter::addAttribute("units", StdString("degrees_north"), &face_y);
-								dim0.clear();
-								dim0.push_back(dimFace);
-								dim0.push_back(dimVertex);
-								SuperClassWriter::addVariable(face_nodes, NC_INT, dim0);
-								SuperClassWriter::addAttribute("cf_role", StdString("face_node_connectivity"), &face_nodes);
-								SuperClassWriter::addAttribute("long_name", StdString("Maps every face to its corner nodes."), &face_nodes);
-								SuperClassWriter::addAttribute("start_index", 0, &face_nodes);
-						} // domain->nvertex > 2
-
-						SuperClassWriter::definition_end();
-
-						if (!isWrittenDomain(domid))
-						{
-							if (domain->nvertex == 1)
-							{
-								SuperClassWriter::writeData(domain->mesh->node_lat, node_y, isCollective, 0);
-								SuperClassWriter::writeData(domain->mesh->node_lon, node_x, isCollective, 0);
-							}
-							else if (domain->nvertex == 2)
+    //--------------------------------------------------------------
+
+    void CNc4DataOutput::writeUnstructuredDomainUgrid(CDomain* domain)
+    {
+      CContext* context = CContext::getCurrent() ;
+      CContextServer* server=context->server ;
+
+      if (domain->IsWritten(this->filename)) return;
+      domain->checkAttributes();
+      if (domain->isEmpty())
+        if (SuperClass::type==MULTI_FILE) return ;
+
+      std::vector<StdString> dim0;
+      StdString domid = domain->getDomainOutputName();
+      StdString domainName = domain->name;
+
+      if (domain->mesh->isWritten(domainName)) domain->mesh = CMesh::getMesh;
+
+      //domain->mesh->createMesh(domain->lonvalue_srv, domain->latvalue_srv, domain->bounds_lon_srv, domain->bounds_lat_srv);
+      domain->mesh->createMeshEpsilon(domain->lonvalue_srv, domain->latvalue_srv, domain->bounds_lon_srv, domain->bounds_lat_srv);
+
+      StdString node_x = domainName + "_node_x";
+      StdString node_y = domainName + "_node_y";
+
+      StdString edge_x = domainName + "_edge_x";
+      StdString edge_y = domainName + "_edge_y";
+      StdString edge_nodes = domainName + "_edge_nodes";
+
+      StdString face_x = domainName + "_face_x";
+      StdString face_y = domainName + "_face_y";
+      StdString face_nodes = domainName + "_face_nodes";
+
+      StdString dimNode = "n" + domainName + "_node";
+      StdString dimEdge = "n" + domainName + "_edge";
+      StdString dimFace = "n" + domainName + "_face";
+      StdString dimVertex = "n" + domainName + "_vertex";
+      StdString dimTwo = "Two";
+
+      if (!SuperClassWriter::dimExist(dimTwo)) SuperClassWriter::addDimension(dimTwo, 2);
+      if (!isWrittenDomain(domid))
+      {
+        dim0.clear();
+        SuperClassWriter::addVariable(domainName, NC_INT, dim0);
+        SuperClassWriter::addAttribute("cf_role", StdString("mesh_topology"), &domainName);
+        SuperClassWriter::addAttribute("node_coordinates", node_x + " " + node_y, &domainName);
+      }
+
+      try
+      {
+        switch (SuperClass::type)
+        {
+          case (ONE_FILE) :
+          {
+            // Adding nodes
+            if (domain->nvertex == 1)
+            {
+              if (!SuperClassWriter::varExist(node_x) || !SuperClassWriter::varExist(node_y))
+              {
+                SuperClassWriter::addDimension(dimNode, domain->mesh->nbNodes);
+                dim0.clear();
+                dim0.push_back(dimNode);
+                SuperClassWriter::addVariable(node_x, NC_FLOAT, dim0);
+                SuperClassWriter::addAttribute("standard_name", StdString("longitude"), &node_x);
+                SuperClassWriter::addAttribute("longname_name", StdString("Longitude of mesh nodes."), &node_x);
+                SuperClassWriter::addAttribute("units", StdString("degrees_east"), &node_x);
+                SuperClassWriter::addVariable(node_y, NC_FLOAT, dim0);
+                SuperClassWriter::addAttribute("standard_name", StdString("latitude"), &node_y);
+                SuperClassWriter::addAttribute("longname_name", StdString("Latitude of mesh nodes."), &node_y);
+                SuperClassWriter::addAttribute("units", StdString("degrees_north"), &node_y);
+              }
+            } // domain->nvertex == 1
+
+            // Adding edges and nodes, if nodes have not been defined previously
+            if (domain->nvertex == 2)
+            {
+              // Nodes
+              if (!SuperClassWriter::varExist(node_x) || !SuperClassWriter::varExist(node_y))
+              {
+                SuperClassWriter::addDimension(dimNode, domain->mesh->nbNodes);
+                dim0.clear();
+                dim0.push_back(dimNode);
+                SuperClassWriter::addVariable(node_x, NC_FLOAT, dim0);
+                SuperClassWriter::addAttribute("standard_name", StdString("longitude"), &node_x);
+                SuperClassWriter::addAttribute("longname_name", StdString("Longitude of mesh nodes."), &node_x);
+                SuperClassWriter::addAttribute("units", StdString("degrees_east"), &node_x);
+                SuperClassWriter::addVariable(node_y, NC_FLOAT, dim0);
+                SuperClassWriter::addAttribute("standard_name", StdString("latitude"), &node_y);
+                SuperClassWriter::addAttribute("longname_name", StdString("Latitude of mesh nodes."), &node_y);
+                SuperClassWriter::addAttribute("units", StdString("degrees_north"), &node_y);
+              }
+              // Edges
+              if (!SuperClassWriter::varExist(edge_x) || !SuperClassWriter::varExist(edge_y))
+              {
+                SuperClassWriter::addAttribute("edge_node_connectivity", edge_nodes, &domainName);
+                SuperClassWriter::addAttribute("edge_coordinates", edge_x + " " + edge_y, &domainName);
+                SuperClassWriter::addDimension(dimEdge, domain->mesh->nbEdges);
+                dim0.clear();
+                dim0.push_back(dimEdge);
+                SuperClassWriter::addVariable(edge_x, NC_FLOAT, dim0);
+                SuperClassWriter::addAttribute("standard_name", StdString("longitude"), &edge_x);
+                SuperClassWriter::addAttribute("longname_name", StdString("Characteristic longitude of mesh edges."), &edge_x);
+                SuperClassWriter::addAttribute("units", StdString("degrees_east"), &edge_x);
+                SuperClassWriter::addVariable(edge_y, NC_FLOAT, dim0);
+                SuperClassWriter::addAttribute("standard_name", StdString("latitude"), &edge_y);
+                SuperClassWriter::addAttribute("longname_name", StdString("Characteristic latitude of mesh edges."), &edge_y);
+                SuperClassWriter::addAttribute("units", StdString("degrees_north"), &edge_y);
+                dim0.clear();
+                dim0.push_back(dimEdge);
+                dim0.push_back(dimTwo);
+                SuperClassWriter::addVariable(edge_nodes, NC_INT, dim0);
+                SuperClassWriter::addAttribute("cf_role", StdString("edge_node_connectivity"), &edge_nodes);
+                SuperClassWriter::addAttribute("long_name", StdString("Maps every edge/link to two nodes that it connects."), &edge_nodes);
+                SuperClassWriter::addAttribute("start_index", 0, &edge_nodes);
+              }
+            } // domain->nvertex == 2
+
+            // Adding faces, edges, and nodes, if edges and nodes have not been defined previously
+            if (domain->nvertex > 2)
+            {
+              // Nodes
+              if (!SuperClassWriter::varExist(node_x) || !SuperClassWriter::varExist(node_y))
+              {
+                SuperClassWriter::addDimension(dimNode, domain->mesh->nbNodes);
+                dim0.clear();
+                dim0.push_back(dimNode);
+                SuperClassWriter::addVariable(node_x, NC_FLOAT, dim0);
+                SuperClassWriter::addAttribute("standard_name", StdString("longitude"), &node_x);
+                SuperClassWriter::addAttribute("longname_name", StdString("Longitude of mesh nodes."), &node_x);
+                SuperClassWriter::addAttribute("units", StdString("degrees_east"), &node_x);
+                SuperClassWriter::addVariable(node_y, NC_FLOAT, dim0);
+                SuperClassWriter::addAttribute("standard_name", StdString("latitude"), &node_y);
+                SuperClassWriter::addAttribute("longname_name", StdString("Latitude of mesh nodes."), &node_y);
+                SuperClassWriter::addAttribute("units", StdString("degrees_north"), &node_y);
+              }
+              // Edges
+              if (!SuperClassWriter::varExist(edge_x) || !SuperClassWriter::varExist(edge_y))
+              {
+                SuperClassWriter::addAttribute("edge_coordinates", edge_x + " " + edge_y, &domainName);
+                SuperClassWriter::addAttribute("edge_node_connectivity", edge_nodes, &domainName);
+                SuperClassWriter::addDimension(dimEdge, domain->mesh->nbEdges);
+                dim0.clear();
+                dim0.push_back(dimEdge);
+                SuperClassWriter::addVariable(edge_x, NC_FLOAT, dim0);
+                SuperClassWriter::addAttribute("standard_name", StdString("longitude"), &edge_x);
+                SuperClassWriter::addAttribute("longname_name", StdString("Characteristic longitude of mesh edges."), &edge_x);
+                SuperClassWriter::addAttribute("units", StdString("degrees_east"), &edge_x);
+                SuperClassWriter::addVariable(edge_y, NC_FLOAT, dim0);
+                SuperClassWriter::addAttribute("standard_name", StdString("latitude"), &edge_y);
+                SuperClassWriter::addAttribute("longname_name", StdString("Characteristic latitude of mesh edges."), &edge_y);
+                SuperClassWriter::addAttribute("units", StdString("degrees_north"), &edge_y);
+                dim0.clear();
+                dim0.push_back(dimEdge);
+                dim0.push_back(dimTwo);
+                SuperClassWriter::addVariable(edge_nodes, NC_INT, dim0);
+                SuperClassWriter::addAttribute("cf_role", StdString("edge_node_connectivity"), &edge_nodes);
+                SuperClassWriter::addAttribute("long_name", StdString("Maps every edge/link to two nodes that it connects."), &edge_nodes);
+                SuperClassWriter::addAttribute("start_index", 0, &edge_nodes);
+              }
+              // Faces
+                SuperClassWriter::addAttribute("face_coordinates", face_x + " " + face_y, &domainName);
+                SuperClassWriter::addAttribute("face_node_connectivity", face_nodes, &domainName);
+                SuperClassWriter::addDimension(dimFace, domain->mesh->nbFaces);
+                SuperClassWriter::addDimension(dimVertex, domain->mesh->nvertex);
+                dim0.clear();
+                dim0.push_back(dimFace);
+                SuperClassWriter::addVariable(face_x, NC_FLOAT, dim0);
+                SuperClassWriter::addAttribute("standard_name", StdString("longitude"), &face_x);
+                SuperClassWriter::addAttribute("longname_name", StdString("Characteristic longitude of mesh faces."), &face_x);
+                SuperClassWriter::addAttribute("units", StdString("degrees_east"), &face_x);
+                SuperClassWriter::addVariable(face_y, NC_FLOAT, dim0);
+                SuperClassWriter::addAttribute("standard_name", StdString("latitude"), &face_y);
+                SuperClassWriter::addAttribute("longname_name", StdString("Characteristic latitude of mesh faces."), &face_y);
+                SuperClassWriter::addAttribute("units", StdString("degrees_north"), &face_y);
+                dim0.clear();
+                dim0.push_back(dimFace);
+                dim0.push_back(dimVertex);
+                SuperClassWriter::addVariable(face_nodes, NC_INT, dim0);
+                SuperClassWriter::addAttribute("cf_role", StdString("face_node_connectivity"), &face_nodes);
+                SuperClassWriter::addAttribute("long_name", StdString("Maps every face to its corner nodes."), &face_nodes);
+                SuperClassWriter::addAttribute("start_index", 0, &face_nodes);
+            } // domain->nvertex > 2
+
+            SuperClassWriter::definition_end();
+
+            if (!isWrittenDomain(domid))
+            {
+              if (domain->nvertex == 1)
+              {
+                SuperClassWriter::writeData(domain->mesh->node_lat, node_y, isCollective, 0);
+                SuperClassWriter::writeData(domain->mesh->node_lon, node_x, isCollective, 0);
+              }
+              else if (domain->nvertex == 2)
                             {
-								SuperClassWriter::writeData(domain->mesh->node_lat, node_y, isCollective, 0);
-								SuperClassWriter::writeData(domain->mesh->node_lon, node_x, isCollective, 0);
-								SuperClassWriter::writeData(domain->mesh->edge_lat, edge_y, isCollective, 0);
-								SuperClassWriter::writeData(domain->mesh->edge_lon, edge_x, isCollective, 0);
-								SuperClassWriter::writeData(domain->mesh->edge_nodes, edge_nodes);
+                SuperClassWriter::writeData(domain->mesh->node_lat, node_y, isCollective, 0);
+                SuperClassWriter::writeData(domain->mesh->node_lon, node_x, isCollective, 0);
+                SuperClassWriter::writeData(domain->mesh->edge_lat, edge_y, isCollective, 0);
+                SuperClassWriter::writeData(domain->mesh->edge_lon, edge_x, isCollective, 0);
+                SuperClassWriter::writeData(domain->mesh->edge_nodes, edge_nodes);
                             }
-							else
-							{
-								SuperClassWriter::writeData(domain->mesh->node_lat, node_y, isCollective, 0);
-								SuperClassWriter::writeData(domain->mesh->node_lon, node_x, isCollective, 0);
-								SuperClassWriter::writeData(domain->mesh->edge_lat, edge_y, isCollective, 0);
-								SuperClassWriter::writeData(domain->mesh->edge_lon, edge_x, isCollective, 0);
-								SuperClassWriter::writeData(domain->mesh->edge_nodes, edge_nodes);
-								SuperClassWriter::writeData(domain->mesh->face_lat, face_y, isCollective, 0);
-								SuperClassWriter::writeData(domain->mesh->face_lon, face_x, isCollective, 0);
-								SuperClassWriter::writeData(domain->mesh->face_nodes, face_nodes);
-							}
-							setWrittenDomain(domid);
-						} // !isWrittenDomain
-						else
-						{
-							if (domain->nvertex == 1)
-							{
+              else
+              {
+                SuperClassWriter::writeData(domain->mesh->node_lat, node_y, isCollective, 0);
+                SuperClassWriter::writeData(domain->mesh->node_lon, node_x, isCollective, 0);
+                SuperClassWriter::writeData(domain->mesh->edge_lat, edge_y, isCollective, 0);
+                SuperClassWriter::writeData(domain->mesh->edge_lon, edge_x, isCollective, 0);
+                SuperClassWriter::writeData(domain->mesh->edge_nodes, edge_nodes);
+                SuperClassWriter::writeData(domain->mesh->face_lat, face_y, isCollective, 0);
+                SuperClassWriter::writeData(domain->mesh->face_lon, face_x, isCollective, 0);
+                SuperClassWriter::writeData(domain->mesh->face_nodes, face_nodes);
+              }
+              setWrittenDomain(domid);
+            } // !isWrittenDomain
+            else
+            {
+              if (domain->nvertex == 1)
+              {
                                 if ( (!domain->mesh->edgesAreWritten) && (!domain->mesh->facesAreWritten) )
-								{
-									SuperClassWriter::writeData(domain->mesh->node_lat, node_y, isCollective, 0);
-									SuperClassWriter::writeData(domain->mesh->node_lon, node_x, isCollective, 0);
-								}
-							}
-							if (domain->nvertex == 2)
-							{
+                {
+                  SuperClassWriter::writeData(domain->mesh->node_lat, node_y, isCollective, 0);
+                  SuperClassWriter::writeData(domain->mesh->node_lon, node_x, isCollective, 0);
+                }
+              }
+              if (domain->nvertex == 2)
+              {
                                 if (!domain->mesh->facesAreWritten)
-								{
-									if (!domain->mesh->nodesAreWritten)
-									{
-										SuperClassWriter::writeData(domain->mesh->node_lat, node_y, isCollective, 0);
-										SuperClassWriter::writeData(domain->mesh->node_lon, node_x, isCollective, 0);
-									}
-									SuperClassWriter::writeData(domain->mesh->edge_lat, edge_y, isCollective, 0);
-									SuperClassWriter::writeData(domain->mesh->edge_lon, edge_x, isCollective, 0);
-									SuperClassWriter::writeData(domain->mesh->edge_nodes, edge_nodes);
-								}
-							}	
-							if (domain->nvertex > 2)
-							{
-								if (!domain->mesh->edgesAreWritten)
-								{
-									if (!domain->mesh->nodesAreWritten)
-									{
-										SuperClassWriter::writeData(domain->mesh->node_lat, node_y, isCollective, 0);
-										SuperClassWriter::writeData(domain->mesh->node_lon, node_x, isCollective, 0);
-									}
-									SuperClassWriter::writeData(domain->mesh->edge_lat, edge_y, isCollective, 0);
-									SuperClassWriter::writeData(domain->mesh->edge_lon, edge_x, isCollective, 0);
-									SuperClassWriter::writeData(domain->mesh->edge_nodes, edge_nodes);
-								}
-								SuperClassWriter::writeData(domain->mesh->face_lat, face_y, isCollective, 0);
-								SuperClassWriter::writeData(domain->mesh->face_lon, face_x, isCollective, 0);
-								SuperClassWriter::writeData(domain->mesh->face_nodes, face_nodes);
-							}
-						}// isWrittenDomain
-
-						SuperClassWriter::definition_start();
-
-						break;
-					} // ONE_FILE
-
-					case (MULTI_FILE) :
-					{
-						break;
-					}
-
-					default :
-					ERROR("CNc4DataOutput::writeDomain(domain)",
-					<< "[ type = " << SuperClass::type << "]"
-					<< " not implemented yet !");
-					} // switch
-				} // try
-
-				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);
-	}
-
-	  //--------------------------------------------------------------
-
-	  void CNc4DataOutput::writeUnstructuredDomain(CDomain* domain)
+                {
+                  if (!domain->mesh->nodesAreWritten)
+                  {
+                    SuperClassWriter::writeData(domain->mesh->node_lat, node_y, isCollective, 0);
+                    SuperClassWriter::writeData(domain->mesh->node_lon, node_x, isCollective, 0);
+                  }
+                  SuperClassWriter::writeData(domain->mesh->edge_lat, edge_y, isCollective, 0);
+                  SuperClassWriter::writeData(domain->mesh->edge_lon, edge_x, isCollective, 0);
+                  SuperClassWriter::writeData(domain->mesh->edge_nodes, edge_nodes);
+                }
+              }  
+              if (domain->nvertex > 2)
+              {
+                if (!domain->mesh->edgesAreWritten)
+                {
+                  if (!domain->mesh->nodesAreWritten)
+                  {
+                    SuperClassWriter::writeData(domain->mesh->node_lat, node_y, isCollective, 0);
+                    SuperClassWriter::writeData(domain->mesh->node_lon, node_x, isCollective, 0);
+                  }
+                  SuperClassWriter::writeData(domain->mesh->edge_lat, edge_y, isCollective, 0);
+                  SuperClassWriter::writeData(domain->mesh->edge_lon, edge_x, isCollective, 0);
+                  SuperClassWriter::writeData(domain->mesh->edge_nodes, edge_nodes);
+                }
+                SuperClassWriter::writeData(domain->mesh->face_lat, face_y, isCollective, 0);
+                SuperClassWriter::writeData(domain->mesh->face_lon, face_x, isCollective, 0);
+                SuperClassWriter::writeData(domain->mesh->face_nodes, face_nodes);
+              }
+            }// isWrittenDomain
+
+            SuperClassWriter::definition_start();
+
+            break;
+          } // ONE_FILE
+
+          case (MULTI_FILE) :
+          {
+            break;
+          }
+
+          default :
+          ERROR("CNc4DataOutput::writeDomain(domain)",
+          << "[ type = " << SuperClass::type << "]"
+          << " not implemented yet !");
+          } // switch
+        } // try
+
+        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);
+  }
+
+    //--------------------------------------------------------------
+
+    void CNc4DataOutput::writeUnstructuredDomain(CDomain* domain)
       {
          CContext* context = CContext::getCurrent() ;
@@ -1315,37 +1315,37 @@
                case CDomain::type_attr::unstructured:
                {
-				   if (SuperClassWriter::useCFConvention)
-				   {
-						dimXid     = StdString("cell").append(appendDomId);
-						dimIdList.push_back(dimXid);
-						dimCoordList.push_back(StdString("lon").append(appendDomId));
-						dimCoordList.push_back(StdString("lat").append(appendDomId));
-					}
-				   else
-				   {
-						StdString domainName = domain->name;
-						if (domain->nvertex == 1)
-						{
-							dimXid     = "n" + domainName + "_node";
-							dimIdList.push_back(dimXid);
-							dimCoordList.push_back(StdString(domainName + "_node_x"));
-							dimCoordList.push_back(StdString(domainName + "_node_y"));
-						}
-						else if (domain->nvertex == 2)
-						{
-							dimXid     = "n" + domainName + "_edge";
-							dimIdList.push_back(dimXid);
-							dimCoordList.push_back(StdString(domainName + "_edge_x"));
-							dimCoordList.push_back(StdString(domainName + "_edge_y"));
-						}
-						else
-						{
-							dimXid     = "n" + domainName + "_face";
-							dimIdList.push_back(dimXid);
-							dimCoordList.push_back(StdString(domainName + "_face_x"));
-							dimCoordList.push_back(StdString(domainName + "_face_y"));
-						}
-					}  // ugrid convention
-				}  // case unstructured domain
+           if (SuperClassWriter::useCFConvention)
+           {
+            dimXid     = StdString("cell").append(appendDomId);
+            dimIdList.push_back(dimXid);
+            dimCoordList.push_back(StdString("lon").append(appendDomId));
+            dimCoordList.push_back(StdString("lat").append(appendDomId));
+          }
+           else
+           {
+            StdString domainName = domain->name;
+            if (domain->nvertex == 1)
+            {
+              dimXid     = "n" + domainName + "_node";
+              dimIdList.push_back(dimXid);
+              dimCoordList.push_back(StdString(domainName + "_node_x"));
+              dimCoordList.push_back(StdString(domainName + "_node_y"));
+            }
+            else if (domain->nvertex == 2)
+            {
+              dimXid     = "n" + domainName + "_edge";
+              dimIdList.push_back(dimXid);
+              dimCoordList.push_back(StdString(domainName + "_edge_x"));
+              dimCoordList.push_back(StdString(domainName + "_edge_y"));
+            }
+            else
+            {
+              dimXid     = "n" + domainName + "_face";
+              dimIdList.push_back(dimXid);
+              dimCoordList.push_back(StdString(domainName + "_face_x"));
+              dimCoordList.push_back(StdString(domainName + "_face_y"));
+            }
+          }  // ugrid convention
+        }  // case unstructured domain
              }
 
@@ -1541,267 +1541,6 @@
            ERROR("CNc4DataOutput::writeField_(CField* field)", << msg);
          }
-      }
-
-      //--------------------------------------------------------------
-/*
-      void CNc4DataOutput::writeField_(CField* field)
-      {
-         CContext* context = CContext::getCurrent() ;
-         CContextServer* server=context->server ;
-
-         std::vector<StdString> dims, coodinates;
-         CGrid* grid = field->grid;
-         if (!grid->doGridHaveDataToWrite())
-          if (SuperClass::type==MULTI_FILE) return ;
-
-         CArray<bool,1> axisDomainOrder = grid->axis_domain_order;
-         int numElement = axisDomainOrder.numElements(), idxDomain = 0, idxAxis = 0;
-         std::vector<StdString> domainList = grid->getDomainList();
-         std::vector<StdString> axisList   = grid->getAxisList();
-
-         StdString timeid  = getTimeCounterName();
-         StdString dimXid,dimYid;
-         std::deque<StdString> dimIdList, dimCoordList;
-         bool hasArea = false;
-         StdString cellMeasures = "area:";
-         bool compressedOutput = !field->indexed_output.isEmpty() && field->indexed_output;
-
-         for (int i = 0; i < numElement; ++i)
-         {
-           if (axisDomainOrder(i))
-           {
-             CDomain* domain = CDomain::get(domainList[idxDomain]);
-             StdString domId = domain->getDomainOutputName();
-             StdString appendDomId  = singleDomain ? "" : "_" + domId ;
-
-             if (compressedOutput && domain->isCompressible() && domain->type != CDomain::type_attr::unstructured)
-             {
-               dimIdList.push_back(domId + "_points");
-               field->setUseCompressedOutput();
-             }
-
-             switch (domain->type)
-             {
-               case CDomain::type_attr::curvilinear:
-                 if (!compressedOutput || !domain->isCompressible())
-                 {
-                   dimXid     = StdString("x").append(appendDomId);
-                   dimIdList.push_back(dimXid);
-                   dimYid     = StdString("y").append(appendDomId);
-                   dimIdList.push_back(dimYid);
-                 }
-                 dimCoordList.push_back(StdString("nav_lon").append(appendDomId));
-                 dimCoordList.push_back(StdString("nav_lat").append(appendDomId));
-                 break ;
-               case CDomain::type_attr::rectilinear:
-                 if (!compressedOutput || !domain->isCompressible())
-                 {
-                   dimXid     = StdString("lon").append(appendDomId);
-                   dimIdList.push_back(dimXid);
-                   dimYid     = StdString("lat").append(appendDomId);
-                   dimIdList.push_back(dimYid);
-                 }
-                 break ;
-               case CDomain::type_attr::unstructured:
-                 dimXid     = StdString("cell").append(appendDomId);
-                 dimIdList.push_back(dimXid);
-                 dimCoordList.push_back(StdString("lon").append(appendDomId));
-                 dimCoordList.push_back(StdString("lat").append(appendDomId));
-                 break ;
-             }
-             if (domain->hasArea)
-             {
-               hasArea = true;
-               cellMeasures += " area" + appendDomId;
-             }
-             ++idxDomain;
-           }
-           else
-           {
-             CAxis* axis = CAxis::get(axisList[idxAxis]);
-             StdString axisId = axis->getAxisOutputName();
-
-             if (compressedOutput && axis->isCompressible())
-             {
-               dimIdList.push_back(axisId + "_points");
-               field->setUseCompressedOutput();
-             }
-             else
-               dimIdList.push_back(axisId);
-
-             dimCoordList.push_back(axisId);
-             ++idxAxis;
-           }
-         }
-
-
-//         StdString lonid_loc = (server->intraCommSize > 1)
-//                             ? StdString("lon").append(appendDomid).append("_local")
-//                             : lonid;
-//         StdString latid_loc = (server->intraCommSize > 1)
-//                             ? StdString("lat").append(appendDomid).append("_local")
-//                             : latid;
-
-         StdString fieldid = field->getFieldOutputName();
-
-//         unsigned int ssize = domain->zoom_ni_loc.getValue() * domain->zoom_nj_loc.getValue();
-//         bool isCurvilinear = (domain->lonvalue.getValue()->size() == ssize);
-//          bool isCurvilinear = domain->isCurvilinear ;
-
-         nc_type type ;
-         if (field->prec.isEmpty()) type =  NC_FLOAT ;
-         else
-         {
-           if (field->prec==2) type = NC_SHORT ;
-           else if (field->prec==4)  type =  NC_FLOAT ;
-           else if (field->prec==8)   type =  NC_DOUBLE ;
-         }
-
-         bool wtime   = !(!field->operation.isEmpty() && field->getOperationTimeType() == func::CFunctor::once);
-
-         if (wtime)
-         {
-
-            //StdOStringStream oss;
-           // oss << "time_" << field->operation.getValue()
-           //     << "_" << field->getRelFile()->output_freq.getValue();
-          //oss
-            if (field->getOperationTimeType() == func::CFunctor::instant) coodinates.push_back(string("time_instant"));
-            else if (field->getOperationTimeType() == func::CFunctor::centered) coodinates.push_back(string("time_centered"));
-            dims.push_back(timeid);
-         }
-
-         if (compressedOutput && grid->isCompressible())
-         {
-           dims.push_back(grid->getId() + "_points");
-           field->setUseCompressedOutput();
-         }
-         else
-         {
-           while (!dimIdList.empty())
-           {
-             dims.push_back(dimIdList.back());
-             dimIdList.pop_back();
-           }
-         }
-
-         while (!dimCoordList.empty())
-         {
-           coodinates.push_back(dimCoordList.back());
-           dimCoordList.pop_back();
-         }
-
-         try
-         {
-           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 freqOp = field->freq_op.getValue();
-              freqOp.solveTimeStep(*context->calendar);
-              StdString freqOpStr = freqOp.toStringUDUnits();
-              SuperClassWriter::addAttribute("interval_operation", freqOpStr, &fieldid);
-
-              CDuration freqOut = field->getRelFile()->output_freq.getValue();
-              freqOut.solveTimeStep(*context->calendar);
-              SuperClassWriter::addAttribute("interval_write", freqOut.toStringUDUnits(), &fieldid);
-
-              StdString cellMethods = "time: ";
-              if (field->operation.getValue() == "instant") cellMethods += "point";
-              else if (field->operation.getValue() == "average") cellMethods += "mean";
-              else if (field->operation.getValue() == "accumulate") cellMethods += "sum";
-              else cellMethods += field->operation;
-              if (freqOp.resolve(*context->calendar) != freqOut.resolve(*context->calendar))
-                cellMethods += " (interval: " + freqOpStr + ")";
-              SuperClassWriter::addAttribute("cell_methods", cellMethods, &fieldid);
-           }
-
-           if (hasArea)
-             SuperClassWriter::addAttribute("cell_measures", cellMeasures, &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
-              SuperClassWriter::setDefaultValue(fieldid, (double*)NULL);
-
-            if (field->compression_level.isEmpty())
-              field->compression_level = field->file->compression_level.isEmpty() ? 0 : field->file->compression_level;
-            SuperClassWriter::setCompressionLevel(fieldid, field->compression_level);
-
-           {  // Ecriture des coordonnes
-
-              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);
-         }
-      }
-
-*/
+      } // writeField_()
+
       //--------------------------------------------------------------
 
@@ -1817,5 +1556,5 @@
          try
          {
-		   if (SuperClassWriter::useCFConvention)
+       if (SuperClassWriter::useCFConvention)
              this->writeFileAttributes(filename, description,
                                        StdString("CF-1.5"),
Index: /XIOS/trunk/src/node/mesh.cpp
===================================================================
--- /XIOS/trunk/src/node/mesh.cpp	(revision 879)
+++ /XIOS/trunk/src/node/mesh.cpp	(revision 879)
@@ -0,0 +1,487 @@
+/*!
+  \file mesh.cpp
+  \author Olga Abramkina
+  \brief Definition of class CMesh.
+*/
+
+#include "mesh.hpp"
+
+namespace xios {
+
+/// ////////////////////// DÃ©finitions ////////////////////// ///
+
+  CMesh::CMesh(void) :  nbFaces{0}, nbNodes{0}, nbEdges{0}
+            ,   nvertex{0}
+            ,  nodesAreWritten{false}, edgesAreWritten{false}, facesAreWritten{false}
+            ,  node_lon(), node_lat()
+            ,  edge_lon(), edge_lat(), edge_nodes()
+            ,  face_lon(), face_lat()
+            ,  face_nodes()
+  {
+  }
+
+
+  CMesh::~CMesh(void)
+  {
+  }
+
+  std::map <StdString, CMesh*> CMesh::meshList = std::map <StdString, CMesh*>();
+  CMesh* CMesh::getMesh;
+
+///---------------------------------------------------------------
+/*!
+ * \fn bool CMesh::isWritten (StdString meshName)
+ * Checks if a mesh has been written, updates the list of meshes stored in meshList
+ * \param [in] meshName  The name of a mesh ("name" attribute of a domain).
+ */
+  bool CMesh::isWritten (StdString meshName)
+  {
+    if ( CMesh::meshList.begin() != CMesh::meshList.end() )
+    {
+      if ( CMesh::meshList.find(meshName) != CMesh::meshList.end() )
+      {
+        CMesh::getMesh = meshList[meshName];
+        return true;
+      }
+      else
+      {
+        CMesh::meshList.insert( make_pair(meshName, this) );
+        return false;
+      }
+    }
+    else
+    {
+      CMesh::meshList.insert( make_pair(meshName, this) );
+      return false;
+    }
+  }
+
+///----------------------------------------------------------------
+  int hashPair(int first, int second)
+  {
+    int seed = first + 0x9e3779b9 ;
+    seed ^= second + 0x9e3779b9 + (seed << 6) + (seed >> 2);
+    return seed ;
+  }
+
+///----------------------------------------------------------------
+/*!
+ * \fn size_t CMesh::nodeIndex (double lon, double lat)
+ * Returns its index if a node exists; otherwise adds the node and returns -1.
+ * Precision check is implemented with two hash values for each dimension, longitude and latitude.
+ * \param [in] lon Node longitude in degrees.
+ * \param [in] lat Node latitude in degress ranged from 0 to 360.
+ * \return node index if a node exists; -1 otherwise
+ */
+  size_t CMesh::nodeIndex (double lon, double lat)
+  {
+    double minBoundLon = 0. ;
+    double maxBoundLon = 360. ;
+    double minBoundLat = -90 ;
+    double maxBoundLat = 90 ;
+    double prec=1e-11 ;
+    double precLon=prec ;
+    double precLat=prec ;
+
+    size_t maxsize_t=numeric_limits<size_t>::max() ;
+    if ( (maxBoundLon-minBoundLon)/maxsize_t > precLon) precLon=(maxBoundLon-minBoundLon)/maxsize_t ;
+    if ( (maxBoundLat-minBoundLat)/maxsize_t > precLat) precLat=(maxBoundLat-minBoundLat)/maxsize_t ;
+
+    size_t iMinLon=0 ;
+    size_t iMaxLon=(maxBoundLon-minBoundLon)/precLon ;
+    size_t iMinLat=0 ;
+    size_t iMaxLat=(maxBoundLat-minBoundLat)/precLat ;
+
+    size_t hash0,hash1,hash2,hash3 ;
+    size_t lon0,lon1,lat0,lat1 ;
+
+    lon0=(lon-minBoundLon)/precLon ;
+    if ( ((lon0+1)*precLon + lon0*precLon)/2 > lon-minBoundLon)
+    {
+      if (lon0==iMinLon) lon1=iMaxLon ;
+      else lon1=lon0-1 ;
+    }
+    else
+    {
+      if (lon0==iMaxLon) lon1=iMinLon ;
+      else lon1=lon0+1 ;
+    }
+
+    lat0=(lat-minBoundLat)/precLat ;
+    if ( ((lat0+1)*precLat + lat0*precLat)/2 > lat-minBoundLat)
+    {
+      if (lat0==iMinLat) lat1=lat0 ;
+      else lat1=lat0-1 ;
+    }
+    else
+    {
+      if (lat0==iMaxLat) lat1=lat0 ;
+      else lat1=lat0+1 ;
+    }
+
+    hash0=hashPair(lon0,lat0) ;
+    hash1=hashPair(lon0,lat1) ;
+    hash2=hashPair(lon1,lat0) ;
+    hash3=hashPair(lon1,lat1) ;
+
+    boost::unordered_map<size_t, size_t>::iterator end = hashed_map_nodes.end() ;
+    size_t mapSize = hashed_map_nodes.size();
+    if (hashed_map_nodes.find(hash0)==end && hashed_map_nodes.find(hash1)==end && hashed_map_nodes.find(hash2)==end && hashed_map_nodes.find(hash3)==end)
+    {
+      hashed_map_nodes[hash0] = mapSize ;
+      hashed_map_nodes[hash1] = mapSize + 1;
+      hashed_map_nodes[hash2] = mapSize + 2;
+      hashed_map_nodes[hash3] = mapSize + 3;
+      return -1;
+    }
+    else
+      return ( (hashed_map_nodes[hash0]+1) / 4 );
+
+  } // nodeIndex()
+
+///----------------------------------------------------------------
+/*!
+ * \fn void CMesh::hashDblDbl (double lon, double lat)
+ * Creates two hash values for each dimension, longitude and latitude.
+ * \param [in] lon Node longitude in degrees.
+ * \param [in] lat Node latitude in degress ranged from 0 to 360.
+ */
+  void hashDblDbl (double lon, double lat)
+  {
+    double minBoundLon = 0. ;
+    double maxBoundLon = 360. ;
+    double minBoundLat = -90 ;
+    double maxBoundLat = 90 ;
+    double prec=1e-11 ;
+    double precLon=prec ;
+    double precLat=prec ;
+
+    size_t maxsize_t=numeric_limits<size_t>::max() ;
+    if ( (maxBoundLon-minBoundLon)/maxsize_t > precLon) precLon=(maxBoundLon-minBoundLon)/maxsize_t ;
+    if ( (maxBoundLat-minBoundLat)/maxsize_t > precLat) precLat=(maxBoundLat-minBoundLat)/maxsize_t ;
+
+    size_t iMinLon=0 ;
+    size_t iMaxLon=(maxBoundLon-minBoundLon)/precLon ;
+    size_t iMinLat=0 ;
+    size_t iMaxLat=(maxBoundLat-minBoundLat)/precLat ;
+
+    size_t hash0,hash1,hash2,hash3 ;
+    size_t lon0,lon1,lat0,lat1 ;
+
+    lon0=(lon-minBoundLon)/precLon ;
+    if ( ((lon0+1)*precLon + lon0*precLon)/2 > lon-minBoundLon)
+    {
+      if (lon0==iMinLon) lon1=iMaxLon ;
+      else lon1=lon0-1 ;
+    }
+    else
+    {
+      if (lon0==iMaxLon) lon1=iMinLon ;
+      else lon1=lon0+1 ;
+    }
+
+    lat0=(lat-minBoundLat)/precLat ;
+    if ( ((lat0+1)*precLat + lat0*precLat)/2 > lat-minBoundLat)
+    {
+      if (lat0==iMinLat) lat1=lat0 ;
+      else lat1=lat0-1 ;
+    }
+    else
+    {
+      if (lat0==iMaxLat) lat1=lat0 ;
+      else lat1=lat0+1 ;
+    }
+
+    hash0=hashPair(lon0,lat0) ;
+    hash1=hashPair(lon0,lat1) ;
+    hash2=hashPair(lon1,lat0) ;
+    hash3=hashPair(lon1,lat1) ;
+
+  } // hashDblDbl
+
+///----------------------------------------------------------------
+  std::pair<int,int> make_ordered_pair(int a, int b)
+  {
+    if ( a < b )
+      return std::pair<int,int>(a,b);
+    else
+      return std::pair<int,int>(b,a);
+  }
+
+///----------------------------------------------------------------
+/*!
+ * \fn void CMesh::createMesh(const CArray<double, 1>& lonvalue, const CArray<double, 1>& latvalue,
+            const CArray<double, 2>& bounds_lon, const CArray<double, 2>& bounds_lat)
+ * Creates or updates a mesh for the three types of mesh elements: nodes, edges, and faces.
+ * \param [in] lonvalue  Array of longitudes.
+ * \param [in] latvalue  Array of latitudes.
+ * \param [in] bounds_lon Array of boundary longitudes. Its size depends on the element type.
+ * \param [in] bounds_lat Array of boundarry latitudes. Its size depends on the element type.
+ */
+  void CMesh::createMesh(const CArray<double, 1>& lonvalue, const CArray<double, 1>& latvalue,
+            const CArray<double, 2>& bounds_lon, const CArray<double, 2>& bounds_lat)
+  {
+    nvertex = (bounds_lon.numElements() == 0) ? 1 : bounds_lon.rows();
+
+    if (nvertex == 1)
+    {
+      nbNodes = lonvalue.numElements();
+      node_lon.resizeAndPreserve(nbNodes);
+      node_lat.resizeAndPreserve(nbNodes);
+      for (int nn = 0; nn < nbNodes; ++nn)
+      {
+        if (map_nodes.find(make_pair (lonvalue(nn), latvalue(nn))) == map_nodes.end())
+        {
+          map_nodes[make_pair (lonvalue(nn), latvalue(nn))] = nn ;
+          node_lon(nn) = lonvalue(nn);
+          node_lat(nn) = latvalue(nn);
+        }
+      }
+    }
+    else if (nvertex == 2)
+    {
+      nbEdges = bounds_lon.shape()[1];
+
+      // Create nodes and edge_node connectivity
+      node_lon.resizeAndPreserve(nbEdges*nvertex); // Max possible number of nodes
+      node_lat.resizeAndPreserve(nbEdges*nvertex);
+      edge_nodes.resizeAndPreserve(nvertex, nbEdges);
+
+      for (int ne = 0; ne < nbEdges; ++ne)
+      {
+        for (int nv = 0; nv < nvertex; ++nv)
+        {
+          if (map_nodes.find(make_pair (bounds_lon(nv, ne), bounds_lat(nv ,ne))) == map_nodes.end())
+          {
+            map_nodes[make_pair (bounds_lon(nv, ne), bounds_lat(nv, ne))] = nbNodes ;
+            edge_nodes(nv,ne) = nbNodes ;
+            node_lon(nbNodes) = bounds_lon(nv, ne);
+            node_lat(nbNodes) = bounds_lat(nv, ne);
+            ++nbNodes ;
+          }
+          else
+            edge_nodes(nv,ne) = map_nodes[make_pair (bounds_lon(nv, ne), bounds_lat(nv ,ne))];
+        }
+      }
+      node_lon.resizeAndPreserve(nbNodes);
+      node_lat.resizeAndPreserve(nbNodes);
+
+      // Create edges
+      edge_lon.resizeAndPreserve(nbEdges);
+      edge_lat.resizeAndPreserve(nbEdges);
+
+      for (int ne = 0; ne < nbEdges; ++ne)
+      {
+        if (map_edges.find(make_ordered_pair (edge_nodes(0,ne), edge_nodes(1,ne))) == map_edges.end())
+        {
+          map_edges[make_ordered_pair ( edge_nodes(0,ne), edge_nodes(1,ne) )] = ne ;
+          edge_lon(ne) = lonvalue(ne);
+          edge_lat(ne) = latvalue(ne);
+        }
+
+      }
+      edgesAreWritten = true;
+    }
+    else
+    {
+      nbFaces = bounds_lon.shape()[1];
+  
+      // Create nodes and face_node connectivity
+      node_lon.resizeAndPreserve(nbFaces*nvertex);  // Max possible number of nodes
+      node_lat.resizeAndPreserve(nbFaces*nvertex);
+      face_nodes.resize(nvertex, nbFaces);
+  
+      for (int nf = 0; nf < nbFaces; ++nf)
+      {
+        for (int nv = 0; nv < nvertex; ++nv)
+        {
+          if (map_nodes.find(make_pair (bounds_lon(nv, nf), bounds_lat(nv ,nf))) == map_nodes.end())
+          {
+            map_nodes[make_pair (bounds_lon(nv, nf), bounds_lat(nv, nf))] = nbNodes ;
+            face_nodes(nv,nf) = nbNodes ;
+            node_lon(nbNodes) = bounds_lon(nv, nf);
+            node_lat(nbNodes) = bounds_lat(nv ,nf);
+            ++nbNodes ;
+          }
+          else
+          {
+            face_nodes(nv,nf) = map_nodes[make_pair (bounds_lon(nv, nf), bounds_lat(nv ,nf))];
+          }
+        }
+      }
+      node_lon.resizeAndPreserve(nbNodes);
+      node_lat.resizeAndPreserve(nbNodes);
+  
+      // Create edges and edge_nodes connectivity
+      edge_lon.resizeAndPreserve(nbFaces*nvertex); // Max possible number of edges
+      edge_lat.resizeAndPreserve(nbFaces*nvertex);
+      edge_nodes.resizeAndPreserve(2, nbFaces*nvertex);
+      for (int nf = 0; nf < nbFaces; ++nf)
+      {
+        for (int nv1 = 0; nv1 < nvertex; ++nv1)
+        {
+          int nv2 = (nv1 < nvertex -1 ) ? (nv1 + 1) : (nv1 + 1 - nvertex); // cyclic rotation
+          if (map_edges.find(make_ordered_pair (face_nodes(nv1,nf), face_nodes(nv2,nf))) == map_edges.end())
+          {
+            map_edges[make_ordered_pair (face_nodes(nv1,nf), face_nodes(nv2,nf))] = nbEdges ;
+            edge_nodes(Range::all(),nbEdges) = face_nodes(nv1,nf), face_nodes(nv2,nf);
+            edge_lon(nbEdges) = ( abs( node_lon(face_nodes(nv1,nf)) - node_lon(face_nodes(nv2,nf))) < 180.) ?
+                        (( node_lon(face_nodes(nv1,nf)) + node_lon(face_nodes(nv2,nf))) * 0.5) :
+                        (( node_lon(face_nodes(nv1,nf)) + node_lon(face_nodes(nv2,nf))) * 0.5 -180.);;
+            edge_lat(nbEdges) = ( node_lat(face_nodes(nv1,nf)) + node_lat(face_nodes(nv2,nf)) ) * 0.5;
+            ++nbEdges;
+          }
+        }
+      }
+      edge_nodes.resizeAndPreserve(2, nbEdges);
+      edge_lon.resizeAndPreserve(nbEdges);
+      edge_lat.resizeAndPreserve(nbEdges);
+  
+      // Create faces
+      face_lon.resize(nbFaces);
+      face_lat.resize(nbFaces);
+      face_lon = lonvalue;
+      face_lat = latvalue;
+      facesAreWritten = true;
+    } // nvertex > 2
+    
+  } // createMesh()
+
+///----------------------------------------------------------------
+/*!
+ * \fn void CMesh::createMeshEpsilon(const CArray<double, 1>& lonvalue, const CArray<double, 1>& latvalue,
+            const CArray<double, 2>& bounds_lon, const CArray<double, 2>& bounds_lat)
+ * Creates or updates a mesh for the three types of mesh elements: nodes, edges, and faces.
+ * Precision check is implemented with two hash values for each dimension, longitude and latitude.
+ * \param [in] lonvalue  Array of longitudes.
+ * \param [in] latvalue  Array of latitudes.
+ * \param [in] bounds_lon Array of boundary longitudes. Its size depends on the element type.
+ * \param [in] bounds_lat Array of boundarry latitudes. Its size depends on the element type.
+ */
+  void CMesh::createMeshEpsilon(const CArray<double, 1>& lonvalue, const CArray<double, 1>& latvalue,
+            const CArray<double, 2>& bounds_lon, const CArray<double, 2>& bounds_lat)
+  {
+    nvertex = (bounds_lon.numElements() == 0) ? 1 : bounds_lon.rows();
+
+    if (nvertex == 1)
+    {
+      nbNodes = lonvalue.numElements();
+      node_lon.resizeAndPreserve(nbNodes);
+      node_lat.resizeAndPreserve(nbNodes);
+      for (int nn = 0; nn < nbNodes; ++nn)
+      {
+        if ( nodeIndex(lonvalue(nn), latvalue(nn)) == -1 )
+        {
+          node_lon(nn) = lonvalue(nn);
+          node_lat(nn) = latvalue(nn);
+        }
+      }
+    nodesAreWritten = true;
+    }
+    else if (nvertex == 2)
+    {
+      nbEdges = bounds_lon.shape()[1];
+
+      // Create nodes and edge_node connectivity
+      node_lon.resizeAndPreserve(nbEdges*nvertex); // Max possible number of nodes
+      node_lat.resizeAndPreserve(nbEdges*nvertex);
+      edge_nodes.resizeAndPreserve(nvertex, nbEdges);
+
+      for (int ne = 0; ne < nbEdges; ++ne)
+      {
+        for (int nv = 0; nv < nvertex; ++nv)
+        {
+          if ( nodeIndex(bounds_lon(nv, ne), bounds_lat(nv ,ne)) == -1)
+          {
+            edge_nodes(nv,ne) = nbNodes ;
+            node_lon(nbNodes) = bounds_lon(nv, ne);
+            node_lat(nbNodes) = bounds_lat(nv, ne);
+            ++nbNodes ;
+          }
+          else
+            edge_nodes(nv,ne) = nodeIndex(bounds_lon(nv, ne), bounds_lat(nv ,ne));
+        }
+      }
+      node_lon.resizeAndPreserve(nbNodes);
+      node_lat.resizeAndPreserve(nbNodes);
+
+      // Create edges
+      edge_lon.resizeAndPreserve(nbEdges);
+      edge_lat.resizeAndPreserve(nbEdges);
+
+      for (int ne = 0; ne < nbEdges; ++ne)
+      {
+        if (map_edges.find(make_ordered_pair (edge_nodes(0,ne), edge_nodes(1,ne))) == map_edges.end())
+        {
+          map_edges[make_ordered_pair ( edge_nodes(0,ne), edge_nodes(1,ne) )] = ne ;
+          edge_lon(ne) = lonvalue(ne);
+          edge_lat(ne) = latvalue(ne);
+        }
+      }
+      edgesAreWritten = true;
+    } // nvertex = 2
+    else
+    {
+      nbFaces = bounds_lon.shape()[1];
+
+      // Create nodes and face_node connectivity
+      node_lon.resizeAndPreserve(nbFaces*nvertex);  // Max possible number of nodes
+      node_lat.resizeAndPreserve(nbFaces*nvertex);
+      face_nodes.resize(nvertex, nbFaces);
+
+      for (int nf = 0; nf < nbFaces; ++nf)
+      {
+        for (int nv = 0; nv < nvertex; ++nv)
+        {
+          if ( nodeIndex(bounds_lon(nv, nf), bounds_lat(nv ,nf)) == -1)
+          {
+            face_nodes(nv,nf) = nbNodes ;
+            node_lon(nbNodes) = bounds_lon(nv, nf);
+            node_lat(nbNodes) = bounds_lat(nv ,nf);
+            ++nbNodes ;
+          }
+          else
+          {
+            face_nodes(nv,nf) = nodeIndex(bounds_lon(nv, nf), bounds_lat(nv ,nf));
+          }
+        }
+      }
+      node_lon.resizeAndPreserve(nbNodes);
+      node_lat.resizeAndPreserve(nbNodes);
+
+      // Create edges and edge_nodes connectivity
+      edge_lon.resizeAndPreserve(nbFaces*nvertex); // Max possible number of edges
+      edge_lat.resizeAndPreserve(nbFaces*nvertex);
+      edge_nodes.resizeAndPreserve(2, nbFaces*nvertex);
+      for (int nf = 0; nf < nbFaces; ++nf)
+      {
+        for (int nv1 = 0; nv1 < nvertex; ++nv1)
+        {
+          int nv2 = (nv1 < nvertex -1 ) ? (nv1 + 1) : (nv1 + 1 - nvertex); // cyclic rotation
+          if (map_edges.find(make_ordered_pair (face_nodes(nv1,nf), face_nodes(nv2,nf))) == map_edges.end())
+          {
+            map_edges[make_ordered_pair (face_nodes(nv1,nf), face_nodes(nv2,nf))] = nbEdges ;
+            edge_nodes(Range::all(),nbEdges) = face_nodes(nv1,nf), face_nodes(nv2,nf);
+            edge_lon(nbEdges) = ( abs( node_lon(face_nodes(nv1,nf)) - node_lon(face_nodes(nv2,nf))) < 180.) ?
+                        (( node_lon(face_nodes(nv1,nf)) + node_lon(face_nodes(nv2,nf))) * 0.5) :
+                        (( node_lon(face_nodes(nv1,nf)) + node_lon(face_nodes(nv2,nf))) * 0.5 -180.);;
+            edge_lat(nbEdges) = ( node_lat(face_nodes(nv1,nf)) + node_lat(face_nodes(nv2,nf)) ) * 0.5;
+            ++nbEdges;
+          }
+        }
+      }
+      edge_nodes.resizeAndPreserve(2, nbEdges);
+      edge_lon.resizeAndPreserve(nbEdges);
+      edge_lat.resizeAndPreserve(nbEdges);
+
+      // Create faces
+      face_lon.resize(nbFaces);
+      face_lat.resize(nbFaces);
+      face_lon = lonvalue;
+      face_lat = latvalue;
+      facesAreWritten = true;
+    } // nvertex >= 3
+
+  } // createMeshEpsilon
+
+} // namespace xios
Index: /XIOS/trunk/src/node/mesh.hpp
===================================================================
--- /XIOS/trunk/src/node/mesh.hpp	(revision 879)
+++ /XIOS/trunk/src/node/mesh.hpp	(revision 879)
@@ -0,0 +1,74 @@
+/*!
+  \file mesh.hpp
+  \author Olga Abramkina
+  \brief Declaration of class CMesh.
+*/
+
+#ifndef __XIOS_CMesh__
+#define __XIOS_CMesh__
+ 
+#include "array_new.hpp"
+
+namespace xios {
+  
+   /// ////////////////////// DÃ©clarations ////////////////////// ///
+
+   class CMesh;
+
+   ///--------------------------------------------------------------
+
+/*!
+  \class CMesh
+  \brief CMesh class.
+*/ 
+  class CMesh
+  {
+  
+    public:
+
+      CMesh(void);
+      ~CMesh(void);
+    
+      int nbNodes;
+      int nbEdges;
+      int nbFaces;
+      int nvertex;  
+      
+      bool nodesAreWritten;
+      bool edgesAreWritten;
+      bool facesAreWritten;
+      
+      CArray<double, 1> node_lon;
+      CArray<double, 1> node_lat;
+      
+      CArray<double, 1> edge_lon;
+      CArray<double, 1> edge_lat;
+      CArray<int, 2> edge_nodes;
+
+      CArray<double, 1> face_lon;
+      CArray<double, 1> face_lat;
+      CArray<int, 2> face_nodes;
+
+      void createMesh(const CArray<double, 1>&, const CArray<double, 1>&, 
+            const CArray<double, 2>&, const CArray<double, 2>& );
+                        
+      void createMeshEpsilon(const CArray<double, 1>&, const CArray<double, 1>&, 
+            const CArray<double, 2>&, const CArray<double, 2>& );
+            
+      bool isWritten (StdString);    
+      static CMesh* getMesh;
+          
+       private:
+
+      static std::map <StdString, CMesh*> meshList;
+
+      size_t nodeIndex (double, double);      
+      boost::unordered_map <size_t, size_t> hashed_map_nodes;
+      boost::unordered_map <pair<double,double>, int> map_nodes;
+      boost::unordered_map <pair<int,int>, int> map_edges;
+
+  }; 
+
+} // namespace xios
+
+#endif //__XIOS_CMesh__
