/// @endcond
+void MEDLoader::AssignStaticWritePropertiesTo(ParaMEDMEM::MEDFileWritable& obj)
+{
+ obj.setTooLongStrPolicy(_TOO_LONG_STR);
+}
+
bool MEDLoader::HasXDR()
{
#ifdef HAS_XDR
ParaMEDMEM::MEDCouplingMesh *MEDLoader::ReadMeshFromFile(const char *fileName, const char *meshName, int meshDimRelToMax)
{
CheckFileForRead(fileName);
- MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm=MEDFileMesh::New(fileName,meshName);
+ MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm(MEDFileMesh::New(fileName,meshName));
MEDFileMesh *mmPtr(mm);
MEDFileUMesh *mmuPtr=dynamic_cast<MEDFileUMesh *>(mmPtr);
if(mmuPtr)
ParaMEDMEM::MEDCouplingMesh *MEDLoader::ReadMeshFromFile(const char *fileName, int meshDimRelToMax)
{
CheckFileForRead(fileName);
- MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm=MEDFileMesh::New(fileName);
+ MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm(MEDFileMesh::New(fileName));
MEDFileMesh *mmPtr(mm);
MEDFileUMesh *mmuPtr=dynamic_cast<MEDFileUMesh *>(mmPtr);
if(mmuPtr)
ParaMEDMEM::MEDCouplingUMesh *MEDLoader::ReadUMeshFromFile(const char *fileName, const char *meshName, int meshDimRelToMax)
{
CheckFileForRead(fileName);
- MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm=MEDFileMesh::New(fileName,meshName);
+ MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm(MEDFileMesh::New(fileName,meshName));
MEDFileMesh *mmPtr(mm);
MEDFileUMesh *mmuPtr=dynamic_cast<MEDFileUMesh *>(mmPtr);
if(!mmuPtr)
ParaMEDMEM::MEDCouplingUMesh *MEDLoader::ReadUMeshFromFile(const char *fileName, int meshDimRelToMax)
{
CheckFileForRead(fileName);
- MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm=MEDFileMesh::New(fileName);
+ MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm(MEDFileMesh::New(fileName));
MEDFileMesh *mmPtr(mm);
MEDFileUMesh *mmuPtr=dynamic_cast<MEDFileUMesh *>(mmPtr);
if(!mmuPtr)
ParaMEDMEM::MEDCouplingUMesh *MEDLoader::ReadUMeshFromFamilies(const char *fileName, const char *meshName, int meshDimRelToMax, const std::vector<std::string>& fams)
{
CheckFileForRead(fileName);
- MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm=MEDFileMesh::New(fileName,meshName);
+ MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm(MEDFileMesh::New(fileName,meshName));
MEDFileMesh *mmPtr(mm);
MEDFileUMesh *mmuPtr=dynamic_cast<MEDFileUMesh *>(mmPtr);
if(!mmuPtr)
const MEDCoupling1GTUMesh *um2(dynamic_cast<const MEDCoupling1GTUMesh *>(mesh));
if(um2)
{
- MEDCouplingAutoRefCountObjectPtr<MEDFileUMesh> mmu=MEDFileUMesh::New();
+ MEDCouplingAutoRefCountObjectPtr<MEDFileUMesh> mmu(MEDFileUMesh::New());
+ AssignStaticWritePropertiesTo(*mmu);
mmu->setMeshAtLevel(0,const_cast<MEDCoupling1GTUMesh *>(um2));
mmu->write(fileName,mod);
return ;
const MEDCouplingCMesh *um3(dynamic_cast<const MEDCouplingCMesh *>(mesh));
if(um3)
{
- MEDCouplingAutoRefCountObjectPtr<MEDFileCMesh> mmc=MEDFileCMesh::New();
+ MEDCouplingAutoRefCountObjectPtr<MEDFileCMesh> mmc(MEDFileCMesh::New());
+ AssignStaticWritePropertiesTo(*mmc);
mmc->setMesh(const_cast<MEDCouplingCMesh *>(um3));
mmc->write(fileName,mod);
return ;
const MEDCouplingCurveLinearMesh *um4(dynamic_cast<const MEDCouplingCurveLinearMesh *>(mesh));
if(um4)
{
- MEDCouplingAutoRefCountObjectPtr<MEDFileCurveLinearMesh> mmc=MEDFileCurveLinearMesh::New();
+ MEDCouplingAutoRefCountObjectPtr<MEDFileCurveLinearMesh> mmc(MEDFileCurveLinearMesh::New());
+ AssignStaticWritePropertiesTo(*mmc);
mmc->setMesh(const_cast<MEDCouplingCurveLinearMesh *>(um4));
mmc->write(fileName,mod);
return ;
if(!mesh)
throw INTERP_KERNEL::Exception("MEDLoader::WriteUMesh : input mesh is null !");
int mod=writeFromScratch?2:0;
- MEDCouplingAutoRefCountObjectPtr<MEDFileUMesh> m=MEDFileUMesh::New();
+ MEDCouplingAutoRefCountObjectPtr<MEDFileUMesh> m(MEDFileUMesh::New());
+ AssignStaticWritePropertiesTo(*m);
MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> mcpy(static_cast<MEDCouplingUMesh *>(mesh->deepCpy()));
m->setMeshAtLevel(0,mcpy,true);
m->write(fileName,mod);
std::ostringstream oss; oss << "File with name \'" << fileName << "\' has not valid permissions !";
throw INTERP_KERNEL::Exception(oss.str().c_str());
}
- MEDCouplingAutoRefCountObjectPtr<MEDFileUMesh> m=MEDFileUMesh::New();
+ MEDCouplingAutoRefCountObjectPtr<MEDFileUMesh> m(MEDFileUMesh::New());
+ AssignStaticWritePropertiesTo(*m);
m->setGroupsFromScratch(0,meshes,true);
m->setName(meshNameC);
int mod=writeFromScratch?2:0;
void MEDLoader::WriteUMeshes(const char *fileName, const std::vector<const ParaMEDMEM::MEDCouplingUMesh *>& meshes, bool writeFromScratch)
{
int mod=writeFromScratch?2:0;
- MEDCouplingAutoRefCountObjectPtr<MEDFileUMesh> m=MEDFileUMesh::New();
+ MEDCouplingAutoRefCountObjectPtr<MEDFileUMesh> m(MEDFileUMesh::New());
+ AssignStaticWritePropertiesTo(*m);
m->setMeshes(meshes,true);
m->write(fileName,mod);
}
void MEDLoaderNS::writeFieldWithoutReadingAndMappingOfMeshInFile(const char *fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f, bool writeFromScratch)
{
- MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ff=MEDFileField1TS::New();
+ MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ff(MEDFileField1TS::New());
+ MEDLoader::AssignStaticWritePropertiesTo(*ff);
MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> f2(f->deepCpy());
const MEDCouplingMesh *m(f2->getMesh());
const MEDCouplingUMesh *um(dynamic_cast<const MEDCouplingUMesh *>(m));
int mod=writeFromScratch?2:0;
if(um)
{
- MEDCouplingAutoRefCountObjectPtr<MEDFileUMesh> mmu=MEDFileUMesh::New();
- MEDCouplingAutoRefCountObjectPtr<DataArrayInt> o2n=um->getRenumArrForMEDFileFrmt();
- MEDCouplingAutoRefCountObjectPtr<DataArrayInt> n2o=o2n->invertArrayO2N2N2O(o2n->getNumberOfTuples());
+ MEDCouplingAutoRefCountObjectPtr<MEDFileUMesh> mmu(MEDFileUMesh::New());
+ MEDLoader::AssignStaticWritePropertiesTo(*mmu);
+ MEDCouplingAutoRefCountObjectPtr<DataArrayInt> o2n(um->getRenumArrForMEDFileFrmt());
+ MEDCouplingAutoRefCountObjectPtr<DataArrayInt> n2o(o2n->invertArrayO2N2N2O(o2n->getNumberOfTuples()));
f2->renumberCells(o2n->begin(),false);
mmu->setMeshAtLevel(0,const_cast<MEDCouplingUMesh *>(static_cast<const MEDCouplingUMesh *>(f2->getMesh())));
mmu->setRenumFieldArr(0,n2o);
}
else if(um2)
{
- MEDCouplingAutoRefCountObjectPtr<MEDFileUMesh> mmu=MEDFileUMesh::New();
+ MEDCouplingAutoRefCountObjectPtr<MEDFileUMesh> mmu(MEDFileUMesh::New());
+ MEDLoader::AssignStaticWritePropertiesTo(*mmu);
mmu->setMeshAtLevel(0,const_cast<MEDCoupling1GTUMesh *>(um2));
ff->setFieldNoProfileSBT(f2);
mmu->write(fileName,mod);
}
else if(um3)
{
- MEDCouplingAutoRefCountObjectPtr<MEDFileCMesh> mmc=MEDFileCMesh::New();
+ MEDCouplingAutoRefCountObjectPtr<MEDFileCMesh> mmc(MEDFileCMesh::New());
+ MEDLoader::AssignStaticWritePropertiesTo(*mmc);
mmc->setMesh(const_cast<MEDCouplingCMesh *>(um3));
ff->setFieldNoProfileSBT(f2);
mmc->write(fileName,mod);
}
else if(um4)
{
- MEDCouplingAutoRefCountObjectPtr<MEDFileCurveLinearMesh> mmc=MEDFileCurveLinearMesh::New();
+ MEDCouplingAutoRefCountObjectPtr<MEDFileCurveLinearMesh> mmc(MEDFileCurveLinearMesh::New());
+ MEDLoader::AssignStaticWritePropertiesTo(*mmc);
mmc->setMesh(const_cast<MEDCouplingCurveLinearMesh *>(um4));
ff->setFieldNoProfileSBT(f2);
mmc->write(fileName,mod);
MEDLoaderNS::writeFieldWithoutReadingAndMappingOfMeshInFile(fileName,f,false);
else
{
- MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm=MEDFileMesh::New(fileName,f->getMesh()->getName().c_str());
+ MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm(MEDFileMesh::New(fileName,f->getMesh()->getName().c_str()));
+ AssignStaticWritePropertiesTo(*mm);
const MEDFileMesh *mmPtr(mm);
const MEDFileUMesh *mmuPtr=dynamic_cast<const MEDFileUMesh *>(mmPtr);
if(!mmuPtr)
std::ostringstream oss; oss << "MEDLoader::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());
}
- MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> f1ts=MEDFileField1TS::New();
+ MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> f1ts(MEDFileField1TS::New());
+ AssignStaticWritePropertiesTo(*f1ts);
if(part->isIdentity() && part->getNumberOfTuples()==mread->getNumberOfCells())
f1ts->setFieldNoProfileSBT(f2);
else
std::ostringstream oss; oss << "MEDLoader::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());
}
- MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> f1ts=MEDFileField1TS::New();
+ MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> f1ts(MEDFileField1TS::New());
+ AssignStaticWritePropertiesTo(*f1ts);
if(part->isIdentity() && part->getNumberOfTuples()==mread->getNumberOfNodes())
f1ts->setFieldNoProfileSBT(f2);
else
std::ostringstream oss; oss << "File with name \'" << fileName << "\' has not valid permissions or not exists !";
throw INTERP_KERNEL::Exception(oss.str().c_str());
}
- MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> f1ts=MEDFileField1TS::New();
+ MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> f1ts(MEDFileField1TS::New());
+ AssignStaticWritePropertiesTo(*f1ts);
MEDCouplingUMesh *m=dynamic_cast<MEDCouplingUMesh *>(const_cast<MEDCouplingMesh *>(f->getMesh()));
if(!m)
throw INTERP_KERNEL::Exception("MEDLoader::WriteFieldUsingAlreadyWrittenMesh : only umesh in input field supported !");
self.assertTrue("xonall1" in mesh.getGroupsNames())
pass
+ def testFieldWithTooLongName(self):
+ """ This test is a non regression test, to check that in basic API the policies are taken into account.
+ """
+ fname="Pyfile75.med"
+ # Coordinates
+ coords = [0.,0., 0.,1., 1.,1., 1.,0.]
+ # lvl 0 connectivity
+ conn2D = [1,2,3,4]
+ # lvl 0 mesh
+ m=MEDLoader.MEDCouplingUMesh.New("mesh",2)
+ m.allocateCells(1)
+ m.insertNextCell(MEDLoader.NORM_QUAD4,4,conn2D)
+ m.finishInsertingCells()
+ # assigning coordinates
+ meshCoords=MEDLoader.DataArrayDouble.New()
+ meshCoords.setValues(coords, 4, 2)
+ m.setCoords(meshCoords)
+ #
+ f=MEDLoader.MEDCouplingFieldDouble.New(MEDLoader.ON_CELLS,MEDLoader.ONE_TIME)
+ f.setMesh(m)
+ d=MEDLoader.DataArrayDouble.New()
+ d.alloc(1,1)
+ d.iota(1.)
+ # seting a long name
+ d.setInfoOnComponent(0,"CONCENTRATION of I129")
+ f.setArray(d)
+ f.setName("field")
+ #
+ mm=MEDLoader.MEDFileUMesh()
+ MEDLoader.MEDLoader.SetTooLongStrPolicy(2)
+ MEDLoader.MEDLoader.AssignStaticWritePropertiesTo(mm)
+ self.assertEqual(2,mm.getTooLongStrPolicy())
+ MEDLoader.MEDLoader.SetTooLongStrPolicy(0)
+ MEDLoader.MEDLoader.AssignStaticWritePropertiesTo(mm)
+ self.assertEqual(0,mm.getTooLongStrPolicy())
+ del mm
+ #
+ MEDLoader.MEDLoader.SetTooLongStrPolicy(2)
+ self.assertRaises(MEDLoader.InterpKernelException,MEDLoader.MEDLoader.WriteField,fname,f,True)# the component name is too long + policy 2 -> throw
+ f.getArray().setInfoOnComponent(0,'I129')
+ MEDLoader.MEDLoader.WriteField(fname,f,True)
+ pass
+
pass
unittest.main()