// Author : Anthony Geay (CEA/DEN)
#include "MEDFileMesh.hxx"
-#include "MEDFileUtilities.hxx"
#include "MEDFileFieldOverView.hxx"
#include "MEDFileField.hxx"
#include "MEDLoader.hxx"
+#include "MEDLoaderNS.hxx"
#include "MEDFileSafeCaller.txx"
#include "MEDLoaderBase.hxx"
#include <limits>
#include <cmath>
+extern med_geometry_type typmai[MED_N_CELL_FIXED_GEO];
+extern INTERP_KERNEL::NormalizedCellType typmai2[MED_N_CELL_FIXED_GEO];
extern med_geometry_type typmai3[34];
using namespace MEDCoupling;
*/
MEDFileMesh *MEDFileMesh::New(const std::string& fileName, MEDFileMeshReadSelector *mrs)
{
- std::vector<std::string> ms=MEDCoupling::GetMeshNames(fileName);
+ MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
+ return New(fid,mrs);
+}
+
+MEDFileMesh *MEDFileMesh::New(med_idt fid, MEDFileMeshReadSelector *mrs)
+{
+ std::vector<std::string> ms(MEDLoaderNS::getMeshNamesFid(fid));
if(ms.empty())
{
- std::ostringstream oss; oss << "MEDFileMesh::New : no meshes in file \"" << fileName << "\" !";
+ std::ostringstream oss; oss << "MEDFileMesh::New : no meshes in file \"" << FileNameFromFID(fid) << "\" !";
throw INTERP_KERNEL::Exception(oss.str().c_str());
}
- MEDFileUtilities::CheckFileForRead(fileName);
MEDCoupling::MEDCouplingMeshType meshType;
- MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
int dt,it;
std::string dummy2;
MEDCoupling::MEDCouplingAxisType dummy3;
*/
MEDFileMesh *MEDFileMesh::New(const std::string& fileName, const std::string& mName, int dt, int it, MEDFileMeshReadSelector *mrs, MEDFileJoints* joints)
{
- MEDFileUtilities::CheckFileForRead(fileName);
+ MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
+ return New(fid,mName,dt,it,mrs,joints);
+}
+
+MEDFileMesh *MEDFileMesh::New(med_idt fid, const std::string& mName, int dt, int it, MEDFileMeshReadSelector *mrs, MEDFileJoints* joints)
+{
MEDCoupling::MEDCouplingMeshType meshType;
- MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
int dummy0,dummy1;
std::string dummy2;
MEDCoupling::MEDCouplingAxisType dummy3;
* \throw If the file is open for reading only.
* \throw If the writing mode == 1 and the same data is present in an existing file.
*/
-void MEDFileMesh::write(med_idt fid) const
+void MEDFileMesh::writeLL(med_idt fid) const
{
if(!existsFamily(0))
const_cast<MEDFileMesh *>(this)->addFamily(DFT_FAM_NAME,0);
if(_name.empty())
throw INTERP_KERNEL::Exception("MEDFileMesh : name is empty. MED file ask for a NON EMPTY name !");
- writeLL(fid);
+ writeMeshLL(fid);
writeJoints(fid);
const MEDFileEquivalences *eqs(_equiv);
if(eqs)
- eqs->write(fid);
-}
-
-/*!
- * Writes \a this mesh into a MED file specified by its name.
- * \param [in] fileName - the MED file name.
- * \param [in] mode - the writing mode. For more on \a mode, see \ref AdvMEDLoaderBasics.
- * - 2 - erase; an existing file is removed.
- * - 1 - append; same data should not be present in an existing file.
- * - 0 - overwrite; same data present in an existing file is overwritten.
- * \throw If the mesh name is not set.
- * \throw If \a mode == 1 and the same data is present in an existing file.
- */
-void MEDFileMesh::write(const std::string& fileName, int mode) const
-{
- med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode);
- MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),medmod);
- std::ostringstream oss; oss << "MEDFileMesh : error on attempt to write in file : \"" << fileName << "\"";
- MEDFileUtilities::CheckMEDCode(fid,fid,oss.str());
- write(fid);
+ eqs->writeLL(fid);
}
/*!
*/
MEDFileUMesh *MEDFileUMesh::New(const std::string& fileName, const std::string& mName, int dt, int it, MEDFileMeshReadSelector *mrs)
{
- MEDFileUtilities::CheckFileForRead(fileName);
- MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
+ MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
+ return New(fid,mName,dt,it,mrs);
+}
+
+MEDFileUMesh *MEDFileUMesh::New(med_idt fid, const std::string& mName, int dt, int it, MEDFileMeshReadSelector *mrs)
+{
return new MEDFileUMesh(fid,mName,dt,it,mrs);
}
*/
MEDFileUMesh *MEDFileUMesh::New(const std::string& fileName, MEDFileMeshReadSelector *mrs)
{
- std::vector<std::string> ms(MEDCoupling::GetMeshNames(fileName));
+ MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
+ return New(fid,mrs);
+}
+
+template<class T>
+T *NewForTheFirstMeshInFile(med_idt fid, MEDFileMeshReadSelector *mrs)
+{
+ std::vector<std::string> ms(MEDLoaderNS::getMeshNamesFid(fid));
if(ms.empty())
{
- std::ostringstream oss; oss << "MEDFileUMesh::New : no meshes in file \"" << fileName << "\" !";
+ std::ostringstream oss; oss << MLMeshTraits<T>::ClassName << "::New : no meshes in file \"" << MEDFileWritable::FileNameFromFID(fid) << "\" !";
throw INTERP_KERNEL::Exception(oss.str().c_str());
}
- MEDFileUtilities::CheckFileForRead(fileName);
- MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
int dt,it;
MEDCoupling::MEDCouplingMeshType meshType;
std::string dummy2;
MEDCoupling::MEDCouplingAxisType dummy3;
MEDFileMeshL2::GetMeshIdFromName(fid,ms.front(),meshType,dummy3,dt,it,dummy2);
- return new MEDFileUMesh(fid,ms.front(),dt,it,mrs);
+ return T::New(fid,ms.front(),dt,it,mrs);
+}
+
+MEDFileUMesh *MEDFileUMesh::New(med_idt fid, MEDFileMeshReadSelector *mrs)
+{
+ return NewForTheFirstMeshInFile<MEDFileUMesh>(fid,mrs);
}
/*!
std::size_t MEDFileUMesh::getHeapMemorySizeWithoutChildren() const
{
std::size_t ret(MEDFileMesh::getHeapMemorySizeWithoutChildren());
- ret+=_ms.capacity()*(sizeof(MCAuto<MEDFileUMeshSplitL1>));
+ ret+=_ms.capacity()*(sizeof(MCAuto<MEDFileUMeshSplitL1>))+_elt_str.capacity()*sizeof(MCAuto<MEDFileEltStruct4Mesh>);
return ret;
}
ret.push_back((const PartDefinition *)_part_coords);
for(std::vector< MCAuto<MEDFileUMeshSplitL1> >::const_iterator it=_ms.begin();it!=_ms.end();it++)
ret.push_back((const MEDFileUMeshSplitL1*) *it);
+ for(std::vector< MCAuto<MEDFileEltStruct4Mesh> >::const_iterator it=_elt_str.begin();it!=_elt_str.end();it++)
+ ret.push_back((const MEDFileEltStruct4Mesh *)*it);
return ret;
}
int dummy0,dummy1;
std::string dummy2;
MEDCoupling::MEDCouplingAxisType dummy3;
- int mid(MEDFileUMeshL2::GetMeshIdFromName(fid,mName,meshType,dummy3,dummy0,dummy1,dummy2));
+ INTERP_KERNEL::AutoCppPtr<MeshOrStructMeshCls> mid(MEDFileUMeshL2::GetMeshIdFromName(fid,mName,meshType,dummy3,dummy0,dummy1,dummy2));
if(meshType!=UNSTRUCTURED)
{
std::ostringstream oss; oss << "loadPartUMeshFromFile : Trying to load as unstructured an existing mesh with name '" << mName << "' !";
*/
void MEDFileMesh::writeJoints(med_idt fid) const
{
- if ( (const MEDFileJoints*) _joints )
- _joints->write(fid);
+ if ( _joints.isNotNull() )
+ _joints->writeLL(fid);
}
/*!
int dummy0,dummy1;
std::string dummy2;
MEDCoupling::MEDCouplingAxisType axType;
- int mid(MEDFileUMeshL2::GetMeshIdFromName(fid,mName,meshType,axType,dummy0,dummy1,dummy2));
+ INTERP_KERNEL::AutoCppPtr<MeshOrStructMeshCls> mid(MEDFileUMeshL2::GetMeshIdFromName(fid,mName,meshType,axType,dummy0,dummy1,dummy2));
setAxisType(axType);
if(meshType!=UNSTRUCTURED)
{
}
loaderl2.loadAll(fid,mid,mName,dt,it,mrs);
dispatchLoadedPart(fid,loaderl2,mName,mrs);
+ // Structure element part...
+ int nModels(-1);
+ {
+ med_bool chgt=MED_FALSE,trsf=MED_FALSE;
+ nModels=MEDmeshnEntity(fid,mName.c_str(),dt,it,MED_STRUCT_ELEMENT,MED_GEO_ALL,MED_CONNECTIVITY,MED_NODAL,&chgt,&trsf);
+ }
+ if(nModels<=0)
+ return ;
+ _elt_str.resize(nModels);
+ for(int i=0;i<nModels;i++)
+ _elt_str[i]=MEDFileEltStruct4Mesh::New(fid,mName,dt,it,i,mrs);
}
void MEDFileUMesh::dispatchLoadedPart(med_idt fid, const MEDFileUMeshL2& loaderl2, const std::string& mName, MEDFileMeshReadSelector *mrs)
{
}
-void MEDFileUMesh::writeLL(med_idt fid) const
+void MEDFileUMesh::writeMeshLL(med_idt fid) const
{
const DataArrayDouble *coo=_coords;
INTERP_KERNEL::AutoPtr<char> maa=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
std::string info=coo->getInfoOnComponent(i);
std::string c,u;
MEDLoaderBase::splitIntoNameAndUnit(info,c,u);
- MEDLoaderBase::safeStrCpy2(c.c_str(),MED_SNAME_SIZE-1,comp+i*MED_SNAME_SIZE,_too_long_str);//MED_TAILLE_PNOM-1 to avoid to write '\0' on next compo
- MEDLoaderBase::safeStrCpy2(u.c_str(),MED_SNAME_SIZE-1,unit+i*MED_SNAME_SIZE,_too_long_str);//MED_TAILLE_PNOM-1 to avoid to write '\0' on next compo
+ MEDLoaderBase::safeStrCpy2(c.c_str(),MED_SNAME_SIZE,comp+i*MED_SNAME_SIZE,_too_long_str);//MED_TAILLE_PNOM-1 to avoid to write '\0' on next compo
+ MEDLoaderBase::safeStrCpy2(u.c_str(),MED_SNAME_SIZE,unit+i*MED_SNAME_SIZE,_too_long_str);//MED_TAILLE_PNOM-1 to avoid to write '\0' on next compo
}
MEDFILESAFECALLERWR0(MEDmeshCr,(fid,maa,spaceDim,mdim,MED_UNSTRUCTURED_MESH,desc,"",MED_SORT_DTIT,MEDFileMeshL2::TraduceAxisTypeRev(getAxisType()),comp,unit));
if(_univ_wr_status)
}
}
+bool MEDFileUMesh::presenceOfStructureElements() const
+{
+ for(std::vector< MCAuto<MEDFileEltStruct4Mesh> >::const_iterator it=_elt_str.begin();it!=_elt_str.end();it++)
+ if((*it).isNotNull())
+ return true;
+ return false;
+}
+
+void MEDFileUMesh::killStructureElements()
+{
+ _elt_str.clear();
+}
+
/*!
* Returns the optional numbers of mesh entities of a given dimension transformed using
* DataArrayInt::invertArrayN2O2O2N().
*/
MEDFileCMesh *MEDFileCMesh::New(const std::string& fileName, MEDFileMeshReadSelector *mrs)
{
- std::vector<std::string> ms(MEDCoupling::GetMeshNames(fileName));
- if(ms.empty())
- {
- std::ostringstream oss; oss << "MEDFileUMesh::New : no meshes in file \"" << fileName << "\" !";
- throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
- MEDFileUtilities::CheckFileForRead(fileName);
- MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
- int dt,it;
- MEDCoupling::MEDCouplingMeshType meshType;
- std::string dummy2;
- MEDCoupling::MEDCouplingAxisType dummy3;
- MEDFileMeshL2::GetMeshIdFromName(fid,ms.front(),meshType,dummy3,dt,it,dummy2);
- return new MEDFileCMesh(fid,ms.front(),dt,it,mrs);
+ MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
+ return New(fid,mrs);
+}
+
+MEDFileCMesh *MEDFileCMesh::New(med_idt fid, MEDFileMeshReadSelector *mrs)
+{
+ return NewForTheFirstMeshInFile<MEDFileCMesh>(fid,mrs);
}
/*!
*/
MEDFileCMesh *MEDFileCMesh::New(const std::string& fileName, const std::string& mName, int dt, int it, MEDFileMeshReadSelector *mrs)
{
- MEDFileUtilities::CheckFileForRead(fileName);
- MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
+ MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
+ return New(fid,mName,dt,it,mrs);
+}
+
+MEDFileCMesh *MEDFileCMesh::New(med_idt fid, const std::string& mName, int dt, int it, MEDFileMeshReadSelector *mrs)
+{
return new MEDFileCMesh(fid,mName,dt,it,mrs);
}
int dummy0,dummy1;
std::string dtunit;
MEDCoupling::MEDCouplingAxisType axType;
- int mid=MEDFileMeshL2::GetMeshIdFromName(fid,mName,meshType,axType,dummy0,dummy1,dtunit);
+ INTERP_KERNEL::AutoCppPtr<MeshOrStructMeshCls> mid(MEDFileMeshL2::GetMeshIdFromName(fid,mName,meshType,axType,dummy0,dummy1,dtunit));
if(meshType!=CARTESIAN)
{
std::ostringstream oss; oss << "Trying to load as cartesian an existing mesh with name '" << mName << "' that is NOT cartesian !";
}
}
-void MEDFileCMesh::writeLL(med_idt fid) const
+void MEDFileCMesh::writeMeshLL(med_idt fid) const
{
INTERP_KERNEL::AutoPtr<char> maa=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
INTERP_KERNEL::AutoPtr<char> desc=MEDLoaderBase::buildEmptyString(MED_COMMENT_SIZE);
return new MEDFileCurveLinearMesh;
}
+MEDFileCurveLinearMesh *MEDFileCurveLinearMesh::New(med_idt fid, MEDFileMeshReadSelector *mrs)
+{
+ return NewForTheFirstMeshInFile<MEDFileCurveLinearMesh>(fid,mrs);
+}
+
MEDFileCurveLinearMesh *MEDFileCurveLinearMesh::New(const std::string& fileName, MEDFileMeshReadSelector *mrs)
{
- std::vector<std::string> ms(MEDCoupling::GetMeshNames(fileName));
- if(ms.empty())
- {
- std::ostringstream oss; oss << "MEDFileUMesh::New : no meshes in file \"" << fileName << "\" !";
- throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
- MEDFileUtilities::CheckFileForRead(fileName);
- MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
- int dt,it;
- MEDCoupling::MEDCouplingMeshType meshType;
- MEDCoupling::MEDCouplingAxisType dummy3;
- std::string dummy2;
- MEDFileMeshL2::GetMeshIdFromName(fid,ms.front(),meshType,dummy3,dt,it,dummy2);
- return new MEDFileCurveLinearMesh(fid,ms.front(),dt,it,mrs);
+ MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
+ return New(fid,mrs);
}
MEDFileCurveLinearMesh *MEDFileCurveLinearMesh::New(const std::string& fileName, const std::string& mName, int dt, int it, MEDFileMeshReadSelector *mrs)
{
- MEDFileUtilities::CheckFileForRead(fileName);
- MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
+ MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
+ return New(fid,mName,dt,it,mrs);
+}
+
+MEDFileCurveLinearMesh *MEDFileCurveLinearMesh::New(med_idt fid, const std::string& mName, int dt, int it, MEDFileMeshReadSelector *mrs)
+{
return new MEDFileCurveLinearMesh(fid,mName,dt,it,mrs);
}
throw e;
}
-void MEDFileCurveLinearMesh::writeLL(med_idt fid) const
+void MEDFileCurveLinearMesh::writeMeshLL(med_idt fid) const
{
INTERP_KERNEL::AutoPtr<char> maa=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
INTERP_KERNEL::AutoPtr<char> desc=MEDLoaderBase::buildEmptyString(MED_COMMENT_SIZE);
INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(spaceDim*MED_SNAME_SIZE);
const DataArrayDouble *coords=_clmesh->getCoords();
if(!coords)
- throw INTERP_KERNEL::Exception("MEDFileCurveLinearMesh::writeLL : no coordinates set !");
+ throw INTERP_KERNEL::Exception("MEDFileCurveLinearMesh::writeMeshLL : no coordinates set !");
for(int i=0;i<spaceDim;i++)
{
std::string info(_clmesh->getCoords()->getInfoOnComponent(i));
int dummy0,dummy1;
std::string dtunit;
MEDCoupling::MEDCouplingAxisType axType;
- int mid=MEDFileMeshL2::GetMeshIdFromName(fid,mName,meshType,axType,dummy0,dummy1,dtunit);
+ INTERP_KERNEL::AutoCppPtr<MeshOrStructMeshCls> mid(MEDFileMeshL2::GetMeshIdFromName(fid,mName,meshType,axType,dummy0,dummy1,dtunit));
setAxisType(axType);
if(meshType!=CURVE_LINEAR)
{
return new MEDFileMeshMultiTS;
}
+MEDFileMeshMultiTS *MEDFileMeshMultiTS::New(med_idt fid)
+{
+ return new MEDFileMeshMultiTS(fid);
+}
+
MEDFileMeshMultiTS *MEDFileMeshMultiTS::New(const std::string& fileName)
{
- return new MEDFileMeshMultiTS(fileName);
+ MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
+ return New(fid);
+}
+
+MEDFileMeshMultiTS *MEDFileMeshMultiTS::New(med_idt fid, const std::string& mName)
+{
+ return new MEDFileMeshMultiTS(fid,mName);
}
MEDFileMeshMultiTS *MEDFileMeshMultiTS::New(const std::string& fileName, const std::string& mName)
{
- return new MEDFileMeshMultiTS(fileName,mName);
+ MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
+ return New(fid,mName);
}
MEDFileMeshMultiTS *MEDFileMeshMultiTS::deepCopy() const
{
- MCAuto<MEDFileMeshMultiTS> ret=MEDFileMeshMultiTS::New();
+ MCAuto<MEDFileMeshMultiTS> ret(MEDFileMeshMultiTS::New());
std::vector< MCAuto<MEDFileMesh> > meshOneTs(_mesh_one_ts.size());
- std::size_t i=0;
+ std::size_t i(0);
for(std::vector< MCAuto<MEDFileMesh> >::const_iterator it=_mesh_one_ts.begin();it!=_mesh_one_ts.end();it++,i++)
if((const MEDFileMesh *)*it)
meshOneTs[i]=(*it)->deepCopy();
}
}
-void MEDFileMeshMultiTS::write(med_idt fid) const
+bool MEDFileMeshMultiTS::presenceOfStructureElements() const
+{
+ for(std::vector< MCAuto<MEDFileMesh> >::const_iterator it=_mesh_one_ts.begin();it!=_mesh_one_ts.end();it++)
+ if((*it).isNotNull())
+ if((*it)->presenceOfStructureElements())
+ return true;
+ return false;
+}
+
+void MEDFileMeshMultiTS::killStructureElements()
+{
+ for(std::vector< MCAuto<MEDFileMesh> >::iterator it=_mesh_one_ts.begin();it!=_mesh_one_ts.end();it++)
+ if((*it).isNotNull())
+ (*it)->killStructureElements();
+}
+
+void MEDFileMeshMultiTS::writeLL(med_idt fid) const
{
MEDFileJoints *joints(getJoints());
bool jointsWritten(false);
jointsWritten = true;
(*it)->copyOptionsFrom(*this);
- (*it)->write(fid);
+ (*it)->writeLL(fid);
}
(const_cast<MEDFileMeshMultiTS*>(this))->setJoints( joints ); // restore joints
}
-void MEDFileMeshMultiTS::write(const std::string& fileName, int mode) const
+void MEDFileMeshMultiTS::loadFromFile(med_idt fid, const std::string& mName)
{
- med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode);
- MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),medmod);
- std::ostringstream oss; oss << "MEDFileMesh : error on attempt to write in file : \"" << fileName << "\"";
- MEDFileUtilities::CheckMEDCode(fid,fid,oss.str());
- write(fid);
-}
-
-void MEDFileMeshMultiTS::loadFromFile(const std::string& fileName, const std::string& mName)
-{
- MEDFileJoints* joints = 0;
+ MEDFileJoints *joints(0);
if ( !_mesh_one_ts.empty() && getOneTimeStep() )
{
// joints of mName already read, pass them to MEDFileMesh::New() to prevent repeated reading
joints = getOneTimeStep()->getJoints();
}
-
_mesh_one_ts.clear(); //for the moment to be improved
- _mesh_one_ts.push_back( MEDFileMesh::New(fileName,mName,-1,-1,0, joints ));
+ _mesh_one_ts.push_back( MEDFileMesh::New(fid,mName,-1,-1,0, joints ));
}
MEDFileMeshMultiTS::MEDFileMeshMultiTS()
{
}
-MEDFileMeshMultiTS::MEDFileMeshMultiTS(const std::string& fileName)
+MEDFileMeshMultiTS::MEDFileMeshMultiTS(med_idt fid)
try
{
- std::vector<std::string> ms(MEDCoupling::GetMeshNames(fileName));
+ std::vector<std::string> ms(MEDLoaderNS::getMeshNamesFid(fid));
if(ms.empty())
{
- std::ostringstream oss; oss << "MEDFileUMesh::New : no meshes in file \"" << fileName << "\" !";
+ std::ostringstream oss; oss << "MEDFileMeshMultiTS : no meshes in file \"" << FileNameFromFID(fid) << "\" !";
throw INTERP_KERNEL::Exception(oss.str().c_str());
}
- MEDFileUtilities::CheckFileForRead(fileName);
- MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
int dt,it;
MEDCoupling::MEDCouplingMeshType meshType;
std::string dummy2;
MEDCoupling::MEDCouplingAxisType dummy3;
MEDFileMeshL2::GetMeshIdFromName(fid,ms.front(),meshType,dummy3,dt,it,dummy2);
- loadFromFile(fileName,ms.front());
+ loadFromFile(fid,ms.front());
}
catch(INTERP_KERNEL::Exception& e)
{
throw e;
}
-MEDFileMeshMultiTS::MEDFileMeshMultiTS(const std::string& fileName, const std::string& mName)
+MEDFileMeshMultiTS::MEDFileMeshMultiTS(med_idt fid, const std::string& mName)
try
{
- loadFromFile(fileName,mName);
+ loadFromFile(fid,mName);
}
catch(INTERP_KERNEL::Exception& e)
{
return new MEDFileMeshes;
}
+MEDFileMeshes *MEDFileMeshes::New(med_idt fid)
+{
+ return new MEDFileMeshes(fid);
+}
+
MEDFileMeshes *MEDFileMeshes::New(const std::string& fileName)
{
- return new MEDFileMeshes(fileName);
+ MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
+ return New(fid);
}
-void MEDFileMeshes::write(med_idt fid) const
+void MEDFileMeshes::writeLL(med_idt fid) const
{
checkConsistencyLight();
for(std::vector< MCAuto<MEDFileMeshMultiTS> >::const_iterator it=_meshes.begin();it!=_meshes.end();it++)
{
(*it)->copyOptionsFrom(*this);
- (*it)->write(fid);
+ (*it)->writeLL(fid);
}
}
-void MEDFileMeshes::write(const std::string& fileName, int mode) const
-{
- med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode);
- MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),medmod);
- std::ostringstream oss; oss << "MEDFileMesh : error on attempt to write in file : \"" << fileName << "\"";
- MEDFileUtilities::CheckMEDCode(fid,fid,oss.str());
- checkConsistencyLight();
- write(fid);
-}
+// MEDFileMeshes::writ checkConsistencyLight();
int MEDFileMeshes::getNumberOfMeshes() const
{
_meshes.erase(_meshes.begin()+i);
}
-void MEDFileMeshes::loadFromFile(const std::string& fileName)
+void MEDFileMeshes::loadFromFile(med_idt fid)
{
- std::vector<std::string> ms(MEDCoupling::GetMeshNames(fileName));
+ std::vector<std::string> ms(MEDLoaderNS::getMeshNamesFid(fid));
int i=0;
_meshes.resize(ms.size());
for(std::vector<std::string>::const_iterator it=ms.begin();it!=ms.end();it++,i++)
- _meshes[i]=MEDFileMeshMultiTS::New(fileName,(*it));
+ _meshes[i]=MEDFileMeshMultiTS::New(fid,(*it));
}
MEDFileMeshes::MEDFileMeshes()
{
}
-MEDFileMeshes::MEDFileMeshes(const std::string& fileName)
+MEDFileMeshes::MEDFileMeshes(med_idt fid)
try
{
- loadFromFile(fileName);
+ loadFromFile(fid);
}
catch(INTERP_KERNEL::Exception& /*e*/)
{
for(std::vector< MCAuto<MEDFileMeshMultiTS> >::const_iterator it=_meshes.begin();it!=_meshes.end();it++,i++)
if((const MEDFileMeshMultiTS *)*it)
meshes[i]=(*it)->deepCopy();
- MCAuto<MEDFileMeshes> ret=MEDFileMeshes::New();
+ MCAuto<MEDFileMeshes> ret(MEDFileMeshes::New());
ret->_meshes=meshes;
return ret.retn();
}
}
}
+bool MEDFileMeshes::presenceOfStructureElements() const
+{
+ for(std::vector< MCAuto<MEDFileMeshMultiTS> >::const_iterator it=_meshes.begin();it!=_meshes.end();it++)
+ if((*it).isNotNull())
+ if((*it)->presenceOfStructureElements())
+ return true;
+ return false;
+}
+
+void MEDFileMeshes::killStructureElements()
+{
+ for(std::vector< MCAuto<MEDFileMeshMultiTS> >::iterator it=_meshes.begin();it!=_meshes.end();it++)
+ if((*it).isNotNull())
+ (*it)->killStructureElements();
+}
+
MEDFileMeshesIterator::MEDFileMeshesIterator(MEDFileMeshes *ms):_ms(ms),_iter_id(0),_nb_iter(0)
{
if(ms)
else
return 0;
}
+
+INTERP_KERNEL::NormalizedCellType MEDFileMesh::ConvertFromMEDFileGeoType(med_geometry_type geoType)
+{
+ med_geometry_type *pos(std::find(typmai,typmai+MED_N_CELL_FIXED_GEO,geoType));
+ if(pos==typmai+MED_N_CELL_FIXED_GEO)
+ {
+ if(geoType==MED_NO_GEOTYPE)
+ return INTERP_KERNEL::NORM_ERROR;
+ std::ostringstream oss; oss << "MEDFileMesh::ConvertFromMEDFileGeoType : no entry with " << geoType << " !";
+ throw INTERP_KERNEL::Exception(oss.str());
+ }
+ return typmai2[std::distance(typmai,pos)];
+}
+
+TypeOfField MEDFileMesh::ConvertFromMEDFileEntity(med_entity_type etype)
+{
+ switch(etype)
+ {
+ case MED_NODE:
+ return ON_NODES;
+ case MED_CELL:
+ return ON_CELLS;
+ default:
+ {
+ std::ostringstream oss; oss << "EDFileMesh::ConvertFromMEDFileEntity : not recognized entity " << etype << " !";
+ throw INTERP_KERNEL::Exception(oss.str());
+ }
+ }
+}
+
+