Salome HOME
Typo and whitespace fixes by Kunda
[tools/medcoupling.git] / src / MEDLoader / MEDFileMeshLL.cxx
index 2f6e05dff5ee6213696a4a258568635a522591f7..1fafaf6a62e770409cdf73482b33235fc8157afe 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2015  CEA/DEN, EDF R&D
+// Copyright (C) 2007-2016  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
@@ -23,6 +23,8 @@
 #include "MEDLoaderBase.hxx"
 #include "MEDFileSafeCaller.txx"
 #include "MEDFileMeshReadSelector.hxx"
+#include "MEDFileStructureElement.hxx"
+#include "MEDFileMeshSupport.hxx"
 
 #include "MEDCouplingUMesh.hxx"
 
@@ -42,57 +44,22 @@ const char MEDFileMeshL2::ZE_SEP_FOR_FAMILY_KILLERS[]="!/__\\!";//important star
 
 int MEDFileMeshL2::ZE_SEP2_FOR_FAMILY_KILLERS=4;
 
-MEDFileMeshL2::MEDFileMeshL2():_name(MED_NAME_SIZE),_description(MED_COMMENT_SIZE),_univ_name(MED_LNAME_SIZE),_dt_unit(MED_LNAME_SIZE)
-{
-}
-
-std::size_t MEDFileMeshL2::getHeapMemorySizeWithoutChildren() const
-{
-  return 0;
-}
-
-std::vector<const BigMemoryObject *> MEDFileMeshL2::getDirectChildrenWithNull() const
-{
-  return std::vector<const BigMemoryObject *>();
-}
-
-int MEDFileMeshL2::GetMeshIdFromName(med_idt fid, const std::string& mname, MEDCoupling::MEDCouplingMeshType& meshType, MEDCoupling::MEDCouplingAxisType& axType, int& dt, int& it, std::string& dtunit1)
+std::vector<std::string> MeshCls::getAxisInfoOnMesh(med_idt fid, const std::string& mName, MEDCoupling::MEDCouplingMeshType& meshType, MEDCoupling::MEDCouplingAxisType& axType, int& nstep, int& Mdim, MEDFileString& description, MEDFileString& dtunit, MEDFileString& univName) const
 {
   med_mesh_type type_maillage;
-  char maillage_description[MED_COMMENT_SIZE+1];
-  char dtunit[MED_LNAME_SIZE+1];
-  med_int spaceDim,dim;
-  char nommaa[MED_NAME_SIZE+1];
-  med_int n=MEDnMesh(fid);
-  bool found=false;
-  int ret=-1;
+  med_int spaceDim;
   med_sorting_type stype;
-  std::vector<std::string> ms;
-  int nstep;
   med_axis_type axistype;
-  for(int i=0;i<n && !found;i++)
-    {
-      int naxis(MEDmeshnAxis(fid,i+1));
-      INTERP_KERNEL::AutoPtr<char> axisname=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE);
-      INTERP_KERNEL::AutoPtr<char> axisunit=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE);
-      MEDFILESAFECALLERRD0(MEDmeshInfo,(fid,i+1,nommaa,&spaceDim,&dim,&type_maillage,maillage_description,dtunit,&stype,&nstep,&axistype,axisname,axisunit));      
-      dtunit1=MEDLoaderBase::buildStringFromFortran(dtunit,sizeof(dtunit));
-      std::string cur=MEDLoaderBase::buildStringFromFortran(nommaa,sizeof(nommaa));
-      ms.push_back(cur);
-      if(cur==mname)
-        {
-          found=true;
-          ret=i+1;
-        }
-    }
-  if(!found)
-    {
-      std::ostringstream oss;
-      oss << "No such meshname (" << mname <<  ") in file ! Must be in : ";
-      std::copy(ms.begin(),ms.end(),std::ostream_iterator<std::string>(oss,", "));
-      throw INTERP_KERNEL::Exception(oss.str().c_str());
-    }
-  axType=TraduceAxisType(axistype);
+  int naxis(MEDmeshnAxis(fid,getID()));
+  INTERP_KERNEL::AutoPtr<char> nameTmp(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
+  INTERP_KERNEL::AutoPtr<char> axisname(MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE));
+  INTERP_KERNEL::AutoPtr<char> axisunit(MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE));
+  INTERP_KERNEL::AutoPtr<char> univTmp(MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE));
+  if(MEDmeshInfo(fid,getID(),nameTmp,&spaceDim,&Mdim,&type_maillage,description.getPointer(),dtunit.getPointer(),
+      &stype,&nstep,&axistype,axisname,axisunit)!=0)
+    throw INTERP_KERNEL::Exception("A problem has been detected when trying to get info on mesh !");
+  MEDmeshUniversalNameRd(fid,nameTmp,univName.getPointer());// do not protect  MEDFILESAFECALLERRD0 call : Thanks to fra.med.
+  axType=MEDFileMeshL2::TraduceAxisType(axistype);
   switch(type_maillage)
   {
     case MED_UNSTRUCTURED_MESH:
@@ -101,7 +68,7 @@ int MEDFileMeshL2::GetMeshIdFromName(med_idt fid, const std::string& mname, MEDC
     case MED_STRUCTURED_MESH:
       {
         med_grid_type gt;
-        MEDFILESAFECALLERRD0(MEDmeshGridTypeRd,(fid,mname.c_str(),&gt));
+        MEDFILESAFECALLERRD0(MEDmeshGridTypeRd,(fid,mName.c_str(),&gt));
         switch(gt)
         {
           case MED_CARTESIAN_GRID:
@@ -110,25 +77,28 @@ int MEDFileMeshL2::GetMeshIdFromName(med_idt fid, const std::string& mname, MEDC
           case MED_CURVILINEAR_GRID:
             meshType=CURVE_LINEAR;
             break;
-          case MED_POLAR_GRID:// this is not a bug. A MED file POLAR_GRID is deal by CARTESIAN MEDLoader
+        case MED_POLAR_GRID:// this is not a bug. A MED file POLAR_GRID is deal by CARTESIAN MEDLoader
             meshType=CARTESIAN;
             break;
           default:
-            throw INTERP_KERNEL::Exception("MEDFileMeshL2::getMeshIdFromName : unrecognized structured mesh type ! Supported are :\n - cartesian\n - curve linear\n");
+            throw INTERP_KERNEL::Exception("MEDFileMeshL2::getAxisInfoOnMesh : unrecognized structured mesh type ! Supported are :\n - cartesian\n - curve linear\n");
         }
         break;
       }
     default:
       throw INTERP_KERNEL::Exception("MEDFileMeshL2::getMeshIdFromName : unrecognized mesh type !");
   }
-  med_int numdt,numit;
-  med_float dtt;
-  MEDFILESAFECALLERRD0(MEDmeshComputationStepInfo,(fid,mname.c_str(),1,&numdt,&numit,&dtt));
-  dt=numdt; it=numit;
-  return ret;
+  //
+  std::vector<std::string> infosOnComp(naxis);
+  for(int i=0;i<naxis;i++)
+    {
+      std::string info(MEDLoaderBase::buildUnionUnit(((char *)axisname)+i*MED_SNAME_SIZE,MED_SNAME_SIZE,((char *)axisunit)+i*MED_SNAME_SIZE,MED_SNAME_SIZE));
+      infosOnComp[i]=info;
+    }
+  return infosOnComp;
 }
 
-double MEDFileMeshL2::CheckMeshTimeStep(med_idt fid, const std::string& mName, int nstep, int dt, int it)
+double MeshCls::checkMeshTimeStep(med_idt fid, const std::string& mName, int nstep, int dt, int it) const
 {
   bool found=false;
   med_int numdt,numit;
@@ -137,8 +107,9 @@ double MEDFileMeshL2::CheckMeshTimeStep(med_idt fid, const std::string& mName, i
   for(int i=0;i<nstep;i++)
     {
       MEDFILESAFECALLERRD0(MEDmeshComputationStepInfo,(fid,mName.c_str(),i+1,&numdt,&numit,&dtt));
-      p[i]=std::make_pair(numdt,numit);
-      found=(numdt==dt) && (numit==numit);
+      p[i]=std::make_pair((int)numdt,(int)numit);
+      found=(numdt==dt) && (numit==it);
+      if (found) break;
     }
   if(!found)
     {
@@ -151,61 +122,160 @@ double MEDFileMeshL2::CheckMeshTimeStep(med_idt fid, const std::string& mName, i
   return dtt;
 }
 
-/*!
- * non static and non const method because _description, _dt_unit... are set in this method.
- */
-std::vector<std::string> MEDFileMeshL2::getAxisInfoOnMesh(med_idt fid, int mId, const std::string& mName, MEDCoupling::MEDCouplingMeshType& meshType, MEDCoupling::MEDCouplingAxisType& axType, int& nstep, int& Mdim)
+std::vector<std::string> StructMeshCls::getAxisInfoOnMesh(med_idt fid, const std::string& mName, MEDCoupling::MEDCouplingMeshType& meshType, MEDCoupling::MEDCouplingAxisType& axType, int& nstep, int& Mdim, MEDFileString& description, MEDFileString& dtunit, MEDFileString& univName) const
+{
+  INTERP_KERNEL::AutoPtr<char> msn(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
+  INTERP_KERNEL::AutoPtr<char> zeDescription(MEDLoaderBase::buildEmptyString(MED_COMMENT_SIZE));
+  med_axis_type medAxType;
+  int nAxis(MEDsupportMeshnAxis(fid,getID()));
+  INTERP_KERNEL::AutoPtr<char> axisName(new char[MED_SNAME_SIZE*nAxis+1]),axisUnit(new char[MED_SNAME_SIZE*nAxis+1]);
+  int spaceDim(0),meshDim(0);
+  MEDFILESAFECALLERRD0(MEDsupportMeshInfo,(fid,getID(),msn,&spaceDim,&meshDim,zeDescription,&medAxType,axisName,axisUnit));
+  std::string descriptionCpp(MEDLoaderBase::buildStringFromFortran(zeDescription,MED_COMMENT_SIZE));
+  description.set(descriptionCpp.c_str());
+  dtunit.clear(); univName.clear(); meshType=UNSTRUCTURED; nstep=1;
+  axType=MEDFileMeshL2::TraduceAxisType(medAxType);
+  //int nmodels(0);
+  //med_bool chgt=MED_FALSE,trsf=MED_FALSE;
+  //nmodels=MEDmeshnEntity(fid,_name.c_str(),MED_NO_DT,MED_NO_IT,MED_STRUCT_ELEMENT,MED_GEO_ALL,MED_CONNECTIVITY,MED_NODAL,&chgt,&trsf);
+  std::vector<std::string> ret;
+  for(int i=0;i<nAxis;i++)
+    {
+      std::string info(DataArray::BuildInfoFromVarAndUnit(MEDLoaderBase::buildStringFromFortran(axisName+i*MED_SNAME_SIZE,MED_SNAME_SIZE),
+                                                          MEDLoaderBase::buildStringFromFortran(axisUnit+i*MED_SNAME_SIZE,MED_SNAME_SIZE)));
+      ret.push_back(info);
+    }
+  return ret;
+}
+
+double StructMeshCls::checkMeshTimeStep(med_idt fid, const std::string& mName, int nstep, int dt, int it) const
+{
+  return 0.;
+}
+
+MEDFileMeshL2::MEDFileMeshL2():_name(MED_NAME_SIZE),_description(MED_COMMENT_SIZE),_univ_name(MED_LNAME_SIZE),_dt_unit(MED_LNAME_SIZE)
+{
+}
+
+std::size_t MEDFileMeshL2::getHeapMemorySizeWithoutChildren() const
+{
+  return 0;
+}
+
+std::vector<const BigMemoryObject *> MEDFileMeshL2::getDirectChildrenWithNull() const
+{
+  return std::vector<const BigMemoryObject *>();
+}
+
+INTERP_KERNEL::AutoCppPtr<MeshOrStructMeshCls> MEDFileMeshL2::GetMeshIdFromName(med_idt fid, const std::string& mName, MEDCoupling::MEDCouplingMeshType& meshType, MEDCoupling::MEDCouplingAxisType& axType, int& dt, int& it, std::string& dtunit1)
 {
   med_mesh_type type_maillage;
-  med_int spaceDim;
+  char maillage_description[MED_COMMENT_SIZE+1];
+  char dtunit[MED_LNAME_SIZE+1];
+  med_int spaceDim,dim;
+  char nommaa[MED_NAME_SIZE+1];
+  med_int n=MEDnMesh(fid);
+  char found(0);
+  int ret=-1;
   med_sorting_type stype;
+  std::vector<std::string> ms;
+  int nstep;
   med_axis_type axistype;
-  int naxis(MEDmeshnAxis(fid,mId));
-  INTERP_KERNEL::AutoPtr<char> nameTmp=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
-  INTERP_KERNEL::AutoPtr<char> axisname=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE);
-  INTERP_KERNEL::AutoPtr<char> axisunit=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE);
-  INTERP_KERNEL::AutoPtr<char> univTmp=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
-  if(MEDmeshInfo(fid,mId,nameTmp,&spaceDim,&Mdim,&type_maillage,_description.getPointer(),_dt_unit.getPointer(),
-      &stype,&nstep,&axistype,axisname,axisunit)!=0)
-    throw INTERP_KERNEL::Exception("A problem has been detected when trying to get info on mesh !");
-  MEDmeshUniversalNameRd(fid,nameTmp,_univ_name.getPointer());// do not protect  MEDFILESAFECALLERRD0 call : Thanks to fra.med.
-  axType=TraduceAxisType(axistype);
-  switch(type_maillage)
-  {
-    case MED_UNSTRUCTURED_MESH:
-      meshType=UNSTRUCTURED;
-      break;
-    case MED_STRUCTURED_MESH:
-      {
-        med_grid_type gt;
-        MEDFILESAFECALLERRD0(MEDmeshGridTypeRd,(fid,mName.c_str(),&gt));
-        switch(gt)
+  for(int i=0;i<n && found==0;i++)
+    {
+      int naxis(MEDmeshnAxis(fid,i+1));
+      INTERP_KERNEL::AutoPtr<char> axisname(MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE)),axisunit(MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE));
+      MEDFILESAFECALLERRD0(MEDmeshInfo,(fid,i+1,nommaa,&spaceDim,&dim,&type_maillage,maillage_description,dtunit,&stype,&nstep,&axistype,axisname,axisunit));      
+      dtunit1=MEDLoaderBase::buildStringFromFortran(dtunit,sizeof(dtunit));
+      std::string cur(MEDLoaderBase::buildStringFromFortran(nommaa,sizeof(nommaa)));
+      ms.push_back(cur);
+      if(cur==mName)
         {
-          case MED_CARTESIAN_GRID:
-            meshType=CARTESIAN;
-            break;
-          case MED_CURVILINEAR_GRID:
-            meshType=CURVE_LINEAR;
-            break;
-        case MED_POLAR_GRID:// this is not a bug. A MED file POLAR_GRID is deal by CARTESIAN MEDLoader
-            meshType=CARTESIAN;
+          found=1;
+          ret=i+1;
+        }
+    }
+  if(found==0)
+    {//last chance ! Is it a support mesh ?
+      int nbSM(MEDnSupportMesh(fid));
+      for(int i=0;i<nbSM && found==0;i++)
+        {
+          int naxis(MEDsupportMeshnAxis(fid,i+1));
+          INTERP_KERNEL::AutoPtr<char> axisname(MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE)),axisunit(MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE));
+          MEDFILESAFECALLERRD0(MEDsupportMeshInfo,(fid,i+1,nommaa,&spaceDim,&dim,maillage_description,&axistype,axisname,axisunit));
+          std::string cur(MEDLoaderBase::buildStringFromFortran(nommaa,sizeof(nommaa)));
+          ms.push_back(cur);
+          if(cur==mName)
+            {
+              found=2;
+              ret=i+1;
+            }
+        }
+    }
+  ////////////////////////
+  switch(found)
+    {
+    case 1:
+      {
+        axType=TraduceAxisType(axistype);
+        switch(type_maillage)
+          {
+          case MED_UNSTRUCTURED_MESH:
+            meshType=UNSTRUCTURED;
             break;
+          case MED_STRUCTURED_MESH:
+            {
+              med_grid_type gt;
+              MEDFILESAFECALLERRD0(MEDmeshGridTypeRd,(fid,mName.c_str(),&gt));
+              switch(gt)
+                {
+                case MED_CARTESIAN_GRID:
+                  meshType=CARTESIAN;
+                  break;
+                case MED_CURVILINEAR_GRID:
+                  meshType=CURVE_LINEAR;
+                  break;
+                case MED_POLAR_GRID:// this is not a bug. A MED file POLAR_GRID is deal by CARTESIAN MEDLoader
+                  meshType=CARTESIAN;
+                  break;
+                default:
+                  throw INTERP_KERNEL::Exception("MEDFileMeshL2::getMeshIdFromName : unrecognized structured mesh type ! Supported are :\n - cartesian\n - curve linear\n");
+                }
+              break;
+            }
           default:
-            throw INTERP_KERNEL::Exception("MEDFileMeshL2::getAxisInfoOnMesh : unrecognized structured mesh type ! Supported are :\n - cartesian\n - curve linear\n");
-        }
-        break;
+            throw INTERP_KERNEL::Exception("MEDFileMeshL2::getMeshIdFromName : unrecognized mesh type !");
+          }
+        med_int numdt,numit;
+        med_float dtt;
+        MEDFILESAFECALLERRD0(MEDmeshComputationStepInfo,(fid,mName.c_str(),1,&numdt,&numit,&dtt));
+        dt=numdt; it=numit;
+        return new MeshCls(ret);
+      }
+    case 2:
+      {
+        meshType=UNSTRUCTURED;
+        dt=MED_NO_DT; it=MED_NO_IT; dtunit1.clear();
+        axType=axType=TraduceAxisType(axistype);
+        return new StructMeshCls(ret);
       }
     default:
-      throw INTERP_KERNEL::Exception("MEDFileMeshL2::getMeshIdFromName : unrecognized mesh type !");
-  }
-  //
-  std::vector<std::string> infosOnComp(naxis);
-  for(int i=0;i<naxis;i++)
-    {
-      std::string info=MEDLoaderBase::buildUnionUnit(((char *)axisname)+i*MED_SNAME_SIZE,MED_SNAME_SIZE,((char *)axisunit)+i*MED_SNAME_SIZE,MED_SNAME_SIZE);
-      infosOnComp[i]=info;
+      {
+        std::ostringstream oss;
+        oss << "No such meshname (" << mName <<  ") in file ! Must be in : ";
+        std::copy(ms.begin(),ms.end(),std::ostream_iterator<std::string>(oss,", "));
+        throw INTERP_KERNEL::Exception(oss.str().c_str());
+      }
     }
-  return infosOnComp;
+  
+}
+
+/*!
+ * non static and non const method because _description, _dt_unit... are set in this method.
+ */
+std::vector<std::string> MEDFileMeshL2::getAxisInfoOnMesh(med_idt fid, const MeshOrStructMeshCls *mId, const std::string& mName, MEDCoupling::MEDCouplingMeshType& meshType, MEDCoupling::MEDCouplingAxisType& axType, int& nstep, int& Mdim)
+{
+  return mId->getAxisInfoOnMesh(fid,mName,meshType,axType,nstep,Mdim,_description,_dt_unit,_univ_name);
 }
 
 void MEDFileMeshL2::ReadFamiliesAndGrps(med_idt fid, const std::string& meshName, std::map<std::string,int>& fams, std::map<std::string, std::vector<std::string> >& grps, MEDFileMeshReadSelector *mrs)
@@ -261,7 +331,7 @@ void MEDFileMeshL2::WriteFamiliesAndGrps(med_idt fid, const std::string& mname,
       INTERP_KERNEL::AutoPtr<char> groName=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE*ngro);
       int i=0;
       for(std::vector<std::string>::const_iterator it2=(*it).second.second.begin();it2!=(*it).second.second.end();it2++,i++)
-        MEDLoaderBase::safeStrCpy2((*it2).c_str(),MED_LNAME_SIZE-1,groName+i*MED_LNAME_SIZE,tooLongStrPol);
+        MEDLoaderBase::safeStrCpy2((*it2).c_str(),MED_LNAME_SIZE,groName+i*MED_LNAME_SIZE,tooLongStrPol);
       INTERP_KERNEL::AutoPtr<char> famName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
       MEDLoaderBase::safeStrCpy((*it).first.c_str(),MED_NAME_SIZE,famName,tooLongStrPol);
       int ret=MEDfamilyCr(fid,mname.c_str(),famName,(*it).second.first,ngro,groName);
@@ -284,7 +354,7 @@ void MEDFileMeshL2::RenameFamiliesPatternInternal(std::vector< std::pair<std::st
 
 /*!
  * This method is dedicated to the killers that use a same family name to store different family ids. MED file API authorizes it.
- * So this method renames families (if needed generaly not !) in order to have a discriminant name for families.
+ * So this method renames families (if needed generally not !) in order to have a discriminant name for families.
  */
 void MEDFileMeshL2::RenameFamiliesFromFileToMemInternal(std::vector< std::pair<std::string,std::pair<int,std::vector<std::string> > > >& crudeFams)
 {
@@ -317,7 +387,7 @@ bool MEDFileMeshL2::RenameFamiliesFromFileToMem(std::vector< std::string >& famN
 
 /*!
  * This method is dedicated to the killers that use a same family name to store different family ids. MED file API authorizes it.
- * So this method renames families (if needed generaly not !) in order to have a discriminant name for families.
+ * So this method renames families (if needed generally not !) in order to have a discriminant name for families.
  */
 void MEDFileMeshL2::RenameFamiliesFromMemToFileInternal(std::vector< std::pair<std::string,std::pair<int,std::vector<std::string> > > >& crudeFams)
 {
@@ -443,7 +513,7 @@ MEDFileUMeshL2::MEDFileUMeshL2()
 {
 }
 
-std::vector<std::string> MEDFileUMeshL2::loadCommonPart(med_idt fid, int mId, const std::string& mName, int dt, int it, int& Mdim)
+std::vector<std::string> MEDFileUMeshL2::loadCommonPart(med_idt fid, const MeshOrStructMeshCls *mId, const std::string& mName, int dt, int it, int& Mdim)
 {
   Mdim=-3;
   _name.set(mName.c_str());
@@ -458,23 +528,23 @@ std::vector<std::string> MEDFileUMeshL2::loadCommonPart(med_idt fid, int mId, co
     }
   if(meshType!=UNSTRUCTURED)
     throw INTERP_KERNEL::Exception("Invalid mesh type ! You are expected an unstructured one whereas in file it is not an unstructured !");
-  _time=CheckMeshTimeStep(fid,mName,nstep,dt,it);
+  _time=mId->checkMeshTimeStep(fid,mName,nstep,dt,it);
   _iteration=dt;
   _order=it;
   return ret;
 }
 
-void MEDFileUMeshL2::loadAll(med_idt fid, int mId, const std::string& mName, int dt, int it, MEDFileMeshReadSelector *mrs)
+void MEDFileUMeshL2::loadAll(med_idt fid, const MeshOrStructMeshCls *mId, const std::string& mName, int dt, int it, MEDFileMeshReadSelector *mrs)
 {
   int Mdim;
   std::vector<std::string> infosOnComp(loadCommonPart(fid,mId,mName,dt,it,Mdim));
   if(Mdim==-4)
     return ;
   loadConnectivity(fid,Mdim,mName,dt,it,mrs);//to improve check (dt,it) coherency
-  loadCoords(fid,mId,infosOnComp,mName,dt,it);
+  loadCoords(fid,infosOnComp,mName,dt,it);
 }
 
-void MEDFileUMeshL2::loadPart(med_idt fid, int mId, const std::string& mName, const std::vector<INTERP_KERNEL::NormalizedCellType>& types, const std::vector<int>& slicPerTyp, int dt, int it, MEDFileMeshReadSelector *mrs)
+void MEDFileUMeshL2::loadPart(med_idt fid, const MeshOrStructMeshCls *mId, const std::string& mName, const std::vector<INTERP_KERNEL::NormalizedCellType>& types, const std::vector<int>& slicPerTyp, int dt, int it, MEDFileMeshReadSelector *mrs)
 {
   int Mdim;
   std::vector<std::string> infosOnComp(loadCommonPart(fid,mId,mName,dt,it,Mdim));
@@ -493,7 +563,7 @@ void MEDFileUMeshL2::loadPart(med_idt fid, int mId, const std::string& mName, co
   for(std::vector< std::vector< MCAuto<MEDFileUMeshPerType> > >::const_iterator it0=_per_type_mesh.begin();it0!=_per_type_mesh.end();it0++)
     for(std::vector< MCAuto<MEDFileUMeshPerType> >::const_iterator it1=(*it0).begin();it1!=(*it0).end();it1++)
       (*it1)->getMesh()->renumberNodesWithOffsetInConn(-nMin);
-  loadPartCoords(fid,mId,infosOnComp,mName,dt,it,nMin,nMax);
+  loadPartCoords(fid,infosOnComp,mName,dt,it,nMin,nMax);
 }
 
 void MEDFileUMeshL2::loadConnectivity(med_idt fid, int mdim, const std::string& mName, int dt, int it, MEDFileMeshReadSelector *mrs)
@@ -528,7 +598,7 @@ void MEDFileUMeshL2::loadPartOfConnectivity(med_idt fid, int mdim, const std::st
   sortTypes();
 }
 
-void MEDFileUMeshL2::loadCoords(med_idt fid, int mId, const std::vector<std::string>& infosOnComp, const std::string& mName, int dt, int it)
+void MEDFileUMeshL2::loadCoords(med_idt fid, const std::vector<std::string>& infosOnComp, const std::string& mName, int dt, int it)
 {
   int spaceDim((int)infosOnComp.size());
   med_bool changement,transformation;
@@ -563,11 +633,17 @@ void MEDFileUMeshL2::loadCoords(med_idt fid, int mId, const std::vector<std::str
     }
   else
     _name_coords=0;
+  if(MEDmeshnEntity(fid,mName.c_str(),dt,it,MED_NODE,MED_NO_GEOTYPE,MED_GLOBAL_NUMBER,MED_NODAL,&changement,&transformation)>0)
+    {
+      _global_num_coords=DataArrayInt::New();
+      _global_num_coords->alloc(nCoords,1);
+      MEDFILESAFECALLERRD0(MEDmeshGlobalNumberRd,(fid,mName.c_str(),dt,it,MED_NODE,MED_NO_GEOTYPE,_global_num_coords->getPointer()));
+    }
   for(int i=0;i<spaceDim;i++)
     _coords->setInfoOnComponent(i,infosOnComp[i]);
 }
 
-void MEDFileUMeshL2::loadPartCoords(med_idt fid, int mId, const std::vector<std::string>& infosOnComp, const std::string& mName, int dt, int it, int nMin, int nMax)
+void MEDFileUMeshL2::loadPartCoords(med_idt fid, const std::vector<std::string>& infosOnComp, const std::string& mName, int dt, int it, int nMin, int nMax)
 {
   med_bool changement,transformation;
   int spaceDim((int)infosOnComp.size()),nCoords(MEDmeshnEntity(fid,mName.c_str(),dt,it,MED_NODE,MED_NONE,MED_COORDINATE,MED_NO_CMODE,&changement,&transformation));
@@ -646,15 +722,15 @@ void MEDFileUMeshL2::sortTypes()
   _per_type_mesh.resize(_per_type_mesh.size()-nbOfUselessLev);
 }
 
-void MEDFileUMeshL2::WriteCoords(med_idt fid, const std::string& mname, int dt, int it, double time, const DataArrayDouble *coords, const DataArrayInt *famCoords, const DataArrayInt *numCoords, const DataArrayAsciiChar *nameCoords)
+void MEDFileUMeshL2::WriteCoords(med_idt fid, const std::string& mname, int dt, int it, double time, const DataArrayDouble *coords, const DataArrayInt *famCoords, const DataArrayInt *numCoords, const DataArrayAsciiChar *nameCoords, const DataArrayInt *globalNumCoords)
 {
   if(!coords)
     return ;
-  MEDFILESAFECALLERWR0(MEDmeshNodeCoordinateWr,(fid,mname.c_str(),dt,it,time,MED_FULL_INTERLACE,coords->getNumberOfTuples(),coords->getConstPointer()));
+  MEDFILESAFECALLERWR0(MEDmeshNodeCoordinateWr,(fid,mname.c_str(),dt,it,time,MED_FULL_INTERLACE,coords->getNumberOfTuples(),coords->begin()));
   if(famCoords)
-    MEDFILESAFECALLERWR0(MEDmeshEntityFamilyNumberWr,(fid,mname.c_str(),dt,it,MED_NODE,MED_NO_GEOTYPE,famCoords->getNumberOfTuples(),famCoords->getConstPointer()));
+    MEDFILESAFECALLERWR0(MEDmeshEntityFamilyNumberWr,(fid,mname.c_str(),dt,it,MED_NODE,MED_NO_GEOTYPE,famCoords->getNumberOfTuples(),famCoords->begin()));
   if(numCoords)
-    MEDFILESAFECALLERWR0(MEDmeshEntityNumberWr,(fid,mname.c_str(),dt,it,MED_NODE,MED_NO_GEOTYPE,numCoords->getNumberOfTuples(),numCoords->getConstPointer()));
+    MEDFILESAFECALLERWR0(MEDmeshEntityNumberWr,(fid,mname.c_str(),dt,it,MED_NODE,MED_NO_GEOTYPE,numCoords->getNumberOfTuples(),numCoords->begin()));
   if(nameCoords)
     {
       if(nameCoords->getNumberOfComponents()!=MED_SNAME_SIZE)
@@ -663,8 +739,10 @@ void MEDFileUMeshL2::WriteCoords(med_idt fid, const std::string& mname, int dt,
           oss << " ! The array has " << nameCoords->getNumberOfComponents() << " components !";
           throw INTERP_KERNEL::Exception(oss.str().c_str());
         }
-      MEDFILESAFECALLERWR0(MEDmeshEntityNameWr,(fid,mname.c_str(),dt,it,MED_NODE,MED_NO_GEOTYPE,nameCoords->getNumberOfTuples(),nameCoords->getConstPointer()));
+      MEDFILESAFECALLERWR0(MEDmeshEntityNameWr,(fid,mname.c_str(),dt,it,MED_NODE,MED_NO_GEOTYPE,nameCoords->getNumberOfTuples(),nameCoords->begin()));
     }
+  if(globalNumCoords)
+    MEDFILESAFECALLERWR0(MEDmeshGlobalNumberWr,(fid,mname.c_str(),dt,it,MED_NODE,MED_NONE,globalNumCoords->getNumberOfTuples(),globalNumCoords->begin()));
 }
 
 bool MEDFileUMeshL2::isFamDefinedOnLev(int levId) const
@@ -695,17 +773,17 @@ MEDFileCMeshL2::MEDFileCMeshL2():_ax_type(AX_CART)
 {
 }
 
-void MEDFileCMeshL2::loadAll(med_idt fid, int mId, const std::string& mName, int dt, int it)
+void MEDFileCMeshL2::loadAll(med_idt fid, const MeshOrStructMeshCls *mId, const std::string& mName, int dt, int it)
 {
   _name.set(mName.c_str());
   int nstep;
   int Mdim;
   MEDCoupling::MEDCouplingMeshType meshType;
   MEDCoupling::MEDCouplingAxisType dummy3;
-  std::vector<std::string> infosOnComp=getAxisInfoOnMesh(fid,mId,mName.c_str(),meshType,dummy3,nstep,Mdim);
+  std::vector<std::string> infosOnComp(getAxisInfoOnMesh(fid,mId,mName.c_str(),meshType,dummy3,nstep,Mdim));
   if(meshType!=CARTESIAN)
     throw INTERP_KERNEL::Exception("Invalid mesh type ! You are expected a structured one whereas in file it is not a structured !");
-  _time=CheckMeshTimeStep(fid,mName,nstep,dt,it);
+  _time=mId->checkMeshTimeStep(fid,mName,nstep,dt,it);
   _iteration=dt;
   _order=it;
   //
@@ -747,17 +825,17 @@ MEDFileCLMeshL2::MEDFileCLMeshL2()
 {
 }
 
-void MEDFileCLMeshL2::loadAll(med_idt fid, int mId, const std::string& mName, int dt, int it)
+void MEDFileCLMeshL2::loadAll(med_idt fid, const MeshOrStructMeshCls *mId, const std::string& mName, int dt, int it)
 {
   _name.set(mName.c_str());
   int nstep;
   int Mdim;
   MEDCoupling::MEDCouplingMeshType meshType;
   MEDCoupling::MEDCouplingAxisType dummy3;
-  std::vector<std::string> infosOnComp=getAxisInfoOnMesh(fid,mId,mName,meshType,dummy3,nstep,Mdim);
+  std::vector<std::string> infosOnComp(getAxisInfoOnMesh(fid,mId,mName,meshType,dummy3,nstep,Mdim));
   if(meshType!=CURVE_LINEAR)
     throw INTERP_KERNEL::Exception("Invalid mesh type ! You are expected a structured one whereas in file it is not a structured !");
-  _time=CheckMeshTimeStep(fid,mName,nstep,dt,it);
+  _time=mId->checkMeshTimeStep(fid,mName,nstep,dt,it);
   _iteration=dt;
   _order=it;
   //
@@ -788,7 +866,7 @@ MEDFileUMeshPermCompute::operator MEDCouplingUMesh *() const
     {
       updateTime();
       _m=static_cast<MEDCouplingUMesh *>(_st->_m_by_types.getUmesh()->deepCopy());
-      _m->renumberCells(_st->_num->getConstPointer(),true);
+      _m->renumberCells(_st->_num->begin(),true);
       return _m.retn();
     }
   else
@@ -799,7 +877,7 @@ MEDFileUMeshPermCompute::operator MEDCouplingUMesh *() const
         {
           updateTime();
           _m=static_cast<MEDCouplingUMesh *>(_st->_m_by_types.getUmesh()->deepCopy());
-          _m->renumberCells(_st->_num->getConstPointer(),true);
+          _m->renumberCells(_st->_num->begin(),true);
           return _m.retn();
         }
     }
@@ -1054,7 +1132,7 @@ void MEDFileUMeshSplitL1::assignMesh(MEDCouplingUMesh *m, bool newOrOld)
           _num=da->invertArrayO2N2N2O(m->getNumberOfCells());
           _m.updateTime();
           computeRevNum();
-          _m_by_types.getUmesh()->renumberCells(da->getConstPointer(),false);
+          _m_by_types.getUmesh()->renumberCells(da->begin(),false);
         }
     }
   else
@@ -1126,9 +1204,9 @@ int MEDFileUMeshSplitL1::getSize() const
 MEDCouplingUMesh *MEDFileUMeshSplitL1::getFamilyPart(const int *idsBg, const int *idsEnd, bool renum) const
 {
   MCAuto<DataArrayInt> eltsToKeep=_fam->findIdsEqualList(idsBg,idsEnd);
-  MEDCouplingUMesh *m=(MEDCouplingUMesh *)_m_by_types.getUmesh()->buildPartOfMySelf(eltsToKeep->getConstPointer(),eltsToKeep->getConstPointer()+eltsToKeep->getNumberOfTuples(),true);
+  MEDCouplingUMesh *m=(MEDCouplingUMesh *)_m_by_types.getUmesh()->buildPartOfMySelf(eltsToKeep->begin(),eltsToKeep->end(),true);
   if(renum)
-    return renumIfNeeded(m,eltsToKeep->getConstPointer());
+    return renumIfNeeded(m,eltsToKeep->begin());
   return m;
 }
 
@@ -1343,11 +1421,11 @@ MEDCouplingUMesh *MEDFileUMeshSplitL1::Renumber2(const DataArrayInt *renum, MEDC
   if(renum==0)
     return m;
   if(cellIds==0)
-    m->renumberCells(renum->getConstPointer(),true);
+    m->renumberCells(renum->begin(),true);
   else
     {
       MCAuto<DataArrayInt> locnum=renum->selectByTupleId(cellIds,cellIds+m->getNumberOfCells());
-      m->renumberCells(locnum->getConstPointer(),true);
+      m->renumberCells(locnum->begin(),true);
     }
   return m;
 }
@@ -1371,7 +1449,7 @@ DataArrayInt *MEDFileUMeshSplitL1::Renumber(const DataArrayInt *renum, const Dat
       da->incrRef();
       return const_cast<DataArrayInt *>(da);
     }
-  return renum->selectByTupleId(da->getConstPointer(),da->getConstPointer()+da->getNumberOfTuples());
+  return renum->selectByTupleId(da->begin(),da->end());
 }
 
 DataArrayInt *MEDFileUMeshSplitL1::renumIfNeededArr(const DataArrayInt *da) const
@@ -1986,3 +2064,59 @@ void MEDFileUMeshAggregateCompute::setCoords(DataArrayDouble *coords)
   if(m)
     m->setCoords(coords);
 }
+
+MEDFileEltStruct4Mesh *MEDFileEltStruct4Mesh::New(med_idt fid, const std::string& mName, int dt, int it, int iterOnStEltOfMesh, MEDFileMeshReadSelector *mrs)
+{
+  return new MEDFileEltStruct4Mesh(fid,mName,dt,it,iterOnStEltOfMesh,mrs);
+}
+
+std::size_t MEDFileEltStruct4Mesh::getHeapMemorySizeWithoutChildren() const
+{
+  return _geo_type_name.capacity()+_vars.capacity()*sizeof(MCAuto<DataArray>);
+}
+
+std::vector<const MEDCoupling::BigMemoryObject*> MEDFileEltStruct4Mesh::getDirectChildrenWithNull() const
+{
+  std::vector<const MEDCoupling::BigMemoryObject*> ret;
+  ret.push_back(_conn);
+  ret.push_back(_common);
+  for(std::vector< MCAuto<DataArray> >::const_iterator it=_vars.begin();it!=_vars.end();it++)
+    ret.push_back(*it);
+  return ret;
+}
+
+MEDFileEltStruct4Mesh::MEDFileEltStruct4Mesh(med_idt fid, const std::string& mName, int dt, int it, int iterOnStEltOfMesh, MEDFileMeshReadSelector *mrs)
+{
+  med_geometry_type geoType;
+  INTERP_KERNEL::AutoPtr<char> geoTypeName(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
+  MEDFILESAFECALLERRD0(MEDmeshEntityInfo,(fid,mName.c_str(),dt,it,MED_STRUCT_ELEMENT,iterOnStEltOfMesh+1,geoTypeName,&geoType));
+  _geo_type=geoType;
+  _geo_type_name=MEDLoaderBase::buildStringFromFortran(geoTypeName,MED_NAME_SIZE);
+  int nCells(0);
+  {
+    med_bool chgt=MED_FALSE,trsf=MED_FALSE;
+    nCells=MEDmeshnEntity(fid,mName.c_str(),dt,it,MED_STRUCT_ELEMENT,geoType,MED_CONNECTIVITY,MED_NODAL,&chgt,&trsf);
+  }
+  MCAuto<MEDFileMeshSupports> mss(MEDFileMeshSupports::New(fid));
+  MCAuto<MEDFileStructureElements> mse(MEDFileStructureElements::New(fid,mss));
+  int nbEntities(mse->getNumberOfNodesPerSE(_geo_type_name));
+  _conn=DataArrayInt::New(); _conn->alloc(nCells*nbEntities);
+  MEDFILESAFECALLERRD0(MEDmeshElementConnectivityRd,(fid,mName.c_str(),dt,it,MED_STRUCT_ELEMENT,_geo_type,MED_NODAL,MED_FULL_INTERLACE,_conn->getPointer()));
+  _conn->applyLin(1,-1);
+  _conn->rearrange(nbEntities);
+  _common=MEDFileUMeshPerTypeCommon::New();
+  _common->loadCommonPart(fid,mName.c_str(),dt,it,nCells,geoType,MED_STRUCT_ELEMENT,mrs);
+  std::vector<std::string> vns(mse->getVarAttsOf(_geo_type_name));
+  std::size_t sz(vns.size());
+  _vars.resize(sz);
+  for(std::size_t i=0;i<sz;i++)
+    {
+      const MEDFileSEVarAtt *var(mse->getVarAttOf(_geo_type_name,vns[i]));
+      MCAuto<DataArray> gen(var->getGenerator());
+      MCAuto<DataArray> arr(gen->buildNewEmptyInstance());
+      arr->alloc(nCells,var->getNbOfComponents());
+      arr->setName(vns[i]);
+      MEDFILESAFECALLERRD0(MEDmeshStructElementVarAttRd,(fid,mName.c_str(),dt,it,_geo_type,vns[i].c_str(),arr->getVoidStarPointer()));
+      _vars[i]=arr;
+    }
+}