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 !");
}
#include "InterpKernelException.hxx"
#include "MEDCouplingRefCountObject.hxx"
#include "NormalizedUnstructuredMesh.hxx"
+#include "MCAuto.hxx"
#include <list>
#include <vector>
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,
def MEDCouplingMEDFileParametersnew(cls,*args):
import _MEDLoader
return _MEDLoader.MEDFileParameters____new___(cls,args)
+def ReadField(*args):
+ import _MEDLoader
+ return _MEDLoader.ReadFieldSwig(args)
%}
%include "MEDCouplingFinalize.i"
%newobject ReadUMeshFromFamiliesSwig;
%newobject ReadUMeshFromGroupsSwig;
+%newobject ReadFieldSwig;
%newobject MEDCoupling::ReadUMeshFromFile;
%newobject MEDCoupling::ReadMeshFromFile;
-%newobject MEDCoupling::ReadField;
%newobject MEDCoupling::ReadFieldCell;
%newobject MEDCoupling::ReadFieldNode;
%newobject MEDCoupling::ReadFieldGauss;
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);
PyTuple_SetItem(ret,2,SWIG_From_int(release));
return ret;
}
+
+ MEDCoupling::MEDCouplingFieldDouble *ReadFieldSwig(PyObject *elt0) throw(INTERP_KERNEL::Exception)
+ {
+ const char MSG[]="Invalid call ReadField !\n Supported are :\n - ReadField(fileName)\n - ReadField(fileName,fieldName)\n - ReadField(fileName,fieldName,iteration,order)\n - ReadField(type,fileName,meshName,meshDimRelToMax,fieldName,iteration,orde)";
+ if(elt0 && PyString_Check(elt0))
+ {
+ std::string st(PyString_AsString(elt0));
+ MCAuto<MEDCouplingFieldDouble> ret(MEDCoupling::ReadField(st));
+ return ret.retn();
+ }
+ if(!elt0 || !PyTuple_Check(elt0))
+ throw INTERP_KERNEL::Exception(MSG);
+ int sz(PyTuple_Size(elt0));
+ if(sz==2)
+ {
+ PyObject *o0(PyTuple_GetItem(elt0,0)),*o1(PyTuple_GetItem(elt0,1));
+ if(PyString_Check(o0) && PyString_Check(o1))
+ {
+ std::string st0(PyString_AsString(o0)),st1(PyString_AsString(o1));
+ MCAuto<MEDCouplingFieldDouble> ret(MEDCoupling::ReadField(st0,st1));
+ return ret.retn();
+ }
+ throw INTERP_KERNEL::Exception(MSG);
+ }
+ if(sz==4)
+ {
+ PyObject *o0(PyTuple_GetItem(elt0,0)),*o1(PyTuple_GetItem(elt0,1)),*o2(PyTuple_GetItem(elt0,2)),*o3(PyTuple_GetItem(elt0,3));
+ if(PyString_Check(o0) && PyString_Check(o1) && PyInt_Check(o2) && PyInt_Check(o3))
+ {
+ std::string st0(PyString_AsString(o0)),st1(PyString_AsString(o1));
+ int a((int)PyInt_AS_LONG(o2)),b((int)PyInt_AS_LONG(o3));
+ MCAuto<MEDCouplingFieldDouble> ret(MEDCoupling::ReadField(st0,st1,a,b));
+ return ret.retn();
+ }
+ throw INTERP_KERNEL::Exception(MSG);
+ }
+ if(sz==7)
+ {
+ PyObject *o0(PyTuple_GetItem(elt0,0)),*o1(PyTuple_GetItem(elt0,1)),*o2(PyTuple_GetItem(elt0,2)),*o3(PyTuple_GetItem(elt0,3)),*o4(PyTuple_GetItem(elt0,4)),*o5(PyTuple_GetItem(elt0,5)),*o6(PyTuple_GetItem(elt0,6));
+ if(PyInt_Check(o0) && PyString_Check(o1) && PyString_Check(o2) && PyInt_Check(o3) && PyString_Check(o4) && PyInt_Check(o5) && PyInt_Check(o6))
+ {
+ int a((int)PyInt_AS_LONG(o0)),b((int)PyInt_AS_LONG(o3)),c((int)PyInt_AS_LONG(o5)),d((int)PyInt_AS_LONG(o6));
+ MEDCoupling::TypeOfField aa((MEDCoupling::TypeOfField)a);
+ std::string st0(PyString_AsString(o1)),st1(PyString_AsString(o2)),st2(PyString_AsString(o4));
+ MCAuto<MEDCouplingFieldDouble> ret(MEDCoupling::ReadField(aa,st0,st1,b,st2,c,d));
+ return ret.retn();
+ }
+ throw INTERP_KERNEL::Exception(MSG);
+ }
+ throw INTERP_KERNEL::Exception(MSG);
+ }
PyObject *GetFieldIterationsSwig(MEDCoupling::TypeOfField type, const std::string& fileName, const std::string& meshName, const std::string& fieldName) throw(INTERP_KERNEL::Exception)
{
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):
+ pass
+
pass
if __name__ == "__main__":
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();
}
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();
}