Salome HOME
Indentation and white spaces ...
[tools/medcoupling.git] / src / MEDLoader / MEDLoader.cxx
index 4cd9823b24d6ff77a7a30e875b0f6412e1c9ebdf..8b1ffc7c63e135d9d86c4c8430190cd36070d1ce 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2016  CEA/DEN, EDF R&D
+// Copyright (C) 2007-2019  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
 #include "MEDCouplingUMesh.hxx"
 #include "MEDCouplingMemArray.hxx"
 #include "MEDCouplingFieldDouble.hxx"
+#include "MEDCouplingFieldFloat.hxx"
+#include "MEDCouplingFieldInt.hxx"
 #include "MEDCouplingGaussLocalization.hxx"
+#include "MEDCouplingTraits.hxx"
 #include "MCAuto.hxx"
 
 #include "InterpKernelAutoPtr.hxx"
@@ -64,6 +67,7 @@ med_geometry_type typmai[MED_N_CELL_FIXED_GEO] = { MED_POINT1,
   MED_TETRA10,
   MED_PYRA13,
   MED_PENTA15,
+  MED_PENTA18,
   MED_HEXA20,
   MED_HEXA27,
   MED_POLYGON,
@@ -90,6 +94,7 @@ INTERP_KERNEL::NormalizedCellType typmai2[MED_N_CELL_FIXED_GEO] = { INTERP_KERNE
   INTERP_KERNEL::NORM_TETRA10,
   INTERP_KERNEL::NORM_PYRA13,
   INTERP_KERNEL::NORM_PENTA15,
+  INTERP_KERNEL::NORM_PENTA18,
   INTERP_KERNEL::NORM_HEXA20,
   INTERP_KERNEL::NORM_HEXA27,
   INTERP_KERNEL::NORM_POLYGON,
@@ -124,7 +129,7 @@ med_geometry_type typmai3[34] = { MED_POINT1,//0
   MED_PENTA15,//25
   MED_NONE,//26
   MED_HEXA27,//27
-  MED_NONE,//28
+  MED_PENTA18,//28
   MED_NONE,//29
   MED_HEXA20,//30
   MED_POLYHEDRON,//31
@@ -289,11 +294,26 @@ bool MEDCoupling::HasXDR()
 
 std::string MEDCoupling::MEDFileVersionStr()
 {
-  return std::string(MED_VERSION_STR);
+  const int SZ=20;
+  char buf[SZ];
+  std::fill(buf,buf+SZ,'\0');
+  const char START_EXPECTED[]="MED-";
+  med_err ret(MEDlibraryStrVersion(buf));
+  if(ret!=0)
+    throw INTERP_KERNEL::Exception("MEDFileVersionStr : fail to find version of MED file ! It looks very bad !");
+  std::string zeRet(buf);
+  std::size_t pos(zeRet.find(START_EXPECTED,0));
+  if(pos!=0)
+    {
+      std::ostringstream oss; oss << "MEDFileVersionStr : internal error ! The MEDFile returned version (\"" << zeRet << "\") has not the right pattern !";
+      throw INTERP_KERNEL::Exception(oss.str());
+    }
+  return zeRet.substr(sizeof(START_EXPECTED)-1,std::string::npos);
 }
 
 std::string MEDCoupling::MEDFileVersionOfFileStr(const std::string& fileName)
 {
+#if MED_NUM_MAJEUR>3 || ( MED_NUM_MAJEUR==3 && ( (MED_NUM_MINEUR==2 && MED_NUM_RELEASE>=1) || MED_NUM_MINEUR>=3) )
   MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
   const int SZ=20;
   const char START_EXPECTED[]="MED-";
@@ -308,17 +328,25 @@ std::string MEDCoupling::MEDFileVersionOfFileStr(const std::string& fileName)
       throw INTERP_KERNEL::Exception(oss.str());
     }
   return ret.substr(sizeof(START_EXPECTED)-1,std::string::npos);
+#else
+  std::ostringstream oss; oss << "MEDFileVersionOfFileStr : is implemented with MEDFile " << MEDFileVersionStr() << " ! If you need this feature please use version >= 3.2.1.";
+  throw INTERP_KERNEL::Exception(oss.str());
+#endif
 }
 
 void MEDCoupling::MEDFileVersion(int& major, int& minor, int& release)
 {
-  major=MED_NUM_MAJEUR;
-  minor=MED_NUM_MINEUR;
-  release=MED_NUM_RELEASE;
+  med_int majj,minn,rell;
+  med_err ret(MEDlibraryNumVersion(&majj,&minn,&rell));
+  if(ret!=0)
+    throw INTERP_KERNEL::Exception("MEDFileVersion : fail to call MEDlibraryNumVersion ! It looks very bad !");
+  major=majj;
+  minor=minn;
+  release=rell;
 }
 
 /*!
- * This method sets the epsilon value used for node comparison when trying to buid a profile for a field on node/cell on an already written mesh.
+ * This method sets the epsilon value used for node comparison when trying to build a profile for a field on node/cell on an already written mesh.
  */
 void MEDCoupling::SetEpsilonForNodeComp(double val)
 {
@@ -1130,7 +1158,84 @@ MEDCoupling::MEDCouplingUMesh *MEDCoupling::ReadUMeshFromGroups(const std::strin
   return mmuPtr->getGroups(meshDimRelToMax,grps,true);
 }
 
-MEDCoupling::MEDCouplingFieldDouble *MEDCoupling::ReadField(MEDCoupling::TypeOfField type, const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName, int iteration, int order)
+MCAuto<MEDCoupling::MEDCouplingField> MEDCoupling::ReadField(const std::string& fileName)
+{
+  std::vector<std::string> fieldNames(GetAllFieldNames(fileName));
+  std::size_t sz(fieldNames.size());
+  if(sz==0)
+    {
+      std::ostringstream oss;
+      oss << "The file \"" << fileName << "\" contains no field !";
+      throw INTERP_KERNEL::Exception(oss.str());
+    }
+  if(sz>1)
+    {
+      std::ostringstream oss;
+      oss << "In file \"" << fileName << "\" there are more than one field !" << std::endl;
+      oss << "You are invited to use ReadField(fileName, fieldName) instead to avoid misleading concerning field you want to read !" << std::endl;
+      oss << "For information, fields available are :" << std::endl;
+      for(std::vector<std::string>::const_iterator it=fieldNames.begin();it!=fieldNames.end();it++)
+        oss << " - \"" << *it << "\"" << std::endl;
+      throw INTERP_KERNEL::Exception(oss.str());
+    }
+  return ReadField(fileName,fieldNames[0]);
+}
+
+MCAuto<MEDCoupling::MEDCouplingField> MEDCoupling::ReadField(const std::string& fileName, const std::string& fieldName)
+{
+  std::vector< std::pair< std::pair<int,int>, double> > iterations(GetAllFieldIterations(fileName,fieldName));
+  std::size_t sz(iterations.size());
+  if(sz==0)
+    {
+      std::ostringstream oss;
+      oss << "In file \"" << fileName << "\" field \"" << fieldName << "\" exists but with no time steps !";
+      throw INTERP_KERNEL::Exception(oss.str());
+    }
+  if(sz>1)
+    {
+      std::ostringstream oss;
+      oss << "In file \"" << fileName << "\" field \"" << fieldName << "\" exists but with more than one time steps !" << std::endl;
+      oss << "You are invited to use ReadField(fileName, fieldName, iteration, order) instead to avoid misleading concerning time steps." << std::endl;
+      oss << "For information, time steps available for field \"" << fieldName << "\" are :" << std::endl;
+      for(std::vector< std::pair< std::pair<int,int>, double> >::const_iterator it=iterations.begin();it!=iterations.end();it++)
+        oss << " - " << (*it).first.first << ", " << (*it).first.second << " (" << (*it).second << ")" << std::endl;
+      throw INTERP_KERNEL::Exception(oss.str());
+    }
+  return ReadField(fileName,fieldName,iterations[0].first.first,iterations[0].first.second);
+}
+
+MCAuto<MEDCoupling::MEDCouplingField> MEDCoupling::ReadField(const std::string& fileName, const std::string& fieldName, int iteration, int order)
+{
+  MCAuto<MEDFileAnyTypeField1TS> f(MEDFileAnyTypeField1TS::New(fileName,fieldName,iteration,order));
+  MCAuto<MEDFileMesh> mesh(MEDFileMesh::New(fileName,f->getMeshName()));
+  {
+    MCAuto<MEDFileField1TS> f1(MEDCoupling::DynamicCast<MEDFileAnyTypeField1TS,MEDFileField1TS>(f));
+    if(f1.isNotNull())
+      {
+        MCAuto<MEDCoupling::MEDCouplingFieldDouble> ret(f1->field(mesh));
+        return MEDCoupling::DynamicCast<MEDCouplingFieldDouble,MEDCouplingField>(ret);
+      }
+  }
+  {
+    MCAuto<MEDFileIntField1TS> f1(MEDCoupling::DynamicCast<MEDFileAnyTypeField1TS,MEDFileIntField1TS>(f));
+    if(f1.isNotNull())
+      {
+        MCAuto<MEDCoupling::MEDCouplingFieldInt> ret(f1->field(mesh));
+        return MEDCoupling::DynamicCast<MEDCouplingFieldInt,MEDCouplingField>(ret);
+      }
+  }
+  {
+    MCAuto<MEDFileFloatField1TS> f1(MEDCoupling::DynamicCast<MEDFileAnyTypeField1TS,MEDFileFloatField1TS>(f));
+    if(f1.isNotNull())
+      {
+        MCAuto<MEDCoupling::MEDCouplingFieldFloat> ret(f1->field(mesh));
+        return MEDCoupling::DynamicCast<MEDCouplingFieldFloat,MEDCouplingField>(ret);
+      }
+  }
+  throw INTERP_KERNEL::Exception("MEDCoupling::ReadField : only FLOAT32, FLOAT64 and INT32 supported for the moment !");
+}
+
+MCAuto<MEDCoupling::MEDCouplingField> MEDCoupling::ReadField(MEDCoupling::TypeOfField type, const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName, int iteration, int order)
 {
   MEDCoupling::CheckFileForRead(fileName);
   switch(type)
@@ -1209,97 +1314,139 @@ std::vector<MEDCoupling::MEDCouplingFieldDouble *> MEDCoupling::ReadFieldsGaussN
   return ReadFieldsOnSameMesh(ON_GAUSS_NE,fileName,meshName,meshDimRelToMax,fieldName,its);
 }
 
-MEDCoupling::MEDCouplingFieldDouble *MEDCoupling::ReadFieldCell(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName, int iteration, int order)
+namespace MEDCoupling
 {
-  MCAuto<MEDFileField1TS> ff(MEDFileField1TS::New(fileName,fieldName,iteration,order));
-  MCAuto<MEDFileMesh> mm(MEDFileMesh::New(fileName,meshName));
-  MCAuto<MEDCouplingMesh> m(mm->getMeshAtLevel(meshDimRelToMax,false));
-  MEDFileMesh *mPtr(mm);
-  MEDFileUMesh *muPtr=dynamic_cast<MEDFileUMesh *>(mPtr);
-  MCAuto<MEDCouplingFieldDouble> ret(ff->getFieldOnMeshAtLevel(ON_CELLS,m));
-  if(muPtr)
-    {
-      const DataArrayInt *num(muPtr->getNumberFieldAtLevel(meshDimRelToMax));
-      if(num)
-        ret->renumberCells(num->begin());
-    }
-  return ret.retn();
-}
+  template<class T>
+  MCAuto<typename Traits<T>::FieldType> ReadFieldCellLikeT(typename MLFieldTraits<T>::F1TSType *ff, MEDCoupling::TypeOfField type, const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName, int iteration, int order)
+  {
+    MCAuto<MEDFileMesh> mm(MEDFileMesh::New(fileName,meshName));
+    MCAuto<MEDFileUMesh> muPtr(MEDCoupling::DynamicCast<MEDFileMesh,MEDFileUMesh>(mm));
+    MCAuto<MEDCouplingMesh> m(mm->getMeshAtLevel(meshDimRelToMax,false));
+    MCAuto<typename Traits<T>::FieldType> ret(ff->getFieldOnMeshAtLevel(type,m));
+    if(muPtr.isNotNull())
+      {
+        const DataArrayInt *num(muPtr->getNumberFieldAtLevel(meshDimRelToMax));
+        if(num)
+          ret->renumberCells(num->begin());
+      }
+    return ret;
+  }
 
-MEDCoupling::MEDCouplingFieldDouble *MEDCoupling::ReadFieldNode(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName, int iteration, int order)
-{
-  MCAuto<MEDFileField1TS> ff(MEDFileField1TS::New(fileName,fieldName,iteration,order));
-  MCAuto<MEDFileMesh> mm(MEDFileMesh::New(fileName,meshName));
-  MCAuto<MEDCouplingMesh> m(mm->getMeshAtLevel(meshDimRelToMax,false));
-  MEDFileMesh *mPtr(mm);
-  MCAuto<MEDCouplingFieldDouble> ret(ff->getFieldOnMeshAtLevel(ON_NODES,m));
-  MEDFileUMesh *muPtr=dynamic_cast<MEDFileUMesh *>(mPtr);
-  if(ff->getPflsReallyUsed().empty())
+  MEDCoupling::MEDCouplingField *ReadFieldCellLike(MEDCoupling::TypeOfField type, const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName, int iteration, int order)
+  {
+    MCAuto<MEDFileAnyTypeField1TS> f(MEDFileAnyTypeField1TS::New(fileName,fieldName,iteration,order));
     {
-      if(muPtr)
+      MCAuto<MEDFileField1TS> f1(MEDCoupling::DynamicCast<MEDFileAnyTypeField1TS,MEDFileField1TS>(f));
+      if(f1.isNotNull())
         {
-          const DataArrayInt *num(muPtr->getNumberFieldAtLevel(meshDimRelToMax));
-          if(num)
-            ret->renumberCells(num->begin());
+          MCAuto<MEDCoupling::MEDCouplingFieldDouble> ret(ReadFieldCellLikeT<double>(f1,type,fileName,meshName,meshDimRelToMax,fieldName,iteration,order));
+          return ret.retn();
         }
     }
-  else
     {
-      DataArrayInt *pfl=0,*arr2=0;
-      MCAuto<DataArrayDouble> arr(ff->getFieldWithProfile(ON_NODES,meshDimRelToMax,mm,pfl));
-      MCAuto<DataArrayInt> pflSafe(pfl);
-      MCAuto<DataArrayInt> mp(m->getCellIdsFullyIncludedInNodeIds(pfl->begin(),pfl->end()));
-      MCAuto<MEDCouplingUMesh> mzip(static_cast<MEDCouplingUMesh *>(m->buildPartAndReduceNodes(mp->begin(),mp->end(),arr2)));
-      MCAuto<DataArrayInt> arr2Safe(arr2);
-      MCAuto<DataArrayInt> arr3(arr2->invertArrayO2N2N2O(mzip->getNumberOfNodes()));
-      MCAuto<DataArrayInt> pflSorted(pflSafe->deepCopy()); pflSorted->sort(true);
-      if(!arr3->isEqualWithoutConsideringStr(*pflSorted))
-        throw INTERP_KERNEL::Exception("ReadFieldNode : not implemented yet !");
-      if(!arr3->isEqualWithoutConsideringStr(*pflSafe))
+      MCAuto<MEDFileIntField1TS> f1(MEDCoupling::DynamicCast<MEDFileAnyTypeField1TS,MEDFileIntField1TS>(f));
+      if(f1.isNotNull())
         {
-          MCAuto<DataArrayInt> o2n2(pflSafe->checkAndPreparePermutation());
-          MCAuto<DataArrayInt> n2o2(o2n2->invertArrayO2N2N2O(o2n2->getNumberOfTuples()));
-          mzip->renumberNodes(n2o2->begin(),n2o2->getNumberOfTuples());
-          arr->setName("");
-          ret->setArray(arr);
+          MCAuto<MEDCoupling::MEDCouplingFieldInt> ret(ReadFieldCellLikeT<int>(f1,type,fileName,meshName,meshDimRelToMax,fieldName,iteration,order));
+          return ret.retn();
         }
-      ret->setMesh(mzip);
     }
-  return ret.retn();
+    {
+      MCAuto<MEDFileFloatField1TS> f1(MEDCoupling::DynamicCast<MEDFileAnyTypeField1TS,MEDFileFloatField1TS>(f));
+      if(f1.isNotNull())
+        {
+          MCAuto<MEDCoupling::MEDCouplingFieldFloat> ret(ReadFieldCellLikeT<float>(f1,type,fileName,meshName,meshDimRelToMax,fieldName,iteration,order));
+          return ret.retn();
+        }
+    }
+    throw INTERP_KERNEL::Exception("MEDCoupling::ReadFieldCell : only FLOAT32, FLOAT64 and INT32 supported for the moment !");
+  }
+
+  template<class T>
+  MCAuto<typename Traits<T>::FieldType> ReadFieldNodeT(typename MLFieldTraits<T>::F1TSType *ff, const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName, int iteration, int order)
+  {
+    MCAuto<MEDFileMesh> mm(MEDFileMesh::New(fileName,meshName));
+    MCAuto<MEDCouplingMesh> m(mm->getMeshAtLevel(meshDimRelToMax,false));
+    MCAuto<typename Traits<T>::FieldType> ret(ff->getFieldOnMeshAtLevel(ON_NODES,m));
+    MCAuto<MEDFileUMesh> muPtr(MEDCoupling::DynamicCast<MEDFileMesh,MEDFileUMesh>(mm));
+    if(ff->getPflsReallyUsed().empty())
+      {
+        if(muPtr.isNotNull())
+          {
+            const DataArrayInt *num(muPtr->getNumberFieldAtLevel(meshDimRelToMax));
+            if(num)
+              ret->renumberCells(num->begin());
+          }
+      }
+    else
+      {
+        DataArrayInt *pfl(nullptr),*arr2(nullptr);
+        MCAuto<typename Traits<T>::ArrayType> arr(ff->getFieldWithProfile(ON_NODES,meshDimRelToMax,mm,pfl));
+        MCAuto<DataArrayInt> pflSafe(pfl);
+        MCAuto<DataArrayInt> mp(m->getCellIdsFullyIncludedInNodeIds(pfl->begin(),pfl->end()));
+        MCAuto<MEDCouplingUMesh> mzip(static_cast<MEDCouplingUMesh *>(m->buildPartAndReduceNodes(mp->begin(),mp->end(),arr2)));
+        MCAuto<DataArrayInt> arr2Safe(arr2);
+        MCAuto<DataArrayInt> arr3(arr2->invertArrayO2N2N2O(mzip->getNumberOfNodes()));
+        MCAuto<DataArrayInt> pflSorted(pflSafe->deepCopy()); pflSorted->sort(true);
+        if(!arr3->isEqualWithoutConsideringStr(*pflSorted))
+          throw INTERP_KERNEL::Exception("ReadFieldNode : not implemented yet !");
+        if(!arr3->isEqualWithoutConsideringStr(*pflSafe))
+          {
+            MCAuto<DataArrayInt> o2n2(pflSafe->checkAndPreparePermutation());
+            MCAuto<DataArrayInt> n2o2(o2n2->invertArrayO2N2N2O(o2n2->getNumberOfTuples()));
+            mzip->renumberNodes(n2o2->begin(),n2o2->getNumberOfTuples());
+            arr->setName("");
+            ret->setArray(arr);
+          }
+        ret->setMesh(mzip);
+      }
+    return ret;
+  }
 }
 
-MEDCoupling::MEDCouplingFieldDouble *MEDCoupling::ReadFieldGauss(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName, int iteration, int order)
+MEDCoupling::MEDCouplingField *MEDCoupling::ReadFieldCell(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName, int iteration, int order)
 {
-  MCAuto<MEDFileField1TS> ff(MEDFileField1TS::New(fileName,fieldName,iteration,order));
-  MCAuto<MEDFileMesh> mm(MEDFileMesh::New(fileName,meshName));
-  MCAuto<MEDCouplingMesh> m(mm->getMeshAtLevel(meshDimRelToMax,false));
-  MEDFileMesh *mPtr(mm);
-  MEDFileUMesh *muPtr=dynamic_cast<MEDFileUMesh *>(mPtr);
-  MCAuto<MEDCouplingFieldDouble> ret(ff->getFieldOnMeshAtLevel(ON_GAUSS_PT,m));
-  if(muPtr)
-    {
-      const DataArrayInt *num(muPtr->getNumberFieldAtLevel(meshDimRelToMax));
-      if(num)
-        ret->renumberCells(num->begin());
-    }
-  return ret.retn();
+  return ReadFieldCellLike(ON_CELLS,fileName,meshName,meshDimRelToMax,fieldName,iteration,order);
 }
 
-MEDCoupling::MEDCouplingFieldDouble *MEDCoupling::ReadFieldGaussNE(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName, int iteration, int order)
+MEDCoupling::MEDCouplingField *MEDCoupling::ReadFieldNode(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName, int iteration, int order)
 {
-  MCAuto<MEDFileField1TS> ff(MEDFileField1TS::New(fileName,fieldName,iteration,order));
-  MCAuto<MEDFileMesh> mm(MEDFileMesh::New(fileName,meshName));
-  MCAuto<MEDCouplingMesh> m(mm->getMeshAtLevel(meshDimRelToMax,false));
-  MEDFileMesh *mPtr(mm);
-  MEDFileUMesh *muPtr=dynamic_cast<MEDFileUMesh *>(mPtr);
-  MCAuto<MEDCouplingFieldDouble> ret(ff->getFieldOnMeshAtLevel(ON_GAUSS_NE,m));
-  if(muPtr)
-    {
-      const DataArrayInt *num(muPtr->getNumberFieldAtLevel(meshDimRelToMax));
-      if(num)
-        ret->renumberCells(num->begin());
-    }
-  return ret.retn();
+  MCAuto<MEDFileAnyTypeField1TS> f(MEDFileAnyTypeField1TS::New(fileName,fieldName,iteration,order));
+  {
+    MCAuto<MEDFileField1TS> f1(MEDCoupling::DynamicCast<MEDFileAnyTypeField1TS,MEDFileField1TS>(f));
+    if(f1.isNotNull())
+      {
+        MCAuto<MEDCoupling::MEDCouplingFieldDouble> ret(ReadFieldNodeT<double>(f1,fileName,meshName,meshDimRelToMax,fieldName,iteration,order));
+        return ret.retn();
+      }
+  }
+  {
+    MCAuto<MEDFileIntField1TS> f1(MEDCoupling::DynamicCast<MEDFileAnyTypeField1TS,MEDFileIntField1TS>(f));
+    if(f1.isNotNull())
+      {
+        MCAuto<MEDCoupling::MEDCouplingFieldInt> ret(ReadFieldNodeT<int>(f1,fileName,meshName,meshDimRelToMax,fieldName,iteration,order));
+        return ret.retn();
+      }
+  }
+  {
+    MCAuto<MEDFileFloatField1TS> f1(MEDCoupling::DynamicCast<MEDFileAnyTypeField1TS,MEDFileFloatField1TS>(f));
+    if(f1.isNotNull())
+      {
+        MCAuto<MEDCoupling::MEDCouplingFieldFloat> ret(ReadFieldNodeT<float>(f1,fileName,meshName,meshDimRelToMax,fieldName,iteration,order));
+        return ret.retn();
+      }
+  }
+  throw INTERP_KERNEL::Exception("MEDCoupling::ReadFieldNode : only FLOAT32, FLOAT64 and INT32 supported for the moment !");
+}
+
+MEDCoupling::MEDCouplingField *MEDCoupling::ReadFieldGauss(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName, int iteration, int order)
+{
+  return ReadFieldCellLike(ON_GAUSS_PT,fileName,meshName,meshDimRelToMax,fieldName,iteration,order);
+}
+
+MEDCoupling::MEDCouplingField *MEDCoupling::ReadFieldGaussNE(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName, int iteration, int order)
+{
+  return ReadFieldCellLike(ON_GAUSS_NE,fileName,meshName,meshDimRelToMax,fieldName,iteration,order);
 }
 
 void MEDCoupling::WriteMesh(const std::string& fileName, const MEDCoupling::MEDCouplingMesh *mesh, bool writeFromScratch)
@@ -1386,25 +1533,26 @@ void MEDCoupling::WriteUMeshesPartitionDep(const std::string& fileName, const st
 
 void MEDCoupling::WriteUMeshes(const std::string& fileName, const std::vector<const MEDCoupling::MEDCouplingUMesh *>& meshes, bool writeFromScratch)
 {
-  int mod=writeFromScratch?2:0;
+  int mod(writeFromScratch?2:0);
   MCAuto<MEDFileUMesh> m(MEDFileUMesh::New());
   AssignStaticWritePropertiesTo(*m);
   m->setMeshes(meshes,true);
   m->write(fileName,mod);
 }
 
-void MEDLoaderNS::writeFieldWithoutReadingAndMappingOfMeshInFile(const std::string& fileName, const MEDCoupling::MEDCouplingFieldDouble *f, bool writeFromScratch)
+template<class T>
+void MEDLoaderNS::writeFieldWithoutReadingAndMappingOfMeshInFile(const std::string& fileName, const typename MEDCoupling::Traits<T>::FieldType *f, bool writeFromScratch)
 {
-  MCAuto<MEDFileField1TS> ff(MEDFileField1TS::New());
+  MCAuto< typename MLFieldTraits<T>::F1TSType > ff(MLFieldTraits<T>::F1TSType::New());
   AssignStaticWritePropertiesTo(*ff);
-  MCAuto<MEDCouplingFieldDouble> f2(f->deepCopy());
+  MCAuto<typename MEDCoupling::Traits<T>::FieldType> f2(f->deepCopy());
   const MEDCouplingMesh *m(f2->getMesh());
   const MEDCouplingUMesh *um(dynamic_cast<const MEDCouplingUMesh *>(m));
   const MEDCoupling1GTUMesh *um2(dynamic_cast<const MEDCoupling1GTUMesh *>(m));
   const MEDCouplingCMesh *um3(dynamic_cast<const MEDCouplingCMesh *>(m));
   const MEDCouplingCurveLinearMesh *um4(dynamic_cast<const MEDCouplingCurveLinearMesh *>(m));
   MCAuto<MEDFileMesh> mm;
-  int mod=writeFromScratch?2:0;
+  int mod(writeFromScratch?2:0);
   if(um)
     {
       MCAuto<MEDFileUMesh> mmu(MEDFileUMesh::New());
@@ -1446,12 +1594,13 @@ void MEDLoaderNS::writeFieldWithoutReadingAndMappingOfMeshInFile(const std::stri
   ff->write(fileName,0);
 }
 
-void MEDCoupling::WriteField(const std::string& fileName, const MEDCoupling::MEDCouplingFieldDouble *f, bool writeFromScratch)
+template<class T>
+void WriteFieldT(const std::string& fileName, const typename MEDCoupling::Traits<T>::FieldType *f, bool writeFromScratch)
 {
   if(!f)
     throw INTERP_KERNEL::Exception("WriteField : input field is NULL !");
   f->checkConsistencyLight();
-  int status=MEDLoaderBase::getStatusOfFile(fileName);
+  int status(MEDLoaderBase::getStatusOfFile(fileName));
   if(status!=MEDLoaderBase::EXIST_RW && status!=MEDLoaderBase::NOT_EXIST)
     {
       std::ostringstream oss; oss << "File with name \'" << fileName << "\' has not valid permissions !";
@@ -1459,44 +1608,47 @@ void MEDCoupling::WriteField(const std::string& fileName, const MEDCoupling::MED
     }
   if(writeFromScratch || (!writeFromScratch && status==MEDLoaderBase::NOT_EXIST))
     {
-      MEDLoaderNS::writeFieldWithoutReadingAndMappingOfMeshInFile(fileName,f,true);
+      MEDLoaderNS::writeFieldWithoutReadingAndMappingOfMeshInFile<T>(fileName,f,true);
     }
   else
     {
-      std::vector<std::string> meshNames=GetMeshNames(fileName);
+      std::vector<std::string> meshNames(GetMeshNames(fileName));
       if(!f->getMesh())
         throw INTERP_KERNEL::Exception("WriteField : trying to write a field with no mesh !");
       std::string fileNameCpp(f->getMesh()->getName());
       if(std::find(meshNames.begin(),meshNames.end(),fileNameCpp)==meshNames.end())
-        MEDLoaderNS::writeFieldWithoutReadingAndMappingOfMeshInFile(fileName,f,false);
+        MEDLoaderNS::writeFieldWithoutReadingAndMappingOfMeshInFile<T>(fileName,f,false);
       else
         {
           MCAuto<MEDFileMesh> mm(MEDFileMesh::New(fileName,f->getMesh()->getName().c_str()));
           AssignStaticWritePropertiesTo(*mm);
           const MEDFileMesh *mmPtr(mm);
-          const MEDFileUMesh *mmuPtr=dynamic_cast<const MEDFileUMesh *>(mmPtr);
+          const MEDFileUMesh *mmuPtr(dynamic_cast<const MEDFileUMesh *>(mmPtr));
           if(!mmuPtr)
             throw INTERP_KERNEL::Exception("WriteField : only umeshes are supported now !");
-          MCAuto<MEDCouplingFieldDouble> f2(f->deepCopy());
-          MEDCouplingUMesh *m=dynamic_cast<MEDCouplingUMesh *>(const_cast<MEDCouplingMesh *>(f2->getMesh()));
+          MCAuto< typename MEDCoupling::Traits<T>::FieldType > f2(f->deepCopy());
+          MEDCouplingUMesh *m(dynamic_cast<MEDCouplingUMesh *>(const_cast<MEDCouplingMesh *>(f2->getMesh())));
           if(!m)
             throw INTERP_KERNEL::Exception("WriteField : only umesh in input field supported !");
-          MCAuto<DataArrayInt> o2n=m->getRenumArrForMEDFileFrmt();
+          MCAuto<DataArrayInt> o2n(m->getRenumArrForMEDFileFrmt());
           f2->renumberCells(o2n->begin(),false);
           m=static_cast<MEDCouplingUMesh *>(const_cast<MEDCouplingMesh *>(f2->getMesh()));
-          MCAuto<MEDCouplingUMesh> mread=mmuPtr->getMeshAtLevel(m->getMeshDimension()-mm->getMeshDimension());
+          MCAuto<MEDCouplingUMesh> mread(mmuPtr->getMeshAtLevel(m->getMeshDimension()-mm->getMeshDimension()));
           if(f2->getTypeOfField()!=ON_NODES)
             {
-              m->tryToShareSameCoordsPermute(*mread,_EPS_FOR_NODE_COMP);
-              DataArrayInt *part=0;
-              bool b=mread->areCellsIncludedIn(m,_COMP_FOR_CELL,part);
+              if(!m->getCoords()->isEqualWithoutConsideringStr(*mread->getCoords(),_EPS_FOR_NODE_COMP))
+                m->tryToShareSameCoordsPermute(*mread,_EPS_FOR_NODE_COMP);
+              else
+                mread->setCoords(m->getCoords());
+              DataArrayInt *part(NULL);
+              bool b(mread->areCellsIncludedIn(m,_COMP_FOR_CELL,part));
               MCAuto<DataArrayInt> partSafe(part);
               if(!b)
                 {
                   std::ostringstream oss; oss << "WriteField : The file \""<< fileName << "\" already contains a mesh named \""<< f->getMesh()->getName() << "\" and this mesh in the file is not compatible (a subpart) with the mesh you intend to write ! This is maybe due to a too strict policy ! Try with to lease it by calling SetCompPolicyForCell !";
                   throw INTERP_KERNEL::Exception(oss.str().c_str());
                 }
-              MCAuto<MEDFileField1TS> f1ts(MEDFileField1TS::New());
+              MCAuto< typename MLFieldTraits<T>::F1TSType > f1ts(MLFieldTraits<T>::F1TSType::New());
               AssignStaticWritePropertiesTo(*f1ts);
               if(part->isIota(mread->getNumberOfCells()))
                 f1ts->setFieldNoProfileSBT(f2);
@@ -1510,15 +1662,15 @@ void MEDCoupling::WriteField(const std::string& fileName, const MEDCoupling::MED
             }
           else
             {
-              DataArrayInt *part=0;
-              bool b=mread->getCoords()->areIncludedInMe(m->getCoords(),_EPS_FOR_NODE_COMP,part);
+              DataArrayInt *part(NULL);
+              bool b(mread->getCoords()->areIncludedInMe(m->getCoords(),_EPS_FOR_NODE_COMP,part));
               MCAuto<DataArrayInt> partSafe(part);
               if(!b)
                 {
                   std::ostringstream oss; oss << "WriteField : The file \""<< fileName << "\" already contains a mesh named \""<< f->getMesh()->getName() << "\" and this mesh in the file is not compatible (a subpart regarding nodes) with the mesh you intend to write ! This is maybe due to a too strict epsilon ! Try with to lease it by calling SetEpsilonForNodeComp !";
                   throw INTERP_KERNEL::Exception(oss.str().c_str());
                 }
-              MCAuto<MEDFileField1TS> f1ts(MEDFileField1TS::New());
+              MCAuto< typename MLFieldTraits<T>::F1TSType > f1ts(MLFieldTraits<T>::F1TSType::New());
               AssignStaticWritePropertiesTo(*f1ts);
               if(part->isIota(mread->getNumberOfNodes()))
                 f1ts->setFieldNoProfileSBT(f2);
@@ -1533,29 +1685,61 @@ void MEDCoupling::WriteField(const std::string& fileName, const MEDCoupling::MED
     }
 }
 
-void MEDCoupling::WriteFieldDep(const std::string& fileName, const MEDCoupling::MEDCouplingFieldDouble *f, bool writeFromScratch)
+void MEDCoupling::WriteField(const std::string& fileName, const MEDCoupling::MEDCouplingField *f, bool writeFromScratch)
+{
+  if(!f)
+    throw INTERP_KERNEL::Exception("WriteField : input field is null !");
+  {
+    const MEDCoupling::MEDCouplingFieldDouble *f1(dynamic_cast<const MEDCoupling::MEDCouplingFieldDouble *>(f));
+    if(f1)
+      {
+        WriteFieldT<double>(fileName,f1,writeFromScratch);
+        return ;
+      }
+  }
+  {
+    const MEDCoupling::MEDCouplingFieldInt *f1(dynamic_cast<const MEDCoupling::MEDCouplingFieldInt *>(f));
+    if(f1)
+      {
+        WriteFieldT<int>(fileName,f1,writeFromScratch);
+        return ;
+      }
+  }
+  {
+    const MEDCoupling::MEDCouplingFieldFloat *f1(dynamic_cast<const MEDCoupling::MEDCouplingFieldFloat *>(f));
+    if(f1)
+      {
+        WriteFieldT<float>(fileName,f1,writeFromScratch);
+        return ;
+      }
+  }
+  throw INTERP_KERNEL::Exception("WriteField : input field is not in FLOAT32, FLOAT64, INT32 !");
+}
+
+void MEDCoupling::WriteFieldDep(const std::string& fileName, const MEDCoupling::MEDCouplingField *f, bool writeFromScratch)
 {
   WriteField(fileName,f,writeFromScratch);
 }
 
-void MEDCoupling::WriteFieldUsingAlreadyWrittenMesh(const std::string& fileName, const MEDCoupling::MEDCouplingFieldDouble *f)
+template<class T>
+void WriteFieldUsingAlreadyWrittenMeshT(const std::string& fileName, const typename MEDCoupling::Traits<T>::FieldType *f)
 {
   if(!f)
-    throw INTERP_KERNEL::Exception("WriteFieldUsingAlreadyWrittenMesh : input field is null !");
+    throw INTERP_KERNEL::Exception("WriteFieldUsingAlreadyWrittenMeshT : input field is null !");
   f->checkConsistencyLight();
-  int status=MEDLoaderBase::getStatusOfFile(fileName);
+  int status(MEDLoaderBase::getStatusOfFile(fileName));
   if(status!=MEDLoaderBase::EXIST_RW)
     {
       std::ostringstream oss; oss << "File with name \'" << fileName << "\' has not valid permissions or not exists !";
       throw INTERP_KERNEL::Exception(oss.str().c_str());
     }
-  MCAuto<MEDFileField1TS> f1ts(MEDFileField1TS::New());
+  MCAuto< typename MLFieldTraits<T>::F1TSType > f1ts(MLFieldTraits<T>::F1TSType::New());
   AssignStaticWritePropertiesTo(*f1ts);
   MEDCouplingUMesh *m(dynamic_cast<MEDCouplingUMesh *>(const_cast<MEDCouplingMesh *>(f->getMesh())));
   if(m)
     {
       MCAuto<DataArrayInt> o2n(m->getRenumArrForMEDFileFrmt());
-      MCAuto<MEDCouplingFieldDouble> f2(f->deepCopy());
+      MCAuto< typename MEDCoupling::Traits<T>::FieldType > f2(f->deepCopy());
       f2->renumberCells(o2n->begin(),false);
       f1ts->setFieldNoProfileSBT(f2);
     }
@@ -1563,3 +1747,28 @@ void MEDCoupling::WriteFieldUsingAlreadyWrittenMesh(const std::string& fileName,
     f1ts->setFieldNoProfileSBT(f);
   f1ts->write(fileName,0);
 }
+
+void MEDCoupling::WriteFieldUsingAlreadyWrittenMesh(const std::string& fileName, const MEDCoupling::MEDCouplingField *f)
+{
+  if(!f)
+    throw INTERP_KERNEL::Exception("WriteFieldUsingAlreadyWrittenMesh : input field is null !");
+  {
+    const MEDCoupling::MEDCouplingFieldDouble *f1(dynamic_cast<const MEDCoupling::MEDCouplingFieldDouble *>(f));
+    if(f1)
+      WriteFieldUsingAlreadyWrittenMeshT<double>(fileName,f1);
+    return ;
+  }
+  {
+    const MEDCoupling::MEDCouplingFieldInt *f1(dynamic_cast<const MEDCoupling::MEDCouplingFieldInt *>(f));
+    if(f1)
+      WriteFieldUsingAlreadyWrittenMeshT<int>(fileName,f1);
+    return ;
+  }
+  {
+    const MEDCoupling::MEDCouplingFieldFloat *f1(dynamic_cast<const MEDCoupling::MEDCouplingFieldFloat *>(f));
+    if(f1)
+      WriteFieldUsingAlreadyWrittenMeshT<float>(fileName,f1);
+    return ;
+  }
+  throw INTERP_KERNEL::Exception("WriteFieldUsingAlreadyWrittenMesh : input field is not in FLOAT32, FLOAT64, INT32 !");
+}