]> SALOME platform Git repositories - tools/medcoupling.git/commitdiff
Salome HOME
Overload of MEDLoader.ReadField method to ease access of medcoupling for new comers
authorAnthony Geay <anthony.geay@edf.fr>
Mon, 6 Mar 2017 07:43:13 +0000 (08:43 +0100)
committerAnthony Geay <anthony.geay@edf.fr>
Tue, 7 Mar 2017 16:34:19 +0000 (17:34 +0100)
src/MEDLoader/MEDLoader.cxx
src/MEDLoader/MEDLoader.hxx
src/MEDLoader/Swig/MEDLoaderCommon.i
src/MEDLoader/Swig/MEDLoaderTest1.py
src/MEDLoader/Test/MEDLoaderTest.cxx

index 61ee8bbc2bdecc8b014297731a3d2129d0c3a91f..e9069171676bd8e1ab0d33de49ac02280e82f76b 100644 (file)
@@ -1153,19 +1153,73 @@ 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::MEDCouplingFieldDouble> 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::MEDCouplingFieldDouble> 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::MEDCouplingFieldDouble> MEDCoupling::ReadField(const std::string& fileName, const std::string& fieldName, int iteration, int order)
+{
+  MCAuto<MEDFileField1TS> f(MEDFileField1TS::New(fileName,fieldName,iteration,order));
+  MCAuto<MEDFileMesh> mesh(MEDFileMesh::New(fileName,f->getMeshName()));
+  MCAuto<MEDCoupling::MEDCouplingFieldDouble> ret(f->field(mesh));
+  return ret;
+}
+
+MCAuto<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)
 {
   MEDCoupling::CheckFileForRead(fileName);
   switch(type)
   {
     case ON_CELLS:
-      return ReadFieldCell(fileName,meshName,meshDimRelToMax,fieldName,iteration,order);
+      return MCAuto<MEDCoupling::MEDCouplingFieldDouble>(ReadFieldCell(fileName,meshName,meshDimRelToMax,fieldName,iteration,order));
     case ON_NODES:
-      return ReadFieldNode(fileName,meshName,meshDimRelToMax,fieldName,iteration,order);
+      return MCAuto<MEDCoupling::MEDCouplingFieldDouble>(ReadFieldNode(fileName,meshName,meshDimRelToMax,fieldName,iteration,order));
     case ON_GAUSS_PT:
-      return ReadFieldGauss(fileName,meshName,meshDimRelToMax,fieldName,iteration,order);
+      return MCAuto<MEDCoupling::MEDCouplingFieldDouble>(ReadFieldGauss(fileName,meshName,meshDimRelToMax,fieldName,iteration,order));
     case ON_GAUSS_NE:
-      return ReadFieldGaussNE(fileName,meshName,meshDimRelToMax,fieldName,iteration,order);
+      return MCAuto<MEDCoupling::MEDCouplingFieldDouble>(ReadFieldGaussNE(fileName,meshName,meshDimRelToMax,fieldName,iteration,order));
     default:
       throw INTERP_KERNEL::Exception("Type of field specified not managed ! manages are ON_NODES, ON_CELLS, ON_GAUSS_PT or ON_GAUSS_NE !");
   }
index a8c5eafed4021b8bca3f5d9b0505a8093aba63ef..ab1732fe4b9a2e2705043df873d0713af608f58b 100644 (file)
@@ -25,6 +25,7 @@
 #include "InterpKernelException.hxx"
 #include "MEDCouplingRefCountObject.hxx"
 #include "NormalizedUnstructuredMesh.hxx"
+#include "MCAuto.hxx"
 
 #include <list>
 #include <vector>
@@ -71,7 +72,10 @@ namespace MEDCoupling
   MEDLOADER_EXPORT MEDCoupling::MEDCouplingUMesh *ReadUMeshFromFile(const std::string& fileName, const std::string& meshName, int meshDimRelToMax=0);
   MEDLOADER_EXPORT MEDCoupling::MEDCouplingUMesh *ReadUMeshFromFile(const std::string& fileName, int meshDimRelToMax=0);
   MEDLOADER_EXPORT int ReadUMeshDimFromFile(const std::string& fileName, const std::string& meshName);
-  MEDLOADER_EXPORT MEDCoupling::MEDCouplingFieldDouble *ReadField(MEDCoupling::TypeOfField type, const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName, int iteration, int order);
+  MEDLOADER_EXPORT MCAuto<MEDCoupling::MEDCouplingFieldDouble> ReadField(const std::string& fileName);
+  MEDLOADER_EXPORT MCAuto<MEDCoupling::MEDCouplingFieldDouble> ReadField(const std::string& fileName, const std::string& fieldName);
+  MEDLOADER_EXPORT MCAuto<MEDCoupling::MEDCouplingFieldDouble> ReadField(const std::string& fileName, const std::string& fieldName, int iteration, int order);
+  MEDLOADER_EXPORT MCAuto<MEDCoupling::MEDCouplingFieldDouble> ReadField(MEDCoupling::TypeOfField type, const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName, int iteration, int order);
   MEDLOADER_EXPORT std::vector<MEDCoupling::MEDCouplingFieldDouble *> ReadFieldsOnSameMesh(MEDCoupling::TypeOfField type, const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName,
                                                                                            const std::vector<std::pair<int,int> >& its);
   MEDLOADER_EXPORT std::vector<MEDCoupling::MEDCouplingFieldDouble *> ReadFieldsCellOnSameMesh(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName,
index de7f087a4a5cd1d98bd3c7395c06bfe24fb741dd..3725a37ba68d794e51ce7d4eaeead7770d5ef969 100644 (file)
@@ -77,9 +77,9 @@ using namespace MEDCoupling;
 
 %newobject ReadUMeshFromFamiliesSwig;
 %newobject ReadUMeshFromGroupsSwig;
+%newobject ReadFieldSwig;
 %newobject MEDCoupling::ReadUMeshFromFile;
 %newobject MEDCoupling::ReadMeshFromFile;
-%newobject MEDCoupling::ReadField;
 %newobject MEDCoupling::ReadFieldCell;
 %newobject MEDCoupling::ReadFieldNode;
 %newobject MEDCoupling::ReadFieldGauss;
@@ -332,7 +332,6 @@ namespace MEDCoupling
   MEDCoupling::MEDCouplingUMesh *ReadUMeshFromFile(const std::string& fileName, const std::string& meshName, int meshDimRelToMax=0) throw(INTERP_KERNEL::Exception);
   MEDCoupling::MEDCouplingUMesh *ReadUMeshFromFile(const std::string& fileName, int meshDimRelToMax=0) throw(INTERP_KERNEL::Exception);
   int ReadUMeshDimFromFile(const std::string& fileName, const std::string& meshName) throw(INTERP_KERNEL::Exception);
-  MEDCoupling::MEDCouplingFieldDouble *ReadField(MEDCoupling::TypeOfField type, const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName, int iteration, int order) throw(INTERP_KERNEL::Exception);
   MEDCoupling::MEDCouplingFieldDouble *ReadFieldCell(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName, int iteration, int order) throw(INTERP_KERNEL::Exception);
   MEDCoupling::MEDCouplingFieldDouble *ReadFieldNode(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName, int iteration, int order) throw(INTERP_KERNEL::Exception);
   MEDCoupling::MEDCouplingFieldDouble *ReadFieldGauss(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName, int iteration, int order) throw(INTERP_KERNEL::Exception);
@@ -359,6 +358,7 @@ namespace MEDCoupling
 %rename (GetTypesOfField) GetTypesOfFieldSwig;
 %rename (ReadUMeshFromGroups) ReadUMeshFromGroupsSwig;
 %rename (ReadUMeshFromFamilies) ReadUMeshFromFamiliesSwig;
+%rename (ReadField) ReadFieldSwig;
 
 %inline
 {
@@ -373,6 +373,30 @@ namespace MEDCoupling
     return ret;
   }
 
+  MEDCoupling::MEDCouplingFieldDouble *ReadFieldSwig(const std::string& fileName) throw(INTERP_KERNEL::Exception)
+  {
+    MCAuto<MEDCoupling::MEDCouplingFieldDouble> ret(MEDCoupling::ReadField(fileName));
+    return ret.retn();
+  }
+
+  MEDCoupling::MEDCouplingFieldDouble *ReadFieldSwig(const std::string& fileName, const std::string& fieldName) throw(INTERP_KERNEL::Exception)
+  {
+    MCAuto<MEDCoupling::MEDCouplingFieldDouble> ret(MEDCoupling::ReadField(fileName,fieldName));
+    return ret.retn();
+  }
+  
+  MEDCoupling::MEDCouplingFieldDouble *ReadFieldSwig(const std::string& fileName, const std::string& fieldName, int iteration, int order) throw(INTERP_KERNEL::Exception)
+  {
+    MCAuto<MEDCoupling::MEDCouplingFieldDouble> ret(MEDCoupling::ReadField(fileName,fieldName,iteration,order));
+    return ret.retn();
+  }
+  
+  MEDCoupling::MEDCouplingFieldDouble *ReadFieldSwig(MEDCoupling::TypeOfField type, const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName, int iteration, int order) throw(INTERP_KERNEL::Exception)
+  {
+    MCAuto<MEDCoupling::MEDCouplingFieldDouble> ret(MEDCoupling::ReadField(type,fileName,meshName,meshDimRelToMax,fieldName,iteration,order));
+    return ret.retn();
+  }
+
   PyObject *GetFieldIterationsSwig(MEDCoupling::TypeOfField type, const std::string& fileName, const std::string& meshName, const std::string& fieldName) throw(INTERP_KERNEL::Exception)
   {
     std::vector< std::pair<int,int> > res=MEDCoupling::GetFieldIterations(type,fileName,meshName,fieldName);
index be8dba437e634a9c9aba1b8e4421a2837c266570..94f21b14ee74218ae46690cba3649926985d8a5f 100644 (file)
@@ -751,6 +751,127 @@ class MEDLoaderTest1(unittest.TestCase):
         self.assertTrue(f11.isEqual(f3r,1e-12,1e-12))
         self.assertTrue(f3r.getArray().isEqual(MEDLoader.DataArrayDouble([0.,4.,8.,12.,16.,20.,24.,28.,32.,36.,40.,44.,48.,52.,56.,60.,64.,68.,72.,76.]),1e-12))
         pass
+
+    def testEasyFieldRead1(self):
+        fname="Pyfile111.med"
+        arr=MEDLoader.DataArrayDouble(4) ; arr.iota()
+        m=MEDLoader.MEDCouplingCMesh() ; m.setCoords(arr,arr)
+        m=m.buildUnstructured()
+        m.setName("mesh")
+        f=MEDLoader.MEDCouplingFieldDouble(MEDLoader.ON_CELLS)
+        f.setName("field")
+        f.setTime(3.,1,2)
+        da=MEDLoader.DataArrayDouble([2,3,4,5,6,7,8,9,10])
+        f.setArray(da) ; f.setMesh(m)
+        MEDLoader.WriteField(fname,f,True)
+        #
+        self.assertTrue(f.isEqual(MEDLoader.ReadField(fname),1e-12,1e-12))
+        self.assertTrue(f.isEqual(MEDLoader.ReadField(fname,"field"),1e-12,1e-12))
+        self.assertTrue(f.isEqual(MEDLoader.ReadField(fname,"field",1,2),1e-12,1e-12))
+        self.assertTrue(f.isEqual(MEDLoader.ReadField(MEDLoader.ON_CELLS,fname,"mesh",0,"field",1,2),1e-12,1e-12))
+        #
+        f3=f.deepCopy()
+        f3.setArray(f.getArray()+30)
+        f3.setName("field2")
+        f3.setTime(5.,4,5)
+        MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fname,f3)
+        #
+        self.assertRaises(Exception,MEDLoader.ReadField,fname) # because several fields in fname now
+        self.assertTrue(f.isEqual(MEDLoader.ReadField(fname,"field"),1e-12,1e-12))
+        self.assertTrue(f.isEqual(MEDLoader.ReadField(fname,"field",1,2),1e-12,1e-12))
+        self.assertTrue(f.isEqual(MEDLoader.ReadField(MEDLoader.ON_CELLS,fname,"mesh",0,"field",1,2),1e-12,1e-12))
+        self.assertTrue(f3.isEqual(MEDLoader.ReadField(fname,"field2"),1e-12,1e-12))
+        self.assertTrue(f3.isEqual(MEDLoader.ReadField(fname,"field2",4,5),1e-12,1e-12))
+        self.assertTrue(f3.isEqual(MEDLoader.ReadField(MEDLoader.ON_CELLS,fname,"mesh",0,"field2",4,5),1e-12,1e-12))
+        #
+        f2=f.deepCopy()
+        f2.setTime(4.,3,4)
+        f2.setArray(f2.getArray()+10)
+        MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fname,f2)
+        #
+        self.assertRaises(Exception,MEDLoader.ReadField,fname) # because unique field "field" has more than one time step
+        self.assertRaises(Exception,MEDLoader.ReadField,fname,"field") # because unique field "field" has more than one time step
+        self.assertTrue(f.isEqual(MEDLoader.ReadField(fname,"field",1,2),1e-12,1e-12))
+        self.assertTrue(f.isEqual(MEDLoader.ReadField(MEDLoader.ON_CELLS,fname,"mesh",0,"field",1,2),1e-12,1e-12))
+        self.assertTrue(f2.isEqual(MEDLoader.ReadField(fname,"field",3,4),1e-12,1e-12))
+        self.assertTrue(f2.isEqual(MEDLoader.ReadField(MEDLoader.ON_CELLS,fname,"mesh",0,"field",3,4),1e-12,1e-12))
+        #
+        self.assertTrue(f.isEqual(MEDLoader.ReadField(fname,"field",1,2),1e-12,1e-12))
+        self.assertTrue(f.isEqual(MEDLoader.ReadField(MEDLoader.ON_CELLS,fname,"mesh",0,"field",1,2),1e-12,1e-12))
+        self.assertTrue(f2.isEqual(MEDLoader.ReadField(fname,"field",3,4),1e-12,1e-12))
+        self.assertTrue(f2.isEqual(MEDLoader.ReadField(MEDLoader.ON_CELLS,fname,"mesh",0,"field",3,4),1e-12,1e-12))
+        #
+        self.assertTrue(f3.isEqual(MEDLoader.ReadField(fname,"field2"),1e-12,1e-12))
+        self.assertTrue(f3.isEqual(MEDLoader.ReadField(fname,"field2",4,5),1e-12,1e-12))
+        self.assertRaises(Exception,MEDLoader.ReadField,fname,"field2",5,5) # invalid time step
+        self.assertTrue(f3.isEqual(MEDLoader.ReadField(MEDLoader.ON_CELLS,fname,"mesh",0,"field2",4,5),1e-12,1e-12))
+        self.assertRaises(Exception,MEDLoader.ReadField,MEDLoader.ON_CELLS,fname,"mesh",0,"field2",5,5) # invalid time step
+        # Test on profile - restart from scratch
+        mm=MEDLoader.MEDFileUMesh()
+        mm[0]=m
+        mm.write(fname,2)
+        #
+        pfl=MEDLoader.DataArrayInt(range(8))
+        pfl.setName("PFL")
+        #
+        f=MEDLoader.MEDCouplingFieldDouble(MEDLoader.ON_CELLS)
+        f.setName("field")
+        f.setTime(3.,1,2)
+        da=MEDLoader.DataArrayDouble([2,3,4,5,6,7,8,9])
+        f.setArray(da) ; f.setMesh(m[pfl])
+        f.checkConsistencyLight()
+        #
+        f1ts=MEDLoader.MEDFileField1TS()
+        f1ts.setFieldProfile(f,mm,0,pfl)
+        f1ts.write(fname,0)
+        #
+        self.assertTrue(f.isEqual(MEDLoader.ReadField(fname),1e-12,1e-12))
+        self.assertTrue(f.isEqual(MEDLoader.ReadField(fname,"field"),1e-12,1e-12))
+        self.assertTrue(f.isEqual(MEDLoader.ReadField(fname,"field",1,2),1e-12,1e-12))
+        self.assertTrue(f.isEqual(MEDLoader.ReadField(MEDLoader.ON_CELLS,fname,"mesh",0,"field",1,2),1e-12,1e-12))
+        #
+        f3=f.deepCopy()
+        f3.setArray(f.getArray()+30)
+        f3.setName("field2")
+        f3.setTime(5.,4,5)
+        f1ts=MEDLoader.MEDFileField1TS()
+        f1ts.setFieldProfile(f3,mm,0,pfl)
+        f1ts.write(fname,0)
+        #
+        self.assertRaises(Exception,MEDLoader.ReadField,fname) # because several fields in fname now
+        self.assertTrue(f.isEqual(MEDLoader.ReadField(fname,"field"),1e-12,1e-12))
+        self.assertTrue(f.isEqual(MEDLoader.ReadField(fname,"field",1,2),1e-12,1e-12))
+        self.assertTrue(f.isEqual(MEDLoader.ReadField(MEDLoader.ON_CELLS,fname,"mesh",0,"field",1,2),1e-12,1e-12))
+        self.assertTrue(f3.isEqual(MEDLoader.ReadField(fname,"field2"),1e-12,1e-12))
+        self.assertTrue(f3.isEqual(MEDLoader.ReadField(fname,"field2",4,5),1e-12,1e-12))
+        self.assertTrue(f3.isEqual(MEDLoader.ReadField(MEDLoader.ON_CELLS,fname,"mesh",0,"field2",4,5),1e-12,1e-12))
+        #
+        f2=f.deepCopy()
+        f2.setTime(4.,3,4)
+        f2.setArray(f2.getArray()+10)
+        f1ts=MEDLoader.MEDFileField1TS()
+        f1ts.setFieldProfile(f2,mm,0,pfl)
+        f1ts.write(fname,0)
+        #
+        self.assertRaises(Exception,MEDLoader.ReadField,fname) # because unique field "field" has more than one time step
+        self.assertRaises(Exception,MEDLoader.ReadField,fname,"field") # because unique field "field" has more than one time step
+        self.assertTrue(f.isEqual(MEDLoader.ReadField(fname,"field",1,2),1e-12,1e-12))
+        self.assertTrue(f.isEqual(MEDLoader.ReadField(MEDLoader.ON_CELLS,fname,"mesh",0,"field",1,2),1e-12,1e-12))
+        self.assertTrue(f2.isEqual(MEDLoader.ReadField(fname,"field",3,4),1e-12,1e-12))
+        self.assertTrue(f2.isEqual(MEDLoader.ReadField(MEDLoader.ON_CELLS,fname,"mesh",0,"field",3,4),1e-12,1e-12))
+        #
+        self.assertTrue(f.isEqual(MEDLoader.ReadField(fname,"field",1,2),1e-12,1e-12))
+        self.assertTrue(f.isEqual(MEDLoader.ReadField(MEDLoader.ON_CELLS,fname,"mesh",0,"field",1,2),1e-12,1e-12))
+        self.assertTrue(f2.isEqual(MEDLoader.ReadField(fname,"field",3,4),1e-12,1e-12))
+        self.assertTrue(f2.isEqual(MEDLoader.ReadField(MEDLoader.ON_CELLS,fname,"mesh",0,"field",3,4),1e-12,1e-12))
+        #
+        self.assertTrue(f3.isEqual(MEDLoader.ReadField(fname,"field2"),1e-12,1e-12))
+        self.assertTrue(f3.isEqual(MEDLoader.ReadField(fname,"field2",4,5),1e-12,1e-12))
+        self.assertRaises(Exception,MEDLoader.ReadField,fname,"field2",5,5) # invalid time step
+        self.assertTrue(f3.isEqual(MEDLoader.ReadField(MEDLoader.ON_CELLS,fname,"mesh",0,"field2",4,5),1e-12,1e-12))
+        self.assertRaises(Exception,MEDLoader.ReadField,MEDLoader.ON_CELLS,fname,"mesh",0,"field2",5,5) # invalid time step
+        pass
+    
     pass
 
 if __name__ == "__main__":
index 6d5d041b85e5ab8d314e050df919988c6bd95c26..26079d3a325216f84b55168ab66010ead8e55873 100644 (file)
@@ -477,9 +477,8 @@ void MEDLoaderTest::testFieldGaussRW1()
   const char fileName[]="file13.med";
   MEDCouplingFieldDouble *f1=buildVecFieldOnGauss_1();
   WriteField(fileName,f1,true);
-  MEDCouplingFieldDouble *f2=ReadField(ON_GAUSS_PT,fileName,f1->getMesh()->getName().c_str(),0,f1->getName().c_str(),1,5);
+  MCAuto<MEDCouplingFieldDouble> f2(ReadField(ON_GAUSS_PT,fileName,f1->getMesh()->getName().c_str(),0,f1->getName().c_str(),1,5));
   CPPUNIT_ASSERT(f1->isEqual(f2,1e-12,1e-12));
-  f2->decrRef();
   f1->decrRef();
 }
 
@@ -491,9 +490,8 @@ void MEDLoaderTest::testFieldGaussNERW1()
   std::vector<MEDCoupling::TypeOfField> tof(GetTypesOfField(fileName,"2DMesh_2","MyFieldOnGaussNE"));
   CPPUNIT_ASSERT_EQUAL(1,(int)tof.size());
   CPPUNIT_ASSERT(ON_GAUSS_NE==tof[0]);
-  MEDCouplingFieldDouble *f2=ReadField(ON_GAUSS_NE,fileName,f1->getMesh()->getName().c_str(),0,f1->getName().c_str(),1,5);
+  MCAuto<MEDCouplingFieldDouble> f2(ReadField(ON_GAUSS_NE,fileName,f1->getMesh()->getName().c_str(),0,f1->getName().c_str(),1,5));
   CPPUNIT_ASSERT(f1->isEqual(f2,1e-12,1e-12));
-  f2->decrRef();
   f1->decrRef();
 }