Salome HOME
ParaUMesh.redistributeCells implementation.
[tools/medcoupling.git] / src / MEDLoader / SauvMedConvertor.cxx
index 1fbd660e63a1a7dee2c017d1a4cc327f3460bd66..30448af450cc69da2f8ba6d3ec18a4a29dde7148 100644 (file)
@@ -1,9 +1,9 @@
-// Copyright (C) 2007-2013  CEA/DEN, EDF R&D
+// Copyright (C) 2007-2020  CEA/DEN, EDF R&D
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 // License as published by the Free Software Foundation; either
-// version 2.1 of the License.
+// version 2.1 of the License, or (at your option) any later version.
 //
 // This library is distributed in the hope that it will be useful,
 // but WITHOUT ANY WARRANTY; without even the implied warranty of
 #endif
 
 #ifdef HAS_XDR
+#include <rpc/types.h>
 #include <rpc/xdr.h>
 #endif
 
 using namespace SauvUtilities;
-using namespace ParaMEDMEM;
-using namespace std;
+using namespace MEDCoupling;
 
 namespace
 {
@@ -100,8 +100,8 @@ namespace
     if ( const int * conn = getGibi2MedQuadraticInterlace( type ))
       {
         Cell* ma = const_cast<Cell*>(&aCell);
-        vector< Node* > new_nodes( ma->_nodes.size() );
-        for ( size_t i = 0; i < new_nodes.size(); ++i )
+        std::vector< Node* > new_nodes( ma->_nodes.size() );
+        for (std:: size_t i = 0; i < new_nodes.size(); ++i )
           new_nodes[ i ] = ma->_nodes[ conn[ i ]];
         ma->_nodes.swap( new_nodes );
       }
@@ -114,7 +114,7 @@ namespace
   //================================================================================
 
   void getReverseVector (const INTERP_KERNEL::NormalizedCellType type,
-                         vector<pair<int,int> > &                swapVec )
+                         std::vector<std::pair<int,int> > &                swapVec )
   {
     swapVec.clear();
 
@@ -122,66 +122,66 @@ namespace
       {
       case NORM_TETRA4:
         swapVec.resize(1);
-        swapVec[0] = make_pair( 1, 2 );
+        swapVec[0] = std::make_pair( 1, 2 );
         break;
       case NORM_PYRA5:
         swapVec.resize(1);
-        swapVec[0] = make_pair( 1, 3 );
+        swapVec[0] = std::make_pair( 1, 3 );
         break;
       case NORM_PENTA6:
         swapVec.resize(2);
-        swapVec[0] = make_pair( 1, 2 );
-        swapVec[1] = make_pair( 4, 5 );
+        swapVec[0] = std::make_pair( 1, 2 );
+        swapVec[1] = std::make_pair( 4, 5 );
         break;
       case NORM_HEXA8:
         swapVec.resize(2);
-        swapVec[0] = make_pair( 1, 3 );
-        swapVec[1] = make_pair( 5, 7 );
+        swapVec[0] = std::make_pair( 1, 3 );
+        swapVec[1] = std::make_pair( 5, 7 );
         break;
       case NORM_TETRA10:
         swapVec.resize(3);
-        swapVec[0] = make_pair( 1, 2 );
-        swapVec[1] = make_pair( 4, 6 );
-        swapVec[2] = make_pair( 8, 9 );
+        swapVec[0] = std::make_pair( 1, 2 );
+        swapVec[1] = std::make_pair( 4, 6 );
+        swapVec[2] = std::make_pair( 8, 9 );
         break;
       case NORM_PYRA13:
         swapVec.resize(4);
-        swapVec[0] = make_pair( 1, 3 );
-        swapVec[1] = make_pair( 5, 8 );
-        swapVec[2] = make_pair( 6, 7 );
-        swapVec[3] = make_pair( 10, 12 );
+        swapVec[0] = std::make_pair( 1, 3 );
+        swapVec[1] = std::make_pair( 5, 8 );
+        swapVec[2] = std::make_pair( 6, 7 );
+        swapVec[3] = std::make_pair( 10, 12 );
         break;
       case NORM_PENTA15:
         swapVec.resize(4);
-        swapVec[0] = make_pair( 1, 2 );
-        swapVec[1] = make_pair( 4, 5 );
-        swapVec[2] = make_pair( 6, 8 );
-        swapVec[3] = make_pair( 9, 11 );
+        swapVec[0] = std::make_pair( 1, 2 );
+        swapVec[1] = std::make_pair( 4, 5 );
+        swapVec[2] = std::make_pair( 6, 8 );
+        swapVec[3] = std::make_pair( 9, 11 );
         break;
       case NORM_HEXA20:
         swapVec.resize(7);
-        swapVec[0] = make_pair( 1, 3 );
-        swapVec[1] = make_pair( 5, 7 );
-        swapVec[2] = make_pair( 8, 11 );
-        swapVec[3] = make_pair( 9, 10 );
-        swapVec[4] = make_pair( 12, 15 );
-        swapVec[5] = make_pair( 13, 14 );
-        swapVec[6] = make_pair( 17, 19 );
+        swapVec[0] = std::make_pair( 1, 3 );
+        swapVec[1] = std::make_pair( 5, 7 );
+        swapVec[2] = std::make_pair( 8, 11 );
+        swapVec[3] = std::make_pair( 9, 10 );
+        swapVec[4] = std::make_pair( 12, 15 );
+        swapVec[5] = std::make_pair( 13, 14 );
+        swapVec[6] = std::make_pair( 17, 19 );
         break;
         //   case NORM_SEG3: no need to reverse edges
         //     swapVec.resize(1);
-        //     swapVec[0] = make_pair( 1, 2 );
+        //     swapVec[0] = std::make_pair( 1, 2 );
         //     break;
       case NORM_TRI6:
         swapVec.resize(2);
-        swapVec[0] = make_pair( 1, 2 );
-        swapVec[1] = make_pair( 3, 5 );
+        swapVec[0] = std::make_pair( 1, 2 );
+        swapVec[1] = std::make_pair( 3, 5 );
         break;
       case NORM_QUAD8:
         swapVec.resize(3);
-        swapVec[0] = make_pair( 1, 3 );
-        swapVec[1] = make_pair( 4, 7 );
-        swapVec[2] = make_pair( 5, 6 );
+        swapVec[0] = std::make_pair( 1, 3 );
+        swapVec[1] = std::make_pair( 4, 7 );
+        swapVec[2] = std::make_pair( 5, 6 );
         break;
       default:;
       }
@@ -193,7 +193,7 @@ namespace
    */
   //================================================================================
 
-  inline void reverse(const Cell & aCell, const vector<pair<int,int> > & swapVec )
+  inline void reverse(const Cell & aCell, const std::vector<std::pair<int,int> > & swapVec )
   {
     Cell* ma = const_cast<Cell*>(&aCell);
     for ( unsigned i = 0; i < swapVec.size(); ++i )
@@ -210,12 +210,12 @@ namespace
    */
   struct TCellByIDCompare
   {
-    bool operator () (const Cell* i1, const Cell* i2)
+    bool operator () (const Cell* i1, const Cell* i2) const
     {
       return i1->_number < i2->_number;
     }
   };
-  typedef map< const Cell*, unsigned, TCellByIDCompare > TCellToOrderMap;
+  typedef std::map< const Cell*, unsigned, TCellByIDCompare > TCellToOrderMap;
 
   //================================================================================
   /*!
@@ -235,11 +235,11 @@ namespace
       isRelocated = ( c2oIt->second != newOrder );
 
     if ( isRelocated )
-    {
-      grp->_relocTable.resize( cell2order.size() );
-      for ( newOrder = 0, c2oIt = cell2order.begin(); c2oIt != c2oEnd; ++c2oIt, ++newOrder )
-        grp->_relocTable[ c2oIt->second ] = newOrder;
-    }
+      {
+        grp->_relocTable.resize( cell2order.size() );
+        for ( newOrder = 0, c2oIt = cell2order.begin(); c2oIt != c2oEnd; ++c2oIt, ++newOrder )
+          grp->_relocTable[ c2oIt->second ] = newOrder;
+      }
   }
 }
 
@@ -262,7 +262,7 @@ namespace // define default GAUSS points
 
     TInt GetNbRef() const { return myNbRef; }
 
-    TCoordSlice GetCoord(TInt theRefId) { return &myRefCoord[0] + theRefId * myDim; }
+    TCoordSlice GetCoord(std::size_t theRefId) { return &myRefCoord[0] + theRefId * myDim; }
   };
   //---------------------------------------------------------------
   /*!
@@ -281,9 +281,9 @@ namespace // define default GAUSS points
      *  \param geomType - element geometry (EGeometrieElement or med_geometrie_element)
      *  \param nbPoints - nb gauss point
      *  \param variant - [1-3] to choose the variant of definition
-     * 
+     *
      * Throws in case of invalid parameters
-     * variant == 1 refers to "Fonctions de forme et points d'integration 
+     * variant == 1 refers to "Fonctions de forme et points d'integration
      *              des elements finis" v7.4 by J. PELLET, X. DESROCHES, 15/09/05
      * variant == 2 refers to the same doc v6.4 by J.P. LEFEBVRE, X. DESROCHES, 03/07/03
      * variant == 3 refers to the same doc v6.4, second variant for 2D elements
@@ -291,7 +291,7 @@ namespace // define default GAUSS points
     TGaussDef(const int geomType, const int nbPoints, const int variant=1);
 
     int dim() const { return SauvUtilities::getDimension( NormalizedCellType( myType )); }
-    int nbPoints() const { return myWeights.capacity(); }
+    std::size_t nbPoints() const { return myWeights.capacity(); }
 
   private:
     void add(const double x, const double weight);
@@ -669,8 +669,8 @@ namespace // define default GAUSS points
   THexa20a::THexa20a(TInt theDim, TInt theNbRef):
     TShapeFun(theDim,theNbRef)
   {
-    TInt aNbRef = myRefCoord.size();
-    for(TInt aRefId = 0; aRefId < aNbRef; aRefId++){
+    std::size_t aNbRef = myRefCoord.size();
+    for(std::size_t aRefId = 0; aRefId < aNbRef; aRefId++){
       TCoordSlice aCoord = GetCoord(aRefId);
       switch(aRefId){
       case  0: aCoord[0] = -1.0;  aCoord[1] = -1.0;  aCoord[2] = -1.0; break;
@@ -701,8 +701,8 @@ namespace // define default GAUSS points
   THexa27a::THexa27a():
     THexa20a(3,27)
   {
-    TInt aNbRef = myRefCoord.size();
-    for(TInt aRefId = 0; aRefId < aNbRef; aRefId++){
+    std::size_t aNbRef = myRefCoord.size();
+    for(std::size_t aRefId = 0; aRefId < aNbRef; aRefId++){
       TCoordSlice aCoord = GetCoord(aRefId);
       switch(aRefId){
       case 20: aCoord[0] =  0.0;  aCoord[1] =  0.0;  aCoord[2] = -1.0; break;
@@ -738,8 +738,8 @@ namespace // define default GAUSS points
   THexa20b::THexa20b(TInt theDim, TInt theNbRef):
     TShapeFun(theDim,theNbRef)
   {
-    TInt aNbRef = myRefCoord.size();
-    for(TInt aRefId = 0; aRefId < aNbRef; aRefId++){
+    std::size_t aNbRef = myRefCoord.size();
+    for(std::size_t aRefId = 0; aRefId < aNbRef; aRefId++){
       TCoordSlice aCoord = GetCoord(aRefId);
       switch(aRefId){
       case  0: aCoord[0] = -1.0;  aCoord[1] = -1.0;  aCoord[2] = -1.0; break;
@@ -770,8 +770,8 @@ namespace // define default GAUSS points
   TPenta6a::TPenta6a():
     TShapeFun(3,6)
   {
-    TInt aNbRef = myRefCoord.size();
-    for(TInt aRefId = 0; aRefId < aNbRef; aRefId++){
+    std::size_t aNbRef = myRefCoord.size();
+    for(std::size_t aRefId = 0; aRefId < aNbRef; aRefId++){
       TCoordSlice aCoord = GetCoord(aRefId);
       switch(aRefId){
       case  0: aCoord[0] = -1.0;  aCoord[1] =  1.0;  aCoord[2] =  0.0; break;
@@ -787,8 +787,8 @@ namespace // define default GAUSS points
   TPenta6b::TPenta6b():
     TShapeFun(3,6)
   {
-    TInt aNbRef = myRefCoord.size();
-    for(TInt aRefId = 0; aRefId < aNbRef; aRefId++){
+    std::size_t aNbRef = myRefCoord.size();
+    for(std::size_t aRefId = 0; aRefId < aNbRef; aRefId++){
       TCoordSlice aCoord = GetCoord(aRefId);
       switch(aRefId){
       case  0: aCoord[0] = -1.0;  aCoord[1] =  1.0;  aCoord[2] =  0.0; break;
@@ -804,8 +804,8 @@ namespace // define default GAUSS points
   TPenta15a::TPenta15a():
     TShapeFun(3,15)
   {
-    TInt aNbRef = myRefCoord.size();
-    for(TInt aRefId = 0; aRefId < aNbRef; aRefId++){
+    std::size_t aNbRef = myRefCoord.size();
+    for(std::size_t aRefId = 0; aRefId < aNbRef; aRefId++){
       TCoordSlice aCoord = GetCoord(aRefId);
       switch(aRefId){
       case  0: aCoord[0] = -1.0;  aCoord[1] =  1.0;  aCoord[2] =  0.0; break;
@@ -831,8 +831,8 @@ namespace // define default GAUSS points
   TPenta15b::TPenta15b():
     TShapeFun(3,15)
   {
-    TInt aNbRef = myRefCoord.size();
-    for(TInt aRefId = 0; aRefId < aNbRef; aRefId++){
+    std::size_t aNbRef = myRefCoord.size();
+    for(std::size_t aRefId = 0; aRefId < aNbRef; aRefId++){
       TCoordSlice aCoord = GetCoord(aRefId);
       switch(aRefId){
       case  0: aCoord[0] = -1.0;  aCoord[1] =  1.0;  aCoord[2] =  0.0; break;
@@ -858,8 +858,8 @@ namespace // define default GAUSS points
   TPyra5a::TPyra5a():
     TShapeFun(3,5)
   {
-    TInt aNbRef = myRefCoord.size();
-    for(TInt aRefId = 0; aRefId < aNbRef; aRefId++){
+    std::size_t aNbRef = myRefCoord.size();
+    for(std::size_t aRefId = 0; aRefId < aNbRef; aRefId++){
       TCoordSlice aCoord = GetCoord(aRefId);
       switch(aRefId){
       case  0: aCoord[0] =  1.0;  aCoord[1] =  0.0;  aCoord[2] =  0.0; break;
@@ -874,10 +874,10 @@ namespace // define default GAUSS points
   TPyra5b::TPyra5b():
     TShapeFun(3,5)
   {
-    TInt aNbRef = myRefCoord.size();
-    for(TInt aRefId = 0; aRefId < aNbRef; aRefId++){
+    std::size_t aNbRef = myRefCoord.size();
+    for(std::size_t aRefId = 0; aRefId < aNbRef; aRefId++){
       TCoordSlice aCoord = GetCoord(aRefId);
-      switch(aRefId){        
+      switch(aRefId){
       case  0: aCoord[0] =  1.0;  aCoord[1] =  0.0;  aCoord[2] =  0.0; break;
       case  3: aCoord[0] =  0.0;  aCoord[1] =  1.0;  aCoord[2] =  0.0; break;
       case  2: aCoord[0] = -1.0;  aCoord[1] =  0.0;  aCoord[2] =  0.0; break;
@@ -890,8 +890,8 @@ namespace // define default GAUSS points
   TPyra13a::TPyra13a():
     TShapeFun(3,13)
   {
-    TInt aNbRef = myRefCoord.size();
-    for(TInt aRefId = 0; aRefId < aNbRef; aRefId++){
+    std::size_t aNbRef = myRefCoord.size();
+    for(std::size_t aRefId = 0; aRefId < aNbRef; aRefId++){
       TCoordSlice aCoord = GetCoord(aRefId);
       switch(aRefId){
       case  0: aCoord[0] =  1.0;  aCoord[1] =  0.0;  aCoord[2] =  0.0; break;
@@ -915,8 +915,8 @@ namespace // define default GAUSS points
   TPyra13b::TPyra13b():
     TShapeFun(3,13)
   {
-    TInt aNbRef = myRefCoord.size();
-    for(TInt aRefId = 0; aRefId < aNbRef; aRefId++){
+    std::size_t aNbRef = myRefCoord.size();
+    for(std::size_t aRefId = 0; aRefId < aNbRef; aRefId++){
       TCoordSlice aCoord = GetCoord(aRefId);
       switch(aRefId){
       case  0: aCoord[0] =  1.0;  aCoord[1] =  0.0;  aCoord[2] =  0.0; break;
@@ -966,7 +966,7 @@ namespace // define default GAUSS points
         const double P1 = 1./1.8;
         const double P2 = 1./1.125;
         add( -a,  P1 );
-        add(  0,  P2 ); 
+        add(  0,  P2 );
         add(  a,  P1 ); break;
       }
       case 4: {
@@ -974,7 +974,7 @@ namespace // define default GAUSS points
         const double P1 = 0.652145154862546, P2 = 0.347854845137454 ;
         add(  a,  P1 );
         add( -a,  P1 );
-        add(  b,  P2 ); 
+        add(  b,  P2 );
         add( -b,  P2 ); break;
       }
       default:
@@ -1006,11 +1006,11 @@ namespace // define default GAUSS points
         case 6: { // FPG6
           const double P1 = 0.11169079483905, P2 = 0.0549758718227661;
           const double a  = 0.445948490915965, b = 0.091576213509771;
-          add(     b,     b, P2 ); 
+          add(     b,     b, P2 );
           add( 1-2*b,     b, P2 );
           add(     b, 1-2*b, P2 );
           add(     a, 1-2*a, P1 );
-          add(     a,     a, P1 ); 
+          add(     a,     a, P1 );
           add( 1-2*a,     a, P1 ); break;
         }
         case 7: { // FPG7
@@ -1018,11 +1018,11 @@ namespace // define default GAUSS points
           const double B  = 0.101286507323456;
           const double P1 = 0.066197076394253;
           const double P2 = 0.062969590272413;
-          add(  1/3.,  1/3., 9/80. ); 
-          add(     A,     A, P1 ); 
+          add(  1/3.,  1/3., 9/80. );
+          add(     A,     A, P1 );
           add( 1-2*A,     A, P1 );
           add(     A, 1-2*A, P1 );
-          add(     B,     B, P2 ); 
+          add(     B,     B, P2 );
           add( 1-2*B,     B, P2 );
           add(     B, 1-2*B, P2 ); break;
         }
@@ -1034,10 +1034,10 @@ namespace // define default GAUSS points
           const double P1 = 0.025422453185103;
           const double P2 = 0.058393137863189;
           const double P3 = 0.041425537809187;
-          add(     A,     A, P1 ); 
+          add(     A,     A, P1 );
           add( 1-2*A,     A, P1 );
           add(     A, 1-2*A, P1 );
-          add(     B,     B, P2 ); 
+          add(     B,     B, P2 );
           add( 1-2*B,     B, P2 );
           add(     B, 1-2*B, P2 );
           add(     C,     D, P3 );
@@ -1049,7 +1049,7 @@ namespace // define default GAUSS points
         }
         default:
           THROW_IK_EXCEPTION("TGaussDef: Invalid nb of gauss points for TRIA, variant 1: "
-                     <<nbGauss);
+                             <<nbGauss);
         }
       }
       else if ( variant == 2 ) {
@@ -1067,16 +1067,16 @@ namespace // define default GAUSS points
         case 6: {
           const double P1 = 0.11169079483905, P2 = 0.0549758718227661;
           const double A  = 0.445948490915965, B = 0.091576213509771;
-          add( 2*B-1, 1-4*B, 4*P2 ); 
+          add( 2*B-1, 1-4*B, 4*P2 );
           add( 2*B-1, 2*B-1, 4*P2 );
           add( 1-4*B, 2*B-1, 4*P2 );
           add( 1-4*A, 2*A-1, 4*P1 );
-          add( 2*A-1, 1-4*A, 4*P1 ); 
+          add( 2*A-1, 1-4*A, 4*P1 );
           add( 2*A-1, 2*A-1, 4*P1 ); break;
         }
         default:
           THROW_IK_EXCEPTION("TGaussDef: Invalid nb of gauss points for TRIA, variant 2: "
-                     <<nbGauss);
+                             <<nbGauss);
         }
       }
       else if ( variant == 3 ) {
@@ -1091,7 +1091,7 @@ namespace // define default GAUSS points
         }
         default:
           THROW_IK_EXCEPTION("TGaussDef: Invalid nb of gauss points for TRIA, variant 3: "
-                     <<nbGauss);
+                             <<nbGauss);
         }
       }
       break;
@@ -1134,7 +1134,7 @@ namespace // define default GAUSS points
         }
         default:
           THROW_IK_EXCEPTION("TGaussDef: Invalid nb of gauss points for QUAD, variant 1: "
-                     <<nbGauss);
+                             <<nbGauss);
         }
       }
       else if ( variant == 2 ) {
@@ -1162,7 +1162,7 @@ namespace // define default GAUSS points
         }
         default:
           THROW_IK_EXCEPTION("TGaussDef: Invalid nb of gauss points for QUAD, variant 1: "
-                     <<nbGauss);
+                             <<nbGauss);
         }
       }
       else if ( variant == 3 ) {
@@ -1191,7 +1191,7 @@ namespace // define default GAUSS points
         }
         default:
           THROW_IK_EXCEPTION("TGaussDef: Invalid nb of gauss points for QUAD, variant 3: "
-                     <<nbGauss);
+                             <<nbGauss);
         }
       }
       break;
@@ -1274,12 +1274,12 @@ namespace // define default GAUSS points
         add( 0., 0.,  h3,  p3 ); break;
       }
       case 27: { // FPG27
-        const double a1  = 0.788073483; 
-        const double b6  = 0.499369002; 
-        const double b1  = 0.848418011; 
-        const double c8  = 0.478508449; 
-        const double c1  = 0.652816472; 
-        const double d12 = 0.032303742; 
+        const double a1  = 0.788073483;
+        const double b6  = 0.499369002;
+        const double b1  = 0.848418011;
+        const double c8  = 0.478508449;
+        const double c1  = 0.652816472;
+        const double d12 = 0.032303742;
         const double d1  = 1.106412899;
         double z = 1/2., fz = b1/2*(1 - z);
         add(  0.,  0.,   z,  a1 ); // 1
@@ -1443,7 +1443,7 @@ namespace // define default GAUSS points
       THROW_IK_EXCEPTION("TGaussDef: Not all gauss points defined");
   }
 }
-  
+
 //================================================================================
 /*!
  * \brief Return dimension for the given cell type
@@ -1464,7 +1464,7 @@ unsigned SauvUtilities::getDimension( INTERP_KERNEL::NormalizedCellType type )
 
 const int * SauvUtilities::getGibi2MedQuadraticInterlace( INTERP_KERNEL::NormalizedCellType type )
 {
-  static vector<const int*> conn;
+  static std::vector<const int*> conn;
   static const int hexa20 [] = {0,6,4,2, 12,18,16,14, 7,5,3,1, 19,17,15,13, 8,11,10,9};
   static const int penta15[] = {0,2,4, 9,11,13, 1,3,5, 10,12,14, 6,8,7};
   static const int pyra13 [] = {0,2,4,6, 12, 1,3,5,7, 8,9,10,11};
@@ -1473,16 +1473,16 @@ const int * SauvUtilities::getGibi2MedQuadraticInterlace( INTERP_KERNEL::Normali
   static const int tria6  [] = {0,2,4, 1,3,5};
   static const int seg3   [] = {0,2,1};
   if ( conn.empty() )
-  {
-    conn.resize( MaxMedCellType + 1, 0 );
-    conn[ NORM_HEXA20 ] = hexa20;
-    conn[ NORM_PENTA15] = penta15;
-    conn[ NORM_PYRA13 ] = pyra13;
-    conn[ NORM_TETRA10] = tetra10;
-    conn[ NORM_SEG3   ] = seg3;
-    conn[ NORM_TRI6   ] = tria6;
-    conn[ NORM_QUAD8  ] = quad8;
-  }
+    {
+      conn.resize( MaxMedCellType + 1, 0 );
+      conn[ NORM_HEXA20 ] = hexa20;
+      conn[ NORM_PENTA15] = penta15;
+      conn[ NORM_PYRA13 ] = pyra13;
+      conn[ NORM_TETRA10] = tetra10;
+      conn[ NORM_SEG3   ] = seg3;
+      conn[ NORM_TRI6   ] = tria6;
+      conn[ NORM_QUAD8  ] = quad8;
+    }
   return conn[ type ];
 }
 
@@ -1497,7 +1497,7 @@ Cell::Cell(const Cell& ma)
 {
   if ( ma._sortedNodeIDs )
     {
-      _sortedNodeIDs = new int[ _nodes.size() ];
+      _sortedNodeIDs = new TID[ _nodes.size() ];
       std::copy( ma._sortedNodeIDs, ma._sortedNodeIDs + _nodes.size(), _sortedNodeIDs );
     }
 }
@@ -1510,11 +1510,11 @@ Cell::Cell(const Cell& ma)
 
 SauvUtilities::Link Cell::link(int i) const
 {
-  int i2 = ( i + 1 ) % _nodes.size();
+  std::size_t i2 = ( i + 1 ) % _nodes.size();
   if ( _reverse )
-    return make_pair( _nodes[i2]->_number, _nodes[i]->_number );
+    return std::make_pair( _nodes[i2]->_number, _nodes[i]->_number );
   else
-    return make_pair( _nodes[i]->_number, _nodes[i2]->_number );
+    return std::make_pair( _nodes[i]->_number, _nodes[i2]->_number );
 }
 
 //================================================================================
@@ -1526,14 +1526,14 @@ SauvUtilities::Link Cell::link(int i) const
 const TID* Cell::getSortedNodes() const
 {
   if ( !_sortedNodeIDs )
-  {
-    size_t l=_nodes.size();
-    _sortedNodeIDs = new int[ l ];
+    {
+      size_t l=_nodes.size();
+      _sortedNodeIDs = new TID[ l ];
 
-    for (size_t i=0; i!=l; ++i)
-      _sortedNodeIDs[i]=_nodes[i]->_number;
-    std::sort( _sortedNodeIDs, _sortedNodeIDs + l );
-  }
+      for (size_t i=0; i!=l; ++i)
+        _sortedNodeIDs[i]=_nodes[i]->_number;
+      std::sort( _sortedNodeIDs, _sortedNodeIDs + l );
+    }
   return _sortedNodeIDs;
 }
 
@@ -1548,9 +1548,9 @@ bool Cell::operator< (const Cell& ma) const
   if ( _nodes.size() == 1 )
     return _nodes[0] < ma._nodes[0];
 
-  const int* v1 = getSortedNodes();
-  const int* v2 = ma.getSortedNodes();
-  for ( const int* vEnd = v1 + _nodes.size(); v1 < vEnd; ++v1, ++v2 )
+  const TID* v1 = getSortedNodes();
+  const TID* v2 = ma.getSortedNodes();
+  for ( const TID* vEnd = v1 + _nodes.size(); v1 < vEnd; ++v1, ++v2 )
     if(*v1 != *v2)
       return *v1 < *v2;
   return false;
@@ -1588,9 +1588,9 @@ std::ostream& SauvUtilities::operator<< (std::ostream& os, const SauvUtilities::
  */
 //================================================================================
 
-int Group::size() const
+mcIdType Group::size() const
 {
-  int sizze = 0;
+  std::size_t sizze = 0;
   if ( !_relocTable.empty() )
     sizze =  _relocTable.size();
   else if ( _medGroup )
@@ -1600,7 +1600,7 @@ int Group::size() const
   else
     for ( size_t i = 0; i < _groups.size(); ++i )
       sizze += _groups[i]->size();
-  return sizze;
+  return ToIdType( sizze );
 }
 
 //================================================================================
@@ -1739,13 +1739,13 @@ bool ASCIIReader::getLine(char* & line)
   bool aResult = true;
   // Check the state of the buffer;
   // if there is too little left, read the next portion of data
-  int nBytesRest = _eptr - _ptr;
+  std::size_t nBytesRest = _eptr - _ptr;
   if (nBytesRest < GIBI_MaxOutputLen)
     {
       if (nBytesRest > 0)
         {
           // move the remaining portion to the buffer beginning
-          for ( int i = 0; i < nBytesRest; ++i )
+          for ( std::size_t i = 0; i < nBytesRest; ++i )
             _start[i] = _ptr[i];
           //memcpy (_tmpBuf, _ptr, nBytesRest);
           //memcpy (_start, _tmpBuf, nBytesRest);
@@ -1755,9 +1755,9 @@ bool ASCIIReader::getLine(char* & line)
           nBytesRest = 0;
         }
       _ptr = _start;
-      const int nBytesRead = ::read (_file,
-                                     &_start [nBytesRest],
-                                     GIBI_BufferSize - nBytesRest);
+      const std::size_t nBytesRead = ::read (_file,
+                                             &_start [nBytesRest],
+                                             GIBI_BufferSize - nBytesRest);
       nBytesRest += nBytesRead;
       _eptr = &_start [nBytesRest];
     }
@@ -1819,7 +1819,6 @@ void ASCIIReader::init( int nbToRead, int nbPosInLine, int width, int shift /*=
     {
       _curPos = 0;
     }
-  _curLocale.clear();
 }
 
 //================================================================================
@@ -1852,11 +1851,7 @@ void ASCIIReader::initIntReading(int nbValues)
 
 void ASCIIReader::initDoubleReading(int nbValues)
 {
-  init( nbValues, 3, 22 );
-
-  // Correction 2 of getDouble(): set "C" numeric locale to read numbers
-  // with dot decimal point separator, as it is in SAUVE files
-  _curLocale = setlocale(LC_NUMERIC, "C");
+  init( nbValues, 3, 22 ); 
 }
 
 //================================================================================
@@ -1903,11 +1898,6 @@ void ASCIIReader::next()
   else
     {
       _curPos = 0;
-      if ( !_curLocale.empty() )
-        {
-          setlocale(LC_NUMERIC, _curLocale.c_str());
-          _curLocale.clear();
-        }
     }
 }
 
@@ -1925,7 +1915,7 @@ int ASCIIReader::getInt() const
   // 53619905   |       1       2       6       8
   // 53619906   |                                                                SCALAIRE
   // 53619907   |    -63312600499       1       0       0       0      -2       0       2
-  //   where -63312600499 is actualy -633 and 12600499
+  //   where -63312600499 is actually -633 and 12600499
   char hold=_curPos[_width];
   _curPos[_width] = '\0';
   int result = atoi( _curPos );
@@ -1942,7 +1932,7 @@ int ASCIIReader::getInt() const
 
 float ASCIIReader::getFloat() const
 {
-  return getDouble();
+  return (float)getDouble();
 }
 
 //================================================================================
@@ -1972,7 +1962,7 @@ double ASCIIReader::getDouble() const
   //0123456789012345678901234567890123456789012345678901234567890123456789
   const size_t posE = 18;
   std::string aStr (_curPos);
-  if ( aStr.find('E') < 0 && aStr.find('e') < 0 )
+  if ( aStr.find('E') == std::string::npos && aStr.find('e') == std::string::npos )
     {
       if ( aStr.size() < posE+1 )
         THROW_IK_EXCEPTION("No more doubles (line #" << lineNb() << ")");
@@ -1988,12 +1978,12 @@ double ASCIIReader::getDouble() const
  */
 //================================================================================
 
-string ASCIIReader::getName() const
+std::string ASCIIReader::getName() const
 {
   int len = _width;
   while (( _curPos[len-1] == ' ' || _curPos[len-1] == 0) && len > 0 )
     len--;
-  return string( _curPos, len );
+  return std::string( _curPos, len );
 }
 
 //================================================================================
@@ -2014,7 +2004,7 @@ XDRReader::XDRReader(const char* fileName) :FileReader(fileName), _xdrs_file(NUL
 
 XDRReader::~XDRReader()
 {
-#ifdef HAS_XDR  
+#ifdef HAS_XDR
   if ( _xdrs_file )
     {
       xdr_destroy((XDR*)_xdrs);
@@ -2046,27 +2036,31 @@ bool XDRReader::open()
 {
   bool xdr_ok = false;
 #ifdef HAS_XDR
-  if ((_xdrs_file = ::fopen(_fileName.c_str(), "r")))
-    {
-      _xdrs = (XDR *)malloc(sizeof(XDR));
-      xdrstdio_create((XDR*)_xdrs, _xdrs_file, XDR_DECODE);
+#ifdef WIN32
+  if ((_xdrs_file = ::fopen(_fileName.c_str(), "rb")))
+#else
+    if ((_xdrs_file = ::fopen(_fileName.c_str(), "r")))
+#endif
+      {
+        _xdrs = (XDR *)malloc(sizeof(XDR));
+        xdrstdio_create((XDR*)_xdrs, _xdrs_file, XDR_DECODE);
 
-      const int maxsize = 10;
-      char icha[maxsize+1];
-      char* icha2 = icha;
-      if (( xdr_ok = xdr_string((XDR*)_xdrs, &icha2, maxsize)))
-        {
-          icha[maxsize] = '\0';
-          xdr_ok = (strcmp(icha, "CASTEM XDR") == 0);
-        }
-      if ( !xdr_ok )
-        {
-          xdr_destroy((XDR*)_xdrs);
-          free((XDR*)_xdrs);
-          fclose(_xdrs_file);
-          _xdrs_file = NULL;
-        }
-    }
+        const int maxsize = 10;
+        char icha[maxsize+1];
+        char* icha2 = icha;
+        if (( xdr_ok = xdr_string((XDR*)_xdrs, &icha2, maxsize)))
+          {
+            icha[maxsize] = '\0';
+            xdr_ok = (strcmp(icha, "CASTEM XDR") == 0);
+          }
+        if ( !xdr_ok )
+          {
+            xdr_destroy((XDR*)_xdrs);
+            free((XDR*)_xdrs);
+            fclose(_xdrs_file);
+            _xdrs_file = NULL;
+          }
+      }
 #endif
   return xdr_ok;
 }
@@ -2094,8 +2088,8 @@ void XDRReader::init( int nbToRead, int width/*=0*/ )
 {
   if(_iRead < _nbToRead)
     {
-      cout << "_iRead, _nbToRead : " << _iRead << " " << _nbToRead << endl;
-      cout << "Unfinished iteration before new one !" << endl;
+      std::cout << "_iRead, _nbToRead : " << _iRead << " " << _nbToRead << std::endl;
+      std::cout << "Unfinished iteration before new one !" << std::endl;
       THROW_IK_EXCEPTION("SauvUtilities::XDRReader::init(): Unfinished iteration before new one !");
     }
   _iRead    = 0;
@@ -2272,7 +2266,7 @@ std::string XDRReader::getName() const
   char* s = _xdr_cvals + _iRead*_width;
   while (( s[len-1] == ' ' || s[len-1] == 0) && len > 0 )
     len--;
-  return string( s, len );
+  return std::string( s, len );
 }
 
 //================================================================================
@@ -2301,17 +2295,85 @@ void IntermediateMED::checkDataAvailability() const
 
 //================================================================================
 /*!
- * \brief Makes ParaMEDMEM::MEDFileData from self
+ * \brief Safely adds a new Group
+ */
+//================================================================================
+
+Group* IntermediateMED::addNewGroup(std::vector<SauvUtilities::Group*>* groupsToFix)
+{
+  if ( _groups.size() == _groups.capacity() ) // re-allocation would occur
+    {
+      std::vector<Group> newGroups( _groups.size() );
+      newGroups.push_back( Group() );
+
+      for ( size_t i = 0; i < _groups.size(); ++i )
+        {
+          // avoid copying _cells
+          std::vector<const Cell*> cells;
+          cells.swap( _groups[i]._cells );
+          newGroups[i] = _groups[i];
+          newGroups[i]._cells.swap( cells );
+
+          // correct pointers to sub-groups
+          for ( size_t j = 0; j < _groups[i]._groups.size(); ++j )
+            {
+              std::size_t iG = _groups[i]._groups[j] - &_groups[0];
+              newGroups[i]._groups[j] = & newGroups[ iG ];
+            }
+        }
+
+      // fix given groups
+      if ( groupsToFix )
+        for ( size_t i = 0; i < groupsToFix->size(); ++i )
+          if ( (*groupsToFix)[i] )
+            {
+              std::size_t iG = (*groupsToFix)[i] - &_groups[0];
+              (*groupsToFix)[i] = & newGroups[ iG ];
+            }
+
+      // fix field supports
+      for ( int isNode = 0; isNode < 2; ++isNode )
+        {
+          std::vector<DoubleField* >& fields = isNode ? _nodeFields : _cellFields;
+          for ( size_t i = 0; i < fields.size(); ++i )
+            {
+              if ( !fields[i] ) continue;
+              for ( size_t j = 0; j < fields[i]->_sub.size(); ++j )
+                if ( fields[i]->_sub[j]._support )
+                  {
+                    std::size_t iG = fields[i]->_sub[j]._support - &_groups[0];
+                    fields[i]->_sub[j]._support = & newGroups[ iG ];
+                  }
+              if ( fields[i]->_group )
+                {
+                  std::size_t iG = fields[i]->_group - &_groups[0];
+                  fields[i]->_group = & newGroups[ iG ];
+                }
+            }
+        }
+
+      _groups.swap( newGroups );
+    }
+  else
+    {
+      _groups.push_back( Group() );
+    }
+  return &_groups.back();
+}
+
+//================================================================================
+/*!
+ * \brief Makes MEDCoupling::MEDFileData from self
  */
 //================================================================================
 
-ParaMEDMEM::MEDFileData* IntermediateMED::convertInMEDFileDS()
+MEDCoupling::MEDFileData* IntermediateMED::convertInMEDFileDS()
 {
-  MEDCouplingAutoRefCountObjectPtr< MEDFileUMesh >  mesh   = makeMEDFileMesh();
-  MEDCouplingAutoRefCountObjectPtr< MEDFileFields > fields = makeMEDFileFields(mesh);
+  MCAuto< MEDFileUMesh >  mesh   = makeMEDFileMesh();
+  MCAuto< MEDFileFields > fields = makeMEDFileFields(mesh);
 
-  MEDCouplingAutoRefCountObjectPtr< MEDFileMeshes > meshes = MEDFileMeshes::New();
-  MEDCouplingAutoRefCountObjectPtr< MEDFileData >  medData = MEDFileData::New();
+  MCAuto< MEDFileMeshes > meshes = MEDFileMeshes::New();
+  MCAuto< MEDFileData >  medData = MEDFileData::New();
   meshes->pushMesh( mesh );
   medData->setMeshes( meshes );
   if ( fields ) medData->setFields( fields );
@@ -2321,16 +2383,18 @@ ParaMEDMEM::MEDFileData* IntermediateMED::convertInMEDFileDS()
 
 //================================================================================
 /*!
- * \brief Creates ParaMEDMEM::MEDFileUMesh from its data
+ * \brief Creates MEDCoupling::MEDFileUMesh from its data
  */
 //================================================================================
 
-ParaMEDMEM::MEDFileUMesh* IntermediateMED::makeMEDFileMesh()
+MEDCoupling::MEDFileUMesh* IntermediateMED::makeMEDFileMesh()
 {
   // check if all needed piles are present
   checkDataAvailability();
 
-  // set long names
+  decreaseHierarchicalDepthOfSubgroups();
+
+  // set long names (before orienting!)
   setGroupLongNames();
 
   // fix element orientation
@@ -2340,7 +2404,6 @@ ParaMEDMEM::MEDFileUMesh* IntermediateMED::makeMEDFileMesh()
     orientElements3D();
 
   // process groups
-  decreaseHierarchicalDepthOfSubgroups();
   eraseUselessGroups();
   //detectMixDimGroups();
 
@@ -2372,12 +2435,22 @@ ParaMEDMEM::MEDFileUMesh* IntermediateMED::makeMEDFileMesh()
 
 void IntermediateMED::setGroupLongNames()
 {
+  if ( _listGIBItoMED_mail.empty() )
+    return;
+
+  // IMP 0023285: only keep the meshes named in the table MED_MAIL
+  // clear all group names
+  for ( size_t i = 0; i < _groups.size(); ++i )
+    if ( !_groups[i]._isProfile )
+      _groups[i]._name.clear();
+
+
   // IMP 0020434: mapping GIBI names to MED names
   // set med names to objects (mesh, fields, support, group or other)
 
-  set<int> treatedGroups;
+  std::set<int> treatedGroups;
 
-  list<nameGIBItoMED>::iterator itGIBItoMED = _listGIBItoMED_mail.begin();
+  std::list<nameGIBItoMED>::iterator itGIBItoMED = _listGIBItoMED_mail.begin();
   for (; itGIBItoMED != _listGIBItoMED_mail.end(); itGIBItoMED++)
     {
       if ( (int)_groups.size() < itGIBItoMED->gibi_id ) continue;
@@ -2402,6 +2475,41 @@ void IntermediateMED::setGroupLongNames()
           grp._refNames.push_back( _mapStrings[ (*itGIBItoMED).med_id ]);
         }
     }
+
+  // IMP 0023285: only keep the meshes named in the table MED_MAIL
+  // remove all cells belonging to non-named groups only
+
+  // use Cell::_reverse to mark cells to keep
+  for ( size_t i = 0; i < _groups.size(); ++i )
+    {
+      SauvUtilities::Group & grp = _groups[i];
+      if ( grp._isProfile || !grp._name.empty() )
+        {
+          for ( size_t iC = 0; iC < grp._cells.size(); ++iC )
+            grp._cells[iC]->_reverse = true;
+
+          for (size_t j = 0; j < grp._groups.size(); ++j )
+            for ( size_t iC = 0; iC < grp._groups[j]->_cells.size(); ++iC )
+              grp._groups[j]->_cells[iC]->_reverse = true;
+        }
+    }
+  // remove non-marked cells (with _reverse == false)
+  CellsByDimIterator cellsIt( *this );
+  while ( cellsIt.nextType() )
+    {
+      std::set<Cell> & cells = _cellsByType[ cellsIt.type() ];
+      std::set<Cell>::iterator cIt = cells.begin();
+      while ( cIt != cells.end() )
+        if ( cIt->_reverse )
+          {
+            cIt->_reverse = false;
+            ++cIt;
+          }
+        else
+          {
+            cells.erase( cIt++ );
+          }
+    }
 }
 
 //================================================================================
@@ -2410,9 +2518,9 @@ void IntermediateMED::setGroupLongNames()
  */
 //================================================================================
 
-void IntermediateMED::setFieldLongNames(set< string >& usedNames)
+void IntermediateMED::setFieldLongNames(std::set< std::string >& usedNames)
 {
-  list<nameGIBItoMED>::iterator itGIBItoMED = _listGIBItoMED_cham.begin();
+  std::list<nameGIBItoMED>::iterator itGIBItoMED = _listGIBItoMED_cham.begin();
   for (; itGIBItoMED != _listGIBItoMED_cham.end(); itGIBItoMED++)
     {
       if (itGIBItoMED->gibi_pile == PILE_FIELD)
@@ -2427,25 +2535,25 @@ void IntermediateMED::setFieldLongNames(set< string >& usedNames)
 
   for (itGIBItoMED =_listGIBItoMED_comp.begin(); itGIBItoMED != _listGIBItoMED_comp.end(); itGIBItoMED++)
     {
-      string medName  = _mapStrings[itGIBItoMED->med_id];
-      string gibiName = _mapStrings[itGIBItoMED->gibi_id];
+      std::string medName  = _mapStrings[itGIBItoMED->med_id];
+      std::string gibiName = _mapStrings[itGIBItoMED->gibi_id];
 
       bool name_found = false;
       for ( int isNodal = 0; isNodal < 2 && !name_found; ++isNodal )
         {
-          vector<DoubleField* > & fields = isNodal ? _nodeFields : _cellFields;
+          std::vector<DoubleField* > & fields = isNodal ? _nodeFields : _cellFields;
           for ( size_t ifi = 0; ifi < fields.size() && !name_found; ifi++)
             {
               if (medName.find( fields[ifi]->_name + "." ) == 0 )
                 {
-                  vector<DoubleField::_Sub_data>& aSubDs = fields[ifi]->_sub;
-                  int nbSub = aSubDs.size();
-                  for (int isu = 0; isu < nbSub; isu++)
+                  std::vector<DoubleField::_Sub_data>& aSubDs = fields[ifi]->_sub;
+                  std::size_t nbSub = aSubDs.size();
+                  for (std::size_t isu = 0; isu < nbSub; isu++)
                     for (int ico = 0; ico < aSubDs[isu].nbComponents(); ico++)
                       {
                         if (aSubDs[isu].compName(ico) == gibiName)
                           {
-                            string medNameCompo = medName.substr( fields[ifi]->_name.size() + 1 );
+                            std::string medNameCompo = medName.substr( fields[ifi]->_name.size() + 1 );
                             fields[ifi]->_sub[isu].compName(ico) = medNameCompo;
                           }
                       }
@@ -2469,28 +2577,28 @@ void IntermediateMED::setFieldLongNames(set< string >& usedNames)
 void IntermediateMED::decreaseHierarchicalDepthOfSubgroups()
 {
   for (size_t i=0; i!=_groups.size(); ++i)
-  {
-    Group& grp = _groups[i];
-    for (size_t j = 0; j < grp._groups.size(); ++j )
     {
-      Group & sub_grp = *grp._groups[j];
-      if ( !sub_grp._groups.empty() )
-      {
-        // replace j with its 1st subgroup
-        grp._groups[j] = sub_grp._groups[0];
-        // push back the rest subs
-        grp._groups.insert( grp._groups.end(), ++sub_grp._groups.begin(), sub_grp._groups.end() );
-      }
+      Group& grp = _groups[i];
+      for (size_t j = 0; j < grp._groups.size(); ++j )
+        {
+          Group & sub_grp = *grp._groups[j];
+          if ( !sub_grp._groups.empty() )
+            {
+              // replace j with its 1st subgroup
+              grp._groups[j] = sub_grp._groups[0];
+              // push back the rest subs
+              grp._groups.insert( grp._groups.end(), ++sub_grp._groups.begin(), sub_grp._groups.end() );
+            }
+        }
+      // remove empty sub-_groups
+      std::vector< Group* > newSubGroups;
+      newSubGroups.reserve( grp._groups.size() );
+      for (size_t j = 0; j < grp._groups.size(); ++j )
+        if ( !grp._groups[j]->empty() )
+          newSubGroups.push_back( grp._groups[j] );
+      if ( newSubGroups.size() < grp._groups.size() )
+        grp._groups.swap( newSubGroups );
     }
-    // remove empty sub-_groups
-    vector< Group* > newSubGroups;
-    newSubGroups.reserve( grp._groups.size() );
-    for (size_t j = 0; j < grp._groups.size(); ++j )
-      if ( !grp._groups[j]->empty() )
-        newSubGroups.push_back( grp._groups[j] );
-    if ( newSubGroups.size() < grp._groups.size() )
-      grp._groups.swap( newSubGroups );
-  }
 }
 
 //================================================================================
@@ -2512,32 +2620,32 @@ void IntermediateMED::eraseUselessGroups()
   std::set<Group*> groups2convert;
   // keep not named sub-groups of field supports
   for (size_t i=0; i!=_groups.size(); ++i)
-  {
-    Group& grp = _groups[i];
-    if ( grp._isProfile && !grp._groups.empty() )
-      groups2convert.insert( grp._groups.begin(), grp._groups.end() );
-  }
+    {
+      Group& grp = _groups[i];
+      if ( grp._isProfile && !grp._groups.empty() )
+        groups2convert.insert( grp._groups.begin(), grp._groups.end() );
+    }
 
   // keep named groups and their subgroups
   for (size_t i=0; i!=_groups.size(); ++i)
-  {
-    Group& grp = _groups[i];
-    if ( !grp._name.empty() && !grp.empty() )
     {
-      groups2convert.insert( &grp );
-      groups2convert.insert( grp._groups.begin(), grp._groups.end() );
+      Group& grp = _groups[i];
+      if ( !grp._name.empty() && !grp.empty() )
+        {
+          groups2convert.insert( &grp );
+          groups2convert.insert( grp._groups.begin(), grp._groups.end() );
+        }
     }
-  }
   // erase groups that are not in groups2convert and not _isProfile
   for (size_t i=0; i!=_groups.size(); ++i)
-  {
-    Group* grp = &_groups[i];
-    if ( !grp->_isProfile && !groups2convert.count( grp ) )
     {
-      grp->_cells.clear();
-      grp->_groups.clear();
+      Group* grp = &_groups[i];
+      if ( !grp->_isProfile && !groups2convert.count( grp ) )
+        {
+          grp->_cells.clear();
+          grp->_groups.clear();
+        }
     }
-  }
 }
 
 //================================================================================
@@ -2550,26 +2658,26 @@ void IntermediateMED::detectMixDimGroups()
 {
   //hasMixedCells = false;
   for ( size_t i=0; i < _groups.size(); ++i )
-  {
-    Group& grp = _groups[i];
-    if ( grp._groups.size() < 2 )
-      continue;
-
-    // check if sub-groups have different dimension
-    unsigned dim1 = getDim( &grp );
-    for ( size_t j = 1; j  < grp._groups.size(); ++j )
     {
-      unsigned dim2 = getDim( grp._groups[j] );
-      if ( dim1 != dim2 )
-      {
-        grp._cells.clear();
-        grp._groups.clear();
-        if ( !grp._name.empty() )
-          cout << "Erase a group with elements of different dim |" << grp._name << "|"<< endl;
-        break;
-      }
+      Group& grp = _groups[i];
+      if ( grp._groups.size() < 2 )
+        continue;
+
+      // check if sub-groups have different dimension
+      unsigned dim1 = getDim( &grp );
+      for ( size_t j = 1; j  < grp._groups.size(); ++j )
+        {
+          unsigned dim2 = getDim( grp._groups[j] );
+          if ( dim1 != dim2 )
+            {
+              grp._cells.clear();
+              grp._groups.clear();
+              if ( !grp._name.empty() )
+                std::cout << "Erase a group with elements of different dim |" << grp._name << "|"<< std::endl;
+              break;
+            }
+        }
     }
-  }
 }
 
 //================================================================================
@@ -2580,13 +2688,13 @@ void IntermediateMED::detectMixDimGroups()
 
 void IntermediateMED::orientElements2D()
 {
-  set<Cell>::const_iterator elemIt, elemEnd;
-  vector< pair<int,int> > swapVec;
+  std::set<Cell>::const_iterator elemIt, elemEnd;
+  std::vector< std::pair<int,int> > swapVec;
 
   // ------------------------------------
   // fix connectivity of quadratic edges
   // ------------------------------------
-  set<Cell>& quadEdges = _cellsByType[ INTERP_KERNEL::NORM_SEG3 ];
+  std::set<Cell>& quadEdges = _cellsByType[ INTERP_KERNEL::NORM_SEG3 ];
   if ( !quadEdges.empty() )
     {
       elemIt = quadEdges.begin(), elemEnd = quadEdges.end();
@@ -2595,7 +2703,7 @@ void IntermediateMED::orientElements2D()
     }
 
   CellsByDimIterator faceIt( *this, 2 );
-  while ( const set<Cell > * faces = faceIt.nextType() )
+  while ( const std::set<Cell > * faces = faceIt.nextType() )
     {
       TCellType cellType = faceIt.type();
       bool isQuadratic = getGibi2MedQuadraticInterlace( cellType );
@@ -2612,42 +2720,43 @@ void IntermediateMED::orientElements2D()
       // --------------------------
       // orient faces clockwise
       // --------------------------
-      int iQuad = isQuadratic ? 2 : 1;
-      for ( elemIt = faces->begin(), elemEnd = faces->end(); elemIt != elemEnd; elemIt++ )
-        {
-          // look for index of the most left node
-          int iLeft = 0, iNode, nbNodes = elemIt->_nodes.size() / iQuad;
-          double x, minX = nodeCoords( elemIt->_nodes[0] )[0];
-          for ( iNode = 1; iNode < nbNodes; ++iNode )
-            if (( x = nodeCoords( elemIt->_nodes[ iNode ])[ 0 ]) < minX )
-              minX = x, iLeft = iNode;
-
-          // indeces of the nodes neighboring the most left one
-          int iPrev = ( iLeft - 1 < 0 ) ? nbNodes - 1 : iLeft - 1;
-          int iNext = ( iLeft + 1 == nbNodes ) ? 0 : iLeft + 1;
-          // find components of prev-left and left-next vectors
-          double xP = nodeCoords( elemIt->_nodes[ iPrev ])[ 0 ];
-          double yP = nodeCoords( elemIt->_nodes[ iPrev ])[ 1 ];
-          double xN = nodeCoords( elemIt->_nodes[ iNext ])[ 0 ];
-          double yN = nodeCoords( elemIt->_nodes[ iNext ])[ 1 ];
-          double xL = nodeCoords( elemIt->_nodes[ iLeft ])[ 0 ];
-          double yL = nodeCoords( elemIt->_nodes[ iLeft ])[ 1 ];
-          double xPL = xL - xP, yPL = yL - yP; // components of prev-left vector
-          double xLN = xN - xL, yLN = yN - yL; // components of left-next vector
-          // normalise y of the vectors
-          double modPL = sqrt ( xPL * xPL + yPL * yPL );
-          double modLN = sqrt ( xLN * xLN + yLN * yLN );
-          if ( modLN > std::numeric_limits<double>::min() &&
-               modPL > std::numeric_limits<double>::min() )
-            {
-              yPL /= modPL;
-              yLN /= modLN;
-              // summary direction of neighboring links must be positive
-              bool clockwise = ( yPL + yLN > 0 );
-              if ( !clockwise )
-                reverse( *elemIt, swapVec );
-            }
-        }
+      // COMMENTED for issue 0022612 note 17739
+      // int iQuad = isQuadratic ? 2 : 1;
+      // for ( elemIt = faces->begin(), elemEnd = faces->end(); elemIt != elemEnd; elemIt++ )
+      //   {
+      //     // look for index of the most left node
+      //     int iLeft = 0, iNode, nbNodes = elemIt->_nodes.size() / iQuad;
+      //     double x, minX = nodeCoords( elemIt->_nodes[0] )[0];
+      //     for ( iNode = 1; iNode < nbNodes; ++iNode )
+      //       if (( x = nodeCoords( elemIt->_nodes[ iNode ])[ 0 ]) < minX )
+      //         minX = x, iLeft = iNode;
+
+      //     // indices of the nodes neighboring the most left one
+      //     int iPrev = ( iLeft - 1 < 0 ) ? nbNodes - 1 : iLeft - 1;
+      //     int iNext = ( iLeft + 1 == nbNodes ) ? 0 : iLeft + 1;
+      //     // find components of prev-left and left-next vectors
+      //     double xP = nodeCoords( elemIt->_nodes[ iPrev ])[ 0 ];
+      //     double yP = nodeCoords( elemIt->_nodes[ iPrev ])[ 1 ];
+      //     double xN = nodeCoords( elemIt->_nodes[ iNext ])[ 0 ];
+      //     double yN = nodeCoords( elemIt->_nodes[ iNext ])[ 1 ];
+      //     double xL = nodeCoords( elemIt->_nodes[ iLeft ])[ 0 ];
+      //     double yL = nodeCoords( elemIt->_nodes[ iLeft ])[ 1 ];
+      //     double xPL = xL - xP, yPL = yL - yP; // components of prev-left vector
+      //     double xLN = xN - xL, yLN = yN - yL; // components of left-next vector
+      //     // normalise y of the vectors
+      //     double modPL = sqrt ( xPL * xPL + yPL * yPL );
+      //     double modLN = sqrt ( xLN * xLN + yLN * yLN );
+      //     if ( modLN > std::numeric_limits<double>::min() &&
+      //          modPL > std::numeric_limits<double>::min() )
+      //       {
+      //         yPL /= modPL;
+      //         yLN /= modLN;
+      //         // summary direction of neighboring links must be positive
+      //         bool clockwise = ( yPL + yLN > 0 );
+      //         if ( !clockwise )
+      //           reverse( *elemIt, swapVec );
+      //       }
+      //   }
     }
 }
 
@@ -2660,39 +2769,41 @@ void IntermediateMED::orientElements2D()
 void IntermediateMED::orientElements3D()
 {
   // set _reverse flags of faces
-  orientFaces3D();
+  // COMMENTED for issue 0022612 note 17739
+  //orientFaces3D();
 
   // -----------------
   // fix connectivity
   // -----------------
 
-  set<Cell>::const_iterator elemIt, elemEnd;
-  vector< pair<int,int> > swapVec;
+  std::set<Cell>::const_iterator elemIt, elemEnd;
+  std::vector< std::pair<int,int> > swapVec;
 
   for ( int dim = 1; dim <= 3; ++dim )
-  {
-    CellsByDimIterator cellsIt( *this, dim );
-    while ( const set<Cell > * elems = cellsIt.nextType() )
     {
-      TCellType cellType = cellsIt.type();
-      bool isQuadratic = getGibi2MedQuadraticInterlace( cellType );
-      getReverseVector( cellType, swapVec );
+      CellsByDimIterator cellsIt( *this, dim );
+      while ( const std::set<Cell > * elems = cellsIt.nextType() )
+        {
+          TCellType cellType = cellsIt.type();
+          bool isQuadratic = getGibi2MedQuadraticInterlace( cellType );
+          getReverseVector( cellType, swapVec );
 
-      elemIt = elems->begin(), elemEnd = elems->end();
-      for ( ; elemIt != elemEnd; elemIt++ )
-      {
-        // GIBI connectivity -> MED one
-        if( isQuadratic )
-          ConvertQuadratic( cellType, *elemIt );
+          elemIt = elems->begin(), elemEnd = elems->end();
+          for ( ; elemIt != elemEnd; elemIt++ )
+            {
+              // GIBI connectivity -> MED one
+              if( isQuadratic )
+                ConvertQuadratic( cellType, *elemIt );
 
-        // reverse faces
-        if ( elemIt->_reverse )
-          reverse ( *elemIt, swapVec );
-      }
+              // reverse faces
+              if ( elemIt->_reverse )
+                reverse ( *elemIt, swapVec );
+            }
+        }
     }
-  }
 
-  orientVolumes();
+  // COMMENTED for issue 0022612 note 17739
+  //orientVolumes();
 }
 
 //================================================================================
@@ -2704,10 +2815,10 @@ void IntermediateMED::orientElements3D()
 void IntermediateMED::orientFaces3D()
 {
   // fill map of links and their faces
-  set<const Cell*> faces;
-  map<const Cell*, Group*> fgm;
-  map<Link, list<const Cell*> > linkFacesMap;
-  map<Link, list<const Cell*> >::iterator lfIt, lfIt2;
+  std::set<const Cell*> faces;
+  std::map<const Cell*, Group*> fgm;
+  std::map<Link, std::list<const Cell*> > linkFacesMap;
+  std::map<Link, std::list<const Cell*> >::iterator lfIt, lfIt2;
 
   for (size_t i=0; i!=_groups.size(); ++i)
     {
@@ -2716,24 +2827,24 @@ void IntermediateMED::orientFaces3D()
         for ( size_t j = 0; j < grp._cells.size(); ++j )
           if ( faces.insert( grp._cells[j] ).second )
             {
-              for ( size_t k = 0; k < grp._cells[j]->_nodes.size(); ++k )
+              for ( unsigned int k = 0; k < grp._cells[j]->_nodes.size(); ++k )
                 linkFacesMap[ grp._cells[j]->link( k ) ].push_back( grp._cells[j] );
-              fgm.insert( make_pair( grp._cells[j], &grp ));
+              fgm.insert( std::make_pair( grp._cells[j], &grp ));
             }
     }
   // dump linkFacesMap
   //     for ( lfIt = linkFacesMap.begin(); lfIt!=linkFacesMap.end(); lfIt++) {
-  //       cout<< "LINK: " << lfIt->first.first << "-" << lfIt->first.second << endl;
-  //       list<const Cell*> & fList = lfIt->second;
-  //       list<const Cell*>::iterator fIt = fList.begin();
+  //       cout<< "LINK: " << lfIt->first.first << "-" << lfIt->first.second << std::endl;
+  //       std::list<const Cell*> & fList = lfIt->second;
+  //       std::list<const Cell*>::iterator fIt = fList.begin();
   //       for ( ; fIt != fList.end(); fIt++ )
-  //         cout << "\t" << **fIt << fgm[*fIt]->nom << endl;
+  //         cout << "\t" << **fIt << fgm[*fIt]->nom << std::endl;
   //     }
 
   // Each oriented link must appear in one face only, else a face is reversed.
 
-  queue<const Cell*> faceQueue; /* the queue contains well oriented faces
-                                     whose neighbors orientation is to be checked */
+  std::queue<const Cell*> faceQueue; /* the queue contains well oriented faces
+                                        whose neighbors orientation is to be checked */
   bool manifold = true;
   while ( !linkFacesMap.empty() )
     {
@@ -2754,11 +2865,11 @@ void IntermediateMED::orientFaces3D()
               // find the neighbor faces
               lfIt = linkFacesMap.find( link );
               int nbFaceByLink = 0;
-              list< const Cell* > ml;
+              std::list< const Cell* > ml;
               if ( lfIt != linkFacesMap.end() )
                 {
-                  list<const Cell*> & fList = lfIt->second;
-                  list<const Cell*>::iterator fIt = fList.begin();
+                  std::list<const Cell*> & fList = lfIt->second;
+                  std::list<const Cell*>::iterator fIt = fList.begin();
                   assert( fIt != fList.end() );
                   for ( ; fIt != fList.end(); fIt++, nbFaceByLink++ )
                     {
@@ -2774,8 +2885,8 @@ void IntermediateMED::orientFaces3D()
                               lfIt2 = linkFacesMap.find( badlink );
                               if ( lfIt2 != linkFacesMap.end() )
                                 {
-                                  list<const Cell*> & ff = lfIt2->second;
-                                  list<const Cell*>::iterator lfIt3 = find( ff.begin(), ff.end(), badFace );
+                                  std::list<const Cell*> & ff = lfIt2->second;
+                                  std::list<const Cell*>::iterator lfIt3 = find( ff.begin(), ff.end(), badFace );
                                   // check if badFace has been found,
                                   // else we can't erase it
                                   // case of degenerated face in edge
@@ -2799,8 +2910,8 @@ void IntermediateMED::orientFaces3D()
               lfIt = linkFacesMap.find( revLink );
               if ( lfIt != linkFacesMap.end() )
                 {
-                  list<const Cell*> & fList = lfIt->second;
-                  list<const Cell*>::iterator fIt = fList.begin();
+                  std::list<const Cell*> & fList = lfIt->second;
+                  std::list<const Cell*>::iterator fIt = fList.begin();
                   for ( ; fIt != fList.end(); fIt++, nbFaceByLink++ )
                     {
                       ml.push_back( *fIt );
@@ -2813,10 +2924,10 @@ void IntermediateMED::orientFaces3D()
                 {
                   if ( manifold )
                     {
-                      list<const Cell*>::iterator ii = ml.begin();
-                      cout << nbFaceByLink << " faces by 1 link:" << endl;
+                      std::list<const Cell*>::iterator ii = ml.begin();
+                      std::cout << nbFaceByLink << " faces by 1 link:" << std::endl;
                       for( ; ii!= ml.end(); ii++ )
-                        cout << "in sub-mesh <" << fgm[ *ii ]->_name << "> " << **ii << endl;
+                        std::cout << "in sub-mesh <" << fgm[ *ii ]->_name << "> " << **ii << std::endl;
                     }
                   manifold = false;
                 }
@@ -2825,7 +2936,7 @@ void IntermediateMED::orientFaces3D()
     } // while ( !linkFacesMap.empty() )
 
   if ( !manifold )
-    cout << " -> Non manifold mesh, faces orientation may be incorrect" << endl;
+    std::cout << " -> Non manifold mesh, faces orientation may be incorrect" << std::endl;
 }
 
 //================================================================================
@@ -2837,11 +2948,11 @@ void IntermediateMED::orientFaces3D()
 
 void IntermediateMED::orientVolumes()
 {
-  set<Cell>::const_iterator elemIt, elemEnd;
-  vector< pair<int,int> > swapVec;
+  std::set<Cell>::const_iterator elemIt, elemEnd;
+  std::vector< std::pair<int,int> > swapVec;
 
   CellsByDimIterator cellsIt( *this, 3 );
-  while ( const set<Cell > * elems = cellsIt.nextType() )
+  while ( const std::set<Cell > * elems = cellsIt.nextType() )
     {
       TCellType cellType = cellsIt.type();
       elemIt = elems->begin(), elemEnd = elems->end();
@@ -2890,7 +3001,7 @@ void IntermediateMED::orientVolumes()
               vec03[0] = n3[0] - n[0][0];
               vec03[1] = n3[1] - n[0][1];
               vec03[2] = n3[2] - n[0][2];
-              if ( fabs( normal[0]+normal[1]+normal[2] ) <= numeric_limits<double>::max() ) // vec01 || vec02
+              if ( fabs( normal[0]+normal[1]+normal[2] ) <= std::numeric_limits<double>::max() ) // vec01 || vec02
                 {
                   normal[0] = vec01[1] * vec03[2] - vec01[2] * vec03[1]; // vec01 ^ vec03
                   normal[1] = vec01[2] * vec03[0] - vec01[0] * vec03[2];
@@ -2952,11 +3063,11 @@ int NodeContainer::numberNodes()
 
 void IntermediateMED::numberElements()
 {
-  set<Cell>::const_iterator elemIt, elemEnd;
+  std::set<Cell>::const_iterator elemIt, elemEnd;
 
   // numbering _cells of type NORM_POINT1 by node number
   {
-    const set<Cell>& points = _cellsByType[ INTERP_KERNEL::NORM_POINT1 ];
+    const std::set<Cell>& points = _cellsByType[ INTERP_KERNEL::NORM_POINT1 ];
     elemIt = points.begin(), elemEnd = points.end();
     for ( ; elemIt != elemEnd; ++elemIt )
       elemIt->_number = elemIt->_nodes[0]->_number;
@@ -2968,8 +3079,8 @@ void IntermediateMED::numberElements()
       // check if re-numeration is needed (to try to keep elem oreder as in sauve file )
       bool ok = true, renumEntity = false;
       CellsByDimIterator cellsIt( *this, dim );
-      int prevNbElems = 0;
-      while ( const set<Cell> * typeCells = cellsIt.nextType() )
+      mcIdType prevNbElems = 0;
+      while ( const std::set<Cell> * typeCells = cellsIt.nextType() )
         {
           TID minNumber = std::numeric_limits<TID>::max(), maxNumber = 0;
           for ( elemIt = typeCells->begin(), elemEnd = typeCells->end(); elemIt!=elemEnd; ++elemIt)
@@ -2977,34 +3088,33 @@ void IntermediateMED::numberElements()
               if ( elemIt->_number < minNumber ) minNumber = elemIt->_number;
               if ( elemIt->_number > maxNumber ) maxNumber = elemIt->_number;
             }
-          TID typeSize = typeCells->size();
+          mcIdType typeSize = ToIdType( typeCells->size() );
           if ( typeSize != maxNumber - minNumber + 1 )
             ok = false;
-          if ( prevNbElems != 0 ) {
-            if ( minNumber == 1 )
-              renumEntity = true;
-            else if ( prevNbElems+1 != (int)minNumber )
-              ok = false;
-          }
+          if ( prevNbElems+1 != (int)minNumber )
+            ok = false;
+          if ( prevNbElems != 0 && minNumber == 1 )
+            renumEntity = true;
+
           prevNbElems += typeSize;
         }
 
       if ( ok && renumEntity ) // each geom type was numerated separately
         {
           cellsIt.init( dim );
-          prevNbElems = cellsIt.nextType()->size(); // no need to renumber the first type
-          while ( const set<Cell> * typeCells = cellsIt.nextType() )
+          prevNbElems = ToIdType( cellsIt.nextType()->size()); // no need to renumber the first type
+          while ( const std::set<Cell> * typeCells = cellsIt.nextType() )
             {
               for ( elemIt = typeCells->begin(), elemEnd = typeCells->end(); elemIt!=elemEnd; ++elemIt)
                 elemIt->_number += prevNbElems;
-              prevNbElems += typeCells->size();
+              prevNbElems += ToIdType( typeCells->size() );
             }
         }
       if ( !ok )
         {
           int cellID=1;
           cellsIt.init( dim );
-          while ( const set<Cell> * typeCells = cellsIt.nextType() )
+          while ( const std::set<Cell> * typeCells = cellsIt.nextType() )
             for ( elemIt = typeCells->begin(), elemEnd = typeCells->end(); elemIt!=elemEnd; ++elemIt)
               elemIt->_number = cellID++;
         }
@@ -3017,12 +3127,12 @@ void IntermediateMED::numberElements()
  */
 //================================================================================
 
-ParaMEDMEM::DataArrayDouble * IntermediateMED::getCoords()
+MEDCoupling::DataArrayDouble * IntermediateMED::getCoords()
 {
   DataArrayDouble* coordArray = DataArrayDouble::New();
   coordArray->alloc( _nbNodes, _spaceDim );
   double * coordPrt = coordArray->getPointer();
-  for ( int i = 0, nb = _points.size(); i < nb; ++i )
+  for ( unsigned int i = 0; i < _points.size(); ++i )
     {
       Node* n = getNode( i+1 );
       if ( n->isUsed() )
@@ -3043,63 +3153,63 @@ ParaMEDMEM::DataArrayDouble * IntermediateMED::getCoords()
  */
 //================================================================================
 
-void IntermediateMED::setConnectivity( ParaMEDMEM::MEDFileUMesh*    mesh,
-                                       ParaMEDMEM::DataArrayDouble* coords )
+void IntermediateMED::setConnectivity( MEDCoupling::MEDFileUMesh*    mesh,
+                                       MEDCoupling::DataArrayDouble* coords )
 {
   int meshDim = 0;
 
   mesh->setCoords( coords );
 
-  set<Cell>::const_iterator elemIt, elemEnd;
+  std::set<Cell>::const_iterator elemIt, elemEnd;
   for ( int dim = 3; dim > 0; --dim )
-  {
-    CellsByDimIterator dimCells( *this, dim );
+    {
+      CellsByDimIterator dimCells( *this, dim );
 
-    int nbOfCells = 0;
-    while ( const std::set<Cell > * cells = dimCells.nextType() )
-      nbOfCells += cells->size();
-    if ( nbOfCells == 0 )
-      continue;
+      mcIdType nbOfCells = 0;
+      while ( const std::set<Cell > * cells = dimCells.nextType() )
+        nbOfCells += ToIdType( cells->size() );
+      if ( nbOfCells == 0 )
+        continue;
 
-    if ( !meshDim ) meshDim = dim;
+      if ( !meshDim ) meshDim = dim;
 
-    MEDCouplingUMesh* dimMesh = MEDCouplingUMesh::New();
-    dimMesh->setCoords( coords );
-    dimMesh->setMeshDimension( dim );
-    dimMesh->allocateCells( nbOfCells );
+      MEDCouplingUMesh* dimMesh = MEDCouplingUMesh::New();
+      dimMesh->setCoords( coords );
+      dimMesh->setMeshDimension( dim );
+      dimMesh->allocateCells( nbOfCells );
 
-    int prevNbCells = 0;
-    dimCells.init( dim );
-    while ( const std::set<Cell > * cells = dimCells.nextType() )
-      {
-        // fill connectivity array to take into account order of elements in the sauv file
-        const int nbCellNodes = cells->begin()->_nodes.size();
-        vector< TID > connectivity( cells->size() * nbCellNodes );
-        int * nodalConnOfCell;
-        for ( elemIt = cells->begin(), elemEnd = cells->end(); elemIt != elemEnd; ++elemIt )
-          {
-            const Cell& cell = *elemIt;
-            const int index = cell._number - 1 - prevNbCells;
-            nodalConnOfCell = &connectivity[ index * nbCellNodes ];
-            if ( cell._reverse )
-              for ( int i = nbCellNodes-1; i >= 0; --i )
-                *nodalConnOfCell++ = cell._nodes[i]->_number - 1;
-            else
-              for ( int i = 0; i < nbCellNodes; ++i )
-                *nodalConnOfCell++ = cell._nodes[i]->_number - 1;
-          }
-        prevNbCells += cells->size();
+      mcIdType prevNbCells = 0;
+      dimCells.init( dim );
+      while ( const std::set<Cell > * cells = dimCells.nextType() )
+        {
+          // fill connectivity array to take into account order of elements in the sauv file
+          const mcIdType nbCellNodes = ToIdType( cells->begin()->_nodes.size() );
+          std::vector< TID > connectivity( cells->size() * nbCellNodes );
+          TID * nodalConnOfCell;
+          for ( elemIt = cells->begin(), elemEnd = cells->end(); elemIt != elemEnd; ++elemIt )
+            {
+              const Cell& cell = *elemIt;
+              const TID index = cell._number - 1 - prevNbCells;
+              nodalConnOfCell = &connectivity[ index * nbCellNodes ];
+              if ( cell._reverse )
+                for ( mcIdType i = nbCellNodes-1; i >= 0; --i )
+                  *nodalConnOfCell++ = cell._nodes[i]->_number - 1;
+              else
+                for ( mcIdType i = 0; i < nbCellNodes; ++i )
+                  *nodalConnOfCell++ = cell._nodes[i]->_number - 1;
+            }
+          prevNbCells += ToIdType( cells->size() );
 
-        // fill dimMesh
-        TCellType cellType = dimCells.type();
-        nodalConnOfCell = &connectivity[0];
-        for ( size_t i = 0; i < cells->size(); ++i, nodalConnOfCell += nbCellNodes )
-          dimMesh->insertNextCell( cellType, nbCellNodes, nodalConnOfCell );
-      }
-    dimMesh->finishInsertingCells();
-    mesh->setMeshAtLevel( dim - meshDim, dimMesh );
-    dimMesh->decrRef();
-  }
+          // fill dimMesh
+          TCellType cellType = dimCells.type();
+          nodalConnOfCell = &connectivity[0];
+          for ( size_t i = 0; i < cells->size(); ++i, nodalConnOfCell += nbCellNodes )
+            dimMesh->insertNextCell( cellType, nbCellNodes, nodalConnOfCell );
+        }
+      dimMesh->finishInsertingCells();
+      mesh->setMeshAtLevel( dim - meshDim, dimMesh );
+      dimMesh->decrRef();
+    }
 }
 
 //================================================================================
@@ -3109,7 +3219,7 @@ void IntermediateMED::setConnectivity( ParaMEDMEM::MEDFileUMesh*    mesh,
  */
 //================================================================================
 
-void IntermediateMED::setGroups( ParaMEDMEM::MEDFileUMesh* mesh )
+void IntermediateMED::setGroups( MEDCoupling::MEDFileUMesh* mesh )
 {
   bool isMeshNameSet = false;
   const int meshDim = mesh->getMeshDimension();
@@ -3117,8 +3227,8 @@ void IntermediateMED::setGroups( ParaMEDMEM::MEDFileUMesh* mesh )
     {
       const int meshDimRelToMaxExt = ( dim == 0 ? 1 : dim - meshDim );
 
-      vector<const DataArrayInt *> medGroups;
-      vector<MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > refGroups;
+      std::vector<const DataArrayIdType *> medGroups;
+      std::vector<MCAuto<DataArrayIdType> > refGroups;
       for ( size_t i = 0; i < _groups.size(); ++i )
         {
           Group& grp = _groups[i];
@@ -3133,7 +3243,7 @@ void IntermediateMED::setGroups( ParaMEDMEM::MEDFileUMesh* mesh )
           // sort cells by ID and remember their initial order in the group
           TCellToOrderMap cell2order;
           unsigned orderInGroup = 0;
-          vector< Group* > groupVec;
+          std::vector< Group* > groupVec;
           if ( grp._groups.empty() ) groupVec.push_back( & grp );
           else                       groupVec = grp._groups;
           for ( size_t iG = 0; iG < groupVec.size(); ++iG )
@@ -3142,17 +3252,17 @@ void IntermediateMED::setGroups( ParaMEDMEM::MEDFileUMesh* mesh )
               if ( (int)getDim( aG ) != dim )
                 continue;
               for ( size_t iC = 0; iC < aG->_cells.size(); ++iC )
-                cell2order.insert( cell2order.end(), make_pair( aG->_cells[iC], orderInGroup++ ));
+                cell2order.insert( cell2order.end(), std::make_pair( aG->_cells[iC], orderInGroup++ ));
             }
           if ( cell2order.empty() )
             continue;
           bool isSelfIntersect = ( orderInGroup != cell2order.size() );
           if ( isSelfIntersect ) // self intersecting group
             {
-              ostringstream msg;
+              std::ostringstream msg;
               msg << "Self intersecting sub-mesh: id = " << i+1
-                  << ", name = |" << grp._name << "|" << endl
-                  << " nb unique elements = " << cell2order.size() << endl
+                  << ", name = |" << grp._name << "|" << std::endl
+                  << " nb unique elements = " << cell2order.size() << std::endl
                   << " total nb elements  = " << orderInGroup;
               if ( grp._isProfile )
                 {
@@ -3160,17 +3270,17 @@ void IntermediateMED::setGroups( ParaMEDMEM::MEDFileUMesh* mesh )
                 }
               else
                 {
-                  cout << msg.str() << endl;
+                  std::cout << msg.str() << std::endl;
                 }
             }
           // create a med group
-          grp._medGroup = DataArrayInt::New();
+          grp._medGroup = DataArrayIdType::New();
           grp._medGroup->setName( grp._name.c_str() );
           grp._medGroup->alloc( cell2order.size(), /*nbOfCompo=*/1 );
-          int * idsPrt = grp._medGroup->getPointer();
+          TID * idsPtr = grp._medGroup->getPointer();
           TCellToOrderMap::iterator cell2orderIt, cell2orderEnd = cell2order.end();
           for ( cell2orderIt = cell2order.begin(); cell2orderIt != cell2orderEnd; ++cell2orderIt )
-            *idsPrt++ = (*cell2orderIt).first->_number - 1;
+            *idsPtr++ = (*cell2orderIt).first->_number - 1;
 
           // try to set the mesh name
           if ( !isMeshNameSet &&
@@ -3191,10 +3301,13 @@ void IntermediateMED::setGroups( ParaMEDMEM::MEDFileUMesh* mesh )
           // Issue 0021311. Use case: a gibi group has references (recorded in pile 1)
           // and several names (pile 27) refer (pile 10) to this group.
           // We create a copy of this group per each named reference
+          std::set<std::string> uniqueNames;
+          uniqueNames.insert( grp._name );
           for ( unsigned iRef = 0 ; iRef < grp._refNames.size(); ++iRef )
-            if ( !grp._refNames[ iRef ].empty() )
+            if ( !grp._refNames[ iRef ].empty() &&
+                 uniqueNames.insert( grp._refNames[ iRef ]).second ) // for name uniqueness (23155)
               {
-                refGroups.push_back( grp._medGroup->deepCpy() );
+                refGroups.push_back( grp._medGroup->deepCopy() );
                 refGroups.back()->setName( grp._refNames[ iRef ].c_str() );
                 medGroups.push_back( refGroups.back() );
               }
@@ -3213,17 +3326,18 @@ bool IntermediateMED::isOnAll( const Group* grp, int & dimRel ) const
 {
   int dim = getDim( grp );
 
-  int nbElems = 0;
-  CellsByDimIterator dimCells( *this, dim );
-  while ( const set<Cell > * cells = dimCells.nextType() )
-    nbElems += cells->size();
-
-  const bool onAll = ( nbElems == grp->size() );
-
+  mcIdType nbElems = 0;
   if ( dim == 0 )
-    dimRel = 0;
+    {
+      nbElems = _nbNodes;
+      dimRel  = 0;
+    }
   else
     {
+      CellsByDimIterator dimCells( *this, dim );
+      while ( const std::set<Cell > * cells = dimCells.nextType() )
+        nbElems += ToIdType( cells->size() );
+
       int meshDim = 3;
       for ( ; meshDim > 0; --meshDim )
         {
@@ -3233,6 +3347,8 @@ bool IntermediateMED::isOnAll( const Group* grp, int & dimRel ) const
         }
       dimRel = dim - meshDim;
     }
+
+  bool onAll = ( nbElems == grp->size() );
   return onAll;
 }
 
@@ -3242,20 +3358,20 @@ bool IntermediateMED::isOnAll( const Group* grp, int & dimRel ) const
  */
 //================================================================================
 
-ParaMEDMEM::MEDFileFields * IntermediateMED::makeMEDFileFields(ParaMEDMEM::MEDFileUMesh* mesh)
+MEDCoupling::MEDFileFields * IntermediateMED::makeMEDFileFields(MEDCoupling::MEDFileUMesh* mesh)
 {
   if ( _nodeFields.empty() && _cellFields.empty() ) return 0;
 
   // set long names
-  set< string > usedFieldNames;
+  std::set< std::string > usedFieldNames;
   setFieldLongNames(usedFieldNames);
 
   MEDFileFields* fields = MEDFileFields::New();
 
-  for ( size_t i = 0; i < _nodeFields.size(); ++i )
+  for ( unsigned int i = 0; i < _nodeFields.size(); ++i )
     setFields( _nodeFields[i], fields, mesh, i+1, usedFieldNames );
 
-  for ( size_t i = 0; i < _cellFields.size(); ++i )
+  for ( unsigned int i = 0; i < _cellFields.size(); ++i )
     setFields( _cellFields[i], fields, mesh, i+1, usedFieldNames );
 
   return fields;
@@ -3268,10 +3384,10 @@ ParaMEDMEM::MEDFileFields * IntermediateMED::makeMEDFileFields(ParaMEDMEM::MEDFi
 //================================================================================
 
 void IntermediateMED::setFields( SauvUtilities::DoubleField* fld,
-                                 ParaMEDMEM::MEDFileFields*  medFields,
-                                 ParaMEDMEM::MEDFileUMesh*   mesh,
+                                 MEDCoupling::MEDFileFields*  medFields,
+                                 MEDCoupling::MEDFileUMesh*   mesh,
                                  const TID                   castemID,
-                                 set< string >&              usedFieldNames)
+                                 std::set< std::string >&    usedFieldNames)
 {
   bool sameNbGauss = true;
   if ( !fld || !fld->isMedCompatible( sameNbGauss )) return;
@@ -3286,10 +3402,10 @@ void IntermediateMED::setFields( SauvUtilities::DoubleField* fld,
 
   const bool uniteSubs = fld->hasCommonSupport() && sameNbGauss;
   if ( !uniteSubs )
-    cout << "Castem field #" << castemID << " <" << fld->_name
-         << "> is incompatible with MED format, so we split it into several fields:" << endl;
+    std::cout << "Castem field #" << castemID << " <" << fld->_name
+              << "> is incompatible with MED format, so we split it into several fields:" << std::endl;
 
-  for ( size_t iSub = 0; iSub < fld->_sub.size(); )
+  for ( unsigned int iSub = 0; iSub < fld->_sub.size(); )
     {
       // set field name
       if ( !uniteSubs || fld->_name.empty() )
@@ -3303,8 +3419,8 @@ void IntermediateMED::setFields( SauvUtilities::DoubleField* fld,
       double * valPtr = values->getPointer();
       if ( uniteSubs )
         {
-          int nbElems = fld->_group->size();
-          for ( int elemShift = 0; elemShift < nbElems && iSub < fld->_sub.size(); )
+          mcIdType nbElems = fld->_group->size();
+          for ( mcIdType elemShift = 0; elemShift < nbElems && iSub < fld->_sub.size(); )
             elemShift += fld->setValues( valPtr, iSub++, elemShift );
           setTS( fld, values, medFields, mesh );
         }
@@ -3313,10 +3429,10 @@ void IntermediateMED::setFields( SauvUtilities::DoubleField* fld,
           fld->setValues( valPtr, iSub );
           setTS( fld, values, medFields, mesh, iSub++ );
 
-          cout << fld->_name << " with compoments";
+          std::cout << fld->_name << " with components";
           for ( size_t i = 0; i < (size_t)fld->_sub[iSub-1].nbComponents(); ++i )
-            cout << " " << fld->_sub[iSub-1]._comp_names[ i ];
-          cout << endl;
+            std::cout << " " << fld->_sub[iSub-1]._comp_names[ i ];
+          std::cout << std::endl;
         }
     }
 }
@@ -3328,9 +3444,9 @@ void IntermediateMED::setFields( SauvUtilities::DoubleField* fld,
 //================================================================================
 
 void IntermediateMED::setTS( SauvUtilities::DoubleField*  fld,
-                             ParaMEDMEM::DataArrayDouble* values,
-                             ParaMEDMEM::MEDFileFields*   medFields,
-                             ParaMEDMEM::MEDFileUMesh*    mesh,
+                             MEDCoupling::DataArrayDouble* values,
+                             MEDCoupling::MEDFileFields*   medFields,
+                             MEDCoupling::MEDFileUMesh*    mesh,
                              const int                    iSub)
 {
   // treat a field support
@@ -3352,25 +3468,25 @@ void IntermediateMED::setTS( SauvUtilities::DoubleField*  fld,
   // set the mesh
   if ( onAll )
     {
-      MEDCouplingAutoRefCountObjectPtr
+      MCAuto
         < MEDCouplingUMesh > dimMesh = mesh->getMeshAtLevel( dimRel );
       timeStamp->setMesh( dimMesh );
     }
-  else if ( timeStamp->getTypeOfField() == ParaMEDMEM::ON_NODES )
+  else if ( timeStamp->getTypeOfField() == MEDCoupling::ON_NODES )
     {
       DataArrayDouble * coo = mesh->getCoords();
-      MEDCouplingAutoRefCountObjectPtr
+      MCAuto
         <DataArrayDouble> subCoo = coo->selectByTupleId(support->_medGroup->begin(),
-                                                        support->_medGroup->end()); 
-      MEDCouplingAutoRefCountObjectPtr< MEDCouplingUMesh > nodeSubMesh =
+                                                        support->_medGroup->end());
+      MCAuto< MEDCouplingUMesh > nodeSubMesh =
         MEDCouplingUMesh::Build0DMeshFromCoords( subCoo );
       timeStamp->setMesh( nodeSubMesh );
     }
   else
     {
-      MEDCouplingAutoRefCountObjectPtr
+      MCAuto
         < MEDCouplingUMesh > dimMesh = mesh->getMeshAtLevel( dimRel );
-      MEDCouplingAutoRefCountObjectPtr
+      MCAuto
         <MEDCouplingMesh> subMesh = dimMesh->buildPart(support->_medGroup->begin(),
                                                        support->_medGroup->end());
       timeStamp->setMesh( subMesh);
@@ -3381,10 +3497,11 @@ void IntermediateMED::setTS( SauvUtilities::DoubleField*  fld,
   timeStamp->setArray( values );
   values->decrRef();
   // set gauss points
-  if ( timeStamp->getTypeOfField() == ParaMEDMEM::ON_GAUSS_PT )
+  if ( timeStamp->getTypeOfField() == MEDCoupling::ON_GAUSS_PT )
     {
-      TGaussDef gaussDef( support->_cellType, fld->_sub[iSub].nbGauss() );
-      timeStamp->setGaussLocalizationOnType( support->_cellType,
+      TGaussDef gaussDef( fld->_sub[iSub]._support->_cellType,
+                          fld->_sub[iSub].nbGauss() );
+      timeStamp->setGaussLocalizationOnType( fld->_sub[iSub]._support->_cellType,
                                              gaussDef.myRefCoords,
                                              gaussDef.myCoords,
                                              gaussDef.myWeights );
@@ -3403,7 +3520,7 @@ void IntermediateMED::setTS( SauvUtilities::DoubleField*  fld,
     timeStamp->setOrder( nbTS );
 
   // add the time-stamp
-  timeStamp->checkCoherency();
+  timeStamp->checkConsistencyLight();
   if ( onAll )
     fld->_curMedField->appendFieldNoProfileSBT( timeStamp );
   else
@@ -3425,15 +3542,15 @@ void IntermediateMED::setTS( SauvUtilities::DoubleField*  fld,
 void IntermediateMED::makeFieldNewName(std::set< std::string >&    usedNames,
                                        SauvUtilities::DoubleField* fld )
 {
-  string base = fld->_name;
+  std::string base = fld->_name;
   if ( base.empty() )
     {
       base = "F_";
     }
   else
     {
-      string::size_type pos = base.rfind('_');
-      if ( pos != string::npos )
+      std::string::size_type pos = base.rfind('_');
+      if ( pos != std::string::npos )
         base = base.substr( 0, pos+1 );
       else
         base += '_';
@@ -3518,9 +3635,9 @@ bool DoubleField::isMultiTimeStamps() const
   if ( _sub.size() < 2 )
     return false;
   bool sameSupports = true;
-  Group* grp1 = _sub[0]._support;
+  Group* grpp1 = _sub[0]._support;// grpp NOT grp because XDR under Windows defines grp...
   for ( size_t i = 1; i < _sub.size() && sameSupports; ++i )
-    sameSupports = ( grp1 == _sub[i]._support );
+    sameSupports = ( grpp1 == _sub[i]._support );
 
   return sameSupports;
 }
@@ -3533,7 +3650,7 @@ bool DoubleField::isMultiTimeStamps() const
 
 bool DoubleField::isMedCompatible(bool& sameNbGauss) const
 {
-  for ( size_t iSub = 0; iSub < _sub.size(); ++iSub )
+  for ( unsigned int iSub = 0; iSub < _sub.size(); ++iSub )
     {
       if ( !getSupport(iSub) || !getSupport(iSub)->_medGroup )
         THROW_IK_EXCEPTION("SauvReader INTERNAL ERROR: NULL field support");
@@ -3541,7 +3658,7 @@ bool DoubleField::isMedCompatible(bool& sameNbGauss) const
       sameNbGauss = true;
       if ( !_sub[iSub].isSameNbGauss() )
         {
-          cout << "Field <" << _name << "> : different nb of gauss points in components" <<endl;
+          std::cout << "Field <" << _name << "> : different nb of gauss points in components" << std::endl;
           sameNbGauss = false;
           //return false;
         }
@@ -3557,17 +3674,17 @@ bool DoubleField::isMedCompatible(bool& sameNbGauss) const
 
 bool DoubleField::hasSameComponentsBySupport() const
 {
-  vector< _Sub_data >::const_iterator sub_data = _sub.begin();
+  std::vector< _Sub_data >::const_iterator sub_data = _sub.begin();
   const _Sub_data& first_sub_data = *sub_data;
   for ( ++sub_data ; sub_data != _sub.end(); ++sub_data )
-  {
-    if ( first_sub_data._comp_names != sub_data->_comp_names )
-      return false; // diff names of components
+    {
+      if ( first_sub_data._comp_names != sub_data->_comp_names )
+        return false; // diff names of components
 
-    if ( first_sub_data._nb_gauss != sub_data->_nb_gauss &&
-         first_sub_data._support->_cellType == sub_data->_support->_cellType)
-      return false; // diff nb of gauss points on same cell type
-  }
+      if ( first_sub_data._nb_gauss != sub_data->_nb_gauss &&
+           first_sub_data._support->_cellType == sub_data->_support->_cellType)
+        return false; // diff nb of gauss points on same cell type
+    }
   return true;
 }
 
@@ -3577,7 +3694,7 @@ bool DoubleField::hasSameComponentsBySupport() const
  */
 //================================================================================
 
-ParaMEDMEM::TypeOfField DoubleField::getMedType( const int iSub ) const
+MEDCoupling::TypeOfField DoubleField::getMedType( const int iSub ) const
 {
   using namespace INTERP_KERNEL;
 
@@ -3599,7 +3716,7 @@ ParaMEDMEM::TypeOfField DoubleField::getMedType( const int iSub ) const
  */
 //================================================================================
 
-ParaMEDMEM::TypeOfTimeDiscretization DoubleField::getMedTimeDisc() const
+MEDCoupling::TypeOfTimeDiscretization DoubleField::getMedTimeDisc() const
 {
   return ONE_TIME;
   // NO_TIME = 4,
@@ -3614,9 +3731,9 @@ ParaMEDMEM::TypeOfTimeDiscretization DoubleField::getMedTimeDisc() const
  */
 //================================================================================
 
-int DoubleField::getNbTuples( const int iSub ) const
+mcIdType DoubleField::getNbTuples( const int iSub ) const
 {
-  int nb = 0;
+  mcIdType nb = 0;
   if ( hasCommonSupport() && !_group->_groups.empty() )
     for ( size_t i = 0; i < _group->_groups.size(); ++i )
       nb += _sub[i].nbGauss() * _sub[i]._support->size();
@@ -3631,51 +3748,51 @@ int DoubleField::getNbTuples( const int iSub ) const
  */
 //================================================================================
 
-int DoubleField::setValues( double * valPtr, const int iSub, const int elemShift ) const
+mcIdType DoubleField::setValues( double * valPtr, const int iSub, const mcIdType elemShift ) const
 {
   // find values for iSub
   int iComp = 0;
   for ( int iS = 0; iS < iSub; ++iS )
     iComp += _sub[iS].nbComponents();
-  const vector< double > * compValues = &_comp_values[ iComp ];
+  const std::vector< double > * compValues = &_comp_values[ iComp ];
 
   // Set values
 
-  const vector< unsigned >& relocTable = getSupport( iSub )->_relocTable;
+  const std::vector< mcIdType >& relocTable = getSupport( iSub )->_relocTable;
 
-  const int nbElems      = _sub[iSub]._support->size();
+  const mcIdType nbElems = _sub[iSub]._support->size();
   const int nbGauss      = _sub[iSub].nbGauss();
   const int nbComponents = _sub[iSub].nbComponents();
   const int nbValsByElem = nbComponents * nbGauss;
 
   // check nb values
-  int nbVals = 0;
+  mcIdType nbVals = 0;
   for ( iComp = 0; iComp < nbComponents; ++iComp )
-    nbVals += compValues[iComp].size();
+    nbVals += ToIdType( compValues[iComp].size() );
   const bool isConstField = ( nbVals == nbComponents ); // one value per component (issue 22321)
   if ( !isConstField && nbVals != nbElems * nbValsByElem )
     THROW_IK_EXCEPTION("SauvMedConvertor.cxx: support size mismatches field size");
 
   // compute nb values in previous subs
-  int valsShift = 0;
-  for ( int iS = iSub-1, shift = elemShift; shift > 0; --iS)
+  mcIdType valsShift = 0;
+  for ( mcIdType iS = iSub-1, shift = elemShift; shift > 0; --iS)
     {
-      int nbE = _sub[iS]._support->size();
+      mcIdType nbE = _sub[iS]._support->size();
       shift -= nbE;
       valsShift += nbE * _sub[iS].nbComponents() * _sub[iS].nbGauss();
     }
 
   if ( isConstField )
-    for ( int iE = 0; iE < nbElems; ++iE )
+    for ( mcIdType iE = 0; iE < nbElems; ++iE )
       {
-        int iMed = valsShift + nbValsByElem * ( relocTable.empty() ? iE : relocTable[iE+elemShift]-elemShift );
+        mcIdType iMed = valsShift + nbValsByElem * ( relocTable.empty() ? iE : relocTable[iE+elemShift]-elemShift );
         for ( iComp = 0; iComp < nbComponents; ++iComp )
           valPtr[ iMed + iComp ] = compValues[iComp][ 0 ];
       }
   else
-    for ( int iE = 0; iE < nbElems; ++iE )
+    for ( mcIdType iE = 0; iE < nbElems; ++iE )
       {
-        int iMed = valsShift + nbValsByElem * ( relocTable.empty() ? iE : relocTable[iE+elemShift]-elemShift );
+        mcIdType iMed = valsShift + nbValsByElem * ( relocTable.empty() ? iE : relocTable[iE+elemShift]-elemShift );
         for ( iComp = 0; iComp < nbComponents; ++iComp )
           for ( int iG = 0; iG < nbGauss; ++iG )
             valPtr[ iMed + iG * nbComponents + iComp ] = compValues[iComp][ iE * nbGauss + iG ];
@@ -3716,7 +3833,7 @@ CellsByDimIterator::CellsByDimIterator( const IntermediateMED & medi, int dimm)
   init( dimm );
 }
 /*!
- * \brief Initialize iteration on cells of given dimention
+ * \brief Initialize iteration on cells of given dimension
  */
 void CellsByDimIterator::init(const int  dimm)
 {
@@ -3746,4 +3863,3 @@ int CellsByDimIterator::dim(const bool last) const
   return typp < myTypeEnd ? getDimension( TCellType( typp )) : 4;
 }
 // END CellsByDimIterator ========================================================
-